Bladeren bron

Get rid of some global variables.

Rika Ichinose 3 jaren geleden
bovenliggende
commit
92771760b7
2 gewijzigde bestanden met toevoegingen van 21 en 31 verwijderingen
  1. 4 12
      compiler/optdfa.pas
  2. 17 19
      compiler/optutils.pas

+ 4 - 12
compiler/optdfa.pas

@@ -675,12 +675,6 @@ unit optdfa;
         inherited destroy;
         inherited destroy;
       end;
       end;
 
 
-    var
-      { we have to pass the address of SearchNode in a call inside of SearchNode:
-        @SearchNode does not work because the compiler thinks we take the address of the result
-        so store the address from outside }
-      SearchNodeProcPointer : function(var n: tnode; arg: pointer): foreachnoderesult;
-
     type
     type
       { helper structure to be able to pass more than one variable to the iterator function }
       { helper structure to be able to pass more than one variable to the iterator function }
       TSearchNodeInfo = record
       TSearchNodeInfo = record
@@ -775,8 +769,8 @@ unit optdfa;
             begin
             begin
               { take care of short boolean evaluation: if the expression to be search is found in left,
               { take care of short boolean evaluation: if the expression to be search is found in left,
                 we do not need to search right }
                 we do not need to search right }
-              if foreachnodestatic(pm_postprocess,taddnode(n).left,SearchNodeProcPointer,arg) or
-                foreachnodestatic(pm_postprocess,taddnode(n).right,SearchNodeProcPointer,arg) then
+              if foreachnodestatic(pm_postprocess,taddnode(n).left,@optdfa.SearchNode,arg) or
+                foreachnodestatic(pm_postprocess,taddnode(n).right,@optdfa.SearchNode,arg) then
                 result:=fen_norecurse_true
                 result:=fen_norecurse_true
               else
               else
                 result:=fen_norecurse_false;
                 result:=fen_norecurse_false;
@@ -809,8 +803,8 @@ unit optdfa;
                       { don't warn about the method pointer }
                       { don't warn about the method pointer }
                       AddFilepos(hpt.fileinfo);
                       AddFilepos(hpt.fileinfo);
 
 
-                      if not(foreachnodestatic(pm_postprocess,tcallnode(n).left,SearchNodeProcPointer,arg)) then
-                        foreachnodestatic(pm_postprocess,tcallnode(n).right,SearchNodeProcPointer,arg);
+                      if not(foreachnodestatic(pm_postprocess,tcallnode(n).left,@optdfa.SearchNode,arg)) then
+                        foreachnodestatic(pm_postprocess,tcallnode(n).right,@optdfa.SearchNode,arg);
                       result:=fen_norecurse_true
                       result:=fen_norecurse_true
                     end;
                     end;
                  end;
                  end;
@@ -1005,6 +999,4 @@ unit optdfa;
       end;
       end;
 
 
 
 
-begin
-  SearchNodeProcPointer:=@SearchNode;
 end.
 end.

+ 17 - 19
compiler/optutils.pas

@@ -402,37 +402,34 @@ unit optutils;
         BreakContinueStack.Done;
         BreakContinueStack.Done;
       end;
       end;
 
 
-    var
-      defsum : TDFASet;
 
 
     function adddef(var n: tnode; arg: pointer): foreachnoderesult;
     function adddef(var n: tnode; arg: pointer): foreachnoderesult;
+      var
+        defsum : PDFASet absolute arg;
       begin
       begin
         if assigned(n.optinfo) then
         if assigned(n.optinfo) then
           begin
           begin
-            DFASetIncludeSet(defsum,n.optinfo^.def);
+            DFASetIncludeSet(defsum^,n.optinfo^.def);
             { for nodes itself do not necessarily expose the definition of the counter as
             { for nodes itself do not necessarily expose the definition of the counter as
               the counter might be undefined after the for loop, so include here the counter
               the counter might be undefined after the for loop, so include here the counter
               explicitly }
               explicitly }
             if (n.nodetype=forn) and assigned(tfornode(n).left.optinfo) then
             if (n.nodetype=forn) and assigned(tfornode(n).left.optinfo) then
-              DFASetInclude(defsum,tfornode(n).left.optinfo^.index);
+              DFASetInclude(defsum^,tfornode(n).left.optinfo^.index);
           end;
           end;
         Result:=fen_false;
         Result:=fen_false;
       end;
       end;
 
 
 
 
     procedure CalcDefSum(p : tnode);
     procedure CalcDefSum(p : tnode);
+      var
+        defsum : PDFASet;
       begin
       begin
         p.allocoptinfo;
         p.allocoptinfo;
-        if not assigned(p.optinfo^.defsum) then
-          begin
-            defsum:=nil;
-            foreachnodestatic(pm_postprocess,p,@adddef,nil);
-            p.optinfo^.defsum:=defsum;
-          end;
+        defsum:[email protected]^.defsum;
+        if not assigned(defsum^) then
+            foreachnodestatic(pm_postprocess,p,@adddef,defsum);
       end;
       end;
 
 
-    var
-      usesum : TDFASet;
 
 
     function SetExecutionWeight(var n: tnode; arg: pointer): foreachnoderesult;
     function SetExecutionWeight(var n: tnode; arg: pointer): foreachnoderesult;
       var
       var
@@ -481,22 +478,23 @@ unit optutils;
 
 
 
 
     function adduse(var n: tnode; arg: pointer): foreachnoderesult;
     function adduse(var n: tnode; arg: pointer): foreachnoderesult;
+      var
+        usesum : PDFASet absolute arg;
       begin
       begin
         if assigned(n.optinfo) then
         if assigned(n.optinfo) then
-          DFASetIncludeSet(usesum,n.optinfo^.use);
+          DFASetIncludeSet(usesum^,n.optinfo^.use);
         Result:=fen_false;
         Result:=fen_false;
       end;
       end;
 
 
 
 
     procedure CalcUseSum(p : tnode);
     procedure CalcUseSum(p : tnode);
+      var
+        usesum : PDFASet;
       begin
       begin
         p.allocoptinfo;
         p.allocoptinfo;
-        if not assigned(p.optinfo^.usesum) then
-          begin
-            usesum:=nil;
-            foreachnodestatic(pm_postprocess,p,@adduse,nil);
-            p.optinfo^.usesum:=usesum;
-          end;
+        usesum:[email protected]^.usesum;
+        if not assigned(usesum^) then
+            foreachnodestatic(pm_postprocess,p,@adduse,usesum);
       end;
       end;