Browse Source

* fix order of procdefs in procsym, procdefs are now always appended
so that loading from a ppu will keep the same order. This is
important for the generation of VMTs

peter 22 years ago
parent
commit
dfb2918780
1 changed files with 108 additions and 90 deletions
  1. 108 90
      compiler/symsym.pas

+ 108 - 90
compiler/symsym.pas

@@ -111,7 +111,8 @@ interface
 
 
        tprocsym = class(tstoredsym)
        tprocsym = class(tstoredsym)
        protected
        protected
-          defs : pprocdeflist; { linked list of overloaded procdefs }
+          pdlistfirst,
+          pdlistlast   : pprocdeflist; { linked list of overloaded procdefs }
           function getprocdef(nr:cardinal):Tprocdef;
           function getprocdef(nr:cardinal):Tprocdef;
        public
        public
           procdef_count : byte;
           procdef_count : byte;
@@ -800,7 +801,8 @@ implementation
       begin
       begin
          inherited create(n);
          inherited create(n);
          typ:=procsym;
          typ:=procsym;
-         defs:=nil;
+         pdlistfirst:=nil;
+         pdlistlast:=nil;
          owner:=nil;
          owner:=nil;
          is_global:=false;
          is_global:=false;
          overloadchecked:=false;
          overloadchecked:=false;
@@ -815,7 +817,8 @@ implementation
       begin
       begin
          inherited loadsym(ppufile);
          inherited loadsym(ppufile);
          typ:=procsym;
          typ:=procsym;
-         defs:=nil;
+         pdlistfirst:=nil;
+         pdlistlast:=nil;
          procdef_count:=0;
          procdef_count:=0;
          repeat
          repeat
            pd:=tprocdef(ppufile.getderef);
            pd:=tprocdef(ppufile.getderef);
@@ -833,7 +836,7 @@ implementation
       var
       var
          hp,p : pprocdeflist;
          hp,p : pprocdeflist;
       begin
       begin
-         p:=defs;
+         p:=pdlistfirst;
          while assigned(p) do
          while assigned(p) do
            begin
            begin
               hp:=p^.next;
               hp:=p^.next;
@@ -848,7 +851,7 @@ implementation
       var
       var
          p : pprocdeflist;
          p : pprocdeflist;
       begin
       begin
-         p:=defs;
+         p:=pdlistfirst;
          while assigned(p) do
          while assigned(p) do
            begin
            begin
               if p^.def<>skipdef then
               if p^.def<>skipdef then
@@ -862,7 +865,7 @@ implementation
       var
       var
          p : pprocdeflist;
          p : pprocdeflist;
       begin
       begin
-         p:=defs;
+         p:=pdlistfirst;
          while assigned(p) do
          while assigned(p) do
            begin
            begin
               if (p^.def.procsym=self) and
               if (p^.def.procsym=self) and
@@ -881,7 +884,7 @@ implementation
       var
       var
          p : pprocdeflist;
          p : pprocdeflist;
       begin
       begin
-         p:=defs;
+         p:=pdlistfirst;
          while assigned(p) do
          while assigned(p) do
            begin
            begin
              resolvedef(pointer(p^.def));
              resolvedef(pointer(p^.def));
@@ -896,8 +899,19 @@ implementation
       begin
       begin
         new(pd);
         new(pd);
         pd^.def:=p;
         pd^.def:=p;
-        pd^.next:=defs;
-        defs:=pd;
+        pd^.next:=nil;
+        { Add at end of list to keep always
+          a correct order, also after loading from ppu }
+        if assigned(pdlistlast) then
+         begin
+           pdlistlast^.next:=pd;
+           pdlistlast:=pd;
+         end
+        else
+         begin
+           pdlistfirst:=pd;
+           pdlistlast:=pd;
+         end;
         inc(procdef_count);
         inc(procdef_count);
       end;
       end;
 
 
@@ -907,7 +921,7 @@ implementation
         i : cardinal;
         i : cardinal;
         pd : Pprocdeflist;
         pd : Pprocdeflist;
       begin
       begin
-        pd:=defs;
+        pd:=pdlistfirst;
         for i:=2 to nr do
         for i:=2 to nr do
           begin
           begin
             if not assigned(pd) then
             if not assigned(pd) then
@@ -922,7 +936,7 @@ implementation
       var
       var
         pd:Pprocdeflist;
         pd:Pprocdeflist;
       begin
       begin
-        pd:=defs;
+        pd:=pdlistfirst;
         while assigned(pd) do
         while assigned(pd) do
           begin
           begin
             if Aprocsym.search_procdef_bypara(pd^.def.para,false,true)=nil then
             if Aprocsym.search_procdef_bypara(pd^.def.para,false,true)=nil then
@@ -933,95 +947,94 @@ implementation
 
 
 
 
     procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
     procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
