Ignore:
Timestamp:
Jun 4, 2024, 12:22:49 AM (4 months ago)
Author:
chronos
Message:
  • Modified: Removed U prefix from unit names.
  • Modified: Updated Common package.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/Modules/Pascal/SourceCodePascal.pas

    r74 r75  
    1 unit USourceCodePascal;
    2 
    3 {$MODE Delphi}
    4 {$MACRO ON}
     1unit SourceCodePascal;
    52
    63interface
    74
    85uses
    9   SysUtils, Variants, Classes, Dialogs, SpecializedList, USourceConvertor;
     6  SysUtils, Variants, Classes, Dialogs, Generics.Collections, SourceConvertor;
    107
    118type
     
    2219
    2320  TCommonBlock = class;
    24   TTypeList = class;
    25   TConstantList = class;
    26   TVariableList = class;
    27   TFunctionList = class;
    28   TListExpression = class;
     21  TTypes = class;
     22  TConstants = class;
     23  TVariables = class;
     24  TFunctions = class;
     25  TExpressions = class;
    2926  TExpression = class;
    3027  TFunction = class;
     
    4037
    4138  TContext = class
    42 
    43   end;
    44 
    45   TCommandList = class;
     39  end;
     40
     41  TCommands = class;
    4642
    4743  TCommand = class
     
    5753  end;
    5854
    59   // TListExpression = TGObjectList<Integer, TExpression>
    60   TListExpression = class(TListObject);
     55  { TExpressions }
     56
     57  TExpressions = class(TObjectList<TExpression>)
     58    procedure Assign(Source: TExpressions);
     59  end;
    6160
    6261  { TFunctionCall }
     
    6463  TFunctionCall = class(TCommand)
    6564    FunctionRef: TFunction;
    66     ParameterExpression: TListExpression;
     65    ParameterExpression: TExpressions;
    6766    constructor Create;
    6867    destructor Destroy; override;
     
    7069
    7170  TBeginEnd = class(TCommand)
    72     Commands: TCommandList;
     71    Commands: TCommands;
    7372    CommonBlock: TCommonBlock;
    7473    procedure Clear;
     
    9089
    9190  TRepeatUntil = class(TCommand)
    92     Block: TCommandList;
     91    Block: TCommands;
    9392    Condition: TExpression;
    9493  end;
     
    120119  end;
    121120
    122   // TListCaseOfEndBranche = TGObjectList<Integer, TCaseOfEndBranche>
    123   TListCaseOfEndBranche = class(TListObject);
     121  TListCaseOfEndBranche = class(TObjectList<TCaseOfEndBranche>);
    124122
    125123  TCaseOfEnd = class(TCommand)
     
    132130
    133131  TTryFinally = class(TCommand)
    134     Block: TCommandList;
    135     FinallyBlock: TCommandList;
     132    Block: TCommands;
     133    FinallyBlock: TCommands;
    136134  end;
    137135
    138136  TTryExcept = class(TCommand)
    139     Block: TCommandList;
    140     ExceptBlock: TCommandList;
    141   end;
    142 
    143   // TCommandList = TGObjectList<Integer, TCommand>
    144   TCommandList = class(TListObject);
     137    Block: TCommands;
     138    ExceptBlock: TCommands;
     139  end;
     140
     141  TCommands = class(TObjectList<TCommand>);
    145142
    146143  TCommonBlockSection = (cbsVariable, cbsType, cbsConstant);
     
    150147    Parent: TCommonBlock;
    151148    ParentModule: TSourceModule;
    152     Constants: TConstantList;
    153     Types: TTypeList;
    154     Variables: TVariableList;
    155     Functions: TFunctionList;
    156     Order: TListObject;
     149    Constants: TConstants;
     150    Types: TTypes;
     151    Variables: TVariables;
     152    Functions: TFunctions;
     153    Order: TObjectList<TObject>;
    157154    Code: TBeginEnd;
    158155    constructor Create; virtual;
     
    166163    ForwardDeclared: Boolean;
    167164    Internal: Boolean;
    168     Parent: TTypeList;
     165    Parent: TTypes;
    169166    Name: string;
    170167    Size: Integer;
     
    172169    Exported: Boolean;
    173170    Visibility: TTypeVisibility;
    174     Parameters: TTypeList;
     171    Parameters: TTypes;
    175172    procedure Assign(Source: TType);
    176173    constructor Create;
     
    178175  end;
    179176
    180   // TListType = TGObjectList<Integer, TType>
    181   TListType = class(TListObject);
    182 
    183   TTypeList = class(TListType)
     177  { TTypes }
     178
     179  TTypes = class(TObjectList<TType>)
    184180    Parent: TCommonBlock;
    185181    function Search(Name: string; Exported: Boolean = False): TType;
    186182    destructor Destroy; override;
     183    function AddNew: TType;
    187184  end;
    188185
     
    214211  end;
    215212
    216   // TListEnumItem = TGObjectList<Integer, TEnumItem>
    217   TListEnumItem = class(TListObject);
     213  TEnumItems = class(TObjectList<TEnumItem>);
    218214
    219215  TTypeEnumeration = class(TType)
    220     Items: TListEnumItem;
     216    Items: TEnumItems;
    221217    constructor Create;
    222218    destructor Destroy; override;
     
    239235  end;
    240236
    241   // TListConstant = TGObjectList<Integer, TConstant>
    242   TListConstant = class(TListObject);
    243 
    244   TConstantList = class(TListConstant)
     237  TConstants = class(TObjectList<TConstant>)
    245238    Parent: TCommonBlock;
    246239    function Search(Name: string): TConstant;
     
    256249  end;
    257250
    258   // TListVariable = TGObjectList<Integer, TVariable>
    259   TListVariable = class(TListObject);
    260 
    261   TVariableList = class(TListVariable)
     251  TVariables = class(TObjectList<TVariable>)
    262252    Parent: TCommonBlock;
    263253    function Search(Name: string; Exported: Boolean = False): TVariable;
     
    268258  end;
    269259
    270   // TListParameter = TGObjectList<Integer, TParameter>
    271   TListParameter = class(TListObject);
    272 
    273   TParameterList = class(TListParameter)
     260  TParameters = class(TObjectList<TParameter>)
    274261    Parent: TFunction;
    275262    function Search(Name: string): TParameter;
     
    288275    Value: TValue;
    289276    OperatorName: string;
    290     SubItems: TListExpression;
     277    SubItems: TExpressions;
    291278    Associated: Boolean;
    292279    Braces: Boolean;
     
    302289    Internal: Boolean;
    303290    FunctionType: TFunctionType;
    304     Parameters: TParameterList;
     291    Parameters: TParameters;
    305292    ResultType: TType;
    306293    Exported: Boolean;
     
    310297  end;
    311298
    312   // TListFunction = TGObjectList<Integer, TFunction>
    313   TListFunction = class(TListObject);
    314 
    315   TFunctionList = class(TListFunction)
     299  { TFunctions }
     300
     301  TFunctions = class(TObjectList<TFunction>)
    316302    Parent: TCommonBlock;
    317303    function Search(Name: string; Exported: Boolean = False): TFunction;
    318304    destructor Destroy; override;
     305    function AddNew: TFunction;
    319306  end;
    320307
     
    326313  end;
    327314
    328   // TListUsedModule = TGObjectList<Integer, TUsedModule>
    329   TListUsedModule = class(TListObject);
    330 
    331   TUsedModuleList = class(TListUsedModule)
     315  TUsedModules = class(TObjectList<TUsedModule>)
    332316    ParentModule: TSourceModule;
    333317  end;
     
    340324    Name: string;
    341325    TargetFile: string;
    342     UsedModules: TUsedModuleList;
     326    UsedModules: TUsedModules;
    343327    Body: TCommonBlock;
    344328    Internal: Boolean;
     
    374358  end;
    375359
    376   // TListModule = TGObjectList<Integer, TModule>
    377   TListModule = class(TListObject);
    378 
    379   { TModuleList }
    380 
    381   TModuleList = class(TListModule)
     360  { TModules }
     361
     362  TModules = class(TObjectList<TSourceModule>)
    382363    function Search(Name: string): TSourceModule;
    383364  end;
     
    387368  TProgram = class(TSource)
    388369    Device: TDevice;
    389     Modules: TModuleList;
     370    Modules: TModules;
    390371    MainModule: TSourceModule;
    391372    procedure Clear;
     
    408389  SAssignmentError = 'Assignment error';
    409390
     391
    410392implementation
    411393
     
    415397begin
    416398  inherited;
    417   Parameters := TParameterList.Create;
     399  Parameters := TParameters.Create;
    418400  Parameters.Parent := Self;
    419401  //ResultType := TType.Create;
     
    422404destructor TFunction.Destroy;
    423405begin
    424   Parameters.Free;
    425 //  ResultType.Free;
     406  FreeAndNil(Parameters);
     407//  FreeAndNil(ResultType);
    426408  inherited;
    427409end;
     
    438420begin
    439421  Device := TDevice.Create;
    440   Modules := TModuleList.Create;
     422  Modules := TModules.Create;
    441423end;
    442424
    443425destructor TProgram.Destroy;
    444426begin
    445   Modules.Free;
    446   Device.Free;
    447 end;
    448 
    449 { TConstant }
    450 
    451 
    452 { TConstantList }
    453 
    454 destructor TConstantList.Destroy;
    455 begin
    456   inherited;
    457 end;
    458 
    459 function TConstantList.Search(Name: string): TConstant;
     427  FreeAndNil(Modules);
     428  FreeAndNil(Device);
     429end;
     430
     431{ TConstants }
     432
     433destructor TConstants.Destroy;
     434begin
     435  inherited;
     436end;
     437
     438function TConstants.Search(Name: string): TConstant;
    460439var
    461440  I: Integer;
     
    476455begin
    477456  inherited;
    478   UsedModules := TUsedModuleList.Create;
     457  UsedModules := TUsedModules.Create;
    479458  UsedModules.ParentModule := Self;
    480459  Body := TCommonBlock.Create;
     
    484463destructor TSourceModule.Destroy;
    485464begin
    486   Body.Free;
    487   UsedModules.Free;
     465  FreeAndNil(Body);
     466  FreeAndNil(UsedModules);
    488467  inherited;
    489468end;
     
    504483constructor TCommonBlock.Create;
    505484begin
    506   Constants := TConstantList.Create;
     485  Constants := TConstants.Create;
    507486  Constants.Parent := Self;
    508   Types := TTypeList.Create;
     487  Types := TTypes.Create;
    509488  Types.Parent := Self;
    510   Variables := TVariableList.Create;
     489  Variables := TVariables.Create;
    511490  Variables.Parent := Self;
    512   Functions := TFunctionList.Create;
     491  Functions := TFunctions.Create;
    513492  Functions.Parent := Self;
    514493  Code := TBeginEnd.Create;
    515494  Code.Parent := Self;
    516495  Code.CommonBlock := Self;
    517   Order := TListObject.Create;
     496  Order := TObjectList<TObject>.Create;
    518497  Order.OwnsObjects := False;
    519498end;
     
    521500destructor TCommonBlock.Destroy;
    522501begin
    523   Constants.Free;
    524   Types.Free;
    525   Variables.Free;
    526   Functions.Free;
    527   Code.Free;
    528   Order.Free;
    529   inherited;
    530 end;
    531 
    532 { TTypeList }
    533 
    534 destructor TTypeList.Destroy;
    535 begin
    536   inherited;
    537 end;
    538 
    539 function TTypeList.Search(Name: string; Exported: Boolean = False): TType;
     502  FreeAndNil(Constants);
     503  FreeAndNil(Types);
     504  FreeAndNil(Variables);
     505  FreeAndNil(Functions);
     506  FreeAndNil(Code);
     507  FreeAndNil(Order);
     508  inherited;
     509end;
     510
     511{ TTypes }
     512
     513destructor TTypes.Destroy;
     514begin
     515  inherited;
     516end;
     517
     518function TTypes.AddNew: TType;
     519begin
     520  Result := TType.Create;
     521  Add(Result);
     522end;
     523
     524function TTypes.Search(Name: string; Exported: Boolean = False): TType;
    540525var
    541526  I: Integer;
     
    557542end;
    558543
    559 { TVariableList }
    560 
    561 destructor TVariableList.Destroy;
    562 begin
    563   inherited;
    564 end;
    565 
    566 function TVariableList.Search(Name: string; Exported: Boolean = False): TVariable;
     544{ TVariables }
     545
     546destructor TVariables.Destroy;
     547begin
     548  inherited;
     549end;
     550
     551function TVariables.Search(Name: string; Exported: Boolean = False): TVariable;
    567552var
    568553  I: Integer;
     
    602587end;
    603588
    604 { TFunctionList }
    605 
    606 destructor TFunctionList.Destroy;
    607 begin
    608   inherited;
    609 end;
    610 
    611 function TFunctionList.Search(Name: string; Exported: Boolean): TFunction;
     589{ TFunctions }
     590
     591destructor TFunctions.Destroy;
     592begin
     593  inherited;
     594end;
     595
     596function TFunctions.AddNew: TFunction;
     597begin
     598  Result := TFunction.Create;
     599  Add(Result);
     600end;
     601
     602function TFunctions.Search(Name: string; Exported: Boolean): TFunction;
    612603var
    613604  I: Integer;
     
    631622constructor TExpression.Create;
    632623begin
    633   SubItems := TListExpression.Create;
     624  SubItems := TExpressions.Create;
    634625  SubItems.Count := 2;
    635626  SubItems.OwnsObjects := False;
     
    638629destructor TExpression.Destroy;
    639630begin
    640   SubItems.Free;
     631  FreeAndNil(SubItems);
    641632  inherited;
    642633end;
     
    654645end;
    655646
    656 { TParameterList }
    657 
    658 destructor TParameterList.Destroy;
    659 begin
    660   inherited;
    661 end;
    662 
    663 function TParameterList.Search(Name: string): TParameter;
     647{ TParameters }
     648
     649destructor TParameters.Destroy;
     650begin
     651  inherited;
     652end;
     653
     654function TParameters.Search(Name: string): TParameter;
    664655var
    665656  I: Integer;
     
    675666procedure TBeginEnd.Clear;
    676667begin
    677 
    678668end;
    679669
     
    681671begin
    682672  inherited;
    683   Commands := TCommandList.Create;
     673  Commands := TCommands.Create;
    684674end;
    685675
    686676destructor TBeginEnd.Destroy;
    687677begin
    688   Commands.Free;
     678  FreeAndNil(Commands);
    689679  inherited;
    690680end;
     
    699689destructor TAssignment.Destroy;
    700690begin
    701   Source.Free;
    702   inherited;
     691  FreeAndNil(Source);
     692  inherited;
     693end;
     694
     695{ TExpressions }
     696
     697procedure TExpressions.Assign(Source: TExpressions);
     698var
     699  I: Integer;
     700begin
     701  while Count > Source.Count do Delete(Count - 1);
     702  while Count < Source.Count do Add(TExpression.Create);
     703  for I := 0 to Count - 1 do
     704    Items[I].Assign(Source[I]);
    703705end;
    704706
     
    713715destructor TWhileDo.Destroy;
    714716begin
    715   Condition.Free;
    716   Command.Free;
     717  FreeAndNil(Condition);
     718  FreeAndNil(Command);
    717719  inherited;
    718720end;
     
    728730destructor TCaseOfEnd.Destroy;
    729731begin
    730   Branches.Free;
     732  FreeAndNil(Branches);
    731733  inherited;
    732734end;
     
    741743destructor TIfThenElse.Destroy;
    742744begin
    743   Condition.Free;
    744   inherited Destroy;
     745  FreeAndNil(Condition);
     746  inherited;
    745747end;
    746748
     
    750752begin
    751753  inherited;
    752   ParameterExpression := TListExpression.Create;
     754  ParameterExpression := TExpressions.Create;
    753755end;
    754756
    755757destructor TFunctionCall.Destroy;
    756758begin
    757   ParameterExpression.Free;
    758   inherited Destroy;
     759  FreeAndNil(ParameterExpression);
     760  inherited;
    759761end;
    760762
     
    770772destructor TForToDo.Destroy;
    771773begin
    772   Start.Free;
    773   Stop.Free;;
    774   inherited Destroy;
     774  FreeAndNil(Start);
     775  FreeAndNil(Stop);
     776  inherited;
    775777end;
    776778
     
    785787destructor TTypeRecord.Destroy;
    786788begin
    787   CommonBlock.Free;
    788   inherited Destroy;
    789 end;
    790 
    791 { TModuleList }
    792 
    793 function TModuleList.Search(Name: string): TSourceModule;
     789  FreeAndNil(CommonBlock);
     790  inherited;
     791end;
     792
     793{ TModules }
     794
     795function TModules.Search(Name: string): TSourceModule;
    794796var
    795797  I: Integer;
     
    820822function TSourceModule.SearchConstant(Name: string; Outside: Boolean): TConstant;
    821823begin
    822 
    823824end;
    824825
     
    864865destructor TModuleProgram.Destroy;
    865866begin
    866   inherited Destroy;
     867  inherited;
    867868end;
    868869
     
    881882destructor TModuleUnit.Destroy;
    882883begin
    883   InititializeSection.Free;
    884   FinalalizeSection.Free;
    885   inherited Destroy;
     884  FreeAndNil(InititializeSection);
     885  FreeAndNil(FinalalizeSection);
     886  inherited;
    886887end;
    887888
     
    891892begin
    892893  inherited;
    893   Items := TListEnumItem.Create;
     894  Items := TEnumItems.Create;
    894895end;
    895896
    896897destructor TTypeEnumeration.Destroy;
    897898begin
    898   Items.Free;
    899   inherited Destroy;
     899  FreeAndNil(Items);
     900  inherited;
    900901end;
    901902
     
    910911destructor TTypeClass.Destroy;
    911912begin
    912   CommonBlock.Free;
    913   inherited Destroy;
     913  FreeAndNil(CommonBlock);
     914  inherited;
    914915end;
    915916
     
    942943constructor TType.Create;
    943944begin
    944   Parameters := TTypeList.Create;
     945  Parameters := TTypes.Create;
    945946  //Parameters.Parent := Parent.Parent;
    946947end;
     
    948949destructor TType.Destroy;
    949950begin
    950   Parameters.Free;
    951   inherited Destroy;
     951  FreeAndNil(Parameters);
     952  inherited;
    952953end;
    953954
Note: See TracChangeset for help on using the changeset viewer.