From: Christoph Mallon Date: Sat, 17 Nov 2007 21:09:15 +0000 (+0000) Subject: Handle array + integer. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=dda254182db6919678d5584fdbd96398fd5c4781;p=cparser Handle array + integer. [r18464] --- diff --git a/ast2firm.c b/ast2firm.c index 71dce36..70ada73 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -1041,11 +1041,11 @@ static ir_node *create_add(const binary_expression_t *expression) return new_d_Add(dbgi, left, right, mode); } - if(type_left->type == TYPE_POINTER) { - return pointer_arithmetic(left, right, type_left, dbgi, new_d_Add); + if (type_left->type == TYPE_POINTER || type_left->type == TYPE_ARRAY) { + return pointer_arithmetic(left, right, type, dbgi, new_d_Add); } else { - assert(type_right->type == TYPE_POINTER); - return pointer_arithmetic(right, left, type_right, dbgi, new_d_Add); + assert(type_right->type == TYPE_POINTER || type_right->type == TYPE_ARRAY); + return pointer_arithmetic(right, left, type, dbgi, new_d_Add); } } diff --git a/parser.c b/parser.c index 1c3f2c8..4b118c7 100644 --- a/parser.c +++ b/parser.c @@ -3115,6 +3115,14 @@ static void semantic_add(binary_expression_t *expression) expression->expression.datatype = type_left; } else if(type_right->type == TYPE_POINTER && is_type_integer(type_left)) { expression->expression.datatype = type_right; + } else if (type_left->type == TYPE_ARRAY && is_type_integer(type_right)) { + const array_type_t *const arr_type = (const array_type_t*)type_left; + expression->expression.datatype = + make_pointer_type(arr_type->element_type, TYPE_QUALIFIER_NONE); + } else if (type_right->type == TYPE_ARRAY && is_type_integer(type_left)) { + const array_type_t *const arr_type = (const array_type_t*)type_right; + expression->expression.datatype = + make_pointer_type(arr_type->element_type, TYPE_QUALIFIER_NONE); } else { parser_print_error_prefix(); fprintf(stderr, "invalid operands to binary + (");