Added 2 newer support classes to the runtime.

With those 2 classes the port of the C++ runtime is essentially complete. We now do only bug fixing.
This commit is contained in:
Mike Lischke 2016-05-12 13:32:10 +02:00
parent 313c971cae
commit 75bb338882
5 changed files with 411 additions and 0 deletions

View File

@ -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 = "<group>"; };
276E5D281CDB57AA003FF4B4 /* VocabularyImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VocabularyImpl.h; sourceTree = "<group>"; };
276E5D2A1CDB57AA003FF4B4 /* WritableToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableToken.h; sourceTree = "<group>"; };
27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuleContextWithAltNum.cpp; sourceTree = "<group>"; wrapsLines = 0; };
27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuleContextWithAltNum.h; sourceTree = "<group>"; wrapsLines = 0; };
27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeMetaData.cpp; sourceTree = "<group>"; wrapsLines = 0; };
27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeMetaData.h; sourceTree = "<group>"; };
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 */,

View File

@ -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<ParserRuleContext> parent, int invokingStateNumber)
: ParserRuleContext(parent, invokingStateNumber) {
}
int RuleContextWithAltNum::getAltNumber() const {
return altNum;
}
void RuleContextWithAltNum::setAltNumber(int altNum) {
this->altNum = altNum;
}

View File

@ -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<ParserRuleContext> parent, int invokingStateNumber);
virtual int getAltNumber() const override;
virtual void setAltNumber(int altNum) override;
};
} // namespace runtime
} // namespace v4
} // namespace antlr
} // namespace org

View File

@ -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);
}

View File

@ -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 {
/// <summary>
/// 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.
///
/// <para>
/// The runtime version information is provided by <seealso cref="#VERSION"/> and
/// <seealso cref="#getRuntimeVersion()"/>. Detailed information about these values is
/// provided in the documentation for each member.</para>
///
/// <para>
/// The runtime version check is implemented by <seealso cref="#checkVersion"/>. 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.</para>
///
/// <para>
/// 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.</para>
///
/// <para>
/// To trap any error messages issued by this code, use System.setErr()
/// in your main() startup code.
/// </para>
///
/// @since 4.3
/// </summary>
class ANTLR4CPP_PUBLIC RuntimeMetaData {
public:
/// A compile-time constant containing the current version of the ANTLR 4
/// runtime library.
///
/// <para>
/// 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.</para>
///
/// <para>Version numbers are assumed to have the form
///
/// <em>major</em>.<em>minor</em>.<em>patch</em>.<em>revision</em>-<em>suffix</em>,
///
/// with the individual components defined as follows.</para>
///
/// <ul>
/// <li><em>major</em> is a required non-negative integer, and is equal to
/// {@code 4} for ANTLR 4.</li>
/// <li><em>minor</em> is a required non-negative integer.</li>
/// <li><em>patch</em> is an optional non-negative integer. When
/// <em>patch</em> is omitted, the {@code .} (dot) appearing before it is
/// also omitted.</li>
/// <li><em>revision</em> is an optional non-negative integer, and may only
/// be included when <em>patch</em> is also included. When <em>revision</em>
/// is omitted, the {@code .} (dot) appearing before it is also omitted.</li>
/// <li><em>suffix</em> is an optional string. When <em>suffix</em> is
/// omitted, the {@code -} (hyphen-minus) appearing before it is also
/// omitted.</li>
/// </ul>
static const std::wstring VERSION;
/// <summary>
/// Gets the currently executing version of the ANTLR 4 runtime library.
///
/// <para>
/// This method provides runtime access to the <seealso cref="#VERSION"/> field, as
/// opposed to directly referencing the field as a compile-time constant.</para>
/// </summary>
/// <returns> The currently executing version of the ANTLR 4 library </returns>
static std::wstring getRuntimeVersion();
/// <summary>
/// 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.
///
/// <para>
/// The version check is designed to detect the following two specific
/// scenarios.</para>
///
/// <ul>
/// <li>The ANTLR Tool version used for code generation does not match the
/// currently executing runtime version.</li>
/// <li>The ANTLR Runtime version referenced at the time a parser was
/// compiled does not match the currently executing runtime version.</li>
/// </ul>
///
/// <para>
/// 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 <seealso cref="#VERSION"/>. 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.</para>
///
/// <para>
/// 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.</para>
///
/// <para>
/// Note that some breaking changes between releases could result in other
/// types of runtime exceptions, such as a <seealso cref="LinkageError"/>, 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.</para>
///
/// <para>
/// <strong>Additional note for target developers:</strong> 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.</para>
/// </summary>
/// <param name="generatingToolVersion"> 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. </param>
/// <param name="compileTimeVersion"> The version of the runtime the parser was
/// compiled against. This should always be passed using a direct reference
/// to <seealso cref="#VERSION"/>. </param>
static void checkVersion(const std::wstring &generatingToolVersion, const std::wstring &compileTimeVersion);
/// <summary>
/// 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.
/// </summary>
/// <param name="version"> The complete version string. </param>
/// <returns> A string of the form <em>major</em>.<em>minor</em> containing
/// only the major and minor components of the version string. </returns>
static std::wstring getMajorMinorVersion(const std::wstring &version);
};
} // namespace runtime
} // namespace v4
} // namespace antlr
} // namespace org