Browse Source

* pass contextobjdef for visibility of methods. There are different
requirements for normal searching and for overloaded searching.
For overloaded searching we need to have the context of the
object where the overload is defined and not the current
module

git-svn-id: trunk@4391 -

peter 19 years ago
parent
commit
4506394cfa
4 changed files with 20 additions and 12 deletions
  1. 3 3
      compiler/htypechk.pas
  2. 2 2
      compiler/nobj.pas
  3. 14 6
      compiler/symdef.pas
  4. 1 1
      compiler/symsym.pas

+ 3 - 3
compiler/htypechk.pas

@@ -1536,7 +1536,7 @@ implementation
 
 
             if isprop or ignorevis or
             if isprop or ignorevis or
                (pd.owner.symtabletype<>objectsymtable) or
                (pd.owner.symtabletype<>objectsymtable) or
-               pd.is_visible_for_object(topclassh) then
+               pd.is_visible_for_object(topclassh,nil) then
              begin
              begin
                { we have at least one procedure that is visible }
                { we have at least one procedure that is visible }
                inc(FProcvisiblecnt);
                inc(FProcvisiblecnt);
@@ -1581,14 +1581,14 @@ implementation
                      { if this visible procedure doesn't have overload we can stop
                      { if this visible procedure doesn't have overload we can stop
                        searching }
                        searching }
                      if not(po_overload in srprocsym.first_procdef.procoptions) and
                      if not(po_overload in srprocsym.first_procdef.procoptions) and
-                        srprocsym.first_procdef.is_visible_for_object(topclassh) then
+                        srprocsym.first_procdef.is_visible_for_object(topclassh,nil) then
                       break;
                       break;
                      { process all overloaded definitions }
                      { process all overloaded definitions }
                      for j:=1 to srprocsym.procdef_count do
                      for j:=1 to srprocsym.procdef_count do
                       begin
                       begin
                         pd:=srprocsym.procdef[j];
                         pd:=srprocsym.procdef[j];
                         { only visible procedures need to be added }
                         { only visible procedures need to be added }
-                        if pd.is_visible_for_object(topclassh) then
+                        if pd.is_visible_for_object(topclassh,nil) then
                           begin
                           begin
                             { only when the # of parameter are supported by the
                             { only when the # of parameter are supported by the
                               procedure }
                               procedure }

+ 2 - 2
compiler/nobj.pas

@@ -626,7 +626,7 @@ implementation
                    procdefs, because they can be reused in the next class.
                    procdefs, because they can be reused in the next class.
                    The check to skip the invisible methods that are in the
                    The check to skip the invisible methods that are in the
                    list is futher down in the code }
                    list is futher down in the code }
-                 is_visible:=pd.is_visible_for_object(_class);
+                 is_visible:=pd.is_visible_for_object(_class,nil);
 
 
                  if pd.procsym=sym then
                  if pd.procsym=sym then
                   begin
                   begin
@@ -796,7 +796,7 @@ implementation
         for i:=1 to Tprocsym(sym).procdef_count do
         for i:=1 to Tprocsym(sym).procdef_count do
           begin
           begin
             pd:=Tprocsym(sym).procdef[i];
             pd:=Tprocsym(sym).procdef[i];
-            newdefentry(vmtentry,pd,pd.is_visible_for_object(_class));
+            newdefentry(vmtentry,pd,pd.is_visible_for_object(_class,nil));
           end;
           end;
       end;
       end;
 
 

+ 14 - 6
compiler/symdef.pas

@@ -549,7 +549,7 @@ interface
           function  cplusplusmangledname : string;
           function  cplusplusmangledname : string;
           function  is_methodpointer:boolean;override;
           function  is_methodpointer:boolean;override;
           function  is_addressonly:boolean;override;
           function  is_addressonly:boolean;override;
-          function  is_visible_for_object(currobjdef:tobjectdef):boolean;
+          function  is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
        end;
        end;
 
 
        { single linked list of overloaded procs }
        { single linked list of overloaded procs }
@@ -3454,15 +3454,23 @@ implementation
       end;
       end;
 
 
 
 
-    function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
+    function tprocdef.is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
+      var
+        contextst : tsymtable;
       begin
       begin
-        is_visible_for_object:=false;
+        result:=false;
+
+        { Support passing a context in which module we are to find protected members }
+        if assigned(contextobjdef) then
+          contextst:=contextobjdef.owner
+        else
+          contextst:=nil;
 
 
         { private symbols are allowed when we are in the same
         { private symbols are allowed when we are in the same
           module as they are defined }
           module as they are defined }
         if (sp_private in symoptions) and
         if (sp_private in symoptions) and
            (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
            (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
-           not(owner.defowner.owner.iscurrentunit) then
+           not(owner.defowner.owner.iscurrentunit or (owner.defowner.owner=contextst)) then
           exit;
           exit;
 
 
         if (sp_strictprivate in symoptions) then
         if (sp_strictprivate in symoptions) then
@@ -3485,7 +3493,7 @@ implementation
            (
            (
             (
             (
              (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
              (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
-             not(owner.defowner.owner.iscurrentunit)
+             not((owner.defowner.owner.iscurrentunit) or (owner.defowner.owner=contextst))
             ) and
             ) and
             not(
             not(
                 assigned(currobjdef) and
                 assigned(currobjdef) and
@@ -3496,7 +3504,7 @@ implementation
            ) then
            ) then
           exit;
           exit;
 
 
-        is_visible_for_object:=true;
+        result:=true;
       end;
       end;
 
 
 
 

+ 1 - 1
compiler/symsym.pas

@@ -1047,7 +1047,7 @@ implementation
         while assigned(p) do
         while assigned(p) do
           begin
           begin
              if (p^.def.owner=owner) and
              if (p^.def.owner=owner) and
-                p^.def.is_visible_for_object(tobjectdef(currobjdef)) then
+                p^.def.is_visible_for_object(tobjectdef(currobjdef),tobjectdef(context)) then
                begin
                begin
                  result:=true;
                  result:=true;
                  exit;
                  exit;