Aaron Ballman | 2fbf994 | 2014-03-31 13:14:44 +0000 | [diff] [blame] | 1 | #include "clang/Basic/Attributes.h" |
Alex Lorenz | 9e7bf16 | 2017-04-18 14:33:39 +0000 | [diff] [blame] | 2 | #include "clang/Basic/AttrSubjectMatchRules.h" |
Aaron Ballman | 2fbf994 | 2014-03-31 13:14:44 +0000 | [diff] [blame] | 3 | #include "clang/Basic/IdentifierTable.h" |
| 4 | #include "llvm/ADT/StringSwitch.h" |
| 5 | using namespace clang; |
| 6 | |
Aaron Ballman | a0344c5 | 2014-11-14 13:44:02 +0000 | [diff] [blame] | 7 | int clang::hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope, |
Bob Wilson | 7c73083 | 2015-07-20 22:57:31 +0000 | [diff] [blame] | 8 | const IdentifierInfo *Attr, const TargetInfo &Target, |
| 9 | const LangOptions &LangOpts) { |
Aaron Ballman | 2fbf994 | 2014-03-31 13:14:44 +0000 | [diff] [blame] | 10 | StringRef Name = Attr->getName(); |
| 11 | // Normalize the attribute name, __foo__ becomes foo. |
Aaron Ballman | c44c1742 | 2018-11-09 17:19:45 +0000 | [diff] [blame^] | 12 | 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 Ballman | ad672ff | 2018-10-24 12:26:23 +0000 | [diff] [blame] | 24 | return 0;
|
Aaron Ballman | 2fbf994 | 2014-03-31 13:14:44 +0000 | [diff] [blame] | 25 | } |
Alex Lorenz | 9e7bf16 | 2017-04-18 14:33:39 +0000 | [diff] [blame] | 26 | |
| 27 | const 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 | } |