Now outputs headers a bit as well as code.
This commit is contained in:
parent
363b640949
commit
fccf0b4036
|
@ -1046,4 +1046,25 @@ initValue(typeName) ::= <<
|
|||
<cppTypeInitMap.(typeName)>
|
||||
>>
|
||||
|
||||
headerFile(file, parser, namedActions) ::= <<
|
||||
FOOM1
|
||||
>>
|
||||
|
||||
parserHeaderFile(file, parser, namedActions) ::= <<
|
||||
FOOM2
|
||||
>>
|
||||
|
||||
visitorHeaderFile(file, parser, namedActions) ::= <<
|
||||
FOOM3
|
||||
>>
|
||||
|
||||
ParserHeaderFile(file, parser, namedActions) ::= <<
|
||||
FOOM4
|
||||
>>
|
||||
|
||||
VisitorHeaderFile(file, parser, namedActions) ::= <<
|
||||
FOOM5
|
||||
>>
|
||||
|
||||
codeFileExtension() ::= ".cpp"
|
||||
headerFileExtension() ::= ".h"
|
||||
|
|
|
@ -203,7 +203,7 @@ public class CodeGenerator {
|
|||
if ( fileName==null ) return;
|
||||
if ( getTemplates().isDefined("headerFile") ) {
|
||||
ST extST = getTemplates().getInstanceOf("headerFileExtension");
|
||||
ST headerFileST = null;
|
||||
ST headerFileST = getTemplates().getInstanceOf("headerFile");
|
||||
// TODO: don't hide this header file generation here!
|
||||
getTarget().genRecognizerHeaderFile(g,headerFileST,extST.render(lineWidth));
|
||||
}
|
||||
|
@ -298,4 +298,39 @@ public class CodeGenerator {
|
|||
String recognizerName = g.getRecognizerName();
|
||||
return recognizerName+extST.render();
|
||||
}
|
||||
|
||||
public String getRecognizerHeaderFileName() {
|
||||
ST extST = getTemplates().getInstanceOf("headerFileExtension");
|
||||
if ( extST==null ) return null;
|
||||
String recognizerName = g.getRecognizerName();
|
||||
return recognizerName+extST.render();
|
||||
}
|
||||
|
||||
public String getListenerHeaderFileName() {
|
||||
ST extST = getTemplates().getInstanceOf("headerFileExtension");
|
||||
if ( extST==null ) return null;
|
||||
String listenerName = g.name + "Listener";
|
||||
return listenerName+extST.render();
|
||||
}
|
||||
|
||||
public String getVisitorHeaderFileName() {
|
||||
ST extST = getTemplates().getInstanceOf("headerFileExtension");
|
||||
if ( extST==null ) return null;
|
||||
String visitorName = g.name + "Visitor";
|
||||
return visitorName+extST.render();
|
||||
}
|
||||
|
||||
public String getBaseListenerHeaderFileName() {
|
||||
assert g.name != null;
|
||||
ST extST = getTemplates().getInstanceOf("headerFileExtension");
|
||||
String visitorName = g.name + "BaseListener";
|
||||
return visitorName+extST.render();
|
||||
}
|
||||
|
||||
public String getBaseVisitorHeaderFileName() {
|
||||
assert g.name != null;
|
||||
ST extST = getTemplates().getInstanceOf("headerFileExtension");
|
||||
String visitorName = g.name + "BaseVisitor";
|
||||
return visitorName+extST.render();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,9 @@
|
|||
|
||||
package org.antlr.v4.codegen;
|
||||
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.ast.GrammarAST;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.StringRenderer;
|
||||
|
||||
|
@ -70,6 +72,10 @@ public class CppTarget extends Target {
|
|||
super(gen, "Cpp");
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "4.1";
|
||||
}
|
||||
|
||||
public Set<String> getBadWords() {
|
||||
if (badWords.isEmpty()) {
|
||||
addBadWords();
|
||||
|
@ -200,4 +206,11 @@ public class CppTarget extends Target {
|
|||
result.registerRenderer(String.class, new StringRenderer(), true);
|
||||
return result;
|
||||
}
|
||||
|
||||
// MEGAHACK -- Make it so we can have different header filenames for the three types of files -- recognizer, listener, visitor.
|
||||
@Override
|
||||
protected void genRecognizerHeaderFile(Grammar grammar, ST headerFileST, String extName) {
|
||||
String fileName = getCodeGenerator().getRecognizerHeaderFileName();
|
||||
getCodeGenerator().write(headerFileST, fileName);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue