[antlr-interest] enum return types for rules?
Jim Idle
jimi at temporal-wave.com
Tue Jul 17 09:35:20 PDT 2007
Actually, in order to deal with this, I thought I had excluded such things from being initialized recently and now only initialize things like trees. However, I will look in to this a bit more on my next bug fix/analyze day.
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Kay Roepke
> Sent: Tuesday, July 17, 2007 12:07 AM
> To: Cameron Esfahani
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] enum return types for rules?
>
>
> On Jul 16, 2007, at 2:07 PM, Cameron Esfahani wrote:
>
> > size_qualifier returns [ ValueNumberValueWidth Width ]
> > : T_SIZE_8
> > {
> > $Width = kValueNumberValue8Bit;
> > }
> > ;
> >
> > And ValueNumberValueWidth is defined as:
> >
> > typedef enum {
> > kValueNumberValue8Bit = 0x300,
> > kValueNumberValue16Bit,
> > kValueNumberValue32Bit,
> > kValueNumberValue64Bit,
> > } ValueNumberValueWidth;
> >
> > When I try and build my tree grammar, I get the following error
> > from gcc:
> >
> > TWalker.c: In function 'size_qualifier':
> > TWalker.c:1132: error: incompatible types in initialization
> >
> > Because antlr has generated the following line:
> >
> > ValueNumberValueWidth Width = NULL;
> >
[...]
> > unsigned long long Number = NULL;
>
> The problem is that the StringTemplate for a target has a type map
> for initialization values.
> The C target has these:
> cTypeInitMap ::= [
> "int" : "0", // Integers start out
> being 0
> "long" : "0", // Longs start
> out being 0
> "float" : "0.0", // Floats start
> out being 0
> "double" : "0.0", // Doubles start out
> being 0
> "ANTLR3_BOOLEAN" : "ANTLR3_FALSE", // Booleans start out
> being Antlr C for false
> "byte" : "0", // Bytes start
> out being 0
> "short" : "0", // Shorts start
> out being 0
> "char" : "0", // Chars start
> out being 0
> default : "NULL" // Anything other than
> an atomic
> type (above) is a NULL (probably NULL pointer).
> ]
>
> As you can see, anything that's not explicitely listed gets
> initialized with NULL. This affects other targets likewise.
> I guess the only chance is to add your enum and possibly unsigned
> long long to that map. It sucks, but I think it cannot be done in the
> grammar directly (though I remember talk of something like overriding
> templates in the grammar. That might just be my blurry memory - and
> this is definitely more than a year ago.)
>
> That stuff is located in the antlr.jar, though if you copy the C.stg
> file to somewhere else, and put it first into the classpath, ANTLR
> will pick up that copy. There you could do your changes.
>
> HTH,
> -k
> --
> Kay Röpke
> http://classdump.org/
>
>
>
More information about the antlr-interest
mailing list