forked from jasder/antlr
Fixed a bug + raised warning level in Visual Studio
- Fixed an endless recursion in Any, caused by the removal of one of the (apparently) unneeded copy constructors. As it turned out both are required. That leads to a warning in VS about a duplicate copy c-tor, which had to be suppressed therefore. - Raised the warning level to W4 in both VS 2013 and VS 2015 and fixed all warnings resulting from that.
This commit is contained in:
parent
d089c8d864
commit
c60f1bb8f9
|
@ -170,7 +170,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
@ -187,7 +187,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
@ -204,7 +204,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
@ -221,7 +221,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
@ -238,7 +238,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
|
@ -259,7 +259,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
|
@ -280,7 +280,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
|
@ -301,7 +301,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
|
|
|
@ -171,7 +171,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
@ -188,7 +188,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
@ -205,7 +205,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug DLL|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
@ -222,7 +222,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>ANTLR4CPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
@ -239,7 +239,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
|
@ -260,7 +260,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
|
@ -281,7 +281,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
|
@ -302,7 +302,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Static|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
|
@ -569,6 +569,7 @@
|
|||
<ClInclude Include="src\RuleContext.h" />
|
||||
<ClInclude Include="src\RuleContextWithAltNum.h" />
|
||||
<ClInclude Include="src\RuntimeMetaData.h" />
|
||||
<ClInclude Include="src\support\Any.h" />
|
||||
<ClInclude Include="src\support\Arrays.h" />
|
||||
<ClInclude Include="src\support\BitSet.h" />
|
||||
<ClInclude Include="src\support\CPPUtils.h" />
|
||||
|
|
|
@ -537,6 +537,9 @@
|
|||
<ClInclude Include="src\antlr4-runtime.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\support\Any.h">
|
||||
<Filter>Source Files\support</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\ANTLRFileStream.cpp">
|
||||
|
|
|
@ -304,7 +304,7 @@ ssize_t BufferedTokenStream::previousTokenOnChannel(size_t i, size_t channel) {
|
|||
return i;
|
||||
}
|
||||
|
||||
std::vector<Token *> BufferedTokenStream::getHiddenTokensToRight(size_t tokenIndex, size_t channel) {
|
||||
std::vector<Token *> BufferedTokenStream::getHiddenTokensToRight(size_t tokenIndex, ssize_t channel) {
|
||||
lazyInit();
|
||||
if (tokenIndex >= _tokens.size()) {
|
||||
throw IndexOutOfBoundsException(std::to_string(tokenIndex) + " not in 0.." + std::to_string(_tokens.size() - 1));
|
||||
|
@ -327,7 +327,7 @@ std::vector<Token *> BufferedTokenStream::getHiddenTokensToRight(size_t tokenInd
|
|||
return getHiddenTokensToRight(tokenIndex, -1);
|
||||
}
|
||||
|
||||
std::vector<Token *> BufferedTokenStream::getHiddenTokensToLeft(size_t tokenIndex, size_t channel) {
|
||||
std::vector<Token *> BufferedTokenStream::getHiddenTokensToLeft(size_t tokenIndex, ssize_t channel) {
|
||||
lazyInit();
|
||||
if (tokenIndex >= _tokens.size()) {
|
||||
throw IndexOutOfBoundsException(std::to_string(tokenIndex) + " not in 0.." + std::to_string(_tokens.size() - 1));
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace antlr4 {
|
|||
/// Collect all tokens on specified channel to the right of
|
||||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL or
|
||||
/// EOF. If channel is -1, find any non default channel token.
|
||||
virtual std::vector<Token *> getHiddenTokensToRight(size_t tokenIndex, size_t channel);
|
||||
virtual std::vector<Token *> getHiddenTokensToRight(size_t tokenIndex, ssize_t channel);
|
||||
|
||||
/// <summary>
|
||||
/// Collect all hidden tokens (any off-default channel) to the right of
|
||||
|
@ -103,7 +103,7 @@ namespace antlr4 {
|
|||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
|
||||
/// If channel is -1, find any non default channel token.
|
||||
/// </summary>
|
||||
virtual std::vector<Token *> getHiddenTokensToLeft(size_t tokenIndex, size_t channel);
|
||||
virtual std::vector<Token *> getHiddenTokensToLeft(size_t tokenIndex, ssize_t channel);
|
||||
|
||||
/// <summary>
|
||||
/// Collect all hidden tokens (any off-default channel) to the left of
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
|
||||
#include "Lexer.h"
|
||||
|
||||
#define DEBUG_LEXER 0
|
||||
|
||||
using namespace antlrcpp;
|
||||
using namespace antlr4;
|
||||
|
||||
|
@ -136,9 +138,10 @@ void Lexer::setMode(size_t m) {
|
|||
}
|
||||
|
||||
void Lexer::pushMode(size_t m) {
|
||||
if (atn::LexerATNSimulator::debug) {
|
||||
#if DEBUG_LEXER == 1
|
||||
std::cout << "pushMode " << m << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
modeStack.push_back(mode);
|
||||
setMode(m);
|
||||
}
|
||||
|
@ -147,9 +150,10 @@ size_t Lexer::popMode() {
|
|||
if (modeStack.empty()) {
|
||||
throw EmptyStackException();
|
||||
}
|
||||
if (atn::LexerATNSimulator::debug) {
|
||||
#if DEBUG_LEXER == 1
|
||||
std::cout << std::string("popMode back to ") << modeStack.back() << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
setMode(modeStack.back());
|
||||
modeStack.pop_back();
|
||||
return mode;
|
||||
|
@ -173,8 +177,8 @@ CharStream* Lexer::getInputStream() {
|
|||
return _input;
|
||||
}
|
||||
|
||||
void Lexer::emit(std::unique_ptr<Token> token) {
|
||||
this->token = std::move(token);
|
||||
void Lexer::emit(std::unique_ptr<Token> newToken) {
|
||||
token = std::move(newToken);
|
||||
}
|
||||
|
||||
Token* Lexer::emit() {
|
||||
|
@ -226,8 +230,8 @@ std::unique_ptr<Token> Lexer::getToken() {
|
|||
return std::move(token);
|
||||
}
|
||||
|
||||
void Lexer::setToken(std::unique_ptr<Token> token) {
|
||||
this->token = std::move(token);
|
||||
void Lexer::setToken(std::unique_ptr<Token> newToken) {
|
||||
token = std::move(newToken);
|
||||
}
|
||||
|
||||
void Lexer::setType(ssize_t ttype) {
|
||||
|
@ -238,8 +242,8 @@ ssize_t Lexer::getType() {
|
|||
return type;
|
||||
}
|
||||
|
||||
void Lexer::setChannel(int channel) {
|
||||
this->channel = channel;
|
||||
void Lexer::setChannel(int newChannel) {
|
||||
channel = newChannel;
|
||||
}
|
||||
|
||||
int Lexer::getChannel() {
|
||||
|
|
|
@ -143,7 +143,7 @@ namespace antlr4 {
|
|||
/// for efficiency reasons. Subclasses can override this method, nextToken,
|
||||
/// and getToken (to push tokens into a list and pull from that list
|
||||
/// rather than a single variable as this implementation does).
|
||||
virtual void emit(std::unique_ptr<Token> token);
|
||||
virtual void emit(std::unique_ptr<Token> newToken);
|
||||
|
||||
/// The standard method called to automatically emit a token at the
|
||||
/// outermost lexical rule. The token object should point into the
|
||||
|
@ -176,13 +176,13 @@ namespace antlr4 {
|
|||
/// Override if emitting multiple tokens.
|
||||
virtual std::unique_ptr<Token> getToken();
|
||||
|
||||
virtual void setToken(std::unique_ptr<Token> token);
|
||||
virtual void setToken(std::unique_ptr<Token> newToken);
|
||||
|
||||
virtual void setType(ssize_t ttype);
|
||||
|
||||
virtual ssize_t getType();
|
||||
|
||||
virtual void setChannel(int channel);
|
||||
virtual void setChannel(int newChannel);
|
||||
|
||||
virtual int getChannel();
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
using namespace antlr4;
|
||||
|
||||
std::map<const dfa::Vocabulary*, std::map<std::string, size_t>> Recognizer::_tokenTypeMapCache;
|
||||
std::map<const dfa::Vocabulary*, std::map<std::string, ssize_t>> Recognizer::_tokenTypeMapCache;
|
||||
std::map<std::vector<std::string>, std::map<std::string, size_t>> Recognizer::_ruleIndexMapCache;
|
||||
|
||||
Recognizer::Recognizer() {
|
||||
|
@ -57,11 +57,11 @@ dfa::Vocabulary const& Recognizer::getVocabulary() const {
|
|||
return vocabulary;
|
||||
}
|
||||
|
||||
std::map<std::string, size_t> Recognizer::getTokenTypeMap() {
|
||||
std::map<std::string, ssize_t> Recognizer::getTokenTypeMap() {
|
||||
const dfa::Vocabulary& vocabulary = getVocabulary();
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lck(mtx);
|
||||
std::map<std::string, size_t> result;
|
||||
std::map<std::string, ssize_t> result;
|
||||
auto iterator = _tokenTypeMapCache.find(&vocabulary);
|
||||
if (iterator != _tokenTypeMapCache.end()) {
|
||||
result = iterator->second;
|
||||
|
@ -102,8 +102,8 @@ std::map<std::string, size_t> Recognizer::getRuleIndexMap() {
|
|||
return result;
|
||||
}
|
||||
|
||||
size_t Recognizer::getTokenType(const std::string &tokenName) {
|
||||
const std::map<std::string, size_t> &map = getTokenTypeMap();
|
||||
ssize_t Recognizer::getTokenType(const std::string &tokenName) {
|
||||
const std::map<std::string, ssize_t> &map = getTokenTypeMap();
|
||||
auto iterator = map.find(tokenName);
|
||||
if (iterator == map.end())
|
||||
return Token::INVALID_TYPE;
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace antlr4 {
|
|||
/// <p/>
|
||||
/// Used for XPath and tree pattern compilation.
|
||||
/// </summary>
|
||||
virtual std::map<std::string, size_t> getTokenTypeMap();
|
||||
virtual std::map<std::string, ssize_t> getTokenTypeMap();
|
||||
|
||||
/// <summary>
|
||||
/// Get a map from rule names to rule indexes.
|
||||
|
@ -74,7 +74,7 @@ namespace antlr4 {
|
|||
/// </summary>
|
||||
virtual std::map<std::string, size_t> getRuleIndexMap();
|
||||
|
||||
virtual size_t getTokenType(const std::string &tokenName);
|
||||
virtual ssize_t getTokenType(const std::string &tokenName);
|
||||
|
||||
/// <summary>
|
||||
/// If this recognizer was generated, it will have a serialized ATN
|
||||
|
@ -175,7 +175,7 @@ namespace antlr4 {
|
|||
atn::ATNSimulator *_interpreter; // Set and deleted in descendants (or the profiler).
|
||||
|
||||
private:
|
||||
static std::map<const dfa::Vocabulary*, std::map<std::string, size_t>> _tokenTypeMapCache;
|
||||
static std::map<const dfa::Vocabulary*, std::map<std::string, ssize_t>> _tokenTypeMapCache;
|
||||
static std::map<std::vector<std::string>, std::map<std::string, size_t>> _ruleIndexMapCache;
|
||||
|
||||
ProxyErrorListener _proxListener; // Manages a collection of listeners.
|
||||
|
|
|
@ -138,24 +138,24 @@ std::string RuleContext::toString(const std::vector<std::string> &ruleNames) {
|
|||
std::string RuleContext::toString(const std::vector<std::string> &ruleNames, Ref<RuleContext> const& stop) {
|
||||
std::stringstream ss;
|
||||
|
||||
Ref<RuleContext> parent = shared_from_this();
|
||||
Ref<RuleContext> currentParent = shared_from_this();
|
||||
ss << "[";
|
||||
while (parent != stop) {
|
||||
while (currentParent != stop) {
|
||||
if (ruleNames.empty()) {
|
||||
if (!parent->isEmpty()) {
|
||||
ss << parent->invokingState;
|
||||
if (!currentParent->isEmpty()) {
|
||||
ss << currentParent->invokingState;
|
||||
}
|
||||
} else {
|
||||
ssize_t ruleIndex = parent->getRuleIndex();
|
||||
ssize_t ruleIndex = currentParent->getRuleIndex();
|
||||
|
||||
std::string ruleName = (ruleIndex >= 0 && ruleIndex < (ssize_t)ruleNames.size()) ? ruleNames[(size_t)ruleIndex] : std::to_string(ruleIndex);
|
||||
ss << ruleName;
|
||||
}
|
||||
|
||||
if (parent->parent.expired()) // No parent anymore.
|
||||
if (currentParent->parent.expired()) // No parent anymore.
|
||||
break;
|
||||
parent = parent->parent.lock();
|
||||
if (!ruleNames.empty() || !parent->isEmpty()) {
|
||||
currentParent = currentParent->parent.lock();
|
||||
if (!ruleNames.empty() || !currentParent->isEmpty()) {
|
||||
ss << " ";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,6 @@ int RuleContextWithAltNum::getAltNumber() const {
|
|||
return altNum;
|
||||
}
|
||||
|
||||
void RuleContextWithAltNum::setAltNumber(int altNum) {
|
||||
this->altNum = altNum;
|
||||
void RuleContextWithAltNum::setAltNumber(int number) {
|
||||
altNum = number;
|
||||
}
|
||||
|
|
|
@ -61,9 +61,9 @@ size_t TokenStreamRewriter::RewriteOperation::execute(std::string * /*buf*/) {
|
|||
|
||||
std::string TokenStreamRewriter::RewriteOperation::toString() {
|
||||
std::string opName = "TokenStreamRewriter";
|
||||
size_t index = opName.find('$');
|
||||
opName = opName.substr(index + 1, opName.length() - (index + 1));
|
||||
return "<" + opName + "@" + outerInstance->tokens->get(index)->getText() + ":\"" + text + "\">";
|
||||
size_t dollarIndex = opName.find('$');
|
||||
opName = opName.substr(dollarIndex + 1, opName.length() - (dollarIndex + 1));
|
||||
return "<" + opName + "@" + outerInstance->tokens->get(dollarIndex)->getText() + ":\"" + text + "\">";
|
||||
}
|
||||
|
||||
void TokenStreamRewriter::RewriteOperation::InitializeInstanceFields() {
|
||||
|
|
|
@ -99,7 +99,7 @@ size_t UnbufferedCharStream::fill(size_t n) {
|
|||
}
|
||||
|
||||
char32_t UnbufferedCharStream::nextChar() {
|
||||
wchar_t result = EOF;
|
||||
wchar_t result = 0;
|
||||
_input >> result;
|
||||
return result;
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ size_t UnbufferedCharStream::getBufferStartIndex() const {
|
|||
void UnbufferedCharStream::InitializeInstanceFields() {
|
||||
_p = 0;
|
||||
_numMarkers = 0;
|
||||
_lastChar = -1;
|
||||
_lastChar = 0;
|
||||
_lastCharBufferStart = 0;
|
||||
_currentCharIndex = 0;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,12 @@
|
|||
// Defines for the Guid class and other platform dependent stuff.
|
||||
#ifdef _WIN32
|
||||
#pragma warning (disable: 4250) // Class inherits by dominance.
|
||||
#pragma warning (disable: 4512) // assignment operator could not be generated
|
||||
|
||||
#if _MSC_VER <= 1900
|
||||
// Before VS 2015 code like "while (true)" will create a (useless) warning in level 4.
|
||||
#pragma warning (disable: 4127) // conditional expression is constant
|
||||
#endif
|
||||
|
||||
#define GUID_WINDOWS
|
||||
|
||||
|
|
|
@ -60,18 +60,18 @@ bool ATNDeserializationOptions::isVerifyATN() {
|
|||
return verifyATN;
|
||||
}
|
||||
|
||||
void ATNDeserializationOptions::setVerifyATN(bool verifyATN) {
|
||||
void ATNDeserializationOptions::setVerifyATN(bool verify) {
|
||||
throwIfReadOnly();
|
||||
this->verifyATN = verifyATN;
|
||||
verifyATN = verify;
|
||||
}
|
||||
|
||||
bool ATNDeserializationOptions::isGenerateRuleBypassTransitions() {
|
||||
return generateRuleBypassTransitions;
|
||||
}
|
||||
|
||||
void ATNDeserializationOptions::setGenerateRuleBypassTransitions(bool generateRuleBypassTransitions) {
|
||||
void ATNDeserializationOptions::setGenerateRuleBypassTransitions(bool generate) {
|
||||
throwIfReadOnly();
|
||||
this->generateRuleBypassTransitions = generateRuleBypassTransitions;
|
||||
generateRuleBypassTransitions = generate;
|
||||
}
|
||||
|
||||
void ATNDeserializationOptions::throwIfReadOnly() {
|
||||
|
|
|
@ -57,11 +57,11 @@ namespace atn {
|
|||
|
||||
bool isVerifyATN();
|
||||
|
||||
void setVerifyATN(bool verifyATN);
|
||||
void setVerifyATN(bool verify);
|
||||
|
||||
bool isGenerateRuleBypassTransitions();
|
||||
|
||||
void setGenerateRuleBypassTransitions(bool generateRuleBypassTransitions);
|
||||
void setGenerateRuleBypassTransitions(bool generate);
|
||||
|
||||
protected:
|
||||
virtual void throwIfReadOnly();
|
||||
|
|
|
@ -128,6 +128,6 @@ bool ATNState::onlyHasEpsilonTransitions() {
|
|||
return epsilonOnlyTransitions;
|
||||
}
|
||||
|
||||
void ATNState::setRuleIndex(int ruleIndex) {
|
||||
this->ruleIndex = ruleIndex;
|
||||
void ATNState::setRuleIndex(int index) {
|
||||
ruleIndex = index;
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ namespace atn {
|
|||
virtual Transition *removeTransition(int index);
|
||||
virtual int getStateType() = 0;
|
||||
bool onlyHasEpsilonTransitions();
|
||||
virtual void setRuleIndex(int ruleIndex);
|
||||
virtual void setRuleIndex(int index);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ bool ActionTransition::isEpsilon() const {
|
|||
return true; // we are to be ignored by analysis 'cept for predicates
|
||||
}
|
||||
|
||||
bool ActionTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
|
||||
bool ActionTransition::matches(ssize_t /*symbol*/, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace atn {
|
|||
|
||||
virtual bool isEpsilon() const override;
|
||||
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
|
||||
virtual std::string toString() const override;
|
||||
};
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
using namespace antlr4::misc;
|
||||
using namespace antlr4::atn;
|
||||
|
||||
AtomTransition::AtomTransition(ATNState *target, size_t label) : Transition(target), _label(label) {
|
||||
AtomTransition::AtomTransition(ATNState *target, ssize_t label) : Transition(target), _label(label) {
|
||||
}
|
||||
|
||||
int AtomTransition::getSerializationType() const {
|
||||
|
@ -48,7 +48,7 @@ IntervalSet AtomTransition::label() const {
|
|||
return IntervalSet::of((int)_label);
|
||||
}
|
||||
|
||||
bool AtomTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
|
||||
bool AtomTransition::matches(ssize_t symbol, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
|
||||
return _label == symbol;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,14 +40,14 @@ namespace atn {
|
|||
class ANTLR4CPP_PUBLIC AtomTransition final : public Transition {
|
||||
public:
|
||||
/// The token type or character value; or, signifies special label.
|
||||
const size_t _label;
|
||||
const ssize_t _label;
|
||||
|
||||
AtomTransition(ATNState *target, size_t label);
|
||||
AtomTransition(ATNState *target, ssize_t label);
|
||||
|
||||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual misc::IntervalSet label() const override;
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
|
||||
virtual std::string toString() const override;
|
||||
};
|
||||
|
|
|
@ -52,7 +52,7 @@ bool EpsilonTransition::isEpsilon() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool EpsilonTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
|
||||
bool EpsilonTransition::matches(ssize_t /*symbol*/, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace atn {
|
|||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual bool isEpsilon() const override;
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
|
||||
virtual std::string toString() const override;
|
||||
|
||||
|
|
|
@ -49,6 +49,10 @@
|
|||
|
||||
#include "atn/LexerATNSimulator.h"
|
||||
|
||||
#define DEBUG_ATN 0
|
||||
#define DEBUG_DFA 0
|
||||
|
||||
|
||||
using namespace antlr4;
|
||||
using namespace antlr4::atn;
|
||||
using namespace antlrcpp;
|
||||
|
@ -208,9 +212,11 @@ dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, ssize
|
|||
}
|
||||
|
||||
dfa::DFAState *target = s->edges[(size_t)(t - MIN_DFA_EDGE)];
|
||||
if (debug && target != nullptr) {
|
||||
#if DEBUG_ATN == 1
|
||||
if (target != nullptr) {
|
||||
std::cout << std::string("reuse state ") << s->stateNumber << std::string(" edge to ") << target->stateNumber << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return target;
|
||||
}
|
||||
|
@ -264,9 +270,9 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
|
|||
continue;
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "testing " << getTokenName((int)t) << " at " << c->toString(true) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t n = c->state->getNumberOfTransitions();
|
||||
for (size_t ti = 0; ti < n; ti++) { // for each transition
|
||||
|
@ -295,10 +301,10 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
|
|||
|
||||
void LexerATNSimulator::accept(CharStream *input, const Ref<LexerActionExecutor> &lexerActionExecutor, int /*startIndex*/,
|
||||
size_t index, size_t line, size_t charPos) {
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "ACTION ";
|
||||
std::cout << toString(lexerActionExecutor) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
// seek to after last char in token
|
||||
input->seek(index);
|
||||
|
@ -332,18 +338,18 @@ std::unique_ptr<ATNConfigSet> LexerATNSimulator::computeStartState(CharStream *i
|
|||
|
||||
bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &config, ATNConfigSet *configs,
|
||||
bool currentAltReachedAcceptState, bool speculative, bool treatEofAsEpsilon) {
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "closure(" << config->toString(true) << ")" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (is<RuleStopState *>(config->state)) {
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
if (_recog != nullptr) {
|
||||
std::cout << "closure at " << _recog->getRuleNames()[(size_t)config->state->ruleIndex] << " rule stop " << config << std::endl;
|
||||
} else {
|
||||
std::cout << "closure at rule stop " << config << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (config->context == nullptr || config->context->hasEmptyPath()) {
|
||||
if (config->context == nullptr || config->context->isEmpty()) {
|
||||
|
@ -423,9 +429,11 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const
|
|||
test them, we cannot cash the DFA state target of ID.
|
||||
*/
|
||||
PredicateTransition *pt = static_cast<PredicateTransition*>(t);
|
||||
if (debug) {
|
||||
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "EVAL rule " << pt->ruleIndex << ":" << pt->predIndex << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
configs->hasSemanticContext = true;
|
||||
if (evaluatePredicate(input, pt->ruleIndex, pt->predIndex, speculative)) {
|
||||
c = std::make_shared<LexerATNConfig>(config, t->target);
|
||||
|
|
|
@ -64,9 +64,6 @@ namespace atn {
|
|||
|
||||
|
||||
public:
|
||||
static const bool debug = false;
|
||||
static const bool dfa_debug = false;
|
||||
|
||||
static const int MIN_DFA_EDGE = 0;
|
||||
static const int MAX_DFA_EDGE = 127; // forces unicode to stay in ATN
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ int NotSetTransition::getSerializationType() const {
|
|||
return NOT_SET;
|
||||
}
|
||||
|
||||
bool NotSetTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const {
|
||||
bool NotSetTransition::matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const {
|
||||
return symbol >= minVocabSymbol && symbol <= maxVocabSymbol
|
||||
&& !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace atn {
|
|||
|
||||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
|
||||
virtual std::string toString() const override;
|
||||
};
|
||||
|
|
|
@ -55,6 +55,11 @@
|
|||
|
||||
#include "atn/ParserATNSimulator.h"
|
||||
|
||||
#define DEBUG_ATN 0
|
||||
#define DEBUG_LIST_ATN_DECISIONS 0
|
||||
#define DEBUG_DFA 0
|
||||
#define RETRY_DEBUG 0
|
||||
|
||||
using namespace antlr4;
|
||||
using namespace antlr4::atn;
|
||||
|
||||
|
@ -83,10 +88,10 @@ void ParserATNSimulator::clearDFA() {
|
|||
}
|
||||
|
||||
int ParserATNSimulator::adaptivePredict(TokenStream *input, int decision, Ref<ParserRuleContext> const& outerContext) {
|
||||
if (debug || debug_list_atn_decisions) {
|
||||
#if DEBUG_ATN == 1 || DEBUG_LIST_ATN_DECISIONS == 1
|
||||
std::cout << "adaptivePredict decision " << decision << " exec LA(1)==" << getLookaheadName(input) << " line "
|
||||
<< input->LT(1)->getLine() << ":" << input->LT(1)->getCharPositionInLine() << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
_input = input;
|
||||
_startIndex = (int)input->index();
|
||||
|
@ -153,16 +158,16 @@ int ParserATNSimulator::adaptivePredict(TokenStream *input, int decision, Ref<Pa
|
|||
|
||||
int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *input, size_t startIndex,
|
||||
Ref<ParserRuleContext> outerContext) {
|
||||
if (debug || debug_list_atn_decisions) {
|
||||
#if DEBUG_ATN == 1 || DEBUG_LIST_ATN_DECISIONS == 1
|
||||
std::cout << "execATN decision " << dfa.decision << " exec LA(1)==" << getLookaheadName(input) <<
|
||||
" line " << input->LT(1)->getLine() << ":" << input->LT(1)->getCharPositionInLine() << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
dfa::DFAState *previousD = s0;
|
||||
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "s0 = " << s0 << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
ssize_t t = input->LA(1);
|
||||
|
||||
|
@ -196,9 +201,10 @@ int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *i
|
|||
// IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
|
||||
BitSet conflictingAlts;
|
||||
if (D->predicates.size() != 0) {
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "DFA state has preds in DFA sim LL failover" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t conflictIndex = input->index();
|
||||
if (conflictIndex != (size_t)startIndex) {
|
||||
input->seek((size_t)startIndex);
|
||||
|
@ -206,9 +212,10 @@ int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *i
|
|||
|
||||
conflictingAlts = evalSemanticContext(D->predicates, outerContext, true);
|
||||
if (conflictingAlts.count() == 1) {
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "Full LL avoided" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return conflictingAlts.nextSetBit(0);
|
||||
}
|
||||
|
||||
|
@ -219,9 +226,10 @@ int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *i
|
|||
}
|
||||
}
|
||||
|
||||
if (dfa_debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "ctx sensitive state " << outerContext << " in " << D << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool fullCtx = true;
|
||||
Ref<ATNConfigSet> s0_closure = computeStartState(dfa.atnStartState, outerContext, fullCtx);
|
||||
reportAttemptingFullContext(dfa, conflictingAlts, D->configs.get(), startIndex, input->index());
|
||||
|
@ -693,9 +701,10 @@ std::vector<Ref<SemanticContext>> ParserATNSimulator::getPredsForAmbigAlts(const
|
|||
if (nPredAlts == 0) {
|
||||
altToPred.clear();
|
||||
}
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "getPredsForAmbigAlts result " << Arrays::toString(altToPred) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return altToPred;
|
||||
}
|
||||
|
||||
|
@ -792,14 +801,15 @@ BitSet ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPr
|
|||
|
||||
bool fullCtx = false; // in dfa
|
||||
bool predicateEvaluationResult = evalSemanticContext(prediction->pred, outerContext, prediction->alt, fullCtx);
|
||||
if (debug || dfa_debug) {
|
||||
#if DEBUG_ATN == 1 || DEBUG_DFA == 1
|
||||
std::cout << "eval pred " << prediction->toString() << " = " << predicateEvaluationResult << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (predicateEvaluationResult) {
|
||||
if (debug || dfa_debug) {
|
||||
#if DEBUG_ATN == 1 || DEBUG_DFA == 1
|
||||
std::cout << "PREDICT " << prediction->alt << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
predictions.set((size_t)prediction->alt);
|
||||
if (!complete) {
|
||||
break;
|
||||
|
@ -826,9 +836,9 @@ void ParserATNSimulator::closure(Ref<ATNConfig> const& config, ATNConfigSet *con
|
|||
void ParserATNSimulator::closureCheckingStopState(Ref<ATNConfig> const& config, ATNConfigSet *configs,
|
||||
ATNConfig::Set &closureBusy, bool collectPredicates, bool fullCtx, int depth, bool treatEofAsEpsilon) {
|
||||
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "closure(" << config->toString(true) << ")" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (is<RuleStopState *>(config->state)) {
|
||||
// We hit rule end. If we have context info, use it
|
||||
|
@ -841,9 +851,9 @@ void ParserATNSimulator::closureCheckingStopState(Ref<ATNConfig> const& config,
|
|||
continue;
|
||||
} else {
|
||||
// we have no context info, just chase follow links (if greedy)
|
||||
if (debug) {
|
||||
#if DEBUG_ATN == 1
|
||||
std::cout << "FALLING off rule " << getRuleName((size_t)config->state->ruleIndex) << std::endl;
|
||||
}
|
||||
#endif
|
||||
closure_(config, configs, closureBusy, collectPredicates, fullCtx, depth, treatEofAsEpsilon);
|
||||
}
|
||||
continue;
|
||||
|
@ -928,9 +938,10 @@ void ParserATNSimulator::closure_(Ref<ATNConfig> const& config, ATNConfigSet *co
|
|||
assert(newDepth > INT_MIN);
|
||||
|
||||
newDepth--;
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "dips into outer ctx: " << c << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
} else if (is<RuleTransition*>(t)) {
|
||||
// latch when newDepth goes negative - once we step out of the entry context we can't return
|
||||
if (newDepth >= 0) {
|
||||
|
@ -987,20 +998,21 @@ Ref<ATNConfig> ParserATNSimulator::getEpsilonTarget(Ref<ATNConfig> const& config
|
|||
}
|
||||
|
||||
Ref<ATNConfig> ParserATNSimulator::actionTransition(Ref<ATNConfig> const& config, ActionTransition *t) {
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "ACTION edge " << t->ruleIndex << ":" << t->actionIndex << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return std::make_shared<ATNConfig>(config, t->target);
|
||||
}
|
||||
|
||||
Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& config, PrecedencePredicateTransition *pt,
|
||||
bool collectPredicates, bool inContext, bool fullCtx) {
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "PRED (collectPredicates=" << collectPredicates << ") " << pt->precedence << ">=_p" << ", ctx dependent=true" << std::endl;
|
||||
if (parser != nullptr) {
|
||||
std::cout << "context surrounding pred is " << Arrays::listToString(parser->getRuleInvocationStack(), ", ") << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Ref<ATNConfig> c;
|
||||
if (collectPredicates && inContext) {
|
||||
|
@ -1026,20 +1038,21 @@ Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& co
|
|||
c = std::make_shared<ATNConfig>(config, pt->target);
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "config from pred transition=" << c << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config, PredicateTransition *pt,
|
||||
bool collectPredicates, bool inContext, bool fullCtx) {
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "PRED (collectPredicates=" << collectPredicates << ") " << pt->ruleIndex << ":" << pt->predIndex << ", ctx dependent=" << pt->isCtxDependent << std::endl;
|
||||
if (parser != nullptr) {
|
||||
std::cout << "context surrounding pred is " << Arrays::listToString(parser->getRuleInvocationStack(), ", ") << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Ref<ATNConfig> c = nullptr;
|
||||
if (collectPredicates && (!pt->isCtxDependent || (pt->isCtxDependent && inContext))) {
|
||||
|
@ -1064,16 +1077,17 @@ Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config,
|
|||
c = std::make_shared<ATNConfig>(config, pt->target);
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "config from pred transition=" << c << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
Ref<ATNConfig> ParserATNSimulator::ruleTransition(Ref<ATNConfig> const& config, RuleTransition *t) {
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "CALL rule " << getRuleName((size_t)t->target->ruleIndex) << ", ctx=" << config->context << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
atn::ATNState *returnState = t->followState;
|
||||
Ref<PredictionContext> newContext = SingletonPredictionContext::create(config->context, returnState->stateNumber);
|
||||
|
@ -1152,9 +1166,9 @@ int ParserATNSimulator::getUniqueAlt(ATNConfigSet *configs) {
|
|||
}
|
||||
|
||||
dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA &dfa, dfa::DFAState *from, ssize_t t, dfa::DFAState *to) {
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "EDGE " << from << " -> " << to << " upon " << getTokenName(t) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (to == nullptr) {
|
||||
return nullptr;
|
||||
|
@ -1172,7 +1186,7 @@ dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA &dfa, dfa::DFAState *from
|
|||
from->edges[(size_t)(t + 1)] = to; // connect
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::string dfaText;
|
||||
if (parser != nullptr) {
|
||||
dfaText = dfa.toString(parser->getVocabulary());
|
||||
|
@ -1180,7 +1194,7 @@ dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA &dfa, dfa::DFAState *from
|
|||
dfaText = dfa.toString(dfa::Vocabulary::EMPTY_VOCABULARY);
|
||||
}
|
||||
std::cout << "DFA=\n" << dfaText << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return to;
|
||||
}
|
||||
|
@ -1204,19 +1218,21 @@ dfa::DFAState *ParserATNSimulator::addDFAState(dfa::DFA &dfa, dfa::DFAState *D)
|
|||
D->configs->setReadonly(true);
|
||||
}
|
||||
dfa.states.insert(D);
|
||||
if (debug) {
|
||||
#if DEBUG_DFA == 1
|
||||
std::cout << "adding new DFA state: " << D << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return D;
|
||||
}
|
||||
}
|
||||
|
||||
void ParserATNSimulator::reportAttemptingFullContext(dfa::DFA &dfa, const antlrcpp::BitSet &conflictingAlts,
|
||||
ATNConfigSet *configs, size_t startIndex, size_t stopIndex) {
|
||||
if (debug || retry_debug) {
|
||||
#if DEBUG_DFA == 1 || RETRY_DEBUG == 1
|
||||
misc::Interval interval = misc::Interval((int)startIndex, (int)stopIndex);
|
||||
std::cout << "reportAttemptingFullContext decision=" << dfa.decision << ":" << configs << ", input=" << parser->getTokenStream()->getText(interval) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (parser != nullptr) {
|
||||
parser->getErrorListenerDispatch().reportAttemptingFullContext(parser, dfa, startIndex, stopIndex, conflictingAlts, configs);
|
||||
}
|
||||
|
@ -1224,10 +1240,11 @@ void ParserATNSimulator::reportAttemptingFullContext(dfa::DFA &dfa, const antlrc
|
|||
|
||||
void ParserATNSimulator::reportContextSensitivity(dfa::DFA &dfa, int prediction, ATNConfigSet *configs,
|
||||
size_t startIndex, size_t stopIndex) {
|
||||
if (debug || retry_debug) {
|
||||
#if DEBUG_DFA == 1 || RETRY_DEBUG == 1
|
||||
misc::Interval interval = misc::Interval((int)startIndex, (int)stopIndex);
|
||||
std::cout << "reportContextSensitivity decision=" << dfa.decision << ":" << configs << ", input=" << parser->getTokenStream()->getText(interval) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (parser != nullptr) {
|
||||
parser->getErrorListenerDispatch().reportContextSensitivity(parser, dfa, startIndex, stopIndex, prediction, configs);
|
||||
}
|
||||
|
@ -1235,17 +1252,18 @@ void ParserATNSimulator::reportContextSensitivity(dfa::DFA &dfa, int prediction,
|
|||
|
||||
void ParserATNSimulator::reportAmbiguity(dfa::DFA &dfa, dfa::DFAState * /*D*/, size_t startIndex, size_t stopIndex,
|
||||
bool exact, const antlrcpp::BitSet &ambigAlts, ATNConfigSet *configs) {
|
||||
if (debug || retry_debug) {
|
||||
#if DEBUG_DFA == 1 || RETRY_DEBUG == 1
|
||||
misc::Interval interval = misc::Interval((int)startIndex, (int)stopIndex);
|
||||
std::cout << "reportAmbiguity " << ambigAlts << ":" << configs << ", input=" << parser->getTokenStream()->getText(interval) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (parser != nullptr) {
|
||||
parser->getErrorListenerDispatch().reportAmbiguity(parser, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
|
||||
}
|
||||
}
|
||||
|
||||
void ParserATNSimulator::setPredictionMode(PredictionMode mode) {
|
||||
this->mode = mode;
|
||||
void ParserATNSimulator::setPredictionMode(PredictionMode newMode) {
|
||||
mode = newMode;
|
||||
}
|
||||
|
||||
atn::PredictionMode ParserATNSimulator::getPredictionMode() {
|
||||
|
|
|
@ -269,12 +269,6 @@ namespace atn {
|
|||
* the input.</p>
|
||||
*/
|
||||
class ANTLR4CPP_PUBLIC ParserATNSimulator : public ATNSimulator {
|
||||
public:
|
||||
static const bool debug = false;
|
||||
static const bool debug_list_atn_decisions = false;
|
||||
static const bool dfa_debug = false;
|
||||
static const bool retry_debug = false;
|
||||
|
||||
protected:
|
||||
Parser *const parser;
|
||||
|
||||
|
@ -848,7 +842,7 @@ namespace atn {
|
|||
ATNConfigSet *configs); // configs that LL not SLL considered conflicting
|
||||
|
||||
public:
|
||||
void setPredictionMode(PredictionMode mode);
|
||||
void setPredictionMode(PredictionMode newMode);
|
||||
PredictionMode getPredictionMode();
|
||||
|
||||
Parser* getParser();
|
||||
|
|
|
@ -45,7 +45,7 @@ bool PrecedencePredicateTransition::isEpsilon() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PrecedencePredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
|
||||
bool PrecedencePredicateTransition::matches(ssize_t /*symbol*/, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace atn {
|
|||
|
||||
virtual int getSerializationType() const override;
|
||||
virtual bool isEpsilon() const override;
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
Ref<SemanticContext::PrecedencePredicate> getPredicate() const;
|
||||
virtual std::string toString() const override;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ bool PredicateTransition::isEpsilon() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
|
||||
bool PredicateTransition::matches(ssize_t /*symbol*/, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace atn {
|
|||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual bool isEpsilon() const override;
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
|
||||
Ref<SemanticContext::Predicate> getPredicate() const;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
using namespace antlr4;
|
||||
using namespace antlr4::atn;
|
||||
|
||||
RangeTransition::RangeTransition(ATNState *target, size_t from, size_t to) : Transition(target), from(from), to(to) {
|
||||
RangeTransition::RangeTransition(ATNState *target, ssize_t from, ssize_t to) : Transition(target), from(from), to(to) {
|
||||
}
|
||||
|
||||
int RangeTransition::getSerializationType() const {
|
||||
|
@ -47,7 +47,7 @@ misc::IntervalSet RangeTransition::label() const {
|
|||
return misc::IntervalSet::of((int)from, (int)to);
|
||||
}
|
||||
|
||||
bool RangeTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
|
||||
bool RangeTransition::matches(ssize_t symbol, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
|
||||
return symbol >= from && symbol <= to;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,15 +38,15 @@ namespace atn {
|
|||
|
||||
class ANTLR4CPP_PUBLIC RangeTransition final : public Transition {
|
||||
public:
|
||||
const size_t from;
|
||||
const size_t to;
|
||||
const ssize_t from;
|
||||
const ssize_t to;
|
||||
|
||||
RangeTransition(ATNState *target, size_t from, size_t to);
|
||||
RangeTransition(ATNState *target, ssize_t from, ssize_t to);
|
||||
|
||||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual misc::IntervalSet label() const override;
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
|
||||
virtual std::string toString() const override;
|
||||
};
|
||||
|
|
|
@ -51,7 +51,7 @@ bool RuleTransition::isEpsilon() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool RuleTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
|
||||
bool RuleTransition::matches(ssize_t /*symbol*/, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace atn {
|
|||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual bool isEpsilon() const override;
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
|
||||
virtual std::string toString() const override;
|
||||
};
|
||||
|
|
|
@ -49,7 +49,7 @@ misc::IntervalSet SetTransition::label() const {
|
|||
return set;
|
||||
}
|
||||
|
||||
bool SetTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
|
||||
bool SetTransition::matches(ssize_t symbol, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
|
||||
return set.contains((int)symbol);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace atn {
|
|||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual misc::IntervalSet label() const override;
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
|
||||
virtual std::string toString() const override;
|
||||
};
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace atn {
|
|||
*/
|
||||
virtual bool isEpsilon() const;
|
||||
virtual misc::IntervalSet label() const;
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const = 0;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const = 0;
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
|
|
@ -42,7 +42,7 @@ int WildcardTransition::getSerializationType() const {
|
|||
return WILDCARD;
|
||||
}
|
||||
|
||||
bool WildcardTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const {
|
||||
bool WildcardTransition::matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const {
|
||||
return symbol >= minVocabSymbol && symbol <= maxVocabSymbol;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace atn {
|
|||
|
||||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
|
||||
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
|
||||
|
||||
virtual std::string toString() const override;
|
||||
};
|
||||
|
|
|
@ -33,6 +33,11 @@
|
|||
|
||||
#include "antlr4-common.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4521) // 'antlrcpp::Any': multiple copy constructors specified
|
||||
#endif
|
||||
|
||||
namespace antlrcpp {
|
||||
|
||||
template<class T>
|
||||
|
@ -46,6 +51,9 @@ struct Any
|
|||
Any() : _ptr(nullptr) {
|
||||
}
|
||||
|
||||
Any(Any& that) : _ptr(that.clone()) {
|
||||
}
|
||||
|
||||
Any(Any&& that) : _ptr(that._ptr) {
|
||||
that._ptr = nullptr;
|
||||
}
|
||||
|
@ -147,3 +155,7 @@ private:
|
|||
};
|
||||
|
||||
} // namespace antlrcpp
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace antlrcpp {
|
|||
switch (c) {
|
||||
case ' ':
|
||||
if (escapeSpaces) {
|
||||
result += (char)'0xB7';
|
||||
result += "·";
|
||||
break;
|
||||
} else {
|
||||
// fall through
|
||||
|
@ -85,7 +85,7 @@ namespace antlrcpp {
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string toHexString(const int t){
|
||||
std::string toHexString(const int t) {
|
||||
std::stringstream stream;
|
||||
stream << std::uppercase << std::hex << t;
|
||||
return stream.str();
|
||||
|
@ -105,8 +105,7 @@ namespace antlrcpp {
|
|||
|
||||
ss = s;
|
||||
p = ss.find(from);
|
||||
while (p != std::string::npos)
|
||||
{
|
||||
while (p != std::string::npos) {
|
||||
if (p > 0)
|
||||
res.append(ss.substr(0, p)).append(to);
|
||||
else
|
||||
|
@ -119,8 +118,6 @@ namespace antlrcpp {
|
|||
return res;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
std::vector<std::string> split(const std::string &s, const std::string &sep, int count) {
|
||||
std::vector<std::string> parts;
|
||||
std::string ss = s;
|
||||
|
@ -134,13 +131,12 @@ namespace antlrcpp {
|
|||
count= -1;
|
||||
|
||||
p = ss.find(sep);
|
||||
while (!ss.empty() && p != std::string::npos && (count < 0 || count > 0))
|
||||
{
|
||||
while (!ss.empty() && p != std::string::npos && (count < 0 || count > 0)) {
|
||||
parts.push_back(ss.substr(0, p));
|
||||
ss= ss.substr(p+sep.size());
|
||||
ss = ss.substr(p+sep.size());
|
||||
|
||||
--count;
|
||||
p= ss.find(sep);
|
||||
p = ss.find(sep);
|
||||
}
|
||||
parts.push_back(ss);
|
||||
|
||||
|
@ -164,24 +160,31 @@ namespace antlrcpp {
|
|||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
// Recursively get the error from a, possibly nested, exception.
|
||||
template <typename T>
|
||||
std::exception_ptr get_nested(const T &e)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026
|
||||
return nullptr; // No nested exceptions before VS 2015.
|
||||
// No nested exceptions before VS 2015.
|
||||
template <typename T>
|
||||
std::exception_ptr get_nested(const T &/*e*/) {
|
||||
try {
|
||||
return nullptr;
|
||||
}
|
||||
catch (const std::bad_cast &) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#else
|
||||
template <typename T>
|
||||
std::exception_ptr get_nested(const T &e) {
|
||||
try {
|
||||
auto nested = dynamic_cast<const std::nested_exception&>(e);
|
||||
return nested.nested_ptr();
|
||||
#endif
|
||||
}
|
||||
catch (const std::bad_cast &)
|
||||
{ return nullptr; }
|
||||
catch (const std::bad_cast &) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string what(std::exception_ptr eptr)
|
||||
{
|
||||
std::string what(std::exception_ptr eptr) {
|
||||
if (!eptr) {
|
||||
throw std::bad_exception();
|
||||
}
|
||||
|
@ -189,10 +192,8 @@ namespace antlrcpp {
|
|||
std::string result;
|
||||
std::size_t nestCount = 0;
|
||||
|
||||
next:
|
||||
{
|
||||
try
|
||||
{
|
||||
next: {
|
||||
try {
|
||||
std::exception_ptr yeptr;
|
||||
std::swap(eptr, yeptr);
|
||||
std::rethrow_exception(yeptr);
|
||||
|
|
|
@ -87,7 +87,7 @@ std::string Trees::toStringTree(Ref<Tree> const& t, const std::vector<std::strin
|
|||
ss << ' ';
|
||||
}
|
||||
Ref<Tree> child = run->getChild(childIndex);
|
||||
std::string temp = antlrcpp::escapeWhitespace(Trees::getNodeText(child, ruleNames), false);
|
||||
temp = antlrcpp::escapeWhitespace(Trees::getNodeText(child, ruleNames), false);
|
||||
if (child->getChildCount() > 0) {
|
||||
// Go deeper one level.
|
||||
stack.push(childIndex);
|
||||
|
|
Loading…
Reference in New Issue