Quellcode durchsuchen

pastojs: fixed class-of RTTI

git-svn-id: trunk@39153 -
Mattias Gaertner vor 7 Jahren
Ursprung
Commit
4c525de9fe

+ 17 - 15
packages/pastojs/src/fppas2js.pp

@@ -15984,31 +15984,33 @@ function TPasToJSConverter.IsClassRTTICreatedBefore(aClass: TPasClassType;
 var
   Decls: TPasDeclarations;
   i: Integer;
-  Types: TFPList;
-  T: TPasType;
+  List: TFPList;
   C: TClass;
+  aParent, Decl: TPasElement;
 begin
   Result:=false;
-  if aClass.Parent=nil then exit;
-  if not aClass.Parent.InheritsFrom(TPasDeclarations) then
+  aParent:=aClass.Parent;
+  if aParent<>Before.Parent then
+    exit(true);
+  if not aParent.InheritsFrom(TPasDeclarations) then
     RaiseInconsistency(20170412101457,aClass);
-  Decls:=TPasDeclarations(aClass.Parent);
-  Types:=Decls.Types;
-  for i:=0 to Types.Count-1 do
-    begin
-    T:=TPasType(Types[i]);
-    if T=Before then exit;
-    if T=aClass then exit(true);
-    C:=T.ClassType;
+  Decls:=TPasDeclarations(aParent);
+  List:=Decls.Declarations;
+  for i:=0 to List.Count-1 do
+    begin
+    Decl:=TPasElement(List[i]);
+    if Decl=Before then exit;
+    if Decl=aClass then exit(true);
+    C:=Decl.ClassType;
     if C=TPasClassType then
       begin
-      if TPasClassType(T).IsForward and (T.CustomData is TResolvedReference)
-          and (TResolvedReference(T.CustomData).Declaration=aClass) then
+      if TPasClassType(Decl).IsForward and (Decl.CustomData is TResolvedReference)
+          and (TResolvedReference(Decl.CustomData).Declaration=aClass) then
         exit(true);
       end
     else if C=TPasClassOfType then
       begin
-      if AConText.Resolver.ResolveAliasType(TPasClassOfType(T).DestType)=aClass then
+      if AConText.Resolver.ResolveAliasType(TPasClassOfType(Decl).DestType)=aClass then
         exit(true);
       end;
     end;

+ 21 - 0
packages/pastojs/src/pas2jsfiler.pp

@@ -5341,6 +5341,7 @@ var
   i: Integer;
   Data: TJSONData;
   El: TPasElement;
+  C: TClass;
 begin
   if not ReadArray(Obj,'Declarations',Arr,Section) then exit;
   {$IFDEF VerbosePCUFiler}
@@ -5353,6 +5354,26 @@ begin
       RaiseMsg(20180207182304,Section,IntToStr(i)+' '+GetObjName(Data));
     El:=ReadElement(TJSONObject(Data),Section,aContext);
     Section.Declarations.Add(El);
+    C:=El.ClassType;
+    if C=TPasResString then
+      Section.ResStrings.Add(El)
+    else if C=TPasConst then
+      Section.Consts.Add(El)
+    else if C=TPasClassType then
+      Section.Classes.Add(El)
+    else if C=TPasRecordType then
+      Section.Classes.Add(El)
+    else if C.InheritsFrom(TPasType) then
+      // not TPasClassType, TPasRecordType !
+      Section.Types.Add(El)
+    else if C.InheritsFrom(TPasProcedure) then
+      Section.Functions.Add(El)
+    else if C=TPasVariable then
+      Section.Variables.Add(El)
+    else if C=TPasProperty then
+      Section.Properties.Add(El)
+    else if C=TPasExportSymbol then
+      Section.ExportSymbols.Add(El);
     end;
 end;
 

+ 5 - 0
packages/pastojs/tests/tcfiler.pas

@@ -388,6 +388,7 @@ begin
 
     // convert using the precompiled procs
     RestConverter:=CreateConverter;
+    RestConverter.Options:=Converter.Options;
     RestConverter.OnIsElementUsed:=@OnRestConverterIsElementUsed;
     RestConverter.OnIsTypeInfoUsed:=@OnRestConverterIsTypeInfoUsed;
     try
@@ -1857,11 +1858,13 @@ end;
 
 procedure TTestPrecompile.TestPC_ClassForward;
 begin
+  Converter.Options:=Converter.Options-[coNoTypeInfo];
   StartUnit(false);
   Add([
   'interface',
   'type',
   '  TObject = class end;',
+  '  TFish = class;',
   '  TBird = class;',
   '  TBirdClass = class of TBird;',
   '  TFish = class',
@@ -1870,10 +1873,12 @@ begin
   '  TBird = class',
   '    F: TFish;',
   '  end;',
+  '  TFishClass = class of TFish;',
   'var',
   '  b: tbird;',
   '  f: tfish;',
   '  bc: TBirdClass;',
+  '  fc: TFishClass;',
   'implementation',
   'end.'
   ]);