-
-    var pd:Pprocdeflist;
-
-    begin
-        pd:=defs;
+      var
+        pd : Pprocdeflist;
+      begin
+        pd:=pdlistfirst;
         while assigned(pd) do
         while assigned(pd) do
-            begin
-                s.addprocdef(pd^.def);
-                pd:=pd^.next;
-            end;
-    end;
+         begin
+           s.addprocdef(pd^.def);
+           pd:=pd^.next;
+         end;
+      end;
+
 
 
     function Tprocsym.first_procdef:Tprocdef;
     function Tprocsym.first_procdef:Tprocdef;
+      begin
+        if assigned(pdlistfirst) then
+          first_procdef:=pdlistfirst^.def
+        else
+          first_procdef:=nil;
+      end;
 
 
-    begin
-        first_procdef:=defs^.def;
-    end;
 
 
     function Tprocsym.last_procdef:Tprocdef;
     function Tprocsym.last_procdef:Tprocdef;
+      begin
+        if assigned(pdlistlast) then
+          last_procdef:=pdlistlast^.def
+        else
+          last_procdef:=nil;
+      end;
 
 
-    var pd:Pprocdeflist;
-
-    begin
-        pd:=defs;
-        while assigned(pd) do
-            begin
-                last_procdef:=pd^.def;
-                pd:=pd^.next;
-            end;
-    end;
 
 
     procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
     procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
-
-    var p:Pprocdeflist;
-
-    begin
-        p:=defs;
+      var
+        p : Pprocdeflist;
+      begin
+        p:=pdlistfirst;
         while assigned(p) do
         while assigned(p) do
-            begin
-                proc2call(p^.def,arg);
-                p:=p^.next;
-            end;
-    end;
-
-    function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
+         begin
+           proc2call(p^.def,arg);
+           p:=p^.next;
+         end;
+      end;
 
 
-    var p:Pprocdeflist;
 
 
-    begin
-      search_procdef_nopara_boolret:=nil;
-      p:=defs;
-      while p<>nil do
-        begin
-          if p^.def.para.empty and is_boolean(p^.def.rettype.def) then
+    function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
+      var
+        p : Pprocdeflist;
+      begin
+        search_procdef_nopara_boolret:=nil;
+        p:=pdlistfirst;
+        while p<>nil do
+         begin
+           if p^.def.para.empty and is_boolean(p^.def.rettype.def) then
             begin
             begin
               search_procdef_nopara_boolret:=p^.def;
               search_procdef_nopara_boolret:=p^.def;
               break;
               break;
             end;
             end;
-          p:=p^.next;
-        end;
-    end;
-
-    function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
+           p:=p^.next;
+         end;
+      end;
 
 
-    var p:Pprocdeflist;
 
 
-    begin
+    function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
+      var
+        p : Pprocdeflist;
+      begin
         search_procdef_bytype:=nil;
         search_procdef_bytype:=nil;
-        p:=defs;
+        p:=pdlistfirst;
         while p<>nil do
         while p<>nil do
+         begin
+           if p^.def.proctypeoption=pt then
             begin
             begin
-                if p^.def.proctypeoption=pt then
-                    begin
-                        search_procdef_bytype:=p^.def;
-                        break;
-                    end;
-                p:=p^.next;
+              search_procdef_bytype:=p^.def;
+              break;
             end;
             end;
-    end;
+           p:=p^.next;
+         end;
+      end;
+
 
 
     function Tprocsym.search_procdef_bypara(params:Tparalinkedlist;
     function Tprocsym.search_procdef_bypara(params:Tparalinkedlist;
                                             allowconvert,
                                             allowconvert,
                                             allowdefault:boolean):Tprocdef;
                                             allowdefault:boolean):Tprocdef;
       var
       var
-        pd:Pprocdeflist;
+        pd : Pprocdeflist;
         eq : tequaltype;
         eq : tequaltype;
       begin
       begin
         search_procdef_bypara:=nil;
         search_procdef_bypara:=nil;
-        pd:=defs;
+        pd:=pdlistfirst;
         while assigned(pd) do
         while assigned(pd) do
          begin
          begin
            eq:=compare_paras(pd^.def.para,params,cp_value_equal_const,allowdefault);
            eq:=compare_paras(pd^.def.para,params,cp_value_equal_const,allowdefault);
@@ -1047,7 +1060,7 @@ implementation
         search_procdef_byprocvardef:=nil;
         search_procdef_byprocvardef:=nil;
         bestpd:=nil;
         bestpd:=nil;
         besteq:=te_incompatible;
         besteq:=te_incompatible;
-        pd:=defs;
+        pd:=pdlistfirst;
         while assigned(pd) do
         while assigned(pd) do
          begin
          begin
            eq:=proc_to_procvar_equal(pd^.def,d);
            eq:=proc_to_procvar_equal(pd^.def,d);
