mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 15:21:51 +00:00
- changed grammar for a class's default block to look and act like DECORATE, so that it can hook into the same property dispatcher.
This had been defined as a regular compound statement but in the context this will be used in, that makes very little sense, because all it can do is set some constant values. The most important thing here is that it doesn't provide an unnecessary learning curve to its users and doing it this way will not only ensure that but also avoid redundant documentation. To allow initialization of other user-defined properties it will require some extensions but that's a job for later and can just as easily be done in the current framework, rather than throwing everything out and start from zero.
This commit is contained in:
parent
e84d6a06d8
commit
2b9af0176c
3 changed files with 104 additions and 3 deletions
|
@ -814,6 +814,26 @@ static void PrintFuncDeclarator(FLispString &out, ZCC_TreeNode *node)
|
|||
out.Close();
|
||||
}
|
||||
|
||||
static void PrintFlagStmt(FLispString &out, ZCC_TreeNode *node)
|
||||
{
|
||||
auto dnode = (ZCC_FlagStmt *)node;
|
||||
out.Break();
|
||||
out.Open("flag-stmt");
|
||||
PrintNodes(out, dnode->name, false);
|
||||
out.AddInt(dnode->set);
|
||||
out.Close();
|
||||
}
|
||||
|
||||
static void PrintPropertyStmt(FLispString &out, ZCC_TreeNode *node)
|
||||
{
|
||||
auto dnode = (ZCC_PropertyStmt *)node;
|
||||
out.Break();
|
||||
out.Open("property-stmt");
|
||||
PrintNodes(out, dnode->Prop, false);
|
||||
PrintNodes(out, dnode->Values, false);
|
||||
out.Close();
|
||||
}
|
||||
|
||||
void (* const TreeNodePrinter[NUM_AST_NODE_TYPES])(FLispString &, ZCC_TreeNode *) =
|
||||
{
|
||||
PrintIdentifier,
|
||||
|
@ -863,7 +883,9 @@ void (* const TreeNodePrinter[NUM_AST_NODE_TYPES])(FLispString &, ZCC_TreeNode *
|
|||
PrintDeclarator,
|
||||
PrintVarDeclarator,
|
||||
PrintFuncDeclarator,
|
||||
PrintDefault
|
||||
PrintDefault,
|
||||
PrintFlagStmt,
|
||||
PrintPropertyStmt
|
||||
};
|
||||
|
||||
FString ZCC_PrintAST(ZCC_TreeNode *root)
|
||||
|
|
|
@ -493,8 +493,72 @@ state_call_params(X) ::= . { X = NULL; }
|
|||
state_call_params(X) ::= LPAREN func_expr_list(A) RPAREN. { X = A; /*X-overwrites-A*/ }
|
||||
|
||||
/* Definition of a default class instance. */
|
||||
%type default_def {ZCC_CompoundStmt *}
|
||||
default_def(X) ::= DEFAULT compound_statement(A). { X = A; /*X-overwrites-A*/ X->NodeType = AST_Default; }
|
||||
%type default_def {ZCC_Default *}
|
||||
%type default_statement_list{ZCC_Statement *}
|
||||
%type default_statement{ZCC_Statement *}
|
||||
|
||||
default_def(X) ::= DEFAULT LBRACE(T) RBRACE.
|
||||
{
|
||||
NEW_AST_NODE(Default,stmt,T);
|
||||
stmt->Content = NULL;
|
||||
X = stmt;
|
||||
}
|
||||
default_def(X) ::= DEFAULT LBRACE(T) default_statement_list(A) RBRACE.
|
||||
{
|
||||
NEW_AST_NODE(Default,stmt,T);
|
||||
stmt->Content = A;
|
||||
X = stmt;
|
||||
}
|
||||
default_def(X) ::= DEFAULT LBRACE(T) error RBRACE.
|
||||
{
|
||||
NEW_AST_NODE(Default,stmt,T);
|
||||
stmt->Content = NULL;
|
||||
X = stmt;
|
||||
}
|
||||
|
||||
default_statement_list(X) ::= default_statement(A).
|
||||
{
|
||||
X = A; /*X-overwrites-A*/
|
||||
}
|
||||
default_statement_list(X) ::= default_statement_list(X) default_statement(B).
|
||||
{
|
||||
SAFE_APPEND(X,B);
|
||||
}
|
||||
|
||||
|
||||
default_statement(X) ::= SEMICOLON. { X = NULL; }
|
||||
//default_statement(X) ::= assign_statement(A) SEMICOLON. { X = A; /*X-overwrites-A*/ }
|
||||
default_statement(X) ::= property_statement(A) SEMICOLON. { X = A; /*X-overwrites-A*/ }
|
||||
default_statement(X) ::= flag_statement(A). { X = A; /*X-overwrites-A*/ }
|
||||
|
||||
%type flag_statement { ZCC_FlagStmt *}
|
||||
|
||||
flag_statement(X) ::= ADD dottable_id(A).
|
||||
{
|
||||
NEW_AST_NODE(FlagStmt, type, A);
|
||||
type->set = true;
|
||||
type->name = A;
|
||||
X = type;
|
||||
}
|
||||
flag_statement(X) ::= SUB dottable_id(A).
|
||||
{
|
||||
NEW_AST_NODE(FlagStmt, type, A);
|
||||
type->set = false;
|
||||
type->name = A;
|
||||
X = type;
|
||||
}
|
||||
|
||||
%type property_statement{ZCC_PropertyStmt *}
|
||||
|
||||
property_statement(X) ::= dottable_id(A) expr_list(B).
|
||||
{
|
||||
NEW_AST_NODE(PropertyStmt,stmt,A);
|
||||
stmt->Prop = A;
|
||||
stmt->Values = B;
|
||||
X = stmt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Type names */
|
||||
%type type_name {ZCC_BasicType *}
|
||||
|
|
|
@ -94,6 +94,8 @@ enum EZCCTreeNodeType
|
|||
AST_VarDeclarator,
|
||||
AST_FuncDeclarator,
|
||||
AST_Default,
|
||||
AST_FlagStmt,
|
||||
AST_PropertyStmt,
|
||||
|
||||
NUM_AST_NODE_TYPES
|
||||
};
|
||||
|
@ -470,6 +472,19 @@ struct ZCC_Default : ZCC_CompoundStmt
|
|||
{
|
||||
};
|
||||
|
||||
struct ZCC_PropertyStmt : ZCC_Statement
|
||||
{
|
||||
ZCC_Identifier *Prop;
|
||||
ZCC_Expression *Values;
|
||||
};
|
||||
|
||||
|
||||
struct ZCC_FlagStmt : ZCC_Statement
|
||||
{
|
||||
ZCC_Identifier *name;
|
||||
bool set;
|
||||
};
|
||||
|
||||
typedef ZCC_ExprConstant *(*EvalConst1op)(ZCC_ExprConstant *);
|
||||
typedef ZCC_ExprConstant *(*EvalConst2op)(ZCC_ExprConstant *, ZCC_ExprConstant *, FSharedStringArena &);
|
||||
|
||||
|
|
Loading…
Reference in a new issue