clang 17.0.0git
ParsedAttr.h
Go to the documentation of this file.
1//======- ParsedAttr.h - Parsed attribute sets ------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ParsedAttr class, which is used to collect
10// parsed attributes.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_SEMA_PARSEDATTR_H
15#define LLVM_CLANG_SEMA_PARSEDATTR_H
16
23#include "llvm/ADT/PointerUnion.h"
24#include "llvm/ADT/SmallVector.h"
25#include "llvm/Support/Allocator.h"
26#include "llvm/Support/VersionTuple.h"
27#include <cassert>
28#include <cstddef>
29#include <cstring>
30#include <utility>
31
32namespace clang {
33
34class ASTContext;
35class Decl;
36class Expr;
37class IdentifierInfo;
38class LangOptions;
39class Sema;
40class Stmt;
41class TargetInfo;
42
43/// Represents information about a change in availability for
44/// an entity, which is part of the encoding of the 'availability'
45/// attribute.
47 /// The location of the keyword indicating the kind of change.
49
50 /// The version number at which the change occurred.
51 VersionTuple Version;
52
53 /// The source range covering the version number.
55
56 /// Determine whether this availability change is valid.
57 bool isValid() const { return !Version.empty(); }
58};
59
60namespace detail {
63};
64
65/// Describes the trailing object for Availability attribute in ParsedAttr.
70
72 const AvailabilityChange &Deprecated,
73 const AvailabilityChange &Obsoleted,
74 SourceLocation Strict, const Expr *ReplaceExpr)
75 : StrictLoc(Strict), Replacement(ReplaceExpr) {
76 Changes[IntroducedSlot] = Introduced;
77 Changes[DeprecatedSlot] = Deprecated;
78 Changes[ObsoletedSlot] = Obsoleted;
79 }
80};
81
84 unsigned LayoutCompatible : 1;
85 unsigned MustBeNull : 1;
86};
89
91 : GetterId(getterId), SetterId(setterId) {}
92};
93
94} // namespace
95
96/// Wraps an identifier and optional source location for the identifier.
100
103};
104
105/// A union of the various pointer types that can be passed to an
106/// ParsedAttr as an argument.
107using ArgsUnion = llvm::PointerUnion<Expr *, IdentifierLoc *>;
109
110/// ParsedAttr - Represents a syntactic attribute.
111///
112/// For a GNU attribute, there are four forms of this construct:
113///
114/// 1: __attribute__(( const )). ParmName/Args/NumArgs will all be unused.
115/// 2: __attribute__(( mode(byte) )). ParmName used, Args/NumArgs unused.
116/// 3: __attribute__(( format(printf, 1, 2) )). ParmName/Args/NumArgs all used.
117/// 4: __attribute__(( aligned(16) )). ParmName is unused, Args/Num used.
118///
119class ParsedAttr final
120 : public AttributeCommonInfo,
121 private llvm::TrailingObjects<
122 ParsedAttr, ArgsUnion, detail::AvailabilityData,
123 detail::TypeTagForDatatypeData, ParsedType, detail::PropertyData> {
124 friend TrailingObjects;
125
126 size_t numTrailingObjects(OverloadToken<ArgsUnion>) const { return NumArgs; }
127 size_t numTrailingObjects(OverloadToken<detail::AvailabilityData>) const {
128 return IsAvailability;
129 }
130 size_t
131 numTrailingObjects(OverloadToken<detail::TypeTagForDatatypeData>) const {
132 return IsTypeTagForDatatype;
133 }
134 size_t numTrailingObjects(OverloadToken<ParsedType>) const {
135 return HasParsedType;
136 }
137 size_t numTrailingObjects(OverloadToken<detail::PropertyData>) const {
138 return IsProperty;
139 }
140
141private:
142 IdentifierInfo *MacroII = nullptr;
143 SourceLocation MacroExpansionLoc;
144 SourceLocation EllipsisLoc;
145
146 /// The number of expression arguments this attribute has.
147 /// The expressions themselves are stored after the object.
148 unsigned NumArgs : 16;
149
150 /// True if already diagnosed as invalid.
151 mutable unsigned Invalid : 1;
152
153 /// True if this attribute was used as a type attribute.
154 mutable unsigned UsedAsTypeAttr : 1;
155
156 /// True if this has the extra information associated with an
157 /// availability attribute.
158 unsigned IsAvailability : 1;
159
160 /// True if this has extra information associated with a
161 /// type_tag_for_datatype attribute.
162 unsigned IsTypeTagForDatatype : 1;
163
164 /// True if this has extra information associated with a
165 /// Microsoft __delcspec(property) attribute.
166 unsigned IsProperty : 1;
167
168 /// True if this has a ParsedType
169 unsigned HasParsedType : 1;
170
171 /// True if the processing cache is valid.
172 mutable unsigned HasProcessingCache : 1;
173
174 /// A cached value.
175 mutable unsigned ProcessingCache : 8;
176
177 /// True if the attribute is specified using '#pragma clang attribute'.
178 mutable unsigned IsPragmaClangAttribute : 1;
179
180 /// The location of the 'unavailable' keyword in an
181 /// availability attribute.
182 SourceLocation UnavailableLoc;
183
184 const Expr *MessageExpr;
185
186 const ParsedAttrInfo &Info;
187
188 ArgsUnion *getArgsBuffer() { return getTrailingObjects<ArgsUnion>(); }
189 ArgsUnion const *getArgsBuffer() const {
190 return getTrailingObjects<ArgsUnion>();
191 }
192
193 detail::AvailabilityData *getAvailabilityData() {
194 return getTrailingObjects<detail::AvailabilityData>();
195 }
196 const detail::AvailabilityData *getAvailabilityData() const {
197 return getTrailingObjects<detail::AvailabilityData>();
198 }
199
200private:
201 friend class AttributeFactory;
202 friend class AttributePool;
203
204 /// Constructor for attributes with expression arguments.
205 ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
206 IdentifierInfo *scopeName, SourceLocation scopeLoc,
207 ArgsUnion *args, unsigned numArgs, Form formUsed,
208 SourceLocation ellipsisLoc)
209 : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
210 EllipsisLoc(ellipsisLoc), NumArgs(numArgs), Invalid(false),
211 UsedAsTypeAttr(false), IsAvailability(false),
212 IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
213 HasProcessingCache(false), IsPragmaClangAttribute(false),
214 Info(ParsedAttrInfo::get(*this)) {
215 if (numArgs)
216 memcpy(getArgsBuffer(), args, numArgs * sizeof(ArgsUnion));
217 }
218
219 /// Constructor for availability attributes.
220 ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
221 IdentifierInfo *scopeName, SourceLocation scopeLoc,
222 IdentifierLoc *Parm, const AvailabilityChange &introduced,
223 const AvailabilityChange &deprecated,
224 const AvailabilityChange &obsoleted, SourceLocation unavailable,
225 const Expr *messageExpr, Form formUsed, SourceLocation strict,
226 const Expr *replacementExpr)
227 : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
228 NumArgs(1), Invalid(false), UsedAsTypeAttr(false), IsAvailability(true),
229 IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
230 HasProcessingCache(false), IsPragmaClangAttribute(false),
231 UnavailableLoc(unavailable), MessageExpr(messageExpr),
232 Info(ParsedAttrInfo::get(*this)) {
233 ArgsUnion PVal(Parm);
234 memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion));
235 new (getAvailabilityData()) detail::AvailabilityData(
236 introduced, deprecated, obsoleted, strict, replacementExpr);
237 }
238
239 /// Constructor for objc_bridge_related attributes.
240 ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
241 IdentifierInfo *scopeName, SourceLocation scopeLoc,
242 IdentifierLoc *Parm1, IdentifierLoc *Parm2, IdentifierLoc *Parm3,
243 Form formUsed)
244 : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
245 NumArgs(3), Invalid(false), UsedAsTypeAttr(false),
246 IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false),
247 HasParsedType(false), HasProcessingCache(false),
248 IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
249 ArgsUnion *Args = getArgsBuffer();
250 Args[0] = Parm1;
251 Args[1] = Parm2;
252 Args[2] = Parm3;
253 }
254
255 /// Constructor for type_tag_for_datatype attribute.
256 ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
257 IdentifierInfo *scopeName, SourceLocation scopeLoc,
258 IdentifierLoc *ArgKind, ParsedType matchingCType,
259 bool layoutCompatible, bool mustBeNull, Form formUsed)
260 : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
261 NumArgs(1), Invalid(false), UsedAsTypeAttr(false),
262 IsAvailability(false), IsTypeTagForDatatype(true), IsProperty(false),
263 HasParsedType(false), HasProcessingCache(false),
264 IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
265 ArgsUnion PVal(ArgKind);
266 memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion));
267 detail::TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot();
268 new (&ExtraData.MatchingCType) ParsedType(matchingCType);
269 ExtraData.LayoutCompatible = layoutCompatible;
270 ExtraData.MustBeNull = mustBeNull;
271 }
272
273 /// Constructor for attributes with a single type argument.
274 ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
275 IdentifierInfo *scopeName, SourceLocation scopeLoc,
276 ParsedType typeArg, Form formUsed, SourceLocation ellipsisLoc)
277 : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
278 EllipsisLoc(ellipsisLoc), NumArgs(0), Invalid(false),
279 UsedAsTypeAttr(false), IsAvailability(false),
280 IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(true),
281 HasProcessingCache(false), IsPragmaClangAttribute(false),
282 Info(ParsedAttrInfo::get(*this)) {
283 new (&getTypeBuffer()) ParsedType(typeArg);
284 }
285
286 /// Constructor for microsoft __declspec(property) attribute.
287 ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
288 IdentifierInfo *scopeName, SourceLocation scopeLoc,
289 IdentifierInfo *getterId, IdentifierInfo *setterId, Form formUsed)
290 : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
291 NumArgs(0), Invalid(false), UsedAsTypeAttr(false),
292 IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(true),
293 HasParsedType(false), HasProcessingCache(false),
294 IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
295 new (&getPropertyDataBuffer()) detail::PropertyData(getterId, setterId);
296 }
297
298 /// Type tag information is stored immediately following the arguments, if
299 /// any, at the end of the object. They are mutually exclusive with
300 /// availability slots.
301 detail::TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() {
302 return *getTrailingObjects<detail::TypeTagForDatatypeData>();
303 }
304 const detail::TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() const {
305 return *getTrailingObjects<detail::TypeTagForDatatypeData>();
306 }
307
308 /// The type buffer immediately follows the object and are mutually exclusive
309 /// with arguments.
310 ParsedType &getTypeBuffer() { return *getTrailingObjects<ParsedType>(); }
311 const ParsedType &getTypeBuffer() const {
312 return *getTrailingObjects<ParsedType>();
313 }
314
315 /// The property data immediately follows the object is mutually exclusive
316 /// with arguments.
317 detail::PropertyData &getPropertyDataBuffer() {
318 assert(IsProperty);
319 return *getTrailingObjects<detail::PropertyData>();
320 }
321 const detail::PropertyData &getPropertyDataBuffer() const {
322 assert(IsProperty);
323 return *getTrailingObjects<detail::PropertyData>();
324 }
325
326 size_t allocated_size() const;
327
328public:
329 ParsedAttr(const ParsedAttr &) = delete;
330 ParsedAttr(ParsedAttr &&) = delete;
331 ParsedAttr &operator=(const ParsedAttr &) = delete;
333 ~ParsedAttr() = delete;
334
335 void operator delete(void *) = delete;
336
337 bool hasParsedType() const { return HasParsedType; }
338
339 /// Is this the Microsoft __declspec(property) attribute?
341 return IsProperty;
342 }
343
344 bool isInvalid() const { return Invalid; }
345 void setInvalid(bool b = true) const { Invalid = b; }
346
347 bool hasProcessingCache() const { return HasProcessingCache; }
348
349 unsigned getProcessingCache() const {
350 assert(hasProcessingCache());
351 return ProcessingCache;
352 }
353
354 void setProcessingCache(unsigned value) const {
355 ProcessingCache = value;
356 HasProcessingCache = true;
357 }
358
359 bool isUsedAsTypeAttr() const { return UsedAsTypeAttr; }
360 void setUsedAsTypeAttr(bool Used = true) { UsedAsTypeAttr = Used; }
361
362 /// True if the attribute is specified using '#pragma clang attribute'.
363 bool isPragmaClangAttribute() const { return IsPragmaClangAttribute; }
364
365 void setIsPragmaClangAttribute() { IsPragmaClangAttribute = true; }
366
367 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
368 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
369
370 /// getNumArgs - Return the number of actual arguments to this attribute.
371 unsigned getNumArgs() const { return NumArgs; }
372
373 /// getArg - Return the specified argument.
374 ArgsUnion getArg(unsigned Arg) const {
375 assert(Arg < NumArgs && "Arg access out of range!");
376 return getArgsBuffer()[Arg];
377 }
378
379 bool isArgExpr(unsigned Arg) const {
380 return Arg < NumArgs && getArg(Arg).is<Expr*>();
381 }
382
383 Expr *getArgAsExpr(unsigned Arg) const {
384 return getArg(Arg).get<Expr*>();
385 }
386
387 bool isArgIdent(unsigned Arg) const {
388 return Arg < NumArgs && getArg(Arg).is<IdentifierLoc*>();
389 }
390
391 IdentifierLoc *getArgAsIdent(unsigned Arg) const {
392 return getArg(Arg).get<IdentifierLoc*>();
393 }
394
396 assert(getParsedKind() == AT_Availability &&
397 "Not an availability attribute");
398 return getAvailabilityData()->Changes[detail::IntroducedSlot];
399 }
400
402 assert(getParsedKind() == AT_Availability &&
403 "Not an availability attribute");
404 return getAvailabilityData()->Changes[detail::DeprecatedSlot];
405 }
406
408 assert(getParsedKind() == AT_Availability &&
409 "Not an availability attribute");
410 return getAvailabilityData()->Changes[detail::ObsoletedSlot];
411 }
412
414 assert(getParsedKind() == AT_Availability &&
415 "Not an availability attribute");
416 return getAvailabilityData()->StrictLoc;
417 }
418
420 assert(getParsedKind() == AT_Availability &&
421 "Not an availability attribute");
422 return UnavailableLoc;
423 }
424
425 const Expr * getMessageExpr() const {
426 assert(getParsedKind() == AT_Availability &&
427 "Not an availability attribute");
428 return MessageExpr;
429 }
430
431 const Expr *getReplacementExpr() const {
432 assert(getParsedKind() == AT_Availability &&
433 "Not an availability attribute");
434 return getAvailabilityData()->Replacement;
435 }
436
438 assert(getParsedKind() == AT_TypeTagForDatatype &&
439 "Not a type_tag_for_datatype attribute");
440 return getTypeTagForDatatypeDataSlot().MatchingCType;
441 }
442
443 bool getLayoutCompatible() const {
444 assert(getParsedKind() == AT_TypeTagForDatatype &&
445 "Not a type_tag_for_datatype attribute");
446 return getTypeTagForDatatypeDataSlot().LayoutCompatible;
447 }
448
449 bool getMustBeNull() const {
450 assert(getParsedKind() == AT_TypeTagForDatatype &&
451 "Not a type_tag_for_datatype attribute");
452 return getTypeTagForDatatypeDataSlot().MustBeNull;
453 }
454
455 const ParsedType &getTypeArg() const {
456 assert(HasParsedType && "Not a type attribute");
457 return getTypeBuffer();
458 }
459
462 "Not a __delcspec(property) attribute");
463 return getPropertyDataBuffer().GetterId;
464 }
465
468 "Not a __delcspec(property) attribute");
469 return getPropertyDataBuffer().SetterId;
470 }
471
472 /// Set the macro identifier info object that this parsed attribute was
473 /// declared in if it was declared in a macro. Also set the expansion location
474 /// of the macro.
476 MacroII = MacroName;
477 MacroExpansionLoc = Loc;
478 }
479
480 /// Returns true if this attribute was declared in a macro.
481 bool hasMacroIdentifier() const { return MacroII != nullptr; }
482
483 /// Return the macro identifier if this attribute was declared in a macro.
484 /// nullptr is returned if it was not declared in a macro.
485 IdentifierInfo *getMacroIdentifier() const { return MacroII; }
486
488 assert(hasMacroIdentifier() && "Can only get the macro expansion location "
489 "if this attribute has a macro identifier.");
490 return MacroExpansionLoc;
491 }
492
493 /// Check if the attribute has exactly as many args as Num. May output an
494 /// error. Returns false if a diagnostic is produced.
495 bool checkExactlyNumArgs(class Sema &S, unsigned Num) const;
496 /// Check if the attribute has at least as many args as Num. May output an
497 /// error. Returns false if a diagnostic is produced.
498 bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const;
499 /// Check if the attribute has at most as many args as Num. May output an
500 /// error. Returns false if a diagnostic is produced.
501 bool checkAtMostNumArgs(class Sema &S, unsigned Num) const;
502
503 bool isTargetSpecificAttr() const;
504 bool isTypeAttr() const;
505 bool isStmtAttr() const;
506
507 bool hasCustomParsing() const;
508 bool acceptsExprPack() const;
509 bool isParamExpr(size_t N) const;
510 unsigned getMinArgs() const;
511 unsigned getMaxArgs() const;
512 unsigned getNumArgMembers() const;
513 bool hasVariadicArg() const;
514 void handleAttrWithDelayedArgs(Sema &S, Decl *D) const;
515 bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const;
516 bool diagnoseAppertainsTo(class Sema &S, const Stmt *St) const;
517 bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const;
518 // This function stub exists for parity with the declaration checking code so
519 // that checkCommonAttributeFeatures() can work generically on declarations
520 // or statements.
521 bool diagnoseMutualExclusion(class Sema &S, const Stmt *St) const {
522 return true;
523 }
524 bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const;
525 void getMatchRules(const LangOptions &LangOpts,
526 SmallVectorImpl<std::pair<attr::SubjectMatchRule, bool>>
527 &MatchRules) const;
528 bool diagnoseLangOpts(class Sema &S) const;
529 bool existsInTarget(const TargetInfo &Target) const;
530 bool isKnownToGCC() const;
531 bool isSupportedByPragmaAttribute() const;
532
533 /// Returns whether a [[]] attribute, if specified ahead of a declaration,
534 /// should be applied to the decl-specifier-seq instead (i.e. whether it
535 /// "slides" to the decl-specifier-seq).
536 ///
537 /// By the standard, attributes specified before the declaration always
538 /// appertain to the declaration, but historically we have allowed some of
539 /// these attributes to slide to the decl-specifier-seq, so we need to keep
540 /// supporting this behavior.
541 ///
542 /// This may only be called if isStandardAttributeSyntax() returns true.
544
545 /// If the parsed attribute has a semantic equivalent, and it would
546 /// have a semantic Spelling enumeration (due to having semantically-distinct
547 /// spelling variations), return the value of that semantic spelling. If the
548 /// parsed attribute does not have a semantic equivalent, or would not have
549 /// a Spelling enumeration, the value UINT_MAX is returned.
550 unsigned getSemanticSpelling() const;
551
552 /// If this is an OpenCL address space attribute, returns its representation
553 /// in LangAS, otherwise returns default address space.
555 switch (getParsedKind()) {
556 case ParsedAttr::AT_OpenCLConstantAddressSpace:
558 case ParsedAttr::AT_OpenCLGlobalAddressSpace:
560 case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
562 case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
564 case ParsedAttr::AT_OpenCLLocalAddressSpace:
566 case ParsedAttr::AT_OpenCLPrivateAddressSpace:
568 case ParsedAttr::AT_OpenCLGenericAddressSpace:
570 default:
571 return LangAS::Default;
572 }
573 }
574
575 /// If this is an OpenCL address space attribute, returns its SYCL
576 /// representation in LangAS, otherwise returns default address space.
578 switch (getKind()) {
579 case ParsedAttr::AT_OpenCLGlobalAddressSpace:
580 return LangAS::sycl_global;
581 case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
583 case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
585 case ParsedAttr::AT_OpenCLLocalAddressSpace:
586 return LangAS::sycl_local;
587 case ParsedAttr::AT_OpenCLPrivateAddressSpace:
589 case ParsedAttr::AT_OpenCLGenericAddressSpace:
590 default:
591 return LangAS::Default;
592 }
593 }
594
595 /// If this is an HLSL address space attribute, returns its representation
596 /// in LangAS, otherwise returns default address space.
598 switch (getParsedKind()) {
599 case ParsedAttr::AT_HLSLGroupSharedAddressSpace:
601 default:
602 return LangAS::Default;
603 }
604 }
605
608 }
609 const ParsedAttrInfo &getInfo() const { return Info; }
610};
611
612class AttributePool;
613/// A factory, from which one makes pools, from which one creates
614/// individual attributes which are deallocated with the pool.
615///
616/// Note that it's tolerably cheap to create and destroy one of
617/// these as long as you don't actually allocate anything in it.
619public:
620 enum {
622 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
624 detail::PropertyData>(1, 1, 0, 0, 0),
626 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
628 detail::PropertyData>(1, 0, 1, 0, 0),
630 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
632 detail::PropertyData>(0, 0, 0, 0, 1),
633 };
634
635private:
636 enum {
637 /// The number of free lists we want to be sure to support
638 /// inline. This is just enough that availability attributes
639 /// don't surpass it. It's actually very unlikely we'll see an
640 /// attribute that needs more than that; on x86-64 you'd need 10
641 /// expression arguments, and on i386 you'd need 19.
642 InlineFreeListsCapacity =
643 1 + (AvailabilityAllocSize - sizeof(ParsedAttr)) / sizeof(void *)
644 };
645
646 llvm::BumpPtrAllocator Alloc;
647
648 /// Free lists. The index is determined by the following formula:
649 /// (size - sizeof(ParsedAttr)) / sizeof(void*)
650 SmallVector<SmallVector<ParsedAttr *, 8>, InlineFreeListsCapacity> FreeLists;
651
652 // The following are the private interface used by AttributePool.
653 friend class AttributePool;
654
655 /// Allocate an attribute of the given size.
656 void *allocate(size_t size);
657
658 void deallocate(ParsedAttr *AL);
659
660 /// Reclaim all the attributes in the given pool chain, which is
661 /// non-empty. Note that the current implementation is safe
662 /// against reclaiming things which were not actually allocated
663 /// with the allocator, although of course it's important to make
664 /// sure that their allocator lives at least as long as this one.
665 void reclaimPool(AttributePool &head);
666
667public:
670};
671
673 friend class AttributeFactory;
674 friend class ParsedAttributes;
675 AttributeFactory &Factory;
677
678 void *allocate(size_t size) {
679 return Factory.allocate(size);
680 }
681
682 ParsedAttr *add(ParsedAttr *attr) {
683 Attrs.push_back(attr);
684 return attr;
685 }
686
687 void remove(ParsedAttr *attr) {
688 assert(llvm::is_contained(Attrs, attr) &&
689 "Can't take attribute from a pool that doesn't own it!");
690 Attrs.erase(llvm::find(Attrs, attr));
691 }
692
693 void takePool(AttributePool &pool);
694
695public:
696 /// Create a new pool for a factory.
697 AttributePool(AttributeFactory &factory) : Factory(factory) {}
698
699 AttributePool(const AttributePool &) = delete;
700 // The copy assignment operator is defined as deleted pending further
701 // motivation.
703
704 ~AttributePool() { Factory.reclaimPool(*this); }
705
706 /// Move the given pool's allocations to this pool.
707 AttributePool(AttributePool &&pool) = default;
708
709 // The move assignment operator is defined as deleted pending further
710 // motivation.
712
713 AttributeFactory &getFactory() const { return Factory; }
714
715 void clear() {
716 Factory.reclaimPool(*this);
717 Attrs.clear();
718 }
719
720 /// Take the given pool's allocations and add them to this pool.
722 takePool(pool);
723 pool.Attrs.clear();
724 }
725
727 IdentifierInfo *scopeName, SourceLocation scopeLoc,
728 ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form,
729 SourceLocation ellipsisLoc = SourceLocation()) {
730 size_t temp =
731 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
733 detail::PropertyData>(numArgs, 0, 0, 0, 0);
734 (void)temp;
735 void *memory = allocate(
736 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
738 detail::PropertyData>(numArgs, 0, 0, 0,
739 0));
740 return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
741 args, numArgs, form, ellipsisLoc));
742 }
743
745 IdentifierInfo *scopeName, SourceLocation scopeLoc,
746 IdentifierLoc *Param, const AvailabilityChange &introduced,
747 const AvailabilityChange &deprecated,
748 const AvailabilityChange &obsoleted,
749 SourceLocation unavailable, const Expr *MessageExpr,
750 ParsedAttr::Form form, SourceLocation strict,
751 const Expr *ReplacementExpr) {
752 void *memory = allocate(AttributeFactory::AvailabilityAllocSize);
753 return add(new (memory) ParsedAttr(
754 attrName, attrRange, scopeName, scopeLoc, Param, introduced, deprecated,
755 obsoleted, unavailable, MessageExpr, form, strict, ReplacementExpr));
756 }
757
759 IdentifierInfo *scopeName, SourceLocation scopeLoc,
760 IdentifierLoc *Param1, IdentifierLoc *Param2,
761 IdentifierLoc *Param3, ParsedAttr::Form form) {
762 void *memory = allocate(
763 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
765 detail::PropertyData>(3, 0, 0, 0, 0));
766 return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
767 Param1, Param2, Param3, form));
768 }
769
770 ParsedAttr *
772 IdentifierInfo *scopeName, SourceLocation scopeLoc,
773 IdentifierLoc *argumentKind,
774 ParsedType matchingCType, bool layoutCompatible,
775 bool mustBeNull, ParsedAttr::Form form) {
776 void *memory = allocate(AttributeFactory::TypeTagForDatatypeAllocSize);
777 return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
778 argumentKind, matchingCType,
779 layoutCompatible, mustBeNull, form));
780 }
781
783 SourceRange attrRange,
784 IdentifierInfo *scopeName,
785 SourceLocation scopeLoc, ParsedType typeArg,
786 ParsedAttr::Form formUsed,
787 SourceLocation ellipsisLoc) {
788 void *memory = allocate(
789 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
791 detail::PropertyData>(0, 0, 0, 1, 0));
792 return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
793 typeArg, formUsed, ellipsisLoc));
794 }
795
796 ParsedAttr *
798 IdentifierInfo *scopeName, SourceLocation scopeLoc,
799 IdentifierInfo *getterId, IdentifierInfo *setterId,
800 ParsedAttr::Form formUsed) {
801 void *memory = allocate(AttributeFactory::PropertyAllocSize);
802 return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
803 getterId, setterId, formUsed));
804 }
805};
806
809 using SizeType = decltype(std::declval<VecTy>().size());
810
811public:
813
814 static const ParsedAttributesView &none() {
815 static const ParsedAttributesView Attrs;
816 return Attrs;
817 }
818
819 bool empty() const { return AttrList.empty(); }
820 SizeType size() const { return AttrList.size(); }
821 ParsedAttr &operator[](SizeType pos) { return *AttrList[pos]; }
822 const ParsedAttr &operator[](SizeType pos) const { return *AttrList[pos]; }
823
824 void addAtEnd(ParsedAttr *newAttr) {
825 assert(newAttr);
826 AttrList.push_back(newAttr);
827 }
828
829 void remove(ParsedAttr *ToBeRemoved) {
830 assert(is_contained(AttrList, ToBeRemoved) &&
831 "Cannot remove attribute that isn't in the list");
832 AttrList.erase(llvm::find(AttrList, ToBeRemoved));
833 }
834
835 void clearListOnly() { AttrList.clear(); }
836
837 struct iterator : llvm::iterator_adaptor_base<iterator, VecTy::iterator,
838 std::random_access_iterator_tag,
839 ParsedAttr> {
840 iterator() : iterator_adaptor_base(nullptr) {}
841 iterator(VecTy::iterator I) : iterator_adaptor_base(I) {}
842 reference operator*() const { return **I; }
844 };
846 : llvm::iterator_adaptor_base<const_iterator, VecTy::const_iterator,
847 std::random_access_iterator_tag,
848 ParsedAttr> {
849 const_iterator() : iterator_adaptor_base(nullptr) {}
850 const_iterator(VecTy::const_iterator I) : iterator_adaptor_base(I) {}
851
852 reference operator*() const { return **I; }
854 };
855
857 AttrList.insert(AttrList.begin(), B.I, E.I);
858 }
859
861 AttrList.insert(AttrList.begin(), B.I, E.I);
862 }
863
865 AttrList.insert(AttrList.end(), B.I, E.I);
866 }
867
869 AttrList.insert(AttrList.end(), B.I, E.I);
870 }
871
872 iterator begin() { return iterator(AttrList.begin()); }
873 const_iterator begin() const { return const_iterator(AttrList.begin()); }
874 iterator end() { return iterator(AttrList.end()); }
875 const_iterator end() const { return const_iterator(AttrList.end()); }
876
878 assert(!empty());
879 return *AttrList.front();
880 }
881 const ParsedAttr &front() const {
882 assert(!empty());
883 return *AttrList.front();
884 }
886 assert(!empty());
887 return *AttrList.back();
888 }
889 const ParsedAttr &back() const {
890 assert(!empty());
891 return *AttrList.back();
892 }
893
895 return llvm::any_of(AttrList, [K](const ParsedAttr *AL) {
896 return AL->getParsedKind() == K;
897 });
898 }
899
901 auto It = llvm::find_if(AttrList, [](const ParsedAttr *AL) {
902 return AL->isDeclspecPropertyAttribute();
903 });
904 if (It != AttrList.end())
905 return *It;
906 return nullptr;
907 }
908 bool hasMSPropertyAttr() const { return getMSPropertyAttr(); }
909
910private:
911 VecTy AttrList;
912};
913
914/// ParsedAttributes - A collection of parsed attributes. Currently
915/// we don't differentiate between the various attribute syntaxes,
916/// which is basically silly.
917///
918/// Right now this is a very lightweight container, but the expectation
919/// is that this will become significantly more serious.
921public:
922 ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
925
926 AttributePool &getPool() const { return pool; }
927
929 assert(&Other != this &&
930 "ParsedAttributes can't take attributes from itself");
931 addAll(Other.begin(), Other.end());
932 Other.clearListOnly();
933 pool.takeAllFrom(Other.pool);
934 }
935
937 assert(&Other != this &&
938 "ParsedAttributes can't take attribute from itself");
939 Other.getPool().remove(PA);
940 Other.remove(PA);
941 getPool().add(PA);
942 addAtEnd(PA);
943 }
944
945 void clear() {
947 pool.clear();
948 Range = SourceRange();
949 }
950
951 /// Add attribute with expression arguments.
953 IdentifierInfo *scopeName, SourceLocation scopeLoc,
954 ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form,
955 SourceLocation ellipsisLoc = SourceLocation()) {
956 ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc,
957 args, numArgs, form, ellipsisLoc);
958 addAtEnd(attr);
959 return attr;
960 }
961
962 /// Add availability attribute.
964 IdentifierInfo *scopeName, SourceLocation scopeLoc,
965 IdentifierLoc *Param, const AvailabilityChange &introduced,
966 const AvailabilityChange &deprecated,
967 const AvailabilityChange &obsoleted,
968 SourceLocation unavailable, const Expr *MessageExpr,
969 ParsedAttr::Form form, SourceLocation strict,
970 const Expr *ReplacementExpr) {
971 ParsedAttr *attr = pool.create(
972 attrName, attrRange, scopeName, scopeLoc, Param, introduced, deprecated,
973 obsoleted, unavailable, MessageExpr, form, strict, ReplacementExpr);
974 addAtEnd(attr);
975 return attr;
976 }
977
978 /// Add objc_bridge_related attribute.
980 IdentifierInfo *scopeName, SourceLocation scopeLoc,
981 IdentifierLoc *Param1, IdentifierLoc *Param2,
982 IdentifierLoc *Param3, ParsedAttr::Form form) {
983 ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc,
984 Param1, Param2, Param3, form);
985 addAtEnd(attr);
986 return attr;
987 }
988
989 /// Add type_tag_for_datatype attribute.
990 ParsedAttr *
992 IdentifierInfo *scopeName, SourceLocation scopeLoc,
993 IdentifierLoc *argumentKind,
994 ParsedType matchingCType, bool layoutCompatible,
995 bool mustBeNull, ParsedAttr::Form form) {
997 attrName, attrRange, scopeName, scopeLoc, argumentKind, matchingCType,
998 layoutCompatible, mustBeNull, form);
999 addAtEnd(attr);
1000 return attr;
1001 }
1002
1003 /// Add an attribute with a single type argument.
1005 IdentifierInfo *scopeName, SourceLocation scopeLoc,
1006 ParsedType typeArg, ParsedAttr::Form formUsed,
1007 SourceLocation ellipsisLoc = SourceLocation()) {
1008 ParsedAttr *attr =
1009 pool.createTypeAttribute(attrName, attrRange, scopeName, scopeLoc,
1010 typeArg, formUsed, ellipsisLoc);
1011 addAtEnd(attr);
1012 return attr;
1013 }
1014
1015 /// Add microsoft __delspec(property) attribute.
1016 ParsedAttr *
1018 IdentifierInfo *scopeName, SourceLocation scopeLoc,
1019 IdentifierInfo *getterId, IdentifierInfo *setterId,
1020 ParsedAttr::Form formUsed) {
1022 attrName, attrRange, scopeName, scopeLoc, getterId, setterId, formUsed);
1023 addAtEnd(attr);
1024 return attr;
1025 }
1026
1027private:
1028 mutable AttributePool pool;
1029};
1030
1031/// Consumes the attributes from `First` and `Second` and concatenates them into
1032/// `Result`. Sets `Result.Range` to the combined range of `First` and `Second`.
1033void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &Second,
1034 ParsedAttributes &Result);
1035
1036/// These constants match the enumerated choices of
1037/// err_attribute_argument_n_type and err_attribute_argument_type.
1045};
1046
1047/// These constants match the enumerated choices of
1048/// warn_attribute_wrong_decl_type and err_attribute_wrong_decl_type.
1063};
1064
1066 const ParsedAttr &At) {
1067 DB.AddTaggedVal(reinterpret_cast<uint64_t>(At.getAttrName()),
1069 return DB;
1070}
1071
1073 const ParsedAttr *At) {
1074 DB.AddTaggedVal(reinterpret_cast<uint64_t>(At->getAttrName()),
1076 return DB;
1077}
1078
1079/// AttributeCommonInfo has a non-explicit constructor which takes an
1080/// SourceRange as its only argument, this constructor has many uses so making
1081/// it explicit is hard. This constructor causes ambiguity with
1082/// DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, SourceRange R).
1083/// We use SFINAE to disable any conversion and remove any ambiguity.
1084template <
1085 typename ACI,
1086 std::enable_if_t<std::is_same<ACI, AttributeCommonInfo>::value, int> = 0>
1088 const ACI &CI) {
1089 DB.AddTaggedVal(reinterpret_cast<uint64_t>(CI.getAttrName()),
1091 return DB;
1092}
1093
1094template <
1095 typename ACI,
1096 std::enable_if_t<std::is_same<ACI, AttributeCommonInfo>::value, int> = 0>
1098 const ACI *CI) {
1099 DB.AddTaggedVal(reinterpret_cast<uint64_t>(CI->getAttrName()),
1101 return DB;
1102}
1103
1104} // namespace clang
1105
1106#endif // LLVM_CLANG_SEMA_PARSEDATTR_H
Defines the Diagnostic-related interfaces.
Defines the clang::SourceLocation class and associated facilities.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__device__ __2f16 b
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Combines information about the source-code form of an attribute, including its syntax and spelling.
AttributeCommonInfo(const IdentifierInfo *AttrName, const IdentifierInfo *ScopeName, SourceRange AttrRange, SourceLocation ScopeLoc, Kind AttrKind, Form FormUsed)
const IdentifierInfo * getAttrName() const
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
Definition: ParsedAttr.h:618
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Definition: ParsedAttr.h:726
ParsedAttr * createTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form)
Definition: ParsedAttr.h:771
AttributePool(AttributePool &&pool)=default
Move the given pool's allocations to this pool.
AttributePool(AttributeFactory &factory)
Create a new pool for a factory.
Definition: ParsedAttr.h:697
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, ParsedAttr::Form form)
Definition: ParsedAttr.h:758
AttributePool & operator=(AttributePool &&pool)=delete
AttributePool(const AttributePool &)=delete
AttributeFactory & getFactory() const
Definition: ParsedAttr.h:713
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param, const AvailabilityChange &introduced, const AvailabilityChange &deprecated, const AvailabilityChange &obsoleted, SourceLocation unavailable, const Expr *MessageExpr, ParsedAttr::Form form, SourceLocation strict, const Expr *ReplacementExpr)
Definition: ParsedAttr.h:744
ParsedAttr * createPropertyAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Form formUsed)
Definition: ParsedAttr.h:797
ParsedAttr * createTypeAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, ParsedAttr::Form formUsed, SourceLocation ellipsisLoc)
Definition: ParsedAttr.h:782
void takeAllFrom(AttributePool &pool)
Take the given pool's allocations and add them to this pool.
Definition: ParsedAttr.h:721
AttributePool & operator=(const AttributePool &)=delete
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
@ ak_identifierinfo
IdentifierInfo.
Definition: Diagnostic.h:221
This represents one expression.
Definition: Expr.h:110
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:82
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:123
bool isPackExpansion() const
Definition: ParsedAttr.h:367
const AvailabilityChange & getAvailabilityDeprecated() const
Definition: ParsedAttr.h:401
bool isTargetSpecificAttr() const
Definition: ParsedAttr.cpp:187
bool hasCustomParsing() const
Definition: ParsedAttr.cpp:152
ParsedAttr(ParsedAttr &&)=delete
LangAS asSYCLLangAS() const
If this is an OpenCL address space attribute, returns its SYCL representation in LangAS,...
Definition: ParsedAttr.h:577
unsigned getSemanticSpelling() const
If the parsed attribute has a semantic equivalent, and it would have a semantic Spelling enumeration ...
Definition: ParsedAttr.cpp:245
bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const
Definition: ParsedAttr.cpp:168
bool isKnownToGCC() const
Definition: ParsedAttr.cpp:199
bool existsInTarget(const TargetInfo &Target) const
Definition: ParsedAttr.cpp:195
unsigned getMinArgs() const
Definition: ParsedAttr.cpp:142
bool checkExactlyNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has exactly as many args as Num.
Definition: ParsedAttr.cpp:281
IdentifierLoc * getArgAsIdent(unsigned Arg) const
Definition: ParsedAttr.h:391
bool hasParsedType() const
Definition: ParsedAttr.h:337
const AvailabilityChange & getAvailabilityIntroduced() const
Definition: ParsedAttr.h:395
void setInvalid(bool b=true) const
Definition: ParsedAttr.h:345
bool hasVariadicArg() const
Definition: ParsedAttr.cpp:249
const ParsedAttrInfo & getInfo() const
Definition: ParsedAttr.h:609
bool hasMacroIdentifier() const
Returns true if this attribute was declared in a macro.
Definition: ParsedAttr.h:481
ParsedAttr & operator=(ParsedAttr &&)=delete
ParsedAttr & operator=(const ParsedAttr &)=delete
void handleAttrWithDelayedArgs(Sema &S, Decl *D) const
Definition: ParsedAttr.cpp:261
const Expr * getReplacementExpr() const
Definition: ParsedAttr.h:431
IdentifierInfo * getPropertyDataSetter() const
Definition: ParsedAttr.h:466
bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const
Definition: ParsedAttr.cpp:164
bool hasProcessingCache() const
Definition: ParsedAttr.h:347
SourceLocation getUnavailableLoc() const
Definition: ParsedAttr.h:419
bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const
Definition: ParsedAttr.cpp:156
unsigned getProcessingCache() const
Definition: ParsedAttr.h:349
LangAS asOpenCLLangAS() const
If this is an OpenCL address space attribute, returns its representation in LangAS,...
Definition: ParsedAttr.h:554
bool acceptsExprPack() const
Definition: ParsedAttr.cpp:243
const Expr * getMessageExpr() const
Definition: ParsedAttr.h:425
const ParsedType & getMatchingCType() const
Definition: ParsedAttr.h:437
const ParsedType & getTypeArg() const
Definition: ParsedAttr.h:455
SourceLocation getStrictLoc() const
Definition: ParsedAttr.h:413
bool isTypeAttr() const
Definition: ParsedAttr.cpp:191
bool isSupportedByPragmaAttribute() const
Definition: ParsedAttr.cpp:201
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
Definition: ParsedAttr.h:371
bool isArgIdent(unsigned Arg) const
Definition: ParsedAttr.h:387
Expr * getArgAsExpr(unsigned Arg) const
Definition: ParsedAttr.h:383
bool getMustBeNull() const
Definition: ParsedAttr.h:449
bool diagnoseMutualExclusion(class Sema &S, const Stmt *St) const
Definition: ParsedAttr.h:521
bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at least as many args as Num.
Definition: ParsedAttr.cpp:286
bool isUsedAsTypeAttr() const
Definition: ParsedAttr.h:359
unsigned getNumArgMembers() const
Definition: ParsedAttr.cpp:148
bool isStmtAttr() const
Definition: ParsedAttr.cpp:193
unsigned getMaxArgs() const
Definition: ParsedAttr.cpp:144
bool isPragmaClangAttribute() const
True if the attribute is specified using '#pragma clang attribute'.
Definition: ParsedAttr.h:363
bool slidesFromDeclToDeclSpecLegacyBehavior() const
Returns whether a [[]] attribute, if specified ahead of a declaration, should be applied to the decl-...
Definition: ParsedAttr.cpp:205
AttributeCommonInfo::Kind getKind() const
Definition: ParsedAttr.h:606
void setProcessingCache(unsigned value) const
Definition: ParsedAttr.h:354
SourceLocation getMacroExpansionLoc() const
Definition: ParsedAttr.h:487
ParsedAttr(const ParsedAttr &)=delete
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool > > &MatchRules) const
Definition: ParsedAttr.cpp:173
bool isParamExpr(size_t N) const
Definition: ParsedAttr.cpp:257
bool isArgExpr(unsigned Arg) const
Definition: ParsedAttr.h:379
bool getLayoutCompatible() const
Definition: ParsedAttr.h:443
void setUsedAsTypeAttr(bool Used=true)
Definition: ParsedAttr.h:360
bool isDeclspecPropertyAttribute() const
Is this the Microsoft __declspec(property) attribute?
Definition: ParsedAttr.h:340
bool diagnoseLangOpts(class Sema &S) const
Definition: ParsedAttr.cpp:180
ArgsUnion getArg(unsigned Arg) const
getArg - Return the specified argument.
Definition: ParsedAttr.h:374
SourceLocation getEllipsisLoc() const
Definition: ParsedAttr.h:368
IdentifierInfo * getPropertyDataGetter() const
Definition: ParsedAttr.h:460
void setMacroIdentifier(IdentifierInfo *MacroName, SourceLocation Loc)
Set the macro identifier info object that this parsed attribute was declared in if it was declared in...
Definition: ParsedAttr.h:475
LangAS asHLSLLangAS() const
If this is an HLSL address space attribute, returns its representation in LangAS, otherwise returns d...
Definition: ParsedAttr.h:597
~ParsedAttr()=delete
bool isInvalid() const
Definition: ParsedAttr.h:344
void setIsPragmaClangAttribute()
Definition: ParsedAttr.h:365
bool checkAtMostNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at most as many args as Num.
Definition: ParsedAttr.cpp:291
const AvailabilityChange & getAvailabilityObsoleted() const
Definition: ParsedAttr.h:407
IdentifierInfo * getMacroIdentifier() const
Return the macro identifier if this attribute was declared in a macro.
Definition: ParsedAttr.h:485
static const ParsedAttributesView & none()
Definition: ParsedAttr.h:814
const ParsedAttr & front() const
Definition: ParsedAttr.h:881
bool hasMSPropertyAttr() const
Definition: ParsedAttr.h:908
const ParsedAttr & back() const
Definition: ParsedAttr.h:889
const_iterator begin() const
Definition: ParsedAttr.h:873
const ParsedAttr * getMSPropertyAttr() const
Definition: ParsedAttr.h:900
void addAll(const_iterator B, const_iterator E)
Definition: ParsedAttr.h:860
void addAllAtEnd(const_iterator B, const_iterator E)
Definition: ParsedAttr.h:868
void addAtEnd(ParsedAttr *newAttr)
Definition: ParsedAttr.h:824
void addAll(iterator B, iterator E)
Definition: ParsedAttr.h:856
bool hasAttribute(ParsedAttr::Kind K) const
Definition: ParsedAttr.h:894
ParsedAttr & operator[](SizeType pos)
Definition: ParsedAttr.h:821
const_iterator end() const
Definition: ParsedAttr.h:875
void remove(ParsedAttr *ToBeRemoved)
Definition: ParsedAttr.h:829
const ParsedAttr & operator[](SizeType pos) const
Definition: ParsedAttr.h:822
void addAllAtEnd(iterator B, iterator E)
Definition: ParsedAttr.h:864
SizeType size() const
Definition: ParsedAttr.h:820
ParsedAttributes - A collection of parsed attributes.
Definition: ParsedAttr.h:920
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
Definition: ParsedAttr.h:952
void takeOneFrom(ParsedAttributes &Other, ParsedAttr *PA)
Definition: ParsedAttr.h:936
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, ParsedAttr::Form form)
Add objc_bridge_related attribute.
Definition: ParsedAttr.h:979
AttributePool & getPool() const
Definition: ParsedAttr.h:926
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param, const AvailabilityChange &introduced, const AvailabilityChange &deprecated, const AvailabilityChange &obsoleted, SourceLocation unavailable, const Expr *MessageExpr, ParsedAttr::Form form, SourceLocation strict, const Expr *ReplacementExpr)
Add availability attribute.
Definition: ParsedAttr.h:963
ParsedAttributes & operator=(const ParsedAttributes &)=delete
ParsedAttr * addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Form formUsed)
Add microsoft __delspec(property) attribute.
Definition: ParsedAttr.h:1017
ParsedAttributes(const ParsedAttributes &)=delete
void takeAllFrom(ParsedAttributes &Other)
Definition: ParsedAttr.h:928
ParsedAttributes(AttributeFactory &factory)
Definition: ParsedAttr.h:922
ParsedAttr * addNewTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form)
Add type_tag_for_datatype attribute.
Definition: ParsedAttr.h:991
ParsedAttr * addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, ParsedAttr::Form formUsed, SourceLocation ellipsisLoc=SourceLocation())
Add an attribute with a single type argument.
Definition: ParsedAttr.h:1004
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:356
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition: Stmt.h:72
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1110
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
Definition: Diagnostic.h:1184
Exposes information about the current target.
Definition: TargetInfo.h:206
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
SubjectMatchRule
A list of all the recognized kinds of attributes.
@ NumAvailabilitySlots
Definition: ParsedAttr.h:62
AttributeDeclKind
These constants match the enumerated choices of warn_attribute_wrong_decl_type and err_attribute_wron...
Definition: ParsedAttr.h:1049
@ ExpectedFunctionMethodOrParameter
Definition: ParsedAttr.h:1055
@ ExpectedFunctionWithProtoType
Definition: ParsedAttr.h:1062
@ ExpectedFunctionMethodOrBlock
Definition: ParsedAttr.h:1054
@ ExpectedTypeOrNamespace
Definition: ParsedAttr.h:1059
@ ExpectedVariableFieldOrTag
Definition: ParsedAttr.h:1058
@ ExpectedVariableOrField
Definition: ParsedAttr.h:1057
@ ExpectedUnion
Definition: ParsedAttr.h:1051
@ ExpectedFunctionOrMethod
Definition: ParsedAttr.h:1053
@ ExpectedVariable
Definition: ParsedAttr.h:1056
@ ExpectedVariableOrFunction
Definition: ParsedAttr.h:1052
@ ExpectedKernelFunction
Definition: ParsedAttr.h:1061
@ ExpectedFunctionVariableOrClass
Definition: ParsedAttr.h:1060
@ ExpectedFunction
Definition: ParsedAttr.h:1050
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
Definition: ParsedAttr.h:107
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &Second, ParsedAttributes &Result)
Consumes the attributes from First and Second and concatenates them into Result.
Definition: ParsedAttr.cpp:297
AttributeArgumentNType
These constants match the enumerated choices of err_attribute_argument_n_type and err_attribute_argum...
Definition: ParsedAttr.h:1038
@ AANT_ArgumentIntegerConstant
Definition: ParsedAttr.h:1040
@ AANT_ArgumentBuiltinFunction
Definition: ParsedAttr.h:1044
@ AANT_ArgumentIntOrBool
Definition: ParsedAttr.h:1039
@ AANT_ArgumentConstantExpr
Definition: ParsedAttr.h:1043
@ AANT_ArgumentIdentifier
Definition: ParsedAttr.h:1042
@ AANT_ArgumentString
Definition: ParsedAttr.h:1041
@ Result
The result type of a method or function.
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition: Ownership.h:243
#define true
Definition: stdbool.h:21
#define false
Definition: stdbool.h:22
Represents information about a change in availability for an entity, which is part of the encoding of...
Definition: ParsedAttr.h:46
VersionTuple Version
The version number at which the change occurred.
Definition: ParsedAttr.h:51
bool isValid() const
Determine whether this availability change is valid.
Definition: ParsedAttr.h:57
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
Definition: ParsedAttr.h:48
SourceRange VersionRange
The source range covering the version number.
Definition: ParsedAttr.h:54
Wraps an identifier and optional source location for the identifier.
Definition: ParsedAttr.h:97
SourceLocation Loc
Definition: ParsedAttr.h:98
IdentifierInfo * Ident
Definition: ParsedAttr.h:99
static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)
Definition: ParsedAttr.cpp:28
unsigned AttrKind
Corresponds to the Kind enum.
const_iterator(VecTy::const_iterator I)
Definition: ParsedAttr.h:850
Describes the trailing object for Availability attribute in ParsedAttr.
Definition: ParsedAttr.h:66
AvailabilityData(const AvailabilityChange &Introduced, const AvailabilityChange &Deprecated, const AvailabilityChange &Obsoleted, SourceLocation Strict, const Expr *ReplaceExpr)
Definition: ParsedAttr.h:71
AvailabilityChange Changes[NumAvailabilitySlots]
Definition: ParsedAttr.h:67
IdentifierInfo * SetterId
Definition: ParsedAttr.h:88
PropertyData(IdentifierInfo *getterId, IdentifierInfo *setterId)
Definition: ParsedAttr.h:90
IdentifierInfo * GetterId
Definition: ParsedAttr.h:88