Parsing deferred type parameter
Steve Kargl
sgk@troutmask.apl.washington.edu
Sun Aug 15 18:36:00 GMT 2010
Here's a patch that does the parsing and some
error checking of deferred type parameter.
It is accomplished by adding a bool to gfc_typespec
to note when a deferred type parameter is encountered.
Currently, the patch does
1) Checks that a deferred type parameter does not appear
in an array constructor, ie,
s = [character(len=:) :: 'ab', 'cd'] ! Invalid.
2) Checks that a deferred type parameter does not appear
in an allocate statement, ie,
allocate(character(len=:) :: s) ! Invalid.
3) Checks that a variable declared with a deferred type
parameter has either the pointer or allocatable attribute.
4) Checks that a variable with a deferred type parameter
does not appear in a specification or initialization
expression, ie,
character(len=:), allocatable :: s
integer, parameter :: n = len(s)
5) Prevents errors about assumed shaped arrays and assumed
length characters when a deferred type parameter is
encountered.
For now, if a variable with a deferred type parameter is
used in a program gfortran issues an error that this
feature is not implemented.
Two items are left:
1) Check for any restrictions with actual and dummy arguments.
2) Write the code for trans-* to actually make this feature
work. I suspect that I can use some help from others here;
otherwise, it may take months (years?) to finish this up.
I have only written some limted tests, so I suspect that there
may be issues with things like components of derived types that
use deferred type parameters and function results.
Anyway, to keep this patch from getting lost again in a dusty
corner of my hard drive, I thought I would post it here.
--
Steve
-------------- next part --------------
2010-08-15 Steven G. Kargl <kargl@gcc.gnu.org>
* gfortran.dg/initialization_9.f90: Update error message.
* gfortran.dg/allocate_derived_1.f90: Ditto.
* gfortran.dg/initialization_1.f90: Ditto.
2010-08-15 Steven G. Kargl <kargl@gcc.gnu.org>
* fortran/decl.c (char_len_param_value) Pass a second argument
for parsing a deferred type parameter.
(match_char_length, gfc_match_char_spec): Use it.
* fortran/array.c (gfc_match_array_constructor): type-spec in
an array constructor cannot have a deferred type parameter.
* fortran/gfortran.h: Add a bool 'deferred' component to the
gfc_typespec structure. Fix a typo in a comment.
* fortran/expr.c (check_inquiry): A deferred type parameter variable
cannot appear in len() within a specification or initialization
expression.
* fortran/resolve.c (resolve_charlen): Add a FIXME above the function
as a reminder to recheck this function.
(resolve_fl_var_and_proc): Prevent an error message about a deferred
shape array when the variable has a deferred type parameter.
(resolve_fl_variable): Check that a variable with a deferred type
parameter has the pointer or allocatable attribute. Prevent an
error about an assumed character length when a deferred length
variable is encountered.
* fortran/trans-decl.c (gfc_trans_deferred_vars): Issue a
fatal error when translating a deferred type parameter.
* fortran/match.c (match_type_spec): Remove part of the derive
type checking, which causes problems for intrinsic type-specs in
an allocate statement. Replace 'goto char_selector' with the
4 lines of code to avoid an unnecessary jump.
(gfc_match_allocate): Add deferred_locus and saw_deferred do allow
error checking of deferred type parameter allocate-objects. A
type-spec in an allocate statement cannot have a deferred type
parameter. For an allocate-object with a deferred type parameter
issue an error until full support is available. Check constraint
F2003:C623.
* fortran/misc.c (gfc_clear_ts): Set ts.deferred to false.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: deferred.diff
Type: text/x-diff
Size: 13598 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20100815/0a64a7f2/attachment.bin>
More information about the Fortran
mailing list