Ejemplo n.º 1
0
        public uint GetEnumTypeIndex(TypeDesc type)
        {
            System.Diagnostics.Debug.Assert(type.IsEnum, "GetEnumTypeIndex was called with wrong type");
            DefType defType = type as DefType;

            System.Diagnostics.Debug.Assert(defType != null, "GetEnumTypeIndex was called with non def type");
            EnumTypeDescriptor enumTypeDescriptor = new EnumTypeDescriptor();
            List <FieldDesc>   fieldsDescriptors  = new List <FieldDesc>();

            foreach (var field in defType.GetFields())
            {
                if (field.IsLiteral)
                {
                    fieldsDescriptors.Add(field);
                }
            }
            enumTypeDescriptor.ElementCount = (ulong)fieldsDescriptors.Count;
            enumTypeDescriptor.ElementType  = PrimitiveTypeDescriptor.GetPrimitiveTypeIndex(defType.UnderlyingType);
            enumTypeDescriptor.Name         = defType.Name;
            enumTypeDescriptor.UniqueName   = defType.GetFullName();
            EnumRecordTypeDescriptor[] typeRecords = new EnumRecordTypeDescriptor[enumTypeDescriptor.ElementCount];
            for (int i = 0; i < fieldsDescriptors.Count; ++i)
            {
                FieldDesc field = fieldsDescriptors[i];
                EnumRecordTypeDescriptor recordTypeDescriptor;
                recordTypeDescriptor.Value = GetEnumRecordValue(field);
                recordTypeDescriptor.Name  = field.Name;
                typeRecords[i]             = recordTypeDescriptor;
            }
            uint typeIndex = _objectWriter.GetEnumTypeIndex(enumTypeDescriptor, typeRecords);

            _knownTypes[type]         = typeIndex;
            _completeKnownTypes[type] = typeIndex;
            return(typeIndex);
        }
Ejemplo n.º 2
0
        private uint GetVariableTypeIndex(TypeDesc type, bool needsCompleteIndex)
        {
            uint variableTypeIndex = 0;

            if (type.IsPrimitive)
            {
                variableTypeIndex = PrimitiveTypeDescriptor.GetPrimitiveTypeIndex(type);
            }
            else
            {
                type = DebuggerCanonicalize(type);

                if ((type.IsDefType && !type.IsValueType) || type.IsArray)
                {
                    // The type index of a variable/field of a reference type is wrapped
                    // in a pointer, as these fields are really pointer fields, and the data is on the heap
                    variableTypeIndex = 0;
                    if (_knownReferenceWrappedTypes.TryGetValue(type, out variableTypeIndex))
                    {
                        return(variableTypeIndex);
                    }
                    else
                    {
                        uint typeindex = GetTypeIndex(type, false);

                        PointerTypeDescriptor descriptor = new PointerTypeDescriptor();
                        descriptor.ElementType = typeindex;
                        descriptor.Is64Bit     = _is64bit ? 1 : 0;
                        descriptor.IsConst     = 0;
                        descriptor.IsReference = 1;

                        variableTypeIndex = _objectWriter.GetPointerTypeIndex(descriptor);
                        _knownReferenceWrappedTypes[type] = variableTypeIndex;

                        return(variableTypeIndex);
                    }
                }
                else if (type.IsEnum)
                {
                    // Enum's use the LF_ENUM record as the variable type index, but it is required to also emit a regular structure record for them.

                    if (_enumTypes.TryGetValue(type, out variableTypeIndex))
                    {
                        return(variableTypeIndex);
                    }

                    variableTypeIndex = GetEnumTypeIndex(type);

                    GetTypeIndex(type, false); // Ensure regular structure record created
                }

                variableTypeIndex = GetTypeIndex(type, needsCompleteIndex);
            }
            return(variableTypeIndex);
        }
Ejemplo n.º 3
0
        public uint GetVariableTypeIndex(TypeDesc type, bool needsCompleteIndex)
        {
            uint typeIndex = 0;

            if (type.IsPrimitive)
            {
                typeIndex = PrimitiveTypeDescriptor.GetPrimitiveTypeIndex(type);
            }
            else
            {
                typeIndex = GetTypeIndex(type, needsCompleteIndex);
            }
            return(typeIndex);
        }