Browse Source

fcl-passrc: added include file and append specializations at end of declarations in front of unfinished elements

git-svn-id: trunk@45862 -
Mattias Gaertner 5 years ago
parent
commit
dc54c1297a
3 changed files with 49 additions and 15 deletions
  1. 1 0
      .gitattributes
  2. 12 0
      packages/fcl-passrc/src/fcl-passrc.inc
  3. 36 15
      packages/fcl-passrc/src/pasresolver.pp

+ 1 - 0
.gitattributes

@@ -3842,6 +3842,7 @@ packages/fcl-passrc/examples/pasrewrite.pp svneol=native#text/plain
 packages/fcl-passrc/examples/test_parser.pp svneol=native#text/plain
 packages/fcl-passrc/examples/test_parser.pp svneol=native#text/plain
 packages/fcl-passrc/examples/testunit1.pp svneol=native#text/plain
 packages/fcl-passrc/examples/testunit1.pp svneol=native#text/plain
 packages/fcl-passrc/fpmake.pp svneol=native#text/plain
 packages/fcl-passrc/fpmake.pp svneol=native#text/plain
+packages/fcl-passrc/src/fcl-passrc.inc svneol=native#text/plain
 packages/fcl-passrc/src/pasresolveeval.pas svneol=native#text/plain
 packages/fcl-passrc/src/pasresolveeval.pas svneol=native#text/plain
 packages/fcl-passrc/src/pasresolver.pp svneol=native#text/plain
 packages/fcl-passrc/src/pasresolver.pp svneol=native#text/plain
 packages/fcl-passrc/src/passrcutil.pp svneol=native#text/plain
 packages/fcl-passrc/src/passrcutil.pp svneol=native#text/plain

+ 12 - 0
packages/fcl-passrc/src/fcl-passrc.inc

@@ -0,0 +1,12 @@
+{$mode objfpc}{$H+}
+{$inline on}
+
+{$ifdef fpc}
+  {$define UsePChar}
+  {$define HasInt64}
+{$endif}
+
+{$IF FPC_FULLVERSION>30100}
+  {$warn 6058 off} // cannot inline
+{$ENDIF}
+

+ 36 - 15
packages/fcl-passrc/src/pasresolver.pp

@@ -306,13 +306,7 @@ Notes:
 }
 }
 unit PasResolver;
 unit PasResolver;
 
 
-{$mode objfpc}{$H+}
-{$inline on}
-
-{$ifdef fpc}
-  {$define UsePChar}
-  {$define HasInt64}
-{$endif}
+{$i fcl-passrc.inc}
 
 
 {$IFOPT Q+}{$DEFINE OverflowCheckOn}{$ENDIF}
 {$IFOPT Q+}{$DEFINE OverflowCheckOn}{$ENDIF}
 {$IFOPT R+}{$DEFINE RangeCheckOn}{$ENDIF}
 {$IFOPT R+}{$DEFINE RangeCheckOn}{$ENDIF}
@@ -16398,8 +16392,18 @@ var
   procedure InsertBehind(List: TFPList);
   procedure InsertBehind(List: TFPList);
   var
   var
     Last: TPasElement;
     Last: TPasElement;
-    i: Integer;
+    i, LastIndex: Integer;
+    LastScope: TPasGenericScope;
   begin
   begin
+    // insert in front of currently parsed elements
+    // beware: specializing an element can create other specialized elements
+    // add behind last specialized element of this GenericEl
+    // for example: A = class(B<C<D>>)
+    // =>
+    //  D
+    //  C<D>
+    //  B<C<D>>
+    //  A
     Last:=GenericEl;
     Last:=GenericEl;
     if SpecializedItems<>nil then
     if SpecializedItems<>nil then
       begin
       begin
@@ -16407,15 +16411,32 @@ var
       if i>=0 then
       if i>=0 then
         Last:=TPRSpecializedItem(SpecializedItems[i]).SpecializedEl;
         Last:=TPRSpecializedItem(SpecializedItems[i]).SpecializedEl;
       end;
       end;
-    i:=List.IndexOf(Last);
-    if i<0 then
+    LastIndex:=List.IndexOf(Last);
+    if LastIndex<0 then
+      RaiseNotYetImplemented(20200725093218,El);
+    i:=List.Count-1;
+    while i>LastIndex do
       begin
       begin
-      {$IF defined(VerbosePasResolver) or defined(VerbosePas2JS)}
-      writeln('InsertBehind Generic=',GetObjName(GenericEl),' Last=',GetObjName(Last));
-      //for i:=0 to List.Count-1 do writeln('  ',GetObjName(TObject(List[i])));
-      {$ENDIF}
-      i:=List.Count-1;
+      Last:=TPasElement(List[i]);
+      if not (Last is TPasGenericType) then break;
+      if (Last.CustomData<>nil) then
+        begin
+        LastScope:=Last.CustomData as TPasGenericScope;
+        if LastScope.GenericStep>=psgsInterfaceParsed then
+          break;
+        end;
+      // type is still parsed => insert in front
+      dec(i);
       end;
       end;
+
+    //if i<0 then
+    //  begin
+    //  {$IF defined(VerbosePasResolver) or defined(VerbosePas2JS)}
+    //  writeln('InsertBehind Generic=',GetObjName(GenericEl),' Last=',GetObjName(Last));
+    //  //for i:=0 to List.Count-1 do writeln('  ',GetObjName(TObject(List[i])));
+    //  {$ENDIF}
+    //  i:=List.Count-1;
+    //  end;
     List.Insert(i+1,NewEl);
     List.Insert(i+1,NewEl);
   end;
   end;