From 3fa23ffe68801466fd85a623b6848ef46496e8ad Mon Sep 17 00:00:00 2001 From: Spoike Date: Fri, 6 May 2005 11:24:36 +0000 Subject: [PATCH] Better handling for integer switches. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@988 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/qclib/qcc_pr_comp.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/engine/qclib/qcc_pr_comp.c b/engine/qclib/qcc_pr_comp.c index a87ddaecc..b6ead6b14 100644 --- a/engine/qclib/qcc_pr_comp.c +++ b/engine/qclib/qcc_pr_comp.c @@ -5048,11 +5048,21 @@ void QCC_PR_ParseStatement (void) else { if (pr_casesdef[i]->type->type != e->type->type) - QCC_PR_ParseWarning(WARN_SWITCHTYPEMISMATCH, "switch case type mismatch"); + { + if (e->type->type == ev_integer && pr_casesdef[i]->type->type == ev_float) + pr_casesdef[i] = QCC_MakeIntDef((int)qcc_pr_globals[pr_casesdef[i]->ofs]); + else + QCC_PR_ParseWarning(WARN_SWITCHTYPEMISMATCH, "switch case type mismatch"); + } if (pr_casesdef2[i]) { if (pr_casesdef2[i]->type->type != e->type->type) - QCC_PR_ParseWarning(WARN_SWITCHTYPEMISMATCH, "switch caserange type mismatch"); + { + if (e->type->type == ev_integer && pr_casesdef[i]->type->type == ev_float) + pr_casesdef2[i] = QCC_MakeIntDef((int)qcc_pr_globals[pr_casesdef2[i]->ofs]); + else + QCC_PR_ParseWarning(WARN_SWITCHTYPEMISMATCH, "switch caserange type mismatch"); + } if (hcstyle) { @@ -5063,13 +5073,24 @@ void QCC_PR_ParseStatement (void) { QCC_def_t *e3; - if (e->type->type != ev_float) + if (e->type->type == ev_float) + { + e2 = QCC_PR_Statement (&pr_opcodes[OP_GE], e, pr_casesdef[i], NULL); + e3 = QCC_PR_Statement (&pr_opcodes[OP_LE], e, pr_casesdef2[i], NULL); + e2 = QCC_PR_Statement (&pr_opcodes[OP_AND], e2, e3, NULL); + QCC_FreeTemp(QCC_PR_Statement (&pr_opcodes[OP_IF], e2, 0, &patch3)); + patch3->b = &statements[pr_cases[i]] - patch3; + } + else if (e->type->type == ev_integer) + { + e2 = QCC_PR_Statement (&pr_opcodes[OP_GE_I], e, pr_casesdef[i], NULL); + e3 = QCC_PR_Statement (&pr_opcodes[OP_LE_I], e, pr_casesdef2[i], NULL); + e2 = QCC_PR_Statement (&pr_opcodes[OP_AND], e2, e3, NULL); + QCC_FreeTemp(QCC_PR_Statement (&pr_opcodes[OP_IF], e2, 0, &patch3)); + patch3->b = &statements[pr_cases[i]] - patch3; + } + else QCC_PR_ParseWarning(WARN_SWITCHTYPEMISMATCH, "switch caserange MUST be a float"); - e2 = QCC_PR_Statement (&pr_opcodes[OP_GE], e, pr_casesdef[i], NULL); - e3 = QCC_PR_Statement (&pr_opcodes[OP_LE], e, pr_casesdef2[i], NULL); - e2 = QCC_PR_Statement (&pr_opcodes[OP_AND], e2, e3, NULL); - QCC_FreeTemp(QCC_PR_Statement (&pr_opcodes[OP_IF], e2, 0, &patch3)); - patch3->b = &statements[pr_cases[i]] - patch3; } } else