public AllocationScope Alloc(Type type) { Contract.Requires(type != null); List <int> localIndices; if (!localsByType.TryGetValue(type, out localIndices)) { localIndices = new List <int>(); localsByType.Add(type, localIndices); } int localIndex; if (localIndices.Count == 0) { string name = GetNextName(); createdCount++; localIndex = methodBodyWriter.DeclareLocal(type, name); } else { localIndex = localIndices[localIndices.Count - 1]; localIndices.RemoveAt(localIndices.Count - 1); } allocatedCount++; return(new AllocationScope(this, localIndex, type)); }
public override int DeclareLocal(Type type, bool pinned, string name) { if (type.IsByRef || type.IsGenericTypeDefinition) { throw Error("Cannot declare a local of type {0}.", type.FullName); } int index = locals.Count; locals.Add(new LocalInfo { Type = type, Name = name }); if (sink != null) { int sinkLocalIndex = sink.DeclareLocal(type, pinned, name); Contract.Assert(sinkLocalIndex == index); } return(index); }