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
/// 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) {
// 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();
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))
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)
}
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)