Revert my optimization to AttributeList::getKind() in r155987;

Benjamin has suggested a better approach.

llvm-svn: 155989
This commit is contained in:
Douglas Gregor 2012-05-02 14:50:50 +00:00
parent 25c1609648
commit 0191bf8655
2 changed files with 20 additions and 33 deletions

View File

@ -14,7 +14,7 @@
#include "clang/Sema/AttributeList.h" #include "clang/Sema/AttributeList.h"
#include "clang/AST/Expr.h" #include "clang/AST/Expr.h"
#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSwitch.h"
using namespace clang; using namespace clang;
size_t AttributeList::allocated_size() const { size_t AttributeList::allocated_size() const {
@ -97,30 +97,6 @@ AttributePool::createIntegerAttribute(ASTContext &C, IdentifierInfo *Name,
return create(Name, TokLoc, 0, TokLoc, 0, TokLoc, &IArg, 1, 0); return create(Name, TokLoc, 0, TokLoc, 0, TokLoc, &IArg, 1, 0);
} }
typedef llvm::StringMap<AttributeList::Kind> AttributeNameKindMap;
static AttributeNameKindMap createAttributeNameKindMap(){
AttributeNameKindMap Result;
#include "clang/Sema/AttrParsedAttrKinds.inc"
Result["address_space"] = AttributeList::AT_address_space;
Result["align"] = AttributeList::AT_aligned; // FIXME: should it be "aligned"?
Result["base_check"] = AttributeList::AT_base_check;
Result["bounded"] = AttributeList::IgnoredAttribute; // OpenBSD
Result["__const"] = AttributeList::AT_const; // some GCC headers do contain this spelling
Result["cf_returns_autoreleased"] = AttributeList::AT_cf_returns_autoreleased;
Result["mode"] = AttributeList::AT_mode;
Result["vec_type_hint"] = AttributeList::IgnoredAttribute;
Result["ext_vector_type"] = AttributeList::AT_ext_vector_type;
Result["neon_vector_type"] = AttributeList::AT_neon_vector_type;
Result["neon_polyvector_type"] = AttributeList::AT_neon_polyvector_type;
Result["opencl_image_access"] = AttributeList::AT_opencl_image_access;
Result["objc_gc"] = AttributeList::AT_objc_gc;
Result["objc_ownership"] = AttributeList::AT_objc_ownership;
Result["vector_size"] = AttributeList::AT_vector_size;
return Result;
}
AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
StringRef AttrName = Name->getName(); StringRef AttrName = Name->getName();
@ -129,10 +105,22 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
AttrName.size() >= 4) AttrName.size() >= 4)
AttrName = AttrName.substr(2, AttrName.size() - 4); AttrName = AttrName.substr(2, AttrName.size() - 4);
static AttributeNameKindMap Map = createAttributeNameKindMap(); return llvm::StringSwitch<AttributeList::Kind>(AttrName)
AttributeNameKindMap::iterator Pos = Map.find(AttrName); #include "clang/Sema/AttrParsedAttrKinds.inc"
if (Pos != Map.end()) .Case("address_space", AT_address_space)
return Pos->second; .Case("align", AT_aligned) // FIXME - should it be "aligned"?
.Case("base_check", AT_base_check)
return UnknownAttribute; .Case("bounded", IgnoredAttribute) // OpenBSD
.Case("__const", AT_const) // some GCC headers do contain this spelling
.Case("cf_returns_autoreleased", AT_cf_returns_autoreleased)
.Case("mode", AT_mode)
.Case("vec_type_hint", IgnoredAttribute)
.Case("ext_vector_type", AT_ext_vector_type)
.Case("neon_vector_type", AT_neon_vector_type)
.Case("neon_polyvector_type", AT_neon_polyvector_type)
.Case("opencl_image_access", AT_opencl_image_access)
.Case("objc_gc", AT_objc_gc)
.Case("objc_ownership", AT_objc_ownership)
.Case("vector_size", AT_vector_size)
.Default(UnknownAttribute);
} }

View File

@ -1083,8 +1083,7 @@ void ClangAttrParsedAttrKindsEmitter::run(raw_ostream &OS) {
AttrName = NormalizeAttrName(AttrName); AttrName = NormalizeAttrName(AttrName);
Spelling = NormalizeAttrSpelling(Spelling); Spelling = NormalizeAttrSpelling(Spelling);
OS << "Result[\"" << Spelling << "\"] = " << "AttributeList::AT_" OS << ".Case(\"" << Spelling << "\", " << "AT_" << AttrName << ")\n";
<< AttrName << ";\n";
} }
} }
} }