public class DecisionProbe
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Set<java.lang.Integer> |
altsWithProblem
The overall list of alts within the decision that have at least one
conflicting input sequence.
|
protected java.util.Set<DFAState> |
danglingStates
The set of states w/o emanating edges and w/o resolving sem preds.
|
DFA |
dfa |
boolean |
nonLLStarDecision
If decision with > 1 alt has recursion in > 1 alt, it's (likely) nonregular
lookahead.
|
static java.lang.Integer |
REACHABLE_BUSY |
static java.lang.Integer |
REACHABLE_NO |
static java.lang.Integer |
REACHABLE_YES |
protected java.util.Map<java.lang.Integer,java.lang.Integer> |
stateReachable
Used to find paths through syntactically ambiguous DFA.
|
protected java.util.Set<DFAState> |
statesResolvedWithSemanticPredicatesSet
Was a syntactic ambiguity resolved with predicates? Any DFA
state that predicts more than one alternative, must be resolved
with predicates or it should be reported to the user.
|
protected java.util.Set<java.lang.String> |
statesVisitedAtInputDepth
Used while finding a path through an NFA whose edge labels match
an input sequence.
|
protected java.util.Set<java.lang.Integer> |
statesVisitedDuringSampleSequence |
protected java.util.Set<DFAState> |
statesWithSyntacticallyAmbiguousAltsSet
Track all DFA states with nondeterministic alternatives.
|
protected java.util.Map<DFAState,java.util.Map<java.lang.Integer,SemanticContext>> |
stateToAltSetWithSemanticPredicatesMap
Track the predicates for each alt per DFA state;
more than one DFA state might have syntactically ambig alt prediction.
|
protected java.util.Map<DFAState,java.util.Map<java.lang.Integer,java.util.Set<Token>>> |
stateToIncompletelyCoveredAltsMap
Tracks alts insufficiently covered.
|
protected MultiMap<java.lang.Integer,NFAConfiguration> |
stateToRecursionOverflowConfigurationsMap
Recursion is limited to a particular depth.
|
protected java.util.Map<DFAState,java.util.Set<java.lang.Integer>> |
stateToSyntacticallyAmbiguousTokensRuleAltsMap
Track just like stateToSyntacticallyAmbiguousAltsMap, but only
for nondeterminisms that arise in the Tokens rule such as keyword vs
ID rule.
|
protected boolean |
timedOut
Did ANTLR have to terminate early on the analysis of this decision?
|
static boolean |
verbose |
| Constructor and Description |
|---|
DecisionProbe(DFA dfa) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
analysisOverflowed()
Took too long to analyze a DFA
|
private void |
computeAltToProblemMaps(java.util.Set<java.lang.Integer> dfaStatesUnaliased,
java.util.Map<java.lang.Integer,java.util.List<NFAConfiguration>> configurationsMap,
java.util.Map<java.lang.Integer,java.util.Map<java.lang.String,java.util.Set<NFAState>>> altToTargetToCallSitesMap,
java.util.Map<java.lang.Integer,DFAState> altToDFAState) |
java.util.Set<DFAState> |
getDanglingStates()
return set of states w/o emanating edges and w/o resolving sem preds.
|
java.lang.String |
getDescription()
Return a string like "3:22: ( A {;} | B )" that describes this
decision.
|
protected java.util.Set<DFAState> |
getDFAPathStatesToTarget(DFAState targetState) |
java.util.Set<DFAState> |
getDFAStatesWithSyntacticallyAmbiguousAlts()
Return all DFA states in this DFA that have NFA configurations that
conflict.
|
java.util.Set<java.lang.Integer> |
getDisabledAlternatives(DFAState d)
Which alts were specifically turned off to resolve nondeterminisms?
This is different than the unreachable alts.
|
java.util.Map<java.lang.Integer,java.util.Set<Token>> |
getIncompletelyCoveredAlts(DFAState d)
Return a list of alts whose predicate context was insufficient to
resolve a nondeterminism for state d.
|
java.lang.String |
getInputSequenceDisplay(java.util.List<? extends Label> labels)
Given List<Label>, return a String with a useful representation
of the associated input string.
|
protected boolean |
getNFAPath(NFAState s,
int labelIndex,
java.util.List<? extends Label> labels,
java.util.List<? super NFAState> path)
Given a sample input sequence, you usually would like to know the
path taken through the NFA.
|
java.util.List<? extends NFAState> |
getNFAPathStatesForAlt(int firstAlt,
int alt,
java.util.List<? extends Label> labels)
Given an alternative associated with a nondeterministic DFA state,
find the path of NFA states associated with the labels sequence.
|
java.util.Set<java.lang.Integer> |
getNonDeterministicAlts() |
java.util.List<java.lang.Integer> |
getNonDeterministicAltsForState(DFAState targetState)
Return the sorted list of alts that conflict within a single state.
|
java.util.Set<DFAState> |
getNondeterministicStatesResolvedWithSemanticPredicate() |
int |
getNumberOfStates()
How many states does the DFA predictor have?
|
protected void |
getSampleInputSequenceUsingStateSet(State startState,
State targetState,
java.util.Set<DFAState> states,
java.util.List<Label> labels)
Given a start state and a final state, find a list of edge labels
between the two ignoring epsilon.
|
java.util.List<Label> |
getSampleNonDeterministicInputSequence(DFAState targetState)
Return a List<Label> indicating an input sequence that can be matched
from the start state of the DFA to the targetState (which is known
to have a problem).
|
SemanticContext |
getSemanticContextForAlt(DFAState d,
int alt)
Each state in the DFA represents a different input sequence for an
alt of the decision.
|
protected java.lang.String |
getStateLabelIndexKey(int s,
int i) |
java.lang.String |
getTokenNameForTokensRuleAlt(int alt)
From an alt number associated with artificial Tokens rule, return
the name of the token that is associated with that alt.
|
private java.util.Set<java.lang.Integer> |
getUnaliasedDFAStateSet(java.util.Set<java.lang.Integer> dfaStatesWithRecursionProblems) |
java.util.List<java.lang.Integer> |
getUnreachableAlts()
Get a list of all unreachable alternatives for this decision.
|
boolean |
hasPredicate()
At least one alt refs a sem or syn pred
|
boolean |
isCyclic() |
boolean |
isDeterministic()
If no states are dead-ends, no alts are unreachable, there are
no nondeterminisms unresolved by syn preds, all is ok with decision.
|
boolean |
isNonLLStarDecision()
Found recursion in > 1 alt
|
boolean |
isReduced() |
protected void |
issueRecursionWarnings() |
void |
issueWarnings() |
protected boolean |
reachesState(DFAState startState,
DFAState targetState,
java.util.Set<DFAState> states)
Given a start state and a target state, return true if start can reach
target state.
|
void |
removeRecursiveOverflowState(DFAState d)
If a recursion overflow is resolve with predicates, then we need
to shut off the warning that would be generated.
|
void |
reportAltPredicateContext(DFAState d,
java.util.Map<java.lang.Integer,? extends SemanticContext> altPredicateContext)
Report the list of predicates found for each alternative; copy
the list because this set gets altered later by the method
tryToResolveWithSemanticPredicates() while flagging NFA configurations
in d as resolved.
|
void |
reportDanglingState(DFAState d)
Report the fact that DFA state d is not a state resolved with
predicates and yet it has no emanating edges.
|
void |
reportIncompletelyCoveredAlts(DFAState d,
java.util.Map<java.lang.Integer,java.util.Set<Token>> altToLocationsReachableWithoutPredicate) |
void |
reportLexerRuleNondeterminism(DFAState d,
java.util.Set<java.lang.Integer> nondeterministicAlts)
Currently the analysis reports issues between token definitions, but
we don't print out warnings in favor of just picking the first token
definition found in the grammar ala lex/flex.
|
void |
reportNondeterminism(DFAState d,
java.util.Set<java.lang.Integer> nondeterministicAlts) |
void |
reportNondeterminismResolvedWithSemanticPredicate(DFAState d) |
void |
reportNonLLStarDecision(DFA dfa)
Report that at least 2 alts have recursive constructs.
|
void |
reportRecursionOverflow(DFAState d,
NFAConfiguration recursionNFAConfiguration) |
void |
reset() |
protected void |
stripWildCardAlts(java.util.Set<java.lang.Integer> disabledAlts)
Get the last disabled alt number and check in the grammar to see
if that alt is a simple wildcard.
|
public DFA dfa
protected java.util.Set<DFAState> statesWithSyntacticallyAmbiguousAltsSet
protected java.util.Map<DFAState,java.util.Set<java.lang.Integer>> stateToSyntacticallyAmbiguousTokensRuleAltsMap
protected java.util.Set<DFAState> statesResolvedWithSemanticPredicatesSet
protected java.util.Map<DFAState,java.util.Map<java.lang.Integer,SemanticContext>> stateToAltSetWithSemanticPredicatesMap
protected java.util.Map<DFAState,java.util.Map<java.lang.Integer,java.util.Set<Token>>> stateToIncompletelyCoveredAltsMap
protected java.util.Set<DFAState> danglingStates
protected java.util.Set<java.lang.Integer> altsWithProblem
public boolean nonLLStarDecision
protected MultiMap<java.lang.Integer,NFAConfiguration> stateToRecursionOverflowConfigurationsMap
protected boolean timedOut
protected java.util.Map<java.lang.Integer,java.lang.Integer> stateReachable
public static final java.lang.Integer REACHABLE_BUSY
public static final java.lang.Integer REACHABLE_NO
public static final java.lang.Integer REACHABLE_YES
protected java.util.Set<java.lang.String> statesVisitedAtInputDepth
protected java.util.Set<java.lang.Integer> statesVisitedDuringSampleSequence
public static boolean verbose
public DecisionProbe(DFA dfa)
public java.lang.String getDescription()
public boolean isReduced()
public boolean isCyclic()
public boolean isDeterministic()
public boolean analysisOverflowed()
public boolean isNonLLStarDecision()
public int getNumberOfStates()
public java.util.List<java.lang.Integer> getUnreachableAlts()
public java.util.Set<DFAState> getDanglingStates()
public java.util.Set<java.lang.Integer> getNonDeterministicAlts()
public java.util.List<java.lang.Integer> getNonDeterministicAltsForState(DFAState targetState)
public java.util.Set<DFAState> getDFAStatesWithSyntacticallyAmbiguousAlts()
public java.util.Set<java.lang.Integer> getDisabledAlternatives(DFAState d)
public void removeRecursiveOverflowState(DFAState d)
public java.util.List<Label> getSampleNonDeterministicInputSequence(DFAState targetState)
public java.lang.String getInputSequenceDisplay(java.util.List<? extends Label> labels)
public java.util.List<? extends NFAState> getNFAPathStatesForAlt(int firstAlt, int alt, java.util.List<? extends Label> labels)
public SemanticContext getSemanticContextForAlt(DFAState d, int alt)
public boolean hasPredicate()
public java.util.Set<DFAState> getNondeterministicStatesResolvedWithSemanticPredicate()
public java.util.Map<java.lang.Integer,java.util.Set<Token>> getIncompletelyCoveredAlts(DFAState d)
public void issueWarnings()
protected void stripWildCardAlts(java.util.Set<java.lang.Integer> disabledAlts)
protected void issueRecursionWarnings()
private void computeAltToProblemMaps(java.util.Set<java.lang.Integer> dfaStatesUnaliased,
java.util.Map<java.lang.Integer,java.util.List<NFAConfiguration>> configurationsMap,
java.util.Map<java.lang.Integer,java.util.Map<java.lang.String,java.util.Set<NFAState>>> altToTargetToCallSitesMap,
java.util.Map<java.lang.Integer,DFAState> altToDFAState)
private java.util.Set<java.lang.Integer> getUnaliasedDFAStateSet(java.util.Set<java.lang.Integer> dfaStatesWithRecursionProblems)
public void reportDanglingState(DFAState d)
public void reportNonLLStarDecision(DFA dfa)
public void reportRecursionOverflow(DFAState d, NFAConfiguration recursionNFAConfiguration)
public void reportNondeterminism(DFAState d, java.util.Set<java.lang.Integer> nondeterministicAlts)
public void reportLexerRuleNondeterminism(DFAState d, java.util.Set<java.lang.Integer> nondeterministicAlts)
public void reportNondeterminismResolvedWithSemanticPredicate(DFAState d)
public void reportAltPredicateContext(DFAState d, java.util.Map<java.lang.Integer,? extends SemanticContext> altPredicateContext)
public void reportIncompletelyCoveredAlts(DFAState d, java.util.Map<java.lang.Integer,java.util.Set<Token>> altToLocationsReachableWithoutPredicate)
protected boolean reachesState(DFAState startState, DFAState targetState, java.util.Set<DFAState> states)
protected java.util.Set<DFAState> getDFAPathStatesToTarget(DFAState targetState)
protected void getSampleInputSequenceUsingStateSet(State startState, State targetState, java.util.Set<DFAState> states, java.util.List<Label> labels)
protected boolean getNFAPath(NFAState s, int labelIndex, java.util.List<? extends Label> labels, java.util.List<? super NFAState> path)
protected java.lang.String getStateLabelIndexKey(int s,
int i)
public java.lang.String getTokenNameForTokensRuleAlt(int alt)
public void reset()