Ignore:
Timestamp:
Jun 29, 2023, 1:47:58 AM (17 months ago)
Author:
chronos
Message:
  • Fixed: Var function parameters processed correctly for both user defined and internal functions.
File:
1 edited

Legend:

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

    r235 r236  
    1414    procedure GenerateProgram(Block: TBlock;  Prog:TProgram);
    1515    procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction);
     16    procedure GenerateFunctionParams(ParentBlock: TBlock; Params: TFunctionParameters);
    1617    procedure GenerateProcedure(ParentBlock: TBlock; ProcedureDef: TProcedure);
    1718    procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock);
     
    218219  AddTextLine('{$mode delphi}');
    219220  AddTextLine('');
    220   AddTextLine('uses SysUtils;');
     221  AddTextLine('uses');
     222  AddTextLine('  SysUtils;');
     223  AddTextLine('');
    221224  GenerateBlock(Block, Prog.Block);
    222225  AddTextLine('.');
     
    225228procedure TGeneratorPascal.GenerateFunction(ParentBlock: TBlock;
    226229  FunctionDef: TFunction);
    227 var
    228   I: Integer;
    229230begin
    230231  AddText('function ' + FunctionDef.Name);
    231   if FunctionDef.Params.Count > 0 then begin
    232     AddText('(');
    233     for I := 0 to FunctionDef.Params.Count - 1 do begin
    234       AddText(FunctionDef.Params[I].Name);
    235       AddText(': ');
    236       AddText(FunctionDef.Params[I].TypeRef.Name);
    237       if I > 0 then AddText(', ');
    238     end;
    239     AddText(')');
    240   end;
     232  GenerateFunctionParams(ParentBlock, FunctionDef.Params);
    241233  if Assigned(FunctionDef.ResultType) then begin
    242234    AddText(': ');
     
    259251end;
    260252
    261 procedure TGeneratorPascal.GenerateProcedure(ParentBlock: TBlock;
    262   ProcedureDef: TProcedure);
    263 var
    264   I: Integer;
    265 begin
    266   AddText('procedure ' + ProcedureDef.Name);
    267   if ProcedureDef.Params.Count > 0 then begin
     253procedure TGeneratorPascal.GenerateFunctionParams(ParentBlock: TBlock;
     254  Params: TFunctionParameters);
     255var
     256  I: Integer;
     257begin
     258  if Params.Count > 0 then begin
    268259    AddText('(');
    269     for I := 0 to ProcedureDef.Params.Count - 1 do begin
    270       AddText(ProcedureDef.Params[I].Name);
     260    for I := 0 to Params.Count - 1 do begin
     261      if Params[I].Kind = pkVar then AddText('var ');
     262      if Params[I].Kind = pkConst then AddText('const ');
     263      AddText(Params[I].Name);
    271264      AddText(': ');
    272       AddText(ProcedureDef.Params[I].TypeRef.Name);
     265      AddText(Params[I].TypeRef.Name);
    273266      if I > 0 then AddText(', ');
    274267    end;
    275268    AddText(')');
    276269  end;
     270end;
     271
     272procedure TGeneratorPascal.GenerateProcedure(ParentBlock: TBlock;
     273  ProcedureDef: TProcedure);
     274begin
     275  AddText('procedure ' + ProcedureDef.Name);
     276  GenerateFunctionParams(ParentBlock, ProcedureDef.Params);
    277277  AddTextLine(';');
    278278  if ProcedureDef.InternalName <> '' then begin
Note: See TracChangeset for help on using the changeset viewer.