+ explanation for the parameters of is_visible_for_object

* fixed accessibility checking for strict_protected (the class
    in which the access occurs also has to be related to the
    objectdef of which a symbol is accessed) + test

git-svn-id: trunk@22565 -
This commit is contained in:
Jonas Maebe 2012-10-06 16:28:27 +00:00
parent 81b50af768
commit e9f4b095e1
5 changed files with 84 additions and 2 deletions

3
.gitattributes vendored
View File

@ -11310,6 +11310,7 @@ tests/test/tset6.pp svneol=native#text/plain
tests/test/tset7.pp svneol=native#text/plain
tests/test/tsetsize.pp svneol=native#text/plain
tests/test/tshuffle1.pp svneol=native#text/pascal
tests/test/tsprot.pp svneol=native#text/plain
tests/test/tstack.pp svneol=native#text/plain
tests/test/tstatic1.pp svneol=native#text/pascal
tests/test/tstatic2.pp svneol=native#text/pascal
@ -11628,6 +11629,8 @@ tests/test/uprocext1.pp svneol=native#text/plain
tests/test/uprocext2.pp svneol=native#text/plain
tests/test/urhlp14.pp svneol=native#text/pascal
tests/test/urhlp17.pp svneol=native#text/pascal
tests/test/usprot1.pp svneol=native#text/plain
tests/test/usprot2.pp svneol=native#text/plain
tests/test/utasout.pp svneol=native#text/plain
tests/test/uunit1.pp svneol=native#text/plain
tests/test/uunit2a.pp svneol=native#text/plain

View File

@ -2113,6 +2113,12 @@ implementation
result:=false;
end;
{ symst: symboltable that contains the symbol (-> symowner def: record/objectdef in which the symbol is defined)
symvisibility: visibility of the symbol
contextobjdef: via which def the symbol is accessed, e.g.:
fieldname:=1 -> contextobjdef = current_structdef
objfield.fieldname:=1 -> contextobjdef = def of objfield
}
function is_visible_for_object(symst:tsymtable;symvisibility:tvisibility;contextobjdef:tabstractrecorddef):boolean;
var
symownerdef : tabstractrecorddef;
@ -2156,9 +2162,16 @@ implementation
vis_strictprotected :
begin
result:=(
{ access from nested class }
assigned(current_structdef) and
(current_structdef.is_related(symownerdef) or
is_owned_by(current_structdef,symownerdef))
is_owned_by(current_structdef,symownerdef)
) or
(
{ access from child class }
assigned(contextobjdef) and
assigned(current_structdef) and
contextobjdef.is_related(symownerdef) and
current_structdef.is_related(contextobjdef)
) or
(
{ helpers can access strict protected symbols }

27
tests/test/tsprot.pp Normal file
View File

@ -0,0 +1,27 @@
{ %fail }
{$ifdef fpc}
{$mode delphi}
{$endif}
unit tsprot;
interface
uses
usprot1,usprot2;
type
tchild2 = class(tbase)
f: tchild1;
procedure test;
end;
implementation
procedure tchild2.test;
begin
f.pmethod;
end;
end.

21
tests/test/usprot1.pp Normal file
View File

@ -0,0 +1,21 @@
{$ifdef fpc}
{$mode delphi}
{$endif}
unit usprot1;
interface
type
tbase = class
strict protected
procedure pmethod; virtual; overload;
end;
implementation
procedure tbase.pmethod;
begin
end;
end.

18
tests/test/usprot2.pp Normal file
View File

@ -0,0 +1,18 @@
{$ifdef fpc}
{$mode delphi}
{$endif}
unit usprot2;
interface
uses
usprot1;
type
tchild1 = class(tbase)
end;
implementation
end.