Browse Source

fcl-passrc: resolver: started hub for shared values

git-svn-id: trunk@46451 -
Mattias Gaertner 5 years ago
parent
commit
db49df38bc
2 changed files with 42 additions and 4 deletions
  1. 37 4
      packages/fcl-passrc/src/pasresolver.pp
  2. 5 0
      packages/fcl-passrc/tests/tcresolver.pas

+ 37 - 4
packages/fcl-passrc/src/pasresolver.pp

@@ -1423,10 +1423,21 @@ type
     //ToDo: proStaticArrayConcat, // concat works with static arrays, returning a dynamic array
     //ToDo: proStaticArrayConcat, // concat works with static arrays, returning a dynamic array
     proProcTypeWithoutIsNested, // proc types can use nested procs without 'is nested'
     proProcTypeWithoutIsNested, // proc types can use nested procs without 'is nested'
     proMethodAddrAsPointer,  // can assign @method to a pointer
     proMethodAddrAsPointer,  // can assign @method to a pointer
-    proSafecallAllowsDefault // allow assigning a default calling convetnion to a SafeCall proc
+    proSafecallAllowsDefault // allow assigning a default calling convention to a SafeCall proc
     );
     );
   TPasResolverOptions = set of TPasResolverOption;
   TPasResolverOptions = set of TPasResolverOption;
 
 
