#include "clang/Parse/AttributeList.h"
#include "clang/Basic/IdentifierTable.h"
+#include "llvm/ADT/StringSwitch.h"
using namespace clang;
AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
AttrName = AttrName.substr(2, AttrName.size() - 4);
// FIXME: Hand generating this is neither smart nor efficient.
- const char *Str = AttrName.data();
- switch (AttrName.size()) {
- case 4:
- if (!memcmp(Str, "weak", 4)) return AT_weak;
- if (!memcmp(Str, "pure", 4)) return AT_pure;
- if (!memcmp(Str, "mode", 4)) return AT_mode;
- if (!memcmp(Str, "used", 4)) return AT_used;
- break;
- case 5:
- if (!memcmp(Str, "alias", 5)) return AT_alias;
- if (!memcmp(Str, "const", 5)) return AT_const;
- break;
- case 6:
- if (!memcmp(Str, "packed", 6)) return AT_packed;
- if (!memcmp(Str, "malloc", 6)) return AT_malloc;
- if (!memcmp(Str, "format", 6)) return AT_format;
- if (!memcmp(Str, "unused", 6)) return AT_unused;
- if (!memcmp(Str, "blocks", 6)) return AT_blocks;
- break;
- case 7:
- if (!memcmp(Str, "aligned", 7)) return AT_aligned;
- if (!memcmp(Str, "cleanup", 7)) return AT_cleanup;
- if (!memcmp(Str, "nodebug", 7)) return AT_nodebug;
- if (!memcmp(Str, "nonnull", 7)) return AT_nonnull;
- if (!memcmp(Str, "nothrow", 7)) return AT_nothrow;
- if (!memcmp(Str, "objc_gc", 7)) return AT_objc_gc;
- if (!memcmp(Str, "regparm", 7)) return AT_regparm;
- if (!memcmp(Str, "section", 7)) return AT_section;
- if (!memcmp(Str, "stdcall", 7)) return AT_stdcall;
- break;
- case 8:
- if (!memcmp(Str, "annotate", 8)) return AT_annotate;
- if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
- if (!memcmp(Str, "noinline", 8)) return AT_noinline;
- if (!memcmp(Str, "fastcall", 8)) return AT_fastcall;
- if (!memcmp(Str, "iboutlet", 8)) return AT_IBOutlet;
- if (!memcmp(Str, "sentinel", 8)) return AT_sentinel;
- if (!memcmp(Str, "NSObject", 8)) return AT_nsobject;
- break;
- case 9:
- if (!memcmp(Str, "dllimport", 9)) return AT_dllimport;
- if (!memcmp(Str, "dllexport", 9)) return AT_dllexport;
- if (!memcmp(Str, "may_alias", 9)) return IgnoredAttribute; // FIXME: TBAA
- break;
- case 10:
- if (!memcmp(Str, "deprecated", 10)) return AT_deprecated;
- if (!memcmp(Str, "visibility", 10)) return AT_visibility;
- if (!memcmp(Str, "destructor", 10)) return AT_destructor;
- if (!memcmp(Str, "format_arg", 10)) return AT_format_arg;
- if (!memcmp(Str, "gnu_inline", 10)) return AT_gnu_inline;
- break;
- case 11:
- if (!memcmp(Str, "weak_import", 11)) return AT_weak_import;
- if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
- if (!memcmp(Str, "constructor", 11)) return AT_constructor;
- if (!memcmp(Str, "unavailable", 11)) return AT_unavailable;
- break;
- case 12:
- if (!memcmp(Str, "overloadable", 12)) return AT_overloadable;
- break;
- case 13:
- if (!memcmp(Str, "address_space", 13)) return AT_address_space;
- if (!memcmp(Str, "always_inline", 13)) return AT_always_inline;
- if (!memcmp(Str, "vec_type_hint", 13)) return IgnoredAttribute;
- break;
- case 14:
- if (!memcmp(Str, "objc_exception", 14)) return AT_objc_exception;
- break;
- case 15:
- if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type;
- break;
- case 17:
- if (!memcmp(Str, "transparent_union", 17)) return AT_transparent_union;
- if (!memcmp(Str, "analyzer_noreturn", 17)) return AT_analyzer_noreturn;
- break;
- case 18:
- if (!memcmp(Str, "warn_unused_result", 18)) return AT_warn_unused_result;
- break;
- case 19:
- if (!memcmp(Str, "ns_returns_retained", 19)) return AT_ns_returns_retained;
- if (!memcmp(Str, "cf_returns_retained", 19)) return AT_cf_returns_retained;
- break;
- case 20:
- if (!memcmp(Str, "reqd_work_group_size", 20)) return AT_reqd_wg_size;
- case 22:
- if (!memcmp(Str, "no_instrument_function", 22))
- return AT_no_instrument_function;
- break;
- }
- return UnknownAttribute;
+ return llvm::StringSwitch<AttributeList::Kind>(AttrName)
+ .Case("weak", AT_weak)
+ .Case("pure", AT_pure)
+ .Case("mode", AT_mode)
+ .Case("used", AT_used)
+ .Case("alias", AT_alias)
+ .Case("const", AT_const)
+ .Case("packed", AT_packed)
+ .Case("malloc", AT_malloc)
+ .Case("format", AT_format)
+ .Case("unused", AT_unused)
+ .Case("blocks", AT_blocks)
+ .Case("aligned", AT_aligned)
+ .Case("cleanup", AT_cleanup)
+ .Case("nodebug", AT_nodebug)
+ .Case("nonnull", AT_nonnull)
+ .Case("nothrow", AT_nothrow)
+ .Case("objc_gc", AT_objc_gc)
+ .Case("regparm", AT_regparm)
+ .Case("section", AT_section)
+ .Case("stdcall", AT_stdcall)
+ .Case("annotate", AT_annotate)
+ .Case("noreturn", AT_noreturn)
+ .Case("noinline", AT_noinline)
+ .Case("fastcall", AT_fastcall)
+ .Case("iboutlet", AT_IBOutlet)
+ .Case("sentinel", AT_sentinel)
+ .Case("NSObject", AT_nsobject)
+ .Case("dllimport", AT_dllimport)
+ .Case("dllexport", AT_dllexport)
+ .Case("may_alias", IgnoredAttribute) // FIXME: TBAA
+ .Case("deprecated", AT_deprecated)
+ .Case("visibility", AT_visibility)
+ .Case("destructor", AT_destructor)
+ .Case("format_arg", AT_format_arg)
+ .Case("gnu_inline", AT_gnu_inline)
+ .Case("weak_import", AT_weak_import)
+ .Case("vector_size", AT_vector_size)
+ .Case("constructor", AT_constructor)
+ .Case("unavailable", AT_unavailable)
+ .Case("overloadable", AT_overloadable)
+ .Case("address_space", AT_address_space)
+ .Case("always_inline", AT_always_inline)
+ .Case("vec_type_hint", IgnoredAttribute)
+ .Case("objc_exception", AT_objc_exception)
+ .Case("ext_vector_type", AT_ext_vector_type)
+ .Case("transparent_union", AT_transparent_union)
+ .Case("analyzer_noreturn", AT_analyzer_noreturn)
+ .Case("warn_unused_result", AT_warn_unused_result)
+ .Case("ns_returns_retained", AT_ns_returns_retained)
+ .Case("cf_returns_retained", AT_cf_returns_retained)
+ .Case("reqd_work_group_size", AT_reqd_wg_size)
+ .Case("no_instrument_function", AT_no_instrument_function)
+ .Default(UnknownAttribute);
}