- parser for states flags.

This commit is contained in:
Christoph Oelckers 2016-11-14 19:35:29 +01:00
parent 384f4fe7ce
commit 7bcd83f0c1
6 changed files with 87 additions and 43 deletions

View file

@ -52,6 +52,8 @@
//========================================================================== //==========================================================================
static bool UncompressZipLump(char *Cache, FileReader *Reader, int Method, int LumpSize, int CompressedSize, int GPFlags) static bool UncompressZipLump(char *Cache, FileReader *Reader, int Method, int LumpSize, int CompressedSize, int GPFlags)
{
try
{ {
switch (Method) switch (Method)
{ {
@ -99,6 +101,12 @@ static bool UncompressZipLump(char *Cache, FileReader *Reader, int Method, int L
assert(0); assert(0);
return false; return false;
} }
}
catch (CRecoverableError &err)
{
Printf("%s\n", err.GetMessage());
return false;
}
return true; return true;
} }

View file

@ -144,6 +144,22 @@ void ParseStates(FScanner &sc, PClassActor * actor, AActor * defaults, Baggage &
char lastsprite[5] = ""; char lastsprite[5] = "";
FxExpression *ScriptCode; FxExpression *ScriptCode;
FArgumentList *args = nullptr; FArgumentList *args = nullptr;
int flagdef = actor->DefaultStateUsage;
if (sc.CheckString("("))
{
flagdef = 0;
do
{
sc.MustGetString();
if (sc.Compare("Actor")) flagdef |= SUF_ACTOR;
else if (sc.Compare("Overlay")) flagdef |= SUF_OVERLAY;
else if (sc.Compare("Weapon")) flagdef |= SUF_WEAPON;
else if (sc.Compare("Item")) flagdef |= SUF_ITEM;
else sc.ScriptError("Unknown state block qualifier %s", sc.String);
} while (sc.CheckString(","));
sc.MustGetStringName(")");
}
sc.MustGetStringName ("{"); sc.MustGetStringName ("{");
sc.SetEscape(false); // disable escape sequences in the state parser sc.SetEscape(false); // disable escape sequences in the state parser
@ -151,6 +167,7 @@ void ParseStates(FScanner &sc, PClassActor * actor, AActor * defaults, Baggage &
{ {
ScriptCode = nullptr; ScriptCode = nullptr;
memset(&state,0,sizeof(state)); memset(&state,0,sizeof(state));
state.UseFlags = (uint8_t)flagdef;
statestring = ParseStateString(sc); statestring = ParseStateString(sc);
if (!statestring.CompareNoCase("GOTO")) if (!statestring.CompareNoCase("GOTO"))
{ {

View file

@ -63,7 +63,6 @@ class FStateDefinitions
FState *laststatebeforelabel; FState *laststatebeforelabel;
intptr_t lastlabel; intptr_t lastlabel;
TArray<FState> StateArray; TArray<FState> StateArray;
uint8_t UseType;
static FStateDefine *FindStateLabelInList(TArray<FStateDefine> &list, FName name, bool create); static FStateDefine *FindStateLabelInList(TArray<FStateDefine> &list, FName name, bool create);
static FStateLabels *CreateStateLabelList(TArray<FStateDefine> &statelist); static FStateLabels *CreateStateLabelList(TArray<FStateDefine> &statelist);
@ -75,11 +74,6 @@ class FStateDefinitions
FState *ResolveGotoLabel(AActor *actor, PClassActor *mytype, char *name); FState *ResolveGotoLabel(AActor *actor, PClassActor *mytype, char *name);
static void FixStatePointers(PClassActor *actor, TArray<FStateDefine> & list); static void FixStatePointers(PClassActor *actor, TArray<FStateDefine> & list);
void ResolveGotoLabels(PClassActor *actor, AActor *defaults, TArray<FStateDefine> & list); void ResolveGotoLabels(PClassActor *actor, AActor *defaults, TArray<FStateDefine> & list);
void SetUseType(int type)
{
UseType = uint8_t(type);
}
public: public:
FStateDefinitions() FStateDefinitions()

View file

@ -358,6 +358,7 @@ static void PrintStates(FLispString &out, ZCC_TreeNode *node)
ZCC_States *snode = (ZCC_States *)node; ZCC_States *snode = (ZCC_States *)node;
out.Break(); out.Break();
out.Open("states"); out.Open("states");
PrintNodes(out, snode->Flags, false, true);
PrintNodes(out, snode->Body, false, true); PrintNodes(out, snode->Body, false, true);
out.Close(); out.Close();
} }

View file

@ -418,14 +418,37 @@ enumerator(X) ::= IDENTIFIER(A) EQ expr(B). /* Expression must be constant. */
%type state_call_params {ZCC_FuncParm *} %type state_call_params {ZCC_FuncParm *}
%type state_opts {StateOpts} %type state_opts {StateOpts}
%type states_opts { ZCC_Identifier *}
%type states_opt { ZCC_Identifier *}
states_def(X) ::= STATES(T) scanner_mode LBRACE states_body(A) RBRACE. states_def(X) ::= STATES(T) scanner_mode LBRACE states_body(A) RBRACE.
states_def(X) ::= STATES(T) states_opts(B) scanner_mode LBRACE states_body(A) RBRACE.
{ {
NEW_AST_NODE(States,def,T); NEW_AST_NODE(States,def,T);
def->Flags = B;
def->Body = A; def->Body = A;
X = def; X = def;
} }
states_opts(X) ::= . { X = nullptr; }
states_opts(X) ::= LPAREN states_opt(A) RPAREN. { X = A; /*X-overwrites-A*/ }
states_opt(X) ::= IDENTIFIER(A).
{
NEW_AST_NODE(Identifier,id,A);
id->Id = A.Name();
X = id;
}
states_opt(X) ::= states_opt(A) COMMA IDENTIFIER(B).
{
NEW_AST_NODE(Identifier,id,B);
id->Id = B.Name();
X = A; /*X-overwrites-A*/
X->AppendSibling(id);
}
/* We use a special scanner mode to allow for sprite names and frame characters /* We use a special scanner mode to allow for sprite names and frame characters
* to not be quoted even if they contain special characters. The scanner_mode * to not be quoted even if they contain special characters. The scanner_mode
* nonterminal is used to enter this mode. The scanner automatically leaves it * nonterminal is used to enter this mode. The scanner automatically leaves it

View file

@ -228,6 +228,7 @@ struct ZCC_EnumTerminator : ZCC_TreeNode
struct ZCC_States : ZCC_TreeNode struct ZCC_States : ZCC_TreeNode
{ {
struct ZCC_StatePart *Body; struct ZCC_StatePart *Body;
ZCC_Identifier *Flags;
}; };
struct ZCC_StatePart : ZCC_TreeNode struct ZCC_StatePart : ZCC_TreeNode