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

Legend:

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

    r232 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 GenerateBlockConst(ParentBlock: TBlock; Block: TBlock);
    1819    procedure GenerateBlockFunctions(ParentBlock: TBlock; Block: TBlock);
     20    procedure GenerateBlockProcedures(ParentBlock: TBlock; Block: TBlock);
    1921    procedure GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd);
    2022    procedure GenerateCommand(Block: TBlock; Command: TCommand);
     
    2426    procedure GenerateForToDo(Block: TBlock; ForToDo: TForToDo);
    2527    procedure GenerateFunctionCall(Block: TBlock; FunctionCall: TFunctionCall);
     28    procedure GenerateProcedureCall(Block: TBlock; ProcedureCall: TProcedureCall);
    2629    procedure GenerateAssignment(Block: TBlock; Assignment: TAssignment);
    2730    procedure GenerateExpression(Block: TBlock; Expression: TExpression);
     
    5255  if Command is TBeginEnd then GenerateBeginEnd(Block, TBeginEnd(Command))
    5356  else if Command is TFunctionCall then GenerateFunctionCall(Block, TFunctionCall(Command))
     57  else if Command is TProcedureCall then GenerateProcedureCall(Block, TProcedureCall(Command))
    5458  else if Command is TAssignment then GenerateAssignment(Block, TAssignment(Command))
    5559  else if Command is TIfThenElse then GenerateIfThenElse(Block, TIfThenElse(Command))
     
    133137end;
    134138
     139procedure TGeneratorPhp.GenerateProcedureCall(Block: TBlock;
     140  ProcedureCall: TProcedureCall);
     141var
     142  I: Integer;
     143begin
     144  AddText(ProcedureCall.ProcedureDef.Name);
     145  if ProcedureCall.Params.Count > 0 then begin
     146    AddText('(');
     147    for I := 0 to ProcedureCall.Params.Count - 1 do
     148      GenerateExpression(Block, TExpression(ProcedureCall.Params[I]));
     149    AddText(')');
     150  end;
     151end;
     152
    135153procedure TGeneratorPhp.GenerateAssignment(Block: TBlock; Assignment: TAssignment);
    136154begin
     
    240258    AddTextLine('{');
    241259    Indent := Indent + 1;
    242     if FunctionDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");')
    243     else if FunctionDef.InternalName = 'Write' then AddTextLine('echo($Text);')
    244     else if FunctionDef.InternalName = 'ReadLn' then AddTextLine('$Text = readline();')
    245     else if FunctionDef.InternalName = 'Read' then AddTextLine('$Text = readline();')
    246     else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;')
     260    if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;')
    247261    else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;')
    248262    else if FunctionDef.InternalName = 'BoolToStr' then AddTextLine('return $Value;')
     
    256270end;
    257271
     272procedure TGeneratorPhp.GenerateProcedure(ParentBlock: TBlock;
     273  ProcedureDef: TProcedure);
     274var
     275  I: Integer;
     276begin
     277  AddText('function ' + ProcedureDef.Name + '(');
     278  for I := 0 to ProcedureDef.Params.Count - 1 do begin
     279    if ProcedureDef.Params[I].Kind = pkVar then
     280      AddText('&');
     281    AddText('$' + TFunctionParameter(ProcedureDef.Params[I]).Name);
     282    if I > 0 then AddText(', ');
     283  end;
     284  AddTextLine(')');
     285  if ProcedureDef.InternalName <> '' then begin
     286    AddTextLine('{');
     287    Indent := Indent + 1;
     288    if ProcedureDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");')
     289    else if ProcedureDef.InternalName = 'Write' then AddTextLine('echo($Text);')
     290    else if ProcedureDef.InternalName = 'ReadLn' then AddTextLine('$Text = readline();')
     291    else if ProcedureDef.InternalName = 'Read' then AddTextLine('$Text = readline();');
     292    Indent := Indent - 1;
     293    AddTextLine('}');
     294  end else begin
     295    GenerateBlock(ParentBlock, ProcedureDef.Block);
     296    AddTextLine;
     297  end;
     298end;
     299
    258300procedure TGeneratorPhp.GenerateBlock(ParentBlock: TBlock; Block: TBlock);
    259301begin
    260302  GenerateBlockConst(ParentBlock, Block);
     303  GenerateBlockProcedures(ParentBlock, Block);
    261304  GenerateBlockFunctions(ParentBlock, Block);
    262305  if Block.BeginEnd.Commands.Count > 0 then begin
     
    290333end;
    291334
     335procedure TGeneratorPhp.GenerateBlockProcedures(ParentBlock: TBlock;
     336  Block: TBlock);
     337var
     338  I: Integer;
     339begin
     340  for I := 0 to Block.Procedures.Count - 1 do begin
     341    GenerateProcedure(ParentBlock, TProcedure(Block.Procedures[I]));
     342    AddTextLine;
     343  end;
     344end;
     345
    292346procedure TGeneratorPhp.GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd);
    293347var
Note: See TracChangeset for help on using the changeset viewer.