sammccall created this revision. sammccall added a reviewer: mboehme. Herald added a project: All. sammccall requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This is more useful for debug/test than getNullabilitySpelling: - default form has uglifying underscores - non-default form crashes on NullableResult - both return unhelpfully verbose strings for Unspecified - operator<< works with gtest, formatv, etc Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D149650 Files: clang/include/clang/Basic/Specifiers.h clang/lib/Basic/IdentifierTable.cpp Index: clang/lib/Basic/IdentifierTable.cpp =================================================================== --- clang/lib/Basic/IdentifierTable.cpp +++ clang/lib/Basic/IdentifierTable.cpp @@ -849,6 +849,20 @@ llvm_unreachable("Unknown nullability kind."); } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NullabilityKind NK) { + switch (NK) { + case NullabilityKind::NonNull: + return OS << "NonNull"; + case NullabilityKind::Nullable: + return OS << "Nullable"; + case NullabilityKind::NullableResult: + return OS << "NullableResult"; + case NullabilityKind::Unspecified: + return OS << "Unspecified"; + } + llvm_unreachable("Unknown nullability kind."); +} + diag::kind IdentifierTable::getFutureCompatDiagKind(const IdentifierInfo &II, const LangOptions &LangOpts) { Index: clang/include/clang/Basic/Specifiers.h =================================================================== --- clang/include/clang/Basic/Specifiers.h +++ clang/include/clang/Basic/Specifiers.h @@ -19,6 +19,9 @@ #include "llvm/Support/DataTypes.h" #include "llvm/Support/ErrorHandling.h" +namespace llvm { +class raw_ostream; +} // namespace llvm namespace clang { /// Define the meaning of possible values of the kind in ExplicitSpecifier. @@ -333,6 +336,8 @@ // parameters are assumed to only get null on error. NullableResult, }; + /// Prints human-readable debug representation. + llvm::raw_ostream &operator<<(llvm::raw_ostream&, NullabilityKind); /// Return true if \p L has a weaker nullability annotation than \p R. The /// ordering is: Unspecified < Nullable < NonNull.
Index: clang/lib/Basic/IdentifierTable.cpp =================================================================== --- clang/lib/Basic/IdentifierTable.cpp +++ clang/lib/Basic/IdentifierTable.cpp @@ -849,6 +849,20 @@ llvm_unreachable("Unknown nullability kind."); } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NullabilityKind NK) { + switch (NK) { + case NullabilityKind::NonNull: + return OS << "NonNull"; + case NullabilityKind::Nullable: + return OS << "Nullable"; + case NullabilityKind::NullableResult: + return OS << "NullableResult"; + case NullabilityKind::Unspecified: + return OS << "Unspecified"; + } + llvm_unreachable("Unknown nullability kind."); +} + diag::kind IdentifierTable::getFutureCompatDiagKind(const IdentifierInfo &II, const LangOptions &LangOpts) { Index: clang/include/clang/Basic/Specifiers.h =================================================================== --- clang/include/clang/Basic/Specifiers.h +++ clang/include/clang/Basic/Specifiers.h @@ -19,6 +19,9 @@ #include "llvm/Support/DataTypes.h" #include "llvm/Support/ErrorHandling.h" +namespace llvm { +class raw_ostream; +} // namespace llvm namespace clang { /// Define the meaning of possible values of the kind in ExplicitSpecifier. @@ -333,6 +336,8 @@ // parameters are assumed to only get null on error. NullableResult, }; + /// Prints human-readable debug representation. + llvm::raw_ostream &operator<<(llvm::raw_ostream&, NullabilityKind); /// Return true if \p L has a weaker nullability annotation than \p R. The /// ordering is: Unspecified < Nullable < NonNull.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits