mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-14 08:30:49 +00:00
Do not use GT, GTEQ, or NEQ operators in the AST.
- Since the VM doesn't directly support the GT, GTEQ, and NEQ comparisons, don't use them in the trees either. Instead, wrap them as LTEQ, LT, and EQEQ inside a BoolNot operator.
This commit is contained in:
parent
a0dbcb5d5b
commit
4bd5bf310b
1 changed files with 48 additions and 45 deletions
|
@ -34,8 +34,8 @@ static void SetNodeLine(ZCC_TreeNode *name, int line)
|
||||||
#define SAFE_APPEND(a,b) \
|
#define SAFE_APPEND(a,b) \
|
||||||
if (a == NULL) a = b; else a->AppendSibling(b);
|
if (a == NULL) a = b; else a->AppendSibling(b);
|
||||||
|
|
||||||
#define UNARY_EXPR(X,T) NEW_AST_NODE(ExprUnary, expr, X); expr->Operation = T; expr->Operand = X; expr->Type = NULL
|
#define UNARY_EXPR(X,T) NEW_AST_NODE(ExprUnary, expr1, X); expr1->Operation = T; expr1->Operand = X; expr1->Type = NULL
|
||||||
#define BINARY_EXPR(X,Y,T) NEW_AST_NODE(ExprBinary, expr, X); expr->Operation = T; expr->Type = NULL; expr->Left = X; expr->Right = Y
|
#define BINARY_EXPR(X,Y,T) NEW_AST_NODE(ExprBinary, expr2, X); expr2->Operation = T; expr2->Type = NULL; expr2->Left = X; expr2->Right = Y
|
||||||
|
|
||||||
#define NEW_INTCONST_NODE(name,type,val,tok) \
|
#define NEW_INTCONST_NODE(name,type,val,tok) \
|
||||||
NEW_AST_NODE(ExprConstant, name, tok); \
|
NEW_AST_NODE(ExprConstant, name, tok); \
|
||||||
|
@ -329,7 +329,7 @@ enum_def(X) ::= ENUM(T) IDENTIFIER(A) enum_type(B) LBRACE opt_enum_list(C) RBRAC
|
||||||
label->Type = NULL;
|
label->Type = NULL;
|
||||||
|
|
||||||
BINARY_EXPR(label, one, PEX_Add);
|
BINARY_EXPR(label, one, PEX_Add);
|
||||||
node->Value = expr;
|
node->Value = expr2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add a new terminating node, to indicate that the ConstantDefs for this enum are done.
|
// Add a new terminating node, to indicate that the ConstantDefs for this enum are done.
|
||||||
|
@ -858,17 +858,17 @@ primary(X) ::= primary(A) DOT IDENTIFIER(B). // Member access
|
||||||
primary(X) ::= primary(A) ADDADD. /* postfix++ */
|
primary(X) ::= primary(A) ADDADD. /* postfix++ */
|
||||||
{
|
{
|
||||||
UNARY_EXPR(A,PEX_PostInc);
|
UNARY_EXPR(A,PEX_PostInc);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
primary(X) ::= primary(A) SUBSUB. /* postfix-- */
|
primary(X) ::= primary(A) SUBSUB. /* postfix-- */
|
||||||
{
|
{
|
||||||
UNARY_EXPR(A,PEX_PostDec);
|
UNARY_EXPR(A,PEX_PostDec);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
primary(X) ::= SCOPE primary(B).
|
primary(X) ::= SCOPE primary(B).
|
||||||
{
|
{
|
||||||
BINARY_EXPR(NULL,B,PEX_Scope);
|
BINARY_EXPR(NULL,B,PEX_Scope);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----- Unary Expressions -----*/
|
/*----- Unary Expressions -----*/
|
||||||
|
@ -895,7 +895,7 @@ unary_expr(X) ::= SUB unary_expr(A). [UNARY]
|
||||||
else
|
else
|
||||||
{ // For everything else, create a new node and do the negation later.
|
{ // For everything else, create a new node and do the negation later.
|
||||||
UNARY_EXPR(A,PEX_Negate);
|
UNARY_EXPR(A,PEX_Negate);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unary_expr(X) ::= ADD unary_expr(A). [UNARY]
|
unary_expr(X) ::= ADD unary_expr(A). [UNARY]
|
||||||
|
@ -907,7 +907,7 @@ unary_expr(X) ::= ADD unary_expr(A). [UNARY]
|
||||||
if (A->Operation != PEX_ConstValue || (!con->Type->IsA(RUNTIME_CLASS(PInt)) && !con->Type->IsA(RUNTIME_CLASS(PFloat))))
|
if (A->Operation != PEX_ConstValue || (!con->Type->IsA(RUNTIME_CLASS(PInt)) && !con->Type->IsA(RUNTIME_CLASS(PFloat))))
|
||||||
{
|
{
|
||||||
UNARY_EXPR(A,PEX_AntiNegate);
|
UNARY_EXPR(A,PEX_AntiNegate);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -917,32 +917,32 @@ unary_expr(X) ::= ADD unary_expr(A). [UNARY]
|
||||||
unary_expr(X) ::= SUBSUB unary_expr(A). [UNARY]
|
unary_expr(X) ::= SUBSUB unary_expr(A). [UNARY]
|
||||||
{
|
{
|
||||||
UNARY_EXPR(A,PEX_PreDec);
|
UNARY_EXPR(A,PEX_PreDec);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
unary_expr(X) ::= ADDADD unary_expr(A). [UNARY]
|
unary_expr(X) ::= ADDADD unary_expr(A). [UNARY]
|
||||||
{
|
{
|
||||||
UNARY_EXPR(A,PEX_PreInc);
|
UNARY_EXPR(A,PEX_PreInc);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
unary_expr(X) ::= TILDE unary_expr(A). [UNARY]
|
unary_expr(X) ::= TILDE unary_expr(A). [UNARY]
|
||||||
{
|
{
|
||||||
UNARY_EXPR(A,PEX_BitNot);
|
UNARY_EXPR(A,PEX_BitNot);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
unary_expr(X) ::= BANG unary_expr(A). [UNARY]
|
unary_expr(X) ::= BANG unary_expr(A). [UNARY]
|
||||||
{
|
{
|
||||||
UNARY_EXPR(A,PEX_BoolNot);
|
UNARY_EXPR(A,PEX_BoolNot);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
unary_expr(X) ::= SIZEOF unary_expr(A). [UNARY]
|
unary_expr(X) ::= SIZEOF unary_expr(A). [UNARY]
|
||||||
{
|
{
|
||||||
UNARY_EXPR(A,PEX_SizeOf);
|
UNARY_EXPR(A,PEX_SizeOf);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
unary_expr(X) ::= ALIGNOF unary_expr(A). [UNARY]
|
unary_expr(X) ::= ALIGNOF unary_expr(A). [UNARY]
|
||||||
{
|
{
|
||||||
UNARY_EXPR(A,PEX_AlignOf);
|
UNARY_EXPR(A,PEX_AlignOf);
|
||||||
X = expr;
|
X = expr1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Due to parsing conflicts, C-style casting is not supported. You
|
/* Due to parsing conflicts, C-style casting is not supported. You
|
||||||
|
@ -958,136 +958,139 @@ expr(X) ::= unary_expr(A).
|
||||||
expr(X) ::= expr(A) ADD expr(B). /* a + b */
|
expr(X) ::= expr(A) ADD expr(B). /* a + b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_Add);
|
BINARY_EXPR(A,B,PEX_Add);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) SUB expr(B). /* a - b */
|
expr(X) ::= expr(A) SUB expr(B). /* a - b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_Sub);
|
BINARY_EXPR(A,B,PEX_Sub);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) MUL expr(B). /* a * b */
|
expr(X) ::= expr(A) MUL expr(B). /* a * b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_Mul);
|
BINARY_EXPR(A,B,PEX_Mul);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) DIV expr(B). /* a / b */
|
expr(X) ::= expr(A) DIV expr(B). /* a / b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_Div);
|
BINARY_EXPR(A,B,PEX_Div);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) MOD expr(B). /* a % b */
|
expr(X) ::= expr(A) MOD expr(B). /* a % b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_Mod);
|
BINARY_EXPR(A,B,PEX_Mod);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) POW expr(B). /* a ** b */
|
expr(X) ::= expr(A) POW expr(B). /* a ** b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_Pow);
|
BINARY_EXPR(A,B,PEX_Pow);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) CROSSPROD expr(B). /* a cross b */
|
expr(X) ::= expr(A) CROSSPROD expr(B). /* a cross b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_CrossProduct);
|
BINARY_EXPR(A,B,PEX_CrossProduct);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) DOTPROD expr(B). /* a dot b */
|
expr(X) ::= expr(A) DOTPROD expr(B). /* a dot b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_DotProduct);
|
BINARY_EXPR(A,B,PEX_DotProduct);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) LSH expr(B). /* a << b */
|
expr(X) ::= expr(A) LSH expr(B). /* a << b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_LeftShift);
|
BINARY_EXPR(A,B,PEX_LeftShift);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) RSH expr(B). /* a >> b */
|
expr(X) ::= expr(A) RSH expr(B). /* a >> b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_RightShift);
|
BINARY_EXPR(A,B,PEX_RightShift);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) DOTDOT expr(B). /* a .. b */
|
expr(X) ::= expr(A) DOTDOT expr(B). /* a .. b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_Concat);
|
BINARY_EXPR(A,B,PEX_Concat);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
expr(X) ::= expr(A) LT expr(B). /* a < b */
|
expr(X) ::= expr(A) LT expr(B). /* a < b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_LT);
|
BINARY_EXPR(A,B,PEX_LT);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) GT expr(B). /* a > b */
|
expr(X) ::= expr(A) GT expr(B). /* a > b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_GT);
|
BINARY_EXPR(A,B,PEX_LTEQ);
|
||||||
X = expr;
|
UNARY_EXPR(expr2,PEX_BoolNot);
|
||||||
|
X = expr1;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) LTEQ expr(B). /* a <= b */
|
expr(X) ::= expr(A) LTEQ expr(B). /* a <= b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_LTEQ);
|
BINARY_EXPR(A,B,PEX_LTEQ);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) GTEQ expr(B). /* a >= b */
|
expr(X) ::= expr(A) GTEQ expr(B). /* a >= b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_GTEQ);
|
BINARY_EXPR(A,B,PEX_LT);
|
||||||
X = expr;
|
UNARY_EXPR(expr1,PEX_BoolNot);
|
||||||
|
X = expr1;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) LTGTEQ expr(B). /* a <>= b */
|
expr(X) ::= expr(A) LTGTEQ expr(B). /* a <>= b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_LTGTEQ);
|
BINARY_EXPR(A,B,PEX_LTGTEQ);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) IS expr(B). /* a is b */
|
expr(X) ::= expr(A) IS expr(B). /* a is b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_Is);
|
BINARY_EXPR(A,B,PEX_Is);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
expr(X) ::= expr(A) EQEQ expr(B). /* a == b */
|
expr(X) ::= expr(A) EQEQ expr(B). /* a == b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_EQEQ);
|
BINARY_EXPR(A,B,PEX_EQEQ);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) NEQ expr(B). /* a != b */
|
expr(X) ::= expr(A) NEQ expr(B). /* a != b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_NEQ);
|
BINARY_EXPR(A,B,PEX_EQEQ);
|
||||||
X = expr;
|
UNARY_EXPR(expr2,PEX_BoolNot);
|
||||||
|
X = expr1;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) APPROXEQ expr(B). /* a ~== b */
|
expr(X) ::= expr(A) APPROXEQ expr(B). /* a ~== b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_APREQ);
|
BINARY_EXPR(A,B,PEX_APREQ);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
expr(X) ::= expr(A) AND expr(B). /* a & b */
|
expr(X) ::= expr(A) AND expr(B). /* a & b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_BitAnd);
|
BINARY_EXPR(A,B,PEX_BitAnd);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) XOR expr(B). /* a ^ b */
|
expr(X) ::= expr(A) XOR expr(B). /* a ^ b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_BitXor);
|
BINARY_EXPR(A,B,PEX_BitXor);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) OR expr(B). /* a | b */
|
expr(X) ::= expr(A) OR expr(B). /* a | b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_BitOr);
|
BINARY_EXPR(A,B,PEX_BitOr);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) ANDAND expr(B). /* a && b */
|
expr(X) ::= expr(A) ANDAND expr(B). /* a && b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_BoolAnd);
|
BINARY_EXPR(A,B,PEX_BoolAnd);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
expr(X) ::= expr(A) OROR expr(B). /* a || b */
|
expr(X) ::= expr(A) OROR expr(B). /* a || b */
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_BoolOr);
|
BINARY_EXPR(A,B,PEX_BoolOr);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
expr(X) ::= expr(A) SCOPE expr(B).
|
expr(X) ::= expr(A) SCOPE expr(B).
|
||||||
{
|
{
|
||||||
BINARY_EXPR(A,B,PEX_Scope);
|
BINARY_EXPR(A,B,PEX_Scope);
|
||||||
X = expr;
|
X = expr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----- Trinary Expression -----*/
|
/*----- Trinary Expression -----*/
|
||||||
|
@ -1337,7 +1340,7 @@ iteration_statement(X) ::= while_or_until(TY) LPAREN expr(EX) RPAREN statement(S
|
||||||
if (TY.Int == ZCC_UNTIL)
|
if (TY.Int == ZCC_UNTIL)
|
||||||
{ // Negate the loop condition
|
{ // Negate the loop condition
|
||||||
UNARY_EXPR(EX,PEX_BoolNot);
|
UNARY_EXPR(EX,PEX_BoolNot);
|
||||||
iter->LoopCondition = expr;
|
iter->LoopCondition = expr1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1355,7 +1358,7 @@ iteration_statement(X) ::= DO(T) statement(ST) while_or_until(TY) LPAREN expr(EX
|
||||||
if (TY.Int == ZCC_UNTIL)
|
if (TY.Int == ZCC_UNTIL)
|
||||||
{ // Negate the loop condition
|
{ // Negate the loop condition
|
||||||
UNARY_EXPR(EX,PEX_BoolNot);
|
UNARY_EXPR(EX,PEX_BoolNot);
|
||||||
iter->LoopCondition = expr;
|
iter->LoopCondition = expr1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue