BitArray isn't a good replacement for BitSet, will need to provide a proper implementation

This commit is contained in:
Sam Harwell 2013-02-18 17:17:17 -06:00
parent a6bd78893d
commit b12aff16b0
13 changed files with 90 additions and 103 deletions

View File

@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
@ -82,7 +81,7 @@ namespace Antlr4.Runtime.Atn
private int uniqueAlt; private int uniqueAlt;
private BitArray conflictingAlts; private BitSet conflictingAlts;
private bool hasSemanticContext; private bool hasSemanticContext;
@ -160,13 +159,13 @@ namespace Antlr4.Runtime.Atn
/// set. /// set.
/// </remarks> /// </remarks>
[NotNull] [NotNull]
public virtual BitArray GetRepresentedAlternatives() public virtual BitSet GetRepresentedAlternatives()
{ {
if (conflictingAlts != null) if (conflictingAlts != null)
{ {
return (BitArray)conflictingAlts.Clone(); return (BitSet)conflictingAlts.Clone();
} }
BitArray alts = new BitArray(); BitSet alts = new BitSet();
foreach (ATNConfig config in this) foreach (ATNConfig config in this)
{ {
alts.Set(config.GetAlt()); alts.Set(config.GetAlt());
@ -605,7 +604,7 @@ namespace Antlr4.Runtime.Atn
hasSemanticContext = true; hasSemanticContext = true;
} }
public virtual BitArray ConflictingAlts public virtual BitSet ConflictingAlts
{ {
get get
{ {
@ -613,7 +612,7 @@ namespace Antlr4.Runtime.Atn
} }
set set
{ {
BitArray conflictingAlts = value; BitSet conflictingAlts = value;
EnsureWritable(); EnsureWritable();
this.conflictingAlts = conflictingAlts; this.conflictingAlts = conflictingAlts;
} }

View File

@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
@ -797,7 +796,7 @@ nextState_break: ;
{ {
return true; return true;
} }
BitArray reachable = new BitArray(atn.states.Count); BitSet reachable = new BitSet(atn.states.Count);
IDeque<ATNState> worklist = new ArrayDeque<ATNState>(); IDeque<ATNState> worklist = new ArrayDeque<ATNState>();
worklist.AddItem(transition.followState); worklist.AddItem(transition.followState);
while (!worklist.IsEmpty()) while (!worklist.IsEmpty())

View File

@ -27,7 +27,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Antlr4.Runtime; using Antlr4.Runtime;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
@ -544,7 +543,7 @@ namespace Antlr4.Runtime.Atn
{ {
input.Seek(startIndex); input.Seek(startIndex);
} }
BitArray predictions = EvalSemanticContext(s.predicates, outerContext, true); BitSet predictions = EvalSemanticContext(s.predicates, outerContext, true);
if (predictions.Cardinality() == 1) if (predictions.Cardinality() == 1)
{ {
return predictions.NextSetBit(0); return predictions.NextSetBit(0);
@ -575,8 +574,8 @@ namespace Antlr4.Runtime.Atn
{ {
input.Seek(startIndex); input.Seek(startIndex);
} }
BitArray alts = EvalSemanticContext(s.predicates, outerContext, reportAmbiguities BitSet alts = EvalSemanticContext(s.predicates, outerContext, reportAmbiguities &&
&& predictionMode == PredictionMode.LlExactAmbigDetection); predictionMode == PredictionMode.LlExactAmbigDetection);
switch (alts.Cardinality()) switch (alts.Cardinality())
{ {
case 0: case 0:
@ -725,7 +724,7 @@ namespace Antlr4.Runtime.Atn
input.Seek(startIndex); input.Seek(startIndex);
} }
// always use complete evaluation here since we'll want to retry with full context if still ambiguous // always use complete evaluation here since we'll want to retry with full context if still ambiguous
BitArray alts = EvalSemanticContext(predPredictions, outerContext, true); BitSet alts = EvalSemanticContext(predPredictions, outerContext, true);
if (alts.Cardinality() == 1) if (alts.Cardinality() == 1)
{ {
return alts.NextSetBit(0); return alts.NextSetBit(0);
@ -755,8 +754,8 @@ namespace Antlr4.Runtime.Atn
{ {
input.Seek(startIndex); input.Seek(startIndex);
} }
BitArray alts = EvalSemanticContext(D.predicates, outerContext, reportAmbiguities BitSet alts = EvalSemanticContext(D.predicates, outerContext, reportAmbiguities &&
&& predictionMode == PredictionMode.LlExactAmbigDetection); predictionMode == PredictionMode.LlExactAmbigDetection);
D.prediction = ATN.InvalidAltNumber; D.prediction = ATN.InvalidAltNumber;
switch (alts.Cardinality()) switch (alts.Cardinality())
{ {
@ -800,7 +799,7 @@ namespace Antlr4.Runtime.Atn
{ {
if (previous.s0 != null) if (previous.s0 != null)
{ {
BitArray alts = new BitArray(); BitSet alts = new BitSet();
foreach (ATNConfig config in previous.s0.configs) foreach (ATNConfig config in previous.s0.configs)
{ {
if (config.GetReachesIntoOuterContext() || config.GetState() is RuleStopState) if (config.GetReachesIntoOuterContext() || config.GetState() is RuleStopState)
@ -1137,7 +1136,7 @@ namespace Antlr4.Runtime.Atn
public virtual DFAState.PredPrediction[] PredicateDFAState(DFAState D, ATNConfigSet public virtual DFAState.PredPrediction[] PredicateDFAState(DFAState D, ATNConfigSet
configs, int nalts) configs, int nalts)
{ {
BitArray conflictingAlts = GetConflictingAltsFromConfigSet(configs); BitSet conflictingAlts = GetConflictingAltsFromConfigSet(configs);
SemanticContext[] altToPred = GetPredsForAmbigAlts(conflictingAlts, configs, nalts SemanticContext[] altToPred = GetPredsForAmbigAlts(conflictingAlts, configs, nalts
); );
// altToPred[uniqueAlt] is now our validating predicate (if any) // altToPred[uniqueAlt] is now our validating predicate (if any)
@ -1154,7 +1153,7 @@ namespace Antlr4.Runtime.Atn
return predPredictions; return predPredictions;
} }
public virtual SemanticContext[] GetPredsForAmbigAlts(BitArray ambigAlts, ATNConfigSet public virtual SemanticContext[] GetPredsForAmbigAlts(BitSet ambigAlts, ATNConfigSet
configs, int nalts) configs, int nalts)
{ {
// REACH=[1|1|[]|0:0, 1|2|[]|0:1] // REACH=[1|1|[]|0:0, 1|2|[]|0:1]
@ -1191,7 +1190,7 @@ namespace Antlr4.Runtime.Atn
return altToPred; return altToPred;
} }
public virtual DFAState.PredPrediction[] GetPredicatePredictions(BitArray ambigAlts public virtual DFAState.PredPrediction[] GetPredicatePredictions(BitSet ambigAlts
, SemanticContext[] altToPred) , SemanticContext[] altToPred)
{ {
IList<DFAState.PredPrediction> pairs = new List<DFAState.PredPrediction>(); IList<DFAState.PredPrediction> pairs = new List<DFAState.PredPrediction>();
@ -1239,10 +1238,10 @@ namespace Antlr4.Runtime.Atn
/// predicate indicates an alt containing an /// predicate indicates an alt containing an
/// unpredicated config which behaves as "always true." /// unpredicated config which behaves as "always true."
/// </remarks> /// </remarks>
public virtual BitArray EvalSemanticContext(DFAState.PredPrediction[] predPredictions public virtual BitSet EvalSemanticContext(DFAState.PredPrediction[] predPredictions
, ParserRuleContext outerContext, bool complete) , ParserRuleContext outerContext, bool complete)
{ {
BitArray predictions = new BitArray(); BitSet predictions = new BitSet();
foreach (DFAState.PredPrediction pair in predPredictions) foreach (DFAState.PredPrediction pair in predPredictions)
{ {
if (pair.pred == null) if (pair.pred == null)
@ -1612,7 +1611,7 @@ namespace Antlr4.Runtime.Atn
private static readonly IComparer<ATNConfig> StateAltSortComparator = new _IComparer_1557 private static readonly IComparer<ATNConfig> StateAltSortComparator = new _IComparer_1557
(); ();
private BitArray IsConflicted(ATNConfigSet configset, PredictionContextCache contextCache private BitSet IsConflicted(ATNConfigSet configset, PredictionContextCache contextCache
) )
{ {
if (configset.UniqueAlt != ATN.InvalidAltNumber || configset.Count <= 1) if (configset.UniqueAlt != ATN.InvalidAltNumber || configset.Count <= 1)
@ -1623,7 +1622,7 @@ namespace Antlr4.Runtime.Atn
configs.Sort(StateAltSortComparator); configs.Sort(StateAltSortComparator);
bool exact = !configset.DipsIntoOuterContext && predictionMode == PredictionMode. bool exact = !configset.DipsIntoOuterContext && predictionMode == PredictionMode.
LlExactAmbigDetection; LlExactAmbigDetection;
BitArray alts = new BitArray(); BitSet alts = new BitSet();
int minAlt = configs[0].GetAlt(); int minAlt = configs[0].GetAlt();
alts.Set(minAlt); alts.Set(minAlt);
// 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
@ -1643,12 +1642,12 @@ namespace Antlr4.Runtime.Atn
currentState = stateNumber; currentState = stateNumber;
} }
} }
BitArray representedAlts = null; BitSet representedAlts = null;
if (exact) if (exact)
{ {
currentState = configs[0].GetState().NonStopStateNumber; 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 BitSet();
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++)
{ {
@ -1799,19 +1798,19 @@ namespace Antlr4.Runtime.Atn
return alts; return alts;
} }
protected internal virtual BitArray GetConflictingAltsFromConfigSet(ATNConfigSet protected internal virtual BitSet GetConflictingAltsFromConfigSet(ATNConfigSet configs
configs) )
{ {
BitArray conflictingAlts = configs.ConflictingAlts; BitSet conflictingAlts = configs.ConflictingAlts;
if (conflictingAlts == null && configs.UniqueAlt != ATN.InvalidAltNumber) if (conflictingAlts == null && configs.UniqueAlt != ATN.InvalidAltNumber)
{ {
conflictingAlts = new BitArray(); conflictingAlts = new BitSet();
conflictingAlts.Set(configs.UniqueAlt); conflictingAlts.Set(configs.UniqueAlt);
} }
return conflictingAlts; return conflictingAlts;
} }
protected internal virtual int ResolveToMinAlt(DFAState D, BitArray conflictingAlts protected internal virtual int ResolveToMinAlt(DFAState D, BitSet conflictingAlts
) )
{ {
// kill dead alts so we don't chase them ever // kill dead alts so we don't chase them ever
@ -2112,7 +2111,7 @@ namespace Antlr4.Runtime.Atn
/// <summary>If context sensitive parsing, we know it's ambiguity not conflict</summary> /// <summary>If context sensitive parsing, we know it's ambiguity not conflict</summary>
public virtual void ReportAmbiguity(DFA dfa, DFAState D, int startIndex, int stopIndex public virtual void ReportAmbiguity(DFA dfa, DFAState D, int startIndex, int stopIndex
, BitArray ambigAlts, ATNConfigSet configs) , BitSet ambigAlts, ATNConfigSet configs)
{ {
if (debug || retry_debug) if (debug || retry_debug)
{ {

View File

@ -27,7 +27,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Misc; using Antlr4.Runtime.Misc;
@ -77,7 +76,7 @@ namespace Antlr4.Runtime.Atn
/// <summary>A Map that uses just the state and the stack context as the key.</summary> /// <summary>A Map that uses just the state and the stack context as the key.</summary>
/// <remarks>A Map that uses just the state and the stack context as the key.</remarks> /// <remarks>A Map that uses just the state and the stack context as the key.</remarks>
internal class AltAndContextMap : Dictionary<ATNConfig, BitArray> internal class AltAndContextMap : Dictionary<ATNConfig, BitSet>
{ {
public AltAndContextMap() : base(PredictionMode.AltAndContextConfigEqualityComparator public AltAndContextMap() : base(PredictionMode.AltAndContextConfigEqualityComparator
.Instance) .Instance)
@ -268,7 +267,7 @@ namespace Antlr4.Runtime.Atn
} }
// now we have combined contexts for configs with dissimilar preds // now we have combined contexts for configs with dissimilar preds
// pure SLL or combined SLL+LL mode parsing // pure SLL or combined SLL+LL mode parsing
ICollection<BitArray> altsets = GetConflictingAltSubsets(configs); ICollection<BitSet> altsets = GetConflictingAltSubsets(configs);
bool heuristic = HasConflictingAltSet(altsets) && !HasStateAssociatedWithOneAlt(configs bool heuristic = HasConflictingAltSet(altsets) && !HasStateAssociatedWithOneAlt(configs
); );
return heuristic; return heuristic;
@ -645,7 +644,7 @@ namespace Antlr4.Runtime.Atn
/// ///
/// {1,2},{1,2}}}, etc... /// {1,2},{1,2}}}, etc...
/// </remarks> /// </remarks>
public static int ResolvesToJustOneViableAlt(ICollection<BitArray> altsets) public static int ResolvesToJustOneViableAlt(ICollection<BitSet> altsets)
{ {
return GetSingleViableAlt(altsets); return GetSingleViableAlt(altsets);
} }
@ -661,15 +660,15 @@ namespace Antlr4.Runtime.Atn
/// ///
/// <code>true</code> /// <code>true</code>
/// if every /// if every
/// <see cref="System.Collections.BitArray">System.Collections.BitArray</see> /// <see cref="Sharpen.BitSet">Sharpen.BitSet</see>
/// in /// in
/// <code>altsets</code> /// <code>altsets</code>
/// has /// has
/// <see cref="System.Collections.BitArray.Cardinality()">cardinality</see> /// <see cref="Sharpen.BitSet.Cardinality()">cardinality</see>
/// &gt; 1, otherwise /// &gt; 1, otherwise
/// <code>false</code> /// <code>false</code>
/// </returns> /// </returns>
public static bool AllSubsetsConflict(ICollection<BitArray> altsets) public static bool AllSubsetsConflict(ICollection<BitSet> altsets)
{ {
return !HasNonConflictingAltSet(altsets); return !HasNonConflictingAltSet(altsets);
} }
@ -687,15 +686,15 @@ namespace Antlr4.Runtime.Atn
/// if /// if
/// <code>altsets</code> /// <code>altsets</code>
/// contains a /// contains a
/// <see cref="System.Collections.BitArray">System.Collections.BitArray</see> /// <see cref="Sharpen.BitSet">Sharpen.BitSet</see>
/// with /// with
/// <see cref="System.Collections.BitArray.Cardinality()">cardinality</see> /// <see cref="Sharpen.BitSet.Cardinality()">cardinality</see>
/// 1, otherwise /// 1, otherwise
/// <code>false</code> /// <code>false</code>
/// </returns> /// </returns>
public static bool HasNonConflictingAltSet(ICollection<BitArray> altsets) public static bool HasNonConflictingAltSet(ICollection<BitSet> altsets)
{ {
foreach (BitArray alts in altsets) foreach (BitSet alts in altsets)
{ {
if (alts.Cardinality() == 1) if (alts.Cardinality() == 1)
{ {
@ -718,15 +717,15 @@ namespace Antlr4.Runtime.Atn
/// if /// if
/// <code>altsets</code> /// <code>altsets</code>
/// contains a /// contains a
/// <see cref="System.Collections.BitArray">System.Collections.BitArray</see> /// <see cref="Sharpen.BitSet">Sharpen.BitSet</see>
/// with /// with
/// <see cref="System.Collections.BitArray.Cardinality()">cardinality</see> /// <see cref="Sharpen.BitSet.Cardinality()">cardinality</see>
/// &gt; 1, otherwise /// &gt; 1, otherwise
/// <code>false</code> /// <code>false</code>
/// </returns> /// </returns>
public static bool HasConflictingAltSet(ICollection<BitArray> altsets) public static bool HasConflictingAltSet(ICollection<BitSet> altsets)
{ {
foreach (BitArray alts in altsets) foreach (BitSet alts in altsets)
{ {
if (alts.Cardinality() > 1) if (alts.Cardinality() > 1)
{ {
@ -751,13 +750,13 @@ namespace Antlr4.Runtime.Atn
/// others, otherwise /// others, otherwise
/// <code>false</code> /// <code>false</code>
/// </returns> /// </returns>
public static bool AllSubsetsEqual(ICollection<BitArray> altsets) public static bool AllSubsetsEqual(ICollection<BitSet> altsets)
{ {
IEnumerator<BitArray> it = altsets.GetEnumerator(); IEnumerator<BitSet> it = altsets.GetEnumerator();
BitArray first = it.Next(); BitSet first = it.Next();
while (it.HasNext()) while (it.HasNext())
{ {
BitArray next = it.Next(); BitSet next = it.Next();
if (!next.Equals(first)) if (!next.Equals(first))
{ {
return false; return false;
@ -774,9 +773,9 @@ namespace Antlr4.Runtime.Atn
/// . /// .
/// </summary> /// </summary>
/// <param name="altsets">a collection of alternative subsets</param> /// <param name="altsets">a collection of alternative subsets</param>
public static int GetUniqueAlt(ICollection<BitArray> altsets) public static int GetUniqueAlt(ICollection<BitSet> altsets)
{ {
BitArray all = GetAlts(altsets); BitSet all = GetAlts(altsets);
if (all.Cardinality() == 1) if (all.Cardinality() == 1)
{ {
return all.NextSetBit(0); return all.NextSetBit(0);
@ -791,7 +790,7 @@ namespace Antlr4.Runtime.Atn
/// <remarks> /// <remarks>
/// Gets the complete set of represented alternatives for a collection of /// Gets the complete set of represented alternatives for a collection of
/// alternative subsets. This method returns the union of each /// alternative subsets. This method returns the union of each
/// <see cref="System.Collections.BitArray">System.Collections.BitArray</see> /// <see cref="Sharpen.BitSet">Sharpen.BitSet</see>
/// in /// in
/// <code>altsets</code> /// <code>altsets</code>
/// . /// .
@ -801,10 +800,10 @@ namespace Antlr4.Runtime.Atn
/// the set of represented alternatives in /// the set of represented alternatives in
/// <code>altsets</code> /// <code>altsets</code>
/// </returns> /// </returns>
public static BitArray GetAlts(ICollection<BitArray> altsets) public static BitSet GetAlts(ICollection<BitSet> altsets)
{ {
BitArray all = new BitArray(); BitSet all = new BitSet();
foreach (BitArray alts in altsets) foreach (BitSet alts in altsets)
{ {
all.Or(alts); all.Or(alts);
} }
@ -828,17 +827,16 @@ namespace Antlr4.Runtime.Atn
/// </pre> /// </pre>
/// </remarks> /// </remarks>
[NotNull] [NotNull]
public static ICollection<BitArray> GetConflictingAltSubsets(ATNConfigSet configs public static ICollection<BitSet> GetConflictingAltSubsets(ATNConfigSet configs)
)
{ {
PredictionMode.AltAndContextMap configToAlts = new PredictionMode.AltAndContextMap PredictionMode.AltAndContextMap configToAlts = new PredictionMode.AltAndContextMap
(); ();
foreach (ATNConfig c in configs) foreach (ATNConfig c in configs)
{ {
BitArray alts = configToAlts.Get(c); BitSet alts = configToAlts.Get(c);
if (alts == null) if (alts == null)
{ {
alts = new BitArray(); alts = new BitSet();
configToAlts.Put(c, alts); configToAlts.Put(c, alts);
} }
alts.Set(c.GetAlt()); alts.Set(c.GetAlt());
@ -862,16 +860,16 @@ namespace Antlr4.Runtime.Atn
/// </pre> /// </pre>
/// </remarks> /// </remarks>
[NotNull] [NotNull]
public static IDictionary<ATNState, BitArray> GetStateToAltMap(ATNConfigSet configs public static IDictionary<ATNState, BitSet> GetStateToAltMap(ATNConfigSet configs
) )
{ {
IDictionary<ATNState, BitArray> m = new Dictionary<ATNState, BitArray>(); IDictionary<ATNState, BitSet> m = new Dictionary<ATNState, BitSet>();
foreach (ATNConfig c in configs) foreach (ATNConfig c in configs)
{ {
BitArray alts = m.Get(c.GetState()); BitSet alts = m.Get(c.GetState());
if (alts == null) if (alts == null)
{ {
alts = new BitArray(); alts = new BitSet();
m.Put(c.GetState(), alts); m.Put(c.GetState(), alts);
} }
alts.Set(c.GetAlt()); alts.Set(c.GetAlt());
@ -881,8 +879,8 @@ namespace Antlr4.Runtime.Atn
public static bool HasStateAssociatedWithOneAlt(ATNConfigSet configs) public static bool HasStateAssociatedWithOneAlt(ATNConfigSet configs)
{ {
IDictionary<ATNState, BitArray> x = GetStateToAltMap(configs); IDictionary<ATNState, BitSet> x = GetStateToAltMap(configs);
foreach (BitArray alts in x.Values) foreach (BitSet alts in x.Values)
{ {
if (alts.Cardinality() == 1) if (alts.Cardinality() == 1)
{ {
@ -892,10 +890,10 @@ namespace Antlr4.Runtime.Atn
return false; return false;
} }
public static int GetSingleViableAlt(ICollection<BitArray> altsets) public static int GetSingleViableAlt(ICollection<BitSet> altsets)
{ {
BitArray viableAlts = new BitArray(); BitSet viableAlts = new BitSet();
foreach (BitArray alts in altsets) foreach (BitSet alts in altsets)
{ {
int minAlt = alts.NextSetBit(0); int minAlt = alts.NextSetBit(0);
viableAlts.Set(minAlt); viableAlts.Set(minAlt);

View File

@ -367,9 +367,8 @@ namespace Antlr4.Runtime.Atn
return result; return result;
} }
/// <seealso cref="ParserATNSimulator.GetPredsForAmbigAlts(System.Collections.BitArray, ATNConfigSet, int) /// <seealso cref="ParserATNSimulator.GetPredsForAmbigAlts(Sharpen.BitSet, ATNConfigSet, int)
/// ">ParserATNSimulator.GetPredsForAmbigAlts(System.Collections.BitArray, ATNConfigSet, int) /// ">ParserATNSimulator.GetPredsForAmbigAlts(Sharpen.BitSet, ATNConfigSet, int)</seealso>
/// </seealso>
public static SemanticContext Or(SemanticContext a, SemanticContext b) public static SemanticContext Or(SemanticContext a, SemanticContext b)
{ {
if (a == null) if (a == null)

View File

@ -27,7 +27,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System.Collections;
using Antlr4.Runtime; using Antlr4.Runtime;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Dfa; using Antlr4.Runtime.Dfa;
@ -45,7 +44,7 @@ namespace Antlr4.Runtime
} }
public virtual void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int public virtual void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int
stopIndex, BitArray ambigAlts, ATNConfigSet configs) stopIndex, BitSet ambigAlts, ATNConfigSet configs)
{ {
} }

View File

@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Antlr4.Runtime; using Antlr4.Runtime;
@ -382,7 +381,7 @@ namespace Antlr4.Runtime
/// if no tokens were found. This /// if no tokens were found. This
/// method looks at both on and off channel tokens. /// method looks at both on and off channel tokens.
/// </summary> /// </summary>
public virtual IList<IToken> GetTokens(int start, int stop, BitArray types) public virtual IList<IToken> GetTokens(int start, int stop, BitSet types)
{ {
LazyInit(); LazyInit();
if (start < 0 || stop >= tokens.Count || stop < 0 || start >= tokens.Count) if (start < 0 || stop >= tokens.Count || stop < 0 || start >= tokens.Count)
@ -413,7 +412,7 @@ namespace Antlr4.Runtime
public virtual IList<IToken> GetTokens(int start, int stop, int ttype) public virtual IList<IToken> GetTokens(int start, int stop, int ttype)
{ {
BitArray s = new BitArray(ttype); BitSet s = new BitSet(ttype);
s.Set(ttype); s.Set(ttype);
return GetTokens(start, stop, s); return GetTokens(start, stop, s);
} }

View File

@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
@ -112,7 +111,7 @@ namespace Antlr4.Runtime.Dfa
/// <remarks>Symbols in this set require a global context transition before matching an input symbol. /// <remarks>Symbols in this set require a global context transition before matching an input symbol.
/// </remarks> /// </remarks>
[Nullable] [Nullable]
private BitArray contextSymbols; private BitSet contextSymbols;
/// <summary> /// <summary>
/// This list is computed by /// This list is computed by
@ -191,7 +190,7 @@ namespace Antlr4.Runtime.Dfa
{ {
return; return;
} }
contextSymbols = new BitArray(); contextSymbols = new BitSet();
contextEdges = new SingletonEdgeMap<DFAState>(-1, atn.states.Count - 1); contextEdges = new SingletonEdgeMap<DFAState>(-1, atn.states.Count - 1);
} }
} }

View File

@ -27,7 +27,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System.Collections;
using Antlr4.Runtime; using Antlr4.Runtime;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Dfa; using Antlr4.Runtime.Dfa;
@ -39,7 +38,7 @@ namespace Antlr4.Runtime
public class DiagnosticErrorListener : BaseErrorListener public class DiagnosticErrorListener : BaseErrorListener
{ {
public override void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, public override void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex,
int stopIndex, BitArray ambigAlts, ATNConfigSet configs) int stopIndex, BitSet ambigAlts, ATNConfigSet configs)
{ {
string format = "reportAmbiguity d=%s: ambigAlts=%s, input='%s'"; string format = "reportAmbiguity d=%s: ambigAlts=%s, input='%s'";
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer

View File

@ -27,7 +27,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System.Collections;
using Antlr4.Runtime; using Antlr4.Runtime;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Dfa; using Antlr4.Runtime.Dfa;
@ -50,7 +49,7 @@ namespace Antlr4.Runtime
/// that can match the input sequence. This method is only called when we are parsing with /// that can match the input sequence. This method is only called when we are parsing with
/// full context. /// full context.
/// </remarks> /// </remarks>
void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, BitArray void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, BitSet
ambigAlts, ATNConfigSet configs); ambigAlts, ATNConfigSet configs);
void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int

View File

@ -170,12 +170,12 @@ namespace Antlr4.Runtime.Misc
EnumSet<Dependents> dependents = EnumSet.Of(Dependents.Self, dependency.Item1.Dependents EnumSet<Dependents> dependents = EnumSet.Of(Dependents.Self, dependency.Item1.Dependents
()); ());
ReportUnimplementedDependents(dependency, dependents); ReportUnimplementedDependents(dependency, dependents);
BitArray checked = new BitArray(); BitSet checked = new BitSet();
int highestRequiredDependency = CheckDependencyVersion(dependency, ruleNames, ruleVersions int highestRequiredDependency = CheckDependencyVersion(dependency, ruleNames, ruleVersions
, effectiveRule, null); , effectiveRule, null);
if (dependents.Contains(Dependents.Parents)) if (dependents.Contains(Dependents.Parents))
{ {
BitArray parents = relations.parents[dependency.Item1.Rule()]; BitSet parents = relations.parents[dependency.Item1.Rule()];
for (int parent = parents.NextSetBit(0); parent >= 0; parent = parents.NextSetBit for (int parent = parents.NextSetBit(0); parent >= 0; parent = parents.NextSetBit
(parent + 1)) (parent + 1))
{ {
@ -191,7 +191,7 @@ namespace Antlr4.Runtime.Misc
} }
if (dependents.Contains(Dependents.Children)) if (dependents.Contains(Dependents.Children))
{ {
BitArray children = relations.children[dependency.Item1.Rule()]; BitSet children = relations.children[dependency.Item1.Rule()];
for (int child = children.NextSetBit(0); child >= 0; child = children.NextSetBit( for (int child = children.NextSetBit(0); child >= 0; child = children.NextSetBit(
child + 1)) child + 1))
{ {
@ -207,7 +207,7 @@ namespace Antlr4.Runtime.Misc
} }
if (dependents.Contains(Dependents.Ancestors)) if (dependents.Contains(Dependents.Ancestors))
{ {
BitArray ancestors = relations.GetAncestors(dependency.Item1.Rule()); BitSet ancestors = relations.GetAncestors(dependency.Item1.Rule());
for (int ancestor = ancestors.NextSetBit(0); ancestor >= 0; ancestor = ancestors. for (int ancestor = ancestors.NextSetBit(0); ancestor >= 0; ancestor = ancestors.
NextSetBit(ancestor + 1)) NextSetBit(ancestor + 1))
{ {
@ -223,7 +223,7 @@ namespace Antlr4.Runtime.Misc
} }
if (dependents.Contains(Dependents.Descendants)) if (dependents.Contains(Dependents.Descendants))
{ {
BitArray descendants = relations.GetDescendants(dependency.Item1.Rule()); BitSet descendants = relations.GetDescendants(dependency.Item1.Rule());
for (int descendant = descendants.NextSetBit(0); descendant >= 0; descendant = descendants for (int descendant = descendants.NextSetBit(0); descendant >= 0; descendant = descendants
.NextSetBit(descendant + 1)) .NextSetBit(descendant + 1))
{ {
@ -780,21 +780,21 @@ namespace Antlr4.Runtime.Misc
private sealed class RuleRelations private sealed class RuleRelations
{ {
private readonly BitArray[] parents; private readonly BitSet[] parents;
private readonly BitArray[] children; private readonly BitSet[] children;
public RuleRelations(int ruleCount) public RuleRelations(int ruleCount)
{ {
parents = new BitArray[ruleCount]; parents = new BitSet[ruleCount];
for (int i = 0; i < ruleCount; i++) for (int i = 0; i < ruleCount; i++)
{ {
parents[i] = new BitArray(); parents[i] = new BitSet();
} }
children = new BitArray[ruleCount]; children = new BitSet[ruleCount];
for (int i_1 = 0; i_1 < ruleCount; i_1++) for (int i_1 = 0; i_1 < ruleCount; i_1++)
{ {
children[i_1] = new BitArray(); children[i_1] = new BitSet();
} }
} }
@ -815,9 +815,9 @@ namespace Antlr4.Runtime.Misc
return true; return true;
} }
public BitArray GetAncestors(int rule) public BitSet GetAncestors(int rule)
{ {
BitArray ancestors = new BitArray(); BitSet ancestors = new BitSet();
ancestors.Or(parents[rule]); ancestors.Or(parents[rule]);
while (true) while (true)
{ {
@ -835,9 +835,9 @@ namespace Antlr4.Runtime.Misc
return ancestors; return ancestors;
} }
public BitArray GetDescendants(int rule) public BitSet GetDescendants(int rule)
{ {
BitArray descendants = new BitArray(); BitSet descendants = new BitSet();
descendants.Or(children[rule]); descendants.Or(children[rule]);
while (true) while (true)
{ {

View File

@ -27,7 +27,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Antlr4.Runtime; using Antlr4.Runtime;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
@ -45,7 +44,7 @@ namespace Antlr4.Runtime
} }
public virtual void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int public virtual void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int
stopIndex, BitArray ambigAlts, ATNConfigSet configs) stopIndex, BitSet ambigAlts, ATNConfigSet configs)
{ {
foreach (IAntlrErrorListener<IToken> listener in GetDelegates()) foreach (IAntlrErrorListener<IToken> listener in GetDelegates())
{ {

View File

@ -120,7 +120,6 @@
-typeMapping java.net.InetAddress System.Net.IPAddress -typeMapping java.net.InetAddress System.Net.IPAddress
-typeMapping java.util.TimeZone System.TimeZoneInfo -typeMapping java.util.TimeZone System.TimeZoneInfo
-typeMapping java.util.ArrayList<> System.Collections.Generic.List -typeMapping java.util.ArrayList<> System.Collections.Generic.List
-typeMapping java.util.BitSet System.Collections.BitArray
-typeMapping java.util.zip.Inflater ICSharpCode.SharpZipLib.Zip.Compression.Inflater -typeMapping java.util.zip.Inflater ICSharpCode.SharpZipLib.Zip.Compression.Inflater
-typeMapping java.util.zip.Deflater ICSharpCode.SharpZipLib.Zip.Compression.Deflater -typeMapping java.util.zip.Deflater ICSharpCode.SharpZipLib.Zip.Compression.Deflater
-typeMapping java.util.zip.ZipException ICSharpCode.SharpZipLib.SharpZipBaseException -typeMapping java.util.zip.ZipException ICSharpCode.SharpZipLib.SharpZipBaseException