From 9a8dc47c35e16229a68774cf8a575340b6418f1b Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Thu, 3 Feb 2022 03:43:50 -0500 Subject: Check for integer-like types in type-checking instead of exact ones Since we allow implicit conversions now the exact type is less relevant. --- src/types.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/types.c b/src/types.c index b2709f8..7a055fe 100644 --- a/src/types.c +++ b/src/types.c @@ -156,9 +156,9 @@ Node *handle_binary_expr_types(Node *node, Token *token) switch (node->type) { case OP_PLUS: { - if (left->type == TYPE_INT && right->type == TYPE_INT) { + if (is_int_type(left) && is_int_type(right)) { node->expr_type = type_new(TYPE_INT); - } else if (left->type == TYPE_PTR && right->type == TYPE_INT) { + } else if (left->type == TYPE_PTR && is_int_type(right)) { node->expr_type = left; // Pointer arithmetic! if (size_for_type(left->ptr) != 1) { @@ -167,7 +167,7 @@ Node *handle_binary_expr_types(Node *node, Token *token) mul->binary.right = Node_from_int_literal(size_for_type(left->ptr)); node->binary.right = mul; } - } else if (left->type == TYPE_INT && right->type == TYPE_PTR) { + } else if (is_int_type(left) && right->type == TYPE_PTR) { node->expr_type = right; // Pointer arithmetic! if (size_for_type(right->ptr) != 1) { @@ -182,9 +182,9 @@ Node *handle_binary_expr_types(Node *node, Token *token) } break; case OP_MINUS: { - if (left->type == TYPE_INT && right->type == TYPE_INT) { + if (is_int_type(left) && is_int_type(right)) { node->expr_type = type_new(TYPE_INT); - } else if (left->type == TYPE_PTR && right->type == TYPE_INT) { + } else if (left->type == TYPE_PTR && is_int_type(right)) { node->expr_type = left; // Pointer arithmetic! if (size_for_type(left->ptr) != 1) { @@ -193,7 +193,7 @@ Node *handle_binary_expr_types(Node *node, Token *token) mul->binary.right = Node_from_int_literal(size_for_type(left->ptr)); node->binary.right = mul; } - } else if (left->type == TYPE_INT && right->type == TYPE_PTR) { + } else if (is_int_type(left) && right->type == TYPE_PTR) { node->expr_type = right; // Pointer arithmetic! if (size_for_type(right->ptr) != 1) { @@ -222,7 +222,7 @@ Node *handle_binary_expr_types(Node *node, Token *token) case OP_DIV: case OP_MOD: case OP_MUL: { - if (left->type == TYPE_INT && right->type == TYPE_INT) { + if (is_int_type(left) && is_int_type(right)) { node->expr_type = left; } else { die_location(token->loc, "Cannot do operation `%s` non-integer types", node_type_to_str(node->type)); -- cgit v1.2.3