Operand of ! must be of scalar type (was too strict), operand of ~ must be of integer...
authorChristoph Mallon <christoph.mallon@gmx.de>
Sat, 17 Nov 2007 19:51:03 +0000 (19:51 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sat, 17 Nov 2007 19:51:03 +0000 (19:51 +0000)
[r18460]

parser.c

index 1d7b3cd..bbc10c3 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2856,6 +2856,36 @@ static void semantic_unexpr_arithmetic(unary_expression_t *expression)
        expression->expression.datatype = orig_type;
 }
 
+static void semantic_unexpr_scalar(unary_expression_t *expression)
+{
+       type_t *orig_type = expression->value->datatype;
+       if(orig_type == NULL)
+               return;
+
+       type_t *type = skip_typeref(orig_type);
+       if (!is_type_scalar(type)) {
+               parse_error("operand of ! must be of scalar type\n");
+               return;
+       }
+
+       expression->expression.datatype = orig_type;
+}
+
+static void semantic_unexpr_integer(unary_expression_t *expression)
+{
+       type_t *orig_type = expression->value->datatype;
+       if(orig_type == NULL)
+               return;
+
+       type_t *type = skip_typeref(orig_type);
+       if (!is_type_integer(type)) {
+               parse_error("operand of ~ must be of integer type\n");
+               return;
+       }
+
+       expression->expression.datatype = orig_type;
+}
+
 static void semantic_dereference(unary_expression_t *expression)
 {
        type_t *orig_type = expression->value->datatype;
@@ -2921,11 +2951,11 @@ static expression_t *parse_##unexpression_type(unsigned precedence)            \
 
 CREATE_UNARY_EXPRESSION_PARSER('-', UNEXPR_NEGATE, semantic_unexpr_arithmetic)
 CREATE_UNARY_EXPRESSION_PARSER('+', UNEXPR_PLUS,   semantic_unexpr_arithmetic)
-CREATE_UNARY_EXPRESSION_PARSER('!', UNEXPR_NOT,    semantic_unexpr_arithmetic)
+CREATE_UNARY_EXPRESSION_PARSER('!', UNEXPR_NOT,    semantic_unexpr_scalar)
 CREATE_UNARY_EXPRESSION_PARSER('*', UNEXPR_DEREFERENCE, semantic_dereference)
 CREATE_UNARY_EXPRESSION_PARSER('&', UNEXPR_TAKE_ADDRESS, semantic_take_addr)
 CREATE_UNARY_EXPRESSION_PARSER('~', UNEXPR_BITWISE_NEGATE,
-                               semantic_unexpr_arithmetic)
+                               semantic_unexpr_integer)
 CREATE_UNARY_EXPRESSION_PARSER(T_PLUSPLUS,   UNEXPR_PREFIX_INCREMENT,
                                semantic_incdec)
 CREATE_UNARY_EXPRESSION_PARSER(T_MINUSMINUS, UNEXPR_PREFIX_DECREMENT,