Skip to content

Commit 81bee08

Browse files
committed
[AST] Make ValueDecls displayable via their DeclRefs.
1 parent b6c5830 commit 81bee08

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/ADT/DenseMap.h"
3838
#include "llvm/ADT/DenseSet.h"
3939
#include "llvm/Support/TrailingObjects.h"
40+
#include <type_traits>
4041

4142
namespace swift {
4243
enum class AccessSemantics : unsigned char;
@@ -6765,6 +6766,9 @@ inline EnumElementDecl *EnumDecl::getUniqueElement(bool hasValue) const {
67656766
std::pair<DefaultArgumentKind, Type>
67666767
getDefaultArgumentInfo(ValueDecl *source, unsigned Index);
67676768

6769+
/// Display ValueDecl subclasses.
6770+
void simple_display(llvm::raw_ostream &out, const ValueDecl *&decl);
6771+
67686772
} // end namespace swift
67696773

67706774
#endif

include/swift/Basic/SimpleDisplay.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,36 @@
2525

2626
namespace swift {
2727
template<typename T>
28-
void simple_display(llvm::raw_ostream &out, const T &value) {
28+
struct HasTrivialDisplay {
29+
static const bool value = false;
30+
};
31+
32+
#define HAS_TRIVIAL_DISPLAY(Type) \
33+
template<> \
34+
struct HasTrivialDisplay<Type> { \
35+
static const bool value = true; \
36+
}
37+
38+
HAS_TRIVIAL_DISPLAY(unsigned char);
39+
HAS_TRIVIAL_DISPLAY(signed char);
40+
HAS_TRIVIAL_DISPLAY(char);
41+
HAS_TRIVIAL_DISPLAY(short);
42+
HAS_TRIVIAL_DISPLAY(unsigned short);
43+
HAS_TRIVIAL_DISPLAY(int);
44+
HAS_TRIVIAL_DISPLAY(unsigned int);
45+
HAS_TRIVIAL_DISPLAY(long);
46+
HAS_TRIVIAL_DISPLAY(unsigned long);
47+
HAS_TRIVIAL_DISPLAY(long long);
48+
HAS_TRIVIAL_DISPLAY(unsigned long long);
49+
HAS_TRIVIAL_DISPLAY(float);
50+
HAS_TRIVIAL_DISPLAY(double);
51+
HAS_TRIVIAL_DISPLAY(bool);
52+
53+
#undef HAS_TRIVIAL_DISPLAY
54+
55+
template<typename T>
56+
typename std::enable_if<HasTrivialDisplay<T>::value>::type
57+
simple_display(llvm::raw_ostream &out, const T &value) {
2958
out << value;
3059
}
3160

lib/AST/Decl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5731,3 +5731,8 @@ NominalTypeDecl *TypeOrExtensionDecl::getBaseNominal() const {
57315731
return getAsDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
57325732
}
57335733
bool TypeOrExtensionDecl::isNull() const { return Decl.isNull(); }
5734+
5735+
void swift::simple_display(llvm::raw_ostream &out, const ValueDecl *&decl) {
5736+
if (decl) decl->dumpRef(out);
5737+
else out << "(null)";
5738+
}

test/decl/class/circular_inheritance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Outer3
4242
}
4343

4444
// CHECK: ===CYCLE DETECTED===
45-
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest
45+
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest({{.*Left}}
4646
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Left@
4747
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest
4848
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Right@

0 commit comments

Comments
 (0)