]> granicus.if.org Git - clang/commitdiff
Teach Diagnostic about Selector.
authorTed Kremenek <kremenek@apple.com>
Sat, 7 Mar 2009 01:36:13 +0000 (01:36 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 7 Mar 2009 01:36:13 +0000 (01:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66314 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
include/clang/Basic/IdentifierTable.h
lib/Basic/Diagnostic.cpp
lib/Sema/SemaDeclObjC.cpp

index 1bb294e7a488640754b28d98e4cc548ad737c8f4..9dfcf3fe75a5787a0d9d06f4e0aa2d8d78919c52 100644 (file)
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_DIAGNOSTIC_H
 
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/IdentifierTable.h"
 #include <string>
 #include <cassert>
 
@@ -26,7 +27,6 @@ namespace clang {
   class DiagnosticClient;
   class SourceRange;
   class DiagnosticBuilder;
-  class IdentifierInfo;
   
   // Import the diagnostic enums themselves.
   namespace diag {
@@ -142,7 +142,8 @@ public:
     ak_identifierinfo,  // IdentifierInfo
     ak_qualtype,        // QualType
     ak_declarationname, // DeclarationName
-    ak_nameddecl        // NamedDecl *
+    ak_nameddecl,       // NamedDecl *
+    ak_selector         // Selector
   };
   
 private:  
@@ -483,6 +484,13 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
   return DB;
 }
   
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+                                           Selector S) {
+  DB.AddTaggedVal(reinterpret_cast<intptr_t>(S.getAsOpaquePtr()),
+                  Diagnostic::ak_selector);
+  return DB;
+}  
+  
 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                            const SourceRange &R) {
   DB.AddSourceRange(R);
@@ -566,6 +574,12 @@ public:
     return reinterpret_cast<IdentifierInfo*>(DiagObj->DiagArgumentsVal[Idx]);
   }
   
+  /// getArgSelector - Return the specified Selector argument.
+  Selector getArgSelector(unsigned Idx) const {
+    assert(getArgKind(Idx) == Diagnostic::ak_selector &&
+           "invalid argument accessor!");
+    return Selector(DiagObj->DiagArgumentsVal[Idx]);
+  }
   /// getRawArg - Return the specified non-string argument in an opaque form.
   intptr_t getRawArg(unsigned Idx) const {
     assert(getArgKind(Idx) != Diagnostic::ak_std_string &&
index 2584136ec4be4b9e5f3b4651565af9b01061404f..b6cee028f469b97c8cfb688a68105bf5dd906463 100644 (file)
@@ -334,6 +334,8 @@ private:
 /// selectors that take no arguments and selectors that take 1 argument, which 
 /// accounts for 78% of all selectors in Cocoa.h.
 class Selector {
+  friend class DiagnosticInfo;
+  
   enum IdentifierInfoFlag {
     // MultiKeywordSelector = 0.
     ZeroArg  = 0x1,
index 893eae5d1a97d6f3338e705a5f7f4a1fddc722fe..84d4055b78e6fbdf6a99976c16d41950c8ea9ea5 100644 (file)
@@ -657,6 +657,14 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
       OutStr.push_back('\'');
       break;
     }
+    case Diagnostic::ak_selector: {
+      Selector S = getArgSelector(ArgNo);
+      OutStr.push_back('\'');
+      const std::string &s = S.getAsString();
+      OutStr.append(&s[0], &s[0]+s.length());
+      OutStr.push_back('\'');
+      break;
+    }
     case Diagnostic::ak_qualtype:
     case Diagnostic::ak_declarationname:
     case Diagnostic::ak_nameddecl:
index f91feb423f9a41588f6b7f55a7b19c3c0f06f8b5..a26581824f9cada497429bdf706caf0c413f3a6f 100644 (file)
@@ -1139,7 +1139,7 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
     Diag(property->getLocation(), 
          diag::err_accessor_property_type_mismatch) 
       << property->getDeclName()
-      << GetterMethod->getSelector().getAsString();
+      << GetterMethod->getSelector();
     Diag(GetterMethod->getLocation(), diag::note_declared_at);
   }
   
@@ -1152,7 +1152,7 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
       Diag(property->getLocation(), 
            diag::err_accessor_property_type_mismatch) 
         << property->getDeclName()
-        << SetterMethod->getSelector().getAsString();
+        << SetterMethod->getSelector();
       Diag(SetterMethod->getLocation(), diag::note_declared_at);
     }
   }