This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR48298 - [F03] User-Defined Derived-Type IO (DTIO)


Dear All,

The attached patch implements the above DTIO feature. This is the
penultimate F2003 feature to be implemented in gfortran. (The last is
Parameterized Derived-Types, which look to be difficult to judge by
the remarks coming from other vendors).

Although fairly long, the patch is straightforward. It includes some
whitespace corrections, which are not remarked upon in the ChangeLogs.

There are four known issues, for which PRs will be raised:
1) DTIO to internal units is not implemented;
2) Inquire length is not implemented;
3) Size = in READ statements is not implemented; and
4) There is a mystery optimization bug, at all levels of optimization,
which causes IF statements to disappear in some of the testcases. This
has been masked by the chunk in trans-decl.c that forces derived-type
and class objects with associated DTIO procedures to be TREE_STATIC.

The testcases dtio_[3,4].f90 are on their way. We had set ourselves
the target of today to submit but the issue #4 derailed the
preparation of these testcases. These will be posted as soon as
possible.

Bootstrapped and regtested on FC21/x86_64 - OK for trunk?

Given that DTIO is only triggered by the specific typebound or generic
interfaces, we intend to commit the patch in one week from today if no
review is forthcoming.

Paul and Jerry

2016-08-22  Paul Thomas  <pault@gcc.gnu.org>
    Jerry DeLisle  <jvdelisle@gcc.gnu.org>

    PR fortran/48298

    * decl.c (access_attr_decl): Include case INTERFACE_DTIO as
    appropriate.
    * gfortran.h : Add INTRINSIC_FORMATTED and
    INTRINSIC_UNFORMATTED to gfc_intrinsic_op. Add INTERFACE_DTIO
    to interface type. Add new enum 'dtio_codes'. Add bitfield
    'has_dtio_procs' to symbol_attr. Add prototypes
    'gfc_check_dtio_interfaces' and 'gfc_find_specific_dtio_proc'.
    * interface.c (dtio_op): New function.
    (gfc_match_generic_spec): Match generic DTIO interfaces.
    (gfc_match_interface): Treat DTIO interfaces in the same way as
    (gfc_current_interface_head): Add INTERFACE_DTIO appropriately.
    (check_dtio_arg_TKR_intent): New function.
    (check_dtio_interface1): New function.
    (gfc_check_dtio_interfaces): New function.
    (gfc_find_specific_dtio_proc): New function.
    * io.c : Add FMT_DT to format_token.
    (format_lex): Handle DTIO formatting.
    * match.c (gfc_op2string): Add DTIO operators.
    * resolve.c (derived_inaccessible): Ignore pointer components
    to enclosing derived type.
    (resolve_transfer): Resolve transfers that involve DTIO.
    procedures. Find the specific subroutine for the transfer and
    use its existence to over-ride some of the constraints on
    derived types.
    (dtio_procs_present): New function.
    (resolve_fl_namelist): Remove inhibition of polymorphic objects
    in namelists if DTIO read and write subroutines exist. Likewise
    for derived types.
    (resolve_types): Invoke 'gfc_verify_dtio_procedures'.
    * symbol.c : Set 'dtio_procs' using 'minit'.
    * trans-decl.c (gfc_finish_var_decl): If a derived-type/class
    object is associated with DTIO procedures, make it TREE_STATIC.
    * trans-expr.c (gfc_conv_derived_to_class): Check 'info' in the
    test for 'useflags'. If the se expression exists and is a
    pointer, use it as the class _data.
    * trans-io.c : Add IOCALL_X_DERIVED to iocall and the function
    prototype. Add two new arguments to IOCALL_SET_NML_VAL.
    (set_parameter_tree): Renamed from 'set_parameter_const', now
    returns void and has new tree argument. Calls modified to match
    new interface.
    (transfer_namelist_element): Transfer DTIO procedure pointer
    and the table to the vpointer, using the two new arguments of
    IOCALL_SET_NML_VAL.
    (get_dtio_proc): New function.
    (transfer_expr): Add new argument for the vptr field of class
    objects. Add the code to call the specific DTIO proc, convert
    derived types to class and call IOCALL_X_DERIVED.
    (trans_transfer): Add BT_CLASS to structures for treatment by
    the scalarizer. Obtain the vptr for the dynamic type, both for
    scalar and array transfer.

2016-08-22  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
    Paul Thomas  <pault@gcc.gnu.org>

    PR libgfortran/48298
    * gfortran.map : Flag _gfortran_transfer_derived.
    * io/format.c (format_lex): Detect DTIO formatting.
    (parse_format_list): Parse the DTIO format.
    (next_format): Include FMT_DT.
    * io/format.h : Likewise. Add structure 'udf' to structure
    'fnode' to carry the IOTYPE string and the 'vlist'.
    * io/io.h : Add prototypes for the two types of DTIO subroutine
    and a typedef for gfc_class. Also, add to 'namelist_type'
    fields for the pointer to the DTIO procedure and the vtable.
    Add fields to struct st_parameter_dt for pointers to the two
    types of DTIO subroutine. Add to gfc_unit DTIO specific fields.
    (internal_proto): Add prototype for 'read_user_defined' and
    'write_user_defined'.
    * io/list_read.c (check_buffers): Use the 'current_unit' field.
    (unget_char): Likewise.
    (eat_spaces): Likewise.
    (list_formatted_read_scalar): For case BT_CLASS, call the DTIO
    procedure.
    (nml_get_obj_data): Likewise when DTIO procedure is present.
    * io/transfer.c : Export prototypes for 'transfer_derived' and
    'transfer_derived_write'.
    (unformatted_read): For case BT_CLASS, call the DTIO procedure.
    (unformatted_write): Likewise.
    (formatted_transfer_scalar_read): Likewise.
    (formatted_transfer_scalar_write: Likewise.
    (transfer_derived): New function.
    (data_transfer_init): Set last_char if no child_dtio.
    (finalize_transfer): Return if child_dtio set.
    (st_write_done): Add condition for child_dtio not set.
    Add extra arguments for st_set_nml_var prototype.
    (st_set_nml_var): Set the 'dtio_sub' and 'vtable' fields of the
    'nml' structure.
    * io/unix.c (tempfile_open): Revert to C style comment.
    * io/write.c (list_formatted_write_scalar): Do the DTIO call.
    (nml_write_obj): Add BT_CLASS and do the DTIO call.

2016-08-22  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
    Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/48298
    * gfortran.dg/dtio_1.f90: New test.
    * gfortran.dg/dtio_2.f90: New test.
    * gfortran.dg/dtio_5.f90: New test.
    * gfortran.dg/dtio_6.f90: New test.
    * gfortran.dg/dtio_7.f90: New test.
    * gfortran.dg/dtio_8.f90: New test.
    * gfortran.dg/dtio_9.f90: New test.
    * gfortran.dg/dtio_10.f90: New test.

Attachment: submit.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]