[Patch, fortran] PR34429 PR34431 and PR34471 - function type characteristics
Paul Richard Thomas
paul.richard.thomas@gmail.com
Tue Jan 15 13:23:00 GMT 2008
:ADDPATCH fortran:
This patch fixes function type specification where one of the
characteristics is deferred from the declaration; eg.
real (kind = mykind) function foo ()
use my_module, only: mykind
or
type(mytype) function bar ()
type mytype
integer :: cpt
end type mytype
The first steps to fix this kind of problem had already been made by,
in certain cases, signalling a deferred characteristic by setting kind
= -1 and, on detecting this, matching the declaration again. This
patch is different in that all function declarations have their
typespec association deferred until a point in the specification block
that is after IMPORT and USE statements for KIND expressions and after
the entire block for derived types. A specialist decode_statement,
which only treats specification expressions has been broken out of the
original and is used to signal the point where typespec association
can occur. A less clumsy method could be implemented but this has the
advantage of clarity, should problems arise. One important feature of
this patch is that the declared_at of the function symbol now points
to the function declaration, rather than the first reference. This
has the advantage that error messages are often clearer and several
existing testcases have had to be changed.
A sticking point over the last few days has been a regression caused
by incorrect use of error checking. This caused a lot of problems:
real (kind(0d0)) function foo ()
foo = real (kind (foo))
end function
as did its incorrect counterpart
real (wrong(0d0)) function foo ()
foo = real (kind (foo))
end function
Both these problems are fixed in this patch, although some extra tests
will have to be added for the latter. I will work on these in the
next days.
The testcases are basically those of the reporters.
Bootstrapped and regtested on x86_ia64/FC8 - OK for trunk?
(I will check CP2K and its ilk before committing).
Paul
2008-01-14 Paul Thomas <pault@gcc.gnu.org>
PR fortran/34429
PR fortran/34431
PR fortran/34471
* decl.c : Remove gfc_function_kind_locus and
gfc_function_type_locus. Add gfc_matching_function.
(match_char_length): If matching a function and the length
does not match, return MATCH_YES and try again later.
(gfc_match_kind_spec): The same.
(match_char_kind): The same.
(gfc_match_type_spec): The same for numeric and derived types.
(match_prefix): Rename as gfc_match_prefix.
(gfc_match_function_decl): Except for function valued character
lengths, defer applying kind, type and charlen info until the
end of specification block.
(gfortran.h): Add ST_GET_FCN_CHARACTERISTICS.
parse.c (decode_specification_statement): New function.
(decode_statement): Call it when a function has kind = -1. Set
and reset gfc_matching function, as function statement is being
matched.
(match_deferred_characteristics): Simplify with a single call
to gfc_match_prefix. Do appropriate error handling. In any
case, make sure that kind = -1 is reset or corrected.
(parse_spec): Call above on seeing ST_GET_FCN_CHARACTERISTICS.
Throw an error if kind = -1 after last specification statement.
parse.h : Prototype for gfc_match_prefix.
misc.c (gfc_clear_ts): Do not clear kind if it = -1.
2008-01-14 Paul Thomas <pault@gcc.gnu.org>
PR fortran/34429
* gfortran.dg/function_charlen_1.f90: New test.
PR fortran/34431
* gfortran.dg/function_types_1.f90: New test.
* gfortran.dg/function_types_2.f90: New test.
PR fortran/34471
* gfortran.dg/function_kinds_4.f90: New test.
* gfortran.dg/defined_operators_1.f90: Errors now at function
declarations.
* gfortran.dg/private_type_4.f90: The same.
* gfortran.dg/interface_15.f90: The same.
* gfortran.dg/elemental_args_check_2.f90: The same.
* gfortran.dg/auto_internal_assumed.f90: The same.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: submit.diff
Type: text/x-patch
Size: 32995 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20080115/bbd432d4/attachment.bin>
More information about the Fortran
mailing list