Ignore:
Timestamp:
Jun 27, 2023, 12:50:09 AM (11 months ago)
Author:
chronos
Message:
  • Fixed: Procedures generation.
  • Fixed: Splitters between panels.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/xpascal/Generators/GeneratorPascal.pas

    r230 r234  
    1414    procedure GenerateProgram(Block: TBlock;  Prog:TProgram);
    1515    procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction);
     16    procedure GenerateProcedure(ParentBlock: TBlock; ProcedureDef: TProcedure);
    1617    procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock);
    1718    procedure GenerateBlockVar(ParentBlock: TBlock; Block: TBlock);
    1819    procedure GenerateBlockConst(ParentBlock: TBlock; Block: TBlock);
    1920    procedure GenerateBlockFunctions(ParentBlock: TBlock; Block: TBlock);
     21    procedure GenerateBlockProcedures(ParentBlock: TBlock; Block: TBlock);
    2022    procedure GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd);
    2123    procedure GenerateCommand(Block: TBlock; Command: TCommand);
     
    2527    procedure GenerateRepeatUntil(Block: TBlock; RepeatUntil: TRepeatUntil);
    2628    procedure GenerateFunctionCall(Block: TBlock; FunctionCall: TFunctionCall);
     29    procedure GenerateProcedureCall(Block: TBlock; ProcedureCall: TProcedureCall);
    2730    procedure GenerateAssignment(Block: TBlock; Assignment: TAssignment);
    2831    procedure GenerateExpression(Block: TBlock; Expression: TExpression);
     
    4750  if Command is TBeginEnd then GenerateBeginEnd(Block, TBeginEnd(Command))
    4851  else if Command is TFunctionCall then GenerateFunctionCall(Block, TFunctionCall(Command))
     52  else if Command is TProcedureCall then GenerateProcedureCall(Block, TProcedureCall(Command))
    4953  else if Command is TAssignment then GenerateAssignment(Block, TAssignment(Command))
    5054  else if Command is TIfThenElse then GenerateIfThenElse(Block, TIfThenElse(Command))
     
    120124end;
    121125
     126procedure TGeneratorPascal.GenerateProcedureCall(Block: TBlock;
     127  ProcedureCall: TProcedureCall);
     128var
     129  I: Integer;
     130begin
     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;
     138end;
     139
    122140procedure TGeneratorPascal.GenerateAssignment(Block: TBlock; Assignment: TAssignment);
    123141begin
     
    228246    AddTextLine('begin');
    229247    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);')
    233249    else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return SysUtils.StrToInt(Value);')
    234250    else if FunctionDef.InternalName = 'BoolToStr' then AddTextLine('return SysUtils.BoolToStr(Value);')
     
    242258end;
    243259
     260procedure TGeneratorPascal.GenerateProcedure(ParentBlock: TBlock;
     261  ProcedureDef: TProcedure);
     262var
     263  I: Integer;
     264begin
     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;
     290end;
     291
    244292procedure TGeneratorPascal.GenerateBlock(ParentBlock: TBlock; Block: TBlock);
    245293begin
    246294  GenerateBlockConst(ParentBlock, Block);
    247295  GenerateBlockVar(ParentBlock, Block);
     296  GenerateBlockProcedures(ParentBlock, Block);
    248297  GenerateBlockFunctions(ParentBlock, Block);
    249298  GenerateBeginEnd(ParentBlock, Block.BeginEnd);
     
    317366end;
    318367
     368procedure TGeneratorPascal.GenerateBlockProcedures(ParentBlock: TBlock;
     369  Block: TBlock);
     370var
     371  I: Integer;
     372begin
     373  for I := 0 to Block.Procedures.Count - 1 do begin
     374    GenerateProcedure(ParentBlock, TProcedure(Block.Procedures[I]));
     375    AddTextLine;
     376  end;
     377end;
     378
    319379procedure TGeneratorPascal.Generate;
    320380begin
Note: See TracChangeset for help on using the changeset viewer.