Пример #1
0
type_t* fortran_update_basic_type_with_type(type_t* type_info, type_t* basic_type)
{
    if (is_error_type(basic_type))
        return basic_type;

    // Many functions drop the reference type, so chek it the first
    if (is_lvalue_reference_type(type_info))
    {
        return get_lvalue_reference_type(
                fortran_update_basic_type_with_type(reference_type_get_referenced_type(type_info), basic_type));
    }
    else if (is_pointer_type(type_info))
    {
        return get_pointer_type(
                fortran_update_basic_type_with_type(pointer_type_get_pointee_type(type_info), basic_type)
                );
    }
    else if (fortran_is_array_type(type_info))
    {
        return get_array_type_bounds(
                fortran_update_basic_type_with_type(array_type_get_element_type(type_info), basic_type),
                array_type_get_array_lower_bound(type_info),
                array_type_get_array_upper_bound(type_info),
                array_type_get_array_size_expr_context(type_info));

    }
    else if (is_function_type(type_info))
    {
        return fortran_replace_return_type_of_function_type(type_info, basic_type);
    }
    else
    {
        return basic_type;
    }
}
    Type Type::get_array_to(Nodecl::NodeclBase lower_bound, Nodecl::NodeclBase upper_bound, Scope sc)
    {
        type_t* result_type = this->_type_info;

        const decl_context_t* decl_context = sc.get_decl_context();

        type_t* array_to = get_array_type_bounds(result_type,
                lower_bound.get_internal_nodecl(),
                upper_bound.get_internal_nodecl(),
                decl_context);

        return Type(array_to);
    }
Пример #3
0
type_t* fortran_rebuild_array_type(type_t* rank0_type, type_t* array_type)
{
    rank0_type = no_ref(rank0_type);

    ERROR_CONDITION(!fortran_is_scalar_type(rank0_type)
            && !fortran_is_character_type(rank0_type), "Invalid rank0 type", 0);

    if (!fortran_is_array_type(array_type))
    {
        return rank0_type;
    }
    else
    {
        type_t* t = fortran_rebuild_array_type(rank0_type, array_type_get_element_type(array_type));

        if (array_type_has_region(array_type))
        {
            return get_array_type_bounds_with_regions(t, 
                    array_type_get_array_lower_bound(array_type),
                    array_type_get_array_upper_bound(array_type),
                    array_type_get_array_size_expr_context(array_type),
                    // Why did we do this so difficult?
                    nodecl_make_range(
                        nodecl_shallow_copy(array_type_get_region_lower_bound(array_type)),
                        nodecl_shallow_copy(array_type_get_region_upper_bound(array_type)),
                        nodecl_shallow_copy(array_type_get_region_stride(array_type)),
                        fortran_get_default_integer_type(),
                        make_locus("", 0, 0)),
                    array_type_get_region_size_expr_context(array_type)
                    );
        }
        else if (array_type_with_descriptor(array_type))
        {
            return get_array_type_bounds_with_descriptor(t, 
                    array_type_get_array_lower_bound(array_type),
                    array_type_get_array_upper_bound(array_type),
                    array_type_get_array_size_expr_context(array_type));
        }
        else 
        {
            return get_array_type_bounds(t, 
                    array_type_get_array_lower_bound(array_type),
                    array_type_get_array_upper_bound(array_type),
                    array_type_get_array_size_expr_context(array_type));
        }
    }
}