Browse Source

pastojs: filer: do not write procedure local identifier scope list

git-svn-id: trunk@38573 -
Mattias Gaertner 7 years ago
parent
commit
0f758b78b9

+ 22 - 15
packages/pastojs/src/pas2jscompiler.pp

@@ -1149,21 +1149,24 @@ begin
       Log.LogPlain(PasModule.GetDeclaration(true));
     end;
 
-    // analyze
-    aPrecompileFormat:=Compiler.FileCache.PrecompileFormat;
-    if aPrecompileFormat<>nil then
-      UseAnalyzer.Options:=UseAnalyzer.Options+[paoImplReferences];
+    if PCUReader=nil then
+      begin
+      // analyze module
+      aPrecompileFormat:=Compiler.FileCache.PrecompileFormat;
+      if aPrecompileFormat<>nil then
+        UseAnalyzer.Options:=UseAnalyzer.Options+[paoImplReferences];
 
-    {$IFDEF VerboseUnitQueue}
-    writeln('TPas2jsCompilerFile.ReaderFinished analyzing ',PasFilename,' ...');
-    {$ENDIF}
-    UseAnalyzer.AnalyzeModule(FPasModule);
-    {$IF defined(VerboseUnitQueue) or defined(VerbosePCUFiler)}
-    writeln('TPas2jsCompilerFile.ReaderFinished analyzed ',PasFilename,' ScopeModule=',GetObjName(UseAnalyzer.ScopeModule));
-    {$ENDIF}
+      {$IFDEF VerboseUnitQueue}
+      writeln('TPas2jsCompilerFile.ReaderFinished analyzing ',PasFilename,' ...');
+      {$ENDIF}
+      UseAnalyzer.AnalyzeModule(FPasModule);
+      {$IF defined(VerboseUnitQueue) or defined(VerbosePCUFiler)}
+      writeln('TPas2jsCompilerFile.ReaderFinished analyzed ',PasFilename,' ScopeModule=',GetObjName(UseAnalyzer.ScopeModule));
+      {$ENDIF}
 
-    if (aPrecompileFormat<>nil) and (PCUReader=nil) then
-      WritePCU;
+      if (aPrecompileFormat<>nil) and (PCUReader=nil) then
+        WritePCU;
+      end;
   except
     on E: ECompilerTerminate do
       raise;
@@ -1374,7 +1377,11 @@ procedure TPas2jsCompilerFile.CreateJS;
 begin
   try
     // show hints only for units that are actually converted
-    UseAnalyzer.EmitModuleHints(PasModule);
+    if PCUReader=nil then
+      begin
+      //writeln('TPas2jsCompilerFile.CreateJS ',PasFilename);
+      UseAnalyzer.EmitModuleHints(PasModule);
+      end;
 
     // convert
     CreateConverter;
@@ -3934,7 +3941,7 @@ begin
   if FHasShownLogo then exit;
   FHasShownLogo:=true;
   WriteVersionLine;
-  Log.LogPlain('Copyright (c) 2017 Mattias Gaertner and others');
+  Log.LogPlain('Copyright (c) 2018 Mattias Gaertner and others');
 end;
 
 procedure TPas2jsCompiler.WriteVersionLine;

+ 49 - 5
packages/pastojs/src/pas2jsfiler.pp

@@ -1918,6 +1918,7 @@ begin
     exit;
   // Element was not yet written -> add a pending item to the queue
   Item:=TPCUWriterPendingElRefArray.Create;
+  Item.ErrorEl:=El;
   Item.Arr:=Arr;
   Item.Index:=Arr.Count-1;
   Ref.AddPending(Item);
@@ -1944,6 +1945,7 @@ begin
     begin
     // Element was not yet written -> add a pending item to the queue
     Item:=TPCUWriterPendingElRefObj.Create;
+    Item.ErrorEl:=El;
     Item.Obj:=Obj;
     Item.PropName:=PropName;
     Ref.AddPending(Item);
