Ignore:
Timestamp:
Sep 8, 2009, 2:01:55 PM (15 years ago)
Author:
george
Message:
  • Přidáno: Analýza páru dalších programových konstrukcí.
  • Přidáno: Pár jednoduchých testovacích příkladů pro překladač.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/UPascalSource.pas

    r19 r20  
    4343
    4444  TCommand = class
    45 
     45    Parent: TObject;
     46
     47  end;
     48
     49  TAssignment = class(TCommand)
     50    Target: TVariable;
     51    Source: TExpression;
     52    constructor Create;
     53    destructor Destroy; override;
     54  end;
     55
     56  TMethodCall = class(TCommand)
     57    Method: TMethod;
    4658  end;
    4759
    4860  TBeginEnd = class(TCommand)
    4961    Commands: TCommandList;
     62    procedure Clear;
     63    constructor Create;
     64    destructor Destroy; override;
    5065  end;
    5166
     
    5368    Condition: TExpression;
    5469    Command: TCommand;
    55   end;
    56 
    57   WithDo = class(TCommand)
     70    constructor Create;
     71    destructor Destroy; override;
     72  end;
     73
     74  TWithDo = class(TCommand)
    5875    Context: TContext;
    5976    Command: TCommand;
    6077  end;
    6178
    62   RepeatUntil = class(TCommand)
     79  TRepeatUntil = class(TCommand)
    6380    Block: TCommandList;
    6481    Condition: TExpression;
    6582  end;
    6683
    67   ForToDo = class(TCommand)
     84  TForToDo = class(TCommand)
    6885    ControlVariable: TVariable;
    6986    Start: TExpression;
     
    7289  end;
    7390
    74   IfThenElse = class(TCommand)
     91  TIfThenElse = class(TCommand)
    7592    Condition: TExpression;
    7693    Command: TCommand;
     
    83100  end;
    84101
    85   CaseOfEnd = class(TCommand)
     102  TCaseOfEnd = class(TCommand)
    86103    Expression: TExpression;
    87104    Branches: TList; // TList<TCaseOfEndBranche>
     
    89106  end;
    90107
    91   TryFinally = class(TCommand)
     108  TTryFinally = class(TCommand)
    92109    Block: TCommandList;
    93110    FinallyBlock: TCommandList;
    94111  end;
    95112
    96   TryExcept = class(TCommand)
     113  TTryExcept = class(TCommand)
    97114    Block: TCommandList;
    98115    ExceptBlock: TCommandList;
    99116  end;
    100 
    101 
    102117
    103118  TCommandList = class(TList)
     
    112127    Variables: TVariableList;
    113128    Methods: TFunctionList;
    114     Operations: TOperationList;
     129    Code: TBeginEnd;
    115130    constructor Create; virtual;
    116131    destructor Destroy; override;
    117     procedure CheckReferences;
     132//    procedure CheckReferences;
    118133  end;
    119134
     
    166181    Parent: TCommonBlock;
    167182    function Search(Name: string): TVariable;
     183    destructor Destroy; override;
     184  end;
     185
     186  TParameter = class
     187    Name: string;
     188    ValueType: TType;
     189    DafaultValue: TValue;
     190  end;
     191
     192  TParameterList = class(TList)
     193    Parent: TFunction;
     194    function Search(Name: string): TParameter;
    168195    destructor Destroy; override;
    169196  end;
     
    200227  TFunction = class(TCommonBlock)
    201228  public
    202     Parameters: TList; // TList<TParameter>
     229    Parameters: TList; // TList<TVariable>
    203230    ResultType: TType;
    204231    constructor Create; override;
     
    246273begin
    247274  inherited;
    248   Parameters := TList.Create;
    249   ResultType := TType.Create;
     275  Parameters := TParameterList.Create;
     276  TParameterList(Parameters).Parent := Self;
     277  //ResultType := TType.Create;
    250278end;
    251279
     
    253281begin
    254282  Parameters.Free;
    255   ResultType.Free;
     283//  ResultType.Free;
    256284  inherited;
    257285end;
     
    310338  Constants.Clear;
    311339  Methods.Clear;
    312   Operations.Clear;
     340  Code.Clear;
    313341end;
    314342
     
    325353end;
    326354
     355(*
    327356procedure TCommonBlock.CheckReferences;
    328357var
     
    335364  end;
    336365end;
     366*)
    337367
    338368constructor TCommonBlock.Create;
     
    346376  Methods := TFunctionList.Create;
    347377  Methods.Parent := Self;
    348   Operations := TOperationList.Create;
     378  Code := TBeginEnd.Create;
    349379end;
    350380
     
    355385  Variables.Destroy;
    356386  Methods.Destroy;
    357   Operations.Destroy;
     387  Code.Destroy;
    358388  inherited;
    359389end;
     
    483513end;
    484514
     515{ TParameterList }
     516
     517destructor TParameterList.Destroy;
     518var
     519  I: Integer;
     520begin
     521  for I := 0 to Count - 1 do
     522    TParameter(Items[I]).Free;
     523  inherited;
     524end;
     525
     526function TParameterList.Search(Name: string): TParameter;
     527var
     528  I: Integer;
     529begin
     530  I := 0;
     531  while (I < Count) and (TParameter(Items[I]).Name <> Name) do Inc(I);
     532  if I < Count then Result := Items[I] else Result := nil;
     533end;
     534
     535{ TBeginEnd }
     536
     537procedure TBeginEnd.Clear;
     538begin
     539
     540end;
     541
     542constructor TBeginEnd.Create;
     543begin
     544  Commands := TCommandList.Create;
     545end;
     546
     547destructor TBeginEnd.Destroy;
     548begin
     549  Commands.Free;
     550  inherited;
     551end;
     552
     553{ TAssignment }
     554
     555constructor TAssignment.Create;
     556begin
     557//  Source := TExpression.Create;
     558end;
     559
     560destructor TAssignment.Destroy;
     561begin
     562  Source.Free;
     563  inherited;
     564end;
     565
     566{ TWhileDo }
     567
     568constructor TWhileDo.Create;
     569begin
     570  Condition := TExpression.Create;
     571  Command := TCommand.Create;
     572end;
     573
     574destructor TWhileDo.Destroy;
     575begin
     576  Condition.Free;
     577  Command.Free;
     578  inherited;
     579end;
     580
    485581end.
    486582
Note: See TracChangeset for help on using the changeset viewer.