ObjectList<Type> Type::parameters(bool& has_ellipsis) const { has_ellipsis = function_type_get_has_ellipsis(_type_info); ObjectList<Type> result; for (int i = 0; i < function_type_get_num_parameters(_type_info); i++) { // The last one is the ellipsis and lacks type if (has_ellipsis && ((i + 1) == function_type_get_num_parameters(_type_info))) { break; } Type t(function_type_get_parameter_type_num(_type_info, i)); result.push_back(t); } return result; }
type_t* fortran_replace_return_type_of_function_type(type_t* function_type, type_t* new_return_type) { ERROR_CONDITION(!is_function_type(function_type), "Must be a function type", 0); int num_parameters = function_type_get_num_parameters(function_type); if (!function_type_get_lacking_prototype(function_type)) { parameter_info_t parameter_info[1 + num_parameters]; memset(¶meter_info, 0, sizeof(parameter_info)); int i; for (i = 0; i < num_parameters; i++) { parameter_info[i].type_info = function_type_get_parameter_type_num(function_type, i); } return get_new_function_type(new_return_type, parameter_info, num_parameters); } else { return get_nonproto_function_type(new_return_type, num_parameters); } }
static type_t* solve_spu_overload_name(scope_entry_t* overloaded_function, AST* arguments, int num_arguments) { // Why people insists on having overload in C? char name[256]; // From gcc source at maximum 16 are defined const int max_valid_overloads = 24; char found_match = 0; type_t* result = NULL; DEBUG_CODE() { fprintf(stderr, "SPU-BUILTIN: Trying to figure out the exact version of '%s' given the following %d arguments\n", overloaded_function->symbol_name, num_arguments); int j; for (j = 0; j < num_arguments; j++) { fprintf(stderr, "SPU-BUILTIN: [%d] %s\n", j, print_declarator(ASTExprType(arguments[j]), overloaded_function->decl_context)); } } int i; for (i = 0; (i < max_valid_overloads) && !found_match; i++) { snprintf(name, 255, "%s_%d", overloaded_function->symbol_name, i); name[255] = '\0'; scope_entry_list_t *entry_list = query_unqualified_name_str(overloaded_function->decl_context, name); // Let's assume no more overloads have been defined if (entry_list == NULL) { break; } scope_entry_t* current_entry = entry_list->entry; type_t* current_function_type = current_entry->type_information; DEBUG_CODE() { fprintf(stderr, "SPU-BUILTIN: Checking with builtin '%s' of type '%s'\n", current_entry->symbol_name, print_declarator(current_function_type, overloaded_function->decl_context)); } if (!is_function_type(current_function_type)) { internal_error("spu builtin '%s' without function type\n", current_entry); } // Don't know if this case is considered but let's be kind with this crazy SDK if (num_arguments != function_type_get_num_parameters(current_function_type)) { continue; } int j; char all_arguments_matched = 1; for (j = 0; (j < num_arguments) && all_arguments_matched; j++) { type_t* argument_type = ASTExprType(arguments[j]); all_arguments_matched = all_arguments_matched && equivalent_types(argument_type, function_type_get_parameter_type_num(current_function_type, j), overloaded_function->decl_context); } if (all_arguments_matched) { DEBUG_CODE() { fprintf(stderr, "SPU-BUILTIN: Builtin '%s' of type '%s' matched!\n", current_entry->symbol_name, print_declarator(current_function_type, overloaded_function->decl_context)); } result = current_function_type; found_match = 1; } } return result; }