check in start of new ATN sim engine; rm traversedPred in DFAState.

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9598]
This commit is contained in:
parrt 2011-12-13 14:38:30 -08:00
parent 8f7fb98e16
commit 8d73f53775
5 changed files with 1175 additions and 8 deletions

View File

@ -39,6 +39,8 @@ import org.antlr.v4.runtime.misc.Nullable;
* chain used to arrive at the state. The semantic context is
* the unordered set semantic predicates encountered before reaching
* an ATN state.
*
* (state, alt, rule context, semantic context)
*/
public class ATNConfig {
/** The ATN state associated with this configuration */
@ -62,7 +64,10 @@ public class ATNConfig {
* otherwise predicates would not get executed again (DFAs don't
* have predicated edges in v4).
*/
public boolean traversedPredicate; // TODO: don't need
//public boolean traversedPredicate; // TODO: don't need
/** Ignore this config when examining config sets */
public boolean resolved;
/**
* We cannot execute predicates dependent upon local context unless
@ -109,10 +114,6 @@ public class ATNConfig {
this.semanticContext = semanticContext;
}
// public ATNConfig(@NotNull ATNConfig c) {
// this(c, c.state, c.context, c.semanticContext);
// }
public ATNConfig(@NotNull ATNConfig c, @NotNull ATNState state) {
this(c, state, c.context, c.semanticContext);
}
@ -131,7 +132,6 @@ public class ATNConfig {
this.state = state;
this.alt = c.alt;
this.context = context;
this.traversedPredicate = c.traversedPredicate;
this.reachesIntoOuterContext = c.reachesIntoOuterContext;
this.semanticContext = semanticContext;
}

View File

@ -0,0 +1,43 @@
/*
[The "BSD license"]
Copyright (c) 2011 Terence Parr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.OrderedHashSet;
/** Specialized OrderedHashSet that can track info about the set.
* Might be able to optimize later w/o affecting code that uses this set.
*/
public class ATNConfigSet extends OrderedHashSet<ATNConfig> {
// TODO: these fields make me pretty uncomfortable but nice to pack up info together, saves recomputation
public int uniqueAlt;
public IntervalSet conflictingAlts;
public boolean hasSemanticContext;
}

View File

@ -526,7 +526,7 @@ public class LexerATNSimulator extends ATNSimulator {
PredicateTransition pt = (PredicateTransition)t;
if ( recog == null || recog.sempred(null, pt.ruleIndex, pt.predIndex) ) {
c = new ATNConfig(config, t.target);
c.traversedPredicate = true;
// c.traversedPredicate = true;
}
}
// ignore actions; just exec one per rule upon accept
@ -641,7 +641,7 @@ public class LexerATNSimulator extends ATNSimulator {
{
firstConfigWithRuleStopState = c;
}
if ( c.traversedPredicate ) traversedPredicate = true;
// if ( c.traversedPredicate ) traversedPredicate = true;
}
if ( firstConfigWithRuleStopState!=null ) {

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,7 @@ package org.antlr.v4.runtime.dfa;
import org.antlr.v4.runtime.RuleContext;
import org.antlr.v4.runtime.atn.ATNConfig;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.atn.SemanticContext;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.misc.OrderedHashSet;
@ -71,6 +72,9 @@ public class DFAState {
@Nullable
public OrderedHashSet<ATNConfig> configs = new OrderedHashSet<ATNConfig>();
// TODO: rename to configs after flipping to new ATN sim
public ATNConfigSet configset = new ATNConfigSet();
/** edges[symbol] points to target of symbol */
@Nullable
public DFAState[] edges;