Bugfixes courtesy of Blub:
Fixed new line counting in multi-line comments. Fixed unary operators to favour a single term, except for the unary not operator. Added: Unary not operator warns whenever it consumes more than a single term. Added more ways to optimise logic (a+0 = a). git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3232 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
2f848fa7b0
commit
2b58210060
2 changed files with 267 additions and 117 deletions
|
@ -584,6 +584,7 @@ pbool OpAssignedTo(QCC_def_t *v, unsigned int op)
|
||||||
#undef ASSOC_RIGHT_RESULT
|
#undef ASSOC_RIGHT_RESULT
|
||||||
|
|
||||||
#define TOP_PRIORITY 7
|
#define TOP_PRIORITY 7
|
||||||
|
#define UNARY_PRIORITY 1
|
||||||
#define NOT_PRIORITY 5
|
#define NOT_PRIORITY 5
|
||||||
//conditional and/or
|
//conditional and/or
|
||||||
#define CONDITION_PRIORITY 7
|
#define CONDITION_PRIORITY 7
|
||||||
|
@ -1050,7 +1051,9 @@ pbool QCC_OPCodeValid(QCC_opcode_t *op)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCC_def_t *QCC_PR_Expression (int priority, pbool allowcomma);
|
#define EXPR_WARN_ABOVE_1 2
|
||||||
|
#define EXPR_DISALLOW_COMMA 4
|
||||||
|
QCC_def_t *QCC_PR_Expression (int priority, int exprflags);
|
||||||
int QCC_AStatementJumpsTo(int targ, int first, int last);
|
int QCC_AStatementJumpsTo(int targ, int first, int last);
|
||||||
pbool QCC_StatementIsAJump(int stnum, int notifdest);
|
pbool QCC_StatementIsAJump(int stnum, int notifdest);
|
||||||
|
|
||||||
|
@ -1630,8 +1633,13 @@ QCC_def_t *QCC_PR_Statement ( QCC_opcode_t *op, QCC_def_t *var_a, QCC_def_t *var
|
||||||
}
|
}
|
||||||
|
|
||||||
//maths operators
|
//maths operators
|
||||||
if (opt_constantarithmatic && (var_a && var_a->constant) && (var_b && var_b->constant))
|
if (opt_constantarithmatic)
|
||||||
{
|
{
|
||||||
|
if (var_a && var_a->constant)
|
||||||
|
{
|
||||||
|
if (var_b && var_b->constant)
|
||||||
|
{
|
||||||
|
//both are constants
|
||||||
switch (op - pr_opcodes) //improve some of the maths.
|
switch (op - pr_opcodes) //improve some of the maths.
|
||||||
{
|
{
|
||||||
case OP_BITOR:
|
case OP_BITOR:
|
||||||
|
@ -1705,6 +1713,142 @@ QCC_def_t *QCC_PR_Statement ( QCC_opcode_t *op, QCC_def_t *var_a, QCC_def_t *var
|
||||||
G_FLOAT(var_a->ofs+2) - G_FLOAT(var_b->ofs+2));
|
G_FLOAT(var_a->ofs+2) - G_FLOAT(var_b->ofs+2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//a is const, b is not
|
||||||
|
switch (op - pr_opcodes)
|
||||||
|
{
|
||||||
|
case OP_BITOR:
|
||||||
|
case OP_OR:
|
||||||
|
case OP_ADD_F:
|
||||||
|
if (G_FLOAT(var_a->ofs) == 0)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_b);
|
||||||
|
return var_b;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_MUL_F:
|
||||||
|
if (G_FLOAT(var_a->ofs) == 1)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_b);
|
||||||
|
return var_b;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_BITAND:
|
||||||
|
case OP_AND:
|
||||||
|
if (G_FLOAT(var_a->ofs) != 0)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_b);
|
||||||
|
return var_b;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OP_BITOR_I:
|
||||||
|
case OP_OR_I:
|
||||||
|
case OP_ADD_I:
|
||||||
|
if (G_INT(var_a->ofs) == 0)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_b);
|
||||||
|
return var_b;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_MUL_I:
|
||||||
|
if (G_INT(var_a->ofs) == 1)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_b);
|
||||||
|
return var_b;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_BITAND_I:
|
||||||
|
case OP_AND_I:
|
||||||
|
if (G_INT(var_a->ofs) != 0)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_b);
|
||||||
|
return var_b;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (var_b && var_b->constant)
|
||||||
|
{
|
||||||
|
//b is const, a is not
|
||||||
|
switch (op - pr_opcodes)
|
||||||
|
{
|
||||||
|
case OP_BITOR:
|
||||||
|
case OP_OR:
|
||||||
|
case OP_SUB_F:
|
||||||
|
case OP_ADD_F:
|
||||||
|
if (G_FLOAT(var_b->ofs) == 0)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_a);
|
||||||
|
return var_a;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_DIV_F:
|
||||||
|
case OP_MUL_F:
|
||||||
|
if (G_FLOAT(var_b->ofs) == 1)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_a);
|
||||||
|
return var_a;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//no bitand_f, I don't trust the casts
|
||||||
|
case OP_AND:
|
||||||
|
if (G_FLOAT(var_b->ofs) != 0)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_a);
|
||||||
|
return var_a;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OP_BITOR_I:
|
||||||
|
case OP_OR_I:
|
||||||
|
case OP_SUB_I:
|
||||||
|
case OP_ADD_I:
|
||||||
|
if (G_INT(var_b->ofs) == 0)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_a);
|
||||||
|
return var_a;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_DIV_I:
|
||||||
|
case OP_MUL_I:
|
||||||
|
if (G_INT(var_b->ofs) == 1)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_a);
|
||||||
|
return var_a;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OP_BITAND_I:
|
||||||
|
if (G_INT(var_b->ofs) == 0xffffffff)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_a);
|
||||||
|
return var_a;
|
||||||
|
}
|
||||||
|
case OP_AND_I:
|
||||||
|
if (G_INT(var_b->ofs) != 0)
|
||||||
|
{
|
||||||
|
optres_constantarithmatic++;
|
||||||
|
QCC_UnFreeTemp(var_a);
|
||||||
|
return var_a;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (op - pr_opcodes)
|
switch (op - pr_opcodes)
|
||||||
{
|
{
|
||||||
|
@ -2840,13 +2984,13 @@ QCC_def_t *QCC_PR_ParseFunctionCall (QCC_def_t *func) //warning, the func could
|
||||||
func->references++;
|
func->references++;
|
||||||
if (!QCC_PR_CheckToken(")"))
|
if (!QCC_PR_CheckToken(")"))
|
||||||
{
|
{
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, false);
|
e = QCC_PR_Expression (TOP_PRIORITY, EXPR_DISALLOW_COMMA);
|
||||||
if (e->type->type != ev_float)
|
if (e->type->type != ev_float)
|
||||||
QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i", 1);
|
QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i", 1);
|
||||||
if (!QCC_PR_CheckToken(")"))
|
if (!QCC_PR_CheckToken(")"))
|
||||||
{
|
{
|
||||||
QCC_PR_Expect(",");
|
QCC_PR_Expect(",");
|
||||||
d = QCC_PR_Expression (TOP_PRIORITY, false);
|
d = QCC_PR_Expression (TOP_PRIORITY, EXPR_DISALLOW_COMMA);
|
||||||
if (d->type->type != ev_float)
|
if (d->type->type != ev_float)
|
||||||
QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i", 2);
|
QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i", 2);
|
||||||
QCC_PR_Expect(")");
|
QCC_PR_Expect(")");
|
||||||
|
@ -2970,13 +3114,13 @@ QCC_def_t *QCC_PR_ParseFunctionCall (QCC_def_t *func) //warning, the func could
|
||||||
func->references++;
|
func->references++;
|
||||||
if (!QCC_PR_CheckToken(")"))
|
if (!QCC_PR_CheckToken(")"))
|
||||||
{
|
{
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, false);
|
e = QCC_PR_Expression (TOP_PRIORITY, EXPR_DISALLOW_COMMA);
|
||||||
if (e->type->type != ev_vector)
|
if (e->type->type != ev_vector)
|
||||||
QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i", 1);
|
QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i", 1);
|
||||||
if (!QCC_PR_CheckToken(")"))
|
if (!QCC_PR_CheckToken(")"))
|
||||||
{
|
{
|
||||||
QCC_PR_Expect(",");
|
QCC_PR_Expect(",");
|
||||||
d = QCC_PR_Expression (TOP_PRIORITY, false);
|
d = QCC_PR_Expression (TOP_PRIORITY, EXPR_DISALLOW_COMMA);
|
||||||
if (d->type->type != ev_vector)
|
if (d->type->type != ev_vector)
|
||||||
QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i", 2);
|
QCC_PR_ParseErrorPrintDef (ERR_TYPEMISMATCHPARM, func, "type mismatch on parm %i", 2);
|
||||||
QCC_PR_Expect(")");
|
QCC_PR_Expect(")");
|
||||||
|
@ -3222,7 +3366,7 @@ QCC_def_t *QCC_PR_ParseFunctionCall (QCC_def_t *func) //warning, the func could
|
||||||
//t = (a/%1) / (nextent(world)/%1)
|
//t = (a/%1) / (nextent(world)/%1)
|
||||||
//a/%1 does a (int)entity to float conversion type thing
|
//a/%1 does a (int)entity to float conversion type thing
|
||||||
|
|
||||||
e = QCC_PR_Expression(TOP_PRIORITY, false);
|
e = QCC_PR_Expression(TOP_PRIORITY, EXPR_DISALLOW_COMMA);
|
||||||
QCC_PR_Expect(")");
|
QCC_PR_Expect(")");
|
||||||
e = QCC_PR_Statement(&pr_opcodes[OP_DIV_F], e, QCC_MakeIntDef(1), (QCC_dstatement_t **)0xffffffff);
|
e = QCC_PR_Statement(&pr_opcodes[OP_DIV_F], e, QCC_MakeIntDef(1), (QCC_dstatement_t **)0xffffffff);
|
||||||
|
|
||||||
|
@ -3305,7 +3449,7 @@ QCC_def_t *QCC_PR_ParseFunctionCall (QCC_def_t *func) //warning, the func could
|
||||||
QCC_PR_Lex();
|
QCC_PR_Lex();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, false);
|
e = QCC_PR_Expression (TOP_PRIORITY, EXPR_DISALLOW_COMMA);
|
||||||
|
|
||||||
if (arg == 0 && func->name)
|
if (arg == 0 && func->name)
|
||||||
{
|
{
|
||||||
|
@ -3941,7 +4085,7 @@ reloop:
|
||||||
{
|
{
|
||||||
numstatements--; //remove the last statement
|
numstatements--; //remove the last statement
|
||||||
|
|
||||||
nd = QCC_PR_Expression (TOP_PRIORITY, true);
|
nd = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
QCC_PR_Expect("]");
|
QCC_PR_Expect("]");
|
||||||
|
|
||||||
if (d->type->size != 1) //we need to multiply it to find the offset.
|
if (d->type->size != 1) //we need to multiply it to find the offset.
|
||||||
|
@ -3981,7 +4125,7 @@ reloop:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ao = QCC_PR_Expression (TOP_PRIORITY, true);
|
ao = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
QCC_PR_Expect("]");
|
QCC_PR_Expect("]");
|
||||||
|
|
||||||
if (QCC_OPCodeValid(&pr_opcodes[OP_LOADA_F]) && d->type->size != 1) //we need to multiply it to find the offset.
|
if (QCC_OPCodeValid(&pr_opcodes[OP_LOADA_F]) && d->type->size != 1) //we need to multiply it to find the offset.
|
||||||
|
@ -4057,7 +4201,7 @@ reloop:
|
||||||
QCC_PR_ParseError(0, "Scoped array without specific engine support");
|
QCC_PR_ParseError(0, "Scoped array without specific engine support");
|
||||||
|
|
||||||
funcretr = QCC_PR_GetDef(type_function, qcva("ArraySet*%s", d->name), NULL, true, 1, false);
|
funcretr = QCC_PR_GetDef(type_function, qcva("ArraySet*%s", d->name), NULL, true, 1, false);
|
||||||
nd = QCC_PR_Expression(TOP_PRIORITY, true);
|
nd = QCC_PR_Expression(TOP_PRIORITY, 0);
|
||||||
if (nd->type->type != d->type->type)
|
if (nd->type->type != d->type->type)
|
||||||
QCC_PR_ParseErrorPrintDef(ERR_TYPEMISMATCH, d, "Type Mismatch on array assignment");
|
QCC_PR_ParseErrorPrintDef(ERR_TYPEMISMATCH, d, "Type Mismatch on array assignment");
|
||||||
|
|
||||||
|
@ -4114,7 +4258,7 @@ reloop:
|
||||||
|
|
||||||
funcretr = QCC_PR_GetDef(type_function, qcva("ArraySet*%s", d->name), NULL, true, 1, false);
|
funcretr = QCC_PR_GetDef(type_function, qcva("ArraySet*%s", d->name), NULL, true, 1, false);
|
||||||
|
|
||||||
nd = QCC_PR_Expression(TOP_PRIORITY, true);
|
nd = QCC_PR_Expression(TOP_PRIORITY, 0);
|
||||||
if (nd->type->type != d->type->type)
|
if (nd->type->type != d->type->type)
|
||||||
QCC_PR_ParseErrorPrintDef(ERR_TYPEMISMATCH, d, "Type Mismatch on array assignment");
|
QCC_PR_ParseErrorPrintDef(ERR_TYPEMISMATCH, d, "Type Mismatch on array assignment");
|
||||||
|
|
||||||
|
@ -4393,7 +4537,7 @@ reloop:
|
||||||
QCC_def_t *field;
|
QCC_def_t *field;
|
||||||
if (QCC_PR_CheckToken("("))
|
if (QCC_PR_CheckToken("("))
|
||||||
{
|
{
|
||||||
field = QCC_PR_Expression(TOP_PRIORITY, true);
|
field = QCC_PR_Expression(TOP_PRIORITY, 0);
|
||||||
QCC_PR_Expect(")");
|
QCC_PR_Expect(")");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -4515,7 +4659,7 @@ QCC_def_t *QCC_PR_Term (void)
|
||||||
|
|
||||||
if (QCC_PR_CheckToken ("!"))
|
if (QCC_PR_CheckToken ("!"))
|
||||||
{
|
{
|
||||||
e = QCC_PR_Expression (NOT_PRIORITY, false);
|
e = QCC_PR_Expression (NOT_PRIORITY, EXPR_DISALLOW_COMMA|EXPR_WARN_ABOVE_1);
|
||||||
t = e->type->type;
|
t = e->type->type;
|
||||||
if (t == ev_float)
|
if (t == ev_float)
|
||||||
e2 = QCC_PR_Statement (&pr_opcodes[OP_NOT_F], e, 0, NULL);
|
e2 = QCC_PR_Statement (&pr_opcodes[OP_NOT_F], e, 0, NULL);
|
||||||
|
@ -4542,7 +4686,7 @@ QCC_def_t *QCC_PR_Term (void)
|
||||||
else if (QCC_PR_CheckToken ("&"))
|
else if (QCC_PR_CheckToken ("&"))
|
||||||
{
|
{
|
||||||
int st = numstatements;
|
int st = numstatements;
|
||||||
e = QCC_PR_Expression (NOT_PRIORITY, false);
|
e = QCC_PR_Expression (UNARY_PRIORITY, 0);
|
||||||
t = e->type->type;
|
t = e->type->type;
|
||||||
|
|
||||||
if (st != numstatements)
|
if (st != numstatements)
|
||||||
|
@ -4572,7 +4716,7 @@ QCC_def_t *QCC_PR_Term (void)
|
||||||
}
|
}
|
||||||
else if (QCC_PR_CheckToken ("*"))
|
else if (QCC_PR_CheckToken ("*"))
|
||||||
{
|
{
|
||||||
e = QCC_PR_Expression (NOT_PRIORITY, false);
|
e = QCC_PR_Expression (UNARY_PRIORITY, 0);
|
||||||
t = e->type->type;
|
t = e->type->type;
|
||||||
|
|
||||||
if (t != ev_pointer)
|
if (t != ev_pointer)
|
||||||
|
@ -4616,7 +4760,7 @@ QCC_def_t *QCC_PR_Term (void)
|
||||||
}
|
}
|
||||||
else if (QCC_PR_CheckToken ("-"))
|
else if (QCC_PR_CheckToken ("-"))
|
||||||
{
|
{
|
||||||
e = QCC_PR_Expression (NOT_PRIORITY, false);
|
e = QCC_PR_Expression (UNARY_PRIORITY, 0);
|
||||||
|
|
||||||
switch(e->type->type)
|
switch(e->type->type)
|
||||||
{
|
{
|
||||||
|
@ -4635,7 +4779,7 @@ QCC_def_t *QCC_PR_Term (void)
|
||||||
}
|
}
|
||||||
else if (QCC_PR_CheckToken ("+"))
|
else if (QCC_PR_CheckToken ("+"))
|
||||||
{
|
{
|
||||||
e = QCC_PR_Expression (NOT_PRIORITY, false);
|
e = QCC_PR_Expression (UNARY_PRIORITY, 0);
|
||||||
|
|
||||||
switch(e->type->type)
|
switch(e->type->type)
|
||||||
{
|
{
|
||||||
|
@ -4720,7 +4864,7 @@ QCC_def_t *QCC_PR_Term (void)
|
||||||
{
|
{
|
||||||
pbool oldcond = conditional;
|
pbool oldcond = conditional;
|
||||||
conditional = conditional?2:0;
|
conditional = conditional?2:0;
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, false);
|
e = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
QCC_PR_Expect (")");
|
QCC_PR_Expect (")");
|
||||||
conditional = oldcond;
|
conditional = oldcond;
|
||||||
}
|
}
|
||||||
|
@ -4765,7 +4909,7 @@ PR_Expression
|
||||||
==============
|
==============
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QCC_def_t *QCC_PR_Expression (int priority, pbool allowcomma)
|
QCC_def_t *QCC_PR_Expression (int priority, int exprflags)
|
||||||
{
|
{
|
||||||
QCC_dstatement32_t *st;
|
QCC_dstatement32_t *st;
|
||||||
QCC_opcode_t *op, *oldop;
|
QCC_opcode_t *op, *oldop;
|
||||||
|
@ -4781,7 +4925,7 @@ QCC_def_t *QCC_PR_Expression (int priority, pbool allowcomma)
|
||||||
if (priority == 0)
|
if (priority == 0)
|
||||||
return QCC_PR_Term ();
|
return QCC_PR_Term ();
|
||||||
|
|
||||||
e = QCC_PR_Expression (priority-1, allowcomma);
|
e = QCC_PR_Expression (priority-1, exprflags);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
@ -4796,18 +4940,21 @@ QCC_def_t *QCC_PR_Expression (int priority, pbool allowcomma)
|
||||||
{
|
{
|
||||||
QCC_dstatement32_t *fromj, *elsej;
|
QCC_dstatement32_t *fromj, *elsej;
|
||||||
QCC_FreeTemp(QCC_PR_Statement(&pr_opcodes[OP_IFNOT], e, NULL, &fromj));
|
QCC_FreeTemp(QCC_PR_Statement(&pr_opcodes[OP_IFNOT], e, NULL, &fromj));
|
||||||
e = QCC_PR_Expression(TOP_PRIORITY, true);
|
e = QCC_PR_Expression(TOP_PRIORITY, 0);
|
||||||
e2 = QCC_GetTemp(e->type);
|
e2 = QCC_GetTemp(e->type);
|
||||||
QCC_PR_Statement(&pr_opcodes[(e2->type->size>=3)?OP_STORE_V:OP_STORE_F], e, e2, NULL);
|
QCC_FreeTemp(QCC_PR_Statement(&pr_opcodes[(e2->type->size>=3)?OP_STORE_V:OP_STORE_F], e, e2, NULL));
|
||||||
|
//e2 can be stomped upon until its reused anyway
|
||||||
|
QCC_UnFreeTemp(e2);
|
||||||
|
|
||||||
QCC_PR_Expect(":");
|
QCC_PR_Expect(":");
|
||||||
QCC_PR_Statement(&pr_opcodes[OP_GOTO], NULL, NULL, &elsej);
|
QCC_PR_Statement(&pr_opcodes[OP_GOTO], NULL, NULL, &elsej);
|
||||||
fromj->b = &statements[numstatements] - fromj;
|
fromj->b = &statements[numstatements] - fromj;
|
||||||
e = QCC_PR_Expression(TOP_PRIORITY, true);
|
e = QCC_PR_Expression(TOP_PRIORITY, 0);
|
||||||
|
|
||||||
if (typecmp(e->type, e2->type) != 0)
|
if (typecmp(e->type, e2->type) != 0)
|
||||||
QCC_PR_ParseError(0, "Ternary operator with mismatching types\n");
|
QCC_PR_ParseError(0, "Ternary operator with mismatching types\n");
|
||||||
QCC_PR_Statement(&pr_opcodes[(e2->type->size>=3)?OP_STORE_V:OP_STORE_F], e, e2, NULL);
|
QCC_FreeTemp(QCC_PR_Statement(&pr_opcodes[(e2->type->size>=3)?OP_STORE_V:OP_STORE_F], e, e2, NULL));
|
||||||
|
QCC_UnFreeTemp(e2);
|
||||||
|
|
||||||
elsej->a = &statements[numstatements] - elsej;
|
elsej->a = &statements[numstatements] - elsej;
|
||||||
return e2;
|
return e2;
|
||||||
|
@ -4868,12 +5015,12 @@ QCC_def_t *QCC_PR_Expression (int priority, pbool allowcomma)
|
||||||
e->type = type_string;
|
e->type = type_string;
|
||||||
|
|
||||||
//now we want to make sure that string = float can't work without it being a dereferenced pointer. (we don't want to allow storep_c without dereferece)
|
//now we want to make sure that string = float can't work without it being a dereferenced pointer. (we don't want to allow storep_c without dereferece)
|
||||||
e2 = QCC_PR_Expression (priority, allowcomma);
|
e2 = QCC_PR_Expression (priority, exprflags);
|
||||||
if (e2->type->type == ev_float)
|
if (e2->type->type == ev_float)
|
||||||
op = &pr_opcodes[OP_STOREP_C];
|
op = &pr_opcodes[OP_STOREP_C];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
e2 = QCC_PR_Expression (priority, allowcomma);
|
e2 = QCC_PR_Expression (priority, exprflags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -4887,7 +5034,7 @@ QCC_def_t *QCC_PR_Expression (int priority, pbool allowcomma)
|
||||||
QCC_PR_Statement3(&pr_opcodes[OP_IF], e, NULL, NULL, false);
|
QCC_PR_Statement3(&pr_opcodes[OP_IF], e, NULL, NULL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
e2 = QCC_PR_Expression (priority-1, allowcomma);
|
e2 = QCC_PR_Expression (priority-1, exprflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
// type check
|
// type check
|
||||||
|
@ -5031,6 +5178,9 @@ QCC_def_t *QCC_PR_Expression (int priority, pbool allowcomma)
|
||||||
if (type_c != ev_void/* && type_c != ev_string*/) // field access gets type from field
|
if (type_c != ev_void/* && type_c != ev_string*/) // field access gets type from field
|
||||||
e->type = e2->type->aux_type;
|
e->type = e2->type->aux_type;
|
||||||
|
|
||||||
|
if (priority > 1 && exprflags & EXPR_WARN_ABOVE_1)
|
||||||
|
QCC_PR_ParseWarning(0, "You may wish to add brackets after that ! operator");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!op)
|
if (!op)
|
||||||
|
@ -5170,10 +5320,10 @@ QCC_def_t *QCC_PR_Expression (int priority, pbool allowcomma)
|
||||||
if (e == NULL)
|
if (e == NULL)
|
||||||
QCC_PR_ParseError(ERR_INTERNAL, "e == null");
|
QCC_PR_ParseError(ERR_INTERNAL, "e == null");
|
||||||
|
|
||||||
if (allowcomma && priority == TOP_PRIORITY && QCC_PR_CheckToken (","))
|
if (!(exprflags&EXPR_DISALLOW_COMMA) && priority == TOP_PRIORITY && QCC_PR_CheckToken (","))
|
||||||
{
|
{
|
||||||
QCC_FreeTemp(e);
|
QCC_FreeTemp(e);
|
||||||
return QCC_PR_Expression(TOP_PRIORITY, true);
|
return QCC_PR_Expression(TOP_PRIORITY, exprflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
|
@ -5268,7 +5418,7 @@ void QCC_PR_ParseStatement (void)
|
||||||
QCC_FreeTemp(QCC_PR_Statement (&pr_opcodes[OP_RETURN], 0, 0, NULL));
|
QCC_FreeTemp(QCC_PR_Statement (&pr_opcodes[OP_RETURN], 0, 0, NULL));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, true);
|
e = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
e2 = QCC_SupplyConversion(e, pr_scope->type->aux_type->type);
|
e2 = QCC_SupplyConversion(e, pr_scope->type->aux_type->type);
|
||||||
if (e != e2)
|
if (e != e2)
|
||||||
{
|
{
|
||||||
|
@ -5296,7 +5446,7 @@ void QCC_PR_ParseStatement (void)
|
||||||
QCC_PR_Expect ("(");
|
QCC_PR_Expect ("(");
|
||||||
patch2 = &statements[numstatements];
|
patch2 = &statements[numstatements];
|
||||||
conditional = 1;
|
conditional = 1;
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, true);
|
e = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
conditional = 0;
|
conditional = 0;
|
||||||
if (((e->constant && !e->temp) || !STRCMP(e->name, "IMMEDIATE")) && opt_compound_jumps)
|
if (((e->constant && !e->temp) || !STRCMP(e->name, "IMMEDIATE")) && opt_compound_jumps)
|
||||||
{
|
{
|
||||||
|
@ -5374,7 +5524,7 @@ void QCC_PR_ParseStatement (void)
|
||||||
QCC_PR_Expect("(");
|
QCC_PR_Expect("(");
|
||||||
if (!QCC_PR_CheckToken(";"))
|
if (!QCC_PR_CheckToken(";"))
|
||||||
{
|
{
|
||||||
QCC_FreeTemp(QCC_PR_Expression(TOP_PRIORITY, true));
|
QCC_FreeTemp(QCC_PR_Expression(TOP_PRIORITY, 0));
|
||||||
QCC_PR_Expect(";");
|
QCC_PR_Expect(";");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5382,7 +5532,7 @@ void QCC_PR_ParseStatement (void)
|
||||||
if (!QCC_PR_CheckToken(";"))
|
if (!QCC_PR_CheckToken(";"))
|
||||||
{
|
{
|
||||||
conditional = 1;
|
conditional = 1;
|
||||||
e = QCC_PR_Expression(TOP_PRIORITY, true);
|
e = QCC_PR_Expression(TOP_PRIORITY, 0);
|
||||||
conditional = 0;
|
conditional = 0;
|
||||||
QCC_PR_Expect(";");
|
QCC_PR_Expect(";");
|
||||||
}
|
}
|
||||||
|
@ -5392,7 +5542,7 @@ void QCC_PR_ParseStatement (void)
|
||||||
if (!QCC_PR_CheckToken(")"))
|
if (!QCC_PR_CheckToken(")"))
|
||||||
{
|
{
|
||||||
old_numstatements = numstatements;
|
old_numstatements = numstatements;
|
||||||
QCC_FreeTemp(QCC_PR_Expression(TOP_PRIORITY, true));
|
QCC_FreeTemp(QCC_PR_Expression(TOP_PRIORITY, 0));
|
||||||
|
|
||||||
numtemp = numstatements - old_numstatements;
|
numtemp = numstatements - old_numstatements;
|
||||||
if (numtemp > sizeof(linenum)/sizeof(linenum[0]))
|
if (numtemp > sizeof(linenum)/sizeof(linenum[0]))
|
||||||
|
@ -5456,7 +5606,7 @@ void QCC_PR_ParseStatement (void)
|
||||||
QCC_PR_Expect ("while");
|
QCC_PR_Expect ("while");
|
||||||
QCC_PR_Expect ("(");
|
QCC_PR_Expect ("(");
|
||||||
conditional = 1;
|
conditional = 1;
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, true);
|
e = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
conditional = 0;
|
conditional = 0;
|
||||||
|
|
||||||
if (e->constant && !e->temp)
|
if (e->constant && !e->temp)
|
||||||
|
@ -5558,7 +5708,7 @@ void QCC_PR_ParseStatement (void)
|
||||||
|
|
||||||
QCC_PR_Expect ("(");
|
QCC_PR_Expect ("(");
|
||||||
conditional = 1;
|
conditional = 1;
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, true);
|
e = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
conditional = 0;
|
conditional = 0;
|
||||||
|
|
||||||
// negate = negate != 0;
|
// negate = negate != 0;
|
||||||
|
@ -5634,7 +5784,7 @@ void QCC_PR_ParseStatement (void)
|
||||||
QCC_PR_Expect ("(");
|
QCC_PR_Expect ("(");
|
||||||
|
|
||||||
conditional = 1;
|
conditional = 1;
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, true);
|
e = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
conditional = 0;
|
conditional = 0;
|
||||||
|
|
||||||
if (e == &def_ret)
|
if (e == &def_ret)
|
||||||
|
@ -5989,10 +6139,10 @@ void QCC_PR_ParseStatement (void)
|
||||||
pr_casesdef2 = realloc(pr_casesdef2, sizeof(*pr_casesdef2)*max_cases);
|
pr_casesdef2 = realloc(pr_casesdef2, sizeof(*pr_casesdef2)*max_cases);
|
||||||
}
|
}
|
||||||
pr_cases[num_cases] = numstatements;
|
pr_cases[num_cases] = numstatements;
|
||||||
pr_casesdef[num_cases] = QCC_PR_Expression (TOP_PRIORITY, false);
|
pr_casesdef[num_cases] = QCC_PR_Expression (TOP_PRIORITY, EXPR_DISALLOW_COMMA);
|
||||||
if (QCC_PR_CheckToken(".."))
|
if (QCC_PR_CheckToken(".."))
|
||||||
{
|
{
|
||||||
pr_casesdef2[num_cases] = QCC_PR_Expression (TOP_PRIORITY, false);
|
pr_casesdef2[num_cases] = QCC_PR_Expression (TOP_PRIORITY, EXPR_DISALLOW_COMMA);
|
||||||
if (pr_casesdef[num_cases]->constant && pr_casesdef2[num_cases]->constant &&
|
if (pr_casesdef[num_cases]->constant && pr_casesdef2[num_cases]->constant &&
|
||||||
!pr_casesdef[num_cases]->temp && !pr_casesdef2[num_cases]->temp)
|
!pr_casesdef[num_cases]->temp && !pr_casesdef2[num_cases]->temp)
|
||||||
if (G_FLOAT(pr_casesdef[num_cases]->ofs) >= G_FLOAT(pr_casesdef2[num_cases]->ofs))
|
if (G_FLOAT(pr_casesdef[num_cases]->ofs) >= G_FLOAT(pr_casesdef2[num_cases]->ofs))
|
||||||
|
@ -6028,9 +6178,9 @@ void QCC_PR_ParseStatement (void)
|
||||||
{
|
{
|
||||||
QCC_def_t *nextthink;
|
QCC_def_t *nextthink;
|
||||||
QCC_def_t *time;
|
QCC_def_t *time;
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, true);
|
e = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
QCC_PR_Expect(":");
|
QCC_PR_Expect(":");
|
||||||
e2 = QCC_PR_Expression (TOP_PRIORITY, true);
|
e2 = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
if (e->type->type != ev_entity || e2->type->type != ev_float)
|
if (e->type->type != ev_entity || e2->type->type != ev_float)
|
||||||
QCC_PR_ParseError(ERR_THINKTIMETYPEMISMATCH, "thinktime type mismatch");
|
QCC_PR_ParseError(ERR_THINKTIMETYPEMISMATCH, "thinktime type mismatch");
|
||||||
|
|
||||||
|
@ -6064,7 +6214,7 @@ void QCC_PR_ParseStatement (void)
|
||||||
// qcc_functioncalled=0;
|
// qcc_functioncalled=0;
|
||||||
|
|
||||||
qcc_usefulstatement = false;
|
qcc_usefulstatement = false;
|
||||||
e = QCC_PR_Expression (TOP_PRIORITY, true);
|
e = QCC_PR_Expression (TOP_PRIORITY, 0);
|
||||||
expandedemptymacro = false;
|
expandedemptymacro = false;
|
||||||
QCC_PR_Expect (";");
|
QCC_PR_Expect (";");
|
||||||
|
|
||||||
|
@ -8570,7 +8720,7 @@ void QCC_PR_ParseDefs (char *classname)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
def = QCC_PR_Expression(TOP_PRIORITY, true);
|
def = QCC_PR_Expression(TOP_PRIORITY, 0);
|
||||||
if (!def->constant)
|
if (!def->constant)
|
||||||
QCC_PR_ParseError(ERR_BADARRAYSIZE, "Array size is not a constant value");
|
QCC_PR_ParseError(ERR_BADARRAYSIZE, "Array size is not a constant value");
|
||||||
else if (def->type->type == ev_integer)
|
else if (def->type->type == ev_integer)
|
||||||
|
@ -8752,7 +8902,7 @@ void QCC_PR_ParseDefs (char *classname)
|
||||||
#pragma message("this is experimental")
|
#pragma message("this is experimental")
|
||||||
if (pr_scope)
|
if (pr_scope)
|
||||||
{
|
{
|
||||||
d = QCC_PR_Expression(TOP_PRIORITY, false);
|
d = QCC_PR_Expression(TOP_PRIORITY, EXPR_DISALLOW_COMMA);
|
||||||
if (d->constant)
|
if (d->constant)
|
||||||
{
|
{
|
||||||
for (i = 0; i < d->type->size; i++)
|
for (i = 0; i < d->type->size; i++)
|
||||||
|
|
|
@ -1600,12 +1600,11 @@ void QCC_PR_LexWhitespace (void)
|
||||||
// skip /* */ comments
|
// skip /* */ comments
|
||||||
if (c=='/' && pr_file_p[1] == '*')
|
if (c=='/' && pr_file_p[1] == '*')
|
||||||
{
|
{
|
||||||
|
pr_file_p+=2;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
pr_file_p++;
|
|
||||||
if (pr_file_p[0]=='\n')
|
if (pr_file_p[0]=='\n')
|
||||||
{
|
{
|
||||||
pr_file_p++;
|
|
||||||
QCC_PR_NewLine(true);
|
QCC_PR_NewLine(true);
|
||||||
}
|
}
|
||||||
if (pr_file_p[1] == 0)
|
if (pr_file_p[1] == 0)
|
||||||
|
@ -1613,8 +1612,9 @@ void QCC_PR_LexWhitespace (void)
|
||||||
pr_file_p++;
|
pr_file_p++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} while (pr_file_p[-1] != '*' || pr_file_p[0] != '/');
|
|
||||||
pr_file_p++;
|
pr_file_p++;
|
||||||
|
} while (pr_file_p[0] != '*' || pr_file_p[1] != '/');
|
||||||
|
pr_file_p+=2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue