slow again since i had to remove full LL context->alt cache (wasn't correct). But, threaded now makes bigger diff than before.

This commit is contained in:
Terence Parr 2012-08-02 17:01:53 -07:00
parent 754e6eb593
commit 06d7c150fd
2 changed files with 1 additions and 19 deletions

View File

@ -282,12 +282,6 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
if ( dfa_debug ) System.out.println("DFA state "+s.stateNumber+" LA(1)=="+getLookaheadName(input)); if ( dfa_debug ) System.out.println("DFA state "+s.stateNumber+" LA(1)=="+getLookaheadName(input));
if ( s.isCtxSensitive && !SLL ) { if ( s.isCtxSensitive && !SLL ) {
if ( dfa_debug ) System.out.println("ctx sensitive state "+outerContext+" in "+s); if ( dfa_debug ) System.out.println("ctx sensitive state "+outerContext+" in "+s);
PredictionContext predictionCtx = PredictionContext.fromRuleContext(outerContext);
predictionCtx = getCachedContext(predictionCtx);
Integer predI = s.contextToPredictedAlt.get(predictionCtx);
if ( predI!=null ) {
return predI; // ha! quick exit :)
}
boolean loopsSimulateTailRecursion = true; boolean loopsSimulateTailRecursion = true;
boolean fullCtx = true; boolean fullCtx = true;
ATNConfigSet s0_closure = ATNConfigSet s0_closure =
@ -301,7 +295,6 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
outerContext, outerContext,
ATN.INVALID_ALT_NUMBER, ATN.INVALID_ALT_NUMBER,
greedy); greedy);
s.contextToPredictedAlt.put(predictionCtx, fullCtxSet.uniqueAlt);
return fullCtxSet.uniqueAlt; return fullCtxSet.uniqueAlt;
} }
if ( s.isAcceptState ) { if ( s.isAcceptState ) {
@ -540,13 +533,9 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
D.configs.conflictingAlts.getMinElement(), D.configs.conflictingAlts.getMinElement(),
greedy); greedy);
// not accept state: isCtxSensitive // not accept state: isCtxSensitive
PredictionContext predictionCtx = PredictionContext.fromRuleContext(outerContext);
predictionCtx = getCachedContext(predictionCtx);
D.isCtxSensitive = true; // always force DFA to ATN simulate D.isCtxSensitive = true; // always force DFA to ATN simulate
predictedAlt = fullCtxSet.uniqueAlt; predictedAlt = fullCtxSet.uniqueAlt;
D.prediction = ATN.INVALID_ALT_NUMBER; D.prediction = ATN.INVALID_ALT_NUMBER;
// TODO: have to cache pred list to test also
D.contextToPredictedAlt.put(predictionCtx, predictedAlt); // CACHE
addDFAEdge(dfa, previousD, t, D); addDFAEdge(dfa, previousD, t, D);
return predictedAlt; // all done with preds, etc... return predictedAlt; // all done with preds, etc...
} }
@ -810,7 +799,7 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
} }
int nPredAlts = 0; int nPredAlts = 0;
for (int i = 0; i < n; i++) { for (int i = 1; i < n; i++) {
if (altToPred[i] == null) { if (altToPred[i] == null) {
altToPred[i] = SemanticContext.NONE; altToPred[i] = SemanticContext.NONE;
} }

View File

@ -31,15 +31,11 @@ package org.antlr.v4.runtime.dfa;
import org.antlr.v4.runtime.atn.ATNConfig; import org.antlr.v4.runtime.atn.ATNConfig;
import org.antlr.v4.runtime.atn.ATNConfigSet; import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.atn.PredictionContext;
import org.antlr.v4.runtime.atn.SemanticContext; import org.antlr.v4.runtime.atn.SemanticContext;
import org.antlr.v4.runtime.misc.Nullable; import org.antlr.v4.runtime.misc.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** A DFA state represents a set of possible ATN configurations. /** A DFA state represents a set of possible ATN configurations.
@ -110,9 +106,6 @@ public class DFAState {
@Nullable @Nullable
public List<PredPrediction> predicates; public List<PredPrediction> predicates;
public Map<PredictionContext,Integer> contextToPredictedAlt =
Collections.synchronizedMap(new HashMap<PredictionContext, Integer>());
/** Map a predicate to a predicted alternative */ /** Map a predicate to a predicted alternative */
public static class PredPrediction { public static class PredPrediction {
public SemanticContext pred; // never null; at least SemanticContext.NONE public SemanticContext pred; // never null; at least SemanticContext.NONE