Implementing finalization
Daniel Kraft
d@domob.eu
Thu May 22 06:30:00 GMT 2008
Hi,
while still working on PR35846 (ICE on nested array constructor) I'm
currently a bit stuck after some analysis (in fact, the same ICE can
occur without nested array constructors, see the bug page) and started
thinking about implementing finalization.
As I see it, derived type definitions are stored in a gfc_symbol node,
so I plan to add a new field "finalizer" there which contains a linked
list of defined finalization procedures. AFAIK, gfc_symbol does
currently not define a generic next member to be put in a linked list
(which is, I believe, for this purpose all we need), thus I could either
also add this field but I prefer to create a new structure gfc_finalizer
something like this:
typedef struct gfc_finalizer
{
struct gfc_finalizer* next;
struct gfc_symbol* procedure;
int kind;
int rank;
} gfc_finalizer;
if you don't mind the definition of a new "public" structure. Then for
the parser part I'd simply attach all final defined procedures to this
linked list of the derived type they are defined on (after checking they
fulfull the requirements, of course; probably similar to checking the
procedures in operator definitions).
For carrying out the finalization itself, I want to add a new function
void gfc_add_finalizer (gfc_expr* expr, stmtblock_t* block)
(good name to be thought about, and I'm not really sure about the
trans-stuff, so will work out what we need exactly). This function will
check if expr is finalizable and if so, insert a call to the matching
finalizer (depending on kind and rank of expr) in block.
Finally, I'll add a call to gfc_add_finalizer at all places where the
standard prescribes it; I'll see if this is more or less complex and
what we need for this, but I hope to get it done somehow ;)
And last but not least, I'll start thinking about test-cases right now
before any coding :D
Is this plan ok or did I miss something / do you want something to be
done another way? This is just what I believe to be the best and
easiest way, but I'm still no gfortran expert...
Cheers,
Daniel
PS: I'm not sure about how big this patch will be (don't think it will
become huge), but is there a chance I could split it, say, in the
parsing part first including the validation of finalizer procedures and
the like with tests, get this approved and checked in, and then work on
carrying out the finalization itself? But I don't think it's a big
problem to do it all in one, I just always like the idea of getting some
changes in without getting too big.
--
Done: Bar-Sam-Val-Wiz, Dwa-Elf-Hum-Orc, Cha-Law, Fem-Mal
Underway: Ran-Gno-Neu-Fem
To go: Arc-Cav-Hea-Kni-Mon-Pri-Rog-Tou
More information about the Fortran
mailing list