Пример #1
0
        public PredefinedMembers(ModuleContainer module)
        {
            var types  = module.PredefinedTypes;
            var atypes = module.PredefinedAttributes;
            var btypes = module.Compiler.BuiltinTypes;

            ActivatorCreateInstance = new PredefinedMember <MethodSpec> (module, types.Activator,
                                                                         MemberFilter.Method("CreateInstance", 1, ParametersCompiled.EmptyReadOnlyParameters, null));

            AsyncTaskMethodBuilderCreate = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilder,
                                                                              MemberFilter.Method("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncTaskMethodBuilder.TypeSpec));

            AsyncTaskMethodBuilderSetResult = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilder,
                                                                                 MemberFilter.Method("SetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, btypes.Void));

            AsyncTaskMethodBuilderTask = new PredefinedMember <PropertySpec> (module, types.AsyncTaskMethodBuilder,
                                                                              MemberFilter.Property("Task", null));

            AsyncTaskMethodBuilderGenericCreate = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
                                                                                     MemberFilter.Method("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncVoidMethodBuilder.TypeSpec));

            AsyncTaskMethodBuilderGenericSetResult = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
                                                                                        MemberFilter.Method("SetResult", 0,
                                                                                                            new ParametersImported(
                                                                                                                new[] {
                new ParameterData(null, Parameter.Modifier.NONE)
            },
                                                                                                                new[] {
                new TypeParameterSpec(0, null, SpecialConstraint.None, Variance.None, null)
            }, false), btypes.Void));

            AsyncTaskMethodBuilderGenericTask = new PredefinedMember <PropertySpec> (module, types.AsyncTaskMethodBuilderGeneric,
                                                                                     MemberFilter.Property("Task", null));

            AsyncVoidMethodBuilderCreate = new PredefinedMember <MethodSpec> (module, types.AsyncVoidMethodBuilder,
                                                                              MemberFilter.Method("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncVoidMethodBuilder.TypeSpec));

            AsyncVoidMethodBuilderSetException = new PredefinedMember <MethodSpec> (module, types.AsyncVoidMethodBuilder,
                                                                                    MemberFilter.Method("SetException", 0, null, btypes.Void));

            AsyncVoidMethodBuilderSetResult = new PredefinedMember <MethodSpec> (module, types.AsyncVoidMethodBuilder,
                                                                                 MemberFilter.Method("SetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, btypes.Void));

            DecimalCtor = new PredefinedMember <MethodSpec> (module, btypes.Decimal,
                                                             MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(
                                                                                          btypes.Int, btypes.Int, btypes.Int, btypes.Bool, btypes.Byte)));

            DecimalCtorInt = new PredefinedMember <MethodSpec> (module, btypes.Decimal,
                                                                MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.Int)));

            DecimalCtorLong = new PredefinedMember <MethodSpec> (module, btypes.Decimal,
                                                                 MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.Long)));

            DecimalConstantAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.DecimalConstant,
                                                                              MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(
                                                                                                           btypes.Byte, btypes.Byte, btypes.UInt, btypes.UInt, btypes.UInt)));

            DefaultMemberAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.DefaultMember,
                                                                            MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.String)));

            DelegateCombine = new PredefinedMember <MethodSpec> (module, btypes.Delegate, "Combine", btypes.Delegate, btypes.Delegate);
            DelegateRemove  = new PredefinedMember <MethodSpec> (module, btypes.Delegate, "Remove", btypes.Delegate, btypes.Delegate);

            DelegateEqual = new PredefinedMember <MethodSpec> (module, btypes.Delegate,
                                                               new MemberFilter(Operator.GetMetadataName(Operator.OpType.Equality), 0, MemberKind.Operator, null, btypes.Bool));

            DelegateInequal = new PredefinedMember <MethodSpec> (module, btypes.Delegate,
                                                                 new MemberFilter(Operator.GetMetadataName(Operator.OpType.Inequality), 0, MemberKind.Operator, null, btypes.Bool));

            DynamicAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.Dynamic,
                                                                      MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(
                                                                                                   ArrayContainer.MakeType(module, btypes.Bool))));

            FieldInfoGetFieldFromHandle = new PredefinedMember <MethodSpec> (module, types.FieldInfo,
                                                                             "GetFieldFromHandle", MemberKind.Method, types.RuntimeFieldHandle);

            FieldInfoGetFieldFromHandle2 = new PredefinedMember <MethodSpec> (module, types.FieldInfo,
                                                                              "GetFieldFromHandle", MemberKind.Method, types.RuntimeFieldHandle, new PredefinedType(btypes.RuntimeTypeHandle));

            FixedBufferAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.FixedBuffer,
                                                                          MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.Type, btypes.Int)));

            IDisposableDispose = new PredefinedMember <MethodSpec> (module, btypes.IDisposable, "Dispose", TypeSpec.EmptyTypes);

            IEnumerableGetEnumerator = new PredefinedMember <MethodSpec> (module, btypes.IEnumerable,
                                                                          "GetEnumerator", TypeSpec.EmptyTypes);

            InterlockedCompareExchange = new PredefinedMember <MethodSpec> (module, types.Interlocked,
                                                                            MemberFilter.Method("CompareExchange", 0,
                                                                                                new ParametersImported(
                                                                                                    new[] {
                new ParameterData(null, Parameter.Modifier.REF),
                new ParameterData(null, Parameter.Modifier.NONE),
                new ParameterData(null, Parameter.Modifier.NONE)
            },
                                                                                                    new[] {
                btypes.Int, btypes.Int, btypes.Int
            },
                                                                                                    false),
                                                                                                btypes.Int));

            InterlockedCompareExchange_T = new PredefinedMember <MethodSpec> (module, types.Interlocked,
                                                                              MemberFilter.Method("CompareExchange", 1,
                                                                                                  new ParametersImported(
                                                                                                      new[] {
                new ParameterData(null, Parameter.Modifier.REF),
                new ParameterData(null, Parameter.Modifier.NONE),
                new ParameterData(null, Parameter.Modifier.NONE)
            },
                                                                                                      new[] {
                new TypeParameterSpec(0, null, SpecialConstraint.None, Variance.None, null),
                new TypeParameterSpec(0, null, SpecialConstraint.None, Variance.None, null),
                new TypeParameterSpec(0, null, SpecialConstraint.None, Variance.None, null),
            }, false),
                                                                                                  null));

            MethodInfoGetMethodFromHandle = new PredefinedMember <MethodSpec> (module, types.MethodBase,
                                                                               "GetMethodFromHandle", MemberKind.Method, types.RuntimeMethodHandle);

            MethodInfoGetMethodFromHandle2 = new PredefinedMember <MethodSpec> (module, types.MethodBase,
                                                                                "GetMethodFromHandle", MemberKind.Method, types.RuntimeMethodHandle, new PredefinedType(btypes.RuntimeTypeHandle));

            MonitorEnter = new PredefinedMember <MethodSpec> (module, types.Monitor, "Enter", btypes.Object);

            MonitorEnter_v4 = new PredefinedMember <MethodSpec> (module, types.Monitor,
                                                                 MemberFilter.Method("Enter", 0,
                                                                                     new ParametersImported(new[] {
                new ParameterData(null, Parameter.Modifier.NONE),
                new ParameterData(null, Parameter.Modifier.REF)
            },
                                                                                                            new[] {
                btypes.Object, btypes.Bool
            }, false), null));

            MonitorExit = new PredefinedMember <MethodSpec> (module, types.Monitor, "Exit", btypes.Object);

            RuntimeCompatibilityWrapNonExceptionThrows = new PredefinedMember <PropertySpec> (module, atypes.RuntimeCompatibility,
                                                                                              MemberFilter.Property("WrapNonExceptionThrows", btypes.Bool));

            RuntimeHelpersInitializeArray = new PredefinedMember <MethodSpec> (module, types.RuntimeHelpers,
                                                                               "InitializeArray", btypes.Array, btypes.RuntimeFieldHandle);

            RuntimeHelpersOffsetToStringData = new PredefinedMember <PropertySpec> (module, types.RuntimeHelpers,
                                                                                    MemberFilter.Property("OffsetToStringData", btypes.Int));

            SecurityActionRequestMinimum = new PredefinedMember <ConstSpec> (module, types.SecurityAction, "RequestMinimum",
                                                                             MemberKind.Field, types.SecurityAction);

            StringEmpty = new PredefinedMember <FieldSpec> (module, btypes.String, MemberFilter.Field("Empty", btypes.String));

            StringEqual = new PredefinedMember <MethodSpec> (module, btypes.String,
                                                             new MemberFilter(Operator.GetMetadataName(Operator.OpType.Equality), 0, MemberKind.Operator, null, btypes.Bool));

            StringInequal = new PredefinedMember <MethodSpec> (module, btypes.String,
                                                               new MemberFilter(Operator.GetMetadataName(Operator.OpType.Inequality), 0, MemberKind.Operator, null, btypes.Bool));

            StructLayoutAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.StructLayout,
                                                                           MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.Short)));

            StructLayoutCharSet = new PredefinedMember <FieldSpec> (module, atypes.StructLayout, "CharSet",
                                                                    MemberKind.Field, types.CharSet);

            StructLayoutSize = new PredefinedMember <FieldSpec> (module, atypes.StructLayout,
                                                                 MemberFilter.Field("Size", btypes.Int));

            TypeGetTypeFromHandle = new PredefinedMember <MethodSpec> (module, btypes.Type, "GetTypeFromHandle", btypes.RuntimeTypeHandle);
        }
Пример #2
0
        //
        // Emits the right opcode to store to an array
        //
        public void EmitArrayStore(ArrayContainer ac)
        {
            if (ac.Rank > 1)
            {
                if (IsAnonymousStoreyMutateRequired)
                {
                    ac = (ArrayContainer)ac.Mutate(CurrentAnonymousMethod.Storey.Mutator);
                }

                ig.Emit(OpCodes.Call, ac.GetSetMethod());
                return;
            }

            var type = ac.Element;

            if (type.IsEnum)
            {
                type = EnumSpec.GetUnderlyingType(type);
            }

            if (type == TypeManager.byte_type || type == TypeManager.sbyte_type || type == TypeManager.bool_type)
            {
                Emit(OpCodes.Stelem_I1);
            }
            else if (type == TypeManager.short_type || type == TypeManager.ushort_type || type == TypeManager.char_type)
            {
                Emit(OpCodes.Stelem_I2);
            }
            else if (type == TypeManager.int32_type || type == TypeManager.uint32_type)
            {
                Emit(OpCodes.Stelem_I4);
            }
            else if (type == TypeManager.int64_type || type == TypeManager.uint64_type)
            {
                Emit(OpCodes.Stelem_I8);
            }
            else if (type == TypeManager.float_type)
            {
                Emit(OpCodes.Stelem_R4);
            }
            else if (type == TypeManager.double_type)
            {
                Emit(OpCodes.Stelem_R8);
            }
            else if (type == TypeManager.intptr_type)
            {
                Emit(OpCodes.Stobj, type);
            }
            else if (TypeManager.IsStruct(type))
            {
                Emit(OpCodes.Stobj, type);
            }
            else if (type.IsGenericParameter)
            {
                Emit(OpCodes.Stelem, type);
            }
            else if (type.IsPointer)
            {
                Emit(OpCodes.Stelem_I);
            }
            else
            {
                Emit(OpCodes.Stelem_Ref);
            }
        }
Пример #3
0
        //
        // Emits the right opcode to load from an array
        //
        public void EmitArrayLoad(ArrayContainer ac)
        {
            if (ac.Rank > 1)
            {
                if (IsAnonymousStoreyMutateRequired)
                {
                    ac = (ArrayContainer)ac.Mutate(CurrentAnonymousMethod.Storey.Mutator);
                }

                ig.Emit(OpCodes.Call, ac.GetGetMethod());
                return;
            }


            var type = ac.Element;

            if (type.Kind == MemberKind.Enum)
            {
                type = EnumSpec.GetUnderlyingType(type);
            }

            switch (type.BuiltinType)
            {
            case BuiltinTypeSpec.Type.Bool:
            //
            // bool array can actually store any byte value in underlying byte slot
            // and C# spec does not specify any normalization rule, except the result
            // is undefined
            //
            case BuiltinTypeSpec.Type.Byte:
                ig.Emit(OpCodes.Ldelem_U1);
                break;

            case BuiltinTypeSpec.Type.SByte:
                ig.Emit(OpCodes.Ldelem_I1);
                break;

            case BuiltinTypeSpec.Type.Short:
                ig.Emit(OpCodes.Ldelem_I2);
                break;

            case BuiltinTypeSpec.Type.UShort:
            case BuiltinTypeSpec.Type.Char:
                ig.Emit(OpCodes.Ldelem_U2);
                break;

            case BuiltinTypeSpec.Type.Int:
                ig.Emit(OpCodes.Ldelem_I4);
                break;

            case BuiltinTypeSpec.Type.UInt:
                ig.Emit(OpCodes.Ldelem_U4);
                break;

            case BuiltinTypeSpec.Type.ULong:
            case BuiltinTypeSpec.Type.Long:
                ig.Emit(OpCodes.Ldelem_I8);
                break;

            case BuiltinTypeSpec.Type.Float:
                ig.Emit(OpCodes.Ldelem_R4);
                break;

            case BuiltinTypeSpec.Type.Double:
                ig.Emit(OpCodes.Ldelem_R8);
                break;

            case BuiltinTypeSpec.Type.IntPtr:
                ig.Emit(OpCodes.Ldelem_I);
                break;

            default:
                switch (type.Kind)
                {
                case MemberKind.Struct:
                    if (IsAnonymousStoreyMutateRequired)
                    {
                        type = CurrentAnonymousMethod.Storey.Mutator.Mutate(type);
                    }

                    ig.Emit(OpCodes.Ldelema, type.GetMetaInfo());
                    ig.Emit(OpCodes.Ldobj, type.GetMetaInfo());
                    break;

                case MemberKind.TypeParameter:
                    if (IsAnonymousStoreyMutateRequired)
                    {
                        type = CurrentAnonymousMethod.Storey.Mutator.Mutate(type);
                    }

                    ig.Emit(OpCodes.Ldelem, type.GetMetaInfo());
                    break;

                case MemberKind.PointerType:
                    ig.Emit(OpCodes.Ldelem_I);
                    break;

                default:
                    ig.Emit(OpCodes.Ldelem_Ref);
                    break;
                }
                break;
            }
        }
Пример #4
0
        //
        // Emits the right opcode to store to an array
        //
        public void EmitArrayStore(ArrayContainer ac)
        {
            if (ac.Rank > 1)
            {
                if (IsAnonymousStoreyMutateRequired)
                {
                    ac = (ArrayContainer)ac.Mutate(CurrentAnonymousMethod.Storey.Mutator);
                }

                ig.Emit(OpCodes.Call, ac.GetSetMethod());
                return;
            }

            var type = ac.Element;

            if (type.Kind == MemberKind.Enum)
            {
                type = EnumSpec.GetUnderlyingType(type);
            }

            switch (type.BuiltinType)
            {
            case BuiltinTypeSpec.Type.Byte:
            case BuiltinTypeSpec.Type.SByte:
            case BuiltinTypeSpec.Type.Bool:
                Emit(OpCodes.Stelem_I1);
                return;

            case BuiltinTypeSpec.Type.Short:
            case BuiltinTypeSpec.Type.UShort:
            case BuiltinTypeSpec.Type.Char:
                Emit(OpCodes.Stelem_I2);
                return;

            case BuiltinTypeSpec.Type.Int:
            case BuiltinTypeSpec.Type.UInt:
                Emit(OpCodes.Stelem_I4);
                return;

            case BuiltinTypeSpec.Type.Long:
            case BuiltinTypeSpec.Type.ULong:
                Emit(OpCodes.Stelem_I8);
                return;

            case BuiltinTypeSpec.Type.Float:
                Emit(OpCodes.Stelem_R4);
                return;

            case BuiltinTypeSpec.Type.Double:
                Emit(OpCodes.Stelem_R8);
                return;
            }

            switch (type.Kind)
            {
            case MemberKind.Struct:
                Emit(OpCodes.Stobj, type);
                break;

            case MemberKind.TypeParameter:
                Emit(OpCodes.Stelem, type);
                break;

            case MemberKind.PointerType:
                Emit(OpCodes.Stelem_I);
                break;

            default:
                Emit(OpCodes.Stelem_Ref);
                break;
            }
        }
