Exemplo n.º 1
0
		void Write (SigType t)
		{
			Write ((int) t.ElementType);

			switch (t.ElementType) {
			case ElementType.ValueType :
				Write ((int) Utilities.CompressMetadataToken (
						CodedIndex.TypeDefOrRef, ((VALUETYPE) t).Type));
				break;
			case ElementType.Class :
				Write ((int) Utilities.CompressMetadataToken (
						CodedIndex.TypeDefOrRef, ((CLASS) t).Type));
				break;
			case ElementType.Ptr :
				PTR p = (PTR) t;
				if (p.Void)
					Write (ElementType.Void);
				else {
					Write (p.CustomMods);
					Write (p.PtrType);
				}
				break;
			case ElementType.FnPtr :
				FNPTR fp = (FNPTR) t;
				if (fp.Method is MethodRefSig)
					(fp.Method as MethodRefSig).Accept (this);
				else
					(fp.Method as MethodDefSig).Accept (this);
				break;
			case ElementType.Array :
				ARRAY ary = (ARRAY) t;
				Write (ary.CustomMods);
				ArrayShape shape = ary.Shape;
				Write (ary.Type);
				Write (shape.Rank);
				Write (shape.NumSizes);
				foreach (int size in shape.Sizes)
					Write (size);
				Write (shape.NumLoBounds);
				foreach (int loBound in shape.LoBounds)
					Write (loBound);
				break;
			case ElementType.SzArray :
				SZARRAY sa = (SZARRAY) t;
				Write (sa.CustomMods);
				Write (sa.Type);
				break;
			case ElementType.Var :
				Write (((VAR) t).Index);
				break;
			case ElementType.MVar :
				Write (((MVAR) t).Index);
				break;
			case ElementType.GenericInst :
				GENERICINST gi = t as GENERICINST;
				Write (gi.ValueType ? ElementType.ValueType : ElementType.Class);
				Write ((int) Utilities.CompressMetadataToken (
						CodedIndex.TypeDefOrRef, gi.Type));
				Write (gi.Signature);
				break;
			}
		}
Exemplo n.º 2
0
        public TypeReference GetTypeRefFromSig(SigType t, GenericContext context)
        {
            switch (t.ElementType) {
            case ElementType.Class :
                CLASS c = t as CLASS;
                return GetTypeDefOrRef (c.Type, context);
            case ElementType.ValueType :
                VALUETYPE vt = t as VALUETYPE;
                TypeReference vtr = GetTypeDefOrRef (vt.Type, context);
                vtr.IsValueType = true;
                return vtr;
            case ElementType.String :
                return SearchCoreType (Constants.String);
            case ElementType.Object :
                return SearchCoreType (Constants.Object);
            case ElementType.Void :
                return SearchCoreType (Constants.Void);
            case ElementType.Boolean :
                return SearchCoreType (Constants.Boolean);
            case ElementType.Char :
                return SearchCoreType (Constants.Char);
            case ElementType.I1 :
                return SearchCoreType (Constants.SByte);
            case ElementType.U1 :
                return SearchCoreType (Constants.Byte);
            case ElementType.I2 :
                return SearchCoreType (Constants.Int16);
            case ElementType.U2 :
                return SearchCoreType (Constants.UInt16);
            case ElementType.I4 :
                return SearchCoreType (Constants.Int32);
            case ElementType.U4 :
                return SearchCoreType (Constants.UInt32);
            case ElementType.I8 :
                return SearchCoreType (Constants.Int64);
            case ElementType.U8 :
                return SearchCoreType (Constants.UInt64);
            case ElementType.R4 :
                return SearchCoreType (Constants.Single);
            case ElementType.R8 :
                return SearchCoreType (Constants.Double);
            case ElementType.I :
                return SearchCoreType (Constants.IntPtr);
            case ElementType.U :
                return SearchCoreType (Constants.UIntPtr);
            case ElementType.TypedByRef :
                return SearchCoreType (Constants.TypedReference);
            case ElementType.Array :
                ARRAY ary = t as ARRAY;
                return new ArrayType (GetTypeRefFromSig (ary.Type, context), ary.Shape);
            case ElementType.SzArray :
                SZARRAY szary = t as SZARRAY;
                ArrayType at = new ArrayType (GetTypeRefFromSig (szary.Type, context));
                return at;
            case ElementType.Ptr :
                PTR pointer = t as PTR;
                if (pointer.Void)
                    return new PointerType (SearchCoreType (Constants.Void));
                return new PointerType (GetTypeRefFromSig (pointer.PtrType, context));
            case ElementType.FnPtr :
                FNPTR funcptr = t as FNPTR;
                FunctionPointerType fnptr = new FunctionPointerType (funcptr.Method.HasThis, funcptr.Method.ExplicitThis,
                    funcptr.Method.MethCallConv, GetMethodReturnType (funcptr.Method, context));

                for (int i = 0; i < funcptr.Method.ParamCount; i++) {
                    Param p = funcptr.Method.Parameters [i];
                    fnptr.Parameters.Add (BuildParameterDefinition (i, p, context));
                }

                CreateSentinelIfNeeded (fnptr, funcptr.Method);

                return fnptr;
            case ElementType.Var:
                VAR var = t as VAR;
                context.CheckProvider (context.Type, var.Index + 1);

                if (context.Type is GenericInstanceType)
                    return (context.Type as GenericInstanceType).GenericArguments [var.Index];
                else
                    return context.Type.GenericParameters [var.Index];
            case ElementType.MVar:
                MVAR mvar = t as MVAR;
                context.CheckProvider (context.Method, mvar.Index + 1);

                if (context.Method is GenericInstanceMethod)
                    return (context.Method as GenericInstanceMethod).GenericArguments [mvar.Index];
                else
                    return context.Method.GenericParameters [mvar.Index];
            case ElementType.GenericInst:
                GENERICINST ginst = t as GENERICINST;
                GenericInstanceType instance = new GenericInstanceType (GetTypeDefOrRef (ginst.Type, context));
                instance.IsValueType = ginst.ValueType;
                context.CheckProvider (instance.GetOriginalType (), ginst.Signature.Arity);

                for (int i = 0; i < ginst.Signature.Arity; i++)
                    instance.GenericArguments.Add (GetGenericArg (
                        ginst.Signature.Types [i], context));

                return instance;
            default:
                break;
            }
            return null;
        }
 public TypeSpec(SigType type)
 {
     this.Type = type;
 }