@@ -2213,6 +2215,8 @@ procedure TPCUWriter.WriteModule(Obj: TJSONObject; aModule: TPasModule;
     if Section.Parent<>aModule then
       RaiseMsg(20180205153912,aModule,PropName);
     aContext.Section:=Section; // set Section before calling virtual method
+    aContext.SectionObj:=nil;
+    aContext.IndirectUsesArr:=nil;
     WriteSection(Obj,Section,PropName,aContext);
   end;
 
@@ -2227,8 +2231,35 @@ procedure TPCUWriter.WriteModule(Obj: TJSONObject; aModule: TPasModule;
     WriteScopeReferences(Obj,Scope.References,PropPrefix+'Refs',aContext);
   end;
 
+  procedure RaisePending(Ref: TPCUFilerElementRef);
+  {$IF defined(VerbosePJUFiler) or defined(VerbosePCUFiler) or defined(VerboseUnitQueue)}
+  var
+    PendObj: TPCUWriterPendingElRefObj;
+    PendArr: TPCUWriterPendingElRefArray;
+  {$ENDIF}
+  begin
+    {$IF defined(VerbosePJUFiler) or defined(VerbosePCUFiler) or defined(VerboseUnitQueue)}
+    {AllowWriteln}
+    writeln('TPCUWriter.WriteModule Ref.Element=',GetElementFullPath(Ref.Element),' Pending=',GetObjName(Ref.Pending),' ErrorEl=',GetElementFullPath(Ref.Pending.ErrorEl));
+    if Ref.Pending is TPCUWriterPendingElRefObj then
+      begin
+      PendObj:=TPCUWriterPendingElRefObj(Ref.Pending);
+      writeln('  Obj=',PendObj.Obj<>nil,' PropName=',PendObj.PropName);
+      end
+    else if Ref.Pending is TPCUWriterPendingElRefArray then
+      begin
+      PendArr:=TPCUWriterPendingElRefArray(Ref.Pending);
+      writeln('  Arr=',PendArr.Arr<>nil,' Index=',PendArr.Index);
+      end;
+    {AllowWriteln-}
+    {$ENDIF}
+    RaiseMsg(20180318225558,Ref.Element,GetObjName(Ref.Pending));
+  end;
+
 var
   ModScope: TPas2JSModuleScope;
+  Node: TAVLTreeNode;
+  Ref: TPCUFilerElementRef;
 begin
   FInImplementation:=false;
   WritePasElement(Obj,aModule,aContext);
@@ -2268,6 +2299,16 @@ begin
 
   //writeln('TPCUWriter.WriteModule WriteExternalReferences of implementation ',Resolver.RootElement.Name,' aContext.Section=',GetObjName(aContext.Section));
   WriteExternalReferences(aContext);
+
+  // consistency check
+  Node:=FElementRefs.FindLowest;
+  while Node<>nil do
+    begin
+    Ref:=TPCUFilerElementRef(Node.Data);
+    if Ref.Pending<>nil then
+      RaisePending(Ref);
+    Node:=FElementRefs.FindSuccessor(Node);
+    end;
 end;
 
 procedure TPCUWriter.WritePasScope(Obj: TJSONObject; Scope: TPasScope;
@@ -2429,6 +2470,7 @@ begin
   Obj:=TJSONObject.Create;
   ParentJSON.Add(PropName,Obj);
   aContext.SectionObj:=Obj;
+  aContext.IndirectUsesArr:=nil;
   WritePasElement(Obj,Section,aContext);
 
   Scope:=TPasSectionScope(CheckElScope(Section,20180206121825,TPasSectionScope));
@@ -2497,7 +2539,7 @@ begin
     if aContext.SectionObj<>Obj then
       RaiseMsg(20180318112544,Section);
     {$IFDEF VerbosePJUFiler}
-    //writeln('TPCUWriter.WriteSection WriteExternalReferences of Interface ',Section.FullPath);
+    //writeln('TPCUWriter.WriteSection WriteExternalReferences of Interface ',GetElementFullPath(Section));
     {$ENDIF}
     WriteExternalReferences(aContext);
     end;
@@ -3448,9 +3490,10 @@ end;
 procedure TPCUWriter.WriteProcedureScope(Obj: TJSONObject;
   Scope: TPas2JSProcedureScope; aContext: TPCUWriterContext);
 begin
-  WriteIdentifierScope(Obj,Scope,aContext);
+  // Not needed, contains only local stuff: WriteIdentifierScope(Obj,Scope,aContext);
   if Scope.ResultVarName<>'' then
     Obj.Add('ResultVarName',Scope.ResultVarName);
+
   if Scope.DeclarationProc<>nil then
     RaiseMsg(20180219135933,Scope.Element);
   AddReferenceToObj(Obj,'ImplProc',Scope.ImplProc);
@@ -3624,6 +3667,7 @@ begin
       ParentRef.Obj.Add('El',ParentRef.Elements);
       end;
     ParentRef.Elements.Add(Ref.Obj);
+    //writeln('TPCUWriter.WriteExternalReference ',GetObjName(El),' WriteExtRefSignature...');
     WriteExtRefSignature(Ref,aContext);
     end
   else if (El.ClassType=TPasModule) or (El is TPasUnitModule) then
@@ -3662,7 +3706,7 @@ begin
       continue; // not used, e.g. when a child is written, its parents are
                 // written too, which might still be in the queue
     El:=Ref.Element;
-    //writeln('TPCUWriter.WriteExternalReferences ',GetObjName(El),' ',El.FullPath);
+    //writeln('TPCUWriter.WriteExternalReferences ',GetObjName(El),' ',GetElementFullPath(El));
     {$IF defined(VerbosePJUFiler) or defined(VerbosePCUFiler) or defined(VerboseUnitQueue)}
     if El.CustomData is TResElDataBuiltInSymbol then
       RaiseMsg(20180314120554,El);
@@ -5624,7 +5668,7 @@ begin
 
   if not ReadBoolean(Obj,'Eval',NeedEvalValue,Expr) then
     NeedEvalValue:=GetDefaultExprHasEvalValue(Expr);
-  //writeln('TPCUReader.ReadExprCustomData ',Expr.FullPath,' ',GetObjName(Expr),' NeedEvalValue=',NeedEvalValue);
+  //writeln('TPCUReader.ReadExprCustomData ',GetElementFullPath(Expr),' ',GetObjName(Expr),' NeedEvalValue=',NeedEvalValue);
   if NeedEvalValue then
     begin
     Value:=Resolver.Eval(Expr,[refAutoConst]);
@@ -6731,7 +6775,7 @@ begin
   Scope.Flags:=ReadProcScopeFlags(Obj,Proc,'SFlags',[]);
   Scope.BoolSwitches:=ReadBoolSwitches(Obj,Proc,'BoolSwitches',aContext.BoolSwitches);
 
-  ReadIdentifierScope(Obj,Scope,aContext);
+  //ReadIdentifierScope(Obj,Scope,aContext);
 end;
 
 procedure TPCUReader.ReadProcScopeReferences(Obj: TJSONObject;

+ 2 - 1
packages/pastojs/tests/tcfiler.pas

@@ -742,7 +742,7 @@ begin
     if Orig.BoolSwitches<>Rest.BoolSwitches then
       Fail(Path+'.BoolSwitches');
 
-    CheckRestoredIdentifierScope(Path,Orig,Rest);
+    //CheckRestoredIdentifierScope(Path,Orig,Rest);
     end
   else
     begin
@@ -1418,6 +1418,7 @@ begin
   RestScope:=Rest.CustomData as TPas2JSProcedureScope;
   CheckRestoredReference(Path+'.CustomData[TPas2JSProcedureScope].DeclarationProc',
     OrigScope.DeclarationProc,RestScope.DeclarationProc);
+  AssertEquals(Path+'.CustomData[TPas2JSProcedureScope].ResultVarName',OrigScope.ResultVarName,RestScope.ResultVarName);
   if RestScope.DeclarationProc=nil then
     begin
     CheckRestoredElement(Path+'.ProcType',Orig.ProcType,Rest.ProcType);

+ 1 - 1
packages/pastojs/tests/tcprecompile.pas

@@ -127,7 +127,7 @@ end;
 constructor TCustomTestCLI_Precompile.Create;
 begin
   inherited Create;
-  FFormat:=PrecompileFormats.FindExt('pcu');
+  FFormat:=PrecompileFormats[0];
 end;
 
 { TTestCLI_Precompile }