@@ -1074,7 +1087,7 @@ implementation
         pd:Pprocdeflist;
         pd:Pprocdeflist;
       begin
       begin
         search_procdef_by1paradef:=nil;
         search_procdef_by1paradef:=nil;
-        pd:=defs;
+        pd:=pdlistfirst;
         while assigned(pd) do
         while assigned(pd) do
           begin
           begin
             if equal_defs(Tparaitem(pd^.def.para.first).paratype.def,firstpara) and
             if equal_defs(Tparaitem(pd^.def.para.first).paratype.def,firstpara) and
@@ -1100,7 +1113,7 @@ implementation
         search_procdef_assignment_operator:=nil;
         search_procdef_assignment_operator:=nil;
         bestpd:=nil;
         bestpd:=nil;
         besteq:=te_incompatible;
         besteq:=te_incompatible;
-        pd:=defs;
+        pd:=pdlistfirst;
         while assigned(pd) do
         while assigned(pd) do
           begin
           begin
             if equal_defs(todef,pd^.def.rettype.def) then
             if equal_defs(todef,pd^.def.rettype.def) then
@@ -1137,7 +1150,7 @@ implementation
         search_procdef_binary_operator:=nil;
         search_procdef_binary_operator:=nil;
         bestpd:=nil;
         bestpd:=nil;
         bestlev:=0;
         bestlev:=0;
-        pd:=defs;
+        pd:=pdlistfirst;
         while assigned(pd) do
         while assigned(pd) do
           begin
           begin
             eq1:=compare_defs_ext(def1,Tparaitem(pd^.def.para.first).paratype.def,
             eq1:=compare_defs_ext(def1,Tparaitem(pd^.def.para.first).paratype.def,
@@ -1172,7 +1185,7 @@ implementation
          p : pprocdeflist;
          p : pprocdeflist;
       begin
       begin
          inherited writesym(ppufile);
          inherited writesym(ppufile);
-         p:=defs;
+         p:=pdlistfirst;
          while assigned(p) do
          while assigned(p) do
            begin
            begin
              { only write the proc definitions that belong
              { only write the proc definitions that belong
@@ -1194,7 +1207,7 @@ implementation
          if not inherited write_references(ppufile,locals) then
          if not inherited write_references(ppufile,locals) then
            exit;
            exit;
          write_references:=true;
          write_references:=true;
-         p:=defs;
+         p:=pdlistfirst;
          while assigned(p) do
          while assigned(p) do
            begin
            begin
               if (p^.def.procsym=self) then
               if (p^.def.procsym=self) then
@@ -1206,29 +1219,30 @@ implementation
 
 
     procedure tprocsym.unchain_overload;
     procedure tprocsym.unchain_overload;
       var
       var
-         p,hp,
-         first,
-         last : pprocdeflist;
+         p,hp : pprocdeflist;
       begin
       begin
          { remove all overloaded procdefs from the
          { remove all overloaded procdefs from the
            procdeflist that are not in the current symtable }
            procdeflist that are not in the current symtable }
-         first:=nil;
-         last:=nil;
-         p:=defs;
+         p:=pdlistfirst;
+         { reset new lists }
+         pdlistfirst:=nil;
+         pdlistlast:=nil;
          while assigned(p) do
          while assigned(p) do
            begin
            begin
               hp:=p^.next;
               hp:=p^.next;
               if (p^.def.procsym=self) then
               if (p^.def.procsym=self) then
                 begin
                 begin
-                  { keep in list }
-                  if not assigned(first) then
+                  { keep, add to list }
+                  if assigned(pdlistlast) then
                    begin
                    begin
-                     first:=p;
-                     last:=p;
+                     pdlistlast^.next:=p;
+                     pdlistlast:=p;
                    end
                    end
                   else
                   else
-                   last^.next:=p;
-                  last:=p;
+                   begin
+                     pdlistfirst:=p;
+                     pdlistlast:=p;
+                   end;
                   p^.next:=nil;
                   p^.next:=nil;
                 end
                 end
               else
               else
@@ -1239,7 +1253,6 @@ implementation
                 end;
                 end;
               p:=hp;
               p:=hp;
            end;
            end;
-         defs:=first;
       end;
       end;
 
 
 
 
@@ -2504,7 +2517,12 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.82  2002-12-11 22:39:23  peter
+  Revision 1.83  2002-12-16 22:08:31  peter
+    * fix order of procdefs in procsym, procdefs are now always appended
+      so that loading from a ppu will keep the same order. This is
+      important for the generation of VMTs
+
+  Revision 1.82  2002/12/11 22:39:23  peter
     * better error message when no operator is found for equal
     * better error message when no operator is found for equal
 
 
   Revision 1.81  2002/12/07 14:27:10  carl
   Revision 1.81  2002/12/07 14:27:10  carl