]> git.sur5r.net Git - cc65/blobdiff - src/cc65/testexpr.c
Fixed _textcolor definition.
[cc65] / src / cc65 / testexpr.c
index a8d559f4f3a3e074df2715eb41b1f0e9382a36e7..5bb7bf7e44eabd3da7f27f42a792a329f2cecb52 100644 (file)
 /*****************************************************************************/
 
 
-
+                     
+/* cc65 */
 #include "codegen.h"
 #include "error.h"
 #include "expr.h"
+#include "loadexpr.h"
 #include "scanner.h"
 #include "testexpr.h"
 
 
 
 /*****************************************************************************/
-/*                                  Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
 
 unsigned Test (unsigned Label, int Invert)
 /* Evaluate a boolean test expression and jump depending on the result of
- * the test and on Invert. The function returns one of the TESTEXPR_xx codes
- * defined above. If the jump is always true, a warning is output.
- */
+** the test and on Invert. The function returns one of the TESTEXPR_xx codes
+** defined above. If the jump is always true, a warning is output.
+*/
 {
-    ExprDesc lval;
+    ExprDesc Expr;
     unsigned Result;
 
-    /* Evaluate the expression */
-    expr (hie0, InitExprDesc (&lval));
-
-    /* Check for a boolean expression */
-    CheckBoolExpr (&lval);
+    /* Read a boolean expression */
+    BoolExpr (hie0, &Expr);
 
     /* Check for a constant expression */
-    if (ED_IsRVal (&lval) && lval.Flags == E_MCONST) {
+    if (ED_IsConstAbs (&Expr)) {
 
         /* Result is constant, so we know the outcome */
-        Result = (lval.ConstVal != 0);
-
-       /* Constant rvalue */
-               if (!Invert && lval.ConstVal == 0) {
-           g_jump (Label);
-           Warning ("Unreachable code");
-       } else if (Invert && lval.ConstVal != 0) {
-           g_jump (Label);
-       }
+        Result = (Expr.IVal != 0);
+
+        /* Constant rvalue */
+        if (!Invert && Expr.IVal == 0) {
+            g_jump (Label);
+            Warning ("Unreachable code");
+        } else if (Invert && Expr.IVal != 0) {
+            g_jump (Label);
+        }
 
     } else {
 
@@ -82,12 +81,12 @@ unsigned Test (unsigned Label, int Invert)
         Result = TESTEXPR_UNKNOWN;
 
         /* If the expr hasn't set condition codes, set the force-test flag */
-        if ((lval.Test & E_CC) == 0) {
-            lval.Test |= E_FORCETEST;
+        if (!ED_IsTested (&Expr)) {
+            ED_MarkForTest (&Expr);
         }
 
         /* Load the value into the primary register */
-        ExprLoad (CF_FORCECHAR, &lval);
+        LoadExpr (CF_FORCECHAR, &Expr);
 
         /* Generate the jump */
         if (Invert) {
@@ -105,10 +104,10 @@ unsigned Test (unsigned Label, int Invert)
 
 unsigned TestInParens (unsigned Label, int Invert)
 /* Evaluate a boolean test expression in parenthesis and jump depending on
- * the result of the test * and on Invert. The function returns one of the
- * TESTEXPR_xx codes defined above. If the jump is always true, a warning is
- * output.
- */
+** the result of the test * and on Invert. The function returns one of the
+** TESTEXPR_xx codes defined above. If the jump is always true, a warning is
+** output.
+*/
 {
     unsigned Result;
 
@@ -124,7 +123,3 @@ unsigned TestInParens (unsigned Label, int Invert)
     /* Return the result of the expression */
     return Result;
 }
-
-
-
-