diff options
author | Galin Simeonov <gts@volconst.com> | 2021-06-04 16:42:52 +0300 |
---|---|---|
committer | Galin Simeonov <gts@volconst.com> | 2021-07-15 18:04:59 +0300 |
commit | a26684a417729699e95b335a3d00798237ffba9b (patch) | |
tree | 6cd73bc90fbe5fd435b8cc721455d0a70420a4ac /src/backend/backend.c | |
parent | b845e4754be86d2216733d9bea75cb301f38739d (diff) | |
download | MEGATRON-a26684a417729699e95b335a3d00798237ffba9b.tar.gz |
added the if statement
Diffstat (limited to 'src/backend/backend.c')
-rw-r--r-- | src/backend/backend.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/backend/backend.c b/src/backend/backend.c index 512d247..ff9d0bf 100644 --- a/src/backend/backend.c +++ b/src/backend/backend.c @@ -20,10 +20,7 @@ struct State_And_Transitions** extract_transition_table(struct AST_States *state /*traverse transitions and push them into the queue of their coresponding state*/ for(i=0;i<transitions->size;++i) { - hold_state=extract_state(transitions->transitions[i]->from,states); - - assert(hold_state!=NULL); - + hold_state=transitions->transitions[i]->from; Queue_Push(qs+hold_state->number,transitions->transitions[i]); } @@ -101,7 +98,7 @@ void anotate_machine(struct AST_Machine *machine,struct AST_Translation_Unit *un size_t i; for(i=0;i<machine->transitions->size;++i) { - machine->transitions->transitions[i]->from=anotate_expression(machine->transitions->transitions[i]->from,unit,machine,translation_data); + machine->transitions->transitions[i]->statement=anotate_statement(machine->transitions->transitions[i]->statement,unit,machine,translation_data); } if(has_new_errors(translation_data)) { @@ -109,6 +106,17 @@ void anotate_machine(struct AST_Machine *machine,struct AST_Translation_Unit *un delete_ast_machine(machine); } } +struct AST* anotate_statement(struct AST *statement,struct AST_Translation_Unit *unit,struct AST_Machine *current_machine,struct Translation_Data *translation_data) +{ + if(statement==NULL)return NULL; + if(statement->type==AST_TYPE_IF) + { + ((struct AST_If_Statement*)statement)->condition=anotate_expression(((struct AST_If_Statement*)statement)->condition,unit,current_machine,translation_data); + }else + { + return statement; + } +} struct AST* anotate_expression(struct AST *expression,struct AST_Translation_Unit *unit,struct AST_Machine *current_machine,struct Translation_Data *translation_data) { struct AST_Machine *hold_machine; @@ -131,8 +139,17 @@ struct AST* anotate_expression(struct AST *expression,struct AST_Translation_Uni }else { hold_left=(struct AST*)ast_check_state((struct AST_Unchecked_State*)hold_right,hold_machine->states,translation_data); - ((struct AST_State*)hold_left)->parent=hold_machine; - return hold_left; + if(hold_left) + { + ((struct AST_State*)hold_left)->parent=hold_machine; + delete_ast(hold_right); + return hold_left; + }else + { + push_error_with_token("state id from foreign machine is undefined",((struct AST_Unchecked_State*)hold_right)->name,translation_data); + delete_ast(hold_right); + return NULL; + } } }else { |