Skip to content

[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

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/include/llvm/Support/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

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.

Copy link
Contributor Author

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)

Copy link
Contributor

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.

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);
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Support/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading