]> granicus.if.org Git - clang/commitdiff
Rename IdentifierInfo::isName to ::isStr. Use a nifty trick
authorChris Lattner <sabre@nondot.org>
Thu, 20 Nov 2008 04:42:34 +0000 (04:42 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 20 Nov 2008 04:42:34 +0000 (04:42 +0000)
from Sebastian to enforce that a literal string is passed in,
and use this to avoid having to call strlen on it.

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

include/clang/Basic/IdentifierTable.h
lib/AST/Expr.cpp
lib/CodeGen/CGObjC.cpp
lib/Parse/ParseObjc.cpp
lib/Sema/SemaDeclAttr.cpp

index 78013047519183eadd5bcbc1db354df5a04dfecc..348ef1477f492e5f75f5ca432b3315d9d0bb358f 100644 (file)
@@ -62,10 +62,11 @@ class IdentifierInfo {
 public:
   IdentifierInfo();
 
-  /// isName - Return true if this is the identifier for the specified string.
-  bool isName(const char *Str) const {
-    unsigned Len = strlen(Str);
-    return getLength() == Len && !memcmp(getName(), Str, Len);
+  /// isStr - Return true if this is the identifier for the specified string.
+  /// This is intended to be used for string literals only: II->isStr("foo").
+  template <std::size_t StrLen>
+  bool isStr(const char (&Str)[StrLen]) const {
+    return getLength() == StrLen-1 && !memcmp(getName(), Str, StrLen-1);
   }
   
   /// getName - Return the actual string for this identifier.  The returned 
index 061402076e53b4a0969be1bc62ae809134da2365..e9d5eb75ea486306a1b604b3fce548cb692b5f3f 100644 (file)
@@ -1165,10 +1165,10 @@ bool ExtVectorElementExpr::containsDuplicateElements() const {
 /// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
 void ExtVectorElementExpr::getEncodedElementAccess(
                                   llvm::SmallVectorImpl<unsigned> &Elts) const {
-  bool isHi =   Accessor.isName("hi");
-  bool isLo =   Accessor.isName("lo");
-  bool isEven = Accessor.isName("e");
-  bool isOdd  = Accessor.isName("o");
+  bool isHi =   Accessor.isStr("hi");
+  bool isLo =   Accessor.isStr("lo");
+  bool isEven = Accessor.isStr("e");
+  bool isOdd  = Accessor.isStr("o");
     
   const char *compStr = Accessor.getName();
   for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
index 4469bab2b2eec45208cb52ec4e0ecac4087bd6da..c2e42d598176284298528c456544984590d9d8b5 100644 (file)
@@ -63,7 +63,7 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E) {
     // Very special case, super send in class method. The receiver is
     // self (the class object) and the send uses super semantics.
     if (!OID) {
-      assert(E->getClassName()->isName("super") &&
+      assert(E->getClassName()->isStr("super") &&
              "Unexpected missing class interface in message send.");
       isSuperMessage = true;
       Receiver = LoadObjCSelf();
index 9c97ea2efa68bf77fdbdffd7202c7edbd59c6590..ea92e880f78b581cbbd2be535a833e9d387159e9 100644 (file)
@@ -387,19 +387,19 @@ void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) {
     
     SourceLocation AttrName = ConsumeToken(); // consume last attribute name
     
-    if (II->isName("readonly"))
+    if (II->isStr("readonly"))
       DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly);
-    else if (II->isName("assign"))
+    else if (II->isStr("assign"))
       DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign);
-    else if (II->isName("readwrite"))
+    else if (II->isStr("readwrite"))
       DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite);
-    else if (II->isName("retain"))
+    else if (II->isStr("retain"))
       DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain);
-    else if (II->isName("copy"))
+    else if (II->isStr("copy"))
       DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy);
-    else if (II->isName("nonatomic"))
+    else if (II->isStr("nonatomic"))
       DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic);
-    else if (II->isName("getter") || II->isName("setter")) {
+    else if (II->isStr("getter") || II->isStr("setter")) {
       // getter/setter require extra treatment.
       if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "",
                            tok::r_paren))
index 57d1cc7fa0b3b4999a14cd5b0fbe9c346896ac68..1e3a310305cd74720ce4960a1f63207d203e3d9d 100644 (file)
@@ -555,12 +555,12 @@ static void HandleObjCGCAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   
   
   ObjCGCAttr::GCAttrTypes type;
-  if (Attr.getParameterName()->isName("weak")) {
+  if (Attr.getParameterName()->isStr("weak")) {
     if (isa<FieldDecl>(d))
       S.Diag(Attr.getLoc(), diag::warn_attribute_weak_on_field);
     type = ObjCGCAttr::Weak;
   }
-  else if (Attr.getParameterName()->isName("strong"))
+  else if (Attr.getParameterName()->isStr("strong"))
     type = ObjCGCAttr::Strong;
   else {
     S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported)
@@ -584,7 +584,7 @@ static void HandleBlocksAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   }
   
   BlocksAttr::BlocksAttrTypes type;
-  if (Attr.getParameterName()->isName("byref"))
+  if (Attr.getParameterName()->isStr("byref"))
     type = BlocksAttr::ByRef;
   else {
     S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported)