Skip to content

Commit bfd7f9a

Browse files
committed
add hasAttribute overload
1 parent e73f6b5 commit bfd7f9a

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H
1616

1717
#include "clang/Basic/SourceLocation.h"
18-
#include "clang/Basic/TargetInfo.h"
1918
#include "clang/Basic/TokenKinds.h"
2019

2120
namespace clang {
@@ -249,9 +248,6 @@ class AttributeCommonInfo {
249248

250249
static AttrArgsInfo getCXX11AttrArgsInfo(const IdentifierInfo *Name);
251250

252-
static bool hasCXX11Attr(const IdentifierInfo *Name, const TargetInfo &Target,
253-
const LangOptions &LangOpts);
254-
255251
private:
256252
/// Get an index into the attribute spelling list
257253
/// defined in Attr.td. This index is used by an attribute

clang/include/clang/Basic/Attributes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ int hasAttribute(AttributeCommonInfo::Syntax Syntax,
2323
const IdentifierInfo *Scope, const IdentifierInfo *Attr,
2424
const TargetInfo &Target, const LangOptions &LangOpts);
2525

26+
int hasAttribute(AttributeCommonInfo::Syntax Syntax,
27+
const IdentifierInfo *Scope, const IdentifierInfo *Attr,
28+
const TargetInfo &Target, const LangOptions &LangOpts,
29+
bool CheckPlugins);
30+
2631
} // end namespace clang
2732

2833
#endif // LLVM_CLANG_BASIC_ATTRIBUTES_H

clang/lib/Basic/Attributes.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ static int hasAttributeImpl(AttributeCommonInfo::Syntax Syntax, StringRef Name,
3333

3434
int clang::hasAttribute(AttributeCommonInfo::Syntax Syntax,
3535
const IdentifierInfo *Scope, const IdentifierInfo *Attr,
36-
const TargetInfo &Target, const LangOptions &LangOpts) {
36+
const TargetInfo &Target, const LangOptions &LangOpts,
37+
bool CheckPlugins) {
3738
StringRef Name = Attr->getName();
3839
// Normalize the attribute name, __foo__ becomes foo.
3940
if (Name.size() >= 4 && Name.starts_with("__") && Name.ends_with("__"))
@@ -61,14 +62,23 @@ int clang::hasAttribute(AttributeCommonInfo::Syntax Syntax,
6162
if (res)
6263
return res;
6364

64-
// Check if any plugin provides this attribute.
65-
for (auto &Ptr : getAttributePluginInstances())
66-
if (Ptr->hasSpelling(Syntax, Name))
67-
return 1;
65+
if (CheckPlugins) {
66+
// Check if any plugin provides this attribute.
67+
for (auto &Ptr : getAttributePluginInstances())
68+
if (Ptr->hasSpelling(Syntax, Name))
69+
return 1;
70+
}
6871

6972
return 0;
7073
}
7174

75+
int clang::hasAttribute(AttributeCommonInfo::Syntax Syntax,
76+
const IdentifierInfo *Scope, const IdentifierInfo *Attr,
77+
const TargetInfo &Target, const LangOptions &LangOpts) {
78+
return hasAttribute(Syntax, Scope, Attr, Target, LangOpts,
79+
/*CheckPlugins*/ true);
80+
}
81+
7282
const char *attr::getSubjectMatchRuleSpelling(attr::SubjectMatchRule Rule) {
7383
switch (Rule) {
7484
#define ATTR_MATCH_RULE(NAME, SPELLING, IsAbstract) \
@@ -162,15 +172,6 @@ AttributeCommonInfo::getCXX11AttrArgsInfo(const IdentifierInfo *Name) {
162172
#undef CXX11_ATTR_ARGS_INFO
163173
}
164174

165-
bool AttributeCommonInfo::hasCXX11Attr(const IdentifierInfo *Name,
166-
const TargetInfo &Target,
167-
const LangOptions &LangOpts) {
168-
StringRef AttrName =
169-
normalizeAttrName(Name, /*NormalizedScopeName*/ "", Syntax::AS_CXX11);
170-
return hasAttributeImpl(Syntax::AS_CXX11, AttrName, /*ScopeName*/ "", Target,
171-
LangOpts) > 0;
172-
}
173-
174175
std::string AttributeCommonInfo::getNormalizedFullName() const {
175176
return static_cast<std::string>(
176177
normalizeName(getAttrName(), getScopeName(), getSyntax()));

clang/lib/Lex/PPDirectives.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr,
179179
static bool isReservedCXXAttributeName(Preprocessor &PP, IdentifierInfo *II) {
180180
const LangOptions &Lang = PP.getLangOpts();
181181
if (Lang.CPlusPlus &&
182-
AttributeCommonInfo::hasCXX11Attr(II, PP.getTargetInfo(), Lang)) {
182+
hasAttribute(AttributeCommonInfo::AS_CXX11, /* Scope*/ nullptr, II,
183+
PP.getTargetInfo(), Lang, /*CheckPlugins*/ false) > 0) {
183184
AttributeCommonInfo::AttrArgsInfo AttrArgsInfo =
184185
AttributeCommonInfo::getCXX11AttrArgsInfo(II);
185186
if (AttrArgsInfo == AttributeCommonInfo::AttrArgsInfo::Required)

0 commit comments

Comments
 (0)