Пример #1
0
 /// <summary>
 /// Builds an array type from an ARRAY signature
 /// </summary>
 /// <param name="t">Type of the array</param>
 /// <param name="r">Rank of the array</param>
 /// <param name="s">Sizes of the lower dimensions (possibly all)</param>
 /// <param name="l">Lower bounds of lower dimensions</param>
 internal ArrayType(CLITypeNode t, int r, int[] s, int[] l)
 {
     // Used to not loose the declaration SZARRAY
     szarray  = false;
     type     = t;
     rank     = r;
     sizes    = s;
     lobounds = l;
 }
Пример #2
0
 /// <summary>
 /// Builds a Pointer type for a given type.
 /// </summary>
 /// <param name="t">Type to be used as a pointer type.</param>
 internal PointerType(CLITypeNode t)
 {
     type = t;
 }
Пример #3
0
 /// <summary>
 /// Build the ByRefType node.
 /// </summary>
 /// <param name="t">Type to be used to build the ref type.</param>
 internal ByRefType(CLITypeNode t)
 {
     type = t;
 }
Пример #4
0
 /// <summary>
 /// Build a PinnedType object for a given type.
 /// </summary>
 /// <param name="t">Type to mark as pinned.</param>
 internal PinnedType(CLITypeNode t)
 {
     type = t;
 }
Пример #5
0
 public static CLIType ReadType(ref MapPtr p, CLIFile f)
 {
     return(CLITypeNode.ReadType(ref p, f));
 }
Пример #6
0
 /// <summary>
 /// Build a CustomModType node.
 /// </summary>
 /// <param name="mod">The type modifier (actually one of CMOD_OPT or CMOD_REQD)</param>
 /// <param name="t">The type to which the modifier applies</param>
 internal CustomModType(ELEMENT_TYPE mod, CLITypeNode t)
 {
     Debug.Assert(mod == ELEMENT_TYPE.ELEMENT_TYPE_CMOD_OPT || mod == ELEMENT_TYPE.ELEMENT_TYPE_CMOD_REQD, "Invalid Custom Modifier!");
     cmod = mod;
     type = t;
 }
Пример #7
0
 /// <summary>
 /// Builds an array type from SZARRAY signature
 /// </summary>
 /// <param name="t">Type of the array</param>
 internal ArrayType(CLITypeNode t)
     : this(t, 1, null, null)
 {
     szarray = true;
 }
Пример #8
0
 internal CLIType(CLIFile f, CLITypeNode t)
 {
     this.file = f;
     this.type = t;
 }
