Sfoglia il codice sorgente

* 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 anni fa
parent
commit
4506394cfa
4 ha cambiato i file con 20 aggiunte e 12 eliminazioni
  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
                (pd.owner.symtabletype<>objectsymtable) or
-               pd.is_visible_for_object(topclassh) then
+               pd.is_visible_for_object(topclassh,nil) then
              begin
                { we have at least one procedure that is visible }
                inc(FProcvisiblecnt);
@@ -1581,14 +1581,14 @@ implementation
                      { if this visible procedure doesn't have overload we can stop
                        searching }
                      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;
                      { process all overloaded definitions }
                      for j:=1 to srprocsym.procdef_count do
                       begin
                         pd:=srprocsym.procdef[j];
                         { 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
                             { only when the # of parameter are supported by the
                               procedure }

+ 2 - 2
compiler/nobj.pas

@@ -626,7 +626,7 @@ implementation
                    procdefs, because they can be reused in the next class.
                    The check to skip the invisible methods that are in the
                    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
                   begin
@@ -796,7 +796,7 @@ implementation
         for i:=1 to Tprocsym(sym).procdef_count do
           begin
             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;
 

+ 14 - 6
compiler/symdef.pas

@@ -549,7 +549,7 @@ interface
           function  cplusplusmangledname : string;
           function  is_methodpointer: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;
 
        { single linked list of overloaded procs }
@@ -3454,15 +3454,23 @@ implementation
       end;
 
 
-    function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
+    function tprocdef.is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
+      var
+        contextst : tsymtable;
       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
           module as they are defined }
         if (sp_private in symoptions) 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;
 
         if (sp_strictprivate in symoptions) then
@@ -3485,7 +3493,7 @@ implementation
            (
             (
              (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
-             not(owner.defowner.owner.iscurrentunit)
+             not((owner.defowner.owner.iscurrentunit) or (owner.defowner.owner=contextst))
             ) and
             not(
                 assigned(currobjdef) and
@@ -3496,7 +3504,7 @@ implementation
            ) then
           exit;
 
-        is_visible_for_object:=true;
+        result:=true;
       end;
 
 

+ 1 - 1
compiler/symsym.pas

@@ -1047,7 +1047,7 @@ implementation
         while assigned(p) do
           begin
              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
                  result:=true;
                  exit;