[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: no $$ in %destructor = no unset value warnings?
From: |
Joel E. Denny |
Subject: |
Re: no $$ in %destructor = no unset value warnings? |
Date: |
Thu, 14 Sep 2006 21:19:36 -0400 (EDT) |
On Thu, 14 Sep 2006, Akim Demaille wrote:
> >>> "Joel" == Joel E Denny <address@hidden> writes:
>
> > a. value is likely set/constructed = $$ appears in semantic action
> > b. value is likely destroyed = $$ appears in %destructor
>
> > That is, I think Bison shouldn't warn about !a when !b. However,
> > Bison currently considers a value to be likely destroyed by a
> > %destructor regardless of whether $$ appears in the %destructor. I
> > think that's inconsistent.
>
> It is inconsistent, you are right, but I would have chosen the other
> possibility: just like we invite users to YYUSE (or whatever the
> macro) in rule actions, we should do that in destructors and printers.
> Not because it is always wrong not to use the value, but because it's
> always possibly an error.
Ok, I think I agree.
> > Moreover, it might be convenient to override a per-type or default
> > %destructor by defining an empty per-symbol %destructor, which
> > would suppress the warnings:
>
> > %destructor { free ($$); }
> > %destructor { } symbol_with_no_value
>
> > What do you think?
>
> Err? Default destructors apply whether there is a semantic value or
> not? I have plenty of catch-up to do :(
I was thinking of a user-defined YYSTYPE (no %union) with no <...> usage.
In this case, Bison would have no idea what symbols truly have semantic
values. So, I think we need the ability to remove the destructor for
specific symbols. There might even be cases where nearly all symbols of a
particular type need a destructor, but a few don't. Finally, I still like
the idea of a %destructor that doesn't access $$ but perhaps just prints a
message, and I don't think Bison should warn about rules that don't use
such a $$/$n.
You once discussed the possibility of named semantic values in grammar
rules:
exp(sum): exp(term1) '+' exp(term2) {
$sum = $term1 + $term2
}
And instead of USE($1), you suggested empty parens, for which I still
prefer (!). I think empty parens make a nice default value name:
grammar(): defs() rules() epilogue(!) {
$grammar = new_grammar( $defs, $rules );
}
Maybe something similar is useful with %destructor/%printer:
%destructor(!) { printf ("A SYM was discarded.\n"); } SYM
Because the user has explicitly declared that SYM does not need to destroy
its value, Bison would not warn about unused SYM values in %destructor or
semantic actions.
By the way, shouldn't Bison warn when there's %union or <...> usage in the
grammar but a $$ without a type appears in a %destructor/%printer? This
is already the case for semantic actions.