reorg to get extensions

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8767]
This commit is contained in:
parrt 2011-06-27 11:33:40 -08:00
parent 506f8eec09
commit 55ce044acf
57 changed files with 245 additions and 183 deletions

View File

@ -1,6 +1,6 @@
parser grammar T;
options {output=AST;}
a : A ;
a : A^ ;
/*
r[int a] returns [int b]
scope {int qq;}

View File

@ -33,14 +33,14 @@ public class ActionTranslator implements ActionSplitterListener {
ActionAST node;
RuleFunction rf;
List<ActionChunk> chunks = new ArrayList<ActionChunk>();
OutputModelFactory factory;
CoreOutputModelFactory factory;
public ActionTranslator(OutputModelFactory factory, ActionAST node) {
public ActionTranslator(CoreOutputModelFactory factory, ActionAST node) {
this.factory = factory;
this.node = node;
}
public static List<ActionChunk> translateAction(OutputModelFactory factory,
public static List<ActionChunk> translateAction(CoreOutputModelFactory factory,
RuleFunction rf,
Token tokenWithinAction,
ActionAST node)
@ -54,7 +54,7 @@ public class ActionTranslator implements ActionSplitterListener {
return translateActionChunk(factory, rf, action, node);
}
public static List<ActionChunk> translateActionChunk(OutputModelFactory factory,
public static List<ActionChunk> translateActionChunk(CoreOutputModelFactory factory,
RuleFunction rf,
String action,
ActionAST node)

View File

@ -76,7 +76,7 @@ public class CodeGenerator {
}
public ST generate() {
OutputModelFactory factory;
CoreOutputModelFactory factory;
if ( g.isParser() || g.isCombined() || g.isTreeGrammar() ) {
factory = new ParserFactory(this);
}

View File

@ -0,0 +1,67 @@
package org.antlr.v4.codegen;
import org.antlr.v4.codegen.model.*;
import java.util.List;
/** Filter list of SrcOps and return; default is pass-through filter */
public class CodeGeneratorExtension {
public CoreOutputModelFactory factory;
public CodeGeneratorExtension(CoreOutputModelFactory factory) {
this.factory = factory;
}
public OutputModelObject buildOutputModel(OutputModelObject root) {
return null;
}
public List<SrcOp> alternative(List<SrcOp> ops) { return ops; }
public List<SrcOp> ruleRef(List<SrcOp> ops) { return ops; }
public List<SrcOp> tokenRef(List<SrcOp> ops) { return ops; }
public List<SrcOp> stringRef(List<SrcOp> ops) { return ops; }
public List<SrcOp> epsilon(List<SrcOp> ops) { return ops; }
// ACTIONS
public List<SrcOp> action(List<SrcOp> ops) { return ops; }
public List<SrcOp> forcedAction(List<SrcOp> ops) { return ops; }
public List<SrcOp> sempred(List<SrcOp> ops) { return ops; }
// AST OPS
public List<SrcOp> rootToken(List<SrcOp> ops) { return ops; }
public List<SrcOp> rootRule(List<SrcOp> ops) { return ops; }
// BLOCKS
public List<SrcOp> getChoiceBlock(List<SrcOp> ops) { return ops; }
public List<SrcOp> getEBNFBlock(List<SrcOp> ops) { return ops; }
public List<SrcOp> getLL1ChoiceBlock(List<SrcOp> ops) { return ops; }
public List<SrcOp> getLLStarChoiceBlock(List<SrcOp> ops) { return ops; }
public List<SrcOp> getLL1EBNFBlock(List<SrcOp> ops) { return ops; }
public List<SrcOp> getLLStarEBNFBlock(List<SrcOp> ops) { return ops; }
public List<SrcOp> getLL1Test(List<SrcOp> ops) { return ops; }
/** 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;
}
}

View File

@ -11,16 +11,20 @@ import java.util.*;
* objects such as RuleFunction that surround elements in rule
* functions.
*/
public abstract class OutputModelFactory {
public abstract class CoreOutputModelFactory implements OutputModelFactory {
// Interface to outside world
public Grammar g;
public CodeGenerator gen;
// Post-processing
List<CodeGeneratorExtension> extensions = new ArrayList<CodeGeneratorExtension>();
// Context ptrs
public OutputModelObject file; // root
public OutputModelObject root; // normally ParserFile, LexerFile, ...
public Stack<RuleFunction> currentRule = new Stack<RuleFunction>();
public Alternative currentAlt;
protected OutputModelFactory(CodeGenerator gen) {
protected CoreOutputModelFactory(CodeGenerator gen) {
this.gen = gen;
this.g = gen.g;
}
@ -31,39 +35,23 @@ public abstract class OutputModelFactory {
// ALTERNATIVES / ELEMENTS
public CodeBlock alternative(List<SrcOp> elems) {
return null;
}
public CodeBlock alternative(List<SrcOp> elems) { return null; }
public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) {
return null;
}
public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) { return null; }
public List<SrcOp> tokenRef(GrammarAST ID, GrammarAST label, GrammarAST args) {
return null;
}
public List<SrcOp> tokenRef(GrammarAST ID, GrammarAST label, GrammarAST args) { return null; }
public List<SrcOp> stringRef(GrammarAST ID, GrammarAST label) {
return null;
}
public List<SrcOp> stringRef(GrammarAST ID, GrammarAST label) { return null; }
public CodeBlock epsilon() {
return null;
}
public CodeBlock epsilon() { return null; }
// ACTIONS
public SrcOp action(GrammarAST ast) {
return null;
}
public List<SrcOp> action(GrammarAST ast) { return null; }
public SrcOp forcedAction(GrammarAST ast) {
return null;
}
public List<SrcOp> forcedAction(GrammarAST ast) { return null; }
public SrcOp sempred(GrammarAST ast) {
return null;
}
public List<SrcOp> sempred(GrammarAST ast) { return null; }
// AST OPS
@ -73,32 +61,31 @@ public abstract class OutputModelFactory {
// BLOCKS
public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlock> alts) {
return null;
}
public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlock> alts) { return null; }
public Choice getEBNFBlock(GrammarAST ebnfRoot, List<CodeBlock> alts) {
return null;
}
public Choice getEBNFBlock(GrammarAST ebnfRoot, List<CodeBlock> alts) { return null; }
public Choice getLL1ChoiceBlock(BlockAST blkAST, List<CodeBlock> alts) {
return null;
}
public Choice getLL1ChoiceBlock(BlockAST blkAST, List<CodeBlock> alts) { return null; }
public Choice getLLStarChoiceBlock(BlockAST blkAST, List<CodeBlock> alts) {
return null;
}
public Choice getLLStarChoiceBlock(BlockAST blkAST, List<CodeBlock> alts) { return null; }
public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List<CodeBlock> alts) {
return null;
}
public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List<CodeBlock> alts) { return null; }
public Choice getLLStarEBNFBlock(GrammarAST ebnfRoot, List<CodeBlock> alts) {
return null;
}
public Choice getLLStarEBNFBlock(GrammarAST ebnfRoot, List<CodeBlock> alts) { return null; }
public SrcOp getLL1Test(IntervalSet look, GrammarAST blkAST) {
return null;
public SrcOp getLL1Test(IntervalSet look, GrammarAST blkAST) { return null; }
public List<SrcOp> list(Object... values) {
List<SrcOp> x = new ArrayList<SrcOp>(values.length);
for (Object v : values) {
if ( v!=null ) {
if ( v instanceof SrcOp ) x.add((SrcOp)v);
else if ( v instanceof List<?> ) x.addAll((List)v);
else g.tool.errMgr.toolError(ErrorType.INTERNAL_ERROR,
"add type " + v.getClass() + " to list");
}
}
return x;
}
}

