Skip to content

Commit

Permalink
Clarify abseil formatter helpers
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Korobeynikov <[email protected]>
  • Loading branch information
asl committed Nov 4, 2024
1 parent 8cbf376 commit aa0d7d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ir/id.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ struct ID : Util::IHasSourceInfo, public IHasDbPrint {
Util::SourceInfo getSourceInfo() const override { return srcInfo; }
cstring toString() const override { return originalName.isNullOrEmpty() ? name : originalName; }

/// Helper to simplify usage of ID in Abseil functions (e.g. StrCat / StrFormat, etc.) without
/// explicit string_view conversion.
template <typename Sink>
friend void AbslStringify(Sink &sink, const ID &id) {
sink.Append(id.string_view());
Expand Down
3 changes: 3 additions & 0 deletions ir/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class Node : public virtual INode {

bool operator!=(const Node &n) const { return !operator==(n); }

/// Helper to simplify usage of nodes in Abseil functions (e.g. StrCat / StrFormat, etc.)
/// without explicit string_view conversion. Note that this calls Node::toString() so might
/// not be always appropriate for user-visible messages / strings.
template <typename Sink>
friend void AbslStringify(Sink &sink, const IR::Node *n) {
sink.Append(n->toString());
Expand Down
2 changes: 2 additions & 0 deletions lib/cstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ class cstring {
/// Append this many spaces after each newline (and before the first string).
cstring indent(size_t amount) const;

/// Helper to simplify usage of cstring in Abseil functions (e.g. StrCat / StrFormat, etc.)
/// without explicit string_view conversion.
template <typename Sink>
friend void AbslStringify(Sink &sink, cstring s) {
sink.Append(s.string_view());
Expand Down

0 comments on commit aa0d7d0

Please sign in to comment.