F diff --git a/src/backend/print/print.c b/src/backend/print/print.c
--- a/src/backend/print/print.c
+++ b/src/backend/print/print.c
}
void print_function_expression_tree(FILE *out,struct AST_Function_Expression *function_call)
{
- size_t i;
+ struct Queue_Node *it;
print_ast(out,(struct AST*)function_call->id);
fprintf(out,"(");
- if(function_call->number_of_arguments>0)
+ if(function_call->arguments.size>0)
{
- for(i=0;i<function_call->number_of_arguments;++i)
+ fprintf(out,"\n");
+ for(it=function_call->arguments.first;it!=function_call->arguments.last;it=it->prev)
{
- print_ast(out,(struct AST*)function_call->arg_list[i]);
- if(i!=function_call->number_of_arguments-1)
- fprintf(out,",");
+ print_ast(out,(struct AST*)(struct AST*)(it->data));
+ fprintf(out,",\n");
}
+ if(it!=NULL)
+ {
+ print_ast(out,(struct AST*)(struct AST*)(it->data));
+ }
+
}
fprintf(out,")");
}
F diff --git a/src/frontend/parse/parse_declaration.c b/src/frontend/parse/parse_declaration.c
--- a/src/frontend/parse/parse_declaration.c
+++ b/src/frontend/parse/parse_declaration.c
/*check if this is a function definition*/
if(parse_function_definitions && get_and_check(translation_data,KW_OPEN_CURLY))
{
- struct Type_Function *function_type;
- function_type=(struct Type_Function*)((struct Denoted_Function*)hold)->type;
((struct Denoted_Function*)hold) ->body=
- (struct AST_Compound_Statement*)parse_finish_compound_statement(translation_data,(struct Scope*)function_type->function_prototype_scope);
+ (struct AST_Compound_Statement*)parse_finish_compound_statement(translation_data,scope);
Queue_Push(where_to_push,get_function_definition_tree(scope,(struct Denoted_Function*)hold));
Scope_Push(scope,hold,translation_data);
break;
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
struct AST_Function_Expression* parse_arglist(struct Translation_Data *translation_data,struct Scope *scope,struct AST_Expression* id)
{
struct AST_Function_Expression *ret;
- struct AST_Expression *hold_expression;
- struct Queue arg_list;
-
- Queue_Init(&arg_list);
+ ret=get_function_expression_tree(id,scope);
+ ret->id=id;
if(get_and_check(translation_data,KW_CLOSE_NORMAL))
{
- return get_function_expression_tree(id,&arg_list,translation_data);
+ return ret;
}
-
do
{
- hold_expression=parse_assignment_expression(translation_data,scope);
- if(hold_expression==NULL)
- {
- while(arg_list.size>0)
- delete_ast((struct AST*)Queue_Pop(&arg_list));
- 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));
-
- ret=get_function_expression_tree(id,&arg_list,translation_data);
- assert(arg_list.size==0);
-
+ Queue_Push(&ret->arguments,parse_assignment_expression(translation_data,scope));
+ } while(get_and_check(translation_data,KW_COMMA));
if(get_and_check(translation_data,KW_CLOSE_NORMAL))
{
return ret;
}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);
}
}
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 *left_type;
left_type=extract_expresion_value_type(left->value,translation_data);
- left_type=get_unqualified_version_of_type(left_type,translation_data);
+ left_type=get_unqualified_version_of_type(left_type);
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);
{
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);
+ left_type=get_unqualified_version_of_type(left_type);
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 ret;
}
- struct AST_Function_Expression* get_function_expression_tree(struct AST_Expression *id,struct Queue *arg_list,struct Translation_Data *translation_data)
+ struct AST_Function_Expression* get_function_expression_tree(struct AST_Expression *id,struct Scope *scope)
{
struct AST_Function_Expression *ret;
- struct Type_Function *id_type;
- size_t i;
-
- id_type=(struct Type_Function*)extract_expresion_value_type(id->value,translation_data);
ret=malloc(sizeof(struct AST_Function_Expression));
ret->type=OP_FUNCTION;
- ret->value=get_expression_value_rvalue(get_temp_object(id_type->return_type));
ret->id=id;
- 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;
- }
+ Queue_Init(&ret->arguments);
+ return ret;
}
struct AST_Unary_Expression* get_unary_expression_tree(struct AST_Expression *operand,struct Expression_Value *value,enum AST_Type type)
{
void delete_ast_function_expression(struct AST_Function_Expression *function_expression)
{
struct Queue_Node *it;
- size_t i;
-
if(function_expression->id!=NULL)
delete_ast((struct AST*)function_expression->id);
- if(function_expression->number_of_arguments!=0)
- {
- for(i=0;i<function_expression->number_of_arguments;++i)
- {
- delete_ast((struct AST*)function_expression->arg_list[i]);
- }
- free(function_expression->arg_list);
- }
+ while(function_expression->arguments.size>0)
+ delete_ast(Queue_Pop(&function_expression->arguments));
free(function_expression);
F diff --git a/src/semantics/ast.h b/src/semantics/ast.h
--- a/src/semantics/ast.h
+++ b/src/semantics/ast.h
struct Expression_Value *value;
struct AST_Expression *id;
-
- size_t number_of_arguments;
- struct AST_Expression **arg_list;
+ /*queue of astrees*/
+ struct Queue arguments;
};
struct AST_Constant
struct AST_Binary_Expression* get_struct_union_member_trough_ptr_tree(struct AST_Expression *left,struct token *id,struct Translation_Data *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);
- struct AST_Function_Expression* get_function_expression_tree(struct AST_Expression *id,struct Queue *arg_list,struct Translation_Data *translation_data);
+ struct AST_Function_Expression* get_function_expression_tree(struct AST_Expression *id,struct Scope *scope);
struct AST_Unary_Expression* get_unary_expression_tree(struct AST_Expression *operand,struct Expression_Value *value,enum AST_Type type);
struct AST_Unary_Expression* get_indirection_expression_tree(struct AST_Expression *operand,struct Translation_Data *translation_data);
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
}
}
}
- char constraint_check_function_expression(struct AST_Function_Expression *proposed_function,struct Translation_Data *translation_data)
+ char constraint_check_function_expression(struct AST_Expression *id,struct Scope *scope,struct Translation_Data *translation_data)
{
- struct Type *expected_argument_type;
- struct Type *given_argument_type;
- struct Type_Function *proposed_function_type;
- size_t i;
-
- proposed_function_type=(struct Type_Function*)extract_expresion_value_type(proposed_function->id->value,translation_data);
- if(proposed_function_type->specifier!=TS_FUNC)
- {
- push_translation_error("is not a function",translation_data);
- return 0;
- }
-
- if(proposed_function_type->number_of_arguments!=proposed_function->number_of_arguments)
- {
- push_translation_error("mismatching number of arguments",translation_data);
- return 0;
- }
-
- for(i=0;i<proposed_function->number_of_arguments;++i)
- {
- expected_argument_type=proposed_function_type->arguments[i]->object->type;
- given_argument_type=extract_expresion_value_type(proposed_function->arg_list[i]->value,translation_data);
- if(!types_are_compatible_unqualified(expected_argument_type,given_argument_type))
- {
- push_translation_error("incompatible types of argument",translation_data);
- return 0;
- }
- }
return 1;
}
char constraint_check_indirection_expression(struct AST_Expression *operand,struct Translation_Data *translation_data)
F diff --git a/src/semantics/value/constraints.h b/src/semantics/value/constraints.h
--- a/src/semantics/value/constraints.h
+++ b/src/semantics/value/constraints.h
char constraint_check_struct_union_member_expression(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data);
char constraint_check_struct_union_member_trough_ptr_expression(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data);
char constraint_check_conditional_expression(struct AST_Expression *left,struct AST_Expression *center,struct AST_Expression *right,struct Translation_Data *translation_data);
- char constraint_check_function_expression(struct AST_Function_Expression *proposed_function,struct Translation_Data *translation_data);
+ char constraint_check_function_expression(struct AST_Expression *id,struct Scope *scope,struct Translation_Data *translation_data);
char constraint_check_indirection_expression(struct AST_Expression *operand,struct Translation_Data *translation_data);
char constraint_check_address_expression(struct AST_Expression *operand,struct Translation_Data *translation_data);
char constraint_check_sizeof_by_type(struct Type *type);
F diff --git a/src/semantics/value/type.c b/src/semantics/value/type.c
--- a/src/semantics/value/type.c
+++ b/src/semantics/value/type.c
}
struct Type* get_type_bitfield(struct Type *base,struct AST* number_of_bits,struct Translation_Data *translation_data)
{
- size_t hold_number_of_bits=0;
-
- assert(number_of_bits!=NULL);
- hold_number_of_bits=evaluate_const_expression_integer(number_of_bits,translation_data);
- delete_ast(number_of_bits);
-
- return get_type_bitfield_inner(base,hold_number_of_bits,translation_data);
-
- }
- struct Type* get_type_bitfield_inner(struct Type *base,size_t number_of_bits,struct Translation_Data *translation_data)
- {
-
struct Type_Bit_Field *ret;
ret=calloc(1,sizeof(struct Type_Bit_Field));
ret->specifier=TS_BITFIELD;
- ret->number_of_bits=number_of_bits;
+
+ assert(number_of_bits!=NULL);
+ ret->number_of_bits=evaluate_const_expression_integer(number_of_bits,translation_data);
+ delete_ast(number_of_bits);
ret->base=base;
}
/*TODO*/
- struct Type* get_unqualified_version_of_type(struct Type *type,struct Translation_Data *translation_data)
+ struct Type* get_unqualified_version_of_type(struct Type *type)
{
- struct Denotation_Prototype *prototype;
- struct Type *hold_unqualified_type;
-
- prototype=(struct Denotation_Prototype*)get_denotation_prototype(translation_data->types);
-
- switch(type->specifier)
- {
- case TS_VOID:
- case TS_CHAR:
- case TS_INT:
- case TS_FLOAT:
- case TS_DOUBLE:
- prototype->specifier=type->specifier;
-
- hold_unqualified_type=get_basic_type(prototype);
- break;
- case TS_STRUCT:
- case TS_UNION:
- prototype->specifier=type->specifier;
- prototype->struct_union=((struct Type_Struct_Union*)type)->struct_union;
- hold_unqualified_type=get_struct_union_type(prototype);
- break;
- case TS_ENUM:
- prototype->specifier=TS_ENUM;
- prototype->enumerator=((struct Type_Enum*)type)->enumeration;
-
- hold_unqualified_type=get_enum_type(prototype);
- break;
- case TS_POINTER:
- hold_unqualified_type=get_pointer_type(((struct Type_Pointer*)type)->points_to,0,0);
- break;
- case TS_ARRAY:
- hold_unqualified_type=type;
- break;
- case TS_FUNC:
- hold_unqualified_type=type;
- break;
- case TS_BITFIELD:
- hold_unqualified_type=get_type_bitfield_inner(((struct Type_Bit_Field*)type)->base,((struct Type_Bit_Field*)type)->number_of_bits,translation_data);
- break;
- default:
- return NULL;
-
- }
- delete_denoted_prototype(prototype);
- return hold_unqualified_type;
+ return type;
}
/*TODO*/
int type_get_integer_conversion_rank(struct Type_Basic *type)
F diff --git a/src/semantics/value/type.h b/src/semantics/value/type.h
--- a/src/semantics/value/type.h
+++ b/src/semantics/value/type.h
struct Type* get_array_type(struct Type *array_of,struct AST* number_of_elements,struct Translation_Data *translation_data);
struct Type* get_enum_type(struct Denotation_Prototype *prototype);
struct Type* get_type_bitfield(struct Type *base,struct AST* number_of_bits,struct Translation_Data *translation_data);
- struct Type* get_type_bitfield_inner(struct Type *base,size_t number_of_bits,struct Translation_Data *translation_data);
struct Type* get_function_type(struct Type *return_type,struct Queue *parameters,struct Normal_Scope* function_prototype_scope);
struct Type_Basic* get_type_insecure(enum Type_Specifier type_specifier,enum Type_Signedness sign,enum Type_Constraint constraint,size_t type_size,struct Translation_Data *translation_data);
struct Type* get_type_for_promotion(struct Type *type,struct Translation_Data *translation_data);
- struct Type* get_unqualified_version_of_type(struct Type *type,struct Translation_Data *translation_data);
+ struct Type* get_unqualified_version_of_type(struct Type *type);
void delete_enum(struct Enum *enumeration);
void delete_struct_union(struct Struct_Union *su);