diff options
Diffstat (limited to 'src/backend/targets/C/ast_to_c.c')
-rw-r--r-- | src/backend/targets/C/ast_to_c.c | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/src/backend/targets/C/ast_to_c.c b/src/backend/targets/C/ast_to_c.c index 3ce923d..9c8b38d 100644 --- a/src/backend/targets/C/ast_to_c.c +++ b/src/backend/targets/C/ast_to_c.c @@ -189,7 +189,8 @@ void ast_transitions_of_state_to_c(FILE *out,struct AST_Machine *machine,struct ast_event_to_c_enum(out,machine,vector->transitions[i]->event); fprintf(out,":\n"); - ast_pipeline_to_c(out,3,vector->transitions[i]->pipeline); + //ast_pipeline_to_c(out,3,vector->transitions[i]->pipeline); + ast_statement_to_c(out,3,vector->transitions[i]->statement); fprintf(out,"\t\t\tmachine_states["); ast_token_to_c(out,machine->id); fprintf(out,"]="); @@ -370,4 +371,77 @@ void ast_to_c_print_comment(FILE *out,char *comment) fprintf(out,"%s\n",comment); fprintf(out,"*/\n"); } +void ast_statement_to_c(FILE *out,size_t indentation,struct AST *statement) +{ + if(statement==NULL)return; + if(statement->type==AST_TYPE_PIPELINE) + ast_pipeline_to_c(out,indentation,(struct AST_Pipeline*)statement); + else if(statement->type==AST_TYPE_IF) + ast_if_to_c(out,indentation,(struct AST_If_Statement*)statement); + else + assert(0); + +} +void ast_if_to_c(FILE *out,size_t indentation,struct AST_If_Statement *statement) +{ + ast_to_c_print_tabs(out,indentation); + fprintf(out,"if"); + ast_expression_to_c(out,statement->condition); + fprintf(out,"\n"); + + ast_to_c_print_tabs(out,indentation); + fprintf(out,"{\n"); + + ast_statement_to_c(out,indentation+1,statement->body); + + ast_to_c_print_tabs(out,indentation); + fprintf(out,"}"); + if(statement->else_statement) + { + fprintf(out,"else{\n"); + + ast_statement_to_c(out,indentation+1,statement->else_statement); + + ast_to_c_print_tabs(out,indentation); + fprintf(out,"}"); + } + fprintf(out,"\n"); +} +void ast_expression_to_c(FILE *out,struct AST *expression) +{ + fprintf(out,"("); + switch(expression->type) + { + case AST_TYPE_OP_OR: + ast_expression_to_c(out,AS_BIN_EXPR_PTR(expression)->left); + fprintf(out,"||"); + ast_expression_to_c(out,AS_BIN_EXPR_PTR(expression)->right); + break; + case AST_TYPE_OP_NOT: + fprintf(out,"!"); + ast_expression_to_c(out,AS_UN_EXPR_PTR(expression)->operand); + break; + case AST_TYPE_OP_AND: + ast_expression_to_c(out,AS_BIN_EXPR_PTR(expression)->left); + fprintf(out,"&&"); + ast_expression_to_c(out,AS_BIN_EXPR_PTR(expression)->right); + break; + case AST_TYPE_STATE: + ast_expression_state_to_c(out,(struct AST_State*)expression); + break; + case AST_TYPE_OP_SELECTOR: + assert(!"selector in final product!\n"); + default: + assert(0); + } + fprintf(out,")"); +} +void ast_expression_state_to_c(FILE *out,struct AST_State *state) +{ + fprintf(out,"machine_states["); + ast_token_to_c(out,state->parent->id); + fprintf(out,"]=="); + ast_state_to_c_function_name(out,state->parent,state); + +} #endif |