forked from jasder/antlr
alts outer-context flag/counter in ATNConfig is now unsiged.
A few more removals of no longer necessary casts.
This commit is contained in:
parent
0e0ecfafde
commit
c968b5209e
|
@ -352,12 +352,12 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
|
|||
if (iop->index == rop->index) {
|
||||
// E.g., insert before 2, delete 2..2; update replace
|
||||
// text to include insert before, kill insert
|
||||
rewrites[(size_t)iop->instructionIndex] = nullptr;
|
||||
rewrites[iop->instructionIndex] = nullptr;
|
||||
rop->text = iop->text + (!rop->text.empty() ? rop->text : "");
|
||||
}
|
||||
else if (iop->index > rop->index && iop->index <= rop->lastIndex) {
|
||||
// delete insert as it's a no-op.
|
||||
rewrites[(size_t)iop->instructionIndex] = nullptr;
|
||||
rewrites[iop->instructionIndex] = nullptr;
|
||||
}
|
||||
}
|
||||
// Drop any prior replaces contained within
|
||||
|
@ -366,7 +366,7 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
|
|||
for (auto prevRop : prevReplaces) {
|
||||
if (prevRop->index >= rop->index && prevRop->lastIndex <= rop->lastIndex) {
|
||||
// delete replace as it's a no-op.
|
||||
rewrites[(size_t)prevRop->instructionIndex] = nullptr;
|
||||
rewrites[prevRop->instructionIndex] = nullptr;
|
||||
continue;
|
||||
}
|
||||
// throw exception unless disjoint or identical
|
||||
|
@ -376,7 +376,7 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
|
|||
// D.i-j.u D.x-y.v | boundaries overlap combine to max(min)..max(right)
|
||||
if (prevRop->text.empty() && rop->text.empty() && !disjoint) {
|
||||
//System.out.println("overlapping deletes: "+prevRop+", "+rop);
|
||||
rewrites[(size_t)prevRop->instructionIndex] = nullptr; // kill first delete
|
||||
rewrites[prevRop->instructionIndex] = nullptr; // kill first delete
|
||||
rop->index = std::min(prevRop->index, rop->index);
|
||||
rop->lastIndex = std::max(prevRop->lastIndex, rop->lastIndex);
|
||||
std::cout << "new rop " << rop << std::endl;
|
||||
|
|
|
@ -78,7 +78,7 @@ void UnbufferedCharStream::sync(size_t want) {
|
|||
|
||||
size_t UnbufferedCharStream::fill(size_t n) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (_data.size() > 0 && _data.back() == EOF) {
|
||||
if (_data.size() > 0 && (size_t)_data.back() == EOF) {
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,11 +39,11 @@ using namespace antlr4::atn;
|
|||
|
||||
const size_t ATNConfig::SUPPRESS_PRECEDENCE_FILTER = 0x40000000;
|
||||
|
||||
ATNConfig::ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context)
|
||||
ATNConfig::ATNConfig(ATNState *state, size_t alt, Ref<PredictionContext> const& context)
|
||||
: ATNConfig(state, alt, context, SemanticContext::NONE) {
|
||||
}
|
||||
|
||||
ATNConfig::ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext)
|
||||
ATNConfig::ATNConfig(ATNState *state, size_t alt, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext)
|
||||
: state(state), alt(alt), context(context), semanticContext(semanticContext) {
|
||||
reachesIntoOuterContext = 0;
|
||||
}
|
||||
|
@ -78,14 +78,14 @@ ATNConfig::~ATNConfig() {
|
|||
size_t ATNConfig::hashCode() const {
|
||||
size_t hashCode = misc::MurmurHash::initialize(7);
|
||||
hashCode = misc::MurmurHash::update(hashCode, state->stateNumber);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)alt);
|
||||
hashCode = misc::MurmurHash::update(hashCode, alt);
|
||||
hashCode = misc::MurmurHash::update(hashCode, context);
|
||||
hashCode = misc::MurmurHash::update(hashCode, semanticContext);
|
||||
hashCode = misc::MurmurHash::finish(hashCode, 4);
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
int ATNConfig::getOuterContextDepth() const {
|
||||
size_t ATNConfig::getOuterContextDepth() const {
|
||||
return reachesIntoOuterContext & ~SUPPRESS_PRECEDENCE_FILTER;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,9 +63,8 @@ namespace atn {
|
|||
/// The ATN state associated with this configuration.
|
||||
ATNState * state;
|
||||
|
||||
/// <summary>
|
||||
/// What alt (or lexer rule) is predicted by this configuration </summary>
|
||||
const int alt;
|
||||
/// What alt (or lexer rule) is predicted by this configuration.
|
||||
const size_t alt;
|
||||
|
||||
/// The stack of invoking states leading to the rule/states associated
|
||||
/// with this config. We track only those contexts pushed during
|
||||
|
@ -97,13 +96,13 @@ namespace atn {
|
|||
* {@link ATNConfigSet#add(ATNConfig, DoubleKeyMap)} method are
|
||||
* <em>completely</em> unaffected by the change.</p>
|
||||
*/
|
||||
int reachesIntoOuterContext;
|
||||
size_t reachesIntoOuterContext;
|
||||
|
||||
/// Can be shared between multiple ATNConfig instances.
|
||||
Ref<SemanticContext> semanticContext;
|
||||
|
||||
ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context);
|
||||
ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext);
|
||||
ATNConfig(ATNState *state, size_t alt, Ref<PredictionContext> const& context);
|
||||
ATNConfig(ATNState *state, size_t alt, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext);
|
||||
|
||||
ATNConfig(Ref<ATNConfig> const& c); // dup
|
||||
ATNConfig(Ref<ATNConfig> const& c, ATNState *state);
|
||||
|
@ -121,7 +120,7 @@ namespace atn {
|
|||
* as it existed prior to the introduction of the
|
||||
* {@link #isPrecedenceFilterSuppressed} method.
|
||||
*/
|
||||
int getOuterContextDepth() const ;
|
||||
size_t getOuterContextDepth() const ;
|
||||
bool isPrecedenceFilterSuppressed() const;
|
||||
void setPrecedenceFilterSuppressed(bool value);
|
||||
|
||||
|
|
|
@ -239,7 +239,7 @@ std::string ATNConfigSet::toString() {
|
|||
size_t ATNConfigSet::getHash(ATNConfig *c) {
|
||||
size_t hashCode = 7;
|
||||
hashCode = 31 * hashCode + c->state->stateNumber;
|
||||
hashCode = 31 * hashCode + (size_t)c->alt;
|
||||
hashCode = 31 * hashCode + c->alt;
|
||||
hashCode = 31 * hashCode + c->semanticContext->hashCode();
|
||||
return hashCode;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace atn {
|
|||
|
||||
// TO_DO: these fields make me pretty uncomfortable but nice to pack up info together, saves recomputation
|
||||
// TO_DO: can we track conflicts as they are added to save scanning configs later?
|
||||
int uniqueAlt;
|
||||
size_t uniqueAlt;
|
||||
|
||||
/** Currently this is only used when we detect SLL conflict; this does
|
||||
* not necessarily represent the ambiguous alternatives. In fact,
|
||||
|
|
|
@ -192,7 +192,7 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
|
|||
|
||||
// delay the assignment of loop back and end states until we know all the state instances have been initialized
|
||||
for (auto &pair : loopBackStateNumbers) {
|
||||
pair.first->loopBackState = atn.states[(size_t)pair.second];
|
||||
pair.first->loopBackState = atn.states[pair.second];
|
||||
}
|
||||
|
||||
for (auto &pair : endStateNumbers) {
|
||||
|
@ -224,7 +224,7 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < nrules; i++) {
|
||||
size_t s = (size_t)data[p++];
|
||||
size_t s = data[p++];
|
||||
// Also here, the serialized atn must ensure to point to the correct class type.
|
||||
RuleStartState *startState = (RuleStartState*)atn.states[s];
|
||||
atn.ruleToStartState.push_back(startState);
|
||||
|
@ -298,7 +298,7 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
|
|||
size_t arg2 = data[p + 4];
|
||||
size_t arg3 = data[p + 5];
|
||||
Transition *trans = edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets);
|
||||
ATNState *srcState = atn.states[(size_t)src];
|
||||
ATNState *srcState = atn.states[src];
|
||||
srcState->addTransition(trans);
|
||||
p += 6;
|
||||
}
|
||||
|
@ -363,7 +363,7 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
|
|||
//
|
||||
// DECISIONS
|
||||
//
|
||||
size_t ndecisions = (size_t)data[p++];
|
||||
size_t ndecisions = data[p++];
|
||||
for (size_t i = 1; i <= ndecisions; i++) {
|
||||
size_t s = data[p++];
|
||||
DecisionState *decState = dynamic_cast<DecisionState*>(atn.states[s]);
|
||||
|
|
|
@ -78,7 +78,7 @@ bool LexerATNConfig::hasPassedThroughNonGreedyDecision() {
|
|||
size_t LexerATNConfig::hashCode() const {
|
||||
size_t hashCode = misc::MurmurHash::initialize(7);
|
||||
hashCode = misc::MurmurHash::update(hashCode, state->stateNumber);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)alt);
|
||||
hashCode = misc::MurmurHash::update(hashCode, alt);
|
||||
hashCode = misc::MurmurHash::update(hashCode, context);
|
||||
hashCode = misc::MurmurHash::update(hashCode, semanticContext);
|
||||
hashCode = misc::MurmurHash::update(hashCode, _passedThroughNonGreedyDecision ? 1 : 0);
|
||||
|
|
|
@ -260,7 +260,7 @@ size_t LexerATNSimulator::failOrAccept(CharStream *input, ATNConfigSet *reach, s
|
|||
void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *closure_, ATNConfigSet *reach, size_t t) {
|
||||
// this is used to skip processing for configs which have a lower priority
|
||||
// than a config that already reached an accept state for the same rule
|
||||
int skipAlt = ATN::INVALID_ALT_NUMBER;
|
||||
size_t skipAlt = ATN::INVALID_ALT_NUMBER;
|
||||
|
||||
for (auto c : closure_->configs) {
|
||||
bool currentAltReachedAcceptState = c->alt == skipAlt;
|
||||
|
|
|
@ -289,7 +289,7 @@ dfa::DFAState *ParserATNSimulator::computeTargetState(dfa::DFA &dfa, dfa::DFASta
|
|||
|
||||
// create new target state; we'll add to DFA after it's complete
|
||||
dfa::DFAState *D = new dfa::DFAState(std::move(reach)); /* mem-check: managed by the DFA or deleted below, "reach" is no longer valid now. */
|
||||
int predictedAlt = getUniqueAlt(D->configs.get());
|
||||
size_t predictedAlt = getUniqueAlt(D->configs.get());
|
||||
|
||||
if (predictedAlt != ATN::INVALID_ALT_NUMBER) {
|
||||
// NO CONFLICT, UNIQUELY PREDICTED ALT
|
||||
|
@ -685,8 +685,8 @@ std::vector<Ref<SemanticContext>> ParserATNSimulator::getPredsForAmbigAlts(const
|
|||
std::vector<Ref<SemanticContext>> altToPred(nalts + 1);
|
||||
|
||||
for (auto &c : configs->configs) {
|
||||
if (ambigAlts.test((size_t)c->alt)) {
|
||||
altToPred[(size_t)c->alt] = SemanticContext::Or(altToPred[(size_t)c->alt], c->semanticContext);
|
||||
if (ambigAlts.test(c->alt)) {
|
||||
altToPred[c->alt] = SemanticContext::Or(altToPred[c->alt], c->semanticContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -794,7 +794,7 @@ BitSet ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPr
|
|||
BitSet predictions;
|
||||
for (auto prediction : predPredictions) {
|
||||
if (prediction->pred == SemanticContext::NONE) {
|
||||
predictions.set((size_t)prediction->alt);
|
||||
predictions.set(prediction->alt);
|
||||
if (!complete) {
|
||||
break;
|
||||
}
|
||||
|
@ -812,7 +812,7 @@ BitSet ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPr
|
|||
std::cout << "PREDICT " << prediction->alt << std::endl;
|
||||
#endif
|
||||
|
||||
predictions.set((size_t)prediction->alt);
|
||||
predictions.set(prediction->alt);
|
||||
if (!complete) {
|
||||
break;
|
||||
}
|
||||
|
@ -823,7 +823,7 @@ BitSet ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPr
|
|||
}
|
||||
|
||||
bool ParserATNSimulator::evalSemanticContext(Ref<SemanticContext> const& pred, Ref<ParserRuleContext> const& parserCallStack,
|
||||
int /*alt*/, bool /*fullCtx*/) {
|
||||
size_t /*alt*/, bool /*fullCtx*/) {
|
||||
return pred->eval(parser, parserCallStack);
|
||||
}
|
||||
|
||||
|
@ -1104,7 +1104,7 @@ BitSet ParserATNSimulator::getConflictingAlts(ATNConfigSet *configs) {
|
|||
BitSet ParserATNSimulator::getConflictingAltsOrUniqueAlt(ATNConfigSet *configs) {
|
||||
BitSet conflictingAlts;
|
||||
if (configs->uniqueAlt != ATN::INVALID_ALT_NUMBER) {
|
||||
conflictingAlts.set((size_t)configs->uniqueAlt);
|
||||
conflictingAlts.set(configs->uniqueAlt);
|
||||
} else {
|
||||
conflictingAlts = configs->conflictingAlts;
|
||||
}
|
||||
|
@ -1155,8 +1155,8 @@ NoViableAltException ParserATNSimulator::noViableAlt(TokenStream *input, Ref<Par
|
|||
return NoViableAltException(parser, input, input->get(startIndex), input->LT(1), configs, outerContext);
|
||||
}
|
||||
|
||||
int ParserATNSimulator::getUniqueAlt(ATNConfigSet *configs) {
|
||||
int alt = ATN::INVALID_ALT_NUMBER;
|
||||
size_t ParserATNSimulator::getUniqueAlt(ATNConfigSet *configs) {
|
||||
size_t alt = ATN::INVALID_ALT_NUMBER;
|
||||
for (auto &c : configs->configs) {
|
||||
if (alt == ATN::INVALID_ALT_NUMBER) {
|
||||
alt = c->alt; // found first alt
|
||||
|
|
|
@ -686,7 +686,7 @@ namespace atn {
|
|||
* @since 4.3
|
||||
*/
|
||||
virtual bool evalSemanticContext(Ref<SemanticContext> const& pred, Ref<ParserRuleContext> const& parserCallStack,
|
||||
int alt, bool fullCtx);
|
||||
size_t alt, bool fullCtx);
|
||||
|
||||
/* TO_DO: If we are doing predicates, there is no point in pursuing
|
||||
closure operations if we reach a DFA state that uniquely predicts
|
||||
|
@ -788,7 +788,7 @@ namespace atn {
|
|||
virtual NoViableAltException noViableAlt(TokenStream *input, Ref<ParserRuleContext> const& outerContext,
|
||||
ATNConfigSet *configs, size_t startIndex);
|
||||
|
||||
static int getUniqueAlt(ATNConfigSet *configs);
|
||||
static size_t getUniqueAlt(ATNConfigSet *configs);
|
||||
|
||||
/// <summary>
|
||||
/// Add an edge to the DFA, if possible. This method calls
|
||||
|
|
|
@ -37,7 +37,7 @@ using namespace antlr4;
|
|||
using namespace antlr4::atn;
|
||||
|
||||
PredicateEvalInfo::PredicateEvalInfo(size_t decision, TokenStream *input, size_t startIndex, size_t stopIndex,
|
||||
Ref<SemanticContext> const& semctx, bool evalResult, int predictedAlt, bool fullCtx)
|
||||
Ref<SemanticContext> const& semctx, bool evalResult, size_t predictedAlt, bool fullCtx)
|
||||
: DecisionEventInfo(decision, nullptr, input, startIndex, stopIndex, fullCtx),
|
||||
semctx(semctx), predictedAlt(predictedAlt), evalResult(evalResult) {
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace atn {
|
|||
/// configurations may predict the same alternative which are guarded by
|
||||
/// other semantic contexts and/or <seealso cref="SemanticContext#NONE"/>.
|
||||
/// </summary>
|
||||
const int predictedAlt;
|
||||
const size_t predictedAlt;
|
||||
|
||||
/// The result of evaluating the semantic context <seealso cref="#semctx"/>.
|
||||
const bool evalResult;
|
||||
|
@ -81,7 +81,7 @@ namespace atn {
|
|||
/// <seealso cref= ParserATNSimulator#evalSemanticContext(SemanticContext, ParserRuleContext, int, boolean) </seealso>
|
||||
/// <seealso cref= SemanticContext#eval(Recognizer, RuleContext) </seealso>
|
||||
PredicateEvalInfo(size_t decision, TokenStream *input, size_t startIndex, size_t stopIndex,
|
||||
Ref<SemanticContext> const& semctx, bool evalResult, int predictedAlt, bool fullCtx);
|
||||
Ref<SemanticContext> const& semctx, bool evalResult, size_t predictedAlt, bool fullCtx);
|
||||
};
|
||||
|
||||
} // namespace atn
|
||||
|
|
|
@ -198,7 +198,7 @@ std::vector<antlrcpp::BitSet> PredictionModeClass::getConflictingAltSubsets(ATNC
|
|||
std::map<ATNState*, antlrcpp::BitSet> PredictionModeClass::getStateToAltMap(ATNConfigSet *configs) {
|
||||
std::map<ATNState*, antlrcpp::BitSet> m;
|
||||
for (auto &c : configs->configs) {
|
||||
m[c->state].set((size_t)c->alt);
|
||||
m[c->state].set(c->alt);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ std::unique_ptr<ATNConfigSet> ProfilingATNSimulator::computeReachSet(ATNConfigSe
|
|||
}
|
||||
|
||||
bool ProfilingATNSimulator::evalSemanticContext(Ref<SemanticContext> const& pred, Ref<ParserRuleContext> const& parserCallStack,
|
||||
int alt, bool fullCtx) {
|
||||
size_t alt, bool fullCtx) {
|
||||
bool result = ParserATNSimulator::evalSemanticContext(pred, parserCallStack, alt, fullCtx);
|
||||
if (!(std::dynamic_pointer_cast<SemanticContext::PrecedencePredicate>(pred) != nullptr)) {
|
||||
bool fullContext = _llStopIndex >= 0;
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace atn {
|
|||
virtual dfa::DFAState* computeTargetState(dfa::DFA &dfa, dfa::DFAState *previousD, size_t t) override;
|
||||
virtual std::unique_ptr<ATNConfigSet> computeReachSet(ATNConfigSet *closure, size_t t, bool fullCtx) override;
|
||||
virtual bool evalSemanticContext(Ref<SemanticContext> const& pred, Ref<ParserRuleContext> const& parserCallStack,
|
||||
int alt, bool fullCtx) override;
|
||||
size_t alt, bool fullCtx) override;
|
||||
virtual void reportAttemptingFullContext(dfa::DFA &dfa, const antlrcpp::BitSet &conflictingAlts, ATNConfigSet *configs,
|
||||
size_t startIndex, size_t stopIndex) override;
|
||||
virtual void reportContextSensitivity(dfa::DFA &dfa, size_t prediction, ATNConfigSet *configs,
|
||||
|
|
|
@ -70,8 +70,8 @@ DFAState::~DFAState() {
|
|||
}
|
||||
}
|
||||
|
||||
std::set<int> DFAState::getAltSet() {
|
||||
std::set<int> alts;
|
||||
std::set<size_t> DFAState::getAltSet() {
|
||||
std::set<size_t> alts;
|
||||
if (configs != nullptr) {
|
||||
for (size_t i = 0; i < configs->size(); i++) {
|
||||
alts.insert(configs->get(i)->alt);
|
||||
|
|
|
@ -129,7 +129,7 @@ namespace dfa {
|
|||
/// Get the set of all alts mentioned by all ATN configurations in this
|
||||
/// DFA state.
|
||||
/// </summary>
|
||||
virtual std::set<int> getAltSet();
|
||||
virtual std::set<size_t> getAltSet();
|
||||
|
||||
virtual size_t hashCode() const;
|
||||
|
||||
|
|
|
@ -478,7 +478,7 @@ std::string IntervalSet::elementName(const dfa::Vocabulary &vocabulary, ssize_t
|
|||
size_t IntervalSet::size() const {
|
||||
size_t result = 0;
|
||||
for (auto &interval : _intervals) {
|
||||
result += (size_t)(interval.b - interval.a + 1);
|
||||
result += size_t(interval.b - interval.a + 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -556,9 +556,9 @@ void IntervalSet::remove(ssize_t el) {
|
|||
}
|
||||
// if in middle a..x..b, split interval
|
||||
if (el > a && el < b) { // found in this interval
|
||||
size_t oldb = (size_t)interval.b;
|
||||
ssize_t oldb = interval.b;
|
||||
interval.b = el - 1; // [a..x-1]
|
||||
add(el + 1, (int)oldb); // add [x+1..b]
|
||||
add(el + 1, oldb); // add [x+1..b]
|
||||
|
||||
break; // ml: not in the Java code but I believe we also should stop searching here, as we found x.
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue