Browse Source

pastojs: fixed compile

git-svn-id: trunk@47136 -
Mattias Gaertner 4 years ago
parent
commit
764b035c23
2 changed files with 51 additions and 20 deletions
  1. 3 3
      packages/pastojs/src/pas2jsfiler.pp
  2. 48 17
      packages/pastojs/tests/tcfiler.pas

+ 3 - 3
packages/pastojs/src/pas2jsfiler.pp

@@ -5738,15 +5738,15 @@ end;
 function TPCUReader.AddElReference(Id: integer; ErrorEl: TPasElement;
 function TPCUReader.AddElReference(Id: integer; ErrorEl: TPasElement;
   El: TPasElement): TPCUFilerElementRef;
   El: TPasElement): TPCUFilerElementRef;
 var
 var
+  {$IF defined(VerbosePCUFiler) or defined(memcheck)}
+  Node: TAVLTreeNode;
+  {$ENDIF}
   Ref: TPCUFilerElementRef;
   Ref: TPCUFilerElementRef;
   RefItem: TPCUFilerPendingElRef;
   RefItem: TPCUFilerPendingElRef;
   PendingElRef: TPCUReaderPendingElRef;
   PendingElRef: TPCUReaderPendingElRef;
   PendingElListRef: TPCUReaderPendingElListRef;
   PendingElListRef: TPCUReaderPendingElListRef;
   PendingElArrRef: TPCUReaderPendingElArrRef;
   PendingElArrRef: TPCUReaderPendingElArrRef;
-  {$IF defined(VerbosePCUFiler) or defined(memcheck)}
-  Node: TAVLTreeNode;
   PendingElScopeRef: TPCUReaderPendingElScopeRef;
   PendingElScopeRef: TPCUReaderPendingElScopeRef;
-  {$ENDIF}
 begin
 begin
   if Id<=0 then
   if Id<=0 then
     RaiseMsg(20180207151233,ErrorEl);
     RaiseMsg(20180207151233,ErrorEl);

+ 48 - 17
packages/pastojs/tests/tcfiler.pas

@@ -253,7 +253,7 @@ var
   Ref1: TPasScopeReference absolute Item1;
   Ref1: TPasScopeReference absolute Item1;
   Ref2: TPasScopeReference absolute Item2;
   Ref2: TPasScopeReference absolute Item2;
 begin
 begin
-  Result:=CompareText(Ref1.Element.Name,Ref2.Element.Name);
+  Result:=CompareText(GetObjPath(Ref1.Element),GetObjPath(Ref2.Element));
   if Result<>0 then exit;
   if Result<>0 then exit;
   Result:=ComparePointer(Ref1.Element,Ref2.Element);
   Result:=ComparePointer(Ref1.Element,Ref2.Element);
 end;
 end;
