[cfe-commits] r59706 - in /cfe/trunk: include/clang/Basic/IdentifierTable.h lib/AST/Expr.cpp lib/CodeGen/CGObjC.cpp lib/Parse/ParseObjc.cpp lib/Sema/SemaDeclAttr.cpp

Chris Lattner sabre at nondot.org
Wed Nov 19 20:42:35 PST 2008


Author: lattner
Date: Wed Nov 19 22:42:34 2008
New Revision: 59706

URL: http://llvm.org/viewvc/llvm-project?rev=59706&view=rev
Log:
Rename IdentifierInfo::isName to ::isStr.  Use a nifty trick
from Sebastian to enforce that a literal string is passed in,
and use this to avoid having to call strlen on it.

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

Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=59706&r1=59705&r2=59706&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Wed Nov 19 22:42:34 2008
@@ -62,10 +62,11 @@
 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 

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=59706&r1=59705&r2=59706&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Nov 19 22:42:34 2008
@@ -1165,10 +1165,10 @@
 /// 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) {

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=59706&r1=59705&r2=59706&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Wed Nov 19 22:42:34 2008
@@ -63,7 +63,7 @@
     // 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();

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=59706&r1=59705&r2=59706&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Nov 19 22:42:34 2008
@@ -387,19 +387,19 @@
     
     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))

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=59706&r1=59705&r2=59706&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Nov 19 22:42:34 2008
@@ -555,12 +555,12 @@
   
   
   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 @@
   }
   
   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)





More information about the cfe-commits mailing list