Updated properties and parameter types

This commit is contained in:
Sam Harwell 2013-02-19 11:45:58 -06:00
parent c865930973
commit b0a106eaa4
10 changed files with 344 additions and 317 deletions

View File

@ -86,19 +86,20 @@ namespace Antlr4.Runtime.Atn
public static Antlr4.Runtime.Atn.ATNConfig Create(ATNState state, int alt, PredictionContext
context)
{
return Create(state, alt, context, SemanticContext.None, -1);
return Create(state, alt, context, Antlr4.Runtime.Atn.SemanticContext.None, -1);
}
public static Antlr4.Runtime.Atn.ATNConfig Create(ATNState state, int alt, PredictionContext
context, SemanticContext semanticContext)
context, Antlr4.Runtime.Atn.SemanticContext semanticContext)
{
return Create(state, alt, context, semanticContext, -1);
}
public static Antlr4.Runtime.Atn.ATNConfig Create(ATNState state, int alt, PredictionContext
context, SemanticContext semanticContext, int actionIndex)
context, Antlr4.Runtime.Atn.SemanticContext semanticContext, int actionIndex
)
{
if (semanticContext != SemanticContext.None)
if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
{
if (actionIndex != -1)
{
@ -124,124 +125,143 @@ namespace Antlr4.Runtime.Atn
}
}
/// <summary>Gets the ATN state associated with this configuration</summary>
[NotNull]
public ATNState GetState()
/// <summary>Gets the ATN state associated with this configuration.</summary>
/// <remarks>Gets the ATN state associated with this configuration.</remarks>
public ATNState State
{
return state;
}
/// <summary>What alt (or lexer rule) is predicted by this configuration</summary>
public int GetAlt()
{
return altAndOuterContextDepth & unchecked((int)(0x00FFFFFF));
}
public bool IsHidden()
{
return altAndOuterContextDepth < 0;
}
public virtual void SetHidden(bool value)
{
if (value)
get
{
altAndOuterContextDepth |= unchecked((int)(0x80000000));
}
else
{
altAndOuterContextDepth &= ~unchecked((int)(0x80000000));
return state;
}
}
[NotNull]
public PredictionContext GetContext()
/// <summary>What alt (or lexer rule) is predicted by this configuration.</summary>
/// <remarks>What alt (or lexer rule) is predicted by this configuration.</remarks>
public int Alt
{
return context;
get
{
return altAndOuterContextDepth & unchecked((int)(0x00FFFFFF));
}
}
public virtual void SetContext(PredictionContext context)
public virtual bool IsHidden
{
this.context = context;
get
{
return altAndOuterContextDepth < 0;
}
set
{
if (value)
{
altAndOuterContextDepth |= unchecked((int)(0x80000000));
}
else
{
altAndOuterContextDepth &= ~unchecked((int)(0x80000000));
}
}
}
public bool GetReachesIntoOuterContext()
public virtual PredictionContext Context
{
return GetOuterContextDepth() != 0;
get
{
return context;
}
set
{
PredictionContext context = value;
this.context = context;
}
}
public bool ReachesIntoOuterContext
{
get
{
return OuterContextDepth != 0;
}
}
/// <summary>
/// We cannot execute predicates dependent upon local context unless
/// we know for sure we are in the correct context.
/// We cannot execute predicates dependent upon local context unless we know
/// for sure we are in the correct context.
/// </summary>
/// <remarks>
/// We cannot execute predicates dependent upon local context unless
/// we know for sure we are in the correct context. Because there is
/// no way to do this efficiently, we simply cannot evaluate
/// dependent predicates unless we are in the rule that initially
/// invokes the ATN simulator.
/// closure() tracks the depth of how far we dip into the
/// outer context: depth &gt; 0. Note that it may not be totally
/// accurate depth since I don't ever decrement. TODO: make it a boolean then
/// We cannot execute predicates dependent upon local context unless we know
/// for sure we are in the correct context. Because there is no way to do
/// this efficiently, we simply cannot evaluate dependent predicates unless
/// we are in the rule that initially invokes the ATN simulator.
/// closure() tracks the depth of how far we dip into the outer context:
/// depth &gt; 0. Note that it may not be totally accurate depth since I don't
/// ever decrement. TODO: make it a boolean then
/// </remarks>
public int GetOuterContextDepth()
public virtual int OuterContextDepth
{
return ((int)(((uint)altAndOuterContextDepth) >> 24)) & unchecked((int)(0x7F));
get
{
return ((int)(((uint)altAndOuterContextDepth) >> 24)) & unchecked((int)(0x7F));
}
set
{
int outerContextDepth = value;
System.Diagnostics.Debug.Assert(outerContextDepth >= 0);
// saturate at 0x7F - everything but zero/positive is only used for debug information anyway
outerContextDepth = Math.Min(outerContextDepth, unchecked((int)(0x7F)));
this.altAndOuterContextDepth = (outerContextDepth << 24) | (altAndOuterContextDepth
& ~unchecked((int)(0x7F000000)));
}
}
public virtual void SetOuterContextDepth(int outerContextDepth)
public virtual int ActionIndex
{
System.Diagnostics.Debug.Assert(outerContextDepth >= 0);
// saturate at 0x7F - everything but zero/positive is only used for debug information anyway
outerContextDepth = Math.Min(outerContextDepth, unchecked((int)(0x7F)));
this.altAndOuterContextDepth = (outerContextDepth << 24) | (altAndOuterContextDepth
& ~unchecked((int)(0x7F000000)));
get
{
return -1;
}
}
public virtual int GetActionIndex()
public virtual Antlr4.Runtime.Atn.SemanticContext SemanticContext
{
return -1;
}
[NotNull]
public virtual SemanticContext GetSemanticContext()
{
return SemanticContext.None;
get
{
return Antlr4.Runtime.Atn.SemanticContext.None;
}
}
public Antlr4.Runtime.Atn.ATNConfig Clone()
{
return Transform(this.GetState());
return Transform(this.State);
}
public Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state)
{
return Transform(state, this.context, this.GetSemanticContext(), this.GetActionIndex
());
return Transform(state, this.context, this.SemanticContext, this.ActionIndex);
}
public Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, SemanticContext semanticContext
)
public Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, Antlr4.Runtime.Atn.SemanticContext
semanticContext)
{
return Transform(state, this.context, semanticContext, this.GetActionIndex());
return Transform(state, this.context, semanticContext, this.ActionIndex);
}
public Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, PredictionContext context
)
{
return Transform(state, context, this.GetSemanticContext(), this.GetActionIndex()
);
return Transform(state, context, this.SemanticContext, this.ActionIndex);
}
public Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, int actionIndex)
{
return Transform(state, context, this.GetSemanticContext(), actionIndex);
return Transform(state, context, this.SemanticContext, actionIndex);
}
private Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, PredictionContext
context, SemanticContext semanticContext, int actionIndex)
context, Antlr4.Runtime.Atn.SemanticContext semanticContext, int actionIndex)
{
if (semanticContext != SemanticContext.None)
if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
{
if (actionIndex != -1)
{
@ -270,33 +290,30 @@ namespace Antlr4.Runtime.Atn
public virtual Antlr4.Runtime.Atn.ATNConfig AppendContext(int context, PredictionContextCache
contextCache)
{
PredictionContext appendedContext = GetContext().AppendContext(context, contextCache
);
Antlr4.Runtime.Atn.ATNConfig result = Transform(GetState(), appendedContext);
PredictionContext appendedContext = Context.AppendContext(context, contextCache);
Antlr4.Runtime.Atn.ATNConfig result = Transform(State, appendedContext);
return result;
}
public virtual Antlr4.Runtime.Atn.ATNConfig AppendContext(PredictionContext context
, PredictionContextCache contextCache)
{
PredictionContext appendedContext = GetContext().AppendContext(context, contextCache
);
Antlr4.Runtime.Atn.ATNConfig result = Transform(GetState(), appendedContext);
PredictionContext appendedContext = Context.AppendContext(context, contextCache);
Antlr4.Runtime.Atn.ATNConfig result = Transform(State, appendedContext);
return result;
}
public virtual bool Contains(Antlr4.Runtime.Atn.ATNConfig subconfig)
{
if (this.GetState().stateNumber != subconfig.GetState().stateNumber || this.GetAlt
() != subconfig.GetAlt() || !this.GetSemanticContext().Equals(subconfig.GetSemanticContext
()))
if (this.State.stateNumber != subconfig.State.stateNumber || this.Alt != subconfig
.Alt || !this.SemanticContext.Equals(subconfig.SemanticContext))
{
return false;
}
IDeque<PredictionContext> leftWorkList = new ArrayDeque<PredictionContext>();
IDeque<PredictionContext> rightWorkList = new ArrayDeque<PredictionContext>();
leftWorkList.AddItem(GetContext());
rightWorkList.AddItem(subconfig.GetContext());
leftWorkList.AddItem(Context);
rightWorkList.AddItem(subconfig.Context);
while (!leftWorkList.IsEmpty())
{
PredictionContext left = leftWorkList.Pop();
@ -363,21 +380,20 @@ namespace Antlr4.Runtime.Atn
return false;
}
}
return this.GetState().stateNumber == other.GetState().stateNumber && this.GetAlt
() == other.GetAlt() && this.GetReachesIntoOuterContext() == other.GetReachesIntoOuterContext
() && this.GetContext().Equals(other.GetContext()) && this.GetSemanticContext
().Equals(other.GetSemanticContext()) && this.GetActionIndex() == other.GetActionIndex
();
return this.State.stateNumber == other.State.stateNumber && this.Alt == other.Alt
&& this.ReachesIntoOuterContext == other.ReachesIntoOuterContext && this.Context
.Equals(other.Context) && this.SemanticContext.Equals(other.SemanticContext)
&& this.ActionIndex == other.ActionIndex;
}
public override int GetHashCode()
{
int hashCode = 7;
hashCode = 5 * hashCode + GetState().stateNumber;
hashCode = 5 * hashCode + GetAlt();
hashCode = 5 * hashCode + (GetReachesIntoOuterContext() ? 1 : 0);
hashCode = 5 * hashCode + (GetContext() != null ? GetContext().GetHashCode() : 0);
hashCode = 5 * hashCode + GetSemanticContext().GetHashCode();
hashCode = 5 * hashCode + State.stateNumber;
hashCode = 5 * hashCode + Alt;
hashCode = 5 * hashCode + (ReachesIntoOuterContext ? 1 : 0);
hashCode = 5 * hashCode + (Context != null ? Context.GetHashCode() : 0);
hashCode = 5 * hashCode + SemanticContext.GetHashCode();
return hashCode;
}
@ -389,8 +405,8 @@ namespace Antlr4.Runtime.Atn
IDictionary<PredictionContext, PredictionContext> visited = new IdentityHashMap<PredictionContext
, PredictionContext>();
IDeque<PredictionContext> workList = new ArrayDeque<PredictionContext>();
workList.AddItem(GetContext());
visited.Put(GetContext(), GetContext());
workList.AddItem(Context);
visited.Put(Context, Context);
while (!workList.IsEmpty())
{
PredictionContext current = workList.Pop();
@ -433,7 +449,7 @@ namespace Antlr4.Runtime.Atn
string[] contexts;
if (showContext)
{
contexts = GetContext().ToStrings(recog, this.GetState().stateNumber);
contexts = Context.ToStrings(recog, this.State.stateNumber);
}
else
{
@ -451,25 +467,26 @@ namespace Antlr4.Runtime.Atn
buf.Append(", ");
}
buf.Append('(');
buf.Append(GetState());
buf.Append(State);
if (showAlt)
{
buf.Append(",");
buf.Append(GetAlt());
buf.Append(Alt);
}
if (GetContext() != null)
if (Context != null)
{
buf.Append(",");
buf.Append(contextDesc);
}
if (GetSemanticContext() != null && GetSemanticContext() != SemanticContext.None)
if (SemanticContext != null && SemanticContext != Antlr4.Runtime.Atn.SemanticContext
.None)
{
buf.Append(",");
buf.Append(GetSemanticContext());
buf.Append(SemanticContext);
}
if (GetReachesIntoOuterContext())
if (ReachesIntoOuterContext)
{
buf.Append(",up=").Append(GetOuterContextDepth());
buf.Append(",up=").Append(OuterContextDepth);
}
buf.Append(')');
}
@ -479,23 +496,28 @@ namespace Antlr4.Runtime.Atn
private class SemanticContextATNConfig : ATNConfig
{
[NotNull]
private readonly SemanticContext semanticContext;
private readonly Antlr4.Runtime.Atn.SemanticContext semanticContext;
public SemanticContextATNConfig(SemanticContext semanticContext, ATNState state,
int alt, PredictionContext context) : base(state, alt, context)
public SemanticContextATNConfig(Antlr4.Runtime.Atn.SemanticContext semanticContext
, ATNState state, int alt, PredictionContext context) : base(state, alt, context
)
{
this.semanticContext = semanticContext;
}
public SemanticContextATNConfig(SemanticContext semanticContext, ATNConfig c, ATNState
state, PredictionContext context) : base(c, state, context)
public SemanticContextATNConfig(Antlr4.Runtime.Atn.SemanticContext semanticContext
, ATNConfig c, ATNState state, PredictionContext context) : base(c, state, context
)
{
this.semanticContext = semanticContext;
}
public override SemanticContext GetSemanticContext()
public override Antlr4.Runtime.Atn.SemanticContext SemanticContext
{
return semanticContext;
get
{
return semanticContext;
}
}
}
@ -512,16 +534,19 @@ namespace Antlr4.Runtime.Atn
protected internal ActionATNConfig(int actionIndex, ATNConfig c, ATNState state,
PredictionContext context) : base(c, state, context)
{
if (c.GetSemanticContext() != SemanticContext.None)
if (c.SemanticContext != SemanticContext.None)
{
throw new NotSupportedException();
}
this.actionIndex = actionIndex;
}
public override int GetActionIndex()
public override int ActionIndex
{
return actionIndex;
get
{
return actionIndex;
}
}
}
@ -543,9 +568,12 @@ namespace Antlr4.Runtime.Atn
this.actionIndex = actionIndex;
}
public override int GetActionIndex()
public override int ActionIndex
{
return actionIndex;
get
{
return actionIndex;
}
}
}
}

