blob: 9a8eb3d932cc64356a172e1b5cb4ed4edba5a4ce [file] [log] [blame]
Aaron Ballman2fbf9942014-03-31 13:14:44 +00001#include "clang/Basic/Attributes.h"
Alex Lorenz9e7bf162017-04-18 14:33:39 +00002#include "clang/Basic/AttrSubjectMatchRules.h"
Aaron Ballman2fbf9942014-03-31 13:14:44 +00003#include "clang/Basic/IdentifierTable.h"
4#include "llvm/ADT/StringSwitch.h"
5using namespace clang;
6
Aaron Ballmana0344c52014-11-14 13:44:02 +00007int clang::hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope,
Bob Wilson7c730832015-07-20 22:57:31 +00008 const IdentifierInfo *Attr, const TargetInfo &Target,
9 const LangOptions &LangOpts) {
Aaron Ballman2fbf9942014-03-31 13:14:44 +000010 StringRef Name = Attr->getName();
11 // Normalize the attribute name, __foo__ becomes foo.
Aaron Ballmanc44c17422018-11-09 17:19:45 +000012 if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__"))
13 Name = Name.substr(2, Name.size() - 4);
14
15 // Normalize the scope name, but only for gnu and clang attributes.
16 StringRef ScopeName = Scope ? Scope->getName() : "";
17 if (ScopeName == "__gnu__")
18 ScopeName = "gnu";
19 else if (ScopeName == "_Clang")
20 ScopeName = "clang";
21
22#include "clang/Basic/AttrHasAttributeImpl.inc"
23
Aaron Ballmanad672ff2018-10-24 12:26:23 +000024 return 0;
Aaron Ballman2fbf9942014-03-31 13:14:44 +000025}
Alex Lorenz9e7bf162017-04-18 14:33:39 +000026
27const char *attr::getSubjectMatchRuleSpelling(attr::SubjectMatchRule Rule) {
28 switch (Rule) {
29#define ATTR_MATCH_RULE(NAME, SPELLING, IsAbstract) \
30 case attr::NAME: \
31 return SPELLING;
32#include "clang/Basic/AttrSubMatchRulesList.inc"
33 }
34 llvm_unreachable("Invalid subject match rule");
35}