Ejemplo n.º 1
0
 private void PrintArrayDimension(ArrayDimension dimension)
 {
     if (dimension.LowerBound.HasValue)
     {
         if (dimension.UpperBound.HasValue)
         {
             _builder.Append(dimension.LowerBound.Value);
             _builder.Append("...");
             _builder.Append(dimension.UpperBound.Value);
         }
         else
         {
             _builder.Append(dimension.LowerBound.Value);
             _builder.Append("...");
         }
     }
     else if (dimension.UpperBound.HasValue)
     {
         _builder.Append(dimension.UpperBound.Value);
     }
     else
     {
         _builder.Append("...");
     }
 }
Ejemplo n.º 2
0
        public bool Equals(ArrayDimension other)
        {
            if (other._lowerBound != _lowerBound)
            {
                return(false);
            }

            if (other._upperBound != _upperBound)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        private static ArrayDimension[] LoadDimensions(IBinaryAccessor accessor)
        {
            int rank = accessor.ReadCompressedInteger();

            int numSizes = accessor.ReadCompressedInteger();

            int[] sizes = new int[numSizes];
            for (int i = 0; i < numSizes; i++)
            {
                sizes[i] = accessor.ReadCompressedInteger();
            }

            int numLoBounds = accessor.ReadCompressedInteger();

            int[] loBounds = new int[numLoBounds];
            for (int i = 0; i < numLoBounds; i++)
            {
                loBounds[i] = accessor.ReadCompressedInteger();
            }

            var dimensions = new ArrayDimension[rank];

            for (int i = 0; i < rank; i++)
            {
                int?lowerBound = null;
                if (loBounds.Length > i)
                {
                    lowerBound = loBounds[i];
                }

                int?upperBound = null;
                if (sizes.Length > i)
                {
                    upperBound = sizes[i] + lowerBound - 1;
                }

                dimensions[i] = new ArrayDimension(lowerBound, upperBound);
            }

            return(dimensions);
        }
Ejemplo n.º 4
0
        private TypeSignature ReadType(ref int pos)
        {
            switch ((TypeElementCode)_blob.ReadByte(ref pos))
            {
            case TypeElementCode.Array:
            {
                int arrayDimensionCount = _blob.Read7BitEncodedInt(ref pos);
                var arrayDimensions     = new ArrayDimension[arrayDimensionCount];
                for (int i = 0; i < arrayDimensionCount; i++)
                {
                    int?lowerBound = ReadArrayDimensionBound(ref pos);
                    int?upperBound = ReadArrayDimensionBound(ref pos);
                    arrayDimensions[i] = new ArrayDimension(lowerBound, upperBound);
                }

                var elementType = ReadReferenced <TypeSignature>(ref pos);

                return(new ArrayType(elementType, arrayDimensions));
            }

            case TypeElementCode.ByRef:
            {
                var elementType = ReadReferenced <TypeSignature>(ref pos);

                return(new ByRefType(elementType));
            }

            case TypeElementCode.CustomModifier:
            {
                var modifierType = (CustomModifierType)_blob.ReadByte(ref pos);
                var modifier     = ReadReferenced <TypeSignature>(ref pos);
                var elementType  = ReadReferenced <TypeSignature>(ref pos);

                return(new CustomModifier(elementType, modifier, modifierType));
            }

            case TypeElementCode.FunctionPointer:
            {
                var callSite = ReadReferenced <CallSite>(ref pos);

                return(new FunctionPointer(callSite));
            }

            case TypeElementCode.GenericParameter:
            {
                bool isMethod = _blob.ReadBoolean(ref pos);
                int  position = _blob.Read7BitEncodedInt(ref pos);

                return(new GenericParameterType(isMethod, position));
            }

            case TypeElementCode.GenericType:
            {
                int genericArgumentCount = _blob.Read7BitEncodedInt(ref pos);
                var genericArguments     = ReadReferenced <TypeSignature>(ref pos, genericArgumentCount);
                var declaringType        = (TypeReference)ReadReferenced <TypeSignature>(ref pos);

                return(new GenericTypeReference(declaringType, genericArguments));
            }

            case TypeElementCode.Pinned:
            {
                var elementType = ReadReferenced <TypeSignature>(ref pos);

                return(new PinnedType(elementType));
            }

            case TypeElementCode.Pointer:
            {
                var elementType = ReadReferenced <TypeSignature>(ref pos);

                return(new PointerType(elementType));
            }

            case TypeElementCode.DeclaringType:
            {
                string name        = ReadString(ref pos);
                string ns          = ReadString(ref pos);
                bool?  isValueType = _blob.ReadNullableBoolean(ref pos);

                Signature owner = null;
                if (_blob.ReadBoolean(ref pos))
                {
                    owner = ReadReferenced <Signature>(ref pos);
                }

                return(new TypeReference(name, ns, owner, isValueType));
            }

            default:
                throw new NotImplementedException();
            }
        }