Пример #9
0
        /// <summary>
        /// Read a type from a signature.
        /// </summary>
        /// <param name="p">Pointer to the signature to be read</param>
        /// <param name="f">CLIFileReader in use</param>
        /// <returns>
        /// A CLIType object representing a type. It is similar to a Reflection.Type
        /// object though it is less expensive and contains enough information to
        /// access type definitions in CLIFile table.
        /// </returns>
        private static CLITypeNode ReadTypeNode(ref MapPtr p, CLIFile f)
        {
            ELEMENT_TYPE t = (ELEMENT_TYPE)SignatureUtil.ReadCompressedInt(ref p);

            switch (t)
            {
            case ELEMENT_TYPE.ELEMENT_TYPE_BOOLEAN:
            case ELEMENT_TYPE.ELEMENT_TYPE_CHAR:
            case ELEMENT_TYPE.ELEMENT_TYPE_I1:
            case ELEMENT_TYPE.ELEMENT_TYPE_U1:
            case ELEMENT_TYPE.ELEMENT_TYPE_I2:
            case ELEMENT_TYPE.ELEMENT_TYPE_U2:
            case ELEMENT_TYPE.ELEMENT_TYPE_I4:
            case ELEMENT_TYPE.ELEMENT_TYPE_U4:
            case ELEMENT_TYPE.ELEMENT_TYPE_I8:
            case ELEMENT_TYPE.ELEMENT_TYPE_U8:
            case ELEMENT_TYPE.ELEMENT_TYPE_R4:
            case ELEMENT_TYPE.ELEMENT_TYPE_R8:
            case ELEMENT_TYPE.ELEMENT_TYPE_I:
            case ELEMENT_TYPE.ELEMENT_TYPE_U:
            case ELEMENT_TYPE.ELEMENT_TYPE_STRING:
            case ELEMENT_TYPE.ELEMENT_TYPE_OBJECT:
            case ELEMENT_TYPE.ELEMENT_TYPE_TYPEDBYREF:
            case ELEMENT_TYPE.ELEMENT_TYPE_VOID:
                return(BaseType.TypeOf(t).type);

            case ELEMENT_TYPE.ELEMENT_TYPE_VAR:
                return(new VariableType(f, SignatureUtil.ReadCompressedInt(ref p)));

            case ELEMENT_TYPE.ELEMENT_TYPE_MVAR:
                return(new MethodVariableType(f, SignatureUtil.ReadCompressedInt(ref p)));

            case ELEMENT_TYPE.ELEMENT_TYPE_VALUETYPE:
            case ELEMENT_TYPE.ELEMENT_TYPE_CLASS:
                return(new CompoundType(f, SignatureUtil.ReadCompressedInt(ref p)));

            case ELEMENT_TYPE.ELEMENT_TYPE_GENERICINST:
            {
                ELEMENT_TYPE isClass = (ELEMENT_TYPE)SignatureUtil.ReadCompressedInt(ref p);
                int          ttk     = SignatureUtil.ReadCompressedInt(ref p);
                int          count   = SignatureUtil.ReadCompressedInt(ref p);
                CLIType[]    args    = new CLIType[count];
                for (int i = 0; i < count; i++)
                {
                    args[i] = new CLIType(f, ReadTypeNode(ref p, f));
                }

                return(new CompoundType(f, ttk, args));
            }

            case ELEMENT_TYPE.ELEMENT_TYPE_PTR:
            {
                int          sz;
                ELEMENT_TYPE opt  = (ELEMENT_TYPE)SignatureUtil.ReadCompressedInt(p, out sz);
                ELEMENT_TYPE?cmod = null;
                if (opt == ELEMENT_TYPE.ELEMENT_TYPE_CMOD_OPT || opt == ELEMENT_TYPE.ELEMENT_TYPE_CMOD_REQD)
                {
                    cmod = opt;
                    p   += 1;
                }
                CLITypeNode ptrt = new PointerType(ReadTypeNode(ref p, f));
                if (cmod.HasValue)
                {
                    ptrt = new CustomModType(cmod.Value, ptrt);
                }
                return(ptrt);
            }

            case ELEMENT_TYPE.ELEMENT_TYPE_FNPTR:
                return(new FunPointerType(f, p));

            case ELEMENT_TYPE.ELEMENT_TYPE_ARRAY:
            {
                CLITypeNode at   = ReadTypeNode(ref p, f);
                int         rank = SignatureUtil.ReadCompressedInt(ref p);
                int         sz   = SignatureUtil.ReadCompressedInt(ref p);
                int[]       szs  = new int[sz];
                for (int i = 0; i < sz; i++)
                {
                    szs[i] = SignatureUtil.ReadCompressedInt(ref p);
                }
                sz = SignatureUtil.ReadCompressedInt(ref p);
                int[] lb = new int[sz];
                for (int i = 0; i < sz; i++)
                {
                    lb[i] = SignatureUtil.ReadCompressedInt(ref p);
                }
                return(new ArrayType(at, rank, szs, lb));
            }

            case ELEMENT_TYPE.ELEMENT_TYPE_SZARRAY:
            {
                int          sz;
                ELEMENT_TYPE opt  = (ELEMENT_TYPE)SignatureUtil.ReadCompressedInt(p, out sz);
                ELEMENT_TYPE?cmod = null;
                if (opt == ELEMENT_TYPE.ELEMENT_TYPE_CMOD_OPT || opt == ELEMENT_TYPE.ELEMENT_TYPE_CMOD_REQD)
                {
                    cmod = opt;
                    p   += 1;
                }
                CLITypeNode sat = new ArrayType(ReadTypeNode(ref p, f));
                if (cmod.HasValue)
                {
                    sat = new CustomModType(cmod.Value, sat);
                }
                return(sat);
            }

            default:
                throw new Exception("Internal error in CLI File Reader library!");
            }
        }