summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-23 09:13:29 +0000
committerChris Lattner <sabre@nondot.org>2008-11-23 09:13:29 +0000
commit6a2ed6f6dcd63ef05bc094195a646f44e6a2a029 (patch)
treec2e30875c58541688d3b1c5fe43398b7fe1938fd /clang/lib/Sema
parent4e2e9f1a5dc76166ec0b1d8e88502ffc99d7073d (diff)
downloadbcm5719-llvm-6a2ed6f6dcd63ef05bc094195a646f44e6a2a029.tar.gz
bcm5719-llvm-6a2ed6f6dcd63ef05bc094195a646f44e6a2a029.zip
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. llvm-svn: 59907
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/Sema.cpp19
-rw-r--r--clang/lib/Sema/SemaExpr.cpp23
2 files changed, 30 insertions, 12 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 2edf08ec425..d43eadd5744 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/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/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ef3ead4fa2c..bebde38a18b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/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();
}
OpenPOWER on IntegriCloud