コード例 #1
0
ファイル: parameter.cs プロジェクト: shugo/babel
 public Parameter(ParameterBuilder pb, Type type,
                  MemberInfo member)
 {
     this.ClassImpl = type;
     this.MemberImpl = member;
     this.NameImpl = pb.Name;
     this.PositionImpl = pb.Position - 1;
     this.AttrsImpl = (ParameterAttributes) pb.Attributes;
 }
コード例 #2
0
ファイル: ParameterInfo.cs プロジェクト: Viewserve/mono
		internal ParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
			this.ClassImpl = type;
			this.MemberImpl = member;
			if (pb != null) {
				this.NameImpl = pb.Name;
				this.PositionImpl = pb.Position - 1;	// ParameterInfo.Position is zero-based
				this.AttrsImpl = (ParameterAttributes) pb.Attributes;
			} else {
				this.NameImpl = null;
				this.PositionImpl = position - 1;
				this.AttrsImpl = ParameterAttributes.None;
			}
		}
コード例 #3
0
        private MethodBuilder GenerateMethod(TypeBuilder typeBuilder)
        {
            var methodBuilder = typeBuilder.DefineMethod(
                _methodMetadata.Name,
                _methodMetadata.MethodAttributes,
                CallingConventions.Standard,
                _methodMetadata.ReturnType,
                _methodMetadata.ParameterTypes);

            var parameters = _methodMetadata.Method.GetParameters();
            var parameterCount = parameters.Length;

            var parameterBuilders = new ParameterBuilder[parameterCount];

            for (var i = 0; i < parameterCount; i++)
            {
                parameterBuilders[i] = methodBuilder.DefineParameter(i + 1, ParameterAttributes.None, parameters[i].Name);
            }

            var il = methodBuilder.GetILGenerator();

            var args = new IExpressionEmitter[parameterCount];

            for (var i = 0; i < parameterCount; i++)
            {
                args[i] = new LoadArgumentExpression(parameterBuilders[i]);
            }

            il.Emit(OpCodes.Ldarg_0);

            if (_methodMetadata.ReturnType == typeof(void))
            {
                new CallMethodStatement(_methodMetadata.TargetMethod, args).Emit(il);

                il.Emit(OpCodes.Ldnull);

                new ReturnStatement().Emit(il);
            }
            else
            {
                new ReturnStatement(
                    new CallMethodExpression(_methodMetadata.TargetMethod, args)
                ).Emit(il);
            }

            return methodBuilder;
        }
コード例 #4
0
        public ParameterBuilder DefineParameter(int iSequence, ParameterAttributes attributes, string strParamName)
        {
            // The 0th ParameterBuilder does not correspond to an
            // actual parameter, but .NETFramework lets you define
            // it anyway. It is not useful.
            if (iSequence < 0 || iSequence > GetParametersCount())
            {
                throw new ArgumentOutOfRangeException("iSequence");
            }
            if (type.is_created)
            {
                throw not_after_created();
            }

            ParameterBuilder pb = new ParameterBuilder(this, iSequence, attributes, strParamName);

            if (pinfo == null)
            {
                pinfo = new ParameterBuilder [parameters.Length + 1];
            }
            pinfo [iSequence] = pb;
            return(pb);
        }
コード例 #5
0
ファイル: TypeConverter.cs プロジェクト: dbremner/clrinterop
        /// <summary>
        /// Apply the custom attribute to parameters
        /// </summary>
        public void ApplyAttributes(ParameterBuilder paramBuilder)
        {
            if (m_attribute != null)
                paramBuilder.SetCustomAttribute(m_attribute);

            if (m_typeInfo != null)
                ConvCommon.HandleAlias(m_info, m_typeInfo, m_typeDesc, paramBuilder);
        }
コード例 #6
0
ファイル: MethodBuilder.cs プロジェクト: stabbylambda/mono
		public ParameterBuilder DefineParameter (int position, ParameterAttributes attributes, string strParamName)
		{
			RejectIfCreated ();
			
			//
			// Extension: Mono allows position == 0 for the return attribute
			//
			if ((position < 0) || (position > parameters.Length))
				throw new ArgumentOutOfRangeException ("position");

			ParameterBuilder pb = new ParameterBuilder (this, position, attributes, strParamName);
			if (pinfo == null)
				pinfo = new ParameterBuilder [parameters.Length + 1];
			pinfo [position] = pb;
			return pb;
		}
コード例 #7
0
 public static void EmitLoadArg(ILGenerator generator, bool hasThis, ParameterBuilder builder)
 {
     int index = hasThis ? builder.Position : builder.Position - 1;
     if (index == 0) generator.Emit(OpCodes.Ldarg_0);
     else if (index == 1) generator.Emit(OpCodes.Ldarg_1);
     else if (index == 2) generator.Emit(OpCodes.Ldarg_2);
     else if (index == 3) generator.Emit(OpCodes.Ldarg_3);
     else if (index <= SByte.MaxValue) generator.Emit(OpCodes.Ldarg_S, (SByte)index);
     else generator.Emit(OpCodes.Ldarg, index);
 }
コード例 #8
0
ファイル: attribute.cs プロジェクト: alisci01/mono
		public void EmitAttribute (ParameterBuilder builder)
		{
			if (ResolveBuilder ())
				builder.SetCustomAttribute (cab);
		}
コード例 #9
0
		public ParameterBuilder DefineParameter (int iSequence, ParameterAttributes attributes, string strParamName)
		{
			if (iSequence < 1 || iSequence > GetParametersCount ())
				throw new ArgumentOutOfRangeException ("iSequence");
			if (type.is_created)
				throw not_after_created ();

			ParameterBuilder pb = new ParameterBuilder (this, iSequence, attributes, strParamName);
			if (pinfo == null)
				pinfo = new ParameterBuilder [parameters.Length + 1];
			pinfo [iSequence] = pb;
			return pb;
		}
コード例 #10
0
ファイル: ReflectionEmitter.cs プロジェクト: furesoft/roslyn
        // ParameterBuilder.SetConstant(object) doesn't allow us to set null as a default value for a value typed parameter.
        private void SetParameterDefaultStructValue(ParameterBuilder builder)
        {
            if (s_lazyTypeBuilder_SetConstantValue == null)
            {
                s_lazyTypeBuilder_SetConstantValue = (MethodInfo)typeof(TypeBuilder).GetMember("SetConstantValue", BindingFlags.NonPublic | BindingFlags.Static).
                    SingleOrDefault(overload => (((MethodInfo)overload).Attributes & MethodAttributes.PinvokeImpl) != 0);

                if (s_lazyTypeBuilder_SetConstantValue == null)
                {
                    throw new NotSupportedException("Ref.Emit limitation");
                }
            }

            const int ELEMENT_TYPE_VALUETYPE = 0x11;

            s_lazyTypeBuilder_SetConstantValue.Invoke(null, new[] { RuntimeModule, builder.GetToken().Token, ELEMENT_TYPE_VALUETYPE, null });
        }
コード例 #11
0
        public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            ThrowIfGeneric ();

            // set Marshal info for the return type

            m_containingType.ThrowIfCreated();
            
            if (m_retParam == null)
            {
                m_retParam = new ParameterBuilder(this, 0, 0, null);
            }

            m_retParam.SetMarshal(unmanagedMarshal);
        }
コード例 #12
0
 private void Visit(IParameterDefinition parameterDefinition, ParameterBuilder parameterBuilder) {
   if (parameterDefinition.HasDefaultValue) {
     parameterDefinition.DefaultValue.Dispatch(this);
     parameterBuilder.SetConstant(this.value);
   }
   foreach (var customAttribute in parameterDefinition.Attributes) {
     var customAttributeBuilder = this.GetCustomAttributeBuilder(customAttribute);
     parameterBuilder.SetCustomAttribute(customAttributeBuilder);
   }
   if (parameterDefinition.IsMarshalledExplicitly)
     parameterBuilder.SetCustomAttribute(GetMarshalAsAttribute(parameterDefinition.MarshallingInformation));
 }
