Forráskód Böngészése

compiler: search namespace symbols also in the interface symtable of a unit when we are registering a unit with a namespace in the implementation section (fixes issue #0025059)

git-svn-id: trunk@25560 -
paul 12 éve
szülő
commit
ce6c8c1b59

+ 4 - 0
.gitattributes

@@ -13592,6 +13592,7 @@ tests/webtbs/tw25030.pp svneol=native#text/pascal
 tests/webtbs/tw2504.pp svneol=native#text/plain
 tests/webtbs/tw2504.pp svneol=native#text/plain
 tests/webtbs/tw25054a.pp svneol=native#text/pascal
 tests/webtbs/tw25054a.pp svneol=native#text/pascal
 tests/webtbs/tw25054b.pp svneol=native#text/pascal
 tests/webtbs/tw25054b.pp svneol=native#text/pascal
+tests/webtbs/tw25059.pp svneol=native#text/pascal
 tests/webtbs/tw2514.pp svneol=native#text/plain
 tests/webtbs/tw2514.pp svneol=native#text/plain
 tests/webtbs/tw2525.pp svneol=native#text/plain
 tests/webtbs/tw2525.pp svneol=native#text/plain
 tests/webtbs/tw2536.pp svneol=native#text/plain
 tests/webtbs/tw2536.pp svneol=native#text/plain
@@ -14366,6 +14367,9 @@ tests/webtbs/uw23204.pp svneol=native#text/plain
 tests/webtbs/uw2364.pp svneol=native#text/plain
 tests/webtbs/uw2364.pp svneol=native#text/plain
 tests/webtbs/uw25054a.pp svneol=native#text/pascal
 tests/webtbs/uw25054a.pp svneol=native#text/pascal
 tests/webtbs/uw25054b.pp svneol=native#text/pascal
 tests/webtbs/uw25054b.pp svneol=native#text/pascal
+tests/webtbs/uw25059.pp svneol=native#text/pascal
+tests/webtbs/uw25059.test.pp svneol=native#text/pascal
+tests/webtbs/uw25059.withdot.pp svneol=native#text/pascal
 tests/webtbs/uw2706a.pp svneol=native#text/plain
 tests/webtbs/uw2706a.pp svneol=native#text/plain
 tests/webtbs/uw2706b.pp svneol=native#text/plain
 tests/webtbs/uw2706b.pp svneol=native#text/plain
 tests/webtbs/uw2731.pp svneol=native#text/plain
 tests/webtbs/uw2731.pp svneol=native#text/plain

+ 21 - 3
compiler/symtable.pas

@@ -143,6 +143,7 @@ interface
        public
        public
           constructor create(const n : string;id:word);
           constructor create(const n : string;id:word);
           function checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
           function checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
+          function findnamespace(const n:string):TSymEntry;virtual;
           function iscurrentunit:boolean;override;
           function iscurrentunit:boolean;override;
           procedure insertunit(sym:TSymEntry);
           procedure insertunit(sym:TSymEntry);
        end;
        end;
@@ -160,7 +161,8 @@ interface
           constructor create(const n : string;id:word);
           constructor create(const n : string;id:word);
           procedure ppuload(ppufile:tcompilerppufile);override;
           procedure ppuload(ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
-          function  checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
+          function checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
+          function findnamespace(const n:string):TSymEntry;override;
        end;
        end;
 
 
        tspecializesymtable = class(tglobalsymtable)
        tspecializesymtable = class(tglobalsymtable)
@@ -1698,6 +1700,13 @@ implementation
           end;
           end;
       end;
       end;
 
 
+    function tabstractuniTSymtable.findnamespace(const n:string):TSymEntry;
+      begin
+        result:=find(n);
+        if assigned(result)and(result.typ<>namespacesym)then
+          result:=nil;
+      end;
+
     function tabstractuniTSymtable.iscurrentunit:boolean;
     function tabstractuniTSymtable.iscurrentunit:boolean;
       begin
       begin
         result:=assigned(current_module) and
         result:=assigned(current_module) and
@@ -1724,8 +1733,8 @@ implementation
             else
             else
               ns:=ns+'.'+copy(n,1,p-1);
               ns:=ns+'.'+copy(n,1,p-1);
             system.delete(n,1,p);
             system.delete(n,1,p);
-            oldsym:=Find(upper(ns));
-            if not Assigned(oldsym) or (oldsym.typ<>namespacesym) then
+            oldsym:=findnamespace(upper(ns));
+            if not assigned(oldsym) then
               insert(tnamespacesym.create(ns));
               insert(tnamespacesym.create(ns));
             p:=pos('.',n);
             p:=pos('.',n);
           end;
           end;
@@ -1769,6 +1778,15 @@ implementation
           result:=tglobalsymtable(current_module.globalsymtable).checkduplicate(hashedid,sym);
           result:=tglobalsymtable(current_module.globalsymtable).checkduplicate(hashedid,sym);
       end;
       end;
 
 
+    function tstaticsymtable.findnamespace(const n:string):TSymEntry;
+      begin
+        result:=inherited findnamespace(n);
+        if not assigned(result) and
+           (current_module.localsymtable=self) and
+           assigned(current_module.globalsymtable) then
+          result:=tglobalsymtable(current_module.globalsymtable).findnamespace(n);
+     end;
+
 
 
 {****************************************************************************
 {****************************************************************************
                               TGlobalSymtable
                               TGlobalSymtable

+ 11 - 0
tests/webtbs/tw25059.pp

@@ -0,0 +1,11 @@
+program tw25059;
+
+{$mode delphi}
+
+uses
+  uw25059.test;
+
+begin
+  if ExecuteTest() <> 1 then
+    Halt(1);
+end.

+ 16 - 0
tests/webtbs/uw25059.pp

@@ -0,0 +1,16 @@
+unit uw25059;
+
+{$mode delphi}
+
+interface
+
+function GetValue(): Integer;
+
+implementation
+
+function GetValue(): Integer;
+begin
+  Result := 1;
+end;
+
+end.

+ 20 - 0
tests/webtbs/uw25059.test.pp

@@ -0,0 +1,20 @@
+unit uw25059.test;
+
+{$mode delphi}
+
+interface
+
+function ExecuteTest(): Integer;
+
+implementation
+
+uses
+  uw25059,
+  uw25059.withdot;
+
+function ExecuteTest(): Integer;
+begin
+  Result := uw25059.GetValue();
+end;
+
+end.

+ 9 - 0
tests/webtbs/uw25059.withdot.pp

@@ -0,0 +1,9 @@
+unit uw25059.withdot;
+
+{$mode delphi}
+
+interface
+
+implementation
+
+end.