public class DecisionProbe extends Object
Modifier and Type | Field and Description |
---|---|
protected Set<Integer> |
altsWithProblem
The overall list of alts within the decision that have at least one
conflicting input sequence.
|
protected Set<DFAState> |
danglingStates
The set of states w/o emanating edges and w/o resolving sem preds.
|
DFA |
dfa |
protected boolean |
nonLLStarDecision
If decision with > 1 alt has recursion in > 1 alt, it's nonregular
lookahead.
|
static Integer |
REACHABLE_BUSY |
static Integer |
REACHABLE_NO |
static Integer |
REACHABLE_YES |
protected Map<Integer,Integer> |
stateReachable
Used to find paths through syntactically ambiguous DFA.
|
protected 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 Set<String> |
statesVisitedAtInputDepth
Used while finding a path through an NFA whose edge labels match
an input sequence.
|
protected Set<Integer> |
statesVisitedDuringSampleSequence |
protected Set<DFAState> |
statesWithSyntacticallyAmbiguousAltsSet
Track all DFA states with nondeterministic alternatives.
|
protected Map<DFAState,Map<Integer,SemanticContext>> |
stateToAltSetWithSemanticPredicatesMap
Track the predicates for each alt per DFA state;
more than one DFA state might have syntactically ambig alt prediction.
|
protected Map<DFAState,Map<Integer,Set<antlr.Token>>> |
stateToIncompletelyCoveredAltsMap
Tracks alts insufficiently covered.
|
protected MultiMap<Integer,NFAConfiguration> |
stateToRecursionOverflowConfigurationsMap
Recursion is limited to a particular depth.
|
protected Map<DFAState,Set<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
|
boolean |
analysisTimedOut()
Did the analysis complete it's work?
|
Set |
getDanglingStates()
return set of states w/o emanating edges and w/o resolving sem preds.
|
String |
getDescription()
Return a string like "3:22: ( A {;} | B )" that describes this
decision.
|
protected Set |
getDFAPathStatesToTarget(DFAState targetState) |
Set |
getDFAStatesWithSyntacticallyAmbiguousAlts()
Return all DFA states in this DFA that have NFA configurations that
conflict.
|
Set |
getDisabledAlternatives(DFAState d)
Which alts were specifically turned off to resolve nondeterminisms?
This is different than the unreachable alts.
|
Map<Integer,Set<antlr.Token>> |
getIncompletelyCoveredAlts(DFAState d)
Return a list of alts whose predicate context was insufficient to
resolve a nondeterminism for state d.
|
String |
getInputSequenceDisplay(List labels)
Given List
|
protected boolean |
getNFAPath(NFAState s,
int labelIndex,
List labels,
List path)
Given a sample input sequence, you usually would like to know the
path taken through the NFA.
|
List |
getNFAPathStatesForAlt(int firstAlt,
int alt,
List labels)
Given an alternative associated with a nondeterministic DFA state,
find the path of NFA states associated with the labels sequence.
|
Set |
getNonDeterministicAlts() |
List |
getNonDeterministicAltsForState(DFAState targetState)
Return the sorted list of alts that conflict within a single state.
|
Set |
getNondeterministicStatesResolvedWithSemanticPredicate() |
int |
getNumberOfStates()
How many states does the DFA predictor have?
|
protected void |
getSampleInputSequenceUsingStateSet(State startState,
State targetState,
Set states,
List<Label> labels)
Given a start state and a final state, find a list of edge labels
between the two ignoring epsilon.
|
List<Label> |
getSampleNonDeterministicInputSequence(DFAState targetState)
Return a List
|
SemanticContext |
getSemanticContextForAlt(DFAState d,
int alt)
Each state in the DFA represents a different input sequence for an
alt of the decision.
|
protected String |
getStateLabelIndexKey(int s,
int i) |
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.
|
List<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,
Set 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,
Map 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 |
reportAnalysisTimeout() |
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,
Map<Integer,Set<antlr.Token>> altToLocationsReachableWithoutPredicate) |
void |
reportLexerRuleNondeterminism(DFAState d,
Set<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,
Set<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(Set 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 Set<DFAState> statesWithSyntacticallyAmbiguousAltsSet
protected Map<DFAState,Set<Integer>> stateToSyntacticallyAmbiguousTokensRuleAltsMap
protected Set<DFAState> statesResolvedWithSemanticPredicatesSet
protected Map<DFAState,Map<Integer,SemanticContext>> stateToAltSetWithSemanticPredicatesMap
protected Map<DFAState,Map<Integer,Set<antlr.Token>>> stateToIncompletelyCoveredAltsMap
protected Set<DFAState> danglingStates
protected Set<Integer> altsWithProblem
protected boolean nonLLStarDecision
protected MultiMap<Integer,NFAConfiguration> stateToRecursionOverflowConfigurationsMap
protected boolean timedOut
protected Map<Integer,Integer> stateReachable
public static final Integer REACHABLE_BUSY
public static final Integer REACHABLE_NO
public static final Integer REACHABLE_YES
protected Set<String> statesVisitedAtInputDepth
public static boolean verbose
public DecisionProbe(DFA dfa)
public String getDescription()
public boolean isReduced()
public boolean isCyclic()
public boolean isDeterministic()
public boolean analysisTimedOut()
public boolean analysisOverflowed()
public boolean isNonLLStarDecision()
public int getNumberOfStates()
public List<Integer> getUnreachableAlts()
public Set getDanglingStates()
public Set getNonDeterministicAlts()
public List getNonDeterministicAltsForState(DFAState targetState)
public Set getDFAStatesWithSyntacticallyAmbiguousAlts()
public Set getDisabledAlternatives(DFAState d)
public void removeRecursiveOverflowState(DFAState d)
public List<Label> getSampleNonDeterministicInputSequence(DFAState targetState)
public List getNFAPathStatesForAlt(int firstAlt, int alt, List labels)
public SemanticContext getSemanticContextForAlt(DFAState d, int alt)
public boolean hasPredicate()
public Set getNondeterministicStatesResolvedWithSemanticPredicate()
public Map<Integer,Set<antlr.Token>> getIncompletelyCoveredAlts(DFAState d)
public void issueWarnings()
protected void stripWildCardAlts(Set disabledAlts)
protected void issueRecursionWarnings()
public void reportDanglingState(DFAState d)
public void reportAnalysisTimeout()
public void reportNonLLStarDecision(DFA dfa)
public void reportRecursionOverflow(DFAState d, NFAConfiguration recursionNFAConfiguration)
public void reportNondeterminism(DFAState d, Set<Integer> nondeterministicAlts)
public void reportLexerRuleNondeterminism(DFAState d, Set<Integer> nondeterministicAlts)
public void reportNondeterminismResolvedWithSemanticPredicate(DFAState d)
public void reportAltPredicateContext(DFAState d, Map altPredicateContext)
public void reportIncompletelyCoveredAlts(DFAState d, Map<Integer,Set<antlr.Token>> altToLocationsReachableWithoutPredicate)
protected boolean reachesState(DFAState startState, DFAState targetState, Set states)
protected void getSampleInputSequenceUsingStateSet(State startState, State targetState, Set states, List<Label> labels)
protected boolean getNFAPath(NFAState s, int labelIndex, List labels, List path)
protected String getStateLabelIndexKey(int s, int i)
public String getTokenNameForTokensRuleAlt(int alt)
public void reset()
Copyright © 2020. All rights reserved.