コード例 #13
0
ファイル: MethodBuilder.cs プロジェクト: ForNeVeR/pnet
        // Constructor.
        internal MethodBuilder(TypeBuilder type, String name,
                               MethodAttributes attributes,
                               CallingConventions callingConvention,
                               Type returnType, Type[] parameterTypes)
        {
            // Validate the parameters.
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            else if (name == String.Empty)
            {
                throw new ArgumentException(_("Emit_NameEmpty"));
            }
            if (returnType == null)
            {
                returnType = typeof(void);
            }
            if ((attributes & MethodAttributes.Static) == 0)
            {
                callingConvention |= CallingConventions.HasThis;
            }
            else if ((attributes & MethodAttributes.Virtual) != 0)
            {
                throw new ArgumentException
                          (_("Emit_BothStaticAndVirtual"));
            }
            if ((type.Attributes & TypeAttributes.ClassSemanticsMask)
                == TypeAttributes.Interface &&
                (attributes & MethodAttributes.SpecialName) == 0)
            {
                if ((attributes & (MethodAttributes.Virtual |
                                   MethodAttributes.Abstract))
                    != (MethodAttributes.Virtual |
                        MethodAttributes.Abstract))
                {
                    throw new ArgumentException
                              (_("Emit_InterfaceMethodAttrs"));
                }
            }

            // Set the local state.
            this.type          = type;
            this.bodySet       = false;
            this.initLocals    = true;
            this.explicitBody  = null;
            this.ilGenerator   = null;
            this.returnType    = returnType;
            this.returnBuilder = null;
            this.numParams     = (parameterTypes != null
                                                                        ? parameterTypes.Length : 0);

            // Register this item to be detached later.
            type.module.assembly.AddDetach(this);

            // Create the method signature.
            helper = SignatureHelper.GetMethodSigHelper
                         (type.module, callingConvention,
                         (CallingConvention)0,
                         returnType, parameterTypes);

            // Create the method.
            lock (typeof(AssemblyBuilder))
            {
                this.privateData = ClrMethodCreate
                                       (((IClrProgramItem)type).ClrHandle, name,
                                       attributes, helper.sig);
            }

            // Add the method to the type for post-processing.
            type.AddMethod(this);
        }
コード例 #14
0
ファイル: ParameterInfo.cs プロジェクト: nlhepler/mono
		internal static ParameterInfo New (ParameterBuilder pb, Type type, MemberInfo member, int position)
		{
#if NET_4_0
			return new MonoParameterInfo (pb, type, member, position);
#else
			return new ParameterInfo (pb, type, member, position);
#endif
		}
コード例 #15
0
        public void DefineParameterBuilder()
        {
            if (!Method.IsShared) ParameterIndex++;

            ParameterBuilder = Method.MethodBuilder.DefineParameter(ParameterIndex + 1, ParameterAttributes.None, Name);
        }
コード例 #16
0
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     this.ThrowIfGeneric();
     this.m_containingType.ThrowIfCreated();
     if (this.m_retParam == null)
     {
         this.m_retParam = new ParameterBuilder(this, 0, ParameterAttributes.None, null);
     }
     this.m_retParam.SetMarshal(unmanagedMarshal);
 }
コード例 #17
0
 private void ReadParameterCore(ParameterBuilder pb)
 {
     // TODO custom attr for pb
     if (m_br.ReadBoolean())
     {
         // default value
     }
 }
コード例 #18
0
 public static void EmitStoreArg(ILGenerator generator, bool hasThis, ParameterBuilder builder)
 {
     int index = hasThis ? builder.Position : builder.Position - 1;
     if (index <= SByte.MaxValue) generator.Emit(OpCodes.Starg_S, (SByte)index);
     else generator.Emit(OpCodes.Starg, index);
 }
コード例 #19
0
ファイル: ReflectionEmitter.cs プロジェクト: furesoft/roslyn
 private void EmitCustomAttributes(ParameterBuilder paramBuilder, IEnumerable<Cci.ICustomAttribute> attributes)
 {
     foreach (var attribute in attributes)
     {
         paramBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute));
     }
 }
コード例 #20
0
ファイル: ParameterInfo.cs プロジェクト: Profit0004/mono
		internal static ParameterInfo New (ParameterBuilder pb, Type type, MemberInfo member, int position)
		{
			return new MonoParameterInfo (pb, type, member, position);
		}
