compiler: if method has no self node then load it as a usual identifier (issue #0024871)

git-svn-id: trunk@25273 -
This commit is contained in:
paul 2013-08-17 02:54:55 +00:00
parent d55a32e875
commit 89e154bc10
4 changed files with 78 additions and 3 deletions

1
.gitattributes vendored
View File

@ -13477,6 +13477,7 @@ tests/webtbs/tw2481.pp svneol=native#text/plain
tests/webtbs/tw2483.pp svneol=native#text/plain
tests/webtbs/tw24848.pp svneol=native#text/pascal
tests/webtbs/tw24863.pp svneol=native#text/plain
tests/webtbs/tw24871.pp svneol=native#text/pascal
tests/webtbs/tw2492.pp svneol=native#text/plain
tests/webtbs/tw2494.pp svneol=native#text/plain
tests/webtbs/tw2503.pp svneol=native#text/plain

View File

@ -2788,6 +2788,22 @@ implementation
factor_read_set:=buildp;
end;
function can_load_self_node: boolean;
var
procinfo: tprocinfo;
begin
result:=false;
if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
not assigned(current_structdef) or
not assigned(current_procinfo) then
exit;
procinfo:=current_procinfo;
if procinfo.procdef.parast.symtablelevel<normal_function_level then
exit;
while assigned(procinfo.parent)and(procinfo.procdef.parast.symtablelevel>normal_function_level) do
procinfo:=procinfo.parent;
result:=not procinfo.procdef.no_self_node;
end;
{---------------------------------------------
Factor (Main)
@ -2822,9 +2838,7 @@ implementation
begin
again:=true;
{ Handle references to self }
if (idtoken=_SELF) and
not(block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) and
assigned(current_structdef) then
if (idtoken=_SELF) and can_load_self_node then
begin
p1:=load_self_node;
consume(_ID);

View File

@ -52,6 +52,9 @@ unit procinfo;
{ This object gives information on the current routine being
compiled.
}
{ tprocinfo }
tprocinfo = class(tlinkedlistitem)
private
{ list to store the procinfo's of the nested procedures }

57
tests/webtbs/tw24871.pp Normal file
View File

@ -0,0 +1,57 @@
program tw24871;
{$mode delphi}
{$APPTYPE CONSOLE}
type
TRec = record
class procedure Foo(Self: TObject); static;
end;
{ TClass }
TClass = class
class procedure Foo(Self: TObject); static;
end;
{ TRec }
class procedure TRec.Foo(Self: TObject);
procedure Foo1;
procedure Foo2;
begin
Self.ClassName;
end;
begin
Self.ClassName;
end;
begin
Self.ClassName;
end;
{ TClass }
class procedure TClass.Foo(Self: TObject);
procedure Foo1;
procedure Foo2;
begin
Self.ClassName;
end;
begin
Self.ClassName;
end;
begin
Self.ClassName;
end;
begin
end.