clang 24.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 <bitset>
28#include <cassert>
29#include <cstddef>
30#include <cstring>
31#include <utility>
32
33namespace clang {
34
35class ASTContext;
36class Decl;
37class Expr;
38class IdentifierInfo;
39class LangOptions;
40class Sema;
41class Stmt;
42class TargetInfo;
43
44/// Represents information about a change in availability for
45/// an entity, which is part of the encoding of the 'availability'
46/// attribute.
48 /// The location of the keyword indicating the kind of change.
50
51 /// The version number at which the change occurred.
52 VersionTuple Version;
53
54 /// The source range covering the version number.
56
57 /// Determine whether this availability change is valid.
58 bool isValid() const { return !Version.empty(); }
59};
60
61namespace detail {
65
66/// Describes the trailing object for Availability attribute in ParsedAttr.
72
74 const AvailabilityChange &Deprecated,
75 const AvailabilityChange &Obsoleted, SourceLocation Strict,
76 const Expr *ReplaceExpr, const IdentifierLoc *EnvironmentLoc)
77 : StrictLoc(Strict), Replacement(ReplaceExpr),
79 Changes[IntroducedSlot] = Introduced;
80 Changes[DeprecatedSlot] = Deprecated;
81 Changes[ObsoletedSlot] = Obsoleted;
82 }
83};
84
87 LLVM_PREFERRED_TYPE(bool)
89 LLVM_PREFERRED_TYPE(bool)
90 unsigned MustBeNull : 1;
91};
94
96 : GetterId(getterId), SetterId(setterId) {}
97};
98
99} // namespace detail
100
101/// A union of the various pointer types that can be passed to an
102/// ParsedAttr as an argument.
103using ArgsUnion = llvm::PointerUnion<Expr *, IdentifierLoc *>;
105
106/// ParsedAttr - Represents a syntactic attribute.
107///
108/// For a GNU attribute, there are four forms of this construct:
109///
110/// 1: __attribute__(( const )). ParmName/Args/NumArgs will all be unused.
111/// 2: __attribute__(( mode(byte) )). ParmName used, Args/NumArgs unused.
112/// 3: __attribute__(( format(printf, 1, 2) )). ParmName/Args/NumArgs all used.
113/// 4: __attribute__(( aligned(16) )). ParmName is unused, Args/Num used.
114///
115class ParsedAttr final
116 : public AttributeCommonInfo,
117 private llvm::TrailingObjects<
118 ParsedAttr, ArgsUnion, detail::AvailabilityData,
119 detail::TypeTagForDatatypeData, ParsedType, detail::PropertyData> {
120 friend TrailingObjects;
121
122 size_t numTrailingObjects(OverloadToken<ArgsUnion>) const { return NumArgs; }
123 size_t numTrailingObjects(OverloadToken<detail::AvailabilityData>) const {
124 return IsAvailability;
125 }
126 size_t
127 numTrailingObjects(OverloadToken<detail::TypeTagForDatatypeData>) const {
128 return IsTypeTagForDatatype;
129 }
130 size_t numTrailingObjects(OverloadToken<ParsedType>) const {
131 return HasParsedType;
132 }
133
134private:
135 IdentifierInfo *MacroII = nullptr;
136 SourceLocation MacroExpansionLoc;
137 SourceLocation EllipsisLoc;
138
139 /// The number of expression arguments this attribute has.
140 /// The expressions themselves are stored after the object.
141 unsigned NumArgs : 16;
142
143 /// True if already diagnosed as invalid.
144 LLVM_PREFERRED_TYPE(bool)
145 mutable unsigned Invalid : 1;
146
147 /// True if this attribute was used as a type attribute.
148 LLVM_PREFERRED_TYPE(bool)
149 mutable unsigned UsedAsTypeAttr : 1;
150
151 /// True if this has the extra information associated with an
152 /// availability attribute.
153 LLVM_PREFERRED_TYPE(bool)
154 unsigned IsAvailability : 1;
155
156 /// True if this has extra information associated with a
157 /// type_tag_for_datatype attribute.
158 LLVM_PREFERRED_TYPE(bool)
159 unsigned IsTypeTagForDatatype : 1;
160
161 /// True if this has extra information associated with a
162 /// Microsoft __delcspec(property) attribute.
163 LLVM_PREFERRED_TYPE(bool)
164 unsigned IsProperty : 1;
165
166 /// True if this has a ParsedType
167 LLVM_PREFERRED_TYPE(bool)
168 unsigned HasParsedType : 1;
169
170 /// True if the processing cache is valid.
171 LLVM_PREFERRED_TYPE(bool)
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 LLVM_PREFERRED_TYPE(bool)
179 mutable unsigned IsPragmaClangAttribute : 1;
180
181 /// The location of the 'unavailable' keyword in an
182 /// availability attribute.
183 SourceLocation UnavailableLoc;
184
185 const Expr *MessageExpr;
186
187 const ParsedAttrInfo &Info;
188
189 ArgsUnion *getArgsBuffer() { return getTrailingObjects<ArgsUnion>(); }
190 ArgsUnion const *getArgsBuffer() const {
191 return getTrailingObjects<ArgsUnion>();
192 }
193
194 detail::AvailabilityData *getAvailabilityData() {
195 return getTrailingObjects<detail::AvailabilityData>();
196 }
197 const detail::AvailabilityData *getAvailabilityData() const {
198 return getTrailingObjects<detail::AvailabilityData>();
199 }
200
201private:
202 friend class AttributeFactory;
203 friend class AttributePool;
204
205 /// Constructor for attributes with expression arguments.
206 ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
207 AttributeScopeInfo scope, ArgsUnion *args, unsigned numArgs,
208 Form formUsed, SourceLocation ellipsisLoc)
209 : AttributeCommonInfo(attrName, scope, attrRange, 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,
222 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, const IdentifierLoc *environmentLoc)
227 : AttributeCommonInfo(attrName, scope, attrRange, formUsed), NumArgs(1),
228 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())
236 detail::AvailabilityData(introduced, deprecated, obsoleted, strict,
237 replacementExpr, environmentLoc);
238 }
239
240 /// Constructor for objc_bridge_related attributes.
241 ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
242 AttributeScopeInfo scope, IdentifierLoc *Parm1,
243 IdentifierLoc *Parm2, IdentifierLoc *Parm3, Form formUsed)
244 : AttributeCommonInfo(attrName, scope, attrRange, formUsed), NumArgs(3),
245 Invalid(false), UsedAsTypeAttr(false), IsAvailability(false),
246 IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
247 HasProcessingCache(false), IsPragmaClangAttribute(false),
248 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 AttributeScopeInfo scope, IdentifierLoc *ArgKind,
258 ParsedType matchingCType, bool layoutCompatible, bool mustBeNull,
259 Form formUsed)
260 : AttributeCommonInfo(attrName, scope, attrRange, formUsed), NumArgs(1),
261 Invalid(false), UsedAsTypeAttr(false), IsAvailability(false),
262 IsTypeTagForDatatype(true), IsProperty(false), HasParsedType(false),
263 HasProcessingCache(false), IsPragmaClangAttribute(false),
264 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 AttributeScopeInfo scope, ParsedType typeArg, Form formUsed,
276 SourceLocation ellipsisLoc)
277 : AttributeCommonInfo(attrName, scope, attrRange, 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 AttributeScopeInfo scope, IdentifierInfo *getterId,
289 IdentifierInfo *setterId, Form formUsed)
290 : AttributeCommonInfo(attrName, scope, attrRange, formUsed), NumArgs(0),
291 Invalid(false), UsedAsTypeAttr(false), IsAvailability(false),
292 IsTypeTagForDatatype(false), IsProperty(true), HasParsedType(false),
293 HasProcessingCache(false), IsPragmaClangAttribute(false),
294 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;
332 ParsedAttr &operator=(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 && isa<Expr *>(getArg(Arg));
381 }
382
383 Expr *getArgAsExpr(unsigned Arg) const { return cast<Expr *>(getArg(Arg)); }
384
385 bool isArgIdent(unsigned Arg) const {
386 return Arg < NumArgs && isa<IdentifierLoc *>(getArg(Arg));
387 }
388
389 IdentifierLoc *getArgAsIdent(unsigned Arg) const {
390 return cast<IdentifierLoc *>(getArg(Arg));
391 }
392
394 assert(getParsedKind() == AT_Availability &&
395 "Not an availability attribute");
396 return getAvailabilityData()->Changes[detail::IntroducedSlot];
397 }
398
400 assert(getParsedKind() == AT_Availability &&
401 "Not an availability attribute");
402 return getAvailabilityData()->Changes[detail::DeprecatedSlot];
403 }
404
406 assert(getParsedKind() == AT_Availability &&
407 "Not an availability attribute");
408 return getAvailabilityData()->Changes[detail::ObsoletedSlot];
409 }
410
412 assert(getParsedKind() == AT_Availability &&
413 "Not an availability attribute");
414 return getAvailabilityData()->StrictLoc;
415 }
416
418 assert(getParsedKind() == AT_Availability &&
419 "Not an availability attribute");
420 return UnavailableLoc;
421 }
422
423 const Expr * getMessageExpr() const {
424 assert(getParsedKind() == AT_Availability &&
425 "Not an availability attribute");
426 return MessageExpr;
427 }
428
429 const Expr *getReplacementExpr() const {
430 assert(getParsedKind() == AT_Availability &&
431 "Not an availability attribute");
432 return getAvailabilityData()->Replacement;
433 }
434
436 assert(getParsedKind() == AT_Availability &&
437 "Not an availability attribute");
438 return getAvailabilityData()->EnvironmentLoc;
439 }
440
442 assert(getParsedKind() == AT_TypeTagForDatatype &&
443 "Not a type_tag_for_datatype attribute");
444 return getTypeTagForDatatypeDataSlot().MatchingCType;
445 }
446
447 bool getLayoutCompatible() const {
448 assert(getParsedKind() == AT_TypeTagForDatatype &&
449 "Not a type_tag_for_datatype attribute");
450 return getTypeTagForDatatypeDataSlot().LayoutCompatible;
451 }
452
453 bool getMustBeNull() const {
454 assert(getParsedKind() == AT_TypeTagForDatatype &&
455 "Not a type_tag_for_datatype attribute");
456 return getTypeTagForDatatypeDataSlot().MustBeNull;
457 }
458
459 const ParsedType &getTypeArg() const {
460 assert(HasParsedType && "Not a type attribute");
461 return getTypeBuffer();
462 }
463
466 "Not a __delcspec(property) attribute");
467 return getPropertyDataBuffer().GetterId;
468 }
469
472 "Not a __delcspec(property) attribute");
473 return getPropertyDataBuffer().SetterId;
474 }
475
476 /// Set the macro identifier info object that this parsed attribute was
477 /// declared in if it was declared in a macro. Also set the expansion location
478 /// of the macro.
480 MacroII = MacroName;
481 MacroExpansionLoc = Loc;
482 }
483
484 /// Returns true if this attribute was declared in a macro.
485 bool hasMacroIdentifier() const { return MacroII != nullptr; }
486
487 /// Return the macro identifier if this attribute was declared in a macro.
488 /// nullptr is returned if it was not declared in a macro.
489 IdentifierInfo *getMacroIdentifier() const { return MacroII; }
490
492 assert(hasMacroIdentifier() && "Can only get the macro expansion location "
493 "if this attribute has a macro identifier.");
494 return MacroExpansionLoc;
495 }
496
497 /// Check if the attribute has exactly as many args as Num. May output an
498 /// error. Returns false if a diagnostic is produced.
499 bool checkExactlyNumArgs(class Sema &S, unsigned Num) const;
500 /// Check if the attribute has at least as many args as Num. May output an
501 /// error. Returns false if a diagnostic is produced.
502 bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const;
503 /// Check if the attribute has at most as many args as Num. May output an
504 /// error. Returns false if a diagnostic is produced.
505 bool checkAtMostNumArgs(class Sema &S, unsigned Num) const;
506
507 bool isTargetSpecificAttr() const;
508 bool isTypeAttr() const;
509 bool isStmtAttr() const;
510
511 bool hasCustomParsing() const;
512 bool acceptsExprPack() const;
513 bool isParamExpr(size_t N) const;
514 unsigned getMinArgs() const;
515 unsigned getMaxArgs() const;
516 unsigned getNumArgMembers() const;
517 bool hasVariadicArg() const;
518 void handleAttrWithDelayedArgs(Sema &S, Decl *D) const;
519 bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const;
520 bool diagnoseAppertainsTo(class Sema &S, const Stmt *St) const;
521 // This function stub exists for parity with the declaration and statement
522 // checking code so that checkCommonAttributeFeatures() can work generically
523 // on types.
524 bool diagnoseAppertainsTo(class Sema &S, QualType T) const { return true; }
525 bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const;
526 // This function stub exists for parity with the declaration checking code so
527 // that checkCommonAttributeFeatures() can work generically on declarations
528 // or statements.
529 bool diagnoseMutualExclusion(class Sema &S, const Stmt *St) const {
530 return true;
531 }
532 // This function stub exists for parity with the declaration and statement
533 // checking code so that checkCommonAttributeFeatures() can work generically
534 // on types.
535 bool diagnoseMutualExclusion(class Sema &S, QualType T) const { return true; }
536 bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const;
537 void getMatchRules(const LangOptions &LangOpts,
538 SmallVectorImpl<std::pair<attr::SubjectMatchRule, bool>>
539 &MatchRules) const;
540 bool diagnoseLangOpts(class Sema &S) const;
541 bool existsInTarget(const TargetInfo &Target) const;
542 bool isKnownToGCC() const;
543 bool isSupportedByPragmaAttribute() const;
544
545 /// Returns whether a [[]] attribute, if specified ahead of a declaration,
546 /// should be applied to the decl-specifier-seq instead (i.e. whether it
547 /// "slides" to the decl-specifier-seq).
548 ///
549 /// By the standard, attributes specified before the declaration always
550 /// appertain to the declaration, but historically we have allowed some of
551 /// these attributes to slide to the decl-specifier-seq, so we need to keep
552 /// supporting this behavior.
553 ///
554 /// This may only be called if isStandardAttributeSyntax() returns true.
555 bool slidesFromDeclToDeclSpecLegacyBehavior() const;
556
557 /// If the parsed attribute has a semantic equivalent, and it would
558 /// have a semantic Spelling enumeration (due to having semantically-distinct
559 /// spelling variations), return the value of that semantic spelling. If the
560 /// parsed attribute does not have a semantic equivalent, or would not have
561 /// a Spelling enumeration, the value UINT_MAX is returned.
562 unsigned getSemanticSpelling() const;
563
564 /// If this is an OpenCL address space attribute, returns its representation
565 /// in LangAS, otherwise returns default address space.
567 switch (getParsedKind()) {
568 case ParsedAttr::AT_OpenCLConstantAddressSpace:
570 case ParsedAttr::AT_OpenCLGlobalAddressSpace:
572 case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
574 case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
576 case ParsedAttr::AT_OpenCLLocalAddressSpace:
578 case ParsedAttr::AT_OpenCLPrivateAddressSpace:
580 case ParsedAttr::AT_OpenCLGenericAddressSpace:
582 default:
583 return LangAS::Default;
584 }
585 }
586
587 /// If this is a SYCL address space attribute, returns its SYCL
588 /// representation in LangAS.
590 switch (getParsedKind()) {
591 case ParsedAttr::AT_SYCLGlobalAddressSpace:
592 return LangAS::sycl_global;
593 case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
595 case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
597 case ParsedAttr::AT_SYCLLocalAddressSpace:
598 return LangAS::sycl_local;
599 case ParsedAttr::AT_SYCLPrivateAddressSpace:
601 case ParsedAttr::AT_SYCLGenericAddressSpace:
603 case ParsedAttr::AT_SYCLConstantAddressSpace:
605 // The OpenCL address space attributes are available to enable
606 // implicit conversions between OpenCL address space attributes and
607 // SYCL address space attributes when targeting the OpenCL execution
608 // environments.
609 case ParsedAttr::AT_OpenCLGlobalAddressSpace:
610 case ParsedAttr::AT_OpenCLLocalAddressSpace:
611 case ParsedAttr::AT_OpenCLPrivateAddressSpace:
612 case ParsedAttr::AT_OpenCLGenericAddressSpace:
613 case ParsedAttr::AT_OpenCLConstantAddressSpace:
614 return asOpenCLLangAS();
615 default:
616 return LangAS::Default;
617 }
618 }
619
620 /// If this is an HLSL address space attribute, returns its representation
621 /// in LangAS, otherwise returns default address space.
623 switch (getParsedKind()) {
624 case ParsedAttr::AT_HLSLGroupSharedAddressSpace:
626 default:
627 return LangAS::Default;
628 }
629 }
630
632 return AttributeCommonInfo::Kind(Info.AttrKind);
633 }
634 const ParsedAttrInfo &getInfo() const { return Info; }
635};
636
637class AttributePool;
638/// A factory, from which one makes pools, from which one creates
639/// individual attributes which are deallocated with the pool.
640///
641/// Note that it's tolerably cheap to create and destroy one of
642/// these as long as you don't actually allocate anything in it.
644public:
645 enum {
647 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
649 detail::PropertyData>(1, 1, 0, 0, 0),
651 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
653 detail::PropertyData>(1, 0, 1, 0, 0),
655 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
657 detail::PropertyData>(0, 0, 0, 0, 1),
658 };
659
660private:
661 enum {
662 /// The number of free lists we want to be sure to support
663 /// inline. This is just enough that availability attributes
664 /// don't surpass it. It's actually very unlikely we'll see an
665 /// attribute that needs more than that; on x86-64 you'd need 10
666 /// expression arguments, and on i386 you'd need 19.
667 InlineFreeListsCapacity =
668 1 + (AvailabilityAllocSize - sizeof(ParsedAttr)) / sizeof(void *)
669 };
670
671 llvm::BumpPtrAllocator Alloc;
672
673 /// Free lists. The index is determined by the following formula:
674 /// (size - sizeof(ParsedAttr)) / sizeof(void*)
675 SmallVector<SmallVector<ParsedAttr *, 8>, InlineFreeListsCapacity> FreeLists;
676
677 // The following are the private interface used by AttributePool.
678 friend class AttributePool;
679
680 /// Allocate an attribute of the given size.
681 void *allocate(size_t size);
682
683 void deallocate(ParsedAttr *AL);
684
685 /// Reclaim all the attributes in the given pool chain, which is
686 /// non-empty. Note that the current implementation is safe
687 /// against reclaiming things which were not actually allocated
688 /// with the allocator, although of course it's important to make
689 /// sure that their allocator lives at least as long as this one.
690 void reclaimPool(AttributePool &head);
691
692public:
695};
696
699 friend class AttributeFactory;
700 friend class ParsedAttributes;
701 AttributeFactory &Factory;
703
704 void *allocate(size_t size) {
705 return Factory.allocate(size);
706 }
707
708 ParsedAttr *add(ParsedAttr *attr) {
709 Attrs.push_back(attr);
710 return attr;
711 }
712
713 void remove(ParsedAttr *attr) {
714 assert(llvm::is_contained(Attrs, attr) &&
715 "Can't take attribute from a pool that doesn't own it!");
716 Attrs.erase(llvm::find(Attrs, attr));
717 }
718
719 void takePool(AttributePool &pool);
720
721public:
722 /// Create a new pool for a factory.
723 AttributePool(AttributeFactory &factory) : Factory(factory) {}
724
725 AttributePool(const AttributePool &) = delete;
726 // The copy assignment operator is defined as deleted pending further
727 // motivation.
729
730 ~AttributePool() { Factory.reclaimPool(*this); }
731
732 /// Move the given pool's allocations to this pool.
733 AttributePool(AttributePool &&pool) = default;
734
735 // The move assignment operator is defined as deleted pending further
736 // motivation.
738
739 AttributeFactory &getFactory() const { return Factory; }
740
741 void clear() {
742 Factory.reclaimPool(*this);
743 Attrs.clear();
744 }
745
746 /// Take the given pool's allocations and add them to this pool.
748 takePool(pool);
749 pool.Attrs.clear();
750 }
751
752 /// Removes the attributes from \c List, which are owned by \c Pool, and adds
753 /// them at the end of this \c AttributePool.
754 void takeFrom(ParsedAttributesView &List, AttributePool &Pool);
755
757 AttributeScopeInfo scope, ArgsUnion *args,
758 unsigned numArgs, ParsedAttr::Form form,
759 SourceLocation ellipsisLoc = SourceLocation()) {
760 void *memory = allocate(
761 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
763 detail::PropertyData>(numArgs, 0, 0, 0,
764 0));
765 return add(new (memory) ParsedAttr(attrName, attrRange, scope, args,
766 numArgs, form, ellipsisLoc));
767 }
768
770 AttributeScopeInfo scope, IdentifierLoc *Param,
771 const AvailabilityChange &introduced,
772 const AvailabilityChange &deprecated,
773 const AvailabilityChange &obsoleted,
774 SourceLocation unavailable, const Expr *MessageExpr,
775 ParsedAttr::Form form, SourceLocation strict,
776 const Expr *ReplacementExpr,
777 IdentifierLoc *EnvironmentLoc) {
778 void *memory = allocate(AttributeFactory::AvailabilityAllocSize);
779 return add(new (memory)
780 ParsedAttr(attrName, attrRange, scope, Param, introduced,
781 deprecated, obsoleted, unavailable, MessageExpr,
782 form, strict, ReplacementExpr, EnvironmentLoc));
783 }
784
786 AttributeScopeInfo scope, IdentifierLoc *Param1,
787 IdentifierLoc *Param2, IdentifierLoc *Param3,
788 ParsedAttr::Form form) {
789 void *memory = allocate(
790 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
792 detail::PropertyData>(3, 0, 0, 0, 0));
793 return add(new (memory) ParsedAttr(attrName, attrRange, scope, Param1,
794 Param2, Param3, form));
795 }
796
798 IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope,
799 IdentifierLoc *argumentKind, ParsedType matchingCType,
800 bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form) {
801 void *memory = allocate(AttributeFactory::TypeTagForDatatypeAllocSize);
802 return add(new (memory) ParsedAttr(attrName, attrRange, scope, argumentKind,
803 matchingCType, layoutCompatible,
804 mustBeNull, form));
805 }
806
808 SourceRange attrRange,
809 AttributeScopeInfo scope, ParsedType typeArg,
810 ParsedAttr::Form formUsed,
811 SourceLocation ellipsisLoc) {
812 void *memory = allocate(
813 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
815 detail::PropertyData>(0, 0, 0, 1, 0));
816 return add(new (memory) ParsedAttr(attrName, attrRange, scope, typeArg,
817 formUsed, ellipsisLoc));
818 }
819
820 ParsedAttr *
822 AttributeScopeInfo scope, IdentifierInfo *getterId,
823 IdentifierInfo *setterId, ParsedAttr::Form formUsed) {
824 void *memory = allocate(AttributeFactory::PropertyAllocSize);
825 return add(new (memory) ParsedAttr(attrName, attrRange, scope, getterId,
826 setterId, formUsed));
827 }
828};
829
831 friend class AttributePool;
833 using SizeType = decltype(std::declval<VecTy>().size());
834
835public:
837
838 static const ParsedAttributesView &none() {
839 static const ParsedAttributesView Attrs;
840 return Attrs;
841 }
842
843 bool empty() const { return AttrList.empty(); }
844 SizeType size() const { return AttrList.size(); }
845 ParsedAttr &operator[](SizeType pos) { return *AttrList[pos]; }
846 const ParsedAttr &operator[](SizeType pos) const { return *AttrList[pos]; }
847
848 void addAtEnd(ParsedAttr *newAttr) {
849 assert(newAttr);
850 AttrList.push_back(newAttr);
851 }
852
853 void remove(ParsedAttr *ToBeRemoved) {
854 assert(is_contained(AttrList, ToBeRemoved) &&
855 "Cannot remove attribute that isn't in the list");
856 AttrList.erase(llvm::find(AttrList, ToBeRemoved));
857 }
858
859 void clearListOnly() { AttrList.clear(); }
860
861 struct iterator : llvm::iterator_adaptor_base<iterator, VecTy::iterator,
862 std::random_access_iterator_tag,
863 ParsedAttr> {
864 iterator() : iterator_adaptor_base(nullptr) {}
865 iterator(VecTy::iterator I) : iterator_adaptor_base(I) {}
866 reference operator*() const { return **I; }
868 };
870 : llvm::iterator_adaptor_base<const_iterator, VecTy::const_iterator,
871 std::random_access_iterator_tag,
872 ParsedAttr> {
873 const_iterator() : iterator_adaptor_base(nullptr) {}
874 const_iterator(VecTy::const_iterator I) : iterator_adaptor_base(I) {}
875
876 reference operator*() const { return **I; }
878 };
879
881 AttrList.insert(AttrList.begin(), B.I, E.I);
882 }
883
885 AttrList.insert(AttrList.begin(), B.I, E.I);
886 }
887
889 AttrList.insert(AttrList.end(), B.I, E.I);
890 }
891
893 AttrList.insert(AttrList.end(), B.I, E.I);
894 }
895
896 iterator begin() { return iterator(AttrList.begin()); }
897 const_iterator begin() const { return const_iterator(AttrList.begin()); }
898 iterator end() { return iterator(AttrList.end()); }
899 const_iterator end() const { return const_iterator(AttrList.end()); }
900
902 assert(!empty());
903 return *AttrList.front();
904 }
905 const ParsedAttr &front() const {
906 assert(!empty());
907 return *AttrList.front();
908 }
910 assert(!empty());
911 return *AttrList.back();
912 }
913 const ParsedAttr &back() const {
914 assert(!empty());
915 return *AttrList.back();
916 }
917
919 return llvm::any_of(AttrList, [K](const ParsedAttr *AL) {
920 return AL->getParsedKind() == K;
921 });
922 }
923
925 auto It = llvm::find_if(AttrList, [](const ParsedAttr *AL) {
926 return AL->isDeclspecPropertyAttribute();
927 });
928 if (It != AttrList.end())
929 return *It;
930 return nullptr;
931 }
932 bool hasMSPropertyAttr() const { return getMSPropertyAttr(); }
933
934private:
935 VecTy AttrList;
936};
937
940 : StringLiterals(StringLiteralBits) {}
941 bool isStringLiteralArg(unsigned I) const {
942 // If the last bit is set, assume we have a variadic parameter
943 if (I >= StringLiterals.size())
944 return StringLiterals.test(StringLiterals.size() - 1);
945 return StringLiterals.test(I);
946 }
947
948private:
949 std::bitset<32> StringLiterals;
950};
951
952/// ParsedAttributes - A collection of parsed attributes. Currently
953/// we don't differentiate between the various attribute syntaxes,
954/// which is basically silly.
955///
956/// Right now this is a very lightweight container, but the expectation
957/// is that this will become significantly more serious.
959public:
960 ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
964
965 AttributePool &getPool() const { return pool; }
966
968 assert(&Other != this &&
969 "ParsedAttributes can't take attributes from itself");
970 prepend(Other.begin(), Other.end());
971 Other.clearListOnly();
972 pool.takeAllFrom(Other.pool);
973 }
974
976 assert(&Other != this &&
977 "ParsedAttributes can't take attributes from itself");
978 append(Other.begin(), Other.end());
979 Other.clearListOnly();
980 pool.takeAllFrom(Other.pool);
981 }
982
984 assert(&Other != this &&
985 "ParsedAttributes can't take attribute from itself");
986 Other.getPool().remove(PA);
987 Other.remove(PA);
988 getPool().add(PA);
989 addAtEnd(PA);
990 }
991
992 void clear() {
994 pool.clear();
995 Range = SourceRange();
996 }
997
998 /// Add attribute with expression arguments.
1000 AttributeScopeInfo scope, ArgsUnion *args,
1001 unsigned numArgs, ParsedAttr::Form form,
1002 SourceLocation ellipsisLoc = SourceLocation()) {
1003 ParsedAttr *attr = pool.create(attrName, attrRange, scope, args, numArgs,
1004 form, ellipsisLoc);
1005 addAtEnd(attr);
1006 return attr;
1007 }
1008
1009 /// Add availability attribute.
1011 AttributeScopeInfo scope, IdentifierLoc *Param,
1012 const AvailabilityChange &introduced,
1013 const AvailabilityChange &deprecated,
1014 const AvailabilityChange &obsoleted,
1015 SourceLocation unavailable, const Expr *MessageExpr,
1016 ParsedAttr::Form form, SourceLocation strict,
1017 const Expr *ReplacementExpr,
1018 IdentifierLoc *EnvironmentLoc) {
1019 ParsedAttr *attr =
1020 pool.create(attrName, attrRange, scope, Param, introduced, deprecated,
1021 obsoleted, unavailable, MessageExpr, form, strict,
1022 ReplacementExpr, EnvironmentLoc);
1023 addAtEnd(attr);
1024 return attr;
1025 }
1026
1027 /// Add objc_bridge_related attribute.
1029 AttributeScopeInfo scope, IdentifierLoc *Param1,
1030 IdentifierLoc *Param2, IdentifierLoc *Param3,
1031 ParsedAttr::Form form) {
1032 ParsedAttr *attr =
1033 pool.create(attrName, attrRange, scope, Param1, Param2, Param3, form);
1034 addAtEnd(attr);
1035 return attr;
1036 }
1037
1038 /// Add type_tag_for_datatype attribute.
1040 IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope,
1041 IdentifierLoc *argumentKind, ParsedType matchingCType,
1042 bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form) {
1043 ParsedAttr *attr = pool.createTypeTagForDatatype(
1044 attrName, attrRange, scope, argumentKind, matchingCType,
1045 layoutCompatible, mustBeNull, form);
1046 addAtEnd(attr);
1047 return attr;
1048 }
1049
1050 /// Add an attribute with a single type argument.
1052 AttributeScopeInfo scope, ParsedType typeArg,
1053 ParsedAttr::Form formUsed,
1054 SourceLocation ellipsisLoc = SourceLocation()) {
1055 ParsedAttr *attr = pool.createTypeAttribute(attrName, attrRange, scope,
1056 typeArg, formUsed, ellipsisLoc);
1057 addAtEnd(attr);
1058 return attr;
1059 }
1060
1061 /// Add microsoft __delspec(property) attribute.
1062 ParsedAttr *
1064 AttributeScopeInfo scope, IdentifierInfo *getterId,
1065 IdentifierInfo *setterId, ParsedAttr::Form formUsed) {
1066 ParsedAttr *attr = pool.createPropertyAttribute(
1067 attrName, attrRange, scope, getterId, setterId, formUsed);
1068 addAtEnd(attr);
1069 return attr;
1070 }
1071
1072private:
1073 mutable AttributePool pool;
1074};
1075
1076/// Consumes the attributes from `Second` and concatenates them
1077/// at the end of `First`. Sets `First.Range`
1078/// to the combined range of `First` and `Second`.
1079void takeAndConcatenateAttrs(ParsedAttributes &First,
1080 ParsedAttributes &&Second);
1081
1082/// These constants match the enumerated choices of
1083/// err_attribute_argument_n_type and err_attribute_argument_type.
1092
1093/// These constants match the enumerated choices of
1094/// warn_attribute_wrong_decl_type and err_attribute_wrong_decl_type.
1117
1118} // namespace clang
1119
1120#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)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
Combines information about the source-code form of an attribute, including its syntax and spelling.
AttributeCommonInfo(const IdentifierInfo *AttrName, AttributeScopeInfo AttrScope, SourceRange AttrRange, Kind AttrKind, Form FormUsed)
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
Definition ParsedAttr.h:643
friend class AttributePool
Definition ParsedAttr.h:678
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Definition ParsedAttr.h:756
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierLoc *Param, const AvailabilityChange &introduced, const AvailabilityChange &deprecated, const AvailabilityChange &obsoleted, SourceLocation unavailable, const Expr *MessageExpr, ParsedAttr::Form form, SourceLocation strict, const Expr *ReplacementExpr, IdentifierLoc *EnvironmentLoc)
Definition ParsedAttr.h:769
friend class ParsedAttributes
Definition ParsedAttr.h:700
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:723
ParsedAttr * createTypeAttribute(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ParsedType typeArg, ParsedAttr::Form formUsed, SourceLocation ellipsisLoc)
Definition ParsedAttr.h:807
AttributePool & operator=(AttributePool &&pool)=delete
AttributePool(const AttributePool &)=delete
ParsedAttr * createTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form)
Definition ParsedAttr.h:797
AttributeFactory & getFactory() const
Definition ParsedAttr.h:739
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, ParsedAttr::Form form)
Definition ParsedAttr.h:785
friend class AttributeFactory
Definition ParsedAttr.h:699
void takeAllFrom(AttributePool &pool)
Take the given pool's allocations and add them to this pool.
Definition ParsedAttr.h:747
ParsedAttr * createPropertyAttribute(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Form formUsed)
Definition ParsedAttr.h:821
AttributePool & operator=(const AttributePool &)=delete
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
This represents one expression.
Definition Expr.h:114
One of these records is kept for each identifier that is lexed.
A simple pair of identifier info and location.
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.
Definition ParsedAttr.h:119
bool isPackExpansion() const
Definition ParsedAttr.h:367
friend class AttributePool
Definition ParsedAttr.h:203
const AvailabilityChange & getAvailabilityDeprecated() const
Definition ParsedAttr.h:399
ParsedAttr(ParsedAttr &&)=delete
LangAS asSYCLLangAS() const
If this is a SYCL address space attribute, returns its SYCL representation in LangAS.
Definition ParsedAttr.h:589
IdentifierLoc * getArgAsIdent(unsigned Arg) const
Definition ParsedAttr.h:389
bool hasParsedType() const
Definition ParsedAttr.h:337
const AvailabilityChange & getAvailabilityIntroduced() const
Definition ParsedAttr.h:393
void setInvalid(bool b=true) const
Definition ParsedAttr.h:345
const ParsedAttrInfo & getInfo() const
Definition ParsedAttr.h:634
bool hasMacroIdentifier() const
Returns true if this attribute was declared in a macro.
Definition ParsedAttr.h:485
ParsedAttr & operator=(ParsedAttr &&)=delete
bool diagnoseAppertainsTo(class Sema &S, QualType T) const
Definition ParsedAttr.h:524
ParsedAttr & operator=(const ParsedAttr &)=delete
const Expr * getReplacementExpr() const
Definition ParsedAttr.h:429
IdentifierInfo * getPropertyDataSetter() const
Definition ParsedAttr.h:470
bool hasProcessingCache() const
Definition ParsedAttr.h:347
SourceLocation getUnavailableLoc() const
Definition ParsedAttr.h:417
unsigned getProcessingCache() const
Definition ParsedAttr.h:349
const IdentifierLoc * getEnvironment() const
Definition ParsedAttr.h:435
LangAS asOpenCLLangAS() const
If this is an OpenCL address space attribute, returns its representation in LangAS,...
Definition ParsedAttr.h:566
const Expr * getMessageExpr() const
Definition ParsedAttr.h:423
const ParsedType & getMatchingCType() const
Definition ParsedAttr.h:441
const ParsedType & getTypeArg() const
Definition ParsedAttr.h:459
SourceLocation getStrictLoc() const
Definition ParsedAttr.h:411
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:385
Expr * getArgAsExpr(unsigned Arg) const
Definition ParsedAttr.h:383
bool getMustBeNull() const
Definition ParsedAttr.h:453
bool diagnoseMutualExclusion(class Sema &S, const Stmt *St) const
Definition ParsedAttr.h:529
bool isUsedAsTypeAttr() const
Definition ParsedAttr.h:359
bool diagnoseMutualExclusion(class Sema &S, QualType T) const
Definition ParsedAttr.h:535
bool isPragmaClangAttribute() const
True if the attribute is specified using 'pragma clang attribute'.
Definition ParsedAttr.h:363
AttributeCommonInfo::Kind getKind() const
Definition ParsedAttr.h:631
void setProcessingCache(unsigned value) const
Definition ParsedAttr.h:354
SourceLocation getMacroExpansionLoc() const
Definition ParsedAttr.h:491
ParsedAttr(const ParsedAttr &)=delete
bool isArgExpr(unsigned Arg) const
Definition ParsedAttr.h:379
bool getLayoutCompatible() const
Definition ParsedAttr.h:447
void setUsedAsTypeAttr(bool Used=true)
Definition ParsedAttr.h:360
bool isDeclspecPropertyAttribute() const
Is this the Microsoft __declspec(property) attribute?
Definition ParsedAttr.h:340
friend class AttributeFactory
Definition ParsedAttr.h:202
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:464
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:479
LangAS asHLSLLangAS() const
If this is an HLSL address space attribute, returns its representation in LangAS, otherwise returns d...
Definition ParsedAttr.h:622
~ParsedAttr()=delete
bool isInvalid() const
Definition ParsedAttr.h:344
void setIsPragmaClangAttribute()
Definition ParsedAttr.h:365
const AvailabilityChange & getAvailabilityObsoleted() const
Definition ParsedAttr.h:405
IdentifierInfo * getMacroIdentifier() const
Return the macro identifier if this attribute was declared in a macro.
Definition ParsedAttr.h:489
static const ParsedAttributesView & none()
Definition ParsedAttr.h:838
const ParsedAttr & front() const
Definition ParsedAttr.h:905
void append(const_iterator B, const_iterator E)
Definition ParsedAttr.h:892
const ParsedAttr & back() const
Definition ParsedAttr.h:913
const_iterator begin() const
Definition ParsedAttr.h:897
void prepend(iterator B, iterator E)
Definition ParsedAttr.h:880
const ParsedAttr * getMSPropertyAttr() const
Definition ParsedAttr.h:924
void prepend(const_iterator B, const_iterator E)
Definition ParsedAttr.h:884
void append(iterator B, iterator E)
Definition ParsedAttr.h:888
void addAtEnd(ParsedAttr *newAttr)
Definition ParsedAttr.h:848
bool hasAttribute(ParsedAttr::Kind K) const
Definition ParsedAttr.h:918
ParsedAttr & operator[](SizeType pos)
Definition ParsedAttr.h:845
const_iterator end() const
Definition ParsedAttr.h:899
void remove(ParsedAttr *ToBeRemoved)
Definition ParsedAttr.h:853
const ParsedAttr & operator[](SizeType pos) const
Definition ParsedAttr.h:846
void takeAllPrependingFrom(ParsedAttributes &Other)
Definition ParsedAttr.h:967
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierLoc *Param, const AvailabilityChange &introduced, const AvailabilityChange &deprecated, const AvailabilityChange &obsoleted, SourceLocation unavailable, const Expr *MessageExpr, ParsedAttr::Form form, SourceLocation strict, const Expr *ReplacementExpr, IdentifierLoc *EnvironmentLoc)
Add availability attribute.
void takeOneFrom(ParsedAttributes &Other, ParsedAttr *PA)
Definition ParsedAttr.h:983
AttributePool & getPool() const
Definition ParsedAttr.h:965
ParsedAttributes & operator=(const ParsedAttributes &)=delete
ParsedAttr * addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Form formUsed)
Add microsoft __delspec(property) attribute.
ParsedAttributes(const ParsedAttributes &)=delete
ParsedAttr * addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ParsedType typeArg, ParsedAttr::Form formUsed, SourceLocation ellipsisLoc=SourceLocation())
Add an attribute with a single type argument.
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, ParsedAttr::Form form)
Add objc_bridge_related attribute.
ParsedAttributes(AttributeFactory &factory)
Definition ParsedAttr.h:960
ParsedAttr * addNewTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form)
Add type_tag_for_datatype attribute.
void takeAllAppendingFrom(ParsedAttributes &Other)
Definition ParsedAttr.h:975
ParsedAttributes(ParsedAttributes &&G)=default
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
Definition ParsedAttr.h:999
A (possibly-)qualified type.
Definition TypeBase.h:938
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:862
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition Stmt.h:85
Exposes information about the current target.
Definition TargetInfo.h:228
SubjectMatchRule
A list of all the recognized kinds of attributes.
Top level wrappers for InstallAPI frontend operations.
AttributeDeclKind
These constants match the enumerated choices of warn_attribute_wrong_decl_type and err_attribute_wron...
@ ExpectedParameterOrImplicitObjectParameter
@ ExpectedFunctionMethodOrParameter
@ ExpectedFunctionWithProtoType
@ ExpectedFunctionMethodOrBlock
@ ExpectedClass
@ ExpectedTypeOrNamespace
@ ExpectedVariableFieldOrTag
@ ExpectedVariableOrField
@ ExpectedForLoopStatement
@ ExpectedUnion
@ ExpectedFunctionOrMethod
@ ExpectedVariable
@ ExpectedFunctionOrClassOrEnum
@ ExpectedVariableOrFunction
@ ExpectedKernelFunction
@ ExpectedFunctionVariableOrClass
@ ExpectedVirtualFunction
@ ExpectedFunction
@ ExpectedNonMemberFunction
@ ExpectedTypedef
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:103
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
llvm::SmallVector< ArgsUnion, 12U > ArgsVector
Definition ParsedAttr.h:104
AttributeArgumentNType
These constants match the enumerated choices of err_attribute_argument_n_type and err_attribute_argum...
@ AANT_ArgumentIntegerConstant
@ AANT_ArgumentBuiltinFunction
@ AANT_ArgumentIntOrBool
@ AANT_ArgumentConstantExpr
@ AANT_ArgumentIdentifier
@ AANT_ArgumentString
const FunctionProtoType * T
LangAS
Defines the address space values used by the address space qualifier of QualType.
void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &&Second)
Consumes the attributes from Second and concatenates them at the end of First.
U cast(CodeGen::Address addr)
Definition Address.h:327
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition Ownership.h:230
@ Other
Other implicit parameter.
Definition Decl.h:1787
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25
Represents information about a change in availability for an entity, which is part of the encoding of...
Definition ParsedAttr.h:47
VersionTuple Version
The version number at which the change occurred.
Definition ParsedAttr.h:52
bool isValid() const
Determine whether this availability change is valid.
Definition ParsedAttr.h:58
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
Definition ParsedAttr.h:49
SourceRange VersionRange
The source range covering the version number.
Definition ParsedAttr.h:55
ParsedAttributeArgumentsProperties(uint32_t StringLiteralBits)
Definition ParsedAttr.h:939
bool isStringLiteralArg(unsigned I) const
Definition ParsedAttr.h:941
const_iterator(VecTy::const_iterator I)
Definition ParsedAttr.h:874
Describes the trailing object for Availability attribute in ParsedAttr.
Definition ParsedAttr.h:67
AvailabilityData(const AvailabilityChange &Introduced, const AvailabilityChange &Deprecated, const AvailabilityChange &Obsoleted, SourceLocation Strict, const Expr *ReplaceExpr, const IdentifierLoc *EnvironmentLoc)
Definition ParsedAttr.h:73
const IdentifierLoc * EnvironmentLoc
Definition ParsedAttr.h:71
AvailabilityChange Changes[NumAvailabilitySlots]
Definition ParsedAttr.h:68
IdentifierInfo * SetterId
Definition ParsedAttr.h:93
PropertyData(IdentifierInfo *getterId, IdentifierInfo *setterId)
Definition ParsedAttr.h:95
IdentifierInfo * GetterId
Definition ParsedAttr.h:93