F diff --git a/src/backend/compile.h b/src/backend/compile.h --- a/src/backend/compile.h +++ b/src/backend/compile.h{enum Compilation_Type type;};- struct Compile_Data_Print- {- enum Compilation_Type type;- };struct Compiled_Object{enum Compilation_Type type;};- struct Compiled_Object_Print- {- enum Compilation_Type type;- };struct Compiled_Object* compile_program(struct Program *program,enum Compilation_Type compile_to_what);void save_compiled_object(struct Compiled_Object *object,FILE *out);- struct Compiled_Object_Print* compile_program_for_print(struct Program *program);- void save_compiled_object_for_print(struct Compiled_Object_Print *object,FILE *out);#endifF diff --git a/src/backend/text/print/print.c b/src/backend/text/print/print.c --- a/src/backend/text/print/print.c +++ b/src/backend/text/print/print.c#ifndef WONKY_PRINT#define WONKY_PRINT WONKY_PRINT- #include "print.h"+ #include <print.h>+ struct Compiled_Object_Print* get_print_compile_object(struct Queue *lines)+ {+ struct Compiled_Object_Print *ret;++ ret=malloc(sizeof(struct Compiled_Object_Print));+ ret->type=COMPILE_TO_PRINT;+ ret->lines=lines;+ return ret;+ }+ struct Compile_Data_Print* get_print_compile_data()+ {+ struct Compile_Data_Print *ret;+ ret=malloc(sizeof(struct Compile_Data_Print));+ ret->type=COMPILE_TO_PRINT;+ ret->indent=0;- int indent=0;+ ret->lines=malloc(sizeof(struct Queue*));+ Queue_Init(ret->lines);- void print_token(FILE *out,struct token *token)+ return ret;++ }+ struct Compiled_Object_Print* compile_program_for_print(struct Program *program){- size_t i;- if(token==NULL)return;- for(i=0;i<token->data_size;++i)+ struct Compile_Data_Print *compile_data;+ struct Compiled_Object_Print *ret;++ compile_data=get_print_compile_data();+ print_program_ast(compile_data,program);++ ret=get_print_compile_object(compile_data->lines);++ free(compile_data);++ return ret;+ }+ void save_compiled_object_for_print(struct Compiled_Object_Print *object,FILE *out)+ {+ struct Queue_Node *it;+ struct Line *current_line;+ int i;+ for(it=object->lines->first;it!=NULL;it=it->prev){- fprintf(out,"%c",token->data[i]);+ current_line=it->data; /*TODO add assert is valid line*/++ for(i=0;i<current_line->indent;++i)+ fprintf(out,"\t");+ fputs(current_line->data,out);+ fputs("\n",out);}}+ void print_token(struct Compile_Data_Print *compile_data,struct token *token)+ {+ char *token_string;+ token_string=gstr_dup(token->data,token->data+token->data_size,1024);+ append_to_last_line(token_string,compile_data->lines);+ }+char print_tokens_of_program(FILE *out,char **base_source_names){void print_tokens(FILE *out,struct Queue *tokens){struct Queue_Node *it;+ size_t i;+ struct token *token;for( it=tokens->first; it!=NULL; it=it->prev){- fprintf(out,"[");- print_keyword_enum(out,((struct token*)(it->data))->type);- print_token(out,(struct token*)(it->data));- fprintf(out,"] ");+ token=it->data;+ fprintf(out,"[");+ print_keyword_enum(out,token->type);++ if(token->data==NULL)continue;+ for(i=0;i<token->data_size;++i)+ {+ fprintf(out,"%c",token->data[i]);+ }++ fprintf(out,"] ");}}- void print_ast_enum(FILE *out,enum AST_Type op)+ void print_ast_enum(struct Compile_Data_Print *compile_data,enum AST_Type op){- switch(op)+ static const char *map[AST_TYPE_END]+ =+ {+ [OP_COMMA]=",",+ [OP_ADDITION]="+",+ [OP_SUBTRACTION]="-",+ [OP_MUL]="*",+ [OP_DIV]="/",+ [OP_REMAINDER]="%",+ [OP_COND]="CONDITIONAL",+ [OP_FUNCTION]="FUNCTION_CALL",+ [OP_ASSIGN]="=",+ [OP_ADD_ASSIGN]="+=",+ [OP_SUBTRACT_ASSIGN]="-=",+ [OP_MULTIPLY_ASSIGN]="*=",+ [OP_REMAINDER_ASSIGN]="%=",+ [OP_DIV_ASSIGN]="/=",+ [OP_SHIFT_LEFT_ASSIGN]="<<=",+ [OP_SHIFT_RIGHT_ASSIGN]=">>=",+ [OP_AND_ASSIGN]="&=",+ [OP_XOR_ASSIGN]="^=",+ [OP_PIPE_ASSIGN]="|=",+ [OP_NOP]="NOP",+ [OP_LOGICAL_OR]="||",+ [OP_LOGICAL_AND]="&&",+ [OP_LOGICAL_NOT]="!",+ [OP_BITWISE_OR]="|",+ [OP_BITWISE_AND]="&",+ [OP_BITWISE_XOR]="^",+ [OP_BITWISE_NOT]="~",+ [OP_ADDR_OF]="&",+ [OP_DEREFERENCE]="*",+ [OP_MEMBER_TROUGH_PTR]="->",+ [OP_MEMBER]=".",+ [OP_ARR_SUBSCRIPT]="ARR_SUBSCRIPT",+ [OP_POSTFIX_INC]="++",+ [OP_POSTFIX_DEC]="--",+ [OP_PREFIX_INC]="++",+ [OP_PREFIX_DEC]="--",+ [OP_UNARY_PLUS]="+",+ [OP_UNARY_MINUS]="-",+ [OP_CAST]="CAST",+ [OP_SIZEOF]="sizeof",+ [OP_SHIFT_LEFT]="<<",+ [OP_SHIFT_RIGHT]=">>",+ [OP_LESS_EQ]="<=",+ [OP_GREATER_EQ]=">=",+ [OP_LESS]="<",+ [OP_GREATER]=">",+ [OP_EQUAL]="==",+ [OP_NOT_EQUAL]="!=",+ [OP_CONSTANT]="CONSTANT",+ [OP_STRING_LITERAL]="STRING_LITERAL",+ [ST_COMPOUND]="COMPOUND_STATEMENT",+ [ST_EXPRESSION]="EXPRESSION",+ [ST_SWITCH]="switch",+ [ST_IF]="if",+ [ST_WHILE]="while",+ [ST_DO_WHILE]="do_while",+ [ST_GOTO]="goto",+ [ST_LABEL]="LABEL",+ [ST_CASE]="case",+ [ST_DEFAULT]="default",+ [ST_CONTINUE]="continue",+ [ST_BREAK]="break",+ [ST_RETURN]="return",+ [ST_FOR]="for",+ [ST_FUNCTION_DEFINITION]="FUNCTION_DEFINITION",+ [TRANSLATION_UNIT]="TRANSLATION_UNIT",+ };+ wonky_assert(is_valid_ast_enum(op));+ if(map[op]==NULL){- case OP_COMMA:- fprintf(out,",");break;- case OP_ADDITION:- fprintf(out,"+");break;- case OP_SUBTRACTION:- fprintf(out,"-");break;- case OP_MUL:- fprintf(out,"*");break;- case OP_DIV:- fprintf(out,"/");break;- case OP_REMAINDER:- fprintf(out,"%");break;- case OP_COND:- fprintf(out,"CONDITIONAL");break;- case OP_FUNCTION:- fprintf(out,"FUNCTION_CALL");break;- case OP_ASSIGN:- fprintf(out,"=");break;- case OP_ADD_ASSIGN:- fprintf(out,"+=");break;- case OP_SUBTRACT_ASSIGN:- fprintf(out,"-=");break;- case OP_MULTIPLY_ASSIGN:- fprintf(out,"*=");break;- case OP_REMAINDER_ASSIGN:- fprintf(out,"%=");break;- case OP_DIV_ASSIGN:- fprintf(out,"/=");break;- case OP_SHIFT_LEFT_ASSIGN:- fprintf(out,">>=");break;- case OP_SHIFT_RIGHT_ASSIGN:- fprintf(out,"<<=");break;- case OP_AND_ASSIGN:- fprintf(out,"&=");break;- case OP_XOR_ASSIGN:- fprintf(out,"^=");break;- case OP_PIPE_ASSIGN:- fprintf(out,"|=");break;- case OP_NOP:- fprintf(out,"NOP");break;- case OP_LOGICAL_OR:- fprintf(out,"||");break;- case OP_LOGICAL_AND:- fprintf(out,"&&");break;- case OP_LOGICAL_NOT:- fprintf(out,"!");break;- case OP_BITWISE_OR:- fprintf(out,"|");break;- case OP_BITWISE_AND:- fprintf(out,"&");break;- case OP_BITWISE_XOR:- fprintf(out,"^");break;- case OP_BITWISE_NOT:- fprintf(out,"~");break;- case OP_ADDR_OF:- fprintf(out,"&");break;- case OP_DEREFERENCE:- fprintf(out,"*");break;- case OP_MEMBER_TROUGH_PTR:- fprintf(out,"->");break;- case OP_MEMBER:- fprintf(out,".");break;- case OP_ARR_SUBSCRIPT:- fprintf(out,"ARR_SUBSCRIPT");break;- case OP_POSTFIX_INC:- fprintf(out,"++");break;- case OP_POSTFIX_DEC:- fprintf(out,"--");break;- case OP_PREFIX_INC:- fprintf(out,"++");break;- case OP_PREFIX_DEC:- fprintf(out,"--");break;- case OP_UNARY_PLUS:- fprintf(out,"+");break;- case OP_UNARY_MINUS:- fprintf(out,"-");break;- case OP_CAST:- fprintf(out,"CAST");break;- case OP_SIZEOF:- fprintf(out,"sizeof");break;- case OP_SHIFT_LEFT:- fprintf(out,"<<");break;- case OP_SHIFT_RIGHT:- fprintf(out,">>");break;- case OP_LESS_EQ:- fprintf(out,"<=");break;- case OP_GREATER_EQ:- fprintf(out,">=");break;- case OP_LESS:- fprintf(out,"<");break;- case OP_GREATER:- fprintf(out,">");break;- case OP_EQUAL:- fprintf(out,"==");break;- case OP_NOT_EQUAL:- fprintf(out,"!=");break;- case OP_CONSTANT:- fprintf(out,"CONSTANT");break;- case OP_STRING_LITERAL:- fprintf(out,"STRING_LITERAL");break;- case ST_COMPOUND:- fprintf(out,"COMPOUND");break;- case ST_EXPRESSION:- fprintf(out,"EXPRESSION");break;- case ST_SWITCH:- fprintf(out,"switch");break;- case ST_IF:- fprintf(out,"if");break;- case ST_WHILE:- fprintf(out,"while");break;- case ST_DO_WHILE:- fprintf(out,"do_while");break;- case ST_GOTO:- fprintf(out,"goto");break;- case ST_LABEL:- fprintf(out,"LABEL");break;- case ST_CASE:- fprintf(out,"case");break;- case ST_DEFAULT:- fprintf(out,"default");break;- case ST_CONTINUE:- fprintf(out,"continue");break;- case ST_BREAK:- fprintf(out,"break");break;- case ST_RETURN:- fprintf(out,"return");break;- case ST_FOR:- fprintf(out,"for");break;-- /*TODO obj dec obj def func decl*/- case ST_FUNCTION_DEFINITION:- fprintf(out,"FUNCTION_DEFINITION");break;- case TRANSLATION_UNIT:- fprintf(out,"TRANSLATION_UNIT");break;- case ERROR:- fprintf(out,"ERROR");break;- default:- fprintf(out,"NOT_POSSIBLE");break;++ }else+ {+ char *hold;+ hold=gstr_to_heap(map[op]);+ append_to_last_line(hold,compile_data->lines);}}- void print_error_tree(FILE *out,struct AST_Error *error)+ void print_error_tree(struct Compile_Data_Print *compile_data,struct AST_Error *error){- fprintf(out,"ERROR");+ append_to_last_line(gstr_to_heap("ERROR"),compile_data->lines);if(error->error!=NULL){- print_ast(out,(struct AST*)error->error);+ print_ast(compile_data,error->error);}}- void print_designator_expression_tree(FILE *out,struct AST_Designator *designator)+ void print_designator_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Designator *designator){- print_token(out,designator->id);+ print_token(compile_data,designator->id);}- void print_binary_expression_tree(FILE *out,struct AST_Binary_Expression *bin)+ void print_binary_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Binary_Expression *bin){if(bin->type==OP_ARR_SUBSCRIPT){- print_ast(out,(struct AST*)(struct AST*)bin->left);- fprintf(out,"[");- print_ast(out,(struct AST*)(struct AST*)bin->right);- fprintf(out,"]");+ print_ast(compile_data,(struct AST*)bin->left);+ append_to_last_line(gstr_to_heap("["),compile_data->lines);+ print_ast(compile_data,(struct AST*)bin->right);+ append_to_last_line(gstr_to_heap("]"),compile_data->lines);}else{- fprintf(out,"(");- print_ast(out,(struct AST*)(struct AST*)bin->left);- print_ast_enum(out,bin->type);- print_ast(out,(struct AST*)(struct AST*)bin->right);- fprintf(out,")");+ append_to_last_line(gstr_to_heap("("),compile_data->lines);+ print_ast(compile_data,(struct AST*)bin->left);+ print_ast_enum(compile_data,bin->type);+ print_ast(compile_data,(struct AST*)bin->right);+ append_to_last_line(gstr_to_heap(")"),compile_data->lines);}}- void print_conditional_expression_tree(FILE *out,struct AST_Conditional_Expression *cond)+ void print_conditional_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Conditional_Expression *cond){- fprintf(out,"(");- print_ast(out,(struct AST*)cond->left);- fprintf(out,"?");- print_ast(out,(struct AST*)cond->center);- fprintf(out,":");- print_ast(out,(struct AST*)cond->right);- fprintf(out,")");+ append_to_last_line(gstr_to_heap("("),compile_data->lines);+ print_ast(compile_data,(struct AST*)cond->left);+ append_to_last_line(gstr_to_heap("?"),compile_data->lines);+ print_ast(compile_data,(struct AST*)cond->center);+ append_to_last_line(gstr_to_heap(":"),compile_data->lines);+ print_ast(compile_data,(struct AST*)cond->right);+ append_to_last_line(gstr_to_heap(")"),compile_data->lines);}- void print_function_expression_tree(FILE *out,struct AST_Function_Expression *function_call)+ void print_function_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Function_Expression *function_call){size_t i;- print_ast(out,(struct AST*)function_call->id);- fprintf(out,"(");+ print_ast(compile_data,(struct AST*)function_call->id);+ append_to_last_line(gstr_to_heap("("),compile_data->lines);+if(function_call->number_of_arguments>0){for(i=0;i<function_call->number_of_arguments;++i){- print_ast(out,(struct AST*)function_call->arg_list[i]);+ print_ast(compile_data,(struct AST*)function_call->arg_list[i]);if(i!=function_call->number_of_arguments-1)- fprintf(out,",");+ append_to_last_line(gstr_to_heap(","),compile_data->lines);}}- fprintf(out,")");+ append_to_last_line(gstr_to_heap(")"),compile_data->lines);}- void print_unary_expression_tree(FILE *out,struct AST_Unary_Expression *unary_expression)+ void print_unary_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Unary_Expression *unary_expression){if(unary_expression->type==OP_CAST){- fprintf(out,"(");- print_expression_value_type(out,unary_expression->value);- fprintf(out,")(");+ append_to_last_line(gstr_to_heap("("),compile_data->lines);+ print_expression_value_type(compile_data,unary_expression->value);+ append_to_last_line(gstr_to_heap(")("),compile_data->lines);- print_ast(out,(struct AST*)unary_expression->operand);- fprintf(out,")");+ print_ast(compile_data,(struct AST*)unary_expression->operand);+ append_to_last_line(gstr_to_heap(")"),compile_data->lines);}else{- print_ast_enum(out,unary_expression->type);- print_ast(out,(struct AST*)unary_expression->operand);+ print_ast_enum(compile_data,unary_expression->type);+ print_ast(compile_data,(struct AST*)unary_expression->operand);}}- void print_labeled_statement_tree(FILE *out,struct AST_Labeled_Statement *lab)+ void print_labeled_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Labeled_Statement *lab){if(lab->type!=ST_LABEL)- print_ast_enum(out,lab->type);+ print_ast_enum(compile_data,lab->type);if(lab->label!=NULL)- print_denoted(out,(struct Denoted*)lab->label);+ print_denoted(compile_data,(struct Denoted*)lab->label);}- void print_compound_statement_tree(FILE *out,struct AST_Compound_Statement *comp)+ void print_compound_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Compound_Statement *comp){struct Queue_Node *it;- fprintf(out,"{\n");+ push_line(gstr_to_heap("{"),compile_data->indent,compile_data->lines);+ ++compile_data->indent;for(it=comp->components.first;it!=NULL;it=it->prev){- print_ast(out,(struct AST*)(struct AST*)(it->data));- fprintf(out,";\n");+ push_line(gstr_to_heap(""),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)(struct AST*)(it->data));+ append_to_last_line(gstr_to_heap(";"),compile_data->lines);}- fprintf(out,"}\n");+ --compile_data->indent;+ push_line(gstr_to_heap("}"),compile_data->indent,compile_data->lines);}- void print_if_statement_tree(FILE *out,struct AST_If_Statement *ifs)+ void print_if_statement_tree(struct Compile_Data_Print *compile_data,struct AST_If_Statement *ifs){- fprintf(out,"if(");- print_ast(out,(struct AST*)ifs->condition);- fprintf(out,")\n");- print_ast(out,(struct AST*)ifs->body_statement);+ push_line(gstr_to_heap("if("),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)ifs->condition);+ append_to_last_line(gstr_to_heap(")"),compile_data->lines);++ push_line(gstr_to_heap(""),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)ifs->body_statement);if(ifs->else_statement!=NULL){- fprintf(out,"\nelse");- print_ast(out,(struct AST*)ifs->else_statement);+ push_line(gstr_to_heap("else"),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)ifs->else_statement);}}- void print_switch_statement_tree(FILE *out,struct AST_Switch_Statement *swi)+ void print_switch_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Switch_Statement *swi){- fprintf(out,"switch(");- print_ast(out,(struct AST*)swi->condition);- fprintf(out,")\n");- print_ast(out,(struct AST*)swi->body_statement);+ push_line(gstr_to_heap("switch("),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)swi->condition);+ append_to_last_line(gstr_to_heap(")"),compile_data->lines);++ push_line(gstr_to_heap(""),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)swi->body_statement);}- void print_while_statement_tree(FILE *out,struct AST_While_Statement *whi)+ void print_while_statement_tree(struct Compile_Data_Print *compile_data,struct AST_While_Statement *whi){- fprintf(out,"while(");- print_ast(out,(struct AST*)whi->condition);- fprintf(out,")\n");- print_ast(out,(struct AST*)whi->body_statement);+ push_line(gstr_to_heap("while("),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)whi->condition);+ append_to_last_line(gstr_to_heap(")"),compile_data->lines);++ push_line(gstr_to_heap(""),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)whi->body_statement);}- void print_do_while_statement_tree(FILE *out,struct AST_Do_While_Statement *whi)+ void print_do_while_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Do_While_Statement *whi){- fprintf(out,"do\n");- print_ast(out,(struct AST*)whi->body_statement);- fprintf(out,"while(");- print_ast(out,(struct AST*)whi->condition);- fprintf(out,")\n");+ push_line(gstr_to_heap("do"),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)whi->body_statement);++ push_line(gstr_to_heap("while("),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)whi->condition);+ append_to_last_line(gstr_to_heap(")"),compile_data->lines);}- void print_for_statement_tree(FILE *out,struct AST_For_Statement *fo)+ void print_for_statement_tree(struct Compile_Data_Print *compile_data,struct AST_For_Statement *fo){- fprintf(out,"for(\n");- print_ast(out,(struct AST*)fo->initialisation);- fprintf(out,";\n");- print_ast(out,(struct AST*)fo->condition);- fprintf(out,";\n");- print_ast(out,(struct AST*)fo->update);- fprintf(out,")\n");- print_ast(out,(struct AST*)fo->body_statement);+ push_line(gstr_to_heap("for("),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)fo->initialisation);++ push_line(gstr_to_heap(";"),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)fo->condition);++ push_line(gstr_to_heap(";"),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)fo->update);++ push_line(gstr_to_heap(")"),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)fo->body_statement);}- void print_return_statement_tree(FILE *out,struct AST_Return_Statement *return_expression)+ void print_return_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Return_Statement *return_expression){- fprintf(out,"return ");- print_ast(out,(struct AST*)return_expression->return_expression);+ push_line(gstr_to_heap("return "),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)return_expression->return_expression);}- void print_goto_statement_tree(FILE *out,struct AST_Goto_Statement *got)+ void print_goto_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Goto_Statement *got){- fprintf(out,"goto ");- print_denoted(out,(struct Denoted*)got->label);+ push_line(gstr_to_heap("goto"),compile_data->indent,compile_data->lines);+ print_denoted(compile_data,(struct Denoted*)got->label);}- void print_type(FILE *out,struct Type *type,char should_print_struct_union)+ void print_type(struct Compile_Data_Print *compile_data,struct Type *type,char should_print_struct_union){- print_type_qualifier(out,type);- print_type_sign(out,type);- print_type_constraint(out,type);+ print_type_qualifier(compile_data,type);+ print_type_sign(compile_data,type);+ print_type_constraint(compile_data,type);+switch(type->specifier){case TS_VOID:- fprintf(out,"void");return;+ append_to_last_line(gstr_to_heap(" void"),compile_data->lines);+ return;case TS_CHAR:- fprintf(out,"char");return;+ append_to_last_line(gstr_to_heap(" char"),compile_data->lines);+ return;case TS_INT:- fprintf(out,"int");return;+ append_to_last_line(gstr_to_heap(" int"),compile_data->lines);+ return;case TS_FLOAT:- fprintf(out,"float");return;+ append_to_last_line(gstr_to_heap(" float"),compile_data->lines);+ return;case TS_DOUBLE:- fprintf(out,"double");return;+ append_to_last_line(gstr_to_heap(" double"),compile_data->lines);+ return;case TS_UNION:case TS_STRUCT:if(should_print_struct_union){- print_struct_union(out,((struct Type_Struct_Union*)type)->struct_union);+ print_struct_union(compile_data,((struct Type_Struct_Union*)type)->struct_union);}else{- fprintf(out,(type->specifier==TS_STRUCT?"struct":"union"));+ append_to_last_line( gstr_to_heap((type->specifier==TS_STRUCT?"struct":"union")),+ compile_data->lines+ );}return;case TS_ENUM:- print_enumeration(out,((struct Type_Enum*)type)->enumeration);+ print_enumeration(compile_data,((struct Type_Enum*)type)->enumeration);return;case TS_POINTER:- fprintf(out,"pointer to ");- print_type(out,((struct Type_Pointer*)type)->points_to,0);+ append_to_last_line(gstr_to_heap(" pointer to"),compile_data->lines);+ print_type(compile_data,((struct Type_Pointer*)type)->points_to,0);return;case TS_ARRAY:- fprintf(out,"array [%zu] of ",((struct Type_Array*)type)->number_of_elements);- print_type(out,((struct Type_Array*)type)->is_array_of,should_print_struct_union);- return;+ {+ char *number_of_elements;+ number_of_elements=calloc(1,1024);++ if(snprintf(number_of_elements,1024," array [%zu] of ",((struct Type_Array*)type)->number_of_elements)==1024)+ number_of_elements[1023]='\0';+ append_to_last_line(number_of_elements,compile_data->lines);++ print_type(compile_data,((struct Type_Array*)type)->is_array_of,should_print_struct_union);+ return;+ }case TS_FUNC:- fprintf(out,"function taking arguments (");- print_function_args(out,(struct Type_Function*)type);- fprintf(out,") returning ");- print_type(out,((struct Type_Function*)type)->return_type,should_print_struct_union);+ append_to_last_line(gstr_to_heap(" function taking arguments ("),compile_data->lines);+ print_function_args(compile_data,(struct Type_Function*)type);+ append_to_last_line(gstr_to_heap(") returning"),compile_data->lines);+ print_type(compile_data,((struct Type_Function*)type)->return_type,should_print_struct_union);return;case TS_NONE:- fprintf(out,"NONE");return;+ append_to_last_line(gstr_to_heap(" NONE "),compile_data->lines);+ return;case TS_ERROR:- fprintf(out,"ERROR!");return;+ append_to_last_line(gstr_to_heap(" ERROR! "),compile_data->lines);+ return;}wonky_assert(SHOULD_NOT_REACH_HERE);}- void print_denoted(FILE *out,struct Denoted *denoted)+ void print_denoted(struct Compile_Data_Print *compile_data,struct Denoted *denoted){switch(denoted->denotation){case DT_Macro:- fprintf(out,"macro ");return;+ append_to_last_line(gstr_to_heap("macro"),compile_data->lines);+ return;case DT_Macro_Parameter:- fprintf(out,"macro parameter ");return;+ append_to_last_line(gstr_to_heap("macro parameter"),compile_data->lines);+ return;case DT_Statement:- fprintf(out,"label ");return;+ append_to_last_line(gstr_to_heap("label"),compile_data->lines);+ return;case DT_Object:switch(((struct Denoted_Object*)denoted)->linkage){case LINKAGE_INTERNAL:- fprintf(out,"internally linked ");+ append_to_last_line(gstr_to_heap("internally linked "),compile_data->lines);break;case LINKAGE_EXTERNAL:- fprintf(out,"externally linked ");+ append_to_last_line(gstr_to_heap("externally linked "),compile_data->lines);break;case LINKAGE_NONE:break;default:wonky_assert(SHOULD_NOT_REACH_HERE);}- fprintf(out,"denoted object ");- print_token(out,((struct Denoted_Object*)denoted)->id);- print_object(out,((struct Denoted_Object*)denoted)->object);- fprintf(out," is a ");- print_type(out,((struct Denoted_Object*)denoted)->object->type,1);-+ append_to_last_line(gstr_to_heap("denoted object "),compile_data->lines);+ print_token(compile_data,((struct Denoted_Object*)denoted)->id);+ print_object(compile_data,((struct Denoted_Object*)denoted)->object);+ append_to_last_line(gstr_to_heap(" is a"),compile_data->lines);+ print_type(compile_data,((struct Denoted_Object*)denoted)->object->type,1);return;case DT_Typedef:- fprintf(out,"typedef ");- print_token(out,((struct Denoted_Type*)denoted)->id);- fprintf(out," to ");- print_type(out,((struct Denoted_Type*)denoted)->type,0);+ append_to_last_line(gstr_to_heap("typedef "),compile_data->lines);+ print_token(compile_data,((struct Denoted_Type*)denoted)->id);+ append_to_last_line(gstr_to_heap(" to "),compile_data->lines);+ print_type(compile_data,((struct Denoted_Type*)denoted)->type,0);return;case DT_Function:- print_token(out,((struct Denoted_Function*)denoted)->id);- fprintf(out," is ");+ print_token(compile_data,((struct Denoted_Function*)denoted)->id);+ append_to_last_line(gstr_to_heap(" is "),compile_data->lines);switch(((struct Denoted_Function*)denoted)->linkage){+ case LINKAGE_INTERNAL:+ append_to_last_line(gstr_to_heap("an internally linked"),compile_data->lines);+ break;case LINKAGE_EXTERNAL:- fprintf(out," an externally linked ");+ append_to_last_line(gstr_to_heap("an externally linked"),compile_data->lines);break;- case LINKAGE_INTERNAL:- fprintf(out," an internally linked ");+ case LINKAGE_NONE:break;default:wonky_assert(SHOULD_NOT_REACH_HERE);}- print_type(out,((struct Denoted_Function*)denoted)->type,1);+ print_type(compile_data,((struct Denoted_Function*)denoted)->type,1);return;case DT_Enum:- print_token(out,((struct Denoted_Enum*)denoted)->enumeration->id);- fprintf(out," is ");- print_enumeration(out,((struct Denoted_Enum*)denoted)->enumeration);+ print_token(compile_data,((struct Denoted_Enum*)denoted)->enumeration->id);+ append_to_last_line(gstr_to_heap(" is "),compile_data->lines);+ print_enumeration(compile_data,((struct Denoted_Enum*)denoted)->enumeration);return;case DT_Enum_Constant:- fprintf(out,"%i ",((struct Denoted_Enum_Const*)denoted)->value);- return;+ {+ char *value;+ value=malloc(1024);+ if(snprintf(value,1024,"%d ",((struct Denoted_Enum_Const*)denoted)->value)==1024)+ value[1023]='\0';+ append_to_last_line(value,compile_data->lines);+ return;+ }case DT_Struct_Union_Tag:- print_token(out,((struct Denoted_Struct_Union*)denoted)->struct_union->id);- fprintf(out," is ");- print_struct_union(out,((struct Denoted_Struct_Union*)denoted)->struct_union);+ print_token(compile_data,((struct Denoted_Struct_Union*)denoted)->struct_union->id);+ append_to_last_line(gstr_to_heap(" is "),compile_data->lines);+ print_struct_union(compile_data,((struct Denoted_Struct_Union*)denoted)->struct_union);+ return;case DT_Error:- fprintf(out,"denotation error");return;+ append_to_last_line(gstr_to_heap("denotation error"),compile_data->lines);+ return;case DT_Prototype:- fprintf(out,"denotation prototyep");return;+ append_to_last_line(gstr_to_heap("denotation prototype"),compile_data->lines);+ return;default:wonky_assert(SHOULD_NOT_REACH_HERE);}}- void print_list_of_denoted(FILE *out,struct Queue *denoted)+ void print_list_of_denoted(struct Compile_Data_Print *compile_data,struct Queue *denoted){struct Queue_Node *it;for(it=denoted->first;it!=NULL;it=it->prev){- print_denoted(out,(struct Denoted*)it->data);+ print_denoted(compile_data,(struct Denoted*)it->data);if(it->prev!=NULL)- fprintf(out,",");+ append_to_last_line(gstr_to_heap(","),compile_data->lines);}}- void print_enumeration(FILE *out,struct Enum *enumeration)+ void print_enumeration(struct Compile_Data_Print *compile_data,struct Enum *enumeration){- fprintf(out,"enum ");- print_list_of_denoted(out,enumeration->consts);+ append_to_last_line(gstr_to_heap("enum "),compile_data->lines);+ print_list_of_denoted(compile_data,enumeration->consts);}- void print_struct_union(FILE *out,struct Struct_Union *struct_union)+ void print_struct_union(struct Compile_Data_Print *compile_data,struct Struct_Union *struct_union){switch(struct_union->specifier){case TS_UNION:- fprintf(out,"union ");+ append_to_last_line(gstr_to_heap("union "),compile_data->lines);break;case TS_STRUCT:- fprintf(out,"struct ");+ append_to_last_line(gstr_to_heap("struct "),compile_data->lines);break;default:- wonky_assert(1==0);+ wonky_assert(SHOULD_NOT_REACH_HERE);}- fprintf(out,"{");- print_list_of_denoted(out,struct_union->members);- fprintf(out,"}");+ append_to_last_line(gstr_to_heap("{"),compile_data->lines);+ print_list_of_denoted(compile_data,struct_union->members);+ append_to_last_line(gstr_to_heap("}"),compile_data->lines);}- void print_object(FILE *out,struct Object *object)+ void print_object(struct Compile_Data_Print *compile_data,struct Object *object){if(object->kind==OBJECT_KIND_NORMAL){- print_normal_object(out,object);+ print_normal_object(compile_data,object);}else{- print_bitfield_object(out,(struct Object_Bitfield*)object);+ print_bitfield_object(compile_data,(struct Object_Bitfield*)object);}}- void print_normal_object(FILE *out,struct Object *object)+ void print_normal_object(struct Compile_Data_Print *compile_data,struct Object *object){- fprintf(out," normal object that ");+ append_to_last_line(gstr_to_heap(" normal object that"),compile_data->lines);}- void print_bitfield_object(FILE *out,struct Object_Bitfield *object)+ void print_bitfield_object(struct Compile_Data_Print *compile_data,struct Object_Bitfield *object){- fprintf(out," bitfield object with %zu bits ",object->number_of_bits);+ char *str;++ str=calloc(1,1024);++ if(snprintf(str,1024," bitfield object with %zu bits ",object->number_of_bits)==1024)+ str[1023]='\0';+ append_to_last_line(str,compile_data->lines);}- void print_translation_unit_tree(FILE *out,struct AST_Translation_Unit *unit)+ void print_translation_unit_tree(struct Compile_Data_Print *compile_data,struct AST_Translation_Unit *unit){struct Queue_Node *it;struct AST* hold;for(it=unit->components->first;it!=NULL;it=it->prev){hold=(struct AST*)(it->data);- print_ast(out,(struct AST*)hold);+ print_ast(compile_data,(struct AST*)hold);if(hold->type!=ST_FUNCTION_DEFINITION){- fprintf(out,";\n");+ append_to_last_line(gstr_to_heap(";"),compile_data->lines);+ push_line(gstr_to_heap(""),compile_data->indent,compile_data->lines);}}}- void print_ast(FILE *out,struct AST* tree)+ void print_ast(struct Compile_Data_Print *compile_data,struct AST* tree){if(tree==NULL){- fprintf(out,"NULL");- return ;+ append_to_last_line(gstr_to_heap("NULL"),compile_data->lines);+ return;}switch(tree->type){case OP_DESIGNATOR:- print_designator_expression_tree(out,(struct AST_Designator*)tree);+ print_designator_expression_tree(compile_data,(struct AST_Designator*)tree);break;case OP_MEMBER_TROUGH_PTR:case OP_MEMBER:case OP_GREATER_EQ:case OP_GREATER:case OP_NOT_EQUAL:- print_binary_expression_tree(out,(struct AST_Binary_Expression*)tree);+ print_binary_expression_tree(compile_data,(struct AST_Binary_Expression*)tree);break;case OP_COND:- print_conditional_expression_tree(out,(struct AST_Conditional_Expression*)tree);+ print_conditional_expression_tree(compile_data,(struct AST_Conditional_Expression*)tree);break;case OP_FUNCTION:- print_function_expression_tree(out,(struct AST_Function_Expression*)tree);+ print_function_expression_tree(compile_data,(struct AST_Function_Expression*)tree);break;case OP_LOGICAL_NOT:case OP_UNARY_MINUS:case OP_POSTFIX_DEC:case OP_PREFIX_DEC:case OP_CAST:- print_unary_expression_tree(out,(struct AST_Unary_Expression*)tree);+ print_unary_expression_tree(compile_data,(struct AST_Unary_Expression*)tree);break;case OP_STRING_LITERAL:- print_string_literal(out,(struct AST_String_Literal*)tree);+ print_string_literal(compile_data,(struct AST_String_Literal*)tree);break;case OP_CONSTANT:- print_constant_tree(out,(struct AST_Constant*)tree);+ print_constant_tree(compile_data,(struct AST_Constant*)tree);break;case OP_NOP:- fprintf(out,"NOP");+ append_to_last_line(gstr_to_heap("NOP"),compile_data->lines);break;case ST_SWITCH:- print_switch_statement_tree(out,(struct AST_Switch_Statement*)tree);+ print_switch_statement_tree(compile_data,(struct AST_Switch_Statement*)tree);break;case ST_IF:- print_if_statement_tree(out,(struct AST_If_Statement*)tree);+ print_if_statement_tree(compile_data,(struct AST_If_Statement*)tree);break;case ST_WHILE:- print_while_statement_tree(out,(struct AST_While_Statement*)tree);+ print_while_statement_tree(compile_data,(struct AST_While_Statement*)tree);break;case ST_DO_WHILE:- print_do_while_statement_tree(out,(struct AST_Do_While_Statement*)tree);+ print_do_while_statement_tree(compile_data,(struct AST_Do_While_Statement*)tree);break;case ST_GOTO:- print_goto_statement_tree(out,(struct AST_Goto_Statement*)tree);+ print_goto_statement_tree(compile_data,(struct AST_Goto_Statement*)tree);break;case ST_DEFAULT:case ST_LABEL:case ST_CASE:- print_labeled_statement_tree(out,(struct AST_Labeled_Statement*)tree);+ print_labeled_statement_tree(compile_data,(struct AST_Labeled_Statement*)tree);break;case ST_CONTINUE:- fprintf(out,"continue");+ append_to_last_line(gstr_to_heap("continue"),compile_data->lines);break;case ST_BREAK:- fprintf(out,"break");+ append_to_last_line(gstr_to_heap("break"),compile_data->lines);break;case ST_RETURN:- print_return_statement_tree(out,(struct AST_Return_Statement*)tree);+ print_return_statement_tree(compile_data,(struct AST_Return_Statement*)tree);break;case ST_FOR:- print_for_statement_tree(out,(struct AST_For_Statement*)tree);+ print_for_statement_tree(compile_data,(struct AST_For_Statement*)tree);break;case ST_COMPOUND:- print_compound_statement_tree(out,(struct AST_Compound_Statement*)tree);+ print_compound_statement_tree(compile_data,(struct AST_Compound_Statement*)tree);break;case ST_OBJECT_DECLARATION:- print_denoted(out,(struct Denoted*)((struct AST_Object_Declaration*)tree)->object);+ print_denoted(compile_data,(struct Denoted*)((struct AST_Object_Declaration*)tree)->object);break;case ST_TYPE_DEFINITION:- print_denoted(out,(struct Denoted*)((struct AST_Type_Definition*)tree)->definition);+ print_denoted(compile_data,(struct Denoted*)((struct AST_Type_Definition*)tree)->definition);break;case ST_FUNCTION_DECLARATION:- print_denoted(out,(struct Denoted*)((struct AST_Function_Declaration*)tree)->function);+ print_denoted(compile_data,(struct Denoted*)((struct AST_Function_Declaration*)tree)->function);break;case ST_FUNCTION_DEFINITION:- print_function_definition(out,(struct AST_Function_Definition*)tree);+ print_function_definition(compile_data,(struct AST_Function_Definition*)tree);break;case TRANSLATION_UNIT:- print_translation_unit_tree(out,(struct AST_Translation_Unit*)tree);+ print_translation_unit_tree(compile_data,(struct AST_Translation_Unit*)tree);break;case ERROR:- print_error_tree(out,(struct AST_Error*)tree);+ print_error_tree(compile_data,(struct AST_Error*)tree);break;default:- fprintf(out,"NOT_POSSIBLE");break;+ append_to_last_line(gstr_to_heap("NOT_POSSIBLE"),compile_data->lines);}}- void print_function_definition(FILE *out,struct AST_Function_Definition *function)+ void print_function_definition(struct Compile_Data_Print *compile_data,struct AST_Function_Definition *function){- print_token(out,function->function->id);- fprintf(out," is");+ print_token(compile_data,function->function->id);+ append_to_last_line(gstr_to_heap(" is"),compile_data->lines);+switch(function->function->linkage){case LINKAGE_EXTERNAL:- fprintf(out," an externally linked ");+ append_to_last_line(gstr_to_heap(" an externally linked "),compile_data->lines);break;case LINKAGE_INTERNAL:- fprintf(out," an internally linked ");+ append_to_last_line(gstr_to_heap(" an internally linked "),compile_data->lines);break;default:wonky_assert(SHOULD_NOT_REACH_HERE);}- print_type(out,function->function->type,1);- print_compound_statement_tree(out,function->body);+ print_type(compile_data,function->function->type,1);+ print_compound_statement_tree(compile_data,function->body);}- void print_program_ast(FILE *out,struct Program *program)+ void print_program_ast(struct Compile_Data_Print *compile_data,struct Program *program){size_t i;struct Queue_Node *it;for(it=program->translation_units->first;it!=NULL;it=it->prev){- fprintf(out,"TRANSLATION_UNIT {\n");- print_ast(out,(struct AST*)(struct AST*)it->data);- fprintf(out,"\n} TRANSLATION_UNIT_END\n");+ push_line(gstr_to_heap("TRANSLATION_UNIT {"),compile_data->indent,compile_data->lines);+ ++compile_data->indent;++ push_line(gstr_to_heap(""),compile_data->indent,compile_data->lines);+ print_ast(compile_data,(struct AST*)(struct AST*)it->data);++ --compile_data->indent;+ push_line(gstr_to_heap("} TRANSLATION_UNIT_END"),compile_data->indent,compile_data->lines);}}void print_keyword_enum(FILE *out,enum KEYWORDS kw)print_translation_error(out,(struct Translation_Message*)it->data);}}- void print_function_args(FILE *out,struct Type_Function *func)+ void print_function_args(struct Compile_Data_Print *compile_data,struct Type_Function *func){size_t i;if(func->number_of_arguments==0)return;- print_denoted(out,(struct Denoted*)func->arguments[0]);+ print_denoted(compile_data,(struct Denoted*)func->arguments[0]);for(i=1;i<func->number_of_arguments;++i){- fprintf(out,", ");- print_denoted(out,(struct Denoted*)func->arguments[i]);+ append_to_last_line(gstr_to_heap(", "),compile_data->lines);+ print_denoted(compile_data,(struct Denoted*)func->arguments[i]);}}- void print_type_qualifier(FILE *out,struct Type *type)+ void print_type_qualifier(struct Compile_Data_Print *compile_data,struct Type *type){-- switch(type->specifier)- {- case TS_VOID:- case TS_CHAR:- case TS_INT:- case TS_FLOAT:- case TS_DOUBLE:- fprintf(out,"%s %s",- (AS_BASIC_TYPE_PTR(type)->is_const?"constant ":""),- (AS_BASIC_TYPE_PTR(type)->is_volatile ?"volatile ":"")- );- break;- case TS_STRUCT:- case TS_UNION:- fprintf(out,"%s %s",- (AS_STRUCT_UNION_PTR(type)->is_const?"constant ":""),- (AS_STRUCT_UNION_PTR(type)->is_volatile ?"volatile ":"")- );- break;- case TS_ENUM:- fprintf(out,"%s %s",- (AS_STRUCT_UNION_PTR(type)->is_const?"constant ":""),- (AS_STRUCT_UNION_PTR(type)->is_volatile ?"volatile ":"")- );- break;- case TS_POINTER:- fprintf(out,"%s %s",- (AS_TYPE_PTR_PTR(type)->is_const?"constant ":""),- (AS_TYPE_PTR_PTR(type)->is_volatile ?"volatile ":"")- );- break;- case TS_ARRAY:- case TS_FUNC:- break;- case TS_NONE:- case TS_ERROR:- default:- fprintf(out,"error");- }+ if(type_is_constant(type))+ append_to_last_line(gstr_to_heap(" constant "),compile_data->lines);+ if(type_is_volatile(type))+ append_to_last_line(gstr_to_heap(" volatile "),compile_data->lines);}- void print_type_constraint_enum(FILE *out,enum Type_Specifier specifier)+ void print_type_constraint_enum(struct Compile_Data_Print *compile_data,enum Type_Specifier specifier){switch(specifier){case TC_LONG:- fprintf(out,"long ");+ append_to_last_line(gstr_to_heap("long "),compile_data->lines);break;case TC_LONG_LONG:- fprintf(out,"long long ");+ append_to_last_line(gstr_to_heap("long long "),compile_data->lines);break;case TC_SHORT:- fprintf(out,"short ");+ append_to_last_line(gstr_to_heap("short "),compile_data->lines);break;}}- void print_type_sign_enum(FILE *out,enum Type_Signedness sign)+ void print_type_sign_enum(struct Compile_Data_Print *compile_data,enum Type_Signedness sign){-if(sign==TSIGN_UNSIGNED)- fprintf(out,"unsigned ");+ append_to_last_line(gstr_to_heap("unsigned "),compile_data->lines);}- void print_type_constraint(FILE *out,struct Type *type)+ void print_type_constraint(struct Compile_Data_Print *compile_data,struct Type *type){switch(type->specifier){case TS_INT:case TS_FLOAT:case TS_DOUBLE:- print_type_constraint_enum(out,AS_BASIC_TYPE_PTR(type)->constraint);+ print_type_constraint_enum(compile_data,AS_BASIC_TYPE_PTR(type)->constraint);}}- void print_type_sign(FILE *out,struct Type *type)+ void print_type_sign(struct Compile_Data_Print *compile_data,struct Type *type){switch(type->specifier){case TS_INT:case TS_FLOAT:case TS_DOUBLE:- print_type_sign_enum(out,AS_BASIC_TYPE_PTR(type)->sign);+ print_type_sign_enum(compile_data,AS_BASIC_TYPE_PTR(type)->sign);break;}}- void print_constant_tree(FILE *out,struct AST_Constant *constant)+ void print_constant_tree(struct Compile_Data_Print *compile_data,struct AST_Constant *constant){- fprintf(out,"CONSTANT of type ");+ append_to_last_line(gstr_to_heap("CONSTANT of type"),compile_data->lines);//print_type(out,constant->value_type,1);}- void print_string_literal(FILE *out,struct AST_String_Literal *string)+ void print_string_literal(struct Compile_Data_Print *compile_data,struct AST_String_Literal *string){- fprintf(out,"STRING LITERAL of type");+ append_to_last_line(gstr_to_heap("STRING LITERAL"),compile_data->lines);//print_token(out,string->string);}- void print_expression_value(FILE *out,struct Expression_Value *value)+ void print_expression_value(struct Compile_Data_Print *compile_data,struct Expression_Value *value){- fprintf(out,"EXPRESSION VALUE OF TYPE");- print_expression_value_type(out,value);+ append_to_last_line(gstr_to_heap("EXPRESSION VALUE of type"),compile_data->lines);+ print_expression_value_type(compile_data,value);}- void print_expression_value_type(FILE *out,struct Expression_Value *expression_value)+ void print_expression_value_type(struct Compile_Data_Print *compile_data,struct Expression_Value *expression_value){switch(expression_value->type){case VALUE_LVALUE:- print_type(out, ((struct Expression_Value_LValue*)expression_value)->object->type,1);+ print_type(compile_data, ((struct Expression_Value_LValue*)expression_value)->object->type,1);return;case VALUE_TEMP:- print_type(out,((struct Expression_Value_RValue*)expression_value)->temp_object->type,1);+ print_type(compile_data,((struct Expression_Value_RValue*)expression_value)->temp_object->type,1);return;case VALUE_FUNCTION_DESIGNATOR:- print_type(out,((struct Expression_Value_Function_Designator*)expression_value)->function->type,1);+ print_type(compile_data,((struct Expression_Value_Function_Designator*)expression_value)->function->type,1);return;case VALUE_CONSTANT:- print_type(out, ((struct Expression_Value_Constant*)expression_value)->constant->type,1);+ print_type(compile_data, ((struct Expression_Value_Constant*)expression_value)->constant->type,1);return;case VALUE_VOID:- fprintf(out,"void");+ append_to_last_line(gstr_to_heap("void"),compile_data->lines);return;}wonky_assert(SHOULD_NOT_REACH_HERE);F diff --git a/src/backend/text/print/print.h b/src/backend/text/print/print.h --- a/src/backend/text/print/print.h +++ b/src/backend/text/print/print.h#ifndef WONKY_PRINT_H#define WONKY_PRINT_H WONKY_PRINT_H-+ #include <print.hh>#include <stdio.h>#include <wonky_assert.h>#include <wonky.h>#include <compile.h>#include <lines.h>-- #define INDENT for(int j=0;j<indent;++j) fprintf(out," ");- #define TOK(s) ((struct token*)(s))#define ASTPTR(s) ((struct AST*)(s))- extern int indent;+ struct Compile_Data_Print+ {+ enum Compilation_Type type;+ struct Queue *lines;/*queue of struct Lines*/+ int indent;+ };+ struct Compiled_Object_Print+ {+ enum Compilation_Type type;+ struct Queue *lines;+ };++ struct Compiled_Object_Print* compile_program_for_print(struct Program *program);+ void save_compiled_object_for_print(struct Compiled_Object_Print *object,FILE *out);++ struct Compiled_Object_Print* get_print_compile_object(struct Queue *lines);+ struct Compile_Data_Print* get_print_compile_data();++- void print_token(FILE *out,struct token *token);+ void print_token(struct Compile_Data_Print *compile_data,struct token *token);void print_tokens(FILE *out,struct Queue *tokens);- char print_tokens_of_program(FILE *out,char **base_names);- void print_ast_enum(FILE *out,enum AST_Type op);- void print_error_tree(FILE *out,struct AST_Error *error);- void print_designator_expression_tree(FILE *out,struct AST_Designator *designator);- void print_binary_expression_tree(FILE *out,struct AST_Binary_Expression *bin);- void print_conditional_expression_tree(FILE *out,struct AST_Conditional_Expression *cond);- void print_function_expression_tree(FILE *out,struct AST_Function_Expression *function_call);- void print_unary_expression_tree(FILE *out,struct AST_Unary_Expression *unary_expression);- void print_constant_tree(FILE *out,struct AST_Constant *constant);- void print_string_literal(FILE *out,struct AST_String_Literal *string);- //void print_lvalue_expression_tree(FILE *out,struct AST_Lvalue_Expression *lval);- void print_labeled_statement_tree(FILE *out,struct AST_Labeled_Statement *lab);- void print_compound_statement_tree(FILE *out,struct AST_Compound_Statement *comp);- void print_if_statement_tree(FILE *out,struct AST_If_Statement *ifs);- void print_switch_statement_tree(FILE *out,struct AST_Switch_Statement *swi);- void print_while_statement_tree(FILE *out,struct AST_While_Statement *whi);- void print_do_while_statement_tree(FILE *out,struct AST_Do_While_Statement *whi);- void print_for_statement_tree(FILE *out,struct AST_For_Statement *fo);- void print_return_statement_tree(FILE *out,struct AST_Return_Statement *return_expression);- void print_goto_statement_tree(FILE *out,struct AST_Goto_Statement *got);- void print_type(FILE *out,struct Type *type,char print_struct_union);- void print_denoted(FILE *out,struct Denoted *denoted);- void print_list_of_denoted(FILE *out,struct Queue *denoted);- void print_enumeration(FILE *out,struct Enum *enumeration);- void print_struct_union(FILE *out,struct Struct_Union *struct_union);- void print_object(FILE *out,struct Object *object);- void print_normal_object(FILE *out,struct Object *object);- void print_bitfield_object(FILE *out,struct Object_Bitfield *object);- void print_translation_unit_tree(FILE *out,struct AST_Translation_Unit *unit);- void print_ast(FILE *out,struct AST* tree);- void print_program_tokens(FILE *out,struct Program *program);- void print_program_ast(FILE *out,struct Program *program);+ char print_tokens_of_program(FILE *out,char **base_source_names);+ void print_ast_enum(struct Compile_Data_Print *compile_data,enum AST_Type op);+ void print_error_tree(struct Compile_Data_Print *compile_data,struct AST_Error *error);+ void print_designator_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Designator *designator);+ void print_binary_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Binary_Expression *bin);+ void print_conditional_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Conditional_Expression *cond);+ void print_function_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Function_Expression *function_call);+ void print_unary_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Unary_Expression *unary_expression);+ void print_constant_tree(struct Compile_Data_Print *compile_data,struct AST_Constant *constant);+ void print_string_literal(struct Compile_Data_Print *compile_data,struct AST_String_Literal *string);+ //void print_lvalue_expression_tree(struct Compile_Data_Print *compile_data,struct AST_Lvalue_Expression *lval);+ void print_labeled_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Labeled_Statement *lab);+ void print_compound_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Compound_Statement *comp);+ void print_if_statement_tree(struct Compile_Data_Print *compile_data,struct AST_If_Statement *ifs);+ void print_switch_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Switch_Statement *swi);+ void print_while_statement_tree(struct Compile_Data_Print *compile_data,struct AST_While_Statement *whi);+ void print_do_while_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Do_While_Statement *whi);+ void print_for_statement_tree(struct Compile_Data_Print *compile_data,struct AST_For_Statement *fo);+ void print_return_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Return_Statement *return_expression);+ void print_goto_statement_tree(struct Compile_Data_Print *compile_data,struct AST_Goto_Statement *got);+ void print_type(struct Compile_Data_Print *compile_data,struct Type *type,char print_struct_union);+ void print_denoted(struct Compile_Data_Print *compile_data,struct Denoted *denoted);+ void print_list_of_denoted(struct Compile_Data_Print *compile_data,struct Queue *denoted);+ void print_enumeration(struct Compile_Data_Print *compile_data,struct Enum *enumeration);+ void print_struct_union(struct Compile_Data_Print *compile_data,struct Struct_Union *struct_union);+ void print_object(struct Compile_Data_Print *compile_data,struct Object *object);+ void print_normal_object(struct Compile_Data_Print *compile_data,struct Object *object);+ void print_bitfield_object(struct Compile_Data_Print *compile_data,struct Object_Bitfield *object);+ void print_translation_unit_tree(struct Compile_Data_Print *compile_data,struct AST_Translation_Unit *unit);+ void print_ast(struct Compile_Data_Print *compile_data,struct AST* tree);+ void print_program_tokens(struct Compile_Data_Print *compile_data,struct Program *program);+ void print_program_ast(struct Compile_Data_Print *compile_data,struct Program *program);void print_keyword_enum(FILE *out,enum KEYWORDS kw);- void print_function_definition(FILE *out,struct AST_Function_Definition *function);+ void print_function_definition(struct Compile_Data_Print *compile_data,struct AST_Function_Definition *function);void print_errors(FILE *out,struct Queue *errors);- void print_function_args(FILE *out,struct Type_Function *func);- void print_type_qualifier(FILE *out,struct Type *type);- void print_type_constraint_enum(FILE *out,enum Type_Specifier specifier);- void print_type_sign_enum(FILE *out,enum Type_Signedness sign);- void print_type_constraint(FILE *out,struct Type *type);- void print_type_sign(FILE *out,struct Type *type);- void print_expression_value(FILE *out,struct Expression_Value *value);- void print_expression_value_type(FILE *out,struct Expression_Value *value);+ void print_function_args(struct Compile_Data_Print *compile_data,struct Type_Function *func);+ void print_type_qualifier(struct Compile_Data_Print *compile_data,struct Type *type);+ void print_type_constraint_enum(struct Compile_Data_Print *compile_data,enum Type_Specifier specifier);+ void print_type_sign_enum(struct Compile_Data_Print *compile_data,enum Type_Signedness sign);+ void print_type_constraint(struct Compile_Data_Print *compile_data,struct Type *type);+ void print_type_sign(struct Compile_Data_Print *compile_data,struct Type *type);+ void print_expression_value(struct Compile_Data_Print *compile_data,struct Expression_Value *value);+ void print_expression_value_type(struct Compile_Data_Print *compile_data,struct Expression_Value *value);#endifF diff --git a/src/backend/text/print/print.hh b/src/backend/text/print/print.hh new file mode 100644 --- /dev/null +++ b/src/backend/text/print/print.hh+ #ifndef WONKY_PRINT_HH+ #define WONKY_PRINT_HH WONKY_PRINT_HH+++ struct Compile_Data_Print;+ struct Compiled_Object_Print;++ #endifF diff --git a/src/debug/wobler/wobler.c b/src/debug/wobler/wobler.c --- a/src/debug/wobler/wobler.c +++ b/src/debug/wobler/wobler.c}void dump_program(FILE *where,struct Program *program){+ struct Compiled_Object_Print *object;+fprintf(where,"\n\n---------------- PROGRAM DUMP BEGIN ----------------\n\n");dump_program_messages(where,program);fprintf(where,"\n\n----- AST DUMP BEGIN -----\n\n");- print_program_ast(where,program);++ object=compile_program_for_print(program);+ save_compiled_object_for_print(object,where);fprintf(where,"\n\n----- AST DUMP END -----\n\n");fprintf(where,"\n\n---------------- PROGRAM DUMP END ----------------\n\n");F diff --git a/src/debug/wobler/wobler_tests.h b/src/debug/wobler/wobler_tests.h --- a/src/debug/wobler/wobler_tests.h +++ b/src/debug/wobler/wobler_tests.h.how_much_time_should_execution_take=0.01,},{+ .filenames={"test_linkage2.c"},+ .test_function=should_compile,+ .how_much_time_should_execution_take=0.01,+ },+ {.filenames={"test_linkage_error.c"},.test_function=should_not_compile,.how_much_time_should_execution_take=0.01,F diff --git a/src/wonky.c b/src/wonky.c --- a/src/wonky.c +++ b/src/wonky.creturn 1;}else if(command_arguments->print_ast && !command_arguments->is_quiet){- print_program_ast(stdout,program);+ struct Compiled_Object_Print *object;+ object=compile_program_for_print(program);+ save_compiled_object_for_print(object,stdout);}else if(command_arguments->transpile_to_js){//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 <map.h>#include <stack.h>+ #include <compile.h>#include <print.h>F diff --git a/tests/test_declaration_error.c b/tests/test_declaration_error.c --- a/tests/test_declaration_error.c +++ b/tests/test_declaration_error.c- int main;-int main(){F diff --git a/tests/test_linkage2.c b/tests/test_linkage2.c new file mode 100644 --- /dev/null +++ b/tests/test_linkage2.c+ int main();++ int main()+ {+ return 0;+ }