Browse Source

* rename duplicate symbols and insert with unique name in the
symtable

peter 21 years ago
parent
commit
ad89ee8150
2 changed files with 48 additions and 56 deletions
  1. 6 2
      compiler/pdecsub.pas
  2. 42 54
      compiler/symtable.pas

+ 6 - 2
compiler/pdecsub.pas

@@ -731,7 +731,7 @@ implementation
                    if (m_fpc in aktmodeswitches) then
                    if (m_fpc in aktmodeswitches) then
                     Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
                     Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
                    else
                    else
-                    DuplicateSym(aprocsym);
+                    tstoredsymtable(symtablestack).DuplicateSym(nil,aprocsym);
                    { rename the name to an unique name to avoid an
                    { rename the name to an unique name to avoid an
                      error when inserting the symbol in the symtable }
                      error when inserting the symbol in the symtable }
                    orgsp:=orgsp+'$'+tostr(aktfilepos.line);
                    orgsp:=orgsp+'$'+tostr(aktfilepos.line);
@@ -2259,7 +2259,11 @@ const
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.198  2004-10-31 18:54:24  peter
+  Revision 1.199  2004-11-05 21:16:55  peter
+    * rename duplicate symbols and insert with unique name in the
+      symtable
+
+  Revision 1.198  2004/10/31 18:54:24  peter
     * $fpctarget expands to <cpu>-<os>
     * $fpctarget expands to <cpu>-<os>
     * allow * in middle of the path to support ../*/units/$fpctarget
     * allow * in middle of the path to support ../*/units/$fpctarget
 
 

+ 42 - 54
compiler/symtable.pas

@@ -69,6 +69,7 @@ interface
           procedure buildderefimpl;virtual;
           procedure buildderefimpl;virtual;
           procedure deref;virtual;
           procedure deref;virtual;
           procedure derefimpl;virtual;
           procedure derefimpl;virtual;
+          procedure duplicatesym(dupsym,sym:tsymentry);
           procedure insert(sym : tsymentry);override;
           procedure insert(sym : tsymentry);override;
           procedure reset_all_defs;virtual;
           procedure reset_all_defs;virtual;
           function  speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;override;
           function  speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;override;
@@ -191,7 +192,6 @@ interface
 {*** Misc ***}
 {*** Misc ***}
     procedure globaldef(const s : string;var t:ttype);
     procedure globaldef(const s : string;var t:ttype);
     function  findunitsymtable(st:tsymtable):tsymtable;
     function  findunitsymtable(st:tsymtable):tsymtable;
-    procedure duplicatesym(sym:tsym);
     function  FullTypeName(def,otherdef:tdef):string;
     function  FullTypeName(def,otherdef:tdef):string;
     procedure incompatibletypes(def1,def2:tdef);
     procedure incompatibletypes(def1,def2:tdef);
 
 
@@ -267,6 +267,9 @@ implementation
       procinfo
       procinfo
       ;
       ;
 
 
+    var
+      dupnr : longint; { unique number for duplicate symbols }
+
 
 
 {*****************************************************************************
 {*****************************************************************************
                              TStoredSymtable
                              TStoredSymtable
@@ -558,6 +561,29 @@ implementation
       end;
       end;
 
 
 
 
+    procedure tstoredsymtable.duplicatesym(dupsym,sym:tsymentry);
+      var
+        st : tsymtable;
+      begin
+        Message1(sym_e_duplicate_id,tsym(sym).realname);
+        st:=findunitsymtable(sym.owner);
+        with tsym(sym).fileinfo do
+          begin
+            if assigned(st) and (st.unitid<>0) then
+              Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
+            else
+              Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
+          end;
+        { Rename duplicate sym to an unreachable name, but it can be
+          inserted in the symtable without errors }
+        if assigned(dupsym) then
+          begin
+            inc(dupnr);
+            dupsym.name:='dup'+tostr(dupnr)+dupsym.name;
+          end;
+      end;
+
+
     procedure tstoredsymtable.insert(sym:tsymentry);
     procedure tstoredsymtable.insert(sym:tsymentry);
       var
       var
          hsym : tsym;
          hsym : tsym;
@@ -580,10 +606,7 @@ implementation
                    (vo_is_result in tvarsym(sym).varoptions)) then
                    (vo_is_result in tvarsym(sym).varoptions)) then
              sym.name:='hidden'+sym.name
              sym.name:='hidden'+sym.name
             else
             else
-             begin
-               DuplicateSym(hsym);
-               exit;
-             end;
+             DuplicateSym(sym,hsym);
           end;
           end;
 
 
          { register definition of typesym }
          { register definition of typesym }
@@ -1153,10 +1176,7 @@ implementation
               hsym:=search_class_member(tobjectdef(defowner),sym.name);
               hsym:=search_class_member(tobjectdef(defowner),sym.name);
               if assigned(hsym) and
               if assigned(hsym) and
                  Tsym(hsym).is_visible_for_object(tobjectdef(defowner)) then
                  Tsym(hsym).is_visible_for_object(tobjectdef(defowner)) then
-               begin
-                 DuplicateSym(hsym);
-                 exit;
-               end;
+                DuplicateSym(sym,hsym);
            end;
            end;
          inherited insert(sym);
          inherited insert(sym);
       end;
       end;
