}
type_error_incompatible("can't implicitly cast types",
- expression->source_position,
- source_type, dest_type);
+ expression->source_position,
+ source_type, dest_type);
return expression;
}
return declaration;
}
-static void parse_enum_entries(void)
+static void parse_enum_entries(type_t *enum_type)
{
eat('{');
return;
}
entry->storage_class = STORAGE_CLASS_ENUM_ENTRY;
+ entry->type = enum_type;
entry->symbol = token.v.symbol;
entry->source_position = token.source_position;
next_token();
if(token.type == '=') {
next_token();
entry->init.enum_value = parse_constant_expression();
+
+ /* TODO semantic */
}
record_declaration(entry);
record_declaration(declaration);
declaration->init.is_defined = 1;
- parse_enum_entries();
+ parse_enum_entries(NULL);
parse_attributes();
}
}
static construct_type_t *parse_inner_declarator(declaration_t *declaration,
- int may_be_abstract)
+ bool may_be_abstract)
{
construct_type_t *result = NULL;
- construct_type_t *last = NULL;
while(token.type == '*') {
construct_type_t *type = parse_pointer_declarator();
- if(last != NULL) {
- last->next = type;
- } else {
- result = type;
- }
- last = type;
+
+ type->next = result;
+ result = type;
}
/* TODO: find out if this is correct */
goto declarator_finished;
}
- if(last != NULL) {
- last->next = type;
- } else {
- result = type;
- }
- last = type;
+ type->next = result;
+ result = type;
}
declarator_finished:
parse_attributes();
if(inner_types != NULL) {
- if(last != NULL) {
- last->next = inner_types;
- } else {
- result = inner_types;
+ construct_type_t *t = inner_types;
+ for( ; t->next != NULL; t = t->next) {
}
- last = inner_types;
+ t->next = result;
+ result = inner_types;
}
return result;
type_t *hashed_type = typehash_insert((type_t*) type);
if(hashed_type != type) {
- free_type(type);
+ /* the function type was constructed earlier freeing it here will
+ * destroy other types... */
+ if(iter->type != CONSTRUCT_FUNCTION) {
+ free_type(type);
+ }
type = hashed_type;
}
}
call->function = expression;
function_type_t *function_type;
- type_t *type = expression->datatype;
+ type_t *orig_type = expression->datatype;
+ type_t *type = skip_typeref(orig_type);
+
+ if(type->type == TYPE_POINTER) {
+ pointer_type_t *pointer_type = (pointer_type_t*) type;
+
+ type = skip_typeref(pointer_type->points_to);
+ }
if (type->type == TYPE_FUNCTION) {
function_type = (function_type_t*) type;
call->expression.datatype = function_type->result_type;
- } else if (type->type == TYPE_POINTER &&
- ((pointer_type_t*)type)->points_to->type == TYPE_FUNCTION) {
- pointer_type_t *const ptr_type = (pointer_type_t*)type;
- function_type = (function_type_t*)ptr_type->points_to;
- call->expression.datatype = function_type->result_type;
} else {
parser_print_error_prefix();
fputs("called object '", stderr);
print_expression(expression);
fputs("' (type ", stderr);
- print_type_quoted(type);
+ print_type_quoted(orig_type);
fputs(") is not a function\n", stderr);
function_type = NULL;
CREATE_BINEXPR_PARSER('^', BINEXPR_BITWISE_XOR, semantic_binexpr_arithmetic, 1)
CREATE_BINEXPR_PARSER(T_ANDAND, BINEXPR_LOGICAL_AND, semantic_logical_op, 1)
CREATE_BINEXPR_PARSER(T_PIPEPIPE, BINEXPR_LOGICAL_OR, semantic_logical_op, 1)
-/* TODO shift has a bit special semantic */
CREATE_BINEXPR_PARSER(T_LESSLESS, BINEXPR_SHIFTLEFT,
semantic_shift_op, 1)
CREATE_BINEXPR_PARSER(T_GREATERGREATER, BINEXPR_SHIFTRIGHT,