diff --git a/contributors.txt b/contributors.txt
index a19451c6c..c784d5fdf 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -251,4 +251,7 @@ YYYY/MM/DD, github id, Full name, email
2020/05/25, graknol, Sindre van der Linden, graknol@gmail.com
2020/05/31, d-markey, David Markey, dmarkey@free.fr
2020/06/02, cohomology, Kilian Kilger, kkilger AT gmail.com
-2020/07/01, sha-N, Shan M Mathews, admin@bluestarqatar.com
\ No newline at end of file
+2020/06/04, IohannRabeson, Iohann Rabeson, iotaka6@gmail.com
+2020/07/01, sha-N, Shan M Mathews, admin@bluestarqatar.com
+2020/08/22, stevenjohnstone, Steven Johnstone, steven.james.johnstone@gmail.com
+2020/09/06, ArthurSonzogni, Sonzogni Arthur, arthursonzogni@gmail.com
\ No newline at end of file
diff --git a/doc/cpp-target.md b/doc/cpp-target.md
index eec7cf88b..1fc8e8684 100644
--- a/doc/cpp-target.md
+++ b/doc/cpp-target.md
@@ -65,7 +65,7 @@ int main(int argc, const char* argv[]) {
tree::ParseTree *tree = parser.key();
TreeShapeListener listener;
- tree::ParseTreeWalker::DEFAULT->walk(&listener, tree);
+ tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
return 0;
}
diff --git a/runtime/Cpp/CMakeLists.txt b/runtime/Cpp/CMakeLists.txt
index 9610d7b9b..e763f85d4 100644
--- a/runtime/Cpp/CMakeLists.txt
+++ b/runtime/Cpp/CMakeLists.txt
@@ -19,7 +19,7 @@ if(NOT WITH_DEMO)
FORCE)
endif(NOT WITH_DEMO)
-option(WITH_LIBCXX "Building with clang++ and libc++(in Linux). To enable with: -DWITH_LIBCXX=On" On)
+option(WITH_LIBCXX "Building with clang++ and libc++(in Linux). To enable with: -DWITH_LIBCXX=On" Off)
option(WITH_STATIC_CRT "(Visual C++) Enable to statically link CRT, which avoids requiring users to install the redistribution package.
To disable with: -DWITH_STATIC_CRT=Off" On)
diff --git a/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj b/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj
index 42a81fc06..54f0aeb14 100644
--- a/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj
+++ b/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj
@@ -182,6 +182,7 @@
4251
true
false
+ /Zc:__cplusplus %(AdditionalOptions)
Windows
@@ -201,6 +202,7 @@
4251
true
false
+ /Zc:__cplusplus %(AdditionalOptions)
Windows
@@ -220,6 +222,7 @@
4251
true
false
+ /Zc:__cplusplus %(AdditionalOptions)
Windows
@@ -239,6 +242,7 @@
4251
true
false
+ /Zc:__cplusplus %(AdditionalOptions)
Windows
@@ -259,6 +263,7 @@
4251
true
+ /Zc:__cplusplus %(AdditionalOptions)
Windows
@@ -281,6 +286,7 @@
4251
true
+ /Zc:__cplusplus %(AdditionalOptions)
Windows
@@ -303,6 +309,7 @@
4251
true
+ /Zc:__cplusplus %(AdditionalOptions)
Windows
@@ -325,6 +332,7 @@
4251
true
+ /Zc:__cplusplus %(AdditionalOptions)
Windows
diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp
index a5e21618e..2e06c5efc 100755
--- a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp
+++ b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp
@@ -17,7 +17,11 @@ using namespace antlrcpp;
using misc::Interval;
+#if __cplusplus >= 201703L
+ANTLRInputStream::ANTLRInputStream(std::string_view input) {
+#else
ANTLRInputStream::ANTLRInputStream(const std::string &input) {
+#endif
InitializeInstanceFields();
load(input);
}
@@ -31,6 +35,16 @@ ANTLRInputStream::ANTLRInputStream(std::istream &stream) {
load(stream);
}
+#if __cplusplus >= 201703L
+void ANTLRInputStream::load(std::string_view input) {
+ // Remove the UTF-8 BOM if present.
+ constexpr std::string_view bom = "\xef\xbb\xbf";
+ if (input.compare(0, 3, bom) == 0)
+ input.remove_prefix(3);
+ _data = antlrcpp::utf8_to_utf32(input.data(), input.data() + input.size());
+ p = 0;
+}
+#else
void ANTLRInputStream::load(const std::string &input) {
// Remove the UTF-8 BOM if present.
const char bom[4] = "\xef\xbb\xbf";
@@ -40,6 +54,7 @@ void ANTLRInputStream::load(const std::string &input) {
_data = antlrcpp::utf8_to_utf32(input.data(), input.data() + input.size());
p = 0;
}
+#endif
void ANTLRInputStream::load(std::istream &stream) {
if (!stream.good() || stream.eof()) // No fail, bad or EOF.
diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.h b/runtime/Cpp/runtime/src/ANTLRInputStream.h
index e9850504d..7b575df2e 100755
--- a/runtime/Cpp/runtime/src/ANTLRInputStream.h
+++ b/runtime/Cpp/runtime/src/ANTLRInputStream.h
@@ -25,11 +25,19 @@ namespace antlr4 {
/// What is name or source of this char stream?
std::string name;
+#if __cplusplus >= 201703L
+ ANTLRInputStream(std::string_view input = "");
+#else
ANTLRInputStream(const std::string &input = "");
+#endif
ANTLRInputStream(const char data_[], size_t numberOfActualCharsInArray);
ANTLRInputStream(std::istream &stream);
+#if __cplusplus >= 201703L
+ virtual void load(std::string_view input);
+#else
virtual void load(const std::string &input);
+#endif
virtual void load(std::istream &stream);
/// Reset the stream so that it's in the same state it was
diff --git a/runtime/Cpp/runtime/src/Vocabulary.cpp b/runtime/Cpp/runtime/src/Vocabulary.cpp
index dcfa45e4b..9bbf0b23a 100755
--- a/runtime/Cpp/runtime/src/Vocabulary.cpp
+++ b/runtime/Cpp/runtime/src/Vocabulary.cpp
@@ -22,8 +22,7 @@ Vocabulary::Vocabulary(const std::vector &literalNames,
// See note here on -1 part: https://github.com/antlr/antlr4/pull/1146
}
-Vocabulary::~Vocabulary() {
-}
+Vocabulary::~Vocabulary() = default;
Vocabulary Vocabulary::fromTokenNames(const std::vector &tokenNames) {
if (tokenNames.empty()) {
@@ -34,25 +33,18 @@ Vocabulary Vocabulary::fromTokenNames(const std::vector &tokenNames
std::vector symbolicNames = tokenNames;
std::locale locale;
for (size_t i = 0; i < tokenNames.size(); i++) {
- std::string tokenName = tokenNames[i];
- if (tokenName == "") {
+ const std::string& tokenName = tokenNames[i];
+ if (tokenName.empty()) {
continue;
+ } else if (tokenName.front() == '\'') {
+ symbolicNames[i].clear();
+ } else if (std::isupper(tokenName.front(), locale)) {
+ literalNames[i].clear();
+ } else {
+ // wasn't a literal or symbolic name
+ literalNames[i].clear();
+ symbolicNames[i].clear();
}
-
- if (!tokenName.empty()) {
- char firstChar = tokenName[0];
- if (firstChar == '\'') {
- symbolicNames[i] = "";
- continue;
- } else if (std::isupper(firstChar, locale)) {
- literalNames[i] = "";
- continue;
- }
- }
-
- // wasn't a literal or symbolic name
- literalNames[i] = "";
- symbolicNames[i] = "";
}
return Vocabulary(literalNames, symbolicNames, tokenNames);
diff --git a/runtime/Cpp/runtime/src/Vocabulary.h b/runtime/Cpp/runtime/src/Vocabulary.h
index 7dbf85cd3..f06ce6978 100755
--- a/runtime/Cpp/runtime/src/Vocabulary.h
+++ b/runtime/Cpp/runtime/src/Vocabulary.h
@@ -14,9 +14,6 @@ namespace dfa {
/// interface.
class ANTLR4CPP_PUBLIC Vocabulary {
public:
- Vocabulary(Vocabulary const&) = default;
- virtual ~Vocabulary();
-
/// Gets an empty instance.
///
///
@@ -25,7 +22,9 @@ namespace dfa {
/// except .
static const Vocabulary EMPTY_VOCABULARY;
- Vocabulary() {}
+ Vocabulary() = default;
+ Vocabulary(Vocabulary const&) = default;
+ virtual ~Vocabulary();
///
/// Constructs a new instance of from the specified
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg
index 6930e3e47..2b8ed0b13 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg
@@ -63,7 +63,7 @@ public:
};
- (antlr4::CharStream *input);
+ explicit (antlr4::CharStream *input);
~();
@@ -192,23 +192,23 @@ atn::ATN ::_atn;
std::vector\ ::_serializedATN;
std::vector\ ::_ruleNames = {
- "}; separator = ", ", wrap, anchor>
+ "}; separator = ", ", wrap, anchor>
};
std::vector\ ::_channelNames = {
- "DEFAULT_TOKEN_CHANNEL", "HIDDEN", "}; separator = ", ", wrap, anchor>
+ "DEFAULT_TOKEN_CHANNEL", "HIDDEN", "}; separator = ", ", wrap, anchor>
};
std::vector\ ::_modeNames = {
- "}; separator = ", ", wrap, anchor>
+ "}; separator = ", ", wrap, anchor>
};
std::vector\ ::_literalNames = {
- }; null = "\"\"", separator = ", ", wrap, anchor>
+ }; null = "\"\"", separator = ", ", wrap, anchor>
};
std::vector\ ::_symbolicNames = {
- }; null = "\"\"", separator = ", ", wrap, anchor>
+ }; null = "\"\"", separator = ", ", wrap, anchor>
};
dfa::Vocabulary ::_vocabulary(_literalNames, _symbolicNames);
@@ -290,7 +290,7 @@ public:
};
- (antlr4::TokenStream *input);
+ explicit (antlr4::TokenStream *input);
~();
virtual std::string getGrammarFileName() const override;
@@ -710,6 +710,8 @@ switch (getInterpreter\()->adaptivePredict(_input,
+default:
+ break;
}
>>
@@ -724,6 +726,8 @@ switch (getInterpreter\()->adaptivePredict(_input,
+default:
+ break;
}
>>