From 4b2ae689ed8a6e7597382c87f817f95d556a54c2 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Mon, 23 Jan 2012 02:47:51 +0000 Subject: [PATCH] - Added modulus to FParseContext/xlat. - Fixed: Division of tag arguments for xlat was in the wrong order. SVN r3344 (trunk) --- src/p_xlat.cpp | 15 ++++++++------- src/parsecontext.cpp | 1 + src/parsecontext.h | 2 ++ src/xlat/xlat.h | 1 + src/xlat/xlat_parser.y | 10 ++++++++++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/p_xlat.cpp b/src/p_xlat.cpp index 28792ff7a..07828ac50 100644 --- a/src/p_xlat.cpp +++ b/src/p_xlat.cpp @@ -137,13 +137,14 @@ void P_TranslateLineDef (line_t *ld, maplinedef_t *mld) int tagop = (linetrans->flags >> (LINETRANS_TAGSHIFT + t*TAGOP_NUMBITS)) & TAGOP_MASK; switch (tagop) { - case TAGOP_None: default: break; - case TAGOP_Add: ld->args[t] += tag; break; - case TAGOP_Mul: ld->args[t] *= tag; break; - case TAGOP_Div: ld->args[t] /= tag; break; - case TAGOP_And: ld->args[t] &= tag; break; - case TAGOP_Or: ld->args[t] |= tag; break; - case TAGOP_Xor: ld->args[t] ^= tag; break; + case TAGOP_None: default: break; + case TAGOP_Add: ld->args[t] += tag; break; + case TAGOP_Mul: ld->args[t] *= tag; break; + case TAGOP_Div: ld->args[t] = tag / ld->args[t]; break; + case TAGOP_Mod: ld->args[t] = tag % ld->args[t]; break; + case TAGOP_And: ld->args[t] &= tag; break; + case TAGOP_Or: ld->args[t] |= tag; break; + case TAGOP_Xor: ld->args[t] ^= tag; break; } } diff --git a/src/parsecontext.cpp b/src/parsecontext.cpp index 5b764d954..6fa36b2a8 100644 --- a/src/parsecontext.cpp +++ b/src/parsecontext.cpp @@ -267,6 +267,7 @@ loop: case '-': return TokenTrans[MINUS]; case '+': return TokenTrans[PLUS]; case '*': return TokenTrans[MULTIPLY]; + case '%': return TokenTrans[MODULUS]; case '(': return TokenTrans[LPAREN]; case ')': return TokenTrans[RPAREN]; case ',': return TokenTrans[COMMA]; diff --git a/src/parsecontext.h b/src/parsecontext.h index 020fc7e03..bafeaa888 100644 --- a/src/parsecontext.h +++ b/src/parsecontext.h @@ -47,6 +47,7 @@ enum PLUS , MULTIPLY , DIVIDE , + MODULUS , NUM , FLOATVAL , LPAREN , @@ -78,6 +79,7 @@ enum prefix##PLUS, \ prefix##MULTIPLY, \ prefix##DIVIDE, \ + prefix##MODULUS, \ prefix##NUM, \ prefix##FLOATVAL, \ prefix##LPAREN, \ diff --git a/src/xlat/xlat.h b/src/xlat/xlat.h index 0653d4ab6..765b9fd78 100644 --- a/src/xlat/xlat.h +++ b/src/xlat/xlat.h @@ -10,6 +10,7 @@ enum ELineTransTagOp TAGOP_Add, TAGOP_Mul, TAGOP_Div, + TAGOP_Mod, TAGOP_And, TAGOP_Or, TAGOP_Xor, diff --git a/src/xlat/xlat_parser.y b/src/xlat/xlat_parser.y index 1f14409c4..0fc702f74 100644 --- a/src/xlat/xlat_parser.y +++ b/src/xlat/xlat_parser.y @@ -36,6 +36,7 @@ exp(A) ::= exp(B) PLUS exp(C). { A = B + C; } exp(A) ::= exp(B) MINUS exp(C). { A = B - C; } exp(A) ::= exp(B) MULTIPLY exp(C). { A = B * C; } exp(A) ::= exp(B) DIVIDE exp(C). { if (C != 0) A = B / C; else context->PrintError("Division by zero"); } +exp(A) ::= exp(B) MODULUS exp(C). { if (C != 0) A = B % C; else context->PrintError("Division by zero"); } exp(A) ::= exp(B) OR exp(C). { A = B | C; } exp(A) ::= exp(B) AND exp(C). { A = B & C; } exp(A) ::= exp(B) XOR exp(C). { A = B ^ C; } @@ -135,6 +136,15 @@ special_arg(Z) ::= TAG DIVIDE exp(A). context->PrintError("Division by zero"); } } +special_arg(Z) ::= TAG MODULUS exp(A). +{ + Z.arg = A; + Z.tagop = TAGOP_Mod; + if (A == 0) + { + context->PrintError("Division by zero"); + } +} special_arg(Z) ::= TAG OR exp(A). { Z.arg = A;