Some thoughts on PDTs
Thomas Koenig
tkoenig@netcologne.de
Sun Apr 23 21:50:00 GMT 2017
Hello world,
after Jerry's implementation of DTIO, only PDTs are
missing as a major F2003 feature from gfortran.
I'd like to share some unordered thoughts on a way to
implement these. Comments, corrections etc. are the whole
point of this mail, so very highly welcome :-)
To recap: A PDT could look like
TYPE matrix (k, n)
integer, kind :: k=4
integer, len :: n
real(k) :: a(n,n)
END TYPE matrix
with a later declaration of a type that is actually usable as
TYPE (matrix(k=selected_real_kind(15),n=100) :: mymatrix
What changes would we need for the internal data structures?
We would probably have to extend gfc_symbol with a list of type
parameters, including defaults. During resolution, we could then
instantiate the new type. This sound doable in principle (but I am sure
that there are quite a few traps and pitfalls). This would work
for a static variable.
Things will get more interesting for an allocatable or pointer
variable or dummy argument which is a PDT.
Apparently, the kind number has to be a constant expression, which
makes things a bit easier.
Still, to pass a variable of a type like
TYPE foo(k1, k2, n, m)
integer, kind :: k1
integer, kind :: k2
integer, len :: n
integer, len :: m
real(kind=k1), dimension(n,m) :: a
real(kind=k2), dimension(2*n,m) :: b
END TYPE foo
we would need some new type of descriptor. It is not totally clear to
me at the moment what data this would need to contain, or how it would
look like.
Any ideas? Or did anybody of our esteemed colleagues from the other
Fortran compilers who have already implemented PDTs publish anything on
the matter?
Just some thoughts...
Thomas
More information about the Fortran
mailing list