diff --git a/src/coreclr/inc/cor.h b/src/coreclr/inc/cor.h index 636e4ec82b4c1..7771f9ca5fe88 100644 --- a/src/coreclr/inc/cor.h +++ b/src/coreclr/inc/cor.h @@ -1808,10 +1808,14 @@ FORCEINLINE ULONG CorSigUncompressData( } inline ULONG CorSigUncompressConstTypeArgData( - PCCOR_SIGNATURE & pData) // [IN,OUT] compressed const type argument data + PCCOR_SIGNATURE & pData, // [IN,OUT] compressed const type argument data + CorElementType* pType = NULL) // [OUT] const type argument type { ULONG size = 1; - switch (*pData++) + CorElementType type = (CorElementType)*pData++; + if (pType) + *pType = type; + switch (type) { case ELEMENT_TYPE_BOOLEAN : case ELEMENT_TYPE_I1 : diff --git a/src/coreclr/vm/sigformat.cpp b/src/coreclr/vm/sigformat.cpp index 52ac7f9ad3192..1211898da5569 100644 --- a/src/coreclr/vm/sigformat.cpp +++ b/src/coreclr/vm/sigformat.cpp @@ -338,13 +338,86 @@ void SigFormat::AddTypeString(Module* pModule, SigPointer sig, const SigTypeCont AddString(")"); break; } - + case ELEMENT_TYPE_CTARG: + { + CorElementType constValueType; + uint32_t cbSig; + PCCOR_SIGNATURE pSig; + IfFailThrow(sig.GetConstTypeArg(&constValueType, &cbSig, &pSig)); + uint64_t constValue = 0; + memcpy(&constValue, pSig, cbSig); + AddConstValueTypeString(constValueType, constValue); + break; + } default: AddString("**UNKNOWN TYPE**"); } } +void SigFormat::AddConstValueTypeString(CorElementType constValueType, uint64_t constValue) +{ + AddString("const "); + char buffer[42]; + switch (constValueType) + { + case ELEMENT_TYPE_BOOLEAN: + AddString("Boolean ("); + sprintf_s(buffer, sizeof(buffer), *(uint8_t*)&constValue == 1 ? "true" : "false"); + break; + case ELEMENT_TYPE_I1: + AddString("SByte ("); + sprintf_s(buffer, sizeof(buffer), "%hhd", *(int8_t*)&constValue); + break; + case ELEMENT_TYPE_U1: + AddString("Byte ("); + sprintf_s(buffer, sizeof(buffer), "%hhu", *(uint8_t*)&constValue); + break; + case ELEMENT_TYPE_I2: + AddString("Int16 ("); + sprintf_s(buffer, sizeof(buffer), "%hd", *(int16_t*)&constValue); + break; + case ELEMENT_TYPE_U2: + AddString("UInt16 ("); + sprintf_s(buffer, sizeof(buffer), "%hu", *(uint16_t*)&constValue); + break; + case ELEMENT_TYPE_CHAR: + AddString("Char ("); + sprintf_s(buffer, sizeof(buffer), "0x%04hX", *(uint16_t*)&constValue); + break; + case ELEMENT_TYPE_I4: + AddString("Int32 ("); + sprintf_s(buffer, sizeof(buffer), "%d", *(int32_t*)&constValue); + break; + case ELEMENT_TYPE_U4: + AddString("UInt32 ("); + sprintf_s(buffer, sizeof(buffer), "%u", *(uint32_t*)&constValue); + break; + case ELEMENT_TYPE_I8: + AddString("Int64 ("); + sprintf_s(buffer, sizeof(buffer), "%lld", *(int64_t*)&constValue); + break; + case ELEMENT_TYPE_U8: + AddString("UInt64 ("); + sprintf_s(buffer, sizeof(buffer), "%llu", *(uint64_t*)&constValue); + break; + case ELEMENT_TYPE_R4: + AddString("Single ("); + sprintf_s(buffer, sizeof(buffer), "%f", *(float*)&constValue); + break; + case ELEMENT_TYPE_R8: + AddString("Double ("); + sprintf_s(buffer, sizeof(buffer), "%lf", *(double*)&constValue); + break; + default: + AddString("**UNKNOWN CONST VALUE TYPE** ("); + sprintf_s(buffer, sizeof(buffer), "**UNKNOWN CONST VALUE**"); + break; + } + AddString(buffer); + AddString(")"); +} + void SigFormat::FormatSig(MetaSig &sig, LPCUTF8 szMemberName, LPCUTF8 szClassName, LPCUTF8 szNameSpace) { CONTRACTL @@ -568,7 +641,13 @@ void SigFormat::AddType(TypeHandle th) break; } - + case ELEMENT_TYPE_CTARG: + { + _ASSERTE(th.IsConstValue()); + AddConstValueTypeString(th.AsConstValue()->GetConstValueType().GetInternalCorElementType(), + th.AsConstValue()->GetConstValue()); + break; + } default: AddString("**UNKNOWN TYPE**"); } diff --git a/src/coreclr/vm/sigformat.h b/src/coreclr/vm/sigformat.h index 65a50db0a8448..762b0b1db03bb 100644 --- a/src/coreclr/vm/sigformat.h +++ b/src/coreclr/vm/sigformat.h @@ -35,6 +35,7 @@ class SigFormat size_t _pos; void AddString(LPCUTF8 s); + void AddConstValueTypeString(CorElementType constValueType, uint64_t constValue); void AddTypeString(Module* pModule, SigPointer sig, const SigTypeContext *pTypeContext); };