[4.5, Patch, Fortran] PR 36704: Procedure pointer as function result

Janus Weil jaydub66@googlemail.com
Sat Dec 6 20:04:00 GMT 2008


Hi all,

here is my patch for procedure pointers as function result. The easy
case of procptr function results (i.e. using a result variable) is
already working on 4.4 trunk. This patch has the ambition to also make
the harder cases work where no result variable is used. After thinking
about it for a while, I came to the conclusion that the best way of
implementing this would be to add a "hidden" result variable for those
cases where no actual RESULT statement is used. The primary motivation
for this is that the interface of the returned procptr must be kept
separate from the interface of the function which returns the procptr,
i.e. we need two separate symbols. The hidden result variable should
have a name which is not a valid Fortran variable name, and I simply
chose "ppr@" (for procedur pointer result, plus the @ to make it
invalid). If anyone thinks this is a poor choice for some reason, I
can easily change this of course.

I also attached a testcase, which should give you an idea of what the
patch is able to handle. I tried to include all the different ways to
declare a procedure pointer, and hope I forgot none. Possibly there
are still some details missing, but I'd like to have the general
concept of the patch reviewed already. Maybe someone even has an idea
how this can be done in a simpler way. I think it's kind of tricky.
The patch actually grew piece by piece, since I started with the easy
cases and made my way towards the harder ones. Also I'd appreciate it
very much if someone could test the patch from a "user's perspective",
to uncover those usage cases that I am missing.

Regtested on i686-pc-linux-gnu without any failures.

Cheers,
Janus



2008-12-06  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36704
	* decl.c (add_hidden_procptr_result): New function for handling
	procedure pointer return values by adding a hidden result variable.
	(variable_decl,match_procedure_decl,gfc_match_function_decl,
	gfc_match_subroutine,gfc_match_end,attr_decl1): Handle procedure pointer
	return values.
	* primary.c (match_variable): Replace symbol with hidden result
	variable.
	* resolve.c (resolve_contained_fntype): Allow for procedure pointer
	function results.
	(resolve_fl_procedure): Conflict detection moved here from
	'check_conflict'.
	* symbol.c (gfc_check_function_type): Allow for procedure pointer
	function results.
	(check_conflict): Move some conflict detection to resolution stage.


2008-12-06  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36704
	* gfortran.dg/external_procedures_1.f90: Modified.
	* gfortran.dg/proc_ptr_13.f90: New.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr36704_2.diff
Type: text/x-patch
Size: 9632 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20081206/d2e76db6/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: proc_ptr_13.f90
Type: application/octet-stream
Size: 1558 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20081206/d2e76db6/attachment.obj>


More information about the Gcc-patches mailing list