Move Scriptparser State into C4ScriptHost

liquid_container
Günther Brammer 2016-01-03 03:38:05 +01:00
parent 2fe0beebdb
commit b21acff0c7
6 changed files with 16 additions and 33 deletions

View File

@ -43,9 +43,6 @@ const char *C4AulError::what() const noexcept
C4AulScript::C4AulScript()
{
// not compiled
State = ASS_NONE;
// prepare lists
Prev = Next = NULL;
Engine = NULL;
@ -72,8 +69,6 @@ void C4AulScript::Unreg()
void C4AulScript::Clear()
{
// reset flags
State = ASS_NONE;
}

View File

@ -75,18 +75,6 @@ protected:
friend class C4ScriptHost;
};
// aul script state
enum C4AulScriptState
{
ASS_ERROR, // erroneous script
ASS_NONE, // nothing
ASS_PREPARSED, // function list built; CodeSize set
ASS_LINKED, // includes and appends resolved
ASS_PARSED // byte code generated
};
// script profiler entry
class C4AulProfiler
{
@ -150,19 +138,11 @@ public:
virtual void ResetProfilerTimes(); // zero all profiler times of owned functions
virtual void CollectProfilerTimes(class C4AulProfiler &rProfiler);
bool IsReady() { return State == ASS_PARSED; } // whether script calls may be done
// helper functions
void Warn(const char *pMsg, ...) GNUC_FORMAT_ATTRIBUTE_O;
friend class C4AulParseError;
friend class C4AulFunc;
friend class C4AulScriptFunc;
friend class C4AulScriptEngine;
friend class C4AulParse;
friend class C4AulDebug;
friend class C4ScriptHost;
// Translate a string using the script's lang table
std::string Translate(const std::string &text) const;
@ -172,8 +152,6 @@ protected:
C4AulScriptEngine *Engine; //owning engine
C4AulScript *Prev, *Next; // tree structure
C4AulScriptState State; // script state
virtual bool ReloadScript(const char *szPath, const char *szLanguage); // reload given script
virtual bool Parse();
virtual bool ResolveIncludes(C4DefList *rDefs);

View File

@ -150,7 +150,6 @@ void C4AulScriptEngine::UnLink()
for (C4AulScript *s = Child0; s; s = s->Next)
s->UnLink();
GetPropList()->Thaw();
if (State > ASS_PREPARSED) State = ASS_PREPARSED;
// Do not clear global variables and constants, because they are registered by the
// preparser or other parts. Note that keeping those fields means that you cannot delete a global
// variable or constant at runtime by removing it from the script.
@ -177,9 +176,6 @@ void C4AulScriptEngine::Link(C4DefList *rDefs)
for (C4AulScript *s = Child0; s; s = s->Next)
s->Parse();
// engine is always parsed (for global funcs)
State = ASS_PARSED;
if (rDefs)
rDefs->CallEveryDefinition();

View File

@ -804,7 +804,7 @@ bool C4ScriptHost::Preparse()
GetPropList()->Properties.Swap(&LocalValues);
// return success
C4AulScript::State = ASS_PREPARSED;
this->State = ASS_PREPARSED;
return true;
}

View File

@ -24,7 +24,8 @@
/*--- C4ScriptHost ---*/
C4ScriptHost::C4ScriptHost()
C4ScriptHost::C4ScriptHost():
State(ASS_NONE) // not compiled
{
Script = NULL;
stringTable = 0;
@ -58,6 +59,8 @@ void C4ScriptHost::Clear()
// remove includes
Includes.clear();
Appends.clear();
// reset flags
State = ASS_NONE;
}
bool C4ScriptHost::Load(C4Group &hGroup, const char *szFilename,

View File

@ -23,6 +23,15 @@
#include <C4ComponentHost.h>
#include <C4Aul.h>
// aul script state
enum C4AulScriptState
{
ASS_NONE, // nothing
ASS_PREPARSED, // function list built; CodeSize set
ASS_LINKED, // includes and appends resolved
ASS_PARSED // byte code generated
};
// generic script host for objects
class C4ScriptHost : public C4AulScript
{
@ -35,6 +44,7 @@ public:
const char *szLanguage, C4LangStringTable *pLocalTable);
virtual bool LoadData(const char *szFilename, const char *szData, class C4LangStringTable *pLocalTable);
const char *GetScript() const { return Script.getData(); }
bool IsReady() { return State == ASS_PARSED; } // whether script calls may be done
virtual C4ScriptHost * GetScriptHost() { return this; }
std::list<C4ScriptHost *> SourceScripts;
protected:
@ -62,6 +72,7 @@ protected:
StdStrBuf Script; // script
C4ValueMapNames LocalNamed;
C4Set<C4Property> LocalValues;
C4AulScriptState State; // script state
friend class C4AulParse;
friend class C4AulScriptFunc;
friend class C4AulDebug;