stage3/print_datatypes_error.cc
changeset 430 d7a6221f64d7
parent 428 42d02558ebd9
child 431 5792016eedd8
equal deleted inserted replaced
429:26bec44c591f 430:d7a6221f64d7
  1031 	bool function_invocation_error = false;
  1031 	bool function_invocation_error = false;
  1032 
  1032 
  1033 	if ((NULL != symbol->formal_param_list) && (NULL != symbol->nonformal_param_list)) 
  1033 	if ((NULL != symbol->formal_param_list) && (NULL != symbol->nonformal_param_list)) 
  1034 		ERROR;
  1034 		ERROR;
  1035 
  1035 
       
  1036 	symbol_c *f_decl = symbol->called_function_declaration;
       
  1037 	if (NULL == symbol->called_function_declaration) {
       
  1038 		STAGE3_ERROR(0, symbol, symbol, "Unable to resolve which overloaded function '%s' is being invoked.", ((identifier_c *)symbol->function_name)->value);
       
  1039 		/* we now try to find any function declaration with the same name, just so we can provide some relevant error messages */
       
  1040 		function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);
       
  1041 		if (lower == function_symtable.end()) ERROR;
       
  1042 		f_decl = function_symtable.get_value(lower);
       
  1043 	}
       
  1044 
  1036 	if (NULL != symbol->formal_param_list) {
  1045 	if (NULL != symbol->formal_param_list) {
  1037 		symbol->formal_param_list->accept(*this);
  1046 		symbol->formal_param_list->accept(*this);
  1038 		while ((param_name = fcp_iterator.next_f()) != NULL) {
  1047 		if (NULL != f_decl) {
  1039 			param_value = fcp_iterator.get_current_value();
  1048 			function_param_iterator_c fp_iterator(f_decl);
  1040 			if (NULL == param_value->datatype) {
  1049 			while ((param_name = fcp_iterator.next_f()) != NULL) {
  1041 				function_invocation_error = true;
  1050 				param_value = fcp_iterator.get_current_value();
  1042 				STAGE3_ERROR(0, symbol, symbol, "Invalid parameter '%s' in function invocation: %s", ((identifier_c *)param_name)->value, ((identifier_c *)symbol->function_name)->value);
  1051 				/* Find the corresponding parameter in function declaration */
       
  1052 				if (NULL == fp_iterator.search(param_name)) {
       
  1053 					STAGE3_ERROR(0, symbol, symbol, "Invalid parameter '%s' when invoking function '%s'", ((identifier_c *)param_name)->value, ((identifier_c *)symbol->function_name)->value);		  
       
  1054 				} else if (NULL == param_value->datatype) {
       
  1055 					function_invocation_error = true;
       
  1056 					STAGE3_ERROR(0, symbol, symbol, "Data type incompatibility between parameter '%s' and value being passed, when invoking function '%s'", ((identifier_c *)param_name)->value, ((identifier_c *)symbol->function_name)->value);
       
  1057 				}
  1043 			}
  1058 			}
  1044 		}
  1059 		}
  1045 	}
  1060 	}
  1046 	if (NULL != symbol->nonformal_param_list) {
  1061 	if (NULL != symbol->nonformal_param_list) {
  1047 		symbol->nonformal_param_list->accept(*this);
  1062 		symbol->nonformal_param_list->accept(*this);
  1048 		for (int i = 1; (param_value = fcp_iterator.next_nf()) != NULL; i++) {
  1063 		if (f_decl)
  1049 			if (NULL == param_value->datatype) {
  1064 			for (int i = 1; (param_value = fcp_iterator.next_nf()) != NULL; i++) {
  1050 				function_invocation_error = true;
  1065 				if (NULL == param_value->datatype) {
  1051 				STAGE3_ERROR(0, symbol, symbol, "Invalid parameter (position %d) in function invocation: %s", i, ((identifier_c *)symbol->function_name)->value);
  1066 					function_invocation_error = true;
       
  1067 					STAGE3_ERROR(0, symbol, symbol, "Data type incompatibility for value passed in position %d when invoking function '%s'", i, ((identifier_c *)symbol->function_name)->value);
       
  1068 				}
  1052 			}
  1069 			}
  1053 		}
       
  1054 	}
  1070 	}
  1055 
  1071 
  1056 	if (function_invocation_error) {
  1072 	if (function_invocation_error) {
  1057 		/* No compatible function exists */
  1073 		/* No compatible function exists */
  1058 		STAGE3_ERROR(2, symbol, symbol, "Invalid parameters in function invocation: %s", ((identifier_c *)symbol->function_name)->value);
  1074 		STAGE3_ERROR(2, symbol, symbol, "Invalid parameters when invoking function '%s'", ((identifier_c *)symbol->function_name)->value);
  1059 	} 
  1075 	} 
  1060 
  1076 
  1061 	return NULL;
  1077 	return NULL;
  1062 }
  1078 }
  1063 
  1079 
  1107 		symbol->formal_param_list->accept(*this);
  1123 		symbol->formal_param_list->accept(*this);
  1108 		while ((param_name = fcp_iterator.next_f()) != NULL) {
  1124 		while ((param_name = fcp_iterator.next_f()) != NULL) {
  1109 			param_value = fcp_iterator.get_current_value();
  1125 			param_value = fcp_iterator.get_current_value();
  1110 			if (NULL == param_value->datatype) {
  1126 			if (NULL == param_value->datatype) {
  1111 				function_invocation_error = true;
  1127 				function_invocation_error = true;
  1112 				STAGE3_ERROR(0, symbol, symbol, "Invalid parameter '%s' in function invocation: %s", ((identifier_c *)param_name)->value, ((identifier_c *)symbol->fb_name)->value);
  1128 				STAGE3_ERROR(0, symbol, symbol, "Invalid parameter '%s' in FB invocation: %s", ((identifier_c *)param_name)->value, ((identifier_c *)symbol->fb_name)->value);
  1113 			}
  1129 			}
  1114 		}
  1130 		}
  1115 	}
  1131 	}
  1116 	if (NULL != symbol->nonformal_param_list) {
  1132 	if (NULL != symbol->nonformal_param_list) {
  1117 		symbol->nonformal_param_list->accept(*this);
  1133 		symbol->nonformal_param_list->accept(*this);
  1118 		for (int i = 1; (param_value = fcp_iterator.next_nf()) != NULL; i++) {
  1134 		for (int i = 1; (param_value = fcp_iterator.next_nf()) != NULL; i++) {
  1119 			if (NULL == param_value->datatype) {
  1135 			if (NULL == param_value->datatype) {
  1120 				function_invocation_error = true;
  1136 				function_invocation_error = true;
  1121 				STAGE3_ERROR(0, symbol, symbol, "Invalid parameter (position %d) in function invocation: %s", i, ((identifier_c *)symbol->fb_name)->value);
  1137 				STAGE3_ERROR(0, symbol, symbol, "Invalid parameter (position %d) in FB invocation: %s", i, ((identifier_c *)symbol->fb_name)->value);
  1122 			}
  1138 			}
  1123 		}
  1139 		}
  1124 	}
  1140 	}
  1125 
  1141 
  1126 	if (function_invocation_error) {
  1142 	if (function_invocation_error) {