Dynamic dispatch of class typebound procedures - post LTO patch for gfortran

Paul Richard Thomas paul.richard.thomas@gmail.com
Sun Oct 4 07:35:00 GMT 2009


Dear All,

Please find attached the promised patch to implement dynamic dispatch
of class objects.  Both functions and subroutines are correctly
handled.  It should be noted that some of the error handling is a bit
ragged; eg. trying to use host associated procedures generates all the
correct error messages, followed by an ICE.  I will track these down
over the coming weeks and put them right.

The patch consists of four distinct elements:

(i) module.c
Derived type extensions in the f2k_derived namespace were not be
written to and loaded from module files.  This has been put right.

(ii) symbol.c
gfc_type_compatible did not handle the case of both typespecs being
BT_CLASS correctly.  This has been corrected.

(iii) resolve.c
Typebound calls of class objects are now intercepted in
resolve_class_compcall (functions) and resolve_class_typebound_call
(subroutines).  These generate a gfc_class_esym_list, which points to
the derived type and the symbol for the specific procedure.  The
specific symbols are identified using existing functions,
check_class_members and check_members.  After eliminating trivial
gfc_class_esym_list's (ie. with only one procedure) in
resolve_class_esym, the list is added to the expression for the call.

(iv) trans-expr.c
The presence of the gfc_class_esym_list is detected in
conv_function_value, which then calls select_class_proc.  This latter
uses the list to generate a select case, using the vindex as the
selector and cases for each of the class members.

Bootstrapped and regtested on FC9/x86_64 - OK for trunk after the dust
settles on LTO?

Paul

2009-10-04  Paul Thomas  <pault@gcc.gnu.org>

	* trans-expr.c (select_class_proc): New function.
	(conv_function_val): Deal with class methods and call above.
	* symbol.c (gfc_type_compatible): Treat case where both ts1 and
	ts2 are BT_CLASS.
	gfortran.h : Add structure gfc_class_esym_list and include in
	the structure gfc_expr.
	* module.c (load_derived_extensions): New function.
	(read_module): Call above.
	(write_dt_extensions): New function.
	(write_derived_extensions): New function.
	(write_module): Use the above.
	* resolve.c (resolve_typebound_call): Add a function expression
	for class methods.  This carries the chain of symbols for the
	dynamic dispatch in select_class_proc.
	(resolve_compcall): Add second, boolean argument to indicate if
	a function is being handled.
	(check_members): New function.
	(check_class_members): New function.
	(resolve_class_esym): New function.
	(resolve_class_compcall): New function.
	(resolve_class_typebound_call): New function.
	(gfc_resolve_expr): Call above for component calls..

2009-10-04  Paul Thomas  <pault@gcc.gnu.org>

	* gfortran.dg/dynamic_dispatch_1.f90: New test.
	* gfortran.dg/dynamic_dispatch_2.f90: New test.
	* gfortran.dg/module_md5_1.f90: Update md5 sum.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dispatch1004.diff
Type: text/x-patch
Size: 24081 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20091004/6bab4e28/attachment.bin>


More information about the Gcc-patches mailing list