2010-03-17 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / ilasm / codegen / SwitchInstr.cs
index 2282a4194774739e1d72ae737fd16959fe8ba108..810e779628db8ccd0489308ec2f6038daf7655a2 100644 (file)
@@ -17,23 +17,29 @@ namespace Mono.ILASM {
 
                 private ArrayList label_list;
 
-                public SwitchInstr (ArrayList label_list)
+                public SwitchInstr (ArrayList label_list, Location loc)
+                       : base (loc)
                 {
                         this.label_list = label_list;
                 }
 
-                public void Emit (CodeGen code_gen, MethodDef meth, PEAPI.CILInstructions cil)
+                public override void Emit (CodeGen code_gen, MethodDef meth,
+                                          PEAPI.CILInstructions cil)
                 {
                         int count = 0;
-                        PEAPI.CILLabel[] label_array = new PEAPI.CILLabel[label_list.Count];
-
-                        foreach (object lab in label_list) {
-                                if (lab is string) {
-                                        label_array[count++] = meth.GetLabelDef ((string) lab);
-                                } else {
-                                        // TODO: int32 labels
-                                        throw new NotImplementedException ("offsets in switch statements.");
+                        PEAPI.CILLabel[] label_array;
+
+                        if (label_list != null) {
+                                label_array = new PEAPI.CILLabel[label_list.Count];
+                                foreach (object lab in label_list) {
+                                        if (lab is LabelInfo) {
+                                                label_array[count++] = ((LabelInfo)lab).Label;
+                                        } else {                                                
+                                                throw new InternalErrorException ("offsets in switch statements.");
+                                        }
                                 }
+                        } else {
+                                label_array = new PEAPI.CILLabel [0];
                         }
 
                         cil.Switch (label_array);