Merge pull request #17395 from DougGregor/simple-print-value-decl
diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h
index 2cd9e47..1ebe6ca 100644
--- a/include/swift/AST/Decl.h
+++ b/include/swift/AST/Decl.h
@@ -37,6 +37,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/TrailingObjects.h"
+#include <type_traits>
namespace swift {
enum class AccessSemantics : unsigned char;
@@ -6765,6 +6766,9 @@
std::pair<DefaultArgumentKind, Type>
getDefaultArgumentInfo(ValueDecl *source, unsigned Index);
+/// Display ValueDecl subclasses.
+void simple_display(llvm::raw_ostream &out, const ValueDecl *&decl);
+
} // end namespace swift
#endif
diff --git a/include/swift/Basic/SimpleDisplay.h b/include/swift/Basic/SimpleDisplay.h
index 4033ad0..d2062b4 100644
--- a/include/swift/Basic/SimpleDisplay.h
+++ b/include/swift/Basic/SimpleDisplay.h
@@ -25,7 +25,36 @@
namespace swift {
template<typename T>
- void simple_display(llvm::raw_ostream &out, const T &value) {
+ struct HasTrivialDisplay {
+ static const bool value = false;
+ };
+
+#define HAS_TRIVIAL_DISPLAY(Type) \
+ template<> \
+ struct HasTrivialDisplay<Type> { \
+ static const bool value = true; \
+ }
+
+ HAS_TRIVIAL_DISPLAY(unsigned char);
+ HAS_TRIVIAL_DISPLAY(signed char);
+ HAS_TRIVIAL_DISPLAY(char);
+ HAS_TRIVIAL_DISPLAY(short);
+ HAS_TRIVIAL_DISPLAY(unsigned short);
+ HAS_TRIVIAL_DISPLAY(int);
+ HAS_TRIVIAL_DISPLAY(unsigned int);
+ HAS_TRIVIAL_DISPLAY(long);
+ HAS_TRIVIAL_DISPLAY(unsigned long);
+ HAS_TRIVIAL_DISPLAY(long long);
+ HAS_TRIVIAL_DISPLAY(unsigned long long);
+ HAS_TRIVIAL_DISPLAY(float);
+ HAS_TRIVIAL_DISPLAY(double);
+ HAS_TRIVIAL_DISPLAY(bool);
+
+#undef HAS_TRIVIAL_DISPLAY
+
+ template<typename T>
+ typename std::enable_if<HasTrivialDisplay<T>::value>::type
+ simple_display(llvm::raw_ostream &out, const T &value) {
out << value;
}
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index cc9168b..5dc6783 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -5731,3 +5731,8 @@
return getAsDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
}
bool TypeOrExtensionDecl::isNull() const { return Decl.isNull(); }
+
+void swift::simple_display(llvm::raw_ostream &out, const ValueDecl *&decl) {
+ if (decl) decl->dumpRef(out);
+ else out << "(null)";
+}
diff --git a/test/decl/class/circular_inheritance.swift b/test/decl/class/circular_inheritance.swift
index 5696455..f4dad62 100644
--- a/test/decl/class/circular_inheritance.swift
+++ b/test/decl/class/circular_inheritance.swift
@@ -42,7 +42,7 @@
}
// CHECK: ===CYCLE DETECTED===
-// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest
+// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest({{.*Left}}
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Left@
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Right@