-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[JSON][NFC] Support print
and dump
methods in json::Value
#129302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-support Author: Nikolay Panchenko (npanchen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/129302.diff 2 Files Affected:
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<json::Array>() : 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;
|
@nikic ping |
@@ -472,6 +472,14 @@ class Value { | |||
return LLVM_LIKELY(Type == T_Array) ? &as<json::Array>() : nullptr; | |||
} | |||
|
|||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | |||
void print(llvm::raw_ostream &OS) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need print() if we already have operator<<? Esp. as they don't quite match in this implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate why they don't match ?
I've added print
more for completeness as usually classes do have a pair to print (w/o \n) and dump(w/ \n)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate why they don't match ?
Nevermind, I misread the code.
@nikic pin |
@@ -472,6 +472,14 @@ class Value { | |||
return LLVM_LIKELY(Type == T_Array) ? &as<json::Array>() : nullptr; | |||
} | |||
|
|||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | |||
void print(llvm::raw_ostream &OS) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate why they don't match ?
Nevermind, I misread the code.
@npanchen Having this conditional compilation inside a header file breaks the linking phase in out-of-tree projects which are built in debug mode (that is, with the NDEBUG variable not defined) and at the same time link with a release build of LLVM (that is, with the NDEBUG variable defined). |
@mscuttari #131639 that should fix it. However, I'm not sure using debug header file and linking with release is what needs to be handled by community. |
Thanks for the update, I will build the proposed version and see it actually fixes the problem. |
That's why I'm not sure. On one hand I do agree that it makes life of the downstream project easier, on another I was hearing |
No description provided.