Refactoring of further int values, mostly converting them to size_t.

- Switched most symbolic signed constants to unsigned variants. Redefined EOF in particular to become (size)-1, to avoid having to use signed token type values.
- Introduced INVALID_INDEX for all previous -1 values to indicate e.g. not found indexes etc.
- Added 2 helpers to convert between symbolic and numeric form (mostly for intervals and toString()).
- Removed many no longer needed type casts to size_t.
- Updated templates for these changes.
- Limited runtime tests to C++ tests only, to see how Travis CI copes with that.
This commit is contained in:
Mike Lischke 2016-10-02 16:51:57 +02:00
parent de4df872fe
commit 8280beb564
150 changed files with 1060 additions and 1118 deletions

View File

@ -113,7 +113,7 @@ antlr4-tool-testsuite/4.5.2-SNAPSHOT/antlr4-tool-testsuite-4.5.2-SNAPSHOT.jar
Note that ANTLR is written in itself, which is why maven downloads antlr4-4.5.jar for boostrapping 4.5.2-SNAPSHOT purposes.
## Building without testing
To build without running the tests (saves more than 30 mins), do this:
To build without running the tests (saves a lot of time), do this:
```bash
mvn -DskipTests install

View File

@ -70,12 +70,12 @@
<version>2.12.4</version>
<configuration>
<includes>
<include>**/csharp/Test*.java</include>
<include>**/cpp/Test*.java</include>
<include>**/cpp/TestParserErrors.java</include>
<!--include>**/csharp/Test*.java</include>
<include>**/java/Test*.java</include>
<include>**/javascript/node/Test*.java</include>
<include>**/python2/Test*.java</include>
<include>**/python3/Test*.java</include>
<include>**/python3/Test*.java</include-->
</includes>
</configuration>
</plugin>

View File

@ -946,18 +946,14 @@ public abstract class BaseCppTest {
+ "#include \"antlr4-runtime.h\"\n"
+ "#include \"<lexerName>.h\"\n"
+ "#include \"<parserName>.h\"\n"
+ "#include \"<listenerName>.h\"\n"
+ "#include \"<visitorName>.h\"\n"
+ "\n"
+ "#include \"support/StringUtils.h\"\n"
+ "\n"
+ "using namespace antlr4;\n"
+ "\n"
+ "class TreeShapeListener : public tree::ParseTreeListener {\n"
+ "public:\n"
+ " void visitTerminal(tree::TerminalNode *node) override {}\n"
+ " void visitErrorNode(tree::ErrorNode *node) override {}\n"
+ " void exitEveryRule(ParserRuleContext *ctx) override {}\n"
+ " void visitTerminal(tree::TerminalNode *) override {}\n"
+ " void visitErrorNode(tree::ErrorNode *) override {}\n"
+ " void exitEveryRule(ParserRuleContext *) override {}\n"
+ " void enterEveryRule(ParserRuleContext *ctx) override {\n"
+ " for (auto child : ctx->children) {\n"
+ " auto parent = child->parent.lock();\n"

View File

@ -911,7 +911,7 @@
276E5C201CDB57AA003FF4B4 /* ATNConfigSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNConfigSet.h; sourceTree = "<group>"; wrapsLines = 0; };
276E5C211CDB57AA003FF4B4 /* ATNDeserializationOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNDeserializationOptions.cpp; sourceTree = "<group>"; };
276E5C221CDB57AA003FF4B4 /* ATNDeserializationOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNDeserializationOptions.h; sourceTree = "<group>"; };
276E5C231CDB57AA003FF4B4 /* ATNDeserializer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNDeserializer.cpp; sourceTree = "<group>"; };
276E5C231CDB57AA003FF4B4 /* ATNDeserializer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNDeserializer.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5C241CDB57AA003FF4B4 /* ATNDeserializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNDeserializer.h; sourceTree = "<group>"; };
276E5C251CDB57AA003FF4B4 /* ATNSerializer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = ATNSerializer.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
276E5C261CDB57AA003FF4B4 /* ATNSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNSerializer.h; sourceTree = "<group>"; };
@ -969,7 +969,7 @@
276E5C5D1CDB57AA003FF4B4 /* LexerSkipAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerSkipAction.h; sourceTree = "<group>"; };
276E5C5E1CDB57AA003FF4B4 /* LexerTypeAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerTypeAction.cpp; sourceTree = "<group>"; };
276E5C5F1CDB57AA003FF4B4 /* LexerTypeAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerTypeAction.h; sourceTree = "<group>"; };
276E5C601CDB57AA003FF4B4 /* LL1Analyzer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LL1Analyzer.cpp; sourceTree = "<group>"; };
276E5C601CDB57AA003FF4B4 /* LL1Analyzer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LL1Analyzer.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5C611CDB57AA003FF4B4 /* LL1Analyzer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LL1Analyzer.h; sourceTree = "<group>"; wrapsLines = 0; };
276E5C621CDB57AA003FF4B4 /* LookaheadEventInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LookaheadEventInfo.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5C631CDB57AA003FF4B4 /* LookaheadEventInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LookaheadEventInfo.h; sourceTree = "<group>"; wrapsLines = 0; };
@ -1059,7 +1059,7 @@
276E5CB91CDB57AA003FF4B4 /* FailedPredicateException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FailedPredicateException.h; sourceTree = "<group>"; };
276E5CBA1CDB57AA003FF4B4 /* InputMismatchException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InputMismatchException.cpp; sourceTree = "<group>"; };
276E5CBB1CDB57AA003FF4B4 /* InputMismatchException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InputMismatchException.h; sourceTree = "<group>"; };
276E5CBC1CDB57AA003FF4B4 /* InterpreterRuleContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InterpreterRuleContext.cpp; sourceTree = "<group>"; };
276E5CBC1CDB57AA003FF4B4 /* InterpreterRuleContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InterpreterRuleContext.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5CBD1CDB57AA003FF4B4 /* InterpreterRuleContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterpreterRuleContext.h; sourceTree = "<group>"; };
276E5CBE1CDB57AA003FF4B4 /* IntStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntStream.cpp; sourceTree = "<group>"; };
276E5CBF1CDB57AA003FF4B4 /* IntStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntStream.h; sourceTree = "<group>"; };
@ -1074,7 +1074,7 @@
276E5CC81CDB57AA003FF4B4 /* ListTokenSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListTokenSource.h; sourceTree = "<group>"; wrapsLines = 0; };
276E5CCA1CDB57AA003FF4B4 /* Interval.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Interval.cpp; sourceTree = "<group>"; };
276E5CCB1CDB57AA003FF4B4 /* Interval.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Interval.h; sourceTree = "<group>"; };
276E5CCC1CDB57AA003FF4B4 /* IntervalSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntervalSet.cpp; sourceTree = "<group>"; };
276E5CCC1CDB57AA003FF4B4 /* IntervalSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntervalSet.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5CCD1CDB57AA003FF4B4 /* IntervalSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntervalSet.h; sourceTree = "<group>"; };
276E5CCE1CDB57AA003FF4B4 /* MurmurHash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MurmurHash.cpp; sourceTree = "<group>"; };
276E5CCF1CDB57AA003FF4B4 /* MurmurHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MurmurHash.h; sourceTree = "<group>"; };

View File

@ -77,7 +77,7 @@ namespace antlr4 {
/// the parser was able to recover in line without exiting the
/// surrounding rule. </param>
virtual void syntaxError(IRecognizer *recognizer, Token *offendingSymbol, size_t line,
int charPositionInLine, const std::string &msg, std::exception_ptr e) = 0;
size_t charPositionInLine, const std::string &msg, std::exception_ptr e) = 0;
/**
* This method is called by the parser when a full-context prediction
@ -187,7 +187,7 @@ namespace antlr4 {
* was determined
*/
virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
int prediction, atn::ATNConfigSet *configs) = 0;
size_t prediction, atn::ATNConfigSet *configs) = 0;
};
} // namespace antlr4

View File

@ -92,7 +92,7 @@ void ANTLRInputStream::consume() {
}
}
ssize_t ANTLRInputStream::LA(ssize_t i) {
size_t ANTLRInputStream::LA(ssize_t i) {
if (i == 0) {
return 0; // undefined
}
@ -112,7 +112,7 @@ ssize_t ANTLRInputStream::LA(ssize_t i) {
return _data[(size_t)(position + i - 1)];
}
ssize_t ANTLRInputStream::LT(ssize_t i) {
size_t ANTLRInputStream::LT(ssize_t i) {
return LA(i);
}
@ -149,8 +149,8 @@ std::string ANTLRInputStream::getText(const Interval &interval) {
return "";
}
size_t start = (size_t)interval.a;
size_t stop = (size_t)interval.b;
size_t start = interval.a;
size_t stop = interval.b;
if (stop >= _data.size()) {

View File

@ -67,8 +67,8 @@ namespace antlr4 {
/// touched.
virtual void reset();
virtual void consume() override;
virtual ssize_t LA(ssize_t i) override;
virtual ssize_t LT(ssize_t i);
virtual size_t LA(ssize_t i) override;
virtual size_t LT(ssize_t i);
/// <summary>
/// Return the current input symbol index 0..n where n indicates the

View File

@ -35,7 +35,7 @@
using namespace antlr4;
void BaseErrorListener::syntaxError(IRecognizer * /*recognizer*/, Token * /*offendingSymbol*/, size_t /*line*/,
int /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) {
size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) {
}
void BaseErrorListener::reportAmbiguity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/,
@ -47,5 +47,5 @@ void BaseErrorListener::reportAttemptingFullContext(Parser * /*recognizer*/, con
}
void BaseErrorListener::reportContextSensitivity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/,
size_t /*stopIndex*/, int /*prediction*/, atn::ATNConfigSet * /*configs*/) {
size_t /*stopIndex*/, size_t /*prediction*/, atn::ATNConfigSet * /*configs*/) {
}

View File

@ -46,7 +46,7 @@ namespace antlr4 {
*/
class ANTLR4CPP_PUBLIC BaseErrorListener : public ANTLRErrorListener {
virtual void syntaxError(IRecognizer *recognizer, Token * offendingSymbol, size_t line, int charPositionInLine,
virtual void syntaxError(IRecognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine,
const std::string &msg, std::exception_ptr e) override;
virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
@ -56,7 +56,7 @@ namespace antlr4 {
const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override;
virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
int prediction, atn::ATNConfigSet *configs) override;
size_t prediction, atn::ATNConfigSet *configs) override;
};
} // namespace antlr4

View File

@ -169,7 +169,7 @@ std::vector<Token *> BufferedTokenStream::get(size_t start, size_t stop) {
return subset;
}
ssize_t BufferedTokenStream::LA(ssize_t i) {
size_t BufferedTokenStream::LA(ssize_t i) {
return LT(i)->getType();
}
@ -229,13 +229,13 @@ std::vector<Token *> BufferedTokenStream::getTokens() {
return result;
}
std::vector<Token *> BufferedTokenStream::getTokens(int start, int stop) {
return getTokens(start, stop, std::vector<int>());
std::vector<Token *> BufferedTokenStream::getTokens(size_t start, size_t stop) {
return getTokens(start, stop, std::vector<size_t>());
}
std::vector<Token *> BufferedTokenStream::getTokens(int start, int stop, const std::vector<int> &types) {
std::vector<Token *> BufferedTokenStream::getTokens(size_t start, size_t stop, const std::vector<size_t> &types) {
lazyInit();
if (start < 0 || stop >= (int)_tokens.size() || stop < 0 || start >= (int)_tokens.size()) {
if (stop >= _tokens.size() || start >= _tokens.size()) {
throw IndexOutOfBoundsException(std::string("start ") +
std::to_string(start) +
std::string(" or stop ") +
@ -250,7 +250,7 @@ std::vector<Token *> BufferedTokenStream::getTokens(int start, int stop, const s
return filteredTokens;
}
for (size_t i = (size_t)start; i <= (size_t)stop; i++) {
for (size_t i = start; i <= stop; i++) {
Token *tok = _tokens[i].get();
if (types.empty() || std::find(types.begin(), types.end(), tok->getType()) != types.end()) {
@ -260,8 +260,8 @@ std::vector<Token *> BufferedTokenStream::getTokens(int start, int stop, const s
return filteredTokens;
}
std::vector<Token *> BufferedTokenStream::getTokens(int start, int stop, int ttype) {
std::vector<int> s;
std::vector<Token *> BufferedTokenStream::getTokens(size_t start, size_t stop, size_t ttype) {
std::vector<size_t> s;
s.push_back(ttype);
return getTokens(start, stop, s);
}
@ -311,7 +311,7 @@ std::vector<Token *> BufferedTokenStream::getHiddenTokensToRight(size_t tokenInd
}
ssize_t nextOnChannel = nextTokenOnChannel(tokenIndex + 1, Lexer::DEFAULT_TOKEN_CHANNEL);
ssize_t to;
size_t to;
size_t from = tokenIndex + 1;
// if none onchannel to right, nextOnChannel=-1 so set to = last token
if (nextOnChannel == -1) {
@ -320,7 +320,7 @@ std::vector<Token *> BufferedTokenStream::getHiddenTokensToRight(size_t tokenInd
to = nextOnChannel;
}
return filterForChannel(from, (size_t)to, channel);
return filterForChannel(from, to, channel);
}
std::vector<Token *> BufferedTokenStream::getHiddenTokensToRight(size_t tokenIndex) {
@ -386,22 +386,22 @@ std::string BufferedTokenStream::getSourceName() const
std::string BufferedTokenStream::getText() {
lazyInit();
fill();
return getText(misc::Interval(0, (int)size() - 1));
return getText(misc::Interval(0, size() - 1));
}
std::string BufferedTokenStream::getText(const misc::Interval &interval) {
int start = interval.a;
int stop = interval.b;
if (start < 0 || stop < 0) {
size_t start = interval.a;
size_t stop = interval.b;
if (start == INVALID_INDEX || stop == INVALID_INDEX) {
return "";
}
lazyInit();
if (stop >= (int)_tokens.size()) {
stop = (int)_tokens.size() - 1;
if (stop >= _tokens.size()) {
stop = _tokens.size() - 1;
}
std::stringstream ss;
for (size_t i = (size_t)start; i <= (size_t)stop; i++) {
for (size_t i = start; i <= stop; i++) {
Token *t = _tokens[i].get();
if (t->getType() == Token::EOF) {
break;

View File

@ -70,21 +70,21 @@ namespace antlr4 {
/// Get all tokens from start..stop inclusively.
virtual std::vector<Token *> get(size_t start, size_t stop);
virtual ssize_t LA(ssize_t i) override;
virtual size_t LA(ssize_t i) override;
virtual Token* LT(ssize_t k) override;
/// Reset this token stream by setting its token source.
virtual void setTokenSource(TokenSource *tokenSource);
virtual std::vector<Token *> getTokens();
virtual std::vector<Token *> getTokens(int start, int stop);
virtual std::vector<Token *> getTokens(size_t start, size_t stop);
/// <summary>
/// Given a start and stop index, return a List of all tokens in
/// the token type BitSet. Return null if no tokens were found. This
/// method looks at both on and off channel tokens.
/// </summary>
virtual std::vector<Token *> getTokens(int start, int stop, const std::vector<int> &types);
virtual std::vector<Token *> getTokens(int start, int stop, int ttype);
virtual std::vector<Token *> getTokens(size_t start, size_t stop, const std::vector<size_t> &types);
virtual std::vector<Token *> getTokens(size_t start, size_t stop, size_t ttype);
/// Collect all tokens on specified channel to the right of
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL or

View File

@ -38,16 +38,18 @@
#include "CommonToken.h"
using namespace antlr4;
using namespace antlr4::misc;
using namespace antlrcpp;
const std::pair<TokenSource*, CharStream*> CommonToken::EMPTY_SOURCE;
CommonToken::CommonToken(int type) {
CommonToken::CommonToken(size_t type) {
InitializeInstanceFields();
_type = type;
}
CommonToken::CommonToken(std::pair<TokenSource*, CharStream*> source, int type, int channel, int start, int stop) {
CommonToken::CommonToken(std::pair<TokenSource*, CharStream*> source, size_t type, size_t channel, size_t start, size_t stop) {
InitializeInstanceFields();
_source = source;
_type = type;
@ -60,7 +62,7 @@ CommonToken::CommonToken(std::pair<TokenSource*, CharStream*> source, int type,
}
}
CommonToken::CommonToken(int type, const std::string &text) {
CommonToken::CommonToken(size_t type, const std::string &text) {
InitializeInstanceFields();
_type = type;
_channel = DEFAULT_CHANNEL;
@ -87,11 +89,11 @@ CommonToken::CommonToken(Token *oldToken) {
}
}
int CommonToken::getType() const {
size_t CommonToken::getType() const {
return _type;
}
void CommonToken::setLine(int line) {
void CommonToken::setLine(size_t line) {
_line = line;
}
@ -105,7 +107,7 @@ std::string CommonToken::getText() const {
return "";
}
size_t n = input->size();
if ((size_t)_start < n && (size_t)_stop < n) {
if (_start < n && _stop < n) {
return input->getText(misc::Interval(_start, _stop));
} else {
return "<EOF>";
@ -116,15 +118,15 @@ void CommonToken::setText(const std::string &text) {
_text = text;
}
int CommonToken::getLine() const {
size_t CommonToken::getLine() const {
return _line;
}
int CommonToken::getCharPositionInLine() const {
size_t CommonToken::getCharPositionInLine() const {
return _charPositionInLine;
}
void CommonToken::setCharPositionInLine(int charPositionInLine) {
void CommonToken::setCharPositionInLine(size_t charPositionInLine) {
_charPositionInLine = charPositionInLine;
}
@ -132,35 +134,35 @@ size_t CommonToken::getChannel() const {
return _channel;
}
void CommonToken::setChannel(int channel) {
void CommonToken::setChannel(size_t channel) {
_channel = channel;
}
void CommonToken::setType(int type) {
void CommonToken::setType(size_t type) {
_type = type;
}
int CommonToken::getStartIndex() const {
size_t CommonToken::getStartIndex() const {
return _start;
}
void CommonToken::setStartIndex(int start) {
void CommonToken::setStartIndex(size_t start) {
_start = start;
}
int CommonToken::getStopIndex() const {
size_t CommonToken::getStopIndex() const {
return _stop;
}
void CommonToken::setStopIndex(int stop) {
void CommonToken::setStopIndex(size_t stop) {
_stop = stop;
}
int CommonToken::getTokenIndex() const {
size_t CommonToken::getTokenIndex() const {
return _index;
}
void CommonToken::setTokenIndex(int index) {
void CommonToken::setTokenIndex(size_t index) {
_index = index;
}
@ -188,8 +190,9 @@ std::string CommonToken::toString() const {
txt = "<no text>";
}
ss << "[@" << getTokenIndex() << "," << _start << ":" << _stop << "='" << txt << "',<" << _type << ">" << channelStr
<< "," << _line << ":" << getCharPositionInLine() << "]";
ss << "[@" << symbolToNumeric(getTokenIndex()) << "," << symbolToNumeric(_start) << ":" << symbolToNumeric(_stop)
<< "='" << txt << "',<" << symbolToNumeric(_type) << ">" << channelStr << "," << _line << ":"
<< getCharPositionInLine() << "]";
return ss.str();
}
@ -197,9 +200,9 @@ std::string CommonToken::toString() const {
void CommonToken::InitializeInstanceFields() {
_type = 0;
_line = 0;
_charPositionInLine = -1;
_charPositionInLine = INVALID_INDEX;
_channel = DEFAULT_CHANNEL;
_index = -1;
_index = INVALID_INDEX;
_start = 0;
_stop = 0;
_source = EMPTY_SOURCE;

View File

@ -46,18 +46,18 @@ namespace antlr4 {
/**
* This is the backing field for {@link #getType} and {@link #setType}.
*/
int _type;
size_t _type;
/**
* This is the backing field for {@link #getLine} and {@link #setLine}.
*/
int _line;
size_t _line;
/**
* This is the backing field for {@link #getCharPositionInLine} and
* {@link #setCharPositionInLine}.
*/
int _charPositionInLine; // set to invalid position
size_t _charPositionInLine; // set to invalid position
/**
* This is the backing field for {@link #getChannel} and
@ -90,19 +90,19 @@ namespace antlr4 {
* This is the backing field for {@link #getTokenIndex} and
* {@link #setTokenIndex}.
*/
int _index;
size_t _index;
/**
* This is the backing field for {@link #getStartIndex} and
* {@link #setStartIndex}.
*/
int _start;
size_t _start;
/**
* This is the backing field for {@link #getStopIndex} and
* {@link #setStopIndex}.
*/
int _stop;
size_t _stop;
public:
/**
@ -110,8 +110,8 @@ namespace antlr4 {
*
* @param type The token type.
*/
CommonToken(int type);
CommonToken(std::pair<TokenSource*, CharStream*> source, int type, int channel, int start, int stop);
CommonToken(size_t type);
CommonToken(std::pair<TokenSource*, CharStream*> source, size_t type, size_t channel, size_t start, size_t stop);
/**
* Constructs a new {@link CommonToken} with the specified token type and
@ -120,7 +120,7 @@ namespace antlr4 {
* @param type The token type.
* @param text The text of the token.
*/
CommonToken(int type, const std::string &text);
CommonToken(size_t type, const std::string &text);
/**
* Constructs a new {@link CommonToken} as a copy of another {@link Token}.
@ -137,7 +137,7 @@ namespace antlr4 {
*/
CommonToken(Token *oldToken);
virtual int getType() const override;
virtual size_t getType() const override;
/**
* Explicitly set the text for this token. If {code text} is not
@ -151,25 +151,25 @@ namespace antlr4 {
virtual void setText(const std::string &text) override;
virtual std::string getText() const override;
virtual void setLine(int line) override;
virtual int getLine() const override;
virtual void setLine(size_t line) override;
virtual size_t getLine() const override;
virtual int getCharPositionInLine() const override;
virtual void setCharPositionInLine(int charPositionInLine) override;
virtual size_t getCharPositionInLine() const override;
virtual void setCharPositionInLine(size_t charPositionInLine) override;
virtual size_t getChannel() const override;
virtual void setChannel(int channel) override;
virtual void setChannel(size_t channel) override;
virtual void setType(int type) override;
virtual void setType(size_t type) override;
virtual int getStartIndex() const override;
virtual void setStartIndex(int start);
virtual size_t getStartIndex() const override;
virtual void setStartIndex(size_t start);
virtual int getStopIndex() const override;
virtual void setStopIndex(int stop);
virtual size_t getStopIndex() const override;
virtual void setStopIndex(size_t stop);
virtual int getTokenIndex() const override;
virtual void setTokenIndex(int index) override;
virtual size_t getTokenIndex() const override;
virtual void setTokenIndex(size_t index) override;
virtual TokenSource *getTokenSource() const override;
virtual CharStream *getInputStream() const override;

View File

@ -45,8 +45,8 @@ CommonTokenFactory::CommonTokenFactory(bool copyText) : copyText(copyText) {
CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) {
}
std::unique_ptr<CommonToken> CommonTokenFactory::create(std::pair<TokenSource*, CharStream*> source, int type,
const std::string &text, int channel, int start, int stop, int line, int charPositionInLine) {
std::unique_ptr<CommonToken> CommonTokenFactory::create(std::pair<TokenSource*, CharStream*> source, size_t type,
const std::string &text, size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) {
std::unique_ptr<CommonToken> t(new CommonToken(source, type, channel, start, stop));
t->setLine(line);
@ -60,6 +60,6 @@ std::unique_ptr<CommonToken> CommonTokenFactory::create(std::pair<TokenSource*,
return t;
}
std::unique_ptr<CommonToken> CommonTokenFactory::create(int type, const std::string &text) {
std::unique_ptr<CommonToken> CommonTokenFactory::create(size_t type, const std::string &text) {
return std::unique_ptr<CommonToken>(new CommonToken(type, text));
}

View File

@ -91,10 +91,10 @@ namespace antlr4 {
*/
CommonTokenFactory();
virtual std::unique_ptr<CommonToken> create(std::pair<TokenSource*, CharStream*> source, int type,
const std::string &text, int channel, int start, int stop, int line, int charPositionInLine) override;
virtual std::unique_ptr<CommonToken> create(std::pair<TokenSource*, CharStream*> source, size_t type,
const std::string &text, size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) override;
virtual std::unique_ptr<CommonToken> create(int type, const std::string &text) override;
virtual std::unique_ptr<CommonToken> create(size_t type, const std::string &text) override;
};
} // namespace antlr4

View File

@ -36,6 +36,6 @@ using namespace antlr4;
ConsoleErrorListener ConsoleErrorListener::INSTANCE;
void ConsoleErrorListener::syntaxError(IRecognizer * /*recognizer*/, Token * /*offendingSymbol*/,
size_t line, int charPositionInLine, const std::string &msg, std::exception_ptr /*e*/) {
size_t line, size_t charPositionInLine, const std::string &msg, std::exception_ptr /*e*/) {
std::cerr << "line " << line << ":" << charPositionInLine << " " << msg << std::endl;
}

View File

@ -54,7 +54,7 @@ namespace antlr4 {
* line <em>line</em>:<em>charPositionInLine</em> <em>msg</em>
* </pre>
*/
virtual void syntaxError(IRecognizer *recognizer, Token * offendingSymbol, size_t line, int charPositionInLine,
virtual void syntaxError(IRecognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine,
const std::string &msg, std::exception_ptr e) override;
};

View File

@ -46,6 +46,8 @@
#include "DefaultErrorStrategy.h"
using namespace antlr4;
using namespace antlr4::atn;
using namespace antlrcpp;
DefaultErrorStrategy::DefaultErrorStrategy() {
@ -113,7 +115,7 @@ void DefaultErrorStrategy::recover(Parser *recognizer, std::exception_ptr /*e*/)
}
void DefaultErrorStrategy::sync(Parser *recognizer) {
atn::ATNState *s = recognizer->getInterpreter<atn::ATNSimulator>()->atn.states[(size_t)recognizer->getState()];
atn::ATNState *s = recognizer->getInterpreter<atn::ATNSimulator>()->atn.states[recognizer->getState()];
// If already recovering, don't try to sync
if (inErrorRecoveryMode(recognizer)) {
@ -121,10 +123,10 @@ void DefaultErrorStrategy::sync(Parser *recognizer) {
}
TokenStream *tokens = recognizer->getTokenStream();
ssize_t la = tokens->LA(1);
size_t la = tokens->LA(1);
// try cheaper subset first; might get lucky. seems to shave a wee bit off
if (recognizer->getATN().nextTokens(s).contains((int)la) || la == Token::EOF) {
if (recognizer->getATN().nextTokens(s).contains(la) || la == Token::EOF) {
return;
}
@ -183,7 +185,7 @@ void DefaultErrorStrategy::reportInputMismatch(Parser *recognizer, const InputMi
}
void DefaultErrorStrategy::reportFailedPredicate(Parser *recognizer, const FailedPredicateException &e) {
const std::string& ruleName = recognizer->getRuleNames()[(size_t)recognizer->getContext()->getRuleIndex()];
const std::string& ruleName = recognizer->getRuleNames()[recognizer->getContext()->getRuleIndex()];
std::string msg = "rule " + ruleName + " " + e.what();
recognizer->notifyErrorListeners(e.getOffendingToken(), msg, std::make_exception_ptr(e));
}
@ -243,11 +245,11 @@ bool DefaultErrorStrategy::singleTokenInsertion(Parser *recognizer) {
// if current token is consistent with what could come after current
// ATN state, then we know we're missing a token; error recovery
// is free to conjure up and insert the missing token
atn::ATNState *currentState = recognizer->getInterpreter<atn::ATNSimulator>()->atn.states[(size_t)recognizer->getState()];
atn::ATNState *currentState = recognizer->getInterpreter<atn::ATNSimulator>()->atn.states[recognizer->getState()];
atn::ATNState *next = currentState->transition(0)->target;
const atn::ATN &atn = recognizer->getInterpreter<atn::ATNSimulator>()->atn;
misc::IntervalSet expectingAtLL2 = atn.nextTokens(next, recognizer->getContext());
if (expectingAtLL2.contains((int)currentSymbolType)) {
if (expectingAtLL2.contains(currentSymbolType)) {
reportMissingToken(recognizer);
return true;
}
@ -255,9 +257,9 @@ bool DefaultErrorStrategy::singleTokenInsertion(Parser *recognizer) {
}
Token* DefaultErrorStrategy::singleTokenDeletion(Parser *recognizer) {
ssize_t nextTokenType = recognizer->getInputStream()->LA(2);
size_t nextTokenType = recognizer->getInputStream()->LA(2);
misc::IntervalSet expecting = getExpectedTokens(recognizer);
if (expecting.contains((int)nextTokenType)) {
if (expecting.contains(nextTokenType)) {
reportUnwantedToken(recognizer);
recognizer->consume(); // simply delete extra token
// we want to return the token we're actually matching
@ -271,7 +273,7 @@ Token* DefaultErrorStrategy::singleTokenDeletion(Parser *recognizer) {
Token* DefaultErrorStrategy::getMissingSymbol(Parser *recognizer) {
Token *currentSymbol = recognizer->getCurrentToken();
misc::IntervalSet expecting = getExpectedTokens(recognizer);
ssize_t expectedTokenType = expecting.getMinElement(); // get any element
size_t expectedTokenType = expecting.getMinElement(); // get any element
std::string tokenText;
if (expectedTokenType == Token::EOF) {
tokenText = "<missing EOF>";
@ -315,7 +317,7 @@ std::string DefaultErrorStrategy::getSymbolText(Token *symbol) {
return symbol->getText();
}
int DefaultErrorStrategy::getSymbolType(Token *symbol) {
size_t DefaultErrorStrategy::getSymbolType(Token *symbol) {
return symbol->getType();
}
@ -331,9 +333,9 @@ misc::IntervalSet DefaultErrorStrategy::getErrorRecoverySet(Parser *recognizer)
const atn::ATN &atn = recognizer->getInterpreter<atn::ATNSimulator>()->atn;
RuleContext *ctx = recognizer->getContext().get();
misc::IntervalSet recoverSet;
while (ctx->invokingState >= 0) {
while (ctx->invokingState != ATNState::INVALID_STATE_NUMBER) {
// compute what follows who invoked us
atn::ATNState *invokingState = atn.states[(size_t)ctx->invokingState];
atn::ATNState *invokingState = atn.states[ctx->invokingState];
atn::RuleTransition *rt = dynamic_cast<atn::RuleTransition*>(invokingState->transition(0));
misc::IntervalSet follow = atn.nextTokens(rt->followState);
recoverSet.addAll(follow);
@ -348,8 +350,8 @@ misc::IntervalSet DefaultErrorStrategy::getErrorRecoverySet(Parser *recognizer)
}
void DefaultErrorStrategy::consumeUntil(Parser *recognizer, const misc::IntervalSet &set) {
ssize_t ttype = recognizer->getInputStream()->LA(1);
while (ttype != Token::EOF && !set.contains((int)ttype)) {
size_t ttype = recognizer->getInputStream()->LA(1);
while (ttype != Token::EOF && !set.contains(ttype)) {
recognizer->consume();
ttype = recognizer->getInputStream()->LA(1);
}

View File

@ -382,7 +382,7 @@ namespace antlr4 {
virtual std::string getSymbolText(Token *symbol);
virtual int getSymbolType(Token *symbol);
virtual size_t getSymbolType(Token *symbol);
virtual std::string escapeWSAndQuote(const std::string &s) const;

View File

@ -54,7 +54,7 @@ void DiagnosticErrorListener::reportAmbiguity(Parser *recognizer, const dfa::DFA
std::string decision = getDecisionDescription(recognizer, dfa);
antlrcpp::BitSet conflictingAlts = getConflictingAlts(ambigAlts, configs);
std::string text = recognizer->getTokenStream()->getText(misc::Interval((int)startIndex, (int)stopIndex));
std::string text = recognizer->getTokenStream()->getText(misc::Interval(startIndex, stopIndex));
std::string message = "reportAmbiguity d=" + decision + ": ambigAlts=" + conflictingAlts.toString() +
", input='" + text + "'";
@ -64,29 +64,29 @@ void DiagnosticErrorListener::reportAmbiguity(Parser *recognizer, const dfa::DFA
void DiagnosticErrorListener::reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex,
size_t stopIndex, const antlrcpp::BitSet &/*conflictingAlts*/, atn::ATNConfigSet * /*configs*/) {
std::string decision = getDecisionDescription(recognizer, dfa);
std::string text = recognizer->getTokenStream()->getText(misc::Interval((int)startIndex, (int)stopIndex));
std::string text = recognizer->getTokenStream()->getText(misc::Interval(startIndex, stopIndex));
std::string message = "reportAttemptingFullContext d=" + decision + ", input='" + text + "'";
recognizer->notifyErrorListeners(message);
}
void DiagnosticErrorListener::reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex,
size_t stopIndex, int /*prediction*/, atn::ATNConfigSet * /*configs*/) {
size_t stopIndex, size_t /*prediction*/, atn::ATNConfigSet * /*configs*/) {
std::string decision = getDecisionDescription(recognizer, dfa);
std::string text = recognizer->getTokenStream()->getText(misc::Interval((int)startIndex, (int)stopIndex));
std::string text = recognizer->getTokenStream()->getText(misc::Interval(startIndex, stopIndex));
std::string message = "reportContextSensitivity d=" + decision + ", input='" + text + "'";
recognizer->notifyErrorListeners(message);
}
std::string DiagnosticErrorListener::getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa) {
int decision = dfa.decision;
int ruleIndex = ((atn::ATNState*)dfa.atnStartState)->ruleIndex;
size_t decision = dfa.decision;
size_t ruleIndex = ((atn::ATNState*)dfa.atnStartState)->ruleIndex;
const std::vector<std::string>& ruleNames = recognizer->getRuleNames();
if (ruleIndex < 0 || ruleIndex >= (int)ruleNames.size()) {
if (ruleIndex == INVALID_INDEX || ruleIndex >= ruleNames.size()) {
return std::to_string(decision);
}
std::string ruleName = ruleNames[(size_t)ruleIndex];
std::string ruleName = ruleNames[ruleIndex];
if (ruleName == "" || ruleName.empty()) {
return std::to_string(decision);
}
@ -103,7 +103,7 @@ antlrcpp::BitSet DiagnosticErrorListener::getConflictingAlts(const antlrcpp::Bit
antlrcpp::BitSet result;
for (auto &config : configs->configs) {
result.set((size_t)config->alt);
result.set(config->alt);
}
return result;

View File

@ -85,7 +85,7 @@ namespace antlr4 {
const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override;
virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
int prediction, atn::ATNConfigSet *configs) override;
size_t prediction, atn::ATNConfigSet *configs) override;
protected:
virtual std::string getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa);

View File

@ -51,7 +51,7 @@ FailedPredicateException::FailedPredicateException(Parser *recognizer, const std
: RecognitionException(!message.empty() ? message : "failed predicate: " + predicate + "?", recognizer,
recognizer->getInputStream(), recognizer->getContext(), recognizer->getCurrentToken()) {
atn::ATNState *s = recognizer->getInterpreter<atn::ATNSimulator>()->atn.states[(size_t)recognizer->getState()];
atn::ATNState *s = recognizer->getInterpreter<atn::ATNSimulator>()->atn.states[recognizer->getState()];
atn::Transition *transition = s->transition(0);
if (is<atn::PredicateTransition*>(transition)) {
_ruleIndex = ((atn::PredicateTransition *)transition)->ruleIndex;
@ -65,11 +65,11 @@ FailedPredicateException::FailedPredicateException(Parser *recognizer, const std
_predicate = predicate;
}
int FailedPredicateException::getRuleIndex() {
size_t FailedPredicateException::getRuleIndex() {
return _ruleIndex;
}
int FailedPredicateException::getPredIndex() {
size_t FailedPredicateException::getPredIndex() {
return _predicateIndex;
}

View File

@ -45,13 +45,13 @@ namespace antlr4 {
FailedPredicateException(Parser *recognizer, const std::string &predicate);
FailedPredicateException(Parser *recognizer, const std::string &predicate, const std::string &message);
virtual int getRuleIndex();
virtual int getPredIndex();
virtual size_t getRuleIndex();
virtual size_t getPredIndex();
virtual std::string getPredicate();
private:
int _ruleIndex;
int _predicateIndex;
size_t _ruleIndex;
size_t _predicateIndex;
std::string _predicate;
};

View File

@ -37,7 +37,7 @@ namespace antlr4 {
public:
virtual ~IRecognizer() {};
virtual int getState() = 0;
virtual size_t getState() const = 0;
// Get the ATN used by the recognizer for prediction.
virtual const atn::ATN& getATN() const = 0;

View File

@ -53,7 +53,7 @@ namespace antlr4 {
/// </summary>
class ANTLR4CPP_PUBLIC IntStream {
public:
static const ssize_t EOF = -1;
static const size_t EOF = (size_t)-1;
/// The value returned by <seealso cref="#LA LA()"/> when the end of the stream is
/// reached.
@ -124,7 +124,7 @@ namespace antlr4 {
/// </summary>
/// <exception cref="UnsupportedOperationException"> if the stream does not support
/// retrieving the value of the specified symbol </exception>
virtual ssize_t LA(ssize_t i) = 0;
virtual size_t LA(ssize_t i) = 0;
/// <summary>
/// A mark provides a guarantee that <seealso cref="#seek seek()"/> operations will be

View File

@ -36,10 +36,11 @@ using namespace antlr4;
InterpreterRuleContext::InterpreterRuleContext() {
}
InterpreterRuleContext::InterpreterRuleContext(std::weak_ptr<ParserRuleContext> parent, int invokingStateNumber, ssize_t ruleIndex)
InterpreterRuleContext::InterpreterRuleContext(std::weak_ptr<ParserRuleContext> parent, size_t invokingStateNumber,
size_t ruleIndex)
: ParserRuleContext(parent, invokingStateNumber), _ruleIndex(ruleIndex) {
}
ssize_t InterpreterRuleContext::getRuleIndex() const {
size_t InterpreterRuleContext::getRuleIndex() const {
return _ruleIndex;
}

View File

@ -59,13 +59,13 @@ namespace antlr4 {
* @param invokingStateNumber The invoking state number.
* @param ruleIndex The rule index for the current context.
*/
InterpreterRuleContext(std::weak_ptr<ParserRuleContext> parent, int invokingStateNumber, ssize_t ruleIndex);
InterpreterRuleContext(std::weak_ptr<ParserRuleContext> parent, size_t invokingStateNumber, size_t ruleIndex);
virtual ssize_t getRuleIndex() const override;
virtual size_t getRuleIndex() const override;
protected:
/** This is the backing field for {@link #getRuleIndex}. */
const ssize_t _ruleIndex = -1;
const size_t _ruleIndex = INVALID_INDEX;
};
} // namespace antlr4

View File

@ -96,13 +96,13 @@ std::unique_ptr<Token> Lexer::nextToken() {
token.reset();
channel = Token::DEFAULT_CHANNEL;
tokenStartCharIndex = (int)_input->index();
tokenStartCharIndex = _input->index();
tokenStartCharPositionInLine = getInterpreter<atn::LexerATNSimulator>()->getCharPositionInLine();
tokenStartLine = (int)getInterpreter<atn::LexerATNSimulator>()->getLine();
tokenStartLine = getInterpreter<atn::LexerATNSimulator>()->getLine();
_text = "";
do {
type = Token::INVALID_TYPE;
int ttype;
size_t ttype;
try {
ttype = getInterpreter<atn::LexerATNSimulator>()->match(_input, mode);
} catch (LexerNoViableAltException &e) {
@ -184,16 +184,15 @@ void Lexer::emit(std::unique_ptr<Token> newToken) {
}
Token* Lexer::emit() {
emit(_factory->create({ this, _input }, (int)type, _text, channel,
tokenStartCharIndex, getCharIndex() - 1, (int)tokenStartLine, tokenStartCharPositionInLine));
emit(_factory->create({ this, _input }, type, _text, channel,
tokenStartCharIndex, getCharIndex() - 1, tokenStartLine, tokenStartCharPositionInLine));
return token.get();
}
Token* Lexer::emitEOF() {
int cpos = getCharPositionInLine();
size_t cpos = getCharPositionInLine();
size_t line = getLine();
emit(_factory->create({ this, _input }, EOF, "", Token::DEFAULT_CHANNEL, (int)_input->index(),
(int)_input->index() - 1, (int)line, cpos));
emit(_factory->create({ this, _input }, EOF, "", Token::DEFAULT_CHANNEL, _input->index(), _input->index() - 1, line, cpos));
return token.get();
}
@ -201,7 +200,7 @@ size_t Lexer::getLine() const {
return getInterpreter<atn::LexerATNSimulator>()->getLine();
}
int Lexer::getCharPositionInLine() {
size_t Lexer::getCharPositionInLine() {
return getInterpreter<atn::LexerATNSimulator>()->getCharPositionInLine();
}
@ -209,12 +208,12 @@ void Lexer::setLine(size_t line) {
getInterpreter<atn::LexerATNSimulator>()->setLine(line);
}
void Lexer::setCharPositionInLine(int charPositionInLine) {
void Lexer::setCharPositionInLine(size_t charPositionInLine) {
getInterpreter<atn::LexerATNSimulator>()->setCharPositionInLine(charPositionInLine);
}
int Lexer::getCharIndex() {
return (int)_input->index();
size_t Lexer::getCharIndex() {
return _input->index();
}
std::string Lexer::getText() {
@ -236,19 +235,19 @@ void Lexer::setToken(std::unique_ptr<Token> newToken) {
token = std::move(newToken);
}
void Lexer::setType(ssize_t ttype) {
void Lexer::setType(size_t ttype) {
type = ttype;
}
ssize_t Lexer::getType() {
size_t Lexer::getType() {
return type;
}
void Lexer::setChannel(int newChannel) {
void Lexer::setChannel(size_t newChannel) {
channel = newChannel;
}
int Lexer::getChannel() {
size_t Lexer::getChannel() {
return channel;
}
@ -271,7 +270,7 @@ void Lexer::recover(const LexerNoViableAltException &/*e*/) {
void Lexer::notifyListeners(const LexerNoViableAltException & /*e*/) {
++_syntaxErrors;
std::string text = _input->getText(misc::Interval(tokenStartCharIndex, (int)_input->index()));
std::string text = _input->getText(misc::Interval(tokenStartCharIndex, _input->index()));
std::string msg = std::string("token recognition error at: '") + getErrorDisplay(text) + std::string("'");
ProxyErrorListener &listener = getErrorListenerDispatch();

View File

@ -44,12 +44,12 @@ namespace antlr4 {
/// of speed.
class ANTLR4CPP_PUBLIC Lexer : public Recognizer, public TokenSource {
public:
static const int DEFAULT_MODE = 0;
static const int MORE = -2;
static const int SKIP = -3;
static const size_t DEFAULT_MODE = 0;
static const size_t MORE = (size_t)-2;
static const size_t SKIP = (size_t)-3;
static const size_t DEFAULT_TOKEN_CHANNEL = Token::DEFAULT_CHANNEL;
static const int HIDDEN = Token::HIDDEN_CHANNEL;
static const size_t HIDDEN = Token::HIDDEN_CHANNEL;
static const size_t MIN_CHAR_VALUE = 0;
static const size_t MAX_CHAR_VALUE = 0x10FFFF;
@ -78,29 +78,24 @@ namespace antlr4 {
/// Needed, for example, to get the text for current token. Set at
/// the start of nextToken.
/// </summary>
int tokenStartCharIndex;
size_t tokenStartCharIndex;
/// <summary>
/// The line on which the first character of the token resides </summary>
size_t tokenStartLine;
/// <summary>
/// The character position of first character within the line </summary>
int tokenStartCharPositionInLine;
/// The character position of first character within the line.
size_t tokenStartCharPositionInLine;
/// <summary>
/// Once we see EOF on char stream, next token will be EOF.
/// If you have DONE : EOF ; then you see DONE EOF.
/// </summary>
bool hitEOF;
/// <summary>
/// The channel number for the current token </summary>
int channel;
/// The channel number for the current token.
size_t channel;
/// <summary>
/// The token type for the current token </summary>
ssize_t type;
/// The token type for the current token.
size_t type;
// Use the vector as a stack.
std::vector<size_t> modeStack;
@ -156,14 +151,14 @@ namespace antlr4 {
virtual size_t getLine() const override;
virtual int getCharPositionInLine() override;
virtual size_t getCharPositionInLine() override;
virtual void setLine(size_t line);
virtual void setCharPositionInLine(int charPositionInLine);
virtual void setCharPositionInLine(size_t charPositionInLine);
/// What is the index of the current character of lookahead?
virtual int getCharIndex();
virtual size_t getCharIndex();
/// Return the text matched so far for the current token or any
/// text override.
@ -178,13 +173,13 @@ namespace antlr4 {
virtual void setToken(std::unique_ptr<Token> newToken);
virtual void setType(ssize_t ttype);
virtual void setType(size_t ttype);
virtual ssize_t getType();
virtual size_t getType();
virtual void setChannel(int newChannel);
virtual void setChannel(size_t newChannel);
virtual int getChannel();
virtual size_t getChannel();
virtual const std::vector<std::string>& getModeNames() const = 0;

View File

@ -60,8 +60,8 @@ LexerInterpreter::LexerInterpreter(const std::string &grammarFileName, const dfa
_tokenNames.push_back(vocabulary.getDisplayName(i));
}
for (size_t i = 0; i < (size_t)atn.getNumberOfDecisions(); ++i) {
_decisionToDFA.push_back(dfa::DFA(_atn.getDecisionState((int)i), (int)i));
for (size_t i = 0; i < atn.getNumberOfDecisions(); ++i) {
_decisionToDFA.push_back(dfa::DFA(_atn.getDecisionState(i), i));
}
_interpreter = new atn::LexerATNSimulator(_atn, _decisionToDFA, _sharedContextCache); /* mem-check: deleted in d-tor */
}

View File

@ -54,7 +54,7 @@ atn::ATNConfigSet* LexerNoViableAltException::getDeadEndConfigs() {
std::string LexerNoViableAltException::toString() {
std::string symbol;
if (_startIndex < getInputStream()->size()) {
symbol = ((CharStream *)getInputStream())->getText(misc::Interval((int)_startIndex, (int)_startIndex));
symbol = ((CharStream *)getInputStream())->getText(misc::Interval(_startIndex, _startIndex));
symbol = antlrcpp::escapeWhitespace(symbol, false);
}
std::string format = "LexerNoViableAltException('" + symbol + "')";

View File

@ -50,19 +50,19 @@ ListTokenSource::ListTokenSource(std::vector<std::unique_ptr<Token>> tokens_, co
// Check if there is an eof token and create one if not.
if (tokens.back()->getType() != Token::EOF) {
Token *lastToken = tokens.back().get();
int start = -1;
int previousStop = lastToken->getStopIndex();
if (previousStop != -1) {
size_t start = INVALID_INDEX;
size_t previousStop = lastToken->getStopIndex();
if (previousStop != INVALID_INDEX) {
start = previousStop + 1;
}
int stop = std::max(-1, start - 1);
size_t stop = std::max(INVALID_INDEX, start - 1);
tokens.emplace_back((_factory->create({ this, getInputStream() }, Token::EOF, "EOF",
Token::DEFAULT_CHANNEL, start, stop, (int)lastToken->getLine(), lastToken->getCharPositionInLine())));
}
}
int ListTokenSource::getCharPositionInLine() {
size_t ListTokenSource::getCharPositionInLine() {
if (i < tokens.size()) {
return tokens[i]->getCharPositionInLine();
}
@ -78,7 +78,7 @@ std::unique_ptr<Token> ListTokenSource::nextToken() {
size_t ListTokenSource::getLine() const {
if (i < tokens.size()) {
return (size_t)tokens[i]->getLine();
return tokens[i]->getLine();
}
return 1;

View File

@ -94,7 +94,7 @@ namespace antlr4 {
/// <exception cref="NullPointerException"> if {@code tokens} is {@code null} </exception>
ListTokenSource(std::vector<std::unique_ptr<Token>> tokens_, const std::string &sourceName_);
virtual int getCharPositionInLine() override;
virtual size_t getCharPositionInLine() override;
virtual std::unique_ptr<Token> nextToken() override;
virtual size_t getLine() const override;
virtual CharStream* getInputStream() override;

View File

@ -52,6 +52,8 @@
#include "Parser.h"
using namespace antlr4;
using namespace antlr4::atn;
using namespace antlrcpp;
std::map<std::vector<uint16_t>, atn::ATN> Parser::bypassAltsAtnCache;
@ -60,20 +62,20 @@ Parser::TraceListener::TraceListener(Parser *outerInstance) : outerInstance(oute
}
void Parser::TraceListener::enterEveryRule(ParserRuleContext *ctx) {
std::cout << "enter " << outerInstance->getRuleNames()[(size_t)ctx->getRuleIndex()]
std::cout << "enter " << outerInstance->getRuleNames()[ctx->getRuleIndex()]
<< ", LT(1)=" << outerInstance->_input->LT(1)->getText() << std::endl;
}
void Parser::TraceListener::visitTerminal(tree::TerminalNode *node) {
std::cout << "consume " << node->getSymbol() << " rule "
<< outerInstance->getRuleNames()[(size_t)outerInstance->getContext()->getRuleIndex()] << std::endl;
<< outerInstance->getRuleNames()[outerInstance->getContext()->getRuleIndex()] << std::endl;
}
void Parser::TraceListener::visitErrorNode(tree::ErrorNode * /*node*/) {
}
void Parser::TraceListener::exitEveryRule(ParserRuleContext *ctx) {
std::cout << "exit " << outerInstance->getRuleNames()[(size_t)ctx->getRuleIndex()]
std::cout << "exit " << outerInstance->getRuleNames()[ctx->getRuleIndex()]
<< ", LT(1)=" << outerInstance->_input->LT(1)->getText() << std::endl;
}
@ -118,7 +120,7 @@ void Parser::reset() {
}
}
Token* Parser::match(int ttype) {
Token* Parser::match(size_t ttype) {
Token *t = getCurrentToken();
if (t->getType() == ttype) {
if (ttype == EOF) {
@ -128,7 +130,7 @@ Token* Parser::match(int ttype) {
consume();
} else {
t = _errHandler->recoverInline(this);
if (_buildParseTrees && t->getTokenIndex() == -1) {
if (_buildParseTrees && t->getTokenIndex() == INVALID_INDEX) {
// we must have conjured up a new token during single token insertion
// if it's not the current symbol
_ctx->addErrorNode(t);
@ -144,7 +146,7 @@ Token* Parser::matchWildcard() {
consume();
} else {
t = _errHandler->recoverInline(this);
if (_buildParseTrees && t->getTokenIndex() == -1) {
if (_buildParseTrees && t->getTokenIndex() == INVALID_INDEX) {
// we must have conjured up a new token during single token insertion
// if it's not the current symbol
_ctx->addErrorNode(t);
@ -301,13 +303,11 @@ void Parser::notifyErrorListeners(const std::string &msg) {
void Parser::notifyErrorListeners(Token *offendingToken, const std::string &msg, std::exception_ptr e) {
_syntaxErrors++;
int line = -1;
int charPositionInLine = -1;
line = offendingToken->getLine();
charPositionInLine = offendingToken->getCharPositionInLine();
size_t line = offendingToken->getLine();
size_t charPositionInLine = offendingToken->getCharPositionInLine();
ProxyErrorListener &listener = getErrorListenerDispatch();
listener.syntaxError(this, offendingToken, (size_t)line, charPositionInLine, msg, e);
listener.syntaxError(this, offendingToken, line, charPositionInLine, msg, e);
}
Token* Parser::consume() {
@ -345,7 +345,7 @@ void Parser::addContextToParseTree() {
parent->addChild(_ctx);
}
void Parser::enterRule(Ref<ParserRuleContext> const& localctx, int state, int /*ruleIndex*/) {
void Parser::enterRule(Ref<ParserRuleContext> const& localctx, size_t state, size_t /*ruleIndex*/) {
setState(state);
_ctx = localctx;
_ctx->start = _input->LT(1);
@ -396,21 +396,21 @@ int Parser::getPrecedence() const {
return _precedenceStack.back();
}
void Parser::enterRecursionRule(Ref<ParserRuleContext> const& localctx, int ruleIndex) {
enterRecursionRule(localctx, getATN().ruleToStartState[(size_t)ruleIndex]->stateNumber, ruleIndex, 0);
void Parser::enterRecursionRule(Ref<ParserRuleContext> const& localctx, size_t ruleIndex) {
enterRecursionRule(localctx, getATN().ruleToStartState[ruleIndex]->stateNumber, ruleIndex, 0);
}
void Parser::enterRecursionRule(Ref<ParserRuleContext> const& localctx, int state, int /*ruleIndex*/, int precedence) {
void Parser::enterRecursionRule(Ref<ParserRuleContext> const& localctx, size_t state, size_t /*ruleIndex*/, int precedence) {
setState(state);
_precedenceStack.push_back(precedence);
_ctx = localctx;
_ctx->start = _input->LT(1);
if (_parseListeners.size() > 0) {
if (!_parseListeners.empty()) {
triggerEnterRuleEvent(); // simulates rule entry for left-recursive rules
}
}
void Parser::pushNewRecursionContext(Ref<ParserRuleContext> const& localctx, int state, int /*ruleIndex*/) {
void Parser::pushNewRecursionContext(Ref<ParserRuleContext> const& localctx, size_t state, size_t /*ruleIndex*/) {
Ref<ParserRuleContext> previous = _ctx;
previous->parent = localctx;
previous->invokingState = state;
@ -451,7 +451,7 @@ void Parser::unrollRecursionContexts(Ref<ParserRuleContext> const& parentctx) {
}
}
Ref<ParserRuleContext> Parser::getInvokingContext(int ruleIndex) {
Ref<ParserRuleContext> Parser::getInvokingContext(size_t ruleIndex) {
Ref<ParserRuleContext> p = _ctx;
while (p) {
if (p->getRuleIndex() == ruleIndex) {
@ -481,10 +481,10 @@ bool Parser::inContext(const std::string &/*context*/) {
return false;
}
bool Parser::isExpectedToken(int symbol) {
bool Parser::isExpectedToken(size_t symbol) {
const atn::ATN &atn = getInterpreter<atn::ParserATNSimulator>()->atn;
Ref<ParserRuleContext> ctx = _ctx;
atn::ATNState *s = atn.states[(size_t)getState()];
atn::ATNState *s = atn.states[getState()];
misc::IntervalSet following = atn.nextTokens(s);
if (following.contains(symbol)) {
@ -495,8 +495,8 @@ bool Parser::isExpectedToken(int symbol) {
return false;
}
while (ctx && ctx->invokingState >= 0 && following.contains(Token::EPSILON)) {
atn::ATNState *invokingState = atn.states[(size_t)ctx->invokingState];
while (ctx && ctx->invokingState != ATNState::INVALID_STATE_NUMBER && following.contains(Token::EPSILON)) {
atn::ATNState *invokingState = atn.states[ctx->invokingState];
atn::RuleTransition *rt = static_cast<atn::RuleTransition*>(invokingState->transition(0));
following = atn.nextTokens(rt->followState);
if (following.contains(symbol)) {
@ -523,15 +523,15 @@ misc::IntervalSet Parser::getExpectedTokens() {
misc::IntervalSet Parser::getExpectedTokensWithinCurrentRule() {
const atn::ATN &atn = getInterpreter<atn::ParserATNSimulator>()->atn;
atn::ATNState *s = atn.states[(size_t)getState()];
atn::ATNState *s = atn.states[getState()];
return atn.nextTokens(s);
}
ssize_t Parser::getRuleIndex(const std::string &ruleName) {
size_t Parser::getRuleIndex(const std::string &ruleName) {
const std::map<std::string, size_t> &m = getRuleIndexMap();
auto iterator = m.find(ruleName);
if (iterator == m.end()) {
return -1;
return INVALID_INDEX;
}
return iterator->second;
}
@ -550,11 +550,11 @@ std::vector<std::string> Parser::getRuleInvocationStack(Ref<RuleContext> const&
RuleContext *run = p.get();
while (run != nullptr) {
// compute what follows who invoked us
ssize_t ruleIndex = run->getRuleIndex();
if (ruleIndex < 0) {
size_t ruleIndex = run->getRuleIndex();
if (ruleIndex == INVALID_INDEX ) {
stack.push_back("n/a");
} else {
stack.push_back(ruleNames[(size_t)ruleIndex]);
stack.push_back(ruleNames[ruleIndex]);
}
if (p->parent.expired())
break;

View File

@ -92,7 +92,7 @@ namespace antlr4 {
/// <exception cref="RecognitionException"> if the current input symbol did not match
/// {@code ttype} and the error strategy could not recover from the
/// mismatched symbol </exception>
virtual Token* match(int ttype);
virtual Token* match(size_t ttype);
/// <summary>
/// Match current input symbol as a wildcard. If the symbol type matches
@ -298,7 +298,7 @@ namespace antlr4 {
/// Always called by generated parsers upon entry to a rule. Access field
/// <seealso cref="#_ctx"/> get the current context.
/// </summary>
virtual void enterRule(Ref<ParserRuleContext> const& localctx, int state, int ruleIndex);
virtual void enterRule(Ref<ParserRuleContext> const& localctx, size_t state, size_t ruleIndex);
virtual void exitRule();
@ -314,15 +314,15 @@ namespace antlr4 {
/// @deprecated Use
/// <seealso cref="#enterRecursionRule(ParserRuleContext, int, int, int)"/> instead.
virtual void enterRecursionRule(Ref<ParserRuleContext> const& localctx, int ruleIndex);
virtual void enterRecursionRule(Ref<ParserRuleContext> const& localctx, int state, int ruleIndex, int precedence);
virtual void enterRecursionRule(Ref<ParserRuleContext> const& localctx, size_t ruleIndex);
virtual void enterRecursionRule(Ref<ParserRuleContext> const& localctx, size_t state, size_t ruleIndex, int precedence);
/** Like {@link #enterRule} but for recursive rules.
* Make the current context the child of the incoming localctx.
*/
virtual void pushNewRecursionContext(Ref<ParserRuleContext> const& localctx, int state, int ruleIndex);
virtual void pushNewRecursionContext(Ref<ParserRuleContext> const& localctx, size_t state, size_t ruleIndex);
virtual void unrollRecursionContexts(Ref<ParserRuleContext> const& parentctx);
virtual Ref<ParserRuleContext> getInvokingContext(int ruleIndex);
virtual Ref<ParserRuleContext> getInvokingContext(size_t ruleIndex);
virtual Ref<ParserRuleContext> getContext();
virtual void setContext(Ref<ParserRuleContext> const& ctx);
virtual bool precpred(Ref<RuleContext> const& localctx, int precedence) override;
@ -341,7 +341,7 @@ namespace antlr4 {
/// <param name="symbol"> the symbol type to check </param>
/// <returns> {@code true} if {@code symbol} can follow the current state in
/// the ATN, otherwise {@code false}. </returns>
virtual bool isExpectedToken(int symbol);
virtual bool isExpectedToken(size_t symbol);
bool isMatchedEOF() const;
@ -355,9 +355,8 @@ namespace antlr4 {
virtual misc::IntervalSet getExpectedTokensWithinCurrentRule();
/// <summary>
/// Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found. </summary>
virtual ssize_t getRuleIndex(const std::string &ruleName);
/// Get a rule's index (i.e., {@code RULE_ruleName} field) or INVALID_INDEX if not found.
virtual size_t getRuleIndex(const std::string &ruleName);
virtual Ref<ParserRuleContext> getRuleContext();

View File

@ -55,6 +55,8 @@
using namespace antlr4;
using namespace antlr4::atn;
using namespace antlr4::misc;
using namespace antlrcpp;
ParserInterpreter::ParserInterpreter(const std::string &grammarFileName, const std::vector<std::string>& tokenNames,
@ -71,7 +73,7 @@ ParserInterpreter::ParserInterpreter(const std::string &grammarFileName, const d
}
// init decision DFA
for (int i = 0; i < atn.getNumberOfDecisions(); ++i) {
for (size_t i = 0; i < atn.getNumberOfDecisions(); ++i) {
atn::DecisionState *decisionState = atn.getDecisionState(i);
_decisionToDFA.push_back(dfa::DFA(decisionState, i));
}
@ -110,8 +112,8 @@ std::string ParserInterpreter::getGrammarFileName() const {
return _grammarFileName;
}
Ref<ParserRuleContext> ParserInterpreter::parse(int startRuleIndex) {
atn::RuleStartState *startRuleStartState = _atn.ruleToStartState[(size_t)startRuleIndex];
Ref<ParserRuleContext> ParserInterpreter::parse(size_t startRuleIndex) {
atn::RuleStartState *startRuleStartState = _atn.ruleToStartState[startRuleIndex];
_rootContext = createInterpreterRuleContext(std::weak_ptr<ParserRuleContext>(), atn::ATNState::INVALID_STATE_NUMBER, startRuleIndex);
@ -158,7 +160,7 @@ Ref<ParserRuleContext> ParserInterpreter::parse(int startRuleIndex) {
}
}
void ParserInterpreter::enterRecursionRule(Ref<ParserRuleContext> const& localctx, int state, int ruleIndex, int precedence) {
void ParserInterpreter::enterRecursionRule(Ref<ParserRuleContext> const& localctx, size_t state, size_t ruleIndex, int precedence) {
_parentContextStack.push({ _ctx, localctx->invokingState });
Parser::enterRecursionRule(localctx, state, ruleIndex, precedence);
}
@ -178,11 +180,11 @@ Ref<InterpreterRuleContext> ParserInterpreter::getRootContext() {
}
atn::ATNState* ParserInterpreter::getATNState() {
return _atn.states[(size_t)getState()];
return _atn.states[getState()];
}
void ParserInterpreter::visitState(atn::ATNState *p) {
int predictedAlt = 1;
size_t predictedAlt = 1;
if (is<DecisionState *>(p)) {
predictedAlt = visitDecisionState(dynamic_cast<DecisionState *>(p));
}
@ -221,7 +223,7 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
case atn::Transition::RULE:
{
atn::RuleStartState *ruleStartState = (atn::RuleStartState*)(transition->target);
int ruleIndex = ruleStartState->ruleIndex;
size_t ruleIndex = ruleStartState->ruleIndex;
Ref<InterpreterRuleContext> newctx = createInterpreterRuleContext(_ctx, p->stateNumber, ruleIndex);
if (ruleStartState->isLeftRecursiveRule) {
enterRecursionRule(newctx, ruleStartState->stateNumber, ruleIndex, ((atn::RuleTransition*)(transition))->precedence);
@ -262,8 +264,8 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
setState(transition->target->stateNumber);
}
int ParserInterpreter::visitDecisionState(DecisionState *p) {
int predictedAlt = 1;
size_t ParserInterpreter::visitDecisionState(DecisionState *p) {
size_t predictedAlt = 1;
if (p->getNumberOfTransitions() > 1) {
getErrorHandler()->sync(this);
int decision = p->decision;
@ -278,12 +280,12 @@ int ParserInterpreter::visitDecisionState(DecisionState *p) {
}
Ref<InterpreterRuleContext> ParserInterpreter::createInterpreterRuleContext(std::weak_ptr<ParserRuleContext> parent,
int invokingStateNumber, int ruleIndex) {
size_t invokingStateNumber, size_t ruleIndex) {
return std::make_shared<InterpreterRuleContext>(parent, invokingStateNumber, ruleIndex);
}
void ParserInterpreter::visitRuleStopState(atn::ATNState *p) {
atn::RuleStartState *ruleStartState = _atn.ruleToStartState[(size_t)p->ruleIndex];
atn::RuleStartState *ruleStartState = _atn.ruleToStartState[p->ruleIndex];
if (ruleStartState->isLeftRecursiveRule) {
std::pair<Ref<ParserRuleContext>, int> parentContext = _parentContextStack.top();
_parentContextStack.pop();
@ -294,7 +296,7 @@ void ParserInterpreter::visitRuleStopState(atn::ATNState *p) {
exitRule();
}
atn::RuleTransition *ruleTransition = static_cast<atn::RuleTransition*>(_atn.states[(size_t)getState()]->transition(0));
atn::RuleTransition *ruleTransition = static_cast<atn::RuleTransition*>(_atn.states[getState()]->transition(0));
setState(ruleTransition->followState->stateNumber);
}
@ -307,7 +309,7 @@ void ParserInterpreter::recover(RecognitionException &e) {
if (is<InputMismatchException *>(&e)) {
InputMismatchException &ime = (InputMismatchException&)e;
Token *tok = e.getOffendingToken();
int expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element
size_t expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element
_errorToken = getTokenFactory()->create({ tok->getTokenSource(), tok->getTokenSource()->getInputStream() },
expectedTokenType, tok->getText(), Token::DEFAULT_CHANNEL, -1, -1, // invalid start/stop
tok->getLine(), tok->getCharPositionInLine());

View File

@ -75,9 +75,9 @@ namespace antlr4 {
virtual std::string getGrammarFileName() const override;
/// Begin parsing at startRuleIndex
virtual Ref<ParserRuleContext> parse(int startRuleIndex);
virtual Ref<ParserRuleContext> parse(size_t startRuleIndex);
virtual void enterRecursionRule(Ref<ParserRuleContext> const& localctx, int state, int ruleIndex, int precedence) override;
virtual void enterRecursionRule(Ref<ParserRuleContext> const& localctx, size_t state, size_t ruleIndex, int precedence) override;
/** Override this parser interpreters normal decision-making process
@ -181,13 +181,13 @@ namespace antlr4 {
* a decision state (instance of DecisionState). It gives an opportunity
* for subclasses to track interesting things.
*/
int visitDecisionState(atn::DecisionState *p);
size_t visitDecisionState(atn::DecisionState *p);
/** Provide simple "factory" for InterpreterRuleContext's.
* @since 4.5.1
*/
Ref<InterpreterRuleContext> createInterpreterRuleContext(std::weak_ptr<ParserRuleContext> parent, int invokingStateNumber,
int ruleIndex);
Ref<InterpreterRuleContext> createInterpreterRuleContext(std::weak_ptr<ParserRuleContext> parent,
size_t invokingStateNumber, size_t ruleIndex);
virtual void visitRuleStopState(atn::ATNState *p);

View File

@ -54,7 +54,7 @@ void ParserRuleContext::copyFrom(Ref<ParserRuleContext> const& ctx) {
this->stop = ctx->stop;
}
ParserRuleContext::ParserRuleContext(std::weak_ptr<ParserRuleContext> parent, int invokingStateNumber)
ParserRuleContext::ParserRuleContext(std::weak_ptr<ParserRuleContext> parent, size_t invokingStateNumber)
: RuleContext(parent, invokingStateNumber) {
}
@ -94,7 +94,7 @@ Ref<tree::ErrorNode> ParserRuleContext::addErrorNode(Token *badToken) {
return t;
}
Ref<tree::TerminalNode> ParserRuleContext::getToken(int ttype, std::size_t i) {
Ref<tree::TerminalNode> ParserRuleContext::getToken(size_t ttype, size_t i) {
if (i >= children.size()) {
return nullptr;
}
@ -115,7 +115,7 @@ Ref<tree::TerminalNode> ParserRuleContext::getToken(int ttype, std::size_t i) {
return nullptr;
}
std::vector<Ref<tree::TerminalNode>> ParserRuleContext::getTokens(int ttype) {
std::vector<Ref<tree::TerminalNode>> ParserRuleContext::getTokens(size_t ttype) {
std::vector<Ref<tree::TerminalNode>> tokens;
for (auto &o : children) {
if (is<tree::TerminalNode>(o)) {

View File

@ -99,7 +99,7 @@ namespace antlr4 {
*/
virtual void copyFrom(Ref<ParserRuleContext> const& ctx);
ParserRuleContext(std::weak_ptr<ParserRuleContext> parent, int invokingStateNumber);
ParserRuleContext(std::weak_ptr<ParserRuleContext> parent, size_t invokingStateNumber);
// Double dispatch methods for listeners
@ -118,9 +118,9 @@ namespace antlr4 {
virtual Ref<tree::TerminalNode> addChild(Token *matchedToken);
virtual Ref<tree::ErrorNode> addErrorNode(Token *badToken);
virtual Ref<tree::TerminalNode> getToken(int ttype, std::size_t i);
virtual Ref<tree::TerminalNode> getToken(size_t ttype, std::size_t i);
virtual std::vector<Ref<tree::TerminalNode>> getTokens(int ttype);
virtual std::vector<Ref<tree::TerminalNode>> getTokens(size_t ttype);
template<typename T>
Ref<T> getRuleContext(size_t i) {

View File

@ -50,7 +50,7 @@ void ProxyErrorListener::removeErrorListeners() {
}
void ProxyErrorListener::syntaxError(IRecognizer *recognizer, Token *offendingSymbol, size_t line,
int charPositionInLine, const std::string &msg, std::exception_ptr e) {
size_t charPositionInLine, const std::string &msg, std::exception_ptr e) {
for (auto listener : _delegates) {
listener->syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
@ -72,7 +72,7 @@ void ProxyErrorListener::reportAttemptingFullContext(Parser *recognizer, const d
}
void ProxyErrorListener::reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
int prediction, atn::ATNConfigSet *configs) {
size_t prediction, atn::ATNConfigSet *configs) {
for (auto listener : _delegates) {
listener->reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs);
}

View File

@ -48,7 +48,7 @@ namespace antlr4 {
void removeErrorListener(ANTLRErrorListener *listener);
void removeErrorListeners();
void syntaxError(IRecognizer *recognizer, Token *offendingSymbol, size_t line, int charPositionInLine,
void syntaxError(IRecognizer *recognizer, Token *offendingSymbol, size_t line, size_t charPositionInLine,
const std::string &msg, std::exception_ptr e) override;
virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
@ -58,7 +58,7 @@ namespace antlr4 {
const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override;
virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
int prediction, atn::ATNConfigSet *configs) override;
size_t prediction, atn::ATNConfigSet *configs) override;
};
} // namespace antlr4

View File

@ -53,11 +53,11 @@ RecognitionException::RecognitionException(const std::string &message, IRecogniz
}
}
int RecognitionException::getOffendingState() const {
size_t RecognitionException::getOffendingState() const {
return _offendingState;
}
void RecognitionException::setOffendingState(int offendingState) {
void RecognitionException::setOffendingState(size_t offendingState) {
_offendingState = offendingState;
}

View File

@ -52,7 +52,7 @@ namespace antlr4 {
/// instance itself.
Token *_offendingToken;
int _offendingState;
size_t _offendingState;
public:
RecognitionException(IRecognizer *recognizer, IntStream *input, Ref<ParserRuleContext> const& ctx,
@ -68,10 +68,10 @@ namespace antlr4 {
/// edge we couldn't match.
///
/// If the state number is not known, this method returns -1.
virtual int getOffendingState() const;
virtual size_t getOffendingState() const;
protected:
void setOffendingState(int offendingState);
void setOffendingState(size_t offendingState);
/// Gets the set of input symbols which could potentially follow the
/// previously matched symbol at the time this exception was thrown.

View File

@ -43,8 +43,9 @@
#include "Recognizer.h"
using namespace antlr4;
using namespace antlr4::atn;
std::map<const dfa::Vocabulary*, std::map<std::string, ssize_t>> Recognizer::_tokenTypeMapCache;
std::map<const dfa::Vocabulary*, std::map<std::string, size_t>> Recognizer::_tokenTypeMapCache;
std::map<std::vector<std::string>, std::map<std::string, size_t>> Recognizer::_ruleIndexMapCache;
Recognizer::Recognizer() {
@ -57,11 +58,11 @@ dfa::Vocabulary const& Recognizer::getVocabulary() const {
return vocabulary;
}
std::map<std::string, ssize_t> Recognizer::getTokenTypeMap() {
std::map<std::string, size_t> Recognizer::getTokenTypeMap() {
const dfa::Vocabulary& vocabulary = getVocabulary();
std::lock_guard<std::recursive_mutex> lck(mtx);
std::map<std::string, ssize_t> result;
std::map<std::string, size_t> result;
auto iterator = _tokenTypeMapCache.find(&vocabulary);
if (iterator != _tokenTypeMapCache.end()) {
result = iterator->second;
@ -102,8 +103,8 @@ std::map<std::string, size_t> Recognizer::getRuleIndexMap() {
return result;
}
ssize_t Recognizer::getTokenType(const std::string &tokenName) {
const std::map<std::string, ssize_t> &map = getTokenTypeMap();
size_t Recognizer::getTokenType(const std::string &tokenName) {
const std::map<std::string, size_t> &map = getTokenTypeMap();
auto iterator = map.find(tokenName);
if (iterator == map.end())
return Token::INVALID_TYPE;
@ -125,9 +126,9 @@ void Recognizer::setInterpreter(atn::ATNSimulator *interpreter) {
std::string Recognizer::getErrorHeader(RecognitionException *e) {
// We're having issues with cross header dependencies, these two classes will need to be
// rewritten to remove that.
int line = e->getOffendingToken()->getLine();
int charPositionInLine = e->getOffendingToken()->getCharPositionInLine();
return std::string("line ") + std::to_string(line) + std::string(":") + std::to_string(charPositionInLine);
size_t line = e->getOffendingToken()->getLine();
size_t charPositionInLine = e->getOffendingToken()->getCharPositionInLine();
return std::string("line ") + std::to_string(line) + ":" + std::to_string(charPositionInLine);
}
@ -167,7 +168,7 @@ ProxyErrorListener& Recognizer::getErrorListenerDispatch() {
return _proxListener;
}
bool Recognizer::sempred(Ref<RuleContext> const& /*localctx*/, int /*ruleIndex*/, int /*actionIndex*/) {
bool Recognizer::sempred(Ref<RuleContext> const& /*localctx*/, size_t /*ruleIndex*/, size_t /*actionIndex*/) {
return true;
}
@ -175,20 +176,19 @@ bool Recognizer::precpred(Ref<RuleContext> const& /*localctx*/, int /*precedence
return true;
}
void Recognizer::action(Ref<RuleContext> const& /*localctx*/, int /*ruleIndex*/, int /*actionIndex*/) {
void Recognizer::action(Ref<RuleContext> const& /*localctx*/, size_t /*ruleIndex*/, size_t /*actionIndex*/) {
}
int Recognizer::getState() {
size_t Recognizer::getState() const {
return _stateNumber;
}
void Recognizer::setState(int atnState) {
void Recognizer::setState(size_t atnState) {
_stateNumber = atnState;
// if ( traceATNStates ) _ctx.trace(atnState);
}
void Recognizer::InitializeInstanceFields() {
_stateNumber = -1;
_stateNumber = ATNState::INVALID_STATE_NUMBER;
_interpreter = nullptr;
}

View File

@ -38,7 +38,7 @@ namespace antlr4 {
class ANTLR4CPP_PUBLIC Recognizer : public IRecognizer {
public:
static const ssize_t EOF = -1;
static const size_t EOF = (size_t)-1;
Recognizer();
virtual ~Recognizer() {};
@ -65,7 +65,7 @@ namespace antlr4 {
/// <p/>
/// Used for XPath and tree pattern compilation.
/// </summary>
virtual std::map<std::string, ssize_t> getTokenTypeMap();
virtual std::map<std::string, size_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 ssize_t getTokenType(const std::string &tokenName);
virtual size_t getTokenType(const std::string &tokenName);
/// <summary>
/// If this recognizer was generated, it will have a serialized ATN
@ -144,13 +144,13 @@ namespace antlr4 {
// subclass needs to override these if there are sempreds or actions
// that the ATN interp needs to execute
virtual bool sempred(Ref<RuleContext> const& localctx, int ruleIndex, int actionIndex);
virtual bool sempred(Ref<RuleContext> const& localctx, size_t ruleIndex, size_t actionIndex);
virtual bool precpred(Ref<RuleContext> const& localctx, int precedence);
virtual void action(Ref<RuleContext> const& localctx, int ruleIndex, int actionIndex);
virtual void action(Ref<RuleContext> const& localctx, size_t ruleIndex, size_t actionIndex);
int getState();
virtual size_t getState() const override;
/// <summary>
/// Indicate that the recognizer has changed internal state that is
@ -160,7 +160,7 @@ namespace antlr4 {
/// invoking rules. Combine this and we have complete ATN
/// configuration information.
/// </summary>
void setState(int atnState);
void setState(size_t atnState);
virtual IntStream* getInputStream() = 0;
@ -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, ssize_t>> _tokenTypeMapCache;
static std::map<const dfa::Vocabulary*, std::map<std::string, size_t>> _tokenTypeMapCache;
static std::map<std::vector<std::string>, std::map<std::string, size_t>> _ruleIndexMapCache;
ProxyErrorListener _proxListener; // Manages a collection of listeners.
@ -183,7 +183,7 @@ namespace antlr4 {
// Mutex to manage synchronized access for multithreading.
std::recursive_mutex mtx;
int _stateNumber;
size_t _stateNumber;
void InitializeInstanceFields();

View File

@ -33,17 +33,19 @@
#include "misc/Interval.h"
#include "Parser.h"
#include "atn/ATN.h"
#include "atn/ATNState.h"
#include "tree/ParseTreeVisitor.h"
#include "RuleContext.h"
using namespace antlr4;
using namespace antlr4::atn;
RuleContext::RuleContext() {
InitializeInstanceFields();
}
RuleContext::RuleContext(std::weak_ptr<RuleContext> parent, int invokingState) {
RuleContext::RuleContext(std::weak_ptr<RuleContext> parent, size_t invokingState) {
InitializeInstanceFields();
this->parent = parent;
this->invokingState = invokingState;
@ -62,7 +64,7 @@ int RuleContext::depth() {
}
bool RuleContext::isEmpty() {
return invokingState == -1;
return invokingState == ATNState::INVALID_STATE_NUMBER;
}
misc::Interval RuleContext::getSourceInterval() {
@ -91,8 +93,8 @@ std::string RuleContext::getText() {
return ss.str();
}
ssize_t RuleContext::getRuleIndex() const {
return -1;
size_t RuleContext::getRuleIndex() const {
return INVALID_INDEX;
}
int RuleContext::getAltNumber() const {
@ -135,9 +137,9 @@ std::string RuleContext::toString(const std::vector<std::string> &ruleNames, Ref
ss << currentParent->invokingState;
}
} else {
ssize_t ruleIndex = currentParent->getRuleIndex();
size_t ruleIndex = currentParent->getRuleIndex();
std::string ruleName = (ruleIndex >= 0 && ruleIndex < (ssize_t)ruleNames.size()) ? ruleNames[(size_t)ruleIndex] : std::to_string(ruleIndex);
std::string ruleName = (ruleIndex < ruleNames.size()) ? ruleNames[ruleIndex] : std::to_string(ruleIndex);
ss << ruleName;
}
@ -169,5 +171,5 @@ std::string RuleContext::toString(Recognizer *recog, Ref<RuleContext> const& sto
}
void RuleContext::InitializeInstanceFields() {
invokingState = -1;
invokingState = INVALID_INDEX;
}

View File

@ -90,11 +90,11 @@ namespace antlr4 {
/// What state invoked the rule associated with this context?
/// The "return address" is the followState of invokingState
/// If parent is null, this should be -1 and this context object represents the start rule.
int invokingState;
size_t invokingState;
RuleContext();
RuleContext(std::weak_ptr<RuleContext> parent, int invokingState);
RuleContext(std::weak_ptr<RuleContext> parent, size_t invokingState);
virtual int depth();
@ -108,7 +108,7 @@ namespace antlr4 {
virtual Ref<RuleContext> getRuleContext() override;
virtual std::string getText() override;
virtual ssize_t getRuleIndex() const;
virtual size_t getRuleIndex() const;
/** For rule associated with this parse tree internal node, return
* the outer alternative number used to match the input. Default

View File

@ -44,9 +44,9 @@ namespace antlr4 {
/// During lookahead operations, this "token" signifies we hit rule end ATN state
/// and did not follow it despite needing to.
static const ssize_t EPSILON = -2;
static const size_t EPSILON = (size_t)-2;
static const size_t MIN_USER_TOKEN_TYPE = 1;
static const ssize_t EOF = IntStream::EOF;
static const size_t EOF = IntStream::EOF;
virtual ~Token() {};
@ -72,64 +72,44 @@ namespace antlr4 {
*/
static const size_t MIN_USER_CHANNEL_VALUE = 2;
/// <summary>
/// Get the text of the token.
/// </summary>
virtual std::string getText() const = 0;
/// <summary>
/// Get the token type of the token </summary>
virtual int getType() const = 0;
/// Get the token type of the token
virtual size_t getType() const = 0;
/// <summary>
/// The line number on which the 1st character of this token was matched,
/// line=1..n
/// </summary>
virtual int getLine() const = 0;
/// The line number on which the 1st character of this token was matched, line=1..n
virtual size_t getLine() const = 0;
/// <summary>
/// The index of the first character of this token relative to the
/// beginning of the line at which it occurs, 0..n-1
/// </summary>
virtual int getCharPositionInLine() const = 0;
virtual size_t getCharPositionInLine() const = 0;
/// <summary>
/// Return the channel this token. Each token can arrive at the parser
/// on a different channel, but the parser only "tunes" to a single channel.
/// The parser ignores everything not on DEFAULT_CHANNEL.
/// </summary>
virtual size_t getChannel() const = 0;
/// <summary>
/// An index from 0..n-1 of the token object in the input stream.
/// This must be valid in order to print token streams and
/// use TokenRewriteStream.
///
/// Return -1 to indicate that this token was conjured up since
/// Return INVALID_INDEX to indicate that this token was conjured up since
/// it doesn't have a valid index.
/// </summary>
virtual int getTokenIndex() const = 0;
virtual size_t getTokenIndex() const = 0;
/// <summary>
/// The starting character index of the token
/// This method is optional; return -1 if not implemented.
/// </summary>
virtual int getStartIndex() const = 0;
/// This method is optional; return INVALID_INDEX if not implemented.
virtual size_t getStartIndex() const = 0;
/// <summary>
/// The last character index of the token.
/// This method is optional; return -1 if not implemented.
/// </summary>
virtual int getStopIndex() const = 0;
/// This method is optional; return INVALID_INDEX if not implemented.
virtual size_t getStopIndex() const = 0;
/// <summary>
/// Gets the <seealso cref="TokenSource"/> which created this token.
/// </summary>
virtual TokenSource *getTokenSource() const = 0;
/// <summary>
/// Gets the <seealso cref="CharStream"/> from which this token was derived.
/// </summary>
virtual CharStream *getInputStream() const = 0;
virtual std::string toString() const = 0;

View File

@ -44,11 +44,11 @@ namespace antlr4 {
/// This is the method used to create tokens in the lexer and in the
/// error handling strategy. If text!=null, than the start and stop positions
/// are wiped to -1 in the text override is set in the CommonToken.
virtual std::unique_ptr<Symbol> create(std::pair<TokenSource *, CharStream *> source, int type, const std::string &text,
int channel, int start, int stop, int line, int charPositionInLine) = 0;
virtual std::unique_ptr<Symbol> create(std::pair<TokenSource *, CharStream *> source, size_t type, const std::string &text,
size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) = 0;
/// Generically useful
virtual std::unique_ptr<Symbol> create(int type, const std::string &text) = 0;
virtual std::unique_ptr<Symbol> create(size_t type, const std::string &text) = 0;
};
} // namespace antlr4

View File

@ -73,8 +73,8 @@ namespace antlr4 {
/// stream. The first character on a line has position 0.
/// </summary>
/// <returns> The line number for the current position in the input stream, or
/// -1 if the current token source does not track character positions. </returns>
virtual int getCharPositionInLine() = 0;
/// (sze_t)-1 if the current token source does not track character positions. </returns>
virtual size_t getCharPositionInLine() = 0;
/// <summary>
/// Get the <seealso cref="CharStream"/> from which this token source is currently

View File

@ -42,13 +42,15 @@ using namespace antlrcpp;
using antlr4::misc::Interval;
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, size_t index) : outerInstance(outerInstance) {
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, size_t index)
: outerInstance(outerInstance) {
InitializeInstanceFields();
this->index = index;
}
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::string& text) : outerInstance(outerInstance) {
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, size_t index,
const std::string& text) : outerInstance(outerInstance) {
InitializeInstanceFields();
this->index = index;
@ -125,11 +127,11 @@ TokenStream *TokenStreamRewriter::getTokenStream() {
return tokens;
}
void TokenStreamRewriter::rollback(int instructionIndex) {
void TokenStreamRewriter::rollback(size_t instructionIndex) {
rollback(DEFAULT_PROGRAM_NAME, instructionIndex);
}
void TokenStreamRewriter::rollback(const std::string &programName, int instructionIndex) {
void TokenStreamRewriter::rollback(const std::string &programName, size_t instructionIndex) {
std::vector<RewriteOperation*> is = _programs[programName];
if (is.size() > 0) {
_programs.insert({ programName, std::vector<RewriteOperation*>(is.begin() + MIN_TOKEN_INDEX, is.begin() + instructionIndex) });
@ -153,7 +155,7 @@ void TokenStreamRewriter::insertAfter(size_t index, const std::string& text) {
}
void TokenStreamRewriter::insertAfter(const std::string &programName, Token *t, const std::string& text) {
insertAfter(programName, (size_t)t->getTokenIndex(), text);
insertAfter(programName, t->getTokenIndex(), text);
}
void TokenStreamRewriter::insertAfter(const std::string &programName, size_t index, const std::string& text) {
@ -170,13 +172,13 @@ void TokenStreamRewriter::insertBefore(size_t index, const std::string& text) {
}
void TokenStreamRewriter::insertBefore(const std::string &programName, Token *t, const std::string& text) {
insertBefore(programName, (size_t)t->getTokenIndex(), text);
insertBefore(programName, t->getTokenIndex(), text);
}
void TokenStreamRewriter::insertBefore(const std::string &programName, size_t index, const std::string& text) {
RewriteOperation *op = new InsertBeforeOp(this, index, text); /* mem-check: deleted in d-tor */
std::vector<RewriteOperation*> &rewrites = getProgram(programName);
op->instructionIndex = (int)rewrites.size();
op->instructionIndex = rewrites.size();
rewrites.push_back(op);
}
@ -203,12 +205,12 @@ void TokenStreamRewriter::replace(const std::string &programName, size_t from, s
}
RewriteOperation *op = new ReplaceOp(this, from, to, text); /* mem-check: deleted in d-tor */
std::vector<RewriteOperation*> &rewrites = getProgram(programName);
op->instructionIndex = (int)rewrites.size();
op->instructionIndex = rewrites.size();
rewrites.push_back(op);
}
void TokenStreamRewriter::replace(const std::string &programName, Token *from, Token *to, const std::string& text) {
replace(programName, (size_t)from->getTokenIndex(), (size_t)to->getTokenIndex(), text);
replace(programName, from->getTokenIndex(), to->getTokenIndex(), text);
}
void TokenStreamRewriter::Delete(size_t index) {
@ -235,18 +237,18 @@ void TokenStreamRewriter::Delete(const std::string &programName, Token *from, To
replace(programName, from, to, nullptr);
}
int TokenStreamRewriter::getLastRewriteTokenIndex() {
size_t TokenStreamRewriter::getLastRewriteTokenIndex() {
return getLastRewriteTokenIndex(DEFAULT_PROGRAM_NAME);
}
int TokenStreamRewriter::getLastRewriteTokenIndex(const std::string &programName) {
size_t TokenStreamRewriter::getLastRewriteTokenIndex(const std::string &programName) {
if (_lastRewriteTokenIndexes.find(programName) == _lastRewriteTokenIndexes.end()) {
return -1;
return INVALID_INDEX;
}
return _lastRewriteTokenIndexes[programName];
}
void TokenStreamRewriter::setLastRewriteTokenIndex(const std::string &programName, int i) {
void TokenStreamRewriter::setLastRewriteTokenIndex(const std::string &programName, size_t i) {
_lastRewriteTokenIndexes.insert({ programName, i });
}
@ -265,11 +267,11 @@ std::vector<TokenStreamRewriter::RewriteOperation*> TokenStreamRewriter::initial
}
std::string TokenStreamRewriter::getText() {
return getText(DEFAULT_PROGRAM_NAME, Interval(0, (int)tokens->size() - 1));
return getText(DEFAULT_PROGRAM_NAME, Interval(0, tokens->size() - 1));
}
std::string TokenStreamRewriter::getText(std::string programName) {
return getText(programName, Interval(0, (int)tokens->size() - 1));
return getText(programName, Interval(0, tokens->size() - 1));
}
std::string TokenStreamRewriter::getText(const Interval &interval) {
@ -278,14 +280,14 @@ std::string TokenStreamRewriter::getText(const Interval &interval) {
std::string TokenStreamRewriter::getText(const std::string &programName, const Interval &interval) {
std::vector<TokenStreamRewriter::RewriteOperation*> rewrites = _programs[programName];
int start = interval.a;
int stop = interval.b;
size_t start = interval.a;
size_t stop = interval.b;
// ensure start/end are in range
if (stop > (int)tokens->size() - 1) {
stop = (int)tokens->size() - 1;
if (stop > tokens->size() - 1) {
stop = tokens->size() - 1;
}
if (start < 0) {
if (start == INVALID_INDEX) {
start = 0;
}
@ -298,8 +300,8 @@ std::string TokenStreamRewriter::getText(const std::string &programName, const I
std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> indexToOp = reduceToSingleOperationPerIndex(rewrites);
// Walk buffer, executing instructions and emitting tokens
size_t i = (size_t)start;
while (i <= (size_t)stop && i < tokens->size()) {
size_t i = start;
while (i <= stop && i < tokens->size()) {
RewriteOperation *op = indexToOp[i];
indexToOp.erase(i); // remove so any left have index size-1
Token *t = tokens->get(i);
@ -318,7 +320,7 @@ std::string TokenStreamRewriter::getText(const std::string &programName, const I
// include stuff after end if it's last index in buffer
// So, if they did an insertAfter(lastValidIndex, "foo"), include
// foo if end==lastValidIndex.
if (stop == (int)tokens->size() - 1) {
if (stop == tokens->size() - 1) {
// Scan any remaining operations after last token
// should be included (they will be inserts).
for (auto op : indexToOp) {
@ -405,7 +407,7 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
// whole token buffer so no lazy eval issue with any templates
iop->text = catOpText(&iop->text, &prevIop->text);
// delete redundant prior insert
rewrites[(size_t)prevIop->instructionIndex] = nullptr;
rewrites[prevIop->instructionIndex] = nullptr;
}
}
// look for replaces where iop.index is in range; error

View File

@ -112,22 +112,22 @@ namespace antlr4 {
class ANTLR4CPP_PUBLIC TokenStreamRewriter {
public:
static const std::string DEFAULT_PROGRAM_NAME;
static const int PROGRAM_INIT_SIZE = 100;
static const int MIN_TOKEN_INDEX = 0;
static const size_t PROGRAM_INIT_SIZE = 100;
static const size_t MIN_TOKEN_INDEX = 0;
TokenStreamRewriter(TokenStream *tokens);
virtual ~TokenStreamRewriter();
TokenStream *getTokenStream();
virtual void rollback(int instructionIndex);
virtual void rollback(size_t instructionIndex);
/// <summary>
/// Rollback the instruction stream for a program so that
/// the indicated instruction (via instructionIndex) is no
/// longer in the stream. UNTESTED!
/// </summary>
virtual void rollback(const std::string &programName, int instructionIndex);
virtual void rollback(const std::string &programName, size_t instructionIndex);
virtual void deleteProgram();
@ -158,7 +158,7 @@ namespace antlr4 {
virtual void Delete(const std::string &programName, size_t from, size_t to);
virtual void Delete(const std::string &programName, Token *from, Token *to);
virtual int getLastRewriteTokenIndex();
virtual size_t getLastRewriteTokenIndex();
/// Return the text from the original tokens altered per the
/// instructions given to this rewriter.
@ -189,22 +189,20 @@ namespace antlr4 {
TokenStreamRewriter *const outerInstance;
public:
/// <summary>
/// What index into rewrites List are we? </summary>
/// What index into rewrites List are we?
virtual ~RewriteOperation() {};
/// <summary>
/// Token buffer index. </summary>
/// Token buffer index.
size_t index;
std::string text;
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index);
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::string& text);
/// <summary>
/// Execute the rewrite operation by possibly adding to the buffer.
/// Return the index of the next token to operate on.
/// </summary>
int instructionIndex;
size_t instructionIndex;
virtual size_t execute(std::string *buf);
@ -249,9 +247,9 @@ namespace antlr4 {
/// <summary>
/// Map String (program name) -> Integer index </summary>
std::map<std::string, int> _lastRewriteTokenIndexes;
virtual int getLastRewriteTokenIndex(const std::string &programName);
virtual void setLastRewriteTokenIndex(const std::string &programName, int i);
std::map<std::string, size_t> _lastRewriteTokenIndexes;
virtual size_t getLastRewriteTokenIndex(const std::string &programName);
virtual void setLastRewriteTokenIndex(const std::string &programName, size_t i);
virtual std::vector<RewriteOperation*>& getProgram(const std::string &name);
/// <summary>

View File

@ -37,6 +37,7 @@
using namespace antlrcpp;
using namespace antlr4;
using namespace antlr4::misc;
UnbufferedCharStream::UnbufferedCharStream(std::wistream &input) : _input(input) {
InitializeInstanceFields();
@ -108,7 +109,7 @@ void UnbufferedCharStream::add(char32_t c) {
_data += c;
}
ssize_t UnbufferedCharStream::LA(ssize_t i) {
size_t UnbufferedCharStream::LA(ssize_t i) {
if (i == -1) { // special case
return _lastChar;
}
@ -122,11 +123,7 @@ ssize_t UnbufferedCharStream::LA(ssize_t i) {
return EOF;
}
ssize_t c = _data[(size_t)index];
if (c == EOF) {
return EOF;
}
return c;
return _data[(size_t)index];
}
ssize_t UnbufferedCharStream::mark() {
@ -199,24 +196,24 @@ std::string UnbufferedCharStream::getSourceName() const {
}
std::string UnbufferedCharStream::getText(const misc::Interval &interval) {
if (interval.a < 0 || interval.b < interval.a - 1) {
if (interval.a < 0 || interval.b >= interval.a - 1) {
throw IllegalArgumentException("invalid interval");
}
size_t bufferStartIndex = getBufferStartIndex();
if (!_data.empty() && _data.back() == 0xFFFF) {
if ((size_t)(interval.a + interval.length()) > bufferStartIndex + _data.size()) {
if (interval.a + interval.length() > bufferStartIndex + _data.size()) {
throw IllegalArgumentException("the interval extends past the end of the stream");
}
}
if ((size_t)interval.a < bufferStartIndex || (size_t)interval.b >= bufferStartIndex + _data.size()) {
if (interval.a < (ssize_t)bufferStartIndex || interval.b >= ssize_t(bufferStartIndex + _data.size())) {
throw UnsupportedOperationException("interval " + interval.toString() + " outside buffer: " +
std::to_string(bufferStartIndex) + ".." + std::to_string(bufferStartIndex + _data.size() - 1));
}
// convert from absolute to local index
size_t i = (size_t)interval.a - bufferStartIndex;
return utfConverter.to_bytes(_data.substr(i, (size_t)interval.length()));
size_t i = interval.a - bufferStartIndex;
return utfConverter.to_bytes(_data.substr(i, interval.length()));
}
size_t UnbufferedCharStream::getBufferStartIndex() const {

View File

@ -47,7 +47,7 @@ namespace antlr4 {
UnbufferedCharStream(std::wistream &input);
virtual void consume() override;
virtual ssize_t LA(ssize_t i) override;
virtual size_t LA(ssize_t i) override;
/// <summary>
/// Return a marker that we can release later.

View File

@ -85,7 +85,7 @@ Token* UnbufferedTokenStream::LT(ssize_t i)
return _tokens[(size_t)index].get();
}
ssize_t UnbufferedTokenStream::LA(ssize_t i)
size_t UnbufferedTokenStream::LA(ssize_t i)
{
return LT(i)->getType();
}
@ -262,8 +262,8 @@ std::string UnbufferedTokenStream::getText(const misc::Interval &interval)
size_t bufferStartIndex = getBufferStartIndex();
size_t bufferStopIndex = bufferStartIndex + _tokens.size() - 1;
size_t start = (size_t)interval.a;
size_t stop = (size_t)interval.b;
size_t start = interval.a;
size_t stop = interval.b;
if (start < bufferStartIndex || stop > bufferStopIndex) {
throw UnsupportedOperationException(std::string("interval ") + interval.toString() +
" not in token buffer window: " + std::to_string(bufferStartIndex) + ".." + std::to_string(bufferStopIndex));

View File

@ -46,7 +46,7 @@ namespace antlr4 {
virtual Token* get(size_t i) const override;
virtual Token* LT(ssize_t i) override;
virtual ssize_t LA(ssize_t i) override;
virtual size_t LA(ssize_t i) override;
virtual TokenSource* getTokenSource() const override;

View File

@ -35,8 +35,7 @@
using namespace antlr4::dfa;
const std::vector<std::string> Vocabulary::EMPTY_NAMES;
const Vocabulary Vocabulary::EMPTY_VOCABULARY = Vocabulary(EMPTY_NAMES, EMPTY_NAMES, EMPTY_NAMES);
const Vocabulary Vocabulary::EMPTY_VOCABULARY;
Vocabulary::Vocabulary(const std::vector<std::string> &literalNames, const std::vector<std::string> &symbolicNames)
: Vocabulary(literalNames, symbolicNames, {}) {
@ -44,10 +43,8 @@ Vocabulary::Vocabulary(const std::vector<std::string> &literalNames, const std::
Vocabulary::Vocabulary(const std::vector<std::string> &literalNames,
const std::vector<std::string> &symbolicNames, const std::vector<std::string> &displayNames)
: _literalNames(!literalNames.empty() ? literalNames : EMPTY_NAMES),
_symbolicNames(!symbolicNames.empty() ? symbolicNames : EMPTY_NAMES),
_displayNames(!displayNames.empty() ? displayNames : EMPTY_NAMES),
_maxTokenType(std::max((int)_displayNames.size(), std::max((int)_literalNames.size(), (int)_symbolicNames.size())) - 1) {
: _literalNames(literalNames), _symbolicNames(symbolicNames), _displayNames(displayNames),
_maxTokenType(std::max(_displayNames.size(), std::max(_literalNames.size(), _symbolicNames.size())) - 1) {
// See note here on -1 part: https://github.com/antlr/antlr4/pull/1146
}
@ -84,32 +81,32 @@ Vocabulary Vocabulary::fromTokenNames(const std::vector<std::string> &tokenNames
return Vocabulary(literalNames, symbolicNames, tokenNames);
}
int Vocabulary::getMaxTokenType() const {
size_t Vocabulary::getMaxTokenType() const {
return _maxTokenType;
}
std::string Vocabulary::getLiteralName(ssize_t tokenType) const {
if (tokenType >= 0 && tokenType < (int)_literalNames.size()) {
std::string Vocabulary::getLiteralName(size_t tokenType) const {
if (tokenType < _literalNames.size()) {
return _literalNames[tokenType];
}
return "";
}
std::string Vocabulary::getSymbolicName(ssize_t tokenType) const {
if (tokenType >= 0 && tokenType < (int)_symbolicNames.size()) {
return _symbolicNames[tokenType];
}
std::string Vocabulary::getSymbolicName(size_t tokenType) const {
if (tokenType == Token::EOF) {
return "EOF";
}
if (tokenType < _symbolicNames.size()) {
return _symbolicNames[tokenType];
}
return "";
}
std::string Vocabulary::getDisplayName(ssize_t tokenType) const {
if (tokenType >= 0 && tokenType < (int)_displayNames.size()) {
std::string Vocabulary::getDisplayName(size_t tokenType) const {
if (tokenType < _displayNames.size()) {
std::string displayName = _displayNames[tokenType];
if (!displayName.empty()) {
return displayName;

View File

@ -50,6 +50,8 @@ namespace dfa {
/// except <seealso cref="Token#EOF"/>.</para>
static const Vocabulary EMPTY_VOCABULARY;
Vocabulary() {};
/// <summary>
/// Constructs a new instance of <seealso cref="Vocabulary"/> from the specified
/// literal and symbolic token names.
@ -101,7 +103,7 @@ namespace dfa {
/// Returns the highest token type value. It can be used to iterate from
/// zero to that number, inclusively, thus querying all stored entries. </summary>
/// <returns> the highest token type value </returns>
virtual int getMaxTokenType() const;
virtual size_t getMaxTokenType() const;
/// <summary>
/// Gets the string literal associated with a token type. The string returned
@ -138,7 +140,7 @@ namespace dfa {
/// </param>
/// <returns> The string literal associated with the specified token type, or
/// {@code null} if no string literal is associated with the type. </returns>
virtual std::string getLiteralName(ssize_t tokenType) const;
virtual std::string getLiteralName(size_t tokenType) const;
/// <summary>
/// Gets the symbolic name associated with a token type. The string returned
@ -182,7 +184,7 @@ namespace dfa {
/// </param>
/// <returns> The symbolic name associated with the specified token type, or
/// {@code null} if no symbolic name is associated with the type. </returns>
virtual std::string getSymbolicName(ssize_t tokenType) const;
virtual std::string getSymbolicName(size_t tokenType) const;
/// <summary>
/// Gets the display name of a token type.
@ -203,15 +205,13 @@ namespace dfa {
/// </param>
/// <returns> The display name of the token type, for use in error reporting or
/// other user-visible messages which reference specific token types. </returns>
virtual std::string getDisplayName(ssize_t tokenType) const;
virtual std::string getDisplayName(size_t tokenType) const;
private:
static std::vector<std::string> const EMPTY_NAMES;
std::vector<std::string> const _literalNames;
std::vector<std::string> const _symbolicNames;
std::vector<std::string> const _displayNames;
const int _maxTokenType;
const size_t _maxTokenType = 0;
};
} // namespace atn

View File

@ -38,11 +38,11 @@ namespace antlr4 {
class ANTLR4CPP_PUBLIC WritableToken : public Token {
public:
virtual void setText(const std::string &text) = 0;
virtual void setType(int ttype) = 0;
virtual void setLine(int line) = 0;
virtual void setCharPositionInLine(int pos) = 0;
virtual void setChannel(int channel) = 0;
virtual void setTokenIndex(int index) = 0;
virtual void setType(size_t ttype) = 0;
virtual void setLine(size_t line) = 0;
virtual void setCharPositionInLine(size_t pos) = 0;
virtual void setChannel(size_t channel) = 0;
virtual void setTokenIndex(size_t index) = 0;
};
} // namespace antlr4

View File

@ -143,4 +143,5 @@
#undef EOF
#endif
#define INVALID_INDEX (size_t)-1
template<class T> using Ref = std::shared_ptr<T>;

View File

@ -129,8 +129,8 @@ void ATN::addState(ATNState *state) {
}
void ATN::removeState(ATNState *state) {
delete states.at((size_t)state->stateNumber);// just free mem, don't shift states in list
states.at((size_t)state->stateNumber) = nullptr;
delete states.at(state->stateNumber);// just free mem, don't shift states in list
states.at(state->stateNumber) = nullptr;
}
int ATN::defineDecisionState(DecisionState *s) {
@ -139,24 +139,24 @@ int ATN::defineDecisionState(DecisionState *s) {
return s->decision;
}
DecisionState *ATN::getDecisionState(int decision) const {
DecisionState *ATN::getDecisionState(size_t decision) const {
if (!decisionToState.empty()) {
return decisionToState[(size_t)decision];
return decisionToState[decision];
}
return nullptr;
}
int ATN::getNumberOfDecisions() const {
return (int)decisionToState.size();
size_t ATN::getNumberOfDecisions() const {
return decisionToState.size();
}
misc::IntervalSet ATN::getExpectedTokens(int stateNumber, RuleContext *context) const {
if (stateNumber < 0 || stateNumber >= (int)states.size()) {
misc::IntervalSet ATN::getExpectedTokens(size_t stateNumber, RuleContext *context) const {
if (stateNumber == ATNState::INVALID_STATE_NUMBER || stateNumber >= states.size()) {
throw IllegalArgumentException("Invalid state number.");
}
RuleContext *ctx = context;
ATNState *s = states.at((size_t)stateNumber);
ATNState *s = states.at(stateNumber);
misc::IntervalSet following = nextTokens(s);
if (!following.contains(Token::EPSILON)) {
return following;
@ -165,8 +165,8 @@ misc::IntervalSet ATN::getExpectedTokens(int stateNumber, RuleContext *context)
misc::IntervalSet expected;
expected.addAll(following);
expected.remove(Token::EPSILON);
while (ctx && ctx->invokingState >= 0 && following.contains(Token::EPSILON)) {
ATNState *invokingState = states.at((size_t)ctx->invokingState);
while (ctx && ctx->invokingState != ATNState::INVALID_STATE_NUMBER && following.contains(Token::EPSILON)) {
ATNState *invokingState = states.at(ctx->invokingState);
RuleTransition *rt = static_cast<RuleTransition*>(invokingState->transition(0));
following = nextTokens(rt->followState);
expected.addAll(following);

View File

@ -38,7 +38,7 @@ namespace atn {
class ANTLR4CPP_PUBLIC ATN {
public:
static const int INVALID_ALT_NUMBER = 0;
static const size_t INVALID_ALT_NUMBER = 0;
/// Used for runtime deserialization of ATNs from strings.
ATN();
@ -72,7 +72,7 @@ namespace atn {
/// <seealso cref="ATNDeserializationOptions#isGenerateRuleBypassTransitions"/>
/// deserialization option was specified; otherwise, this is {@code null}.
/// </summary>
std::vector<int> ruleToTokenType;
std::vector<size_t> ruleToTokenType;
/// For lexer ATNs, this is an array of {@link LexerAction} objects which may
/// be referenced by action transitions in the ATN.
@ -104,9 +104,9 @@ namespace atn {
virtual int defineDecisionState(DecisionState *s);
virtual DecisionState *getDecisionState(int decision) const;
virtual DecisionState *getDecisionState(size_t decision) const;
virtual int getNumberOfDecisions() const;
virtual size_t getNumberOfDecisions() const;
/// <summary>
/// Computes the set of input symbols which could follow ATN state number
@ -126,7 +126,7 @@ namespace atn {
/// specified state in the specified context. </returns>
/// <exception cref="IllegalArgumentException"> if the ATN does not contain a state with
/// number {@code stateNumber} </exception>
virtual misc::IntervalSet getExpectedTokens(int stateNumber, RuleContext *context) const;
virtual misc::IntervalSet getExpectedTokens(size_t stateNumber, RuleContext *context) const;
std::string toString() const;
};

View File

@ -77,7 +77,7 @@ ATNConfig::~ATNConfig() {
size_t ATNConfig::hashCode() const {
size_t hashCode = misc::MurmurHash::initialize(7);
hashCode = misc::MurmurHash::update(hashCode, (size_t)state->stateNumber);
hashCode = misc::MurmurHash::update(hashCode, state->stateNumber);
hashCode = misc::MurmurHash::update(hashCode, (size_t)alt);
hashCode = misc::MurmurHash::update(hashCode, context);
hashCode = misc::MurmurHash::update(hashCode, semanticContext);

View File

@ -238,7 +238,7 @@ std::string ATNConfigSet::toString() {
size_t ATNConfigSet::getHash(ATNConfig *c) {
size_t hashCode = 7;
hashCode = 31 * hashCode + (size_t)c->state->stateNumber;
hashCode = 31 * hashCode + c->state->stateNumber;
hashCode = 31 * hashCode + (size_t)c->alt;
hashCode = 31 * hashCode + c->semanticContext->hashCode();
return hashCode;

View File

@ -163,18 +163,18 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
//
// STATES
//
std::vector<std::pair<LoopEndState*, int>> loopBackStateNumbers;
std::vector<std::pair<BlockStartState*, int>> endStateNumbers;
int nstates = data[p++];
for (int i = 0; i < nstates; i++) {
int stype = data[p++];
std::vector<std::pair<LoopEndState*, size_t>> loopBackStateNumbers;
std::vector<std::pair<BlockStartState*, size_t>> endStateNumbers;
size_t nstates = data[p++];
for (size_t i = 0; i < nstates; i++) {
size_t stype = data[p++];
// ignore bad type of states
if (stype == ATNState::ATN_INVALID_TYPE) {
atn.addState(nullptr);
continue;
}
int ruleIndex = data[p++];
size_t ruleIndex = data[p++];
if (ruleIndex == 0xFFFF) { // Max Unicode char limit imposed by ANTLR.
ruleIndex = -1;
}
@ -196,29 +196,29 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
}
for (auto &pair : endStateNumbers) {
pair.first->endState = (BlockEndState*)atn.states[(size_t)pair.second];
pair.first->endState = (BlockEndState*)atn.states[pair.second];
}
int numNonGreedyStates = data[p++];
for (int i = 0; i < numNonGreedyStates; i++) {
int stateNumber = data[p++];
size_t numNonGreedyStates = data[p++];
for (size_t i = 0; i < numNonGreedyStates; i++) {
size_t stateNumber = data[p++];
// The serialized ATN must be specifying the right states, so that the
// cast below is correct.
((DecisionState *)atn.states[(size_t)stateNumber])->nonGreedy = true;
((DecisionState *)atn.states[stateNumber])->nonGreedy = true;
}
if (supportsPrecedencePredicates) {
int numPrecedenceStates = data[p++];
for (int i = 0; i < numPrecedenceStates; i++) {
int stateNumber = data[p++];
((RuleStartState *)atn.states[(size_t)stateNumber])->isLeftRecursiveRule = true;
size_t numPrecedenceStates = data[p++];
for (size_t i = 0; i < numPrecedenceStates; i++) {
size_t stateNumber = data[p++];
((RuleStartState *)atn.states[stateNumber])->isLeftRecursiveRule = true;
}
}
//
// RULES
//
size_t nrules = (size_t)data[p++];
size_t nrules = data[p++];
if (atn.grammarType == ATNType::LEXER) {
atn.ruleToTokenType.resize(nrules);
}
@ -229,7 +229,7 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
RuleStartState *startState = (RuleStartState*)atn.states[s];
atn.ruleToStartState.push_back(startState);
if (atn.grammarType == ATNType::LEXER) {
int tokenType = data[p++];
size_t tokenType = data[p++];
if (tokenType == 0xFFFF) {
tokenType = Token::EOF;
}
@ -252,16 +252,16 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
}
RuleStopState *stopState = static_cast<RuleStopState*>(state);
atn.ruleToStopState[(size_t)state->ruleIndex] = stopState;
atn.ruleToStartState[(size_t)state->ruleIndex]->stopState = stopState;
atn.ruleToStopState[state->ruleIndex] = stopState;
atn.ruleToStartState[state->ruleIndex]->stopState = stopState;
}
//
// MODES
//
int nmodes = data[p++];
for (int i = 0; i < nmodes; i++) {
size_t s = (size_t)data[p++];
size_t nmodes = data[p++];
for (size_t i = 0; i < nmodes; i++) {
size_t s = data[p++];
atn.modeToStartState.push_back(static_cast<TokensStartState*>(atn.states[s]));
}
@ -291,12 +291,12 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
//
int nedges = data[p++];
for (int i = 0; i < nedges; i++) {
int src = data[p];
int trg = data[p + 1];
int ttype = data[p + 2];
int arg1 = data[p + 3];
int arg2 = data[p + 4];
int arg3 = data[p + 5];
size_t src = data[p];
size_t trg = data[p + 1];
size_t ttype = data[p + 2];
size_t arg1 = data[p + 3];
size_t arg2 = data[p + 4];
size_t arg3 = data[p + 5];
Transition *trans = edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets);
ATNState *srcState = atn.states[(size_t)src];
srcState->addTransition(trans);
@ -312,7 +312,7 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
}
RuleTransition *ruleTransition = static_cast<RuleTransition*>(t);
int outermostPrecedenceReturn = -1;
size_t outermostPrecedenceReturn = INVALID_INDEX;
if (atn.ruleToStartState[ruleTransition->target->ruleIndex]->isLeftRecursiveRule) {
if (ruleTransition->precedence == 0) {
outermostPrecedenceReturn = ruleTransition->target->ruleIndex;
@ -405,10 +405,10 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
continue;
}
int ruleIndex = static_cast<ActionTransition *>(transition)->ruleIndex;
int actionIndex = static_cast<ActionTransition *>(transition)->actionIndex;
size_t ruleIndex = static_cast<ActionTransition *>(transition)->ruleIndex;
size_t actionIndex = static_cast<ActionTransition *>(transition)->actionIndex;
Ref<LexerCustomAction> lexerAction = std::make_shared<LexerCustomAction>(ruleIndex, actionIndex);
state->setTransition(i, new ActionTransition(transition->target, ruleIndex, (int)atn.lexerActions.size(), false)); /* mem-check freed in ATNState d-tor */
state->setTransition(i, new ActionTransition(transition->target, ruleIndex, atn.lexerActions.size(), false)); /* mem-check freed in ATNState d-tor */
atn.lexerActions.push_back(lexerAction);
}
}
@ -447,7 +447,7 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
// wrap from the beginning of the rule to the StarLoopEntryState
endState = nullptr;
for (ATNState *state : atn.states) {
if (state->ruleIndex != (int)i) {
if (state->ruleIndex != i) {
continue;
}
@ -617,10 +617,11 @@ Guid ATNDeserializer::toUUID(const unsigned short *data, int offset) {
}
/* mem check: all created instances are freed in the d-tor of the ATNState they are added to. */
Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int /*src*/, int trg, int arg1, int arg2, int arg3,
Transition *ATNDeserializer::edgeFactory(const ATN &atn, size_t type, size_t /*src*/, size_t trg, size_t arg1,
size_t arg2, size_t arg3,
const std::vector<misc::IntervalSet> &sets) {
ATNState *target = atn.states[(size_t)trg];
ATNState *target = atn.states[trg];
switch (type) {
case Transition::EPSILON :
return new EpsilonTransition(target);
@ -631,11 +632,11 @@ Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int /*src*/,
return new RangeTransition(target, arg1, arg2);
}
case Transition::RULE :
return new RuleTransition(static_cast<RuleStartState*>(atn.states[(size_t)arg1]), arg2, arg3, target);
return new RuleTransition(static_cast<RuleStartState*>(atn.states[arg1]), arg2, (int)arg3, target);
case Transition::PREDICATE :
return new PredicateTransition(target, arg1, arg2, arg3 != 0);
case Transition::PRECEDENCE:
return new PrecedencePredicateTransition(target, arg1);
return new PrecedencePredicateTransition(target, (int)arg1);
case Transition::ATOM :
if (arg3 != 0) {
return new AtomTransition(target, Token::EOF);
@ -645,9 +646,9 @@ Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int /*src*/,
case Transition::ACTION :
return new ActionTransition(target, arg1, arg2, arg3 != 0);
case Transition::SET :
return new SetTransition(target, sets[(size_t)arg1]);
return new SetTransition(target, sets[arg1]);
case Transition::NOT_SET :
return new NotSetTransition(target, sets[(size_t)arg1]);
return new NotSetTransition(target, sets[arg1]);
case Transition::WILDCARD :
return new WildcardTransition(target);
}
@ -656,7 +657,7 @@ Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int /*src*/,
}
/* mem check: all created instances are freed in the d-tor of the ATN. */
ATNState* ATNDeserializer::stateFactory(int type, int ruleIndex) {
ATNState* ATNDeserializer::stateFactory(size_t type, size_t ruleIndex) {
ATNState *s;
switch (type) {
case ATNState::ATN_INVALID_TYPE:

View File

@ -57,10 +57,10 @@ namespace atn {
static void checkCondition(bool condition);
static void checkCondition(bool condition, const std::string &message);
static Transition *edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3,
const std::vector<misc::IntervalSet> &sets);
static Transition *edgeFactory(const ATN &atn, size_t type, size_t src, size_t trg, size_t arg1, size_t arg2,
size_t arg3, const std::vector<misc::IntervalSet> &sets);
static ATNState *stateFactory(int type, int ruleIndex);
static ATNState *stateFactory(size_t type, size_t ruleIndex);
protected:
/// Determines if a particular serialized representation of an ATN supports

View File

@ -83,15 +83,15 @@ std::vector<size_t> ATNSerializer::serialize() {
// convert grammar type to ATN const to avoid dependence on ANTLRParser
data.push_back((size_t)atn->grammarType);
data.push_back((size_t)atn->maxTokenType);
data.push_back(atn->maxTokenType);
size_t nedges = 0;
std::unordered_map<misc::IntervalSet, int> setIndices;
std::vector<misc::IntervalSet> sets;
// dump states, count edges and collect sets while doing so
std::vector<int> nonGreedyStates;
std::vector<int> precedenceStates;
std::vector<size_t> nonGreedyStates;
std::vector<size_t> precedenceStates;
data.push_back(atn->states.size());
for (ATNState *s : atn->states) {
if (s == nullptr) { // might be optimized away
@ -110,18 +110,18 @@ std::vector<size_t> ATNSerializer::serialize() {
data.push_back((size_t)stateType);
if (s->ruleIndex == -1) {
if (s->ruleIndex == INVALID_INDEX) {
data.push_back(0xFFFF);
}
else {
data.push_back((size_t)s->ruleIndex);
data.push_back(s->ruleIndex);
}
if (s->getStateType() == ATNState::LOOP_END) {
data.push_back((size_t)(static_cast<LoopEndState *>(s))->loopBackState->stateNumber);
data.push_back((static_cast<LoopEndState *>(s))->loopBackState->stateNumber);
}
else if (is<BlockStartState *>(s)) {
data.push_back((size_t)(static_cast<BlockStartState *>(s))->endState->stateNumber);
data.push_back((static_cast<BlockStartState *>(s))->endState->stateNumber);
}
if (s->getStateType() != ATNState::RULE_STOP) {
@ -132,7 +132,7 @@ std::vector<size_t> ATNSerializer::serialize() {
for (size_t i = 0; i < s->getNumberOfTransitions(); i++) {
Transition *t = s->transition(i);
int edgeType = t->getSerializationType();
Transition::SerializationType edgeType = t->getSerializationType();
if (edgeType == Transition::SET || edgeType == Transition::NOT_SET) {
SetTransition *st = static_cast<SetTransition *>(t);
if (setIndices.find(st->set) == setIndices.end()) {
@ -146,26 +146,26 @@ std::vector<size_t> ATNSerializer::serialize() {
// non-greedy states
data.push_back(nonGreedyStates.size());
for (size_t i = 0; i < nonGreedyStates.size(); i++) {
data.push_back((size_t)nonGreedyStates.at(i));
data.push_back(nonGreedyStates.at(i));
}
// precedence states
data.push_back(precedenceStates.size());
for (size_t i = 0; i < precedenceStates.size(); i++) {
data.push_back((size_t)precedenceStates.at(i));
data.push_back(precedenceStates.at(i));
}
size_t nrules = atn->ruleToStartState.size();
data.push_back(nrules);
for (size_t r = 0; r < nrules; r++) {
ATNState *ruleStartState = atn->ruleToStartState[r];
data.push_back((size_t)ruleStartState->stateNumber);
data.push_back(ruleStartState->stateNumber);
if (atn->grammarType == ATNType::LEXER) {
if (atn->ruleToTokenType[r] == Token::EOF) {
data.push_back(0xFFFF);
}
else {
data.push_back((size_t)atn->ruleToTokenType[r]);
data.push_back(atn->ruleToTokenType[r]);
}
}
}
@ -174,7 +174,7 @@ std::vector<size_t> ATNSerializer::serialize() {
data.push_back(nmodes);
if (nmodes > 0) {
for (const auto &modeStartState : atn->modeToStartState) {
data.push_back((size_t)modeStartState->stateNumber);
data.push_back(modeStartState->stateNumber);
}
}
@ -182,7 +182,7 @@ std::vector<size_t> ATNSerializer::serialize() {
data.push_back(nsets);
for (auto set : sets) {
bool containsEof = set.contains(Token::EOF);
if (containsEof && set.getIntervals().at(0).b == Token::EOF) {
if (containsEof && set.getIntervals().at(0).b == -1) {
data.push_back(set.getIntervals().size() - 1);
}
else {
@ -191,18 +191,18 @@ std::vector<size_t> ATNSerializer::serialize() {
data.push_back(containsEof ? 1 : 0);
for (auto &interval : set.getIntervals()) {
if (interval.a == Token::EOF) {
if (interval.b == Token::EOF) {
if (interval.a == -1) {
if (interval.b == -1) {
continue;
} else {
data.push_back(0);
}
}
else {
data.push_back((size_t)interval.a);
data.push_back(interval.a);
}
data.push_back((size_t)interval.b);
data.push_back(interval.b);
}
}
@ -220,16 +220,16 @@ std::vector<size_t> ATNSerializer::serialize() {
for (size_t i = 0; i < s->getNumberOfTransitions(); i++) {
Transition *t = s->transition(i);
if (atn->states[(size_t)t->target->stateNumber] == nullptr) {
if (atn->states[t->target->stateNumber] == nullptr) {
throw IllegalStateException("Cannot serialize a transition to a removed state.");
}
int src = s->stateNumber;
int trg = t->target->stateNumber;
int edgeType = t->getSerializationType();
int arg1 = 0;
int arg2 = 0;
int arg3 = 0;
size_t src = s->stateNumber;
size_t trg = t->target->stateNumber;
Transition::SerializationType edgeType = t->getSerializationType();
size_t arg1 = 0;
size_t arg2 = 0;
size_t arg3 = 0;
switch (edgeType) {
case Transition::RULE:
trg = (static_cast<RuleTransition *>(t))->followState->stateNumber;
@ -253,8 +253,8 @@ std::vector<size_t> ATNSerializer::serialize() {
}
break;
case Transition::RANGE:
arg1 = (int)(static_cast<RangeTransition *>(t))->from;
arg2 = (int)(static_cast<RangeTransition *>(t))->to;
arg1 = (static_cast<RangeTransition *>(t))->from;
arg2 = (static_cast<RangeTransition *>(t))->to;
if (arg1 == Token::EOF) {
arg1 = 0;
arg3 = 1;
@ -262,7 +262,7 @@ std::vector<size_t> ATNSerializer::serialize() {
break;
case Transition::ATOM:
arg1 = (int)(static_cast<AtomTransition *>(t))->_label;
arg1 = (static_cast<AtomTransition *>(t))->_label;
if (arg1 == Token::EOF) {
arg1 = 0;
arg3 = 1;
@ -274,7 +274,7 @@ std::vector<size_t> ATNSerializer::serialize() {
ActionTransition *at = static_cast<ActionTransition *>(t);
arg1 = at->ruleIndex;
arg2 = at->actionIndex;
if (arg2 == -1) {
if (arg2 == INVALID_INDEX) {
arg2 = 0xFFFF;
}
@ -288,23 +288,24 @@ std::vector<size_t> ATNSerializer::serialize() {
case Transition::NOT_SET:
arg1 = setIndices[(static_cast<SetTransition *>(t))->set];
break;
case Transition::WILDCARD:
default:
break;
}
data.push_back((size_t)src);
data.push_back((size_t)trg);
data.push_back((size_t)edgeType);
data.push_back((size_t)arg1);
data.push_back((size_t)arg2);
data.push_back((size_t)arg3);
data.push_back(src);
data.push_back(trg);
data.push_back(edgeType);
data.push_back(arg1);
data.push_back(arg2);
data.push_back(arg3);
}
}
size_t ndecisions = atn->decisionToState.size();
data.push_back(ndecisions);
for (DecisionState *decStartState : atn->decisionToState) {
data.push_back((size_t)decStartState->stateNumber);
data.push_back(decStartState->stateNumber);
}
// LEXER ACTIONS
@ -405,7 +406,7 @@ std::string ATNSerializer::decode(const std::wstring &inpdata) {
std::string buf;
int p = 0;
size_t version = (size_t)data[p++];
size_t version = data[p++];
if (version != ATNDeserializer::SERIALIZED_VERSION) {
std::string reason = "Could not deserialize ATN with version " + std::to_string(version) + "(expected " +
std::to_string(ATNDeserializer::SERIALIZED_VERSION) + ").";
@ -425,11 +426,11 @@ std::string ATNSerializer::decode(const std::wstring &inpdata) {
buf.append("max type ").append(std::to_string(maxType)).append("\n");
int nstates = data[p++];
for (int i = 0; i < nstates; i++) {
int stype = data[p++];
size_t stype = data[p++];
if (stype == ATNState::ATN_INVALID_TYPE) { // ignore bad type of states
continue;
}
int ruleIndex = data[p++];
size_t ruleIndex = data[p++];
if (ruleIndex == 0xFFFF) {
ruleIndex = -1;
}
@ -447,13 +448,13 @@ std::string ATNSerializer::decode(const std::wstring &inpdata) {
}
buf.append(std::to_string(i))
.append(":")
.append(ATNState::serializationNames[(size_t)stype])
.append(ATNState::serializationNames[stype])
.append(" ")
.append(std::to_string(ruleIndex))
.append(arg)
.append("\n");
}
int numNonGreedyStates = data[p++];
size_t numNonGreedyStates = data[p++];
p += numNonGreedyStates; // Instead of that useless loop below.
/*
for (int i = 0; i < numNonGreedyStates; i++) {
@ -461,7 +462,7 @@ std::string ATNSerializer::decode(const std::wstring &inpdata) {
}
*/
int numPrecedenceStates = data[p++];
size_t numPrecedenceStates = data[p++];
p += numPrecedenceStates;
/*
for (int i = 0; i < numPrecedenceStates; i++) {
@ -469,11 +470,11 @@ std::string ATNSerializer::decode(const std::wstring &inpdata) {
}
*/
int nrules = data[p++];
for (int i = 0; i < nrules; i++) {
int s = data[p++];
size_t nrules = data[p++];
for (size_t i = 0; i < nrules; i++) {
size_t s = data[p++];
if (atn->grammarType == ATNType::LEXER) {
int arg1 = data[p++];
size_t arg1 = data[p++];
buf.append("rule ")
.append(std::to_string(i))
.append(":")
@ -490,25 +491,25 @@ std::string ATNSerializer::decode(const std::wstring &inpdata) {
.append("\n");
}
}
int nmodes = data[p++];
for (int i = 0; i < nmodes; i++) {
int s = data[p++];
size_t nmodes = data[p++];
for (size_t i = 0; i < nmodes; i++) {
size_t s = data[p++];
buf.append("mode ")
.append(std::to_string(i))
.append(":")
.append(std::to_string(s))
.append("\n");
}
int nsets = data[p++];
for (int i = 0; i < nsets; i++) {
int nintervals = data[p++];
size_t nsets = data[p++];
for (size_t i = 0; i < nsets; i++) {
size_t nintervals = data[p++];
buf.append(std::to_string(i)).append(":");
bool containsEof = data[p++] != 0;
if (containsEof) {
buf.append(getTokenName(Token::EOF));
}
for (int j = 0; j < nintervals; j++) {
for (size_t j = 0; j < nintervals; j++) {
if (containsEof || j > 0) {
buf.append(", ");
}
@ -520,19 +521,19 @@ std::string ATNSerializer::decode(const std::wstring &inpdata) {
}
buf.append("\n");
}
int nedges = data[p++];
for (int i = 0; i < nedges; i++) {
int src = data[p];
int trg = data[p + 1];
int ttype = data[p + 2];
int arg1 = data[p + 3];
int arg2 = data[p + 4];
int arg3 = data[p + 5];
size_t nedges = data[p++];
for (size_t i = 0; i < nedges; i++) {
size_t src = data[p];
size_t trg = data[p + 1];
size_t ttype = data[p + 2];
size_t arg1 = data[p + 3];
size_t arg2 = data[p + 4];
size_t arg3 = data[p + 5];
buf.append(std::to_string(src))
.append("->")
.append(std::to_string(trg))
.append(" ")
.append(Transition::serializationNames[(size_t)ttype])
.append(Transition::serializationNames[ttype])
.append(" ")
.append(std::to_string(arg1))
.append(",")
@ -542,10 +543,10 @@ std::string ATNSerializer::decode(const std::wstring &inpdata) {
.append("\n");
p += 6;
}
int ndecisions = data[p++];
for (int i = 0; i < ndecisions; i++) {
int s = data[p++];
buf.append(std::to_string(i)).append(":").append(std::to_string(s)).append("\n");
size_t ndecisions = data[p++];
for (size_t i = 0; i < ndecisions; i++) {
size_t s = data[p++];
buf += std::to_string(i) + ":" + std::to_string(s) + "\n";
}
if (atn->grammarType == ATNType::LEXER) {
@ -564,12 +565,12 @@ std::string ATNSerializer::decode(const std::wstring &inpdata) {
return buf;
}
std::string ATNSerializer::getTokenName(ssize_t t) {
if (t == -1) {
std::string ATNSerializer::getTokenName(size_t t) {
if (t == Token::EOF) {
return "EOF";
}
if (atn->grammarType == ATNType::LEXER && t >= 0 && t <= 0xFFFF) {
if (atn->grammarType == ATNType::LEXER && t <= 0x10FFFF) {
switch (t) {
case '\n':
return "'\\n'";
@ -587,19 +588,19 @@ std::string ATNSerializer::getTokenName(ssize_t t) {
return "'\\''";
default:
std::string s_hex = antlrcpp::toHexString((int)t);
if (s_hex >= "0" && s_hex <= "7F" &&
!iscntrl((int)t)) {
if (s_hex >= "0" && s_hex <= "7F" && !iscntrl((int)t)) {
return "'" + std::to_string(t) + "'";
}
// turn on the bit above max "\uFFFF" value so that we pad with zeros
// then only take last 4 digits
std::string hex = antlrcpp::toHexString((int)t | 0x10000).substr(1, 4);
// turn on the bit above max "\u10FFFF" value so that we pad with zeros
// then only take last 6 digits
std::string hex = antlrcpp::toHexString((int)t | 0x1000000).substr(1, 6);
std::string unicodeStr = std::string("'\\u") + hex + std::string("'");
return unicodeStr;
}
}
if (_tokenNames.size() > 0 && t >= 0 && t < (ssize_t)_tokenNames.size()) {
if (_tokenNames.size() > 0 && t < _tokenNames.size()) {
return _tokenNames[(size_t)t];
}

View File

@ -69,7 +69,7 @@ namespace atn {
virtual std::vector<size_t> serialize();
virtual std::string decode(const std::wstring& data);
virtual std::string getTokenName(ssize_t t);
virtual std::string getTokenName(size_t t);
/// Used by Java target to encode short/int array as chars in string.
static std::wstring getSerializedAsString(ATN *atn);

View File

@ -39,9 +39,6 @@
using namespace antlr4::atn;
using namespace antlrcpp;
const int ATNState::INITIAL_NUM_TRANSITIONS = 4;
const int ATNState::INVALID_STATE_NUMBER = -1;
ATNState::ATNState() {
}
@ -58,7 +55,7 @@ const std::vector<std::string> ATNState::serializationNames = {
};
size_t ATNState::hashCode() {
return (size_t)stateNumber;
return stateNumber;
}
bool ATNState::operator == (const ATNState &other) {
@ -72,10 +69,10 @@ bool ATNState::isNonGreedyExitState() {
std::string ATNState::toString() const {
std::stringstream ss;
ss << "(ATNState " << std::hex << this << std::dec << ") {" << std::endl;
if (stateNumber < 0 || stateNumber >= (int)serializationNames.size())
if (stateNumber == INVALID_STATE_NUMBER || stateNumber >= serializationNames.size())
ss << " state: INVALID ";
else
ss << " state: " << serializationNames[(size_t)stateNumber];
ss << " state: " << serializationNames[stateNumber];
ss << " (" << stateNumber << ")" << std::endl;
ss << " ruleIndex: " << ruleIndex << std::endl << " epsilonOnlyTransitions: " << epsilonOnlyTransitions << std::endl;
ss << " transistions (" << transitions.size() << "):" << std::endl;
@ -100,7 +97,7 @@ void ATNState::addTransition(Transition *e) {
addTransition((int)transitions.size(), e);
}
void ATNState::addTransition(int index, Transition *e) {
void ATNState::addTransition(size_t index, Transition *e) {
if (transitions.empty()) {
epsilonOnlyTransitions = e->isEpsilon();
} else if (epsilonOnlyTransitions != e->isEpsilon()) {
@ -119,7 +116,7 @@ void ATNState::setTransition(size_t i, Transition *e) {
transitions[i] = e;
}
Transition *ATNState::removeTransition(int index) {
Transition *ATNState::removeTransition(size_t index) {
transitions.erase(transitions.begin() + index);
return nullptr;
}
@ -128,6 +125,6 @@ bool ATNState::onlyHasEpsilonTransitions() {
return epsilonOnlyTransitions;
}
void ATNState::setRuleIndex(int index) {
void ATNState::setRuleIndex(size_t index) {
ruleIndex = index;
}

View File

@ -102,8 +102,8 @@ namespace atn {
virtual ~ATNState();
static const int INITIAL_NUM_TRANSITIONS;
static const int INVALID_STATE_NUMBER;
static const size_t INITIAL_NUM_TRANSITIONS = 4;
static const size_t INVALID_STATE_NUMBER = (size_t)-1;
enum {
ATN_INVALID_TYPE = 0,
@ -124,10 +124,8 @@ namespace atn {
static const std::vector<std::string> serializationNames;
/// Which ATN are we in?
// ml: just a reference to the owner. Set when the state gets added to an ATN.
//const ATN *atn = nullptr;
int stateNumber = INVALID_STATE_NUMBER;
int ruleIndex = 0; // at runtime, we don't have Rule objects
size_t stateNumber = INVALID_STATE_NUMBER;
size_t ruleIndex = 0; // at runtime, we don't have Rule objects
bool epsilonOnlyTransitions = false;
protected:
@ -146,13 +144,13 @@ namespace atn {
virtual std::vector<Transition*> getTransitions();
virtual size_t getNumberOfTransitions();
virtual void addTransition(Transition *e);
virtual void addTransition(int index, Transition *e);
virtual void addTransition(size_t index, Transition *e);
virtual Transition *transition(size_t i);
virtual void setTransition(size_t i, Transition *e);
virtual Transition *removeTransition(int index);
virtual Transition* removeTransition(size_t index);
virtual int getStateType() = 0;
bool onlyHasEpsilonTransitions();
virtual void setRuleIndex(int index);
virtual void setRuleIndex(size_t index);
};

View File

@ -33,15 +33,15 @@
using namespace antlr4::atn;
ActionTransition::ActionTransition(ATNState *target, int ruleIndex)
: Transition(target), ruleIndex(ruleIndex), actionIndex(0), isCtxDependent(false) {
ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex)
: Transition(target), ruleIndex(ruleIndex), actionIndex(INVALID_INDEX), isCtxDependent(false) {
}
ActionTransition::ActionTransition(ATNState *target, int ruleIndex, int actionIndex, bool isCtxDependent)
ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent)
: Transition(target), ruleIndex(ruleIndex), actionIndex(actionIndex), isCtxDependent(isCtxDependent) {
}
int ActionTransition::getSerializationType() const {
Transition::SerializationType ActionTransition::getSerializationType() const {
return ACTION;
}
@ -49,7 +49,7 @@ bool ActionTransition::isEpsilon() const {
return true; // we are to be ignored by analysis 'cept for predicates
}
bool ActionTransition::matches(ssize_t /*symbol*/, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
bool ActionTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
return false;
}

View File

@ -38,19 +38,19 @@ namespace atn {
class ANTLR4CPP_PUBLIC ActionTransition final : public Transition {
public:
const int ruleIndex;
const int actionIndex;
const size_t ruleIndex;
const size_t actionIndex;
const bool isCtxDependent; // e.g., $i ref in action
ActionTransition(ATNState *target, int ruleIndex); //this(target, ruleIndex, -1, false);
ActionTransition(ATNState *target, size_t ruleIndex);
ActionTransition(ATNState *target, int ruleIndex, int actionIndex, bool isCtxDependent);
ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent);
virtual int getSerializationType() const override;
virtual SerializationType getSerializationType() const override;
virtual bool isEpsilon() const override;
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
virtual std::string toString() const override;
};

View File

@ -34,7 +34,7 @@
using namespace antlr4;
using namespace antlr4::atn;
AmbiguityInfo::AmbiguityInfo(int decision, ATNConfigSet *configs, const antlrcpp::BitSet &ambigAlts,
AmbiguityInfo::AmbiguityInfo(size_t decision, ATNConfigSet *configs, const antlrcpp::BitSet &ambigAlts,
TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx)
: DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) {

View File

@ -86,7 +86,7 @@ namespace atn {
/// <param name="fullCtx"> {@code true} if the ambiguity was identified during LL
/// prediction; otherwise, {@code false} if the ambiguity was identified
/// during SLL prediction </param>
AmbiguityInfo(int decision, ATNConfigSet *configs, const antlrcpp::BitSet &ambigAlts, TokenStream *input,
AmbiguityInfo(size_t decision, ATNConfigSet *configs, const antlrcpp::BitSet &ambigAlts, TokenStream *input,
size_t startIndex, size_t stopIndex, bool fullCtx);
};

View File

@ -41,7 +41,7 @@ ArrayPredictionContext::ArrayPredictionContext(Ref<SingletonPredictionContext> c
}
ArrayPredictionContext::ArrayPredictionContext(std::vector<std::weak_ptr<PredictionContext>> parents_,
std::vector<int> const& returnStates)
std::vector<size_t> const& returnStates)
: PredictionContext(calculateHashCode(parents_, returnStates)), parents(makeRef(parents_)), returnStates(returnStates) {
assert(parents.size() > 0);
assert(returnStates.size() > 0);
@ -60,7 +60,7 @@ std::weak_ptr<PredictionContext> ArrayPredictionContext::getParent(size_t index)
return parents[index];
}
int ArrayPredictionContext::getReturnState(size_t index) const {
size_t ArrayPredictionContext::getReturnState(size_t index) const {
return returnStates[index];
}

View File

@ -49,17 +49,17 @@ namespace atn {
const std::vector<Ref<PredictionContext>> parents;
/// Sorted for merge, no duplicates; if present, EMPTY_RETURN_STATE is always last.
const std::vector<int> returnStates;
const std::vector<size_t> returnStates;
ArrayPredictionContext(Ref<SingletonPredictionContext> const& a);
ArrayPredictionContext(std::vector<std::weak_ptr<PredictionContext>> parents_,
std::vector<int> const& returnStates);
std::vector<size_t> const& returnStates);
virtual ~ArrayPredictionContext() {};
virtual bool isEmpty() const override;
virtual size_t size() const override;
virtual std::weak_ptr<PredictionContext> getParent(size_t index) const override;
virtual int getReturnState(size_t index) const override;
virtual size_t getReturnState(size_t index) const override;
bool operator == (const PredictionContext &o) const override;
virtual std::string toString() const override;

View File

@ -37,10 +37,10 @@
using namespace antlr4::misc;
using namespace antlr4::atn;
AtomTransition::AtomTransition(ATNState *target, ssize_t label) : Transition(target), _label(label) {
AtomTransition::AtomTransition(ATNState *target, size_t label) : Transition(target), _label(label) {
}
int AtomTransition::getSerializationType() const {
Transition::SerializationType AtomTransition::getSerializationType() const {
return ATOM;
}
@ -48,7 +48,7 @@ IntervalSet AtomTransition::label() const {
return IntervalSet::of((int)_label);
}
bool AtomTransition::matches(ssize_t symbol, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
bool AtomTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
return _label == symbol;
}

View File

@ -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 ssize_t _label;
const size_t _label;
AtomTransition(ATNState *target, ssize_t label);
AtomTransition(ATNState *target, size_t label);
virtual int getSerializationType() const override;
virtual SerializationType getSerializationType() const override;
virtual misc::IntervalSet label() const override;
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
virtual std::string toString() const override;
};

View File

@ -34,7 +34,7 @@
using namespace antlr4;
using namespace antlr4::atn;
ContextSensitivityInfo::ContextSensitivityInfo(int decision, ATNConfigSet *configs, TokenStream *input,
ContextSensitivityInfo::ContextSensitivityInfo(size_t decision, ATNConfigSet *configs, TokenStream *input,
size_t startIndex, size_t stopIndex)
: DecisionEventInfo(decision, configs, input, startIndex, stopIndex, true) {
}

View File

@ -66,7 +66,7 @@ namespace atn {
/// <param name="startIndex"> The start index for the current prediction </param>
/// <param name="stopIndex"> The index at which the context sensitivity was
/// identified during full-context prediction </param>
ContextSensitivityInfo(int decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex);
ContextSensitivityInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex);
};
} // namespace atn

View File

@ -34,7 +34,7 @@
using namespace antlr4;
using namespace antlr4::atn;
DecisionEventInfo::DecisionEventInfo(int decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex,
DecisionEventInfo::DecisionEventInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex,
size_t stopIndex, bool fullCtx)
: decision(decision), configs(configs), input(input), startIndex(startIndex), stopIndex(stopIndex), fullCtx(fullCtx) {
}

View File

@ -57,7 +57,7 @@ namespace atn {
/// The invoked decision number which this event is related to.
/// </summary>
/// <seealso cref= ATN#decisionToState </seealso>
const int decision;
const size_t decision;
/// <summary>
/// The configuration set containing additional information relevant to the
@ -88,7 +88,7 @@ namespace atn {
/// </summary>
const bool fullCtx;
DecisionEventInfo(int decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex,
DecisionEventInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex,
size_t stopIndex, bool fullCtx);
};

View File

@ -48,7 +48,7 @@ std::weak_ptr<PredictionContext> EmptyPredictionContext::getParent(size_t /*inde
return std::weak_ptr<PredictionContext>();
}
int EmptyPredictionContext::getReturnState(size_t /*index*/) const {
size_t EmptyPredictionContext::getReturnState(size_t /*index*/) const {
return returnState;
}

View File

@ -43,7 +43,7 @@ namespace atn {
virtual bool isEmpty() const override;
virtual size_t size() const override;
virtual std::weak_ptr<PredictionContext> getParent(size_t index) const override;
virtual int getReturnState(size_t index) const override;
virtual size_t getReturnState(size_t index) const override;
virtual std::string toString() const override;
virtual bool operator == (const PredictionContext &o) const override;

View File

@ -33,18 +33,18 @@
using namespace antlr4::atn;
EpsilonTransition::EpsilonTransition(ATNState *target) : EpsilonTransition(target, -1) {
EpsilonTransition::EpsilonTransition(ATNState *target) : EpsilonTransition(target, INVALID_INDEX) {
}
EpsilonTransition::EpsilonTransition(ATNState *target, int outermostPrecedenceReturn)
EpsilonTransition::EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn)
: Transition(target), _outermostPrecedenceReturn(outermostPrecedenceReturn) {
}
int EpsilonTransition::outermostPrecedenceReturn() {
size_t EpsilonTransition::outermostPrecedenceReturn() {
return _outermostPrecedenceReturn;
}
int EpsilonTransition::getSerializationType() const {
Transition::SerializationType EpsilonTransition::getSerializationType() const {
return EPSILON;
}
@ -52,7 +52,7 @@ bool EpsilonTransition::isEpsilon() const {
return true;
}
bool EpsilonTransition::matches(ssize_t /*symbol*/, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
bool EpsilonTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
return false;
}

View File

@ -39,7 +39,7 @@ namespace atn {
class ANTLR4CPP_PUBLIC EpsilonTransition final : public Transition {
public:
EpsilonTransition(ATNState *target);
EpsilonTransition(ATNState *target, int outermostPrecedenceReturn);
EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn);
/**
* @return the rule index of a precedence rule for which this transition is
@ -49,16 +49,16 @@ namespace atn {
* @see ParserATNSimulator#applyPrecedenceFilter(ATNConfigSet)
* @since 4.4.1
*/
int outermostPrecedenceReturn();
virtual int getSerializationType() const override;
size_t outermostPrecedenceReturn();
virtual SerializationType getSerializationType() const override;
virtual bool isEpsilon() const override;
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
virtual std::string toString() const override;
private:
const int _outermostPrecedenceReturn;
const size_t _outermostPrecedenceReturn; // A rule index.
};
} // namespace atn

View File

@ -36,6 +36,6 @@
using namespace antlr4;
using namespace antlr4::atn;
ErrorInfo::ErrorInfo(int decision, ATNConfigSet *configs, TokenStream *input, int startIndex, int stopIndex, bool fullCtx)
ErrorInfo::ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx)
: DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) {
}

View File

@ -61,7 +61,7 @@ namespace atn {
/// <param name="fullCtx"> {@code true} if the syntax error was identified during LL
/// prediction; otherwise, {@code false} if the syntax error was identified
/// during SLL prediction </param>
ErrorInfo(int decision, ATNConfigSet *configs, TokenStream *input, int startIndex, int stopIndex,
ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex,
bool fullCtx);
};

View File

@ -124,16 +124,16 @@ void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, Ref<PredictionContext>
if (ctx != PredictionContext::EMPTY) {
// run thru all possible stack tops in ctx
for (size_t i = 0; i < ctx->size(); i++) {
ATNState *returnState = _atn.states[(size_t)ctx->getReturnState(i)];
ATNState *returnState = _atn.states[ctx->getReturnState(i)];
bool removed = calledRuleStack.test((size_t)returnState->ruleIndex);
bool removed = calledRuleStack.test(returnState->ruleIndex);
auto onExit = finally([removed, &calledRuleStack, returnState] {
if (removed) {
calledRuleStack.set((size_t)returnState->ruleIndex);
calledRuleStack.set(returnState->ruleIndex);
}
});
calledRuleStack[(size_t)returnState->ruleIndex] = false;
calledRuleStack[returnState->ruleIndex] = false;
_LOOK(returnState, stopState, ctx->getParent(i).lock(), look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
}
return;
@ -145,16 +145,16 @@ void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, Ref<PredictionContext>
Transition *t = s->transition(i);
if (is<RuleTransition *>(t)) {
if (calledRuleStack[(size_t)(static_cast<RuleTransition*>(t))->target->ruleIndex]) {
if (calledRuleStack[(static_cast<RuleTransition*>(t))->target->ruleIndex]) {
continue;
}
Ref<PredictionContext> newContext = SingletonPredictionContext::create(ctx, (static_cast<RuleTransition*>(t))->followState->stateNumber);
auto onExit = finally([t, &calledRuleStack] {
calledRuleStack[(size_t)((static_cast<RuleTransition*>(t))->target->ruleIndex)] = false;
calledRuleStack[(static_cast<RuleTransition*>(t))->target->ruleIndex] = false;
});
calledRuleStack.set((size_t)(static_cast<RuleTransition*>(t))->target->ruleIndex);
calledRuleStack.set((static_cast<RuleTransition*>(t))->target->ruleIndex);
_LOOK(t->target, stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
} else if (is<AbstractPredicateTransition *>(t)) {

View File

@ -43,7 +43,7 @@ namespace atn {
public:
/// Special value added to the lookahead sets to indicate that we hit
/// a predicate during analysis if {@code seeThruPreds==false}.
static const int HIT_PRED = Token::INVALID_TYPE;
static const size_t HIT_PRED = Token::INVALID_TYPE;
const atn::ATN &_atn;

View File

@ -77,7 +77,7 @@ bool LexerATNConfig::hasPassedThroughNonGreedyDecision() {
size_t LexerATNConfig::hashCode() const {
size_t hashCode = misc::MurmurHash::initialize(7);
hashCode = misc::MurmurHash::update(hashCode, (size_t)state->stateNumber);
hashCode = misc::MurmurHash::update(hashCode, state->stateNumber);
hashCode = misc::MurmurHash::update(hashCode, (size_t)alt);
hashCode = misc::MurmurHash::update(hashCode, context);
hashCode = misc::MurmurHash::update(hashCode, semanticContext);

View File

@ -90,7 +90,7 @@ void LexerATNSimulator::copyState(LexerATNSimulator *simulator) {
_startIndex = simulator->_startIndex;
}
int LexerATNSimulator::match(CharStream *input, size_t mode) {
size_t LexerATNSimulator::match(CharStream *input, size_t mode) {
match_calls++;
_mode = mode;
ssize_t mark = input->mark();
@ -99,7 +99,7 @@ int LexerATNSimulator::match(CharStream *input, size_t mode) {
input->release(mark);
});
_startIndex = (int)input->index();
_startIndex = input->index();
_prevAccept.reset();
const dfa::DFA &dfa = _decisionToDFA[mode];
if (dfa.s0 == nullptr) {
@ -108,12 +108,12 @@ int LexerATNSimulator::match(CharStream *input, size_t mode) {
return execATN(input, dfa.s0);
}
return -1;
return Token::EOF;
}
void LexerATNSimulator::reset() {
_prevAccept.reset();
_startIndex = -1;
_startIndex = 0;
_line = 1;
_charPositionInLine = 0;
_mode = Lexer::DEFAULT_MODE;
@ -127,7 +127,7 @@ void LexerATNSimulator::clearDFA() {
}
}
int LexerATNSimulator::matchATN(CharStream *input) {
size_t LexerATNSimulator::matchATN(CharStream *input) {
ATNState *startState = (ATNState *)atn.modeToStartState[_mode];
std::unique_ptr<ATNConfigSet> s0_closure = computeStartState(input, startState);
@ -140,19 +140,19 @@ int LexerATNSimulator::matchATN(CharStream *input) {
_decisionToDFA[_mode].s0 = next;
}
int predict = execATN(input, next);
size_t predict = execATN(input, next);
return predict;
}
int LexerATNSimulator::execATN(CharStream *input, dfa::DFAState *ds0) {
size_t LexerATNSimulator::execATN(CharStream *input, dfa::DFAState *ds0) {
if (ds0->isAcceptState) {
// allow zero-length tokens
// ml: in Java code this method uses 3 params. The first is a member var of the class anyway (_prevAccept), so why pass it here?
captureSimState(input, ds0);
}
ssize_t t = input->LA(1);
size_t t = input->LA(1);
dfa::DFAState *s = ds0; // s is current/from DFA state
while (true) { // while more work
@ -204,12 +204,12 @@ int LexerATNSimulator::execATN(CharStream *input, dfa::DFAState *ds0) {
return failOrAccept(input, s->configs.get(), t);
}
dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, ssize_t t) {
if (s->edges.size() == 0 || t < MIN_DFA_EDGE || t > MAX_DFA_EDGE) {
dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, size_t t) {
if (s->edges.empty()|| /*t < MIN_DFA_EDGE ||*/ t > MAX_DFA_EDGE) { // MIN_DFA_EDGE is 0, hence code gives a warning, if left in.
return nullptr;
}
dfa::DFAState *target = s->edges[(size_t)(t - MIN_DFA_EDGE)];
dfa::DFAState *target = s->edges[t - MIN_DFA_EDGE];
#if DEBUG_ATN == 1
if (target != nullptr) {
std::cout << std::string("reuse state ") << s->stateNumber << std::string(" edge to ") << target->stateNumber << std::endl;
@ -219,7 +219,7 @@ dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, ssize
return target;
}
dfa::DFAState *LexerATNSimulator::computeTargetState(CharStream *input, dfa::DFAState *s, ssize_t t) {
dfa::DFAState *LexerATNSimulator::computeTargetState(CharStream *input, dfa::DFAState *s, size_t t) {
OrderedATNConfigSet *reach = new OrderedATNConfigSet(); /* mem-check: deleted on error or managed by new DFA state. */
// if we don't find an existing DFA state
@ -242,22 +242,22 @@ dfa::DFAState *LexerATNSimulator::computeTargetState(CharStream *input, dfa::DFA
return addDFAEdge(s, t, reach);
}
int LexerATNSimulator::failOrAccept(CharStream *input, ATNConfigSet *reach, ssize_t t) {
size_t LexerATNSimulator::failOrAccept(CharStream *input, ATNConfigSet *reach, size_t t) {
if (_prevAccept.dfaState != nullptr) {
Ref<LexerActionExecutor> lexerActionExecutor = _prevAccept.dfaState->lexerActionExecutor;
accept(input, lexerActionExecutor, _startIndex, (size_t)_prevAccept.index, _prevAccept.line, (size_t)_prevAccept.charPos);
accept(input, lexerActionExecutor, _startIndex, _prevAccept.index, _prevAccept.line, _prevAccept.charPos);
return _prevAccept.dfaState->prediction;
} else {
// if no accept and EOF is first char, return EOF
if (t == Token::EOF && input->index() == (size_t)_startIndex) {
if (t == Token::EOF && input->index() == _startIndex) {
return Token::EOF;
}
throw LexerNoViableAltException(_recog, input, (size_t)_startIndex, reach);
throw LexerNoViableAltException(_recog, input, _startIndex, reach);
}
}
void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *closure_, ATNConfigSet *reach, ssize_t t) {
void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *closure_, ATNConfigSet *reach, size_t t) {
// this is used to skip processing for configs which have a lower priority
// than a config that already reached an accept state for the same rule
int skipAlt = ATN::INVALID_ALT_NUMBER;
@ -279,7 +279,7 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
if (target != nullptr) {
Ref<LexerActionExecutor> lexerActionExecutor = std::static_pointer_cast<LexerATNConfig>(c)->getLexerActionExecutor();
if (lexerActionExecutor != nullptr) {
lexerActionExecutor = lexerActionExecutor->fixOffsetBeforeMatch((int)input->index() - _startIndex);
lexerActionExecutor = lexerActionExecutor->fixOffsetBeforeMatch((int)input->index() - (int)_startIndex);
}
bool treatEofAsEpsilon = t == Token::EOF;
@ -297,7 +297,7 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
}
}
void LexerATNSimulator::accept(CharStream *input, const Ref<LexerActionExecutor> &lexerActionExecutor, int /*startIndex*/,
void LexerATNSimulator::accept(CharStream *input, const Ref<LexerActionExecutor> &lexerActionExecutor, size_t /*startIndex*/,
size_t index, size_t line, size_t charPos) {
#if DEBUG_ATN == 1
std::cout << "ACTION ";
@ -314,8 +314,8 @@ void LexerATNSimulator::accept(CharStream *input, const Ref<LexerActionExecutor>
}
}
atn::ATNState *LexerATNSimulator::getReachableTarget(Transition *trans, ssize_t t) {
if (trans->matches((int)t, std::numeric_limits<char32_t>::min(), std::numeric_limits<char32_t>::max())) {
atn::ATNState *LexerATNSimulator::getReachableTarget(Transition *trans, size_t t) {
if (trans->matches(t, Lexer::MIN_CHAR_VALUE, Lexer::MAX_CHAR_VALUE)) {
return trans->target;
}
@ -343,7 +343,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
if (is<RuleStopState *>(config->state)) {
#if DEBUG_ATN == 1
if (_recog != nullptr) {
std::cout << "closure at " << _recog->getRuleNames()[(size_t)config->state->ruleIndex] << " rule stop " << config << std::endl;
std::cout << "closure at " << _recog->getRuleNames()[config->state->ruleIndex] << " rule stop " << config << std::endl;
} else {
std::cout << "closure at rule stop " << config << std::endl;
}
@ -363,7 +363,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
for (size_t i = 0; i < config->context->size(); i++) {
if (config->context->getReturnState(i) != PredictionContext::EMPTY_RETURN_STATE) {
std::weak_ptr<PredictionContext> newContext = config->context->getParent(i); // "pop" return state
ATNState *returnState = atn.states[(size_t)config->context->getReturnState(i)];
ATNState *returnState = atn.states[config->context->getReturnState(i)];
Ref<LexerATNConfig> c = std::make_shared<LexerATNConfig>(config, returnState, newContext.lock());
currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon);
}
@ -479,12 +479,15 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const
}
break;
default: // To silence the compiler. Other transition types are not used here.
break;
}
return c;
}
bool LexerATNSimulator::evaluatePredicate(CharStream *input, int ruleIndex, int predIndex, bool speculative) {
bool LexerATNSimulator::evaluatePredicate(CharStream *input, size_t ruleIndex, size_t predIndex, bool speculative) {
// assume true if no recognizer was provided
if (_recog == nullptr) {
return true;
@ -494,7 +497,7 @@ bool LexerATNSimulator::evaluatePredicate(CharStream *input, int ruleIndex, int
return _recog->sempred(nullptr, ruleIndex, predIndex);
}
int savedCharPositionInLine = _charPositionInLine;
size_t savedCharPositionInLine = _charPositionInLine;
size_t savedLine = _line;
size_t index = input->index();
ssize_t marker = input->mark();
@ -511,13 +514,13 @@ bool LexerATNSimulator::evaluatePredicate(CharStream *input, int ruleIndex, int
}
void LexerATNSimulator::captureSimState(CharStream *input, dfa::DFAState *dfaState) {
_prevAccept.index = (int)input->index();
_prevAccept.index = input->index();
_prevAccept.line = _line;
_prevAccept.charPos = _charPositionInLine;
_prevAccept.dfaState = dfaState;
}
dfa::DFAState *LexerATNSimulator::addDFAEdge(dfa::DFAState *from, ssize_t t, ATNConfigSet *q) {
dfa::DFAState *LexerATNSimulator::addDFAEdge(dfa::DFAState *from, size_t t, ATNConfigSet *q) {
/* leading to this call, ATNConfigSet.hasSemanticContext is used as a
* marker indicating dynamic predicate evaluation makes this edge
* dependent on the specific input sequence, so the static edge in the
@ -542,8 +545,8 @@ dfa::DFAState *LexerATNSimulator::addDFAEdge(dfa::DFAState *from, ssize_t t, ATN
return to;
}
void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, ssize_t t, dfa::DFAState *q) {
if (t < MIN_DFA_EDGE || t > MAX_DFA_EDGE) {
void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, size_t t, dfa::DFAState *q) {
if (/*t < MIN_DFA_EDGE ||*/ t > MAX_DFA_EDGE) { // MIN_DFA_EDGE is 0
// Only track edges within the DFA bounds
return;
}
@ -599,7 +602,7 @@ dfa::DFA& LexerATNSimulator::getDFA(size_t mode) {
std::string LexerATNSimulator::getText(CharStream *input) {
// index is first lookahead char, don't include.
return input->getText(misc::Interval((int)_startIndex, (int)input->index() - 1));
return input->getText(misc::Interval(_startIndex, input->index() - 1));
}
size_t LexerATNSimulator::getLine() const {
@ -610,16 +613,16 @@ void LexerATNSimulator::setLine(size_t line) {
_line = line;
}
int LexerATNSimulator::getCharPositionInLine() {
size_t LexerATNSimulator::getCharPositionInLine() {
return _charPositionInLine;
}
void LexerATNSimulator::setCharPositionInLine(int charPositionInLine) {
void LexerATNSimulator::setCharPositionInLine(size_t charPositionInLine) {
_charPositionInLine = charPositionInLine;
}
void LexerATNSimulator::consume(CharStream *input) {
ssize_t curChar = input->LA(1);
size_t curChar = input->LA(1);
if (curChar == '\n') {
_line++;
_charPositionInLine = 0;
@ -629,16 +632,15 @@ void LexerATNSimulator::consume(CharStream *input) {
input->consume();
}
std::string LexerATNSimulator::getTokenName(int t) {
if (t == -1) {
std::string LexerATNSimulator::getTokenName(size_t t) {
if (t == Token::EOF) {
return "EOF";
}
//if ( atn.g!=null ) return atn.g.getTokenDisplayName(t);
return std::string("'") + static_cast<char>(t) + std::string("'");
}
void LexerATNSimulator::InitializeInstanceFields() {
_startIndex = -1;
_startIndex = 0;
_line = 1;
_charPositionInLine = 0;
_mode = antlr4::Lexer::DEFAULT_MODE;

View File

@ -46,9 +46,9 @@ namespace atn {
virtual ~SimState() {};
protected:
int index;
size_t index;
size_t line;
int charPos;
size_t charPos;
dfa::DFAState *dfaState;
virtual void reset();
friend class LexerATNSimulator;
@ -64,9 +64,10 @@ namespace atn {
public:
static const int MIN_DFA_EDGE = 0;
static const int MAX_DFA_EDGE = 127; // forces unicode to stay in ATN
static const size_t MIN_DFA_EDGE = 0;
static const size_t MAX_DFA_EDGE = 127; // forces unicode to stay in ATN
protected:
/// <summary>
/// When we hit an accept state in either the DFA or the ATN, we
/// have to notify the character stream to start buffering characters
@ -83,24 +84,19 @@ namespace atn {
/// then the ATN does the accept and the DFA simulator that invoked it
/// can simply return the predicted token type.
/// </summary>
protected:
Lexer *const _recog;
/// <summary>
/// The current token's starting index into the character stream.
/// Shared across DFA to ATN simulation in case the ATN fails and the
/// DFA did not have a previous accept state. In this case, we use the
/// ATN-generated exception object.
/// </summary>
int _startIndex;
size_t _startIndex;
/// <summary>
/// line number 1..n within the input </summary>
/// line number 1..n within the input.
size_t _line;
/// <summary>
/// The index of the character relative to the beginning of the line 0..n-1 </summary>
int _charPositionInLine;
/// The index of the character relative to the beginning of the line 0..n-1.
size_t _charPositionInLine;
public:
std::vector<dfa::DFA> &_decisionToDFA;
@ -120,14 +116,14 @@ namespace atn {
PredictionContextCache &sharedContextCache);
virtual void copyState(LexerATNSimulator *simulator);
virtual int match(CharStream *input, size_t mode);
virtual size_t match(CharStream *input, size_t mode);
virtual void reset() override;
virtual void clearDFA() override;
protected:
virtual int matchATN(CharStream *input);
virtual int execATN(CharStream *input, dfa::DFAState *ds0);
virtual size_t matchATN(CharStream *input);
virtual size_t execATN(CharStream *input, dfa::DFAState *ds0);
/// <summary>
/// Get an existing target state for an edge in the DFA. If the target state
@ -139,7 +135,7 @@ namespace atn {
/// <returns> The existing target DFA state for the given input symbol
/// {@code t}, or {@code null} if the target state for this edge is not
/// already cached </returns>
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *s, ssize_t t);
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *s, size_t t);
/// <summary>
/// Compute a target state for an edge in the DFA, and attempt to add the
@ -152,9 +148,9 @@ namespace atn {
/// <returns> The computed target DFA state for the given input symbol
/// {@code t}. If {@code t} does not lead to a valid DFA state, this method
/// returns <seealso cref="#ERROR"/>. </returns>
virtual dfa::DFAState *computeTargetState(CharStream *input, dfa::DFAState *s, ssize_t t);
virtual dfa::DFAState *computeTargetState(CharStream *input, dfa::DFAState *s, size_t t);
virtual int failOrAccept(CharStream *input, ATNConfigSet *reach, ssize_t t);
virtual size_t failOrAccept(CharStream *input, ATNConfigSet *reach, size_t t);
/// <summary>
/// Given a starting configuration set, figure out all ATN configurations
@ -162,12 +158,12 @@ namespace atn {
/// parameter.
/// </summary>
void getReachableConfigSet(CharStream *input, ATNConfigSet *closure_, // closure_ as we have a closure() already
ATNConfigSet *reach, ssize_t t);
ATNConfigSet *reach, size_t t);
virtual void accept(CharStream *input, const Ref<LexerActionExecutor> &lexerActionExecutor, int startIndex, size_t index,
virtual void accept(CharStream *input, const Ref<LexerActionExecutor> &lexerActionExecutor, size_t startIndex, size_t index,
size_t line, size_t charPos);
virtual ATNState *getReachableTarget(Transition *trans, ssize_t t);
virtual ATNState *getReachableTarget(Transition *trans, size_t t);
virtual std::unique_ptr<ATNConfigSet> computeStartState(CharStream *input, ATNState *p);
@ -207,11 +203,11 @@ namespace atn {
/// </param>
/// <returns> {@code true} if the specified predicate evaluates to
/// {@code true}. </returns>
virtual bool evaluatePredicate(CharStream *input, int ruleIndex, int predIndex, bool speculative);
virtual bool evaluatePredicate(CharStream *input, size_t ruleIndex, size_t predIndex, bool speculative);
virtual void captureSimState(CharStream *input, dfa::DFAState *dfaState);
virtual dfa::DFAState* addDFAEdge(dfa::DFAState *from, ssize_t t, ATNConfigSet *q);
virtual void addDFAEdge(dfa::DFAState *p, ssize_t t, dfa::DFAState *q);
virtual dfa::DFAState* addDFAEdge(dfa::DFAState *from, size_t t, ATNConfigSet *q);
virtual void addDFAEdge(dfa::DFAState *p, size_t t, dfa::DFAState *q);
/// <summary>
/// Add a new DFA state if there isn't one with this set of
@ -228,10 +224,10 @@ namespace atn {
virtual std::string getText(CharStream *input);
virtual size_t getLine() const;
virtual void setLine(size_t line);
virtual int getCharPositionInLine();
virtual void setCharPositionInLine(int charPositionInLine);
virtual size_t getCharPositionInLine();
virtual void setCharPositionInLine(size_t charPositionInLine);
virtual void consume(CharStream *input);
virtual std::string getTokenName(int t);
virtual std::string getTokenName(size_t t);
private:
void InitializeInstanceFields();

View File

@ -79,7 +79,7 @@ std::vector<Ref<LexerAction>> LexerActionExecutor::getLexerActions() const {
return _lexerActions;
}
void LexerActionExecutor::execute(Lexer *lexer, CharStream *input, int startIndex) {
void LexerActionExecutor::execute(Lexer *lexer, CharStream *input, size_t startIndex) {
bool requiresSeek = false;
size_t stopIndex = input->index();
@ -93,7 +93,7 @@ void LexerActionExecutor::execute(Lexer *lexer, CharStream *input, int startInde
int offset = (std::static_pointer_cast<LexerIndexedCustomAction>(lexerAction))->getOffset();
input->seek(startIndex + offset);
lexerAction = std::static_pointer_cast<LexerIndexedCustomAction>(lexerAction)->getAction();
requiresSeek = (size_t)(startIndex + offset) != stopIndex;
requiresSeek = (startIndex + offset) != stopIndex;
} else if (lexerAction->isPositionDependent()) {
input->seek(stopIndex);
requiresSeek = false;

View File

@ -121,7 +121,7 @@ namespace atn {
/// <param name="startIndex"> The token start index. This value may be passed to
/// <seealso cref="IntStream#seek"/> to set the {@code input} position to the beginning
/// of the token. </param>
virtual void execute(Lexer *lexer, CharStream *input, int startIndex);
virtual void execute(Lexer *lexer, CharStream *input, size_t startIndex);
virtual size_t hashCode() const;
virtual bool operator == (const LexerActionExecutor &obj) const;

View File

@ -39,11 +39,11 @@ using namespace antlr4::atn;
NotSetTransition::NotSetTransition(ATNState *target, const misc::IntervalSet &set) : SetTransition(target, set) {
}
int NotSetTransition::getSerializationType() const {
Transition::SerializationType NotSetTransition::getSerializationType() const {
return NOT_SET;
}
bool NotSetTransition::matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const {
bool NotSetTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const {
return symbol >= minVocabSymbol && symbol <= maxVocabSymbol
&& !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol);
}

View File

@ -40,9 +40,9 @@ namespace atn {
public:
NotSetTransition(ATNState *target, const misc::IntervalSet &set);
virtual int getSerializationType() const override;
virtual SerializationType getSerializationType() const override;
virtual bool matches(ssize_t symbol, ssize_t minVocabSymbol, ssize_t maxVocabSymbol) const override;
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
virtual std::string toString() const override;
};

View File

@ -87,16 +87,17 @@ void ParserATNSimulator::clearDFA() {
}
}
int ParserATNSimulator::adaptivePredict(TokenStream *input, int decision, Ref<ParserRuleContext> const& outerContext) {
size_t ParserATNSimulator::adaptivePredict(TokenStream *input, size_t decision, Ref<ParserRuleContext> const& outerContext) {
#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();
_startIndex = input->index();
_outerContext = outerContext;
dfa::DFA &dfa = decisionToDFA[(size_t)decision];
dfa::DFA &dfa = decisionToDFA[decision];
_dfa = &dfa;
ssize_t m = input->mark();
@ -151,13 +152,14 @@ int ParserATNSimulator::adaptivePredict(TokenStream *input, int decision, Ref<Pa
}
// We can start with an existing DFA.
int alt = execATN(dfa, s0, input, index, outerContext != nullptr ? outerContext : ParserRuleContext::EMPTY);
size_t alt = execATN(dfa, s0, input, index, outerContext != nullptr ? outerContext : ParserRuleContext::EMPTY);
return alt;
}
int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *input, size_t startIndex,
size_t ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *input, size_t startIndex,
Ref<ParserRuleContext> outerContext) {
#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;
@ -169,7 +171,7 @@ int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *i
std::cout << "s0 = " << s0 << std::endl;
#endif
ssize_t t = input->LA(1);
size_t t = input->LA(1);
while (true) { // while more work
dfa::DFAState *D = getExistingTargetState(previousD, t);
@ -189,7 +191,7 @@ int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *i
// will get error no matter what.
NoViableAltException e = noViableAlt(input, outerContext, previousD->configs.get(), startIndex);
input->seek(startIndex);
int alt = getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previousD->configs.get(), outerContext);
size_t alt = getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previousD->configs.get(), outerContext);
if (alt != ATN::INVALID_ALT_NUMBER) {
return alt;
}
@ -206,8 +208,8 @@ int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *i
#endif
size_t conflictIndex = input->index();
if (conflictIndex != (size_t)startIndex) {
input->seek((size_t)startIndex);
if (conflictIndex != startIndex) {
input->seek(startIndex);
}
conflictingAlts = evalSemanticContext(D->predicates, outerContext, true);
@ -233,7 +235,7 @@ int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *i
bool fullCtx = true;
Ref<ATNConfigSet> s0_closure = computeStartState(dfa.atnStartState, outerContext, fullCtx);
reportAttemptingFullContext(dfa, conflictingAlts, D->configs.get(), startIndex, input->index());
int alt = execATNWithFullContext(dfa, D, s0_closure.get(), input, startIndex, outerContext);
size_t alt = execATNWithFullContext(dfa, D, s0_closure.get(), input, startIndex, outerContext);
return alt;
}
@ -269,7 +271,7 @@ int ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *i
}
}
dfa::DFAState *ParserATNSimulator::getExistingTargetState(dfa::DFAState *previousD, ssize_t t) {
dfa::DFAState *ParserATNSimulator::getExistingTargetState(dfa::DFAState *previousD, size_t t) {
auto iterator = previousD->edges.find(t);
if (iterator == previousD->edges.end()) {
return nullptr;
@ -278,7 +280,7 @@ dfa::DFAState *ParserATNSimulator::getExistingTargetState(dfa::DFAState *previou
return iterator->second;
}
dfa::DFAState *ParserATNSimulator::computeTargetState(dfa::DFA &dfa, dfa::DFAState *previousD, ssize_t t) {
dfa::DFAState *ParserATNSimulator::computeTargetState(dfa::DFA &dfa, dfa::DFAState *previousD, size_t t) {
std::unique_ptr<ATNConfigSet> reach = computeReachSet(previousD->configs.get(), t, false);
if (reach == nullptr) {
addDFAEdge(dfa, previousD, t, ERROR.get());
@ -338,7 +340,7 @@ void ParserATNSimulator::predicateDFAState(dfa::DFAState *dfaState, DecisionStat
}
}
int ParserATNSimulator::execATNWithFullContext(dfa::DFA &dfa, dfa::DFAState *D, ATNConfigSet *s0,
size_t ParserATNSimulator::execATNWithFullContext(dfa::DFA &dfa, dfa::DFAState *D, ATNConfigSet *s0,
TokenStream *input, size_t startIndex, Ref<ParserRuleContext> const& outerContext) {
bool fullCtx = true;
@ -347,8 +349,8 @@ int ParserATNSimulator::execATNWithFullContext(dfa::DFA &dfa, dfa::DFAState *D,
std::unique_ptr<ATNConfigSet> reach;
ATNConfigSet *previous = s0;
input->seek(startIndex);
ssize_t t = input->LA(1);
int predictedAlt;
size_t t = input->LA(1);
size_t predictedAlt;
while (true) {
reach = computeReachSet(previous, t, fullCtx);
@ -364,7 +366,7 @@ int ParserATNSimulator::execATNWithFullContext(dfa::DFA &dfa, dfa::DFAState *D,
// will get error no matter what.
NoViableAltException e = noViableAlt(input, outerContext, previous, startIndex);
input->seek(startIndex);
int alt = getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previous, outerContext);
size_t alt = getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previous, outerContext);
if (alt != ATN::INVALID_ALT_NUMBER) {
return alt;
}
@ -441,12 +443,12 @@ int ParserATNSimulator::execATNWithFullContext(dfa::DFA &dfa, dfa::DFAState *D,
the fact that we should predict alternative 1. We just can't say for
sure that there is an ambiguity without looking further.
*/
reportAmbiguity(dfa, D, (size_t)startIndex, input->index(), foundExactAmbig, reach->getAlts(), reach.get());
reportAmbiguity(dfa, D, startIndex, input->index(), foundExactAmbig, reach->getAlts(), reach.get());
return predictedAlt;
}
std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *closure_, ssize_t t, bool fullCtx) {
std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *closure_, size_t t, bool fullCtx) {
std::unique_ptr<ATNConfigSet> intermediate(new ATNConfigSet(fullCtx));
@ -585,7 +587,7 @@ ATNConfigSet* ParserATNSimulator::removeAllConfigsNotInRuleStopState(ATNConfigSe
if (lookToEndOfRule && config->state->onlyHasEpsilonTransitions()) {
misc::IntervalSet nextTokens = atn.nextTokens(config->state);
if (nextTokens.contains(Token::EPSILON)) {
ATNState *endOfRuleState = atn.ruleToStopState[(size_t)config->state->ruleIndex];
ATNState *endOfRuleState = atn.ruleToStopState[config->state->ruleIndex];
result->add(std::make_shared<ATNConfig>(config, endOfRuleState), &mergeCache);
}
}
@ -610,7 +612,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeStartState(ATNState *p,
}
std::unique_ptr<ATNConfigSet> ParserATNSimulator::applyPrecedenceFilter(ATNConfigSet *configs) {
std::map<int, Ref<PredictionContext>> statesFromAlt1;
std::map<size_t, Ref<PredictionContext>> statesFromAlt1;
std::unique_ptr<ATNConfigSet> configSet(new ATNConfigSet(configs->fullCtx));
for (Ref<ATNConfig> &config : configs->configs) {
// handle alt 1 first
@ -657,8 +659,8 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::applyPrecedenceFilter(ATNConfi
return configSet;
}
atn::ATNState* ParserATNSimulator::getReachableTarget(Transition *trans, int ttype) {
if (trans->matches(ttype, 0, (int)atn.maxTokenType)) {
atn::ATNState* ParserATNSimulator::getReachableTarget(Transition *trans, size_t ttype) {
if (trans->matches(ttype, 0, atn.maxTokenType)) {
return trans->target;
}
@ -733,13 +735,13 @@ std::vector<dfa::DFAState::PredPrediction *> ParserATNSimulator::getPredicatePre
return pairs;
}
int ParserATNSimulator::getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(ATNConfigSet *configs,
size_t ParserATNSimulator::getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(ATNConfigSet *configs,
Ref<ParserRuleContext> const& outerContext)
{
std::pair<ATNConfigSet *, ATNConfigSet *> sets = splitAccordingToSemanticValidity(configs, outerContext);
std::unique_ptr<ATNConfigSet> semValidConfigs(sets.first);
std::unique_ptr<ATNConfigSet> semInvalidConfigs(sets.second);
int alt = getAltThatFinishedDecisionEntryRule(semValidConfigs.get());
size_t alt = getAltThatFinishedDecisionEntryRule(semValidConfigs.get());
if (alt != ATN::INVALID_ALT_NUMBER) { // semantically/syntactically viable path exists
return alt;
}
@ -753,7 +755,7 @@ int ParserATNSimulator::getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(
return ATN::INVALID_ALT_NUMBER;
}
int ParserATNSimulator::getAltThatFinishedDecisionEntryRule(ATNConfigSet *configs) {
size_t ParserATNSimulator::getAltThatFinishedDecisionEntryRule(ATNConfigSet *configs) {
misc::IntervalSet alts;
for (auto &c : configs->configs) {
if (c->getOuterContextDepth() > 0 || (is<RuleStopState *>(c->state) && c->context->hasEmptyPath())) {
@ -852,13 +854,13 @@ void ParserATNSimulator::closureCheckingStopState(Ref<ATNConfig> const& config,
} else {
// we have no context info, just chase follow links (if greedy)
#if DEBUG_ATN == 1
std::cout << "FALLING off rule " << getRuleName((size_t)config->state->ruleIndex) << std::endl;
std::cout << "FALLING off rule " << getRuleName(config->state->ruleIndex) << std::endl;
#endif
closure_(config, configs, closureBusy, collectPredicates, fullCtx, depth, treatEofAsEpsilon);
}
continue;
}
ATNState *returnState = atn.states[(size_t)config->context->getReturnState(i)];
ATNState *returnState = atn.states[config->context->getReturnState(i)];
std::weak_ptr<PredictionContext> newContext = config->context->getParent(i); // "pop" return state
Ref<ATNConfig> c = std::make_shared<ATNConfig>(returnState, config->alt, newContext.lock(), config->semanticContext);
// While we have context to pop back from, we may have
@ -927,7 +929,7 @@ void ParserATNSimulator::closure_(Ref<ATNConfig> const& config, ATNConfigSet *co
closureBusy.insert(c);
if (_dfa != nullptr && _dfa->isPrecedenceDfa()) {
int outermostPrecedenceReturn = dynamic_cast<EpsilonTransition *>(t)->outermostPrecedenceReturn();
size_t outermostPrecedenceReturn = dynamic_cast<EpsilonTransition *>(t)->outermostPrecedenceReturn();
if (outermostPrecedenceReturn == _dfa->atnStartState->ruleIndex) {
c->setPrecedenceFilterSuppressed(true);
}
@ -1024,7 +1026,7 @@ Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& co
// the config sets. It also obviates the need to test predicates
// later during conflict resolution.
size_t currentPosition = _input->index();
_input->seek((size_t)_startIndex);
_input->seek(_startIndex);
bool predSucceeds = evalSemanticContext(pt->getPredicate(), _outerContext, config->alt, fullCtx);
_input->seek(currentPosition);
if (predSucceeds) {
@ -1063,7 +1065,7 @@ Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config,
// the config sets. It also obviates the need to test predicates
// later during conflict resolution.
size_t currentPosition = _input->index();
_input->seek((size_t)_startIndex);
_input->seek(_startIndex);
bool predSucceeds = evalSemanticContext(pt->getPredicate(), _outerContext, config->alt, fullCtx);
_input->seek(currentPosition);
if (predSucceeds) {
@ -1086,7 +1088,7 @@ Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config,
Ref<ATNConfig> ParserATNSimulator::ruleTransition(Ref<ATNConfig> const& config, RuleTransition *t) {
#if DEBUG_DFA == 1
std::cout << "CALL rule " << getRuleName((size_t)t->target->ruleIndex) << ", ctx=" << config->context << std::endl;
std::cout << "CALL rule " << getRuleName(t->target->ruleIndex) << ", ctx=" << config->context << std::endl;
#endif
atn::ATNState *returnState = t->followState;
@ -1109,7 +1111,7 @@ BitSet ParserATNSimulator::getConflictingAltsOrUniqueAlt(ATNConfigSet *configs)
return conflictingAlts;
}
std::string ParserATNSimulator::getTokenName(ssize_t t) {
std::string ParserATNSimulator::getTokenName(size_t t) {
if (t == Token::EOF) {
return "EOF";
}
@ -1236,10 +1238,10 @@ void ParserATNSimulator::reportAttemptingFullContext(dfa::DFA &dfa, const antlrc
}
}
void ParserATNSimulator::reportContextSensitivity(dfa::DFA &dfa, int prediction, ATNConfigSet *configs,
void ParserATNSimulator::reportContextSensitivity(dfa::DFA &dfa, size_t prediction, ATNConfigSet *configs,
size_t startIndex, size_t stopIndex) {
#if DEBUG_DFA == 1 || RETRY_DEBUG == 1
misc::Interval interval = misc::Interval((int)startIndex, (int)stopIndex);
misc::Interval interval = misc::Interval(startIndex, stopIndex);
std::cout << "reportContextSensitivity decision=" << dfa.decision << ":" << configs << ", input=" << parser->getTokenStream()->getText(interval) << std::endl;
#endif

View File

@ -297,7 +297,7 @@ namespace atn {
// LAME globals to avoid parameters!!!!! I need these down deep in predTransition
TokenStream *_input;
int _startIndex;
size_t _startIndex;
Ref<ParserRuleContext> _outerContext;
dfa::DFA *_dfa; // Reference into the decisionToDFA vector.
@ -311,7 +311,7 @@ namespace atn {
virtual void reset() override;
virtual void clearDFA() override;
virtual int adaptivePredict(TokenStream *input, int decision, Ref<ParserRuleContext> const& outerContext);
virtual size_t adaptivePredict(TokenStream *input, size_t decision, Ref<ParserRuleContext> const& outerContext);
/// <summary>
/// Performs ATN simulation to compute a predicted alternative based
@ -345,7 +345,7 @@ namespace atn {
/// conflict + preds
/// </summary>
protected:
virtual int execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *input, size_t startIndex,
virtual size_t execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream *input, size_t startIndex,
Ref<ParserRuleContext> outerContext);
/// <summary>
@ -358,7 +358,7 @@ namespace atn {
/// <returns> The existing target DFA state for the given input symbol
/// {@code t}, or {@code null} if the target state for this edge is not
/// already cached </returns>
virtual dfa::DFAState* getExistingTargetState(dfa::DFAState *previousD, ssize_t t);
virtual dfa::DFAState* getExistingTargetState(dfa::DFAState *previousD, size_t t);
/// <summary>
/// Compute a target state for an edge in the DFA, and attempt to add the
@ -371,15 +371,15 @@ namespace atn {
/// <returns> The computed target DFA state for the given input symbol
/// {@code t}. If {@code t} does not lead to a valid DFA state, this method
/// returns <seealso cref="#ERROR"/>. </returns>
virtual dfa::DFAState *computeTargetState(dfa::DFA &dfa, dfa::DFAState *previousD, ssize_t t);
virtual dfa::DFAState *computeTargetState(dfa::DFA &dfa, dfa::DFAState *previousD, size_t t);
virtual void predicateDFAState(dfa::DFAState *dfaState, DecisionState *decisionState);
// comes back with reach.uniqueAlt set to a valid alt
virtual int execATNWithFullContext(dfa::DFA &dfa, dfa::DFAState *D, ATNConfigSet *s0,
virtual size_t execATNWithFullContext(dfa::DFA &dfa, dfa::DFAState *D, ATNConfigSet *s0,
TokenStream *input, size_t startIndex, Ref<ParserRuleContext> const& outerContext); // how far we got before failing over
virtual std::unique_ptr<ATNConfigSet> computeReachSet(ATNConfigSet *closure, ssize_t t, bool fullCtx);
virtual std::unique_ptr<ATNConfigSet> computeReachSet(ATNConfigSet *closure, size_t t, bool fullCtx);
/// <summary>
/// Return a configuration set containing only the configurations from
@ -573,7 +573,7 @@ namespace atn {
*/
std::unique_ptr<ATNConfigSet> applyPrecedenceFilter(ATNConfigSet *configs);
virtual ATNState *getReachableTarget(Transition *trans, int ttype);
virtual ATNState *getReachableTarget(Transition *trans, size_t ttype);
virtual std::vector<Ref<SemanticContext>> getPredsForAmbigAlts(const antlrcpp::BitSet &ambigAlts,
ATNConfigSet *configs, size_t nalts);
@ -627,10 +627,10 @@ namespace atn {
* {@link ATN#INVALID_ALT_NUMBER} if a suitable alternative was not
* identified and {@link #adaptivePredict} should report an error instead.
*/
int getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(ATNConfigSet *configs,
size_t getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(ATNConfigSet *configs,
Ref<ParserRuleContext> const& outerContext);
virtual int getAltThatFinishedDecisionEntryRule(ATNConfigSet *configs);
virtual size_t getAltThatFinishedDecisionEntryRule(ATNConfigSet *configs);
/** Walk the list of configurations and split them according to
* those that have preds evaluating to true/false. If no pred, assume
@ -773,7 +773,7 @@ namespace atn {
virtual antlrcpp::BitSet getConflictingAltsOrUniqueAlt(ATNConfigSet *configs);
public:
virtual std::string getTokenName(ssize_t t);
virtual std::string getTokenName(size_t t);
virtual std::string getLookaheadName(TokenStream *input);
@ -830,7 +830,7 @@ namespace atn {
virtual void reportAttemptingFullContext(dfa::DFA &dfa, const antlrcpp::BitSet &conflictingAlts,
ATNConfigSet *configs, size_t startIndex, size_t stopIndex);
virtual void reportContextSensitivity(dfa::DFA &dfa, int prediction, ATNConfigSet *configs,
virtual void reportContextSensitivity(dfa::DFA &dfa, size_t prediction, ATNConfigSet *configs,
size_t startIndex, size_t stopIndex);
/// If context sensitive parsing, we know it's ambiguity not conflict.

View File

@ -37,7 +37,7 @@ PrecedencePredicateTransition::PrecedencePredicateTransition(ATNState *target, i
: AbstractPredicateTransition(target), precedence(precedence) {
}
int PrecedencePredicateTransition::getSerializationType() const {
Transition::SerializationType PrecedencePredicateTransition::getSerializationType() const {
return PRECEDENCE;
}
@ -45,7 +45,7 @@ bool PrecedencePredicateTransition::isEpsilon() const {
return true;
}
bool PrecedencePredicateTransition::matches(ssize_t /*symbol*/, ssize_t /*minVocabSymbol*/, ssize_t /*maxVocabSymbol*/) const {
bool PrecedencePredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
return false;
}

Some files were not shown because too many files have changed in this diff Show More