View File

@ -44,7 +44,7 @@ namespace Antlr4.Runtime.Atn
/// <see cref="ATNConfig">ATNConfig</see>
/// . The key does not account for
/// the
/// <see cref="ATNConfig.GetSemanticContext()">ATNConfig.GetSemanticContext()</see>
/// <see cref="ATNConfig.SemanticContext()">ATNConfig.SemanticContext()</see>
/// of the value, which is only a problem if a single
/// <code>ATNConfigSet</code>
/// contains two configs with the same state and alternative
@ -168,7 +168,7 @@ namespace Antlr4.Runtime.Atn
BitSet alts = new BitSet();
foreach (ATNConfig config in this)
{
alts.Set(config.GetAlt());
alts.Set(config.Alt);
}
return alts;
}
@ -188,7 +188,7 @@ namespace Antlr4.Runtime.Atn
();
while (iterator.HasNext())
{
if (iterator.Next().Value.IsHidden())
if (iterator.Next().Value.IsHidden)
{
iterator.Remove();
}
@ -196,7 +196,7 @@ namespace Antlr4.Runtime.Atn
IListIterator<ATNConfig> iterator2 = unmerged.ListIterator();
while (iterator2.HasNext())
{
if (iterator2.Next().IsHidden())
if (iterator2.Next().IsHidden)
{
iterator2.Remove();
}
@ -204,7 +204,7 @@ namespace Antlr4.Runtime.Atn
iterator2 = configs.ListIterator();
while (iterator2.HasNext())
{
if (iterator2.Next().IsHidden())
if (iterator2.Next().IsHidden)
{
iterator2.Remove();
}
@ -234,7 +234,7 @@ namespace Antlr4.Runtime.Atn
ISet<ATNState> states = new HashSet<ATNState>();
foreach (ATNConfig c in this.configs)
{
states.AddItem(c.GetState());
states.AddItem(c.State);
}
return states;
}
@ -248,7 +248,7 @@ namespace Antlr4.Runtime.Atn
for (int i = 0; i < configs.Count; i++)
{
ATNConfig config = configs[i];
config.SetContext(interpreter.atn.GetCachedContext(config.GetContext()));
config.Context = interpreter.atn.GetCachedContext(config.Context);
}
}
@ -317,9 +317,9 @@ namespace Antlr4.Runtime.Atn
public virtual bool Add(ATNConfig e, PredictionContextCache contextCache)
{
EnsureWritable();
System.Diagnostics.Debug.Assert(!outermostConfigSet || !e.GetReachesIntoOuterContext
());
System.Diagnostics.Debug.Assert(!e.IsHidden());
System.Diagnostics.Debug.Assert(!outermostConfigSet || !e.ReachesIntoOuterContext
);
System.Diagnostics.Debug.Assert(!e.IsHidden);
if (contextCache == null)
{
contextCache = PredictionContextCache.Uncached;
@ -330,16 +330,16 @@ namespace Antlr4.Runtime.Atn
addKey = (mergedConfig == null);
if (mergedConfig != null && CanMerge(e, key, mergedConfig))
{
mergedConfig.SetOuterContextDepth(Math.Max(mergedConfig.GetOuterContextDepth(), e
.GetOuterContextDepth()));
PredictionContext joined = PredictionContext.Join(mergedConfig.GetContext(), e.GetContext
(), contextCache);
mergedConfig.OuterContextDepth = Math.Max(mergedConfig.OuterContextDepth, e.OuterContextDepth
);
PredictionContext joined = PredictionContext.Join(mergedConfig.Context, e.Context
, contextCache);
UpdatePropertiesForMergedConfig(e);
if (mergedConfig.GetContext() == joined)
if (mergedConfig.Context == joined)
{
return false;
}
mergedConfig.SetContext(joined);
mergedConfig.Context = joined;
return true;
}
for (int i = 0; i < unmerged.Count; i++)
@ -347,16 +347,16 @@ namespace Antlr4.Runtime.Atn
ATNConfig unmergedConfig = unmerged[i];
if (CanMerge(e, key, unmergedConfig))
{
unmergedConfig.SetOuterContextDepth(Math.Max(unmergedConfig.GetOuterContextDepth(
), e.GetOuterContextDepth()));
PredictionContext joined = PredictionContext.Join(unmergedConfig.GetContext(), e.
GetContext(), contextCache);
unmergedConfig.OuterContextDepth = Math.Max(unmergedConfig.OuterContextDepth, e.OuterContextDepth
);
PredictionContext joined = PredictionContext.Join(unmergedConfig.Context, e.Context
, contextCache);
UpdatePropertiesForMergedConfig(e);
if (unmergedConfig.GetContext() == joined)
if (unmergedConfig.Context == joined)
{
return false;
}
unmergedConfig.SetContext(joined);
unmergedConfig.Context = joined;
if (addKey)
{
mergedConfigs.Put(key, unmergedConfig);
@ -381,7 +381,7 @@ namespace Antlr4.Runtime.Atn
private void UpdatePropertiesForMergedConfig(ATNConfig config)
{
// merged configs can't change the alt or semantic context
dipsIntoOuterContext |= config.GetReachesIntoOuterContext();
dipsIntoOuterContext |= config.ReachesIntoOuterContext;
System.Diagnostics.Debug.Assert(!outermostConfigSet || !dipsIntoOuterContext);
}
@ -389,24 +389,24 @@ namespace Antlr4.Runtime.Atn
{
if (configs.Count == 1)
{
uniqueAlt = config.GetAlt();
uniqueAlt = config.Alt;
}
else
{
if (uniqueAlt != config.GetAlt())
if (uniqueAlt != config.Alt)
{
uniqueAlt = ATN.InvalidAltNumber;
}
}
hasSemanticContext |= !SemanticContext.None.Equals(config.GetSemanticContext());
dipsIntoOuterContext |= config.GetReachesIntoOuterContext();
hasSemanticContext |= !SemanticContext.None.Equals(config.SemanticContext);
dipsIntoOuterContext |= config.ReachesIntoOuterContext;
System.Diagnostics.Debug.Assert(!outermostConfigSet || !dipsIntoOuterContext);
}
protected internal virtual bool CanMerge(ATNConfig left, long leftKey, ATNConfig
right)
{
if (left.GetState().stateNumber != right.GetState().stateNumber)
if (left.State.stateNumber != right.State.stateNumber)
{
return false;
}
@ -414,13 +414,13 @@ namespace Antlr4.Runtime.Atn
{
return false;
}
return left.GetSemanticContext().Equals(right.GetSemanticContext());
return left.SemanticContext.Equals(right.SemanticContext);
}
protected internal virtual long GetKey(ATNConfig e)
{
long key = e.GetState().stateNumber;
key = (key << 12) | (e.GetAlt() & unchecked((int)(0xFFF)));
long key = e.State.stateNumber;
key = (key << 12) | (e.Alt & unchecked((int)(0xFFF)));
return key;
}
@ -557,20 +557,20 @@ namespace Antlr4.Runtime.Atn
public int Compare(ATNConfig o1, ATNConfig o2)
{
if (o1.GetAlt() != o2.GetAlt())
if (o1.Alt != o2.Alt)
{
return o1.GetAlt() - o2.GetAlt();
return o1.Alt - o2.Alt;
}
else
{
if (o1.GetState().stateNumber != o2.GetState().stateNumber)
if (o1.State.stateNumber != o2.State.stateNumber)
{
return o1.GetState().stateNumber - o2.GetState().stateNumber;
return o1.State.stateNumber - o2.State.stateNumber;
}
else
{
return string.CompareOrdinal(o1.GetSemanticContext().ToString(), o2.GetSemanticContext
().ToString());
return string.CompareOrdinal(o1.SemanticContext.ToString(), o2.SemanticContext.ToString
());
}
}
}

View File

@ -307,15 +307,15 @@ namespace Antlr4.Runtime.Atn
int skipAlt = ATN.InvalidAltNumber;
foreach (ATNConfig c in closure)
{
if (c.GetAlt() == skipAlt)
if (c.Alt == skipAlt)
{
continue;
}
int n = c.GetState().NumberOfOptimizedTransitions;
int n = c.State.NumberOfOptimizedTransitions;
for (int ti = 0; ti < n; ti++)
{
// for each optimized transition
Transition trans = c.GetState().GetOptimizedTransition(ti);
Transition trans = c.State.GetOptimizedTransition(ti);
ATNState target = GetReachableTarget(trans, t);
if (target != null)
{
@ -323,7 +323,7 @@ namespace Antlr4.Runtime.Atn
{
// any remaining configs for this alt have a lower priority than
// the one that just reached an accept state.
skipAlt = c.GetAlt();
skipAlt = c.Alt;
break;
}
}
@ -397,9 +397,9 @@ namespace Antlr4.Runtime.Atn
protected internal virtual bool Closure(ICharStream input, ATNConfig config, ATNConfigSet
configs, bool speculative)
{
if (config.GetState() is RuleStopState)
if (config.State is RuleStopState)
{
PredictionContext context = config.GetContext();
PredictionContext context = config.Context;
if (context.IsEmpty)
{
configs.AddItem(config);
@ -409,7 +409,7 @@ namespace Antlr4.Runtime.Atn
{
if (context.HasEmpty)
{
configs.AddItem(config.Transform(config.GetState(), PredictionContext.EmptyFull));
configs.AddItem(config.Transform(config.State, PredictionContext.EmptyFull));
return true;
}
}
@ -423,7 +423,7 @@ namespace Antlr4.Runtime.Atn
PredictionContext newContext = context.GetParent(i);
// "pop" return state
ATNState returnState = atn.states[returnStateNumber];
ATNConfig c = ATNConfig.Create(returnState, config.GetAlt(), newContext);
ATNConfig c = ATNConfig.Create(returnState, config.Alt, newContext);
if (Closure(input, c, configs, speculative))
{
return true;
@ -432,11 +432,11 @@ namespace Antlr4.Runtime.Atn
return false;
}
// optimization
if (!config.GetState().OnlyHasEpsilonTransitions)
if (!config.State.OnlyHasEpsilonTransitions)
{
configs.AddItem(config);
}
ATNState p = config.GetState();
ATNState p = config.State;
for (int i_1 = 0; i_1 < p.NumberOfOptimizedTransitions; i_1++)
{
Transition t = p.GetOptimizedTransition(i_1);
@ -463,14 +463,13 @@ namespace Antlr4.Runtime.Atn
case TransitionType.Rule:
{
RuleTransition ruleTransition = (RuleTransition)t;
if (optimize_tail_calls && ruleTransition.optimizedTailCall && !config.GetContext
().HasEmpty)
if (optimize_tail_calls && ruleTransition.optimizedTailCall && !config.Context.HasEmpty)
{
c = config.Transform(t.target);
}
else
{
PredictionContext newContext = config.GetContext().GetChild(ruleTransition.followState
PredictionContext newContext = config.Context.GetChild(ruleTransition.followState
.stateNumber);
c = config.Transform(t.target, newContext);
}
@ -661,7 +660,7 @@ namespace Antlr4.Runtime.Atn
ATNConfig firstConfigWithRuleStopState = null;
foreach (ATNConfig c in configs)
{
if (c.GetState() is RuleStopState)
if (c.State is RuleStopState)
{
firstConfigWithRuleStopState = c;
break;
@ -670,8 +669,8 @@ namespace Antlr4.Runtime.Atn
if (firstConfigWithRuleStopState != null)
{
newState.isAcceptState = true;
newState.lexerRuleIndex = firstConfigWithRuleStopState.GetState().ruleIndex;
newState.lexerActionIndex = firstConfigWithRuleStopState.GetActionIndex();
newState.lexerRuleIndex = firstConfigWithRuleStopState.State.ruleIndex;
newState.lexerActionIndex = firstConfigWithRuleStopState.ActionIndex;
newState.prediction = atn.ruleToTokenType[newState.lexerRuleIndex];
}
return atn.modeToDFA[mode].AddState(newState);

View File

@ -204,7 +204,8 @@ namespace Antlr4.Runtime.Atn
public const bool retry_debug = false;
private PredictionMode predictionMode = PredictionMode.Ll;
private Antlr4.Runtime.Atn.PredictionMode predictionMode = Antlr4.Runtime.Atn.PredictionMode
.Ll;
public bool force_global_context = false;
@ -273,15 +274,17 @@ namespace Antlr4.Runtime.Atn
this.parser = parser;
}
[NotNull]
public PredictionMode GetPredictionMode()
public Antlr4.Runtime.Atn.PredictionMode PredictionMode
{
return predictionMode;
}
public void SetPredictionMode(PredictionMode predictionMode)
{
this.predictionMode = predictionMode;
get
{
return predictionMode;
}
set
{
Antlr4.Runtime.Atn.PredictionMode predictionMode = value;
this.predictionMode = predictionMode;
}
}
public override void Reset()
@ -323,8 +326,8 @@ namespace Antlr4.Runtime.Atn
useContext |= dfa != null && dfa.IsContextSensitive();
}
}
userWantsCtxSensitive = useContext || (predictionMode != PredictionMode.Sll && outerContext
!= null && !atn.decisionToState[decision].sll);
userWantsCtxSensitive = useContext || (predictionMode != Antlr4.Runtime.Atn.PredictionMode
.Sll && outerContext != null && !atn.decisionToState[decision].sll);
if (outerContext == null)
{
outerContext = ParserRuleContext.EmptyContext;
@ -575,7 +578,7 @@ namespace Antlr4.Runtime.Atn
input.Seek(startIndex);
}
BitSet alts = EvalSemanticContext(s.predicates, outerContext, reportAmbiguities &&
predictionMode == PredictionMode.LlExactAmbigDetection);
predictionMode == Antlr4.Runtime.Atn.PredictionMode.LlExactAmbigDetection);
switch (alts.Cardinality())
{
case 0:
@ -755,7 +758,7 @@ namespace Antlr4.Runtime.Atn
input.Seek(startIndex);
}
BitSet alts = EvalSemanticContext(D.predicates, outerContext, reportAmbiguities &&
predictionMode == PredictionMode.LlExactAmbigDetection);
predictionMode == Antlr4.Runtime.Atn.PredictionMode.LlExactAmbigDetection);
D.prediction = ATN.InvalidAltNumber;
switch (alts.Cardinality())
{
@ -802,9 +805,9 @@ namespace Antlr4.Runtime.Atn
BitSet alts = new BitSet();
foreach (ATNConfig config in previous.s0.configs)
{
if (config.GetReachesIntoOuterContext() || config.GetState() is RuleStopState)
if (config.ReachesIntoOuterContext || config.State is RuleStopState)
{
alts.Set(config.GetAlt());
alts.Set(config.Alt);
}
}
if (!alts.IsEmpty())
@ -867,10 +870,10 @@ namespace Antlr4.Runtime.Atn
IList<ATNConfig> skippedStopStates = null;
foreach (ATNConfig c in closureConfigs)
{
if (c.GetState() is RuleStopState)
if (c.State is RuleStopState)
{
System.Diagnostics.Debug.Assert(c.GetContext().IsEmpty);
if (useContext && !c.GetReachesIntoOuterContext() || t == IntStreamConstants.Eof)
System.Diagnostics.Debug.Assert(c.Context.IsEmpty);
if (useContext && !c.ReachesIntoOuterContext || t == IntStreamConstants.Eof)
{
if (skippedStopStates == null)
{
@ -880,11 +883,11 @@ namespace Antlr4.Runtime.Atn
}
continue;
}
int n = c.GetState().NumberOfOptimizedTransitions;
int n = c.State.NumberOfOptimizedTransitions;
for (int ti = 0; ti < n; ti++)
{
// for each optimized transition
Transition trans = c.GetState().GetOptimizedTransition(ti);
Transition trans = c.State.GetOptimizedTransition(ti);
ATNState target = GetReachableTarget(c, trans, t);
if (target != null)
{
@ -907,8 +910,8 @@ namespace Antlr4.Runtime.Atn
{
reach = RemoveAllConfigsNotInRuleStopState(reach, contextCache);
}
if (skippedStopStates != null && (!useContext || !PredictionMode.HasConfigInRuleStopState
(reach)))
if (skippedStopStates != null && (!useContext || !Antlr4.Runtime.Atn.PredictionMode
.HasConfigInRuleStopState(reach)))
{
System.Diagnostics.Debug.Assert(!skippedStopStates.IsEmpty());
foreach (ATNConfig c_1 in skippedStopStates)
@ -994,14 +997,14 @@ namespace Antlr4.Runtime.Atn
protected internal virtual ATNConfigSet RemoveAllConfigsNotInRuleStopState(ATNConfigSet
configs, PredictionContextCache contextCache)
{
if (PredictionMode.AllConfigsInRuleStopStates(configs))
if (Antlr4.Runtime.Atn.PredictionMode.AllConfigsInRuleStopStates(configs))
{
return configs;
}
ATNConfigSet result = new ATNConfigSet();
foreach (ATNConfig config in configs)
{
if (!(config.GetState() is RuleStopState))
if (!(config.State is RuleStopState))
{
continue;
}
@ -1161,10 +1164,9 @@ namespace Antlr4.Runtime.Atn
int n = altToPred.Length;
foreach (ATNConfig c in configs)
{
if (ambigAlts.Get(c.GetAlt()))
if (ambigAlts.Get(c.Alt))
{
altToPred[c.GetAlt()] = SemanticContext.Or(altToPred[c.GetAlt()], c.GetSemanticContext
());
altToPred[c.Alt] = SemanticContext.Or(altToPred[c.Alt], c.SemanticContext);
}
}
int nPredAlts = 0;
@ -1309,26 +1311,26 @@ namespace Antlr4.Runtime.Atn
return;
}
// avoid infinite recursion
if (config.GetState() is RuleStopState)
if (config.State is RuleStopState)
{
// We hit rule end. If we have context info, use it
if (!config.GetContext().IsEmpty)
if (!config.Context.IsEmpty)
{
bool hasEmpty = config.GetContext().HasEmpty;
int nonEmptySize = config.GetContext().Size - (hasEmpty ? 1 : 0);
bool hasEmpty = config.Context.HasEmpty;
int nonEmptySize = config.Context.Size - (hasEmpty ? 1 : 0);
for (int i = 0; i < nonEmptySize; i++)
{
PredictionContext newContext = config.GetContext().GetParent(i);
PredictionContext newContext = config.Context.GetParent(i);
// "pop" return state
ATNState returnState = atn.states[config.GetContext().GetReturnState(i)];
ATNConfig c = ATNConfig.Create(returnState, config.GetAlt(), newContext, config.GetSemanticContext
());
ATNState returnState = atn.states[config.Context.GetReturnState(i)];
ATNConfig c = ATNConfig.Create(returnState, config.Alt, newContext, config.SemanticContext
);
// While we have context to pop back from, we may have
// gotten that context AFTER having fallen off a rule.
// Make sure we track that we are now out of context.
c.SetOuterContextDepth(config.GetOuterContextDepth());
c.OuterContextDepth = config.OuterContextDepth;
System.Diagnostics.Debug.Assert(depth > int.MinValue);
if (optimize_closure_busy && c.GetContext().IsEmpty && !closureBusy.AddItem(c))
if (optimize_closure_busy && c.Context.IsEmpty && !closureBusy.AddItem(c))
{
continue;
}
@ -1339,7 +1341,7 @@ namespace Antlr4.Runtime.Atn
{
return;
}
config = config.Transform(config.GetState(), PredictionContext.EmptyLocal);
config = config.Transform(config.State, PredictionContext.EmptyLocal);
}
else
{
@ -1351,15 +1353,15 @@ namespace Antlr4.Runtime.Atn
else
{
// else if we have no context info, just chase follow links (if greedy)
if (config.GetContext() == PredictionContext.EmptyFull)
if (config.Context == PredictionContext.EmptyFull)
{
// no need to keep full context overhead when we step out
config = config.Transform(config.GetState(), PredictionContext.EmptyLocal);
config = config.Transform(config.State, PredictionContext.EmptyLocal);
}
}
}
}
ATNState p = config.GetState();
ATNState p = config.State;
// optimization
if (!p.OnlyHasEpsilonTransitions)
{
@ -1384,7 +1386,7 @@ namespace Antlr4.Runtime.Atn
if (optimize_closure_busy)
{
bool checkClosure = false;
switch (c.GetState().StateType)
switch (c.State.StateType)
{
case StateType.StarLoopEntry:
case StateType.BlockEnd:
@ -1402,7 +1404,7 @@ namespace Antlr4.Runtime.Atn
case StateType.RuleStop:
{
checkClosure = c.GetContext().IsEmpty;
checkClosure = c.Context.IsEmpty;
break;
}
@ -1418,14 +1420,14 @@ namespace Antlr4.Runtime.Atn
}
}
int newDepth = depth;
if (config.GetState() is RuleStopState)
if (config.State is RuleStopState)
{
// target fell off end of rule; mark resulting c as having dipped into outer context
// We can't get here if incoming config was rule stop and we had context
// track how far we dip into outer context. Might
// come in handy and we avoid evaluating context dependent
// preds if this is > 0.
c.SetOuterContextDepth(c.GetOuterContextDepth() + 1);
c.OuterContextDepth = c.OuterContextDepth + 1;
System.Diagnostics.Debug.Assert(newDepth > int.MinValue);
newDepth--;
}
@ -1434,20 +1436,19 @@ namespace Antlr4.Runtime.Atn
if (t is Antlr4.Runtime.Atn.RuleTransition)
{
if (optimize_tail_calls && ((Antlr4.Runtime.Atn.RuleTransition)t).optimizedTailCall
&& (!tail_call_preserves_sll || !PredictionContext.IsEmptyLocal(config.GetContext
())))
&& (!tail_call_preserves_sll || !PredictionContext.IsEmptyLocal(config.Context
)))
{
System.Diagnostics.Debug.Assert(c.GetContext() == config.GetContext());
System.Diagnostics.Debug.Assert(c.Context == config.Context);
if (newDepth == 0)
{
// the pop/push of a tail call would keep the depth
// constant, except we latch if it goes negative
newDepth--;
if (!tail_call_preserves_sll && PredictionContext.IsEmptyLocal(config.GetContext(
)))
if (!tail_call_preserves_sll && PredictionContext.IsEmptyLocal(config.Context))
{
// make sure the SLL config "dips into the outer context" or prediction may not fall back to LL on conflict
c.SetOuterContextDepth(c.GetOuterContextDepth() + 1);
c.OuterContextDepth = c.OuterContextDepth + 1;
}
}
}
@ -1532,7 +1533,7 @@ namespace Antlr4.Runtime.Atn
ATNConfig c = null;
if (collectPredicates && inContext)
{
SemanticContext newSemCtx = SemanticContext.And(config.GetSemanticContext(), pt.GetPredicate
SemanticContext newSemCtx = SemanticContext.And(config.SemanticContext, pt.GetPredicate
());
c = config.Transform(pt.target, newSemCtx);
}
@ -1550,7 +1551,7 @@ namespace Antlr4.Runtime.Atn
ATNConfig c;
if (collectPredicates && (!pt.isCtxDependent || (pt.isCtxDependent && inContext)))
{
SemanticContext newSemCtx = SemanticContext.And(config.GetSemanticContext(), pt.GetPredicate
SemanticContext newSemCtx = SemanticContext.And(config.SemanticContext, pt.GetPredicate
());
c = config.Transform(pt.target, newSemCtx);
}
@ -1568,38 +1569,38 @@ namespace Antlr4.Runtime.Atn
ATNState returnState = t.followState;
PredictionContext newContext;
if (optimize_tail_calls && t.optimizedTailCall && (!tail_call_preserves_sll || !PredictionContext
.IsEmptyLocal(config.GetContext())))
.IsEmptyLocal(config.Context)))
{
newContext = config.GetContext();
newContext = config.Context;
}
else
{
if (contextCache != null)
{
newContext = contextCache.GetChild(config.GetContext(), returnState.stateNumber);
newContext = contextCache.GetChild(config.Context, returnState.stateNumber);
}
else
{
newContext = config.GetContext().GetChild(returnState.stateNumber);
newContext = config.Context.GetChild(returnState.stateNumber);
}
}
return config.Transform(t.target, newContext);
}
private sealed class _IComparer_1557 : IComparer<ATNConfig>
private sealed class _IComparer_1563 : IComparer<ATNConfig>
{
public _IComparer_1557()
public _IComparer_1563()
{
}
public int Compare(ATNConfig o1, ATNConfig o2)
{
int diff = o1.GetState().NonStopStateNumber - o2.GetState().NonStopStateNumber;
int diff = o1.State.NonStopStateNumber - o2.State.NonStopStateNumber;
if (diff != 0)
{
return diff;
}
diff = o1.GetAlt() - o2.GetAlt();
diff = o1.Alt - o2.Alt;
if (diff != 0)
{
return diff;
@ -1608,7 +1609,7 @@ namespace Antlr4.Runtime.Atn
}
}
private static readonly IComparer<ATNConfig> StateAltSortComparator = new _IComparer_1557
private static readonly IComparer<ATNConfig> StateAltSortComparator = new _IComparer_1563
();
private BitSet IsConflicted(ATNConfigSet configset, PredictionContextCache contextCache
@ -1620,22 +1621,22 @@ namespace Antlr4.Runtime.Atn
}
IList<ATNConfig> configs = new List<ATNConfig>(configset);
configs.Sort(StateAltSortComparator);
bool exact = !configset.DipsIntoOuterContext && predictionMode == PredictionMode.
LlExactAmbigDetection;
bool exact = !configset.DipsIntoOuterContext && predictionMode == Antlr4.Runtime.Atn.PredictionMode
.LlExactAmbigDetection;
BitSet alts = new BitSet();
int minAlt = configs[0].GetAlt();
int minAlt = configs[0].Alt;
alts.Set(minAlt);
// quick check 1 & 2 => if we assume #1 holds and check #2 against the
// minAlt from the first state, #2 will fail if the assumption was
// incorrect
int currentState = configs[0].GetState().NonStopStateNumber;
int currentState = configs[0].State.NonStopStateNumber;
for (int i = 0; i < configs.Count; i++)
{
ATNConfig config = configs[i];
int stateNumber = config.GetState().NonStopStateNumber;
int stateNumber = config.State.NonStopStateNumber;
if (stateNumber != currentState)
{
if (config.GetAlt() != minAlt)
if (config.Alt != minAlt)
{
return null;
}
@ -1645,29 +1646,29 @@ namespace Antlr4.Runtime.Atn
BitSet representedAlts = null;
if (exact)
{
currentState = configs[0].GetState().NonStopStateNumber;
currentState = configs[0].State.NonStopStateNumber;
// get the represented alternatives of the first state
representedAlts = new BitSet();
int maxAlt = minAlt;
for (int i_1 = 0; i_1 < configs.Count; i_1++)
{
ATNConfig config = configs[i_1];
if (config.GetState().NonStopStateNumber != currentState)
if (config.State.NonStopStateNumber != currentState)
{
break;
}
int alt = config.GetAlt();
int alt = config.Alt;
representedAlts.Set(alt);
maxAlt = alt;
}
// quick check #3:
currentState = configs[0].GetState().NonStopStateNumber;
currentState = configs[0].State.NonStopStateNumber;
int currentAlt = minAlt;
for (int i_2 = 0; i_2 < configs.Count; i_2++)
{
ATNConfig config = configs[i_2];
int stateNumber = config.GetState().NonStopStateNumber;
int alt = config.GetAlt();
int stateNumber = config.State.NonStopStateNumber;
int alt = config.Alt;
if (stateNumber != currentState)
{
if (currentAlt != maxAlt)
@ -1690,70 +1691,68 @@ namespace Antlr4.Runtime.Atn
}
}
}
currentState = configs[0].GetState().NonStopStateNumber;
currentState = configs[0].State.NonStopStateNumber;
int firstIndexCurrentState = 0;
int lastIndexCurrentStateMinAlt = 0;
PredictionContext joinedCheckContext = configs[0].GetContext();
PredictionContext joinedCheckContext = configs[0].Context;
for (int i_3 = 1; i_3 < configs.Count; i_3++)
{
ATNConfig config = configs[i_3];
if (config.GetAlt() != minAlt)
if (config.Alt != minAlt)
{
break;
}
if (config.GetState().NonStopStateNumber != currentState)
if (config.State.NonStopStateNumber != currentState)
{
break;
}
lastIndexCurrentStateMinAlt = i_3;
joinedCheckContext = contextCache.Join(joinedCheckContext, configs[i_3].GetContext
());
joinedCheckContext = contextCache.Join(joinedCheckContext, configs[i_3].Context);
}
for (int i_4 = lastIndexCurrentStateMinAlt + 1; i_4 < configs.Count; i_4++)
{
ATNConfig config = configs[i_4];
ATNState state = config.GetState();
alts.Set(config.GetAlt());
ATNState state = config.State;
alts.Set(config.Alt);
if (state.NonStopStateNumber != currentState)
{
currentState = state.NonStopStateNumber;
firstIndexCurrentState = i_4;
lastIndexCurrentStateMinAlt = i_4;
joinedCheckContext = config.GetContext();
joinedCheckContext = config.Context;
for (int j = firstIndexCurrentState + 1; j < configs.Count; j++)
{
ATNConfig config2 = configs[j];
if (config2.GetAlt() != minAlt)
if (config2.Alt != minAlt)
{
break;
}
if (config2.GetState().NonStopStateNumber != currentState)
if (config2.State.NonStopStateNumber != currentState)
{
break;
}
lastIndexCurrentStateMinAlt = j;
joinedCheckContext = contextCache.Join(joinedCheckContext, config2.GetContext());
joinedCheckContext = contextCache.Join(joinedCheckContext, config2.Context);
}
i_4 = lastIndexCurrentStateMinAlt;
continue;
}
PredictionContext joinedCheckContext2 = config.GetContext();
int currentAlt = config.GetAlt();
PredictionContext joinedCheckContext2 = config.Context;
int currentAlt = config.Alt;
int lastIndexCurrentStateCurrentAlt = i_4;
for (int j_1 = lastIndexCurrentStateCurrentAlt + 1; j_1 < configs.Count; j_1++)
{
ATNConfig config2 = configs[j_1];
if (config2.GetAlt() != currentAlt)
if (config2.Alt != currentAlt)
{
break;
}
if (config2.GetState().NonStopStateNumber != currentState)
if (config2.State.NonStopStateNumber != currentState)
{
break;
}
lastIndexCurrentStateCurrentAlt = j_1;
joinedCheckContext2 = contextCache.Join(joinedCheckContext2, config2.GetContext()
);
joinedCheckContext2 = contextCache.Join(joinedCheckContext2, config2.Context);
}
i_4 = lastIndexCurrentStateCurrentAlt;
if (exact)
@ -1777,21 +1776,20 @@ namespace Antlr4.Runtime.Atn
for (int j = firstIndexCurrentState; j_1 <= lastIndexCurrentStateMinAlt; j_1++)
{
ATNConfig checkConfig = configs[j_1];
if (checkConfig.GetSemanticContext() != SemanticContext.None && !checkConfig.GetSemanticContext
().Equals(config.GetSemanticContext()))
if (checkConfig.SemanticContext != SemanticContext.None && !checkConfig.SemanticContext
.Equals(config.SemanticContext))
{
continue;
}
if (joinedCheckContext != checkConfig.GetContext())
if (joinedCheckContext != checkConfig.Context)
{
PredictionContext check = contextCache.Join(checkConfig.GetContext(), config.GetContext
());
if (!checkConfig.GetContext().Equals(check))
PredictionContext check = contextCache.Join(checkConfig.Context, config.Context);
if (!checkConfig.Context.Equals(check))
{
continue;
}
}
config.SetHidden(true);
config.IsHidden = true;
}
}
}
@ -1855,9 +1853,9 @@ namespace Antlr4.Runtime.Atn
foreach (ATNConfig c in nvae.GetDeadEndConfigs())
{
string trans = "no edges";
if (c.GetState().NumberOfOptimizedTransitions > 0)
if (c.State.NumberOfOptimizedTransitions > 0)
{
Transition t = c.GetState().GetOptimizedTransition(0);
Transition t = c.State.GetOptimizedTransition(0);
if (t is AtomTransition)
{
AtomTransition at = (AtomTransition)t;
@ -1885,19 +1883,19 @@ namespace Antlr4.Runtime.Atn
, configs, outerContext);
}
public virtual int GetUniqueAlt(ICollection<ATNConfig> configs)
public virtual int GetUniqueAlt(IEnumerable<ATNConfig> configs)
{
int alt = ATN.InvalidAltNumber;
foreach (ATNConfig c in configs)
{
if (alt == ATN.InvalidAltNumber)
{
alt = c.GetAlt();
alt = c.Alt;
}
else
{
// found first alt
if (c.GetAlt() != alt)
if (c.Alt != alt)
{
return ATN.InvalidAltNumber;
}
@ -1906,14 +1904,14 @@ namespace Antlr4.Runtime.Atn
return alt;
}
public virtual bool ConfigWithAltAtStopState(ICollection<ATNConfig> configs, int
public virtual bool ConfigWithAltAtStopState(IEnumerable<ATNConfig> configs, int
alt)
{
foreach (ATNConfig c in configs)
{
if (c.GetAlt() == alt)
if (c.Alt == alt)
{
if (c.GetState() is RuleStopState)
if (c.State is RuleStopState)
{
return true;
}

View File

@ -98,8 +98,8 @@ namespace Antlr4.Runtime.Atn
public override int GetHashCode(ATNConfig o)
{
int hashCode = 7;
hashCode = 31 * hashCode + o.GetState().stateNumber;
hashCode = 31 * hashCode + o.GetContext().GetHashCode();
hashCode = 31 * hashCode + o.State.stateNumber;
hashCode = 31 * hashCode + o.Context.GetHashCode();
return hashCode;
}
@ -117,8 +117,7 @@ namespace Antlr4.Runtime.Atn
{
return false;
}
return a.GetState().stateNumber == b.GetState().stateNumber && a.GetContext().Equals
(b.GetContext());
return a.State.stateNumber == b.State.stateNumber && a.Context.Equals(b.Context);
}
}
@ -259,7 +258,7 @@ namespace Antlr4.Runtime.Atn
ATNConfigSet dup = new ATNConfigSet();
foreach (ATNConfig c in configs)
{
c = c.Transform(c.GetState(), SemanticContext.None);
c = c.Transform(c.State, SemanticContext.None);
dup.AddItem(c);
}
configs = dup;
@ -293,11 +292,11 @@ namespace Antlr4.Runtime.Atn
/// , otherwise
/// <code>false</code>
/// </returns>
public static bool HasConfigInRuleStopState(ATNConfigSet configs)
public static bool HasConfigInRuleStopState(IEnumerable<ATNConfig> configs)
{
foreach (ATNConfig c in configs)
{
if (c.GetState() is RuleStopState)
if (c.State is RuleStopState)
{
return true;
}
@ -325,11 +324,11 @@ namespace Antlr4.Runtime.Atn
/// , otherwise
/// <code>false</code>
/// </returns>
public static bool AllConfigsInRuleStopStates(ATNConfigSet configs)
public static bool AllConfigsInRuleStopStates(IEnumerable<ATNConfig> configs)
{
foreach (ATNConfig config in configs)
{
if (!(config.GetState() is RuleStopState))
if (!(config.State is RuleStopState))
{
return false;
}
@ -363,7 +362,7 @@ namespace Antlr4.Runtime.Atn
/// <see cref="ATNConfig#context">ATNConfig#context</see>
/// values
/// but different
/// <see cref="ATNConfig.GetAlt()">ATNConfig.GetAlt()</see>
/// <see cref="ATNConfig.Alt()">ATNConfig.Alt()</see>
/// value, e.g.
/// <code>(s, i, ctx, _)</code>
/// and
@ -392,7 +391,7 @@ namespace Antlr4.Runtime.Atn
/// :
/// <pre>
/// map[c] U= c.
/// <see cref="ATNConfig.GetAlt()">getAlt()</see>
/// <see cref="ATNConfig.Alt()">getAlt()</see>
/// # map hash/equals uses s and x, not
/// alt and not pred
/// </pre>
@ -644,7 +643,7 @@ namespace Antlr4.Runtime.Atn
///
/// {1,2},{1,2}}}, etc...
/// </remarks>
public static int ResolvesToJustOneViableAlt(ICollection<BitSet> altsets)
public static int ResolvesToJustOneViableAlt(IEnumerable<BitSet> altsets)
{
return GetSingleViableAlt(altsets);
}
@ -668,7 +667,7 @@ namespace Antlr4.Runtime.Atn
/// &gt; 1, otherwise
/// <code>false</code>
/// </returns>
public static bool AllSubsetsConflict(ICollection<BitSet> altsets)
public static bool AllSubsetsConflict(IEnumerable<BitSet> altsets)
{
return !HasNonConflictingAltSet(altsets);
}
@ -692,7 +691,7 @@ namespace Antlr4.Runtime.Atn
/// 1, otherwise
/// <code>false</code>
/// </returns>
public static bool HasNonConflictingAltSet(ICollection<BitSet> altsets)
public static bool HasNonConflictingAltSet(IEnumerable<BitSet> altsets)
{
foreach (BitSet alts in altsets)
{
@ -723,7 +722,7 @@ namespace Antlr4.Runtime.Atn
/// &gt; 1, otherwise
/// <code>false</code>
/// </returns>
public static bool HasConflictingAltSet(ICollection<BitSet> altsets)
public static bool HasConflictingAltSet(IEnumerable<BitSet> altsets)
{
foreach (BitSet alts in altsets)
{
@ -750,7 +749,7 @@ namespace Antlr4.Runtime.Atn
/// others, otherwise
/// <code>false</code>
/// </returns>
public static bool AllSubsetsEqual(ICollection<BitSet> altsets)
public static bool AllSubsetsEqual(IEnumerable<BitSet> altsets)
{
IEnumerator<BitSet> it = altsets.GetEnumerator();
BitSet first = it.Next();
@ -773,7 +772,7 @@ namespace Antlr4.Runtime.Atn
/// .
/// </summary>
/// <param name="altsets">a collection of alternative subsets</param>
public static int GetUniqueAlt(ICollection<BitSet> altsets)
public static int GetUniqueAlt(IEnumerable<BitSet> altsets)
{
BitSet all = GetAlts(altsets);
if (all.Cardinality() == 1)
@ -800,7 +799,7 @@ namespace Antlr4.Runtime.Atn
/// the set of represented alternatives in
/// <code>altsets</code>
/// </returns>
public static BitSet GetAlts(ICollection<BitSet> altsets)
public static BitSet GetAlts(IEnumerable<BitSet> altsets)
{
BitSet all = new BitSet();
foreach (BitSet alts in altsets)
@ -821,13 +820,14 @@ namespace Antlr4.Runtime.Atn
/// :
/// <pre>
/// map[c] U= c.
/// <see cref="ATNConfig.GetAlt()">getAlt()</see>
/// <see cref="ATNConfig.Alt()">getAlt()</see>
/// # map hash/equals uses s and x, not
/// alt and not pred
/// </pre>
/// </remarks>
[NotNull]
public static ICollection<BitSet> GetConflictingAltSubsets(ATNConfigSet configs)
public static ICollection<BitSet> GetConflictingAltSubsets(IEnumerable<ATNConfig>
configs)
{
PredictionMode.AltAndContextMap configToAlts = new PredictionMode.AltAndContextMap
();
@ -839,7 +839,7 @@ namespace Antlr4.Runtime.Atn
alts = new BitSet();
configToAlts.Put(c, alts);
}
alts.Set(c.GetAlt());
alts.Set(c.Alt);
}
return configToAlts.Values;
}
@ -856,28 +856,28 @@ namespace Antlr4.Runtime.Atn
/// map[c.
/// <see cref="ATNConfig#state">state</see>
/// ] U= c.
/// <see cref="ATNConfig.GetAlt()">getAlt()</see>
/// <see cref="ATNConfig.Alt()">getAlt()</see>
/// </pre>
/// </remarks>
[NotNull]
public static IDictionary<ATNState, BitSet> GetStateToAltMap(ATNConfigSet configs
)
public static IDictionary<ATNState, BitSet> GetStateToAltMap(IEnumerable<ATNConfig
> configs)
{
IDictionary<ATNState, BitSet> m = new Dictionary<ATNState, BitSet>();
foreach (ATNConfig c in configs)
{
BitSet alts = m.Get(c.GetState());
BitSet alts = m.Get(c.State);
if (alts == null)
{
alts = new BitSet();
m.Put(c.GetState(), alts);
m.Put(c.State, alts);
}
alts.Set(c.GetAlt());
alts.Set(c.Alt);
}
return m;
}
public static bool HasStateAssociatedWithOneAlt(ATNConfigSet configs)
public static bool HasStateAssociatedWithOneAlt(IEnumerable<ATNConfig> configs)
{
IDictionary<ATNState, BitSet> x = GetStateToAltMap(configs);
foreach (BitSet alts in x.Values)
@ -890,7 +890,7 @@ namespace Antlr4.Runtime.Atn
return false;
}
public static int GetSingleViableAlt(ICollection<BitSet> altsets)
public static int GetSingleViableAlt(IEnumerable<BitSet> altsets)
{
BitSet viableAlts = new BitSet();
foreach (BitSet alts in altsets)

View File

@ -209,7 +209,7 @@ namespace Antlr4.Runtime.Dfa
stateStr += "*";
foreach (ATNConfig config in s.configs)
{
if (config.GetReachesIntoOuterContext())
if (config.ReachesIntoOuterContext)
{
stateStr += "*";
break;

View File

@ -283,7 +283,7 @@ namespace Antlr4.Runtime.Misc
if (diagnostics)
{
parser.AddErrorListener(new DiagnosticErrorListener());
parser.Interpreter.SetPredictionMode(PredictionMode.LlExactAmbigDetection);
parser.Interpreter.PredictionMode = PredictionMode.LlExactAmbigDetection;
}
if (printTree || gui || psFile != null)
{
@ -292,7 +292,7 @@ namespace Antlr4.Runtime.Misc
if (Sll)
{
// overrides diagnostics
parser.Interpreter.SetPredictionMode(PredictionMode.Sll);
parser.Interpreter.PredictionMode = PredictionMode.Sll;
}
parser.SetInputStream(tokens);
parser.Trace = trace;

View File

@ -36,17 +36,19 @@ namespace Antlr4.Runtime
/// <author>Sam Harwell</author>
public class ProxyErrorListener<Symbol> : IAntlrErrorListener<Symbol>
{
private readonly ICollection<IAntlrErrorListener<Symbol>> delegates;
private readonly IEnumerable<IAntlrErrorListener<Symbol>> delegates;
public ProxyErrorListener(ICollection<IAntlrErrorListener<Symbol>> delegates)
public ProxyErrorListener(IEnumerable<IAntlrErrorListener<Symbol>> delegates)
{
this.delegates = delegates;
}
protected internal virtual ICollection<IAntlrErrorListener<Symbol>> GetDelegates(
)
protected internal virtual IEnumerable<IAntlrErrorListener<Symbol>> Delegates
{
return delegates;
get
{
return delegates;
}
}
public virtual void SyntaxError<T>(Recognizer<T, object> recognizer, T offendingSymbol

View File

@ -46,7 +46,7 @@ namespace Antlr4.Runtime
public virtual void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int
stopIndex, BitSet ambigAlts, ATNConfigSet configs)
{
foreach (IAntlrErrorListener<IToken> listener in GetDelegates())
foreach (IAntlrErrorListener<IToken> listener in Delegates)
{
if (!(listener is IParserErrorListener))
{
@ -61,7 +61,7 @@ namespace Antlr4.Runtime
public virtual void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex
, int stopIndex, SimulatorState initialState)
{
foreach (IAntlrErrorListener<IToken> listener in GetDelegates())
foreach (IAntlrErrorListener<IToken> listener in Delegates)
{
if (!(listener is IParserErrorListener))
{
@ -76,7 +76,7 @@ namespace Antlr4.Runtime
public virtual void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex
, int stopIndex, SimulatorState acceptState)
{
foreach (IAntlrErrorListener<IToken> listener in GetDelegates())
foreach (IAntlrErrorListener<IToken> listener in Delegates)
{
if (!(listener is IParserErrorListener))
{

@ -1 +1 @@
Subproject commit e4d1c14c8df3f27105e3bbf935d49f500bc3552e
Subproject commit 7e785daa65e15f9786218e5dd63ea5a3cecf67a8