Exemple #1
0
char fortran_equivalent_tk_types(type_t* t1, type_t* t2)
{
    type_t* r1 = t1;
    if (is_function_type(r1))
    {
        r1 = function_type_get_return_type(r1);
    }
    r1 = fortran_get_rank0_type_internal(r1, /* ignore pointer */ 1);

    type_t* r2 = t2;
    if (is_function_type(r2))
    {
        r2 = function_type_get_return_type(r2);
    }
    r2 = fortran_get_rank0_type_internal(r2, /* ignore pointer */ 1);

    // Preprocess for character types
    if (fortran_is_character_type(r1))
    {
        r1 = get_unqualified_type(array_type_get_element_type(r1));
    }
    if (fortran_is_character_type(r2))
    {
        r2 = get_unqualified_type(array_type_get_element_type(r2));
    }

    return equivalent_types(get_unqualified_type(r1), get_unqualified_type(r2));
}
 bool Type::is_same_type(Type t) const
 {
     return equivalent_types(this->_type_info, t._type_info);
 }
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;
}