Exemplo n.º 1
0
 /// <summary>
 /// Removes all modifiers and pinned sig
 /// </summary>
 /// <param name="a">The type</param>
 /// <returns>Inputer after modifiers and pinned signature</returns>
 public static TypeSig RemovePinnedAndModifiers(this TypeSig a)
 {
     a = a.RemoveModifiers();
     a = a.RemovePinned();
     a = a.RemoveModifiers();
     return(a);
 }
Exemplo n.º 2
0
        void AddPushDefaultValue(int count, ref int index, TypeSig pushType)
        {
            pushType = pushType.RemovePinned();
            switch (count > 10 ? ElementType.End : pushType.RemovePinnedAndModifiers().GetElementType()) {
            case ElementType.Void:
                break;

            case ElementType.Boolean:
            case ElementType.Char:
            case ElementType.I1:
            case ElementType.U1:
            case ElementType.I2:
            case ElementType.U2:
            case ElementType.I4:
            case ElementType.U4:
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Ldc_I4_0));
                break;

            case ElementType.I8:
            case ElementType.U8:
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Ldc_I4_0));
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Conv_I8));
                break;

            case ElementType.R4:
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Ldc_R4));
                break;

            case ElementType.R8:
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Ldc_R8));
                break;

            case ElementType.I:
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Ldc_I4_0));
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Conv_I));
                break;

            case ElementType.U:
            case ElementType.Ptr:
            case ElementType.FnPtr:
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Ldc_I4_0));
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Conv_U));
                break;

            case ElementType.ValueType:
                var td = ((ValueTypeSig)pushType).TypeDefOrRef.ResolveTypeDef();
                if (td != null && td.IsEnum) {
                    var undType = td.GetEnumUnderlyingType().RemovePinnedAndModifiers();
                    var et = undType.GetElementType();
                    if ((ElementType.Boolean <= et && et <= ElementType.R8) || et == ElementType.I || et == ElementType.U) {
                        AddPushDefaultValue(count + 1, ref index, undType);
                        break;
                    }
                }
                goto case ElementType.TypedByRef;

            case ElementType.TypedByRef:
            case ElementType.Var:
            case ElementType.MVar:
                var local = new LocalVM(typeSigCreatorOptions, new LocalOptions(new Local(pushType)));
                this.LocalsListVM.Add(local);

                var newInstr = CreateInstructionVM(Code.Ldloca);
                newInstr.InstructionOperandVM.OperandListItem = local;
                InstructionsListVM.Insert(index++, newInstr);

                newInstr = CreateInstructionVM(Code.Initobj);
                newInstr.InstructionOperandVM.Other = local.Type.ToTypeDefOrRef();
                InstructionsListVM.Insert(index++, newInstr);

                newInstr = CreateInstructionVM(Code.Ldloc);
                newInstr.InstructionOperandVM.OperandListItem = local;
                InstructionsListVM.Insert(index++, newInstr);
                break;

            case ElementType.GenericInst:
                if (((GenericInstSig)pushType).GenericType is ValueTypeSig)
                    goto case ElementType.TypedByRef;
                goto case ElementType.Class;

            case ElementType.End:
            case ElementType.String:
            case ElementType.ByRef:
            case ElementType.Class:
            case ElementType.Array:
            case ElementType.ValueArray:
            case ElementType.R:
            case ElementType.Object:
            case ElementType.SZArray:
            case ElementType.CModReqd:
            case ElementType.CModOpt:
            case ElementType.Internal:
            case ElementType.Module:
            case ElementType.Sentinel:
            case ElementType.Pinned:
            default:
                InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Ldnull));
                break;
            }
        }