[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8776]
This commit is contained in:
parrt 2011-06-27 16:20:03 -08:00
parent 7e45a0c01d
commit de0881a88b
4 changed files with 18 additions and 12 deletions

View File

@ -99,14 +99,6 @@ public abstract class DefaultOutputModelFactory implements OutputModelFactory {
// MISC
/** Find exact object type in list */
public static SrcOp find(List<SrcOp> ops, Class cl) {
for (SrcOp op : ops) {
if ( op.getClass() == cl ) return op;
}
return null;
}
public static List<SrcOp> list(Object... values) {
List<SrcOp> x = new ArrayList<SrcOp>(values.length);
for (Object v : values) {

View File

@ -2,6 +2,7 @@ package org.antlr.v4.codegen;
import org.antlr.v4.codegen.model.*;
import org.antlr.v4.codegen.model.ast.AddLeaf;
import org.antlr.v4.misc.Utils;
import java.util.List;
@ -10,9 +11,14 @@ public class ParserASTExtension extends CodeGeneratorExtension {
super(factory);
}
@Override
public List<SrcOp> ruleRef(List<SrcOp> ops) {
return super.ruleRef(ops);
}
@Override
public List<SrcOp> tokenRef(List<SrcOp> ops) {
MatchToken matchOp = (MatchToken) DefaultOutputModelFactory.find(ops, MatchToken.class);
MatchToken matchOp = (MatchToken)Utils.find(ops, MatchToken.class);
SrcOp treeOp = new AddLeaf(factory, matchOp.ast, matchOp);
return DefaultOutputModelFactory.list(ops, treeOp);
}

View File

@ -1,8 +1,8 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.*;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.model.decl.*;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.misc.*;
import org.antlr.v4.tool.GrammarAST;
import java.util.*;
@ -46,7 +46,8 @@ public abstract class Choice extends RuleElement {
}
public SrcOp addCodeForLookaheadTempVar(IntervalSet look) {
SrcOp expr = DefaultOutputModelFactory.find(factory.getLL1Test(look, ast), TestSetInline.class);
List<SrcOp> testOps = factory.getLL1Test(look, ast);
SrcOp expr = (SrcOp)Utils.find(testOps, TestSetInline.class);
if ( expr instanceof TestSetInline) {
TestSetInline e = (TestSetInline)expr;
Decl d = new TokenTypeDecl(factory, e.varName);

View File

@ -142,4 +142,11 @@ public class Utils {
return b;
}
/** Find exact object type in list */
public static Object find(List<?> ops, Class cl) {
for (Object o : ops) {
if ( o.getClass() == cl ) return o;
}
return null;
}
}