---------------------------------------------------------- Implementation of assumed-rank arrays ---------------------------------------------------------- See Technical Specification (TS) 29113, "Further Interoperability of Fortran with C" ftp://ftp.nag.co.uk/sc22wg5/N1901-N1950/N1917.pdf DRAFT: * assumed-rank-scalar.diff: EARLY DRAFT * Scalar to (type, class) array. * Issues: Copy back, CLASS(*) type -> class, class->class, class->type TODO: * Better diagnostic for type/rank mismatch * Check that in interfaces/generic assumed-rank vs. any other rank aren't regarded as identical. Submitted patch: * http://gcc.gnu.org/ml/fortran/2012-06/msg00147.html old version? assumed-rank-class-2012-06-26.diff Requires the submitted patch (cf. below) and adds support for handling CLASS and type<->class combinations. Possible issues: - Passing assumed-rank CLASS to (assumed-rank) TYPE. For class-to-type, a copy might be needed, at least for descriptorless arrays as the dynamic type might be different from the declared one. An additional issue are for allocatables/pointers (I have to check the standard for that.) Possibly, the stride calculation works without copying, at least for array-descriptor variables; needs checking and possibly a the new array descriptor. Otherwise, it needs a scalarizer, which can handled assumed-rank arrays. - allocatable/pointer vs. nonpointer/nonallocatable and non(simply)contiguous -> contiguous have to be tested. * http://gcc.gnu.org/ml/fortran/2012-06/msg00144.html which is identical to assumed-rank-2012-06-24.diff Supported: - Basic support assumed-rank arrays: Parsing, constraint checking, argument passing - size (w/ and w/o dim=) and lbound/ubound with dim=, and rank. Still unsupported: - Passing scalars to assume-rank arrays - shape and lbound/ubound without dim= - Some smaller issues Other missing functionality: - C_LOC and other C binding facilities have to be updated - Access from C, which implies a new array descriptor - is_contiguous intrinsic is missing Longer scratch version of a TODO list: - New array descriptor and updated internal handling - IS_Contiguous is missing - Update C_LOC and C binding - Usage constraints (90% done) - Scalarizer: For internal usage with ELEMENTAL (-> FINAL) and for UBOUND/LBOUND w/o dim= - Handling of scalars, including CLASS. (type to class, class to type etc.) - Handling of passing non (simply) contiguous (assumed-rank)array to contiguous array. - Ditto if the actual argument is assumed rank and CLASS and the dummy is assumed-rank and TYPE (and vice versa) - Handling of lbound: Should be 1, unless allocatable/pointer (-> gfc_trans_dummy_array_bias) - Type definition: Why does one have to dereference the array twice in convert_bounds/convert_rank in trans-intrinsics.c. It also has an "&" too much in the libgfortran call to size. For instance: print *, associated (x, y) - Type declaration: Currently, MAXRANK is used. That's probably okay, but a typedef of the form (C syntax) "dim_triplet dim[];" instead of "dim_triplet dim[MAX_DIMENSION];" would be better. (Those can only live as pointer, which is fine) Digest from the standard: * Internal representation to match ISO_Fortran_binding.h (deferred until the new array descriptor is available) * Update C binding support * Usage constraints: Only valid as - Actual argument to assumed-rank dummies - C_LOC - First argument to intrinsic inquiry functions. In particular: shape, size, lbound, ubound (The other 20+ should simply work - or aren't possible for other reasons) * In particular: - Valid are assumed-rank dummies with CLASS, scalar/array actual arguments, contiguous, allocatable, pointer, target; assumed-size actuals - Invalid are codimension and value * Scalars are valid and yield: - size(scalar) = 1 - shape(scalar) == lbound(scalar) == ubound(scalar) == (/ /) * Assumed-size arguments to assumed-rank dummies: - shape(a, dim = rank(a)) == -1 - shape(a) = [ shape(a,1), ..., shape(a,rank(a)-1), -1 ] - size(a) = product(shape(a)) < 0 - ubound(a,dim=rank(a)) == lbound(a, dim=rank(a)) - 2