Add the StateType and TransitionType enumerations; more properties

This commit is contained in:
Sam Harwell 2013-02-16 14:09:40 -06:00
parent a47fde57b2
commit e0044cc4dd
34 changed files with 383 additions and 270 deletions

View File

@ -82,8 +82,10 @@
<Compile Include="Atn\StarBlockStartState.cs" /> <Compile Include="Atn\StarBlockStartState.cs" />
<Compile Include="Atn\StarLoopbackState.cs" /> <Compile Include="Atn\StarLoopbackState.cs" />
<Compile Include="Atn\StarLoopEntryState.cs" /> <Compile Include="Atn\StarLoopEntryState.cs" />
<Compile Include="Atn\StateType.cs" />
<Compile Include="Atn\TokensStartState.cs" /> <Compile Include="Atn\TokensStartState.cs" />
<Compile Include="Atn\Transition.cs" /> <Compile Include="Atn\Transition.cs" />
<Compile Include="Atn\TransitionType.cs" />
<Compile Include="Atn\WildcardTransition.cs" /> <Compile Include="Atn\WildcardTransition.cs" />
<Compile Include="BailErrorStrategy.cs" /> <Compile Include="BailErrorStrategy.cs" />
<Compile Include="BaseErrorListener.cs" /> <Compile Include="BaseErrorListener.cs" />

View File

