[Patch, fortran] Implementation of F2018 SELECT RANK

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Patch, fortran] Implementation of F2018 SELECT RANK

Paul Richard Thomas
When I started on this about three months ago, I thought that with
SELECT TYPE as a template this was going to be low hanging fruit. Not
so :-)

Among the issues on the way were: class selectors; unlimited
polymorphic selectors even more so; and error recovery. It's a good
starting point but I am not holding my breath for it being PR-free.

It will be noted that the select rank temporaries are also select type
temporaries. This simplifies some of the logic, especially in
resolution, and allows RANK DEFAULT to be handled in the same way as
CLASS DEFAULT in trans-stmt.c.

In the new function, trans-stmt.c(copy_descriptor), memcpy is used to
copy-in/copy-out sections of the dim[] array between the case
descriptor and the assumed rank selector. This avoids explicitly
copying the bounds and strides or messing around trying to convert the
types. There is maybe a better way to do this but I didn't find it.

While I was about it, I made the code in some of the SELECT TYPE
matching much more readable by using a gfc_symbol *selector =

Bootstraps and regtests on FC29/x86_64 - OK for trunk?

Now on to PDTs....


2019-08-31  Paul Thomas  <[hidden email]>

    * array.c (spec_dimen_size): Check for the presence of
    expressions for the bounds.
    * decl.c (gfc_match_end): Add case COMP_SELECT_RANK.
    * dump-parse-tree.c(show_symbol): Show the arrayspec of class
    (show_code_node): Show the code for SELECT_RANK.
    * expr.c (gfc_check_vardef_context): Omit the context of
    variable definition for select rank associate names since the
    ASSUMED RANK throws.
    * gfortran.h : Add ST_SELECT_RANK and ST_RANK to enum
    gfc_statement. Add select_rank_temporary to symbol attribute
    structure. Add EXEC_SELECT_RANK to enum gfc_exec_op.
    * match.c (match_exit_cycle): Add COMP_SELECT_RANK.
    (copy_ts_from_selector_to_associate): Add as special case for
    assumed rank class variables.
    (select_intrinsic_set_tmp): Clean up the code by using symbols
    for references to the temporary and the selector.
    (select_type_set_tmp): Ditto.
    (select_rank_set_tmp): New function.
    (gfc_match_select_rank): New function.
    (gfc_match_rank_is): New function.
    * match.h : Add prototypes for gfc_match_select_rank and
    * parse.c (decode_statement): Attempt to match select_rank and
    rank statements.
    (next_statement, gfc_ascii_statement): Add ST_SELECT_RANK.
    (parse_select_rank_block): New function.
    (parse_executable): Parse select rank block for ST_SELECT_RANK.
    * parse.h : Add COMP_SELECT_RANK to enum gfc_compile_state.
    * resolve.c (resolve_variable): Exclude select_rank_temporaries
    from the check on use of ASSUMED RANK.
    (gfc_resolve_expr): Make sure that unlimited polymorphic select
    rank temporaries expressions are not resolved again after being
    successfully resolved.
    (resolve_assoc_var): Do not do the rank check for select rank
    (resolve_select_rank): New function.
    (gfc_resolve_blocks): Deal with case EXEC_SELECT_RANK.
    (resolve_symbol): Exclude select rank temporaries for check on
    use of ASSUMED RANK.
    * st.c (gfc_free_statement): Include EXEC_SELECT_RANK.
    * trans-array.c (gfc_conv_array_ref): Select rank temporaries
    may have dimen == 0.
    (gfc_conv_expr_descriptor): Zero the offset of select rank
    * trans-stmt.c (copy_descriptor): New function.
    (trans_associate_var): Add code to associate select rank temps.
    (gfc_trans_select_rank_cases): New function.
    (gfc_trans_select_rank): New function.
    * trans-stmt.h : Add prototype for gfc_trans_select_rank.
    trans.c (trans_code): Add select rank case.

2019-08-31  Paul Thomas  <[hidden email]>

    * gfortran.dg/select_rank_1.f90 : New test.

submit.diff (88K) Download Attachment