Script: No #appendto in Defs or global functions in #appendtos (#734)

So the only thing #appendtos may contain are lokal functions and variables,
which are only reachable via the Definition the script is appended to, and
global constants and variables, which only need to be parsed once. Thus,
#appendto scripts can skip being parsed without a definition, and the
errors that sometimes produces are gone.
floating-point
Günther Brammer 2012-04-13 21:43:43 +02:00
parent ac02380b58
commit f89f19b2cb
1 changed files with 12 additions and 4 deletions

View File

@ -1248,6 +1248,8 @@ void C4AulParse::Parse_Script()
}
else if (SEqual(Idtf, C4AUL_Append))
{
if (pOrgScript->GetPropList()->GetDef())
throw new C4AulParseError(this, "#appendto in a Definition");
// for #appendto * '*' needs to be ATT_STAR, not an operator.
Shift(StarsPlease);
if (Type == PREPARSER)
@ -1368,7 +1370,7 @@ void C4AulParse::Parse_Function()
// func in global context: fallthru
case AA_GLOBAL:
if (a != pOrgScript)
Warn("global func in appendto/included script: ", Idtf);
throw new C4AulParseError(this, "global func in appendto/included script: ", Idtf);
if (a->Engine->GlobalNamedNames.GetItemNr(Idtf) != -1)
throw new C4AulParseError(this, "function definition: name already in use (global variable)");
if (a->Engine->GlobalConstNames.GetItemNr(Idtf) != -1)
@ -1401,9 +1403,8 @@ void C4AulParse::Parse_Function()
assert(Fn);
if (Type == PARSER)
{
assert(Fn->GetCodeOwner() == a || (Acc == AA_GLOBAL && Fn->GetCodeOwner() == pOrgScript)); // FIXME: handle globals better
if (Fn->GetCodeOwner() == a)
Fn->CodePos = a->Code.size();
assert(Fn->GetCodeOwner() == a);
Fn->CodePos = a->Code.size();
}
// Parse function body
@ -2879,6 +2880,13 @@ bool C4ScriptHost::Parse()
// delete existing code
ClearCode();
if (!Appends.empty())
{
// #appendto scripts are not allowed to contain global functions or belong to definitions
// so their contents are not reachable
return true;
}
C4AulFunc * thisfuncs = Func0;
for (C4AulFunc *f = thisfuncs; f; f = f->Next)
if (f->GetName() && f->SFunc())