diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/parser.c | 8 | ||||
| -rw-r--r-- | src/types.c | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/parser.c b/src/parser.c index 30d080b..e917564 100644 --- a/src/parser.c +++ b/src/parser.c @@ -873,10 +873,14 @@ Node *parse_func(Lexer *lexer) Token token; token = assert_token(Lexer_next(lexer), TOKEN_FN); + token = assert_token(Lexer_next(lexer), TOKEN_IDENTIFIER); + if (identifier_exists(&token)) + die_location(token.loc, "Function name already exists as an identifier"); + Node *func = Node_new(AST_FUNC); push_new_function(func); - token = assert_token(Lexer_next(lexer), TOKEN_IDENTIFIER); + func->func.name = token.value.as_string; parse_func_args(lexer, func); @@ -922,6 +926,8 @@ Type *parse_struct_union_declaration(Lexer *lexer, bool is_global) { struct_type->struct_name = token.value.as_string; push_struct_definition(struct_type); Lexer_next(lexer); + } else { + struct_type->struct_name = "<anonymous>"; } assert_token(Lexer_next(lexer), TOKEN_OPEN_BRACE); diff --git a/src/types.c b/src/types.c index d004634..8ac4c77 100644 --- a/src/types.c +++ b/src/types.c @@ -37,6 +37,7 @@ i64 size_for_type(Type *type) case TYPE_CHAR: return 1; case TYPE_ARRAY: return type->array_size * size_for_type(type->ptr); case TYPE_STRUCT: return type->fields.size; + case TYPE_UNION: return type->fields.size; default: { printf("Unknown type: %d\n", type->type); assert(false && "Unreachable type"); @@ -89,10 +90,11 @@ bool is_int_type(Type *type) bool is_struct_or_struct_ptr(Type *type) { - if (type->type == TYPE_STRUCT) - return true; - if (type->type == TYPE_PTR && type->ptr->type == TYPE_STRUCT) + if (type->type == TYPE_STRUCT || type->type == TYPE_UNION) return true; + if (type->type == TYPE_PTR) + if (type->ptr->type == TYPE_STRUCT || type->ptr->type == TYPE_UNION) + return true; return false; } |