Przeglądaj źródła

* make the mangled names of symbols in the local scope of
procedures/functions/methods on the JVM platform unique

git-svn-id: branches/jvmbackend@18583 -

Jonas Maebe 14 lat temu
rodzic
commit
ba5e264a93
2 zmienionych plików z 22 dodań i 12 usunięć
  1. 2 4
      compiler/jvmdef.pas
  2. 20 8
      compiler/symdef.pas

+ 2 - 4
compiler/jvmdef.pas

@@ -531,10 +531,8 @@ implementation
                         begin
                           if tdef(container.defowner).typ<>procdef then
                             internalerror(2011040303);
-                          { not safe yet in case of overloaded routines, need to
-                            encode parameters too or find another way for conflict
-                            resolution }
-                          result:=tprocdef(container.defowner).procsym.realname+'$'+result;
+                          { symid is added to prevent problem with overloads }
+                          result:=tprocdef(container.defowner).procsym.realname+'$$'+tostr(tprocdef(container.defowner).procsym.symid)+'$'+result;
                           container:=container.defowner.owner;
                         end;
                     end;

+ 20 - 8
compiler/symdef.pas

@@ -3068,7 +3068,7 @@ implementation
     function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
       var
         st: tsymtable;
-        enclosingobj: tabstractrecorddef;
+        enclosingdef: tdef;
       begin
         if typ=objectdef then
           result:=tobjectdef(self).objextname^
@@ -3080,15 +3080,19 @@ implementation
 
         st:=owner;
         while assigned(st) and
-              (st.symtabletype in [objectsymtable,recordsymtable]) do
+              (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
           begin
             { nested classes are named as "OuterClass$InnerClass" }
-            enclosingobj:=tabstractrecorddef(st.defowner);
-            if enclosingobj.typ=objectdef then
-              result:=tobjectdef(enclosingobj).objextname^+'$'+result
-            else if assigned(enclosingobj.typesym) then
-              result:=enclosingobj.typesym.realname+'$'+result;
-            st:=enclosingobj.owner;
+            enclosingdef:=tdef(st.defowner);
+            if enclosingdef.typ=procdef then
+              result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
+            else if enclosingdef.typ=objectdef then
+              result:=tobjectdef(enclosingdef).objextname^+'$'+result
+            else if assigned(enclosingdef.typesym) then
+              result:=enclosingdef.typesym.realname+'$'+result
+            else
+              internalerror(2011060305);
+            st:=enclosingdef.owner;
           end;
 
         if with_package_name and
@@ -4454,6 +4458,7 @@ implementation
         i: longint;
         founderror: tdef;
         tmpresult: string;
+        container: tsymtable;
       begin
         { format:
             * method definition (in Jasmin):
@@ -4483,6 +4488,13 @@ implementation
                 tmpresult:=procsym.realname;
                 if tmpresult[1]='$' then
                   tmpresult:=copy(tmpresult,2,length(tmpresult)-1);
+                { nested functions }
+                container:=owner;
+                while container.symtabletype=localsymtable do
+                  begin
+                    tmpresult:='$'+tprocdef(owner.defowner).procsym.realname+'$'+tostr(tprocdef(owner.defowner).procsym.symid)+'$'+tmpresult;
+                    container:=container.defowner.owner;
+                  end;
               end;
           end
         else