Remove C4AulFunc::LinkedTo

The parser doesn't need it to find the functions it has to parse anymore.

And the global proplist can be cleared before removing the functions,
instead of having engine functions deregister themselves and script
functions being deregistered when their linked function is removed.
Günther Brammer 2012-02-13 22:20:10 +01:00
parent 30c843925f
commit 65801a5188
5 changed files with 20 additions and 77 deletions

View File

@ -48,7 +48,6 @@ void C4AulError::show()
C4AulFunc::C4AulFunc(C4AulScript *pOwner, const char *pName):
Name(pName ? Strings.RegString(pName) : 0),
MapNext(NULL),
LinkedTo (NULL),
OverloadedBy (NULL)
{
AppendToScript(pOwner);
@ -75,26 +74,6 @@ void C4AulFunc::AppendToScript(C4AulScript * pOwner)
C4AulFunc::~C4AulFunc()
{
// if it's a global: remove the global link!
if (LinkedTo && Owner)
if (LinkedTo->Owner == Owner->Engine)
{
if (!LinkedTo->OverloadedBy)
LinkedTo->Owner->GetPropList()->ResetProperty(LinkedTo->Name);
delete LinkedTo;
}
// unlink func
if (LinkedTo)
{
// find prev
C4AulFunc* pAkt = this;
while (pAkt->LinkedTo != this) pAkt = pAkt->LinkedTo;
if (pAkt == LinkedTo)
pAkt->LinkedTo = NULL;
else
pAkt->LinkedTo = LinkedTo;
LinkedTo = NULL;
}
// remove from list
if (Prev) Prev->Next = Next;
if (Next) Next->Prev = Prev;
@ -113,13 +92,6 @@ C4AulFunc::~C4AulFunc()
}
}
void C4AulFunc::DestroyLinked()
{
// delete all functions linked to this one.
while (LinkedTo)
delete LinkedTo;
}
StdStrBuf C4AulFunc::GetFullName()
{
// "lost" function?
@ -154,8 +126,10 @@ C4AulDefFunc::C4AulDefFunc(C4AulScript *pOwner, const char *pName, C4ScriptFnDef
C4AulDefFunc::~C4AulDefFunc()
{
if (!OverloadedBy)
Owner->GetPropList()->ResetProperty(Name);
assert(Owner);
assert(Owner->GetPropList());
assert(Name);
assert(Owner->GetPropList()->GetFunc(Name) != this);
}
C4AulScript::C4AulScript()
@ -312,10 +286,10 @@ void C4AulScriptEngine::Clear()
while (Child0)
if (Child0->Delete()) delete Child0;
else Child0->Unreg();
// clear inherited
C4AulScript::Clear();
// clear own stuff
GetPropList()->Clear();
// clear inherited
C4AulScript::Clear();
// reset values
warnCnt = errCnt = lineCnt = 0;
// resetting name lists will reset all data lists, too

View File

@ -226,7 +226,6 @@ protected:
C4RefCntPointer<C4String> Name; // function name
C4AulFunc *Prev, *Next; // linked list members
C4AulFunc *MapNext; // map member
C4AulFunc *LinkedTo; // points to next linked function; destructor will destroy linked func, too
void AppendToScript(C4AulScript *);
public:
@ -242,10 +241,6 @@ public:
virtual C4Value Exec(C4AulContext *pCallerCtx, C4Value pPars[], bool fPassErrors=false) { return C4Value(); } // execute func (script call)
virtual C4Value Exec(C4PropList * p = NULL, C4AulParSet *pPars = NULL, bool fPassErrors=false); // execute func (engine call)
virtual void UnLink() { OverloadedBy = NULL; }
protected:
void DestroyLinked(); // destroys linked functions
};
// script function class

View File

@ -259,8 +259,10 @@ public:
}
~C4AulDefFuncHelper()
{
if (!OverloadedBy)
Owner->GetPropList()->ResetProperty(Name);
assert(Owner);
assert(Owner->GetPropList());
assert(Name);
assert(Owner->GetPropList()->GetFunc(Name) != this);
}
virtual C4V_Type* GetParType() { return ParType; }
virtual bool GetPublic() { return Public; }

