718 |
718 |
719 |
719 |
720 /* A helper function... */ |
720 /* A helper function... */ |
721 /* check the semantics of a FB or Function non-formal call */ |
721 /* check the semantics of a FB or Function non-formal call */ |
722 /* e.g. foo(1, 2, 3, 4); */ |
722 /* e.g. foo(1, 2, 3, 4); */ |
723 void visit_expression_type_c::check_nonformal_call(symbol_c *f_call, symbol_c *f_decl, bool use_il_defvar) { |
723 /* If error_count pointer is != NULL, we do not really print out the errors, |
|
724 * but rather only count how many errors were found. |
|
725 * This is used to support overloaded functions, where we have to check each possible |
|
726 * function, one at a time, untill we find a function call without any errors. |
|
727 */ |
|
728 void visit_expression_type_c::check_nonformal_call(symbol_c *f_call, symbol_c *f_decl, bool use_il_defvar, int *error_count) { |
724 symbol_c *call_param_value, *call_param_type, *param_type; |
729 symbol_c *call_param_value, *call_param_type, *param_type; |
725 identifier_c *param_name; |
730 identifier_c *param_name; |
726 function_param_iterator_c fp_iterator(f_decl); |
731 function_param_iterator_c fp_iterator(f_decl); |
727 function_call_param_iterator_c fcp_iterator(f_call); |
732 function_call_param_iterator_c fcp_iterator(f_call); |
728 |
733 int extensible_parameter_highest_index = -1; |
|
734 |
|
735 /* reset error counter */ |
|
736 if (error_count != NULL) *error_count = 0; |
729 /* if use_il_defvar, then the first parameter for the call comes from the il_default_variable */ |
737 /* if use_il_defvar, then the first parameter for the call comes from the il_default_variable */ |
730 if (use_il_defvar) { |
738 if (use_il_defvar) { |
731 /* The first parameter of the function corresponds to the il_default_variable_type of the function call */ |
739 /* The first parameter of the function corresponds to the il_default_variable_type of the function call */ |
732 do { |
740 do { |
733 param_name = fp_iterator.next(); |
741 param_name = fp_iterator.next(); |
738 * in the function. |
746 * in the function. |
739 */ |
747 */ |
740 } while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0)); |
748 } while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0)); |
741 /* If the function does not have any parameters (param_name == NULL) |
749 /* If the function does not have any parameters (param_name == NULL) |
742 * then we cannot compare its type with the il_default_variable_type. |
750 * then we cannot compare its type with the il_default_variable_type. |
|
751 * |
|
752 * However, I (Mario) think this is invalid syntax, as it seems to me all functions must |
|
753 * have at least one parameter. |
|
754 * However, we will make this semantic verification consider it possible, as later |
|
755 * versions of the standard may change that syntax. |
|
756 * So, instead of generating a syntax error message, we simply check whether the call |
|
757 * is passing any more parameters besides the default variable (the il default variable may be ignored |
|
758 * in this case, and not consider it as being a parameter being passed to the function). |
|
759 * If it does, then we have found a semantic error, otherwise the function call is |
|
760 * correct, and we simply return. |
743 */ |
761 */ |
744 if(param_name != NULL) { |
762 if(param_name == NULL) { |
|
763 if (fcp_iterator.next_nf() != NULL) |
|
764 STAGE3_ERROR(f_call, f_call, "Too many parameters in function/FB call."); |
|
765 return; |
|
766 } else { |
|
767 /* param_name != NULL */ |
745 param_type = fp_iterator.param_type(); |
768 param_type = fp_iterator.param_type(); |
746 if(!is_valid_assignment(param_type, il_default_variable_type)) |
769 if(!is_valid_assignment(param_type, il_default_variable_type)) { |
747 STAGE3_ERROR(f_call, f_call, "In function/FB call, first parameter has invalid data type."); |
770 if (error_count != NULL) (*error_count)++; |
|
771 else STAGE3_ERROR(f_call, f_call, "In function/FB call, first parameter has invalid data type."); |
|
772 } |
|
773 } |
|
774 |
|
775 /* the fisrt parameter (il_def_variable) is correct */ |
|
776 if (extensible_parameter_highest_index < fp_iterator.extensible_param_index()) { |
|
777 extensible_parameter_highest_index = fp_iterator.extensible_param_index(); |
748 } |
778 } |
749 } // if (use_il_defvar) |
779 } // if (use_il_defvar) |
|
780 |
|
781 |
750 |
782 |
751 /* Iterating through the non-formal parameters of the function call */ |
783 /* Iterating through the non-formal parameters of the function call */ |
752 while((call_param_value = fcp_iterator.next_nf()) != NULL) { |
784 while((call_param_value = fcp_iterator.next_nf()) != NULL) { |
753 /* Obtaining the type of the value being passed in the function call */ |
785 /* Obtaining the type of the value being passed in the function call */ |
754 call_param_type = base_type((symbol_c*)call_param_value->accept(*this)); |
786 call_param_type = base_type((symbol_c*)call_param_value->accept(*this)); |
755 if (call_param_type == NULL) { |
787 if (call_param_type == NULL) { |
756 STAGE3_ERROR(call_param_value, call_param_value, "Could not determine data type of value being passed in function/FB call."); |
788 if (error_count != NULL) (*error_count)++; |
|
789 /* the following error will usually occur when ST code uses an identifier, that could refer to an enumerated constant, |
|
790 * but was not actually used as a constant in any definitions of an enumerated data type |
|
791 */ |
|
792 else STAGE3_ERROR(call_param_value, call_param_value, "Could not determine data type of value being passed in function/FB call."); |
757 continue; |
793 continue; |
758 } |
794 } |
759 |
795 |
760 /* Iterate to the next parameter of the function being called. |
796 /* Iterate to the next parameter of the function being called. |
761 * Get the name of that parameter, and ignore if EN or ENO. |
797 * Get the name of that parameter, and ignore if EN or ENO. |
762 */ |
798 */ |
763 do { |
799 do { |
764 param_name = fp_iterator.next(); |
800 param_name = fp_iterator.next(); |
765 /* If there is no parameter declared with that name */ |
801 /* If there is no other parameter declared, then we are passing too many parameters... */ |
766 if(param_name == NULL) {STAGE3_ERROR(f_call, f_call, "Too many parameters in function/FB call."); break;} |
802 if(param_name == NULL) { |
|
803 if (error_count != NULL) (*error_count)++; |
|
804 /* Note: We don't want to print out the follwoing error message multiple times, so we return instead of continuing with 'break' */ |
|
805 else STAGE3_ERROR(f_call, f_call, "Too many parameters in function/FB call."); return; |
|
806 } |
767 } while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0)); |
807 } while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0)); |
768 |
808 |
769 if(param_name != NULL) { |
809 /* Get the parameter type */ |
770 /* Get the parameter type */ |
810 param_type = base_type(fp_iterator.param_type()); |
771 param_type = base_type(fp_iterator.param_type()); |
811 /* If the declared parameter and the parameter from the function call do not have the same type */ |
772 /* If the declared parameter and the parameter from the function call do no have the same type */ |
812 if(!is_valid_assignment(param_type, call_param_type)) { |
773 if(!is_valid_assignment(param_type, call_param_type)) STAGE3_ERROR(call_param_value, call_param_value, "Type mismatch in function/FB call parameter."); |
813 if (error_count != NULL) (*error_count)++; |
|
814 else STAGE3_ERROR(call_param_value, call_param_value, "Type mismatch in function/FB call parameter."); |
774 } |
815 } |
775 } |
816 |
|
817 if (extensible_parameter_highest_index < fp_iterator.extensible_param_index()) { |
|
818 extensible_parameter_highest_index = fp_iterator.extensible_param_index(); |
|
819 } |
|
820 } |
|
821 |
|
822 /* The function call may not have any errors! */ |
|
823 /* In the case of a call to an extensible function, we store the highest index |
|
824 * of the extensible parameters this particular call uses, in the symbol_c object |
|
825 * of the function call itself! |
|
826 * In calls to non-extensible functions, this value will be set to -1. |
|
827 * This information is later used in stage4 to correctly generate the |
|
828 * output code. |
|
829 */ |
|
830 int extensible_param_count = -1; |
|
831 if (extensible_parameter_highest_index >=0) /* if call to extensible function */ |
|
832 extensible_param_count = 1 + extensible_parameter_highest_index - fp_iterator.first_extensible_param_index(); |
|
833 il_function_call_c *il_function_call = dynamic_cast<il_function_call_c *>(f_call); |
|
834 function_invocation_c *function_invocation = dynamic_cast<function_invocation_c *>(f_call); |
|
835 if (il_function_call != NULL) il_function_call ->extensible_param_count = extensible_param_count; |
|
836 else if (function_invocation != NULL) function_invocation->extensible_param_count = extensible_param_count; |
|
837 // else ERROR; /* this function is also called by Function Blocks, so this is not an error! */ |
776 } |
838 } |
777 |
839 |
778 |
840 |
779 /* check semantics of FB call in the IL language using input operators */ |
841 /* check semantics of FB call in the IL language using input operators */ |
780 /* e.g. CU, CLK, IN, PT, SR, ... */ |
842 /* e.g. CU, CLK, IN, PT, SR, ... */ |
812 |
874 |
813 |
875 |
814 /* A helper function... */ |
876 /* A helper function... */ |
815 /* check the semantics of a FB or Function formal call */ |
877 /* check the semantics of a FB or Function formal call */ |
816 /* e.g. foo(IN1 := 1, OUT1 =>x, EN := true); */ |
878 /* e.g. foo(IN1 := 1, OUT1 =>x, EN := true); */ |
817 void visit_expression_type_c::check_formal_call(symbol_c *f_call, symbol_c *f_decl) { |
879 /* If error_count pointer is != NULL, we do not really print out the errors, |
|
880 * but rather only count how many errors were found. |
|
881 * This is used to support overloaded functions, where we have to check each possible |
|
882 * function, one at a time, untill we find a function call without any errors. |
|
883 */ |
|
884 void visit_expression_type_c::check_formal_call(symbol_c *f_call, symbol_c *f_decl, int *error_count) { |
818 symbol_c *call_param_value, *call_param_type, *call_param_name, *param_type; |
885 symbol_c *call_param_value, *call_param_type, *call_param_name, *param_type; |
819 symbol_c *verify_duplicate_param; |
886 symbol_c *verify_duplicate_param; |
820 identifier_c *param_name; |
887 identifier_c *param_name; |
821 function_param_iterator_c fp_iterator(f_decl); |
888 function_param_iterator_c fp_iterator(f_decl); |
822 function_call_param_iterator_c fcp_iterator(f_call); |
889 function_call_param_iterator_c fcp_iterator(f_call); |
|
890 int extensible_parameter_highest_index = -1; |
|
891 identifier_c *extensible_parameter_name; |
|
892 |
|
893 /* reset error counter */ |
|
894 if (error_count != NULL) *error_count = 0; |
823 |
895 |
824 /* Iterating through the formal parameters of the function call */ |
896 /* Iterating through the formal parameters of the function call */ |
825 while((call_param_name = fcp_iterator.next_f()) != NULL) { |
897 while((call_param_name = fcp_iterator.next_f()) != NULL) { |
826 |
898 |
827 /* Obtaining the value being passed in the function call */ |
899 /* Obtaining the value being passed in the function call */ |
830 if (NULL == call_param_value) ERROR; |
902 if (NULL == call_param_value) ERROR; |
831 |
903 |
832 /* Checking if there are duplicated parameter values */ |
904 /* Checking if there are duplicated parameter values */ |
833 verify_duplicate_param = fcp_iterator.search_f(call_param_name); |
905 verify_duplicate_param = fcp_iterator.search_f(call_param_name); |
834 if(verify_duplicate_param != call_param_value){ |
906 if(verify_duplicate_param != call_param_value){ |
835 STAGE3_ERROR(call_param_name, verify_duplicate_param, "Duplicated parameter values."); |
907 if (error_count != NULL) (*error_count)++; |
|
908 else STAGE3_ERROR(call_param_name, verify_duplicate_param, "Duplicated parameter values."); |
836 } |
909 } |
837 |
910 |
838 /* Obtaining the type of the value being passed in the function call */ |
911 /* Obtaining the type of the value being passed in the function call */ |
839 call_param_type = (symbol_c*)call_param_value->accept(*this); |
912 call_param_type = (symbol_c*)call_param_value->accept(*this); |
840 if (call_param_type == NULL) { |
913 if (call_param_type == NULL) { |
841 STAGE3_ERROR(call_param_name, call_param_value, "Could not determine data type of value being passed in function/FB call."); |
914 if (error_count != NULL) (*error_count)++; |
|
915 else STAGE3_ERROR(call_param_name, call_param_value, "Could not determine data type of value being passed in function/FB call."); |
842 /* The data value being passed is possibly any enumerated type value. |
916 /* The data value being passed is possibly any enumerated type value. |
843 * We do not yet handle semantic verification of enumerated types. |
917 * We do not yet handle semantic verification of enumerated types. |
844 */ |
918 */ |
845 ERROR; |
919 ERROR; |
846 } |
920 } |
848 if (call_param_type == NULL) STAGE3_ERROR(call_param_name, call_param_value, "Could not determine data type of value being passed in function/FB call."); |
922 if (call_param_type == NULL) STAGE3_ERROR(call_param_name, call_param_value, "Could not determine data type of value being passed in function/FB call."); |
849 |
923 |
850 /* Find the corresponding parameter of the function being called */ |
924 /* Find the corresponding parameter of the function being called */ |
851 param_name = fp_iterator.search(call_param_name); |
925 param_name = fp_iterator.search(call_param_name); |
852 if(param_name == NULL) { |
926 if(param_name == NULL) { |
853 STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call."); |
927 if (error_count != NULL) (*error_count)++; |
|
928 else STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call."); |
854 } else { |
929 } else { |
855 /* Get the parameter type */ |
930 /* Get the parameter type */ |
856 param_type = base_type(fp_iterator.param_type()); |
931 param_type = base_type(fp_iterator.param_type()); |
857 /* If the declared parameter and the parameter from the function call have the same type */ |
932 /* If the declared parameter and the parameter from the function call have the same type */ |
858 if(!is_valid_assignment(param_type, call_param_type)) STAGE3_ERROR(call_param_name, call_param_value, "Type mismatch function/FB call parameter."); |
933 if(!is_valid_assignment(param_type, call_param_type)) { |
|
934 if (error_count != NULL) (*error_count)++; |
|
935 else STAGE3_ERROR(call_param_name, call_param_value, "Type mismatch function/FB call parameter."); |
|
936 } |
|
937 if (extensible_parameter_highest_index < fp_iterator.extensible_param_index()) { |
|
938 extensible_parameter_highest_index = fp_iterator.extensible_param_index(); |
|
939 extensible_parameter_name = param_name; |
|
940 } |
859 } |
941 } |
860 } |
942 } |
|
943 |
|
944 /* In the case of a call to an extensible function, we store the highest index |
|
945 * of the extensible parameters this particular call uses, in the symbol_c object |
|
946 * of the function call itself! |
|
947 * In calls to non-extensible functions, this value will be set to -1. |
|
948 * This information is later used in stage4 to correctly generate the |
|
949 * output code. |
|
950 */ |
|
951 int extensible_param_count = -1; |
|
952 if (extensible_parameter_highest_index >=0) /* if call to extensible function */ |
|
953 extensible_param_count = 1 + extensible_parameter_highest_index - fp_iterator.first_extensible_param_index(); |
|
954 il_formal_funct_call_c *il_formal_funct_call = dynamic_cast<il_formal_funct_call_c *>(f_call); |
|
955 function_invocation_c *function_invocation = dynamic_cast<function_invocation_c *>(f_call); |
|
956 if (il_formal_funct_call != NULL) il_formal_funct_call->extensible_param_count = extensible_param_count; |
|
957 else if (function_invocation != NULL) function_invocation->extensible_param_count = extensible_param_count; |
|
958 // else ERROR; /* this function is also called by Function Blocks, so this is not an error! */ |
|
959 |
|
960 /* We have iterated through all the formal parameters of the function call, |
|
961 * and everything seems fine. |
|
962 * If the function being called in an extensible function, we now check |
|
963 * whether the extensible paramters in the formal invocation do not skip |
|
964 * any indexes... |
|
965 * |
|
966 * f(in1:=0, in2:=0, in4:=0) --> ERROR!! |
|
967 */ |
|
968 if (extensible_parameter_highest_index >=0) { /* if call to extensible function */ |
|
969 for (int i=fp_iterator.first_extensible_param_index(); i < extensible_parameter_highest_index; i++) { |
|
970 char tmp[256]; |
|
971 if (snprintf(tmp, 256, "%s%d", extensible_parameter_name->value, i) >= 256) ERROR; |
|
972 if (fcp_iterator.search_f(tmp) == NULL) { |
|
973 /* error in invocation of extensible function */ |
|
974 if (error_count != NULL) (*error_count)++; |
|
975 else STAGE3_ERROR(f_call, f_call, "Missing extensible parameters in call to extensible function."); |
|
976 } |
|
977 } |
|
978 } |
861 } |
979 } |
862 |
980 |
863 |
981 |
864 |
982 |
865 |
983 |
988 //SYM_REF2(il_function_call_c, function_name, il_operand_list) |
1106 //SYM_REF2(il_function_call_c, function_name, il_operand_list) |
989 void *visit_expression_type_c::visit(il_function_call_c *symbol) { |
1107 void *visit_expression_type_c::visit(il_function_call_c *symbol) { |
990 if (il_error) |
1108 if (il_error) |
991 return NULL; |
1109 return NULL; |
992 |
1110 |
|
1111 symbol_c *return_data_type = NULL; |
|
1112 |
993 /* First find the declaration of the function being called! */ |
1113 /* First find the declaration of the function being called! */ |
994 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
1114 function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name); |
995 |
1115 function_symtable_t::iterator upper = function_symtable.upper_bound(symbol->function_name); |
996 symbol_c *return_data_type = NULL; |
1116 if (lower == function_symtable.end()) ERROR; |
997 |
1117 |
998 if (f_decl == function_symtable.end_value()) { |
1118 int error_count = 0; |
999 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
1119 int *error_count_ptr = NULL; |
1000 if (current_function_type == function_none) ERROR; |
1120 |
1001 /* This code is for the functions that the user did not declare and that are |
1121 function_symtable_t::iterator second = lower; |
1002 * part of the IL or ST languagem (built-in functions). |
1122 second++; |
1003 * For now we won't do the semantics analysis for that kind of functions. |
1123 if (second != upper) |
1004 */ |
1124 /* This is a call to an overloaded function... */ |
1005 /* |
1125 error_count_ptr = &error_count; |
1006 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
1126 |
1007 if (NULL == return_data_type) ERROR; |
1127 for(; lower != upper; lower++) { |
1008 |
1128 function_declaration_c *f_decl = function_symtable.get_value(lower); |
1009 function_call_param_iterator_c fcp_iterator(symbol); |
|
1010 |
|
1011 int nb_param = 0; |
|
1012 if (symbol->il_param_list != NULL) |
|
1013 nb_param += ((list_c *)symbol->il_param_list)->n; |
|
1014 |
|
1015 identifier_c en_param_name("EN");*/ |
|
1016 /* Get the value from EN param */ |
|
1017 /*symbol_c *EN_param_value = fcp_iterator.search(&en_param_name); |
|
1018 if (EN_param_value == NULL) |
|
1019 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
1020 else |
|
1021 nb_param --; |
|
1022 ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
|
1023 |
|
1024 identifier_c eno_param_name("EN0");*/ |
|
1025 /* Get the value from ENO param */ |
|
1026 /*symbol_c *ENO_param_value = fcp_iterator.search(&eno_param_name); |
|
1027 if (ENO_param_value != NULL) |
|
1028 nb_param --; |
|
1029 ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
1030 |
1129 |
1031 #include "st_code_gen.c" |
1130 check_nonformal_call(symbol, f_decl, true, error_count_ptr); |
1032 */ |
1131 |
1033 } else { |
1132 if (0 == error_count) { |
1034 /* determine the base data type returned by the function being called... */ |
1133 /* Either: |
1035 return_data_type = base_type(f_decl->type_name); |
1134 * (i) we have a call to a non-overloaded function (error_cnt_ptr is NULL!, so error_count won't change!) |
1036 /* If the following occurs, then we must have some big bug in the syntax parser (stage 2)... */ |
1135 * (ii) we have a call to an overloaded function, with no errors! |
1037 if (NULL == return_data_type) ERROR; |
1136 */ |
1038 |
1137 |
1039 /* check semantics of data passed in the function call... */ |
1138 /* Store the pointer to the declaration of the function being called. |
1040 check_nonformal_call(symbol, f_decl, true); |
1139 * This data will be used by stage 4 to call the correct function. |
1041 |
1140 * Mostly needed to disambiguate overloaded functions... |
1042 /* set the new ddata type of the default variable for the following verifications... */ |
1141 * See comments in absyntax.def for more details |
1043 il_default_variable_type = return_data_type; |
1142 */ |
1044 } |
1143 symbol->called_function_declaration = f_decl; |
|
1144 /* determine the base data type returned by the function being called... */ |
|
1145 return_data_type = base_type(f_decl->type_name); |
|
1146 /* If the following occurs, then we must have some big bug in the syntax parser (stage 2)... */ |
|
1147 if (NULL == return_data_type) ERROR; |
|
1148 /* set the new data type of the default variable for the following verifications... */ |
|
1149 il_default_variable_type = return_data_type; |
|
1150 return NULL; |
|
1151 } |
|
1152 } |
|
1153 |
|
1154 /* No compatible function was found for this function call */ |
|
1155 STAGE3_ERROR(symbol, symbol, "Call to an overloaded function with invalid parameter type."); |
1045 return NULL; |
1156 return NULL; |
1046 } |
1157 } |
1047 |
1158 |
1048 |
1159 |
1049 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
1160 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
1159 /* SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) */ |
1270 /* SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) */ |
1160 void *visit_expression_type_c::visit(il_formal_funct_call_c *symbol) { |
1271 void *visit_expression_type_c::visit(il_formal_funct_call_c *symbol) { |
1161 if (il_error) |
1272 if (il_error) |
1162 return NULL; |
1273 return NULL; |
1163 |
1274 |
1164 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
1165 |
|
1166 symbol_c *return_data_type = NULL; |
1275 symbol_c *return_data_type = NULL; |
1167 |
1276 function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name); |
1168 if (f_decl == function_symtable.end_value()) { |
1277 function_symtable_t::iterator upper = function_symtable.upper_bound(symbol->function_name); |
|
1278 |
|
1279 if (lower == function_symtable.end()) { |
1169 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
1280 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
1170 if (current_function_type == function_none) ERROR; |
1281 if (current_function_type == function_none) ERROR; |
1171 |
1282 return NULL; |
1172 /* This code is for the functions that the user did not declare and that are |
1283 } |
1173 * part of the IL or ST languagem (built-in functions). |
1284 |
1174 * For now we won't do the semantics analysis for that kind of functions. |
1285 int error_count = 0; |
1175 */ |
1286 int *error_count_ptr = NULL; |
1176 #if 0 |
1287 |
1177 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
1288 function_symtable_t::iterator second = lower; |
1178 if (NULL == return_data_type) ERROR; |
1289 second++; |
1179 |
1290 if (second != upper) |
1180 function_call_param_iterator_c fcp_iterator(symbol); |
1291 /* This is a call to an overloaded function... */ |
1181 |
1292 error_count_ptr = &error_count; |
1182 int nb_param = 0; |
1293 |
1183 if (symbol->il_param_list != NULL) |
1294 for(; lower != upper; lower++) { |
1184 nb_param += ((list_c *)symbol->il_param_list)->n; |
1295 function_declaration_c *f_decl = function_symtable.get_value(lower); |
1185 |
1296 |
1186 identifier_c en_param_name("EN"); |
|
1187 /* Get the value from EN param */ |
|
1188 symbol_c *EN_param_value = fcp_iterator.search(&en_param_name); |
|
1189 if (EN_param_value == NULL) |
|
1190 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
1191 else |
|
1192 nb_param --; |
|
1193 ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
|
1194 |
|
1195 identifier_c eno_param_name("EN0"); |
|
1196 /* Get the value from ENO param */ |
|
1197 symbol_c *ENO_param_value = fcp_iterator.search(&eno_param_name); |
|
1198 if (ENO_param_value != NULL) |
|
1199 nb_param --; |
|
1200 ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
1201 |
|
1202 #include "st_code_gen.c" |
|
1203 #endif |
|
1204 } else { |
|
1205 /* determine the base data type returned by the function being called... */ |
|
1206 return_data_type = base_type(f_decl->type_name); |
|
1207 /* the following should never occur. If it does, then we have a bug in the syntax parser (stage 2)... */ |
|
1208 if (NULL == return_data_type) ERROR; |
|
1209 |
|
1210 /* check semantics of data passed in the function call... */ |
1297 /* check semantics of data passed in the function call... */ |
1211 check_formal_call(symbol, f_decl); |
1298 check_formal_call(symbol, f_decl, error_count_ptr); |
1212 |
1299 |
1213 /* the data type of the data returned by the function, and stored in the il default variable... */ |
1300 if (0 == error_count) { |
1214 il_default_variable_type = return_data_type; |
1301 /* Either: |
1215 } |
1302 * (i) we have a call to a non-overloaded function (error_cnt_ptr is NULL!, so error_count won't change!) |
|
1303 * (ii) we have a call to an overloaded function, with no errors! |
|
1304 */ |
|
1305 |
|
1306 /* Store the pointer to the declaration of the function being called. |
|
1307 * This data will be used by stage 4 to call the correct function. |
|
1308 * Mostly needed to disambiguate overloaded functions... |
|
1309 * See comments in absyntax.def for more details |
|
1310 */ |
|
1311 symbol->called_function_declaration = f_decl; |
|
1312 /* determine the base data type returned by the function being called... */ |
|
1313 return_data_type = base_type(f_decl->type_name); |
|
1314 /* the following should never occur. If it does, then we have a bug in the syntax parser (stage 2)... */ |
|
1315 if (NULL == return_data_type) ERROR; |
|
1316 /* the data type of the data returned by the function, and stored in the il default variable... */ |
|
1317 il_default_variable_type = return_data_type; |
|
1318 return NULL; |
|
1319 } |
|
1320 } |
|
1321 |
|
1322 /* No compatible function was found for this function call */ |
|
1323 STAGE3_ERROR(symbol, symbol, "Call to an overloaded function with invalid parameter type."); |
1216 return NULL; |
1324 return NULL; |
1217 } |
1325 } |
1218 |
1326 |
1219 |
1327 |
1220 #if 0 |
1328 #if 0 |
1959 return compute_expression(type, type, &visit_expression_type_c::is_ANY_BIT_compatible); |
2067 return compute_expression(type, type, &visit_expression_type_c::is_ANY_BIT_compatible); |
1960 } |
2068 } |
1961 |
2069 |
1962 |
2070 |
1963 void *visit_expression_type_c::visit(function_invocation_c *symbol) { |
2071 void *visit_expression_type_c::visit(function_invocation_c *symbol) { |
1964 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
2072 function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name); |
1965 if (f_decl == function_symtable.end_value()) { |
2073 function_symtable_t::iterator upper = function_symtable.upper_bound(symbol->function_name); |
1966 /* TODO: the following code is for standard library functions. We do not yet support this... */ |
2074 if (lower == function_symtable.end()) ERROR; |
1967 void *res = compute_standard_function_default(symbol); |
2075 |
1968 if (res != NULL) return res; |
2076 function_symtable_t::iterator second = lower; |
1969 ERROR; |
2077 second++; |
1970 } |
2078 if (second == upper) { |
1971 |
2079 /* call to a function that is not overloaded. */ |
1972 /* now check the semantics of the function call... */ |
2080 /* now check the semantics of the function call... */ |
1973 /* If the syntax parser is working correctly, exactly one of the |
2081 /* If the syntax parser is working correctly, exactly one of the |
1974 * following two symbols will be NULL, while the other is != NULL. |
2082 * following two symbols will be NULL, while the other is != NULL. |
1975 */ |
2083 */ |
1976 if (symbol-> formal_param_list != NULL) check_formal_call (symbol, f_decl); |
2084 function_declaration_c *f_decl = function_symtable.get_value(lower); |
1977 if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, f_decl); |
2085 if (symbol-> formal_param_list != NULL) check_formal_call (symbol, f_decl); |
1978 |
2086 if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, f_decl); |
1979 return base_type(f_decl->type_name); |
2087 /* Store the pointer to the declaration of the function being called. |
|
2088 * This data will be used by stage 4 to call the correct function. |
|
2089 * Mostly needed to disambiguate overloaded functions... |
|
2090 * See comments in absyntax.def for more details |
|
2091 */ |
|
2092 symbol->called_function_declaration = f_decl; |
|
2093 return base_type(f_decl->type_name); |
|
2094 } |
|
2095 |
|
2096 /* This is a call to an overloaded function... */ |
|
2097 if (debug) printf("visit_expression_type_c::visit(function_invocation_c *symbol): FOUND CALL TO OVERLOADED FUNCTION!!\n"); |
|
2098 for(; lower != upper; lower++) { |
|
2099 if (debug) printf("visit_expression_type_c::visit(function_invocation_c *symbol): FOUND CALL TO OVERLOADED FUNCTION!! iterating...\n"); |
|
2100 int error_count = 0; |
|
2101 function_declaration_c *f_decl = function_symtable.get_value(lower); |
|
2102 if (symbol-> formal_param_list != NULL) check_formal_call (symbol, f_decl, &error_count); |
|
2103 if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, f_decl, false, &error_count); |
|
2104 if (0 == error_count) { |
|
2105 /* Store the pointer to the declaration of the function being called. |
|
2106 * This data will be used by stage 4 to call the correct function. |
|
2107 * Mostly needed to disambiguate overloaded functions... |
|
2108 * See comments in absyntax.def for more details |
|
2109 */ |
|
2110 symbol->called_function_declaration = f_decl; |
|
2111 return base_type(f_decl->type_name); |
|
2112 } |
|
2113 } |
|
2114 |
|
2115 /* No compatible function was found for this function call */ |
|
2116 STAGE3_ERROR(symbol, symbol, "Call to an overloaded function with invalid parameter type."); |
|
2117 return NULL; |
1980 } |
2118 } |
1981 |
2119 |
1982 /********************/ |
2120 /********************/ |
1983 /* B 3.2 Statements */ |
2121 /* B 3.2 Statements */ |
1984 /********************/ |
2122 /********************/ |