clang: lib/Sema/ParsedAttr.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
19#include "llvm/ADT/SmallVector.h"
20#include
21#include
22#include
23
24using namespace clang;
25
26size_t ParsedAttr::allocated_size() const {
28 else if (IsTypeTagForDatatype)
30 else if (IsProperty)
32 else if (HasParsedType)
33 return totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
34 detail::TypeTagForDatatypeData, ParsedType,
35 detail::PropertyData>(0, 0, 0, 1, 0);
36 return totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
37 detail::TypeTagForDatatypeData, ParsedType,
38 detail::PropertyData>(NumArgs, 0, 0, 0, 0);
39}
40
42
43 FreeLists.resize(InlineFreeListsCapacity);
44}
46
49 assert((size % sizeof(void*)) == 0);
50 return ((size - sizeof(ParsedAttr)) / sizeof(void *));
51}
52
53void *AttributeFactory::allocate(size_t size) {
54
56 if (index < FreeLists.size() && !FreeLists[index].empty()) {
57 ParsedAttr *attr = FreeLists[index].pop_back_val();
59 }
60
61
63}
64
66 size_t size = Attr->allocated_size();
68
69
70 if (freeListIndex >= FreeLists.size())
71 FreeLists.resize(freeListIndex + 1);
72
73#ifndef NDEBUG
74
75 memset(Attr, 0, size);
76#endif
77
78
79 FreeLists[freeListIndex].push_back(Attr);
80}
81
82void AttributeFactory::reclaimPool(AttributePool &cur) {
83 for (ParsedAttr *AL : cur.Attrs)
84 deallocate(AL);
85}
86
87void AttributePool::takePool(AttributePool &pool) {
88 llvm::append_range(Attrs, pool.Attrs);
89 pool.Attrs.clear();
90}
91
93 assert(&Pool != this && "AttributePool can't take attributes from itself");
95 Pool.remove(A);
96 llvm::append_range(Attrs, List.AttrList);
97}
98
99namespace {
100
101#include "clang/Sema/AttrParsedAttrImpl.inc"
102
103}
104
106
107 if ((size_t)A.getParsedKind() < std::size(AttrInfoMap))
109
110
114 return IgnoredParsedAttrInfo;
115
116
117
118
123
125 if (Ptr->hasSpelling(SyntaxUsed, FullName))
126 return *Ptr;
127
128
131 return DefaultParsedAttrInfo;
132}
133
137
139
143
147
151
155
159
163
166 return checkAttributeMatchRuleAppliesTo(D, MatchRule);
167}
168
171 SmallVectorImpl<std::pair<attr::SubjectMatchRule, bool>> &MatchRules)
172 const {
174}
175
178 return true;
179 S.Diag(getLoc(), diag::warn_attribute_ignored) << *this;
180 return false;
181}
182
186
188
190
193
194
195
196
199 bool TargetSpecificSpellingExists =
200 !HasSpelling ||
202
204}
205
207
211
214
215
216 return false;
217
219
220
221
222
223
224
225
226
227
228
230 case AT_AddressSpace:
231 case AT_OpenCLPrivateAddressSpace:
232 case AT_OpenCLGlobalAddressSpace:
233 case AT_OpenCLGlobalDeviceAddressSpace:
234 case AT_OpenCLGlobalHostAddressSpace:
235 case AT_OpenCLLocalAddressSpace:
236 case AT_OpenCLConstantAddressSpace:
237 case AT_OpenCLGenericAddressSpace:
238 case AT_NeonPolyVectorType:
239 case AT_NeonVectorType:
240 case AT_ArmMveStrictPolymorphism:
241 case AT_BTFTypeTag:
242 case AT_ObjCGC:
243 case AT_MatrixType:
244 return true;
245 default:
246 return false;
247 }
248}
249
251
255
263
267
271
276
277template
279 unsigned Num, unsigned Diag,
280 Compare Comp) {
283 return false;
284 }
285 return true;
286}
287
290 diag::err_attribute_wrong_number_arguments,
291 std::not_equal_to());
292}
295 diag::err_attribute_too_few_arguments,
296 std::less());
297}
300 diag::err_attribute_too_many_arguments,
301 std::greater());
302}
303
306
307 First.takeAllAppendingFrom(Second);
308
309 if (.Range.getBegin().isValid())
310 First.Range.setBegin(Second.Range.getBegin());
311
312 if (Second.Range.getEnd().isValid())
313 First.Range.setEnd(Second.Range.getEnd());
314}
Defines the clang::ASTContext interface.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
static bool checkAttributeNumArgsImpl(Sema &S, const ParsedAttr &AL, unsigned Num, unsigned Diag, Compare Comp)
Definition ParsedAttr.cpp:278
static size_t getFreeListIndexForSize(size_t size)
Definition ParsedAttr.cpp:47
static unsigned getNumAttributeArgs(const ParsedAttr &AL)
Definition ParsedAttr.cpp:272
__DEVICE__ void * memset(void *__a, int __b, size_t __c)
Attr - This represents one attribute.
std::string getNormalizedFullName() const
Gets the normalized full name, which consists of both scope and name and with surrounding underscores...
Syntax
The style used to specify an attribute.
@ AS_Keyword
__ptr16, alignas(...), etc.
@ AS_ContextSensitiveKeyword
Context-sensitive version of a keyword attribute.
unsigned getAttributeSpellingListIndex() const
bool isRegularKeywordAttribute() const
SourceLocation getLoc() const
bool isStandardAttributeSyntax() const
The attribute is spelled [[]] in either C or C++ mode, including standard attributes spelled with a k...
Kind getParsedKind() const
AttributeFactory()
Definition ParsedAttr.cpp:41
@ TypeTagForDatatypeAllocSize
AttributePool(AttributeFactory &factory)
Create a new pool for a factory.
void takeFrom(ParsedAttributesView &List, AttributePool &Pool)
Removes the attributes from List, which are owned by Pool, and adds them at the end of this Attribute...
Definition ParsedAttr.cpp:92
Decl - This represents one declaration (or definition), e.g.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
ParsedAttr - Represents a syntactic attribute.
bool isTargetSpecificAttr() const
Definition ParsedAttr.cpp:183
bool hasCustomParsing() const
Definition ParsedAttr.cpp:148
unsigned getSemanticSpelling() const
If the parsed attribute has a semantic equivalent, and it would have a semantic Spelling enumeration ...
Definition ParsedAttr.cpp:252
bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const
Definition ParsedAttr.cpp:164
bool isKnownToGCC() const
Definition ParsedAttr.cpp:206
bool existsInTarget(const TargetInfo &Target) const
Definition ParsedAttr.cpp:191
unsigned getMinArgs() const
Definition ParsedAttr.cpp:138
bool checkExactlyNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has exactly as many args as Num.
Definition ParsedAttr.cpp:288
bool hasParsedType() const
bool hasVariadicArg() const
Definition ParsedAttr.cpp:256
const ParsedAttrInfo & getInfo() const
void handleAttrWithDelayedArgs(Sema &S, Decl *D) const
Definition ParsedAttr.cpp:268
bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const
Definition ParsedAttr.cpp:160
bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const
Definition ParsedAttr.cpp:152
bool acceptsExprPack() const
Definition ParsedAttr.cpp:250
bool isTypeAttr() const
Definition ParsedAttr.cpp:187
bool isSupportedByPragmaAttribute() const
Definition ParsedAttr.cpp:208
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at least as many args as Num.
Definition ParsedAttr.cpp:293
unsigned getNumArgMembers() const
Definition ParsedAttr.cpp:144
bool isStmtAttr() const
Definition ParsedAttr.cpp:189
unsigned getMaxArgs() const
Definition ParsedAttr.cpp:140
bool slidesFromDeclToDeclSpecLegacyBehavior() const
Returns whether a [[]] attribute, if specified ahead of a declaration, should be applied to the decl-...
Definition ParsedAttr.cpp:212
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool > > &MatchRules) const
Definition ParsedAttr.cpp:169
bool isParamExpr(size_t N) const
Definition ParsedAttr.cpp:264
bool diagnoseLangOpts(class Sema &S) const
Definition ParsedAttr.cpp:176
bool checkAtMostNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at most as many args as Num.
Definition ParsedAttr.cpp:298
ParsedAttributes - A collection of parsed attributes.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Sema - This implements semantic analysis and AST building for C.
const LangOptions & getLangOpts() const
Stmt - This represents one statement.
Exposes information about the current target.
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Attr > attr
SubjectMatchRule
A list of all the recognized kinds of attributes.
The JSON file list parser is used to communicate input to InstallAPI.
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
const std::list< std::unique_ptr< ParsedAttrInfo > > & getAttributePluginInstances()
void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &&Second)
Consumes the attributes from Second and concatenates them at the end of First.
Definition ParsedAttr.cpp:304
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
constexpr ParsedAttrInfo(AttributeCommonInfo::Kind AttrKind=AttributeCommonInfo::NoSemaHandlerAttribute)
static ArrayRef< const ParsedAttrInfo * > getAllBuiltin()
Definition ParsedAttr.cpp:134
unsigned IsKnownToGCC
True if this attribute has any spellings that are known to gcc.
unsigned HasCustomParsing
True if the parsing does not match the semantic content.
unsigned IsType
True if this attribute applies to types.
unsigned IsTargetSpecific
True if this attribute is only available for certain targets.
unsigned IsSupportedByPragmaAttribute
True if this attribute is supported by pragma clang attribute.
unsigned NumArgs
The number of required arguments of this attribute.
virtual bool diagAppertainsToStmt(Sema &S, const ParsedAttr &Attr, const Stmt *St) const
Check if this attribute appertains to St, and issue a diagnostic if not.
virtual unsigned spellingIndexToSemanticSpelling(const ParsedAttr &Attr) const
Convert the spelling index of Attr to a semantic spelling enum value.
static const ParsedAttrInfo & get(const AttributeCommonInfo &A)
Definition ParsedAttr.cpp:105
virtual bool isParamExpr(size_t N) const
Returns true if the specified parameter index for this attribute in Attr.td is an ExprArgument or Var...
virtual void getPragmaAttributeMatchRules(llvm::SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool > > &Rules, const LangOptions &LangOpts) const
Populate Rules with the match rules of this attribute.
virtual bool existsInTarget(const TargetInfo &Target) const
Check if this attribute is allowed when compiling for the given target.
virtual bool spellingExistsInTarget(const TargetInfo &Target, const unsigned SpellingListIndex) const
Check if this attribute's spelling is allowed when compiling for the given target.
virtual bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr, const Decl *D) const
Check if this attribute appertains to D, and issue a diagnostic if not.
unsigned OptArgs
The number of optional arguments of this attributes.
virtual bool diagMutualExclusion(Sema &S, const ParsedAttr &A, const Decl *D) const
Check if the given attribute is mutually exclusive with other attributes already applied to the given...
unsigned IsStmt
True if this attribute applies to statements.
unsigned NumArgMembers
The number of non-fake arguments specified in the attribute definition.