[antlr-interest] [C target] [3.1] Cast to ASTLabelType missing in Treeparser template

Sven Van Echelpoel sven.van.echelpoel at empolis.com
Mon Aug 25 05:41:46 PDT 2008


Hi,

When compiling a tree parser generated for the C target, the compiler
complains about an illegal conversion from void* when it is compiled as
a C++ source. E.g.:

`MyTreeParser_translation_unit_return translation_unit(
        MyTreeParser_Ctx_struct *
    )':
.../MyTreeParser.cpp:603: error:
    invalid conversion from `void *' to `ANTLR3_BASE_TREE_struct *'

I think I have have traced the source of this problem down to this
template in ASTTreeParser.stg:


ruleCleanUp() ::= <<
<super.ruleCleanUp(...)>
<if(backtracking)>
if ( BACKTRACKING==0 ) {<\n>
<endif>
<if(!ruleDescriptor.isSynPred)>
	retval.stop = LT(-1);<\n>
<endif>
        retval.tree = ADAPTOR->rulePostProcessing(ADAPTOR, root_0);
                    ^^^^^^^^^^^
                    (Cast Missing here?)
[...]

The corresponding template in ASTParser.stg does have the cast in place:

ruleCleanUp() ::= <<
<super.ruleCleanUp(...)>
<if(backtracking)>
if ( BACKTRACKING==0 ) {<\n>
<endif>

<if(!ruleDescriptor.isSynPred)>
	retval.stop = LT(-1);<\n>
<endif>
	retval.tree =
 (<ASTLabelType>)(ADAPTOR->rulePostProcessing(ADAPTOR, root_0));
^^^^^^^^^^^^^^^^^
(With cast here)

[...]

I Added the cast to my local copy of the ASTTreeParser templates,
updated the jar file and now everything seems to work fine.

Can it be that this is an oversight and that the cast should be in the
template?

Regards,

Sven





More information about the antlr-interest mailing list