View File

@ -3,7 +3,7 @@ package org.antlr.v4.codegen;
import org.antlr.v4.codegen.model.*;
/** */
public class LexerFactory extends OutputModelFactory {
public class LexerFactory extends CoreOutputModelFactory {
public LexerFactory(CodeGenerator gen) { super(gen); }
public OutputModelObject buildOutputModel() {

View File

@ -0,0 +1,19 @@
package org.antlr.v4.codegen;
import org.antlr.v4.codegen.model.*;
import org.antlr.v4.codegen.model.ast.AddLeaf;
import java.util.List;
public class ParserASTExtension extends CodeGeneratorExtension {
public ParserASTExtension(CoreOutputModelFactory factory) {
super(factory);
}
@Override
public List<SrcOp> tokenRef(List<SrcOp> ops) {
MatchToken matchOp = (MatchToken)find(ops, MatchToken.class);
SrcOp treeOp = new AddLeaf(factory, matchOp.ast, matchOp);
return factory.list(ops, treeOp);
}
}

View File

@ -2,8 +2,7 @@ package org.antlr.v4.codegen;
import org.antlr.v4.analysis.AnalysisPipeline;
import org.antlr.v4.codegen.model.*;
import org.antlr.v4.codegen.model.ast.AddLeaf;
import org.antlr.v4.misc.*;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.tool.*;
@ -11,7 +10,7 @@ import org.antlr.v4.tool.*;
import java.util.List;
/** */
public class ParserFactory extends OutputModelFactory {
public class ParserFactory extends CoreOutputModelFactory {
public ParserFactory(CodeGenerator gen) { super(gen); }
public OutputModelObject buildOutputModel() {
@ -22,11 +21,11 @@ public class ParserFactory extends OutputModelFactory {
public CodeBlock alternative(List<SrcOp> elems) { return new CodeBlock(this, elems); }
public SrcOp action(GrammarAST ast) { return new Action(this, ast); }
public List<SrcOp> action(GrammarAST ast) { return list(new Action(this, ast)); }
public SrcOp forcedAction(GrammarAST ast) { return new ForcedAction(this, ast); }
public List<SrcOp> forcedAction(GrammarAST ast) { return list(new ForcedAction(this, ast)); }
public SrcOp sempred(GrammarAST ast) { return new SemPred(this, ast); }
public List<SrcOp> sempred(GrammarAST ast) { return list(new SemPred(this, ast)); }
public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) {
InvokeRule r = new InvokeRule(this, ID, label);
@ -34,7 +33,7 @@ public class ParserFactory extends OutputModelFactory {
if ( label!=null && label.parent.getType()==ANTLRParser.PLUS_ASSIGN ) {
a = new AddToLabelList(this, gen.target.getListLabel(label.getText()), r);
}
return Utils.list(r, a);
return list(r, a);
}
public List<SrcOp> tokenRef(GrammarAST ID, GrammarAST label, GrammarAST args) {
@ -44,11 +43,14 @@ public class ParserFactory extends OutputModelFactory {
String listLabel = gen.target.getListLabel(label.getText());
labelOp = new AddToLabelList(this, listLabel, matchOp);
}
/*
SrcOp treeOp = null;
if ( g.hasASTOption() ) {
treeOp = new AddLeaf(this, ID, matchOp);
}
return Utils.list(matchOp, labelOp, treeOp);
return list(matchOp, labelOp, treeOp);
*/
return list(matchOp, labelOp);
}
public List<SrcOp> stringRef(GrammarAST ID, GrammarAST label) {

View File

@ -56,19 +56,19 @@ alternative returns [CodeBlock omo]
element returns [List<SrcOp> omos]
: labeledElement {$omos = $labeledElement.omos;}
| atom[null] {$omos = $atom.omos;}
| ebnf {$omos = Utils.list($ebnf.omo);}
| ACTION {$omos = Utils.list(factory.action($ACTION));}
| FORCED_ACTION {$omos = Utils.list(factory.forcedAction($FORCED_ACTION));}
| SEMPRED {$omos = Utils.list(factory.sempred($SEMPRED));}
| ebnf {$omos = factory.list($ebnf.omo);}
| ACTION {$omos = factory.list(factory.action($ACTION));}
| FORCED_ACTION {$omos = factory.list(factory.forcedAction($FORCED_ACTION));}
| SEMPRED {$omos = factory.list(factory.sempred($SEMPRED));}
| GATED_SEMPRED
| treeSpec
;
labeledElement returns [List<SrcOp> omos]
: ^(ASSIGN ID atom[$ID] ) {$omos = $atom.omos;}
| ^(ASSIGN ID block[$ID,null]) {$omos = Utils.list($block.omo);}
| ^(ASSIGN ID block[$ID,null]) {$omos = factory.list($block.omo);}
| ^(PLUS_ASSIGN ID atom[$ID]) {$omos = $atom.omos;}
| ^(PLUS_ASSIGN ID block[$ID,null]) {$omos = Utils.list($block.omo);}
| ^(PLUS_ASSIGN ID block[$ID,null]) {$omos = factory.list($block.omo);}
;
treeSpec returns [SrcOp omo]

View File

@ -10,7 +10,7 @@ import java.util.List;
public class Action extends RuleElement {
@ModelElement public List<ActionChunk> chunks;
public Action(OutputModelFactory factory, GrammarAST ast) {
public Action(CoreOutputModelFactory factory, GrammarAST ast) {
super(factory,ast);
RuleFunction rf = null;
if ( factory.currentRule.size()>0 ) rf = factory.currentRule.peek();

View File

@ -1,13 +1,13 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
/** */
public class AddToLabelList extends SrcOp {
public String listName;
public LabeledOp opWithResultToAdd;
public AddToLabelList(OutputModelFactory factory, String listName, LabeledOp opWithResultToAdd) {
public AddToLabelList(CoreOutputModelFactory factory, String listName, LabeledOp opWithResultToAdd) {
super(factory);
this.listName = listName;
this.opWithResultToAdd = opWithResultToAdd;

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.runtime.atn.BlockStartState;
import org.antlr.v4.tool.GrammarAST;
@ -9,7 +9,7 @@ import java.util.List;
public class AltBlock extends Choice {
@ModelElement public ThrowNoViableAlt error;
public AltBlock(OutputModelFactory factory,
public AltBlock(CoreOutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
List<CodeBlock> alts)
{

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.codegen.model.decl.*;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
@ -23,7 +23,7 @@ public abstract class Choice extends RuleElement {
@ModelElement public List<CodeBlock> alts;
@ModelElement public List<SrcOp> preamble;
public Choice(OutputModelFactory factory,
public Choice(CoreOutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
List<CodeBlock> alts)
{

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import java.util.*;
@ -8,14 +8,14 @@ import java.util.*;
public class CodeBlock extends SrcOp {
@ModelElement public List<SrcOp> ops;
public CodeBlock(OutputModelFactory factory) { this.factory = factory; }
public CodeBlock(CoreOutputModelFactory factory) { this.factory = factory; }
public CodeBlock(OutputModelFactory factory, List<SrcOp> ops) {
public CodeBlock(CoreOutputModelFactory factory, List<SrcOp> ops) {
super(factory);
this.ops = ops;
}
public CodeBlock(OutputModelFactory factory, final SrcOp elem) {
public CodeBlock(CoreOutputModelFactory factory, final SrcOp elem) {
this(factory, new ArrayList<SrcOp>() {{ add(elem); }});
}

View File

@ -1,10 +1,10 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
public class ForcedAction extends Action {
public ForcedAction(OutputModelFactory factory, GrammarAST ast) {
public ForcedAction(CoreOutputModelFactory factory, GrammarAST ast) {
super(factory, ast);
}
}

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.codegen.model.decl.*;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.atn.RuleTransition;
@ -15,7 +15,7 @@ public class InvokeRule extends RuleElement implements LabeledOp {
public String argExprs;
public String ctxName;
public InvokeRule(OutputModelFactory factory, GrammarAST ast, GrammarAST labelAST) {
public InvokeRule(CoreOutputModelFactory factory, GrammarAST ast, GrammarAST labelAST) {
super(factory, ast);
if ( ast.atnState!=null ) {
RuleTransition ruleTrans = (RuleTransition)ast.atnState.transition(0);

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.DecisionState;
import org.antlr.v4.tool.GrammarAST;
@ -9,7 +9,7 @@ import java.util.List;
/** (A | B | C) */
public class LL1AltBlock extends LL1Choice {
public LL1AltBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
public LL1AltBlock(CoreOutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts);
this.decision = ((DecisionState)blkAST.atnState).decision;

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
import java.util.List;
@ -10,7 +10,7 @@ public abstract class LL1Choice extends Choice {
public List<String[]> altLook;
@ModelElement public ThrowNoViableAlt error;
public LL1Choice(OutputModelFactory factory, GrammarAST blkAST,
public LL1Choice(CoreOutputModelFactory factory, GrammarAST blkAST,
List<CodeBlock> alts)
{
super(factory, blkAST, alts);

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
@ -12,7 +12,7 @@ public abstract class LL1Loop extends Choice {
@ModelElement public List<SrcOp> iteration;
@ModelElement public Sync sync;
public LL1Loop(OutputModelFactory factory,
public LL1Loop(CoreOutputModelFactory factory,
GrammarAST blkAST,
List<CodeBlock> alts)
{

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
import java.util.List;
@ -11,7 +11,7 @@ import java.util.List;
* (A | B | C)?
*/
public class LL1OptionalBlock extends LL1AltBlock {
public LL1OptionalBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
public LL1OptionalBlock(CoreOutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts);
}
}

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.DecisionState;
import org.antlr.v4.tool.GrammarAST;
@ -12,7 +12,7 @@ public class LL1OptionalBlockSingleAlt extends LL1Choice {
@ModelElement public OutputModelObject expr;
@ModelElement public OutputModelObject followExpr;
public LL1OptionalBlockSingleAlt(OutputModelFactory factory,
public LL1OptionalBlockSingleAlt(CoreOutputModelFactory factory,
GrammarAST blkAST,
List<CodeBlock> alts)
{

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.PlusBlockStartState;
import org.antlr.v4.tool.GrammarAST;
@ -20,7 +20,7 @@ public class LL1PlusBlock extends LL1Loop {
@ModelElement public SrcOp loopExpr;
@ModelElement public ThrowNoViableAlt error;
public LL1PlusBlock(OutputModelFactory factory, GrammarAST plusRoot, List<CodeBlock> alts) {
public LL1PlusBlock(CoreOutputModelFactory factory, GrammarAST plusRoot, List<CodeBlock> alts) {
super(factory, plusRoot, alts);
PlusBlockStartState blkStart = (PlusBlockStartState)plusRoot.atnState;

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.PlusBlockStartState;
import org.antlr.v4.tool.GrammarAST;
@ -11,7 +11,7 @@ import java.util.List;
public class LL1PlusBlockSingleAlt extends LL1Loop {
@ModelElement public Sync iterationSync;
public LL1PlusBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
public LL1PlusBlockSingleAlt(CoreOutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts);
PlusBlockStartState plus = (PlusBlockStartState)blkAST.atnState;

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.StarBlockStartState;
import org.antlr.v4.tool.GrammarAST;
@ -14,7 +14,7 @@ public class LL1StarBlock extends LL1Loop {
public String loopLabel;
public String[] exitLook;
public LL1StarBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
public LL1StarBlock(CoreOutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts);
StarBlockStartState blkStart = (StarBlockStartState)blkAST.atnState;

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.StarBlockStartState;
import org.antlr.v4.tool.GrammarAST;
@ -9,7 +9,7 @@ import java.util.List;
/** */
public class LL1StarBlockSingleAlt extends LL1Loop {
public LL1StarBlockSingleAlt(OutputModelFactory factory, GrammarAST starRoot, List<CodeBlock> alts) {
public LL1StarBlockSingleAlt(CoreOutputModelFactory factory, GrammarAST starRoot, List<CodeBlock> alts) {
super(factory, starRoot, alts);
StarBlockStartState star = (StarBlockStartState)starRoot.atnState;

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.*;
import java.util.*;
@ -17,7 +17,7 @@ public class Lexer extends OutputModelObject {
@ModelElement public LinkedHashMap<Integer, Action> actions;
@ModelElement public LinkedHashMap<Integer, Action> sempreds;
public Lexer(OutputModelFactory factory, LexerFile file) {
public Lexer(CoreOutputModelFactory factory, LexerFile file) {
this.factory = factory;
this.file = file; // who contains us?
name = factory.g.getRecognizerName();

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
import java.util.*;
@ -11,10 +11,10 @@ public class LexerFile extends OutputModelObject {
@ModelElement public Lexer lexer;
@ModelElement public Map<String, Action> namedActions;
public LexerFile(OutputModelFactory factory, String fileName) {
public LexerFile(CoreOutputModelFactory factory, String fileName) {
super(factory);
this.fileName = fileName;
factory.file = this;
factory.root = this;
namedActions = new HashMap<String, Action>();
for (String name : factory.gen.g.namedActions.keySet()) {
GrammarAST ast = factory.gen.g.namedActions.get(name);

View File

@ -1,13 +1,13 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
import java.util.List;
public class Loop extends Choice {
public int exitAlt;
public Loop(OutputModelFactory factory,
public Loop(CoreOutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
List<CodeBlock> alts)
{

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.codegen.model.decl.*;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.tool.*;
@ -12,7 +12,7 @@ public class MatchToken extends RuleElement implements LabeledOp {
public String name;
public List<Decl> labels = new ArrayList<Decl>();
public MatchToken(OutputModelFactory factory, TerminalAST ast, GrammarAST labelAST) {
public MatchToken(CoreOutputModelFactory factory, TerminalAST ast, GrammarAST labelAST) {
super(factory, ast);
int ttype = factory.g.getTokenType(ast.getText());
name = factory.gen.target.getTokenTypeAsTargetLabel(factory.g, ttype);

View File

@ -1,13 +1,13 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
import java.util.List;
/** */
public class OptionalBlock extends AltBlock {
public OptionalBlock(OutputModelFactory factory,
public OptionalBlock(CoreOutputModelFactory factory,
GrammarAST questionAST,
List<CodeBlock> alts)
{

View File

@ -1,18 +1,18 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
/** */
public abstract class OutputModelObject {
public OutputModelFactory factory;
public CoreOutputModelFactory factory;
public GrammarAST ast;
public OutputModelObject() {;}
public OutputModelObject(OutputModelFactory factory) { this.factory = factory; }
public OutputModelObject(CoreOutputModelFactory factory) { this.factory = factory; }
public OutputModelObject(OutputModelFactory factory, GrammarAST ast) {
public OutputModelObject(CoreOutputModelFactory factory, GrammarAST ast) {
this.factory = factory;
this.ast = ast;
}

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.*;
import java.util.*;
@ -18,7 +18,7 @@ public class Parser extends OutputModelObject {
@ModelElement public LinkedHashMap<Integer, ForcedAction> actions;
@ModelElement public LinkedHashMap<Integer, Action> sempreds;
public Parser(OutputModelFactory factory, ParserFile file) {
public Parser(CoreOutputModelFactory factory, ParserFile file) {
this.factory = factory;
this.file = file; // who contains us?
name = factory.g.getRecognizerName();

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
import java.util.*;
@ -14,10 +14,10 @@ public class ParserFile extends OutputModelObject {
@ModelElement public Parser parser;
@ModelElement public Map<String, Action> namedActions;
public ParserFile(OutputModelFactory factory, String fileName) {
public ParserFile(CoreOutputModelFactory factory, String fileName) {
super(factory);
this.fileName = fileName;
factory.file = this;
factory.root = this;
TokenLabelType = factory.gen.g.getOption("TokenLabelType");
ASTLabelType = factory.gen.g.getOption("ASTLabelType");
namedActions = new HashMap<String, Action>();

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.tool.GrammarAST;
@ -9,7 +9,7 @@ import java.util.List;
public class PlusBlock extends Loop {
@ModelElement public ThrowNoViableAlt error;
public PlusBlock(OutputModelFactory factory,
public PlusBlock(CoreOutputModelFactory factory,
GrammarAST ebnfRootAST,
List<CodeBlock> alts)
{

View File

@ -1,13 +1,13 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
public class RuleElement extends SrcOp {
/** Associated ATN state for this rule elements (action, token, ruleref, ...) */
public int stateNumber;
public RuleElement(OutputModelFactory factory, GrammarAST ast) {
public RuleElement(CoreOutputModelFactory factory, GrammarAST ast) {
super(factory, ast);
if ( ast.atnState!=null ) stateNumber = ast.atnState.stateNumber;
}

View File

@ -31,11 +31,11 @@ public class RuleFunction extends OutputModelObject {
@ModelElement public Map<String, Action> namedActions;
@ModelElement public Action finallyAction;
public RuleFunction(OutputModelFactory factory) {
public RuleFunction(CoreOutputModelFactory factory) {
super(factory);
}
public RuleFunction(OutputModelFactory factory, Rule r) {
public RuleFunction(CoreOutputModelFactory factory, Rule r) {
super(factory);
this.name = r.name;
if ( r.modifiers!=null && r.modifiers.size()>0 ) {

View File

@ -1,9 +1,9 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
/** */
public class SemPred extends Action {
public SemPred(OutputModelFactory factory, GrammarAST ast) { super(factory,ast); }
public SemPred(CoreOutputModelFactory factory, GrammarAST ast) { super(factory,ast); }
}

View File

@ -1,7 +1,7 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.automata.ATNSerializer;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.runtime.atn.ATN;
import java.util.*;
@ -9,7 +9,7 @@ import java.util.*;
public class SerializedATN extends OutputModelObject {
// TODO: make this into a kind of decl or multiple?
public List<String> serialized;
public SerializedATN(OutputModelFactory factory, ATN atn) {
public SerializedATN(CoreOutputModelFactory factory, ATN atn) {
super(factory);
List<Integer> data = ATNSerializer.getSerialized(atn);
serialized = new ArrayList<String>(data.size());

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.tool.GrammarAST;
/** */
@ -9,8 +9,8 @@ public abstract class SrcOp extends OutputModelObject {
public int uniqueID;
public SrcOp() {;}
public SrcOp(OutputModelFactory factory) { super(factory); }
public SrcOp(OutputModelFactory factory, GrammarAST ast) {
public SrcOp(CoreOutputModelFactory factory) { super(factory); }
public SrcOp(CoreOutputModelFactory factory, GrammarAST ast) {
super(factory,ast);
uniqueID = ast.token.getTokenIndex();
}

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.runtime.atn.BlockStartState;
import org.antlr.v4.tool.GrammarAST;
@ -9,7 +9,7 @@ import java.util.List;
public class StarBlock extends Loop {
public String loopLabel;
public StarBlock(OutputModelFactory factory,
public StarBlock(CoreOutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
List<CodeBlock> alts)
{

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
@ -8,7 +8,7 @@ import org.antlr.v4.tool.GrammarAST;
public class Sync extends SrcOp {
public int decision;
// public BitSetDecl expecting;
public Sync(OutputModelFactory factory,
public Sync(CoreOutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
IntervalSet expecting,
int decision,

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
@ -8,14 +8,9 @@ import org.antlr.v4.tool.GrammarAST;
public class TestSetInline extends SrcOp {
public String varName;
public String[] ttypes;
// public CaptureNextToken nextToken;
// public Choice choice;
public TestSetInline(OutputModelFactory factory, GrammarAST ast, IntervalSet set) {
public TestSetInline(CoreOutputModelFactory factory, GrammarAST ast, IntervalSet set) {
super(factory, ast);
this.ttypes = factory.gen.target.getTokenTypesAsTargetLabels(factory.g, set.toArray());
this.varName = "_la";
// this.choice = choice;
// nextToken = new CaptureNextToken();
// choice.addPreambleOp(nextToken);
}
}

View File

@ -1,12 +1,12 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */
public class ThrowEarlyExitException extends ThrowRecognitionException {
public ThrowEarlyExitException(OutputModelFactory factory, GrammarAST ast, IntervalSet expecting) {
public ThrowEarlyExitException(CoreOutputModelFactory factory, GrammarAST ast, IntervalSet expecting) {
super(factory, ast, expecting);
}
}

View File

@ -1,12 +1,12 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */
public class ThrowNoViableAlt extends ThrowRecognitionException {
public ThrowNoViableAlt(OutputModelFactory factory, GrammarAST blkOrEbnfRootAST,
public ThrowNoViableAlt(CoreOutputModelFactory factory, GrammarAST blkOrEbnfRootAST,
IntervalSet expecting)
{
super(factory, blkOrEbnfRootAST, expecting);

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
@ -11,7 +11,7 @@ public class ThrowRecognitionException extends SrcOp {
public int grammarLine;
public int grammarCharPosInLine;
public ThrowRecognitionException(OutputModelFactory factory, GrammarAST ast, IntervalSet expecting) {
public ThrowRecognitionException(CoreOutputModelFactory factory, GrammarAST ast, IntervalSet expecting) {
super(factory, ast);
//this.decision = ((BlockStartState)ast.ATNState).decision;
grammarLine = ast.getLine();

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model.ast;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.codegen.model.*;
import org.antlr.v4.codegen.model.decl.Decl;
import org.antlr.v4.tool.GrammarAST;
@ -10,7 +10,7 @@ public class AddLeaf extends SrcOp {
public LabeledOp opWithResultToAdd;
public Decl label;
public AddLeaf(OutputModelFactory factory, GrammarAST ast, LabeledOp opWithResultToAdd) {
public AddLeaf(CoreOutputModelFactory factory, GrammarAST ast, LabeledOp opWithResultToAdd) {
super(factory, ast);
this.opWithResultToAdd = opWithResultToAdd;
label = opWithResultToAdd.getLabels().get(0);

View File

@ -1,10 +1,10 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
/** */
public class AttributeDecl extends Decl {
public AttributeDecl(OutputModelFactory factory, String name, String decl) {
public AttributeDecl(CoreOutputModelFactory factory, String name, String decl) {
super(factory, name, decl);
}
}

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.codegen.model.SrcOp;
/** */
@ -9,12 +9,12 @@ public class Decl extends SrcOp {
public String decl; // whole thing if copied from action
public boolean isLocal; // if local var (not in RuleContext struct)
public Decl(OutputModelFactory factory, String name, String decl) {
public Decl(CoreOutputModelFactory factory, String name, String decl) {
this(factory, name);
this.decl = decl;
}
public Decl(OutputModelFactory factory, String name) {
public Decl(CoreOutputModelFactory factory, String name) {
super(factory);
this.name = name;
}

View File

@ -1,10 +1,10 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
public class KidsListDecl extends Decl {
public int level;
public KidsListDecl(OutputModelFactory factory, int level) {
public KidsListDecl(CoreOutputModelFactory factory, int level) {
super(factory, factory.gen.target.getKidsListName(level));
}
}

View File

@ -1,10 +1,10 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
public class RootDecl extends Decl {
public int level;
public RootDecl(OutputModelFactory factory, int level) {
public RootDecl(CoreOutputModelFactory factory, int level) {
super(factory, factory.gen.target.getRootName(level));
}
}

View File

@ -1,11 +1,11 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
/** */
public class RuleContextDecl extends Decl {
public String ctxName;
public RuleContextDecl(OutputModelFactory factory, String name, String ctxName) {
public RuleContextDecl(CoreOutputModelFactory factory, String name, String ctxName) {
super(factory, name);
this.ctxName = ctxName;
}

View File

@ -1,10 +1,10 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
public class RuleContextListDecl extends Decl {
public RuleContextDecl decl;
public RuleContextListDecl(OutputModelFactory factory, String name, RuleContextDecl decl) {
public RuleContextListDecl(CoreOutputModelFactory factory, String name, RuleContextDecl decl) {
super(factory, name);
this.decl = decl;
}

View File

@ -1,6 +1,6 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
import org.antlr.v4.codegen.model.ModelElement;
import org.antlr.v4.tool.Attribute;
@ -11,11 +11,11 @@ public class StructDecl extends Decl {
@ModelElement public List<Decl> attrs = new ArrayList<Decl>();
@ModelElement public Collection<Attribute> ctorAttrs;
public StructDecl(OutputModelFactory factory) {
public StructDecl(CoreOutputModelFactory factory) {
super(factory, null);
}
public StructDecl(OutputModelFactory factory, String name) {
public StructDecl(CoreOutputModelFactory factory, String name) {
super(factory, name);
}

View File

@ -1,10 +1,10 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
/** */
public class TokenDecl extends Decl {
public TokenDecl(OutputModelFactory factory, String varName) {
public TokenDecl(CoreOutputModelFactory factory, String varName) {
super(factory, varName);
}
}

View File

@ -1,10 +1,10 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
/** */
public class TokenListDecl extends Decl {
public TokenListDecl(OutputModelFactory factory, String varName) {
public TokenListDecl(CoreOutputModelFactory factory, String varName) {
super(factory, varName);
}
}

View File

@ -1,10 +1,10 @@
package org.antlr.v4.codegen.model.decl;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.CoreOutputModelFactory;
/** */
public class TokenTypeDecl extends Decl {
public TokenTypeDecl(OutputModelFactory factory, String name) {
public TokenTypeDecl(CoreOutputModelFactory factory, String name) {
super(factory, name);
}
}

View File

@ -108,14 +108,6 @@ public class Utils {
// return x;
// }
public static List list(Object... values) {
List x = new ArrayList(values.length);
for (Object v : values) {
if ( v!=null ) x.add(v);
}
return x;
}
public static int[] toIntArray(List<Integer> list) {
if ( list==null ) return null;
int[] a = new int[list.size()];