forked from jasder/antlr
Always update ATNConfigSet.hasSemanticContext and ATNConfigSet.dipsIntoOuterContext when adding configurations to the set; remove unnecessary manual updates
This commit is contained in:
parent
9b5417c54a
commit
6c23a96046
|
@ -33,6 +33,8 @@ package org.antlr.v4.runtime.atn;
|
|||
import org.antlr.v4.runtime.misc.AbstractEqualityComparator;
|
||||
import org.antlr.v4.runtime.misc.Array2DHashSet;
|
||||
import org.antlr.v4.runtime.misc.DoubleKeyMap;
|
||||
import org.antlr.v4.runtime.misc.NotNull;
|
||||
import org.antlr.v4.runtime.misc.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
|
@ -317,22 +319,28 @@ public class ATNConfigSet implements Set<ATNConfig> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean add(ATNConfig config) {
|
||||
public boolean add(@NotNull ATNConfig config) {
|
||||
return add(config, null);
|
||||
}
|
||||
|
||||
/** Adding a new config means merging contexts with existing configs for
|
||||
* (s, i, pi, _)
|
||||
* We use (s,i,pi) as key
|
||||
* <p/>
|
||||
* This method updates {@link #dipsIntoOuterContext} and
|
||||
* {@link #hasSemanticContext} when necessary.
|
||||
*/
|
||||
public boolean add(
|
||||
ATNConfig config,
|
||||
DoubleKeyMap<PredictionContext,PredictionContext,PredictionContext> mergeCache)
|
||||
@NotNull ATNConfig config,
|
||||
@Nullable DoubleKeyMap<PredictionContext,PredictionContext,PredictionContext> mergeCache)
|
||||
{
|
||||
if ( readonly ) throw new IllegalStateException("This set is readonly");
|
||||
if ( config.semanticContext!=SemanticContext.NONE ) {
|
||||
hasSemanticContext = true;
|
||||
}
|
||||
if (config.reachesIntoOuterContext > 0) {
|
||||
dipsIntoOuterContext = true;
|
||||
}
|
||||
ATNConfig existing = configLookup.getOrAdd(config);
|
||||
if ( existing==config ) { // we added this new one
|
||||
configs.add(config); // track order here
|
||||
|
|
|
@ -968,7 +968,6 @@ public class ParserATNSimulator extends ATNSimulator {
|
|||
|
||||
if (skippedStopStates != null && !PredictionMode.hasConfigAtRuleStopState(reach)) {
|
||||
for (ATNConfig c : skippedStopStates) {
|
||||
assert c.reachesIntoOuterContext == 0 && c.semanticContext == SemanticContext.NONE;
|
||||
reach.add(c, mergeCache);
|
||||
}
|
||||
}
|
||||
|
@ -1232,12 +1231,6 @@ public class ParserATNSimulator extends ATNSimulator {
|
|||
// optimization
|
||||
if ( !p.onlyHasEpsilonTransitions() ) {
|
||||
configs.add(config, mergeCache);
|
||||
if ( config.semanticContext!= SemanticContext.NONE ) {
|
||||
configs.hasSemanticContext = true;
|
||||
}
|
||||
if ( config.reachesIntoOuterContext>0 ) {
|
||||
configs.dipsIntoOuterContext = true;
|
||||
}
|
||||
// if ( debug ) System.out.println("added config "+configs);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue