diff --git a/contributors.txt b/contributors.txt
index a629610e3..71e97419e 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -148,4 +148,5 @@ YYYY/MM/DD, github id, Full name, email
2017/05/11, jimallman, Jim Allman, jim@ibang.com
2017/05/26, waf, Will Fuqua, wafuqua@gmail.com
2017/05/29, kosak, Corey Kosak, kosak@kosak.com
+2017/06/10, jm-mikkelsen, Jan Martin Mikkelsen, janm@transactionware.com
2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
diff --git a/runtime/Cpp/runtime/src/ANTLRErrorListener.cpp b/runtime/Cpp/runtime/src/ANTLRErrorListener.cpp
new file mode 100644
index 000000000..ab0d40328
--- /dev/null
+++ b/runtime/Cpp/runtime/src/ANTLRErrorListener.cpp
@@ -0,0 +1,5 @@
+#include "ANTLRErrorListener.h"
+
+antlr4::ANTLRErrorListener::~ANTLRErrorListener()
+{
+}
diff --git a/runtime/Cpp/runtime/src/ANTLRErrorListener.h b/runtime/Cpp/runtime/src/ANTLRErrorListener.h
index a8340d586..d6efad1d9 100755
--- a/runtime/Cpp/runtime/src/ANTLRErrorListener.h
+++ b/runtime/Cpp/runtime/src/ANTLRErrorListener.h
@@ -16,7 +16,7 @@ namespace antlr4 {
/// How to emit recognition errors (an interface in Java).
class ANTLR4CPP_PUBLIC ANTLRErrorListener {
public:
- virtual ~ANTLRErrorListener() {};
+ virtual ~ANTLRErrorListener();
///
/// Upon syntax error, notify any interested parties. This is not how to
diff --git a/runtime/Cpp/runtime/src/ANTLRErrorStrategy.cpp b/runtime/Cpp/runtime/src/ANTLRErrorStrategy.cpp
new file mode 100644
index 000000000..04af575c3
--- /dev/null
+++ b/runtime/Cpp/runtime/src/ANTLRErrorStrategy.cpp
@@ -0,0 +1,5 @@
+#include "ANTLRErrorStrategy.h"
+
+antlr4::ANTLRErrorStrategy::~ANTLRErrorStrategy()
+{
+}
diff --git a/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h b/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h
index 4e3297ff2..67576c607 100755
--- a/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h
+++ b/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h
@@ -32,7 +32,7 @@ namespace antlr4 {
///
/// Reset the error handler state for the specified {@code recognizer}.
/// the parser instance
- virtual ~ANTLRErrorStrategy() {};
+ virtual ~ANTLRErrorStrategy();
virtual void reset(Parser *recognizer) = 0;
diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp
index 714ea3ab1..a5e21618e 100755
--- a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp
+++ b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp
@@ -71,7 +71,7 @@ size_t ANTLRInputStream::LA(ssize_t i) {
return 0; // undefined
}
- ssize_t position = (ssize_t)p;
+ ssize_t position = static_cast(p);
if (i < 0) {
i++; // e.g., translate LA(-1) to use offset i=0; then _data[p+0-1]
if ((position + i - 1) < 0) {
@@ -79,11 +79,11 @@ size_t ANTLRInputStream::LA(ssize_t i) {
}
}
- if ((position + i - 1) >= (ssize_t)_data.size()) {
+ if ((position + i - 1) >= static_cast(_data.size())) {
return IntStream::EOF;
}
- return _data[(size_t)(position + i - 1)];
+ return _data[static_cast((position + i - 1))];
}
size_t ANTLRInputStream::LT(ssize_t i) {
@@ -123,8 +123,8 @@ std::string ANTLRInputStream::getText(const Interval &interval) {
return "";
}
- size_t start = interval.a;
- size_t stop = interval.b;
+ size_t start = static_cast(interval.a);
+ size_t stop = static_cast(interval.b);
if (stop >= _data.size()) {
diff --git a/runtime/Cpp/runtime/src/BailErrorStrategy.cpp b/runtime/Cpp/runtime/src/BailErrorStrategy.cpp
index 16fc26058..5fbc01161 100755
--- a/runtime/Cpp/runtime/src/BailErrorStrategy.cpp
+++ b/runtime/Cpp/runtime/src/BailErrorStrategy.cpp
@@ -18,7 +18,7 @@ void BailErrorStrategy::recover(Parser *recognizer, std::exception_ptr e) {
context->exception = e;
if (context->parent == nullptr)
break;
- context = (ParserRuleContext *)context->parent;
+ context = static_cast(context->parent);
} while (true);
try {
@@ -42,7 +42,7 @@ Token* BailErrorStrategy::recoverInline(Parser *recognizer) {
context->exception = exception;
if (context->parent == nullptr)
break;
- context = (ParserRuleContext *)context->parent;
+ context = static_cast(context->parent);
} while (true);
try {
diff --git a/runtime/Cpp/runtime/src/BufferedTokenStream.cpp b/runtime/Cpp/runtime/src/BufferedTokenStream.cpp
index 752f5452b..d2a88dd6c 100755
--- a/runtime/Cpp/runtime/src/BufferedTokenStream.cpp
+++ b/runtime/Cpp/runtime/src/BufferedTokenStream.cpp
@@ -96,7 +96,7 @@ size_t BufferedTokenStream::fetch(size_t n) {
std::unique_ptr t(_tokenSource->nextToken());
if (is(t.get())) {
- (static_cast(t.get()))->setTokenIndex((int)_tokens.size());
+ (static_cast(t.get()))->setTokenIndex(_tokens.size());
}
_tokens.push_back(std::move(t));
@@ -272,7 +272,7 @@ ssize_t BufferedTokenStream::previousTokenOnChannel(size_t i, size_t channel) {
}
if (i == 0)
- return i;
+ break;
i--;
}
return i;
@@ -289,7 +289,7 @@ std::vector BufferedTokenStream::getHiddenTokensToRight(size_t tokenInd
size_t from = tokenIndex + 1;
// if none onchannel to right, nextOnChannel=-1 so set to = last token
if (nextOnChannel == -1) {
- to = (ssize_t)size() - 1;
+ to = static_cast(size() - 1);
} else {
to = nextOnChannel;
}
@@ -313,11 +313,11 @@ std::vector BufferedTokenStream::getHiddenTokensToLeft(size_t tokenInde
}
ssize_t prevOnChannel = previousTokenOnChannel(tokenIndex - 1, Lexer::DEFAULT_TOKEN_CHANNEL);
- if (prevOnChannel == (ssize_t)tokenIndex - 1) {
+ if (prevOnChannel == static_cast(tokenIndex - 1)) {
return { };
}
// if none onchannel to left, prevOnChannel=-1 then from=0
- size_t from = (size_t)(prevOnChannel + 1);
+ size_t from = static_cast(prevOnChannel + 1);
size_t to = tokenIndex - 1;
return filterForChannel(from, to, channel);
@@ -336,7 +336,7 @@ std::vector BufferedTokenStream::filterForChannel(size_t from, size_t t
hidden.push_back(t);
}
} else {
- if (t->getChannel() == (size_t)channel) {
+ if (t->getChannel() == static_cast(channel)) {
hidden.push_back(t);
}
}
diff --git a/runtime/Cpp/runtime/src/CharStream.h b/runtime/Cpp/runtime/src/CharStream.h
index c42c67b67..5f2a3408d 100755
--- a/runtime/Cpp/runtime/src/CharStream.h
+++ b/runtime/Cpp/runtime/src/CharStream.h
@@ -13,7 +13,7 @@ namespace antlr4 {
/// A source of characters for an ANTLR lexer.
class ANTLR4CPP_PUBLIC CharStream : public IntStream {
public:
- virtual ~CharStream() = 0;
+ virtual ~CharStream();
/// This method returns the text for a range of characters within this input
/// stream. This method is guaranteed to not throw an exception if the
diff --git a/runtime/Cpp/runtime/src/CommonToken.cpp b/runtime/Cpp/runtime/src/CommonToken.cpp
index 147e85b96..200a6af94 100755
--- a/runtime/Cpp/runtime/src/CommonToken.cpp
+++ b/runtime/Cpp/runtime/src/CommonToken.cpp
@@ -35,7 +35,7 @@ CommonToken::CommonToken(std::pair source, size_t typ
_start = start;
_stop = stop;
if (_source.first != nullptr) {
- _line = (int)source.first->getLine();
+ _line = static_cast(source.first->getLine());
_charPositionInLine = source.first->getCharPositionInLine();
}
}
diff --git a/runtime/Cpp/runtime/src/CommonTokenFactory.cpp b/runtime/Cpp/runtime/src/CommonTokenFactory.cpp
index fc51b540a..0b9a7c04f 100755
--- a/runtime/Cpp/runtime/src/CommonTokenFactory.cpp
+++ b/runtime/Cpp/runtime/src/CommonTokenFactory.cpp
@@ -13,7 +13,7 @@ using namespace antlr4;
const Ref> CommonTokenFactory::DEFAULT = std::make_shared();
-CommonTokenFactory::CommonTokenFactory(bool copyText) : copyText(copyText) {
+CommonTokenFactory::CommonTokenFactory(bool copyText_) : copyText(copyText_) {
}
CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) {
diff --git a/runtime/Cpp/runtime/src/CommonTokenStream.cpp b/runtime/Cpp/runtime/src/CommonTokenStream.cpp
index 3d9ec9bf2..7834296ae 100755
--- a/runtime/Cpp/runtime/src/CommonTokenStream.cpp
+++ b/runtime/Cpp/runtime/src/CommonTokenStream.cpp
@@ -12,8 +12,8 @@ using namespace antlr4;
CommonTokenStream::CommonTokenStream(TokenSource *tokenSource) : CommonTokenStream(tokenSource, Token::DEFAULT_CHANNEL) {
}
-CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, size_t channel)
-: BufferedTokenStream(tokenSource), channel(channel) {
+CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, size_t channel_)
+: BufferedTokenStream(tokenSource), channel(channel_) {
}
ssize_t CommonTokenStream::adjustSeekIndex(size_t i) {
@@ -25,7 +25,7 @@ Token* CommonTokenStream::LB(size_t k) {
return nullptr;
}
- ssize_t i = (ssize_t)_p;
+ ssize_t i = static_cast(_p);
size_t n = 1;
// find k good tokens looking backwards
while (n <= k) {
@@ -46,7 +46,7 @@ Token* CommonTokenStream::LT(ssize_t k) {
return nullptr;
}
if (k < 0) {
- return LB((size_t)-k);
+ return LB(static_cast(-k));
}
size_t i = _p;
ssize_t n = 1; // we know tokens[p] is a good one
diff --git a/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp b/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp
index a3f8d5ec6..e0c942639 100755
--- a/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp
+++ b/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp
@@ -62,18 +62,18 @@ void DefaultErrorStrategy::reportError(Parser *recognizer, const RecognitionExce
beginErrorCondition(recognizer);
if (is(&e)) {
- reportNoViableAlternative(recognizer, (const NoViableAltException &)e);
+ reportNoViableAlternative(recognizer, static_cast(e));
} else if (is(&e)) {
- reportInputMismatch(recognizer, (const InputMismatchException &)e);
+ reportInputMismatch(recognizer, static_cast(e));
} else if (is(&e)) {
- reportFailedPredicate(recognizer, (const FailedPredicateException &)e);
+ reportFailedPredicate(recognizer, static_cast(e));
} else if (is(&e)) {
recognizer->notifyErrorListeners(e.getOffendingToken(), e.what(), std::current_exception());
}
}
void DefaultErrorStrategy::recover(Parser *recognizer, std::exception_ptr /*e*/) {
- if (lastErrorIndex == (int)recognizer->getInputStream()->index() &&
+ if (lastErrorIndex == static_cast(recognizer->getInputStream()->index()) &&
lastErrorStates.contains(recognizer->getState())) {
// uh oh, another error at same token index and previously-visited
@@ -82,7 +82,7 @@ void DefaultErrorStrategy::recover(Parser *recognizer, std::exception_ptr /*e*/)
// at least to prevent an infinite loop; this is a failsafe.
recognizer->consume();
}
- lastErrorIndex = (int)recognizer->getInputStream()->index();
+ lastErrorIndex = static_cast(recognizer->getInputStream()->index());
lastErrorStates.add(recognizer->getState());
misc::IntervalSet followSet = getErrorRecoverySet(recognizer);
consumeUntil(recognizer, followSet);
@@ -312,7 +312,7 @@ misc::IntervalSet DefaultErrorStrategy::getErrorRecoverySet(Parser *recognizer)
if (ctx->parent == nullptr)
break;
- ctx = (RuleContext *)ctx->parent;
+ ctx = static_cast(ctx->parent);
}
recoverSet.remove(Token::EPSILON);
diff --git a/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp b/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp
index d514f116a..ea2eaa0d8 100755
--- a/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp
+++ b/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp
@@ -17,7 +17,7 @@ using namespace antlr4;
DiagnosticErrorListener::DiagnosticErrorListener() : DiagnosticErrorListener(true) {
}
-DiagnosticErrorListener::DiagnosticErrorListener(bool exactOnly) : exactOnly(exactOnly) {
+DiagnosticErrorListener::DiagnosticErrorListener(bool exactOnly_) : exactOnly(exactOnly_) {
}
void DiagnosticErrorListener::reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
@@ -53,7 +53,7 @@ void DiagnosticErrorListener::reportContextSensitivity(Parser *recognizer, const
std::string DiagnosticErrorListener::getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa) {
size_t decision = dfa.decision;
- size_t ruleIndex = ((atn::ATNState*)dfa.atnStartState)->ruleIndex;
+ size_t ruleIndex = (reinterpret_cast(dfa.atnStartState))->ruleIndex;
const std::vector& ruleNames = recognizer->getRuleNames();
if (ruleIndex == INVALID_INDEX || ruleIndex >= ruleNames.size()) {
diff --git a/runtime/Cpp/runtime/src/Exceptions.cpp b/runtime/Cpp/runtime/src/Exceptions.cpp
index 1b971ac14..b6a7b06c6 100644
--- a/runtime/Cpp/runtime/src/Exceptions.cpp
+++ b/runtime/Cpp/runtime/src/Exceptions.cpp
@@ -22,3 +22,43 @@ IOException::IOException(const std::string &msg) : std::exception(), _message(ms
const char* IOException::what() const NOEXCEPT {
return _message.c_str();
}
+
+//------------------ IllegalStateException -----------------------------------------------------------------------------
+
+IllegalStateException::~IllegalStateException() {
+}
+
+//------------------ IllegalArgumentException --------------------------------------------------------------------------
+
+IllegalArgumentException::~IllegalArgumentException() {
+}
+
+//------------------ NullPointerException ------------------------------------------------------------------------------
+
+NullPointerException::~NullPointerException() {
+}
+
+//------------------ IndexOutOfBoundsException -------------------------------------------------------------------------
+
+IndexOutOfBoundsException::~IndexOutOfBoundsException() {
+}
+
+//------------------ UnsupportedOperationException ---------------------------------------------------------------------
+
+UnsupportedOperationException::~UnsupportedOperationException() {
+}
+
+//------------------ EmptyStackException -------------------------------------------------------------------------------
+
+EmptyStackException::~EmptyStackException() {
+}
+
+//------------------ CancellationException -----------------------------------------------------------------------------
+
+CancellationException::~CancellationException() {
+}
+
+//------------------ ParseCancellationException ------------------------------------------------------------------------
+
+ParseCancellationException::~ParseCancellationException() {
+}
diff --git a/runtime/Cpp/runtime/src/Exceptions.h b/runtime/Cpp/runtime/src/Exceptions.h
index 11df72c92..d57b26a83 100644
--- a/runtime/Cpp/runtime/src/Exceptions.h
+++ b/runtime/Cpp/runtime/src/Exceptions.h
@@ -21,32 +21,51 @@ namespace antlr4 {
class ANTLR4CPP_PUBLIC IllegalStateException : public RuntimeException {
public:
- IllegalStateException(const std::string &msg = "") : RuntimeException(msg) {};
+ IllegalStateException(const std::string &msg = "") : RuntimeException(msg) {}
+ IllegalStateException(IllegalStateException const&) = default;
+ ~IllegalStateException();
+ IllegalStateException& operator=(IllegalStateException const&) = default;
};
class ANTLR4CPP_PUBLIC IllegalArgumentException : public RuntimeException {
public:
- IllegalArgumentException(const std::string &msg = "") : RuntimeException(msg) {};
+ IllegalArgumentException(IllegalArgumentException const&) = default;
+ IllegalArgumentException(const std::string &msg = "") : RuntimeException(msg) {}
+ ~IllegalArgumentException();
+ IllegalArgumentException& operator=(IllegalArgumentException const&) = default;
};
class ANTLR4CPP_PUBLIC NullPointerException : public RuntimeException {
public:
- NullPointerException(const std::string &msg = "") : RuntimeException(msg) {};
+ NullPointerException(const std::string &msg = "") : RuntimeException(msg) {}
+ NullPointerException(NullPointerException const&) = default;
+ ~NullPointerException();
+ NullPointerException& operator=(NullPointerException const&) = default;
};
class ANTLR4CPP_PUBLIC IndexOutOfBoundsException : public RuntimeException {
public:
- IndexOutOfBoundsException(const std::string &msg = "") : RuntimeException(msg) {};
+ IndexOutOfBoundsException(const std::string &msg = "") : RuntimeException(msg) {}
+ IndexOutOfBoundsException(IndexOutOfBoundsException const&) = default;
+ ~IndexOutOfBoundsException();
+ IndexOutOfBoundsException& operator=(IndexOutOfBoundsException const&) = default;
};
class ANTLR4CPP_PUBLIC UnsupportedOperationException : public RuntimeException {
public:
- UnsupportedOperationException(const std::string &msg = "") : RuntimeException(msg) {};
+ UnsupportedOperationException(const std::string &msg = "") : RuntimeException(msg) {}
+ UnsupportedOperationException(UnsupportedOperationException const&) = default;
+ ~UnsupportedOperationException();
+ UnsupportedOperationException& operator=(UnsupportedOperationException const&) = default;
+
};
class ANTLR4CPP_PUBLIC EmptyStackException : public RuntimeException {
public:
- EmptyStackException(const std::string &msg = "") : RuntimeException(msg) {};
+ EmptyStackException(const std::string &msg = "") : RuntimeException(msg) {}
+ EmptyStackException(EmptyStackException const&) = default;
+ ~EmptyStackException();
+ EmptyStackException& operator=(EmptyStackException const&) = default;
};
// IOException is not a runtime exception (in the java hierarchy).
@@ -63,12 +82,18 @@ namespace antlr4 {
class ANTLR4CPP_PUBLIC CancellationException : public IllegalStateException {
public:
- CancellationException(const std::string &msg = "") : IllegalStateException(msg) {};
+ CancellationException(const std::string &msg = "") : IllegalStateException(msg) {}
+ CancellationException(CancellationException const&) = default;
+ ~CancellationException();
+ CancellationException& operator=(CancellationException const&) = default;
};
class ANTLR4CPP_PUBLIC ParseCancellationException : public CancellationException {
public:
- ParseCancellationException(const std::string &msg = "") : CancellationException(msg) {};
+ ParseCancellationException(const std::string &msg = "") : CancellationException(msg) {}
+ ParseCancellationException(ParseCancellationException const&) = default;
+ ~ParseCancellationException();
+ ParseCancellationException& operator=(ParseCancellationException const&) = default;
};
} // namespace antlr4
diff --git a/runtime/Cpp/runtime/src/FailedPredicateException.cpp b/runtime/Cpp/runtime/src/FailedPredicateException.cpp
index 3410173d5..3ec7b27f8 100755
--- a/runtime/Cpp/runtime/src/FailedPredicateException.cpp
+++ b/runtime/Cpp/runtime/src/FailedPredicateException.cpp
@@ -28,8 +28,8 @@ FailedPredicateException::FailedPredicateException(Parser *recognizer, const std
atn::ATNState *s = recognizer->getInterpreter()->atn.states[recognizer->getState()];
atn::Transition *transition = s->transitions[0];
if (is(transition)) {
- _ruleIndex = ((atn::PredicateTransition *)transition)->ruleIndex;
- _predicateIndex = ((atn::PredicateTransition *)transition)->predIndex;
+ _ruleIndex = static_cast(transition)->ruleIndex;
+ _predicateIndex = static_cast(transition)->predIndex;
} else {
_ruleIndex = 0;
_predicateIndex = 0;
diff --git a/runtime/Cpp/runtime/src/InputMismatchException.cpp b/runtime/Cpp/runtime/src/InputMismatchException.cpp
index c5aae3e6c..1c85a35a2 100755
--- a/runtime/Cpp/runtime/src/InputMismatchException.cpp
+++ b/runtime/Cpp/runtime/src/InputMismatchException.cpp
@@ -13,3 +13,6 @@ InputMismatchException::InputMismatchException(Parser *recognizer)
: RecognitionException(recognizer, recognizer->getInputStream(), recognizer->getContext(),
recognizer->getCurrentToken()) {
}
+
+InputMismatchException::~InputMismatchException() {
+}
diff --git a/runtime/Cpp/runtime/src/InputMismatchException.h b/runtime/Cpp/runtime/src/InputMismatchException.h
index defacfbf0..051a2a415 100755
--- a/runtime/Cpp/runtime/src/InputMismatchException.h
+++ b/runtime/Cpp/runtime/src/InputMismatchException.h
@@ -16,6 +16,9 @@ namespace antlr4 {
class ANTLR4CPP_PUBLIC InputMismatchException : public RecognitionException {
public:
InputMismatchException(Parser *recognizer);
+ InputMismatchException(InputMismatchException const&) = default;
+ ~InputMismatchException();
+ InputMismatchException& operator=(InputMismatchException const&) = default;
};
} // namespace antlr4
diff --git a/runtime/Cpp/runtime/src/IntStream.cpp b/runtime/Cpp/runtime/src/IntStream.cpp
index af8bea07d..5408ae50f 100755
--- a/runtime/Cpp/runtime/src/IntStream.cpp
+++ b/runtime/Cpp/runtime/src/IntStream.cpp
@@ -8,3 +8,5 @@
using namespace antlr4;
const std::string IntStream::UNKNOWN_SOURCE_NAME = "";
+
+IntStream::~IntStream() = default;
diff --git a/runtime/Cpp/runtime/src/IntStream.h b/runtime/Cpp/runtime/src/IntStream.h
index c07f0072a..7c7401074 100755
--- a/runtime/Cpp/runtime/src/IntStream.h
+++ b/runtime/Cpp/runtime/src/IntStream.h
@@ -27,7 +27,7 @@ namespace antlr4 {
///
class ANTLR4CPP_PUBLIC IntStream {
public:
- static const size_t EOF = (size_t)-1;
+ static const size_t EOF = std::numeric_limits::max();
/// The value returned by when the end of the stream is
/// reached.
@@ -40,7 +40,7 @@ namespace antlr4 {
///
static const std::string UNKNOWN_SOURCE_NAME;
- virtual ~IntStream() {};
+ virtual ~IntStream();
///
/// Consumes the current symbol in the stream. This method has the following
diff --git a/runtime/Cpp/runtime/src/Lexer.h b/runtime/Cpp/runtime/src/Lexer.h
index f7c13f2ab..f722f7fb1 100755
--- a/runtime/Cpp/runtime/src/Lexer.h
+++ b/runtime/Cpp/runtime/src/Lexer.h
@@ -19,8 +19,8 @@ namespace antlr4 {
class ANTLR4CPP_PUBLIC Lexer : public Recognizer, public TokenSource {
public:
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 MORE = static_cast(-2);
+ static const size_t SKIP = static_cast(-3);
static const size_t DEFAULT_TOKEN_CHANNEL = Token::DEFAULT_CHANNEL;
static const size_t HIDDEN = Token::HIDDEN_CHANNEL;
diff --git a/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp b/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp
index 017c8a5ff..cc4fdcfd9 100755
--- a/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp
+++ b/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp
@@ -28,7 +28,7 @@ atn::ATNConfigSet* LexerNoViableAltException::getDeadEndConfigs() {
std::string LexerNoViableAltException::toString() {
std::string symbol;
if (_startIndex < getInputStream()->size()) {
- symbol = ((CharStream *)getInputStream())->getText(misc::Interval(_startIndex, _startIndex));
+ symbol = static_cast(getInputStream())->getText(misc::Interval(_startIndex, _startIndex));
symbol = antlrcpp::escapeWhitespace(symbol, false);
}
std::string format = "LexerNoViableAltException('" + symbol + "')";
diff --git a/runtime/Cpp/runtime/src/ListTokenSource.cpp b/runtime/Cpp/runtime/src/ListTokenSource.cpp
index 6261834c9..4a734596f 100755
--- a/runtime/Cpp/runtime/src/ListTokenSource.cpp
+++ b/runtime/Cpp/runtime/src/ListTokenSource.cpp
@@ -11,7 +11,7 @@
using namespace antlr4;
-ListTokenSource::ListTokenSource(std::vector> tokens) : ListTokenSource(std::move(tokens), "") {
+ListTokenSource::ListTokenSource(std::vector> tokens_) : ListTokenSource(std::move(tokens_), "") {
}
ListTokenSource::ListTokenSource(std::vector> tokens_, const std::string &sourceName_)
@@ -32,7 +32,7 @@ ListTokenSource::ListTokenSource(std::vector> tokens_, co
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())));
+ Token::DEFAULT_CHANNEL, start, stop, static_cast(lastToken->getLine()), lastToken->getCharPositionInLine())));
}
}
diff --git a/runtime/Cpp/runtime/src/Parser.cpp b/runtime/Cpp/runtime/src/Parser.cpp
index 79d7b1b57..f65da1433 100755
--- a/runtime/Cpp/runtime/src/Parser.cpp
+++ b/runtime/Cpp/runtime/src/Parser.cpp
@@ -33,7 +33,10 @@ using namespace antlrcpp;
std::map, atn::ATN> Parser::bypassAltsAtnCache;
-Parser::TraceListener::TraceListener(Parser *outerInstance) : outerInstance(outerInstance) {
+Parser::TraceListener::TraceListener(Parser *outerInstance_) : outerInstance(outerInstance_) {
+}
+
+Parser::TraceListener::~TraceListener() {
}
void Parser::TraceListener::enterEveryRule(ParserRuleContext *ctx) {
@@ -56,6 +59,9 @@ void Parser::TraceListener::exitEveryRule(ParserRuleContext *ctx) {
Parser::TrimToSizeListener Parser::TrimToSizeListener::INSTANCE;
+Parser::TrimToSizeListener::~TrimToSizeListener() {
+}
+
void Parser::TrimToSizeListener::enterEveryRule(ParserRuleContext * /*ctx*/) {
}
diff --git a/runtime/Cpp/runtime/src/Parser.h b/runtime/Cpp/runtime/src/Parser.h
index e320c9c1c..14a41ba9c 100755
--- a/runtime/Cpp/runtime/src/Parser.h
+++ b/runtime/Cpp/runtime/src/Parser.h
@@ -21,7 +21,7 @@ namespace antlr4 {
class TraceListener : public tree::ParseTreeListener {
public:
TraceListener(Parser *outerInstance);
- virtual ~TraceListener() {};
+ virtual ~TraceListener();
virtual void enterEveryRule(ParserRuleContext *ctx) override;
virtual void visitTerminal(tree::TerminalNode *node) override;
@@ -36,7 +36,7 @@ namespace antlr4 {
public:
static TrimToSizeListener INSTANCE;
- virtual ~TrimToSizeListener() {};
+ virtual ~TrimToSizeListener();
virtual void enterEveryRule(ParserRuleContext *ctx) override;
virtual void visitTerminal(tree::TerminalNode *node) override;
@@ -375,7 +375,7 @@ namespace antlr4 {
*/
bool isTrace() const;
- tree::ParseTreeTracker& getTreeTracker() { return _tracker; };
+ tree::ParseTreeTracker& getTreeTracker() { return _tracker; }
/** How to create a token leaf node associated with a parent.
* Typically, the terminal node to create is not a function of the parent
diff --git a/runtime/Cpp/runtime/src/ParserInterpreter.cpp b/runtime/Cpp/runtime/src/ParserInterpreter.cpp
index 21449eea2..5d5d2ced7 100755
--- a/runtime/Cpp/runtime/src/ParserInterpreter.cpp
+++ b/runtime/Cpp/runtime/src/ParserInterpreter.cpp
@@ -174,19 +174,19 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
// We are at the start of a left recursive rule's (...)* loop
// and we're not taking the exit branch of loop.
InterpreterRuleContext *localctx = createInterpreterRuleContext(_parentContextStack.top().first,
- _parentContextStack.top().second, (int)_ctx->getRuleIndex());
- pushNewRecursionContext(localctx, _atn.ruleToStartState[p->ruleIndex]->stateNumber, (int)_ctx->getRuleIndex());
+ _parentContextStack.top().second, static_cast(_ctx->getRuleIndex()));
+ pushNewRecursionContext(localctx, _atn.ruleToStartState[p->ruleIndex]->stateNumber, static_cast(_ctx->getRuleIndex()));
}
break;
case atn::Transition::ATOM:
- match((int)((atn::AtomTransition*)(transition))->_label);
+ match(static_cast(static_cast(transition)->_label));
break;
case atn::Transition::RANGE:
case atn::Transition::SET:
case atn::Transition::NOT_SET:
- if (!transition->matches((int)_input->LA(1), Token::MIN_USER_TOKEN_TYPE, Lexer::MAX_CHAR_VALUE)) {
+ if (!transition->matches(static_cast(_input->LA(1)), Token::MIN_USER_TOKEN_TYPE, Lexer::MAX_CHAR_VALUE)) {
recoverInline();
}
matchWildcard();
@@ -198,11 +198,11 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
case atn::Transition::RULE:
{
- atn::RuleStartState *ruleStartState = (atn::RuleStartState*)(transition->target);
+ atn::RuleStartState *ruleStartState = static_cast(transition->target);
size_t ruleIndex = ruleStartState->ruleIndex;
InterpreterRuleContext *newctx = createInterpreterRuleContext(_ctx, p->stateNumber, ruleIndex);
if (ruleStartState->isLeftRecursiveRule) {
- enterRecursionRule(newctx, ruleStartState->stateNumber, ruleIndex, ((atn::RuleTransition*)(transition))->precedence);
+ enterRecursionRule(newctx, ruleStartState->stateNumber, ruleIndex, static_cast(transition)->precedence);
} else {
enterRule(newctx, transition->target->stateNumber, ruleIndex);
}
@@ -211,7 +211,7 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
case atn::Transition::PREDICATE:
{
- atn::PredicateTransition *predicateTransition = (atn::PredicateTransition*)(transition);
+ atn::PredicateTransition *predicateTransition = static_cast(transition);
if (!sempred(_ctx, predicateTransition->ruleIndex, predicateTransition->predIndex)) {
throw FailedPredicateException(this);
}
@@ -220,15 +220,15 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
case atn::Transition::ACTION:
{
- atn::ActionTransition *actionTransition = (atn::ActionTransition*)(transition);
+ atn::ActionTransition *actionTransition = static_cast(transition);
action(_ctx, actionTransition->ruleIndex, actionTransition->actionIndex);
}
break;
case atn::Transition::PRECEDENCE:
{
- if (!precpred(_ctx, ((atn::PrecedencePredicateTransition*)(transition))->precedence)) {
- throw FailedPredicateException(this, "precpred(_ctx, " + std::to_string(((atn::PrecedencePredicateTransition*)(transition))->precedence) + ")");
+ if (!precpred(_ctx, static_cast(transition)->precedence)) {
+ throw FailedPredicateException(this, "precpred(_ctx, " + std::to_string(static_cast(transition)->precedence) + ")");
}
}
break;
@@ -283,7 +283,7 @@ void ParserInterpreter::recover(RecognitionException &e) {
if (_input->index() == i) {
// no input consumed, better add an error node
if (is(&e)) {
- InputMismatchException &ime = (InputMismatchException&)e;
+ InputMismatchException &ime = static_cast(e);
Token *tok = e.getOffendingToken();
size_t expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element
_errorToken = getTokenFactory()->create({ tok->getTokenSource(), tok->getTokenSource()->getInputStream() },
diff --git a/runtime/Cpp/runtime/src/RecognitionException.cpp b/runtime/Cpp/runtime/src/RecognitionException.cpp
index 2847196e9..29c950819 100755
--- a/runtime/Cpp/runtime/src/RecognitionException.cpp
+++ b/runtime/Cpp/runtime/src/RecognitionException.cpp
@@ -27,6 +27,9 @@ RecognitionException::RecognitionException(const std::string &message, Recognize
}
}
+RecognitionException::~RecognitionException() {
+}
+
size_t RecognitionException::getOffendingState() const {
return _offendingState;
}
diff --git a/runtime/Cpp/runtime/src/RecognitionException.h b/runtime/Cpp/runtime/src/RecognitionException.h
index 9513c8cb6..aa204f71e 100755
--- a/runtime/Cpp/runtime/src/RecognitionException.h
+++ b/runtime/Cpp/runtime/src/RecognitionException.h
@@ -33,7 +33,9 @@ namespace antlr4 {
Token *offendingToken = nullptr);
RecognitionException(const std::string &message, Recognizer *recognizer, IntStream *input,
ParserRuleContext *ctx, Token *offendingToken = nullptr);
- ~RecognitionException() {}
+ RecognitionException(RecognitionException const&) = default;
+ ~RecognitionException();
+ RecognitionException& operator=(RecognitionException const&) = default;
/// Get the ATN state number the parser was in at the time the error
/// occurred. For NoViableAltException and
diff --git a/runtime/Cpp/runtime/src/Recognizer.cpp b/runtime/Cpp/runtime/src/Recognizer.cpp
index 36165617e..257619ba1 100755
--- a/runtime/Cpp/runtime/src/Recognizer.cpp
+++ b/runtime/Cpp/runtime/src/Recognizer.cpp
@@ -27,6 +27,9 @@ Recognizer::Recognizer() {
_proxListener.addErrorListener(&ConsoleErrorListener::INSTANCE);
}
+Recognizer::~Recognizer() {
+}
+
dfa::Vocabulary const& Recognizer::getVocabulary() const {
static dfa::Vocabulary vocabulary = dfa::Vocabulary::fromTokenNames(getTokenNames());
return vocabulary;
diff --git a/runtime/Cpp/runtime/src/Recognizer.h b/runtime/Cpp/runtime/src/Recognizer.h
index db42ab1ff..dbffde2e7 100755
--- a/runtime/Cpp/runtime/src/Recognizer.h
+++ b/runtime/Cpp/runtime/src/Recognizer.h
@@ -11,10 +11,13 @@ namespace antlr4 {
class ANTLR4CPP_PUBLIC Recognizer {
public:
- static const size_t EOF = (size_t)-1;
+ static const size_t EOF = std::numeric_limits::max();
Recognizer();
- virtual ~Recognizer() {};
+ Recognizer(Recognizer const&) = delete;
+ virtual ~Recognizer();
+
+ Recognizer& operator=(Recognizer const&) = delete;
/** Used to print out token names like ID during debugging and
* error reporting. The generated parsers implement a method
diff --git a/runtime/Cpp/runtime/src/RuleContext.cpp b/runtime/Cpp/runtime/src/RuleContext.cpp
index 66650be0e..73cfe24e1 100755
--- a/runtime/Cpp/runtime/src/RuleContext.cpp
+++ b/runtime/Cpp/runtime/src/RuleContext.cpp
@@ -19,10 +19,10 @@ RuleContext::RuleContext() {
InitializeInstanceFields();
}
-RuleContext::RuleContext(RuleContext *parent, size_t invokingState) {
+RuleContext::RuleContext(RuleContext *parent_, size_t invokingState_) {
InitializeInstanceFields();
- this->parent = parent;
- this->invokingState = invokingState;
+ this->parent = parent_;
+ this->invokingState = invokingState_;
}
int RuleContext::depth() {
@@ -31,7 +31,7 @@ int RuleContext::depth() {
while (true) {
if (p->parent == nullptr)
break;
- p = (RuleContext *)p->parent;
+ p = static_cast(p->parent);
n++;
}
return n;
@@ -112,7 +112,7 @@ std::string RuleContext::toString(const std::vector &ruleNames, Rul
if (currentParent->parent == nullptr) // No parent anymore.
break;
- currentParent = (RuleContext *)currentParent->parent;
+ currentParent = static_cast(currentParent->parent);
if (!ruleNames.empty() || !currentParent->isEmpty()) {
ss << " ";
}
diff --git a/runtime/Cpp/runtime/src/Token.cpp b/runtime/Cpp/runtime/src/Token.cpp
new file mode 100644
index 000000000..06047867a
--- /dev/null
+++ b/runtime/Cpp/runtime/src/Token.cpp
@@ -0,0 +1,4 @@
+#include "Token.h"
+
+antlr4::Token::~Token() {
+}
diff --git a/runtime/Cpp/runtime/src/Token.h b/runtime/Cpp/runtime/src/Token.h
index 46ed0fee7..2560c7f1b 100755
--- a/runtime/Cpp/runtime/src/Token.h
+++ b/runtime/Cpp/runtime/src/Token.h
@@ -18,11 +18,11 @@ namespace antlr4 {
/// During lookahead operations, this "token" signifies we hit rule end ATN state
/// and did not follow it despite needing to.
- static const size_t EPSILON = (size_t)-2;
+ static const size_t EPSILON = std::numeric_limits::max() - 1;
static const size_t MIN_USER_TOKEN_TYPE = 1;
static const size_t EOF = IntStream::EOF;
- virtual ~Token() {};
+ virtual ~Token();
/// All tokens go to the parser (unless skip() is called in that rule)
/// on a particular "channel". The parser tunes to a particular channel
diff --git a/runtime/Cpp/runtime/src/TokenFactory.h b/runtime/Cpp/runtime/src/TokenFactory.h
index b22fc8047..e29335f5b 100755
--- a/runtime/Cpp/runtime/src/TokenFactory.h
+++ b/runtime/Cpp/runtime/src/TokenFactory.h
@@ -15,7 +15,7 @@ namespace antlr4 {
template
class ANTLR4CPP_PUBLIC TokenFactory {
public:
- virtual ~TokenFactory() {};
+ virtual ~TokenFactory() {}
/// 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
diff --git a/runtime/Cpp/runtime/src/TokenSource.cpp b/runtime/Cpp/runtime/src/TokenSource.cpp
new file mode 100644
index 000000000..50b9684ec
--- /dev/null
+++ b/runtime/Cpp/runtime/src/TokenSource.cpp
@@ -0,0 +1,4 @@
+#include "TokenSource.h"
+
+antlr4::TokenSource::~TokenSource() {
+}
diff --git a/runtime/Cpp/runtime/src/TokenSource.h b/runtime/Cpp/runtime/src/TokenSource.h
index ff7b7ba84..72981cea0 100755
--- a/runtime/Cpp/runtime/src/TokenSource.h
+++ b/runtime/Cpp/runtime/src/TokenSource.h
@@ -26,7 +26,7 @@ namespace antlr4 {
///
class ANTLR4CPP_PUBLIC TokenSource {
public:
- virtual ~TokenSource() {};
+ virtual ~TokenSource();
/// Return a object from your input stream (usually a
/// ). Do not fail/return upon lexing error; keep chewing
diff --git a/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp b/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp
index 20e81e910..e281b19cc 100755
--- a/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp
+++ b/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp
@@ -14,19 +14,23 @@ using namespace antlr4;
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;
+ 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;
- this->text = text;
+ this->index = index_;
+ this->text = text_;
+}
+
+TokenStreamRewriter::RewriteOperation::~RewriteOperation()
+{
}
size_t TokenStreamRewriter::RewriteOperation::execute(std::string * /*buf*/) {
@@ -45,8 +49,8 @@ void TokenStreamRewriter::RewriteOperation::InitializeInstanceFields() {
index = 0;
}
-TokenStreamRewriter::InsertBeforeOp::InsertBeforeOp(TokenStreamRewriter *outerInstance, size_t index, const std::string& text)
-: RewriteOperation(outerInstance, index, text), outerInstance(outerInstance) {
+TokenStreamRewriter::InsertBeforeOp::InsertBeforeOp(TokenStreamRewriter *outerInstance_, size_t index_, const std::string& text_)
+: RewriteOperation(outerInstance_, index_, text_), outerInstance(outerInstance_) {
}
size_t TokenStreamRewriter::InsertBeforeOp::execute(std::string *buf) {
@@ -57,8 +61,8 @@ size_t TokenStreamRewriter::InsertBeforeOp::execute(std::string *buf) {
return index + 1;
}
-TokenStreamRewriter::ReplaceOp::ReplaceOp(TokenStreamRewriter *outerInstance, size_t from, size_t to, const std::string& text)
-: RewriteOperation(outerInstance, from, text), outerInstance(outerInstance) {
+TokenStreamRewriter::ReplaceOp::ReplaceOp(TokenStreamRewriter *outerInstance_, size_t from, size_t to, const std::string& text)
+: RewriteOperation(outerInstance_, from, text), outerInstance(outerInstance_) {
InitializeInstanceFields();
lastIndex = to;
@@ -84,7 +88,7 @@ void TokenStreamRewriter::ReplaceOp::InitializeInstanceFields() {
const std::string TokenStreamRewriter::DEFAULT_PROGRAM_NAME = "default";
-TokenStreamRewriter::TokenStreamRewriter(TokenStream *tokens) : tokens(tokens) {
+TokenStreamRewriter::TokenStreamRewriter(TokenStream *tokens_) : tokens(tokens_) {
_programs[DEFAULT_PROGRAM_NAME].reserve(PROGRAM_INIT_SIZE);
}
@@ -413,10 +417,10 @@ std::string TokenStreamRewriter::catOpText(std::string *a, std::string *b) {
std::string x = "";
std::string y = "";
if (a != nullptr) {
- x = std::string(*a);
+ x = *a;
}
if (b != nullptr) {
- y = std::string(*b);
+ y = *b;
}
return x + y;
}
diff --git a/runtime/Cpp/runtime/src/TokenStreamRewriter.h b/runtime/Cpp/runtime/src/TokenStreamRewriter.h
index ce8c1f78b..102a9e946 100755
--- a/runtime/Cpp/runtime/src/TokenStreamRewriter.h
+++ b/runtime/Cpp/runtime/src/TokenStreamRewriter.h
@@ -164,7 +164,7 @@ namespace antlr4 {
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index);
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::string& text);
- virtual ~RewriteOperation() {};
+ virtual ~RewriteOperation();
/// Execute the rewrite operation by possibly adding to the buffer.
/// Return the index of the next token to operate on.
diff --git a/runtime/Cpp/runtime/src/Vocabulary.cpp b/runtime/Cpp/runtime/src/Vocabulary.cpp
index 66b494cc1..dcfa45e4b 100755
--- a/runtime/Cpp/runtime/src/Vocabulary.cpp
+++ b/runtime/Cpp/runtime/src/Vocabulary.cpp
@@ -22,6 +22,9 @@ Vocabulary::Vocabulary(const std::vector &literalNames,
// See note here on -1 part: https://github.com/antlr/antlr4/pull/1146
}
+Vocabulary::~Vocabulary() {
+}
+
Vocabulary Vocabulary::fromTokenNames(const std::vector &tokenNames) {
if (tokenNames.empty()) {
return EMPTY_VOCABULARY;
diff --git a/runtime/Cpp/runtime/src/Vocabulary.h b/runtime/Cpp/runtime/src/Vocabulary.h
index 9640698fd..df78b4364 100755
--- a/runtime/Cpp/runtime/src/Vocabulary.h
+++ b/runtime/Cpp/runtime/src/Vocabulary.h
@@ -14,7 +14,9 @@ namespace dfa {
/// interface.
class ANTLR4CPP_PUBLIC Vocabulary {
public:
- virtual ~Vocabulary() {};
+ Vocabulary(Vocabulary const&) = default;
+ virtual ~Vocabulary();
+ Vocabulary& operator=(Vocabulary const&) = default;
/// Gets an empty instance.
///
@@ -24,7 +26,7 @@ namespace dfa {
/// except .
static const Vocabulary EMPTY_VOCABULARY;
- Vocabulary() {};
+ Vocabulary() {}
///
/// Constructs a new instance of from the specified
diff --git a/runtime/Cpp/runtime/src/WritableToken.cpp b/runtime/Cpp/runtime/src/WritableToken.cpp
new file mode 100644
index 000000000..2e3b01241
--- /dev/null
+++ b/runtime/Cpp/runtime/src/WritableToken.cpp
@@ -0,0 +1,4 @@
+#include "WritableToken.h"
+
+antlr4::WritableToken::~WritableToken() {
+}
diff --git a/runtime/Cpp/runtime/src/WritableToken.h b/runtime/Cpp/runtime/src/WritableToken.h
index fe9bf4bf8..56bc9d079 100755
--- a/runtime/Cpp/runtime/src/WritableToken.h
+++ b/runtime/Cpp/runtime/src/WritableToken.h
@@ -11,6 +11,7 @@ namespace antlr4 {
class ANTLR4CPP_PUBLIC WritableToken : public Token {
public:
+ virtual ~WritableToken();
virtual void setText(const std::string &text) = 0;
virtual void setType(size_t ttype) = 0;
virtual void setLine(size_t line) = 0;
diff --git a/runtime/Cpp/runtime/src/antlr4-common.h b/runtime/Cpp/runtime/src/antlr4-common.h
index 85477d813..dc0596f1d 100644
--- a/runtime/Cpp/runtime/src/antlr4-common.h
+++ b/runtime/Cpp/runtime/src/antlr4-common.h
@@ -12,6 +12,7 @@
#include
#include
#include
+#include
#include
#include
#include