bison-patches
[Top][All Lists]
Advanced

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

Re: %destructor declared by semantic type


From: Joel E. Denny
Subject: Re: %destructor declared by semantic type
Date: Wed, 21 Jun 2006 06:47:49 -0400 (EDT)

On Tue, 20 Jun 2006, Paul Eggert wrote:

> What about grammars without %union, but where the program defines
> YYSTYPE?  Do you still allow "%destructor { free ($$); }"?

I think the case of no %union has two subcases:

1. If Bison finds <tag> usage (once you're done with your patch for this), 
then it should assume the user will define YYSTYPE as a union.  This 
subcase should be no different from the case where the user declares 
%union, right?

2. If Bison finds no <tag> usage, then destructors by type make no sense, 
so perhaps Bison should report an error if the user declares such 
destructors.  However, destructors by symbol do still make sense.  A 
catch-all destructor makes sense too, I think.

> For "%destructor { free ($$); } <type1> <type2>" do Bison generate
> just one copy of the "free ($$);", or one for each type?

I haven't thought through the implementation yet.  To be general, I think 
they have to be separate.  For example, for C++, delete invokes different 
code for different pointer types.

> For (3), suppose a midrule action has both $<T1>$ and $<T2>$, and <T1>
> has a destructor but T2 does not.  Shouldn't this generate a
> warning/error too?

Yes, that's what I intended.

> Again for (3), if $<T1>$ and $<T2>$ have the same destructor, which
> type is used to call the destructor?

What a glaring flaw!  As many times as I read over this....

Thanks for spotting that.  That'll save me some time.

That persuades me to believe that Akim's right: $<T>$ and $<T>n should be 
thought of like unsafe C-style casts, and Bison should ignore them when 
choosing destructors.  It's much easier that way.

> Also, I don't understand the last two sentences of the above URL:
> 
>   $<T>n appears after the time when bison might actually generate
>   destructor calls on the semantic value.  So, the user can play with
>   whatever union members he wants here.
> 
> Can you please give an example of this?  It sounds dangerous to let
> the user play with destroyed members.

Sorry, I worded that poorly.  I meant that, once the parser passes a 
semantic value to a user action as a $<T>n, the parser leaves it up to the 
user code to call any necessary destructors.  That is, it doesn't matter 
what the user specifies for T in $<T>n because destruction is out of the 
parser's hands at this point.

It occurs to me now that this isn't quite true in the case of midrule 
actions.  However, it's a moot point now that I'm going to abandon this.

Thanks.

Joel




reply via email to

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