bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Per-type %destructor?


From: Bart Samwel
Subject: Per-type %destructor?
Date: Sat, 08 Apr 2006 19:55:52 +0200
User-agent: Thunderbird 1.5 (Windows/20051201)

Hi everybody,

I've just picked up bison 2.1, and I read in the manual that feedback on the %destructor feature was wanted. I do have one issue with the way it is implemented, and I didn't find any discussions in the archives that mentioned this, so here I am to report. If this has already been resolved or rejected earlier, please forgive my ignorance. :-)

My issue with the 2.1 %destructor feature is that destructors are only specifiable on a per-symbol basis, while I would like to specify them per *type*. I am building a parser that simply generates an AST, using something like this:

%union {
   Element *elem;
   SomeOtherType *blah;
}

%type <elem> almost all of my symbols go here
%type <blah> a couple of symbols go here

All of the elem types are "owned" by their tokens, while the blah types are *not* the owners of the SomeOtherType objects that the blah value points to. So I would like to specify something like:

%destructor <elem> { delete $$; }

And leave the <blah>-typed symbols without a destructor. But no, I apparently have to specify:

%destructor { delete $$; } almost all of my symbols go here

So, I have to redundantly specify every symbol that has type <elem>. If I make one mistake in the list, I'm screwed:

1. If I mistakenly include a blah-typed symbol, the destructor will delete the SomeOtherType that the symbol didn't own. And it will compile cleanly. :-(

2. If I mistakenly forget an elem-typed symbol (for instance because I added a new one), then its destructor won't get called, and I have a memory leak.

So, is there any chance that a type-wide %destructor specification will appear in bison? Without it, I'm afraid that I'm not going to use the feature, as I'm quite sure that someone on my team will forget to keep the lists in sync at some point. :-) Thanks in advance for your thoughts.

Cheers,
Bart




reply via email to

[Prev in Thread] Current Thread [Next in Thread]