Remove unnecessary duplicate conditions

This commit is contained in:
Sam Harwell 2013-04-18 12:35:15 -05:00
parent 3defe6a2b1
commit 74f4938033
1 changed files with 23 additions and 31 deletions

View File

@ -328,16 +328,13 @@ public class ParserATNSimulator extends ATNSimulator {
// Now we are certain to have a specific decision's DFA // Now we are certain to have a specific decision's DFA
// But, do we still need an initial state? // But, do we still need an initial state?
if ( dfa.s0==null ) { // recheck if ( dfa.s0==null ) {
if ( dfa.s0==null ) { // recheck try {
try { return predictATN(dfa, input, outerContext);
return predictATN(dfa, input, outerContext); }
} finally {
finally { mergeCache = null; // wack cache after each prediction
mergeCache = null; // wack cache after each prediction
}
} }
// fall through; another thread set dfa.s0 while we waited for lock
} }
// We can start with an existing DFA // We can start with an existing DFA
@ -467,30 +464,25 @@ public class ParserATNSimulator extends ATNSimulator {
" at DFA state "+s.stateNumber); " at DFA state "+s.stateNumber);
} }
//TODO: recheck synchronization here. don't need if no sync alt = execATN(dfa, s, input, startIndex, outerContext);
// recheck; another thread might have added edge // this adds edge even if next state is accept for
if ( s.edges == null || t >= s.edges.length || t < -1 || s.edges[t+1] == null ) { // same alt; e.g., s0-A->:s1=>2-B->:s2=>2
alt = execATN(dfa, s, input, startIndex, outerContext); // TODO: This next stuff kills edge, but extra states remain. :(
// this adds edge even if next state is accept for if ( s.isAcceptState && alt!=ATN.INVALID_ALT_NUMBER ) {
// same alt; e.g., s0-A->:s1=>2-B->:s2=>2 DFAState d = s.edges[input.LA(1)+1];
// TODO: This next stuff kills edge, but extra states remain. :( if ( d.isAcceptState && d.prediction==s.prediction ) {
if ( s.isAcceptState && alt!=ATN.INVALID_ALT_NUMBER ) { // we can carve it out.
DFAState d = s.edges[input.LA(1)+1]; s.edges[input.LA(1)+1] = ERROR; // IGNORE really not error
if ( d.isAcceptState && d.prediction==s.prediction ) {
// we can carve it out.
s.edges[input.LA(1)+1] = ERROR; // IGNORE really not error
}
} }
if ( dfa_debug ) {
System.out.println("back from DFA update, alt="+alt+", dfa=\n"+dfa.toString(parser.getTokenNames()));
//dump(dfa);
}
// action already executed
if ( dfa_debug ) System.out.println("DFA decision "+dfa.decision+
" predicts "+alt);
return alt; // we've updated DFA, exec'd action, and have our deepest answer
} }
// fall through; another thread gave us the edge if ( dfa_debug ) {
System.out.println("back from DFA update, alt="+alt+", dfa=\n"+dfa.toString(parser.getTokenNames()));
//dump(dfa);
}
// action already executed
if ( dfa_debug ) System.out.println("DFA decision "+dfa.decision+
" predicts "+alt);
return alt; // we've updated DFA, exec'd action, and have our deepest answer
} }
DFAState target = s.edges[t+1]; DFAState target = s.edges[t+1];
if ( target == ERROR ) { if ( target == ERROR ) {