49 |
49 |
50 private: |
50 private: |
51 generate_c_il_c *generate_c_il; |
51 generate_c_il_c *generate_c_il; |
52 generate_c_st_c *generate_c_st; |
52 generate_c_st_c *generate_c_st; |
53 generate_c_SFC_IL_ST_c *generate_c_code; |
53 generate_c_SFC_IL_ST_c *generate_c_code; |
|
54 search_var_instance_decl_c *search_var_instance_decl; |
54 |
55 |
55 int transition_number; |
56 int transition_number; |
56 std::list<TRANSITION> transition_list; |
57 std::list<TRANSITION> transition_list; |
57 |
58 |
58 symbol_c *current_step; |
59 symbol_c *current_step; |
64 generate_c_sfc_elements_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
65 generate_c_sfc_elements_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
65 : generate_c_base_c(s4o_ptr) { |
66 : generate_c_base_c(s4o_ptr) { |
66 generate_c_il = new generate_c_il_c(s4o_ptr, name, scope, variable_prefix); |
67 generate_c_il = new generate_c_il_c(s4o_ptr, name, scope, variable_prefix); |
67 generate_c_st = new generate_c_st_c(s4o_ptr, name, scope, variable_prefix); |
68 generate_c_st = new generate_c_st_c(s4o_ptr, name, scope, variable_prefix); |
68 generate_c_code = new generate_c_SFC_IL_ST_c(s4o_ptr, name, scope, variable_prefix); |
69 generate_c_code = new generate_c_SFC_IL_ST_c(s4o_ptr, name, scope, variable_prefix); |
|
70 search_var_instance_decl = new search_var_instance_decl_c(scope); |
69 this->set_variable_prefix(variable_prefix); |
71 this->set_variable_prefix(variable_prefix); |
70 } |
72 } |
71 |
73 |
72 ~generate_c_sfc_elements_c(void) { |
74 ~generate_c_sfc_elements_c(void) { |
73 transition_list.clear(); |
75 transition_list.clear(); |
74 delete generate_c_il; |
76 delete generate_c_il; |
75 delete generate_c_st; |
77 delete generate_c_st; |
76 delete generate_c_code; |
78 delete generate_c_code; |
77 } |
79 delete search_var_instance_decl; |
|
80 } |
|
81 |
|
82 |
|
83 bool is_variable(symbol_c *symbol) { |
|
84 /* we try to find the variable instance declaration, to determine if symbol is variable... */ |
|
85 symbol_c *var_decl = search_var_instance_decl->get_decl(symbol); |
|
86 |
|
87 return var_decl != NULL; |
|
88 } |
78 |
89 |
79 void reset_transition_number(void) {transition_number = 0;} |
90 void reset_transition_number(void) {transition_number = 0;} |
80 |
91 |
81 void generate(symbol_c *symbol, sfcgeneration_t generation_type) { |
92 void generate(symbol_c *symbol, sfcgeneration_t generation_type) { |
82 wanted_sfcgeneration = generation_type; |
93 wanted_sfcgeneration = generation_type; |
421 |
432 |
422 void *visit(steps_c *symbol) { |
433 void *visit(steps_c *symbol) { |
423 if (symbol->step_name != NULL) { |
434 if (symbol->step_name != NULL) { |
424 switch (wanted_sfcgeneration) { |
435 switch (wanted_sfcgeneration) { |
425 case transitiontest_sg: |
436 case transitiontest_sg: |
426 s4o.print(GET_VAR); |
437 s4o.print(GET_VAR); |
427 s4o.print("("); |
438 s4o.print("("); |
428 print_step_argument(symbol->step_name, "state"); |
439 print_step_argument(symbol->step_name, "state"); |
429 s4o.print(")"); |
440 s4o.print(")"); |
430 break; |
441 break; |
431 case stepset_sg: |
442 case stepset_sg: |
432 print_set_step(symbol->step_name); |
443 print_set_step(symbol->step_name); |
446 |
457 |
447 void *visit(step_name_list_c *symbol) { |
458 void *visit(step_name_list_c *symbol) { |
448 switch (wanted_sfcgeneration) { |
459 switch (wanted_sfcgeneration) { |
449 case transitiontest_sg: |
460 case transitiontest_sg: |
450 for(int i = 0; i < symbol->n; i++) { |
461 for(int i = 0; i < symbol->n; i++) { |
451 s4o.print(GET_VAR); |
462 s4o.print(GET_VAR); |
452 s4o.print("("); |
463 s4o.print("("); |
453 print_step_argument(symbol->elements[i], "state"); |
464 print_step_argument(symbol->elements[i], "state"); |
454 s4o.print(")"); |
465 s4o.print(")"); |
455 if (i < symbol->n - 1) { |
466 if (i < symbol->n - 1) { |
456 s4o.print(" && "); |
467 s4o.print(" && "); |
457 } |
468 } |
522 if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "S") == 0 || |
533 if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "S") == 0 || |
523 strcmp(qualifier, "R") == 0) { |
534 strcmp(qualifier, "R") == 0) { |
524 s4o.print("active"); |
535 s4o.print("active"); |
525 } |
536 } |
526 else if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || |
537 else if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || |
527 strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0 || |
538 strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0 || |
528 strcmp(qualifier, "P0") == 0) { |
539 strcmp(qualifier, "P0") == 0) { |
529 s4o.print("activated"); |
540 s4o.print("activated"); |
530 } |
541 } |
531 else if (strcmp(qualifier, "P1") == 0) { |
542 else if (strcmp(qualifier, "P1") == 0) { |
532 s4o.print("desactivated"); |
543 s4o.print("desactivated"); |
533 } |
544 } |
547 s4o.indent_right(); |
558 s4o.indent_right(); |
548 s4o.print(s4o.indent_spaces); |
559 s4o.print(s4o.indent_spaces); |
549 if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 || |
560 if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 || |
550 strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0 || |
561 strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0 || |
551 strcmp(qualifier, "P0") == 0 || strcmp(qualifier, "P1") == 0) { |
562 strcmp(qualifier, "P0") == 0 || strcmp(qualifier, "P1") == 0) { |
552 s4o.print(SET_VAR); |
563 |
553 s4o.print("("); |
564 if (is_variable(current_action)) { |
554 print_action_argument(current_action, "state", true); |
565 unsigned int vartype = search_var_instance_decl->get_vartype(current_action); |
555 s4o.print(",1);\n"); |
566 |
|
567 if (vartype == search_var_instance_decl_c::external_vt) |
|
568 s4o.print(SET_EXTERNAL); |
|
569 else if (vartype == search_var_instance_decl_c::located_vt) |
|
570 s4o.print(SET_LOCATED); |
|
571 else |
|
572 s4o.print(SET_VAR); |
|
573 s4o.print("("); |
|
574 print_variable_prefix(); |
|
575 s4o.print(","); |
|
576 current_action->accept(*this); |
|
577 s4o.print(",1);\n"); |
|
578 s4o.indent_left(); |
|
579 s4o.print("}\n"); |
|
580 s4o.print(s4o.indent_spaces + "else if (active) {\n"); |
|
581 s4o.indent_right(); |
|
582 if (vartype == search_var_instance_decl_c::external_vt) |
|
583 s4o.print(SET_EXTERNAL); |
|
584 else if (vartype == search_var_instance_decl_c::located_vt) |
|
585 s4o.print(SET_LOCATED); |
|
586 else |
|
587 s4o.print(SET_VAR); |
|
588 s4o.print("("); |
|
589 print_variable_prefix(); |
|
590 s4o.print(","); |
|
591 current_action->accept(*this); |
|
592 s4o.print(",0);\n"); |
|
593 } |
|
594 |
|
595 else { |
|
596 s4o.print(SET_VAR); |
|
597 s4o.print("("); |
|
598 print_action_argument(current_action, "state", true); |
|
599 s4o.print(",1);\n"); |
|
600 } |
556 } |
601 } |
557 if (strcmp(qualifier, "S") == 0 || strcmp(qualifier, "SL") == 0) { |
602 if (strcmp(qualifier, "S") == 0 || strcmp(qualifier, "SL") == 0) { |
558 print_action_argument(current_action, "set"); |
603 print_action_argument(current_action, "set"); |
559 s4o.print(" = 1;\n"); |
604 s4o.print(" = 1;\n"); |
560 } |
605 } |
863 /* generate action execution */ |
908 /* generate action execution */ |
864 s4o.print(s4o.indent_spaces + "// Actions execution\n"); |
909 s4o.print(s4o.indent_spaces + "// Actions execution\n"); |
865 { |
910 { |
866 std::list<VARIABLE>::iterator pt; |
911 std::list<VARIABLE>::iterator pt; |
867 for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { |
912 for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { |
868 symbol_c *var_decl = search_var_instance_decl->get_decl(pt->symbol); |
913 |
869 if (var_decl != NULL) { |
914 if (is_variable(pt->symbol)) { |
870 unsigned int vartype = search_var_instance_decl->get_vartype(pt->symbol); |
915 unsigned int vartype = search_var_instance_decl->get_vartype(pt->symbol); |
871 |
916 |
872 s4o.print(s4o.indent_spaces); |
917 s4o.print(s4o.indent_spaces + "if ("); |
873 if (vartype == search_var_instance_decl_c::external_vt) |
|
874 s4o.print(SET_EXTERNAL); |
|
875 else if (vartype == search_var_instance_decl_c::located_vt) |
|
876 s4o.print(SET_LOCATED); |
|
877 else |
|
878 s4o.print(SET_VAR); |
|
879 s4o.print("("); |
|
880 print_variable_prefix(); |
|
881 s4o.print(","); |
|
882 pt->symbol->accept(*this); |
|
883 s4o.print(","); |
|
884 s4o.print(GET_VAR); |
|
885 s4o.print("("); |
|
886 print_variable_prefix(); |
918 print_variable_prefix(); |
887 s4o.print("__action_list["); |
919 s4o.print("__action_list["); |
888 s4o.print(SFC_STEP_ACTION_PREFIX); |
920 s4o.print(SFC_STEP_ACTION_PREFIX); |
889 pt->symbol->accept(*this); |
921 pt->symbol->accept(*this); |
890 s4o.print("].state));\n"); |
922 s4o.print("].reset) {\n"); |
|
923 s4o.indent_right(); |
|
924 s4o.print(s4o.indent_spaces); |
|
925 if (vartype == search_var_instance_decl_c::external_vt) |
|
926 s4o.print(SET_EXTERNAL); |
|
927 else if (vartype == search_var_instance_decl_c::located_vt) |
|
928 s4o.print(SET_LOCATED); |
|
929 else |
|
930 s4o.print(SET_VAR); |
|
931 s4o.print("("); |
|
932 print_variable_prefix(); |
|
933 s4o.print(","); |
|
934 pt->symbol->accept(*this); |
|
935 s4o.print(",0);\n"); |
|
936 s4o.indent_left(); |
|
937 s4o.print(s4o.indent_spaces + "}\n"); |
|
938 s4o.print(s4o.indent_spaces + "else if ("); |
|
939 print_variable_prefix(); |
|
940 s4o.print("__action_list["); |
|
941 s4o.print(SFC_STEP_ACTION_PREFIX); |
|
942 pt->symbol->accept(*this); |
|
943 s4o.print("].set) {\n"); |
|
944 s4o.indent_right(); |
|
945 s4o.print(s4o.indent_spaces); |
|
946 if (vartype == search_var_instance_decl_c::external_vt) |
|
947 s4o.print(SET_EXTERNAL); |
|
948 else if (vartype == search_var_instance_decl_c::located_vt) |
|
949 s4o.print(SET_LOCATED); |
|
950 else |
|
951 s4o.print(SET_VAR); |
|
952 s4o.print("("); |
|
953 print_variable_prefix(); |
|
954 s4o.print(","); |
|
955 pt->symbol->accept(*this); |
|
956 s4o.print(",1);\n"); |
|
957 s4o.indent_left(); |
|
958 s4o.print(s4o.indent_spaces + "}\n"); |
891 } |
959 } |
892 } |
960 } |
893 } |
961 } |
894 for(i = 0; i < symbol->n; i++) { |
962 for(i = 0; i < symbol->n; i++) { |
895 generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::actionbody_sg); |
963 generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::actionbody_sg); |
908 symbol->action_association_list->accept(*this); |
976 symbol->action_association_list->accept(*this); |
909 return NULL; |
977 return NULL; |
910 } |
978 } |
911 |
979 |
912 void *visit(action_association_c *symbol) { |
980 void *visit(action_association_c *symbol) { |
913 symbol_c *var_decl = search_var_instance_decl->get_decl(symbol->action_name); |
981 if (is_variable(symbol->action_name)) { |
914 |
|
915 if (var_decl != NULL) { |
|
916 std::list<VARIABLE>::iterator pt; |
982 std::list<VARIABLE>::iterator pt; |
917 for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { |
983 for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { |
918 if (!compare_identifiers(pt->symbol, symbol->action_name)) |
984 if (!compare_identifiers(pt->symbol, symbol->action_name)) |
919 return NULL; |
985 return NULL; |
920 } |
986 } |