Exemplo n.º 1
0
        public uint GetArrayTypeIndex(TypeDesc type)
        {
            System.Diagnostics.Debug.Assert(type.IsArray, "GetArrayTypeIndex was called with wrong type");
            ArrayType           arrayType           = (ArrayType)type;
            ArrayTypeDescriptor arrayTypeDescriptor = new ArrayTypeDescriptor
            {
                Rank               = (uint)arrayType.Rank,
                ElementType        = GetVariableTypeIndex(arrayType.ElementType, false),
                Size               = (uint)arrayType.GetElementSize().AsInt,
                IsMultiDimensional = arrayType.IsMdArray ? 1 : 0
            };

            ClassTypeDescriptor classDescriptor = new ClassTypeDescriptor
            {
                IsStruct    = 0,
                Name        = _objectWriter.GetMangledName(type),
                BaseClassId = GetVariableTypeIndex(arrayType.BaseType, false)
            };

            uint typeIndex = _objectWriter.GetArrayTypeIndex(classDescriptor, arrayTypeDescriptor);

            _knownTypes[type]         = typeIndex;
            _completeKnownTypes[type] = typeIndex;
            return(typeIndex);
        }
        private uint GetArrayTypeIndex(TypeDesc type)
        {
            System.Diagnostics.Debug.Assert(type.IsArray, "GetArrayTypeIndex was called with wrong type");
            ArrayType arrayType = (ArrayType)type;

            uint      elementSize       = (uint)type.Context.Target.PointerSize;
            LayoutInt layoutElementSize = arrayType.GetElementSize();

            if (!layoutElementSize.IsIndeterminate)
            {
                elementSize = (uint)layoutElementSize.AsInt;
            }

            ArrayTypeDescriptor arrayTypeDescriptor = new ArrayTypeDescriptor
            {
                Rank               = (uint)arrayType.Rank,
                ElementType        = GetVariableTypeIndex(arrayType.ElementType, false),
                Size               = elementSize,
                IsMultiDimensional = arrayType.IsMdArray ? 1 : 0
            };

            ClassTypeDescriptor classDescriptor = new ClassTypeDescriptor
            {
                IsStruct    = 0,
                Name        = _objectWriter.GetMangledName(type),
                BaseClassId = GetTypeIndex(arrayType.BaseType, false)
            };

            uint typeIndex = _objectWriter.GetArrayTypeIndex(classDescriptor, arrayTypeDescriptor);

            _knownTypes[type]         = typeIndex;
            _completeKnownTypes[type] = typeIndex;
            return(typeIndex);
        }
Exemplo n.º 3
0
        public uint GetArrayTypeIndex(ClassTypeDescriptor classDescriptor, ArrayTypeDescriptor arrayTypeDescriptor, int targetPointerSize)
        {
            uint simpleArrayDebugType = GetSimpleArrayTypeIndex(arrayTypeDescriptor.ElementType, arrayTypeDescriptor.Size);

            FieldListInProgress fieldList = default(FieldListInProgress);

            fieldList = StartFieldList();
            EmitBaseClass(ref fieldList, classDescriptor.BaseClassId);
            EmitDataMember(ref fieldList, (uint)PrimitiveTypeDescriptor.TYPE_ENUM.T_INT4, targetPointerSize, new Utf8String("count"));
            int nextOffset = targetPointerSize * 2;

            if (arrayTypeDescriptor.IsMultiDimensional != 0)
            {
                for (uint i = 0; i < arrayTypeDescriptor.Rank; i++)
                {
                    EmitDataMember(ref fieldList, (uint)PrimitiveTypeDescriptor.TYPE_ENUM.T_INT4, nextOffset, new Utf8String("length" + i.ToStringInvariant()));
                    nextOffset += 4;
                }
                for (uint i = 0; i < arrayTypeDescriptor.Rank; i++)
                {
                    EmitDataMember(ref fieldList, (uint)PrimitiveTypeDescriptor.TYPE_ENUM.T_INT4, nextOffset, new Utf8String("bounds" + i.ToStringInvariant()));
                    nextOffset += 4;
                }
            }

            EmitDataMember(ref fieldList, simpleArrayDebugType, nextOffset, new Utf8String("values"));

            FinalizeFieldList(fieldList);

            uint       classTypeIndex = _blob.GetNextTypeIndex();
            Utf8String name           = new Utf8String(classDescriptor.Name);
            uint       recordSize     = 20 + DebugInfoBlob.StringLengthEncoded(name) + TypeRecordsBlob.NumericLeafSize(targetPointerSize) /*size of length */;

            _blob.WriteWORD(checked ((ushort)(_blob.DWORDAlignedSize(recordSize) - 2))); // don't include size of 'length' in 'length'
            _blob.WriteLeafKind(classDescriptor.IsStruct != 0 ? LeafKind.LF_STRUCTURE : LeafKind.LF_CLASS);
            _blob.WriteWORD(fieldList.FieldsCount);
            _blob.WriteLF_CLASS_Properties(LF_CLASS_Properties.None);
            _blob.WriteDWORD(fieldList.TypeIndexOfFieldList);
            _blob.WriteDWORD(0);                 // Derivation list is not filled in here
            _blob.WriteDWORD(_tiVTShapePointer); // No vtable shape
            _blob.WriteNumericLeaf(targetPointerSize);
            _blob.WriteString(name);
            _blob.AlignToDWORD();
            VerifyBlobEligibleToBeBetweenRecords();
            return(classTypeIndex);
        }