14
14
#ifndef LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H
15
15
#define LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H
16
16
17
+ #include " clang/Basic/AttributeScopeInfo.h"
17
18
#include " clang/Basic/SourceLocation.h"
18
19
#include " clang/Basic/TokenKinds.h"
19
20
@@ -61,6 +62,7 @@ class AttributeCommonInfo {
61
62
// / implicitly.
62
63
AS_Implicit
63
64
};
65
+
64
66
enum Kind {
65
67
#define PARSED_ATTR (NAME ) AT_##NAME,
66
68
#include " clang/Basic/AttrParsedAttrList.inc"
@@ -78,9 +80,9 @@ class AttributeCommonInfo {
78
80
79
81
private:
80
82
const IdentifierInfo *AttrName = nullptr ;
81
- const IdentifierInfo *ScopeName = nullptr ;
83
+ AttributeScopeInfo AttrScope ;
82
84
SourceRange AttrRange;
83
- const SourceLocation ScopeLoc;
85
+
84
86
// Corresponds to the Kind enum.
85
87
LLVM_PREFERRED_TYPE (Kind)
86
88
unsigned AttrKind : 16 ;
@@ -146,33 +148,31 @@ class AttributeCommonInfo {
146
148
};
147
149
148
150
AttributeCommonInfo (const IdentifierInfo *AttrName,
149
- const IdentifierInfo *ScopeName, SourceRange AttrRange,
150
- SourceLocation ScopeLoc, Kind AttrKind, Form FormUsed)
151
- : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange),
152
- ScopeLoc (ScopeLoc), AttrKind(AttrKind),
153
- SyntaxUsed(FormUsed.getSyntax()),
151
+ AttributeScopeInfo AttrScope, SourceRange AttrRange,
152
+ Kind AttrKind, Form FormUsed)
153
+ : AttrName(AttrName), AttrScope(AttrScope), AttrRange(AttrRange),
154
+ AttrKind (AttrKind), SyntaxUsed(FormUsed.getSyntax()),
154
155
SpellingIndex(FormUsed.getSpellingIndex()),
155
156
IsAlignas(FormUsed.isAlignas()),
156
157
IsRegularKeywordAttribute(FormUsed.isRegularKeywordAttribute()) {
157
158
assert (SyntaxUsed >= AS_GNU && SyntaxUsed <= AS_Implicit &&
158
159
" Invalid syntax!" );
159
160
}
160
161
161
- AttributeCommonInfo (const IdentifierInfo *AttrName,
162
- const IdentifierInfo *ScopeName, SourceRange AttrRange,
163
- SourceLocation ScopeLoc, Form FormUsed)
162
+ AttributeCommonInfo (const IdentifierInfo *AttrName, AttributeScopeInfo Scope,
163
+ SourceRange AttrRange, Form FormUsed)
164
164
: AttributeCommonInfo(
165
- AttrName, ScopeName , AttrRange, ScopeLoc ,
166
- getParsedKind (AttrName, ScopeName , FormUsed.getSyntax()),
165
+ AttrName, Scope , AttrRange,
166
+ getParsedKind (AttrName, Scope.getName() , FormUsed.getSyntax()),
167
167
FormUsed) {}
168
168
169
169
AttributeCommonInfo (const IdentifierInfo *AttrName, SourceRange AttrRange,
170
170
Form FormUsed)
171
- : AttributeCommonInfo(AttrName, nullptr , AttrRange, SourceLocation() ,
171
+ : AttributeCommonInfo(AttrName, AttributeScopeInfo() , AttrRange,
172
172
FormUsed) {}
173
173
174
174
AttributeCommonInfo (SourceRange AttrRange, Kind K, Form FormUsed)
175
- : AttributeCommonInfo(nullptr , nullptr , AttrRange, SourceLocation() , K,
175
+ : AttributeCommonInfo(nullptr , AttributeScopeInfo() , AttrRange, K,
176
176
FormUsed) {}
177
177
178
178
AttributeCommonInfo (AttributeCommonInfo &&) = default;
@@ -190,17 +190,27 @@ class AttributeCommonInfo {
190
190
SourceRange getRange () const { return AttrRange; }
191
191
void setRange (SourceRange R) { AttrRange = R; }
192
192
193
- bool hasScope () const { return ScopeName; }
194
- const IdentifierInfo *getScopeName () const { return ScopeName; }
195
- SourceLocation getScopeLoc () const { return ScopeLoc; }
193
+ bool hasScope () const { return AttrScope.isValid (); }
194
+ bool isExplicitScope () const { return AttrScope.IsExplicit (); }
195
+
196
+ const IdentifierInfo *getScopeName () const { return AttrScope.getName (); }
197
+ SourceLocation getScopeLoc () const { return AttrScope.getNameLoc (); }
196
198
197
199
// / Gets the normalized full name, which consists of both scope and name and
198
200
// / with surrounding underscores removed as appropriate (e.g.
199
201
// / __gnu__::__attr__ will be normalized to gnu::attr).
200
202
std::string getNormalizedFullName () const ;
201
- std::optional<std::string>
202
- getCorrectedFullName (const TargetInfo &Target,
203
- const LangOptions &LangOpts) const ;
203
+ std::string getNormalizedFullName (StringRef ScopeName,
204
+ StringRef AttrName) const ;
205
+ StringRef getNormalizedScopeName () const ;
206
+ StringRef getNormalizedAttrName (StringRef ScopeName) const ;
207
+
208
+ std::optional<StringRef> tryGetCorrectedScopeName (StringRef ScopeName) const ;
209
+ std::optional<StringRef>
210
+ tryGetCorrectedAttrName (StringRef ScopeName, StringRef AttrName,
211
+ const TargetInfo &Target,
212
+ const LangOptions &LangOpts) const ;
213
+
204
214
SourceRange getNormalizedRange () const ;
205
215
206
216
bool isDeclspecAttribute () const { return SyntaxUsed == AS_Declspec; }
0 commit comments