]> granicus.if.org Git - clang/commitdiff
replace a dirty hack with a clean solution. Too bad we can't
authorChris Lattner <sabre@nondot.org>
Thu, 19 Feb 2009 23:53:20 +0000 (23:53 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 19 Feb 2009 23:53:20 +0000 (23:53 +0000)
use Blocks for our callbacks ;-)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65083 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
lib/Sema/Sema.cpp

index 42b019df06fe9cc8ad2991c9069aaf489773a63b..387120ea3d2f4aed9fb580fca8b981fd71fa3fb7 100644 (file)
@@ -283,7 +283,8 @@ public:
   /// ObjCQualifiedInterfaceType type for the given interface decl and
   /// the conforming protocol list.
   QualType getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl,
-             ObjCProtocolDecl **ProtocolList, unsigned NumProtocols);
+                                         ObjCProtocolDecl **ProtocolList,
+                                         unsigned NumProtocols);
   
   /// getObjCQualifiedIdType - Return an ObjCQualifiedIdType for a 
   /// given 'id' and conforming protocol list.
index c6e91a9a46128920f4d6629af3e77f7f6b880227..db62ca95e75852d28c48c55194d0cdffec37d3fb 100644 (file)
@@ -125,7 +125,9 @@ private:
   typedef void (*ArgToStringFnTy)(ArgumentKind Kind, intptr_t Val,
                                   const char *Modifier, unsigned ModifierLen,
                                   const char *Argument, unsigned ArgumentLen,
-                                  llvm::SmallVectorImpl<char> &Output);
+                                  llvm::SmallVectorImpl<char> &Output,
+                                  void *Cookie);
+  void *ArgToStringCookie;
   ArgToStringFnTy ArgToStringFn;
 public:
   explicit Diagnostic(DiagnosticClient *client = 0);
@@ -202,11 +204,13 @@ public:
                           const char *Modifier, unsigned ModLen,
                           const char *Argument, unsigned ArgLen,
                           llvm::SmallVectorImpl<char> &Output) const {
-    ArgToStringFn(Kind, Val, Modifier, ModLen, Argument, ArgLen, Output);
+    ArgToStringFn(Kind, Val, Modifier, ModLen, Argument, ArgLen, Output,
+                  ArgToStringCookie);
   }
   
-  void SetArgToStringFn(ArgToStringFnTy Fn) {
+  void SetArgToStringFn(ArgToStringFnTy Fn, void *Cookie) {
     ArgToStringFn = Fn;
+    ArgToStringCookie = Cookie;
   }
   
   //===--------------------------------------------------------------------===//
index 83ccd22e2843b287b60fdd03898acd62c5237c3b..893eae5d1a97d6f3338e705a5f7f4a1fddc722fe 100644 (file)
@@ -175,7 +175,8 @@ namespace clang {
 static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT,
                                const char *Modifier, unsigned ML,
                                const char *Argument, unsigned ArgLen,
-                               llvm::SmallVectorImpl<char> &Output) {
+                               llvm::SmallVectorImpl<char> &Output,
+                               void *Cookie) {
   const char *Str = "<can't format argument>";
   Output.append(Str, Str+strlen(Str));
 }
@@ -199,6 +200,7 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
   LastDiagLevel = Fatal;
   
   ArgToStringFn = DummyArgToStringFn;
+  ArgToStringCookie = 0;
 }
 
 Diagnostic::~Diagnostic() {
index 1ffaf939eff11550cf05b885cb0973e80fcf2cb3..2bb6a17ac10861b26ab0fa1527b203c0445e984e 100644 (file)
@@ -24,7 +24,9 @@ using namespace clang;
 static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val,
                                  const char *Modifier, unsigned ModLen,
                                  const char *Argument, unsigned ArgLen,
-                                 llvm::SmallVectorImpl<char> &Output) {
+                                 llvm::SmallVectorImpl<char> &Output,
+                                 void *Cookie) {
+  ASTContext &Context = *static_cast<ASTContext*>(Cookie);
   
   std::string S;
   if (Kind == Diagnostic::ak_qualtype) {
@@ -47,8 +49,14 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val,
         // it will turn into an attribute mess. People want their "vec4".
         !isa<VectorType>(DesugaredTy) &&
       
-        // Don't desugar objc types.  FIXME: THIS IS A HACK.
-        S != "id" && S != "Class") {
+        // Don't desugar magic Objective-C types.
+        Ty.getUnqualifiedType() != Context.getObjCIdType() &&
+        Ty.getUnqualifiedType() != Context.getObjCSelType() &&
+        Ty.getUnqualifiedType() != Context.getObjCProtoType() &&
+        Ty.getUnqualifiedType() != Context.getObjCClassType() &&
+        
+        // Not va_list.
+        Ty.getUnqualifiedType() != Context.getBuiltinVaListType()) {
       S = "'"+S+"' (aka '";
       S += DesugaredTy.getAsString();
       S += "')";
@@ -165,7 +173,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
     FieldCollector.reset(new CXXFieldCollector());
       
   // Tell diagnostics how to render things from the AST library.
-  PP.getDiagnostics().SetArgToStringFn(ConvertArgToStringFn);
+  PP.getDiagnostics().SetArgToStringFn(ConvertArgToStringFn, &Context);
 }
 
 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.