diff --git a/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj b/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj index bef1ba81f..6253ea155 100644 --- a/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj +++ b/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj @@ -819,6 +819,18 @@ 276E60731CDB57AA003FF4B4 /* WritableToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5D2A1CDB57AA003FF4B4 /* WritableToken.h */; }; 276E60741CDB57AA003FF4B4 /* WritableToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5D2A1CDB57AA003FF4B4 /* WritableToken.h */; }; 276E60751CDB57AA003FF4B4 /* WritableToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5D2A1CDB57AA003FF4B4 /* WritableToken.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 27745EFD1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */; }; + 27745EFE1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */; }; + 27745EFF1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */; }; + 27745F001CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */; }; + 27745F011CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */; }; + 27745F021CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */; }; + 27745F031CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */; }; + 27745F041CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */; }; + 27745F051CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */; }; + 27745F061CE49C000067C6A3 /* RuntimeMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */; }; + 27745F071CE49C000067C6A3 /* RuntimeMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */; }; + 27745F081CE49C000067C6A3 /* RuntimeMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */; }; 27874F1E1CCB7A0700AF1C53 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27874F1D1CCB7A0700AF1C53 /* CoreFoundation.framework */; }; 27874F211CCB7B1700AF1C53 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27874F1D1CCB7A0700AF1C53 /* CoreFoundation.framework */; }; /* End PBXBuildFile section */ @@ -1098,6 +1110,10 @@ 276E5D271CDB57AA003FF4B4 /* VocabularyImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VocabularyImpl.cpp; sourceTree = ""; }; 276E5D281CDB57AA003FF4B4 /* VocabularyImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VocabularyImpl.h; sourceTree = ""; }; 276E5D2A1CDB57AA003FF4B4 /* WritableToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableToken.h; sourceTree = ""; }; + 27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuleContextWithAltNum.cpp; sourceTree = ""; wrapsLines = 0; }; + 27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuleContextWithAltNum.h; sourceTree = ""; wrapsLines = 0; }; + 27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeMetaData.cpp; sourceTree = ""; wrapsLines = 0; }; + 27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeMetaData.h; sourceTree = ""; }; 27874F1D1CCB7A0700AF1C53 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; 37C147171B4D5A04008EDDDB /* libantlrcpp_static.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libantlrcpp_static.a; sourceTree = BUILT_PRODUCTS_DIR; }; 37D727AA1867AF1E007B6D10 /* antlrcpp.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = antlrcpp.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1210,6 +1226,10 @@ 276E5CE11CDB57AA003FF4B4 /* Recognizer.h */, 276E5CE21CDB57AA003FF4B4 /* RuleContext.cpp */, 276E5CE31CDB57AA003FF4B4 /* RuleContext.h */, + 27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */, + 27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */, + 27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */, + 27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */, 276E5CEF1CDB57AA003FF4B4 /* Token.cpp */, 276E5CF01CDB57AA003FF4B4 /* Token.h */, 276E5CF21CDB57AA003FF4B4 /* TokenFactory.h */, @@ -1567,6 +1587,7 @@ 276E5F821CDB57AA003FF4B4 /* NoViableAltException.h in Headers */, 276E5DEA1CDB57AA003FF4B4 /* LexerATNConfig.h in Headers */, 276E60481CDB57AA003FF4B4 /* TerminalNodeImpl.h in Headers */, + 27745F081CE49C000067C6A3 /* RuntimeMetaData.h in Headers */, 276E5FF41CDB57AA003FF4B4 /* ErrorNodeImpl.h in Headers */, 276E5EC51CDB57AA003FF4B4 /* TokensStartState.h in Headers */, 276E5DC91CDB57AA003FF4B4 /* EmptyPredictionContext.h in Headers */, @@ -1591,6 +1612,7 @@ 276E5F941CDB57AA003FF4B4 /* ParserRuleContext.h in Headers */, 276E5FEE1CDB57AA003FF4B4 /* ErrorNode.h in Headers */, 276E5EB91CDB57AA003FF4B4 /* StarLoopbackState.h in Headers */, + 27745F021CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */, 276E5E5F1CDB57AA003FF4B4 /* PlusLoopbackState.h in Headers */, 276E5E081CDB57AA003FF4B4 /* LexerModeAction.h in Headers */, 276E5E591CDB57AA003FF4B4 /* PlusBlockStartState.h in Headers */, @@ -1659,6 +1681,7 @@ buildActionMask = 2147483647; files = ( 276E5FEA1CDB57AA003FF4B4 /* AbstractParseTreeVisitor.h in Headers */, + 27745F011CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */, 276E60321CDB57AA003FF4B4 /* TextChunk.h in Headers */, 276E5F421CDB57AA003FF4B4 /* IntStream.h in Headers */, 276E5D5C1CDB57AA003FF4B4 /* ATN.h in Headers */, @@ -1715,6 +1738,7 @@ 276E5E7C1CDB57AA003FF4B4 /* PredictionMode.h in Headers */, 276E5EBE1CDB57AA003FF4B4 /* StarLoopEntryState.h in Headers */, 276E5F9F1CDB57AA003FF4B4 /* RecognitionException.h in Headers */, + 27745F071CE49C000067C6A3 /* RuntimeMetaData.h in Headers */, 276E5EA61CDB57AA003FF4B4 /* SetTransition.h in Headers */, 276E5F1E1CDB57AA003FF4B4 /* LexerDFASerializer.h in Headers */, 276E5E461CDB57AA003FF4B4 /* OrderedATNConfigSet.h in Headers */, @@ -1814,6 +1838,7 @@ buildActionMask = 2147483647; files = ( 276E5FE91CDB57AA003FF4B4 /* AbstractParseTreeVisitor.h in Headers */, + 27745F001CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */, 276E60311CDB57AA003FF4B4 /* TextChunk.h in Headers */, 276E5F411CDB57AA003FF4B4 /* IntStream.h in Headers */, 276E5D5B1CDB57AA003FF4B4 /* ATN.h in Headers */, @@ -1870,6 +1895,7 @@ 276E5E7B1CDB57AA003FF4B4 /* PredictionMode.h in Headers */, 276E5EBD1CDB57AA003FF4B4 /* StarLoopEntryState.h in Headers */, 276E5F9E1CDB57AA003FF4B4 /* RecognitionException.h in Headers */, + 27745F061CE49C000067C6A3 /* RuntimeMetaData.h in Headers */, 276E5EA51CDB57AA003FF4B4 /* SetTransition.h in Headers */, 276E5F1D1CDB57AA003FF4B4 /* LexerDFASerializer.h in Headers */, 276E5E451CDB57AA003FF4B4 /* OrderedATNConfigSet.h in Headers */, @@ -2070,6 +2096,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 27745EFF1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */, 276E5F671CDB57AA003FF4B4 /* IntervalSet.cpp in Sources */, 276E5D3C1CDB57AA003FF4B4 /* ANTLRInputStream.cpp in Sources */, 276E5FC71CDB57AA003FF4B4 /* Strings.cpp in Sources */, @@ -2142,6 +2169,7 @@ 276E602A1CDB57AA003FF4B4 /* TagChunk.cpp in Sources */, 276E5F7F1CDB57AA003FF4B4 /* NoViableAltException.cpp in Sources */, 276E5D781CDB57AA003FF4B4 /* ATNSerializer.cpp in Sources */, + 27745F051CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */, 276E5DAE1CDB57AA003FF4B4 /* ContextSensitivityInfo.cpp in Sources */, 276E5D661CDB57AA003FF4B4 /* ATNConfigSet.cpp in Sources */, 276E5FAF1CDB57AA003FF4B4 /* Arrays.cpp in Sources */, @@ -2199,6 +2227,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 27745EFE1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */, 276E5F661CDB57AA003FF4B4 /* IntervalSet.cpp in Sources */, 276E5D3B1CDB57AA003FF4B4 /* ANTLRInputStream.cpp in Sources */, 276E5FC61CDB57AA003FF4B4 /* Strings.cpp in Sources */, @@ -2271,6 +2300,7 @@ 276E60291CDB57AA003FF4B4 /* TagChunk.cpp in Sources */, 276E5F7E1CDB57AA003FF4B4 /* NoViableAltException.cpp in Sources */, 276E5D771CDB57AA003FF4B4 /* ATNSerializer.cpp in Sources */, + 27745F041CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */, 276E5DAD1CDB57AA003FF4B4 /* ContextSensitivityInfo.cpp in Sources */, 276E5D651CDB57AA003FF4B4 /* ATNConfigSet.cpp in Sources */, 276E5FAE1CDB57AA003FF4B4 /* Arrays.cpp in Sources */, @@ -2328,6 +2358,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 27745EFD1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */, 276E5F651CDB57AA003FF4B4 /* IntervalSet.cpp in Sources */, 276E5D3A1CDB57AA003FF4B4 /* ANTLRInputStream.cpp in Sources */, 276E5FC51CDB57AA003FF4B4 /* Strings.cpp in Sources */, @@ -2400,6 +2431,7 @@ 276E60281CDB57AA003FF4B4 /* TagChunk.cpp in Sources */, 276E5F7D1CDB57AA003FF4B4 /* NoViableAltException.cpp in Sources */, 276E5D761CDB57AA003FF4B4 /* ATNSerializer.cpp in Sources */, + 27745F031CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */, 276E5DAC1CDB57AA003FF4B4 /* ContextSensitivityInfo.cpp in Sources */, 276E5D641CDB57AA003FF4B4 /* ATNConfigSet.cpp in Sources */, 276E5FAD1CDB57AA003FF4B4 /* Arrays.cpp in Sources */, diff --git a/runtime/Cpp/runtime/src/RuleContextWithAltNum.cpp b/runtime/Cpp/runtime/src/RuleContextWithAltNum.cpp new file mode 100755 index 000000000..24c908ecc --- /dev/null +++ b/runtime/Cpp/runtime/src/RuleContextWithAltNum.cpp @@ -0,0 +1,52 @@ +/* + * [The "BSD license"] + * Copyright (c) 2016 Mike Lischke + * Copyright (c) 2016 Terence Parr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ATN.h" + +#include "RuleContextWithAltNum.h" + +using namespace org::antlr::v4::runtime; +using namespace org::antlr::v4::runtime::atn; + +RuleContextWithAltNum::RuleContextWithAltNum() : ParserRuleContext() { + altNum = ATN::INVALID_ALT_NUMBER; +} + +RuleContextWithAltNum::RuleContextWithAltNum(Ref parent, int invokingStateNumber) + : ParserRuleContext(parent, invokingStateNumber) { +} + +int RuleContextWithAltNum::getAltNumber() const { + return altNum; +} + +void RuleContextWithAltNum::setAltNumber(int altNum) { + this->altNum = altNum; +} diff --git a/runtime/Cpp/runtime/src/RuleContextWithAltNum.h b/runtime/Cpp/runtime/src/RuleContextWithAltNum.h new file mode 100755 index 000000000..e92b8d0fd --- /dev/null +++ b/runtime/Cpp/runtime/src/RuleContextWithAltNum.h @@ -0,0 +1,63 @@ +/* + * [The "BSD license"] + * Copyright (c) 2016 Mike Lischke + * Copyright (c) 2016 Terence Parr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "ParserRuleContext.h" + +namespace org { +namespace antlr { +namespace v4 { +namespace runtime { + + /// A handy class for use with + /// + /// options {contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;} + /// + /// that provides a backing field / impl for the outer alternative number + /// matched for an internal parse tree node. + /// + /// I'm only putting into Java runtime as I'm certain I'm the only one that + /// will really every use this. + class ANTLR4CPP_PUBLIC RuleContextWithAltNum : public ParserRuleContext { + public: + int altNum = 0; + + RuleContextWithAltNum(); + RuleContextWithAltNum(Ref parent, int invokingStateNumber); + + virtual int getAltNumber() const override; + virtual void setAltNumber(int altNum) override; + }; + +} // namespace runtime +} // namespace v4 +} // namespace antlr +} // namespace org diff --git a/runtime/Cpp/runtime/src/RuntimeMetaData.cpp b/runtime/Cpp/runtime/src/RuntimeMetaData.cpp new file mode 100755 index 000000000..2f8c439b6 --- /dev/null +++ b/runtime/Cpp/runtime/src/RuntimeMetaData.cpp @@ -0,0 +1,79 @@ +/* + * [The "BSD license"] + * Copyright (c) 2016 Mike Lischke + * Copyright (c) 2014 Terence Parr + * Copyright (c) 2014 Sam Harwell + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "RuntimeMetaData.h" + +using namespace org::antlr::v4::runtime; + +const std::wstring RuntimeMetaData::VERSION = L"4.5.3"; + +std::wstring RuntimeMetaData::getRuntimeVersion() { + return VERSION; +} + +void RuntimeMetaData::checkVersion(const std::wstring &generatingToolVersion, const std::wstring &compileTimeVersion) { + std::wstring runtimeVersion = VERSION; + bool runtimeConflictsWithGeneratingTool = false; + bool runtimeConflictsWithCompileTimeTool = false; + + if (generatingToolVersion != L"") { + runtimeConflictsWithGeneratingTool = runtimeVersion != generatingToolVersion + && getMajorMinorVersion(runtimeVersion) != getMajorMinorVersion(generatingToolVersion); + } + + runtimeConflictsWithCompileTimeTool = runtimeVersion != compileTimeVersion + && getMajorMinorVersion(runtimeVersion) != getMajorMinorVersion(compileTimeVersion); + + if (runtimeConflictsWithGeneratingTool) { + std::wcerr << "ANTLR Tool version " << generatingToolVersion << " used for code generation does not match " + "the current runtime version " << runtimeVersion << std::endl; + } + if (runtimeConflictsWithCompileTimeTool) { + std::wcerr << "ANTLR Runtime version " << compileTimeVersion << " used for parser compilation does not match " + "the current runtime version " << runtimeVersion << std::endl; + } +} + +std::wstring RuntimeMetaData::getMajorMinorVersion(const std::wstring &version) { + size_t firstDot = version.find(L'.'); + size_t secondDot = firstDot != std::wstring::npos ? version.find(L'.', firstDot + 1) : std::wstring::npos; + size_t firstDash = version.find(L'-'); + size_t referenceLength = version.size(); + if (secondDot != std::wstring::npos) { + referenceLength = std::min(referenceLength, secondDot); + } + + if (firstDash != std::wstring::npos) { + referenceLength = std::min(referenceLength, firstDash); + } + + return version.substr(0, referenceLength); +} diff --git a/runtime/Cpp/runtime/src/RuntimeMetaData.h b/runtime/Cpp/runtime/src/RuntimeMetaData.h new file mode 100755 index 000000000..ecbe997b9 --- /dev/null +++ b/runtime/Cpp/runtime/src/RuntimeMetaData.h @@ -0,0 +1,185 @@ +/* + * [The "BSD license"] + * Copyright (c) 2016 Mike Lischke + * Copyright (c) 2014 Terence Parr + * Copyright (c) 2014 Sam Harwell + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +namespace org { +namespace antlr { +namespace v4 { +namespace runtime { + + /// + /// This class provides access to the current version of the ANTLR 4 runtime + /// library as compile-time and runtime constants, along with methods for + /// checking for matching version numbers and notifying listeners in the case + /// where a version mismatch is detected. + /// + /// + /// The runtime version information is provided by and + /// . Detailed information about these values is + /// provided in the documentation for each member. + /// + /// + /// The runtime version check is implemented by . Detailed + /// information about incorporating this call into user code, as well as its use + /// in generated code, is provided in the documentation for the method. + /// + /// + /// Version strings x.y and x.y.z are considered "compatible" and no error + /// would be generated. Likewise, version strings x.y-SNAPSHOT and x.y.z are + /// considered "compatible" because the major and minor components x.y + /// are the same in each. + /// + /// + /// To trap any error messages issued by this code, use System.setErr() + /// in your main() startup code. + /// + /// + /// @since 4.3 + /// + class ANTLR4CPP_PUBLIC RuntimeMetaData { + public: + /// A compile-time constant containing the current version of the ANTLR 4 + /// runtime library. + /// + /// + /// This compile-time constant value allows generated parsers and other + /// libraries to include a literal reference to the version of the ANTLR 4 + /// runtime library the code was compiled against. At each release, we + /// change this value. + /// + /// Version numbers are assumed to have the form + /// + /// major.minor.patch.revision-suffix, + /// + /// with the individual components defined as follows. + /// + ///
    + ///
  • major is a required non-negative integer, and is equal to + /// {@code 4} for ANTLR 4.
  • + ///
  • minor is a required non-negative integer.
  • + ///
  • patch is an optional non-negative integer. When + /// patch is omitted, the {@code .} (dot) appearing before it is + /// also omitted.
  • + ///
  • revision is an optional non-negative integer, and may only + /// be included when patch is also included. When revision + /// is omitted, the {@code .} (dot) appearing before it is also omitted.
  • + ///
  • suffix is an optional string. When suffix is + /// omitted, the {@code -} (hyphen-minus) appearing before it is also + /// omitted.
  • + ///
+ static const std::wstring VERSION; + + /// + /// Gets the currently executing version of the ANTLR 4 runtime library. + /// + /// + /// This method provides runtime access to the field, as + /// opposed to directly referencing the field as a compile-time constant. + /// + /// The currently executing version of the ANTLR 4 library + + static std::wstring getRuntimeVersion(); + + /// + /// This method provides the ability to detect mismatches between the version + /// of ANTLR 4 used to generate a parser, the version of the ANTLR runtime a + /// parser was compiled against, and the version of the ANTLR runtime which + /// is currently executing. + /// + /// + /// The version check is designed to detect the following two specific + /// scenarios. + /// + ///
    + ///
  • The ANTLR Tool version used for code generation does not match the + /// currently executing runtime version.
  • + ///
  • The ANTLR Runtime version referenced at the time a parser was + /// compiled does not match the currently executing runtime version.
  • + ///
+ /// + /// + /// Starting with ANTLR 4.3, the code generator emits a call to this method + /// using two constants in each generated lexer and parser: a hard-coded + /// constant indicating the version of the tool used to generate the parser + /// and a reference to the compile-time constant . At + /// runtime, this method is called during the initialization of the generated + /// parser to detect mismatched versions, and notify the registered listeners + /// prior to creating instances of the parser. + /// + /// + /// This method does not perform any detection or filtering of semantic + /// changes between tool and runtime versions. It simply checks for a + /// version match and emits an error to stderr if a difference + /// is detected. + /// + /// + /// Note that some breaking changes between releases could result in other + /// types of runtime exceptions, such as a , prior to + /// calling this method. In these cases, the underlying version mismatch will + /// not be reported here. This method is primarily intended to + /// notify users of potential semantic changes between releases that do not + /// result in binary compatibility problems which would be detected by the + /// class loader. As with semantic changes, changes that break binary + /// compatibility between releases are mentioned in the release notes + /// accompanying the affected release. + /// + /// + /// Additional note for target developers: The version check + /// implemented by this class is designed to address specific compatibility + /// concerns that may arise during the execution of Java applications. Other + /// targets should consider the implementation of this method in the context + /// of that target's known execution environment, which may or may not + /// resemble the design provided for the Java target. + ///
+ /// The version of the tool used to generate a parser. + /// This value may be null when called from user code that was not generated + /// by, and does not reference, the ANTLR 4 Tool itself. + /// The version of the runtime the parser was + /// compiled against. This should always be passed using a direct reference + /// to . + static void checkVersion(const std::wstring &generatingToolVersion, const std::wstring &compileTimeVersion); + + /// + /// Gets the major and minor version numbers from a version string. For + /// details about the syntax of the input {@code version}. + /// E.g., from x.y.z return x.y. + /// + /// The complete version string. + /// A string of the form major.minor containing + /// only the major and minor components of the version string. + static std::wstring getMajorMinorVersion(const std::wstring &version); + }; + +} // namespace runtime +} // namespace v4 +} // namespace antlr +} // namespace org