Use IEnumerable

This commit is contained in:
Sam Harwell 2013-02-19 14:15:47 -06:00
parent 9a351761d6
commit 9e9be6427d
4 changed files with 24 additions and 8 deletions

View File

@ -33,11 +33,13 @@ using System.Text;
using Antlr4.Runtime.Atn; using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Misc; using Antlr4.Runtime.Misc;
using Sharpen; using Sharpen;
using IEnumerable = System.Collections.IEnumerable;
using IEnumerator = System.Collections.IEnumerator;
namespace Antlr4.Runtime.Atn namespace Antlr4.Runtime.Atn
{ {
/// <author>Sam Harwell</author> /// <author>Sam Harwell</author>
public class ATNConfigSet : ISet<ATNConfig> public class ATNConfigSet : IEnumerable<ATNConfig>
{ {
/// <summary> /// <summary>
/// This maps (state, alt) -&gt; merged /// This maps (state, alt) -&gt; merged
@ -301,7 +303,12 @@ namespace Antlr4.Runtime.Atn
public virtual IEnumerator<ATNConfig> GetEnumerator() public virtual IEnumerator<ATNConfig> GetEnumerator()
{ {
return new ATNConfigSet.ATNConfigSetIterator(this); return configs.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
} }
public virtual object[] ToArray() public virtual object[] ToArray()
@ -446,13 +453,12 @@ namespace Antlr4.Runtime.Atn
return true; return true;
} }
public virtual bool AddAll<_T0>(ICollection<_T0> c) where _T0:ATNConfig public virtual bool AddAll(IEnumerable<ATNConfig> c)
{ {
return AddAll(c, null); return AddAll(c, null);
} }
public virtual bool AddAll<_T0>(ICollection<_T0> c, PredictionContextCache contextCache public virtual bool AddAll(IEnumerable<ATNConfig> c, PredictionContextCache contextCache)
) where _T0:ATNConfig
{ {
EnsureWritable(); EnsureWritable();
bool changed = false; bool changed = false;

View File

@ -114,5 +114,15 @@ namespace Antlr4.Runtime.Dfa
public abstract int Size(); public abstract int Size();
public abstract IDictionary<int, T> ToMap(); public abstract IDictionary<int, T> ToMap();
public virtual IEnumerator<KeyValuePair<int, T>> GetEnumerator()
{
return ToMap().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
} }
} }

View File

@ -85,8 +85,8 @@ namespace Antlr4.Runtime.Dfa
states.Sort(new _IComparer_85()); states.Sort(new _IComparer_85());
foreach (DFAState s in states) foreach (DFAState s in states)
{ {
IDictionary<int, DFAState> edges = s.EdgeMap; IEnumerable<KeyValuePair<int, DFAState>> edges = s.EdgeMap;
IDictionary<int, DFAState> contextEdges = s.ContextEdgeMap; IEnumerable<KeyValuePair<int, DFAState>> contextEdges = s.ContextEdgeMap;
foreach (KeyValuePair<int, DFAState> entry in edges) foreach (KeyValuePair<int, DFAState> entry in edges)
{ {
if ((entry.Value == null || entry.Value == ATNSimulator.Error) && !s.IsContextSymbol if ((entry.Value == null || entry.Value == ATNSimulator.Error) && !s.IsContextSymbol

View File

@ -35,7 +35,7 @@ using Sharpen;
namespace Antlr4.Runtime.Dfa namespace Antlr4.Runtime.Dfa
{ {
/// <author>Sam Harwell</author> /// <author>Sam Harwell</author>
public interface IEdgeMap<T> public interface IEdgeMap<T> : IEnumerable<KeyValuePair<int, T>>
{ {
int Size(); int Size();