protected override QilNode VisitChoice(QilChoice ndChoice) {
QilNode ndBranches;
Label[] switchLabels;
Label lblOtherwise, lblDone;
int regBranches, idx;
Debug.Assert(XmlILConstructInfo.Read(ndChoice).PushToWriterFirst);
// Evaluate the expression
NestedVisit(ndChoice.Expression);
// Generate switching code
ndBranches = ndChoice.Branches;
regBranches = ndBranches.Count - 1;
switchLabels = new Label[regBranches];
for (idx = 0; idx < regBranches; idx++)
switchLabels[idx] = this.helper.DefineLabel();
lblOtherwise = this.helper.DefineLabel();
lblDone = this.helper.DefineLabel();
// switch (value)
// case 0: goto Label[0];
// ...
// case N-1: goto Label[N-1];
// default: goto LabelOtherwise;
this.helper.Emit(OpCodes.Switch, switchLabels);
this.helper.EmitUnconditionalBranch(OpCodes.Br, lblOtherwise);
for (idx = 0; idx < regBranches; idx++) {
// Label[i]:
this.helper.MarkLabel(switchLabels[idx]);
// Generate regular branch code
NestedVisit(ndBranches[idx]);
// goto LabelDone
this.helper.EmitUnconditionalBranch(OpCodes.Br, lblDone);
}
// LabelOtherwise:
this.helper.MarkLabel(lblOtherwise);
// Generate otherwise branch code
NestedVisit(ndBranches[idx]);
// LabelDone:
this.helper.MarkLabel(lblDone);
this.iterCurr.Storage = StorageDescriptor.None();
return ndChoice;
}