Esempio n. 1
0
 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;
 }
Esempio n. 2
0
		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;
			}
		}
        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;
        }
Esempio n. 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);
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
		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;
		}
Esempio n. 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);
 }
Esempio n. 8
0
		public void EmitAttribute (ParameterBuilder builder)
		{
			if (ResolveBuilder ())
				builder.SetCustomAttribute (cab);
		}
Esempio n. 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;
		}
Esempio n. 10
0
        // 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 });
        }
        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);
        }
 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));
 }
Esempio n. 13
0
        // 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);
        }
Esempio n. 14
0
		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
		}
        public void DefineParameterBuilder()
        {
            if (!Method.IsShared) ParameterIndex++;

            ParameterBuilder = Method.MethodBuilder.DefineParameter(ParameterIndex + 1, ParameterAttributes.None, Name);
        }
 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);
 }
 private void ReadParameterCore(ParameterBuilder pb)
 {
     // TODO custom attr for pb
     if (m_br.ReadBoolean())
     {
         // default value
     }
 }
Esempio n. 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);
 }
Esempio n. 19
0
 private void EmitCustomAttributes(ParameterBuilder paramBuilder, IEnumerable<Cci.ICustomAttribute> attributes)
 {
     foreach (var attribute in attributes)
     {
         paramBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute));
     }
 }
Esempio n. 20
0
		internal static ParameterInfo New (ParameterBuilder pb, Type type, MemberInfo member, int position)
		{
			return new MonoParameterInfo (pb, type, member, position);
		}
Esempio n. 21
0
		public void EmitAttribute (ParameterBuilder builder, TypeSpec type)
		{
			if (ResolveTransformationCtor ()) {
				var cab = new CustomAttributeBuilder ((ConstructorInfo) tctor.GetMetaInfo (), new object[] { GetTransformationFlags (type) });
				builder.SetCustomAttribute (cab);
			}
		}
Esempio n. 22
0
		internal MonoParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
Esempio n. 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);
            }
        }
		public static void Load(this ILGenerator gen, ParameterBuilder param)
		{
			gen.LoadParameter(param.Position);
		}
Esempio n. 25
0
 void SetParamArrayAttribute(ParameterBuilder builder)
 {
     builder.SetCustomAttribute(
         new CustomAttributeBuilder(
             ParamArrayAttribute_Constructor,
             new object[0]));
 }
Esempio n. 26
0
 internal void RegisterBuilder(ParameterBuilder builder, bool isInstance)
 {
     if(Builder != null)
     {
         throw new InvalidOperationException();
     }
     Builder = builder;
     IsInstance = isInstance;
 }
Esempio n. 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())));
 }
Esempio n. 28
0
 public static void SetCustomAttributes(ParameterBuilder pb, IPersistentMap attributes)
 {
     foreach (CustomAttributeBuilder cab in CreateCustomAttributeBuilders(attributes))
         pb.SetCustomAttribute(cab);
 }
        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);
        }
Esempio n. 30
0
		public ParamInfo(ParameterBuilder pb)
		{
			_pb = pb;
		}
Esempio n. 31
0
        //добавление параметра
		public ParamInfo AddParameter(IParameterNode p, ParameterBuilder pb)
		{
			ParamInfo pi = new ParamInfo(pb);
			defs[p] = pi;
			return pi;
		}
 public LoadArgumentExpression(ParameterBuilder parameter)
 {
     _index = parameter.Position;
 }