コード例 #21
0
ファイル: attribute.cs プロジェクト: Ein/monodevelop
		public void EmitAttribute (ParameterBuilder builder, TypeSpec type)
		{
			if (ResolveTransformationCtor ()) {
				var cab = new CustomAttributeBuilder ((ConstructorInfo) tctor.GetMetaInfo (), new object[] { GetTransformationFlags (type) });
				builder.SetCustomAttribute (cab);
			}
		}
コード例 #22
0
ファイル: MonoParameterInfo.cs プロジェクト: skolima/mono
		internal MonoParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
コード例 #23
0
        public static void CopyParameterAttributes(ParameterInfo from, ParameterBuilder to) {
            if (from.IsDefined(typeof(ParamArrayAttribute), false)) {
                to.SetCustomAttribute(new CustomAttributeBuilder(
                    typeof(ParamArrayAttribute).GetConstructor(Type.EmptyTypes), ArrayUtils.EmptyObjects)
                );
            } else if (from.IsDefined(typeof(ParamDictionaryAttribute), false)) {
                to.SetCustomAttribute(new CustomAttributeBuilder(
                    typeof(ParamDictionaryAttribute).GetConstructor(Type.EmptyTypes), ArrayUtils.EmptyObjects)
                );
            }

            if ((from.Attributes & ParameterAttributes.HasDefault) != 0) {
                to.SetConstant(from.DefaultValue);
            }
        }
コード例 #24
0
		public static void Load(this ILGenerator gen, ParameterBuilder param)
		{
			gen.LoadParameter(param.Position);
		}
コード例 #25
0
ファイル: EmitAssembly.cs プロジェクト: Bombadil77/boo
 void SetParamArrayAttribute(ParameterBuilder builder)
 {
     builder.SetCustomAttribute(
         new CustomAttributeBuilder(
             ParamArrayAttribute_Constructor,
             new object[0]));
 }
コード例 #26
0
 internal void RegisterBuilder(ParameterBuilder builder, bool isInstance)
 {
     if(Builder != null)
     {
         throw new InvalidOperationException();
     }
     Builder = builder;
     IsInstance = isInstance;
 }
コード例 #27
0
 public static void SetCustomAttributes(ParameterBuilder pb, IPersistentMap attributes)
 {
     for (ISeq s = RT.seq(attributes); s != null; s = s.next())
         pb.SetCustomAttribute(CreateCustomAttributeBuilder((IMapEntry)(s.first())));
 }
コード例 #28
0
ファイル: GenInterface.cs プロジェクト: TerabyteX/clojure-clr
 public static void SetCustomAttributes(ParameterBuilder pb, IPersistentMap attributes)
 {
     foreach (CustomAttributeBuilder cab in CreateCustomAttributeBuilders(attributes))
         pb.SetCustomAttribute(cab);
 }
コード例 #29
0
        private void VerifyParameterBuilder(
            ParameterBuilder actualBuilder,
            string desiredName,
            ParameterAttributes desiredAttributes,
            int desiredPosition)
        {
            const int ReservedMaskParameterAttribute = 0xF000; // This constant maps to ParameterAttributes.ReservedMask that is not available in the contract.
            Assert.Equal(desiredName, actualBuilder.Name);

            int removedReservedAttributes = (int)desiredAttributes & ~ReservedMaskParameterAttribute;
            Assert.Equal((int)removedReservedAttributes, (actualBuilder.Attributes & (int)removedReservedAttributes));
            Assert.Equal(desiredPosition, actualBuilder.Position);
        }
コード例 #30
0
ファイル: Helpers.cs プロジェクト: Slav76/pascalabcnet
		public ParamInfo(ParameterBuilder pb)
		{
			_pb = pb;
		}
コード例 #31
0
ファイル: Helpers.cs プロジェクト: Slav76/pascalabcnet
        //добавление параметра
		public ParamInfo AddParameter(IParameterNode p, ParameterBuilder pb)
		{
			ParamInfo pi = new ParamInfo(pb);
			defs[p] = pi;
			return pi;
		}
コード例 #32
0
 public LoadArgumentExpression(ParameterBuilder parameter)
 {
     _index = parameter.Position;
 }