[antlr-interest] Bug report; generated C(++) code inappropriately initialises non-primitive return values
Jim Idle
jimi at temporal-wave.com
Mon Mar 30 08:22:15 PDT 2009
Richard Thrippleton wrote:
> When I have a rule of the form
>
> "rule returns [std::vector<int> foo]
> ..."
>
> the generated code for that rule will start with
>
> "std::vector<int> foo = NULL;"
>
> which will (obviously) not compile. I've modified the relevant .stg to
> prevent it generating initialisation code for return values (declaration
> only), and not encountered any issues in my grammars thus far.
>
Yeah - you can't really do that I think. ANTLR does not support very
complex return type declarations and you are probably just "getting away
with that". I believe I looked in to not initializing return variables
and there is some reason that you cannot just disable that
initialization, but it may just be the behavioral requirements of the
return value for the rule reference. I do know that sometimes the
complex declarations will fail though and it is better to use a typedef
type. We could do with the ability to not initialize things that we
don't know about really.
A better approach would be to return a pointer rather than the vector,
or to pass in the reference as a parameter to the rule.
Jim
More information about the antlr-interest
mailing list