F diff --git a/src/frontend/parse/parse_expression.c b/src/frontend/parse/parse_expression.c
--- a/src/frontend/parse/parse_expression.c
+++ b/src/frontend/parse/parse_expression.c
do
{
hold_expression=parse_assignment_expression(translation_data,scope);
+ /*
+ * COMENTED THIS WHILE TRYING TO REMOVE NULL RETURNS
if(hold_expression==NULL)
{
while(arg_list.size>0)
push_translation_error("error in argument list in function call expression",translation_data);
return NULL;
}
+ */
Queue_Push(&arg_list,hold_expression);
}while(get_and_check(translation_data,KW_COMMA));
}else
{
push_translation_error("expected ')' here",translation_data);
- delete_ast((struct AST*)ret);
- return NULL;
+ return (struct AST_Function_Expression*)get_error_tree((struct AST*)ret);
}
}
hold_postfix_expression=parse_primary_expression(translation_data,scope);
- while(translation_data->tokens->size!=0 && hold_postfix_expression!=NULL)
+ while(translation_data->tokens->size!=0)
{
switch(kw_get(translation_data))
{
if(!get_and_check(translation_data,KW_CLOSE_SQUARE))
{
push_translation_error("expected ']' here",translation_data);
- delete_ast((struct AST*)hold_second_expr);
- delete_ast((struct AST*)hold_postfix_expression);
- return NULL;
+ return (struct AST_Expression*)get_error_tree((struct AST*)hold_postfix_expression);
}
}
break;
{
/*TODO error*/
push_translation_error("expected something here",translation_data);
- return NULL;
+ return (struct AST_Expression*)get_error_tree(NULL);
}
/*TODO make it iterative*/
{
case KW_PLUSPLUS:
chomp(translation_data); hold_expression=parse_unary_expression(translation_data,scope);
-
- if(hold_expression==NULL)
- { push_translation_error("expected unary_expression after '++' operator",translation_data); goto error; }
- else
- return (struct AST_Expression*)get_prefix_inc_dec_tree(hold_expression,OP_PREFIX_INC,translation_data);
+ return (struct AST_Expression*)get_prefix_inc_dec_tree(hold_expression,OP_PREFIX_INC,translation_data);
case KW_MINUSMINUS:
chomp(translation_data); hold_expression=parse_unary_expression(translation_data,scope);
-
- if(hold_expression==NULL)
- { push_translation_error("expected unary_expression after '--' operator",translation_data); goto error; }
- else
- return (struct AST_Expression*)get_prefix_inc_dec_tree(hold_expression,OP_PREFIX_DEC,translation_data);
+ return (struct AST_Expression*)get_prefix_inc_dec_tree(hold_expression,OP_PREFIX_DEC,translation_data);
case KW_PLUS:
chomp(translation_data); hold_expression=parse_cast_expression(translation_data,scope);
-
- if(hold_expression==NULL)
- { push_translation_error("expected cast expression after unary '+' operator",translation_data); goto error; }
- else
- return (struct AST_Expression*)get_unary_plus_minus_expression(hold_expression,OP_UNARY_PLUS,translation_data);
+ return (struct AST_Expression*)get_unary_plus_minus_expression(hold_expression,OP_UNARY_PLUS,translation_data);
case KW_MINUS:
chomp(translation_data); hold_expression=parse_cast_expression(translation_data,scope);
-
- if(hold_expression==NULL)
- { push_translation_error("expected cast expression after unary '-' operator",translation_data); goto error; }
- else
- return (struct AST_Expression*)get_unary_plus_minus_expression(hold_expression,OP_UNARY_MINUS,translation_data);
+ return (struct AST_Expression*)get_unary_plus_minus_expression(hold_expression,OP_UNARY_MINUS,translation_data);
case KW_EXCLAMATION:
chomp(translation_data); hold_expression=parse_cast_expression(translation_data,scope);
- if(hold_expression==NULL)
- { push_translation_error("expected cast expression after unary '!' operator",translation_data); goto error; }
- else
- return (struct AST_Expression*) get_unary_logical_not_expression(hold_expression,translation_data);
+ return (struct AST_Expression*) get_unary_logical_not_expression(hold_expression,translation_data);
case KW_TILDE:
chomp(translation_data); hold_expression=parse_cast_expression(translation_data,scope);
-
- if(hold_expression==NULL)
- { push_translation_error("expected cast expression after unary '~' operator",translation_data); goto error; }
- else
- return (struct AST_Expression*) get_unary_bitwise_not_expression(hold_expression,translation_data);
+ return (struct AST_Expression*) get_unary_bitwise_not_expression(hold_expression,translation_data);
case KW_STAR:
chomp(translation_data); hold_expression=parse_cast_expression(translation_data,scope);
-
- if(hold_expression==NULL)
- { push_translation_error("expected cast expression after unary '*' operator",translation_data); goto error; }
- else
- return (struct AST_Expression*) get_indirection_expression_tree(hold_expression,translation_data);
+ return (struct AST_Expression*) get_indirection_expression_tree(hold_expression,translation_data);
case KW_AND:
chomp(translation_data); hold_expression=parse_cast_expression(translation_data,scope);
-
- if(hold_expression==NULL)
- { push_translation_error("expected cast expression after unary '&' operator",translation_data); goto error; }
- else
- return (struct AST_Expression*) get_address_expression_tree(hold_expression,translation_data);
+ return (struct AST_Expression*) get_address_expression_tree(hold_expression,translation_data);
case KW_SIZEOF:
chomp(translation_data);
if(get_and_check(translation_data,KW_OPEN_NORMAL))
}else
{
hold_expression=parse_unary_expression(translation_data,scope);
- if(hold_expression==NULL)
- { push_translation_error("expected unary expression after 'sizeof' operator",translation_data); goto error; }
- else
- get_unary_sizeof_tree(hold_expression,translation_data);
+ return (struct AST_Expression*)get_unary_sizeof_tree(hold_expression,translation_data);
}
default:
return parse_postfix_expression(translation_data,scope);
}
+ assert(0);
/*shouldn't reach here - the default of the switch returns*/
-
- error:
- if(hold_expression) delete_ast((struct AST*)hold_expression);
- return NULL;
}
/*
multiplicative-expression:
hold_left_expression=parse_cast_expression(translation_data,scope);
- while(translation_data->tokens->size!=0 && hold_left_expression!=NULL)
+ while(translation_data->tokens->size!=0)
{
switch(kw_get(translation_data))
{
chomp(translation_data);
hold_right_expression=parse_cast_expression(translation_data,scope);
-
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected cast expression as the second operator in multiplicative expression",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_left_expression);
-
- return NULL; /*BEWARE*/
- }
-
hold_left_expression=(struct AST_Expression*)get_multiplicative_expression_tree(hold_left_expression,hold_right_expression,operation_type,translation_data);
}
hold_left_expression=parse_multiplicative_expression(translation_data,scope);
- while(translation_data->tokens->size!=0 && hold_left_expression!=NULL)
+ while(translation_data->tokens->size!=0)
{
switch(kw_get(translation_data))
{
chomp(translation_data);
hold_right_expression=parse_multiplicative_expression(translation_data,scope);
-
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected multiplicative expression in the additive expression",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_left_expression);
-
- return NULL;
- }
-
hold_left_expression=(struct AST_Expression*)get_additive_expression_tree(hold_left_expression,hold_right_expression,operation_type,translation_data);
}
hold_left_expression=parse_additive_expression(translation_data,scope);
- while(translation_data->tokens->size!=0 && hold_left_expression!=NULL)
+ while(translation_data->tokens->size!=0)
{
switch(kw_get(translation_data))
{
}
chomp(translation_data);
hold_right_expression=parse_additive_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected additive expression in second argument of the bitwise shift",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_left_expression);
-
- return NULL;
- }
hold_left_expression=(struct AST_Expression*)get_shift_expression_tree(hold_left_expression,hold_right_expression,operation_type,translation_data);
}
return hold_left_expression; /*this could return null if there was a constraint check violation or the first cast operation is invalid*/
hold_left_expression=parse_shift_expression(translation_data,scope);
- while(translation_data->tokens->size!=0 && hold_left_expression!=NULL)
+ while(translation_data->tokens->size!=0)
{
switch(kw_get(translation_data))
{
chomp(translation_data);
hold_right_expression=parse_shift_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected shift expression as the second operand of the relational expression",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_right_expression);
-
- return NULL;
- }
hold_left_expression=(struct AST_Expression*)get_relation_expression_tree(hold_left_expression,hold_right_expression,operation_type,translation_data);
}
return hold_left_expression; /*this could return null if there was a constraint check violation or the first cast operation is invalid*/
hold_left_expression=parse_relational_expression(translation_data,scope);
- while(translation_data->tokens->size!=0 && hold_left_expression!=NULL)
+ while(translation_data->tokens->size!=0)
{
switch(kw_get(translation_data))
{
}
chomp(translation_data);
hold_right_expression=parse_relational_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected relational expression as the second operand of the equality expression",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_left_expression);
- return NULL;
- }
hold_left_expression=(struct AST_Expression*)get_equality_expression_tree(hold_left_expression,hold_right_expression,operation_type,translation_data);
}
return hold_left_expression; /*this could return null if there was a constraint check violation or the first cast operation is invalid*/
hold_left_expression=parse_equality_expression(translation_data,scope);
- while(get_and_check(translation_data,KW_AND) && hold_left_expression!=NULL)
+ while(get_and_check(translation_data,KW_AND))
{
hold_right_expression=parse_equality_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected equality expression as the second argument of the bitwise and operation",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_left_expression);
-
- return NULL;
- }
hold_left_expression=(struct AST_Expression*)get_bitwise_expression_tree(hold_left_expression,hold_right_expression,OP_BITWISE_AND,translation_data);
}
return hold_left_expression;
hold_left_expression=parse_and_expression(translation_data,scope);
- while(get_and_check(translation_data,KW_HAT) && hold_left_expression!=NULL)
+ while(get_and_check(translation_data,KW_HAT))
{
hold_right_expression=parse_and_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected bitwise and expression as the second argument of the bitwise xor operation",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_left_expression);
-
- return NULL;
- }
hold_left_expression=(struct AST_Expression*)get_bitwise_expression_tree(hold_left_expression,hold_right_expression,OP_BITWISE_XOR,translation_data);
}
return hold_left_expression;
hold_left_expression=parse_exclusive_or_expression(translation_data,scope);
- while(get_and_check(translation_data,KW_PIPE) && hold_left_expression!=NULL)
+ while(get_and_check(translation_data,KW_PIPE))
{
hold_right_expression=parse_exclusive_or_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected exclusive or expression as the second argument of the bitwise or operation",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_left_expression);
-
- return NULL;
- }
hold_left_expression=(struct AST_Expression*)get_bitwise_expression_tree(hold_left_expression,hold_right_expression,OP_BITWISE_OR,translation_data);
}
return hold_left_expression;
hold_left_expression=parse_inclusive_or_expression(translation_data,scope);
- while(get_and_check(translation_data,KW_AND_AND) && hold_left_expression!=NULL)
+ while(get_and_check(translation_data,KW_AND_AND))
{
hold_right_expression=parse_inclusive_or_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected or-expression as the second argument of the logical and operation",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_left_expression);
-
- return NULL;
- }
hold_left_expression=(struct AST_Expression*)get_logical_expression_tree(hold_left_expression,hold_right_expression,OP_LOGICAL_AND,translation_data);
}
return hold_left_expression;
hold_left_expression=parse_logical_and_expression(translation_data,scope);
- while(get_and_check(translation_data,KW_PIPE_PIPE) && hold_left_expression!=NULL)
+ while(get_and_check(translation_data,KW_PIPE_PIPE))
{
hold_right_expression=parse_logical_and_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected or-expression as the second argument of the logical and operation",translation_data);
-
- assert(hold_left_expression!=NULL);
- delete_ast((struct AST*)hold_left_expression);
-
- return NULL;
- }
hold_left_expression=(struct AST_Expression*)get_logical_expression_tree(hold_left_expression,hold_right_expression,OP_LOGICAL_OR,translation_data);
}
return hold_left_expression;
struct AST_Expression *hold_right_expression;
hold_left_expression=parse_logical_or_expression(translation_data,scope);
- if(hold_left_expression==NULL)
- return NULL;
-
if(get_and_check(translation_data,KW_QUESTION))
{
hold_center_expression=(struct AST_Expression*)parse_expression(translation_data,scope);
-
- if(hold_center_expression==NULL)
- {
- push_translation_error("expected wellformed middle expression in the conditional expression",translation_data);
- delete_ast((struct AST*)hold_left_expression);
- return NULL;
- }
-
if(get_and_check(translation_data,KW_COLUMN))
{
hold_right_expression=parse_conditional_expression(translation_data,scope);
- if(hold_right_expression)
- {
- push_translation_error("error in the third expression of the conditional expression",translation_data);
- delete_ast((struct AST*)hold_left_expression);
- delete_ast((struct AST*)hold_right_expression);
-
- return NULL;
- }
-
- return (struct AST_Expression*)get_conditional_expression_tree(hold_right_expression,hold_center_expression,hold_right_expression,translation_data);
}else
{
push_translation_error("expected ':' here",translation_data);
-
- if(hold_left_expression)delete_ast((struct AST*)hold_left_expression);
- if(hold_center_expression)delete_ast((struct AST*)hold_center_expression);
-
- return NULL;
+ hold_right_expression=(struct AST_Expression*)get_error_tree(NULL);
}
+ return (struct AST_Expression*)get_conditional_expression_tree(hold_right_expression,hold_center_expression,hold_right_expression,translation_data);
}else
{
return hold_left_expression;
if(translation_data->tokens->size==0)
{
- /*TODO error*/
push_translation_error("expected something here",translation_data);
- return NULL;
+ return (struct AST_Expression*)get_error_tree(NULL);
}
hold_left_expression=parse_conditional_expression(translation_data,scope);
- if(hold_left_expression==NULL)
- return NULL;
+
if(translation_data->tokens->size==0)
return hold_left_expression;
}
chomp(translation_data);
hold_right_expression=parse_assignment_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected a second operand for the assignment expression",translation_data);
- delete_ast((struct AST*)hold_left_expression);
- return NULL;
- }
if(operation_type==OP_ASSIGN)
return (struct AST_Expression*)get_simple_assignment_expression_tree(hold_left_expression,hold_right_expression,translation_data);
struct AST_Expression *hold_right_expression;
hold_left_expression=parse_assignment_expression(translation_data,scope);
-
- if(hold_left_expression==NULL)
- return NULL;
-
while(get_and_check(translation_data,KW_COMMA))
{
hold_right_expression=parse_assignment_expression(translation_data,scope);
- if(hold_right_expression==NULL)
- {
- push_translation_error("expected an assignment expression after comma in comma operator",translation_data);
-
- delete_ast((struct AST*)hold_left_expression);
- return NULL;
- }
hold_left_expression=(struct AST_Expression*)get_comma_expression_tree(hold_left_expression,hold_right_expression,translation_data);
}
return hold_left_expression;
F diff --git a/src/program/gcc_error.c b/src/program/gcc_error.c
--- a/src/program/gcc_error.c
+++ b/src/program/gcc_error.c
/*
%T - type
%D - denoted
- /bin/bash: line 1: src/program/gcc_error.h: Permission denied
- /bin/bash: line 1: =: No such file or directory
+ %t - token
*/
struct Translation_Message* get_translation_message(const char *message_format,struct Translation_Data *translation_data,char *filename,size_t line,size_t column,va_list args)
{
hold_return_string=gstr_append_and_consume(hold_return_string,hold_return_substring);
where_in_return_message=message_format+i+2;
- i+=2;
+ ++i;
}
}
F diff --git a/src/semantics/ast.c b/src/semantics/ast.c
--- a/src/semantics/ast.c
+++ b/src/semantics/ast.c
{
struct Type *operand_type;
if(!type_is_scalar(type))
- { push_translation_error("cast type needs to be of scalar type",translation_data);return NULL; }
-
- operand_type=extract_expresion_value_type(operand->value,translation_data);
- if(types_are_identical(operand_type,type))
- return operand;
-
- return (struct AST_Expression*) get_unary_expression_tree(
- operand,
- get_expression_value_rvalue(get_temp_object(type)),
- OP_CAST
- );
+ {
+ push_translation_error("cast type needs to be of scalar type",translation_data);
+ push_translation_note("got %T instead",translation_data,type);
+
+ return (struct AST_Expression*)get_error_tree((struct AST*)get_unary_expression_tree(
+ operand,
+ get_expression_value_rvalue(get_temp_object(type)),
+ OP_CAST
+ ));
+ }else
+ {
+ operand_type=extract_expresion_value_type(operand->value,translation_data);
+ if(types_are_identical(operand_type,type))
+ return operand;
+
+ return (struct AST_Expression*) get_unary_expression_tree(
+ operand,
+ get_expression_value_rvalue(get_temp_object(type)),
+ OP_CAST
+ );
+ }
}
struct AST_Expression* get_degraded_array_expression_if_it_has_the_right_type(struct AST_Expression *expression,struct Translation_Data *translation_data)
{
return get_binary_expression_after_conversion(left,right,OP_REMAINDER,translation_data);
}else
{
- delete_ast((struct AST*)left), delete_ast((struct AST*)right);
- return NULL;
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,OP_REMAINDER));
}
}
struct AST_Binary_Expression* get_multiplicative_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
return get_binary_expression_after_conversion(left,right,operation,translation_data);
}else
{
- delete_ast((struct AST*)left), delete_ast((struct AST*)right);
- return NULL;
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,operation));
}
}
struct AST_Binary_Expression* get_additive_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
return get_binary_expression_after_conversion(left,right,operation,translation_data);
}else
{
- delete_ast((struct AST*)left), delete_ast((struct AST*)right);
- return NULL;
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,operation));
}
}
struct AST_Binary_Expression* get_shift_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object(extract_expresion_value_type(left->value,translation_data))),operation);
}else
{
- delete_ast((struct AST*)left), delete_ast((struct AST*)right);
- return NULL;
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,operation));
}
}
struct AST_Binary_Expression* get_bitwise_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
return get_binary_expression_after_conversion(left,right,operation,translation_data);
}else
{
- delete_ast((struct AST*)left), delete_ast((struct AST*)right);
- return NULL;
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,operation));
}
}
return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((struct Type*)get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE,translation_data))),operation);
}else
{
- delete_ast((struct AST*)left), delete_ast((struct AST*)right);
- return NULL;
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,operation));
}
}
struct AST_Binary_Expression* get_equality_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((struct Type*)get_type_insecure(TS_INT,TSIGN_SIGNED,TC_NONE,INT_SIZE,translation_data))),operation);
}else
{
- delete_ast((struct AST*)left), delete_ast((struct AST*)right);
- return NULL;
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,operation));
}
}
struct AST_Binary_Expression* get_logical_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
if(constraint_check_simple_assignment_expression(left,right,translation_data))
{
struct Type *left_type;
+
left_type=extract_expresion_value_type(left->value,translation_data);
+
left_type=get_unqualified_version_of_type(left_type,translation_data);
right=get_cast_expression_tree(right,left_type,translation_data);
+
return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object(left_type)),OP_ASSIGN);
}else
{
- delete_ast((struct AST*)left), delete_ast((struct AST*)right);
- return NULL;
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,OP_ASSIGN));
}
}
left_type=get_unqualified_version_of_type(left_type,translation_data);
right=get_cast_expression_tree(right,left_type,translation_data);
- return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object(left_type)),OP_ASSIGN);
+ return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object(left_type)),operation);
}else
{
- delete_ast((struct AST*)left), delete_ast((struct AST*)right);
- return NULL;
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,OP_ASSIGN));
}
}
struct AST_Binary_Expression* get_comma_expression_tree(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data)
{
- return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((extract_expresion_value_type(right->value,translation_data)))),OP_COMMA);
+ if(left->type!=ERROR && right->type!=ERROR)
+ {
+ return get_binary_expression_tree(left,right,get_expression_value_rvalue(get_temp_object((extract_expresion_value_type(right->value,translation_data)))),OP_COMMA);
+ }else
+ {
+ return get_binary_expression_tree(left,right,NULL,OP_COMMA);
+ }
}
/*TODO right might be null if so then it's a [] array */
left_type=extract_expresion_value_type(left->value,translation_data);
if(left_type->specifier!=TS_POINTER)
- {push_translation_error("expected pointer in array subscript",translation_data);return NULL;}
+ {
+ push_translation_error("Expected a pointer type in array subscript",translation_data);
+ push_translation_note("Instead got %T",translation_data,left_type);
+
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,OP_ARR_SUBSCRIPT));
+ }
member_type=((struct Type_Pointer*)left_type)->points_to;
if(!type_is_of_object(member_type))
- {push_translation_error("expected pointer to object type in array subscript",translation_data);return NULL;}
+ {
+ push_translation_error("expected pointer to object type in array subscript",translation_data);
+ push_translation_note("Instead got %T",translation_data,member_type);
+
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,OP_ARR_SUBSCRIPT));
+ }
return get_binary_expression_tree(left,right,get_expression_value_lvalue(get_temp_object(member_type)),OP_ARR_SUBSCRIPT);
left_lvalue=(struct Expression_Value_LValue*)left->value;
if(left_lvalue->type!=VALUE_LVALUE)
- { push_translation_error("nonlvalue on left side of . operator",translation_data);return NULL; }
+ {
+ struct AST_Expression *right;
+
+ push_translation_error("nonlvalue on left side of . operator",translation_data);
+
+ ret->right=(struct AST_Expression*)get_designator_tree(id,(struct Scope*)struct_union->inner_namespace,translation_data);
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,OP_MEMBER));
+ }
left_type=(struct Type_Struct_Union*)left_lvalue->object->type;
if(left_type->specifier!=TS_STRUCT && left_type->specifier!=TS_UNION)
- { push_translation_error("expected struct or union type",translation_data);return NULL; }
+ {
+ struct AST_Expression *right;
+
+ push_translation_error("expected struct or union type",translation_data);
+ push_translation_note("instead got %T",translation_data,left_type);
+
+ ret->right=(struct AST_Expression*)get_designator_tree(id,(struct Scope*)struct_union->inner_namespace,translation_data);
+ return (struct AST_Binary_Expression*) get_error_tree((struct AST*)get_binary_expression_tree(left,right,NULL,OP_MEMBER));
+ }
struct_union=left_type->struct_union;
{
struct AST_Expression *hold_derefernced;
hold_derefernced=(struct AST_Expression*)get_indirection_expression_tree(left,translation_data);
- if(hold_derefernced==NULL)
- {
- push_translation_error("in struct/union member access trough pointer",translation_data);
- return NULL;
- }else
- {
+ if(hold_derefernced->type==ERROR)
+ return (struct AST_Binary_Expression*)hold_derefernced;
+ else
return get_struct_union_member_tree(hold_derefernced,id,translation_data);
- }
}
struct AST_Conditional_Expression* get_conditional_expression_tree(struct AST_Expression *left,struct AST_Expression *center,struct AST_Expression *right,struct Translation_Data *translation_data)
ret->number_of_arguments=arg_list->size;
ret->arg_list=calloc(ret->number_of_arguments,sizeof(struct AST_Expression*));
+
for(i=0;i<ret->number_of_arguments;++i)
{
assert(arg_list->size>0);
ret->arg_list[i]=(struct AST_Expression*)Queue_Pop(arg_list);
}
+
assert(arg_list->size==0);
+
if(constraint_check_function_expression(ret,translation_data))
- {
return ret;
- }
else
- {
- delete_ast((struct AST*)ret);
- push_translation_error("constraint check violation in function call expression",translation_data);
- return NULL;
- }
+ return (struct AST_Function_Expression*)get_error_tree((struct AST*)ret);
}
struct AST_Unary_Expression* get_unary_expression_tree(struct AST_Expression *operand,struct Expression_Value *value,enum AST_Type type)
{
return ret;
}else
{
- delete_ast((struct AST*)operand);
- return NULL;
+ return operand->type==ERROR ? (struct AST_Unary_Expression*)operand : (struct AST_Unary_Expression*)get_error_tree((struct AST*)operand);
}
}
return ret;
}else
{
- delete_ast((struct AST*)operand);
- return NULL;
+ return operand->type==ERROR ? (struct AST_Unary_Expression*)operand : (struct AST_Unary_Expression*)get_error_tree((struct AST*)operand);
}
}
return get_unary_expression_tree(operand,get_expression_value_rvalue(get_temp_object(operand_type)),operation);
}else
{
- delete_ast((struct AST*)operand);
- return NULL;
+ return operand->type==ERROR ? (struct AST_Unary_Expression*)operand : (struct AST_Unary_Expression*)get_error_tree((struct AST*)operand);
}
}
struct AST_Unary_Expression* get_unary_bitwise_not_expression(struct AST_Expression *operand,struct Translation_Data *translation_data)
return get_unary_expression_tree(operand,get_expression_value_rvalue(get_temp_object(operand_type)),OP_BITWISE_NOT);
}else
{
- delete_ast((struct AST*)operand);
- return NULL;
+ return operand->type==ERROR ? (struct AST_Unary_Expression*)operand : (struct AST_Unary_Expression*)get_error_tree((struct AST*)operand);
}
}
struct AST_Unary_Expression* get_unary_logical_not_expression(struct AST_Expression *operand,struct Translation_Data *translation_data)
return get_unary_expression_tree(operand,get_expression_value_rvalue(get_temp_object(operand_type)),OP_LOGICAL_NOT);
}else
{
- delete_ast((struct AST*)operand);
- return NULL;
+ return operand->type==ERROR ? (struct AST_Unary_Expression*)operand : (struct AST_Unary_Expression*)get_error_tree((struct AST*)operand);
}
}
return get_unary_expression_tree(operand,get_expression_value_rvalue(get_temp_object(operand_type)),operation); /*TODO return expression value rvaluesness is under question*/
}else
{
- delete_ast((struct AST*)operand);
- return NULL;
+ return operand->type==ERROR ? (struct AST_Unary_Expression*)operand : (struct AST_Unary_Expression*)get_error_tree((struct AST*)operand);
}
}
struct AST_Unary_Expression* get_prefix_inc_dec_tree(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data)
return get_unary_expression_tree(operand,get_expression_value_rvalue(get_temp_object(operand_type)),operation); /*TODO return expression value rvaluesness is under question*/
}else
{
- delete_ast((struct AST*)operand);
- return NULL;
+ return operand->type==ERROR ? (struct AST_Unary_Expression*)operand : (struct AST_Unary_Expression*)get_error_tree((struct AST*)operand);
}
}
struct AST_Unary_Expression* get_unary_sizeof_tree(struct AST_Expression *operand,struct Translation_Data *translation_data)
{
- return NULL;
+ return (struct AST_Unary_Expression*)get_error_tree(NULL);
}
struct AST_Constant* get_constant_tree(struct Expression_Value *value)
{
F diff --git a/src/semantics/identifiers/denoted.h b/src/semantics/identifiers/denoted.h
--- a/src/semantics/identifiers/denoted.h
+++ b/src/semantics/identifiers/denoted.h
#include <linkage.h>
#include <object.h>
- /*
- todo : delete these if nothing subtle breaks
- enum Denotation_Type;
- enum Function_Specifier;
- */
-
-
struct Denoted
{
enum Denotation_Type denotation;
};
-
-
struct Denoted_Error
{
enum Denotation_Type denotation;
F diff --git a/src/semantics/identifiers/scope.c b/src/semantics/identifiers/scope.c
--- a/src/semantics/identifiers/scope.c
+++ b/src/semantics/identifiers/scope.c
struct Linkage *linkage;
resolve_object_linkage(current,translation_data,denoted_object);
if(has_new_errors(translation_data))
- {PO_ERROR("in declaration");}
+ {
+ push_translation_note("in declaration %D",translation_data,denoted_object);
+ delete_denoted_object(denoted_object);
+ return;
+ }
hold_object=CHECK_AND_PUSH(denoted_object,&AS_NORMAL_SCOPE(current)->ordinary);
if(hold_object!=NULL && hold_object->linkage==LINKAGE_NONE)
- {PO_ERROR("redeclaration of identifier %t ");}
+ {
+ push_translation_error("redeclaration of identifier %t",translation_data,denoted_object->id);
+ delete_denoted_object(denoted_object);
+ return;
+ }
if(denoted_object->linkage==LINKAGE_NONE)
{
if(hold_object!=NULL)
- {PO_ERROR("redeclaration of identifier");}
+ {
+ push_translation_error("redeclaration of identifier %t",translation_data,denoted_object->id);
+ delete_denoted_object(denoted_object);
+ return;
+ }
}else if(denoted_object->linkage==LINKAGE_EXTERNAL || denoted_object->linkage==LINKAGE_INTERNAL)
{
linkage=(denoted_object->linkage==LINKAGE_EXTERNAL?translation_data->external_linkage:translation_data->internal_linkage);
if(hold_object!=NULL)
{
if(hold_object->denotation!=DT_Object)
- {PO_ERROR("linking an object to a function");}
- if(!types_are_identical(hold_object->object->type,denoted_object->object->type))
- {PO_ERROR("linking an objects with mismatching types");}
- if(denoted_object->initializer!=NULL)
+ {
+ push_translation_error("linking an object to a function %D",translation_data,denoted_object);
+ push_translation_note("linking against %D",translation_data,hold_object);
+ delete_denoted_object(denoted_object);
+ return;
+ }else if(!types_are_identical(hold_object->object->type,denoted_object->object->type))
+ {
+ push_translation_error("linking objects with mismatching types",translation_data);
+ push_translation_note("%t has type %T",translation_data,denoted_object->id,denoted_object->object->type);
+ push_translation_note("whilst %t has type %T",translation_data,hold_object->id,hold_object->object->type);
+ delete_denoted_object(denoted_object);
+ return;
+ }else if(denoted_object->initializer!=NULL)
{
if(hold_object->initializer==NULL)
hold_object->initializer=denoted_object->initializer;
F diff --git a/src/semantics/value/constraints.c b/src/semantics/value/constraints.c
--- a/src/semantics/value/constraints.c
+++ b/src/semantics/value/constraints.c
{
struct Type *left_type;
struct Type *right_type;
+
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
left_type=extract_expresion_value_type(left->value,translation_data);
right_type=extract_expresion_value_type(right->value,translation_data);
if(!type_is_integer_type(left_type))
/*constraints only on modulo operation 6.5.5*/
char constraint_check_multiplicative_expression(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
{
+
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
if(operation==OP_REMAINDER)
{
return constraint_check_modulo_expression(left,right,translation_data);
struct Type *left_type;
struct Type *right_type;
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
+
assert(operation==OP_SUBTRACTION || operation==OP_ADDITION);
{
struct Type *left_type;
struct Type *right_type;
+
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
left_type=extract_expresion_value_type(left->value,translation_data);
right_type=extract_expresion_value_type(right->value,translation_data);
if(type_is_integer_type(left_type) && type_is_integer_type(right_type))
}
char constraint_check_bitwise_expression(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
{
+
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
return 1;
}
/*
* */
char constraint_check_relational_operation(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type operation,struct Translation_Data *translation_data)
{
+
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
return 1;
}
/* One of the following shall hold:
{
struct Type *left_type;
struct Type *right_type;
+
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
left_type=extract_expresion_value_type(left->value,translation_data);
right_type=extract_expresion_value_type(right->value,translation_data);
if(type_is_arithmetic(left_type) && type_is_arithmetic(right_type))
{
struct Type *left_type;
struct Type *right_type;
+
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
left_type=extract_expresion_value_type(left->value,translation_data);
right_type=extract_expresion_value_type(right->value,translation_data);
struct Type *left_type;
struct Type *right_type;
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
+
if(!expression_value_is_modifiable(left->value))
{
push_translation_error("left operand of assignment operator must be modifiable",translation_data);
struct Type *left_type;
struct Type *right_type;
+
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
if(!expression_value_is_modifiable(left->value))
{
push_translation_error("left operand of assignment operator must be modifiable",translation_data);
*/
char constraint_check_comma_expression(struct AST_Expression *left,struct AST_Expression *right,struct Translation_Data *translation_data)
{
+
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
return 1;
}
/*
struct Type *left_type;
struct Type *right_type;
+ if(left->type==ERROR || right->type==ERROR)
+ return 0;
+
+
left_type=extract_expresion_value_type(left->value,translation_data);
right_type=extract_expresion_value_type(right->value,translation_data);
char constraint_check_struct_union_member_expression(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data)
{
struct Type *left_type;
+
+ if(left->type==ERROR)
+ return 0;
+
left_type=extract_expresion_value_type(left->value,translation_data);
return type_is_struct_union(left_type);
}
char constraint_check_struct_union_member_trough_ptr_expression(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data)
{
struct Type *left_type;
+
+ if(left->type==ERROR)
+ return 0;
+
left_type=extract_expresion_value_type(left->value,translation_data);
if(type_is_pointer_to_object(left_type))
{
char constraint_check_conditional_expression(struct AST_Expression *left,struct AST_Expression *center,struct AST_Expression *right,struct Translation_Data *translation_data)
{
struct Type *left_type;
+
+ if(left->type==ERROR || center->type==ERROR || right->type==ERROR)
+ return 0;
+
left_type=extract_expresion_value_type(left->value,translation_data);
if(!type_is_arithmetic(left_type))
{
struct Type *given_argument_type;
struct Type_Function *proposed_function_type;
size_t i;
+
+ if(proposed_function->type==ERROR)
+ return 0;
proposed_function_type=(struct Type_Function*)extract_expresion_value_type(proposed_function->id->value,translation_data);
if(proposed_function_type->specifier!=TS_FUNC)
char constraint_check_indirection_expression(struct AST_Expression *operand,struct Translation_Data *translation_data)
{
struct Type *operand_type;
+
+ if(operand->type==ERROR)
+ return 0;
+
operand_type=extract_expresion_value_type(operand->value,translation_data);
if(operand_type->specifier==TS_POINTER)
{
char constraint_check_address_expression(struct AST_Expression *operand,struct Translation_Data *translation_data)
{
struct Type *operand_type;
+
+ if(operand->type==ERROR)
+ return 0;
+
operand_type=extract_expresion_value_type(operand->value,translation_data);
if(operand->value->type==VALUE_FUNCTION_DESIGNATOR || operand->type==OP_ARR_SUBSCRIPT || operand->type==OP_DEREFERENCE)
{
}
char constraint_check_sizeof_by_type(struct Type *type)
{
- return 1;
+ if(type->specifier==TS_ERROR)
+ return 0;
+ else
+ return 1;
}
char constraint_check_sizeof_expression(struct AST_Expression *expression,struct Translation_Data *translation_data)
{
- return 1;
+ if(expression->type==ERROR)
+ return 0;
+ else
+ return 1;
}
/*
* operand shall have arithmetic type
char constraint_check_unary_plus_minus(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data)
{
struct Type *operand_type;
+
+ if(operand->type==ERROR)
+ return 0;
+
operand_type=extract_expresion_value_type(operand->value,translation_data);
if(type_is_arithmetic(operand_type))
{
char constraint_check_unary_bitwise_not(struct AST_Expression *operand,struct Translation_Data *translation_data)
{
struct Type *operand_type;
+
+ if(operand->type==ERROR)
+ return 0;
+
operand_type=extract_expresion_value_type(operand->value,translation_data);
if(type_is_integer_type(operand_type))
{
char constraint_check_unary_logical_not(struct AST_Expression *operand,struct Translation_Data *translation_data)
{
struct Type *operand_type;
+
+ if(operand->type==ERROR)
+ return 0;
+
operand_type=extract_expresion_value_type(operand->value,translation_data);
if(type_is_scalar(operand_type))
{
{
struct Type *operand_type;
+ if(operand->type==ERROR)
+ return 0;
+
if(!expression_value_is_modifiable(operand->value))
{
push_translation_error("expected modifiable lvalue as operand to the ++/-- operator",translation_data);
* */
char constraint_check_prefix_inc_dec_expression(struct AST_Expression *operand,enum AST_Type operation,struct Translation_Data *translation_data)
{
+ if(operand->type==ERROR)
+ return 0;
return constraint_check_postfix_inc_dec_expression(operand,operation,translation_data);
}
char constraint_check_cast_expression(struct Type *type,struct AST_Expression *expression,struct Translation_Data *translation_data)
{
+ if(expression->type==ERROR || type->specifier==TS_ERROR)
+ return 0;
return 1;
}
#endif