Exemple #1
0
    ObjectList<Symbol> Scope::get_symbols_from_name(const std::string& str) const
    {
        ObjectList<Symbol> result;
        // Fix this for C++
        scope_entry_list_t* entry_list = query_unqualified_name_str(_decl_context, const_cast<char*>(str.c_str()));

        convert_to_vector(entry_list, result);

        return result;
    }
scope_entry_t* query_name_no_implicit(decl_context_t decl_context, const char* name)
{
    scope_entry_list_t* entry_list = query_unqualified_name_str(decl_context, strtolower(name));

    scope_entry_t* result = NULL;

    if (entry_list != NULL )
    {
        result = entry_list_head(entry_list);
        entry_list_free(entry_list);
    }

    return result;
}
scope_entry_t* query_name_no_implicit_or_builtin(decl_context_t decl_context, const char* name)
{
    scope_entry_list_t* entry_list = query_unqualified_name_str(decl_context, strtolower(name));

    scope_entry_t* result = NULL;

    if (entry_list != NULL )
    {
        result = entry_list_head(entry_list);
        entry_list_free(entry_list);

        if (result->entity_specs.is_builtin)
            result = NULL;
    }

    return result;
}
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;
}