Serialized ATN generation changed.

Originally the serialized ATN was coded as a wide string literal with embeded Unicode escapes (where necessary). This might fail on Windows however, as VS is very strict when checking Unicode code points and rejects compilation if it finds undefined code points. Hence this generation has been changed to hex numbers instead of that string literal.
This commit is contained in:
Mike Lischke 2016-04-23 11:10:12 +02:00
parent b2daab9477
commit 77d0a6c32a
4 changed files with 21 additions and 16 deletions

View File

@ -9,8 +9,8 @@ set -o errexit
# There are 2 ways of running the ANTLR generator here. # There are 2 ways of running the ANTLR generator here.
# 1) Running from jar. Use the given jar (or replace it by another one you built or downloaded) for generation. # 1) Running from jar. Use the given jar (or replace it by another one you built or downloaded) for generation.
LOCATION=antlr-4.1.1-dev-complete.jar #LOCATION=antlr-4.1.1-dev-complete.jar
java -jar $LOCATION -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4 #java -jar $LOCATION -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
#java -jar $LOCATION -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest -XdbgST TLexer.g4 TParser.g4 #java -jar $LOCATION -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest -XdbgST TLexer.g4 TParser.g4
#java -jar $LOCATION -Dlanguage=Java -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4 #java -jar $LOCATION -Dlanguage=Java -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
@ -23,7 +23,7 @@ java -jar $LOCATION -Dlanguage=Cpp -listener -visitor -o generated/ -package ant
# antlr jar over and over again. # antlr jar over and over again.
CLASSPATH=../../../tool/resources/:ST-4.0.8.jar:../../../tool/target/classes:../../../runtime/Java/target/classes:../../../../antlr3/runtime/Java/target/classes CLASSPATH=../../../tool/resources/:ST-4.0.8.jar:../../../tool/target/classes:../../../runtime/Java/target/classes:../../../../antlr3/runtime/Java/target/classes
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4 java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest -XdbgST TLexer.g4 TParser.g4 #java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest -XdbgST TLexer.g4 TParser.g4
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Java -listener -visitor -o generated/ TLexer.g4 TParser.g4 #java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Java -listener -visitor -o generated/ TLexer.g4 TParser.g4

View File

@ -354,15 +354,17 @@ static std::wstring _serializedATN;
// Constructs the serialized ATN and writes init code for static member vars. // Constructs the serialized ATN and writes init code for static member vars.
SerializedATN(model) ::= << SerializedATN(model) ::= <<
<if (rest(model.segments))> <if (rest(model.segments))>
<model.segments: {segment | static std::wstring _serializedATNSegment<i0> = <model.segments: {segment | static std::wstring _serializedATNSegment<i0> = {
L"<segment; wrap={"<\n> "}>";}; separator="\n"> <segment; wrap={<\n> }>
\};}; separator="\n">
_serializedATN = _serializedATN =
<model.segments: {segment | _serializedATNSegment<i0>}; separator=" +\n">; <model.segments: {segment | _serializedATNSegment<i0>}; separator=" +\n">;
<else> <else>
<! only one segment, can be inlined !> <! only one segment, can be inlined !>
_serializedATN = _serializedATN = {
L"<model.serialized; wrap = {"<\n> "}>"; <model.serialized; wrap = {<\n> }>
};
<endif> <endif>
atn::ATNDeserializer deserializer; atn::ATNDeserializer deserializer;

View File

@ -154,10 +154,10 @@ class <file.grammarName>BaseListener : public <file.grammarName>Listener {
void exit<lname; format="cap">(<file.parserName>::<lname; format = "cap">Context *ctx) { \} void exit<lname; format="cap">(<file.parserName>::<lname; format = "cap">Context *ctx) { \}
}; separator="\n"> }; separator="\n">
void enterEveryRule(ParserRuleContext ctx) { } void enterEveryRule(ParserRuleContext::Ref ctx) { }
void exitEveryRule(ParserRuleContext ctx) { } void exitEveryRule(ParserRuleContext::Ref ctx) { }
void visitTerminal(tree::TerminalNode node) { } void visitTerminal(std::shared_ptr\<tree::TerminalNode> node) { }
void visitErrorNode(tree::ErrorNode node) { } void visitErrorNode(std::shared_ptr\<tree::ErrorNode> node) { }
}; };
<if (file.genPackage)> <if (file.genPackage)>
@ -239,10 +239,11 @@ namespace <file.genPackage> {
template \<typename T> template \<typename T>
class <file.grammarName>BaseVisitor : public tree::AbstractParseTreeVisitor\<T>, public <file.grammarName>Visitor\<T> { class <file.grammarName>BaseVisitor : public tree::AbstractParseTreeVisitor\<T>, public <file.grammarName>Visitor\<T> {
public: public:
<file.visitorNames: { <file.visitorNames: { lname |
lname | virtual T* visit<lname; format = "cap">(<file.parserName>::<lname; format = "cap">Context *ctx) <\\> virtual T* visit<lname; format = "cap">(<file.parserName>::<lname; format = "cap">Context *ctx) override {
override { return tree::AbstractParseTreeVisitor\<T>::visitChildren(ctx); \} return tree::AbstractParseTreeVisitor\<T>::visitChildren(ctx);
}; separator="\n"> \}
}; separator="\n">
}; };
<if(file.genPackage)> <if(file.genPackage)>

View File

@ -176,7 +176,7 @@ public class CppTarget extends Target {
if (v < Character.MIN_VALUE || v > Character.MAX_VALUE) { if (v < Character.MIN_VALUE || v > Character.MAX_VALUE) {
throw new IllegalArgumentException(String.format("Cannot encode the specified value: %d", v)); throw new IllegalArgumentException(String.format("Cannot encode the specified value: %d", v));
} }
/*
if (v >= 0 && v < targetCharValueEscape.length && targetCharValueEscape[v] != null) { if (v >= 0 && v < targetCharValueEscape.length && targetCharValueEscape[v] != null) {
return targetCharValueEscape[v]; return targetCharValueEscape[v];
} }
@ -192,6 +192,8 @@ public class CppTarget extends Target {
String hex = Integer.toHexString(v | 0x10000).substring(1, 5); String hex = Integer.toHexString(v | 0x10000).substring(1, 5);
return "\\u" + hex; return "\\u" + hex;
*/
return "0x" + Integer.toHexString(v) + ", ";
} }
@Override @Override