Helper method to generate the dump expression for a field
(CppType type, string variableAccess)
| 103 | |
| 104 | // Helper method to generate the dump expression for a field |
| 105 | static string GetDumpExpression(CppType type, string variableAccess) |
| 106 | { |
| 107 | var unwrappedType = UnwrapType(type); |
| 108 | |
| 109 | if (unwrappedType is CppPrimitiveType cppPrim) { |
| 110 | if (cppPrim.FullName == "char" || cppPrim.FullName == "unsigned char") { |
| 111 | return $"(int){variableAccess}"; |
| 112 | } |
| 113 | return variableAccess; |
| 114 | } |
| 115 | else if (unwrappedType is CppClass) { |
| 116 | return $"DumpGenerated({variableAccess})"; |
| 117 | } |
| 118 | else if (unwrappedType is CppEnum) { |
| 119 | return $"DumpGenerated({variableAccess})"; |
| 120 | } |
| 121 | else if (unwrappedType is CppArrayType arrayType) { |
| 122 | var elementType = UnwrapType(arrayType.ElementType); |
| 123 | // special case for char arrays, dump as c-string |
| 124 | if (elementType.FullName == "char") { |
| 125 | return variableAccess; |
| 126 | } |
| 127 | // sized arrays can be displayed |
| 128 | else { |
| 129 | var isPrimitiveString = elementType is CppPrimitiveType ? "true" : "false"; |
| 130 | var name = arrayType.ElementType is CppTypedef typedef ? typedef.Name : arrayType.ElementType.FullName; |
| 131 | return $"DumpArray_<{name}, {arrayType.Size}, {isPrimitiveString}>({variableAccess})"; |
| 132 | } |
| 133 | } |
| 134 | else if (unwrappedType is CppPointerType pointerType) { |
| 135 | return $"({variableAccess} ? std::format(\"0x{{:016X}}\", reinterpret_cast<std::uintptr_t>({variableAccess})) : \"null\"s)"; |
| 136 | } |
| 137 | return "\"{ unsupported }\""; |
| 138 | } |
| 139 | |
| 140 | static CppType UnwrapType(CppType type) |
| 141 | { |
nothing calls this directly
no outgoing calls
no test coverage detected