Since ASTLabelType=GrammarAST, construct CommonTreeNodeStream with GrammarASTAdaptor to make sure UP/DOWN nodes cannot result in a ClassCastException

This commit is contained in:
Sam Harwell 2012-11-12 13:41:26 -06:00
parent 669f676c55
commit 05fb538304
2 changed files with 3 additions and 3 deletions

View File

@ -96,7 +96,7 @@ public ErrorManager getErrorManager() { return null; }
public void visitGrammar(GrammarAST t) { visit(t, "grammarSpec"); }
public void visit(GrammarAST t, String ruleName) {
CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
CommonTreeNodeStream nodes = new CommonTreeNodeStream(new GrammarASTAdaptor(), t);
setTreeNodeStream(nodes);
try {
Method m = getClass().getMethod(ruleName);

View File

@ -30,6 +30,7 @@
package org.antlr.v4.tool;
import org.antlr.runtime.CommonToken;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.tree.Tree;
import org.antlr.runtime.tree.TreeVisitor;
import org.antlr.runtime.tree.TreeVisitorAction;
@ -76,8 +77,7 @@ public class GrammarTransformPipeline {
}
public void reduceBlocksToSets(GrammarAST root) {
org.antlr.runtime.tree.CommonTreeNodeStream nodes =
new org.antlr.runtime.tree.CommonTreeNodeStream(root);
CommonTreeNodeStream nodes = new CommonTreeNodeStream(new GrammarASTAdaptor(), root);
GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
BlockSetTransformer transformer = new BlockSetTransformer(nodes, g);
transformer.setTreeAdaptor(adaptor);