瀏覽代碼

Merged revisions 7348 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r7348 | peter | 2007-05-15 19:39:09 +0200 (Tue, 15 May 2007) | 3 lines

* during specialization use the symtable stack at
definition time, fixes tgeneric14
........

git-svn-id: branches/fixes_2_2@7386 -

peter 18 年之前
父節點
當前提交
4aac6821b3
共有 1 個文件被更改,包括 46 次插入5 次删除
  1. 46 5
      compiler/psub.pas

+ 46 - 5
compiler/psub.pas

@@ -1708,10 +1708,32 @@ implementation
 
 
     procedure specialize_objectdefs(p:TObject;arg:pointer);
+
+        function find_module_from_symtable(st:tsymtable):tmodule;
+        var
+          hp : tmodule;
+        begin
+          result:=nil;
+          hp:=tmodule(loaded_units.first);
+          while assigned(hp) do
+            begin
+              if (hp.globalsymtable=st) or
+                 (hp.localsymtable=st) then
+                begin
+                  result:=hp;
+                  exit;
+                end;
+              hp:=tmodule(hp.next);
+           end;
+        end;
+
       var
         i  : longint;
         hp : tdef;
         oldcurrent_filepos : tfileposinfo;
+        oldsymtablestack   : tsymtablestack;
+        pu : tused_unit;
+        hmodule : tmodule;
       begin
         if not((tsym(p).typ=typesym) and
                (ttypesym(p).typedef.typ=objectdef) and
@@ -1719,6 +1741,25 @@ implementation
               ) then
           exit;
 
+        { Setup symtablestack a definition time }
+        oldsymtablestack:=symtablestack;
+        symtablestack:=tsymtablestack.create;
+        if not assigned(tobjectdef(ttypesym(p).typedef).genericdef) then
+          internalerror(200705151);
+        hmodule:=find_module_from_symtable(tobjectdef(ttypesym(p).typedef).genericdef.owner);
+        if hmodule=nil then
+          internalerror(200705152);
+        pu:=tused_unit(hmodule.used_units.first);
+        while assigned(pu) do
+          begin
+            if not assigned(pu.u.globalsymtable) then
+              internalerror(200705153);
+            symtablestack.push(pu.u.globalsymtable);
+            pu:=tused_unit(pu.next);
+          end;
+        symtablestack.push(hmodule.globalsymtable);
+        symtablestack.push(hmodule.localsymtable);
+
         { definitions }
         for i:=0 to tobjectdef(ttypesym(p).typedef).symtable.DefList.Count-1 do
           begin
@@ -1740,6 +1781,10 @@ implementation
                  MessagePos1(tprocdef(tprocdef(hp).genericdef).fileinfo,sym_e_forward_not_resolved,tprocdef(tprocdef(hp).genericdef).fullprocname(false));
              end;
          end;
+
+        { Restore symtablestack }
+        symtablestack.free;
+        symtablestack:=oldsymtablestack;
       end;
 
 
@@ -1748,11 +1793,7 @@ implementation
         if assigned(current_module.globalsymtable) then
           current_module.globalsymtable.SymList.ForEachCall(@specialize_objectdefs,nil);
         if assigned(current_module.localsymtable) then
-          begin
-            symtablestack.push(current_module.localsymtable);
-            current_module.localsymtable.SymList.ForEachCall(@specialize_objectdefs,nil);
-            symtablestack.pop(current_module.localsymtable);
-          end;
+          current_module.localsymtable.SymList.ForEachCall(@specialize_objectdefs,nil);
       end;
 
 end.