Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/Cpp/runtime/src/TokenStreamRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ TokenStreamRewriter::TokenStreamRewriter(TokenStream *tokens_) : tokens(tokens_)
}

TokenStreamRewriter::~TokenStreamRewriter() {
for (auto program : _programs) {
for (const auto &program : _programs) {
for (auto *operation : program.second) {
delete operation;
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/Cpp/runtime/src/TokenStreamRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#pragma once

#include "antlr4-common.h"

namespace antlr4 {

/**
Expand Down
2 changes: 2 additions & 0 deletions runtime/Cpp/runtime/src/atn/ATNConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#pragma once

#include "antlr4-common.h"

namespace antlr4 {
namespace atn {

Expand Down
12 changes: 6 additions & 6 deletions runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ bool ATNConfigSet::add(const Ref<ATNConfig> &config, PredictionContextMergeCache
}

bool ATNConfigSet::addAll(const Ref<ATNConfigSet> &other) {
for (auto &c : other->configs) {
for (const auto &c : other->configs) {
add(c);
}
return false;
}

std::vector<ATNState*> ATNConfigSet::getStates() {
std::vector<ATNState*> states;
for (auto c : configs) {
for (const auto &c : configs) {
states.push_back(c->state);
}
return states;
Expand All @@ -99,15 +99,15 @@ std::vector<ATNState*> ATNConfigSet::getStates() {

BitSet ATNConfigSet::getAlts() {
BitSet alts;
for (ATNConfig config : configs) {
for (const ATNConfig &config : configs) {
alts.set(config.alt);
}
return alts;
}

std::vector<Ref<SemanticContext>> ATNConfigSet::getPredicates() {
std::vector<Ref<SemanticContext>> preds;
for (auto c : configs) {
for (const auto &c : configs) {
if (c->semanticContext != SemanticContext::NONE) {
preds.push_back(c->semanticContext);
}
Expand All @@ -126,7 +126,7 @@ void ATNConfigSet::optimizeConfigs(ATNSimulator *interpreter) {
if (_configLookup.empty())
return;

for (auto &config : configs) {
for (const auto &config : configs) {
config->context = interpreter->getCachedContext(config->context);
}
}
Expand All @@ -150,7 +150,7 @@ bool ATNConfigSet::operator == (const ATNConfigSet &other) {
size_t ATNConfigSet::hashCode() {
if (!isReadonly() || _cachedHashCode == 0) {
_cachedHashCode = 1;
for (auto &i : configs) {
for (const auto &i : configs) {
_cachedHashCode = 31 * _cachedHashCode + i->hashCode(); // Same as Java's list hashCode impl.
}
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/Cpp/runtime/src/atn/ATNSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ std::vector<size_t> ATNSerializer::serialize() {

size_t nsets = sets.size();
data.push_back(nsets);
for (auto set : sets) {
for (const auto &set : sets) {
bool containsEof = set.contains(Token::EOF);
if (containsEof && set.getIntervals().at(0).b == -1) {
data.push_back(set.getIntervals().size() - 1);
Expand Down Expand Up @@ -287,7 +287,7 @@ std::vector<size_t> ATNSerializer::serialize() {
// LEXER ACTIONS
if (atn->grammarType == ATNType::LEXER) {
data.push_back(atn->lexerActions.size());
for (Ref<LexerAction> &action : atn->lexerActions) {
for (const auto &action : atn->lexerActions) {
data.push_back(static_cast<size_t>(action->getActionType()));
switch (action->getActionType()) {
case LexerActionType::CHANNEL:
Expand Down
2 changes: 2 additions & 0 deletions runtime/Cpp/runtime/src/atn/ATNSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#pragma once

#include "antlr4-common.h"

namespace antlr4 {
namespace atn {

Expand Down
4 changes: 2 additions & 2 deletions runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
// than a config that already reached an accept state for the same rule
size_t skipAlt = ATN::INVALID_ALT_NUMBER;

for (auto c : closure_->configs) {
for (const auto &c : closure_->configs) {
bool currentAltReachedAcceptState = c->alt == skipAlt;
if (currentAltReachedAcceptState && (std::static_pointer_cast<LexerATNConfig>(c))->hasPassedThroughNonGreedyDecision()) {
continue;
Expand Down Expand Up @@ -543,7 +543,7 @@ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {

dfa::DFAState *proposed = new dfa::DFAState(std::unique_ptr<ATNConfigSet>(configs)); /* mem-check: managed by the DFA or deleted below */
Ref<ATNConfig> firstConfigWithRuleStopState = nullptr;
for (auto &c : configs->configs) {
for (const auto &c : configs->configs) {
if (is<RuleStopState *>(c->state)) {
firstConfigWithRuleStopState = c;
break;
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool LexerActionExecutor::operator != (const LexerActionExecutor &obj) const {

size_t LexerActionExecutor::generateHashCode() const {
size_t hash = MurmurHash::initialize();
for (auto lexerAction : _lexerActions) {
for (const auto &lexerAction : _lexerActions) {
hash = MurmurHash::update(hash, lexerAction);
}
hash = MurmurHash::finish(hash, _lexerActions.size());
Expand Down
22 changes: 11 additions & 11 deletions runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
std::vector<Ref<ATNConfig>> skippedStopStates;

// First figure out where we can reach on input t
for (auto &c : closure_->configs) {
for (const auto &c : closure_->configs) {
if (is<RuleStopState *>(c->state)) {
assert(c->context->isEmpty());

Expand Down Expand Up @@ -507,7 +507,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
ATNConfig::Set closureBusy;

bool treatEofAsEpsilon = t == Token::EOF;
for (auto c : intermediate->configs) {
for (const auto &c : intermediate->configs) {
closure(c, reach.get(), closureBusy, false, fullCtx, treatEofAsEpsilon);
}
}
Expand Down Expand Up @@ -546,7 +546,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
if (skippedStopStates.size() > 0 && (!fullCtx || !PredictionModeClass::hasConfigInRuleStopState(reach.get()))) {
assert(!skippedStopStates.empty());

for (auto c : skippedStopStates) {
for (const auto &c : skippedStopStates) {
reach->add(c, &mergeCache);
}
}
Expand All @@ -565,7 +565,7 @@ ATNConfigSet* ParserATNSimulator::removeAllConfigsNotInRuleStopState(ATNConfigSe

ATNConfigSet *result = new ATNConfigSet(configs->fullCtx); /* mem-check: released by caller */

for (auto &config : configs->configs) {
for (const auto &config : configs->configs) {
if (is<RuleStopState*>(config->state)) {
result->add(config, &mergeCache);
continue;
Expand Down Expand Up @@ -601,7 +601,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeStartState(ATNState *p,
std::unique_ptr<ATNConfigSet> ParserATNSimulator::applyPrecedenceFilter(ATNConfigSet *configs) {
std::map<size_t, Ref<PredictionContext>> statesFromAlt1;
std::unique_ptr<ATNConfigSet> configSet(new ATNConfigSet(configs->fullCtx));
for (Ref<ATNConfig> &config : configs->configs) {
for (const auto &config : configs->configs) {
// handle alt 1 first
if (config->alt != 1) {
continue;
Expand All @@ -622,7 +622,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::applyPrecedenceFilter(ATNConfi
}
}

for (Ref<ATNConfig> &config : configs->configs) {
for (const auto &config : configs->configs) {
if (config->alt == 1) {
// already handled
continue;
Expand Down Expand Up @@ -671,7 +671,7 @@ std::vector<Ref<SemanticContext>> ParserATNSimulator::getPredsForAmbigAlts(const
*/
std::vector<Ref<SemanticContext>> altToPred(nalts + 1);

for (auto &c : configs->configs) {
for (const auto &c : configs->configs) {
if (ambigAlts.test(c->alt)) {
altToPred[c->alt] = SemanticContext::Or(altToPred[c->alt], c->semanticContext);
}
Expand Down Expand Up @@ -739,7 +739,7 @@ size_t ParserATNSimulator::getSynValidOrSemInvalidAltThatFinishedDecisionEntryRu

size_t ParserATNSimulator::getAltThatFinishedDecisionEntryRule(ATNConfigSet *configs) {
misc::IntervalSet alts;
for (auto &c : configs->configs) {
for (const auto &c : configs->configs) {
if (c->getOuterContextDepth() > 0 || (is<RuleStopState *>(c->state) && c->context->hasEmptyPath())) {
alts.add(c->alt);
}
Expand All @@ -756,7 +756,7 @@ std::pair<ATNConfigSet *, ATNConfigSet *> ParserATNSimulator::splitAccordingToSe
// mem-check: both pointers must be freed by the caller.
ATNConfigSet *succeeded(new ATNConfigSet(configs->fullCtx));
ATNConfigSet *failed(new ATNConfigSet(configs->fullCtx));
for (Ref<ATNConfig> &c : configs->configs) {
for (const auto &c : configs->configs) {
if (c->semanticContext != SemanticContext::NONE) {
bool predicateEvaluationResult = evalSemanticContext(c->semanticContext, outerContext, c->alt, configs->fullCtx);
if (predicateEvaluationResult) {
Expand Down Expand Up @@ -1204,7 +1204,7 @@ std::string ParserATNSimulator::getLookaheadName(TokenStream *input) {

void ParserATNSimulator::dumpDeadEndConfigs(NoViableAltException &nvae) {
std::cerr << "dead end configs: ";
for (auto c : nvae.getDeadEndConfigs()->configs) {
for (const auto &c : nvae.getDeadEndConfigs()->configs) {
std::string trans = "no edges";
if (c->state->transitions.size() > 0) {
Transition *t = c->state->transitions[0];
Expand All @@ -1230,7 +1230,7 @@ NoViableAltException ParserATNSimulator::noViableAlt(TokenStream *input, ParserR

size_t ParserATNSimulator::getUniqueAlt(ATNConfigSet *configs) {
size_t alt = ATN::INVALID_ALT_NUMBER;
for (auto &c : configs->configs) {
for (const auto &c : configs->configs) {
if (alt == ATN::INVALID_ALT_NUMBER) {
alt = c->alt; // found first alt
} else if (c->alt != alt) {
Expand Down
14 changes: 7 additions & 7 deletions runtime/Cpp/runtime/src/atn/PredictionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ size_t PredictionContext::calculateHashCode(const std::vector<Ref<PredictionCont
const std::vector<size_t> &returnStates) {
size_t hash = MurmurHash::initialize(INITIAL_HASH);

for (auto parent : parents) {
for (const auto &parent : parents) {
hash = MurmurHash::update(hash, parent);
}

for (auto returnState : returnStates) {
for (const auto &returnState : returnStates) {
hash = MurmurHash::update(hash, returnState);
}

Expand Down Expand Up @@ -391,7 +391,7 @@ std::string PredictionContext::toDOTString(const Ref<PredictionContext> &context
return o1->id - o2->id;
});

for (auto current : nodes) {
for (const auto &current : nodes) {
if (is<SingletonPredictionContext>(current)) {
std::string s = std::to_string(current->id);
ss << " s" << s;
Expand Down Expand Up @@ -420,7 +420,7 @@ std::string PredictionContext::toDOTString(const Ref<PredictionContext> &context
ss << "\"];\n";
}

for (auto current : nodes) {
for (const auto &current : nodes) {
if (current == EMPTY) {
continue;
}
Expand Down Expand Up @@ -646,16 +646,16 @@ void PredictionContextMergeCache::clear() {

std::string PredictionContextMergeCache::toString() const {
std::string result;
for (auto pair : _data)
for (auto pair2 : pair.second)
for (const auto &pair : _data)
for (const auto &pair2 : pair.second)
result += pair2.second->toString() + "\n";

return result;
}

size_t PredictionContextMergeCache::count() const {
size_t result = 0;
for (auto entry : _data)
for (const auto &entry : _data)
result += entry.second.size();
return result;
}
Expand Down
22 changes: 11 additions & 11 deletions runtime/Cpp/runtime/src/atn/SemanticContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ SemanticContext::AND::AND(Ref<SemanticContext> const& a, Ref<SemanticContext> co
Set operands;

if (is<AND>(a)) {
for (auto operand : std::dynamic_pointer_cast<AND>(a)->opnds) {
for (const auto &operand : std::dynamic_pointer_cast<AND>(a)->opnds) {
operands.insert(operand);
}
} else {
operands.insert(a);
}

if (is<AND>(b)) {
for (auto operand : std::dynamic_pointer_cast<AND>(b)->opnds) {
for (const auto &operand : std::dynamic_pointer_cast<AND>(b)->opnds) {
operands.insert(operand);
}
} else {
Expand Down Expand Up @@ -157,7 +157,7 @@ size_t SemanticContext::AND::hashCode() const {
}

bool SemanticContext::AND::eval(Recognizer *parser, RuleContext *parserCallStack) {
for (auto opnd : opnds) {
for (const auto &opnd : opnds) {
if (!opnd->eval(parser, parserCallStack)) {
return false;
}
Expand All @@ -168,7 +168,7 @@ bool SemanticContext::AND::eval(Recognizer *parser, RuleContext *parserCallStack
Ref<SemanticContext> SemanticContext::AND::evalPrecedence(Recognizer *parser, RuleContext *parserCallStack) {
bool differs = false;
std::vector<Ref<SemanticContext>> operands;
for (auto context : opnds) {
for (const auto &context : opnds) {
Ref<SemanticContext> evaluated = context->evalPrecedence(parser, parserCallStack);
differs |= (evaluated != context);
if (evaluated == nullptr) {
Expand Down Expand Up @@ -199,7 +199,7 @@ Ref<SemanticContext> SemanticContext::AND::evalPrecedence(Recognizer *parser, Ru

std::string SemanticContext::AND::toString() const {
std::string tmp;
for (auto var : opnds) {
for (const auto &var : opnds) {
tmp += var->toString() + " && ";
}
return tmp;
Expand All @@ -211,15 +211,15 @@ SemanticContext::OR::OR(Ref<SemanticContext> const& a, Ref<SemanticContext> cons
Set operands;

if (is<OR>(a)) {
for (auto operand : std::dynamic_pointer_cast<OR>(a)->opnds) {
for (const auto &operand : std::dynamic_pointer_cast<OR>(a)->opnds) {
operands.insert(operand);
}
} else {
operands.insert(a);
}

if (is<OR>(b)) {
for (auto operand : std::dynamic_pointer_cast<OR>(b)->opnds) {
for (const auto &operand : std::dynamic_pointer_cast<OR>(b)->opnds) {
operands.insert(operand);
}
} else {
Expand Down Expand Up @@ -259,7 +259,7 @@ size_t SemanticContext::OR::hashCode() const {
}

bool SemanticContext::OR::eval(Recognizer *parser, RuleContext *parserCallStack) {
for (auto opnd : opnds) {
for (const auto &opnd : opnds) {
if (opnd->eval(parser, parserCallStack)) {
return true;
}
Expand All @@ -270,7 +270,7 @@ bool SemanticContext::OR::eval(Recognizer *parser, RuleContext *parserCallStack)
Ref<SemanticContext> SemanticContext::OR::evalPrecedence(Recognizer *parser, RuleContext *parserCallStack) {
bool differs = false;
std::vector<Ref<SemanticContext>> operands;
for (auto context : opnds) {
for (const auto &context : opnds) {
Ref<SemanticContext> evaluated = context->evalPrecedence(parser, parserCallStack);
differs |= (evaluated != context);
if (evaluated == NONE) {
Expand Down Expand Up @@ -301,7 +301,7 @@ Ref<SemanticContext> SemanticContext::OR::evalPrecedence(Recognizer *parser, Rul

std::string SemanticContext::OR::toString() const {
std::string tmp;
for(auto var : opnds) {
for(const auto &var : opnds) {
tmp += var->toString() + " || ";
}
return tmp;
Expand Down Expand Up @@ -361,7 +361,7 @@ Ref<SemanticContext> SemanticContext::Or(Ref<SemanticContext> const& a, Ref<Sema

std::vector<Ref<SemanticContext::PrecedencePredicate>> SemanticContext::filterPrecedencePredicates(const Set &collection) {
std::vector<Ref<SemanticContext::PrecedencePredicate>> result;
for (auto context : collection) {
for (const auto &context : collection) {
if (antlrcpp::is<PrecedencePredicate>(context)) {
result.push_back(std::dynamic_pointer_cast<PrecedencePredicate>(context));
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/Cpp/runtime/src/misc/InterpreterDataReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#pragma once

#include "antlr4-common.h"
#include "atn/ATN.h"
#include "Vocabulary.h"

namespace antlr4 {
namespace misc {
Expand Down
Loading