From 6458016449500151053964411398145244374352 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Tue, 20 May 2025 18:36:42 -0400 Subject: Add fmt printer for Ref --- type.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'type.cpp') diff --git a/type.cpp b/type.cpp index f0795ea3..4de8fc91 100644 --- a/type.cpp +++ b/type.cpp @@ -1332,7 +1332,7 @@ bool Type::EnumerateTypesForAccess(BinaryView* data, uint64_t offset, size_t siz std::vector Type::GetLines(const TypeContainer& types, const std::string& name, - int paddingCols, bool collapsed, BNTokenEscapingType escaping) + int paddingCols, bool collapsed, BNTokenEscapingType escaping) const { size_t count; BNTypeDefinitionLine* list = @@ -3110,3 +3110,36 @@ bool BinaryNinja::PreprocessSource( delete[] includeDirList; return result; } + + +fmt::format_context::iterator fmt::formatter::format( + const Type& obj, + fmt::format_context& ctx +) const +{ + if (presentation == '?') + { + auto tc = TypeContainer::GetEmptyTypeContainer(); + auto lines = obj.GetLines(tc, ""); + + string result = ""; + for (auto& line: lines) + { + string lineStr = ""; + for (auto& token: line.tokens) + { + lineStr += token.text; + } + result += lineStr + "\n"; + } + // Remove trailing newline + if (!result.empty()) + result.erase(result.size() - 1); + return fmt::format_to(ctx.out(), "{}", result); + } + else + { + return fmt::format_to(ctx.out(), "{}{}", obj.GetStringBeforeName(), obj.GetStringAfterName()); + } +} + -- cgit v1.3.1