[antlr-interest] GCC lexer warnings with C target
Wincent Colaiuta
win at wincent.com
Wed Jun 13 03:43:11 PDT 2007
El 6/6/2007, a las 15:55, Wincent Colaiuta escribió:
> GCC issues this warning while compiling the lexer:
>
> SimpleLexer.c:198: warning: ‘mFOO’ declared inline after being
> called
> SimpleLexer.c:198: warning: previous declaration of ‘mFOO’ was here
>
> The warning can be eliminated in one of three ways:
>
> - either dropping the ANTLR3_INLINE from the function implementation
>
> - or adding ANTLR3_INLINE to the forward declaration
>
> - or moving the mFOO function further up in the file so that it's
> not called prior to the implementation (in the case of the example
> grammar, it's called exactly once prior to the implementation, from
> the SimpleLexerNew function)
>
> Of these, the cleanest solution looks to be adding ANTLR3_INLINE to
> the forward declaration, at least with GCC... I don't have access
> to any other compilers though so I don't know what the effect would
> be. I'm not aware of any switch that can be passed to GCC to
> suppress these warnings, but in a large lexer than tend to produce
> a fair bit of noise (two warnings for each lexer rule).
The warnings were making it harder to see stuff that I really should
have been paying attention to, so I patched the C.stg template as
follows:
714c714
< <rules:{r | static <headerReturnType
(ruleDescriptor=r.ruleDescriptor)> <if(!
r.ruleDescriptor.isSynPred)>m<endif><r.ruleDescriptor.name>
(p<name> ctx<if(r.ruleDescriptor.parameterScope)>,
<endif><r.ruleDescriptor.parameterScope:parameterScope(scope=it)>);};
separator="\n";>
---
> <rules:{r | static <if(!r.ruleDescriptor.isSynPred)
>ANTLR3_INLINE<endif> <headerReturnType
(ruleDescriptor=r.ruleDescriptor)> <if(!r.ruleDescriptor.isSynPred)
>m<endif><r.ruleDescriptor.name> (p<name> ctx<if
(r.ruleDescriptor.parameterScope)>,
<endif><r.ruleDescriptor.parameterScope:parameterScope(scope=it)>);};
separator="\n";>
This implements the second option mentioned above (adding
ANTLR3_INLINE to the forward declaration). Works on GCC with on
warnings.
Cheers,
Wincent
More information about the antlr-interest
mailing list