From 24f2056c597ab57b111a10b5eb88958009709335 Mon Sep 17 00:00:00 2001 From: Kolya Panchenko Date: Fri, 28 Feb 2025 15:12:18 -0500 Subject: [PATCH] [JSON][NFC] Support `print` and `dump` methods in `json::Value` --- llvm/include/llvm/Support/JSON.h | 8 ++++++++ llvm/lib/Support/JSON.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/llvm/include/llvm/Support/JSON.h b/llvm/include/llvm/Support/JSON.h index 14a5c7142ed8c..3e3f783ffb857 100644 --- a/llvm/include/llvm/Support/JSON.h +++ b/llvm/include/llvm/Support/JSON.h @@ -472,6 +472,14 @@ class Value { return LLVM_LIKELY(Type == T_Array) ? &as() : nullptr; } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) + void print(llvm::raw_ostream &OS) const; + LLVM_DUMP_METHOD void dump() const { + print(llvm::dbgs()); + llvm::dbgs() << '\n'; + } +#endif // !NDEBUG || LLVM_ENABLE_DUMP + private: void destroy(); void copyFrom(const Value &M); diff --git a/llvm/lib/Support/JSON.cpp b/llvm/lib/Support/JSON.cpp index a5c617bb4a076..98fef5dcf68a3 100644 --- a/llvm/lib/Support/JSON.cpp +++ b/llvm/lib/Support/JSON.cpp @@ -182,6 +182,10 @@ void Value::destroy() { } } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) +void Value::print(llvm::raw_ostream &OS) const { OS << *this; } +#endif // !NDEBUG || LLVM_ENABLE_DUMP + bool operator==(const Value &L, const Value &R) { if (L.kind() != R.kind()) return false;