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
This commit is contained in:
Chris Lattner 2008-11-20 04:42:34 +00:00
Родитель a751217e76
Коммит 92e62b0222
5 изменённых файлов: 20 добавлений и 19 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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();

Просмотреть файл

@ -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))

Просмотреть файл

@ -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)