Use accessors for fields in Target
This commit is contained in:
parent
4d854a521e
commit
d48ffa1459
|
@ -65,7 +65,7 @@ public class Target {
|
||||||
*/
|
*/
|
||||||
protected String[] targetCharValueEscape = new String[255];
|
protected String[] targetCharValueEscape = new String[255];
|
||||||
|
|
||||||
public CodeGenerator gen;
|
private final CodeGenerator gen;
|
||||||
private final String language;
|
private final String language;
|
||||||
private STGroup templates;
|
private STGroup templates;
|
||||||
|
|
||||||
|
@ -97,6 +97,14 @@ public class Target {
|
||||||
addBadWords();
|
addBadWords();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CodeGenerator getCodeGenerator() {
|
||||||
|
return gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
public STGroup getTemplates() {
|
public STGroup getTemplates() {
|
||||||
if (templates == null) {
|
if (templates == null) {
|
||||||
templates = loadTemplates();
|
templates = loadTemplates();
|
||||||
|
@ -115,14 +123,14 @@ public class Target {
|
||||||
ST outputFileST,
|
ST outputFileST,
|
||||||
String fileName)
|
String fileName)
|
||||||
{
|
{
|
||||||
gen.write(outputFileST, fileName);
|
getCodeGenerator().write(outputFileST, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void genListenerFile(Grammar g,
|
protected void genListenerFile(Grammar g,
|
||||||
ST outputFileST)
|
ST outputFileST)
|
||||||
{
|
{
|
||||||
String fileName = gen.getListenerFileName();
|
String fileName = getCodeGenerator().getListenerFileName();
|
||||||
gen.write(outputFileST, fileName);
|
getCodeGenerator().write(outputFileST, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void genRecognizerHeaderFile(Grammar g,
|
protected void genRecognizerHeaderFile(Grammar g,
|
||||||
|
@ -343,11 +351,11 @@ public class Target {
|
||||||
// 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 = getTemplates().getInstanceOf("ImplicitTokenLabel");
|
ST st = getTemplates().getInstanceOf("ImplicitTokenLabel");
|
||||||
int ttype = gen.g.getTokenType(tokenName);
|
int ttype = getCodeGenerator().g.getTokenType(tokenName);
|
||||||
if ( tokenName.startsWith("'") ) {
|
if ( tokenName.startsWith("'") ) {
|
||||||
return "s"+ttype;
|
return "s"+ttype;
|
||||||
}
|
}
|
||||||
String text = getTokenTypeAsTargetLabel(gen.g, ttype);
|
String text = getTokenTypeAsTargetLabel(getCodeGenerator().g, ttype);
|
||||||
st.add("tokenName", text);
|
st.add("tokenName", text);
|
||||||
return st.render();
|
return st.render();
|
||||||
}
|
}
|
||||||
|
@ -376,10 +384,10 @@ public class Target {
|
||||||
return "_wild";
|
return "_wild";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( gen.g.getRule(name)!=null ) return name;
|
if ( getCodeGenerator().g.getRule(name)!=null ) return name;
|
||||||
int ttype = gen.g.getTokenType(name);
|
int ttype = getCodeGenerator().g.getTokenType(name);
|
||||||
if ( ttype==Token.INVALID_TYPE ) return name;
|
if ( ttype==Token.INVALID_TYPE ) return name;
|
||||||
return getTokenTypeAsTargetLabel(gen.g, ttype);
|
return getTokenTypeAsTargetLabel(getCodeGenerator().g, ttype);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean grammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode) {
|
public boolean grammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode) {
|
||||||
|
@ -421,7 +429,7 @@ public class Target {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected STGroup loadTemplates() {
|
protected STGroup loadTemplates() {
|
||||||
STGroup result = new STGroupFile(CodeGenerator.TEMPLATE_ROOT+"/"+language+"/"+language+STGroup.GROUP_FILE_EXTENSION);
|
STGroup result = new STGroupFile(CodeGenerator.TEMPLATE_ROOT+"/"+getLanguage()+"/"+getLanguage()+STGroup.GROUP_FILE_EXTENSION);
|
||||||
result.registerRenderer(Integer.class, new NumberRenderer());
|
result.registerRenderer(Integer.class, new NumberRenderer());
|
||||||
result.registerRenderer(String.class, new StringRenderer());
|
result.registerRenderer(String.class, new StringRenderer());
|
||||||
result.setListener(new STErrorListener() {
|
result.setListener(new STErrorListener() {
|
||||||
|
@ -446,7 +454,7 @@ public class Target {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reportError(STMessage msg) {
|
private void reportError(STMessage msg) {
|
||||||
gen.tool.errMgr.toolError(ErrorType.STRING_TEMPLATE_WARNING, msg.cause, msg.toString());
|
getCodeGenerator().tool.errMgr.toolError(ErrorType.STRING_TEMPLATE_WARNING, msg.cause, msg.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue