]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
also warn about mixing logical and/or operations without parenthesis
authorWolfgang Bumiller <wry.git@bumiller.com>
Thu, 29 Aug 2013 06:26:17 +0000 (08:26 +0200)
committerWolfgang Bumiller <wry.git@bumiller.com>
Thu, 29 Aug 2013 06:26:17 +0000 (08:26 +0200)
parser.c

index 92301d417f73fc3917b2f31e7ba09e574e2e501c..e0864493eab449bff48a727478933df9a48e4744 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1629,7 +1629,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
     /* only warn once about an assignment in a truth value because the current code
      * would trigger twice on: if(a = b && ...), once for the if-truth-value, once for the && part
      */
-    bool warn_truthvalue = true;
+    bool warn_parenthesis = true;
 
     /* count the parens because an if starts with one, so the
      * end of a condition is an unmatched closing paren
@@ -1703,24 +1703,30 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
                 (x) == opid2('|','=') || \
                 (x) == opid3('&','~','=') \
                 )
-            if (warn_truthvalue) {
+            if (warn_parenthesis) {
                 if ( (olast && IsAssignOp(olast->id) && (op->id == opid2('&','&') || op->id == opid2('|','|'))) ||
                      (olast && IsAssignOp(op->id) && (olast->id == opid2('&','&') || olast->id == opid2('|','|'))) ||
                      (truthvalue && !vec_size(sy.paren) && IsAssignOp(op->id))
                    )
                 {
                     (void)!parsewarning(parser, WARN_PARENTHESIS, "suggesting parenthesis around assignment used as truth value");
-                    warn_truthvalue = false;
+                    warn_parenthesis = false;
                 }
-            }
 
-            if (olast &&
-                olast->id != op->id &&
-                (op->id    == opid1('&') || op->id    == opid1('|') || op->id    == opid1('^')) &&
-                (olast->id == opid1('&') || olast->id == opid1('|') || olast->id == opid1('^')))
-            {
-                (void)!parsewarning(parser, WARN_PARENTHESIS, "suggesting parenthesis around bitwise operations");
-                warn_truthvalue = false;
+                if (olast && olast->id != op->id) {
+                    if ((op->id    == opid1('&') || op->id    == opid1('|') || op->id    == opid1('^')) &&
+                        (olast->id == opid1('&') || olast->id == opid1('|') || olast->id == opid1('^')))
+                    {
+                        (void)!parsewarning(parser, WARN_PARENTHESIS, "suggesting parenthesis around bitwise operations");
+                        warn_parenthesis = false;
+                    }
+                    else if ((op->id    == opid2('&','&') || op->id    == opid2('|','|')) &&
+                             (olast->id == opid2('&','&') || olast->id == opid2('|','|')))
+                    {
+                        (void)!parsewarning(parser, WARN_PARENTHESIS, "suggesting parenthesis around logical operations");
+                        warn_parenthesis = false;
+                    }
+                }
             }
 
             while (olast && (