Changeset 234 for branches/xpascal/Generators/GeneratorPascal.pas
- Timestamp:
- Jun 27, 2023, 12:50:09 AM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/xpascal/Generators/GeneratorPascal.pas
r230 r234 14 14 procedure GenerateProgram(Block: TBlock; Prog:TProgram); 15 15 procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction); 16 procedure GenerateProcedure(ParentBlock: TBlock; ProcedureDef: TProcedure); 16 17 procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock); 17 18 procedure GenerateBlockVar(ParentBlock: TBlock; Block: TBlock); 18 19 procedure GenerateBlockConst(ParentBlock: TBlock; Block: TBlock); 19 20 procedure GenerateBlockFunctions(ParentBlock: TBlock; Block: TBlock); 21 procedure GenerateBlockProcedures(ParentBlock: TBlock; Block: TBlock); 20 22 procedure GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd); 21 23 procedure GenerateCommand(Block: TBlock; Command: TCommand); … … 25 27 procedure GenerateRepeatUntil(Block: TBlock; RepeatUntil: TRepeatUntil); 26 28 procedure GenerateFunctionCall(Block: TBlock; FunctionCall: TFunctionCall); 29 procedure GenerateProcedureCall(Block: TBlock; ProcedureCall: TProcedureCall); 27 30 procedure GenerateAssignment(Block: TBlock; Assignment: TAssignment); 28 31 procedure GenerateExpression(Block: TBlock; Expression: TExpression); … … 47 50 if Command is TBeginEnd then GenerateBeginEnd(Block, TBeginEnd(Command)) 48 51 else if Command is TFunctionCall then GenerateFunctionCall(Block, TFunctionCall(Command)) 52 else if Command is TProcedureCall then GenerateProcedureCall(Block, TProcedureCall(Command)) 49 53 else if Command is TAssignment then GenerateAssignment(Block, TAssignment(Command)) 50 54 else if Command is TIfThenElse then GenerateIfThenElse(Block, TIfThenElse(Command)) … … 120 124 end; 121 125 126 procedure TGeneratorPascal.GenerateProcedureCall(Block: TBlock; 127 ProcedureCall: TProcedureCall); 128 var 129 I: Integer; 130 begin 131 AddText(ProcedureCall.ProcedureDef.Name); 132 if ProcedureCall.Params.Count > 0 then begin 133 AddText('('); 134 for I := 0 to ProcedureCall.Params.Count - 1 do 135 GenerateExpression(Block, TExpression(ProcedureCall.Params[I])); 136 AddText(')'); 137 end; 138 end; 139 122 140 procedure TGeneratorPascal.GenerateAssignment(Block: TBlock; Assignment: TAssignment); 123 141 begin … … 228 246 AddTextLine('begin'); 229 247 Indent := Indent + 1; 230 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('System.WriteLn(Text);') 231 else if FunctionDef.InternalName = 'Write' then AddTextLine('System.Write(Text);') 232 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return SysUtils.IntToStr(Value);') 248 if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return SysUtils.IntToStr(Value);') 233 249 else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return SysUtils.StrToInt(Value);') 234 250 else if FunctionDef.InternalName = 'BoolToStr' then AddTextLine('return SysUtils.BoolToStr(Value);') … … 242 258 end; 243 259 260 procedure TGeneratorPascal.GenerateProcedure(ParentBlock: TBlock; 261 ProcedureDef: TProcedure); 262 var 263 I: Integer; 264 begin 265 AddText('procedure ' + ProcedureDef.Name); 266 if ProcedureDef.Params.Count > 0 then begin 267 AddText('('); 268 for I := 0 to ProcedureDef.Params.Count - 1 do begin 269 AddText(TFunctionParameter(ProcedureDef.Params[I]).Name); 270 AddText(': '); 271 AddText(TFunctionParameter(ProcedureDef.Params[I]).TypeRef.Name); 272 if I > 0 then AddText(', '); 273 end; 274 AddText(')'); 275 end; 276 AddTextLine(';'); 277 if ProcedureDef.InternalName <> '' then begin 278 AddTextLine('begin'); 279 Indent := Indent + 1; 280 if ProcedureDef.InternalName = 'WriteLn' then AddTextLine('System.WriteLn(Text);') 281 else if ProcedureDef.InternalName = 'Write' then AddTextLine('System.Write(Text);') 282 else if ProcedureDef.InternalName = 'ReadLn' then AddTextLine('System.ReadLn(Text);') 283 else if ProcedureDef.InternalName = 'Read' then AddTextLine('System.Read(Text);'); 284 Indent := Indent - 1; 285 AddTextLine('end;'); 286 end else begin 287 GenerateBlock(ParentBlock, ProcedureDef.Block); 288 AddTextLine(';'); 289 end; 290 end; 291 244 292 procedure TGeneratorPascal.GenerateBlock(ParentBlock: TBlock; Block: TBlock); 245 293 begin 246 294 GenerateBlockConst(ParentBlock, Block); 247 295 GenerateBlockVar(ParentBlock, Block); 296 GenerateBlockProcedures(ParentBlock, Block); 248 297 GenerateBlockFunctions(ParentBlock, Block); 249 298 GenerateBeginEnd(ParentBlock, Block.BeginEnd); … … 317 366 end; 318 367 368 procedure TGeneratorPascal.GenerateBlockProcedures(ParentBlock: TBlock; 369 Block: TBlock); 370 var 371 I: Integer; 372 begin 373 for I := 0 to Block.Procedures.Count - 1 do begin 374 GenerateProcedure(ParentBlock, TProcedure(Block.Procedures[I])); 375 AddTextLine; 376 end; 377 end; 378 319 379 procedure TGeneratorPascal.Generate; 320 380 begin
Note:
See TracChangeset
for help on using the changeset viewer.