Exemplo n.º 4
0
        void Write(SigType t)
        {
            Write((int)t.ElementType);

            switch (t.ElementType)
            {
            case ElementType.ValueType:
                Write((int)Utilities.CompressMetadataToken(
                          CodedIndex.TypeDefOrRef, ((VALUETYPE)t).Type));
                break;

            case ElementType.Class:
                Write((int)Utilities.CompressMetadataToken(
                          CodedIndex.TypeDefOrRef, ((CLASS)t).Type));
                break;

            case ElementType.Ptr:
                PTR p = (PTR)t;
                if (p.Void)
                {
                    Write(ElementType.Void);
                }
                else
                {
                    Write(p.CustomMods);
                    Write(p.PtrType);
                }
                break;

            case ElementType.FnPtr:
                FNPTR fp = (FNPTR)t;
                if (fp.Method is MethodRefSig)
                {
                    (fp.Method as MethodRefSig).Accept(this);
                }
                else
                {
                    (fp.Method as MethodDefSig).Accept(this);
                }
                break;

            case ElementType.Array:
                ARRAY ary = (ARRAY)t;
                Write(ary.CustomMods);
                ArrayShape shape = ary.Shape;
                Write(ary.Type);
                Write(shape.Rank);
                Write(shape.NumSizes);
                foreach (int size in shape.Sizes)
                {
                    Write(size);
                }
                Write(shape.NumLoBounds);
                foreach (int loBound in shape.LoBounds)
                {
                    Write(loBound);
                }
                break;

            case ElementType.SzArray:
                SZARRAY sa = (SZARRAY)t;
                Write(sa.CustomMods);
                Write(sa.Type);
                break;

            case ElementType.Var:
                Write(((VAR)t).Index);
                break;

            case ElementType.MVar:
                Write(((MVAR)t).Index);
                break;

            case ElementType.GenericInst:
                GENERICINST gi = t as GENERICINST;
                Write(gi.ValueType ? ElementType.ValueType : ElementType.Class);
                Write((int)Utilities.CompressMetadataToken(
                          CodedIndex.TypeDefOrRef, gi.Type));
                Write(gi.Signature);
                break;
            }
        }
Exemplo n.º 5
0
 public TypeSpec(SigType type)
 {
     this.Type = type;
 }