@@ -644,11 +644,31 @@ procedure TCustomTestPrecompile.CheckRestoredDeclarations(const Path: string;
         and (TPasGenericScope(El.CustomData).SpecializedFromItem<>nil);
         and (TPasGenericScope(El.CustomData).SpecializedFromItem<>nil);
   end;
   end;
 
 
+  function GetSubPath(const Path: string; OrigIndex: integer; OrigDecl: TPasElement): string;
+  begin
+    Result:=Path+'['+IntToStr(OrigIndex)+']';
+    if OrigDecl.Name<>'' then
+      Result:=Result+'"'+OrigDecl.Name+'"'
+    else
+      Result:=Result+'?noname?';
+  end;
+
+{  procedure WriteList;
+  var
+    i: Integer;
+  begin
+    writeln('CheckRestoredDeclarations.WriteList');
+    for i:=0 to Orig.Declarations.Count-1 do
+      if i<Rest.Declarations.Count then
+        writeln('  ',i,' Orig=',TPasElement(Orig.Declarations[i]).Name,' Rest=',TPasElement(Rest.Declarations[i]).Name);
+  end;}
+
 var
 var
   OrigIndex, RestIndex: Integer;
   OrigIndex, RestIndex: Integer;
   OrigDecl, RestDecl: TPasElement;
   OrigDecl, RestDecl: TPasElement;
   SubPath: String;
   SubPath: String;
 begin
 begin
+  //WriteList;
   // check non specializations
   // check non specializations
   RestIndex:=0;
   RestIndex:=0;
   for OrigIndex:=0 to Orig.Declarations.Count-1 do
   for OrigIndex:=0 to Orig.Declarations.Count-1 do
@@ -656,12 +676,8 @@ begin
     OrigDecl:=TPasElement(Orig.Declarations[OrigIndex]);
     OrigDecl:=TPasElement(Orig.Declarations[OrigIndex]);
     if IsSpecialization(OrigDecl) then
     if IsSpecialization(OrigDecl) then
       continue;
       continue;
-    SubPath:=Path+'['+IntToStr(OrigIndex)+']';
-    if OrigDecl.Name<>'' then
-      SubPath:=SubPath+'"'+OrigDecl.Name+'"'
-    else
-      SubPath:=SubPath+'?noname?';
-    // skip to next non specializations in restored declarations
+    SubPath:=GetSubPath(Path,OrigIndex,OrigDecl);
+    // skip to next non specialization in restored declarations
     while RestIndex<Rest.Declarations.Count do
     while RestIndex<Rest.Declarations.Count do
       begin
       begin
       RestDecl:=TPasElement(Rest.Declarations[RestIndex]);
       RestDecl:=TPasElement(Rest.Declarations[RestIndex]);
@@ -682,11 +698,7 @@ begin
     OrigDecl:=TPasElement(Orig.Declarations[OrigIndex]);
     OrigDecl:=TPasElement(Orig.Declarations[OrigIndex]);
     if not IsSpecialization(OrigDecl) then
     if not IsSpecialization(OrigDecl) then
       continue;
       continue;
-    SubPath:=Path+'['+IntToStr(OrigIndex)+']';
-    if OrigDecl.Name<>'' then
-      SubPath:=SubPath+'"'+OrigDecl.Name+'"'
-    else
-      SubPath:=SubPath+'?noname?';
+    SubPath:=GetSubPath(Path,OrigIndex,OrigDecl);
     // search specialization with same name
     // search specialization with same name
     RestIndex:=0;
     RestIndex:=0;
     repeat
     repeat
@@ -699,14 +711,33 @@ begin
     until false;
     until false;
 
 
     if (OrigIndex<Rest.Declarations.Count) and (OrigIndex<>RestIndex) then
     if (OrigIndex<Rest.Declarations.Count) and (OrigIndex<>RestIndex) then
+      begin
       // move restored element to original place to generate the same JS
       // move restored element to original place to generate the same JS
-      Rest.Declarations.Move(RestIndex,OrigIndex);
+      //writeln('TCustomTestPrecompile.CheckRestoredDeclarations Orig[',OrigIndex,']=',GetObjName(OrigDecl),' Rest[',RestIndex,']=',GetObjName(RestDecl));
+      if RestIndex>OrigIndex then
+        Rest.Declarations.Move(RestIndex,OrigIndex)
+      else
+        Rest.Declarations.Exchange(RestIndex,OrigIndex);
+      //writeln('TCustomTestPrecompile.CheckRestoredDeclarations RestIndex=',RestIndex,' ->',OrigIndex);
+      //WriteList;
+      end;
 
 
     // check
     // check
     CheckRestoredElement(SubPath,OrigDecl,RestDecl,Flags);
     CheckRestoredElement(SubPath,OrigDecl,RestDecl,Flags);
     end;
     end;
-
   AssertEquals(Path+'.Declarations.Count',Orig.Declarations.Count,Rest.Declarations.Count);
   AssertEquals(Path+'.Declarations.Count',Orig.Declarations.Count,Rest.Declarations.Count);
+
+  //WriteList;
+  for OrigIndex:=0 to Orig.Declarations.Count-1 do
+    begin
+    OrigDecl:=TPasElement(Orig.Declarations[OrigIndex]);
+    RestDecl:=TPasElement(Rest.Declarations[OrigIndex]);
+    if OrigDecl.Name<>RestDecl.Name then
+      begin
+      SubPath:=GetSubPath(Path,OrigIndex,OrigDecl);
+      AssertEquals(SubPath+'.Name',GetObjPath(OrigDecl),GetObjPath(RestDecl));
+      end;
+    end;
 end;
 end;
 
 
 procedure TCustomTestPrecompile.CheckRestoredSection(const Path: string; Orig,
 procedure TCustomTestPrecompile.CheckRestoredSection(const Path: string; Orig,
@@ -3241,9 +3272,9 @@ begin
   '  TBird<T> = class',
   '  TBird<T> = class',
   '    a: T;',
   '    a: T;',
   '  end;',
   '  end;',
-  //'  TDoubleBird = TBIrd<double>;',
-  //'var',
-  //'  db: TDoubleBird;',
+  '  TDoubleBird = TBIrd<double>;',
+  'var',
+  '  db: TDoubleBird;',
   'procedure Fly;',
   'procedure Fly;',
   'implementation',
   'implementation',
   'type',
   'type',