Ignore:
Timestamp:
Oct 31, 2010, 9:40:18 PM (14 years ago)
Author:
george
Message:
  • Modified: TObjectList replaced by generics templates.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Transpascal/Compiler/USourceCode.pas

    r82 r83  
    22
    33{$MODE Delphi}
     4{$MACRO ON}
    45
    56interface
    67
    78uses
    8   SysUtils, Variants, Classes, Dialogs, ListObject;
     9  SysUtils, Variants, Classes, Dialogs;
    910
    1011type
     
    5556  end;
    5657
     58  // TListExpression = TGObjectList<Integer, TExpression>
     59  {$DEFINE TGObjectListIndex := Integer}
     60  {$DEFINE TGObjectListItem := TExpression}
     61  {$DEFINE TGObjectListList := TObjectListExpression}
     62  {$DEFINE TGObjectList := TListExpression}
     63  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareExpression}
     64  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterExpression}
     65  {$DEFINE INTERFACE}
     66  {$I 'GenericObjectList.inc'}
     67
    5768  { TFunctionCall }
    5869
    5970  TFunctionCall = class(TCommand)
    6071    FunctionRef: TFunction;
    61     ParameterExpression: TListObject; // TListObject<TExpression>
     72    ParameterExpression: TListExpression;
    6273    constructor Create;
    6374    destructor Destroy; override;
     
    115126  end;
    116127
     128  // TListCaseOfEndBranche = TGObjectList<Integer, TCaseOfEndBranche>
     129  {$DEFINE TGObjectListIndex := Integer}
     130  {$DEFINE TGObjectListItem := TCaseOfEndBranche}
     131  {$DEFINE TGObjectListList := TObjectListCaseOfEndBranche}
     132  {$DEFINE TGObjectList := TListCaseOfEndBranche}
     133  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareCaseOfEndBranche}
     134  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterCaseOfEndBranche}
     135  {$DEFINE INTERFACE}
     136  {$I 'GenericObjectList.inc'}
     137
    117138  TCaseOfEnd = class(TCommand)
    118139    Expression: TExpression;
    119     Branches: TListObject; // TListObject<TCaseOfEndBranche>
     140    Branches: TListCaseOfEndBranche;
    120141    ElseCommand: TCommand;
    121142    constructor Create;
     
    133154  end;
    134155
    135   TCommandList = class(TListObject)
    136 
    137   end;
     156  // TCommandList = TGObjectList<Integer, TCommand>
     157  {$DEFINE TGObjectListIndex := Integer}
     158  {$DEFINE TGObjectListItem := TCommand}
     159  {$DEFINE TGObjectListList := TObjectListCommand}
     160  {$DEFINE TGObjectList := TCommandList}
     161  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareCommand}
     162  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterCommand}
     163  {$DEFINE INTERFACE}
     164  {$I 'GenericObjectList.inc'}
    138165
    139166  TCommonBlock = class
     
    161188  end;
    162189
     190  // TListType = TGObjectList<Integer, TType>
     191  {$DEFINE TGObjectListIndex := Integer}
     192  {$DEFINE TGObjectListItem := TType}
     193  {$DEFINE TGObjectListList := TObjectListType}
     194  {$DEFINE TGObjectList := TListType}
     195  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareType}
     196  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterType}
     197  {$DEFINE INTERFACE}
     198  {$I 'GenericObjectList.inc'}
     199
     200  TTypeList = class(TListType)
     201    Parent: TCommonBlock;
     202    function Search(Name: string; Exported: Boolean = False): TType;
     203    destructor Destroy; override;
     204  end;
     205
    163206  TTypeInherited = class(TType)
    164207  end;
     
    188231  end;
    189232
     233  // TListEnumItem = TGObjectList<Integer, TEnumItem>
     234  {$DEFINE TGObjectListIndex := Integer}
     235  {$DEFINE TGObjectListItem := TEnumItem}
     236  {$DEFINE TGObjectListList := TObjectListEnumItem}
     237  {$DEFINE TGObjectList := TListEnumItem}
     238  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareEnumItem}
     239  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterEnumItem}
     240  {$DEFINE INTERFACE}
     241  {$I 'GenericObjectList.inc'}
     242
    190243  TTypeEnumeration = class(TType)
    191     Items: TListObject; // TListObject<TEnumItem>
     244    Items: TListEnumItem;
    192245    constructor Create;
    193246    destructor Destroy; override;
     
    197250
    198251  TTypeClass = class(TType)
    199     Items: TListObject; // TListObject<TType>
    200     constructor Create;
    201     destructor Destroy; override;
    202   end;
    203 
    204   TTypeList = class(TListObject)
    205     Parent: TCommonBlock;
    206     function Search(Name: string; Exported: Boolean = False): TType;
     252    Items: TListType;
     253    constructor Create;
    207254    destructor Destroy; override;
    208255  end;
     
    216263  end;
    217264
    218   TConstantList = class(TListObject)
     265  // TListConstant = TGObjectList<Integer, TConstant>
     266  {$DEFINE TGObjectListIndex := Integer}
     267  {$DEFINE TGObjectListItem := TConstant}
     268  {$DEFINE TGObjectListList := TObjectListConstant}
     269  {$DEFINE TGObjectList := TListConstant}
     270  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareConstant}
     271  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterConstant}
     272  {$DEFINE INTERFACE}
     273  {$I 'GenericObjectList.inc'}
     274
     275  TConstantList = class(TListConstant)
    219276    Parent: TCommonBlock;
    220277    function Search(Name: string): TConstant;
     
    229286  end;
    230287
    231   TVariableList = class(TListObject)
     288  // TListVariable = TGObjectList<Integer, TVariable>
     289  {$DEFINE TGObjectListIndex := Integer}
     290  {$DEFINE TGObjectListItem := TVariable}
     291  {$DEFINE TGObjectListList := TObjectListVariable}
     292  {$DEFINE TGObjectList := TListVariable}
     293  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareVariable}
     294  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterVariable}
     295  {$DEFINE INTERFACE}
     296  {$I 'GenericObjectList.inc'}
     297
     298  TVariableList = class(TListVariable)
    232299    Parent: TCommonBlock;
    233300    function Search(Name: string; Exported: Boolean = False): TVariable;
     
    238305  end;
    239306
    240   TParameterList = class(TListObject)
     307  // TListParameter = TGObjectList<Integer, TParameter>
     308  {$DEFINE TGObjectListIndex := Integer}
     309  {$DEFINE TGObjectListItem := TParameter}
     310  {$DEFINE TGObjectListList := TObjectListParameter}
     311  {$DEFINE TGObjectList := TListParameter}
     312  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareParameter}
     313  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterParameter}
     314  {$DEFINE INTERFACE}
     315  {$I 'GenericObjectList.inc'}
     316
     317  TParameterList = class(TListParameter)
    241318    Parent: TFunction;
    242319    function Search(Name: string): TParameter;
     
    261338  end;
    262339
    263   TExpressionList = class(TListObject)
     340  TExpressionList = class(TListExpression)
    264341    destructor Destroy; override;
    265342  end;
     
    278355  end;
    279356
    280   TFunctionList = class(TListObject)
     357  // TListFunction = TGObjectList<Integer, TFunction>
     358  {$DEFINE TGObjectListIndex := Integer}
     359  {$DEFINE TGObjectListItem := TFunction}
     360  {$DEFINE TGObjectListList := TObjectListFunction}
     361  {$DEFINE TGObjectList := TListFunction}
     362  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareFunction}
     363  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterFunction}
     364  {$DEFINE INTERFACE}
     365  {$I 'GenericObjectList.inc'}
     366
     367  TFunctionList = class(TListFunction)
    281368    Parent: TCommonBlock;
    282369    function Search(Name: string; Exported: Boolean = False): TFunction;
     
    291378  end;
    292379
    293   TUsedModuleList = class(TListObject)
     380  // TListUsedModule = TGObjectList<Integer, TUsedModule>
     381  {$DEFINE TGObjectListIndex := Integer}
     382  {$DEFINE TGObjectListItem := TUsedModule}
     383  {$DEFINE TGObjectListList := TObjectListUsedModule}
     384  {$DEFINE TGObjectList := TListUsedModule}
     385  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareUsedModule}
     386  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterUsedModule}
     387  {$DEFINE INTERFACE}
     388  {$I 'GenericObjectList.inc'}
     389
     390  TUsedModuleList = class(TListUsedModule)
    294391    ParentModule: TModule;
    295392  end;
     
    332429  end;
    333430
     431  // TListModule = TGObjectList<Integer, TModule>
     432  {$DEFINE TGObjectListIndex := Integer}
     433  {$DEFINE TGObjectListItem := TModule}
     434  {$DEFINE TGObjectListList := TObjectListModule}
     435  {$DEFINE TGObjectList := TListModule}
     436  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareModule}
     437  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterModule}
     438  {$DEFINE INTERFACE}
     439  {$I 'GenericObjectList.inc'}
     440
    334441  { TModuleList }
    335442
    336   TModuleList = class(TListObject)
     443  TModuleList = class(TListModule)
    337444    function Search(Name: string): TModule;
    338445  end;
     
    358465implementation
    359466
     467{$DEFINE IMPLEMENTATION_USES}
     468{$I 'GenericObjectList.inc'}
     469
     470// TListExpression = TGObjectList<Integer, TExpression>
     471{$DEFINE TGObjectListIndex := Integer}
     472{$DEFINE TGObjectListItem := TExpression}
     473{$DEFINE TGObjectListList := TObjectListExpression}
     474{$DEFINE TGObjectList := TListExpression}
     475{$DEFINE TGObjectListSortCompare := TObjectListSortCompareExpression}
     476{$DEFINE TGObjectListStringConverter := TObjectListStringConverterExpression}
     477{$DEFINE IMPLEMENTATION}
     478{$I 'GenericObjectList.inc'}
     479
     480// TListCaseOfEndBranche = TGObjectList<Integer, TCaseOfEndBranche>
     481{$DEFINE TGObjectListIndex := Integer}
     482{$DEFINE TGObjectListItem := TCaseOfEndBranche}
     483{$DEFINE TGObjectListList := TObjectListCaseOfEndBranche}
     484{$DEFINE TGObjectList := TListCaseOfEndBranche}
     485{$DEFINE TGObjectListSortCompare := TObjectListSortCompareCaseOfEndBranche}
     486{$DEFINE TGObjectListStringConverter := TObjectListStringConverterCaseOfEndBranche}
     487{$DEFINE IMPLEMENTATION}
     488{$I 'GenericObjectList.inc'}
     489
     490// TCommandList = TGObjectList<Integer, TCommand>
     491{$DEFINE TGObjectListIndex := Integer}
     492{$DEFINE TGObjectListItem := TCommand}
     493{$DEFINE TGObjectListList := TObjectListCommand}
     494{$DEFINE TGObjectList := TCommandList}
     495{$DEFINE TGObjectListSortCompare := TObjectListSortCompareCommand}
     496{$DEFINE TGObjectListStringConverter := TObjectListStringConverterCommand}
     497{$DEFINE IMPLEMENTATION}
     498{$I 'GenericObjectList.inc'}
     499
     500// TListEnumItem = TGObjectList<Integer, TEnumItem>
     501{$DEFINE TGObjectListIndex := Integer}
     502{$DEFINE TGObjectListItem := TEnumItem}
     503{$DEFINE TGObjectListList := TObjectListEnumItem}
     504{$DEFINE TGObjectList := TListEnumItem}
     505{$DEFINE TGObjectListSortCompare := TObjectListSortCompareEnumItem}
     506{$DEFINE TGObjectListStringConverter := TObjectListStringConverterEnumItem}
     507{$DEFINE IMPLEMENTATION}
     508{$I 'GenericObjectList.inc'}
     509
     510// TListType = TGObjectList<Integer, TType>
     511{$DEFINE TGObjectListIndex := Integer}
     512{$DEFINE TGObjectListItem := TType}
     513{$DEFINE TGObjectListList := TObjectListType}
     514{$DEFINE TGObjectList := TListType}
     515{$DEFINE TGObjectListSortCompare := TObjectListSortCompareType}
     516{$DEFINE TGObjectListStringConverter := TObjectListStringConverterType}
     517{$DEFINE IMPLEMENTATION}
     518{$I 'GenericObjectList.inc'}
     519
     520// TListConstant = TGObjectList<Integer, TConstant>
     521{$DEFINE TGObjectListIndex := Integer}
     522{$DEFINE TGObjectListItem := TConstant}
     523{$DEFINE TGObjectListList := TObjectListConstant}
     524{$DEFINE TGObjectList := TListConstant}
     525{$DEFINE TGObjectListSortCompare := TObjectListSortCompareConstant}
     526{$DEFINE TGObjectListStringConverter := TObjectListStringConverterConstant}
     527{$DEFINE IMPLEMENTATION}
     528{$I 'GenericObjectList.inc'}
     529
     530// TListVariable = TGObjectList<Integer, TVariable>
     531{$DEFINE TGObjectListIndex := Integer}
     532{$DEFINE TGObjectListItem := TVariable}
     533{$DEFINE TGObjectListList := TObjectListVariable}
     534{$DEFINE TGObjectList := TListVariable}
     535{$DEFINE TGObjectListSortCompare := TObjectListSortCompareVariable}
     536{$DEFINE TGObjectListStringConverter := TObjectListStringConverterVariable}
     537{$DEFINE IMPLEMENTATION}
     538{$I 'GenericObjectList.inc'}
     539
     540// TListParameter = TGObjectList<Integer, TParameter>
     541{$DEFINE TGObjectListIndex := Integer}
     542{$DEFINE TGObjectListItem := TParameter}
     543{$DEFINE TGObjectListList := TObjectListParameter}
     544{$DEFINE TGObjectList := TListParameter}
     545{$DEFINE TGObjectListSortCompare := TObjectListSortCompareParameter}
     546{$DEFINE TGObjectListStringConverter := TObjectListStringConverterParameter}
     547{$DEFINE IMPLEMENTATION}
     548{$I 'GenericObjectList.inc'}
     549
     550// TListFunction = TGObjectList<Integer, TFunction>
     551{$DEFINE TGObjectListIndex := Integer}
     552{$DEFINE TGObjectListItem := TFunction}
     553{$DEFINE TGObjectListList := TObjectListFunction}
     554{$DEFINE TGObjectList := TListFunction}
     555{$DEFINE TGObjectListSortCompare := TObjectListSortCompareFunction}
     556{$DEFINE TGObjectListStringConverter := TObjectListStringConverterFunction}
     557{$DEFINE IMPLEMENTATION}
     558{$I 'GenericObjectList.inc'}
     559
     560// TListUsedModule = TGObjectList<Integer, TUsedModule>
     561{$DEFINE TGObjectListIndex := Integer}
     562{$DEFINE TGObjectListItem := TUsedModule}
     563{$DEFINE TGObjectListList := TObjectListUsedModule}
     564{$DEFINE TGObjectList := TListUsedModule}
     565{$DEFINE TGObjectListSortCompare := TObjectListSortCompareUsedModule}
     566{$DEFINE TGObjectListStringConverter := TObjectListStringConverterUsedModule}
     567{$DEFINE IMPLEMENTATION}
     568{$I 'GenericObjectList.inc'}
     569
     570// TListModule = TGObjectList<Integer, TModule>
     571{$DEFINE TGObjectListIndex := Integer}
     572{$DEFINE TGObjectListItem := TModule}
     573{$DEFINE TGObjectListList := TObjectListModule}
     574{$DEFINE TGObjectList := TListModule}
     575{$DEFINE TGObjectListSortCompare := TObjectListSortCompareModule}
     576{$DEFINE TGObjectListStringConverter := TObjectListStringConverterModule}
     577{$DEFINE IMPLEMENTATION}
     578{$I 'GenericObjectList.inc'}
     579
    360580{ TFunction }
    361581
     
    404624begin
    405625  I := 0;
    406   while (I < Count) and (LowerCase(TConstant(Items[I]).Name) <> LowerCase(Name)) do Inc(I);
    407   if I < Count then Result := TConstant(Items[I]) else begin
     626  while (I < Count) and (LowerCase(Items[I].Name) <> LowerCase(Name)) do Inc(I);
     627  if I < Count then Result := Items[I] else begin
    408628    if Assigned(Parent.Parent) then Result := Parent.Parent.Constants.Search(Name)
    409629      else begin
     
    482702  // Search in own list
    483703  I := 0;
    484   while (I < Count) and (LowerCase(TType(Items[I]).Name) <> LowerCase(Name)) do Inc(I);
    485   if I < Count then Result := TType(Items[I]) else Result := nil;
     704  while (I < Count) and (LowerCase(Items[I].Name) <> LowerCase(Name)) do Inc(I);
     705  if I < Count then Result := Items[I] else Result := nil;
    486706
    487707  // Search in parent
     
    508728  // Search in own list
    509729  I := 0;
    510   while (I < Count) and (LowerCase(TVariable(Items[I]).Name) <> LowerCase(Name)) do Inc(I);
     730  while (I < Count) and (LowerCase(Items[I].Name) <> LowerCase(Name)) do Inc(I);
    511731  if I < Count then Result := TVariable(Items[I]) else Result := nil;
    512732
     
    553773  // Search in own list
    554774  I := 0;
    555   while (I < Count) and (LowerCase(TFunction(Items[I]).Name) <> LowerCase(Name)) do Inc(I);
    556   if I < Count then Result := TFunction(Items[I]) else Result := nil;
     775  while (I < Count) and (LowerCase(Items[I].Name) <> LowerCase(Name)) do Inc(I);
     776  if I < Count then Result := Items[I] else Result := nil;
    557777
    558778  // Search parent block list
     
    611831begin
    612832  I := 0;
    613   while (I < Count) and (LowerCase(TParameter(Items[I]).Name) <> LowerCase(Name)) do Inc(I);
    614   if I < Count then Result := TParameter(Items[I])
     833  while (I < Count) and (LowerCase(Items[I].Name) <> LowerCase(Name)) do Inc(I);
     834  if I < Count then Result := Items[I]
    615835    else Result := nil;
    616836end;
     
    668888begin
    669889  inherited;
    670   Branches := TListObject.Create
     890  Branches := TListCaseOfEndBranche.Create
    671891end;
    672892
     
    695915begin
    696916  inherited;
    697   ParameterExpression := TListObject.Create;
     917  ParameterExpression := TListExpression.Create;
    698918end;
    699919
     
    741961begin
    742962  I := 0;
    743   while (I < Count) and (LowerCase(TModule(Items[I]).Name) <> LowerCase(Name)) do Inc(I);
    744   if I < Count then Result := TModule(Items[I]) else Result := nil;
     963  while (I < Count) and (LowerCase(Items[I].Name) <> LowerCase(Name)) do Inc(I);
     964  if I < Count then Result := Items[I] else Result := nil;
    745965end;
    746966
     
    756976    I := 0;
    757977    while (I < UsedModules.Count) and (not Assigned(Result)) do begin
    758       Result := TUsedModule(UsedModules[I]).Module.SearchVariable(Name, False);
     978      Result := UsedModules[I].Module.SearchVariable(Name, False);
    759979      Inc(I);
    760980    end;
     
    776996    I := 0;
    777997    while (I < UsedModules.Count) and (not Assigned(Result)) do begin
    778       with TUsedModule(UsedModules[I]) do
     998      with UsedModules[I] do
    779999        if Assigned(Module) then
    7801000        with Module do
     
    7941014    I := 0;
    7951015    while (I < UsedModules.Count) and (not Assigned(Result)) do begin
    796     if Assigned(TUsedModule(UsedModules[I]).Module) then
    797       Result := TUsedModule(UsedModules[I]).Module.SearchFunction(Name, False);
     1016    if Assigned(UsedModules[I].Module) then
     1017      Result := UsedModules[I].Module.SearchFunction(Name, False);
    7981018      Inc(I);
    7991019    end;
     
    8291049begin
    8301050  inherited;
    831   Items := TListObject.Create;
     1051  Items := TListEnumItem.Create;
    8321052end;
    8331053
     
    8421062constructor TTypeClass.Create;
    8431063begin
    844   Items := TListObject.Create;
     1064  Items := TListType.Create;
    8451065end;
    8461066
Note: See TracChangeset for help on using the changeset viewer.