[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

DAG creation in versions 1.18.1 and 3.0.0-beta



I have found a bug present in versions 1.18.1 and 3.0.0-beta of SableCC.

It is possible to create DAGs using list nodes. Once such a DAG has been
created, it is possible for the parent link of a node in a list to point to
the wrong parent. I have attached a SableCC specification file and Java
program that demonstrates this problem.

The root of this problem occurs in the Cast subclasses defined by the
alternatives.txt file:

Macro:Cast

     private class $0$_Cast implements Cast
     {
         public Object cast(Object o)
         {
             $1$ node = ($1$) o;
	
             if((node.parent() != null) &&
	       (node.parent() != $2$.this))
             {
	        node.parent().removeChild(node);
	    }
					
	    if((node.parent() == null) ||
                 (node.parent() != $2$.this))
             {
	        node.parent($2$.this);
             }
							
             return node;
        }
  }

  $

After some strightforward case analysis, the following equivalent code is
somwehat more revealing:

Macro:Cast

     private class $0$_Cast implements Cast
     {
         public Object cast(Object o)
         {
             $1$ node = ($1$) o;
	
             if(node.parent() != $2$.this)
             {
	    	if(node.parent() != null)
		{
	            node.parent().removeChild(node);
	        }
	        node.parent($2$.this);
             }
							
             return node;
        }
  }

  $

It is the initial test that compares the node parent to the node containing
the list that causes the problem, since it permits nodes that are already
contained by the node to be added to the list. It doesn't matter if the node
being added to the list is contained by the same list, another list, or if
it is a simple node not contained by any list. The attached SableCC
specification file and Java program demonstrate this problem using a node
that contains a single list.

It also strikes me that an IllegalArgumentException should be thrown if the
node parameter is null, rather than a NullPointerException, although this is
not really a problem.

There is another problem that occurs in version 2.18.1. The build.xml file
specifies the "jikes" compiler instead of the "modern" compiler. This has
been fixed in version 3.0.0-beta, complete with a comment saying that the
jikes compiler doesn't work.

--
Jon Shapcott <eden@xibalba.demon.co.uk>
"This is the Space Age, and we are Here To Go" - Wlliam S. Burroughs