[antlr-interest] Avoiding ClassCastExceptions inorg.antlr.runtime.tree.BaseTree (Limitation in ANTLR v 3.1)

Sam Harwell sharwell at pixelminegames.com
Tue Jan 20 15:20:19 PST 2009


I already fixed some of these in the C# port. Some other ones are:

BaseTree.sanityCheckParentAndChildIndexes: this could almost be a static
utility method. It doesn't rely on any special features of BaseTree, but
it's not part of the Tree interface.

BaseTree.replaceChildren: assumes t is a BaseTree. Can be rewritten to
accept any tree by using the Tree.getChild() instead of directly
accessing BaseTree.children.

BaseTree.addChild: assumes t is a BaseTree. Can be rewritten to accept
any Tree like replaceChildren.

I have special-case handling in replaceChildren and addChild in case t
is in fact a BaseTree.

Sam

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Terence Parr
Sent: Tuesday, January 20, 2009 5:01 PM
To: Tim Halloran
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Avoiding ClassCastExceptions
inorg.antlr.runtime.tree.BaseTree (Limitation in ANTLR v 3.1)

Cool. done. fixed in my development branch. I changed one of the  
method also.
Ter
On Oct 2, 2008, at 6:26 AM, Tim Halloran wrote:

> 3.1.1 didn't fix the below problem.  I can't get into Jira; but I  
> think the below is really a bug.
>
> On Wed, Sep 24, 2008 at 2:03 PM, Tim Halloran <hallorant at gmail.com>  
> wrote:
> I'm using the standard Tree implementations (extending BaseTree) in  
> combination with a custom implementation of Tree.  The problem is  
> that BaseTree assumes that it is only being used with subclasses of  
> BaseTree despite it's implementation really not needing to make this  
> assumption.  I propose fixing the code to eliminate this problem.
>
> I modified the getChild() and toStringTree() methods in  
> BaseTree.java.  I changed lines 56 and 297 to cast to Tree, instead  
> of BaseTree.  For example:
>
>     public Tree getChild(int i) {
>         if ( children==null || i>=children.size() ) {
>             return null;
>         }
>         return (Tree) children.get(i);  // line 56
>     }
>
> There might be some other places to change, but I have only  
> encountered problems with these.
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-addr
ess
>


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list