The following was received via email following an analysis by a colleague.
The following F2K features need support by the build system of fcm make
:
- Dummy procedure arguments:
This sort of dummy argument seems to be fine:
external :: foo
integer, external :: bar
In Fortran 2003 you can also use a procedure declaration:
subroutine sub(a)
procedure(foo), pointer :: a
where foo
is the interface, or
procedure(), pointer :: a
where there is no interface. If the foo
is coming from a module the above can be made to work by simply adding procedure
to the list of declarations in FCM::System::Make::Build::Task::ExtractInterface
line 36. However, it is also possible (and may be preferable in some cases) to declare the interface explicitly in the routine, i.e.:
subroutine sub(a)
interface
subroutine foo
end subroutine foo
end interface
procedure(foo), pointer :: a
! ...
The ability to give an interface to a procedure argument is not new to F2003, in F90 you can do
subroutine sub(a)
interface
subroutine a
end subroutine a
end interface
! ...
FCM interface generation cannot handle this sort of interface at the moment and I don't know how difficult it would be to support it. One could of course simply use module subroutines instead in which case all is well but it would be good if it was documented in the FCM user guide that this sort of interface declarations can only be used in module procedures.
To further confuse issues you can also do
abstract interface
! ...
end interface
instead of
interface
! ...
end interface
so ideally FCM would handle interface and abstract interface the same. The difference between abstract and non-abstract interfaces are not relevant to procedure dummy arguments so either could be used.
- Class declarations:
These are very similar to TYPE
declarations, i.e. instead of
subroutine foo(a)
type(bar) :: a
you have
subroutine foo(a)
class(bar) :: a
Again this can be supported by appending class
to line 36 of FCM::System::Make::Build::Task::ExtractInterface
.
- Use intrinsic:
In addition to USE foo[, only: ...]
one can do:
use, intrinsic :: foo [, only: ...]
The rules as I understand them are:
- With
intrinsic
not specified a user defined module is used if found, otherwise the intrinsic module is used.
- With
intrinsic
specified only intrinsic modules are used, compilation fails if there is no intrinsic module
This is similar to external
and intrinsic
for procedures although the search order is reversed in the default case which is a bit confusing. FCM should support intrinsic and the coding standards should recommend that for intrinsic modules use, intrinsic
is used in preference to just use
. When use
is used on its own FCM should base its dependencies on the hard-coded list as it does now but it should never generate a dependency for "use, intrinsic" as in principle compilers could add their own intrinsic modules (in the same way that they can add their own intrinsinc procedures) and we may want to use those modules for whatever reason. Note that e.g.
subroutine foo(a)
use, intrinsic :: iso_c_binding
integer(c_int) :: a
still needs to include the reference to iso_c_binding
in the interface block even though there is no dependency.
iso_fortran_env
The intrinsic module iso_fortran_env
should be added to line 39 of FCM::System::Make::Build::FileType::Fortran
.
Briefly, for Fortran 2008 there will be the following issues for FCM
- Double Complex
I noticed that this appears to be missing from line 36 of FCM::System::Make::Build::Task::ExtractInterface
. It is actually optional in F90, so technically it counts as an F2K change. I don't know of any code that uses it but it should probably be included for completeness.
- Submodules
module foo
! ...
end module foo
submodule (foo) foo_bar
! ...
The idea is that foo
contains interface blocks and foo_bar
contains implementations although no doubt people will find other uses in future. The dependency generator would need to ensure that foo_bar
depends on foo
.
impure elemental
In F2008 there is an impure elemental
procedure, sort of like elemental but less so (sorry, I haven't checked the exact details), i.e.
impure elemental subroutine foo(a)
! ...
I presume this would mean updating line 53 of FCM::System::Make::Build::FileType::Fortran
.
I'm not sure what else is relevant to interface generation. In FCM::System::Make::Build::Task::ExtractInterface
there is
my %TYPE_DECL_KEYWORD_SET = map { ($_, 1) } qw{
allocatable
dimension
in
inout
intent
kind
len
optional
out
parameter
pointer
save
target
};
which appears to be a list of attributes that dummy arguments may have, but I tried declaring dummy arguments with things not on the list:
volatile
asynchronous
external
value
contiguous
and the interface block seemed to include them. It appears that FCM just copies the entire line (which is the correct thing to do). Similarly for function or subroutine names the bind(c)
is included correctly even though bind isn't mentioned anywhere in the Perl code.