* self is not a token anymore. It is handled special when found

in a code block and when parsing an method
This commit is contained in:
peter 2003-10-09 15:20:56 +00:00
parent 8fcfcc6606
commit 56ebcd1249
2 changed files with 31 additions and 37 deletions

View File

@ -71,12 +71,12 @@ implementation
symconst,symbase,symsym,symtable,defutil,defcmp, symconst,symbase,symsym,symtable,defutil,defcmp,
{ pass 1 } { pass 1 }
pass_1,htypechk, pass_1,htypechk,
nutils,nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas, nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,
{ parser } { parser }
scanner, scanner,
pbase,pinline, pbase,pinline,
{ codegen } { codegen }
cgbase,procinfo procinfo
; ;
{ sub_expr(opmultiply) is need to get -1 ** 4 to be { sub_expr(opmultiply) is need to get -1 ** 4 to be
@ -805,7 +805,7 @@ implementation
{ the following procedure handles the access to a property symbol } { the following procedure handles the access to a property symbol }
procedure handle_propertysym(sym : tsym;st : tsymtable;var p1 : tnode; getaddr: boolean); procedure handle_propertysym(sym : tsym;st : tsymtable;var p1 : tnode);
procedure symlist_to_node(var p1:tnode;pl:tsymlist); procedure symlist_to_node(var p1:tnode;pl:tsymlist);
var var
@ -1093,7 +1093,7 @@ implementation
begin begin
if isclassref then if isclassref then
Message(parser_e_only_class_methods_via_class_ref); Message(parser_e_only_class_methods_via_class_ref);
handle_propertysym(sym,sym.owner,p1,getaddr); handle_propertysym(sym,sym.owner,p1);
end; end;
else internalerror(16); else internalerror(16);
end; end;
@ -1390,7 +1390,7 @@ implementation
Message(parser_e_only_class_methods); Message(parser_e_only_class_methods);
{ no method pointer } { no method pointer }
p1:=nil; p1:=nil;
handle_propertysym(srsym,srsymtable,p1,getaddr); handle_propertysym(srsym,srsymtable,p1);
end; end;
labelsym : labelsym :
@ -1564,7 +1564,7 @@ implementation
begin begin
{ The property symbol is referenced indirect } { The property symbol is referenced indirect }
inc(protsym.refs); inc(protsym.refs);
handle_propertysym(protsym,protsym.owner,p1,getaddr); handle_propertysym(protsym,protsym.owner,p1);
end; end;
end end
else else
@ -1817,7 +1817,19 @@ implementation
again:=false; again:=false;
if token=_ID then if token=_ID then
begin begin
factor_read_id(p1,again); again:=true;
{ Handle references to self }
if (idtoken=_SELF) and
not(block_type in [bt_const,bt_type]) and
assigned(current_procinfo) and
assigned(current_procinfo.procdef._class) then
begin
p1:=load_self_node;
consume(_ID);
again:=true;
end
else
factor_read_id(p1,again);
if again then if again then
begin begin
check_tokenpos; check_tokenpos;
@ -1828,24 +1840,6 @@ implementation
end end
else else
case token of case token of
_SELF :
begin
again:=true;
consume(_SELF);
if not(assigned(current_procinfo) and
assigned(current_procinfo.procdef._class)) then
begin
p1:=cerrornode.create;
again:=false;
Message(parser_e_self_not_in_method);
end
else
begin
p1:=load_self_node;
postfixoperators(p1,again);
end;
end;
_INHERITED : _INHERITED :
begin begin
again:=true; again:=true;
@ -2418,7 +2412,11 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.134 2003-10-09 15:00:13 florian Revision 1.135 2003-10-09 15:20:56 peter
* self is not a token anymore. It is handled special when found
in a code block and when parsing an method
Revision 1.134 2003/10/09 15:00:13 florian
* fixed constructor call in class methods * fixed constructor call in class methods
Revision 1.133 2003/10/08 19:19:45 peter Revision 1.133 2003/10/08 19:19:45 peter

View File

@ -1057,7 +1057,6 @@ implementation
var var
old_current_procinfo : tprocinfo; old_current_procinfo : tprocinfo;
oldconstsymtable : tsymtable; oldconstsymtable : tsymtable;
oldselftokenmode,
oldfailtokenmode : tmodeswitch; oldfailtokenmode : tmodeswitch;
pdflags : tpdflags; pdflags : tpdflags;
pd : tprocdef; pd : tprocdef;
@ -1169,12 +1168,6 @@ implementation
oldfailtokenmode:=tokeninfo^[_FAIL].keyword; oldfailtokenmode:=tokeninfo^[_FAIL].keyword;
tokeninfo^[_FAIL].keyword:=m_all; tokeninfo^[_FAIL].keyword:=m_all;
end; end;
{ set _SELF as keyword if methods }
if assigned(pd._class) then
begin
oldselftokenmode:=tokeninfo^[_SELF].keyword;
tokeninfo^[_SELF].keyword:=m_all;
end;
tcgprocinfo(current_procinfo).parse_body; tcgprocinfo(current_procinfo).parse_body;
@ -1192,9 +1185,6 @@ implementation
{ reset _FAIL as _SELF normal } { reset _FAIL as _SELF normal }
if (pd.proctypeoption=potype_constructor) then if (pd.proctypeoption=potype_constructor) then
tokeninfo^[_FAIL].keyword:=oldfailtokenmode; tokeninfo^[_FAIL].keyword:=oldfailtokenmode;
if assigned(pd._class) then
tokeninfo^[_SELF].keyword:=oldselftokenmode;
consume(_SEMICOLON);
{ release procinfo } { release procinfo }
if tprocinfo(current_module.procinfo)<>current_procinfo then if tprocinfo(current_module.procinfo)<>current_procinfo then
@ -1202,6 +1192,8 @@ implementation
current_module.procinfo:=current_procinfo.parent; current_module.procinfo:=current_procinfo.parent;
if not isnestedproc then if not isnestedproc then
current_procinfo.free; current_procinfo.free;
consume(_SEMICOLON);
end; end;
{ Restore old state } { Restore old state }
@ -1316,7 +1308,11 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.159 2003-10-07 15:17:07 peter Revision 1.160 2003-10-09 15:20:56 peter
* self is not a token anymore. It is handled special when found
in a code block and when parsing an method
Revision 1.159 2003/10/07 15:17:07 peter
* inline supported again, LOC_REFERENCEs are used to pass the * inline supported again, LOC_REFERENCEs are used to pass the
parameters parameters
* inlineparasymtable,inlinelocalsymtable removed * inlineparasymtable,inlinelocalsymtable removed