Hi All!

Proposed patch to:

Bug 101047 - Pointer explicit initialization fails
Bug 101048 - Class pointer explicit initialization refuses valid

Patch tested only on x86_64-pc-linux-gnu.

This patch deals with implementation of explicit initialization for pointer variables.

It basically relies on using "gfc_conv_expr_descriptor" to build a pointer assignment and re-parsing it back into a descriptor constructor.

It proceeds to implement the necessary differences between allocatable and pointer variables explicit initialization and to add, and correct, missing references to "CLASS_DATA" entities.

Thank you very much.

Best regards,
José Rui

Fortran: get pointer explicit initialization working.

gcc/fortran/ChangeLog:

        PR fortran/10148
        * class.c (gfc_class_initializer): only disassociate pointer if
        explicitly requested.
        PR fortran/10148
        * expr.c (gfc_check_assign_symbol): get rank from CLASS_DATA if
        necessary.
        PR fortran/10147
        * expr.c (class_allocatable): remove unnecessary auxiliary
        function.
        (class_pointer): remove unnecessary auxiliary function.
        (comp_allocatable): consolidate allocatable attribute checking.
        (comp_pointer): consolidate pointer attribute checking.
        * gfortran.h (gfc_class_initializer): change prototype to reflect
        the extra parameter.
        * trans-array.c: new group of functions to re-parse a
        "STATEMENT_LIST" back into a "CONSTRUCTOR".
        (build_init_dtype): Create a new dtype constructor.
        (build_init_desc_dtype): Find the old dtype constructor and create
        a new one.
        (append_init_dim): Append one of dim fields to vector.
        (build_init_dim): Create a dim constructor.
        (build_init_desc_dim): Create the dim array constructor.
        (append_desc_field): Append a field to the constructor vector.
        (build_init_descriptor): Create an array descriptor constructor.
        (gfc_build_init_descriptor_dtype): new function to build a
        descriptor containing only a dtype.
        (gfc_build_null_descriptor): update function to nullify and add
        the dtype.
        (gfc_build_init_descriptor): new function to build a full array
        descriptor constructor.
        (gfc_trans_static_array_pointer): updated to take in consideration
        the diferences between pointer and allocatable explicit
        initialization and the initialization of entities containing
        "CLASS_DATA".
        (gfc_conv_array_initializer): change function calls to reflect
        interface changes.
        * trans-array.h (gfc_trans_static_array_pointer): add return
        value.
        (gfc_build_null_descriptor): add parameter to prototype.
        (gfc_build_init_descriptor): new prototype.
        * trans-common.c (create_common): change function call to reflect
        interface changes.
        * trans-decl.c (gfc_create_string_length): set initial deferred
        character length to zero.
        (gfc_get_symbol_decl): change function call to reflect interface
        changes.
        (get_proc_pointer_decl): change function call to reflect interface
        changes.
        (gfc_trans_deferred_vars): change function call to reflect
        interface changes.
        (gfc_emit_parameter_debug_info): get rank from CLASS_DATA if
        necessary, change function call to reflect interface changes.
        * trans-expr.c (gfc_class_unlimited_poly): new auxiliary function
        to check if a tree representing a type is unlimited polymorphic.
        (gfc_conv_initializer): renamed gfc_conv_initializer_common.
        (gfc_conv_initializer_common): take in consideration differences
        between pointers and allocatables in initialization.
        (gfc_conv_sym_initializer): interface for initialization using
        gfc_symbol.
        (gfc_conv_comp_initializer): interface for initialization using
        gfc_component.
        (gfc_conv_expr_initializer): interface for initialization using
        gfc_expr.
        (gfc_trans_subcomponent_assign): change function call to reflect
        interface changes.
        (gfc_conv_union_initializer): change function call to reflect
        interface changes.
        (gfc_conv_structure): split in two divide between explicit
        initialization default initialization.
        (gfc_conv_structure_initializer): handles explicit initialization
        of every component field.
        (gfc_conv_expr): change function call to reflect interface
        changes.
        * trans-types.c (gfc_get_dtype_rank_type): if the "static_flag" is
        set elem_len to the initial value, from "DECL_INITIAL", or zero.
        * trans-types.h (gfc_get_dtype_rank_type): add parameter to
        prototype.
        * trans.c: new group of functions to extract a RHS from a
        "CONSTRUCTOR" or a "STATEMENT_LIST" or a "MODIFY_EXPR".
        (tree_ref_equal): simple tree equality check.
        (gfc_get_expr_from_chain): Get RHS for given LHS in a
        "MODIFY_EXPR".
        (gfc_get_expr_from_ctor): Get value from "CONSTRUCTOR".
        * trans.h (gfc_class_unlimited_poly): new prototype.
        (gfc_conv_structure): replaced by gfc_conv_structure_initializer.
        (gfc_conv_structure_initializer): new prototype.
        (gfc_get_expr_from_chain): new prototype.
        (gfc_get_expr_from_ctor): new prototype.
        (gfc_conv_initializer): replaced by the gfc_conv_*_initializer
        functions.
        (gfc_conv_sym_initializer): new prototype.
        (gfc_conv_comp_initializer): new prototype.
        (gfc_conv_expr_initializer): new prototype.

gcc/testsuite/ChangeLog:

        * gfortran.dg/class_allocate_14.f90: update regex.
        * gfortran.dg/init_flag_19.f03: update regex.
        * gfortran.dg/init_workout.f90: New test.

  • [Patch, fortran] PR fortran/10... José Rui Faustino de Sousa via Gcc-patches

Reply via email to