@@ -1211,10 +1231,7 @@ implementation
                    (vo_is_result in tvarsym(hsym).varoptions)) then
                    (vo_is_result in tvarsym(hsym).varoptions)) then
               hsym.owner.rename(hsym.name,'hidden'+hsym.name)
               hsym.owner.rename(hsym.name,'hidden'+hsym.name)
             else
             else
-              begin
-                DuplicateSym(hsym);
-                exit;
-              end;
+              DuplicateSym(sym,hsym);
           end;
           end;
 
 
         if assigned(next) and
         if assigned(next) and
@@ -1233,10 +1250,7 @@ implementation
                        (vo_is_result in tvarsym(sym).varoptions)) then
                        (vo_is_result in tvarsym(sym).varoptions)) then
                   sym.name:='hidden'+sym.name
                   sym.name:='hidden'+sym.name
                 else
                 else
-                  begin
-                    DuplicateSym(hsym);
-                    exit;
-                  end;
+                  DuplicateSym(sym,hsym);
               end;
               end;
             { check for duplicate id in local symtable of methods }
             { check for duplicate id in local symtable of methods }
             if assigned(next.next) and
             if assigned(next.next) and
@@ -1254,10 +1268,7 @@ implementation
                     in object (tp7 compatible) }
                     in object (tp7 compatible) }
                   if not((m_delphi in aktmodeswitches) and
                   if not((m_delphi in aktmodeswitches) and
                          is_class(tdef(next.next.defowner))) then
                          is_class(tdef(next.next.defowner))) then
-                   begin
-                     DuplicateSym(hsym);
-                     exit;
-                   end;
+                    DuplicateSym(sym,hsym);
                 end;
                 end;
              end;
              end;
           end;
           end;
@@ -1297,10 +1308,7 @@ implementation
                    in object (tp7 compatible) }
                    in object (tp7 compatible) }
                  if not((m_delphi in aktmodeswitches) and
                  if not((m_delphi in aktmodeswitches) and
                         is_class_or_interface(tobjectdef(next.defowner))) then
                         is_class_or_interface(tobjectdef(next.defowner))) then
-                  begin
-                    DuplicateSym(hsym);
-                    exit;
-                  end;
+                   DuplicateSym(sym,hsym);
                end;
                end;
            end;
            end;
 
 
@@ -1461,10 +1469,7 @@ implementation
                   (hsym.typ=symconst.unitsym) then
                   (hsym.typ=symconst.unitsym) then
                 hsym.owner.rename(hsym.name,'hidden'+hsym.name)
                 hsym.owner.rename(hsym.name,'hidden'+hsym.name)
                else
                else
-                begin
-                  DuplicateSym(hsym);
-                  exit;
-                end;
+                DuplicateSym(sym,hsym);
              end;
              end;
           end;
           end;
 
 
@@ -1603,10 +1608,7 @@ implementation
                   (hsym.typ=symconst.unitsym) then
                   (hsym.typ=symconst.unitsym) then
                 hsym.owner.rename(hsym.name,'hidden'+hsym.name)
                 hsym.owner.rename(hsym.name,'hidden'+hsym.name)
                else
                else
-                begin
-                  DuplicateSym(hsym);
-                  exit;
-                end;
+                DuplicateSym(sym,hsym);
              end;
              end;
           end;
           end;
 
 
@@ -1620,10 +1622,7 @@ implementation
                (hsym.typ=symconst.unitsym) then
                (hsym.typ=symconst.unitsym) then
              hsym.owner.rename(hsym.name,'hidden'+hsym.name)
              hsym.owner.rename(hsym.name,'hidden'+hsym.name)
             else
             else
-             begin
-               DuplicateSym(hsym);
-               exit;
-             end;
+             DuplicateSym(sym,hsym);
           end;
           end;
 
 
          inherited insert(sym);
          inherited insert(sym);
@@ -1728,22 +1727,6 @@ implementation
       end;
       end;
 
 
 
 
-     procedure duplicatesym(sym:tsym);
-       var
-         st : tsymtable;
-       begin
-         Message1(sym_e_duplicate_id,sym.realname);
-         st:=findunitsymtable(sym.owner);
-         with sym.fileinfo do
-           begin
-             if assigned(st) and (st.unitid<>0) then
-               Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
-             else
-               Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
-           end;
-       end;
-
-
     function FullTypeName(def,otherdef:tdef):string;
     function FullTypeName(def,otherdef:tdef):string;
       var
       var
         s1,s2 : string;
         s1,s2 : string;
@@ -2299,6 +2282,7 @@ implementation
         { unit aliases }
         { unit aliases }
         unitaliases:=tdictionary.create;
         unitaliases:=tdictionary.create;
 {$endif}
 {$endif}
+        dupnr:=0;
      end;
      end;
 
 
 
 
@@ -2314,7 +2298,11 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.160  2004-11-01 23:30:11  peter
+  Revision 1.161  2004-11-05 21:16:55  peter
+    * rename duplicate symbols and insert with unique name in the
+      symtable
+
+  Revision 1.160  2004/11/01 23:30:11  peter
     * support > 32bit accesses for x86_64
     * support > 32bit accesses for x86_64
     * rewrote array size checking to support 64bit
     * rewrote array size checking to support 64bit