From: Chris Lattner Date: Wed, 20 Feb 2008 23:17:35 +0000 (+0000) Subject: Use getKind() in HandleDeclAttribute instead of decoding the string inline. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=212839c2ee8d5e4cbff9f03375f2d3ee8c7f8630;p=clang Use getKind() in HandleDeclAttribute instead of decoding the string inline. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47413 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 9ca5f2be22..95b9c44d31 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -567,7 +567,8 @@ bool Sema::CheckInitializerListTypes(InitListExpr*& IList, QualType &DeclType, if (DeclType->isIncompleteArrayType()) { // FIXME: use a proper constant maxElements = 0x7FFFFFFF; - } else if (const VariableArrayType *VAT = DeclType->getAsVariableArrayType()) { + } else if (const VariableArrayType *VAT = + DeclType->getAsVariableArrayType()) { // Check for VLAs; in standard C it would be possible to check this // earlier, but I don't know where clang accepts VLAs (gcc accepts // them in all sorts of strange places). @@ -1735,17 +1736,9 @@ Sema::DeclTy* Sema::ActOnLinkageSpec(SourceLocation Loc, } void Sema::HandleDeclAttribute(Decl *New, AttributeList *rawAttr) { - const char *attrName = rawAttr->getAttributeName()->getName(); - unsigned attrLen = rawAttr->getAttributeName()->getLength(); - // Normalize the attribute name, __foo__ becomes foo. - if (attrLen > 4 && attrName[0] == '_' && attrName[1] == '_' && - attrName[attrLen - 2] == '_' && attrName[attrLen - 1] == '_') { - attrName += 2; - attrLen -= 4; - } - - if (attrLen == 11 && !memcmp(attrName, "vector_size", 11)) { + switch (rawAttr->getKind()) { + case AttributeList::AT_vector_size: if (ValueDecl *vDecl = dyn_cast(New)) { QualType newType = HandleVectorTypeAttribute(vDecl->getType(), rawAttr); if (!newType.isNull()) // install the new vector type into the decl @@ -1757,13 +1750,15 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *rawAttr) { if (!newType.isNull()) // install the new vector type into the decl tDecl->setUnderlyingType(newType); } - } else if (attrLen == 15 && !memcmp(attrName, "ocu_vector_type", 15)) { + break; + case AttributeList::AT_ocu_vector_type: if (TypedefDecl *tDecl = dyn_cast(New)) HandleOCUVectorTypeAttribute(tDecl, rawAttr); else Diag(rawAttr->getAttributeLoc(), diag::err_typecheck_ocu_vector_not_typedef); - } else if (attrLen == 13 && !memcmp(attrName, "address_space", 13)) { + break; + case AttributeList::AT_address_space: if (TypedefDecl *tDecl = dyn_cast(New)) { QualType newType = HandleAddressSpaceTypeAttribute( tDecl->getUnderlyingType(), @@ -1776,12 +1771,17 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *rawAttr) { if (!newType.isNull()) // install the new addr spaced type into the decl vDecl->setType(newType); } - } else if (attrLen == 7 && !memcmp(attrName, "aligned", 7)) + break; + case AttributeList::AT_aligned: HandleAlignedAttribute(New, rawAttr); - else if (attrLen == 6 && !memcmp(attrName, "packed", 6)) + break; + case AttributeList::AT_packed: HandlePackedAttribute(New, rawAttr); - - // FIXME: add other attributes... + break; + default: + // FIXME: add other attributes... + break; + } } void Sema::HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix,