[antlr-interest] An issue with label method references in actions

Gerald Rosenberg gerald at certiv.net
Fri Jan 16 16:47:08 PST 2009


At 03:40 PM 1/16/2009, Jim Idle wrote:
>Gerald Rosenberg wrote:
>>At 01:20 PM 1/16/2009, Jim Idle wrote:
>
>Hence, because the reference parser is simple, and does not know 
>anything about the object it will generate code to reference, there 
>is no way to protect you from the NPE, hence there is nothing to fix per se.

Hmmm, if the code gen is smart enough to break up

gDecl .setName($k.start.getStartIndex());

to produce this

gDecl .setName((k != null ? ((CommonToken) k.start ) : null 
).getStartIndex());

then it should be able to produce this instead

gDecl .setName((k != null ? ((CommonToken) k.start.getStartIndex()) : null ));

Yes, "start" could be null, but at least with this production, the 
code gen is leaving me no more worse off than I was to begin 
with.  The null check will continue to protect in the case of 
optional label references - a really different requirement than a 
null check on "start".  The current production unfortunately kills 
the whole 'protect the optional label reference' point of the code 
generated null check.

I did see Ter's note that the current code gen analysis is not 
looking far enough ahead to handle this.  But, that is just one of 
those minor, no-doubt short-lived practical inconveniences. ;-)

>It's one of those things that you have to garner some extra 
>knowledge from by looking at the code, which you have done :-)

I have to say that I am doing this less and less and, always now, the 
issues are these kind of odd code generation issues.  The evolution 
of Antlr as a language has been amazing to watch.  Still, I look 
forward to when lifting the cover will not be required except in the 
most exceptional of circumstances.

Best,
Gerald
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090116/b6b0a6b6/attachment.html 


More information about the antlr-interest mailing list