@Override public boolean equals(ATNConfig a, ATNConfig b) { if ( a==b ) return true; if ( a==null || b==null ) return false; return a.getState().stateNumber==b.getState().stateNumber && a.getContext().equals(b.getContext()); } }
public void optimizeConfigs(ATNSimulator interpreter) { if (configs.isEmpty()) { return; } for (int i = 0; i < configs.size(); i++) { ATNConfig config = configs.get(i); config.setContext(interpreter.atn.getCachedContext(config.getContext())); } }
workList.add(getContext()); visited.put(getContext(), getContext()); while (!workList.isEmpty()) { PredictionContext current = workList.pop();
@NotNull protected ATNConfig ruleTransition(@NotNull ATNConfig config, @NotNull RuleTransition t, @Nullable PredictionContextCache contextCache) { if ( debug ) { System.out.println("CALL rule "+getRuleName(t.target.ruleIndex)+ ", ctx="+config.getContext()); } ATNState returnState = t.followState; PredictionContext newContext; if (optimize_tail_calls && t.optimizedTailCall && (!tail_call_preserves_sll || !PredictionContext.isEmptyLocal(config.getContext()))) { newContext = config.getContext(); } else if (contextCache != null) { newContext = contextCache.getChild(config.getContext(), returnState.stateNumber); } else { newContext = config.getContext().getChild(returnState.stateNumber); } return config.transform(t.target, newContext, false); }
public ATNConfig appendContext(int context, PredictionContextCache contextCache) { PredictionContext appendedContext = getContext().appendContext(context, contextCache); ATNConfig result = transform(getState(), appendedContext, false); return result; }
public ATNConfig appendContext(PredictionContext context, PredictionContextCache contextCache) { PredictionContext appendedContext = getContext().appendContext(context, contextCache); ATNConfig result = transform(getState(), appendedContext, false); return result; }
contexts = getContext().toStrings(recog, this.getState().stateNumber); buf.append(getAlt()); if ( getContext()!=null ) { buf.append(","); buf.append(contextDesc);
/** * The hash code is only a function of the {@link ATNState#stateNumber} * and {@link ATNConfig#context}. */ @Override public int hashCode(ATNConfig o) { int hashCode = MurmurHash.initialize(7); hashCode = MurmurHash.update(hashCode, o.getState().stateNumber); hashCode = MurmurHash.update(hashCode, o.getContext()); hashCode = MurmurHash.finish(hashCode, 2); return hashCode; }
PredictionContext joined = PredictionContext.join(mergedConfig.getContext(), e.getContext(), contextCache); updatePropertiesForMergedConfig(e); if (mergedConfig.getContext() == joined) { return false; PredictionContext joined = PredictionContext.join(unmergedConfig.getContext(), e.getContext(), contextCache); updatePropertiesForMergedConfig(e); if (unmergedConfig.getContext() == joined) { return false;
leftWorkList.add(getContext()); rightWorkList.add(subconfig.getContext()); while (!leftWorkList.isEmpty()) { PredictionContext left = leftWorkList.pop();
int firstIndexCurrentState = 0; int lastIndexCurrentStateMinAlt = 0; PredictionContext joinedCheckContext = configs.get(0).getContext(); for (int i = 1; i < configs.size(); i++) { ATNConfig config = configs.get(i); joinedCheckContext = contextCache.join(joinedCheckContext, configs.get(i).getContext()); firstIndexCurrentState = i; lastIndexCurrentStateMinAlt = i; joinedCheckContext = config.getContext(); for (int j = firstIndexCurrentState + 1; j < configs.size(); j++) { ATNConfig config2 = configs.get(j); joinedCheckContext = contextCache.join(joinedCheckContext, config2.getContext()); PredictionContext joinedCheckContext2 = config.getContext(); int currentAlt = config.getAlt(); int lastIndexCurrentStateCurrentAlt = i; joinedCheckContext2 = contextCache.join(joinedCheckContext2, config2.getContext());
public boolean equals(ATNConfig other) { if (this == other) { return true; } else if (other == null) { return false; } return this.getState().stateNumber==other.getState().stateNumber && this.getAlt()==other.getAlt() && this.getReachesIntoOuterContext() == other.getReachesIntoOuterContext() && this.getContext().equals(other.getContext()) && this.getSemanticContext().equals(other.getSemanticContext()) && this.isPrecedenceFilterSuppressed() == other.isPrecedenceFilterSuppressed() && this.hasPassedThroughNonGreedyDecision() == other.hasPassedThroughNonGreedyDecision() && ObjectEqualityComparator.INSTANCE.equals(this.getLexerActionExecutor(), other.getLexerActionExecutor()); }
statesFromAlt1.put(config.getState().stateNumber, config.getContext()); if (updatedContext != config.getSemanticContext()) { configSet.add(config.transform(config.getState(), updatedContext, false), contextCache); if (context != null && context.equals(config.getContext())) {
case Transition.RULE: RuleTransition ruleTransition = (RuleTransition)t; if (optimize_tail_calls && ruleTransition.optimizedTailCall && !config.getContext().hasEmpty()) { c = config.transform(t.target, true); PredictionContext newContext = config.getContext().getChild(ruleTransition.followState.stateNumber); c = config.transform(t.target, newContext, true); if (config.getContext().hasEmpty()) {
if ( !config.getContext().isEmpty() ) { boolean hasEmpty = config.getContext().hasEmpty(); int nonEmptySize = config.getContext().size() - (hasEmpty ? 1 : 0); for (int i = 0; i < nonEmptySize; i++) { PredictionContext newContext = config.getContext().getParent(i); // "pop" return state ATNState returnState = atn.states.get(config.getContext().getReturnState(i)); ATNConfig c = ATNConfig.create(returnState, config.getAlt(), newContext, config.getSemanticContext()); getRuleName(config.getState().ruleIndex)); if (config.getContext() == PredictionContext.EMPTY_FULL) { else if (!config.getReachesIntoOuterContext() && PredictionContext.isEmptyLocal(config.getContext())) { && p.getStateType() == ATNState.STAR_LOOP_ENTRY && ((StarLoopEntryState)p).precedenceRuleDecision && !config.getContext().hasEmpty()) { for (int j = 0; j < config.getContext().size(); j++) { if (!precedenceDecision.precedenceLoopbackStates.get(config.getContext().getReturnState(j))) { suppress = false; break; if (optimize_tail_calls && ((RuleTransition)t).optimizedTailCall && (!tail_call_preserves_sll || !PredictionContext.isEmptyLocal(config.getContext()))) { assert c.getContext() == config.getContext(); if (newDepth == 0) { if (!tail_call_preserves_sll && PredictionContext.isEmptyLocal(config.getContext())) {
@Override public int hashCode() { int hashCode = MurmurHash.initialize(7); hashCode = MurmurHash.update(hashCode, getState().stateNumber); hashCode = MurmurHash.update(hashCode, getAlt()); hashCode = MurmurHash.update(hashCode, getReachesIntoOuterContext() ? 1 : 0); hashCode = MurmurHash.update(hashCode, getContext()); hashCode = MurmurHash.update(hashCode, getSemanticContext()); hashCode = MurmurHash.update(hashCode, hasPassedThroughNonGreedyDecision() ? 1 : 0); hashCode = MurmurHash.update(hashCode, getLexerActionExecutor()); hashCode = MurmurHash.finish(hashCode, 7); return hashCode; }
assert c.getContext().isEmpty(); if (useContext && !c.getReachesIntoOuterContext() || t == IntStream.EOF) { if (skippedStopStates == null) {
PredictionContext context = config.getContext(); if ( context.isEmpty() ) { configs.add(config);