@ -109,16 +109,16 @@ namespace Antlr4.Runtime.Atn
int nstates = ToInt(data[p++]); int nstates = ToInt(data[p++]);
for (int i_1 = 1; i_1 <= nstates; i_1++) for (int i_1 = 1; i_1 <= nstates; i_1++)
{ {
int stype = ToInt(data[p++]); StateType stype = StateType.Values()[ToInt(data[p++])];
// ignore bad type of states // ignore bad type of states
if (stype == ATNState.InvalidType) if (stype == StateType.InvalidType)
{ {
atn.AddState(null); atn.AddState(null);
continue; continue;
} }
int ruleIndex = ToInt(data[p++]); int ruleIndex = ToInt(data[p++]);
ATNState s = StateFactory(stype, ruleIndex); ATNState s = StateFactory(stype, ruleIndex);
if (stype == ATNState.LoopEnd) if (stype == StateType.LoopEnd)
{ {
// special case // special case
int loopBackStateNumber = ToInt(data[p++]); int loopBackStateNumber = ToInt(data[p++]);
@ -234,7 +234,7 @@ namespace Antlr4.Runtime.Atn
{ {
int src = ToInt(data[p]); int src = ToInt(data[p]);
int trg = ToInt(data[p + 1]); int trg = ToInt(data[p + 1]);
int ttype = ToInt(data[p + 2]); TransitionType ttype = TransitionType.Values()[ToInt(data[p + 2])];
int arg1 = ToInt(data[p + 3]); int arg1 = ToInt(data[p + 3]);
int arg2 = ToInt(data[p + 4]); int arg2 = ToInt(data[p + 4]);
int arg3 = ToInt(data[p + 5]); int arg3 = ToInt(data[p + 5]);
@ -252,7 +252,7 @@ namespace Antlr4.Runtime.Atn
{ {
bool returningToLeftFactored = state_1.ruleIndex >= 0 && atn.ruleToStartState[state_1 bool returningToLeftFactored = state_1.ruleIndex >= 0 && atn.ruleToStartState[state_1
.ruleIndex].leftFactored; .ruleIndex].leftFactored;
for (int i_10 = 0; i_10 < state_1.GetNumberOfTransitions(); i_10++) for (int i_10 = 0; i_10 < state_1.NumberOfTransitions; i_10++)
{ {
Transition t = state_1.Transition(i_10); Transition t = state_1.Transition(i_10);
if (!(t is RuleTransition)) if (!(t is RuleTransition))
@ -289,7 +289,7 @@ namespace Antlr4.Runtime.Atn
if (state_2 is PlusLoopbackState) if (state_2 is PlusLoopbackState)
{ {
PlusLoopbackState loopbackState = (PlusLoopbackState)state_2; PlusLoopbackState loopbackState = (PlusLoopbackState)state_2;
for (int i_10 = 0; i_10 < loopbackState.GetNumberOfTransitions(); i_10++) for (int i_10 = 0; i_10 < loopbackState.NumberOfTransitions; i_10++)
{ {
ATNState target = loopbackState.Transition(i_10).target; ATNState target = loopbackState.Transition(i_10).target;
if (target is PlusBlockStartState) if (target is PlusBlockStartState)
@ -303,7 +303,7 @@ namespace Antlr4.Runtime.Atn
if (state_2 is StarLoopbackState) if (state_2 is StarLoopbackState)
{ {
StarLoopbackState loopbackState = (StarLoopbackState)state_2; StarLoopbackState loopbackState = (StarLoopbackState)state_2;
for (int i_10 = 0; i_10 < loopbackState.GetNumberOfTransitions(); i_10++) for (int i_10 = 0; i_10 < loopbackState.NumberOfTransitions; i_10++)
{ {
ATNState target = loopbackState.Transition(i_10).target; ATNState target = loopbackState.Transition(i_10).target;
if (target is StarLoopEntryState) if (target is StarLoopEntryState)
@ -359,8 +359,7 @@ namespace Antlr4.Runtime.Atn
{ {
continue; continue;
} }
CheckCondition(state.OnlyHasEpsilonTransitions() || state.GetNumberOfTransitions( CheckCondition(state.OnlyHasEpsilonTransitions || state.NumberOfTransitions <= 1);
) <= 1);
if (state is PlusBlockStartState) if (state is PlusBlockStartState)
{ {
CheckCondition(((PlusBlockStartState)state).loopBackState != null); CheckCondition(((PlusBlockStartState)state).loopBackState != null);
@ -369,7 +368,7 @@ namespace Antlr4.Runtime.Atn
{ {
StarLoopEntryState starLoopEntryState = (StarLoopEntryState)state; StarLoopEntryState starLoopEntryState = (StarLoopEntryState)state;
CheckCondition(starLoopEntryState.loopBackState != null); CheckCondition(starLoopEntryState.loopBackState != null);
CheckCondition(starLoopEntryState.GetNumberOfTransitions() == 2); CheckCondition(starLoopEntryState.NumberOfTransitions == 2);
if (starLoopEntryState.Transition(0).target is StarBlockStartState) if (starLoopEntryState.Transition(0).target is StarBlockStartState)
{ {
CheckCondition(starLoopEntryState.Transition(1).target is LoopEndState); CheckCondition(starLoopEntryState.Transition(1).target is LoopEndState);
@ -390,7 +389,7 @@ namespace Antlr4.Runtime.Atn
} }
if (state is StarLoopbackState) if (state is StarLoopbackState)
{ {
CheckCondition(state.GetNumberOfTransitions() == 1); CheckCondition(state.NumberOfTransitions == 1);
CheckCondition(state.Transition(0).target is StarLoopEntryState); CheckCondition(state.Transition(0).target is StarLoopEntryState);
} }
if (state is LoopEndState) if (state is LoopEndState)
@ -412,12 +411,12 @@ namespace Antlr4.Runtime.Atn
if (state is DecisionState) if (state is DecisionState)
{ {
DecisionState decisionState = (DecisionState)state; DecisionState decisionState = (DecisionState)state;
CheckCondition(decisionState.GetNumberOfTransitions() <= 1 || decisionState.decision CheckCondition(decisionState.NumberOfTransitions <= 1 || decisionState.decision >=
>= 0); 0);
} }
else else
{ {
CheckCondition(state.GetNumberOfTransitions() <= 1 || state is RuleStopState); CheckCondition(state.NumberOfTransitions <= 1 || state is RuleStopState);
} }
} }
} }
@ -444,36 +443,36 @@ namespace Antlr4.Runtime.Atn
{ {
RuleStartState startState = atn.ruleToStartState[i]; RuleStartState startState = atn.ruleToStartState[i];
ATNState middleState = startState; ATNState middleState = startState;
while (middleState.OnlyHasEpsilonTransitions() && middleState.GetNumberOfOptimizedTransitions while (middleState.OnlyHasEpsilonTransitions && middleState.NumberOfOptimizedTransitions
() == 1 && middleState.GetOptimizedTransition(0).SerializationType == Transition == 1 && middleState.GetOptimizedTransition(0).TransitionType == TransitionType
.Epsilon) .Epsilon)
{ {
middleState = middleState.GetOptimizedTransition(0).target; middleState = middleState.GetOptimizedTransition(0).target;
} }
if (middleState.GetNumberOfOptimizedTransitions() != 1) if (middleState.NumberOfOptimizedTransitions != 1)
{ {
continue; continue;
} }
Transition matchTransition = middleState.GetOptimizedTransition(0); Transition matchTransition = middleState.GetOptimizedTransition(0);
ATNState matchTarget = matchTransition.target; ATNState matchTarget = matchTransition.target;
if (matchTransition.IsEpsilon || !matchTarget.OnlyHasEpsilonTransitions() || matchTarget if (matchTransition.IsEpsilon || !matchTarget.OnlyHasEpsilonTransitions || matchTarget
.GetNumberOfOptimizedTransitions() != 1 || !(matchTarget.GetOptimizedTransition .NumberOfOptimizedTransitions != 1 || !(matchTarget.GetOptimizedTransition(0)
(0).target is RuleStopState)) .target is RuleStopState))
{ {
continue; continue;
} }
switch (matchTransition.SerializationType) switch (matchTransition.TransitionType)
{ {
case Transition.Atom: case TransitionType.Atom:
case Transition.Range: case TransitionType.Range:
case Transition.Set: case TransitionType.Set:
{ {
ruleToInlineTransition[i] = matchTransition; ruleToInlineTransition[i] = matchTransition;
break; break;
} }
case Transition.NotSet: case TransitionType.NotSet:
case Transition.Wildcard: case TransitionType.Wildcard:
{ {
// not implemented yet // not implemented yet
continue; continue;
@ -495,7 +494,7 @@ namespace Antlr4.Runtime.Atn
continue; continue;
} }
IList<Transition> optimizedTransitions = null; IList<Transition> optimizedTransitions = null;
for (int i_1 = 0; i_1 < state.GetNumberOfOptimizedTransitions(); i_1++) for (int i_1 = 0; i_1 < state.NumberOfOptimizedTransitions; i_1++)
{ {
Transition transition = state.GetOptimizedTransition(i_1); Transition transition = state.GetOptimizedTransition(i_1);
if (!(transition is RuleTransition)) if (!(transition is RuleTransition))
@ -530,23 +529,23 @@ namespace Antlr4.Runtime.Atn
intermediateState.SetRuleIndex(target.ruleIndex); intermediateState.SetRuleIndex(target.ruleIndex);
atn.AddState(intermediateState); atn.AddState(intermediateState);
optimizedTransitions.AddItem(new EpsilonTransition(intermediateState)); optimizedTransitions.AddItem(new EpsilonTransition(intermediateState));
switch (effective.SerializationType) switch (effective.TransitionType)
{ {
case Transition.Atom: case TransitionType.Atom:
{ {
intermediateState.AddTransition(new AtomTransition(target, ((AtomTransition)effective intermediateState.AddTransition(new AtomTransition(target, ((AtomTransition)effective
).label)); ).label));
break; break;
} }
case Transition.Range: case TransitionType.Range:
{ {
intermediateState.AddTransition(new RangeTransition(target, ((RangeTransition)effective intermediateState.AddTransition(new RangeTransition(target, ((RangeTransition)effective
).from, ((RangeTransition)effective).to)); ).from, ((RangeTransition)effective).to));
break; break;
} }
case Transition.Set: case TransitionType.Set:
{ {
intermediateState.AddTransition(new SetTransition(target, effective.Label)); intermediateState.AddTransition(new SetTransition(target, effective.Label));
break; break;
@ -560,11 +559,11 @@ namespace Antlr4.Runtime.Atn
} }
if (optimizedTransitions != null) if (optimizedTransitions != null)
{ {
if (state.IsOptimized()) if (state.IsOptimized)
{ {
while (state.GetNumberOfOptimizedTransitions() > 0) while (state.NumberOfOptimizedTransitions > 0)
{ {
state.RemoveOptimizedTransition(state.GetNumberOfOptimizedTransitions() - 1); state.RemoveOptimizedTransition(state.NumberOfOptimizedTransitions - 1);
} }
} }
foreach (Transition transition in optimizedTransitions) foreach (Transition transition in optimizedTransitions)
@ -581,17 +580,17 @@ namespace Antlr4.Runtime.Atn
int removedEdges = 0; int removedEdges = 0;
foreach (ATNState state in atn.states) foreach (ATNState state in atn.states)
{ {
if (!state.OnlyHasEpsilonTransitions() || state is RuleStopState) if (!state.OnlyHasEpsilonTransitions || state is RuleStopState)
{ {
continue; continue;
} }
IList<Transition> optimizedTransitions = null; IList<Transition> optimizedTransitions = null;
for (int i = 0; i < state.GetNumberOfOptimizedTransitions(); i++) for (int i = 0; i < state.NumberOfOptimizedTransitions; i++)
{ {
Transition transition = state.GetOptimizedTransition(i); Transition transition = state.GetOptimizedTransition(i);
ATNState intermediate = transition.target; ATNState intermediate = transition.target;
if (transition.SerializationType != Transition.Epsilon || intermediate.GetStateType if (transition.TransitionType != TransitionType.Epsilon || intermediate.StateType
() != ATNState.Basic || !intermediate.OnlyHasEpsilonTransitions()) != StateType.Basic || !intermediate.OnlyHasEpsilonTransitions)
{ {
if (optimizedTransitions != null) if (optimizedTransitions != null)
{ {
@ -599,9 +598,9 @@ namespace Antlr4.Runtime.Atn
} }
goto nextTransition_continue; goto nextTransition_continue;
} }
for (int j = 0; j < intermediate.GetNumberOfOptimizedTransitions(); j++) for (int j = 0; j < intermediate.NumberOfOptimizedTransitions; j++)
{ {
if (intermediate.GetOptimizedTransition(j).SerializationType != Transition.Epsilon) if (intermediate.GetOptimizedTransition(j).TransitionType != TransitionType.Epsilon)
{ {
if (optimizedTransitions != null) if (optimizedTransitions != null)
{ {
@ -619,7 +618,7 @@ namespace Antlr4.Runtime.Atn
optimizedTransitions.AddItem(state.GetOptimizedTransition(j_1)); optimizedTransitions.AddItem(state.GetOptimizedTransition(j_1));
} }
} }
for (int j_2 = 0; j_2 < intermediate.GetNumberOfOptimizedTransitions(); j_2++) for (int j_2 = 0; j_2 < intermediate.NumberOfOptimizedTransitions; j_2++)
{ {
ATNState target = intermediate.GetOptimizedTransition(j_2).target; ATNState target = intermediate.GetOptimizedTransition(j_2).target;
optimizedTransitions.AddItem(new EpsilonTransition(target)); optimizedTransitions.AddItem(new EpsilonTransition(target));
@ -629,11 +628,11 @@ nextTransition_continue: ;
nextTransition_break: ; nextTransition_break: ;
if (optimizedTransitions != null) if (optimizedTransitions != null)
{ {
if (state.IsOptimized()) if (state.IsOptimized)
{ {
while (state.GetNumberOfOptimizedTransitions() > 0) while (state.NumberOfOptimizedTransitions > 0)
{ {
state.RemoveOptimizedTransition(state.GetNumberOfOptimizedTransitions() - 1); state.RemoveOptimizedTransition(state.NumberOfOptimizedTransitions - 1);
} }
} }
foreach (Transition transition in optimizedTransitions) foreach (Transition transition in optimizedTransitions)
@ -658,14 +657,14 @@ nextState_break: ;
foreach (DecisionState decision in decisions) foreach (DecisionState decision in decisions)
{ {
IntervalSet setTransitions = new IntervalSet(); IntervalSet setTransitions = new IntervalSet();
for (int i = 0; i < decision.GetNumberOfOptimizedTransitions(); i++) for (int i = 0; i < decision.NumberOfOptimizedTransitions; i++)
{ {
Transition epsTransition = decision.GetOptimizedTransition(i); Transition epsTransition = decision.GetOptimizedTransition(i);
if (!(epsTransition is EpsilonTransition)) if (!(epsTransition is EpsilonTransition))
{ {
continue; continue;
} }
if (epsTransition.target.GetNumberOfOptimizedTransitions() != 1) if (epsTransition.target.NumberOfOptimizedTransitions != 1)
{ {
continue; continue;
} }
@ -690,7 +689,7 @@ nextState_break: ;
continue; continue;
} }
IList<Transition> optimizedTransitions = new List<Transition>(); IList<Transition> optimizedTransitions = new List<Transition>();
for (int i_1 = 0; i_1 < decision.GetNumberOfOptimizedTransitions(); i_1++) for (int i_1 = 0; i_1 < decision.NumberOfOptimizedTransitions; i_1++)
{ {
if (!setTransitions.Contains(i_1)) if (!setTransitions.Contains(i_1))
{ {
@ -740,14 +739,12 @@ nextState_break: ;
atn.AddState(setOptimizedState); atn.AddState(setOptimizedState);
setOptimizedState.AddTransition(newTransition); setOptimizedState.AddTransition(newTransition);
optimizedTransitions.AddItem(new EpsilonTransition(setOptimizedState)); optimizedTransitions.AddItem(new EpsilonTransition(setOptimizedState));
removedPaths += decision.GetNumberOfOptimizedTransitions() - optimizedTransitions removedPaths += decision.NumberOfOptimizedTransitions - optimizedTransitions.Count;
.Count; if (decision.IsOptimized)
if (decision.IsOptimized())
{ {
while (decision.GetNumberOfOptimizedTransitions() > 0) while (decision.NumberOfOptimizedTransitions > 0)
{ {
decision.RemoveOptimizedTransition(decision.GetNumberOfOptimizedTransitions() - 1 decision.RemoveOptimizedTransition(decision.NumberOfOptimizedTransitions - 1);
);
} }
} }
foreach (Transition transition_1 in optimizedTransitions) foreach (Transition transition_1 in optimizedTransitions)
@ -772,7 +769,7 @@ nextState_break: ;
ruleTransition.tailCall = TestTailCall(atn, ruleTransition, false); ruleTransition.tailCall = TestTailCall(atn, ruleTransition, false);
ruleTransition.optimizedTailCall = TestTailCall(atn, ruleTransition, true); ruleTransition.optimizedTailCall = TestTailCall(atn, ruleTransition, true);
} }
if (!state.IsOptimized()) if (!state.IsOptimized)
{ {
continue; continue;
} }
@ -814,7 +811,7 @@ nextState_break: ;
{ {
continue; continue;
} }
if (!state.OnlyHasEpsilonTransitions()) if (!state.OnlyHasEpsilonTransitions)
{ {
return false; return false;
} }
@ -822,7 +819,7 @@ nextState_break: ;
.transitions; .transitions;
foreach (Transition t in transitions) foreach (Transition t in transitions)
{ {
if (t.SerializationType != Transition.Epsilon) if (t.TransitionType != TransitionType.Epsilon)
{ {
return false; return false;
} }
@ -838,62 +835,62 @@ nextState_break: ;
} }
[NotNull] [NotNull]
public static Transition EdgeFactory(ATN atn, int type, int src, int trg, int arg1 public static Transition EdgeFactory(ATN atn, TransitionType type, int src, int trg
, int arg2, int arg3, IList<IntervalSet> sets) , int arg1, int arg2, int arg3, IList<IntervalSet> sets)
{ {
ATNState target = atn.states[trg]; ATNState target = atn.states[trg];
switch (type) switch (type)
{ {
case Transition.Epsilon: case TransitionType.Epsilon:
{ {
return new EpsilonTransition(target); return new EpsilonTransition(target);
} }
case Transition.Range: case TransitionType.Range:
{ {
return new RangeTransition(target, arg1, arg2); return new RangeTransition(target, arg1, arg2);
} }
case Transition.Rule: case TransitionType.Rule:
{ {
RuleTransition rt = new RuleTransition((RuleStartState)atn.states[arg1], arg2, arg3 RuleTransition rt = new RuleTransition((RuleStartState)atn.states[arg1], arg2, arg3
, target); , target);
return rt; return rt;
} }
case Transition.Predicate: case TransitionType.Predicate:
{ {
PredicateTransition pt = new PredicateTransition(target, arg1, arg2, arg3 != 0); PredicateTransition pt = new PredicateTransition(target, arg1, arg2, arg3 != 0);
return pt; return pt;
} }
case Transition.Precedence: case TransitionType.Precedence:
{ {
return new PrecedencePredicateTransition(target, arg1); return new PrecedencePredicateTransition(target, arg1);
} }
case Transition.Atom: case TransitionType.Atom:
{ {
return new AtomTransition(target, arg1); return new AtomTransition(target, arg1);
} }
case Transition.Action: case TransitionType.Action:
{ {
ActionTransition a = new ActionTransition(target, arg1, arg2, arg3 != 0); ActionTransition a = new ActionTransition(target, arg1, arg2, arg3 != 0);
return a; return a;
} }
case Transition.Set: case TransitionType.Set:
{ {
return new SetTransition(target, sets[arg1]); return new SetTransition(target, sets[arg1]);
} }
case Transition.NotSet: case TransitionType.NotSet:
{ {
return new NotSetTransition(target, sets[arg1]); return new NotSetTransition(target, sets[arg1]);
} }
case Transition.Wildcard: case TransitionType.Wildcard:
{ {
return new WildcardTransition(target); return new WildcardTransition(target);
} }
@ -901,83 +898,83 @@ nextState_break: ;
throw new ArgumentException("The specified transition type is not valid."); throw new ArgumentException("The specified transition type is not valid.");
} }
public static ATNState StateFactory(int type, int ruleIndex) public static ATNState StateFactory(StateType type, int ruleIndex)
{ {
ATNState s; ATNState s;
switch (type) switch (type)
{ {
case ATNState.InvalidType: case StateType.InvalidType:
{ {
return null; return null;
} }
case ATNState.Basic: case StateType.Basic:
{ {
s = new BasicState(); s = new BasicState();
break; break;
} }
case ATNState.RuleStart: case StateType.RuleStart:
{ {
s = new RuleStartState(); s = new RuleStartState();
break; break;
} }
case ATNState.BlockStart: case StateType.BlockStart:
{ {
s = new BasicBlockStartState(); s = new BasicBlockStartState();
break; break;
} }
case ATNState.PlusBlockStart: case StateType.PlusBlockStart:
{ {
s = new PlusBlockStartState(); s = new PlusBlockStartState();
break; break;
} }
case ATNState.StarBlockStart: case StateType.StarBlockStart:
{ {
s = new StarBlockStartState(); s = new StarBlockStartState();
break; break;
} }
case ATNState.TokenStart: case StateType.TokenStart:
{ {
s = new TokensStartState(); s = new TokensStartState();
break; break;
} }
case ATNState.RuleStop: case StateType.RuleStop:
{ {
s = new RuleStopState(); s = new RuleStopState();
break; break;
} }
case ATNState.BlockEnd: case StateType.BlockEnd:
{ {
s = new BlockEndState(); s = new BlockEndState();
break; break;
} }
case ATNState.StarLoopBack: case StateType.StarLoopBack:
{ {
s = new StarLoopbackState(); s = new StarLoopbackState();
break; break;
} }
case ATNState.StarLoopEntry: case StateType.StarLoopEntry:
{ {
s = new StarLoopEntryState(); s = new StarLoopEntryState();
break; break;
} }
case ATNState.PlusLoopBack: case StateType.PlusLoopBack:
{ {
s = new PlusLoopbackState(); s = new PlusLoopbackState();
break; break;
} }
case ATNState.LoopEnd: case StateType.LoopEnd:
{ {
s = new LoopEndState(); s = new LoopEndState();
break; break;

View File

@ -94,32 +94,6 @@ namespace Antlr4.Runtime.Atn
{ {
public const int InitialNumTransitions = 4; public const int InitialNumTransitions = 4;
public const int InvalidType = 0;
public const int Basic = 1;
public const int RuleStart = 2;
public const int BlockStart = 3;
public const int PlusBlockStart = 4;
public const int StarBlockStart = 5;
public const int TokenStart = 6;
public const int RuleStop = 7;
public const int BlockEnd = 8;
public const int StarLoopBack = 9;
public const int StarLoopEntry = 10;
public const int PlusLoopBack = 11;
public const int LoopEnd = 12;
public static readonly IList<string> serializationNames = Sharpen.Collections.UnmodifiableList public static readonly IList<string> serializationNames = Sharpen.Collections.UnmodifiableList
(Arrays.AsList("INVALID", "BASIC", "RULE_START", "BLOCK_START", "PLUS_BLOCK_START" (Arrays.AsList("INVALID", "BASIC", "RULE_START", "BLOCK_START", "PLUS_BLOCK_START"
, "STAR_BLOCK_START", "TOKEN_START", "RULE_STOP", "BLOCK_END", "STAR_LOOP_BACK" , "STAR_BLOCK_START", "TOKEN_START", "RULE_STOP", "BLOCK_END", "STAR_LOOP_BACK"
@ -146,14 +120,16 @@ namespace Antlr4.Runtime.Atn
/// <summary>Used to cache lookahead during parsing, not used during construction</summary> /// <summary>Used to cache lookahead during parsing, not used during construction</summary>
public IntervalSet nextTokenWithinRule; public IntervalSet nextTokenWithinRule;
// constants for serialization
// at runtime, we don't have Rule objects
/// <summary>Gets the state number.</summary> /// <summary>Gets the state number.</summary>
/// <remarks>Gets the state number.</remarks> /// <remarks>Gets the state number.</remarks>
/// <returns>the state number</returns> /// <returns>the state number</returns>
public int GetStateNumber() public int StateNumber
{ {
return stateNumber; get
{
// at runtime, we don't have Rule objects
return stateNumber;
}
} }
/// <summary> /// <summary>
@ -167,9 +143,12 @@ namespace Antlr4.Runtime.Atn
/// <see cref="RuleStopState">RuleStopState</see> /// <see cref="RuleStopState">RuleStopState</see>
/// , otherwise the state number /// , otherwise the state number
/// </returns> /// </returns>
public virtual int GetNonStopStateNumber() public virtual int NonStopStateNumber
{ {
return GetStateNumber(); get
{
return StateNumber;
}
} }
public override int GetHashCode() public override int GetHashCode()
@ -187,9 +166,12 @@ namespace Antlr4.Runtime.Atn
return false; return false;
} }
public virtual bool IsNonGreedyExitState() public virtual bool IsNonGreedyExitState
{ {
return false; get
{
return false;
}
} }
public override string ToString() public override string ToString()
@ -203,9 +185,12 @@ namespace Antlr4.Runtime.Atn
[transitions.Count]); [transitions.Count]);
} }
public virtual int GetNumberOfTransitions() public virtual int NumberOfTransitions
{ {
return transitions.Count; get
{
return transitions.Count;
}
} }
public virtual void AddTransition(Antlr4.Runtime.Atn.Transition e) public virtual void AddTransition(Antlr4.Runtime.Atn.Transition e)
@ -241,11 +226,17 @@ namespace Antlr4.Runtime.Atn
return transitions.Remove(index); return transitions.Remove(index);
} }
public abstract int GetStateType(); public abstract Antlr4.Runtime.Atn.StateType StateType
public bool OnlyHasEpsilonTransitions()
{ {
return epsilonOnlyTransitions; get;
}
public bool OnlyHasEpsilonTransitions
{
get
{
return epsilonOnlyTransitions;
}
} }
public virtual void SetRuleIndex(int ruleIndex) public virtual void SetRuleIndex(int ruleIndex)
@ -253,14 +244,20 @@ namespace Antlr4.Runtime.Atn
this.ruleIndex = ruleIndex; this.ruleIndex = ruleIndex;
} }
public virtual bool IsOptimized() public virtual bool IsOptimized
{ {
return optimizedTransitions != transitions; get
{
return optimizedTransitions != transitions;
}
} }
public virtual int GetNumberOfOptimizedTransitions() public virtual int NumberOfOptimizedTransitions
{ {
return optimizedTransitions.Count; get
{
return optimizedTransitions.Count;
}
} }
public virtual Antlr4.Runtime.Atn.Transition GetOptimizedTransition(int i) public virtual Antlr4.Runtime.Atn.Transition GetOptimizedTransition(int i)
@ -270,7 +267,7 @@ namespace Antlr4.Runtime.Atn
public virtual void AddOptimizedTransition(Antlr4.Runtime.Atn.Transition e) public virtual void AddOptimizedTransition(Antlr4.Runtime.Atn.Transition e)
{ {
if (!IsOptimized()) if (!IsOptimized)
{ {
optimizedTransitions = new List<Antlr4.Runtime.Atn.Transition>(); optimizedTransitions = new List<Antlr4.Runtime.Atn.Transition>();
} }
@ -280,7 +277,7 @@ namespace Antlr4.Runtime.Atn
public virtual void SetOptimizedTransition(int i, Antlr4.Runtime.Atn.Transition e public virtual void SetOptimizedTransition(int i, Antlr4.Runtime.Atn.Transition e
) )
{ {
if (!IsOptimized()) if (!IsOptimized)
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
@ -289,7 +286,7 @@ namespace Antlr4.Runtime.Atn
public virtual void RemoveOptimizedTransition(int i) public virtual void RemoveOptimizedTransition(int i)
{ {
if (!IsOptimized()) if (!IsOptimized)
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }

View File

@ -54,11 +54,11 @@ namespace Antlr4.Runtime.Atn
this.isCtxDependent = isCtxDependent; this.isCtxDependent = isCtxDependent;
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return Action; return Antlr4.Runtime.Atn.TransitionType.Action;
} }
} }

View File

@ -45,11 +45,11 @@ namespace Antlr4.Runtime.Atn
this.label = label; this.label = label;
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return Atom; return Antlr4.Runtime.Atn.TransitionType.Atom;
} }
} }

View File

@ -35,9 +35,12 @@ namespace Antlr4.Runtime.Atn
/// <author>Sam Harwell</author> /// <author>Sam Harwell</author>
public sealed class BasicBlockStartState : BlockStartState public sealed class BasicBlockStartState : BlockStartState
{ {
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return BlockStart; get
{
return Antlr4.Runtime.Atn.StateType.BlockStart;
}
} }
} }
} }

View File

@ -35,9 +35,12 @@ namespace Antlr4.Runtime.Atn
/// <author>Sam Harwell</author> /// <author>Sam Harwell</author>
public sealed class BasicState : ATNState public sealed class BasicState : ATNState
{ {
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return Basic; get
{
return Antlr4.Runtime.Atn.StateType.Basic;
}
} }
} }
} }

View File

@ -41,9 +41,12 @@ namespace Antlr4.Runtime.Atn
{ {
public BlockStartState startState; public BlockStartState startState;
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return BlockEnd; get
{
return Antlr4.Runtime.Atn.StateType.BlockEnd;
}
} }
} }
} }

View File

@ -39,11 +39,11 @@ namespace Antlr4.Runtime.Atn
{ {
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return Epsilon; return Antlr4.Runtime.Atn.TransitionType.Epsilon;
} }
} }

View File

@ -70,8 +70,8 @@ namespace Antlr4.Runtime.Atn
{ {
return null; return null;
} }
IntervalSet[] look = new IntervalSet[s.GetNumberOfTransitions() + 1]; IntervalSet[] look = new IntervalSet[s.NumberOfTransitions + 1];
for (int alt = 1; alt <= s.GetNumberOfTransitions(); alt++) for (int alt = 1; alt <= s.NumberOfTransitions; alt++)
{ {
look[alt] = new IntervalSet(); look[alt] = new IntervalSet();
ICollection<ATNConfig> lookBusy = new HashSet<ATNConfig>(); ICollection<ATNConfig> lookBusy = new HashSet<ATNConfig>();
@ -175,7 +175,7 @@ namespace Antlr4.Runtime.Atn
} }
} }
} }
int n = s.GetNumberOfTransitions(); int n = s.NumberOfTransitions;
for (int i_1 = 0; i_1 < n; i_1++) for (int i_1 = 0; i_1 < n; i_1++)
{ {
Transition t = s.Transition(i_1); Transition t = s.Transition(i_1);

View File

@ -311,7 +311,7 @@ namespace Antlr4.Runtime.Atn
{ {
continue; continue;
} }
int n = c.GetState().GetNumberOfOptimizedTransitions(); int n = c.GetState().NumberOfOptimizedTransitions;
for (int ti = 0; ti < n; ti++) for (int ti = 0; ti < n; ti++)
{ {
// for each optimized transition // for each optimized transition
@ -364,7 +364,7 @@ namespace Antlr4.Runtime.Atn
{ {
PredictionContext initialContext = PredictionContext.EmptyFull; PredictionContext initialContext = PredictionContext.EmptyFull;
ATNConfigSet configs = new OrderedATNConfigSet(); ATNConfigSet configs = new OrderedATNConfigSet();
for (int i = 0; i < p.GetNumberOfTransitions(); i++) for (int i = 0; i < p.NumberOfTransitions; i++)
{ {
ATNState target = p.Transition(i).target; ATNState target = p.Transition(i).target;
ATNConfig c = ATNConfig.Create(target, i + 1, initialContext); ATNConfig c = ATNConfig.Create(target, i + 1, initialContext);
@ -432,12 +432,12 @@ namespace Antlr4.Runtime.Atn
return false; return false;
} }
// optimization // optimization
if (!config.GetState().OnlyHasEpsilonTransitions()) if (!config.GetState().OnlyHasEpsilonTransitions)
{ {
configs.AddItem(config); configs.AddItem(config);
} }
ATNState p = config.GetState(); ATNState p = config.GetState();
for (int i_1 = 0; i_1 < p.GetNumberOfOptimizedTransitions(); i_1++) for (int i_1 = 0; i_1 < p.NumberOfOptimizedTransitions; i_1++)
{ {
Transition t = p.GetOptimizedTransition(i_1); Transition t = p.GetOptimizedTransition(i_1);
ATNConfig c = GetEpsilonTarget(input, config, t, configs, speculative); ATNConfig c = GetEpsilonTarget(input, config, t, configs, speculative);
@ -458,9 +458,9 @@ namespace Antlr4.Runtime.Atn
t, ATNConfigSet configs, bool speculative) t, ATNConfigSet configs, bool speculative)
{ {
ATNConfig c; ATNConfig c;
switch (t.SerializationType) switch (t.TransitionType)
{ {
case Transition.Rule: case TransitionType.Rule:
{ {
RuleTransition ruleTransition = (RuleTransition)t; RuleTransition ruleTransition = (RuleTransition)t;
if (optimize_tail_calls && ruleTransition.optimizedTailCall && !config.GetContext if (optimize_tail_calls && ruleTransition.optimizedTailCall && !config.GetContext
@ -477,13 +477,13 @@ namespace Antlr4.Runtime.Atn
break; break;
} }
case Transition.Precedence: case TransitionType.Precedence:
{ {
throw new NotSupportedException("Precedence predicates are not supported in lexers." throw new NotSupportedException("Precedence predicates are not supported in lexers."
); );
} }
case Transition.Predicate: case TransitionType.Predicate:
{ {
PredicateTransition pt = (PredicateTransition)t; PredicateTransition pt = (PredicateTransition)t;
configs.MarkExplicitSemanticContext(); configs.MarkExplicitSemanticContext();
@ -498,14 +498,14 @@ namespace Antlr4.Runtime.Atn
break; break;
} }
case Transition.Action: case TransitionType.Action:
{ {
// ignore actions; just exec one per rule upon accept // ignore actions; just exec one per rule upon accept
c = config.Transform(t.target, ((ActionTransition)t).actionIndex); c = config.Transform(t.target, ((ActionTransition)t).actionIndex);
break; break;
} }
case Transition.Epsilon: case TransitionType.Epsilon:
{ {
c = config.Transform(t.target); c = config.Transform(t.target);
break; break;

View File

@ -38,9 +38,12 @@ namespace Antlr4.Runtime.Atn
{ {
public ATNState loopBackState; public ATNState loopBackState;
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return LoopEnd; get
{
return Antlr4.Runtime.Atn.StateType.LoopEnd;
}
} }
} }
} }

View File

@ -39,11 +39,11 @@ namespace Antlr4.Runtime.Atn
{ {
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return NotSet; return Antlr4.Runtime.Atn.TransitionType.NotSet;
} }
} }

View File

@ -717,7 +717,7 @@ namespace Antlr4.Runtime.Atn
System.Diagnostics.Debug.Assert(D.isAcceptState); System.Diagnostics.Debug.Assert(D.isAcceptState);
if (D.configs.HasSemanticContext()) if (D.configs.HasSemanticContext())
{ {
int nalts = decState.GetNumberOfTransitions(); int nalts = decState.NumberOfTransitions;
DFAState.PredPrediction[] predPredictions = D.predicates; DFAState.PredPrediction[] predPredictions = D.predicates;
if (predPredictions != null) if (predPredictions != null)
{ {
@ -883,7 +883,7 @@ namespace Antlr4.Runtime.Atn
} }
continue; continue;
} }
int n = c.GetState().GetNumberOfOptimizedTransitions(); int n = c.GetState().NumberOfOptimizedTransitions;
for (int ti = 0; ti < n; ti++) for (int ti = 0; ti < n; ti++)
{ {
// for each optimized transition // for each optimized transition
@ -1068,7 +1068,7 @@ namespace Antlr4.Runtime.Atn
while (true) while (true)
{ {
ATNConfigSet reachIntermediate = new ATNConfigSet(); ATNConfigSet reachIntermediate = new ATNConfigSet();
int n = p.GetNumberOfTransitions(); int n = p.NumberOfTransitions;
for (int ti = 0; ti < n; ti++) for (int ti = 0; ti < n; ti++)
{ {
// for each transition // for each transition
@ -1364,11 +1364,11 @@ namespace Antlr4.Runtime.Atn
} }
ATNState p = config.GetState(); ATNState p = config.GetState();
// optimization // optimization
if (!p.OnlyHasEpsilonTransitions()) if (!p.OnlyHasEpsilonTransitions)
{ {
configs.Add(config, contextCache); configs.Add(config, contextCache);
} }
for (int i_1 = 0; i_1 < p.GetNumberOfOptimizedTransitions(); i_1++) for (int i_1 = 0; i_1 < p.NumberOfOptimizedTransitions; i_1++)
{ {
Transition t = p.GetOptimizedTransition(i_1); Transition t = p.GetOptimizedTransition(i_1);
bool continueCollecting = !(t is Antlr4.Runtime.Atn.ActionTransition) && collectPredicates; bool continueCollecting = !(t is Antlr4.Runtime.Atn.ActionTransition) && collectPredicates;
@ -1387,23 +1387,23 @@ namespace Antlr4.Runtime.Atn
if (optimize_closure_busy) if (optimize_closure_busy)
{ {
bool checkClosure = false; bool checkClosure = false;
switch (c.GetState().GetStateType()) switch (c.GetState().StateType)
{ {
case ATNState.StarLoopEntry: case StateType.StarLoopEntry:
case ATNState.BlockEnd: case StateType.BlockEnd:
case ATNState.LoopEnd: case StateType.LoopEnd:
{ {
checkClosure = true; checkClosure = true;
break; break;
} }
case ATNState.PlusBlockStart: case StateType.PlusBlockStart:
{ {
checkClosure = true; checkClosure = true;
break; break;
} }
case ATNState.RuleStop: case StateType.RuleStop:
{ {
checkClosure = c.GetContext().IsEmpty; checkClosure = c.GetContext().IsEmpty;
break; break;
@ -1484,31 +1484,31 @@ namespace Antlr4.Runtime.Atn
public virtual ATNConfig GetEpsilonTarget(ATNConfig config, Transition t, bool collectPredicates public virtual ATNConfig GetEpsilonTarget(ATNConfig config, Transition t, bool collectPredicates
, bool inContext, PredictionContextCache contextCache) , bool inContext, PredictionContextCache contextCache)
{ {
switch (t.SerializationType) switch (t.TransitionType)
{ {
case Transition.Rule: case TransitionType.Rule:
{ {
return RuleTransition(config, (Antlr4.Runtime.Atn.RuleTransition)t, contextCache); return RuleTransition(config, (Antlr4.Runtime.Atn.RuleTransition)t, contextCache);
} }
case Transition.Precedence: case TransitionType.Precedence:
{ {
return PrecedenceTransition(config, (PrecedencePredicateTransition)t, collectPredicates return PrecedenceTransition(config, (PrecedencePredicateTransition)t, collectPredicates
, inContext); , inContext);
} }
case Transition.Predicate: case TransitionType.Predicate:
{ {
return PredTransition(config, (PredicateTransition)t, collectPredicates, inContext return PredTransition(config, (PredicateTransition)t, collectPredicates, inContext
); );
} }
case Transition.Action: case TransitionType.Action:
{ {
return ActionTransition(config, (Antlr4.Runtime.Atn.ActionTransition)t); return ActionTransition(config, (Antlr4.Runtime.Atn.ActionTransition)t);
} }
case Transition.Epsilon: case TransitionType.Epsilon:
{ {
return config.Transform(t.target); return config.Transform(t.target);
} }
@ -1597,8 +1597,7 @@ namespace Antlr4.Runtime.Atn
public int Compare(ATNConfig o1, ATNConfig o2) public int Compare(ATNConfig o1, ATNConfig o2)
{ {
int diff = o1.GetState().GetNonStopStateNumber() - o2.GetState().GetNonStopStateNumber int diff = o1.GetState().NonStopStateNumber - o2.GetState().NonStopStateNumber;
();
if (diff != 0) if (diff != 0)
{ {
return diff; return diff;
@ -1632,11 +1631,11 @@ namespace Antlr4.Runtime.Atn
// quick check 1 & 2 => if we assume #1 holds and check #2 against the // 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 // minAlt from the first state, #2 will fail if the assumption was
// incorrect // incorrect
int currentState = configs[0].GetState().GetNonStopStateNumber(); int currentState = configs[0].GetState().NonStopStateNumber;
for (int i = 0; i < configs.Count; i++) for (int i = 0; i < configs.Count; i++)
{ {
ATNConfig config = configs[i]; ATNConfig config = configs[i];
int stateNumber = config.GetState().GetNonStopStateNumber(); int stateNumber = config.GetState().NonStopStateNumber;
if (stateNumber != currentState) if (stateNumber != currentState)
{ {
if (config.GetAlt() != minAlt) if (config.GetAlt() != minAlt)
@ -1649,14 +1648,14 @@ namespace Antlr4.Runtime.Atn
BitArray representedAlts = null; BitArray representedAlts = null;
if (exact) if (exact)
{ {
currentState = configs[0].GetState().GetNonStopStateNumber(); currentState = configs[0].GetState().NonStopStateNumber;
// get the represented alternatives of the first state // get the represented alternatives of the first state
representedAlts = new BitArray(); representedAlts = new BitArray();
int maxAlt = minAlt; int maxAlt = minAlt;
for (int i_1 = 0; i_1 < configs.Count; i_1++) for (int i_1 = 0; i_1 < configs.Count; i_1++)
{ {
ATNConfig config = configs[i_1]; ATNConfig config = configs[i_1];
if (config.GetState().GetNonStopStateNumber() != currentState) if (config.GetState().NonStopStateNumber != currentState)
{ {
break; break;
} }
@ -1665,12 +1664,12 @@ namespace Antlr4.Runtime.Atn
maxAlt = alt; maxAlt = alt;
} }
// quick check #3: // quick check #3:
currentState = configs[0].GetState().GetNonStopStateNumber(); currentState = configs[0].GetState().NonStopStateNumber;
int currentAlt = minAlt; int currentAlt = minAlt;
for (int i_2 = 0; i_2 < configs.Count; i_2++) for (int i_2 = 0; i_2 < configs.Count; i_2++)
{ {
ATNConfig config = configs[i_2]; ATNConfig config = configs[i_2];
int stateNumber = config.GetState().GetNonStopStateNumber(); int stateNumber = config.GetState().NonStopStateNumber;
int alt = config.GetAlt(); int alt = config.GetAlt();
if (stateNumber != currentState) if (stateNumber != currentState)
{ {
@ -1694,7 +1693,7 @@ namespace Antlr4.Runtime.Atn
} }
} }
} }
currentState = configs[0].GetState().GetNonStopStateNumber(); currentState = configs[0].GetState().NonStopStateNumber;
int firstIndexCurrentState = 0; int firstIndexCurrentState = 0;
int lastIndexCurrentStateMinAlt = 0; int lastIndexCurrentStateMinAlt = 0;
PredictionContext joinedCheckContext = configs[0].GetContext(); PredictionContext joinedCheckContext = configs[0].GetContext();
@ -1705,7 +1704,7 @@ namespace Antlr4.Runtime.Atn
{ {
break; break;
} }
if (config.GetState().GetNonStopStateNumber() != currentState) if (config.GetState().NonStopStateNumber != currentState)
{ {
break; break;
} }
@ -1718,9 +1717,9 @@ namespace Antlr4.Runtime.Atn
ATNConfig config = configs[i_4]; ATNConfig config = configs[i_4];
ATNState state = config.GetState(); ATNState state = config.GetState();
alts.Set(config.GetAlt()); alts.Set(config.GetAlt());
if (state.GetNonStopStateNumber() != currentState) if (state.NonStopStateNumber != currentState)
{ {
currentState = state.GetNonStopStateNumber(); currentState = state.NonStopStateNumber;
firstIndexCurrentState = i_4; firstIndexCurrentState = i_4;
lastIndexCurrentStateMinAlt = i_4; lastIndexCurrentStateMinAlt = i_4;
joinedCheckContext = config.GetContext(); joinedCheckContext = config.GetContext();
@ -1731,7 +1730,7 @@ namespace Antlr4.Runtime.Atn
{ {
break; break;
} }
if (config2.GetState().GetNonStopStateNumber() != currentState) if (config2.GetState().NonStopStateNumber != currentState)
{ {
break; break;
} }
@ -1751,7 +1750,7 @@ namespace Antlr4.Runtime.Atn
{ {
break; break;
} }
if (config2.GetState().GetNonStopStateNumber() != currentState) if (config2.GetState().NonStopStateNumber != currentState)
{ {
break; break;
} }
@ -1859,7 +1858,7 @@ namespace Antlr4.Runtime.Atn
foreach (ATNConfig c in nvae.GetDeadEndConfigs()) foreach (ATNConfig c in nvae.GetDeadEndConfigs())
{ {
string trans = "no edges"; string trans = "no edges";
if (c.GetState().GetNumberOfOptimizedTransitions() > 0) if (c.GetState().NumberOfOptimizedTransitions > 0)
{ {
Transition t = c.GetState().GetOptimizedTransition(0); Transition t = c.GetState().GetOptimizedTransition(0);
if (t is AtomTransition) if (t is AtomTransition)
@ -2054,7 +2053,7 @@ namespace Antlr4.Runtime.Atn
} }
if (newState.isAcceptState && configs.HasSemanticContext()) if (newState.isAcceptState && configs.HasSemanticContext())
{ {
PredicateDFAState(newState, configs, decisionState.GetNumberOfTransitions()); PredicateDFAState(newState, configs, decisionState.NumberOfTransitions);
} }
DFAState added = dfa.AddState(newState); DFAState added = dfa.AddState(newState);
if (debug && added == newState) if (debug && added == newState)
@ -2168,8 +2167,8 @@ namespace Antlr4.Runtime.Atn
while (!context.IsEmpty()) while (!context.IsEmpty())
{ {
ATNState state = atn.states[context.invokingState]; ATNState state = atn.states[context.invokingState];
System.Diagnostics.Debug.Assert(state.GetNumberOfTransitions() == 1 && state.Transition System.Diagnostics.Debug.Assert(state.NumberOfTransitions == 1 && state.Transition
(0).SerializationType == Transition.Rule); (0).TransitionType == TransitionType.Rule);
Antlr4.Runtime.Atn.RuleTransition transition = (Antlr4.Runtime.Atn.RuleTransition Antlr4.Runtime.Atn.RuleTransition transition = (Antlr4.Runtime.Atn.RuleTransition
)state.Transition(0); )state.Transition(0);
if (!transition.tailCall) if (!transition.tailCall)

View File

@ -48,9 +48,12 @@ namespace Antlr4.Runtime.Atn
{ {
public PlusLoopbackState loopBackState; public PlusLoopbackState loopBackState;
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return PlusBlockStart; get
{
return Antlr4.Runtime.Atn.StateType.PlusBlockStart;
}
} }
} }
} }

View File

@ -42,9 +42,12 @@ namespace Antlr4.Runtime.Atn
/// </summary> /// </summary>
public sealed class PlusLoopbackState : DecisionState public sealed class PlusLoopbackState : DecisionState
{ {
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return PlusLoopBack; get
{
return Antlr4.Runtime.Atn.StateType.PlusLoopBack;
}
} }
} }
} }

View File

@ -43,11 +43,11 @@ namespace Antlr4.Runtime.Atn
this.precedence = precedence; this.precedence = precedence;
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return Precedence; return Antlr4.Runtime.Atn.TransitionType.Precedence;
} }
} }

View File

@ -61,11 +61,11 @@ namespace Antlr4.Runtime.Atn
this.isCtxDependent = isCtxDependent; this.isCtxDependent = isCtxDependent;
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return Predicate; return Antlr4.Runtime.Atn.TransitionType.Predicate;
} }
} }

View File

@ -45,11 +45,11 @@ namespace Antlr4.Runtime.Atn
this.to = to; this.to = to;
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return Range; return Antlr4.Runtime.Atn.TransitionType.Range;
} }
} }

View File

@ -40,9 +40,12 @@ namespace Antlr4.Runtime.Atn
public bool leftFactored; public bool leftFactored;
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return RuleStart; get
{
return Antlr4.Runtime.Atn.StateType.RuleStart;
}
} }
} }
} }

View File

@ -42,14 +42,20 @@ namespace Antlr4.Runtime.Atn
/// </remarks> /// </remarks>
public sealed class RuleStopState : ATNState public sealed class RuleStopState : ATNState
{ {
public override int GetNonStopStateNumber() public override int NonStopStateNumber
{ {
return -1; get
{
return -1;
}
} }
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return RuleStop; get
{
return Antlr4.Runtime.Atn.StateType.RuleStop;
}
} }
} }
} }

View File

@ -57,11 +57,11 @@ namespace Antlr4.Runtime.Atn
this.followState = followState; this.followState = followState;
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return Rule; return Antlr4.Runtime.Atn.TransitionType.Rule;
} }
} }

View File

@ -51,11 +51,11 @@ namespace Antlr4.Runtime.Atn
this.set = set; this.set = set;
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return Set; return Antlr4.Runtime.Atn.TransitionType.Set;
} }
} }

View File

@ -36,9 +36,12 @@ namespace Antlr4.Runtime.Atn
/// <remarks>The block that begins a closure loop.</remarks> /// <remarks>The block that begins a closure loop.</remarks>
public sealed class StarBlockStartState : BlockStartState public sealed class StarBlockStartState : BlockStartState
{ {
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return StarBlockStart; get
{
return Antlr4.Runtime.Atn.StateType.StarBlockStart;
}
} }
} }
} }

View File

@ -36,9 +36,12 @@ namespace Antlr4.Runtime.Atn
{ {
public StarLoopbackState loopBackState; public StarLoopbackState loopBackState;
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return StarLoopEntry; get
{
return Antlr4.Runtime.Atn.StateType.StarLoopEntry;
}
} }
} }
} }

View File

@ -39,9 +39,12 @@ namespace Antlr4.Runtime.Atn
return (StarLoopEntryState)Transition(0).target; return (StarLoopEntryState)Transition(0).target;
} }
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return StarLoopBack; get
{
return Antlr4.Runtime.Atn.StateType.StarLoopBack;
}
} }
} }
} }

View File

@ -0,0 +1,51 @@
/*
* [The "BSD license"]
* Copyright (c) 2013 Terence Parr
* Copyright (c) 2013 Sam Harwell
* 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.
*/
using Antlr4.Runtime.Atn;
using Sharpen;
namespace Antlr4.Runtime.Atn
{
public enum StateType
{
InvalidType,
Basic,
RuleStart,
BlockStart,
PlusBlockStart,
StarBlockStart,
TokenStart,
RuleStop,
BlockEnd,
StarLoopBack,
StarLoopEntry,
PlusLoopBack,
LoopEnd
}
}

View File

@ -35,9 +35,12 @@ namespace Antlr4.Runtime.Atn
/// <summary>The Tokens rule start state linking to each lexer rule start state</summary> /// <summary>The Tokens rule start state linking to each lexer rule start state</summary>
public sealed class TokensStartState : DecisionState public sealed class TokensStartState : DecisionState
{ {
public override int GetStateType() public override Antlr4.Runtime.Atn.StateType StateType
{ {
return TokenStart; get
{
return Antlr4.Runtime.Atn.StateType.TokenStart;
}
} }
} }
} }

View File

@ -51,55 +51,34 @@ namespace Antlr4.Runtime.Atn
/// </remarks> /// </remarks>
public abstract class Transition public abstract class Transition
{ {
public const int Epsilon = 1;
public const int Range = 2;
public const int Rule = 3;
public const int Predicate = 4;
public const int Atom = 5;
public const int Action = 6;
public const int Set = 7;
public const int NotSet = 8;
public const int Wildcard = 9;
public const int Precedence = 10;
public static readonly IList<string> serializationNames = Sharpen.Collections.UnmodifiableList public static readonly IList<string> serializationNames = Sharpen.Collections.UnmodifiableList
(Arrays.AsList("INVALID", "EPSILON", "RANGE", "RULE", "PREDICATE", "ATOM", "ACTION" (Arrays.AsList("INVALID", "EPSILON", "RANGE", "RULE", "PREDICATE", "ATOM", "ACTION"
, "SET", "NOT_SET", "WILDCARD", "PRECEDENCE")); , "SET", "NOT_SET", "WILDCARD", "PRECEDENCE"));
private sealed class _Dictionary_86 : Dictionary<Type, int> private sealed class _Dictionary_74 : Dictionary<Type, Antlr4.Runtime.Atn.TransitionType
>
{ {
public _Dictionary_86() public _Dictionary_74()
{ {
{ {
// constants for serialization this.Put(typeof(EpsilonTransition), Antlr4.Runtime.Atn.TransitionType.Epsilon);
// e.g., {isType(input.LT(1))}? this.Put(typeof(RangeTransition), Antlr4.Runtime.Atn.TransitionType.Range);
// ~(A|B) or ~atom, wildcard, which convert to next 2 this.Put(typeof(RuleTransition), Antlr4.Runtime.Atn.TransitionType.Rule);
this.Put(typeof(EpsilonTransition), Antlr4.Runtime.Atn.Transition.Epsilon); this.Put(typeof(PredicateTransition), Antlr4.Runtime.Atn.TransitionType.Predicate
this.Put(typeof(RangeTransition), Antlr4.Runtime.Atn.Transition.Range);
this.Put(typeof(RuleTransition), Antlr4.Runtime.Atn.Transition.Rule);
this.Put(typeof(PredicateTransition), Antlr4.Runtime.Atn.Transition.Predicate);
this.Put(typeof(AtomTransition), Antlr4.Runtime.Atn.Transition.Atom);
this.Put(typeof(ActionTransition), Antlr4.Runtime.Atn.Transition.Action);
this.Put(typeof(SetTransition), Antlr4.Runtime.Atn.Transition.Set);
this.Put(typeof(NotSetTransition), Antlr4.Runtime.Atn.Transition.NotSet);
this.Put(typeof(WildcardTransition), Antlr4.Runtime.Atn.Transition.Wildcard);
this.Put(typeof(PrecedencePredicateTransition), Antlr4.Runtime.Atn.Transition.Precedence
); );
this.Put(typeof(AtomTransition), Antlr4.Runtime.Atn.TransitionType.Atom);
this.Put(typeof(ActionTransition), Antlr4.Runtime.Atn.TransitionType.Action);
this.Put(typeof(SetTransition), Antlr4.Runtime.Atn.TransitionType.Set);
this.Put(typeof(NotSetTransition), Antlr4.Runtime.Atn.TransitionType.NotSet);
this.Put(typeof(WildcardTransition), Antlr4.Runtime.Atn.TransitionType.Wildcard);
this.Put(typeof(PrecedencePredicateTransition), Antlr4.Runtime.Atn.TransitionType
.Precedence);
} }
} }
} }
public static readonly IDictionary<Type, int> serializationTypes = Sharpen.Collections public static readonly IDictionary<Type, Antlr4.Runtime.Atn.TransitionType> serializationTypes
.UnmodifiableMap(new _Dictionary_86()); = Sharpen.Collections.UnmodifiableMap(new _Dictionary_74());
/// <summary>The target of this transition.</summary> /// <summary>The target of this transition.</summary>
/// <remarks>The target of this transition.</remarks> /// <remarks>The target of this transition.</remarks>
@ -115,7 +94,7 @@ namespace Antlr4.Runtime.Atn
this.target = target; this.target = target;
} }
public abstract int SerializationType public abstract Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get; get;
} }

View File

@ -0,0 +1,49 @@
/*
* [The "BSD license"]
* Copyright (c) 2013 Terence Parr
* Copyright (c) 2013 Sam Harwell
* 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.
*/
using Antlr4.Runtime.Atn;
using Sharpen;
namespace Antlr4.Runtime.Atn
{
public enum TransitionType
{
Invalid,
Epsilon,
Range,
Rule,
Predicate,
Atom,
Action,
Set,
NotSet,
Wildcard,
Precedence
}
}

View File

@ -39,11 +39,11 @@ namespace Antlr4.Runtime.Atn
{ {
} }
public override int SerializationType public override Antlr4.Runtime.Atn.TransitionType TransitionType
{ {
get get
{ {
return Wildcard; return Antlr4.Runtime.Atn.TransitionType.Wildcard;
} }
} }

View File

@ -205,12 +205,12 @@ namespace Antlr4.Runtime
{ {
return; return;
} }
switch (s.GetStateType()) switch (s.StateType)
{ {
case ATNState.BlockStart: case StateType.BlockStart:
case ATNState.StarBlockStart: case StateType.StarBlockStart:
case ATNState.PlusBlockStart: case StateType.PlusBlockStart:
case ATNState.StarLoopEntry: case StateType.StarLoopEntry:
{ {
// report error and recover if possible // report error and recover if possible
if (SingleTokenDeletion(recognizer) != null) if (SingleTokenDeletion(recognizer) != null)
@ -220,8 +220,8 @@ namespace Antlr4.Runtime
throw new InputMismatchException(recognizer); throw new InputMismatchException(recognizer);
} }
case ATNState.PlusLoopBack: case StateType.PlusLoopBack:
case ATNState.StarLoopBack: case StateType.StarLoopBack:
{ {
// System.err.println("at loop back: "+s.getClass().getSimpleName()); // System.err.println("at loop back: "+s.getClass().getSimpleName());
ReportUnwantedToken(recognizer); ReportUnwantedToken(recognizer);

View File

@ -744,7 +744,7 @@ namespace Antlr4.Runtime.Misc
} }
foreach (Transition transition in state.GetTransitions()) foreach (Transition transition in state.GetTransitions())
{ {
if (transition.SerializationType != Transition.Rule) if (transition.TransitionType != TransitionType.Rule)
{ {
continue; continue;
} }

@ -1 +1 @@
Subproject commit 15c7bc6a2623747ddfb9e19d923d1119e9af538f Subproject commit 5cda16588918c8873c62abdeb9ce88e600e5d045