predicateDFAState method

void predicateDFAState(
  1. DFAState dfaState,
  2. DecisionState? decisionState
)

Implementation

void predicateDFAState(DFAState dfaState, DecisionState? decisionState) {
  // Todo: this if was added due to a possible null pointer error
  if (decisionState == null) return;

  // We need to test all predicates, even in DFA states that
  // uniquely predict alternative.
  final nalts = decisionState.numberOfTransitions;
  // Update DFA so reach becomes accept state with (predicate,alt)
  // pairs if preds found for conflicting alts
  final altsToCollectPredsFrom = getConflictingAltsOrUniqueAlt(
    dfaState.configs,
  );
  final altToPred = getPredsForAmbigAlts(
    altsToCollectPredsFrom,
    dfaState.configs,
    nalts,
  );
  if (altToPred != null) {
    dfaState.predicates =
        getPredicatePredictions(altsToCollectPredsFrom, altToPred);
    dfaState.prediction = ATN.INVALID_ALT_NUMBER; // make sure we use preds
  } else {
    // There are preds in configs but they might go away
    // when OR'd together like {p}? || NONE == NONE. If neither
    // alt has preds, resolve to min alt
    dfaState.prediction = altsToCollectPredsFrom.nextset(0);
  }
}