* factored out the creation of loadnodes for special variables/parameters

git-svn-id: trunk@47857 -
This commit is contained in:
Jonas Maebe 2020-12-27 13:18:56 +00:00
parent 5e3e4437c4
commit 8ba4c4bcf0
3 changed files with 62 additions and 72 deletions

View File

@ -182,6 +182,10 @@ interface
{ Current assignment node }
aktassignmentnode : tassignmentnode;
{ Create a node tree to load a variable if symbol is assigned, otherwise an error node.
Generates an internalerror if called for an absolutevarsym of the "tovar" kind (those
are only supported for expansion in the parser) }
function gen_load_var(sym: tabstractvarsym): tnode;
implementation
@ -192,10 +196,32 @@ implementation
defutil,defcmp,
cpuinfo,
htypechk,pass_1,procinfo,paramgr,
ncon,nflw,ninl,ncnv,nmem,ncal,nutils,
nbas,ncon,nflw,ninl,ncnv,nmem,ncal,nutils,
cgbase
;
function gen_load_var(sym: tabstractvarsym): tnode;
begin
result:=nil;
if assigned(sym) then
begin
if (sym.typ<>absolutevarsym) or
(tabsolutevarsym(sym).abstyp<>tovar) then
begin
result:=cloadnode.create(sym,sym.owner);
end
else
internalerror(2020122601);
end
else
begin
result:=cerrornode.create;
CGMessage(parser_e_illegal_expression);
end;
end;
{*****************************************************************************
TLOADNODE
*****************************************************************************}

View File

@ -78,7 +78,7 @@ interface
procedure checktreenodetypes(n : tnode;typeset : tnodetypeset);
procedure load_procvar_from_calln(var p1:tnode);
function get_local_or_para_sym(const aname: string): tsym;
function get_local_or_para_sym(const aname: string): tabstractvarsym;
function maybe_call_procvar(var p1:tnode;tponly:boolean):boolean;
function load_high_value_node(vs:tparavarsym):tnode;
function load_self_node:tnode;
@ -496,10 +496,12 @@ implementation
end;
function get_local_or_para_sym(const aname: string): tsym;
function get_local_or_para_sym(const aname: string): tabstractvarsym;
var
pd : tprocdef;
pd: tprocdef;
ressym: tsym;
begin
ressym:=nil;
result:=nil;
{ is not assigned while parsing a property }
if not assigned(current_procinfo) then
@ -509,11 +511,11 @@ implementation
is run for nested procedures }
pd:=current_procinfo.procdef;
repeat
result := tsym(pd.localst.Find(aname));
if assigned(result) then
ressym:=tsym(pd.localst.Find(aname));
if assigned(ressym) then
break;
result := tsym(pd.parast.Find(aname));
if assigned(result) then
ressym:=tsym(pd.parast.Find(aname));
if assigned(ressym) then
break;
{ try the parent of a nested function }
if assigned(pd.owner.defowner) and
@ -522,98 +524,60 @@ implementation
else
break;
until false;
if assigned(ressym) and
not(ressym.typ in [localvarsym,paravarsym]) then
internalerror(2020122604);
result:=tabstractvarsym(ressym);
end;
function load_high_value_node(vs:tparavarsym):tnode;
var
srsym : tsym;
begin
result:=nil;
srsym:=get_high_value_sym(vs);
if assigned(srsym) then
begin
result:=cloadnode.create(srsym,vs.owner);
typecheckpass(result);
end
else
CGMessage(parser_e_illegal_expression);
result:=gen_load_var(get_high_value_sym(vs));
typecheckpass(result);
end;
function load_self_node:tnode;
var
srsym : tsym;
begin
result:=nil;
srsym:=get_local_or_para_sym('self');
if assigned(srsym) then
begin
result:=cloadnode.create(srsym,srsym.owner);
include(tloadnode(result).loadnodeflags,loadnf_is_self);
end
else
begin
result:=cerrornode.create;
CGMessage(parser_e_illegal_expression);
end;
result:=gen_load_var(get_local_or_para_sym('self'));
if result.nodetype=loadn then
include(tloadnode(result).loadnodeflags,loadnf_is_self)
else if result.nodetype<>errorn then
internalerror(2020122603);
typecheckpass(result);
end;
function load_result_node:tnode;
var
srsym : tsym;
pd : tprocdef;
begin
result:=nil;
srsym:=get_local_or_para_sym('result');
if assigned(srsym) then
result:=cloadnode.create(srsym,srsym.owner)
else
begin
result:=cerrornode.create;
CGMessage(parser_e_illegal_expression);
end;
begin
result:=gen_load_var(get_local_or_para_sym('result'));
typecheckpass(result);
end;
function load_self_pointer_node:tnode;
var
srsym : tsym;
srsym : tabstractvarsym;
begin
result:=nil;
srsym:=get_local_or_para_sym('self');
if assigned(srsym) then
result:=gen_load_var(srsym);
if assigned(srsym) and
(is_object(tabstractvarsym(srsym).vardef) or is_record(tabstractvarsym(srsym).vardef)) then
begin
result:=cloadnode.create(srsym,srsym.owner);
if is_object(tabstractvarsym(srsym).vardef) or is_record(tabstractvarsym(srsym).vardef) then
include(tloadnode(result).loadnodeflags,loadnf_load_addr);
end
else
begin
result:=cerrornode.create;
CGMessage(parser_e_illegal_expression);
if result.nodetype=loadn then
include(tloadnode(result).loadnodeflags,loadnf_load_addr)
else if result.nodetype<>errorn then
internalerror(2020122602);
end;
typecheckpass(result);
end;
function load_vmt_pointer_node:tnode;
var
srsym : tsym;
begin
result:=nil;
srsym:=get_local_or_para_sym('vmt');
if assigned(srsym) then
result:=cloadnode.create(srsym,srsym.owner)
else
begin
result:=cerrornode.create;
CGMessage(parser_e_illegal_expression);
end;
result:=gen_load_var(get_local_or_para_sym('vmt'));
typecheckpass(result);
end;

View File

@ -496,7 +496,7 @@ interface
{ generate internal static field name based on regular field name }
function internal_static_field_name(const fieldname: TSymStr): TSymStr;
function get_high_value_sym(vs: tparavarsym):tsym; { marking it as inline causes IE 200311075 during loading from ppu file }
function get_high_value_sym(vs: tparavarsym):tabstractvarsym; { marking it as inline causes IE 200311075 during loading from ppu file }
procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring);inline;
procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring;filepos:tfileposinfo);
@ -534,9 +534,9 @@ implementation
end;
function get_high_value_sym(vs: tparavarsym):tsym;
function get_high_value_sym(vs: tparavarsym):tabstractvarsym;
begin
result := tsym(vs.owner.Find('high'+vs.name));
result := tabstractvarsym(vs.owner.Find('high'+vs.name));
end;