600 /* | function_name [il_operand_list] */ |
600 /* | function_name [il_operand_list] */ |
601 // SYM_REF2(il_function_call_c, function_name, il_operand_list) |
601 // SYM_REF2(il_function_call_c, function_name, il_operand_list) |
602 void *visit(il_function_call_c *symbol) { |
602 void *visit(il_function_call_c *symbol) { |
603 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
603 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
604 |
604 |
|
605 symbol_c* function_type_prefix = NULL; |
|
606 symbol_c* function_name = NULL; |
|
607 symbol_c* function_type_suffix = NULL; |
|
608 std::list<FUNCTION_PARAM> param_list; |
|
609 FUNCTION_PARAM *param; |
|
610 |
|
611 symbol_c *param_data_type = default_variable_name.current_type; |
|
612 symbol_c *return_data_type = NULL; |
|
613 |
605 if (f_decl == function_symtable.end_value()) { |
614 if (f_decl == function_symtable.end_value()) { |
606 /* should never occur. The function being called MUST be in the symtable... */ |
|
607 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
615 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
608 if (current_function_type == function_none) ERROR; |
616 if (current_function_type == function_none) ERROR; |
609 |
617 |
610 symbol_c *param_data_type = default_variable_name.current_type; |
618 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
611 symbol_c *return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
|
612 if (NULL == return_data_type) ERROR; |
619 if (NULL == return_data_type) ERROR; |
613 |
620 |
614 default_variable_name.current_type = return_data_type; |
|
615 this->default_variable_name.accept(*this); |
|
616 default_variable_name.current_type = param_data_type; |
|
617 s4o.print(" = "); |
|
618 |
|
619 function_call_param_iterator_c function_call_param_iterator(symbol); |
621 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
622 |
|
623 /* Add the value from EN param */ |
|
624 ADD_PARAM_LIST((symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
|
625 (symbol_c*)(new bool_type_name_c()), |
|
626 function_param_iterator_c::direction_in) |
|
627 |
|
628 /* Add the value from ENO param */ |
|
629 ADD_PARAM_LIST(NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
620 |
630 |
621 int nb_param = 1; |
631 int nb_param = 1; |
622 if (symbol->il_operand_list != NULL) |
632 if (symbol->il_operand_list != NULL) |
623 nb_param += ((list_c *)symbol->il_operand_list)->n; |
633 nb_param += ((list_c *)symbol->il_operand_list)->n; |
624 |
634 |
625 #include "il_code_gen.c" |
635 #include "il_code_gen.c" |
626 |
636 |
627 /* the data type returned by the function, and stored in the il default variable... */ |
|
628 default_variable_name.current_type = return_data_type; |
|
629 } |
637 } |
630 else { |
638 else { |
631 /* determine the base data type returned by the function being called... */ |
639 /* determine the base data type returned by the function being called... */ |
632 search_base_type_c search_base_type; |
640 search_base_type_c search_base_type; |
633 symbol_c *return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
641 return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
634 symbol_c *param_data_type = default_variable_name.current_type; |
|
635 if (NULL == return_data_type) ERROR; |
642 if (NULL == return_data_type) ERROR; |
636 |
643 |
637 default_variable_name.current_type = return_data_type; |
644 function_name = symbol->function_name; |
638 this->default_variable_name.accept(*this); |
645 |
639 default_variable_name.current_type = param_data_type; |
|
640 s4o.print(" = "); |
|
641 |
|
642 symbol->function_name->accept(*this); |
|
643 s4o.print("("); |
|
644 |
|
645 /* loop through each function parameter, find the value we should pass |
646 /* loop through each function parameter, find the value we should pass |
646 * to it, and then output the c equivalent... |
647 * to it, and then output the c equivalent... |
647 */ |
648 */ |
648 |
649 |
649 function_param_iterator_c fp_iterator(f_decl); |
650 function_param_iterator_c fp_iterator(f_decl); |
650 identifier_c *param_name; |
651 identifier_c *param_name; |
651 function_call_param_iterator_c function_call_param_iterator(symbol); |
652 function_call_param_iterator_c function_call_param_iterator(symbol); |
652 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
653 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
653 if (i != 1) |
|
654 s4o.print(", "); |
|
655 |
|
656 symbol_c *param_type = fp_iterator.param_type(); |
654 symbol_c *param_type = fp_iterator.param_type(); |
657 if (param_type == NULL) ERROR; |
655 if (param_type == NULL) ERROR; |
658 |
656 |
659 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
657 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
660 |
658 |
661 |
|
662 symbol_c *param_value = NULL; |
659 symbol_c *param_value = NULL; |
663 |
660 |
664 /* if it is the first parameter, semantics specifies that we should |
661 /* if it is the first parameter, semantics specifies that we should |
665 * get the value off the IL default variable! |
662 * get the value off the IL default variable! |
666 */ |
663 */ |
679 param_value = function_call_param_iterator.search(param_name); |
676 param_value = function_call_param_iterator.search(param_name); |
680 |
677 |
681 /* Get the value from a foo(<param_value>) style call */ |
678 /* Get the value from a foo(<param_value>) style call */ |
682 if (param_value == NULL) |
679 if (param_value == NULL) |
683 param_value = function_call_param_iterator.next(); |
680 param_value = function_call_param_iterator.next(); |
684 |
681 |
685 switch (param_direction) { |
682 if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
686 case function_param_iterator_c::direction_in: |
683 /* No value given for parameter, so we must use the default... */ |
687 if (param_value == NULL) { |
684 /* First check whether default value specified in function declaration...*/ |
688 /* No value given for parameter, so we must use the default... */ |
685 param_value = fp_iterator.default_value(); |
689 /* First check whether default value specified in function declaration...*/ |
686 } |
690 param_value = fp_iterator.default_value(); |
687 |
691 } |
688 ADD_PARAM_LIST(param_value, param_type, fp_iterator.param_direction()) |
692 if (param_value == NULL) { |
689 } /* for(...) */ |
693 /* If not, get the default value of this variable's type */ |
690 } |
694 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
691 |
695 } |
692 default_variable_name.current_type = return_data_type; |
696 if (param_value == NULL) ERROR; |
693 this->default_variable_name.accept(*this); |
|
694 default_variable_name.current_type = param_data_type; |
|
695 s4o.print(" = "); |
|
696 |
|
697 if (function_type_prefix != NULL) { |
|
698 s4o.print("("); |
|
699 function_type_prefix->accept(*this); |
|
700 s4o.print(")"); |
|
701 } |
|
702 if (function_name != NULL) |
|
703 function_name->accept(*this); |
|
704 if (function_type_suffix != NULL) |
|
705 function_type_suffix->accept(*this); |
|
706 s4o.print("("); |
|
707 s4o.indent_right(); |
|
708 |
|
709 std::list<FUNCTION_PARAM>::iterator pt; |
|
710 for(pt = param_list.begin(); pt != param_list.end(); pt++) { |
|
711 if (pt != param_list.begin()) |
|
712 s4o.print(",\n"+s4o.indent_spaces); |
|
713 symbol_c *param_value = pt->param_value; |
|
714 symbol_c *param_type = pt->param_type; |
|
715 |
|
716 switch (pt->param_direction) { |
|
717 case function_param_iterator_c::direction_in: |
|
718 if (param_value == NULL) { |
|
719 /* If not, get the default value of this variable's type */ |
|
720 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
|
721 } |
|
722 if (param_value == NULL) ERROR; |
|
723 if (search_base_type.type_is_subrange(param_type)) { |
|
724 s4o.print("__CHECK_"); |
|
725 param_type->accept(*this); |
|
726 s4o.print("("); |
|
727 } |
|
728 param_value->accept(*this); |
|
729 if (search_base_type.type_is_subrange(param_type)) |
|
730 s4o.print(")"); |
|
731 break; |
|
732 case function_param_iterator_c::direction_out: |
|
733 case function_param_iterator_c::direction_inout: |
|
734 current_param_is_pointer = true; |
|
735 if (param_value == NULL) { |
|
736 s4o.print("NULL"); |
|
737 } else { |
697 param_value->accept(*this); |
738 param_value->accept(*this); |
698 break; |
739 } |
699 case function_param_iterator_c::direction_out: |
740 current_param_is_pointer = false; |
700 case function_param_iterator_c::direction_inout: |
741 break; |
701 current_param_is_pointer = true; |
742 case function_param_iterator_c::direction_extref: |
702 if (param_value == NULL) { |
743 /* TODO! */ |
703 s4o.print("NULL"); |
744 ERROR; |
704 } else { |
745 break; |
705 param_value->accept(*this); |
746 } /* switch */ |
706 } |
747 } |
707 current_param_is_pointer = false; |
748 |
708 break; |
749 s4o.print(")"); |
709 case function_param_iterator_c::direction_extref: |
750 /* the data type returned by the function, and stored in the il default variable... */ |
710 /* TODO! */ |
751 default_variable_name.current_type = return_data_type; |
711 ERROR; |
|
712 break; |
|
713 } /* switch */ |
|
714 } /* for(...) */ |
|
715 |
|
716 s4o.print(")"); |
|
717 /* the data type returned by the function, and stored in the il default variable... */ |
|
718 default_variable_name.current_type = return_data_type; |
|
719 } |
|
720 |
|
721 return NULL; |
752 return NULL; |
722 } |
753 } |
723 |
754 |
724 |
755 |
725 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
756 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
899 /* | function_name '(' eol_list [il_param_list] ')' */ |
930 /* | function_name '(' eol_list [il_param_list] ')' */ |
900 // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
931 // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
901 void *visit(il_formal_funct_call_c *symbol) { |
932 void *visit(il_formal_funct_call_c *symbol) { |
902 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
933 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
903 |
934 |
904 if (f_decl == function_symtable.end_value()) |
935 symbol_c* function_type_prefix = NULL; |
905 /* should never occur. The function being called MUST be in the symtable... */ |
936 symbol_c* function_name = NULL; |
906 ERROR; |
937 symbol_c* function_type_suffix = NULL; |
907 |
938 std::list<FUNCTION_PARAM> param_list; |
908 symbol->function_name->accept(*this); |
939 FUNCTION_PARAM *param; |
|
940 |
|
941 symbol_c *return_data_type = NULL; |
|
942 |
|
943 if (f_decl == function_symtable.end_value()) { |
|
944 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
945 if (current_function_type == function_none) ERROR; |
|
946 |
|
947 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
|
948 if (NULL == return_data_type) ERROR; |
|
949 |
|
950 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
951 |
|
952 identifier_c en_param_name("EN"); |
|
953 /* Get the value from EN param */ |
|
954 symbol_c *EN_param_value = function_call_param_iterator.search(&en_param_name); |
|
955 if (EN_param_value == NULL) |
|
956 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
957 ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
|
958 |
|
959 identifier_c eno_param_name("EN0"); |
|
960 /* Get the value from ENO param */ |
|
961 symbol_c *ENO_param_value = function_call_param_iterator.search(&eno_param_name); |
|
962 ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
963 |
|
964 int nb_param = 0; |
|
965 if (symbol->il_param_list != NULL) |
|
966 nb_param += ((list_c *)symbol->il_param_list)->n; |
|
967 |
|
968 #include "st_code_gen.c" |
|
969 |
|
970 } |
|
971 else { |
|
972 /* determine the base data type returned by the function being called... */ |
|
973 search_base_type_c search_base_type; |
|
974 return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
|
975 if (NULL == return_data_type) ERROR; |
|
976 |
|
977 function_name = symbol->function_name; |
|
978 |
|
979 /* loop through each function parameter, find the value we should pass |
|
980 * to it, and then output the c equivalent... |
|
981 */ |
|
982 |
|
983 function_param_iterator_c fp_iterator(f_decl); |
|
984 identifier_c *param_name; |
|
985 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
986 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
987 symbol_c *param_type = fp_iterator.param_type(); |
|
988 if (param_type == NULL) ERROR; |
|
989 |
|
990 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
991 |
|
992 |
|
993 symbol_c *param_value = NULL; |
|
994 |
|
995 /* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
996 if (param_value == NULL) |
|
997 param_value = function_call_param_iterator.search(param_name); |
|
998 |
|
999 /* Get the value from a foo(<param_value>) style call */ |
|
1000 /* NOTE: the following line of code is not required in this case, but it doesn't |
|
1001 * harm to leave it in, as in the case of a formal syntax function call, |
|
1002 * it will always return NULL. |
|
1003 * We leave it in in case we later decide to merge this part of the code together |
|
1004 * with the function calling code in generate_c_st_c, which does require |
|
1005 * the following line... |
|
1006 */ |
|
1007 if (param_value == NULL) |
|
1008 param_value = function_call_param_iterator.next(); |
|
1009 |
|
1010 if (param_value == NULL) { |
|
1011 /* No value given for parameter, so we must use the default... */ |
|
1012 /* First check whether default value specified in function declaration...*/ |
|
1013 param_value = fp_iterator.default_value(); |
|
1014 } |
|
1015 |
|
1016 ADD_PARAM_LIST(param_value, param_type, fp_iterator.param_direction()) |
|
1017 } |
|
1018 } |
|
1019 |
|
1020 default_variable_name.current_type = return_data_type; |
|
1021 this->default_variable_name.accept(*this); |
|
1022 s4o.print(" = "); |
|
1023 |
|
1024 if (function_type_prefix != NULL) { |
|
1025 s4o.print("("); |
|
1026 function_type_prefix->accept(*this); |
|
1027 s4o.print(")"); |
|
1028 } |
|
1029 if (function_name != NULL) |
|
1030 function_name->accept(*this); |
|
1031 if (function_type_suffix != NULL) |
|
1032 function_type_suffix->accept(*this); |
909 s4o.print("("); |
1033 s4o.print("("); |
910 |
1034 s4o.indent_right(); |
911 /* loop through each function parameter, find the value we should pass |
1035 |
912 * to it, and then output the c equivalent... |
1036 std::list<FUNCTION_PARAM>::iterator pt; |
913 */ |
1037 for(pt = param_list.begin(); pt != param_list.end(); pt++) { |
914 |
1038 if (pt != param_list.begin()) |
915 function_param_iterator_c fp_iterator(f_decl); |
1039 s4o.print(",\n"+s4o.indent_spaces); |
916 identifier_c *param_name; |
1040 symbol_c *param_value = pt->param_value; |
917 function_call_param_iterator_c function_call_param_iterator(symbol); |
1041 symbol_c *param_type = pt->param_type; |
918 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
1042 |
919 if (i != 1) |
1043 switch (pt->param_direction) { |
920 s4o.print(", "); |
|
921 |
|
922 symbol_c *param_type = fp_iterator.param_type(); |
|
923 if (param_type == NULL) ERROR; |
|
924 |
|
925 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
926 |
|
927 |
|
928 symbol_c *param_value = NULL; |
|
929 |
|
930 /* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
931 if (param_value == NULL) |
|
932 param_value = function_call_param_iterator.search(param_name); |
|
933 |
|
934 /* Get the value from a foo(<param_value>) style call */ |
|
935 /* NOTE: the following line of code is not required in this case, but it doesn't |
|
936 * harm to leave it in, as in the case of a formal syntax function call, |
|
937 * it will always return NULL. |
|
938 * We leave it in in case we later decide to merge this part of the code together |
|
939 * with the function calling code in generate_c_st_c, which does require |
|
940 * the following line... |
|
941 */ |
|
942 if (param_value == NULL) |
|
943 param_value = function_call_param_iterator.next(); |
|
944 |
|
945 switch (param_direction) { |
|
946 case function_param_iterator_c::direction_in: |
1044 case function_param_iterator_c::direction_in: |
947 if (param_value == NULL) { |
|
948 /* No value given for parameter, so we must use the default... */ |
|
949 /* First check whether default value specified in function declaration...*/ |
|
950 param_value = fp_iterator.default_value(); |
|
951 } |
|
952 if (param_value == NULL) { |
1045 if (param_value == NULL) { |
953 /* If not, get the default value of this variable's type */ |
1046 /* If not, get the default value of this variable's type */ |
954 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
1047 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
955 } |
1048 } |
956 if (param_value == NULL) ERROR; |
1049 if (param_value == NULL) ERROR; |
1332 ERROR; |
1424 ERROR; |
1333 return NULL; |
1425 return NULL; |
1334 } |
1426 } |
1335 |
1427 |
1336 void *visit(DIV_operator_c *symbol) { |
1428 void *visit(DIV_operator_c *symbol) { |
|
1429 if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
|
1430 search_expression_type->is_integer_type(this->current_operand_type)) { |
|
1431 XXX_function("__TIME_DIV", &(this->default_variable_name), this->current_operand); |
|
1432 /* the data type resulting from this operation... */ |
|
1433 return NULL; |
|
1434 } |
1337 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1435 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1338 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1436 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1339 XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); |
1437 XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); |
1340 /* the data type resulting from this operation... */ |
1438 /* the data type resulting from this operation... */ |
1341 this->default_variable_name.current_type = this->current_operand_type; |
1439 this->default_variable_name.current_type = this->current_operand_type; |
1342 } |
1440 } |
1343 else {ERROR;} |
1441 ERROR; |
1344 return NULL; |
1442 return NULL; |
1345 } |
1443 } |
1346 |
1444 |
1347 void *visit(MOD_operator_c *symbol) { |
1445 void *visit(MOD_operator_c *symbol) { |
1348 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1446 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1349 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1447 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1350 XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); |
1448 XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); |
1351 /* the data type resulting from this operation... */ |
1449 /* the data type resulting from this operation... */ |
1352 this->default_variable_name.current_type = this->current_operand_type; |
1450 this->default_variable_name.current_type = this->current_operand_type; |
1353 } |
1451 } |
1354 else {ERROR;} |
1452 ERROR; |
1355 return NULL; |
1453 return NULL; |
1356 } |
1454 } |
1357 |
1455 |
1358 void *visit(GT_operator_c *symbol) { |
1456 void *visit(GT_operator_c *symbol) { |
1359 if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |
1457 if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |