private void updatePropertiesForAddedConfig(ATNConfig config) { if (configs.size() == 1) { uniqueAlt = config.getAlt(); } else if (uniqueAlt != config.getAlt()) { uniqueAlt = ATN.INVALID_ALT_NUMBER; } hasSemanticContext |= !SemanticContext.NONE.equals(config.getSemanticContext()); dipsIntoOuterContext |= config.getReachesIntoOuterContext(); assert !outermostConfigSet || !dipsIntoOuterContext; }
protected long getKey(ATNConfig e) { long key = e.getState().stateNumber; key = (key << 12) | (e.getAlt() & 0xFFF); return key; }
/** * Get the set of all alternatives represented by configurations in this * set. */ @NotNull public BitSet getRepresentedAlternatives() { if (conflictInfo != null) { return (BitSet)conflictInfo.getConflictedAlts().clone(); } BitSet alts = new BitSet(); for (ATNConfig config : this) { alts.set(config.getAlt()); } return alts; }
@Override public int compare(ATNConfig o1, ATNConfig o2) { if (o1.getAlt() != o2.getAlt()) { return o1.getAlt() - o2.getAlt(); } else if (o1.getState().stateNumber != o2.getState().stateNumber) { return o1.getState().stateNumber - o2.getState().stateNumber; } else { return o1.getSemanticContext().toString().compareTo(o2.getSemanticContext().toString()); } } });
/** * Get union of all alts from configs. * * @since 4.5 */ @NotNull public static BitSet getAlts(@NotNull ATNConfigSet configs) { BitSet alts = new BitSet(); for (ATNConfig config : configs) { alts.set(config.getAlt()); } return alts; }
protected boolean configWithAltAtStopState(@NotNull Collection<ATNConfig> configs, int alt) { for (ATNConfig c : configs) { if ( c.getAlt() == alt ) { if ( c.getState() instanceof RuleStopState ) { return true; } } } return false; }
if ( c.getAlt()!=alt ) continue; configsInAlt.add(c);
/** * Get a map from state to alt subset from a configuration set. For each * configuration {@code c} in {@code configs}: * * <pre> * map[c.{@link ATNConfig#state state}] U= c.{@link ATNConfig#getAlt getAlt()} * </pre> */ @NotNull public static Map<ATNState, BitSet> getStateToAltMap(@NotNull ATNConfigSet configs) { Map<ATNState, BitSet> m = new HashMap<ATNState, BitSet>(); for (ATNConfig c : configs) { BitSet alts = m.get(c.getState()); if ( alts==null ) { alts = new BitSet(); m.put(c.getState(), alts); } alts.set(c.getAlt()); } return m; }
/** * Computes the set of conflicting or ambiguous alternatives from a * configuration set, if that information was not already provided by the * parser. * * @param reportedAlts The set of conflicting or ambiguous alternatives, as * reported by the parser. * @param configs The conflicting or ambiguous configuration set. * @return Returns {@code reportedAlts} if it is not {@code null}, otherwise * returns the set of alternatives represented in {@code configs}. */ @NotNull protected BitSet getConflictingAlts(@Nullable BitSet reportedAlts, @NotNull ATNConfigSet configs) { if (reportedAlts != null) { return reportedAlts; } BitSet result = new BitSet(); for (ATNConfig config : configs) { result.set(config.getAlt()); } return result; } }
if ( showAlt ) { buf.append(","); buf.append(getAlt());
/** * This function gets the conflicting alt subsets from a configuration set. * For each configuration {@code c} in {@code configs}: * * <pre> * map[c] U= c.{@link ATNConfig#getAlt getAlt()} # map hash/equals uses s and x, not * alt and not pred * </pre> */ @NotNull public static Collection<BitSet> getConflictingAltSubsets(@NotNull ATNConfigSet configs) { AltAndContextMap configToAlts = new AltAndContextMap(); for (ATNConfig c : configs) { BitSet alts = configToAlts.get(c); if ( alts==null ) { alts = new BitSet(); configToAlts.put(c, alts); } alts.set(c.getAlt()); } return configToAlts.values(); }
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()); }
@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; }