Exemple #1
0
 public bool Equals(__StandAloneMethodSig other)
 {
     return(other != null &&
            other.unmanaged == unmanaged &&
            other.unmanagedCallingConvention == unmanagedCallingConvention &&
            other.callingConvention == callingConvention &&
            other.returnType == returnType &&
            Util.ArrayEquals(other.parameterTypes, parameterTypes) &&
            Util.ArrayEquals(other.optionalParameterTypes, optionalParameterTypes) &&
            other.customModifiers.Equals(customModifiers));
 }
		public bool Equals(__StandAloneMethodSig other)
		{
			return other != null
				&& other.unmanaged == unmanaged
				&& other.unmanagedCallingConvention == unmanagedCallingConvention
				&& other.callingConvention == callingConvention
				&& other.returnType == returnType
				&& Util.ArrayEquals(other.parameterTypes, parameterTypes)
				&& Util.ArrayEquals(other.optionalParameterTypes, optionalParameterTypes)
				&& other.customModifiers.Equals(customModifiers);
		}
Exemple #3
0
        private static Type ReadFunctionPointer(ModuleReader module, ByteReader br, IGenericContext context)
        {
            __StandAloneMethodSig sig = MethodSignature.ReadStandAloneMethodSig(module, br, context);

            if (module.universe.EnableFunctionPointers)
            {
                return(FunctionPointerType.Make(module.universe, sig));
            }
            else
            {
                // by default, like .NET we return System.IntPtr here
                return(module.universe.System_IntPtr);
            }
        }
Exemple #4
0
 public Type MakeFunctionPointer(__StandAloneMethodSig sig)
 {
     return(FunctionPointerType.Make(this, sig));
 }
		internal static void WriteStandAloneMethodSig(ModuleBuilder module, ByteBuffer bb, __StandAloneMethodSig sig)
		{
			if (sig.IsUnmanaged)
			{
				switch (sig.UnmanagedCallingConvention)
				{
					case CallingConvention.Cdecl:
						bb.Write((byte)0x01);	// C
						break;
					case CallingConvention.StdCall:
					case CallingConvention.Winapi:
						bb.Write((byte)0x02);	// STDCALL
						break;
					case CallingConvention.ThisCall:
						bb.Write((byte)0x03);	// THISCALL
						break;
					case CallingConvention.FastCall:
						bb.Write((byte)0x04);	// FASTCALL
						break;
					default:
						throw new ArgumentOutOfRangeException("callingConvention");
				}
			}
			else
			{
				CallingConventions callingConvention = sig.CallingConvention;
				byte flags = 0;
				if ((callingConvention & CallingConventions.HasThis) != 0)
				{
					flags |= HASTHIS;
				}
				if ((callingConvention & CallingConventions.ExplicitThis) != 0)
				{
					flags |= EXPLICITTHIS;
				}
				if ((callingConvention & CallingConventions.VarArgs) != 0)
				{
					flags |= VARARG;
				}
				bb.Write(flags);
			}
			Type[] parameterTypes = sig.ParameterTypes;
			Type[] optionalParameterTypes = sig.OptionalParameterTypes;
			bb.WriteCompressedUInt(parameterTypes.Length + optionalParameterTypes.Length);
			WriteCustomModifiers(module, bb, sig.GetReturnTypeCustomModifiers());
			WriteType(module, bb, sig.ReturnType);
			int index = 0;
			foreach (Type t in parameterTypes)
			{
				WriteCustomModifiers(module, bb, sig.GetParameterCustomModifiers(index++));
				WriteType(module, bb, t);
			}
			// note that optional parameters are only allowed for managed signatures (but we don't enforce that)
			if (optionalParameterTypes.Length > 0)
			{
				bb.Write(SENTINEL);
				foreach (Type t in optionalParameterTypes)
				{
					WriteCustomModifiers(module, bb, sig.GetParameterCustomModifiers(index++));
					WriteType(module, bb, t);
				}
			}
		}
Exemple #6
0
        internal static void WriteStandAloneMethodSig(ModuleBuilder module, ByteBuffer bb, __StandAloneMethodSig sig)
        {
            if (sig.IsUnmanaged)
            {
                switch (sig.UnmanagedCallingConvention)
                {
                case CallingConvention.Cdecl:
                    bb.Write((byte)0x01);                               // C
                    break;

                case CallingConvention.StdCall:
                case CallingConvention.Winapi:
                    bb.Write((byte)0x02);                               // STDCALL
                    break;

                case CallingConvention.ThisCall:
                    bb.Write((byte)0x03);                               // THISCALL
                    break;

                case CallingConvention.FastCall:
                    bb.Write((byte)0x04);                               // FASTCALL
                    break;

                default:
                    throw new ArgumentOutOfRangeException("callingConvention");
                }
            }
            else
            {
                CallingConventions callingConvention = sig.CallingConvention;
                byte flags = 0;
                if ((callingConvention & CallingConventions.HasThis) != 0)
                {
                    flags |= HASTHIS;
                }
                if ((callingConvention & CallingConventions.ExplicitThis) != 0)
                {
                    flags |= EXPLICITTHIS;
                }
                if ((callingConvention & CallingConventions.VarArgs) != 0)
                {
                    flags |= VARARG;
                }
                bb.Write(flags);
            }
            Type[] parameterTypes         = sig.ParameterTypes;
            Type[] optionalParameterTypes = sig.OptionalParameterTypes;
            bb.WriteCompressedInt(parameterTypes.Length + optionalParameterTypes.Length);
            WriteCustomModifiers(module, bb, sig.GetReturnTypeCustomModifiers());
            WriteType(module, bb, sig.ReturnType);
            int index = 0;

            foreach (Type t in parameterTypes)
            {
                WriteCustomModifiers(module, bb, sig.GetParameterCustomModifiers(index++));
                WriteType(module, bb, t);
            }
            // note that optional parameters are only allowed for managed signatures (but we don't enforce that)
            if (optionalParameterTypes.Length > 0)
            {
                bb.Write(SENTINEL);
                foreach (Type t in optionalParameterTypes)
                {
                    WriteCustomModifiers(module, bb, sig.GetParameterCustomModifiers(index++));
                    WriteType(module, bb, t);
                }
            }
        }
Exemple #7
0
		private FunctionPointerType(Universe universe, __StandAloneMethodSig sig)
		{
			this.universe = universe;
			this.sig = sig;
		}
Exemple #8
0
		internal static Type Make(Universe universe, __StandAloneMethodSig sig)
		{
			return universe.CanonicalizeType(new FunctionPointerType(universe, sig));
		}