forked from jasder/antlr
Use accessor methods for CodeGenerator.templates and CodeGenerator.target
This commit is contained in:
parent
b372d4d88d
commit
371bcc83b2
|
@ -106,7 +106,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker {
|
||||||
|
|
||||||
// use codegen to get correct language templates; that's it though
|
// use codegen to get correct language templates; that's it though
|
||||||
CodeGenerator gen = new CodeGenerator(tool, null, language);
|
CodeGenerator gen = new CodeGenerator(tool, null, language);
|
||||||
codegenTemplates = gen.templates;
|
codegenTemplates = gen.getTemplates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class LexerATNFactory extends ParserATNFactory {
|
||||||
// use codegen to get correct language templates for lexer commands
|
// use codegen to get correct language templates for lexer commands
|
||||||
String language = g.getOptionString("language");
|
String language = g.getOptionString("language");
|
||||||
CodeGenerator gen = new CodeGenerator(g.tool, null, language);
|
CodeGenerator gen = new CodeGenerator(g.tool, null, language);
|
||||||
codegenTemplates = gen.templates;
|
codegenTemplates = gen.getTemplates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -316,12 +316,12 @@ public class ActionTranslator implements ActionSplitterListener {
|
||||||
|
|
||||||
public String getTokenLabel(String x) {
|
public String getTokenLabel(String x) {
|
||||||
if ( node.resolver.resolvesToLabel(x, node) ) return x;
|
if ( node.resolver.resolvesToLabel(x, node) ) return x;
|
||||||
return factory.getGenerator().target.getImplicitTokenLabel(x);
|
return factory.getGenerator().getTarget().getImplicitTokenLabel(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRuleLabel(String x) {
|
public String getRuleLabel(String x) {
|
||||||
if ( node.resolver.resolvesToLabel(x, node) ) return x;
|
if ( node.resolver.resolvesToLabel(x, node) ) return x;
|
||||||
return factory.getGenerator().target.getImplicitRuleLabel(x);
|
return factory.getGenerator().getTarget().getImplicitRuleLabel(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,14 +56,14 @@ public class CodeGenPipeline {
|
||||||
idTypes.add(ANTLRParser.TOKEN_REF);
|
idTypes.add(ANTLRParser.TOKEN_REF);
|
||||||
List<GrammarAST> idNodes = g.ast.getNodesWithType(idTypes);
|
List<GrammarAST> idNodes = g.ast.getNodesWithType(idTypes);
|
||||||
for (GrammarAST idNode : idNodes) {
|
for (GrammarAST idNode : idNodes) {
|
||||||
if ( gen.target.grammarSymbolCausesIssueInGeneratedCode(idNode) ) {
|
if ( gen.getTarget().grammarSymbolCausesIssueInGeneratedCode(idNode) ) {
|
||||||
g.tool.errMgr.grammarError(ErrorType.USE_OF_BAD_WORD,
|
g.tool.errMgr.grammarError(ErrorType.USE_OF_BAD_WORD,
|
||||||
g.fileName, idNode.getToken(),
|
g.fileName, idNode.getToken(),
|
||||||
idNode.getText());
|
idNode.getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( gen.templates==null ) return;
|
if ( gen.getTemplates()==null ) return;
|
||||||
|
|
||||||
if ( g.isLexer() ) {
|
if ( g.isLexer() ) {
|
||||||
ST lexer = gen.generateLexer();
|
ST lexer = gen.generateLexer();
|
||||||
|
|
|
@ -67,8 +67,8 @@ public class CodeGenerator {
|
||||||
@NotNull
|
@NotNull
|
||||||
public final Tool tool;
|
public final Tool tool;
|
||||||
|
|
||||||
public Target target;
|
private Target target;
|
||||||
public STGroup templates;
|
private STGroup templates;
|
||||||
|
|
||||||
public int lineWidth = 72;
|
public int lineWidth = 72;
|
||||||
|
|
||||||
|
@ -83,6 +83,14 @@ public class CodeGenerator {
|
||||||
loadTemplates(language);
|
loadTemplates(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Target getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public STGroup getTemplates() {
|
||||||
|
return templates;
|
||||||
|
}
|
||||||
|
|
||||||
void loadLanguageTarget(String language) {
|
void loadLanguageTarget(String language) {
|
||||||
String targetName = "org.antlr.v4.codegen."+language+"Target";
|
String targetName = "org.antlr.v4.codegen."+language+"Target";
|
||||||
try {
|
try {
|
||||||
|
@ -161,7 +169,7 @@ public class CodeGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ST walk(OutputModelObject outputModel) {
|
private ST walk(OutputModelObject outputModel) {
|
||||||
OutputModelWalker walker = new OutputModelWalker(tool, templates);
|
OutputModelWalker walker = new OutputModelWalker(tool, getTemplates());
|
||||||
return walker.walk(outputModel);
|
return walker.walk(outputModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,33 +213,33 @@ public class CodeGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeRecognizer(ST outputFileST) {
|
public void writeRecognizer(ST outputFileST) {
|
||||||
target.genFile(g, outputFileST, getRecognizerFileName());
|
getTarget().genFile(g, outputFileST, getRecognizerFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeListener(ST outputFileST) {
|
public void writeListener(ST outputFileST) {
|
||||||
target.genFile(g,outputFileST, getListenerFileName());
|
getTarget().genFile(g,outputFileST, getListenerFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBaseListener(ST outputFileST) {
|
public void writeBaseListener(ST outputFileST) {
|
||||||
target.genFile(g,outputFileST, getBaseListenerFileName());
|
getTarget().genFile(g,outputFileST, getBaseListenerFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeVisitor(ST outputFileST) {
|
public void writeVisitor(ST outputFileST) {
|
||||||
target.genFile(g,outputFileST, getVisitorFileName());
|
getTarget().genFile(g,outputFileST, getVisitorFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBaseVisitor(ST outputFileST) {
|
public void writeBaseVisitor(ST outputFileST) {
|
||||||
target.genFile(g,outputFileST, getBaseVisitorFileName());
|
getTarget().genFile(g,outputFileST, getBaseVisitorFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeHeaderFile() {
|
public void writeHeaderFile() {
|
||||||
String fileName = getHeaderFileName();
|
String fileName = getHeaderFileName();
|
||||||
if ( fileName==null ) return;
|
if ( fileName==null ) return;
|
||||||
if ( templates.isDefined("headerFile") ) {
|
if ( getTemplates().isDefined("headerFile") ) {
|
||||||
ST extST = templates.getInstanceOf("headerFileExtension");
|
ST extST = getTemplates().getInstanceOf("headerFileExtension");
|
||||||
ST headerFileST = null;
|
ST headerFileST = null;
|
||||||
// TODO: don't hide this header file generation here!
|
// TODO: don't hide this header file generation here!
|
||||||
target.genRecognizerHeaderFile(g,headerFileST,extST.render(lineWidth));
|
getTarget().genRecognizerHeaderFile(g,headerFileST,extST.render(lineWidth));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +249,7 @@ public class CodeGenerator {
|
||||||
ST tokenVocabSerialization = getTokenVocabOutput();
|
ST tokenVocabSerialization = getTokenVocabOutput();
|
||||||
String fileName = getVocabFileName();
|
String fileName = getVocabFileName();
|
||||||
if ( fileName!=null ) {
|
if ( fileName!=null ) {
|
||||||
target.genFile(g, tokenVocabSerialization, fileName);
|
getTarget().genFile(g, tokenVocabSerialization, fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +274,7 @@ public class CodeGenerator {
|
||||||
* just use T.java as output regardless of type.
|
* just use T.java as output regardless of type.
|
||||||
*/
|
*/
|
||||||
public String getRecognizerFileName() {
|
public String getRecognizerFileName() {
|
||||||
ST extST = templates.getInstanceOf("codeFileExtension");
|
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||||
String recognizerName = g.getRecognizerName();
|
String recognizerName = g.getRecognizerName();
|
||||||
return recognizerName+extST.render();
|
return recognizerName+extST.render();
|
||||||
}
|
}
|
||||||
|
@ -276,7 +284,7 @@ public class CodeGenerator {
|
||||||
*/
|
*/
|
||||||
public String getListenerFileName() {
|
public String getListenerFileName() {
|
||||||
assert g.name != null;
|
assert g.name != null;
|
||||||
ST extST = templates.getInstanceOf("codeFileExtension");
|
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||||
String listenerName = g.name + "Listener";
|
String listenerName = g.name + "Listener";
|
||||||
return listenerName+extST.render();
|
return listenerName+extST.render();
|
||||||
}
|
}
|
||||||
|
@ -286,7 +294,7 @@ public class CodeGenerator {
|
||||||
*/
|
*/
|
||||||
public String getVisitorFileName() {
|
public String getVisitorFileName() {
|
||||||
assert g.name != null;
|
assert g.name != null;
|
||||||
ST extST = templates.getInstanceOf("codeFileExtension");
|
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||||
String listenerName = g.name + "Visitor";
|
String listenerName = g.name + "Visitor";
|
||||||
return listenerName+extST.render();
|
return listenerName+extST.render();
|
||||||
}
|
}
|
||||||
|
@ -296,7 +304,7 @@ public class CodeGenerator {
|
||||||
*/
|
*/
|
||||||
public String getBaseListenerFileName() {
|
public String getBaseListenerFileName() {
|
||||||
assert g.name != null;
|
assert g.name != null;
|
||||||
ST extST = templates.getInstanceOf("codeFileExtension");
|
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||||
String listenerName = g.name + "BaseListener";
|
String listenerName = g.name + "BaseListener";
|
||||||
return listenerName+extST.render();
|
return listenerName+extST.render();
|
||||||
}
|
}
|
||||||
|
@ -306,7 +314,7 @@ public class CodeGenerator {
|
||||||
*/
|
*/
|
||||||
public String getBaseVisitorFileName() {
|
public String getBaseVisitorFileName() {
|
||||||
assert g.name != null;
|
assert g.name != null;
|
||||||
ST extST = templates.getInstanceOf("codeFileExtension");
|
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||||
String listenerName = g.name + "BaseVisitor";
|
String listenerName = g.name + "BaseVisitor";
|
||||||
return listenerName+extST.render();
|
return listenerName+extST.render();
|
||||||
}
|
}
|
||||||
|
@ -319,7 +327,7 @@ public class CodeGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHeaderFileName() {
|
public String getHeaderFileName() {
|
||||||
ST extST = templates.getInstanceOf("headerFileExtension");
|
ST extST = getTemplates().getInstanceOf("headerFileExtension");
|
||||||
if ( extST==null ) return null;
|
if ( extST==null ) return null;
|
||||||
String recognizerName = g.getRecognizerName();
|
String recognizerName = g.getRecognizerName();
|
||||||
return recognizerName+extST.render();
|
return recognizerName+extST.render();
|
||||||
|
|
|
@ -213,7 +213,7 @@ public class OutputModelController {
|
||||||
|
|
||||||
// now inject code to start alts
|
// now inject code to start alts
|
||||||
CodeGenerator gen = delegate.getGenerator();
|
CodeGenerator gen = delegate.getGenerator();
|
||||||
STGroup codegenTemplates = gen.templates;
|
STGroup codegenTemplates = gen.getTemplates();
|
||||||
|
|
||||||
// pick out alt(s) for primaries
|
// pick out alt(s) for primaries
|
||||||
CodeBlockForOuterMostAlt outerAlt = (CodeBlockForOuterMostAlt)function.code.get(0);
|
CodeBlockForOuterMostAlt outerAlt = (CodeBlockForOuterMostAlt)function.code.get(0);
|
||||||
|
@ -300,7 +300,7 @@ public class OutputModelController {
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
|
|
||||||
function.ctxType = gen.target.getRuleFunctionContextStructName(function);
|
function.ctxType = gen.getTarget().getRuleFunctionContextStructName(function);
|
||||||
|
|
||||||
function.postamble = rulePostamble(function, r);
|
function.postamble = rulePostamble(function, r);
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ public class OutputModelController {
|
||||||
|
|
||||||
CodeGenerator gen = delegate.getGenerator();
|
CodeGenerator gen = delegate.getGenerator();
|
||||||
Grammar g = delegate.getGrammar();
|
Grammar g = delegate.getGrammar();
|
||||||
String ctxType = gen.target.getRuleFunctionContextStructName(r);
|
String ctxType = gen.getTarget().getRuleFunctionContextStructName(r);
|
||||||
RuleActionFunction raf = lexer.actionFuncs.get(r);
|
RuleActionFunction raf = lexer.actionFuncs.get(r);
|
||||||
if ( raf==null ) {
|
if ( raf==null ) {
|
||||||
raf = new RuleActionFunction(delegate, r, ctxType);
|
raf = new RuleActionFunction(delegate, r, ctxType);
|
||||||
|
|
|
@ -171,7 +171,7 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TokenListDecl getTokenListLabelDecl(String label) {
|
public TokenListDecl getTokenListLabelDecl(String label) {
|
||||||
return new TokenListDecl(this, gen.target.getListLabel(label));
|
return new TokenListDecl(this, gen.getTarget().getListLabel(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -230,7 +230,7 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
c.label = d;
|
c.label = d;
|
||||||
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), d);
|
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), d);
|
||||||
if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
|
if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
|
||||||
String listLabel = gen.target.getListLabel(label);
|
String listLabel = gen.getTarget().getListLabel(label);
|
||||||
TokenListDecl l = new TokenListDecl(this, listLabel);
|
TokenListDecl l = new TokenListDecl(this, listLabel);
|
||||||
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), l);
|
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), l);
|
||||||
}
|
}
|
||||||
|
@ -331,20 +331,20 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
Decl d;
|
Decl d;
|
||||||
if ( ast.getType()==ANTLRParser.SET || ast.getType()==ANTLRParser.WILDCARD ) {
|
if ( ast.getType()==ANTLRParser.SET || ast.getType()==ANTLRParser.WILDCARD ) {
|
||||||
String implLabel =
|
String implLabel =
|
||||||
gen.target.getImplicitSetLabel(String.valueOf(ast.token.getTokenIndex()));
|
gen.getTarget().getImplicitSetLabel(String.valueOf(ast.token.getTokenIndex()));
|
||||||
d = getTokenLabelDecl(implLabel);
|
d = getTokenLabelDecl(implLabel);
|
||||||
((TokenDecl)d).isImplicit = true;
|
((TokenDecl)d).isImplicit = true;
|
||||||
}
|
}
|
||||||
else if ( ast.getType()==ANTLRParser.RULE_REF ) { // a rule reference?
|
else if ( ast.getType()==ANTLRParser.RULE_REF ) { // a rule reference?
|
||||||
Rule r = g.getRule(ast.getText());
|
Rule r = g.getRule(ast.getText());
|
||||||
String implLabel = gen.target.getImplicitRuleLabel(ast.getText());
|
String implLabel = gen.getTarget().getImplicitRuleLabel(ast.getText());
|
||||||
String ctxName =
|
String ctxName =
|
||||||
gen.target.getRuleFunctionContextStructName(r);
|
gen.getTarget().getRuleFunctionContextStructName(r);
|
||||||
d = new RuleContextDecl(this, implLabel, ctxName);
|
d = new RuleContextDecl(this, implLabel, ctxName);
|
||||||
((RuleContextDecl)d).isImplicit = true;
|
((RuleContextDecl)d).isImplicit = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String implLabel = gen.target.getImplicitTokenLabel(ast.getText());
|
String implLabel = gen.getTarget().getImplicitTokenLabel(ast.getText());
|
||||||
d = getTokenLabelDecl(implLabel);
|
d = getTokenLabelDecl(implLabel);
|
||||||
((TokenDecl)d).isImplicit = true;
|
((TokenDecl)d).isImplicit = true;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
public AddToLabelList getAddToListOpIfListLabelPresent(LabeledOp op, GrammarAST label) {
|
public AddToLabelList getAddToListOpIfListLabelPresent(LabeledOp op, GrammarAST label) {
|
||||||
AddToLabelList labelOp = null;
|
AddToLabelList labelOp = null;
|
||||||
if ( label!=null && label.parent.getType()==ANTLRParser.PLUS_ASSIGN ) {
|
if ( label!=null && label.parent.getType()==ANTLRParser.PLUS_ASSIGN ) {
|
||||||
String listLabel = gen.target.getListLabel(label.getText());
|
String listLabel = gen.getTarget().getListLabel(label.getText());
|
||||||
labelOp = new AddToLabelList(this, listLabel, op.getLabels().get(0));
|
labelOp = new AddToLabelList(this, listLabel, op.getLabels().get(0));
|
||||||
}
|
}
|
||||||
return labelOp;
|
return labelOp;
|
||||||
|
|
|
@ -350,20 +350,20 @@ public class Target {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getListLabel(String label) {
|
public String getListLabel(String label) {
|
||||||
ST st = gen.templates.getInstanceOf("ListLabelName");
|
ST st = gen.getTemplates().getInstanceOf("ListLabelName");
|
||||||
st.add("label", label);
|
st.add("label", label);
|
||||||
return st.render();
|
return st.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRuleFunctionContextStructName(Rule r) {
|
public String getRuleFunctionContextStructName(Rule r) {
|
||||||
if ( r.g.isLexer() ) {
|
if ( r.g.isLexer() ) {
|
||||||
return gen.templates.getInstanceOf("LexerRuleContext").render();
|
return gen.getTemplates().getInstanceOf("LexerRuleContext").render();
|
||||||
}
|
}
|
||||||
return Utils.capitalize(r.name)+gen.templates.getInstanceOf("RuleContextNameSuffix").render();
|
return Utils.capitalize(r.name)+gen.getTemplates().getInstanceOf("RuleContextNameSuffix").render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAltLabelContextStructName(String label) {
|
public String getAltLabelContextStructName(String label) {
|
||||||
return Utils.capitalize(label)+gen.templates.getInstanceOf("RuleContextNameSuffix").render();
|
return Utils.capitalize(label)+gen.getTemplates().getInstanceOf("RuleContextNameSuffix").render();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** If we know which actual function, we can provide the actual ctx type.
|
/** If we know which actual function, we can provide the actual ctx type.
|
||||||
|
@ -374,15 +374,15 @@ public class Target {
|
||||||
public String getRuleFunctionContextStructName(RuleFunction function) {
|
public String getRuleFunctionContextStructName(RuleFunction function) {
|
||||||
Rule r = function.rule;
|
Rule r = function.rule;
|
||||||
if ( r.g.isLexer() ) {
|
if ( r.g.isLexer() ) {
|
||||||
return gen.templates.getInstanceOf("LexerRuleContext").render();
|
return gen.getTemplates().getInstanceOf("LexerRuleContext").render();
|
||||||
}
|
}
|
||||||
return Utils.capitalize(r.name)+gen.templates.getInstanceOf("RuleContextNameSuffix").render();
|
return Utils.capitalize(r.name)+gen.getTemplates().getInstanceOf("RuleContextNameSuffix").render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// should be same for all refs to same token like ctx.ID within single rule function
|
// should be same for all refs to same token like ctx.ID within single rule function
|
||||||
// for literals like 'while', we gen _s<ttype>
|
// for literals like 'while', we gen _s<ttype>
|
||||||
public String getImplicitTokenLabel(String tokenName) {
|
public String getImplicitTokenLabel(String tokenName) {
|
||||||
ST st = gen.templates.getInstanceOf("ImplicitTokenLabel");
|
ST st = gen.getTemplates().getInstanceOf("ImplicitTokenLabel");
|
||||||
int ttype = gen.g.getTokenType(tokenName);
|
int ttype = gen.g.getTokenType(tokenName);
|
||||||
if ( tokenName.startsWith("'") ) {
|
if ( tokenName.startsWith("'") ) {
|
||||||
return "s"+ttype;
|
return "s"+ttype;
|
||||||
|
@ -394,19 +394,19 @@ public class Target {
|
||||||
|
|
||||||
// x=(A|B)
|
// x=(A|B)
|
||||||
public String getImplicitSetLabel(String id) {
|
public String getImplicitSetLabel(String id) {
|
||||||
ST st = gen.templates.getInstanceOf("ImplicitSetLabel");
|
ST st = gen.getTemplates().getInstanceOf("ImplicitSetLabel");
|
||||||
st.add("id", id);
|
st.add("id", id);
|
||||||
return st.render();
|
return st.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImplicitRuleLabel(String ruleName) {
|
public String getImplicitRuleLabel(String ruleName) {
|
||||||
ST st = gen.templates.getInstanceOf("ImplicitRuleLabel");
|
ST st = gen.getTemplates().getInstanceOf("ImplicitRuleLabel");
|
||||||
st.add("ruleName", ruleName);
|
st.add("ruleName", ruleName);
|
||||||
return st.render();
|
return st.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getElementListName(String name) {
|
public String getElementListName(String name) {
|
||||||
ST st = gen.templates.getInstanceOf("ElementListName");
|
ST st = gen.getTemplates().getInstanceOf("ElementListName");
|
||||||
st.add("elemName", getElementName(name));
|
st.add("elemName", getElementName(name));
|
||||||
return st.render();
|
return st.render();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ public abstract class Choice extends RuleElement {
|
||||||
List<String[]> altLook = new ArrayList<String[]>();
|
List<String[]> altLook = new ArrayList<String[]>();
|
||||||
for (int a=1; a<altLookSets.length; a++) {
|
for (int a=1; a<altLookSets.length; a++) {
|
||||||
IntervalSet s = altLookSets[a];
|
IntervalSet s = altLookSets[a];
|
||||||
altLook.add(factory.getGenerator().target.getTokenTypesAsTargetLabels(factory.getGrammar(), s.toArray()));
|
altLook.add(factory.getGenerator().getTarget().getTokenTypesAsTargetLabels(factory.getGrammar(), s.toArray()));
|
||||||
}
|
}
|
||||||
return altLook;
|
return altLook;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class InvokeRule extends RuleElement implements LabeledOp {
|
||||||
this.name = ast.getText();
|
this.name = ast.getText();
|
||||||
CodeGenerator gen = factory.getGenerator();
|
CodeGenerator gen = factory.getGenerator();
|
||||||
Rule r = factory.getGrammar().getRule(name);
|
Rule r = factory.getGrammar().getRule(name);
|
||||||
ctxName = gen.target.getRuleFunctionContextStructName(r);
|
ctxName = gen.getTarget().getRuleFunctionContextStructName(r);
|
||||||
|
|
||||||
// TODO: move to factory
|
// TODO: move to factory
|
||||||
RuleFunction rf = factory.getCurrentRuleFunction();
|
RuleFunction rf = factory.getCurrentRuleFunction();
|
||||||
|
@ -73,7 +73,7 @@ public class InvokeRule extends RuleElement implements LabeledOp {
|
||||||
String label = labelAST.getText();
|
String label = labelAST.getText();
|
||||||
if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
|
if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
|
||||||
factory.defineImplicitLabel(ast, this);
|
factory.defineImplicitLabel(ast, this);
|
||||||
String listLabel = gen.target.getListLabel(label);
|
String listLabel = gen.getTarget().getListLabel(label);
|
||||||
RuleContextListDecl l = new RuleContextListDecl(factory, listLabel, ctxName);
|
RuleContextListDecl l = new RuleContextListDecl(factory, listLabel, ctxName);
|
||||||
rf.addContextDecl(ast.getAltLabel(), l);
|
rf.addContextDecl(ast.getAltLabel(), l);
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public class InvokeRule extends RuleElement implements LabeledOp {
|
||||||
|
|
||||||
// If action refs rule as rulename not label, we need to define implicit label
|
// If action refs rule as rulename not label, we need to define implicit label
|
||||||
if ( factory.getCurrentOuterMostAlt().ruleRefsInActions.containsKey(ast.getText()) ) {
|
if ( factory.getCurrentOuterMostAlt().ruleRefsInActions.containsKey(ast.getText()) ) {
|
||||||
String label = gen.target.getImplicitRuleLabel(ast.getText());
|
String label = gen.getTarget().getImplicitRuleLabel(ast.getText());
|
||||||
RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
|
RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
|
||||||
labels.add(d);
|
labels.add(d);
|
||||||
rf.addContextDecl(ast.getAltLabel(), d);
|
rf.addContextDecl(ast.getAltLabel(), d);
|
||||||
|
|
|
@ -71,11 +71,11 @@ public class LL1PlusBlock extends LL1Loop {
|
||||||
|
|
||||||
loopExpr = addCodeForLoopLookaheadTempVar(all);
|
loopExpr = addCodeForLoopLookaheadTempVar(all);
|
||||||
|
|
||||||
loopLabel = gen.target.getLoopLabel(plusRoot);
|
loopLabel = gen.getTarget().getLoopLabel(plusRoot);
|
||||||
loopCounterVar = gen.target.getLoopCounter(plusRoot);
|
loopCounterVar = gen.getTarget().getLoopCounter(plusRoot);
|
||||||
|
|
||||||
IntervalSet exitLookSet = altLookSets[altLookSets.length-1];
|
IntervalSet exitLookSet = altLookSets[altLookSets.length-1];
|
||||||
this.exitLook = gen.target.getTokenTypesAsTargetLabels(g,
|
this.exitLook = gen.getTarget().getTokenTypesAsTargetLabels(g,
|
||||||
exitLookSet.toArray());
|
exitLookSet.toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,9 @@ public class LL1StarBlock extends LL1Loop {
|
||||||
System.arraycopy(altLookSets, 0, copy, 0, altLookSets.length-1); // remove last (exit) alt
|
System.arraycopy(altLookSets, 0, copy, 0, altLookSets.length-1); // remove last (exit) alt
|
||||||
altLookSets = copy;
|
altLookSets = copy;
|
||||||
altLook = getAltLookaheadAsStringLists(altLookSets);
|
altLook = getAltLookaheadAsStringLists(altLookSets);
|
||||||
loopLabel = factory.getGenerator().target.getLoopLabel(starRootAST);
|
loopLabel = factory.getGenerator().getTarget().getLoopLabel(starRootAST);
|
||||||
|
|
||||||
this.exitLook =
|
this.exitLook =
|
||||||
factory.getGenerator().target.getTokenTypesAsTargetLabels(factory.getGrammar(), lastLook.toArray());
|
factory.getGenerator().getTarget().getTokenTypesAsTargetLabels(factory.getGrammar(), lastLook.toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class LeftRecursiveRuleFunction extends RuleFunction {
|
||||||
GrammarAST rrefAST = (GrammarAST)idAST.getParent().getChild(1);
|
GrammarAST rrefAST = (GrammarAST)idAST.getParent().getChild(1);
|
||||||
if ( rrefAST.getType() == ANTLRParser.RULE_REF ) {
|
if ( rrefAST.getType() == ANTLRParser.RULE_REF ) {
|
||||||
Rule targetRule = factory.getGrammar().getRule(rrefAST.getText());
|
Rule targetRule = factory.getGrammar().getRule(rrefAST.getText());
|
||||||
String ctxName = gen.target.getRuleFunctionContextStructName(targetRule);
|
String ctxName = gen.getTarget().getRuleFunctionContextStructName(targetRule);
|
||||||
RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
|
RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
|
||||||
StructDecl struct = ruleCtx;
|
StructDecl struct = ruleCtx;
|
||||||
if ( altLabelCtxs!=null ) {
|
if ( altLabelCtxs!=null ) {
|
||||||
|
|
|
@ -84,13 +84,13 @@ public class Lexer extends OutputModelObject {
|
||||||
if ( tokenNames[i].charAt(0)=='\'' ) {
|
if ( tokenNames[i].charAt(0)=='\'' ) {
|
||||||
boolean addQuotes = false;
|
boolean addQuotes = false;
|
||||||
tokenNames[i] =
|
tokenNames[i] =
|
||||||
gen.target.getTargetStringLiteralFromANTLRStringLiteral(gen,
|
gen.getTarget().getTargetStringLiteralFromANTLRStringLiteral(gen,
|
||||||
tokenNames[i],
|
tokenNames[i],
|
||||||
addQuotes);
|
addQuotes);
|
||||||
tokenNames[i] = "\"'"+tokenNames[i]+"'\"";
|
tokenNames[i] = "\"'"+tokenNames[i]+"'\"";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tokenNames[i] = gen.target.getTargetStringLiteralFromString(tokenNames[i], true);
|
tokenNames[i] = gen.getTarget().getTargetStringLiteralFromString(tokenNames[i], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ruleNames = g.rules.keySet();
|
ruleNames = g.rules.keySet();
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class MatchToken extends RuleElement implements LabeledOp {
|
||||||
Grammar g = factory.getGrammar();
|
Grammar g = factory.getGrammar();
|
||||||
CodeGenerator gen = factory.getGenerator();
|
CodeGenerator gen = factory.getGenerator();
|
||||||
ttype = g.getTokenType(ast.getText());
|
ttype = g.getTokenType(ast.getText());
|
||||||
name = gen.target.getTokenTypeAsTargetLabel(g, ttype);
|
name = gen.getTarget().getTokenTypeAsTargetLabel(g, ttype);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MatchToken(OutputModelFactory factory, GrammarAST ast) {
|
public MatchToken(OutputModelFactory factory, GrammarAST ast) {
|
||||||
|
|
|
@ -82,13 +82,13 @@ public class Parser extends OutputModelObject {
|
||||||
if ( tokenNames[i].charAt(0)=='\'' ) {
|
if ( tokenNames[i].charAt(0)=='\'' ) {
|
||||||
boolean addQuotes = false;
|
boolean addQuotes = false;
|
||||||
tokenNames[i] =
|
tokenNames[i] =
|
||||||
gen.target.getTargetStringLiteralFromANTLRStringLiteral(gen,
|
gen.getTarget().getTargetStringLiteralFromANTLRStringLiteral(gen,
|
||||||
tokenNames[i],
|
tokenNames[i],
|
||||||
addQuotes);
|
addQuotes);
|
||||||
tokenNames[i] = "\"'"+tokenNames[i]+"'\"";
|
tokenNames[i] = "\"'"+tokenNames[i]+"'\"";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tokenNames[i] = gen.target.getTargetStringLiteralFromString(tokenNames[i], true);
|
tokenNames[i] = gen.getTarget().getTargetStringLiteralFromString(tokenNames[i], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ruleNames = g.rules.keySet();
|
ruleNames = g.rules.keySet();
|
||||||
|
|
|
@ -249,7 +249,7 @@ public class RuleFunction extends OutputModelObject {
|
||||||
List<Decl> decls = new ArrayList<Decl>();
|
List<Decl> decls = new ArrayList<Decl>();
|
||||||
if ( t.getType()==RULE_REF ) {
|
if ( t.getType()==RULE_REF ) {
|
||||||
Rule rref = factory.getGrammar().getRule(t.getText());
|
Rule rref = factory.getGrammar().getRule(t.getText());
|
||||||
String ctxName = factory.getGenerator().target
|
String ctxName = factory.getGenerator().getTarget()
|
||||||
.getRuleFunctionContextStructName(rref);
|
.getRuleFunctionContextStructName(rref);
|
||||||
if ( needList ) {
|
if ( needList ) {
|
||||||
decls.add( new ContextRuleListGetterDecl(factory, refLabelName, ctxName) );
|
decls.add( new ContextRuleListGetterDecl(factory, refLabelName, ctxName) );
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class SemPred extends Action {
|
||||||
if (predicate.startsWith("{") && predicate.endsWith("}?")) {
|
if (predicate.startsWith("{") && predicate.endsWith("}?")) {
|
||||||
predicate = predicate.substring(1, predicate.length() - 2);
|
predicate = predicate.substring(1, predicate.length() - 2);
|
||||||
}
|
}
|
||||||
predicate = gen.target.getTargetStringLiteralFromString(predicate);
|
predicate = gen.getTarget().getTargetStringLiteralFromString(predicate);
|
||||||
|
|
||||||
if ( failNode==null ) return;
|
if ( failNode==null ) return;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class SemPred extends Action {
|
||||||
failActionNode);
|
failActionNode);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = gen.target.getTargetStringLiteralFromANTLRStringLiteral(gen,
|
msg = gen.getTarget().getTargetStringLiteralFromANTLRStringLiteral(gen,
|
||||||
failNode.getText(),
|
failNode.getText(),
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class SerializedATN extends OutputModelObject {
|
||||||
IntegerList data = ATNSerializer.getSerialized(factory.getGrammar(), atn);
|
IntegerList data = ATNSerializer.getSerialized(factory.getGrammar(), atn);
|
||||||
serialized = new ArrayList<String>(data.size());
|
serialized = new ArrayList<String>(data.size());
|
||||||
for (int c : data.toArray()) {
|
for (int c : data.toArray()) {
|
||||||
String encoded = factory.getGenerator().target.encodeIntAsCharEscape(c == -1 ? Character.MAX_VALUE : c);
|
String encoded = factory.getGenerator().getTarget().encodeIntAsCharEscape(c == -1 ? Character.MAX_VALUE : c);
|
||||||
serialized.add(encoded);
|
serialized.add(encoded);
|
||||||
}
|
}
|
||||||
// System.out.println(ATNSerializer.getDecoded(factory.getGrammar(), atn));
|
// System.out.println(ATNSerializer.getDecoded(factory.getGrammar(), atn));
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class StarBlock extends Loop {
|
||||||
List<CodeBlockForAlt> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, blkOrEbnfRootAST, alts);
|
super(factory, blkOrEbnfRootAST, alts);
|
||||||
loopLabel = factory.getGenerator().target.getLoopLabel(blkOrEbnfRootAST);
|
loopLabel = factory.getGenerator().getTarget().getLoopLabel(blkOrEbnfRootAST);
|
||||||
StarLoopEntryState star = (StarLoopEntryState)blkOrEbnfRootAST.atnState;
|
StarLoopEntryState star = (StarLoopEntryState)blkOrEbnfRootAST.atnState;
|
||||||
loopBackStateNumber = star.loopBackState.stateNumber;
|
loopBackStateNumber = star.loopBackState.stateNumber;
|
||||||
decision = star.decision;
|
decision = star.decision;
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class TestSetInline extends SrcOp {
|
||||||
bitsetList.add(current);
|
bitsetList.add(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
current.ttypes.add(factory.getGenerator().target.getTokenTypeAsTargetLabel(factory.getGrammar(), ttype));
|
current.ttypes.add(factory.getGenerator().getTarget().getTokenTypeAsTargetLabel(factory.getGrammar(), ttype));
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitsetList.toArray(new Bitset[bitsetList.size()]);
|
return bitsetList.toArray(new Bitset[bitsetList.size()]);
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class AltLabelStructDecl extends StructDecl {
|
||||||
super(factory, r);
|
super(factory, r);
|
||||||
this.altNum = altNum;
|
this.altNum = altNum;
|
||||||
this.name = // override name set in super to the label ctx
|
this.name = // override name set in super to the label ctx
|
||||||
factory.getGenerator().target.getAltLabelContextStructName(label);
|
factory.getGenerator().getTarget().getAltLabelContextStructName(label);
|
||||||
derivedFromName = label;
|
derivedFromName = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class StructDecl extends Decl {
|
||||||
@ModelElement public List<OutputModelObject> extensionMembers;
|
@ModelElement public List<OutputModelObject> extensionMembers;
|
||||||
|
|
||||||
public StructDecl(OutputModelFactory factory, Rule r) {
|
public StructDecl(OutputModelFactory factory, Rule r) {
|
||||||
super(factory, factory.getGenerator().target.getRuleFunctionContextStructName(r));
|
super(factory, factory.getGenerator().getTarget().getRuleFunctionContextStructName(r));
|
||||||
addDispatchMethods(r);
|
addDispatchMethods(r);
|
||||||
derivedFromName = r.name;
|
derivedFromName = r.name;
|
||||||
provideCopyFrom = r.hasAltSpecificContexts();
|
provideCopyFrom = r.hasAltSpecificContexts();
|
||||||
|
|
|
@ -110,9 +110,9 @@ public class BuildDependencyGenerator {
|
||||||
files.add(getOutputFile(generator.getVocabFileName()));
|
files.add(getOutputFile(generator.getVocabFileName()));
|
||||||
// are we generating a .h file?
|
// are we generating a .h file?
|
||||||
ST headerExtST = null;
|
ST headerExtST = null;
|
||||||
ST extST = generator.templates.getInstanceOf("codeFileExtension");
|
ST extST = generator.getTemplates().getInstanceOf("codeFileExtension");
|
||||||
if (generator.templates.isDefined("headerFile")) {
|
if (generator.getTemplates().isDefined("headerFile")) {
|
||||||
headerExtST = generator.templates.getInstanceOf("headerFileExtension");
|
headerExtST = generator.getTemplates().getInstanceOf("headerFileExtension");
|
||||||
String suffix = Grammar.getGrammarTypeToFileNameSuffix(g.getType());
|
String suffix = Grammar.getGrammarTypeToFileNameSuffix(g.getType());
|
||||||
String fileName = g.name + suffix + headerExtST.render();
|
String fileName = g.name + suffix + headerExtST.render();
|
||||||
files.add(getOutputFile(fileName));
|
files.add(getOutputFile(fileName));
|
||||||
|
|
Loading…
Reference in New Issue