Example #1
0
 void Format(DmdMethodBase method, DmdPropertyInfo property, AccessorKind accessorKind)
 {
     if (ReturnTypes)
     {
         FormatReturnType(property.PropertyType, TypeFormatterUtils.IsReadOnlyProperty(property));
         WriteSpace();
     }
     if (DeclaringTypes)
     {
         FormatType(property.DeclaringType);
         WritePeriod();
     }
     if (property.GetIndexParameters().Count != 0)
     {
         OutputWrite(Keyword_this, BoxedTextColor.Keyword);
         WriteToken(property);
         WriteMethodParameterListCore(method, GetAllMethodParameterTypes(property.GetMethodSignature()), IndexerParenOpen, IndexerParenClose, showParameterTypes: true, showParameterNames: false, showParameterValues: false);
     }
     else
     {
         WriteIdentifier(property.Name, TypeFormatterUtils.GetColor(property));
         WriteToken(property);
     }
     WriteAccessor(accessorKind);
     WriteToken(method);
     WriteGenericArguments(method);
     WriteMethodParameterList(method, MethodParenOpen, MethodParenClose);
     WriteOffset();
 }
Example #2
0
        void FormatCore()
        {
            if (ModuleNames)
            {
                OutputWrite(evalInfo.Frame.Module?.Name ?? "???", BoxedTextColor.AssemblyModule);
                OutputWrite("!", BoxedTextColor.Operator);
            }

            var runtime = evalInfo.Runtime.GetDotNetRuntime();
            var method  = runtime.GetFrameMethod(evalInfo);

            if ((object)method == null)
            {
                OutputWrite("???", BoxedTextColor.Error);
            }
            else
            {
                var propInfo = TypeFormatterUtils.TryGetProperty(method);
                if (propInfo.kind != AccessorKind.None)
                {
                    Format(method, propInfo.property, propInfo.kind);
                    return;
                }

                var eventInfo = TypeFormatterUtils.TryGetEvent(method);
                if (eventInfo.kind != AccessorKind.None)
                {
                    Format(method, eventInfo.@event, eventInfo.kind);
                    return;
                }

                Format(method);
            }
        }
Example #3
0
        void WriteRefIfByRef(DmdParameterInfo param)
        {
            if ((object)param == null)
            {
                return;
            }
            var type = param.ParameterType;

            if (!type.IsByRef)
            {
                return;
            }
            if (!param.IsIn && param.IsOut)
            {
                OutputWrite(Keyword_out, BoxedTextColor.Keyword);
                WriteSpace();
            }
            else if (!param.IsIn && !param.IsOut && TypeFormatterUtils.IsReadOnlyParameter(param))
            {
                OutputWrite(Keyword_in, BoxedTextColor.Keyword);
                WriteSpace();
            }
            else
            {
                OutputWrite(Keyword_ref, BoxedTextColor.Keyword);
                WriteSpace();
            }
        }
        void Format(DmdMethodBase method, DmdPropertyInfo property, AccessorKind accessorKind)
        {
            if (property.SetMethod is null)
            {
                OutputWrite(Keyword_ReadOnly, DbgTextColor.Keyword);
                WriteSpace();
            }

            OutputWrite(Keyword_Property, DbgTextColor.Keyword);
            WriteSpace();

            WriteAccessor(accessorKind);
            WriteToken(method);

            if (DeclaringTypes)
            {
                FormatType(property.DeclaringType !);
                WritePeriod();
            }

            WriteIdentifier(property.Name, TypeFormatterUtils.GetColor(property));
            WriteToken(property);
            WriteGenericArguments(method);
            WriteMethodParameterList(method, MethodParenOpen, MethodParenClose);
            WriteReturnType(method);
            WriteOffset();
        }
        protected override void FormatReturnValueMethodName(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DbgValueFormatterTypeOptions typeOptions, DbgValueFormatterOptions valueOptions, CultureInfo cultureInfo, DmdMethodBase method, DmdPropertyInfo property)
        {
            var typeFormatter = new Formatters.CSharp.CSharpTypeFormatter(output, typeOptions.ToTypeFormatterOptions(), null);

            typeFormatter.Format(method.DeclaringType, null);
            var valueFormatter = new Formatters.CSharp.CSharpPrimitiveValueFormatter(output, valueOptions.ToValueFormatterOptions(), cultureInfo);

            output.Write(DbgTextColor.Operator, ".");
            if ((object)property != null)
            {
                if (property.GetIndexParameters().Count != 0)
                {
                    output.Write(DbgTextColor.Keyword, Keyword_this);
                    WriteMethodParameterList(output, method, typeFormatter, GetAllMethodParameterTypes(property.GetMethodSignature()), IndexerParenOpen, IndexerParenClose);
                }
                else
                {
                    output.Write(MemberUtils.GetColor(property), Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(property.Name));
                }
                valueFormatter.WriteTokenComment(property.MetadataToken);
                output.Write(DbgTextColor.Operator, ".");
                output.Write(DbgTextColor.Keyword, "get");
                valueFormatter.WriteTokenComment(method.MetadataToken);
            }
            else
            {
                var methodColor = TypeFormatterUtils.GetColor(method, canBeModule: false);
                if (TypeFormatterUtils.TryGetMethodName(method.Name, out var containingMethodName, out var localFunctionName))
                {
                    output.Write(methodColor, Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(containingMethodName));
                    output.Write(DbgTextColor.Operator, ".");
                    output.Write(methodColor, Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(localFunctionName));
                    valueFormatter.WriteTokenComment(method.MetadataToken);
                    WriteGenericMethodArguments(output, method, typeFormatter);
                }
Example #6
0
        void Format(DmdMethodBase method)
        {
            if (StateMachineUtils.TryGetKickoffMethod(method, out var kickoffMethod))
            {
                method = kickoffMethod;
            }

            var sig = method.GetMethodSignature();

            string[] operatorInfo;
            if (method is DmdConstructorInfo)
            {
                operatorInfo = null;
            }
            else
            {
                operatorInfo = Operators.TryGetOperatorInfo(method.Name);
            }

            if (operatorInfo != null)
            {
                for (int i = 0; i < operatorInfo.Length - 1; i++)
                {
                    WriteOperatorInfoString(operatorInfo[i]);
                    WriteSpace();
                }
            }
            else
            {
                bool isSub = method.GetMethodSignature().ReturnType == method.AppDomain.System_Void;
                OutputWrite(isSub ? Keyword_Sub : Keyword_Function, DbgTextColor.Keyword);
                WriteSpace();
            }

            if (DeclaringTypes)
            {
                FormatType(method.DeclaringType);
                WritePeriod();
            }
            if (method is DmdConstructorInfo)
            {
                OutputWrite(Keyword_New, DbgTextColor.Keyword);
            }
            else
            {
                if (TypeFormatterUtils.TryGetMethodName(method.Name, out var containingMethodName, out var localFunctionName))
                {
                    var methodColor = TypeFormatterUtils.GetColor(method, canBeModule: true);
                    WriteIdentifier(containingMethodName, methodColor);
                    WritePeriod();
                    WriteIdentifier(localFunctionName, methodColor);
                }
Example #7
0
 void Format(DmdMethodBase method, DmdEventInfo @event, AccessorKind accessorKind)
 {
     if (DeclaringTypes)
     {
         FormatType(@event.DeclaringType);
         WritePeriod();
     }
     WriteIdentifier(@event.Name, TypeFormatterUtils.GetColor(@event));
     WriteToken(@event);
     WriteAccessor(accessorKind);
     WriteToken(method);
     WriteGenericArguments(method);
     WriteMethodParameterList(method, MethodParenOpen, MethodParenClose);
     WriteOffset();
 }
Example #8
0
        void Format(DmdMethodBase method)
        {
            if (StateMachineUtils.TryGetKickoffMethod(method, out var kickoffMethod))
            {
                method = kickoffMethod;
            }

            var sig = method.GetMethodSignature();

            string[] operatorInfo;
            if (method is DmdConstructorInfo)
            {
                operatorInfo = null;
            }
            else
            {
                operatorInfo = Operators.TryGetOperatorInfo(method.Name);
            }
            bool isExplicitOrImplicit = operatorInfo != null && (operatorInfo[0] == "explicit" || operatorInfo[0] == "implicit");

            if (!isExplicitOrImplicit)
            {
                if (ReturnTypes && !(method is DmdConstructorInfo))
                {
                    FormatReturnType(sig.ReturnType, TypeFormatterUtils.IsReadOnlyMethod(method));
                    WriteSpace();
                }
            }

            if (DeclaringTypes)
            {
                FormatType(method.DeclaringType);
                WritePeriod();
            }
            if (method is DmdConstructorInfo)
            {
                WriteIdentifier(TypeFormatterUtils.RemoveGenericTick(method.DeclaringType.MetadataName), TypeFormatterUtils.GetColor(method, canBeModule: false));
            }
            else
            {
                if (TypeFormatterUtils.TryGetMethodName(method.Name, out var containingMethodName, out var localFunctionName))
                {
                    var methodColor = TypeFormatterUtils.GetColor(method, canBeModule: false);
                    WriteIdentifier(containingMethodName, methodColor);
                    WritePeriod();
                    WriteIdentifier(localFunctionName, methodColor);
                }
Example #9
0
        void WriteTypeName(DmdType type, KeywordType keywordType)
        {
            switch (keywordType)
            {
            case KeywordType.Boolean:       OutputWrite("Boolean", BoxedTextColor.Keyword); return;

            case KeywordType.Byte:          OutputWrite("Byte", BoxedTextColor.Keyword); return;

            case KeywordType.Char:          OutputWrite("Char", BoxedTextColor.Keyword); return;

            case KeywordType.Date:          OutputWrite("Date", BoxedTextColor.Keyword); return;

            case KeywordType.Decimal:       OutputWrite("Decimal", BoxedTextColor.Keyword); return;

            case KeywordType.Double:        OutputWrite("Double", BoxedTextColor.Keyword); return;

            case KeywordType.Integer:       OutputWrite("Integer", BoxedTextColor.Keyword); return;

            case KeywordType.Long:          OutputWrite("Long", BoxedTextColor.Keyword); return;

            case KeywordType.Object:        OutputWrite("Object", BoxedTextColor.Keyword); return;

            case KeywordType.SByte:         OutputWrite("SByte", BoxedTextColor.Keyword); return;

            case KeywordType.Short:         OutputWrite("Short", BoxedTextColor.Keyword); return;

            case KeywordType.Single:        OutputWrite("Single", BoxedTextColor.Keyword); return;

            case KeywordType.String:        OutputWrite("String", BoxedTextColor.Keyword); return;

            case KeywordType.UInteger:      OutputWrite("UInteger", BoxedTextColor.Keyword); return;

            case KeywordType.ULong:         OutputWrite("ULong", BoxedTextColor.Keyword); return;

            case KeywordType.UShort:        OutputWrite("UShort", BoxedTextColor.Keyword); return;

            case KeywordType.NoKeyword:
                break;

            default:
                throw new InvalidOperationException();
            }

            WriteIdentifier(TypeFormatterUtils.RemoveGenericTick(type.MetadataName), TypeFormatterUtils.GetTypeColor(type, canBeModule: true));
            WriteTokenComment(type.MetadataToken);
        }
Example #10
0
        public void Format(DbgDotNetValue value)
        {
            if (value is null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            evalInfo.CancellationToken.ThrowIfCancellationRequested();
            try {
                if (recursionCounter++ >= MAX_RECURSION)
                {
                    OutputWrite("???", DbgTextColor.Error);
                    return;
                }

                if (TrySimpleFormat(value))
                {
                    return;
                }
                var type       = value.Type;
                int tupleArity = TypeFormatterUtils.GetTupleArity(type);
                if (tupleArity > 0 && TryFormatTuple(value, tupleArity))
                {
                    return;
                }
                if (KeyValuePairTypeUtils.IsKeyValuePair(type) && TryFormatKeyValuePair(value, KeyValuePairTypeUtils.TryGetFields(value.Type)))
                {
                    return;
                }
                if (DictionaryEntryTypeUtils.IsDictionaryEntry(type) && TryFormatKeyValuePair(value, DictionaryEntryTypeUtils.TryGetFields(value.Type)))
                {
                    return;
                }
                if (TryFormatWithDebuggerAttributes(value))
                {
                    return;
                }
                if (TryFormatToString(value))
                {
                    return;
                }
                FormatTypeName(value);
            }
            finally {
                recursionCounter--;
            }
        }
Example #11
0
        void WriteTypeName(DmdType type, KeywordType keywordType)
        {
            switch (keywordType)
            {
            case KeywordType.Void:          OutputWrite("void", BoxedTextColor.Keyword); return;

            case KeywordType.Boolean:       OutputWrite("bool", BoxedTextColor.Keyword); return;

            case KeywordType.Char:          OutputWrite("char", BoxedTextColor.Keyword); return;

            case KeywordType.SByte:         OutputWrite("sbyte", BoxedTextColor.Keyword); return;

            case KeywordType.Byte:          OutputWrite("byte", BoxedTextColor.Keyword); return;

            case KeywordType.Int16:         OutputWrite("short", BoxedTextColor.Keyword); return;

            case KeywordType.UInt16:        OutputWrite("ushort", BoxedTextColor.Keyword); return;

            case KeywordType.Int32:         OutputWrite("int", BoxedTextColor.Keyword); return;

            case KeywordType.UInt32:        OutputWrite("uint", BoxedTextColor.Keyword); return;

            case KeywordType.Int64:         OutputWrite("long", BoxedTextColor.Keyword); return;

            case KeywordType.UInt64:        OutputWrite("ulong", BoxedTextColor.Keyword); return;

            case KeywordType.Single:        OutputWrite("float", BoxedTextColor.Keyword); return;

            case KeywordType.Double:        OutputWrite("double", BoxedTextColor.Keyword); return;

            case KeywordType.Object:        OutputWrite("object", BoxedTextColor.Keyword); return;

            case KeywordType.Decimal:       OutputWrite("decimal", BoxedTextColor.Keyword); return;

            case KeywordType.String:        OutputWrite("string", BoxedTextColor.Keyword); return;

            case KeywordType.NoKeyword:
                break;

            default:
                throw new InvalidOperationException();
            }

            WriteIdentifier(TypeFormatterUtils.RemoveGenericTick(type.MetadataName), TypeFormatterUtils.GetColor(type, canBeModule: false));
            new CSharpPrimitiveValueFormatter(output, options.ToValueFormatterOptions(), cultureInfo).WriteTokenComment(type.MetadataToken);
        }
        void Format(DmdMethodBase method, DmdEventInfo @event, AccessorKind accessorKind)
        {
            OutputWrite(Keyword_Event, DbgTextColor.Keyword);
            WriteSpace();

            WriteAccessor(accessorKind);
            WriteToken(method);

            if (DeclaringTypes)
            {
                FormatType(@event.DeclaringType !);
                WritePeriod();
            }
            WriteIdentifier(@event.Name, TypeFormatterUtils.GetColor(@event));
            WriteToken(@event);
            WriteSpace();
            OutputWrite(Keyword_As, DbgTextColor.Keyword);
            WriteSpace();
            FormatType(@event.EventHandlerType);
            WriteOffset();
        }
Example #13
0
        protected override void FormatReturnValueMethodName(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DbgValueFormatterTypeOptions typeOptions, DbgValueFormatterOptions valueOptions, CultureInfo cultureInfo, DmdMethodBase method, DmdPropertyInfo property)
        {
            var typeFormatter = new Formatters.VisualBasic.VisualBasicTypeFormatter(output, typeOptions.ToTypeFormatterOptions(), null);

            typeFormatter.Format(method.DeclaringType, null);
            var valueFormatter = new Formatters.VisualBasic.VisualBasicPrimitiveValueFormatter(output, valueOptions.ToValueFormatterOptions(), cultureInfo);

            output.Write(DbgTextColor.Operator, ".");
            if ((object)property != null)
            {
                output.Write(MemberUtils.GetColor(property), Formatters.VisualBasic.VisualBasicTypeFormatter.GetFormattedIdentifier(property.Name));
                valueFormatter.WriteTokenComment(property.MetadataToken);
                output.Write(DbgTextColor.Operator, ".");
                output.Write(DbgTextColor.Keyword, "Get");
                valueFormatter.WriteTokenComment(method.MetadataToken);
            }
            else
            {
                var operatorInfo = Formatters.VisualBasic.Operators.TryGetOperatorInfo(method.Name);
                if (operatorInfo != null && method is DmdMethodInfo methodInfo)
                {
                    for (int i = 0; i < operatorInfo.Length; i++)
                    {
                        if (i > 0)
                        {
                            output.Write(DbgTextColor.Text, " ");
                        }
                        var s = operatorInfo[i];
                        output.Write('A' <= s[0] && s[0] <= 'Z' ? DbgTextColor.Keyword : DbgTextColor.Operator, s);
                    }
                    WriteGenericMethodArguments(output, method, typeFormatter);
                }
                else
                {
                    output.Write(TypeFormatterUtils.GetColor(method, canBeModule: true), Formatters.VisualBasic.VisualBasicTypeFormatter.GetFormattedIdentifier(method.Name));
                    valueFormatter.WriteTokenComment(method.MetadataToken);
                    WriteGenericMethodArguments(output, method, typeFormatter);
                }
            }
        }
        bool TryFormatTuple(DbgDotNetValue value, int tupleArity)
        {
            Debug.Assert(TypeFormatterUtils.GetTupleArity(value.Type) == tupleArity && tupleArity > 0);
            OutputWrite(TupleTypeOpenParen, DbgTextColor.Punctuation);

            var values  = ObjectCache.AllocDotNetValueList();
            var runtime = evalInfo.Runtime.GetDotNetRuntime();
            int index   = 0;

            foreach (var info in TupleTypeUtils.GetTupleFields(value.Type, tupleArity))
            {
                if (index++ > 0)
                {
                    OutputWrite(",", DbgTextColor.Punctuation);
                    WriteSpace();
                }
                if (info.tupleIndex < 0)
                {
                    OutputWrite("???", DbgTextColor.Error);
                    break;
                }
                else
                {
                    var objValue = value;
                    DbgDotNetValueResult valueResult = default;
                    try {
                        foreach (var field in info.fields)
                        {
                            valueResult = runtime.LoadField(evalInfo, objValue, field);
                            if (valueResult.Value != null)
                            {
                                values.Add(valueResult.Value);
                            }
                            if (valueResult.HasError || valueResult.ValueIsException)
                            {
                                objValue = null;
                                break;
                            }
                            objValue = valueResult.Value;
                        }
                        valueResult = default;
                        if (objValue == null)
                        {
                            OutputWrite("???", DbgTextColor.Error);
                            break;
                        }
                        Format(objValue);
                    }
                    finally {
                        valueResult.Value?.Dispose();
                        foreach (var v in values)
                        {
                            v?.Dispose();
                        }
                        values.Clear();
                    }
                }
            }
            ObjectCache.Free(ref values);

            OutputWrite(TupleTypeCloseParen, DbgTextColor.Punctuation);
            return(true);
        }
Example #15
0
        public void Format(DmdType type, DbgDotNetValue value)
        {
            if ((object)type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            List <(DmdType type, DbgDotNetValue value)> arrayTypesList = null;

            try {
                if (recursionCounter++ >= MAX_RECURSION)
                {
                    return;
                }

                switch (type.TypeSignatureKind)
                {
                case DmdTypeSignatureKind.SZArray:
                case DmdTypeSignatureKind.MDArray:
                    // Array types are shown in reverse order
                    arrayTypesList = new List <(DmdType type, DbgDotNetValue value)>();
                    do
                    {
                        arrayTypesList.Add((type, arrayTypesList.Count == 0 ? value : null));
                        type = type.GetElementType();
                    } while (type.IsArray);
                    var t = arrayTypesList[arrayTypesList.Count - 1];
                    Format(t.type.GetElementType(), null);
                    foreach (var tuple in arrayTypesList)
                    {
                        var  aryType  = tuple.type;
                        var  aryValue = tuple.value;
                        uint elementCount;
                        if (aryType.IsVariableBoundArray)
                        {
                            OutputWrite(ARRAY_OPEN_PAREN, BoxedTextColor.Punctuation);
                            int rank = Math.Min(aryType.GetArrayRank(), MAX_ARRAY_RANK);
                            if (rank <= 0)
                            {
                                OutputWrite("???", BoxedTextColor.Error);
                            }
                            else
                            {
                                if (rank == 1)
                                {
                                    OutputWrite("*", BoxedTextColor.Operator);
                                }
                                if (aryValue == null || aryValue.IsNull || !aryValue.GetArrayInfo(out elementCount, out var dimensionInfos))
                                {
                                    dimensionInfos = null;
                                }
                                if (ShowArrayValueSizes && dimensionInfos != null && dimensionInfos.Length == rank)
                                {
                                    for (int i = 0; i < rank; i++)
                                    {
                                        if (i > 0)
                                        {
                                            OutputWrite(",", BoxedTextColor.Punctuation);
                                            WriteSpace();
                                        }
                                        if (dimensionInfos[i].BaseIndex == 0)
                                        {
                                            WriteUInt32(dimensionInfos[i].Length);
                                        }
                                        else
                                        {
                                            WriteInt32(dimensionInfos[i].BaseIndex);
                                            OutputWrite("..", BoxedTextColor.Operator);
                                            WriteInt32(dimensionInfos[i].BaseIndex + (int)dimensionInfos[i].Length - 1);
                                        }
                                    }
                                }
                                else
                                {
                                    OutputWrite(TypeFormatterUtils.GetArrayCommas(rank), BoxedTextColor.Punctuation);
                                }
                            }
                            OutputWrite(ARRAY_CLOSE_PAREN, BoxedTextColor.Punctuation);
                        }
                        else
                        {
                            Debug.Assert(aryType.IsSZArray);
                            OutputWrite(ARRAY_OPEN_PAREN, BoxedTextColor.Punctuation);
                            if (ShowArrayValueSizes && aryValue != null && !aryValue.IsNull)
                            {
                                if (aryValue.GetArrayCount(out elementCount))
                                {
                                    WriteUInt32(elementCount);
                                }
                            }
                            OutputWrite(ARRAY_CLOSE_PAREN, BoxedTextColor.Punctuation);
                        }
                    }
                    break;

                case DmdTypeSignatureKind.Pointer:
                    Format(type.GetElementType(), null);
                    OutputWrite("*", BoxedTextColor.Operator);
                    break;

                case DmdTypeSignatureKind.ByRef:
                    OutputWrite(BYREF_KEYWORD, BoxedTextColor.Keyword);
                    WriteSpace();
                    Format(type.GetElementType(), value?.LoadIndirect());
                    break;

                case DmdTypeSignatureKind.TypeGenericParameter:
                    WriteIdentifier(type.MetadataName, BoxedTextColor.TypeGenericParameter);
                    break;

                case DmdTypeSignatureKind.MethodGenericParameter:
                    WriteIdentifier(type.MetadataName, BoxedTextColor.MethodGenericParameter);
                    break;

                case DmdTypeSignatureKind.Type:
                case DmdTypeSignatureKind.GenericInstance:
                    if (type.IsNullable)
                    {
                        Format(type.GetNullableElementType(), null);
                        OutputWrite("?", BoxedTextColor.Operator);
                    }
                    else if (TypeFormatterUtils.IsTupleType(type))
                    {
                        OutputWrite(TUPLE_OPEN_PAREN, BoxedTextColor.Punctuation);
                        var tupleType  = type;
                        int tupleIndex = 0;
                        for (;;)
                        {
                            tupleType = WriteTupleFields(tupleType, ref tupleIndex);
                            if ((object)tupleType != null)
                            {
                                WriteCommaSpace();
                            }
                            else
                            {
                                break;
                            }
                        }
                        OutputWrite(TUPLE_CLOSE_PAREN, BoxedTextColor.Punctuation);
                    }
                    else
                    {
                        var         genericArgs      = type.GetGenericArguments();
                        int         genericArgsIndex = 0;
                        KeywordType keywordType;
                        if ((object)type.DeclaringType == null)
                        {
                            keywordType = GetKeywordType(type);
                            if (keywordType == KeywordType.NoKeyword)
                            {
                                WriteNamespace(type);
                            }
                            WriteTypeName(type, keywordType);
                            WriteGenericArguments(type, genericArgs, ref genericArgsIndex);
                        }
                        else
                        {
                            var typesList = new List <DmdType>();
                            typesList.Add(type);
                            while (type.DeclaringType != null)
                            {
                                type = type.DeclaringType;
                                typesList.Add(type);
                            }
                            keywordType = GetKeywordType(type);
                            if (keywordType == KeywordType.NoKeyword)
                            {
                                WriteNamespace(type);
                            }
                            for (int i = typesList.Count - 1; i >= 0; i--)
                            {
                                WriteTypeName(typesList[i], i == 0 ? keywordType : KeywordType.NoKeyword);
                                WriteGenericArguments(typesList[i], genericArgs, ref genericArgsIndex);
                                if (i != 0)
                                {
                                    OutputWrite(".", BoxedTextColor.Operator);
                                }
                            }
                        }
                    }
                    break;

                case DmdTypeSignatureKind.FunctionPointer:
                    //TODO:
                    OutputWrite("fnptr", BoxedTextColor.Keyword);
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }
            finally {
                recursionCounter--;
                if (arrayTypesList != null)
                {
                    foreach (var info in arrayTypesList)
                    {
                        if (info.value != value)
                        {
                            info.value?.Dispose();
                        }
                    }
                }
            }
        }
Example #16
0
        public void Format(DmdType type, DbgDotNetValue?value)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            List <(DmdType type, DbgDotNetValue?value)>?arrayTypesList = null;
            DbgDotNetValue?disposeThisValue = null;

            try {
                if (recursionCounter++ >= MAX_RECURSION)
                {
                    return;
                }

                switch (type.TypeSignatureKind)
                {
                case DmdTypeSignatureKind.SZArray:
                case DmdTypeSignatureKind.MDArray:
                    // Array types are shown in reverse order
                    arrayTypesList = new List <(DmdType type, DbgDotNetValue?value)>();
                    do
                    {
                        arrayTypesList.Add((type, arrayTypesList.Count == 0 ? value : null));
                        type = type.GetElementType() !;
                    } while (type.IsArray);
                    var t = arrayTypesList[arrayTypesList.Count - 1];
                    Format(t.type.GetElementType() !, null);
                    foreach (var tuple in arrayTypesList)
                    {
                        var  aryType  = tuple.type;
                        var  aryValue = tuple.value;
                        uint elementCount;
                        if (aryType.IsVariableBoundArray)
                        {
                            OutputWrite(ARRAY_OPEN_PAREN, DbgTextColor.Punctuation);
                            int rank = Math.Min(aryType.GetArrayRank(), MAX_ARRAY_RANK);
                            if (rank <= 0)
                            {
                                OutputWrite("???", DbgTextColor.Error);
                            }
                            else
                            {
                                if (aryValue is null || aryValue.IsNull || !aryValue.GetArrayInfo(out elementCount, out var dimensionInfos))
                                {
                                    dimensionInfos = null;
                                }
                                if (ShowArrayValueSizes && dimensionInfos is not null && dimensionInfos.Length == rank)
                                {
                                    for (int i = 0; i < rank; i++)
                                    {
                                        if (i > 0)
                                        {
                                            OutputWrite(",", DbgTextColor.Punctuation);
                                            WriteSpace();
                                        }
                                        if (dimensionInfos[i].BaseIndex == 0)
                                        {
                                            WriteUInt32(dimensionInfos[i].Length);
                                        }
                                        else
                                        {
                                            WriteInt32(dimensionInfos[i].BaseIndex);
                                            OutputWrite("..", DbgTextColor.Operator);
                                            WriteInt32(dimensionInfos[i].BaseIndex + (int)dimensionInfos[i].Length - 1);
                                        }
                                    }
                                }
                                else
                                {
                                    if (rank == 1)
                                    {
                                        OutputWrite("*", DbgTextColor.Operator);
                                    }
                                    OutputWrite(TypeFormatterUtils.GetArrayCommas(rank), DbgTextColor.Punctuation);
                                }
                            }
                            OutputWrite(ARRAY_CLOSE_PAREN, DbgTextColor.Punctuation);
                        }
                        else
                        {
                            Debug.Assert(aryType.IsSZArray);
                            OutputWrite(ARRAY_OPEN_PAREN, DbgTextColor.Punctuation);
                            if (ShowArrayValueSizes && aryValue is not null && !aryValue.IsNull)
                            {
                                if (aryValue.GetArrayCount(out elementCount))
                                {
                                    WriteUInt32(elementCount);
                                }
                            }
                            OutputWrite(ARRAY_CLOSE_PAREN, DbgTextColor.Punctuation);
                        }
                    }