diff options
| author | Mustafa Quraish <[email protected]> | 2022-02-03 03:43:50 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-02-03 03:43:50 -0500 |
| commit | 9a8dc47c35e16229a68774cf8a575340b6418f1b (patch) | |
| tree | 4e294ff1b06b8eada3d902f229c0efa75ff78048 /src/types.c | |
| parent | Remove `putc` intrinsic and replace with `write(fd, buf, size)` (diff) | |
| download | cup-9a8dc47c35e16229a68774cf8a575340b6418f1b.tar.xz cup-9a8dc47c35e16229a68774cf8a575340b6418f1b.zip | |
Check for integer-like types in type-checking instead of exact ones
Since we allow implicit conversions now the exact type is less relevant.
Diffstat (limited to 'src/types.c')
| -rw-r--r-- | src/types.c | 14 |
1 files changed, 7 insertions, 7 deletions
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)); |