Changeset 232 for branches


Ignore:
Timestamp:
Jun 26, 2023, 12:51:06 PM (17 months ago)
Author:
chronos
Message:
  • Fixed: Generation of var function parameters.
Location:
branches/xpascal
Files:
5 edited

Legend:

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

    r230 r232  
    231231  AddText('function ' + FunctionDef.Name + '(');
    232232  for I := 0 to FunctionDef.Params.Count - 1 do begin
     233    if FunctionDef.Params[I].Kind = pkVar then
     234      AddText('&');
    233235    AddText('$' + TFunctionParameter(FunctionDef.Params[I]).Name);
    234236    if I > 0 then AddText(', ');
     
    240242    if FunctionDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");')
    241243    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();')
    242246    else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;')
    243247    else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;')
  • branches/xpascal/Generators/GeneratorXml.pas

    r231 r232  
    4242  Field: TField;
    4343  Obj: TObject;
     44  List: TSourceNodeList<TSourceNode>;
    4445begin
    45   if SourceNode = nil then begin
    46   end else
    47   if SourceNode is TSourceNodeList<TSourceNode> then begin
    48     GenerateNodes(TSourceNodeList<TSourceNode>(SourceNode))
    49   end else
    5046  if SourceNode is TSourceNode then begin
    5147    AddTextLine('<' + SourceNode.ClassName + '>');
     
    5753        if Obj is TSourceNode then
    5854          GenerateNode(TSourceNode(Obj));
     55      end else
     56      if Field.DataType = dtList then begin
     57        SourceNode.GetValue(I, List);
     58        GenerateNodes(List);
    5959      end else
    6060      if Field.DataType = dtString then begin
  • branches/xpascal/Optimizer.pas

    r231 r232  
    5555  Obj: TObject;
    5656  TempNewNode: TSourceNode;
     57  ListValue: TSourceNodeList<TSourceNode>;
    5758begin
    5859  NewNode := nil;
    59   if SourceNode = nil then begin
    60   end else
    61   if SourceNode is TSourceNodeList<TSourceNode> then begin
    62     OptimizeNodes(TSourceNodeList<TSourceNode>(SourceNode), NewNode)
    63   end else
    6460  if (ofReplaceRepeatUntilByWhileDo in Features) and (SourceNode is TRepeatUntil) then begin
    6561    WhileDo := TWhileDo.Create;
     
    113109  end else
    114110    raise Exception.Create(SUnsupportedNodeType);
     111
     112  for I := 0 to SourceNode.FieldsCount - 1 do begin
     113    Field := SourceNode.GetField(I);
     114    if Field.DataType = dtList then begin
     115      SourceNode.GetValue(I, ListValue);
     116      OptimizeNodes(TSourceNodeList<TSourceNode>(ListValue), NewNode)
     117    end;
     118  end;
    115119end;
    116120
  • branches/xpascal/Source.pas

    r231 r232  
    4444
    4545  TType = class(TSourceNode)
    46   private
     46  protected
    4747    function GetFieldsCount: Integer; override;
    4848  public
     
    6767
    6868  TVariable = class(TSourceNode)
    69   private
     69  protected
    7070    function GetFieldsCount: Integer; override;
    7171  public
     
    8787
    8888  TConstant = class(TSourceNode)
    89   private
     89  protected
    9090    function GetFieldsCount: Integer; override;
    9191  public
     
    124124
    125125  TFunction = class(TSourceNode)
    126   private
     126  protected
    127127    function GetFieldsCount: Integer; override;
    128128  public
     
    160160
    161161  TFunctionCall = class(TCommand)
    162   private
     162  protected
    163163    function GetFieldsCount: Integer; override;
    164164  public
     
    175175
    176176  TBeginEnd = class(TCommand)
    177   private
     177  protected
    178178    function GetFieldsCount: Integer; override;
    179179  public
     
    200200
    201201  TExpressionOperation = class(TExpression)
    202   private
     202  protected
    203203    function GetFieldsCount: Integer; override;
    204204  public
     
    222222
    223223  TExpressionOperand = class(TExpression)
    224   private
     224  protected
    225225    function GetFieldsCount: Integer; override;
    226226  public
     
    255255
    256256  TAssignment = class(TCommand)
    257   private
     257  protected
    258258    function GetFieldsCount: Integer; override;
    259259  public
     
    270270
    271271  TReturn = class(TCommand)
    272   private
     272  protected
    273273    function GetFieldsCount: Integer; override;
    274274  public
     
    284284
    285285  TIfThenElse = class(TCommand)
    286   private
     286  protected
    287287    function GetFieldsCount: Integer; override;
    288288  public
     
    305305
    306306  TWhileDo = class(TLoop)
    307   private
     307  protected
    308308    function GetFieldsCount: Integer; override;
    309309  public
     
    320320
    321321  TRepeatUntil = class(TLoop)
    322   private
     322  protected
    323323    function GetFieldsCount: Integer; override;
    324324  public
     
    341341
    342342  TForToDo = class(TLoop)
    343   private
     343  protected
    344344    function GetFieldsCount: Integer; override;
    345345  public
     
    358358
    359359  TBlock = class(TSourceNode)
    360   private
     360  protected
    361361    function GetFieldsCount: Integer; override;
    362362  public
     
    382382
    383383  TProgram = class(TSourceNode)
    384   private
     384  protected
    385385    function GetFieldsCount: Integer; override;
    386386  public
     
    571571begin
    572572  if Index = 0 then Result := TField.Create(dtObject, 'Expression')
    573   else if Index = 1 then Result := TField.Create(dtObject, 'Commands')
     573  else if Index = 1 then Result := TField.Create(dtList, 'Commands')
    574574  else inherited;
    575575end;
     
    779779begin
    780780  if Index = 0 then Result := TField.Create(dtObject, 'Block')
    781   else if Index = 1 then Result := TField.Create(dtObject, 'Parameters')
     781  else if Index = 1 then Result := TField.Create(dtList, 'Parameters')
    782782  else if Index = 2 then Result := TField.Create(dtObject, 'ResultType')
    783783  else if Index = 3 then Result := TField.Create(dtString, 'Name')
     
    11451145begin
    11461146  if Index = 0 then Result := TField.Create(dtObject, 'Block')
    1147   else if Index = 1 then Result := TField.Create(dtObject, 'Types')
    1148   else if Index = 2 then Result := TField.Create(dtObject, 'Variables')
    1149   else if Index = 3 then Result := TField.Create(dtObject, 'Constants')
    1150   else if Index = 4 then Result := TField.Create(dtObject, 'Functions')
     1147  else if Index = 1 then Result := TField.Create(dtList, 'Types')
     1148  else if Index = 2 then Result := TField.Create(dtList, 'Variables')
     1149  else if Index = 3 then Result := TField.Create(dtList, 'Constants')
     1150  else if Index = 4 then Result := TField.Create(dtList, 'Functions')
    11511151  else inherited;
    11521152end;
     
    12371237function TBeginEnd.GetField(Index: Integer): TField;
    12381238begin
    1239   if Index = 0 then Result := TField.Create(dtObject, 'Command')
     1239  if Index = 0 then Result := TField.Create(dtList, 'Command')
    12401240  else inherited;
    12411241end;
  • branches/xpascal/SourceNode.pas

    r231 r232  
    88type
    99  TDataType = (dtNone, dtString, dtBoolean, dtInteger, dtFloat, dtColor,
    10     dtTime, dtDate, dtDateTime, dtEnumeration, dtObject);
     10    dtTime, dtDate, dtDateTime, dtEnumeration, dtObject, dtList);
    1111
    1212  { TField }
     
    4747  { TSourceNodeList }
    4848
    49   TSourceNodeList<T> = class(TSourceNode)
     49  TSourceNodeList<T: TSourceNode> = class(TObjectList<T>)
    5050  private
    5151    Parent: TSourceNode;
    52     function GetCount: Integer;
    53     function GetItem(Index: Integer): T;
    54     procedure SetItem(Index: Integer; AValue: T);
    55   public
    56     List: TObjectList<TSourceNode>;
    57     procedure Clear;
    58     function Add(AObject: T): Integer;
    59     constructor Create;
    60     destructor Destroy; override;
    61     property Items[Index: Integer]: T read GetItem write SetItem; default;
    62     property Count: Integer read GetCount;
    6352  end;
    6453
     
    7564  DataTypeStr: array[TDataType] of string = ('None', 'String', 'Boolean',
    7665    'Integer', 'Float', 'Color', 'Time', 'Date', 'DateTime', 'Enumeration',
    77     'Reference');
     66    'Reference', 'List');
    7867
    7968{ TField }
     
    8372  DataType := ADataType;
    8473  Name := AName;
    85 end;
    86 
    87 { TSourceNodeList }
    88 
    89 function TSourceNodeList<T>.GetCount: Integer;
    90 begin
    91   Result := List.Count;
    92 end;
    93 
    94 function TSourceNodeList<T>.GetItem(Index: Integer): T;
    95 begin
    96   Result := T(List[Index]);
    97 end;
    98 
    99 procedure TSourceNodeList<T>.SetItem(Index: Integer; AValue: T);
    100 begin
    101   List[Index] := AValue;
    102 end;
    103 
    104 procedure TSourceNodeList<T>.Clear;
    105 begin
    106   List.Clear;
    107 end;
    108 
    109 function TSourceNodeList<T>.Add(AObject: T): Integer;
    110 begin
    111   Result := List.Add(AObject);
    112 end;
    113 
    114 constructor TSourceNodeList<T>.Create;
    115 begin
    116   List := TObjectList<TSourceNode>.Create;
    117 end;
    118 
    119 destructor TSourceNodeList<T>.Destroy;
    120 begin
    121   FreeAndNil(List);
    122   inherited;
    12374end;
    12475
Note: See TracChangeset for help on using the changeset viewer.