+  { TPasResolverHub }
+
+  TPasResolverHub = class
+  private
+    FOwner: TObject;
+  public
+    constructor Create(TheOwner: TObject);
+    property Owner: TObject read FOwner;
+  end;
+  TPasResolverHubClass = class of TPasResolverHub;
+
   TPasResolverStep = (
   TPasResolverStep = (
     prsInit,
     prsInit,
     prsParsing,
     prsParsing,
@@ -1480,6 +1491,7 @@ type
     FDefaultScope: TPasDefaultScope;
     FDefaultScope: TPasDefaultScope;
     FDynArrayMaxIndex: TMaxPrecInt;
     FDynArrayMaxIndex: TMaxPrecInt;
     FDynArrayMinIndex: TMaxPrecInt;
     FDynArrayMinIndex: TMaxPrecInt;
+    FHub: TPasResolverHub;
     FLastCreatedData: array[TResolveDataListKind] of TResolveData;
     FLastCreatedData: array[TResolveDataListKind] of TResolveData;
     FLastElement: TPasElement;
     FLastElement: TPasElement;
     FLastMsg: string;
     FLastMsg: string;
@@ -2363,10 +2375,12 @@ type
     function FindLocalBuiltInSymbol(El: TPasElement): TPasElement; virtual;
     function FindLocalBuiltInSymbol(El: TPasElement): TPasElement; virtual;
     function GetFirstSection(WithUnitImpl: boolean): TPasSection;
     function GetFirstSection(WithUnitImpl: boolean): TPasSection;
     function GetLastSection: TPasSection;
     function GetLastSection: TPasSection;
+    function GetParentSection(El: TPasElement): TPasSection;
     function FindUsedUnitInSection(aMod: TPasModule; Section: TPasSection): TPasUsesUnit;
     function FindUsedUnitInSection(aMod: TPasModule; Section: TPasSection): TPasUsesUnit;
     function GetShiftAndMaskForLoHiFunc(BaseType: TResolverBaseType;
     function GetShiftAndMaskForLoHiFunc(BaseType: TResolverBaseType;
       isLoFunc: Boolean; out Mask: LongWord): Integer;
       isLoFunc: Boolean; out Mask: LongWord): Integer;
   public
   public
+    property Hub: TPasResolverHub read FHub write FHub;
     // options
     // options
     property Options: TPasResolverOptions read FOptions write FOptions;
     property Options: TPasResolverOptions read FOptions write FOptions;
     property AnonymousElTypePostfix: String read FAnonymousElTypePostfix
     property AnonymousElTypePostfix: String read FAnonymousElTypePostfix
@@ -2381,15 +2395,15 @@ type
     property ExprEvaluator: TResExprEvaluator read fExprEvaluator;
     property ExprEvaluator: TResExprEvaluator read fExprEvaluator;
     property DynArrayMinIndex: TMaxPrecInt read FDynArrayMinIndex write FDynArrayMinIndex;
     property DynArrayMinIndex: TMaxPrecInt read FDynArrayMinIndex write FDynArrayMinIndex;
     property DynArrayMaxIndex: TMaxPrecInt read FDynArrayMaxIndex write FDynArrayMaxIndex;
     property DynArrayMaxIndex: TMaxPrecInt read FDynArrayMaxIndex write FDynArrayMaxIndex;
+    property StoreSrcColumns: boolean read FStoreSrcColumns write FStoreSrcColumns; {
+       If true Line and Column is mangled together in TPasElement.SourceLineNumber.
+       Use method UnmangleSourceLineNumber to extract. }
     // parsed values
     // parsed values
     property DefaultNameSpace: String read FDefaultNameSpace;
     property DefaultNameSpace: String read FDefaultNameSpace;
     property RootElement: TPasModule read FRootElement write SetRootElement;
     property RootElement: TPasModule read FRootElement write SetRootElement;
     property Step: TPasResolverStep read FStep;
     property Step: TPasResolverStep read FStep;
     property ActiveHelpers: TPRHelperEntryArray read FActiveHelpers;
     property ActiveHelpers: TPRHelperEntryArray read FActiveHelpers;
     // scopes
     // scopes
-    property StoreSrcColumns: boolean read FStoreSrcColumns write FStoreSrcColumns; {
-       If true Line and Column is mangled together in TPasElement.SourceLineNumber.
-       Use method UnmangleSourceLineNumber to extract. }
     property Scopes[Index: integer]: TPasScope read GetScopes;
     property Scopes[Index: integer]: TPasScope read GetScopes;
     property ScopeCount: integer read FScopeCount;
     property ScopeCount: integer read FScopeCount;
     property TopScope: TPasScope read FTopScope;
     property TopScope: TPasScope read FTopScope;
@@ -3063,6 +3077,13 @@ begin
   str(a,Result);
   str(a,Result);
 end;
 end;
 
 
+{ TPasResolverHub }
+
+constructor TPasResolverHub.Create(TheOwner: TObject);
+begin
+  FOwner:=TheOwner;
+end;
+
 { TPRSpecializedItem }
 { TPRSpecializedItem }
 
 
 destructor TPRSpecializedItem.Destroy;
 destructor TPRSpecializedItem.Destroy;
@@ -11780,6 +11801,8 @@ var
   C: TClass;
   C: TClass;
   ModScope: TPasModuleScope;
   ModScope: TPasModuleScope;
 begin
 begin
+  if Hub=nil then
+    RaiseNotYetImplemented(20200815182122,El);
   if TopScope<>DefaultScope then
   if TopScope<>DefaultScope then
     RaiseInvalidScopeForElement(20160922163504,El);
     RaiseInvalidScopeForElement(20160922163504,El);
   ModScope:=TPasModuleScope(PushScope(El,FScopeClass_Module));
   ModScope:=TPasModuleScope(PushScope(El,FScopeClass_Module));
@@ -29229,6 +29252,16 @@ begin
     Result:=Module.InterfaceSection;
     Result:=Module.InterfaceSection;
 end;
 end;
 
 
+function TPasResolver.GetParentSection(El: TPasElement): TPasSection;
+begin
+  while El<>nil do
+    begin
+    if El is TPasSection then exit(TPasSection(El));
+    El:=El.Parent;
+    end;
+  Result:=nil;
+end;
+
 function TPasResolver.FindUsedUnitInSection(aMod: TPasModule;
 function TPasResolver.FindUsedUnitInSection(aMod: TPasModule;
   Section: TPasSection): TPasUsesUnit;
   Section: TPasSection): TPasUsesUnit;
 var
 var

+ 5 - 0
packages/fcl-passrc/tests/tcresolver.pas

@@ -112,6 +112,7 @@ type
 
 
   TCustomTestResolver = Class(TTestParser)
   TCustomTestResolver = Class(TTestParser)
   Private
   Private
+    FHub: TPasResolverHub;
     {$IF defined(VerbosePasResolver) or defined(VerbosePasResolverMem)}
     {$IF defined(VerbosePasResolver) or defined(VerbosePasResolverMem)}
     FStartElementRefCount: int64;
     FStartElementRefCount: int64;
     {$ENDIF}
     {$ENDIF}
@@ -173,6 +174,7 @@ type
     procedure StartUnit(NeedSystemUnit: boolean);
     procedure StartUnit(NeedSystemUnit: boolean);
     property Modules[Index: integer]: TTestEnginePasResolver read GetModules;
     property Modules[Index: integer]: TTestEnginePasResolver read GetModules;
     property ModuleCount: integer read GetModuleCount;
     property ModuleCount: integer read GetModuleCount;
+    property Hub: TPasResolverHub read FHub;
     property ResolverEngine: TTestEnginePasResolver read FResolverEngine;
     property ResolverEngine: TTestEnginePasResolver read FResolverEngine;
     property MsgCount: integer read GetMsgCount;
     property MsgCount: integer read GetMsgCount;
     property Msgs[Index: integer]: TTestResolverMessage read GetMsgs;
     property Msgs[Index: integer]: TTestResolverMessage read GetMsgs;
@@ -1060,6 +1062,7 @@ begin
   FStartElementRefCount:=TPasElement.GlobalRefCount;
   FStartElementRefCount:=TPasElement.GlobalRefCount;
   {$ENDIF}
   {$ENDIF}
   FModules:=TObjectList.Create(true);
   FModules:=TObjectList.Create(true);
+  FHub:=TPasResolverHub.Create(Self);
   inherited SetUp;
   inherited SetUp;
   Parser.Options:=Parser.Options+[po_ResolveStandardTypes];
   Parser.Options:=Parser.Options+[po_ResolveStandardTypes];
   Scanner.OnDirective:=@OnScannerDirective;
   Scanner.OnDirective:=@OnScannerDirective;
@@ -1096,6 +1099,7 @@ begin
     FModules.OwnsObjects:=true;
     FModules.OwnsObjects:=true;
     FreeAndNil(FModules);// free all other modules
     FreeAndNil(FModules);// free all other modules
     end;
     end;
+  FreeAndNil(FHub);
   {$IFDEF VerbosePasResolverMem}
   {$IFDEF VerbosePasResolverMem}
   writeln('TTestResolver.TearDown inherited');
   writeln('TTestResolver.TearDown inherited');
   {$ENDIF}
   {$ENDIF}
@@ -2171,6 +2175,7 @@ begin
   Result.AddObjFPCBuiltInIdentifiers;
   Result.AddObjFPCBuiltInIdentifiers;
   Result.OnFindUnit:=@OnPasResolverFindUnit;
   Result.OnFindUnit:=@OnPasResolverFindUnit;
   Result.OnLog:=@OnPasResolverLog;
   Result.OnLog:=@OnPasResolverLog;
+  Result.Hub:=Hub;
   FModules.Add(Result);
   FModules.Add(Result);
 end;
 end;