235 |
242 |
236 search_varfb_instance_type_c *search_varfb_instance_type; |
243 search_varfb_instance_type_c *search_varfb_instance_type; |
237 |
244 |
238 search_base_type_c search_base_type; |
245 search_base_type_c search_base_type; |
239 |
246 |
240 bool current_param_is_pointer; |
247 int fcall_number; |
|
248 symbol_c *fbname; |
|
249 |
|
250 variablegeneration_t wanted_variablegeneration; |
241 |
251 |
242 public: |
252 public: |
243 generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
253 generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
244 : generate_c_typedecl_c(s4o_ptr), |
254 : generate_c_typedecl_c(s4o_ptr), |
245 default_variable_name(IL_DEFVAR, NULL), |
255 default_variable_name(IL_DEFVAR, NULL), |
246 default_variable_back_name(IL_DEFVAR_BACK, NULL) |
256 default_variable_back_name(IL_DEFVAR_BACK, NULL) |
247 { |
257 { |
248 search_expression_type = new search_expression_type_c(scope); |
258 search_expression_type = new search_expression_type_c(scope); |
249 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
259 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
250 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
260 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
251 current_operand = NULL; |
261 current_operand = NULL; |
252 current_operand_type = NULL; |
262 current_operand_type = NULL; |
253 il_default_variable_init_value = NULL; |
263 il_default_variable_init_value = NULL; |
254 current_param_is_pointer = false; |
264 fcall_number = 0; |
|
265 fbname = name; |
|
266 wanted_variablegeneration = expression_vg; |
255 this->set_variable_prefix(variable_prefix); |
267 this->set_variable_prefix(variable_prefix); |
256 } |
268 } |
257 |
269 |
258 virtual ~generate_c_il_c(void) { |
270 virtual ~generate_c_il_c(void) { |
259 delete search_fb_instance_decl; |
271 delete search_fb_instance_decl; |
450 |
467 |
451 |
468 |
452 /*********************/ |
469 /*********************/ |
453 /* B 1.4 - Variables */ |
470 /* B 1.4 - Variables */ |
454 /*********************/ |
471 /*********************/ |
|
472 /* B 1.4 - Variables */ |
|
473 /*********************/ |
455 void *visit(symbolic_variable_c *symbol) { |
474 void *visit(symbolic_variable_c *symbol) { |
456 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
475 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
457 if (!current_param_is_pointer && (vartype == search_var_instance_decl_c::external_vt || vartype == search_var_instance_decl_c::located_vt)) { |
476 if (this->is_variable_prefix_null()) { |
458 s4o.print("*("); |
477 if (wanted_variablegeneration == fparam_output_vg) { |
459 generate_c_base_c::visit(symbol); |
478 if (vartype == search_var_instance_decl_c::external_vt) { |
460 s4o.print(")"); |
479 s4o.print(GET_EXTERNAL); |
461 } |
480 s4o.print("("); |
462 else if (current_param_is_pointer && vartype != search_var_instance_decl_c::external_vt && vartype != search_var_instance_decl_c::located_vt) { |
481 symbol->var_name->accept(*this); |
463 s4o.print("&("); |
482 } |
464 generate_c_base_c::visit(symbol); |
483 else { |
465 s4o.print(")"); |
484 s4o.print("&("); |
|
485 generate_c_base_c::visit(symbol); |
|
486 } |
|
487 s4o.print(")"); |
|
488 } |
|
489 else { |
|
490 if (vartype == search_var_instance_decl_c::external_vt) { |
|
491 s4o.print(GET_EXTERNAL); |
|
492 s4o.print("("); |
|
493 symbol->var_name->accept(*this); |
|
494 s4o.print(")"); |
|
495 } |
|
496 else |
|
497 generate_c_base_c::visit(symbol); |
|
498 } |
466 } |
499 } |
467 else { |
500 else { |
468 generate_c_base_c::visit(symbol); |
501 switch (wanted_variablegeneration) { |
|
502 case expression_vg: |
|
503 if (vartype == search_var_instance_decl_c::external_vt) { |
|
504 s4o.print(GET_EXTERNAL); |
|
505 s4o.print("("); |
|
506 symbol->var_name->accept(*this); |
|
507 } |
|
508 else { |
|
509 if (vartype == search_var_instance_decl_c::located_vt) |
|
510 s4o.print(GET_LOCATED); |
|
511 else |
|
512 s4o.print(GET_VAR); |
|
513 s4o.print("("); |
|
514 generate_c_base_c::visit(symbol); |
|
515 } |
|
516 s4o.print(")"); |
|
517 break; |
|
518 case fparam_output_vg: |
|
519 if (vartype == search_var_instance_decl_c::external_vt) { |
|
520 s4o.print(GET_EXTERNAL_BY_REF); |
|
521 s4o.print("("); |
|
522 symbol->var_name->accept(*this); |
|
523 } |
|
524 else { |
|
525 if (vartype == search_var_instance_decl_c::located_vt) |
|
526 s4o.print(GET_LOCATED_BY_REF); |
|
527 else |
|
528 s4o.print(GET_VAR_BY_REF); |
|
529 s4o.print("("); |
|
530 generate_c_base_c::visit(symbol); |
|
531 } |
|
532 s4o.print(")"); |
|
533 break; |
|
534 default: |
|
535 if (vartype == search_var_instance_decl_c::external_vt) |
|
536 symbol->var_name->accept(*this); |
|
537 else |
|
538 generate_c_base_c::visit(symbol); |
|
539 break; |
|
540 } |
469 } |
541 } |
470 return NULL; |
542 return NULL; |
471 } |
543 } |
472 |
544 |
473 /********************************************/ |
545 /********************************************/ |
476 // direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
548 // direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
477 void *visit(direct_variable_c *symbol) { |
549 void *visit(direct_variable_c *symbol) { |
478 TRACE("direct_variable_c"); |
550 TRACE("direct_variable_c"); |
479 /* Do not use print_token() as it will change everything into uppercase */ |
551 /* Do not use print_token() as it will change everything into uppercase */ |
480 if (strlen(symbol->value) == 0) ERROR; |
552 if (strlen(symbol->value) == 0) ERROR; |
481 if (!current_param_is_pointer) { |
553 if (this->is_variable_prefix_null()) { |
482 s4o.print("*("); |
554 if (wanted_variablegeneration != fparam_output_vg) |
|
555 s4o.print("*("); |
|
556 } |
|
557 else { |
|
558 switch (wanted_variablegeneration) { |
|
559 case expression_vg: |
|
560 s4o.print(GET_LOCATED); |
|
561 s4o.print("("); |
|
562 break; |
|
563 case fparam_output_vg: |
|
564 s4o.print(GET_LOCATED_BY_REF); |
|
565 s4o.print("("); |
|
566 break; |
|
567 default: |
|
568 break; |
|
569 } |
483 } |
570 } |
484 this->print_variable_prefix(); |
571 this->print_variable_prefix(); |
485 s4o.printlocation(symbol->value + 1); |
572 s4o.printlocation(symbol->value + 1); |
486 if (!current_param_is_pointer) { |
573 if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) || |
|
574 wanted_variablegeneration != assignment_vg) |
487 s4o.print(")"); |
575 s4o.print(")"); |
488 } |
|
489 return NULL; |
576 return NULL; |
490 } |
577 } |
491 |
578 |
492 /****************************************/ |
579 /****************************************/ |
493 /* B.2 - Language IL (Instruction List) */ |
580 /* B.2 - Language IL (Instruction List) */ |
610 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
696 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
611 if (NULL == return_data_type) ERROR; |
697 if (NULL == return_data_type) ERROR; |
612 |
698 |
613 function_call_param_iterator_c function_call_param_iterator(symbol); |
699 function_call_param_iterator_c function_call_param_iterator(symbol); |
614 |
700 |
|
701 identifier_c en_param_name("EN"); |
615 /* Add the value from EN param */ |
702 /* Add the value from EN param */ |
616 ADD_PARAM_LIST((symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
703 ADD_PARAM_LIST(&en_param_name, |
|
704 (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
617 (symbol_c*)(new bool_type_name_c()), |
705 (symbol_c*)(new bool_type_name_c()), |
618 function_param_iterator_c::direction_in) |
706 function_param_iterator_c::direction_in) |
619 |
707 |
|
708 identifier_c eno_param_name("ENO"); |
620 /* Add the value from ENO param */ |
709 /* Add the value from ENO param */ |
621 ADD_PARAM_LIST(NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
710 ADD_PARAM_LIST(&eno_param_name, NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
622 |
711 |
623 int nb_param = 1; |
712 int nb_param = 1; |
624 if (symbol->il_operand_list != NULL) |
713 if (symbol->il_operand_list != NULL) |
625 nb_param += ((list_c *)symbol->il_operand_list)->n; |
714 nb_param += ((list_c *)symbol->il_operand_list)->n; |
626 |
715 |
675 /* No value given for parameter, so we must use the default... */ |
764 /* No value given for parameter, so we must use the default... */ |
676 /* First check whether default value specified in function declaration...*/ |
765 /* First check whether default value specified in function declaration...*/ |
677 param_value = fp_iterator.default_value(); |
766 param_value = fp_iterator.default_value(); |
678 } |
767 } |
679 |
768 |
680 ADD_PARAM_LIST(param_value, param_type, fp_iterator.param_direction()) |
769 ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
681 } /* for(...) */ |
770 } /* for(...) */ |
682 } |
771 } |
683 |
772 |
|
773 bool has_output_params = false; |
|
774 |
|
775 if (!this->is_variable_prefix_null()) { |
|
776 PARAM_LIST_ITERATOR() { |
|
777 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
778 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
779 PARAM_VALUE != NULL) { |
|
780 if (!has_output_params) { |
|
781 has_output_params = true; |
|
782 } |
|
783 } |
|
784 } |
|
785 } |
|
786 |
684 default_variable_name.current_type = return_data_type; |
787 default_variable_name.current_type = return_data_type; |
685 this->default_variable_name.accept(*this); |
788 this->default_variable_name.accept(*this); |
686 default_variable_name.current_type = param_data_type; |
789 default_variable_name.current_type = param_data_type; |
687 s4o.print(" = "); |
790 s4o.print(" = "); |
688 |
791 |
689 if (function_type_prefix != NULL) { |
792 if (function_type_prefix != NULL) { |
690 s4o.print("("); |
793 s4o.print("("); |
691 function_type_prefix->accept(*this); |
794 function_type_prefix->accept(*this); |
692 s4o.print(")"); |
795 s4o.print(")"); |
693 } |
796 } |
694 if (function_name != NULL) |
797 if (has_output_params) { |
|
798 fcall_number++; |
|
799 s4o.print("__"); |
|
800 fbname->accept(*this); |
|
801 s4o.print("_"); |
695 function_name->accept(*this); |
802 function_name->accept(*this); |
696 if (function_type_suffix != NULL) |
803 s4o.print_integer(fcall_number); |
697 function_type_suffix->accept(*this); |
804 } |
|
805 else { |
|
806 if (function_name != NULL) |
|
807 function_name->accept(*this); |
|
808 if (function_type_suffix != NULL) |
|
809 function_type_suffix->accept(*this); |
|
810 } |
698 s4o.print("("); |
811 s4o.print("("); |
699 s4o.indent_right(); |
812 s4o.indent_right(); |
700 |
813 |
701 std::list<FUNCTION_PARAM>::iterator pt; |
814 int nb_param = 0; |
702 for(pt = param_list.begin(); pt != param_list.end(); pt++) { |
815 PARAM_LIST_ITERATOR() { |
703 if (pt != param_list.begin()) |
816 symbol_c *param_value = PARAM_VALUE; |
704 s4o.print(",\n"+s4o.indent_spaces); |
817 symbol_c *param_type = PARAM_TYPE; |
705 symbol_c *param_value = pt->param_value; |
|
706 symbol_c *param_type = pt->param_type; |
|
707 |
818 |
708 switch (pt->param_direction) { |
819 switch (PARAM_DIRECTION) { |
709 case function_param_iterator_c::direction_in: |
820 case function_param_iterator_c::direction_in: |
|
821 if (nb_param > 0) |
|
822 s4o.print(",\n"+s4o.indent_spaces); |
710 if (param_value == NULL) { |
823 if (param_value == NULL) { |
711 /* If not, get the default value of this variable's type */ |
824 /* If not, get the default value of this variable's type */ |
712 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
825 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
713 } |
826 } |
714 if (param_value == NULL) ERROR; |
827 if (param_value == NULL) ERROR; |
|
828 s4o.print("("); |
715 if (search_expression_type->is_literal_integer_type(param_type) || |
829 if (search_expression_type->is_literal_integer_type(param_type) || |
716 search_expression_type->is_literal_real_type(param_type)) { |
830 search_expression_type->is_literal_real_type(param_type)) { |
717 if (function_type_suffix == NULL) ERROR; |
831 if (function_type_suffix == NULL) ERROR; |
718 function_type_suffix->accept(*this); |
832 function_type_suffix->accept(*this); |
719 } |
833 } |
720 else |
834 else |
721 param_type->accept(*this); |
835 param_type->accept(*this); |
722 if (search_base_type.type_is_subrange(param_type)) { |
836 s4o.print(")"); |
723 s4o.print("__CHECK_"); |
837 print_check_function(param_type, param_value); |
724 param_type->accept(*this); |
838 nb_param++; |
725 s4o.print("("); |
|
726 } |
|
727 param_value->accept(*this); |
|
728 if (search_base_type.type_is_subrange(param_type)) |
|
729 s4o.print(")"); |
|
730 break; |
839 break; |
731 case function_param_iterator_c::direction_out: |
840 case function_param_iterator_c::direction_out: |
732 case function_param_iterator_c::direction_inout: |
841 case function_param_iterator_c::direction_inout: |
733 current_param_is_pointer = true; |
842 if (!has_output_params) { |
734 if (param_value == NULL) { |
843 if (nb_param > 0) |
735 s4o.print("NULL"); |
844 s4o.print(",\n"+s4o.indent_spaces); |
736 } else { |
845 if (param_value == NULL) { |
737 param_value->accept(*this); |
846 s4o.print("NULL"); |
738 } |
847 } else { |
739 current_param_is_pointer = false; |
848 wanted_variablegeneration = fparam_output_vg; |
|
849 param_value->accept(*this); |
|
850 wanted_variablegeneration = expression_vg; |
|
851 } |
|
852 nb_param++; |
|
853 } |
740 break; |
854 break; |
741 case function_param_iterator_c::direction_extref: |
855 case function_param_iterator_c::direction_extref: |
742 /* TODO! */ |
856 /* TODO! */ |
743 ERROR; |
857 ERROR; |
744 break; |
858 break; |
745 } /* switch */ |
859 } /* switch */ |
746 } |
860 } |
|
861 if (has_output_params) { |
|
862 if (nb_param > 0) |
|
863 s4o.print(",\n"+s4o.indent_spaces); |
|
864 s4o.print(FB_FUNCTION_PARAM); |
|
865 } |
747 |
866 |
748 s4o.print(")"); |
867 s4o.print(")"); |
749 /* the data type returned by the function, and stored in the il default variable... */ |
868 /* the data type returned by the function, and stored in the il default variable... */ |
750 default_variable_name.current_type = return_data_type; |
869 default_variable_name.current_type = return_data_type; |
|
870 |
|
871 CLEAR_PARAM_LIST() |
|
872 |
751 return NULL; |
873 return NULL; |
752 } |
874 } |
753 |
875 |
754 |
876 |
755 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
877 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
854 |
976 |
855 /* now output the value assignment */ |
977 /* now output the value assignment */ |
856 if (param_value != NULL) |
978 if (param_value != NULL) |
857 if ((param_direction == function_param_iterator_c::direction_in) || |
979 if ((param_direction == function_param_iterator_c::direction_in) || |
858 (param_direction == function_param_iterator_c::direction_inout)) { |
980 (param_direction == function_param_iterator_c::direction_inout)) { |
859 symbol->fb_name->accept(*this); |
981 if (!this->is_variable_prefix_null()) { |
|
982 s4o.print(SET_VAR); |
|
983 s4o.print("("); |
|
984 } |
|
985 symbol->fb_name->accept(*this); |
860 s4o.print("."); |
986 s4o.print("."); |
861 param_name->accept(*this); |
987 param_name->accept(*this); |
862 s4o.print(" = "); |
988 if (this->is_variable_prefix_null()) |
863 if (search_base_type.type_is_subrange(param_type)) { |
989 s4o.print(" = "); |
864 s4o.print("__CHECK_"); |
990 else |
865 param_type->accept(*this); |
991 s4o.print(","); |
866 s4o.print("("); |
992 print_check_function(param_type, param_value); |
867 } |
993 if (!this->is_variable_prefix_null()) |
868 param_value->accept(*this); |
|
869 if (search_base_type.type_is_subrange(param_type)) |
|
870 s4o.print(")"); |
994 s4o.print(")"); |
871 s4o.print(";\n" + s4o.indent_spaces); |
995 s4o.print(";\n" + s4o.indent_spaces); |
872 } |
996 } |
873 } /* for(...) */ |
997 } /* for(...) */ |
874 |
998 |
897 /* now output the value assignment */ |
1021 /* now output the value assignment */ |
898 if (param_value != NULL) |
1022 if (param_value != NULL) |
899 if ((param_direction == function_param_iterator_c::direction_out) || |
1023 if ((param_direction == function_param_iterator_c::direction_out) || |
900 (param_direction == function_param_iterator_c::direction_inout)) { |
1024 (param_direction == function_param_iterator_c::direction_inout)) { |
901 symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false); |
1025 symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false); |
902 |
1026 unsigned int vartype = search_varfb_instance_type->get_vartype(param_value); |
903 s4o.print(";\n"+ s4o.indent_spaces); |
1027 |
904 param_value->accept(*this); |
1028 if (!this->is_variable_prefix_null()) { |
905 s4o.print(" = "); |
1029 s4o.print(";\n"+ s4o.indent_spaces); |
906 if (search_base_type.type_is_subrange(param_type)) { |
1030 if (vartype == search_var_instance_decl_c::external_vt) |
907 s4o.print("__CHECK_"); |
1031 s4o.print(SET_EXTERNAL); |
908 param_type->accept(*this); |
1032 else if (vartype == search_var_instance_decl_c::located_vt) |
909 s4o.print("("); |
1033 s4o.print(SET_LOCATED); |
|
1034 else |
|
1035 s4o.print(SET_VAR); |
|
1036 s4o.print("("); |
|
1037 |
|
1038 wanted_variablegeneration = assignment_vg; |
|
1039 param_value->accept(*this); |
|
1040 wanted_variablegeneration = expression_vg; |
|
1041 s4o.print(","); |
910 } |
1042 } |
911 symbol->fb_name->accept(*this); |
1043 else { |
912 s4o.print("."); |
1044 param_value->accept(*this); |
913 param_name->accept(*this); |
1045 s4o.print(" = "); |
914 if (search_base_type.type_is_subrange(param_type)) |
1046 } |
|
1047 print_check_function(param_type, param_name, symbol->fb_name); |
|
1048 if (!this->is_variable_prefix_null()) |
915 s4o.print(")"); |
1049 s4o.print(")"); |
916 } |
1050 } |
917 } /* for(...) */ |
1051 } /* for(...) */ |
918 |
1052 |
919 s4o.print(";\n"); |
1053 s4o.print(";\n"); |
957 symbol_c *EN_param_value = function_call_param_iterator.search_f(&en_param_name); |
1090 symbol_c *EN_param_value = function_call_param_iterator.search_f(&en_param_name); |
958 if (EN_param_value == NULL) |
1091 if (EN_param_value == NULL) |
959 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
1092 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
960 else |
1093 else |
961 nb_param --; |
1094 nb_param --; |
962 ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
1095 ADD_PARAM_LIST(&en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
963 |
1096 |
964 identifier_c eno_param_name("EN0"); |
1097 identifier_c eno_param_name("EN0"); |
965 /* Get the value from ENO param */ |
1098 /* Get the value from ENO param */ |
966 symbol_c *ENO_param_value = function_call_param_iterator.search_f(&eno_param_name); |
1099 symbol_c *ENO_param_value = function_call_param_iterator.search_f(&eno_param_name); |
967 if (ENO_param_value != NULL) |
1100 if (ENO_param_value != NULL) |
968 nb_param --; |
1101 nb_param --; |
969 ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
1102 ADD_PARAM_LIST(&eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
970 |
1103 |
971 #include "st_code_gen.c" |
1104 #include "st_code_gen.c" |
972 |
1105 |
973 } |
1106 } |
974 else { |
1107 else { |
1014 /* No value given for parameter, so we must use the default... */ |
1147 /* No value given for parameter, so we must use the default... */ |
1015 /* First check whether default value specified in function declaration...*/ |
1148 /* First check whether default value specified in function declaration...*/ |
1016 param_value = fp_iterator.default_value(); |
1149 param_value = fp_iterator.default_value(); |
1017 } |
1150 } |
1018 |
1151 |
1019 ADD_PARAM_LIST(param_value, param_type, fp_iterator.param_direction()) |
1152 ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
1020 } |
1153 } |
1021 } |
1154 } |
1022 |
1155 |
|
1156 bool has_output_params = false; |
|
1157 |
|
1158 if (!this->is_variable_prefix_null()) { |
|
1159 PARAM_LIST_ITERATOR() { |
|
1160 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
1161 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
1162 PARAM_VALUE != NULL) { |
|
1163 if (!has_output_params) { |
|
1164 has_output_params = true; |
|
1165 } |
|
1166 } |
|
1167 } |
|
1168 } |
|
1169 |
1023 default_variable_name.current_type = return_data_type; |
1170 default_variable_name.current_type = return_data_type; |
1024 this->default_variable_name.accept(*this); |
1171 this->default_variable_name.accept(*this); |
1025 s4o.print(" = "); |
1172 s4o.print(" = "); |
1026 |
1173 |
1027 if (function_type_prefix != NULL) { |
1174 if (function_type_prefix != NULL) { |
1028 s4o.print("("); |
1175 s4o.print("("); |
1029 function_type_prefix->accept(*this); |
1176 function_type_prefix->accept(*this); |
1030 s4o.print(")"); |
1177 s4o.print(")"); |
1031 } |
1178 } |
1032 if (function_name != NULL) |
1179 if (has_output_params) { |
|
1180 fcall_number++; |
|
1181 s4o.print("__"); |
|
1182 fbname->accept(*this); |
|
1183 s4o.print("_"); |
1033 function_name->accept(*this); |
1184 function_name->accept(*this); |
1034 if (function_type_suffix != NULL) |
1185 s4o.print_integer(fcall_number); |
1035 function_type_suffix->accept(*this); |
1186 } |
|
1187 else { |
|
1188 if (function_name != NULL) |
|
1189 function_name->accept(*this); |
|
1190 if (function_type_suffix != NULL) |
|
1191 function_type_suffix->accept(*this); |
|
1192 } |
1036 s4o.print("("); |
1193 s4o.print("("); |
1037 s4o.indent_right(); |
1194 s4o.indent_right(); |
1038 |
1195 |
1039 std::list<FUNCTION_PARAM>::iterator pt; |
1196 int nb_param = 0; |
1040 for(pt = param_list.begin(); pt != param_list.end(); pt++) { |
1197 PARAM_LIST_ITERATOR() { |
1041 if (pt != param_list.begin()) |
1198 symbol_c *param_value = PARAM_VALUE; |
1042 s4o.print(",\n"+s4o.indent_spaces); |
1199 symbol_c *param_type = PARAM_TYPE; |
1043 symbol_c *param_value = pt->param_value; |
|
1044 symbol_c *param_type = pt->param_type; |
|
1045 |
1200 |
1046 switch (pt->param_direction) { |
1201 switch (PARAM_DIRECTION) { |
1047 case function_param_iterator_c::direction_in: |
1202 case function_param_iterator_c::direction_in: |
1048 if (param_value == NULL) { |
1203 if (nb_param > 0) |
|
1204 s4o.print(",\n"+s4o.indent_spaces); |
|
1205 if (param_value == NULL) { |
1049 /* If not, get the default value of this variable's type */ |
1206 /* If not, get the default value of this variable's type */ |
1050 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
1207 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
1051 } |
1208 } |
1052 if (param_value == NULL) ERROR; |
1209 if (param_value == NULL) ERROR; |
|
1210 s4o.print("("); |
1053 if (search_expression_type->is_literal_integer_type(param_type) || |
1211 if (search_expression_type->is_literal_integer_type(param_type) || |
1054 search_expression_type->is_literal_real_type(param_type)) { |
1212 search_expression_type->is_literal_real_type(param_type)) { |
1055 if (function_type_suffix == NULL) ERROR; |
1213 if (function_type_suffix == NULL) ERROR; |
1056 function_type_suffix->accept(*this); |
1214 function_type_suffix->accept(*this); |
1057 } |
1215 } |
1058 else |
1216 else |
1059 param_type->accept(*this); |
1217 param_type->accept(*this); |
1060 if (search_base_type.type_is_subrange(param_type)) { |
1218 s4o.print(")"); |
1061 s4o.print("__CHECK_"); |
1219 print_check_function(param_type, param_value); |
1062 param_type->accept(*this); |
1220 nb_param++; |
1063 s4o.print("("); |
1221 break; |
1064 } |
|
1065 param_value->accept(*this); |
|
1066 if (search_base_type.type_is_subrange(param_type)) |
|
1067 s4o.print(")"); |
|
1068 break; |
|
1069 case function_param_iterator_c::direction_out: |
1222 case function_param_iterator_c::direction_out: |
1070 case function_param_iterator_c::direction_inout: |
1223 case function_param_iterator_c::direction_inout: |
1071 current_param_is_pointer = true; |
1224 if (!has_output_params) { |
1072 if (param_value == NULL) { |
1225 if (nb_param > 0) |
1073 s4o.print("NULL"); |
1226 s4o.print(",\n"+s4o.indent_spaces); |
1074 } else { |
1227 if (param_value == NULL) { |
1075 param_value->accept(*this); |
1228 s4o.print("NULL"); |
1076 } |
1229 } else { |
1077 current_param_is_pointer = false; |
1230 wanted_variablegeneration = fparam_output_vg; |
1078 break; |
1231 param_value->accept(*this); |
|
1232 wanted_variablegeneration = expression_vg; |
|
1233 } |
|
1234 } |
|
1235 break; |
1079 case function_param_iterator_c::direction_extref: |
1236 case function_param_iterator_c::direction_extref: |
1080 /* TODO! */ |
1237 /* TODO! */ |
1081 ERROR; |
1238 ERROR; |
1082 break; |
1239 break; |
1083 } /* switch */ |
1240 } /* switch */ |
1084 } /* for(...) */ |
1241 } /* for(...) */ |
|
1242 if (has_output_params) { |
|
1243 if (nb_param > 0) |
|
1244 s4o.print(",\n"+s4o.indent_spaces); |
|
1245 s4o.print(FB_FUNCTION_PARAM); |
|
1246 } |
1085 |
1247 |
1086 // symbol->parameter_assignment->accept(*this); |
1248 // symbol->parameter_assignment->accept(*this); |
1087 s4o.print(")"); |
1249 s4o.print(")"); |
1088 /* the data type returned by the function, and stored in the il default variable... */ |
1250 /* the data type returned by the function, and stored in the il default variable... */ |
|
1251 |
|
1252 CLEAR_PARAM_LIST() |
|
1253 |
1089 return NULL; |
1254 return NULL; |
1090 } |
1255 } |
1091 |
1256 |
1092 |
1257 |
1093 /* | il_operand_list ',' il_operand */ |
1258 /* | il_operand_list ',' il_operand */ |
1213 /* B 2.2 Operators */ |
1378 /* B 2.2 Operators */ |
1214 /*******************/ |
1379 /*******************/ |
1215 |
1380 |
1216 void *visit(LD_operator_c *symbol) { |
1381 void *visit(LD_operator_c *symbol) { |
1217 /* the data type resulting from this operation... */ |
1382 /* the data type resulting from this operation... */ |
1218 if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
1383 this->default_variable_name.current_type = this->current_operand_type; |
1219 this->default_variable_name.current_type = &(this->lint_type); |
|
1220 else if (search_expression_type->is_literal_real_type(this->current_operand_type)) |
|
1221 this->default_variable_name.current_type = &(this->lreal_type); |
|
1222 else |
|
1223 this->default_variable_name.current_type = this->current_operand_type; |
|
1224 XXX_operator(&(this->default_variable_name), " = ", this->current_operand); |
1384 XXX_operator(&(this->default_variable_name), " = ", this->current_operand); |
1225 this->default_variable_name.current_type = this->current_operand_type; |
|
1226 return NULL; |
1385 return NULL; |
1227 } |
1386 } |
1228 |
1387 |
1229 void *visit(LDN_operator_c *symbol) { |
1388 void *visit(LDN_operator_c *symbol) { |
1230 /* the data type resulting from this operation... */ |
1389 /* the data type resulting from this operation... */ |
1231 if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
1390 this->default_variable_name.current_type = this->current_operand_type; |
1232 this->default_variable_name.current_type = &(this->lword_type); |
|
1233 else |
|
1234 this->default_variable_name.current_type = this->current_operand_type; |
|
1235 XXX_operator(&(this->default_variable_name), |
1391 XXX_operator(&(this->default_variable_name), |
1236 search_expression_type->is_bool_type(this->current_operand_type)?" = !":" = ~", |
1392 search_expression_type->is_bool_type(this->current_operand_type)?" = !":" = ~", |
1237 this->current_operand); |
1393 this->current_operand); |
1238 return NULL; |
1394 return NULL; |
1239 } |
1395 } |
1240 |
1396 |
1241 void *visit(ST_operator_c *symbol) { |
1397 void *visit(ST_operator_c *symbol) { |
1242 symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false); |
1398 symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false); |
1243 |
1399 |
1244 this->current_operand->accept(*this); |
1400 if (!this->is_variable_prefix_null()) { |
1245 s4o.print(" = "); |
1401 unsigned int vartype = search_varfb_instance_type->get_vartype(this->current_operand); |
1246 if (search_base_type.type_is_subrange(operand_type)) { |
1402 if (vartype == search_var_instance_decl_c::external_vt) |
1247 s4o.print("__CHECK_"); |
1403 s4o.print(SET_EXTERNAL); |
1248 operand_type->accept(*this); |
1404 else if (vartype == search_var_instance_decl_c::located_vt) |
|
1405 s4o.print(SET_LOCATED); |
|
1406 else |
|
1407 s4o.print(SET_VAR); |
1249 s4o.print("("); |
1408 s4o.print("("); |
|
1409 |
|
1410 wanted_variablegeneration = assignment_vg; |
|
1411 this->current_operand->accept(*this); |
|
1412 wanted_variablegeneration = expression_vg; |
|
1413 |
|
1414 s4o.print(","); |
|
1415 } |
|
1416 else { |
|
1417 this->current_operand->accept(*this); |
|
1418 s4o.print(" = "); |
1250 } |
1419 } |
1251 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type) || |
1420 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type) || |
1252 search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) |
1421 search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) |
1253 this->default_variable_name.current_type = this->current_operand_type; |
1422 this->default_variable_name.current_type = this->current_operand_type; |
1254 this->default_variable_name.accept(*this); |
1423 print_check_function(operand_type, (symbol_c*)&(this->default_variable_name)); |
1255 if (search_base_type.type_is_subrange(operand_type)) |
1424 if (!this->is_variable_prefix_null()) |
1256 s4o.print(")"); |
1425 s4o.print(")"); |
1257 /* the data type resulting from this operation is unchamged. */ |
1426 /* the data type resulting from this operation is unchanged. */ |
1258 return NULL; |
1427 return NULL; |
1259 } |
1428 } |
1260 |
1429 |
1261 void *visit(STN_operator_c *symbol) { |
1430 void *visit(STN_operator_c *symbol) { |
1262 symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false); |
1431 symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false); |
1263 |
1432 |
1264 this->current_operand->accept(*this); |
1433 if (!this->is_variable_prefix_null()) { |
1265 s4o.print(" = "); |
1434 unsigned int vartype = search_varfb_instance_type->get_vartype(this->current_operand); |
1266 if (search_base_type.type_is_subrange(operand_type)) { |
1435 if (vartype == search_var_instance_decl_c::external_vt) |
1267 s4o.print("__CHECK_"); |
1436 s4o.print(SET_EXTERNAL); |
1268 operand_type->accept(*this); |
1437 else if (vartype == search_var_instance_decl_c::located_vt) |
|
1438 s4o.print(SET_LOCATED); |
|
1439 else |
|
1440 s4o.print(SET_VAR); |
1269 s4o.print("("); |
1441 s4o.print("("); |
|
1442 |
|
1443 wanted_variablegeneration = assignment_vg; |
|
1444 this->current_operand->accept(*this); |
|
1445 wanted_variablegeneration = expression_vg; |
|
1446 |
|
1447 s4o.print(","); |
|
1448 } |
|
1449 else { |
|
1450 this->current_operand->accept(*this); |
|
1451 s4o.print(" = "); |
1270 } |
1452 } |
1271 if (search_expression_type->is_bool_type(this->current_operand_type)) |
1453 if (search_expression_type->is_bool_type(this->current_operand_type)) |
1272 s4o.print("!"); |
1454 s4o.print("!"); |
1273 else |
1455 else |
1274 s4o.print("~"); |
1456 s4o.print("~"); |
1275 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) |
1457 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) |
1276 this->default_variable_name.current_type = this->current_operand_type; |
1458 this->default_variable_name.current_type = this->current_operand_type; |
1277 this->default_variable_name.accept(*this); |
1459 this->default_variable_name.accept(*this); |
1278 if (search_base_type.type_is_subrange(operand_type)) |
1460 if (!this->is_variable_prefix_null()) |
1279 s4o.print(")"); |
1461 s4o.print(")"); |
1280 /* the data type resulting from this operation is unchamged. */ |
1462 /* the data type resulting from this operation is unchamged. */ |
1281 return NULL; |
1463 return NULL; |
1282 } |
1464 } |
1283 |
1465 |