diff --git a/runtime/Cpp/runtime/src/Recognizer.cpp b/runtime/Cpp/runtime/src/Recognizer.cpp index 877596f20b..8a944619d5 100755 --- a/runtime/Cpp/runtime/src/Recognizer.cpp +++ b/runtime/Cpp/runtime/src/Recognizer.cpp @@ -149,14 +149,6 @@ bool Recognizer::precpred(RuleContext * /*localctx*/, int /*precedence*/) { void Recognizer::action(RuleContext * /*localctx*/, size_t /*ruleIndex*/, size_t /*actionIndex*/) { } -size_t Recognizer::getState() const { - return _stateNumber; -} - -void Recognizer::setState(size_t atnState) { - _stateNumber = atnState; -} - void Recognizer::InitializeInstanceFields() { _stateNumber = ATNState::INVALID_STATE_NUMBER; _interpreter = nullptr; diff --git a/runtime/Cpp/runtime/src/Recognizer.h b/runtime/Cpp/runtime/src/Recognizer.h index 8d37bf5736..482795fe79 100755 --- a/runtime/Cpp/runtime/src/Recognizer.h +++ b/runtime/Cpp/runtime/src/Recognizer.h @@ -113,7 +113,7 @@ namespace antlr4 { virtual void action(RuleContext *localctx, size_t ruleIndex, size_t actionIndex); - virtual size_t getState() const ; + size_t getState() const { return _stateNumber; } // Get the ATN used by the recognizer for prediction. virtual const atn::ATN& getATN() const = 0; @@ -126,7 +126,7 @@ namespace antlr4 { /// invoking rules. Combine this and we have complete ATN /// configuration information. /// - void setState(size_t atnState); + void setState(size_t atnState) { _stateNumber = atnState; } virtual IntStream* getInputStream() = 0; diff --git a/runtime/Cpp/runtime/src/atn/ATNConfig.cpp b/runtime/Cpp/runtime/src/atn/ATNConfig.cpp index c490f041db..b32a779227 100755 --- a/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +++ b/runtime/Cpp/runtime/src/atn/ATNConfig.cpp @@ -11,12 +11,12 @@ using namespace antlr4::atn; -ATNConfig::ATNConfig(ATNState *state_, size_t alt_, Ref const& context_) - : ATNConfig(state_, alt_, context_, SemanticContext::NONE) { +ATNConfig::ATNConfig(ATNState *state_, size_t alt, Ref context) + : ATNConfig(state_, alt, std::move(context), SemanticContext::NONE) { } -ATNConfig::ATNConfig(ATNState *state_, size_t alt_, Ref const& context_, Ref const& semanticContext_) - : state(state_), alt(alt_), context(context_), semanticContext(semanticContext_) { +ATNConfig::ATNConfig(ATNState *state, size_t alt, Ref context, Ref semanticContext) + : state(state), alt(alt), context(std::move(context)), semanticContext(std::move(semanticContext)) { reachesIntoOuterContext = 0; } @@ -26,25 +26,22 @@ ATNConfig::ATNConfig(Ref const& c) : ATNConfig(c, c->state, c->contex ATNConfig::ATNConfig(Ref const& c, ATNState *state_) : ATNConfig(c, state_, c->context, c->semanticContext) { } -ATNConfig::ATNConfig(Ref const& c, ATNState *state, Ref const& semanticContext) - : ATNConfig(c, state, c->context, semanticContext) { +ATNConfig::ATNConfig(Ref const& c, ATNState *state, Ref semanticContext) + : ATNConfig(c, state, c->context, std::move(semanticContext)) { } -ATNConfig::ATNConfig(Ref const& c, Ref const& semanticContext) - : ATNConfig(c, c->state, c->context, semanticContext) { +ATNConfig::ATNConfig(Ref const& c, Ref semanticContext) + : ATNConfig(c, c->state, c->context, std::move(semanticContext)) { } -ATNConfig::ATNConfig(Ref const& c, ATNState *state, Ref const& context) - : ATNConfig(c, state, context, c->semanticContext) { +ATNConfig::ATNConfig(Ref const& c, ATNState *state, Ref context) + : ATNConfig(c, state, std::move(context), c->semanticContext) { } -ATNConfig::ATNConfig(Ref const& c, ATNState *state, Ref const& context, - Ref const& semanticContext) - : state(state), alt(c->alt), context(context), reachesIntoOuterContext(c->reachesIntoOuterContext), - semanticContext(semanticContext) { -} - -ATNConfig::~ATNConfig() { +ATNConfig::ATNConfig(Ref const& c, ATNState *state, Ref context, + Ref semanticContext) + : state(state), alt(c->alt), context(std::move(context)), reachesIntoOuterContext(c->reachesIntoOuterContext), + semanticContext(std::move(semanticContext)) { } size_t ATNConfig::hashCode() const { @@ -73,22 +70,22 @@ void ATNConfig::setPrecedenceFilterSuppressed(bool value) { } } -bool ATNConfig::operator == (const ATNConfig &other) const { +bool ATNConfig::operator==(const ATNConfig &other) const { return state->stateNumber == other.state->stateNumber && alt == other.alt && ((context == other.context) || (*context == *other.context)) && *semanticContext == *other.semanticContext && isPrecedenceFilterSuppressed() == other.isPrecedenceFilterSuppressed(); } -bool ATNConfig::operator != (const ATNConfig &other) const { +bool ATNConfig::operator!=(const ATNConfig &other) const { return !operator==(other); } -std::string ATNConfig::toString() { +std::string ATNConfig::toString() const { return toString(true); } -std::string ATNConfig::toString(bool showAlt) { +std::string ATNConfig::toString(bool showAlt) const { std::stringstream ss; ss << "("; diff --git a/runtime/Cpp/runtime/src/atn/ATNConfig.h b/runtime/Cpp/runtime/src/atn/ATNConfig.h index aef62f9947..9b3e750808 100755 --- a/runtime/Cpp/runtime/src/atn/ATNConfig.h +++ b/runtime/Cpp/runtime/src/atn/ATNConfig.h @@ -77,18 +77,19 @@ namespace atn { /// Can be shared between multiple ATNConfig instances. Ref semanticContext; - ATNConfig(ATNState *state, size_t alt, Ref const& context); - ATNConfig(ATNState *state, size_t alt, Ref const& context, Ref const& semanticContext); + ATNConfig(ATNState *state, size_t alt, Ref context); + ATNConfig(ATNState *state, size_t alt, Ref context, Ref semanticContext); ATNConfig(Ref const& c); // dup ATNConfig(Ref const& c, ATNState *state); - ATNConfig(Ref const& c, ATNState *state, Ref const& semanticContext); - ATNConfig(Ref const& c, Ref const& semanticContext); - ATNConfig(Ref const& c, ATNState *state, Ref const& context); - ATNConfig(Ref const& c, ATNState *state, Ref const& context, Ref const& semanticContext); + ATNConfig(Ref const& c, ATNState *state, Ref semanticContext); + ATNConfig(Ref const& c, Ref semanticContext); + ATNConfig(Ref const& c, ATNState *state, Ref context); + ATNConfig(Ref const& c, ATNState *state, Ref context, Ref semanticContext); ATNConfig(ATNConfig const&) = default; - virtual ~ATNConfig(); + + virtual ~ATNConfig() = default; virtual size_t hashCode() const; @@ -97,18 +98,18 @@ namespace atn { * as it existed prior to the introduction of the * {@link #isPrecedenceFilterSuppressed} method. */ - size_t getOuterContextDepth() const ; + size_t getOuterContextDepth() const; bool isPrecedenceFilterSuppressed() const; void setPrecedenceFilterSuppressed(bool value); /// An ATN configuration is equal to another if both have /// the same state, they predict the same alternative, and /// syntactic/semantic contexts are the same. - bool operator == (const ATNConfig &other) const; - bool operator != (const ATNConfig &other) const; + bool operator==(const ATNConfig &other) const; + bool operator!=(const ATNConfig &other) const; - virtual std::string toString(); - std::string toString(bool showAlt); + virtual std::string toString() const; + std::string toString(bool showAlt) const; private: /** diff --git a/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp b/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp index 8c84a91e66..9a15c2ff8f 100755 --- a/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +++ b/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp @@ -15,6 +15,8 @@ using namespace antlr4::atn; using namespace antlrcpp; +ATNConfigSet::ATNConfigSet() : ATNConfigSet(true) {} + ATNConfigSet::ATNConfigSet(bool fullCtx) : fullCtx(fullCtx) { InitializeInstanceFields(); } @@ -27,9 +29,6 @@ ATNConfigSet::ATNConfigSet(const Ref &old) : ATNConfigSet(old->ful dipsIntoOuterContext = old->dipsIntoOuterContext; } -ATNConfigSet::~ATNConfigSet() { -} - bool ATNConfigSet::add(const Ref &config) { return add(config, nullptr); } @@ -68,7 +67,7 @@ bool ATNConfigSet::add(const Ref &config, PredictionContextMergeCache existing->setPrecedenceFilterSuppressed(true); } - existing->context = merged; // replace context; no need to alt mapping + existing->context = std::move(merged); // replace context; no need to alt mapping return true; } @@ -80,8 +79,9 @@ bool ATNConfigSet::addAll(const Ref &other) { return false; } -std::vector ATNConfigSet::getStates() { +std::vector ATNConfigSet::getStates() const { std::vector states; + states.reserve(configs.size()); for (const auto &c : configs) { states.push_back(c->state); } @@ -97,7 +97,7 @@ std::vector ATNConfigSet::getStates() { * @since 4.3 */ -BitSet ATNConfigSet::getAlts() { +BitSet ATNConfigSet::getAlts() const { BitSet alts; for (const auto &config : configs) { alts.set(config->alt); @@ -105,8 +105,9 @@ BitSet ATNConfigSet::getAlts() { return alts; } -std::vector> ATNConfigSet::getPredicates() { +std::vector> ATNConfigSet::getPredicates() const { std::vector> preds; + preds.reserve(configs.size()); for (const auto &c : configs) { if (c->semanticContext != SemanticContext::NONE) { preds.push_back(c->semanticContext); @@ -131,7 +132,7 @@ void ATNConfigSet::optimizeConfigs(ATNSimulator *interpreter) { } } -bool ATNConfigSet::operator == (const ATNConfigSet &other) { +bool ATNConfigSet::operator==(const ATNConfigSet &other) const { if (&other == this) { return true; } @@ -147,22 +148,23 @@ bool ATNConfigSet::operator == (const ATNConfigSet &other) { return Arrays::equals(configs, other.configs); } -size_t ATNConfigSet::hashCode() { - if (!isReadonly() || _cachedHashCode == 0) { - _cachedHashCode = 1; +size_t ATNConfigSet::hashCode() const { + size_t cachedHashCode = _cachedHashCode.load(std::memory_order_relaxed); + if (!isReadonly() || cachedHashCode == 0) { + cachedHashCode = 1; for (const auto &i : configs) { - _cachedHashCode = 31 * _cachedHashCode + i->hashCode(); // Same as Java's list hashCode impl. + cachedHashCode = 31 * cachedHashCode + i->hashCode(); // Same as Java's list hashCode impl. } + _cachedHashCode.store(cachedHashCode, std::memory_order_relaxed); } - - return _cachedHashCode; + return cachedHashCode; } -size_t ATNConfigSet::size() { +size_t ATNConfigSet::size() const { return configs.size(); } -bool ATNConfigSet::isEmpty() { +bool ATNConfigSet::isEmpty() const { return configs.empty(); } @@ -175,7 +177,7 @@ void ATNConfigSet::clear() { _configLookup.clear(); } -bool ATNConfigSet::isReadonly() { +bool ATNConfigSet::isReadonly() const { return _readonly; } @@ -184,7 +186,7 @@ void ATNConfigSet::setReadonly(bool readonly) { _configLookup.clear(); } -std::string ATNConfigSet::toString() { +std::string ATNConfigSet::toString() const { std::stringstream ss; ss << "["; for (size_t i = 0; i < configs.size(); i++) { @@ -210,7 +212,7 @@ std::string ATNConfigSet::toString() { return ss.str(); } -size_t ATNConfigSet::getHash(ATNConfig *c) { +size_t ATNConfigSet::getHash(const ATNConfig *c) const { size_t hashCode = 7; hashCode = 31 * hashCode + c->state->stateNumber; hashCode = 31 * hashCode + c->alt; diff --git a/runtime/Cpp/runtime/src/atn/ATNConfigSet.h b/runtime/Cpp/runtime/src/atn/ATNConfigSet.h index 850a07c129..f03cd0a026 100755 --- a/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +++ b/runtime/Cpp/runtime/src/atn/ATNConfigSet.h @@ -39,10 +39,13 @@ namespace atn { /// it's a wildcard whereas it is not for LL context merge. const bool fullCtx; - ATNConfigSet(bool fullCtx = true); - ATNConfigSet(const Ref &old); + ATNConfigSet(); - virtual ~ATNConfigSet(); + explicit ATNConfigSet(bool fullCtx); + + explicit ATNConfigSet(const Ref &old); + + virtual ~ATNConfigSet() = default; virtual bool add(const Ref &config); @@ -58,7 +61,7 @@ namespace atn { /// virtual bool add(const Ref &config, PredictionContextMergeCache *mergeCache); - virtual std::vector getStates(); + virtual std::vector getStates() const; /** * Gets the complete set of represented alternatives for the configuration @@ -68,8 +71,8 @@ namespace atn { * * @since 4.3 */ - antlrcpp::BitSet getAlts(); - virtual std::vector> getPredicates(); + antlrcpp::BitSet getAlts() const; + virtual std::vector> getPredicates() const; virtual Ref get(size_t i) const; @@ -77,14 +80,14 @@ namespace atn { bool addAll(const Ref &other); - bool operator == (const ATNConfigSet &other); - virtual size_t hashCode(); - virtual size_t size(); - virtual bool isEmpty(); + bool operator==(const ATNConfigSet &other) const; + virtual size_t hashCode() const; + virtual size_t size() const; + virtual bool isEmpty() const; virtual void clear(); - virtual bool isReadonly(); + virtual bool isReadonly() const; virtual void setReadonly(bool readonly); - virtual std::string toString(); + virtual std::string toString() const; protected: /// Indicates that the set of configurations is read-only. Do not @@ -94,10 +97,10 @@ namespace atn { /// we've made this readonly. bool _readonly; - virtual size_t getHash(ATNConfig *c); // Hash differs depending on set type. + virtual size_t getHash(const ATNConfig *c) const; // Hash differs depending on set type. private: - size_t _cachedHashCode; + mutable std::atomic _cachedHashCode; /// All configs but hashed by (s, i, _, pi) not including context. Wiped out /// when we go readonly as this set becomes a DFA state. diff --git a/runtime/Cpp/runtime/src/atn/ATNState.cpp b/runtime/Cpp/runtime/src/atn/ATNState.cpp index 5dcb85d844..66e0923fe8 100755 --- a/runtime/Cpp/runtime/src/atn/ATNState.cpp +++ b/runtime/Cpp/runtime/src/atn/ATNState.cpp @@ -13,9 +13,6 @@ using namespace antlr4::atn; using namespace antlrcpp; -ATNState::ATNState() { -} - ATNState::~ATNState() { for (auto *transition : transitions) { delete transition; @@ -28,15 +25,15 @@ const std::vector ATNState::serializationNames = { "BLOCK_END", "STAR_LOOP_BACK", "STAR_LOOP_ENTRY", "PLUS_LOOP_BACK", "LOOP_END" }; -size_t ATNState::hashCode() { +size_t ATNState::hashCode() const { return stateNumber; } -bool ATNState::operator == (const ATNState &other) { +bool ATNState::operator==(const ATNState &other) const { return stateNumber == other.stateNumber; } -bool ATNState::isNonGreedyExitState() { +bool ATNState::isNonGreedyExitState() const { return false; } diff --git a/runtime/Cpp/runtime/src/atn/ATNState.h b/runtime/Cpp/runtime/src/atn/ATNState.h index 8a9fb93edd..4484979ae0 100755 --- a/runtime/Cpp/runtime/src/atn/ATNState.h +++ b/runtime/Cpp/runtime/src/atn/ATNState.h @@ -81,16 +81,20 @@ namespace atn { class ANTLR4CPP_PUBLIC ATNState { public: - ATNState(); + static constexpr size_t INITIAL_NUM_TRANSITIONS = 4; + static constexpr size_t INVALID_STATE_NUMBER = std::numeric_limits::max(); + + size_t stateNumber = INVALID_STATE_NUMBER; + size_t ruleIndex = 0; // at runtime, we don't have Rule objects + bool epsilonOnlyTransitions = false; + + ATNState() = default; ATNState(ATNState const&) = delete; virtual ~ATNState(); ATNState& operator=(ATNState const&) = delete; - static constexpr size_t INITIAL_NUM_TRANSITIONS = 4; - static constexpr size_t INVALID_STATE_NUMBER = std::numeric_limits::max(); - enum { ATN_INVALID_TYPE = 0, BASIC = 1, @@ -109,18 +113,13 @@ namespace atn { static const std::vector serializationNames; - size_t stateNumber = INVALID_STATE_NUMBER; - size_t ruleIndex = 0; // at runtime, we don't have Rule objects - bool epsilonOnlyTransitions = false; - - public: - virtual size_t hashCode(); - bool operator == (const ATNState &other); + virtual size_t hashCode() const; + bool operator==(const ATNState &other) const; /// Track the transitions emanating from this ATN state. std::vector transitions; - virtual bool isNonGreedyExitState(); + virtual bool isNonGreedyExitState() const; virtual std::string toString() const; virtual void addTransition(Transition *e); virtual void addTransition(size_t index, Transition *e); diff --git a/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp b/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp index ef8afc25ed..d5c131d76a 100755 --- a/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp +++ b/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp @@ -9,6 +9,3 @@ using namespace antlr4::atn; AbstractPredicateTransition::AbstractPredicateTransition(ATNState *target) : Transition(target) { } - -AbstractPredicateTransition::~AbstractPredicateTransition() { -} diff --git a/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h b/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h index 4865cb1bd1..ee05b587f3 100755 --- a/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h +++ b/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h @@ -13,11 +13,8 @@ namespace atn { class ANTState; class ANTLR4CPP_PUBLIC AbstractPredicateTransition : public Transition { - public: - AbstractPredicateTransition(ATNState *target); - ~AbstractPredicateTransition(); - + explicit AbstractPredicateTransition(ATNState *target); }; } // namespace atn diff --git a/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp b/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp index b69d30d18d..3619cb7cc5 100755 --- a/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +++ b/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp @@ -14,14 +14,11 @@ ArrayPredictionContext::ArrayPredictionContext(Ref c : ArrayPredictionContext({ a->parent }, { a->returnState }) { } -ArrayPredictionContext::ArrayPredictionContext(std::vector> const& parents_, - std::vector const& returnStates) - : PredictionContext(calculateHashCode(parents_, returnStates)), parents(parents_), returnStates(returnStates) { - assert(parents.size() > 0); - assert(returnStates.size() > 0); -} - -ArrayPredictionContext::~ArrayPredictionContext() { +ArrayPredictionContext::ArrayPredictionContext(std::vector> parents, + std::vector returnStates) + : PredictionContext(calculateHashCode(parents, returnStates)), parents(std::move(parents)), returnStates(std::move(returnStates)) { + assert(this->parents.size() > 0); + assert(this->returnStates.size() > 0); } bool ArrayPredictionContext::isEmpty() const { diff --git a/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h b/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h index 53a5b17a03..0b5a4f11bc 100755 --- a/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +++ b/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h @@ -25,9 +25,9 @@ namespace atn { /// Sorted for merge, no duplicates; if present, EMPTY_RETURN_STATE is always last. const std::vector returnStates; - ArrayPredictionContext(Ref const& a); - ArrayPredictionContext(std::vector> const& parents_, std::vector const& returnStates); - virtual ~ArrayPredictionContext(); + explicit ArrayPredictionContext(Ref const &a); + + ArrayPredictionContext(std::vector> parents, std::vector returnStates); virtual bool isEmpty() const override; virtual size_t size() const override; diff --git a/runtime/Cpp/runtime/src/atn/AtomTransition.h b/runtime/Cpp/runtime/src/atn/AtomTransition.h index cc22e5ad9e..1dcb981719 100755 --- a/runtime/Cpp/runtime/src/atn/AtomTransition.h +++ b/runtime/Cpp/runtime/src/atn/AtomTransition.h @@ -14,6 +14,7 @@ namespace atn { class ANTLR4CPP_PUBLIC AtomTransition final : public Transition { public: /// The token type or character value; or, signifies special label. + /// TODO: rename this to label const size_t _label; AtomTransition(ATNState *target, size_t label); diff --git a/runtime/Cpp/runtime/src/atn/BlockEndState.cpp b/runtime/Cpp/runtime/src/atn/BlockEndState.cpp index 098d52af0b..62d333b074 100755 --- a/runtime/Cpp/runtime/src/atn/BlockEndState.cpp +++ b/runtime/Cpp/runtime/src/atn/BlockEndState.cpp @@ -7,9 +7,6 @@ using namespace antlr4::atn; -BlockEndState::BlockEndState() : startState(nullptr) { -} - size_t BlockEndState::getStateType() { return BLOCK_END; } diff --git a/runtime/Cpp/runtime/src/atn/BlockEndState.h b/runtime/Cpp/runtime/src/atn/BlockEndState.h index b24bee1b4f..ce2739d121 100755 --- a/runtime/Cpp/runtime/src/atn/BlockEndState.h +++ b/runtime/Cpp/runtime/src/atn/BlockEndState.h @@ -15,8 +15,6 @@ namespace atn { public: BlockStartState *startState = nullptr; - BlockEndState(); - virtual size_t getStateType() override; }; diff --git a/runtime/Cpp/runtime/src/atn/BlockStartState.cpp b/runtime/Cpp/runtime/src/atn/BlockStartState.cpp index 44cca8f775..46463b7350 100644 --- a/runtime/Cpp/runtime/src/atn/BlockStartState.cpp +++ b/runtime/Cpp/runtime/src/atn/BlockStartState.cpp @@ -4,6 +4,3 @@ */ #include "BlockStartState.h" - -antlr4::atn::BlockStartState::~BlockStartState() { -} diff --git a/runtime/Cpp/runtime/src/atn/BlockStartState.h b/runtime/Cpp/runtime/src/atn/BlockStartState.h index 725c700f04..2b0052b089 100755 --- a/runtime/Cpp/runtime/src/atn/BlockStartState.h +++ b/runtime/Cpp/runtime/src/atn/BlockStartState.h @@ -13,7 +13,6 @@ namespace atn { /// The start of a regular {@code (...)} block. class ANTLR4CPP_PUBLIC BlockStartState : public DecisionState { public: - ~BlockStartState(); BlockEndState *endState = nullptr; }; diff --git a/runtime/Cpp/runtime/src/atn/DecisionInfo.h b/runtime/Cpp/runtime/src/atn/DecisionInfo.h index cfbb2e9baf..2b43ad8be9 100755 --- a/runtime/Cpp/runtime/src/atn/DecisionInfo.h +++ b/runtime/Cpp/runtime/src/atn/DecisionInfo.h @@ -218,7 +218,7 @@ namespace atn { /// statistics for a particular decision. /// /// The decision number - DecisionInfo(size_t decision); + explicit DecisionInfo(size_t decision); std::string toString() const; }; diff --git a/runtime/Cpp/runtime/src/atn/DecisionState.cpp b/runtime/Cpp/runtime/src/atn/DecisionState.cpp index 924f814a9c..464ca9c020 100755 --- a/runtime/Cpp/runtime/src/atn/DecisionState.cpp +++ b/runtime/Cpp/runtime/src/atn/DecisionState.cpp @@ -7,11 +7,6 @@ using namespace antlr4::atn; -void DecisionState::InitializeInstanceFields() { - decision = -1; - nonGreedy = false; -} - std::string DecisionState::toString() const { return "DECISION " + ATNState::toString(); } diff --git a/runtime/Cpp/runtime/src/atn/DecisionState.h b/runtime/Cpp/runtime/src/atn/DecisionState.h index 005de251a2..a1b12c2ef2 100755 --- a/runtime/Cpp/runtime/src/atn/DecisionState.h +++ b/runtime/Cpp/runtime/src/atn/DecisionState.h @@ -12,16 +12,10 @@ namespace atn { class ANTLR4CPP_PUBLIC DecisionState : public ATNState { public: - int decision; - bool nonGreedy; + int decision = -1; + bool nonGreedy = false; - private: - void InitializeInstanceFields(); - - public: - DecisionState() { - InitializeInstanceFields(); - } + DecisionState() = default; virtual std::string toString() const override; }; diff --git a/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp b/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp index 17223bf1e4..397fa8dc03 100755 --- a/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp +++ b/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp @@ -26,7 +26,7 @@ size_t EmptyPredictionContext::getReturnState(size_t /*index*/) const { return returnState; } -bool EmptyPredictionContext::operator == (const PredictionContext &o) const { +bool EmptyPredictionContext::operator==(const PredictionContext &o) const { return this == &o; } diff --git a/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h b/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h index 93c036c549..8fd7367f11 100755 --- a/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h +++ b/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h @@ -20,7 +20,7 @@ namespace atn { virtual size_t getReturnState(size_t index) const override; virtual std::string toString() const override; - virtual bool operator == (const PredictionContext &o) const override; + virtual bool operator==(const PredictionContext &o) const override; }; } // namespace atn diff --git a/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp b/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp index 550605d32b..67d5b9bc3a 100755 --- a/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +++ b/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp @@ -14,7 +14,7 @@ EpsilonTransition::EpsilonTransition(ATNState *target, size_t outermostPrecedenc : Transition(target), _outermostPrecedenceReturn(outermostPrecedenceReturn) { } -size_t EpsilonTransition::outermostPrecedenceReturn() { +size_t EpsilonTransition::outermostPrecedenceReturn() const { return _outermostPrecedenceReturn; } diff --git a/runtime/Cpp/runtime/src/atn/EpsilonTransition.h b/runtime/Cpp/runtime/src/atn/EpsilonTransition.h index 41fb0fbf82..62bd60e0e6 100755 --- a/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +++ b/runtime/Cpp/runtime/src/atn/EpsilonTransition.h @@ -12,7 +12,7 @@ namespace atn { class ANTLR4CPP_PUBLIC EpsilonTransition final : public Transition { public: - EpsilonTransition(ATNState *target); + explicit EpsilonTransition(ATNState *target); EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn); /** @@ -23,7 +23,7 @@ namespace atn { * @see ParserATNSimulator#applyPrecedenceFilter(ATNConfigSet) * @since 4.4.1 */ - size_t outermostPrecedenceReturn(); + size_t outermostPrecedenceReturn() const; virtual SerializationType getSerializationType() const override; virtual bool isEpsilon() const override; diff --git a/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp b/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp index ddca800889..e7cf22b17f 100755 --- a/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +++ b/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp @@ -22,12 +22,6 @@ using namespace antlr4; using namespace antlr4::atn; using namespace antlrcpp; -LL1Analyzer::LL1Analyzer(const ATN &atn) : _atn(atn) { -} - -LL1Analyzer::~LL1Analyzer() { -} - std::vector LL1Analyzer::getDecisionLookahead(ATNState *s) const { std::vector look; @@ -41,7 +35,7 @@ std::vector LL1Analyzer::getDecisionLookahead(ATNState *s) co ATNConfig::Set lookBusy; antlrcpp::BitSet callRuleStack; - _LOOK(s->transitions[alt]->target, nullptr, PredictionContext::EMPTY, + LOOK(s->transitions[alt]->target, nullptr, PredictionContext::EMPTY, look[alt], lookBusy, callRuleStack, seeThruPreds, false); // Wipe out lookahead for this alternative if we found nothing @@ -64,12 +58,12 @@ misc::IntervalSet LL1Analyzer::LOOK(ATNState *s, ATNState *stopState, RuleContex ATNConfig::Set lookBusy; antlrcpp::BitSet callRuleStack; - _LOOK(s, stopState, lookContext, r, lookBusy, callRuleStack, seeThruPreds, true); + LOOK(s, stopState, lookContext, r, lookBusy, callRuleStack, seeThruPreds, true); return r; } -void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, Ref const& ctx, misc::IntervalSet &look, +void LL1Analyzer::LOOK(ATNState *s, ATNState *stopState, Ref const& ctx, misc::IntervalSet &look, ATNConfig::Set &lookBusy, antlrcpp::BitSet &calledRuleStack, bool seeThruPreds, bool addEOF) const { Ref c = std::make_shared(s, 0, ctx); @@ -110,7 +104,7 @@ void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, Ref // run thru all possible stack tops in ctx for (size_t i = 0; i < ctx->size(); i++) { ATNState *returnState = _atn.states[ctx->getReturnState(i)]; - _LOOK(returnState, stopState, ctx->getParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF); + LOOK(returnState, stopState, ctx->getParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF); } return; } @@ -131,16 +125,16 @@ void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, Ref }); calledRuleStack.set((static_cast(t))->target->ruleIndex); - _LOOK(t->target, stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF); + LOOK(t->target, stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF); } else if (is(t)) { if (seeThruPreds) { - _LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF); + LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF); } else { look.add(HIT_PRED); } } else if (t->isEpsilon()) { - _LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF); + LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF); } else if (t->getSerializationType() == Transition::WILDCARD) { look.addAll(misc::IntervalSet::of(Token::MIN_USER_TOKEN_TYPE, static_cast(_atn.maxTokenType))); } else { diff --git a/runtime/Cpp/runtime/src/atn/LL1Analyzer.h b/runtime/Cpp/runtime/src/atn/LL1Analyzer.h index 624ce1a473..071e01e918 100755 --- a/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +++ b/runtime/Cpp/runtime/src/atn/LL1Analyzer.h @@ -6,23 +6,20 @@ #pragma once #include "Token.h" -#include "support/BitSet.h" -#include "atn/PredictionContext.h" #include "atn/ATNConfig.h" +#include "atn/PredictionContext.h" +#include "support/BitSet.h" namespace antlr4 { namespace atn { - class ANTLR4CPP_PUBLIC LL1Analyzer { + class ANTLR4CPP_PUBLIC LL1Analyzer final { public: /// Special value added to the lookahead sets to indicate that we hit /// a predicate during analysis if {@code seeThruPreds==false}. static constexpr size_t HIT_PRED = Token::INVALID_TYPE; - const atn::ATN &_atn; - - LL1Analyzer(const atn::ATN &atn); - virtual ~LL1Analyzer(); + explicit LL1Analyzer(const atn::ATN &atn) : _atn(atn) {} /// /// Calculates the SLL(1) expected lookahead set for each outgoing transition @@ -33,7 +30,7 @@ namespace atn { /// /// the ATN state /// the expected symbols for each outgoing transition of {@code s}. - virtual std::vector getDecisionLookahead(ATNState *s) const; + std::vector getDecisionLookahead(ATNState *s) const; /// /// Compute set of tokens that can follow {@code s} in the ATN in the @@ -50,7 +47,7 @@ namespace atn { /// /// The set of tokens that can follow {@code s} in the ATN in the /// specified {@code ctx}. - virtual misc::IntervalSet LOOK(ATNState *s, RuleContext *ctx) const; + misc::IntervalSet LOOK(ATNState *s, RuleContext *ctx) const; /// /// Compute set of tokens that can follow {@code s} in the ATN in the @@ -69,7 +66,7 @@ namespace atn { /// /// The set of tokens that can follow {@code s} in the ATN in the /// specified {@code ctx}. - virtual misc::IntervalSet LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx) const; + misc::IntervalSet LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx) const; /// /// Compute set of tokens that can follow {@code s} in the ATN in the @@ -100,9 +97,12 @@ namespace atn { /// Add to the result if the end of the /// outermost context is reached. This parameter has no effect if {@code ctx} /// is {@code null}. - protected: - virtual void _LOOK(ATNState *s, ATNState *stopState, Ref const& ctx, misc::IntervalSet &look, - ATNConfig::Set &lookBusy, antlrcpp::BitSet &calledRuleStack, bool seeThruPreds, bool addEOF) const; + private: + void LOOK(ATNState *s, ATNState *stopState, Ref const &ctx, + misc::IntervalSet &look, ATNConfig::Set &lookBusy, antlrcpp::BitSet &calledRuleStack, + bool seeThruPreds, bool addEOF) const; + + const atn::ATN &_atn; }; } // namespace atn diff --git a/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp b/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp index db91c3f8ce..4f494e1072 100755 --- a/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp @@ -16,13 +16,13 @@ using namespace antlr4::atn; using namespace antlrcpp; -LexerATNConfig::LexerATNConfig(ATNState *state, int alt, Ref const& context) - : ATNConfig(state, alt, context, SemanticContext::NONE), _passedThroughNonGreedyDecision(false) { +LexerATNConfig::LexerATNConfig(ATNState *state, int alt, Ref context) + : ATNConfig(state, alt, std::move(context), SemanticContext::NONE), _passedThroughNonGreedyDecision(false) { } -LexerATNConfig::LexerATNConfig(ATNState *state, int alt, Ref const& context, - Ref const& lexerActionExecutor) - : ATNConfig(state, alt, context, SemanticContext::NONE), _lexerActionExecutor(lexerActionExecutor), +LexerATNConfig::LexerATNConfig(ATNState *state, int alt, Ref context, + Ref lexerActionExecutor) + : ATNConfig(state, alt, std::move(context), SemanticContext::NONE), _lexerActionExecutor(std::move(lexerActionExecutor)), _passedThroughNonGreedyDecision(false) { } @@ -31,21 +31,21 @@ LexerATNConfig::LexerATNConfig(Ref const& c, ATNState *state) _passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) { } -LexerATNConfig::LexerATNConfig(Ref const& c, ATNState *state, Ref const& lexerActionExecutor) - : ATNConfig(c, state, c->context, c->semanticContext), _lexerActionExecutor(lexerActionExecutor), +LexerATNConfig::LexerATNConfig(Ref const& c, ATNState *state, Ref lexerActionExecutor) + : ATNConfig(c, state, c->context, c->semanticContext), _lexerActionExecutor(std::move(lexerActionExecutor)), _passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) { } -LexerATNConfig::LexerATNConfig(Ref const& c, ATNState *state, Ref const& context) - : ATNConfig(c, state, context, c->semanticContext), _lexerActionExecutor(c->_lexerActionExecutor), +LexerATNConfig::LexerATNConfig(Ref const& c, ATNState *state, Ref context) + : ATNConfig(c, state, std::move(context), c->semanticContext), _lexerActionExecutor(c->_lexerActionExecutor), _passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) { } -Ref LexerATNConfig::getLexerActionExecutor() const { +const Ref& LexerATNConfig::getLexerActionExecutor() const { return _lexerActionExecutor; } -bool LexerATNConfig::hasPassedThroughNonGreedyDecision() { +bool LexerATNConfig::hasPassedThroughNonGreedyDecision() const { return _passedThroughNonGreedyDecision; } @@ -61,7 +61,7 @@ size_t LexerATNConfig::hashCode() const { return hashCode; } -bool LexerATNConfig::operator == (const LexerATNConfig& other) const +bool LexerATNConfig::operator==(const LexerATNConfig& other) const { if (this == &other) return true; @@ -75,7 +75,7 @@ bool LexerATNConfig::operator == (const LexerATNConfig& other) const return false; } - return ATNConfig::operator == (other); + return ATNConfig::operator==(other); } bool LexerATNConfig::checkNonGreedyDecision(Ref const& source, ATNState *target) { diff --git a/runtime/Cpp/runtime/src/atn/LexerATNConfig.h b/runtime/Cpp/runtime/src/atn/LexerATNConfig.h index e25d3d1c54..104dd09a3e 100755 --- a/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +++ b/runtime/Cpp/runtime/src/atn/LexerATNConfig.h @@ -12,23 +12,23 @@ namespace atn { class ANTLR4CPP_PUBLIC LexerATNConfig : public ATNConfig { public: - LexerATNConfig(ATNState *state, int alt, Ref const& context); - LexerATNConfig(ATNState *state, int alt, Ref const& context, Ref const& lexerActionExecutor); + LexerATNConfig(ATNState *state, int alt, Ref context); + LexerATNConfig(ATNState *state, int alt, Ref context, Ref lexerActionExecutor); LexerATNConfig(Ref const& c, ATNState *state); - LexerATNConfig(Ref const& c, ATNState *state, Ref const& lexerActionExecutor); - LexerATNConfig(Ref const& c, ATNState *state, Ref const& context); + LexerATNConfig(Ref const& c, ATNState *state, Ref lexerActionExecutor); + LexerATNConfig(Ref const& c, ATNState *state, Ref context); /** * Gets the {@link LexerActionExecutor} capable of executing the embedded * action(s) for the current configuration. */ - Ref getLexerActionExecutor() const; - bool hasPassedThroughNonGreedyDecision(); + const Ref& getLexerActionExecutor() const; + bool hasPassedThroughNonGreedyDecision() const; virtual size_t hashCode() const override; - bool operator == (const LexerATNConfig& other) const; + bool operator==(const LexerATNConfig& other) const; private: /** diff --git a/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp b/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp index 1febd4609b..0bfdde2048 100755 --- a/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp @@ -263,7 +263,7 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c bool treatEofAsEpsilon = t == Token::EOF; Ref config = std::make_shared(std::static_pointer_cast(c), - target, lexerActionExecutor); + target, std::move(lexerActionExecutor)); if (closure(input, config, reach, currentAltReachedAcceptState, true, treatEofAsEpsilon)) { // any remaining configs for this alt have a lower priority than diff --git a/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h b/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h index 1c647cb16d..500ade0669 100755 --- a/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +++ b/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h @@ -88,7 +88,7 @@ namespace atn { LexerATNSimulator(const ATN &atn, std::vector &decisionToDFA, PredictionContextCache &sharedContextCache); LexerATNSimulator(Lexer *recog, const ATN &atn, std::vector &decisionToDFA, PredictionContextCache &sharedContextCache); - virtual ~LexerATNSimulator () {} + virtual ~LexerATNSimulator() = default; virtual void copyState(LexerATNSimulator *simulator); virtual size_t match(CharStream *input, size_t mode); diff --git a/runtime/Cpp/runtime/src/atn/LexerAction.cpp b/runtime/Cpp/runtime/src/atn/LexerAction.cpp index 983ba6d52c..cf3a55fde2 100644 --- a/runtime/Cpp/runtime/src/atn/LexerAction.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerAction.cpp @@ -4,6 +4,3 @@ */ #include "LexerAction.h" - -antlr4::atn::LexerAction::~LexerAction() { -} diff --git a/runtime/Cpp/runtime/src/atn/LexerAction.h b/runtime/Cpp/runtime/src/atn/LexerAction.h index 8e833b669f..e1c5528b59 100755 --- a/runtime/Cpp/runtime/src/atn/LexerAction.h +++ b/runtime/Cpp/runtime/src/atn/LexerAction.h @@ -21,7 +21,7 @@ namespace atn { /// class ANTLR4CPP_PUBLIC LexerAction { public: - virtual ~LexerAction(); + virtual ~LexerAction() = default; /// /// Gets the serialization type of the lexer action. diff --git a/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp b/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp index 328e5d7b31..41b44ac56c 100755 --- a/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp @@ -15,22 +15,19 @@ using namespace antlr4::atn; using namespace antlr4::misc; using namespace antlrcpp; -LexerActionExecutor::LexerActionExecutor(const std::vector> &lexerActions) - : _lexerActions(lexerActions), _hashCode(generateHashCode()) { -} - -LexerActionExecutor::~LexerActionExecutor() { +LexerActionExecutor::LexerActionExecutor(std::vector> lexerActions) + : _lexerActions(std::move(lexerActions)), _hashCode(generateHashCode()) { } Ref LexerActionExecutor::append(Ref const& lexerActionExecutor, - Ref const& lexerAction) { + Ref lexerAction) { if (lexerActionExecutor == nullptr) { - return std::make_shared(std::vector> { lexerAction }); + return std::make_shared(std::vector> { std::move(lexerAction) }); } std::vector> lexerActions = lexerActionExecutor->_lexerActions; // Make a copy. - lexerActions.push_back(lexerAction); - return std::make_shared(lexerActions); + lexerActions.push_back(std::move(lexerAction)); + return std::make_shared(std::move(lexerActions)); } Ref LexerActionExecutor::fixOffsetBeforeMatch(int offset) { @@ -49,10 +46,10 @@ Ref LexerActionExecutor::fixOffsetBeforeMatch(int offset) { return shared_from_this(); } - return std::make_shared(updatedLexerActions); + return std::make_shared(std::move(updatedLexerActions)); } -std::vector> LexerActionExecutor::getLexerActions() const { +const std::vector>& LexerActionExecutor::getLexerActions() const { return _lexerActions; } @@ -84,7 +81,7 @@ size_t LexerActionExecutor::hashCode() const { return _hashCode; } -bool LexerActionExecutor::operator == (const LexerActionExecutor &obj) const { +bool LexerActionExecutor::operator==(const LexerActionExecutor &obj) const { if (&obj == this) { return true; } @@ -92,7 +89,7 @@ bool LexerActionExecutor::operator == (const LexerActionExecutor &obj) const { return _hashCode == obj._hashCode && Arrays::equals(_lexerActions, obj._lexerActions); } -bool LexerActionExecutor::operator != (const LexerActionExecutor &obj) const { +bool LexerActionExecutor::operator!=(const LexerActionExecutor &obj) const { return !operator==(obj); } diff --git a/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h b/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h index 488b54c01d..c4703321d8 100755 --- a/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +++ b/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h @@ -22,8 +22,7 @@ namespace atn { /// /// Constructs an executor for a sequence of actions. /// The lexer actions to execute. - LexerActionExecutor(const std::vector> &lexerActions); - virtual ~LexerActionExecutor(); + explicit LexerActionExecutor(std::vector> lexerActions); /// /// Creates a which executes the actions for @@ -40,7 +39,7 @@ namespace atn { /// A for executing the combine actions /// of {@code lexerActionExecutor} and {@code lexerAction}. static Ref append(Ref const& lexerActionExecutor, - Ref const& lexerAction); + Ref lexerAction); /// /// Creates a which encodes the current offset @@ -75,7 +74,7 @@ namespace atn { /// /// Gets the lexer actions to be executed by this executor. /// The lexer actions to be executed by this executor. - virtual std::vector> getLexerActions() const; + virtual const std::vector>& getLexerActions() const; /// /// Execute the actions encapsulated by this executor within the context of a @@ -98,8 +97,8 @@ namespace atn { virtual void execute(Lexer *lexer, CharStream *input, size_t startIndex); virtual size_t hashCode() const; - virtual bool operator == (const LexerActionExecutor &obj) const; - virtual bool operator != (const LexerActionExecutor &obj) const; + virtual bool operator==(const LexerActionExecutor &obj) const; + virtual bool operator!=(const LexerActionExecutor &obj) const; private: const std::vector> _lexerActions; diff --git a/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp b/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp index 959beab3d5..9cae8a8b03 100755 --- a/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp @@ -37,7 +37,7 @@ size_t LexerChannelAction::hashCode() const { return MurmurHash::finish(hash, 2); } -bool LexerChannelAction::operator == (const LexerAction &obj) const { +bool LexerChannelAction::operator==(const LexerAction &obj) const { if (&obj == this) { return true; } diff --git a/runtime/Cpp/runtime/src/atn/LexerChannelAction.h b/runtime/Cpp/runtime/src/atn/LexerChannelAction.h index 73e3a26bf6..bb98e507f3 100755 --- a/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +++ b/runtime/Cpp/runtime/src/atn/LexerChannelAction.h @@ -25,7 +25,7 @@ namespace atn { /// /// Constructs a new {@code channel} action with the specified channel value. /// The channel value to pass to . - LexerChannelAction(int channel); + explicit LexerChannelAction(int channel); /// /// Gets the channel to use for the created by the lexer. @@ -52,7 +52,7 @@ namespace atn { virtual void execute(Lexer *lexer) override; virtual size_t hashCode() const override; - virtual bool operator == (const LexerAction &obj) const override; + virtual bool operator==(const LexerAction &obj) const override; virtual std::string toString() const override; private: diff --git a/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp b/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp index 9ea396a4c5..649c8c1e8b 100755 --- a/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp @@ -13,8 +13,8 @@ using namespace antlr4; using namespace antlr4::atn; using namespace antlr4::misc; -LexerIndexedCustomAction::LexerIndexedCustomAction(int offset, Ref const& action) - : _offset(offset), _action(action) { +LexerIndexedCustomAction::LexerIndexedCustomAction(int offset, Ref action) + : _offset(offset), _action(std::move(action)) { } int LexerIndexedCustomAction::getOffset() const { @@ -45,7 +45,7 @@ size_t LexerIndexedCustomAction::hashCode() const { return MurmurHash::finish(hash, 2); } -bool LexerIndexedCustomAction::operator == (const LexerAction &obj) const { +bool LexerIndexedCustomAction::operator==(const LexerAction &obj) const { if (&obj == this) { return true; } diff --git a/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h b/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h index bb371f8e3a..797953d8c5 100755 --- a/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +++ b/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h @@ -38,7 +38,7 @@ namespace atn { /// executed. /// The lexer action to execute at a particular offset in the /// input . - LexerIndexedCustomAction(int offset, Ref const& action); + LexerIndexedCustomAction(int offset, Ref action); /// /// Gets the location in the input at which the lexer @@ -69,7 +69,7 @@ namespace atn { virtual void execute(Lexer *lexer) override; virtual size_t hashCode() const override; - virtual bool operator == (const LexerAction &obj) const override; + virtual bool operator==(const LexerAction &obj) const override; virtual std::string toString() const override; private: diff --git a/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp b/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp index 0bda8b7afe..974a9d0614 100755 --- a/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp @@ -15,7 +15,7 @@ using namespace antlr4::misc; LexerModeAction::LexerModeAction(int mode) : _mode(mode) { } -int LexerModeAction::getMode() { +int LexerModeAction::getMode() const { return _mode; } @@ -38,7 +38,7 @@ size_t LexerModeAction::hashCode() const { return MurmurHash::finish(hash, 2); } -bool LexerModeAction::operator == (const LexerAction &obj) const { +bool LexerModeAction::operator==(const LexerAction &obj) const { if (&obj == this) { return true; } diff --git a/runtime/Cpp/runtime/src/atn/LexerModeAction.h b/runtime/Cpp/runtime/src/atn/LexerModeAction.h index 49a858b371..147ea7b4ea 100755 --- a/runtime/Cpp/runtime/src/atn/LexerModeAction.h +++ b/runtime/Cpp/runtime/src/atn/LexerModeAction.h @@ -23,13 +23,13 @@ namespace atn { /// /// Constructs a new {@code mode} action with the specified mode value. /// The mode value to pass to . - LexerModeAction(int mode); + explicit LexerModeAction(int mode); /// /// Get the lexer mode this action should transition the lexer to. /// /// The lexer mode for this {@code mode} command. - int getMode(); + int getMode() const; /// /// {@inheritDoc} diff --git a/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp b/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp index 99b2dd99bf..9167424a7a 100755 --- a/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp @@ -12,14 +12,11 @@ using namespace antlr4; using namespace antlr4::atn; using namespace antlr4::misc; -const Ref LexerMoreAction::getInstance() { +const Ref& LexerMoreAction::getInstance() { static Ref instance(new LexerMoreAction()); return instance; } -LexerMoreAction::LexerMoreAction() { -} - LexerActionType LexerMoreAction::getActionType() const { return LexerActionType::MORE; } @@ -38,7 +35,7 @@ size_t LexerMoreAction::hashCode() const { return MurmurHash::finish(hash, 1); } -bool LexerMoreAction::operator == (const LexerAction &obj) const { +bool LexerMoreAction::operator==(const LexerAction &obj) const { return &obj == this; } diff --git a/runtime/Cpp/runtime/src/atn/LexerMoreAction.h b/runtime/Cpp/runtime/src/atn/LexerMoreAction.h index ee3b2aa617..1b2a22ab2e 100755 --- a/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +++ b/runtime/Cpp/runtime/src/atn/LexerMoreAction.h @@ -25,7 +25,7 @@ namespace atn { /// /// Provides a singleton instance of this parameterless lexer action. /// - static const Ref getInstance(); + static const Ref& getInstance(); /// /// {@inheritDoc} @@ -45,12 +45,12 @@ namespace atn { virtual void execute(Lexer *lexer) override; virtual size_t hashCode() const override; - virtual bool operator == (const LexerAction &obj) const override; + virtual bool operator==(const LexerAction &obj) const override; virtual std::string toString() const override; private: /// Constructs the singleton instance of the lexer {@code more} command. - LexerMoreAction(); + LexerMoreAction() = default; }; } // namespace atn diff --git a/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp b/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp index cac0996f48..1a76a69c8b 100755 --- a/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp @@ -12,14 +12,11 @@ using namespace antlr4; using namespace antlr4::atn; using namespace antlr4::misc; -const Ref LexerPopModeAction::getInstance() { +const Ref& LexerPopModeAction::getInstance() { static Ref instance(new LexerPopModeAction()); return instance; } -LexerPopModeAction::LexerPopModeAction() { -} - LexerActionType LexerPopModeAction::getActionType() const { return LexerActionType::POP_MODE; } @@ -38,7 +35,7 @@ size_t LexerPopModeAction::hashCode() const { return MurmurHash::finish(hash, 1); } -bool LexerPopModeAction::operator == (const LexerAction &obj) const { +bool LexerPopModeAction::operator==(const LexerAction &obj) const { return &obj == this; } diff --git a/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h b/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h index 497305c963..00148b8afa 100755 --- a/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +++ b/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h @@ -25,7 +25,7 @@ namespace atn { /// /// Provides a singleton instance of this parameterless lexer action. /// - static const Ref getInstance(); + static const Ref& getInstance(); /// /// {@inheritDoc} @@ -45,12 +45,12 @@ namespace atn { virtual void execute(Lexer *lexer) override; virtual size_t hashCode() const override; - virtual bool operator == (const LexerAction &obj) const override; + virtual bool operator==(const LexerAction &obj) const override; virtual std::string toString() const override; private: /// Constructs the singleton instance of the lexer {@code popMode} command. - LexerPopModeAction(); + LexerPopModeAction() = default; }; } // namespace atn diff --git a/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp b/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp index 017abed04c..d91e24287f 100755 --- a/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp @@ -38,7 +38,7 @@ size_t LexerPushModeAction::hashCode() const { return MurmurHash::finish(hash, 2); } -bool LexerPushModeAction::operator == (const LexerAction &obj) const { +bool LexerPushModeAction::operator==(const LexerAction &obj) const { if (&obj == this) { return true; } diff --git a/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h b/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h index 43cb888c79..4246e92c8b 100755 --- a/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +++ b/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h @@ -23,7 +23,7 @@ namespace atn { /// /// Constructs a new {@code pushMode} action with the specified mode value. /// The mode value to pass to . - LexerPushModeAction(int mode); + explicit LexerPushModeAction(int mode); /// /// Get the lexer mode this action should transition the lexer to. @@ -50,7 +50,7 @@ namespace atn { virtual void execute(Lexer *lexer) override; virtual size_t hashCode() const override; - virtual bool operator == (const LexerAction &obj) const override; + virtual bool operator==(const LexerAction &obj) const override; virtual std::string toString() const override; private: diff --git a/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp b/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp index 01947ce78c..bef5fb4c8b 100755 --- a/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp @@ -12,14 +12,11 @@ using namespace antlr4; using namespace antlr4::atn; using namespace antlr4::misc; -const Ref LexerSkipAction::getInstance() { +const Ref& LexerSkipAction::getInstance() { static Ref instance(new LexerSkipAction()); return instance; } -LexerSkipAction::LexerSkipAction() { -} - LexerActionType LexerSkipAction::getActionType() const { return LexerActionType::SKIP; } diff --git a/runtime/Cpp/runtime/src/atn/LexerSkipAction.h b/runtime/Cpp/runtime/src/atn/LexerSkipAction.h index 5bd2e1c166..38d4399eca 100755 --- a/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +++ b/runtime/Cpp/runtime/src/atn/LexerSkipAction.h @@ -23,7 +23,7 @@ namespace atn { class ANTLR4CPP_PUBLIC LexerSkipAction final : public LexerAction { public: /// Provides a singleton instance of this parameterless lexer action. - static const Ref getInstance(); + static const Ref& getInstance(); /// /// {@inheritDoc} @@ -43,12 +43,12 @@ namespace atn { virtual void execute(Lexer *lexer) override; virtual size_t hashCode() const override; - virtual bool operator == (const LexerAction &obj) const override; + virtual bool operator==(const LexerAction &obj) const override; virtual std::string toString() const override; private: /// Constructs the singleton instance of the lexer {@code skip} command. - LexerSkipAction(); + LexerSkipAction() = default; }; } // namespace atn diff --git a/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp b/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp index 006778adc6..2f20f5ab1d 100755 --- a/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +++ b/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp @@ -38,7 +38,7 @@ size_t LexerTypeAction::hashCode() const { return MurmurHash::finish(hash, 2); } -bool LexerTypeAction::operator == (const LexerAction &obj) const { +bool LexerTypeAction::operator==(const LexerAction &obj) const { if (&obj == this) { return true; } diff --git a/runtime/Cpp/runtime/src/atn/LexerTypeAction.h b/runtime/Cpp/runtime/src/atn/LexerTypeAction.h index 1c4a8a17c1..3a5b56ab94 100755 --- a/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +++ b/runtime/Cpp/runtime/src/atn/LexerTypeAction.h @@ -18,7 +18,7 @@ namespace atn { /// /// Constructs a new {@code type} action with the specified token type value. /// The type to assign to the token using . - LexerTypeAction(int type); + explicit LexerTypeAction(int type); /// /// Gets the type to assign to a token created by the lexer. @@ -44,7 +44,7 @@ namespace atn { virtual void execute(Lexer *lexer) override; virtual size_t hashCode() const override; - virtual bool operator == (const LexerAction &obj) const override; + virtual bool operator==(const LexerAction &obj) const override; virtual std::string toString() const override; private: diff --git a/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp b/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp index b02910dd06..c4fa94d6ac 100755 --- a/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +++ b/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp @@ -10,7 +10,7 @@ using namespace antlr4; using namespace antlr4::atn; -NotSetTransition::NotSetTransition(ATNState *target, const misc::IntervalSet &set) : SetTransition(target, set) { +NotSetTransition::NotSetTransition(ATNState *target, misc::IntervalSet set) : SetTransition(target, std::move(set)) { } Transition::SerializationType NotSetTransition::getSerializationType() const { diff --git a/runtime/Cpp/runtime/src/atn/NotSetTransition.h b/runtime/Cpp/runtime/src/atn/NotSetTransition.h index 214fb06031..3b69c9092a 100755 --- a/runtime/Cpp/runtime/src/atn/NotSetTransition.h +++ b/runtime/Cpp/runtime/src/atn/NotSetTransition.h @@ -12,7 +12,7 @@ namespace atn { class ANTLR4CPP_PUBLIC NotSetTransition final : public SetTransition { public: - NotSetTransition(ATNState *target, const misc::IntervalSet &set); + NotSetTransition(ATNState *target, misc::IntervalSet set); virtual SerializationType getSerializationType() const override; diff --git a/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp b/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp index a731def936..a06d39b086 100755 --- a/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +++ b/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp @@ -7,6 +7,6 @@ using namespace antlr4::atn; -size_t OrderedATNConfigSet::getHash(ATNConfig *c) { +size_t OrderedATNConfigSet::getHash(const ATNConfig *c) const { return c->hashCode(); } diff --git a/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h b/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h index 4ce43bb965..00f6aca0e7 100755 --- a/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +++ b/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h @@ -13,7 +13,7 @@ namespace atn { class ANTLR4CPP_PUBLIC OrderedATNConfigSet : public ATNConfigSet { protected: - virtual size_t getHash(ATNConfig *c) override; + size_t getHash(const ATNConfig *c) const override; }; } // namespace atn diff --git a/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h b/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h index ba7a4b64e3..c6150fc89a 100755 --- a/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +++ b/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h @@ -13,7 +13,6 @@ namespace atn { /// Decision state for {@code A+} and {@code (A|B)+}. It has two transitions: /// one to the loop back to start of the block and one to exit. class ANTLR4CPP_PUBLIC PlusLoopbackState final : public DecisionState { - public: virtual size_t getStateType() override; }; diff --git a/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp b/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp index 3d86bfee0b..1918c894be 100755 --- a/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +++ b/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp @@ -11,7 +11,7 @@ using namespace antlr4; using namespace antlr4::atn; PredicateEvalInfo::PredicateEvalInfo(size_t decision, TokenStream *input, size_t startIndex, size_t stopIndex, - Ref const& semctx, bool evalResult, size_t predictedAlt, bool fullCtx) + Ref semctx, bool evalResult, size_t predictedAlt, bool fullCtx) : DecisionEventInfo(decision, nullptr, input, startIndex, stopIndex, fullCtx), - semctx(semctx), predictedAlt(predictedAlt), evalResult(evalResult) { + semctx(std::move(semctx)), predictedAlt(predictedAlt), evalResult(evalResult) { } diff --git a/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h b/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h index b0513aea2b..258cdae864 100755 --- a/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +++ b/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h @@ -55,7 +55,7 @@ namespace atn { /// /// PredicateEvalInfo(size_t decision, TokenStream *input, size_t startIndex, size_t stopIndex, - Ref const& semctx, bool evalResult, size_t predictedAlt, bool fullCtx); + Ref semctx, bool evalResult, size_t predictedAlt, bool fullCtx); }; } // namespace atn diff --git a/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h b/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h index 79ecd00b48..56065151ac 100755 --- a/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +++ b/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h @@ -13,7 +13,7 @@ namespace atn { class ANTLR4CPP_PUBLIC ProfilingATNSimulator : public ParserATNSimulator { public: - ProfilingATNSimulator(Parser *parser); + explicit ProfilingATNSimulator(Parser *parser); virtual size_t adaptivePredict(TokenStream *input, size_t decision, ParserRuleContext *outerContext) override; diff --git a/runtime/Cpp/runtime/src/atn/RuleStartState.cpp b/runtime/Cpp/runtime/src/atn/RuleStartState.cpp index 555f8c2e93..b1ceb259b7 100755 --- a/runtime/Cpp/runtime/src/atn/RuleStartState.cpp +++ b/runtime/Cpp/runtime/src/atn/RuleStartState.cpp @@ -7,10 +7,6 @@ using namespace antlr4::atn; -RuleStartState::RuleStartState() { - isLeftRecursiveRule = false; -} - size_t RuleStartState::getStateType() { return RULE_START; } diff --git a/runtime/Cpp/runtime/src/atn/RuleStartState.h b/runtime/Cpp/runtime/src/atn/RuleStartState.h index 94ab0e4138..3e6e7e4556 100755 --- a/runtime/Cpp/runtime/src/atn/RuleStartState.h +++ b/runtime/Cpp/runtime/src/atn/RuleStartState.h @@ -12,8 +12,6 @@ namespace atn { class ANTLR4CPP_PUBLIC RuleStartState final : public ATNState { public: - RuleStartState(); - RuleStopState *stopState = nullptr; bool isLeftRecursiveRule = false; diff --git a/runtime/Cpp/runtime/src/atn/RuleStopState.h b/runtime/Cpp/runtime/src/atn/RuleStopState.h index 8a4a580f6a..db13b0b432 100755 --- a/runtime/Cpp/runtime/src/atn/RuleStopState.h +++ b/runtime/Cpp/runtime/src/atn/RuleStopState.h @@ -15,7 +15,6 @@ namespace atn { /// references to all calls to this rule to compute FOLLOW sets for /// error handling. class ANTLR4CPP_PUBLIC RuleStopState final : public ATNState { - public: virtual size_t getStateType() override; diff --git a/runtime/Cpp/runtime/src/atn/SemanticContext.cpp b/runtime/Cpp/runtime/src/atn/SemanticContext.cpp index cb44017630..99a2938671 100755 --- a/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +++ b/runtime/Cpp/runtime/src/atn/SemanticContext.cpp @@ -137,11 +137,11 @@ SemanticContext::AND::AND(Ref const& a, Ref co std::copy(operands.begin(), operands.end(), std::back_inserter(opnds)); } -std::vector> SemanticContext::AND::getOperands() const { +const std::vector>& SemanticContext::AND::getOperands() const { return opnds; } -bool SemanticContext::AND::operator == (const SemanticContext &other) const { +bool SemanticContext::AND::operator==(const SemanticContext &other) const { if (this == &other) return true; @@ -239,11 +239,11 @@ SemanticContext::OR::OR(Ref const& a, Ref cons std::copy(operands.begin(), operands.end(), std::back_inserter(opnds)); } -std::vector> SemanticContext::OR::getOperands() const { +const std::vector>& SemanticContext::OR::getOperands() const { return opnds; } -bool SemanticContext::OR::operator == (const SemanticContext &other) const { +bool SemanticContext::OR::operator==(const SemanticContext &other) const { if (this == &other) return true; @@ -311,10 +311,7 @@ std::string SemanticContext::OR::toString() const { const Ref SemanticContext::NONE = std::make_shared(INVALID_INDEX, INVALID_INDEX, false); -SemanticContext::~SemanticContext() { -} - -bool SemanticContext::operator != (const SemanticContext &other) const { +bool SemanticContext::operator!=(const SemanticContext &other) const { return !(*this == other); } @@ -369,9 +366,3 @@ std::vector> SemanticContext::filterPr return result; } - - -//------------------ Operator ----------------------------------------------------------------------------------------- - -SemanticContext::Operator::~Operator() { -} diff --git a/runtime/Cpp/runtime/src/atn/SemanticContext.h b/runtime/Cpp/runtime/src/atn/SemanticContext.h index 7ccc16c841..560871761a 100755 --- a/runtime/Cpp/runtime/src/atn/SemanticContext.h +++ b/runtime/Cpp/runtime/src/atn/SemanticContext.h @@ -43,12 +43,12 @@ namespace atn { */ static const Ref NONE; - virtual ~SemanticContext(); + virtual ~SemanticContext() = default; virtual size_t hashCode() const = 0; virtual std::string toString() const = 0; - virtual bool operator == (const SemanticContext &other) const = 0; - virtual bool operator != (const SemanticContext &other) const; + virtual bool operator==(const SemanticContext &other) const = 0; + virtual bool operator!=(const SemanticContext &other) const; /// /// For context independent predicates, we evaluate them without a local @@ -126,7 +126,7 @@ namespace atn { PrecedencePredicate(); public: - PrecedencePredicate(int precedence); + explicit PrecedencePredicate(int precedence); virtual bool eval(Recognizer *parser, RuleContext *parserCallStack) override; virtual Ref evalPrecedence(Recognizer *parser, RuleContext *parserCallStack) override; @@ -144,8 +144,6 @@ namespace atn { */ class ANTLR4CPP_PUBLIC SemanticContext::Operator : public SemanticContext { public: - virtual ~Operator() override; - /** * Gets the operands for the semantic context operator. * @@ -155,7 +153,7 @@ namespace atn { * @since 4.3 */ - virtual std::vector> getOperands() const = 0; + virtual const std::vector>& getOperands() const = 0; }; /** @@ -168,8 +166,8 @@ namespace atn { AND(Ref const& a, Ref const& b) ; - virtual std::vector> getOperands() const override; - virtual bool operator == (const SemanticContext &other) const override; + virtual const std::vector>& getOperands() const override; + virtual bool operator==(const SemanticContext &other) const override; virtual size_t hashCode() const override; /** @@ -191,8 +189,8 @@ namespace atn { OR(Ref const& a, Ref const& b); - virtual std::vector> getOperands() const override; - virtual bool operator == (const SemanticContext &other) const override; + virtual const std::vector>& getOperands() const override; + virtual bool operator==(const SemanticContext &other) const override; virtual size_t hashCode() const override; /** diff --git a/runtime/Cpp/runtime/src/atn/SetTransition.cpp b/runtime/Cpp/runtime/src/atn/SetTransition.cpp index 35d6905be4..7c5561adf2 100755 --- a/runtime/Cpp/runtime/src/atn/SetTransition.cpp +++ b/runtime/Cpp/runtime/src/atn/SetTransition.cpp @@ -11,8 +11,8 @@ using namespace antlr4; using namespace antlr4::atn; -SetTransition::SetTransition(ATNState *target, const misc::IntervalSet &aSet) - : Transition(target), set(aSet.isEmpty() ? misc::IntervalSet::of(Token::INVALID_TYPE) : aSet) { +SetTransition::SetTransition(ATNState *target, misc::IntervalSet aSet) + : Transition(target), set(aSet.isEmpty() ? misc::IntervalSet::of(Token::INVALID_TYPE) : std::move(aSet)) { } Transition::SerializationType SetTransition::getSerializationType() const { diff --git a/runtime/Cpp/runtime/src/atn/SetTransition.h b/runtime/Cpp/runtime/src/atn/SetTransition.h index 044d41a6a3..b70d6e3bc8 100755 --- a/runtime/Cpp/runtime/src/atn/SetTransition.h +++ b/runtime/Cpp/runtime/src/atn/SetTransition.h @@ -16,7 +16,7 @@ namespace atn { public: const misc::IntervalSet set; - SetTransition(ATNState *target, const misc::IntervalSet &set); + SetTransition(ATNState *target, misc::IntervalSet set); virtual SerializationType getSerializationType() const override; diff --git a/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp b/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp index 39ad9fb835..ebe1f9d86a 100755 --- a/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +++ b/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp @@ -9,22 +9,19 @@ using namespace antlr4::atn; -SingletonPredictionContext::SingletonPredictionContext(Ref const& parent, size_t returnState) +SingletonPredictionContext::SingletonPredictionContext(Ref parent, size_t returnState) : PredictionContext(parent ? calculateHashCode(parent, returnState) : calculateEmptyHashCode()), - parent(parent), returnState(returnState) { + parent(std::move(parent)), returnState(returnState) { assert(returnState != ATNState::INVALID_STATE_NUMBER); } -SingletonPredictionContext::~SingletonPredictionContext() { -} - -Ref SingletonPredictionContext::create(Ref const& parent, size_t returnState) { +Ref SingletonPredictionContext::create(Ref parent, size_t returnState) { if (returnState == EMPTY_RETURN_STATE && parent) { // someone can pass in the bits of an array ctx that mean $ return std::dynamic_pointer_cast(EMPTY); } - return std::make_shared(parent, returnState); + return std::make_shared(std::move(parent), returnState); } size_t SingletonPredictionContext::size() const { diff --git a/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h b/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h index f1e993bbae..babd2eb963 100755 --- a/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +++ b/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h @@ -20,10 +20,10 @@ namespace atn { const Ref parent; const size_t returnState; - SingletonPredictionContext(Ref const& parent, size_t returnState); - virtual ~SingletonPredictionContext(); + SingletonPredictionContext(Ref parent, size_t returnState); + virtual ~SingletonPredictionContext() = default; - static Ref create(Ref const& parent, size_t returnState); + static Ref create(Ref parent, size_t returnState); virtual size_t size() const override; virtual Ref getParent(size_t index) const override; diff --git a/runtime/Cpp/runtime/src/atn/StarBlockStartState.h b/runtime/Cpp/runtime/src/atn/StarBlockStartState.h index 8fae316089..ef2f054d81 100755 --- a/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +++ b/runtime/Cpp/runtime/src/atn/StarBlockStartState.h @@ -12,7 +12,6 @@ namespace atn { /// The block that begins a closure loop. class ANTLR4CPP_PUBLIC StarBlockStartState final : public BlockStartState { - public: virtual size_t getStateType() override; }; diff --git a/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp b/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp index 766a858f2e..2c0ecc863c 100755 --- a/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp +++ b/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp @@ -7,9 +7,6 @@ using namespace antlr4::atn; -StarLoopEntryState::StarLoopEntryState() : DecisionState(), isPrecedenceDecision(false) { -} - size_t StarLoopEntryState::getStateType() { return STAR_LOOP_ENTRY; } diff --git a/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h b/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h index a062c58f79..ebab9d485b 100755 --- a/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +++ b/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h @@ -12,8 +12,6 @@ namespace atn { class ANTLR4CPP_PUBLIC StarLoopEntryState final : public DecisionState { public: - StarLoopEntryState(); - /** * Indicates whether this state can benefit from a precedence DFA during SLL * decision making. diff --git a/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp b/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp index f5105896b1..fbf7c93b11 100755 --- a/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +++ b/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp @@ -10,7 +10,7 @@ using namespace antlr4::atn; -StarLoopEntryState *StarLoopbackState::getLoopEntryState() { +StarLoopEntryState *StarLoopbackState::getLoopEntryState() const { return dynamic_cast(transitions[0]->target); } diff --git a/runtime/Cpp/runtime/src/atn/StarLoopbackState.h b/runtime/Cpp/runtime/src/atn/StarLoopbackState.h index f5db3efd85..3d87f65b54 100755 --- a/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +++ b/runtime/Cpp/runtime/src/atn/StarLoopbackState.h @@ -12,7 +12,7 @@ namespace atn { class ANTLR4CPP_PUBLIC StarLoopbackState final : public ATNState { public: - StarLoopEntryState *getLoopEntryState(); + StarLoopEntryState *getLoopEntryState() const; virtual size_t getStateType() override; }; diff --git a/runtime/Cpp/runtime/src/atn/TokensStartState.h b/runtime/Cpp/runtime/src/atn/TokensStartState.h index e534d04ee9..7af591f258 100755 --- a/runtime/Cpp/runtime/src/atn/TokensStartState.h +++ b/runtime/Cpp/runtime/src/atn/TokensStartState.h @@ -12,7 +12,6 @@ namespace atn { /// The Tokens rule start state linking to each lexer rule start state. class ANTLR4CPP_PUBLIC TokensStartState final : public DecisionState { - public: virtual size_t getStateType() override; }; diff --git a/runtime/Cpp/runtime/src/atn/Transition.cpp b/runtime/Cpp/runtime/src/atn/Transition.cpp index 15922a324e..2a431cfe47 100755 --- a/runtime/Cpp/runtime/src/atn/Transition.cpp +++ b/runtime/Cpp/runtime/src/atn/Transition.cpp @@ -25,9 +25,6 @@ Transition::Transition(ATNState *target) { this->target = target; } -Transition::~Transition() { -} - bool Transition::isEpsilon() const { return false; } diff --git a/runtime/Cpp/runtime/src/atn/Transition.h b/runtime/Cpp/runtime/src/atn/Transition.h index ffed2f58f0..dc033839be 100755 --- a/runtime/Cpp/runtime/src/atn/Transition.h +++ b/runtime/Cpp/runtime/src/atn/Transition.h @@ -45,10 +45,10 @@ namespace atn { // ml: this is a reference into the ATN. ATNState *target; - virtual ~Transition(); + virtual ~Transition() = default; protected: - Transition(ATNState *target); + explicit Transition(ATNState *target); public: virtual SerializationType getSerializationType() const = 0; diff --git a/runtime/Cpp/runtime/src/atn/WildcardTransition.h b/runtime/Cpp/runtime/src/atn/WildcardTransition.h index c47c717759..c80a65579b 100755 --- a/runtime/Cpp/runtime/src/atn/WildcardTransition.h +++ b/runtime/Cpp/runtime/src/atn/WildcardTransition.h @@ -12,7 +12,7 @@ namespace atn { class ANTLR4CPP_PUBLIC WildcardTransition final : public Transition { public: - WildcardTransition(ATNState *target); + explicit WildcardTransition(ATNState *target); virtual SerializationType getSerializationType() const override; diff --git a/runtime/Cpp/runtime/src/misc/IntervalSet.h b/runtime/Cpp/runtime/src/misc/IntervalSet.h index 577137e4ec..7f24b78138 100755 --- a/runtime/Cpp/runtime/src/misc/IntervalSet.h +++ b/runtime/Cpp/runtime/src/misc/IntervalSet.h @@ -23,7 +23,7 @@ namespace misc { * the range {@link Integer#MIN_VALUE} to {@link Integer#MAX_VALUE} * (inclusive).

*/ - class ANTLR4CPP_PUBLIC IntervalSet { + class ANTLR4CPP_PUBLIC IntervalSet final { public: static IntervalSet const COMPLETE_CHAR_SET; static IntervalSet const EMPTY_SET; diff --git a/runtime/Cpp/runtime/src/support/BitSet.h b/runtime/Cpp/runtime/src/support/BitSet.h index bf849b1874..bb30364be0 100644 --- a/runtime/Cpp/runtime/src/support/BitSet.h +++ b/runtime/Cpp/runtime/src/support/BitSet.h @@ -54,7 +54,7 @@ namespace antlrcpp { return result; } - std::string toString(){ + std::string toString() const { std::stringstream stream; stream << "{"; bool valueAdded = false;