Пример #5
0
        //
        // Emits the right opcode to load from an array
        //
        public void EmitArrayLoad(ArrayContainer ac)
        {
            if (ac.Rank > 1)
            {
                if (IsAnonymousStoreyMutateRequired)
                {
                    ac = (ArrayContainer)ac.Mutate(CurrentAnonymousMethod.Storey.Mutator);
                }

                ig.Emit(OpCodes.Call, ac.GetGetMethod());
                return;
            }


            var type = ac.Element;

            if (type.Kind == MemberKind.Enum)
            {
                type = EnumSpec.GetUnderlyingType(type);
            }

            switch (type.BuiltinType)
            {
            case BuiltinTypeSpec.Type.Bool:
                //
                // Workaround MSIL limitation. Load bool element as single bit,
                // bool array can actually store any byte value
                //
                ig.Emit(OpCodes.Ldelem_U1);
                ig.Emit(OpCodes.Ldc_I4_1);
                ig.Emit(OpCodes.And);
                break;

            case BuiltinTypeSpec.Type.Byte:
                ig.Emit(OpCodes.Ldelem_U1);
                break;

            case BuiltinTypeSpec.Type.SByte:
                ig.Emit(OpCodes.Ldelem_I1);
                break;

            case BuiltinTypeSpec.Type.Short:
                ig.Emit(OpCodes.Ldelem_I2);
                break;

            case BuiltinTypeSpec.Type.UShort:
            case BuiltinTypeSpec.Type.Char:
                ig.Emit(OpCodes.Ldelem_U2);
                break;

            case BuiltinTypeSpec.Type.Int:
                ig.Emit(OpCodes.Ldelem_I4);
                break;

            case BuiltinTypeSpec.Type.UInt:
                ig.Emit(OpCodes.Ldelem_U4);
                break;

            case BuiltinTypeSpec.Type.ULong:
            case BuiltinTypeSpec.Type.Long:
                ig.Emit(OpCodes.Ldelem_I8);
                break;

            case BuiltinTypeSpec.Type.Float:
                ig.Emit(OpCodes.Ldelem_R4);
                break;

            case BuiltinTypeSpec.Type.Double:
                ig.Emit(OpCodes.Ldelem_R8);
                break;

            case BuiltinTypeSpec.Type.IntPtr:
                ig.Emit(OpCodes.Ldelem_I);
                break;

            default:
                switch (type.Kind)
                {
                case MemberKind.Struct:
                    if (IsAnonymousStoreyMutateRequired)
                    {
                        type = CurrentAnonymousMethod.Storey.Mutator.Mutate(type);
                    }

                    ig.Emit(OpCodes.Ldelema, type.GetMetaInfo());
                    ig.Emit(OpCodes.Ldobj, type.GetMetaInfo());
                    break;

                case MemberKind.TypeParameter:
                    if (IsAnonymousStoreyMutateRequired)
                    {
                        type = CurrentAnonymousMethod.Storey.Mutator.Mutate(type);
                    }

                    ig.Emit(OpCodes.Ldelem, type.GetMetaInfo());
                    break;

                case MemberKind.PointerType:
                    ig.Emit(OpCodes.Ldelem_I);
                    break;

                default:
                    ig.Emit(OpCodes.Ldelem_Ref);
                    break;
                }
                break;
            }
        }