[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: %destructor invocation
From: |
Bob Rossi |
Subject: |
Re: %destructor invocation |
Date: |
Sat, 4 Oct 2014 08:04:01 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Fri, Oct 03, 2014 at 10:18:18PM -0400, Bob Rossi wrote:
> Hi,
>
> I'm trying to get 100% coverage on my bison grammar actions using gcov.
>
> I noticed i'm having difficulty getting the %destructor actions to be
> called, which made me realize that perhaps I've got more of them than
> are necessary. (ie. Bison will never invoke them).
>
> According to the manual, a Bison grammar rule has the following general form:
> result: components…;
> where result is the nonterminal symbol that this rule describes, and
> components are various terminal and nonterminal symbols that are put
> together by this rule (see Symbols).
>
> I have two questions regarding when the %destructor action is called
> regarding the following grammar.
>
> result_list: {
> $$ = NULL;
> };
>
> result_list: result_list COMMA result {
> $$ = append_gdbmi_result ($1, $3);
> };
>
> result: opt_variable list {
> ...
> };
>
> list: OPEN_BRACKET CLOSED_BRACKET {
> $$ = NULL;
> };
>
> list: OPEN_BRACKET result result_list CLOSED_BRACKET {
> $$ = append_gdbmi_result($2, $3);
> };
>
> 1. Is %destructor ever called for list? I see that list itself can fail
> to parse, which shouldn't cause it's destructor to be called. However,
> if list itself is successful, then the next level up result will always
> be successful (I believe).
>
> 2. Once a rule returns successfully (for example a list rule), if result
> then returns successfully, would that rule out the destructor ever being
> called for list in this example? If result could somehow fail from it's
> caller, the %destructor for result would override the %destructor for
> list which result called. Correct?
>
> It would be really nice if Bison could tell you all the symbols that
> need a potential %destructor, does it do that?
I think I can simplify my above language here after trying this for a
few more hours.
I'm only placing %destructor rules by looking at the components in
result,
> result: components…;
and determining if any of them can fail to the right. So for this
result,
> list: OPEN_BRACKET result result_list CLOSED_BRACKET {
OPEN_BRACKET is a candidate if result, result_list or CLOSED_BRACKET fails.
result is a candidate if result_list or CLOSED_BRACKET fails.
result_list is a candidate if CLOSED_BRACKET fails.
CLOSED_BRACKET is not a candidate.
I look at the entire grammar and look at the right hand side of each
rule and look for failures like above. Is my mental algorithm correct?
Does Bison support outputting the candidate symbols that should have a
destructor? That would be a nice feature as many of the symbols in a
grammar are perhaps the last symbol on the right hand side, and are not
eligalbe for destruction.
Thanks,
Bob Rossi