ABSTRACT interfaces + PROCEDURE declarations

Janus Weil jaydub66@googlemail.com
Wed Aug 15 16:26:00 GMT 2007


Hi all,
attached you will find two preliminary patches:

* The first one implements abstract interfaces. It is fairly
straightforward and hopefully complete. I would be very glad if
someone could review it. Maybe this can be committed into trunk soon?

* The second patch deals with procedure declarations. It is not
finished yet, but can already handle some basic PROCEDURE statements,
like in the following example code:


program test

implicit none

abstract interface
  integer function absint(x)
    real x
  end function absint
end interface

procedure(absint) :: proc1
procedure(fun) :: proc2

print *,proc1(2.0)
print *,fun(3.0)
print *,proc2(4.0)

contains

integer function proc1(x)
  real x
  proc1 = 2*int(x)
end function proc1

real function fun(x)
  real x
  fun=x*x
end function fun

real function proc2(x)
  real x
  proc2=2*x*x
end function proc2

end program


One thing that I'm working on right now is to implement some checking
if the FUNCTION implementation actually matches the PROCEDURE
declaration. I've already added some code in decl.c
(gfc_match_function_decl), which checks if the return type of the
function equals the one in the procedure declaration. But putting this
check in gfc_match_function_decl only works for PROCEDUREs which are
derived from an abstract interface, as in

procedure(absint) :: proc1

but does not work for procedures derived from another function, as in

procedure(fun) :: proc2

since the return type of "fun" may not yet be known when "proc2" is declared.
Does anyone have an idea how to do the checking in this case? Also I'm
not sure how to check if the formal arguments match. Any ideas would
be highly appreciated.
Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: absint127507.diff
Type: text/x-patch
Size: 6444 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070815/e12a48cc/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: procdecl127507.diff
Type: text/x-patch
Size: 13454 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070815/e12a48cc/attachment-0001.bin>


More information about the Fortran mailing list