using System;
using System.Collections.Generic;
namespace Smokey
{
/// Contains all of the TypedInstructions in a method.
public class TypedInstructions : IFormattable, IEnumerable<TypedInstruction>
{
public TypedInstructions(MethodDefinition method)
{
m_method = method;
m_instructions = new List<TypedInstruction>(method.Body.Instructions.Count);
m_offsets = new Dictionary<int, TypedInstruction>(method.Body.Instructions.Count);
foreach (Instruction untyped in method.Body.Instructions)
{
TypedInstruction instruction = DoGetTyped(untyped);
m_instructions.Add(instruction);
m_offsets.Add(untyped.Offset, instruction);
}
DoFixBranches();
}
public MethodDefinition Method {get {return m_method;}}
public IEnumerator<TypedInstruction> GetEnumerator()
{
foreach (TypedInstruction instruction in m_instructions)
yield return instruction;
}
public IEnumerator<T> Match<T>() where T: TypedInstruction
{
foreach (TypedInstruction instruction in m_instructions)
{
T instance = instruction as T;
if (instance != null)
yield return instance;
}
}
// snip
}
// error: [csc] TypedInstructions.cs(7,22): error CS0535:
// `Smokey.TypedInstructions' does not implement interface member
// `System.Collections.IEnumerable.GetEnumerator()'