diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-20 04:42:34 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-20 04:42:34 +0000 |
commit | 92e62b02226410bcad8584541b8f1ff4d35ebab9 (patch) | |
tree | aff14a293c5b7307ead4c35ae21ff1c6e940196e | |
parent | a751217e769cbe73df2d579a28153f1c947aef10 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59706 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/IdentifierTable.h | 9 | ||||
-rw-r--r-- | lib/AST/Expr.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/CGObjC.cpp | 2 | ||||
-rw-r--r-- | lib/Parse/ParseObjc.cpp | 14 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 6 |
5 files changed, 20 insertions, 19 deletions
diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h index 7801304751..348ef1477f 100644 --- a/include/clang/Basic/IdentifierTable.h +++ b/include/clang/Basic/IdentifierTable.h @@ -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 diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 061402076e..e9d5eb75ea 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -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) { diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 4469bab2b2..c2e42d5981 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -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(); diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 9c97ea2efa..ea92e880f7 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -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)) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 57d1cc7fa0..1e3a310305 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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) |