diff options
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.cpp | 19 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 23 |
2 files changed, 30 insertions, 12 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. diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index ef3ead4fa2..bebde38a18 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2054,7 +2054,7 @@ Sema::CheckCompoundAssignmentConstraints(QualType lhsType, QualType rhsType) { QualType Sema::InvalidOperands(SourceLocation Loc, Expr *&lex, Expr *&rex) { Diag(Loc, diag::err_typecheck_invalid_operands) - << lex->getType().getAsString() << rex->getType().getAsString() + << lex->getType() << rex->getType() << lex->getSourceRange() << rex->getSourceRange(); return QualType(); } @@ -2809,20 +2809,19 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { return Context.getPointerType(op->getType()); } -QualType Sema::CheckIndirectionOperand(Expr *op, SourceLocation OpLoc) { - UsualUnaryConversions(op); - QualType qType = op->getType(); +QualType Sema::CheckIndirectionOperand(Expr *Op, SourceLocation OpLoc) { + UsualUnaryConversions(Op); + QualType Ty = Op->getType(); - if (const PointerType *PT = qType->getAsPointerType()) { - // Note that per both C89 and C99, this is always legal, even - // if ptype is an incomplete type or void. - // It would be possible to warn about dereferencing a - // void pointer, but it's completely well-defined, - // and such a warning is unlikely to catch any mistakes. + // Note that per both C89 and C99, this is always legal, even if ptype is an + // incomplete type or void. It would be possible to warn about dereferencing + // a void pointer, but it's completely well-defined, and such a warning is + // unlikely to catch any mistakes. + if (const PointerType *PT = Ty->getAsPointerType()) return PT->getPointeeType(); - } + Diag(OpLoc, diag::err_typecheck_indirection_requires_pointer) - << qType.getAsString() << op->getSourceRange(); + << Ty << Op->getSourceRange(); return QualType(); } |