From af06f28e2c3a9d1a8ae8bab22addbddb7833d793 Mon Sep 17 00:00:00 2001 From: Spoike Date: Mon, 29 Nov 2004 21:08:02 +0000 Subject: [PATCH] assignment in conditional is ignored if placed inside brackets. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@542 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/qclib/qcc_pr_comp.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/engine/qclib/qcc_pr_comp.c b/engine/qclib/qcc_pr_comp.c index dd7f584ad..6177be1b9 100644 --- a/engine/qclib/qcc_pr_comp.c +++ b/engine/qclib/qcc_pr_comp.c @@ -10,7 +10,7 @@ void QCC_PR_ParseAsm(void); extern char *compilingfile; -pbool conditional; +int conditional; pbool keyword_var; pbool keyword_thinktime; @@ -3870,8 +3870,11 @@ QCC_def_t *QCC_PR_Term (void) } else { + pbool oldcond = conditional; + conditional = conditional?2:0; e = QCC_PR_Expression (TOP_PRIORITY); QCC_PR_Expect (")"); + conditional = oldcond; } return e; } @@ -4135,7 +4138,7 @@ QCC_def_t *QCC_PR_Expression (int priority) editbadfile(strings+s_file, pr_source_line); #endif } - if (conditional) + if (conditional&1) QCC_PR_ParseWarning(WARN_ASSIGNMENTINCONDITIONAL, "Assignment in conditional"); e = QCC_PR_Statement (op, e2, e, NULL); @@ -4367,9 +4370,9 @@ void QCC_PR_ParseStatement (void) QCC_PR_Expect ("("); patch2 = &statements[numstatements]; - conditional = true; + conditional = 1; e = QCC_PR_Expression (TOP_PRIORITY); - conditional = false; + conditional = 0; if (((e->constant && !e->temp) || !STRCMP(e->name, "IMMEDIATE")) && opt_compound_jumps) { optres_compound_jumps++; @@ -4457,13 +4460,13 @@ void QCC_PR_ParseStatement (void) patch2 = &statements[numstatements]; if (!QCC_PR_Check(";")) { - conditional = true; + conditional = 1; e = QCC_PR_Expression(TOP_PRIORITY); while (QCC_PR_Check(",")) //logicops, string ops? { e = QCC_PR_Statement(pr_opcodes+OP_AND, e, QCC_PR_Expression(TOP_PRIORITY), NULL); } - conditional = false; + conditional = 0; QCC_PR_Expect(";"); } else @@ -4538,9 +4541,9 @@ void QCC_PR_ParseStatement (void) QCC_PR_ParseStatement (); QCC_PR_Expect ("while"); QCC_PR_Expect ("("); - conditional = true; + conditional = 1; e = QCC_PR_Expression (TOP_PRIORITY); - conditional = false; + conditional = 0; junkdef.ofs = patch1 - &statements[numstatements]; junkdef.type = type_float; if (e->constant && !e->temp) @@ -4624,9 +4627,9 @@ void QCC_PR_ParseStatement (void) if (QCC_PR_Check("not")) { QCC_PR_Expect ("("); - conditional = true; + conditional = 1; e = QCC_PR_Expression (TOP_PRIORITY); - conditional = false; + conditional = 0; if (e->type == type_string && flag_ifstring) //special case, as strings are now pointers, not offsets from string table { @@ -4639,9 +4642,9 @@ void QCC_PR_ParseStatement (void) else { QCC_PR_Expect ("("); - conditional = true; + conditional = 1; e = QCC_PR_Expression (TOP_PRIORITY); - conditional = false; + conditional = 0; if (e->type == type_string && flag_ifstring) //special case, as strings are now pointers, not offsets from string table { @@ -4697,9 +4700,9 @@ void QCC_PR_ParseStatement (void) QCC_PR_Expect ("("); - conditional = true; + conditional = 1; e = QCC_PR_Expression (TOP_PRIORITY); - conditional = false; + conditional = 0; if (e == &def_ret) { //copy it out, so our hack just below doesn't crash us @@ -5899,7 +5902,7 @@ QCC_function_t *QCC_PR_ParseImmediateStatements (QCC_type_t *type) pbool needsdone=false; freeoffset_t *oldfofs; - conditional = false; + conditional = 0; f = (void *)qccHunkAlloc (sizeof(QCC_function_t));