View File

@ -135,12 +135,10 @@ void C4AulScript::UnLink()
if (pFunc->SFunc())
if (pFunc->Owner != pFunc->SFunc()->pOrgScript)
// do not kill global links; those will be deleted if corresponding sfunc in script is deleted
if (!pFunc->LinkedTo || pFunc->LinkedTo->SFunc())
{
if (p) p->ResetProperty(pFunc->Name);
delete pFunc;
}
{
if (p) p->ResetProperty(pFunc->Name);
delete pFunc;
}
pFunc = pNextFunc;
}

View File

@ -743,7 +743,7 @@ C4ScriptHost * C4AulScriptFunc::GetCodeOwner()
{
if (Owner == Owner->Engine)
{
return LinkedTo->Owner->GetScriptHost();
return pOrgScript->GetScriptHost();
}
else
{
@ -769,11 +769,6 @@ bool C4ScriptHost::Preparse()
ClearCode();
while (Func0)
{
// belongs to this script?
if (Func0->SFunc())
if (Func0->SFunc()->pOrgScript == this)
// then destroy linked funcs, too
Func0->DestroyLinked();
// destroy func
delete Func0;
}
@ -1384,8 +1379,6 @@ void C4AulParseState::Parse_Function()
{
// global func
Fn = new C4AulScriptFunc(a->Engine, Idtf);
C4AulFunc *FnLink = new C4AulFunc(a, NULL);
FnLink->LinkedTo = Fn; Fn->LinkedTo = FnLink;
Acc = AA_PUBLIC;
}
else
@ -1411,7 +1404,7 @@ void C4AulParseState::Parse_Function()
f = f->Next;
}
assert(Fn);
assert(Fn->GetCodeOwner() == a || Acc == AA_GLOBAL); // FIXME: handle globals better
assert(Fn->GetCodeOwner() == a || (Acc == AA_GLOBAL && Fn->GetCodeOwner() == pOrgScript)); // FIXME: handle globals better
if (Fn->GetCodeOwner() == a)
Fn->CodePos = a->Code.size();
}
@ -2914,17 +2907,6 @@ bool C4ScriptHost::Parse()
// append: create copy
C4AulScriptFunc *sfc = new C4AulScriptFunc(this, sf->GetName());
sfc->CopyBody(*sf);
// link the copy to a local function
if (sf->LinkedTo)
{
sfc->LinkedTo = sf->LinkedTo;
sf->LinkedTo = sfc;
}
else
{
sfc->LinkedTo = sf;
sf->LinkedTo = sfc;
}
}
// copy local var definitions
for (int ivar = 0; ivar < (*s)->LocalNamed.iSize; ivar ++)
@ -2948,12 +2930,8 @@ bool C4ScriptHost::Parse()
// calc absolute code addresses for script funcs
for (C4AulFunc * f = Func0; f; f = f->Next)
{
C4AulScriptFunc *Fn;
if (!(Fn = f->SFunc()))
{
if (f->LinkedTo) Fn = f->LinkedTo->SFunc();
if (Fn) if (Fn->Owner != Engine) Fn=NULL;
}
C4AulScriptFunc * Fn = f->SFunc();
assert(Fn);
if (Fn)
assert(Fn->GetCodeOwner() == this);
}
@ -2965,12 +2943,8 @@ bool C4ScriptHost::Parse()
if (DEBUG_BYTECODE_DUMP)
for (C4AulFunc * f = Func0; f; f = f->Next)
{
C4AulScriptFunc *Fn;
if (!(Fn = f->SFunc()))
{
if (f->LinkedTo) Fn = f->LinkedTo->SFunc();
if (Fn) if (Fn->Owner != Engine) Fn=NULL;
}
C4AulScriptFunc *Fn = f->SFunc();
assert(Fn);
if (!Fn)
continue;
fprintf(stderr, "%s:\n", Fn->GetName());