public override void DefineLabelPosition(ILLabel label)
{
if (label as DynamicILLabel == null)
throw new ArgumentNullException("label");
var label2 = (DynamicILLabel)label;
if (label2.ILGenerator != this)
throw new ArgumentException("The label wasn't created by this generator.", "label");
if (label2.ILOffset != -1)
throw new ArgumentException("The label position has already been defined.", "label");
label2.ILOffset = this.offset;
#if DEBUG
if (label2.EvaluationStack != null)
{
var previousStack = (VESType[])label2.EvaluationStack;
if (this.stackIsIndeterminate == false)
{
// Check the evaluation stack matches that in the label.
var currentStack = this.operands.ToArray();
if (previousStack.Length != currentStack.Length)
throw new InvalidOperationException(string.Format("Stack mismatch from a previous branch. Expected: '{0}' but was: '{1}'",
StringHelpers.Join(", ", previousStack), StringHelpers.Join(", ", currentStack)));
for (int i = 0; i < previousStack.Length; i++)
if (previousStack[i] != currentStack[i])
throw new InvalidOperationException(string.Format("Stack mismatch from a previous branch. Expected: '{0}' but was: '{1}'",
StringHelpers.Join(", ", previousStack), StringHelpers.Join(", ", currentStack)));
}
else
{
// Replace the evaluation stack with the one from the label.
this.stackSize = previousStack.Length;
this.operands.Clear();
for (int i = previousStack.Length - 1; i >= 0; i--)
this.operands.Push(previousStack[i]);
this.stackIsIndeterminate = false;
}
}
#else
if (label2.EvaluationStackSize >= 0)
{
if (this.stackIsIndeterminate == false)
{
// Check the number of items matches.
if (label2.EvaluationStackSize != this.stackSize)
throw new InvalidOperationException(string.Format("Stack size mismatch from a previous branch. Expected {0} items but found {1} items.",
label2.EvaluationStackSize, this.stackSize));
}
else
{
// Replace the evaluation stack with the one from the label.
this.stackSize = label2.EvaluationStackSize;
this.stackIsIndeterminate = false;
}
}
#endif
}