F diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txtsrc/semantics/value/type.csrc/semantics/value/evaluation.csrc/semantics/value/constant.c+ src/semantics/value/value.csrc/semantics/identifiers/denoted.csrc/semantics/identifiers/scope.csrc/semantics/identifiers/linkage.c- src/backend/js/transpile_to_js.csrc/program/gcc_error.csrc/program/gcc_arguments.csrc/program/program.cF diff --git a/src/backend/js/transpile_to_js.c b/src/backend/js/transpile_to_js.c deleted file mode 100644 --- a/src/backend/js/transpile_to_js.c +++ /dev/null- #ifndef WONKY_TRANSPILE_TO_JS_C- #define WONKY_TRANSPILE_TO_JS_C WONKY_TRANSPILE_TO_JS_C- #include <transpile_to_js.h>--- void transpile_to_javascript(FILE* out,struct Program *program,struct Command_Arguments *command_arguments)- {- struct Queue_Node *it;-- if(command_arguments->insert_html)- {- fprintf(out,"<DOCTYPE! html> <html> <head> <title>asdf</title> <script>");- }- to_js_print_externs(out,program,command_arguments);-- for(it=program->translation_units->first;it!=NULL;it=it->prev)- {- fprintf(out,"{");- to_js_print_statics(out,(struct AST_Translation_Unit*)it->data,command_arguments);- fprintf(out,"\n");- to_js_print_translation_unit_tree(out,(struct AST_Translation_Unit*)it->data,program);- fprintf(out,"\n}\n");- }-- if(command_arguments->insert_html)- {- fprintf(out,"</script> </head> <body> </body> </html>");- }-- }-- void _to_js_print_externs(void *denoted,void *args)- {- #define ARGS(x) ((struct Command_Arguments*)x)- #define DENOTED(x) ((struct Denoted*)x)- #define DFUNC(x) ((struct Denoted_Function*)x)- #define DOBJ(x) ((struct Denoted_Object*)x)- if(DENOTED(denoted)->denotation==DT_Function)- {- if(DFUNC(denoted)->body==NULL)- {- fprintf(ARGS(args)->output_file,"/*UNDEFINED*/");- }- fprintf(ARGS(args)->output_file,"var ");- print_token(ARGS(args)->output_file,DFUNC(denoted)->id);- fprintf(ARGS(args)->output_file,";");- fprintf(ARGS(args)->output_file,"\n");-- }else if(DENOTED(denoted)->denotation==DT_Object)- {- fprintf(ARGS(args)->output_file,"var ");- print_token(ARGS(args)->output_file,DFUNC(denoted)->id);- fprintf(ARGS(args)->output_file,";\n");- }-- #undef DOBJ- #undef DFUNC- #undef ARGS- #undef DENOTED- }- void _to_js_print_statics(void *denoted,void *args)- {- #define ARGS(x) ((struct Command_Arguments*)x)- #define DENOTED(x) ((struct Denoted*)x)- #define DFUNC(x) ((struct Denoted_Function*)x)- #define DOBJ(x) ((struct Denoted_Object*)x)- if(DENOTED(denoted)->denotation==DT_Function)- {- if(DFUNC(denoted)->body==NULL)- {- fprintf(ARGS(args)->output_file,"/*UNDEFINED*/");- }- fprintf(ARGS(args)->output_file,"let ");- print_token(ARGS(args)->output_file,DFUNC(denoted)->id);- fprintf(ARGS(args)->output_file,";");- fprintf(ARGS(args)->output_file,"\n");-- }else if(DENOTED(denoted)->denotation==DT_Object)- {- fprintf(ARGS(args)->output_file,"let ");- print_token(ARGS(args)->output_file,DFUNC(denoted)->id);- fprintf(ARGS(args)->output_file,";");- }-- #undef DOBJ- #undef DFUNC- #undef ARGS- #undef DENOTED- }- void to_js_print_externs(FILE* out,struct Program *program,struct Command_Arguments *command_arguments)- {- fprintf(out,"\n/*EXTERNS START*/\n");- Map_Map_Extended(- &program->external_linkage->ids- ,_to_js_print_externs- ,command_arguments);- fprintf(out,"\n/*EXTERNS END*/\n");- }-- void to_js_print_statics(FILE* out,struct AST_Translation_Unit *translation_unit,struct Command_Arguments* command_arguments)- {-- Map_Map_Extended(- &((struct Normal_Scope*)translation_unit->file_scope)->ordinary- ,_to_js_print_statics- ,command_arguments);- }- void to_js_print_ast(FILE* out,struct AST *tree,struct Program *program)- {- if(tree==NULL)- {- return ;- }- switch(tree->type)- {- case OP_MEMBER_TROUGH_PTR:- case OP_MEMBER:- case OP_BITWISE_AND:- case OP_BITWISE_XOR:- case OP_BITWISE_NOT:- case OP_LOGICAL_AND:- case OP_LOGICAL_OR:- case OP_XOR_ASSIGN:- case OP_PIPE_ASSIGN:- case OP_SHIFT_RIGHT_ASSIGN:- case OP_ADD_ASSIGN:- case OP_SUBTRACT_ASSIGN:- case OP_MULTIPLY_ASSIGN:- case OP_REMAINDER_ASSIGN:- case OP_DIV_ASSIGN:- case OP_SUBTRACTION:- case OP_MUL:- case OP_DIV:- case OP_REMAINDER:- case OP_EQUAL:- case OP_LESS:- case OP_LESS_EQ:- case OP_SHIFT_LEFT:- case OP_BITWISE_OR:- case OP_AND_ASSIGN:- case OP_ARR_SUBSCRIPT:- case OP_SHIFT_LEFT_ASSIGN:- case OP_ASSIGN:- case OP_ADDITION:- case OP_COMMA:- case OP_SHIFT_RIGHT:- case OP_GREATER_EQ:- case OP_GREATER:- case OP_NOT_EQUAL:- to_js_print_binary_expression_tree(out,(struct AST_Binary_Expression*)tree,program);- break;- case OP_COND:- to_js_print_conditional_expression_tree(out,(struct AST_Conditional_Expression*)tree,program);- break;- case OP_FUNCTION:- to_js_print_function_expression_tree(out,(struct AST_Function_Expression*)tree,program);- break;- case OP_LOGICAL_NOT:- case OP_UNARY_MINUS:- case OP_SIZEOF:- case OP_ADDR_OF:- case OP_DEREFERENCE:- case OP_POSTFIX_INC:- case OP_PREFIX_INC:- case OP_UNARY_PLUS:- case OP_POSTFIX_DEC:- case OP_PREFIX_DEC:- case OP_CAST:- to_js_print_unary_expression_tree(out,(struct AST_Unary_Expression*)tree,program);- break;- case OP_LVALUE:- to_js_print_lvalue_expression_tree(out,(struct AST_Lvalue_Expression*)tree,program);- break;- case OP_NOP:- fprintf(out,"NOP");- break;-- case ST_SWITCH:- to_js_print_switch_statement_tree(out,(struct AST_Switch_Statement*)tree,program);- break;- case ST_IF:- to_js_print_if_statement_tree(out,(struct AST_If_Statement*)tree,program);- break;- case ST_WHILE:- to_js_print_while_statement_tree(out,(struct AST_While_Statement*)tree,program);- break;- case ST_DO_WHILE:- to_js_print_do_while_statement_tree(out,(struct AST_Do_While_Statement*)tree,program);- break;- case ST_GOTO:- to_js_print_goto_statement_tree(out,(struct AST_Goto_Statement*)tree,program);- break;- case ST_DEFAULT:- case ST_LABEL:- case ST_CASE:- to_js_print_labeled_statement_tree(out,(struct AST_Labeled_Statement*)tree,program);- break;- case ST_CONTINUE:- fprintf(out,"continue");- break;- case ST_BREAK:- fprintf(out,"break");- break;- case ST_RETURN:- to_js_print_return_statement_tree(out,(struct AST_Return_Statement*)tree,program);- break;- case ST_FOR:- to_js_print_for_statement_tree(out,(struct AST_For_Statement*)tree,program);- break;- case ST_COMPOUND:- to_js_print_compound_statement_tree(out,(struct AST_Compound_Statement*)tree,program);- break;- case ST_OBJECT_DECLARATION:- to_js_print_object_declaration_tree(out,((struct AST_Object_Declaration*)tree),program);- if(((struct AST_Object_Declaration*)tree)->object->initializer!=NULL)- {- fprintf(out,"=");- to_js_print_ast(out,((struct AST_Object_Declaration*)tree)->object->initializer,program);- }- break;- case ST_FUNCTION_DECLARATION:- to_js_print_function_declaration_tree(out,((struct AST_Function_Declaration*)tree),program);- break;- case ST_FUNCTION_DEFINITION:- to_js_print_function_definition(out,((struct AST_Function_Definition*)tree),program);- break;- case TRANSLATION_UNIT:- to_js_print_translation_unit_tree(out,(struct AST_Translation_Unit*)tree,program);- break;- case ERROR:- default:- /*TODO error*/- return;- }- }- void to_js_print_translation_unit_tree(FILE* out,struct AST_Translation_Unit *translation_unit,struct Program *program)- {- struct Queue_Node *it;- struct AST* hold;- for(it=translation_unit->components.first;it!=NULL;it=it->prev)- {- hold=(struct AST*)(it->data);- to_js_print_ast(out,hold,program);-- fprintf(out,";\n");- }- }- void to_js_print_binary_expression_tree(FILE* out,struct AST_Binary_Expression *bin,struct Program *program)- {- if(bin->type==OP_ARR_SUBSCRIPT)- {- to_js_print_ast(out,bin->left,program);- fprintf(out,"[");- to_js_print_ast(out,bin->right,program);- fprintf(out,"]");- }else- {- fprintf(out,"(");- to_js_print_ast(out,bin->left,program);- print_ast_enum(out,bin->type);- to_js_print_ast(out,bin->right,program);- fprintf(out,")");- }- }-- void to_js_print_conditional_expression_tree(FILE* out,struct AST_Conditional_Expression *cond,struct Program *program)- {- fprintf(out,"(");- to_js_print_ast(out,cond->left,program);- fprintf(out,"?");- to_js_print_ast(out,cond->center,program);- fprintf(out,":");- to_js_print_ast(out,cond->right,program);- fprintf(out,")");- }- void to_js_print_function_expression_tree(FILE* out,struct AST_Function_Expression *function_call,struct Program *program)- {- struct Queue_Node *it;- to_js_print_ast(out,function_call->id,program);- fprintf(out,"(");- if(function_call->arguments.size>0)- {- fprintf(out,"\n");- for(it=function_call->arguments.first;it!=function_call->arguments.last;it=it->prev)- {- to_js_print_ast(out,(struct AST*)(it->data),program);- fprintf(out,",\n");- }- if(it!=NULL)- {- to_js_print_ast(out,(struct AST*)(it->data),program);- }-- }- fprintf(out,")");- }- void to_js_print_lvalue_expression_tree(FILE* out,struct AST_Lvalue_Expression *lval,struct Program *program)- {- print_denoted(out,lval->lvalue);- }- void to_js_print_unary_expression_tree(FILE* out,struct AST_Unary_Expression *unary,struct Program *program)- {- print_ast_enum(out,unary->type);- to_js_print_ast(out,unary->operand,program);- }- void to_js_print_labeled_statement_tree(FILE* out,struct AST_Labeled_Statement *label,struct Program *program)- {- if(label->type!=ST_LABEL)- print_ast_enum(out,label->type);- if(label->label!=NULL)- {- fprintf(out,"case");- print_token(out,label->label);- }- fprintf(out,":\n");- to_js_print_ast(out,label->statement,program);- }- void to_js_print_compound_statement_tree(FILE* out,struct AST_Compound_Statement *compound,struct Program *program)- {- struct Queue_Node *it;- fprintf(out,"{");- for(it=compound->components.first;it!=NULL;it=it->prev)- {- fprintf(out,"\n");- to_js_print_ast(out,(struct AST*)it->data,program);- fprintf(out,";");- }- fprintf(out,"\n}");- }- void to_js_print_for_statement_tree(FILE* out,struct AST_For_Statement *for_statement,struct Program *program)- {- fprintf(out,"for(\n");- if(for_statement->initialisation!=NULL)- to_js_print_ast(out,for_statement->initialisation,program);- fprintf(out,";\n");- if(for_statement->condition!=NULL)- to_js_print_ast(out,for_statement->condition,program);- fprintf(out,";\n");- if(for_statement->update!=NULL)- to_js_print_ast(out,for_statement->update,program);- fprintf(out,")\n");- print_ast(out,for_statement->body_statement);- }- void to_js_print_while_statement_tree(FILE* out,struct AST_While_Statement *while_statement,struct Program *program)- {- fprintf(out,"while(");- to_js_print_ast(out,while_statement->condition,program);- fprintf(out,")\n");- to_js_print_ast(out,while_statement->body_statement,program);- }- void to_js_print_do_while_statement_tree(FILE* out,struct AST_Do_While_Statement *do_while_statement,struct Program *program)- {- fprintf(out,"do\n");- to_js_print_ast(out,do_while_statement->body_statement,program);- fprintf(out,"while(");- to_js_print_ast(out,do_while_statement->condition,program);- fprintf(out,")\n");- }- void to_js_print_if_statement_tree(FILE* out,struct AST_If_Statement *if_statement,struct Program *program)- {- fprintf(out,"if(");- to_js_print_ast(out,if_statement->condition,program);- fprintf(out,")\n");- to_js_print_ast(out,if_statement->body_statement,program);-- if(if_statement->else_statement!=NULL)- {- fprintf(out,"\nelse");- to_js_print_ast(out,if_statement->else_statement,program);- }- }- void to_js_print_goto_statement_tree(FILE* out,struct AST_Goto_Statement *goto_statement,struct Program *program)- {- /*TODO something here, be it error or not*/- }- void to_js_print_switch_statement_tree(FILE* out,struct AST_Switch_Statement *switch_statement,struct Program *program)- {- fprintf(out,"switch(");- to_js_print_ast(out,switch_statement->condition,program);- fprintf(out,")\n");- to_js_print_ast(out,switch_statement->body_statement,program);- }- void to_js_print_return_statement_tree(FILE* out,struct AST_Return_Statement *return_statement,struct Program *program)- {- fprintf(out,"return ");- to_js_print_ast(out,return_statement->return_expression,program);- }- void to_js_print_object_declaration_tree(FILE* out,struct AST_Object_Declaration *object_declaration,struct Program *program)- {- if(object_declaration->object->object->storage_class!=SCS_EXTERN)- {- fprintf(out,"let ");- print_token(out,object_declaration->object->id);- }-- }- void to_js_print_function_definition(FILE* out,struct AST_Function_Definition *function_definition,struct Program *program)- {- size_t i;- struct Type_Function *cache_type;-- cache_type=(struct Type_Function*)function_definition->function->type;-- if((struct Type_Function*)function_definition->function->linkage==LINKAGE_EXTERNAL)- {- // fprintf(out,"var ");- print_token(out,function_definition->function->id);- fprintf(out,"= function");- }else- {- fprintf(out,"function ");- print_token(out,function_definition->function->id);- }-- /*print parameters*/- fprintf(out,"(");- if(cache_type->number_of_arguments!=0)- {- print_token(out,cache_type->arguments[0]->id);- for(i=1;i<cache_type->number_of_arguments;++i)- {- fprintf(out,",");- print_token(out,cache_type->arguments[i]->id);- }- }-- fprintf(out,")");-- /*print body*/- to_js_print_compound_statement_tree(out,function_definition->function->body,program);--- }- void to_js_print_function_declaration_tree(FILE* out,struct AST_Function_Declaration *function_declaration,struct Program *program)- {- /*TODO probably leave it empty*/- }---- #endifF diff --git a/src/backend/js/transpile_to_js.h b/src/backend/js/transpile_to_js.h deleted file mode 100644 --- a/src/backend/js/transpile_to_js.h +++ /dev/null- #ifndef WONKY_TRANSPILE_TO_JS_H- #define WONKY_TRANSPILE_TO_JS_H WONKY_TRANSPILE_TO_JS_H- #include <program.h>- #include <gcc_arguments.h>- #include <stdio.h>- #include <print.h>--- void transpile_to_javascript(FILE* out,struct Program *program,struct Command_Arguments *command_arguments);-- void _to_js_print_externs(void *denoted,void *args);- void to_js_print_externs(FILE* out,struct Program *program,struct Command_Arguments *command_arguments);-- void _to_js_print_statics(void *denoted,void *args);- void to_js_print_statics(FILE* out,struct AST_Translation_Unit *translation_unit,struct Command_Arguments* command_arguments);-- void to_js_print_ast(FILE* out,struct AST *tree,struct Program *program);- void to_js_print_translation_unit_tree(FILE* out,struct AST_Translation_Unit *translation_unit,struct Program *program);- void to_js_print_binary_expression_tree(FILE* out,struct AST_Binary_Expression *bin,struct Program *program);- void to_js_print_conditional_expression_tree(FILE* out,struct AST_Conditional_Expression *cond,struct Program *program);- void to_js_print_function_expression_tree(FILE* out,struct AST_Function_Expression *function_call,struct Program *program);- //void to_js_print_lvalue_expression_tree(FILE* out,struct AST_Lvalue_Expression *lval,struct Program *program);- void to_js_print_unary_expression_tree(FILE* out,struct AST_Unary_Expression *unary,struct Program *program);- void to_js_print_labeled_statement_tree(FILE* out,struct AST_Labeled_Statement *label,struct Program *program);- void to_js_print_compound_statement_tree(FILE* out,struct AST_Compound_Statement *compound,struct Program *program);- void to_js_print_for_statement_tree(FILE* out,struct AST_For_Statement *for_statement,struct Program *program);- void to_js_print_while_statement_tree(FILE* out,struct AST_While_Statement *while_statement,struct Program *program);- void to_js_print_do_while_statement_tree(FILE* out,struct AST_Do_While_Statement *do_while_statement,struct Program *program);- void to_js_print_if_statement_tree(FILE* out,struct AST_If_Statement *if_statement,struct Program *program);- void to_js_print_goto_statement_tree(FILE* out,struct AST_Goto_Statement *goto_statement,struct Program *program);- void to_js_print_switch_statement_tree(FILE* out,struct AST_Switch_Statement *switch_statement,struct Program *program);- void to_js_print_return_statement_tree(FILE* out,struct AST_Return_Statement *return_statement,struct Program *program);- void to_js_print_object_declaration_tree(FILE* out,struct AST_Object_Declaration *object_declaration,struct Program *program);- void to_js_print_function_definition(FILE* out,struct AST_Function_Definition *function_definition,struct Program *program);- void to_js_print_function_declaration_tree(FILE* out,struct AST_Function_Declaration *function_declaration,struct Program *program);- void to_js_print_denoted(FILE* out,struct Denoted* denoted,struct Program *program);---- #endifF 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.cfprintf(out,"==");break;case OP_NOT_EQUAL:fprintf(out,"!=");break;- case OP_LVALUE:- fprintf(out,"LVALUE");break;case OP_CONSTANT:fprintf(out,"CONSTANT");break;case OP_STRING_LITERAL:fprintf(out,"ERROR");if(error->error!=NULL){- print_ast(out,error->error);+ print_ast(out,(struct AST*)error->error);}}void print_binary_expression_tree(FILE *out,struct AST_Binary_Expression *bin){if(bin->type==OP_ARR_SUBSCRIPT){- print_ast(out,bin->left);+ print_ast(out,(struct AST*)(struct AST*)bin->left);fprintf(out,"[");- print_ast(out,bin->right);+ print_ast(out,(struct AST*)(struct AST*)bin->right);fprintf(out,"]");}else{fprintf(out,"(");- print_ast(out,bin->left);+ print_ast(out,(struct AST*)(struct AST*)bin->left);print_ast_enum(out,bin->type);- print_ast(out,bin->right);+ print_ast(out,(struct AST*)(struct AST*)bin->right);fprintf(out,")");}}void print_conditional_expression_tree(FILE *out,struct AST_Conditional_Expression *cond){fprintf(out,"(");- print_ast(out,cond->left);+ print_ast(out,(struct AST*)(struct AST*)cond->left);fprintf(out,"?");- print_ast(out,cond->center);+ print_ast(out,(struct AST*)(struct AST*)cond->center);fprintf(out,":");- print_ast(out,cond->right);+ print_ast(out,(struct AST*)(struct AST*)cond->right);fprintf(out,")");}void print_function_expression_tree(FILE *out,struct AST_Function_Expression *function_call){struct Queue_Node *it;- print_ast(out,function_call->id);+ print_ast(out,(struct AST*)function_call->id);fprintf(out,"(");if(function_call->arguments.size>0){fprintf(out,"\n");for(it=function_call->arguments.first;it!=function_call->arguments.last;it=it->prev){- print_ast(out,(struct AST*)(it->data));+ print_ast(out,(struct AST*)(struct AST*)(it->data));fprintf(out,",\n");}if(it!=NULL){- print_ast(out,(struct AST*)(it->data));+ print_ast(out,(struct AST*)(struct AST*)(it->data));}}if(unary_expression->type==OP_CAST){fprintf(out,"(");- print_type(out,unary_expression->value_type,1);+ //print_type(out,unary_expression->value_type,1);fprintf(out,")");}- print_ast(out,unary_expression->operand);- }- void print_lvalue_expression_tree(FILE *out,struct AST_Lvalue_Expression *lval)- {- fprintf(out,"LVALUE ");- print_denoted(out,lval->lvalue);+ print_ast(out,(struct AST*)unary_expression->operand);}void print_labeled_statement_tree(FILE *out,struct AST_Labeled_Statement *lab){if(lab->label!=NULL)print_token(out,lab->label);fprintf(out,":\n");- print_ast(out,lab->statement);+ print_ast(out,(struct AST*)lab->statement);}void print_compound_statement_tree(FILE *out,struct AST_Compound_Statement *comp){fprintf(out,"{\n");for(it=comp->components.first;it!=NULL;it=it->prev){- print_ast(out,(struct AST*)(it->data));+ print_ast(out,(struct AST*)(struct AST*)(it->data));fprintf(out,";\n");}fprintf(out,"}\n");void print_if_statement_tree(FILE *out,struct AST_If_Statement *ifs){fprintf(out,"if(");- print_ast(out,ifs->condition);+ print_ast(out,(struct AST*)ifs->condition);fprintf(out,")\n");- print_ast(out,ifs->body_statement);+ print_ast(out,(struct AST*)ifs->body_statement);if(ifs->else_statement!=NULL){fprintf(out,"\nelse");- print_ast(out,ifs->else_statement);+ print_ast(out,(struct AST*)ifs->else_statement);}}void print_switch_statement_tree(FILE *out,struct AST_Switch_Statement *swi){fprintf(out,"switch(");- print_ast(out,swi->condition);+ print_ast(out,(struct AST*)swi->condition);fprintf(out,")\n");- print_ast(out,swi->body_statement);+ print_ast(out,(struct AST*)swi->body_statement);}void print_while_statement_tree(FILE *out,struct AST_While_Statement *whi){fprintf(out,"while(");- print_ast(out,whi->condition);+ print_ast(out,(struct AST*)whi->condition);fprintf(out,")\n");- print_ast(out,whi->body_statement);+ print_ast(out,(struct AST*)whi->body_statement);}void print_do_while_statement_tree(FILE *out,struct AST_Do_While_Statement *whi){fprintf(out,"do\n");- print_ast(out,whi->body_statement);+ print_ast(out,(struct AST*)whi->body_statement);fprintf(out,"while(");- print_ast(out,whi->condition);+ print_ast(out,(struct AST*)whi->condition);fprintf(out,")\n");}void print_for_statement_tree(FILE *out,struct AST_For_Statement *fo){fprintf(out,"for(\n");- print_ast(out,fo->initialisation);+ print_ast(out,(struct AST*)fo->initialisation);fprintf(out,";\n");- print_ast(out,fo->condition);+ print_ast(out,(struct AST*)fo->condition);fprintf(out,";\n");- print_ast(out,fo->update);+ print_ast(out,(struct AST*)fo->update);fprintf(out,")\n");- print_ast(out,fo->body_statement);+ print_ast(out,(struct AST*)fo->body_statement);}void print_return_statement_tree(FILE *out,struct AST_Return_Statement *return_expression){fprintf(out,"return ");- print_ast(out,return_expression->return_expression);+ print_ast(out,(struct AST*)return_expression->return_expression);}void print_goto_statement_tree(FILE *out,struct AST_Goto_Statement *got){for(it=unit->components.first;it!=NULL;it=it->prev){hold=(struct AST*)(it->data);- print_ast(out,hold);+ print_ast(out,(struct AST*)hold);if(hold->type!=ST_FUNCTION_DEFINITION){fprintf(out,";\n");case OP_CAST:print_unary_expression_tree(out,(struct AST_Unary_Expression*)tree);break;- case OP_LVALUE:- print_lvalue_expression_tree(out,(struct AST_Lvalue_Expression*)tree);- break;case OP_STRING_LITERAL:print_string_literal(out,(struct AST_String_Literal*)tree);break;case ST_OBJECT_DECLARATION:print_denoted(out,(struct Denoted*)((struct AST_Object_Declaration*)tree)->object);fprintf(out,"=");- print_ast(out,((struct AST_Object_Declaration*)tree)->object->initializer);+ print_ast(out,(struct AST*)((struct AST_Object_Declaration*)tree)->object->initializer);break;case ST_TYPE_DEFINITION:print_denoted(out,(struct Denoted*)((struct AST_Type_Definition*)tree)->definition);assert(0);}print_type(out,function->type,1);- print_ast(out,(struct AST*)function->body);+ print_ast(out,(struct AST*)(struct AST*)function->body);}void print_program_ast(FILE *out,struct Program *program){for(it=program->translation_units->first;it!=NULL;it=it->prev){fprintf(out,"TRANSLATION_UNIT {\n");- print_ast(out,(struct AST*)it->data);+ print_ast(out,(struct AST*)(struct AST*)it->data);fprintf(out,"\n} TRANSLATION_UNIT_END\n");}}void print_constant_tree(FILE *out,struct AST_Constant *constant){fprintf(out,"CONSTANT of type ");- print_type(out,constant->value_type,1);+ //print_type(out,constant->value_type,1);}void print_string_literal(FILE *out,struct AST_String_Literal *string){fprintf(out,"STRING LITERAL of type");- print_token(out,string->string);+ //print_token(out,string->string);}#undef TOKF diff --git a/src/frontend/lex/preprocessing.c b/src/frontend/lex/preprocessing.c --- a/src/frontend/lex/preprocessing.c +++ b/src/frontend/lex/preprocessing.cstruct Translation_Data hack;struct token *hold_line;struct token *hold_name;+ struct AST *line_expression;tokens=lex_line(src,translation_data,0);hack=*translation_data;if(check(&hack,KW_DECIMAL_CONSTANT,0)){hold_line=(struct token*)Queue_Pop(tokens);- src->which_row=evaluate_integer_constant(hold_line,translation_data);+ line_expression=(struct AST*)get_constant_tree(get_expression_value_constant(extract_constant(hold_line,translation_data)));++ src->which_row=evaluate_const_expression_integer(line_expression,translation_data);if(check(&hack,KW_STRING,0)){hold_name=(struct token*)Queue_Pop(tokens);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.cstruct AST* parse_initializer(struct Translation_Data *translation_data,struct Scope *scope,struct Denoted_Object *base){/*TODO add compound initialiser*/- return parse_assignment_expression(translation_data,scope);+ return (struct AST*)parse_assignment_expression(translation_data,scope);}const const const const const const const const const const const const const const const const const const const const const const const char const const const constant;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.cstruct AST* parse_expression(struct Translation_Data *translation_data,struct Scope *scope){- return parse_comma_expression(translation_data,scope);+ return (struct AST*)parse_comma_expression(translation_data,scope);}- struct AST* parse_const_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_const_expression(struct Translation_Data *translation_data,struct Scope *scope){return parse_comma_expression(translation_data,scope);}generic-selection*/- struct AST* parse_primary_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_primary_expression(struct Translation_Data *translation_data,struct Scope *scope){struct token *hold_token;- struct AST *hold;+ struct AST_Expression *hold;if(translation_data->tokens->size==0){/*TODO error*/push_translation_error("expected something here",translation_data);- return (struct AST*)get_error_tree(NULL);+ return (struct AST_Expression*)get_error_tree(NULL);}hold_token=Queue_Pop(translation_data->tokens);switch(hold_token->type){case KW_STRING:case KW_WIDE_STRING:- return (struct AST*)get_string_literal_tree(get_expression_value_constant(extract_literal_string(hold_token,translation_data)));+ return (struct AST_Expression*)get_string_literal_tree(get_expression_value_constant(extract_literal_string(hold_token,translation_data)));case KW_CHAR_CONSTANT:- return (struct AST*)get_constant_tree(get_expression_value_constant(extract_literal_char(hold_token,translation_data)));+ return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_char(hold_token,translation_data)));case KW_WIDE_CHAR_CONSTANT:- return (struct AST*)get_constant_tree(get_expression_value_constant(extract_literal_wide_char(hold_token,translation_data)));+ return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_wide_char(hold_token,translation_data)));case KW_HEXADECIMAL_CONSTANT:case KW_UNSIGNED_LONG_HEXADECIMAL_CONSTANT:case KW_UNSIGNED_LONG_LONG_HEXADECIMAL_CONSTANT:case KW_UNSIGNED_HEXADECIMAL_CONSTANT:case KW_LONG_HEXADECIMAL_CONSTANT:case KW_LONG_LONG_HEXADECIMAL_CONSTANT:- return (struct AST*)get_constant_tree(get_expression_value_constant(extract_literal_integer_hex(hold_token,translation_data)));+ return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_integer_hex(hold_token,translation_data)));case KW_DECIMAL_CONSTANT:case KW_UNSIGNED_LONG_LONG_DECIMAL_CONSTANT:case KW_UNSIGNED_DECIMAL_CONSTANT:case KW_LONG_DECIMAL_CONSTANT:case KW_LONG_LONG_DECIMAL_CONSTANT:- return (struct AST*)get_constant_tree(get_expression_value_constant(extract_literal_integer_dec(hold_token,translation_data)));+ return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_integer_dec(hold_token,translation_data)));case KW_OCTAL_CONSTANT:case KW_UNSIGNED_OCTAL_CONSTANT:case KW_DOUBLE_DECIMAL_CONSTANT:case KW_LONG_DOUBLE_DECIMAL_CONSTANT:case KW_FLOAT_DECIMAL_CONSTANT:- return (struct AST*)get_constant_tree(get_expression_value_constant(extract_literal_double_dec(hold_token,translation_data)));+ return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_double_dec(hold_token,translation_data)));case KW_DOUBLE_HEXADECIMAL_CONSTANT:case KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT:case KW_FLOAT_HEXADECIMAL_CONSTANT:- return (struct AST*)get_constant_tree(get_expression_value_constant(extract_literal_double_hex(hold_token,translation_data)));+ return (struct AST_Expression*)get_constant_tree(get_expression_value_constant(extract_literal_double_hex(hold_token,translation_data)));case KW_ID:- return (struct AST*)get_designator_tree(hold_token,scope,translation_data);+ return (struct AST_Expression*)get_designator_tree(hold_token,scope,translation_data);case KW_OPEN_NORMAL:- hold=parse_expression(translation_data,scope);+ hold=(struct AST_Expression*)parse_expression(translation_data,scope);if(get_and_check(translation_data,KW_CLOSE_NORMAL)){- return (struct AST*)hold;+ return (struct AST_Expression*)hold;}else{/*TODO error*/push_translation_error("expected ')' here",translation_data);- return (struct AST*)get_error_tree(hold);+ return (struct AST_Expression*)get_error_tree((struct AST*)hold);}default:/*TODO error*/push_translation_error("error in expression",translation_data);- return (struct AST*)get_error_tree(NULL);+ return (struct AST_Expression*)get_error_tree(NULL);}/*just in case*/assert(0);- return (struct AST*)get_error_tree(NULL);+ return (struct AST_Expression*)get_error_tree(NULL);}(e)*\)*/- struct AST_Function_Expression* parse_arglist(struct Translation_Data *translation_data,struct Scope *scope,struct AST* id)+ struct AST_Function_Expression* parse_arglist(struct Translation_Data *translation_data,struct Scope *scope,struct AST_Expression* id){struct AST_Function_Expression *ret;ret=get_function_expression_tree(id,scope);primary_expression ( ++ | -- | \[ expression \] | .id | ->id | \( arglist \) )**/- struct AST* parse_postfix_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_postfix_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;- struct AST *hold_expr;+ struct AST_Expression *hold;+ struct AST_Expression *hold_expr;hold=parse_primary_expression(translation_data,scope);{case KW_PLUSPLUS:chomp(translation_data);- hold=(struct AST*)get_unary_expression_tree(hold,OP_POSTFIX_INC);+ hold=(struct AST_Expression*)get_unary_expression_tree(hold,OP_POSTFIX_INC);break;case KW_MINUSMINUS:chomp(translation_data);- hold=(struct AST*)get_unary_expression_tree(hold,OP_POSTFIX_DEC);+ hold=(struct AST_Expression*)get_unary_expression_tree(hold,OP_POSTFIX_DEC);break;case KW_DOT:chomp(translation_data);if(check(translation_data,KW_ID,0)){- hold=(struct AST*)get_binary_expression_tree(hold,(struct AST*)get_lvalue_expression_tree(Queue_Pop(translation_data->tokens),scope),OP_MEMBER);+ hold=(struct AST_Expression*)get_struct_union_member_tree(hold,Queue_Pop(translation_data->tokens),translation_data);}break;case KW_ARROW:chomp(translation_data);if(check(translation_data,KW_ID,0)){- hold=(struct AST*)get_binary_expression_tree(hold,(struct AST*)get_lvalue_expression_tree(Queue_Pop(translation_data->tokens),scope),OP_MEMBER_TROUGH_PTR);+ hold=(struct AST_Expression*)get_struct_union_member_trough_ptr_tree(hold,Queue_Pop(translation_data->tokens),translation_data);}break;case KW_OPEN_SQUARE:chomp(translation_data);if(get_and_check(translation_data,KW_CLOSE_SQUARE)){- hold=(struct AST*)get_binary_expression_tree(hold,NULL,OP_ARR_SUBSCRIPT);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,NULL,OP_ARR_SUBSCRIPT);}else{- hold_expr=parse_expression(translation_data,scope);- hold=(struct AST*)get_binary_expression_tree(hold,hold_expr,OP_ARR_SUBSCRIPT);+ hold_expr=(struct AST_Expression*)parse_expression(translation_data,scope);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,hold_expr,OP_ARR_SUBSCRIPT);if(!get_and_check(translation_data,KW_CLOSE_SQUARE)){push_translation_error("expected ']' here",translation_data);- return (struct AST*)get_error_tree(hold);+ return (struct AST_Expression*)get_error_tree((struct AST*)hold);}}break;case KW_OPEN_NORMAL:chomp(translation_data);- return (struct AST*)parse_arglist(translation_data,scope,hold);+ return (struct AST_Expression*)parse_arglist(translation_data,scope,hold);break;default:unary-expression(type)cast-expression*/- struct AST* parse_cast_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_cast_expression(struct Translation_Data *translation_data,struct Scope *scope){struct AST_Unary_Expression *ret;if(get_and_check(translation_data,KW_OPEN_NORMAL)){if(is_type(translation_data,scope)){- ret=get_unary_expression_tree(NULL,OP_CAST);- ret->value_type=parse_type_name(translation_data,scope);+ struct Type *cast_type;+ struct AST_Expression *operand;++ cast_type=parse_type_name(translation_data,scope);if(get_and_check(translation_data,KW_CLOSE_NORMAL)){- ret->operand=parse_cast_expression(translation_data,scope);- return (struct AST*)ret;+ operand=parse_cast_expression(translation_data,scope);++ return (struct AST_Expression*)get_cast_expression_tree(operand,cast_type,translation_data);}else{push_translation_error("expected ')' here",translation_data);- return (struct AST*)get_error_tree((struct AST*)ret);+ return (struct AST_Expression*)get_error_tree((struct AST*)operand);}ret=(struct AST_Unary_Expression*)parse_expression(translation_data,scope);if(get_and_check(translation_data,KW_CLOSE_NORMAL)){- return (struct AST*)ret;+ return (struct AST_Expression*)ret;}else{push_translation_error("expected ')' here",translation_data);- return (struct AST*)get_error_tree((struct AST*)ret);+ return (struct AST_Expression*)get_error_tree((struct AST*)ret);}}*/- struct AST* parse_unary_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_unary_expression(struct Translation_Data *translation_data,struct Scope *scope){struct AST_Unary_Expression *hold;{/*TODO error*/push_translation_error("expected something here",translation_data);- return (struct AST*)get_error_tree(NULL);+ return (struct AST_Expression*)get_error_tree(NULL);}/*TODO make it iterative*/{case KW_PLUSPLUS:chomp(translation_data);- return (struct AST*)get_unary_expression_tree(parse_unary_expression(translation_data,scope),OP_PREFIX_INC);+ return (struct AST_Expression*)get_unary_expression_tree(parse_unary_expression(translation_data,scope),OP_PREFIX_INC);case KW_MINUSMINUS:chomp(translation_data);- return (struct AST*)get_unary_expression_tree(parse_unary_expression(translation_data,scope),OP_PREFIX_DEC);+ return (struct AST_Expression*)get_unary_expression_tree(parse_unary_expression(translation_data,scope),OP_PREFIX_DEC);case KW_PLUS:chomp(translation_data);- return (struct AST*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_UNARY_PLUS);+ return (struct AST_Expression*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_UNARY_PLUS);case KW_MINUS:chomp(translation_data);- return (struct AST*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_UNARY_MINUS);+ return (struct AST_Expression*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_UNARY_MINUS);case KW_EXCLAMATION:chomp(translation_data);- return (struct AST*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_LOGICAL_NOT);+ return (struct AST_Expression*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_LOGICAL_NOT);case KW_TILDE:chomp(translation_data);- return (struct AST*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_BITWISE_NOT);+ return (struct AST_Expression*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_BITWISE_NOT);case KW_STAR:chomp(translation_data);- return (struct AST*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_DEREFERENCE);+ return (struct AST_Expression*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_DEREFERENCE);case KW_AND:chomp(translation_data);- return (struct AST*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_ADDR_OF);+ return (struct AST_Expression*)get_unary_expression_tree(parse_cast_expression(translation_data,scope),OP_ADDR_OF);case KW_SIZEOF:chomp(translation_data);if(get_and_check(translation_data,KW_OPEN_NORMAL)){- hold=get_unary_expression_tree(NULL,OP_CAST);- hold->value_type=parse_type_name(translation_data,scope);- hold->operand=parse_unary_expression(translation_data,scope);- return (struct AST*)hold;+ return (struct AST_Expression*)get_sizeof_by_type_tree(parse_type_name(translation_data,scope));}else{- return (struct AST*)get_unary_expression_tree(parse_unary_expression(translation_data,scope),OP_SIZEOF);+ return (struct AST_Expression*)get_unary_expression_tree(parse_unary_expression(translation_data,scope),OP_SIZEOF);}default:return parse_postfix_expression(translation_data,scope);multiplicative-expression:cast-expression ( ( * | / | % ) cast-expression )**/- struct AST* parse_multiplicative_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_multiplicative_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_cast_expression(translation_data,scope);while(translation_data->tokens->size!=0){{case KW_STAR:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_cast_expression(translation_data,scope),OP_MUL);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_cast_expression(translation_data,scope),OP_MUL);break;case KW_FORWARD_SLASH:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_cast_expression(translation_data,scope),OP_DIV);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_cast_expression(translation_data,scope),OP_DIV);break;case KW_PERCENT:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_cast_expression(translation_data,scope),OP_REMAINDER);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_cast_expression(translation_data,scope),OP_REMAINDER);break;default:return hold;additive-expression:multiplicative-expression ( ( + | - ) multiplicative )**/- struct AST* parse_additive_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_additive_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_multiplicative_expression(translation_data,scope);while(translation_data->tokens->size!=0){case KW_PLUS:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_multiplicative_expression(translation_data,scope),OP_ADDITION);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_multiplicative_expression(translation_data,scope),OP_ADDITION);break;case KW_MINUS:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_multiplicative_expression(translation_data,scope),OP_SUBTRACTION);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_multiplicative_expression(translation_data,scope),OP_SUBTRACTION);break;default:return hold;bitwise-shift:additive-expression ( ( << | >> ) additive-expression)**/- struct AST* parse_shift_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_shift_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_additive_expression(translation_data,scope);while(translation_data->tokens->size!=0){case KW_SHIFT_LEFT:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_additive_expression(translation_data,scope),OP_SHIFT_LEFT);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_additive_expression(translation_data,scope),OP_SHIFT_LEFT);break;case KW_SHIFT_RIGHT:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_additive_expression(translation_data,scope),OP_SHIFT_RIGHT);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_additive_expression(translation_data,scope),OP_SHIFT_RIGHT);break;default:return hold;shift-expression ( ( < | > | <= | >= ) shift-expression )**/- struct AST* parse_relational_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_relational_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_shift_expression(translation_data,scope);while(translation_data->tokens->size!=0){case KW_LESS:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_shift_expression(translation_data,scope),OP_LESS);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_shift_expression(translation_data,scope),OP_LESS);break;case KW_LESS_EQ:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_shift_expression(translation_data,scope),OP_LESS_EQ);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_shift_expression(translation_data,scope),OP_LESS_EQ);break;case KW_MORE:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_shift_expression(translation_data,scope),OP_GREATER);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_shift_expression(translation_data,scope),OP_GREATER);break;case KW_MORE_EQ:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_shift_expression(translation_data,scope),OP_GREATER_EQ);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_shift_expression(translation_data,scope),OP_GREATER_EQ);break;default:return hold;equality-expression:realtional-expression ( ( == | != ) relational-expression )**/- struct AST* parse_equality_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_equality_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_relational_expression(translation_data,scope);while(translation_data->tokens->size!=0){case KW_EQEQ:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_relational_expression(translation_data,scope),OP_EQUAL);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_relational_expression(translation_data,scope),OP_EQUAL);break;case KW_NOT_EQ:chomp(translation_data);- hold=(struct AST*)get_binary_expression_tree(hold,parse_relational_expression(translation_data,scope),OP_NOT_EQUAL);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_relational_expression(translation_data,scope),OP_NOT_EQUAL);break;default:return hold;and-expression:equality-expression ( & equality-expression ) **/- struct AST* parse_and_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_and_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_equality_expression(translation_data,scope);while(get_and_check(translation_data,KW_AND)){- hold=(struct AST*)get_binary_expression_tree(hold,parse_equality_expression(translation_data,scope),OP_BITWISE_AND);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_equality_expression(translation_data,scope),OP_BITWISE_AND);}return hold;}and-expression (^ and-expression)**/- struct AST* parse_exclusive_or_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_exclusive_or_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_and_expression(translation_data,scope);while(get_and_check(translation_data,KW_HAT)){- hold=(struct AST*)get_binary_expression_tree(hold,parse_and_expression(translation_data,scope),OP_BITWISE_XOR);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_and_expression(translation_data,scope),OP_BITWISE_XOR);}return hold;inclusive-or-expression:exclusive-or-expression (|exclusive-or-expression)**/- struct AST* parse_inclusive_or_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_inclusive_or_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_exclusive_or_expression(translation_data,scope);while(get_and_check(translation_data,KW_PIPE)){- hold=(struct AST*)get_binary_expression_tree(hold,parse_exclusive_or_expression(translation_data,scope),OP_BITWISE_OR);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_exclusive_or_expression(translation_data,scope),OP_BITWISE_OR);}return hold;}logical-and-expression:inclusive-or-expression(&&inclusive-or-expression)**/- struct AST* parse_logical_and_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_logical_and_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_inclusive_or_expression(translation_data,scope);while(get_and_check(translation_data,KW_AND_AND)){- hold=(struct AST*)get_binary_expression_tree(hold,parse_inclusive_or_expression(translation_data,scope),OP_LOGICAL_AND);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_inclusive_or_expression(translation_data,scope),OP_LOGICAL_AND);}return hold;}logical-or-expression:logical-and-expression ( || logical-and-expression )**/- struct AST* parse_logical_or_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_logical_or_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_logical_and_expression(translation_data,scope);while(get_and_check(translation_data,KW_PIPE_PIPE)){- hold=(struct AST*)get_binary_expression_tree(hold,parse_logical_and_expression(translation_data,scope),OP_LOGICAL_OR);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_logical_and_expression(translation_data,scope),OP_LOGICAL_OR);}return hold;}logical-or-expressionlogical-or-expression?expression:conditional-expression*/- struct AST* parse_conditional_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_conditional_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_logical_or_expression(translation_data,scope);if(get_and_check(translation_data,KW_QUESTION)){- hold=(struct AST*)get_conditional_expression_tree(hold,parse_expression(translation_data,scope),NULL);+ hold=(struct AST_Expression*)get_conditional_expression_tree(hold,(struct AST_Expression*)parse_expression(translation_data,scope),NULL);if(get_and_check(translation_data,KW_COLUMN)){((struct AST_Conditional_Expression*)hold)->right=parse_conditional_expression(translation_data,scope);}else{push_translation_error("expected ':' here",translation_data);- return (struct AST*)get_error_tree(hold);+ return (struct AST_Expression*)get_error_tree((struct AST*)hold);}}else{conditional-expressionunary-expression ( ( = | += | -= | %= | /= | *= | >>= | <<= | &= | |= | ^= ) assignment-expression*/- struct AST* parse_assignment_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_assignment_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;if(translation_data->tokens->size==0){/*TODO error*/push_translation_error("expected something here",translation_data);- return (struct AST*)get_error_tree(NULL);+ return (struct AST_Expression*)get_error_tree(NULL);}hold=parse_conditional_expression(translation_data,scope);{case KW_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_ASSIGN);case KW_PLUS_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_ADD_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_ADD_ASSIGN);case KW_MINUS_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_SUBTRACT_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_SUBTRACT_ASSIGN);case KW_PERCENT_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_REMAINDER_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_REMAINDER_ASSIGN);case KW_DIV_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_DIV_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_DIV_ASSIGN);case KW_STAR_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_MULTIPLY_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_MULTIPLY_ASSIGN);case KW_SHIFT_RIGHT_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_SHIFT_RIGHT_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_SHIFT_RIGHT_ASSIGN);case KW_SHIFT_LEFT_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_SHIFT_LEFT_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_SHIFT_LEFT_ASSIGN);case KW_AND_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_AND_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_AND_ASSIGN);case KW_PIPE_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_PIPE_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_PIPE_ASSIGN);case KW_HAT_EQ:chomp(translation_data);- return (struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_XOR_ASSIGN);+ return (struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_XOR_ASSIGN);default:return hold;}comma-expression:assignment-expression(,assignment-expression)**/- struct AST* parse_comma_expression(struct Translation_Data *translation_data,struct Scope *scope)+ struct AST_Expression* parse_comma_expression(struct Translation_Data *translation_data,struct Scope *scope){- struct AST *hold;+ struct AST_Expression *hold;hold=parse_assignment_expression(translation_data,scope);while(get_and_check(translation_data,KW_COMMA)){- hold=(struct AST*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_COMMA);+ hold=(struct AST_Expression*)get_binary_expression_tree(hold,parse_assignment_expression(translation_data,scope),OP_COMMA);}return hold;}F diff --git a/src/frontend/parse/parse_expression.h b/src/frontend/parse/parse_expression.h --- a/src/frontend/parse/parse_expression.h +++ b/src/frontend/parse/parse_expression.h#include <parse_declaration.h>#include <ast.h>#include <limits.h>+ #include <value.h>struct AST* parse_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_const_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_primary_expression(struct Translation_Data *translation_data,struct Scope *scope);--- struct AST_Function_Expression* parse_arglist(struct Translation_Data *translation_data,struct Scope *scope,struct AST* id);- struct AST* parse_postfix_expression(struct Translation_Data *translation_data,struct Scope *scope);-- struct AST* parse_cast_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_unary_expression(struct Translation_Data *translation_data,struct Scope *scope);-- struct AST* parse_multiplicative_expression(struct Translation_Data *translation_data,struct Scope *scope);-- struct AST* parse_additive_expression(struct Translation_Data *translation_data,struct Scope *scope);-- struct AST* parse_shift_expression(struct Translation_Data *translation_data,struct Scope *scope);--- struct AST* parse_relational_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_equality_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_and_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_exclusive_or_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_inclusive_or_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_logical_and_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_logical_or_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_conditional_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_assignment_expression(struct Translation_Data *translation_data,struct Scope *scope);- struct AST* parse_comma_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_const_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_primary_expression(struct Translation_Data *translation_data,struct Scope *scope);++ struct AST_Function_Expression* parse_arglist(struct Translation_Data *translation_data,struct Scope *scope,struct AST_Expression* id);++ struct AST_Expression* parse_postfix_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_cast_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_unary_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_multiplicative_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_additive_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_shift_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_relational_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_equality_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_and_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_exclusive_or_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_inclusive_or_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_logical_and_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_logical_or_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_conditional_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_assignment_expression(struct Translation_Data *translation_data,struct Scope *scope);+ struct AST_Expression* parse_comma_expression(struct Translation_Data *translation_data,struct Scope *scope);F diff --git a/src/semantics/ast.c b/src/semantics/ast.c --- a/src/semantics/ast.c +++ b/src/semantics/ast.creturn ret;}- struct AST_Binary_Expression* get_binary_expression_tree(struct AST *left,struct AST *right,enum AST_Type type)+ /*TODO remove this*/+ struct AST_Binary_Expression* get_binary_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type type){struct AST_Binary_Expression *ret;ret=malloc(sizeof(struct AST_Binary_Expression));return ret;}- struct AST_Binary_Expression* get_struct_union_member_tree(struct AST *left,struct token *id,enum AST_Type struct_or_union)+ struct AST_Unary_Expression* get_cast_expression_tree(struct AST_Expression *operand,struct Type *type,struct Translation_Data *translation_data){+ struct AST_Unary_Expression *ret;+ if(!type_is_scalar(type))+ { push_translation_error("cast type needs to be of scalar type",translation_data);return NULL; }+++ ret=malloc(sizeof(struct AST_Unary_Expression));+ ret->type=OP_CAST;+ ret->value=get_expression_value_temp_value(get_temp_object(extract_expresion_value_type(operand->value,translation_data)));+ ret->operand=operand;++ return ret;+ }+ struct AST_Unary_Expression* get_sizeof_by_type_tree(struct Type *type)+ {+ struct AST_Unary_Expression *ret;++ ret=malloc(sizeof(struct AST_Unary_Expression));+ ret->type=OP_SIZEOF;+ ret->value=get_expression_value_temp_value(get_temp_object(type));+ ret->operand=NULL;+ return ret;}- struct AST_Conditional_Expression* get_conditional_expression_tree(struct AST *left,struct AST *center,struct AST *right)+++ /*TODO do this*/+ struct AST_Binary_Expression* get_array_subscript_tree(struct AST_Expression *left,struct AST_Expression *right)+ {++ }+ struct AST_Binary_Expression* get_struct_union_member_tree(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data)+ {++ /*TODO make the macros*/+ struct Denoted_Object *hold_denoted_object;+ struct Expression_Value_LValue *left_lvalue;+ struct Struct_Union *struct_union;+ struct Type_Struct_Union *left_type;++ struct AST_Binary_Expression *ret;+++ assert(left->type!=OP_MEMBER);++ 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; }++ left_type=(struct Type_Struct_Union*)left_lvalue->object->type;+ struct_union=left_type->struct_union;+++ ret=malloc(sizeof(struct AST_Binary_Expression));+ ret->type=OP_MEMBER;+ ret->left=left;++ /*TODO could optimise this*/+ ret->right=(struct AST_Expression*)get_designator_tree(id,(struct Scope*)struct_union->inner_namespace,translation_data);++ return ret;+ }+ 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 AST_Conditional_Expression *ret;ret=malloc(sizeof(struct AST_Conditional_Expression));return ret;}- struct AST_Function_Expression* get_function_expression_tree(struct AST* id,struct Scope *scope)+ struct AST_Function_Expression* get_function_expression_tree(struct AST_Expression *id,struct Scope *scope){struct AST_Function_Expression *ret;ret=malloc(sizeof(struct AST_Function_Expression));Queue_Init(&ret->arguments);return ret;}- struct AST_Unary_Expression* get_unary_expression_tree(struct AST *operand,enum AST_Type type)+ struct AST_Unary_Expression* get_unary_expression_tree(struct AST_Expression *operand,enum AST_Type type){struct AST_Unary_Expression *ret;struct AST_Designator* get_designator_tree(struct token *id,struct Scope* scope,struct Translation_Data *translation_data){struct AST_Designator *ret;- struct Denote *hold_denoted;+ struct Denoted *hold_denoted;- ret=malloc(sizeof(struct AST_Lvalue_Expression));+ ret=malloc(sizeof(struct AST_Designator));ret->type=OP_DESIGNATOR;switch(hold_denoted->denotation){case DT_Enum_Constant:- ret->value=get_expression_value_constant(extract_enum_constant((struct Denoted_Enum_Const*)denoted));+ ret->value=get_expression_value_constant(extract_enum_constant((struct Denoted_Enum_Const*)hold_denoted,translation_data));break;case DT_Object:ret->value=get_expression_value_lvalue( ((struct Denoted_Object*)hold_denoted)->object );case OP_SIZEOF:delete_ast_unary_expression((struct AST_Unary_Expression*)ast);break;- case OP_LVALUE:- delete_ast_lvalue_expression((struct AST_Lvalue_Expression*)ast);- break;case OP_CONSTANT:delete_ast_constant((struct AST_Constant*)ast);break;void delete_ast_binary_expression(struct AST_Binary_Expression *binary_expression){if(binary_expression->left!=NULL)- delete_ast(binary_expression->left);+ delete_ast((struct AST*)binary_expression->left);if(binary_expression->right!=NULL)- delete_ast(binary_expression->right);+ delete_ast((struct AST*)binary_expression->right);free(binary_expression);}{if(cond_expression->left!=NULL)- delete_ast(cond_expression->left);+ delete_ast((struct AST*)cond_expression->left);if(cond_expression->center!=NULL)- delete_ast(cond_expression->center);+ delete_ast((struct AST*)cond_expression->center);if(cond_expression->right!=NULL)- delete_ast(cond_expression->right);+ delete_ast((struct AST*)cond_expression->right);free(cond_expression);}{struct Queue_Node *it;if(function_expression->id!=NULL)- delete_ast(function_expression->id);+ delete_ast((struct AST*)function_expression->id);while(function_expression->arguments.size>0)delete_ast(Queue_Pop(&function_expression->arguments));void delete_ast_unary_expression(struct AST_Unary_Expression *unary_expression){if(unary_expression->operand!=NULL)- delete_ast(unary_expression->operand);+ delete_ast((struct AST*)unary_expression->operand);free(unary_expression);}void delete_ast_labeled_statement(struct AST_Labeled_Statement *labeled_statement)free(constant->value);free(constant);}++void delete_ast_string_literal(struct AST_String_Literal *string){- free(string->string);free(string);}--#endifF diff --git a/src/semantics/ast.h b/src/semantics/ast.h --- a/src/semantics/ast.h +++ b/src/semantics/ast.henum AST_Type type;struct Expression_Value *value;- struct AST *left;- struct AST *right;+ struct AST_Expression *left;+ struct AST_Expression *right;};struct AST_Conditional_Expressionenum AST_Type type;struct Expression_Value *value;- struct AST *left;- struct AST *center;- struct AST *right;+ struct AST_Expression *left;+ struct AST_Expression *center;+ struct AST_Expression *right;};struct AST_Function_Expression{enum AST_Type type;struct Expression_Value *value;- struct AST *id;+ struct AST_Expression *id;/*queue of astrees*/struct Queue arguments;};enum AST_Type type;struct Expression_Value *value;- struct AST *operand;+ struct AST_Expression *operand;};struct AST_Labeled_Statementstruct AST_Error* get_error_tree(struct AST *error);struct AST_Declaration_Error* get_declaration_error_tree(struct Denoted *error);- struct AST_Binary_Expression* get_binary_expression_tree(struct AST *left,struct AST *right,enum AST_Type type);- struct AST_Binary_Expression* get_struct_union_member_tree(struct AST *left,struct token *id,enum AST_Type struct_or_union);- struct AST_Conditional_Expression* get_conditional_expression_tree(struct AST *left,struct AST *center,struct AST *right);- struct AST_Function_Expression* get_function_expression_tree(struct AST* id,struct Scope *scope);- struct AST_Unary_Expression* get_unary_expression_tree(struct AST *operand,enum AST_Type type);+ struct AST_Binary_Expression* get_binary_expression_tree(struct AST_Expression *left,struct AST_Expression *right,enum AST_Type type);++ struct AST_Binary_Expression* get_array_subscript_tree(struct AST_Expression *left,struct AST_Expression *right);+ struct AST_Binary_Expression* get_struct_union_member_tree(struct AST_Expression *left,struct token *id,struct Translation_Data *translation_data);+ 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 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,enum AST_Type type);+ struct AST_Unary_Expression* get_sizeof_by_type_tree(struct Type *type);+ struct AST_Unary_Expression* get_cast_expression_tree(struct AST_Expression *operand,struct Type *type,struct Translation_Data *translation_data);++struct AST_Constant* get_constant_tree(struct Expression_Value *value);struct AST_String_Literal* get_string_literal_tree(struct Expression_Value *value);struct AST_Designator* get_designator_tree(struct token *id,struct Scope* scope,struct Translation_Data *translation_data);+++struct AST_Labeled_Statement* get_labeled_statement_tree(struct token *label,struct AST* statement,enum AST_Type type);struct AST_Compound_Statement* get_compound_statement_tree(struct Scope *parent_scope);struct AST_If_Statement* get_if_statement_tree();F diff --git a/src/semantics/memory/location.c b/src/semantics/memory/location.c --- a/src/semantics/memory/location.c +++ b/src/semantics/memory/location.c}+ struct Location* get_temp_location()+ {+ struct Location *ret;+ ret=malloc(sizeof(struct Location));+ ret->type=LT_TEMP;++ return ret;+ }++void delete_location(struct Location *location){F diff --git a/src/semantics/memory/location.h b/src/semantics/memory/location.h --- a/src/semantics/memory/location.h +++ b/src/semantics/memory/location.hstruct Location_Raw* get_location_raw(size_t address);struct Location_Relative* get_relative_location(struct Location *base,size_t offset);struct Location* get_location_for_denoted_object(struct Location *base,struct Type *type,struct token *id);+ struct Location* get_temp_location();void delete_location(struct Location *location);F diff --git a/src/semantics/memory/location.hh b/src/semantics/memory/location.hh --- a/src/semantics/memory/location.hh +++ b/src/semantics/memory/location.hhLT_RAW,LT_RELATIVE,LT_LABELED,- LT_GLOBAL+ LT_GLOBAL,+ LT_TEMP};struct Location;struct Location_Stack;F diff --git a/src/semantics/memory/object.c b/src/semantics/memory/object.c --- a/src/semantics/memory/object.c +++ b/src/semantics/memory/object.cfree(object);}+ struct Object* retype_object(struct Object *object,struct Type *new_type)+ {+ struct Object *ret;+ ret=malloc(sizeof(struct Object));+ ret->location=object->location;+ ret->storage_class=object->storage_class;+ ret->type=new_type;++ return ret;+ }+++ struct Object* get_temp_object(struct Type *type)+ {+ struct Object *ret;+ ret=malloc(sizeof(struct Object));+ ret->location=get_temp_location();+ ret->storage_class=SCS_NONE;+ ret->type=type;++ return ret;+ }++#endifF diff --git a/src/semantics/memory/object.h b/src/semantics/memory/object.h --- a/src/semantics/memory/object.h +++ b/src/semantics/memory/object.h};void delete_object(struct Object *object);+ struct Object* retype_object(struct Object *object,struct Type *new_type);+ struct Object* get_temp_object(struct Type *type);#endifF diff --git a/src/semantics/value/constant.c b/src/semantics/value/constant.c --- a/src/semantics/value/constant.c +++ b/src/semantics/value/constant.cfree(constant);}+ /*TODO*/+ struct Constant* extract_constant(struct token *token,struct Translation_Data *translation_data)+ {+ return extract_literal_integer_dec(token,translation_data);+ }struct Constant* extract_literal_integer_dec(struct token *token,struct Translation_Data *translation_data){/*the sign is acounted for during parsing*/ret->type=get_type_insecure(TS_CHAR,TSIGN_NONE,TC_NONE,CHAR_SIZE,translation_data);return ret;}- struct Constant* extract_enum_constant(struct Denoted_Enum_Const *const)+ struct Constant* extract_enum_constant(struct Denoted_Enum_Const *constant,struct Translation_Data *translation_data){struct Constant *ret;ret=malloc(sizeof(struct Constant));ret->value=malloc(sizeof(int));- *(ret->value)=const->value;+ *((int*)ret->value)=constant->value;ret->type=get_type_insecure(INT_SIZE,TSIGN_NONE,TC_NONE,INT_SIZE,translation_data);return ret;}- struct Constant* resolve_char_escape_sequence(struct token *token,struct Translation_Data *translation_data)+ void resolve_char_escape_sequence(struct token *token,struct Translation_Data *translation_data){- return L'a';}#endifF diff --git a/src/semantics/value/constant.h b/src/semantics/value/constant.h --- a/src/semantics/value/constant.h +++ b/src/semantics/value/constant.hvoid *value;};+ struct Constant* extract_constant(struct token *token,struct Translation_Data *translation_data);struct Constant* extract_literal_integer_dec(struct token *token,struct Translation_Data *translation_data);struct Constant* extract_literal_integer_hex(struct token *token,struct Translation_Data *translation_data);struct Constant* extract_literal_double_dec(struct token *token,struct Translation_Data *translation_data);struct Constant* extract_literal_wide_string(struct token *token,struct Translation_Data *translation_data);struct Constant* extract_literal_char(struct token *token,struct Translation_Data *translation_data);struct Constant* extract_literal_wide_char(struct token *token,struct Translation_Data *translation_data);- struct Constant* resolve_char_escape_sequence(struct token *token,struct Translation_Data *translation_data);- struct Constant* extract_enum_constant(struct Denoted_Enum_Const *const);+ struct Constant* extract_enum_constant(struct Denoted_Enum_Const *constant,struct Translation_Data *translation_data);+ void resolve_char_escape_sequence(struct token *token,struct Translation_Data *translation_data);void delete_constant(struct Constant *constant);#endifF diff --git a/src/semantics/value/evaluation.c b/src/semantics/value/evaluation.c --- a/src/semantics/value/evaluation.c +++ b/src/semantics/value/evaluation.clong long int evaluate_const_expression_integer(struct AST *expression,struct Translation_Data *translation_data){#define RET_BIN_EXPR(x,operator) return \- evaluate_const_expression_integer(BIN_EXPR_PTR(x)->left,translation_data)\+ evaluate_const_expression_integer((struct AST*)BIN_EXPR_PTR(x)->left,translation_data)\operator\- evaluate_const_expression_integer(BIN_EXPR_PTR(x)->right,translation_data);+ evaluate_const_expression_integer((struct AST*)BIN_EXPR_PTR(x)->right,translation_data);#define RET_UNARY_EXPR(x,operator) return \- operator evaluate_const_expression_integer(UN_EXPR_PTR(x)->operand,translation_data);+ operator evaluate_const_expression_integer((struct AST*)UN_EXPR_PTR(x)->operand,translation_data);switch(expression->type){RET_BIN_EXPR(expression,%);case OP_COND:return (- evaluate_const_expression_integer(((struct AST_Conditional_Expression*)expression)->left,translation_data)?- evaluate_const_expression_integer(((struct AST_Conditional_Expression*)expression)->center,translation_data):- evaluate_const_expression_integer(((struct AST_Conditional_Expression*)expression)->right,translation_data)+ evaluate_const_expression_integer((struct AST*)((struct AST_Conditional_Expression*)expression)->left,translation_data)?+ evaluate_const_expression_integer((struct AST*)((struct AST_Conditional_Expression*)expression)->center,translation_data):+ evaluate_const_expression_integer((struct AST*)((struct AST_Conditional_Expression*)expression)->right,translation_data));case OP_LOGICAL_OR: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{return 1;}++++ char type_is_scalar(struct Type *type)+ {+ return (type->specifier==TS_CHAR || type->specifier==TS_INT || type->specifier==TS_FLOAT || type->specifier==TS_DOUBLE || type->specifier==TS_POINTER);+ }++ char type_is_of_object(struct Type *type)+ {+ return !(type->specifier==TS_VOID || type->specifier==TS_FUNC || type->specifier==TS_NONE || type->specifier==TS_ERROR);+ }+ char type_is_complete(struct Type *type)+ {+ if(type->specifier==TS_ENUM)+ {+ return ((struct Type_Enum*)type)->enumeration->is_finished;+ }else if(type->specifier==TS_UNION || type->specifier==TS_STRUCT)+ {+ return ((struct Type_Struct_Union*)type)->struct_union->is_finished;+ }else+ {+ return 1;+ }+ }+ char type_is_integer_type(struct Type *type)+ {+ return type->specifier==TS_INT || type->specifier==TS_CHAR;+ }+ char type_is_basic(struct Type *type)+ {+ return (type->specifier==TS_INT || type->specifier==TS_CHAR || type->specifier==TS_DOUBLE || type->specifier==TS_FLOAT );+ }+ char type_is_arithmetic(struct Type *type)+ {+ return (type->specifier==TS_CHAR || type->specifier==TS_INT || type->specifier==TS_FLOAT || type->specifier==TS_DOUBLE );+ }+ char type_is_aggregate(struct Type *type)+ {+ return (type->specifier==TS_ARRAY || type->specifier==TS_UNION || type->specifier==TS_STRUCT);+ }#endifF 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.hstruct Type* get_function_type(struct Type *return_type,struct Queue *parameters,struct Normal_Scope* function_prototype_scope);- struct Type* get_type_insecure(enum Type_Specifier type_specifier,enum Type_Signedness sign,enum Type_Constraint length,struct Translation_Data *translation_data);+ struct Type* 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);char is_type(struct Translation_Data *translation_data,struct Scope *scope);size_t get_type_size(struct Type *type);- char types_are_identical(struct Type *a,struct Type *b);+ char types_are_identical(struct Type *a,struct Type *b);++ char type_is_of_object(struct Type *type);+ char type_is_complete(struct Type *type);+ char type_is_integer_type(struct Type *type);+ char type_is_basic(struct Type *type);+ char type_is_character(struct Type *type);+ char type_is_arithmetic(struct Type *type);+ char type_is_scalar(struct Type *type);+ char type_is_aggregate(struct Type *type);F diff --git a/src/semantics/value/type.hh b/src/semantics/value/type.hh --- a/src/semantics/value/type.hh +++ b/src/semantics/value/type.hh#define AS_TYPE_ARR_PTR(x) ((struct Type_Array*)x)#define AS_TYPE_ENUM_PTR(x) ((struct Type_Enum*)x)#define AS_TYPE_FUNC_PTR(x) ((struct Type_Function*)x)+ #define AS_TYPE_BITFIELD_PTR(x) ((struct Type_Bit_Field*)x)- /*this isn't just type-specifier :DD*/++ /*this isn't just type-specifier*/enum Type_Specifier{TS_VOID,F diff --git a/src/semantics/value/value.c b/src/semantics/value/value.c --- a/src/semantics/value/value.c +++ b/src/semantics/value/value.c+ struct Type* extract_expresion_value_type(struct Expression_Value *expression_value,struct Translation_Data *translation_data)+ {+ switch(expression_value->type)+ {+ case VALUE_LVALUE:+ return ((struct Expression_Value_LValue*)expression_value)->object->type;+ case VALUE_TEMP:+ return ((struct Expression_Value_Temp_Value*)expression_value)->temp_object->type;+ case VALUE_FUNCTION_DESIGNATOR:+ return ((struct Expression_Value_Function_Designator*)expression_value)->function->type;+ case VALUE_CONSTANT:+ return ((struct Expression_Value_Constant*)expression_value)->constant->type;+ case VALUE_VOID:+ return get_type_insecure(TS_VOID,TSIGN_NONE,TC_NONE,0,translation_data);+ }+ assert(0);+ }void delete_expression_value(struct Expression_Value *expression_value)F diff --git a/src/semantics/value/value.h b/src/semantics/value/value.h --- a/src/semantics/value/value.h +++ b/src/semantics/value/value.hstruct Expression_Value* get_expression_value_temp_value(struct Object *temp_object);struct Expression_Value* get_expression_value_function_designator(struct Denoted_Function *function);+ struct Type* extract_expresion_value_type(struct Expression_Value *expression_value,struct Translation_Data *translation_data);+void delete_expression_value(struct Expression_Value *expression_value);void delete_expression_value_void(struct Expression_Value *void_expression_value);F diff --git a/src/semantics/value/value.hh b/src/semantics/value/value.hh --- a/src/semantics/value/value.hh +++ b/src/semantics/value/value.hh#ifndef WONKY_VALUE_HH#define WONKY_VALUE_HH WONKY_VALUE_HH+enum Expression_Value_Type{VALUE_LVALUE,F diff --git a/src/wonky.c b/src/wonky.c --- a/src/wonky.c +++ b/src/wonky.cprint_program_ast(stdout,program);}else if(command_arguments->transpile_to_js){- transpile_to_javascript(command_arguments->output_file,program,command_arguments);+ //transpile_to_javascript(command_arguments->output_file,program,command_arguments);}}F diff --git a/src/wonky.h b/src/wonky.h --- a/src/wonky.h +++ b/src/wonky.h#include <scope.h>#include <evaluation.h>#include <type.h>- #include <transpile_to_js.h>#include <queue.h>#include <map.h>