Skip to content

Commit b3750a7

Browse files
committed
Add a PrettyStackTrace for working with Clang types.
1 parent a014248 commit b3750a7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/swift/AST/PrettyStackTrace.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include "swift/AST/Identifier.h"
2525
#include "swift/AST/Type.h"
2626

27+
namespace clang {
28+
class Type;
29+
}
30+
2731
namespace swift {
2832
class ASTContext;
2933
class Decl;
@@ -132,6 +136,17 @@ class PrettyStackTraceType : public llvm::PrettyStackTraceEntry {
132136
virtual void print(llvm::raw_ostream &OS) const;
133137
};
134138

139+
/// PrettyStackTraceClangType - Observe that we are processing a
140+
/// specific Clang type.
141+
class PrettyStackTraceClangType : public llvm::PrettyStackTraceEntry {
142+
const clang::Type *TheType;
143+
const char *Action;
144+
public:
145+
PrettyStackTraceClangType(const char *action, const clang::Type *type)
146+
: TheType(type), Action(action) {}
147+
virtual void print(llvm::raw_ostream &OS) const;
148+
};
149+
135150
/// Observe that we are processing a specific type representation.
136151
class PrettyStackTraceTypeRepr : public llvm::PrettyStackTraceEntry {
137152
ASTContext &Context;

lib/AST/PrettyStackTrace.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/AST/TypeRepr.h"
2828
#include "swift/AST/TypeVisitor.h"
2929
#include "swift/Basic/SourceManager.h"
30+
#include "clang/AST/Type.h"
3031
#include "llvm/Support/raw_ostream.h"
3132
#include "llvm/Support/MemoryBuffer.h"
3233

@@ -209,6 +210,15 @@ void swift::printTypeDescription(llvm::raw_ostream &out, Type type,
209210
if (addNewline) out << '\n';
210211
}
211212

213+
void PrettyStackTraceClangType::print(llvm::raw_ostream &out) const {
214+
out << "While " << Action << ' ';
215+
if (TheType == nullptr) {
216+
out << "NULL clang type!\n";
217+
return;
218+
}
219+
TheType->dump(out);
220+
}
221+
212222
void PrettyStackTraceTypeRepr::print(llvm::raw_ostream &out) const {
213223
out << "While " << Action << " type ";
214224
TheType->print(out);

0 commit comments

Comments
 (0)