From 62a829fb659d3f421296d6b406b1bfbdf5f0903d Mon Sep 17 00:00:00 2001 From: Mike Lischke Date: Tue, 9 Mar 2021 09:42:55 +0100 Subject: [PATCH 1/8] Fixed ANTLRInputStream and ANTLRFileStream A previous change to add std::string_view support to ANTLRInputStream for C++17 caused some trouble because of ABI changes. This has been changed to define 2 constructors, one for std::string_view (for C++17) and the original one for std::string. This is turn caused an error in ANTLRFileStream, which also takes a string in the constructor (but handling it as file name instead of input). To make this clearer the c-tor taking a std::string has been deleted in ANTLRFileStream and the class now requires to load input via the loadFile() function. This might cause some trouble for those users who had used the std::string constructor of ANTLRFileStream, but I think the better error reporting outweighs the little annoyance. --- .../antlrcpp.xcodeproj/project.pbxproj | 46 +++++++++++++------ .../xcshareddata/xcschemes/antlr4.xcscheme | 2 +- .../xcschemes/antlr4_ios.xcscheme | 6 +-- .../xcschemes/antlr4_static.xcscheme | 6 +-- runtime/Cpp/runtime/src/ANTLRFileStream.cpp | 6 +-- runtime/Cpp/runtime/src/ANTLRFileStream.h | 13 +++--- runtime/Cpp/runtime/src/ANTLRInputStream.cpp | 9 ++-- runtime/Cpp/runtime/src/ANTLRInputStream.h | 5 +- 8 files changed, 51 insertions(+), 42 deletions(-) diff --git a/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj b/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj index 277186ce0d..17ab198483 100644 --- a/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj +++ b/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -2226,7 +2226,7 @@ 37D727A21867AF1E007B6D10 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1030; + LastUpgradeCheck = 1240; ORGANIZATIONNAME = ANTLR; TargetAttributes = { 270C67EF1CDB4F1E00116E17 = { @@ -2238,7 +2238,7 @@ }; }; buildConfigurationList = 37D727A51867AF1E007B6D10 /* Build configuration list for PBXProject "antlrcpp" */; - compatibilityVersion = "Xcode 3.2"; + compatibilityVersion = "Xcode 12.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( @@ -2751,8 +2751,12 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = "antlrcpp-ios/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "org.antlr.v4.runtime.antlrcpp-ios"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -2782,8 +2786,12 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = "antlrcpp-ios/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "org.antlr.v4.runtime.antlrcpp-ios"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -2841,8 +2849,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_ASSIGN_ENUM = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; @@ -2857,6 +2864,7 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; @@ -2889,8 +2897,12 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = "src/ thirdparty/utfcpp/source/ thirdparty/utfcpp/source/utf8/"; - MACOSX_DEPLOYMENT_TARGET = 10.9; + HEADER_SEARCH_PATHS = ( + src/, + thirdparty/utfcpp/source/, + thirdparty/utfcpp/source/utf8/, + ); + MACOSX_DEPLOYMENT_TARGET = 11.1; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; }; @@ -2901,8 +2913,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_ASSIGN_ENUM = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; @@ -2917,6 +2928,7 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; @@ -2945,8 +2957,12 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = "src/ thirdparty/utfcpp/source/ thirdparty/utfcpp/source/utf8/"; - MACOSX_DEPLOYMENT_TARGET = 10.9; + HEADER_SEARCH_PATHS = ( + src/, + thirdparty/utfcpp/source/, + thirdparty/utfcpp/source/utf8/, + ); + MACOSX_DEPLOYMENT_TARGET = 11.1; SDKROOT = macosx; }; name = Release; diff --git a/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4.xcscheme b/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4.xcscheme index dc8e3432a7..701bbf3838 100644 --- a/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4.xcscheme +++ b/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4.xcscheme @@ -1,6 +1,6 @@ - - - - - - - - = 201703L ANTLRInputStream::ANTLRInputStream(std::string_view input) { -#else -ANTLRInputStream::ANTLRInputStream(const std::string &input) { + InitializeInstanceFields(); + load(input); +} #endif + +ANTLRInputStream::ANTLRInputStream(const std::string &input) { InitializeInstanceFields(); load(input); } diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.h b/runtime/Cpp/runtime/src/ANTLRInputStream.h index 7b575df2e9..2b28b20927 100755 --- a/runtime/Cpp/runtime/src/ANTLRInputStream.h +++ b/runtime/Cpp/runtime/src/ANTLRInputStream.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. +/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ @@ -27,9 +27,8 @@ namespace antlr4 { #if __cplusplus >= 201703L ANTLRInputStream(std::string_view input = ""); -#else - ANTLRInputStream(const std::string &input = ""); #endif + ANTLRInputStream(const std::string &input = ""); ANTLRInputStream(const char data_[], size_t numberOfActualCharsInArray); ANTLRInputStream(std::istream &stream); From 93c06214a6fc0029fd1c8c32b7b6045e8cbc6be3 Mon Sep 17 00:00:00 2001 From: Mike Lischke Date: Tue, 9 Mar 2021 11:01:57 +0100 Subject: [PATCH 2/8] Fixed C++ tests and build warnings --- .../test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java | 6 ++++-- runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java index e6a4526c2a..6117be8ccc 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java @@ -394,7 +394,8 @@ protected void writeParserTestFile(String parserName, String lexerName, + "\n" + "\n" + "int main(int argc, const char* argv[]) {\n" - + " ANTLRFileStream input(argv[1]);\n" + + " ANTLRFileStream input;\n" + + " input.loadFile(argv[1]);\n" + " lexer(&input);\n" + " CommonTokenStream tokens(&lexer);\n" + "" @@ -436,7 +437,8 @@ protected void writeLexerTestFile(String lexerName, boolean showDFA) { + "using namespace antlr4;\n" + "\n" + "int main(int argc, const char* argv[]) {\n" - + " ANTLRFileStream input(argv[1]);\n" + + " ANTLRFileStream input;\n" + + " input.loadFile(argv[1]);\n" + " lexer(&input);\n" + " CommonTokenStream tokens(&lexer);\n" + " tokens.fill();\n" diff --git a/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp b/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp index 025c9c9377..01c83c15e6 100755 --- a/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +++ b/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp @@ -1348,7 +1348,9 @@ Parser* ParserATNSimulator::getParser() { return parser; } -#pragma warning (disable:4996) // 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. +#ifdef _MSC_VER +#pragma warning (disable:4996) // 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. +#endif bool ParserATNSimulator::getLrLoopSetting() { char *var = std::getenv("TURN_OFF_LR_LOOP_ENTRY_BRANCH_OPT"); @@ -1358,7 +1360,9 @@ bool ParserATNSimulator::getLrLoopSetting() { return value == "true" || value == "1"; } +#ifdef _MSC_VER #pragma warning (default:4996) +#endif void ParserATNSimulator::InitializeInstanceFields() { _mode = PredictionMode::LL; From f881e3ec3f85e4a23e683ec78f0a54872e74cf58 Mon Sep 17 00:00:00 2001 From: Mike Lischke Date: Tue, 9 Mar 2021 11:04:04 +0100 Subject: [PATCH 3/8] Wrong load call fixed. --- .../test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java index 6117be8ccc..4b13b7ce43 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java @@ -395,7 +395,7 @@ protected void writeParserTestFile(String parserName, String lexerName, + "\n" + "int main(int argc, const char* argv[]) {\n" + " ANTLRFileStream input;\n" - + " input.loadFile(argv[1]);\n" + + " input.loadFromFile(argv[1]);\n" + " lexer(&input);\n" + " CommonTokenStream tokens(&lexer);\n" + "" @@ -438,7 +438,7 @@ protected void writeLexerTestFile(String lexerName, boolean showDFA) { + "\n" + "int main(int argc, const char* argv[]) {\n" + " ANTLRFileStream input;\n" - + " input.loadFile(argv[1]);\n" + + " input.loadFromFile(argv[1]);\n" + " lexer(&input);\n" + " CommonTokenStream tokens(&lexer);\n" + " tokens.fill();\n" From 84d4ce73defff2d30239510daf80974bb51bfa5b Mon Sep 17 00:00:00 2001 From: Mike Lischke Date: Wed, 10 Mar 2021 11:21:04 +0100 Subject: [PATCH 4/8] More changes to the ANTLRInputStream and ANTLRFileStream classes - Added a default c-tor to the input stream to avoid an ambiquity. - Changed the input stream API so that it can take a string pointer + length and use that for UTF conversion, avoiding so unnecessary copies. Convenience methods exist to use a std::string or a std::string_view. - With that only a single load() method is necessary. - In ANTLRFileStream the other c-tors are now also deleted, as they make no sense there. --- runtime/Cpp/runtime/src/ANTLRFileStream.cpp | 3 -- runtime/Cpp/runtime/src/ANTLRFileStream.h | 3 +- runtime/Cpp/runtime/src/ANTLRInputStream.cpp | 44 +++++++++----------- runtime/Cpp/runtime/src/ANTLRInputStream.h | 14 +++---- 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/runtime/Cpp/runtime/src/ANTLRFileStream.cpp b/runtime/Cpp/runtime/src/ANTLRFileStream.cpp index 072035019f..62061bb83a 100755 --- a/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +++ b/runtime/Cpp/runtime/src/ANTLRFileStream.cpp @@ -9,9 +9,6 @@ using namespace antlr4; -ANTLRFileStream::ANTLRFileStream(): ANTLRInputStream(std::string()) { -} - void ANTLRFileStream::loadFromFile(const std::string &fileName) { _fileName = fileName; if (_fileName.empty()) { diff --git a/runtime/Cpp/runtime/src/ANTLRFileStream.h b/runtime/Cpp/runtime/src/ANTLRFileStream.h index 7a791e720f..1beb36ca23 100755 --- a/runtime/Cpp/runtime/src/ANTLRFileStream.h +++ b/runtime/Cpp/runtime/src/ANTLRFileStream.h @@ -14,8 +14,9 @@ namespace antlr4 { // TODO: this class needs testing. class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream { public: - ANTLRFileStream(); ANTLRFileStream(const std::string &) = delete; + ANTLRFileStream(const char *data, size_t length) = delete; + ANTLRFileStream(std::istream &stream) = delete; // Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM). virtual void loadFromFile(const std::string &fileName); diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp index 9fa20be8a6..e92560ff91 100755 --- a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +++ b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp @@ -17,47 +17,41 @@ using namespace antlrcpp; using misc::Interval; -#if __cplusplus >= 201703L -ANTLRInputStream::ANTLRInputStream(std::string_view input) { +ANTLRInputStream::ANTLRInputStream() { InitializeInstanceFields(); - load(input); +} + +#if __cplusplus >= 201703L +ANTLRInputStream::ANTLRInputStream(const std::string_view &input): ANTLRInputStream() { + load(input.data(), input.length()); } #endif -ANTLRInputStream::ANTLRInputStream(const std::string &input) { - InitializeInstanceFields(); - load(input); +ANTLRInputStream::ANTLRInputStream(const std::string &input): ANTLRInputStream() { + load(input.data(), input.size()); } -ANTLRInputStream::ANTLRInputStream(const char data_[], size_t numberOfActualCharsInArray) - : ANTLRInputStream(std::string(data_, numberOfActualCharsInArray)) { +ANTLRInputStream::ANTLRInputStream(const char *data, size_t length) { + load(data, length); } -ANTLRInputStream::ANTLRInputStream(std::istream &stream) { - InitializeInstanceFields(); +ANTLRInputStream::ANTLRInputStream(std::istream &stream): ANTLRInputStream() { 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) { + load(input.data(), input.size()); +} + +void ANTLRInputStream::load(const char *data, size_t length) { // Remove the UTF-8 BOM if present. const char bom[4] = "\xef\xbb\xbf"; - if (input.compare(0, 3, bom, 3) == 0) - _data = antlrcpp::utf8_to_utf32(input.data() + 3, input.data() + input.size()); + if (strncmp(data, bom, 3) == 0) + _data = antlrcpp::utf8_to_utf32(data + 3, data + length); else - _data = antlrcpp::utf8_to_utf32(input.data(), input.data() + input.size()); + _data = antlrcpp::utf8_to_utf32(data, data + length); p = 0; } -#endif void ANTLRInputStream::load(std::istream &stream) { if (!stream.good() || stream.eof()) // No fail, bad or EOF. @@ -66,7 +60,7 @@ void ANTLRInputStream::load(std::istream &stream) { _data.clear(); std::string s((std::istreambuf_iterator(stream)), std::istreambuf_iterator()); - load(s); + load(s.data(), s.length()); } void ANTLRInputStream::reset() { diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.h b/runtime/Cpp/runtime/src/ANTLRInputStream.h index 2b28b20927..fdf857e3e3 100755 --- a/runtime/Cpp/runtime/src/ANTLRInputStream.h +++ b/runtime/Cpp/runtime/src/ANTLRInputStream.h @@ -25,18 +25,18 @@ namespace antlr4 { /// What is name or source of this char stream? std::string name; + ANTLRInputStream(); + #if __cplusplus >= 201703L - ANTLRInputStream(std::string_view input = ""); + ANTLRInputStream(const std::string_view &input); #endif - ANTLRInputStream(const std::string &input = ""); - ANTLRInputStream(const char data_[], size_t numberOfActualCharsInArray); + + ANTLRInputStream(const std::string &input); + ANTLRInputStream(const char *data, size_t length); 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(const char *data, size_t length); virtual void load(std::istream &stream); /// Reset the stream so that it's in the same state it was From 5731e64e224ffcbc2fc556ae5670b9c4c6ff8ec9 Mon Sep 17 00:00:00 2001 From: Mike Lischke Date: Wed, 10 Mar 2021 11:49:22 +0100 Subject: [PATCH 5/8] Added a sanity check for input size. --- runtime/Cpp/runtime/src/ANTLRInputStream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp index e92560ff91..889492acec 100755 --- a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +++ b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp @@ -45,8 +45,8 @@ void ANTLRInputStream::load(const std::string &input) { void ANTLRInputStream::load(const char *data, size_t length) { // Remove the UTF-8 BOM if present. - const char bom[4] = "\xef\xbb\xbf"; - if (strncmp(data, bom, 3) == 0) + const char *bom = "\xef\xbb\xbf"; + if (length > 3 && strncmp(data, bom, 3) == 0) _data = antlrcpp::utf8_to_utf32(data + 3, data + length); else _data = antlrcpp::utf8_to_utf32(data, data + length); From 9d1737f33b5fd9c86cd2b611a8d54419066af372 Mon Sep 17 00:00:00 2001 From: Mike Lischke Date: Wed, 10 Mar 2021 11:58:49 +0100 Subject: [PATCH 6/8] Build fix --- runtime/Cpp/runtime/src/ANTLRInputStream.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp index 889492acec..1ef8fd4d19 100755 --- a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +++ b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp @@ -3,6 +3,8 @@ * can be found in the LICENSE.txt file in the project root. */ +#include + #include "Exceptions.h" #include "misc/Interval.h" #include "IntStream.h" From ff629d543a7290bc6d76d0109f0b81c1ff9893ea Mon Sep 17 00:00:00 2001 From: Mike Lischke Date: Wed, 10 Mar 2021 12:07:09 +0100 Subject: [PATCH 7/8] Another build fix C++ is not --- runtime/Cpp/runtime/src/ANTLRFileStream.cpp | 3 +++ runtime/Cpp/runtime/src/ANTLRFileStream.h | 1 + 2 files changed, 4 insertions(+) diff --git a/runtime/Cpp/runtime/src/ANTLRFileStream.cpp b/runtime/Cpp/runtime/src/ANTLRFileStream.cpp index 62061bb83a..0051490449 100755 --- a/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +++ b/runtime/Cpp/runtime/src/ANTLRFileStream.cpp @@ -9,6 +9,9 @@ using namespace antlr4; +ANTLRFileStream::ANTLRFileStream(): ANTLRInputStream() { +} + void ANTLRFileStream::loadFromFile(const std::string &fileName) { _fileName = fileName; if (_fileName.empty()) { diff --git a/runtime/Cpp/runtime/src/ANTLRFileStream.h b/runtime/Cpp/runtime/src/ANTLRFileStream.h index 1beb36ca23..1a1a91bdec 100755 --- a/runtime/Cpp/runtime/src/ANTLRFileStream.h +++ b/runtime/Cpp/runtime/src/ANTLRFileStream.h @@ -14,6 +14,7 @@ namespace antlr4 { // TODO: this class needs testing. class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream { public: + ANTLRFileStream(); ANTLRFileStream(const std::string &) = delete; ANTLRFileStream(const char *data, size_t length) = delete; ANTLRFileStream(std::istream &stream) = delete; From 4431f1ff69f24c92ed45f9a00f0946a8830dd99d Mon Sep 17 00:00:00 2001 From: Mike Lischke Date: Wed, 10 Mar 2021 13:21:54 +0100 Subject: [PATCH 8/8] Small improvement --- runtime/Cpp/runtime/src/ANTLRFileStream.cpp | 3 --- runtime/Cpp/runtime/src/ANTLRFileStream.h | 2 +- runtime/Cpp/runtime/src/ANTLRInputStream.cpp | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/runtime/Cpp/runtime/src/ANTLRFileStream.cpp b/runtime/Cpp/runtime/src/ANTLRFileStream.cpp index 0051490449..62061bb83a 100755 --- a/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +++ b/runtime/Cpp/runtime/src/ANTLRFileStream.cpp @@ -9,9 +9,6 @@ using namespace antlr4; -ANTLRFileStream::ANTLRFileStream(): ANTLRInputStream() { -} - void ANTLRFileStream::loadFromFile(const std::string &fileName) { _fileName = fileName; if (_fileName.empty()) { diff --git a/runtime/Cpp/runtime/src/ANTLRFileStream.h b/runtime/Cpp/runtime/src/ANTLRFileStream.h index 1a1a91bdec..6c7d619a00 100755 --- a/runtime/Cpp/runtime/src/ANTLRFileStream.h +++ b/runtime/Cpp/runtime/src/ANTLRFileStream.h @@ -14,7 +14,7 @@ namespace antlr4 { // TODO: this class needs testing. class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream { public: - ANTLRFileStream(); + ANTLRFileStream() = default; ANTLRFileStream(const std::string &) = delete; ANTLRFileStream(const char *data, size_t length) = delete; ANTLRFileStream(std::istream &stream) = delete; diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp index 1ef8fd4d19..2dded40910 100755 --- a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +++ b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp @@ -48,7 +48,7 @@ void ANTLRInputStream::load(const std::string &input) { void ANTLRInputStream::load(const char *data, size_t length) { // Remove the UTF-8 BOM if present. const char *bom = "\xef\xbb\xbf"; - if (length > 3 && strncmp(data, bom, 3) == 0) + if (length >= 3 && strncmp(data, bom, 3) == 0) _data = antlrcpp::utf8_to_utf32(data + 3, data + length); else _data = antlrcpp::utf8_to_utf32(data, data + length);