stage3/narrow_candidate_datatypes.cc
changeset 428 42d02558ebd9
parent 427 eb9bc99944d9
child 438 744b125d911e
equal deleted inserted replaced
427:eb9bc99944d9 428:42d02558ebd9
  1023 void *narrow_candidate_datatypes_c::visit(function_invocation_c *symbol) {
  1023 void *narrow_candidate_datatypes_c::visit(function_invocation_c *symbol) {
  1024 	int  ext_parm_count;
  1024 	int  ext_parm_count;
  1025 
  1025 
  1026 	/* set the called_function_declaration. */
  1026 	/* set the called_function_declaration. */
  1027 	symbol->called_function_declaration = NULL;
  1027 	symbol->called_function_declaration = NULL;
  1028 #if 0
  1028 
  1029 	if (symbol->candidate_datatypes.size() == 1) {
  1029 	/* set the called_function_declaration taking into account the datatype that we need to return */
  1030 		/* If only one possible called function, then that is the function to call!
  1030 	for(unsigned int i = 0; i < symbol->candidate_datatypes.size(); i++) {
  1031 		 * In this case we ignore the symbol->datatype value (that may even be NULL).
  1031 		if (is_type_equal(symbol->candidate_datatypes[i], symbol->datatype)) {
  1032 		 * This helps in identifying potential errors in the expressions used inside this function call
  1032 			symbol->called_function_declaration = symbol->candidate_functions[i];
  1033 		 * even if there is a previous error, allowing us to make a more thorough analysis of the semantics
  1033 			break;
  1034 		 * of the ST code, and providing as many relevant error messages as possible!
  1034 		}
  1035 		 * If symbol->datatype isn't NULL, then this chosen function should be returning the required datatype,
  1035 	}
  1036 		 * otherwise we have a bug in our stage3 code!
  1036 
  1037 		 */
       
  1038 		symbol->called_function_declaration = symbol->candidate_functions[0];
       
  1039 		if ((NULL != symbol->datatype) && (!is_type_equal(symbol->candidate_datatypes[0], symbol->datatype)))
       
  1040 			ERROR;
       
  1041 	} else
       
  1042 #endif	
       
  1043 	{
       
  1044 		/* set the called_function_declaration taking into account the datatype that we need to return */
       
  1045 		for(unsigned int i = 0; i < symbol->candidate_datatypes.size(); i++) {
       
  1046 			if (is_type_equal(symbol->candidate_datatypes[i], symbol->datatype)) {
       
  1047 				symbol->called_function_declaration = symbol->candidate_functions[i];
       
  1048 				break;
       
  1049 			}
       
  1050 		}
       
  1051 	}
       
  1052 	/* NOTE: If we can't figure out the declaration of the function being called, this is not 
  1037 	/* NOTE: If we can't figure out the declaration of the function being called, this is not 
  1053 	 *       necessarily an internal compiler error. It could be because the symbol->datatype is NULL
  1038 	 *       necessarily an internal compiler error. It could be because the symbol->datatype is NULL
  1054 	 *       (because the ST code being analysed has an error _before_ this function invocation).
  1039 	 *       (because the ST code being analysed has an error _before_ this function invocation).
  1055 	 *       However, we don't just give, up, we carry on recursivly analysing the code, so as to be
  1040 	 *       However, we don't just give, up, we carry on recursivly analysing the code, so as to be
  1056 	 *       able to print out any error messages related to the parameters being passed in this function 
  1041 	 *       able to print out any error messages related to the parameters being passed in this function 
  1057 	 *       invocation.
  1042 	 *       invocation.
  1058 	 */
  1043 	 */
  1059 	/* if (NULL == symbol->called_function_declaration) ERROR; */
  1044 	/* if (NULL == symbol->called_function_declaration) ERROR; */
  1060 
       
  1061 	if (symbol->candidate_datatypes.size() == 1) {
  1045 	if (symbol->candidate_datatypes.size() == 1) {
  1062 		/* If only one function declaration, then we use that (even if symbol->datatypes == NULL)
  1046 		/* If only one function declaration, then we use that (even if symbol->datatypes == NULL)
  1063 		 * so we can check for errors in the expressions used to pass parameters in this
  1047 		 * so we can check for errors in the expressions used to pass parameters in this
  1064 		 * function invocation.
  1048 		 * function invocation.
  1065 		 */
  1049 		 */
  1066 		symbol->called_function_declaration = symbol->candidate_functions[0];
  1050 		symbol->called_function_declaration = symbol->candidate_functions[0];
  1067 	}
  1051 	}
       
  1052 
  1068 	/* If an overloaded function is being invoked, and we cannot determine which version to use,
  1053 	/* If an overloaded function is being invoked, and we cannot determine which version to use,
  1069 	 * then we can not meaningfully verify the expressions used inside that function invocation.
  1054 	 * then we can not meaningfully verify the expressions used inside that function invocation.
  1070 	 * We simply give up!
  1055 	 * We simply give up!
  1071 	 */
  1056 	 */
  1072 	if (NULL == symbol->called_function_declaration) {
  1057 	if (NULL == symbol->called_function_declaration)
  1073 printf("giving up!\n");
  1058 		return NULL;
  1074 		return NULL;
       
  1075 	}
       
  1076 
  1059 
  1077 	if (NULL != symbol->nonformal_param_list)  narrow_nonformal_call(symbol, symbol->called_function_declaration, &ext_parm_count);
  1060 	if (NULL != symbol->nonformal_param_list)  narrow_nonformal_call(symbol, symbol->called_function_declaration, &ext_parm_count);
  1078 	if (NULL != symbol->   formal_param_list)     narrow_formal_call(symbol, symbol->called_function_declaration, &ext_parm_count);
  1061 	if (NULL != symbol->   formal_param_list)     narrow_formal_call(symbol, symbol->called_function_declaration, &ext_parm_count);
  1079 	symbol->extensible_param_count = ext_parm_count;
  1062 	symbol->extensible_param_count = ext_parm_count;
  1080 
  1063