diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-23 09:13:29 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-23 09:13:29 +0000 |
commit | 22caddc91d2f6186739c6b20ec58ed38cd68e595 (patch) | |
tree | bd4911d506b8d4c84f9f2882398578e2d733cbfe /lib/Sema/Sema.cpp | |
parent | 3fcbb89cacdba42c5571e15ffab549865da181f9 (diff) |
Add support for sending QualType's directly into diags and convert two
diags over to use this. QualTypes implicitly print single quotes around
them for uniformity and future extension.
Doing this requires a little function pointer dance to prevent libbasic
from depending on libast.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59907 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r-- | lib/Sema/Sema.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 2edf08ec42..d43eadd574 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -20,6 +20,22 @@ #include "clang/Basic/Diagnostic.h" using namespace clang; +/// ConvertQualTypeToStringFn - This function is used to pretty print the +/// specified QualType as a string in diagnostics. +static void ConvertQualTypeToStringFn(intptr_t QT, + const char *Modifier, unsigned ML, + const char *Argument, unsigned ArgLen, + llvm::SmallVectorImpl<char> &Output) { + assert(ML == 0 && ArgLen == 0 && "Invalid modifier for QualType argument"); + + QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast<void*>(QT))); + + // FIXME: Playing with std::string is really slow. + std::string S = Ty.getAsString(); + Output.append(S.begin(), S.end()); +} + + static inline RecordDecl *CreateStructDecl(ASTContext &C, const char *Name) { if (C.getLangOptions().CPlusPlus) return CXXRecordDecl::Create(C, TagDecl::TK_struct, @@ -108,6 +124,9 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer) TUScope = 0; if (getLangOptions().CPlusPlus) FieldCollector.reset(new CXXFieldCollector()); + + // Tell diagnostics how to render things from the AST library. + PP.getDiagnostics().SetQualTypeToStringFn(ConvertQualTypeToStringFn); } /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. |