]> granicus.if.org Git - clang/commitdiff
Selector: (changes made after discussing this more with Steve Naroff)
authorTed Kremenek <kremenek@apple.com>
Sat, 7 Mar 2009 01:22:02 +0000 (01:22 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 7 Mar 2009 01:22:02 +0000 (01:22 +0000)
- Make Selector::getAsIdentifierInfo() private.  Using IdentifierInfo* in
  Selector is an implementation detail that clients shouldn't think about.
- Modify diagnostic emission in Sema::ProcessPropertyDecl to not use
  Selector::getAsIdentifierInfo() (which could crash when IdentifierInfo* is
  null) and instead use Selector::getAsString().
- Tidy up Selector::getAsString() implementation.

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

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

index 32818a91371020771705a4939c3648fb61ca6e98..2584136ec4be4b9e5f3b4651565af9b01061404f 100644 (file)
@@ -353,13 +353,6 @@ class Selector {
     assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
   }
   Selector(uintptr_t V) : InfoPtr(V) {}
-public:
-  friend class SelectorTable; // only the SelectorTable can create these
-  friend class DeclarationName; // and the AST's DeclarationName.
-
-  /// The default ctor should only be used when creating data structures that
-  ///  will contain selectors.
-  Selector() : InfoPtr(0) {}
   
   IdentifierInfo *getAsIdentifierInfo() const {
     if (getIdentifierInfoFlag())
@@ -369,6 +362,14 @@ public:
   unsigned getIdentifierInfoFlag() const {
     return InfoPtr & ArgFlags;
   }
+public:
+  friend class SelectorTable; // only the SelectorTable can create these
+  friend class DeclarationName; // and the AST's DeclarationName.
+
+  /// The default ctor should only be used when creating data structures that
+  ///  will contain selectors.
+  Selector() : InfoPtr(0) {}
+
   /// operator==/!= - Indicate whether the specified selectors are identical.
   bool operator==(Selector RHS) const {
     return InfoPtr == RHS.InfoPtr;
index 4e2e7005e3ede0b1a1b3719bd8cdc17cc8be38a5..f4acbec0199418a46b6856e538fde7a872aa7d16 100644 (file)
@@ -352,8 +352,9 @@ std::string Selector::getAsString() const {
   if (InfoPtr & ArgFlags) {
     IdentifierInfo *II = getAsIdentifierInfo();
     
+    // If the number of arguments is 0 then II is guaranteed to not be null.
     if (getNumArgs() == 0)
-      return II ? II->getName() : "";
+      return II->getName();
 
     std::string Res = II ? II->getName() : "";
     Res += ":";
index 476b6afea57151c62ae54f1f6f82f7f1193564ed..f91feb423f9a41588f6b7f55a7b19c3c0f06f8b5 100644 (file)
@@ -1139,7 +1139,7 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
     Diag(property->getLocation(), 
          diag::err_accessor_property_type_mismatch) 
       << property->getDeclName()
-      << GetterMethod->getSelector().getAsIdentifierInfo();
+      << GetterMethod->getSelector().getAsString();
     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().getAsIdentifierInfo();
+        << SetterMethod->getSelector().getAsString();
       Diag(SetterMethod->getLocation(), diag::note_declared_at);
     }
   }