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 bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const;
522 // This function stub exists for parity with the declaration checking code so
523 // that checkCommonAttributeFeatures() can work generically on declarations
524 // or statements.
525 bool diagnoseMutualExclusion(class Sema &S, const Stmt *St) const {
526 return true;
527 }
528 bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const;
529 void getMatchRules(const LangOptions &LangOpts,
530 SmallVectorImpl<std::pair<attr::SubjectMatchRule, bool>>
531 &MatchRules) const;
532 bool diagnoseLangOpts(class Sema &S) const;
533 bool existsInTarget(const TargetInfo &Target) const;
534 bool isKnownToGCC() const;
535 bool isSupportedByPragmaAttribute() const;
536
537 /// Returns whether a [[]] attribute, if specified ahead of a declaration,
538 /// should be applied to the decl-specifier-seq instead (i.e. whether it
539 /// "slides" to the decl-specifier-seq).
540 ///
541 /// By the standard, attributes specified before the declaration always
542 /// appertain to the declaration, but historically we have allowed some of
543 /// these attributes to slide to the decl-specifier-seq, so we need to keep
544 /// supporting this behavior.
545 ///
546 /// This may only be called if isStandardAttributeSyntax() returns true.
547 bool slidesFromDeclToDeclSpecLegacyBehavior() const;
548
549 /// If the parsed attribute has a semantic equivalent, and it would
550 /// have a semantic Spelling enumeration (due to having semantically-distinct
551 /// spelling variations), return the value of that semantic spelling. If the
552 /// parsed attribute does not have a semantic equivalent, or would not have
553 /// a Spelling enumeration, the value UINT_MAX is returned.
554 unsigned getSemanticSpelling() const;
555
556 /// If this is an OpenCL address space attribute, returns its representation
557 /// in LangAS, otherwise returns default address space.
559 switch (getParsedKind()) {
560 case ParsedAttr::AT_OpenCLConstantAddressSpace:
562 case ParsedAttr::AT_OpenCLGlobalAddressSpace:
564 case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
566 case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
568 case ParsedAttr::AT_OpenCLLocalAddressSpace:
570 case ParsedAttr::AT_OpenCLPrivateAddressSpace:
572 case ParsedAttr::AT_OpenCLGenericAddressSpace:
574 default:
575 return LangAS::Default;
576 }
577 }
578
579 /// If this is a SYCL address space attribute, returns its SYCL
580 /// representation in LangAS.
582 switch (getParsedKind()) {
583 case ParsedAttr::AT_SYCLGlobalAddressSpace:
584 return LangAS::sycl_global;
585 case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
587 case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
589 case ParsedAttr::AT_SYCLLocalAddressSpace:
590 return LangAS::sycl_local;
591 case ParsedAttr::AT_SYCLPrivateAddressSpace:
593 case ParsedAttr::AT_SYCLGenericAddressSpace:
595 case ParsedAttr::AT_SYCLConstantAddressSpace:
597 // The OpenCL address space attributes are available to enable
598 // implicit conversions between OpenCL address space attributes and
599 // SYCL address space attributes when targeting the OpenCL execution
600 // environments.
601 case ParsedAttr::AT_OpenCLGlobalAddressSpace:
602 case ParsedAttr::AT_OpenCLLocalAddressSpace:
603 case ParsedAttr::AT_OpenCLPrivateAddressSpace:
604 case ParsedAttr::AT_OpenCLGenericAddressSpace:
605 case ParsedAttr::AT_OpenCLConstantAddressSpace:
606 return asOpenCLLangAS();
607 default:
608 return LangAS::Default;
609 }
610 }
611
612 /// If this is an HLSL address space attribute, returns its representation
613 /// in LangAS, otherwise returns default address space.
615 switch (getParsedKind()) {
616 case ParsedAttr::AT_HLSLGroupSharedAddressSpace:
618 default:
619 return LangAS::Default;
620 }
621 }
622
624 return AttributeCommonInfo::Kind(Info.AttrKind);
625 }
626 const ParsedAttrInfo &getInfo() const { return Info; }
627};
628
629class AttributePool;
630/// A factory, from which one makes pools, from which one creates
631/// individual attributes which are deallocated with the pool.
632///
633/// Note that it's tolerably cheap to create and destroy one of
634/// these as long as you don't actually allocate anything in it.
636public:
637 enum {
639 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
641 detail::PropertyData>(1, 1, 0, 0, 0),
643 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
645 detail::PropertyData>(1, 0, 1, 0, 0),
647 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
649 detail::PropertyData>(0, 0, 0, 0, 1),
650 };
651
652private:
653 enum {
654 /// The number of free lists we want to be sure to support
655 /// inline. This is just enough that availability attributes
656 /// don't surpass it. It's actually very unlikely we'll see an
657 /// attribute that needs more than that; on x86-64 you'd need 10
658 /// expression arguments, and on i386 you'd need 19.
659 InlineFreeListsCapacity =
660 1 + (AvailabilityAllocSize - sizeof(ParsedAttr)) / sizeof(void *)
661 };
662
663 llvm::BumpPtrAllocator Alloc;
664
665 /// Free lists. The index is determined by the following formula:
666 /// (size - sizeof(ParsedAttr)) / sizeof(void*)
667 SmallVector<SmallVector<ParsedAttr *, 8>, InlineFreeListsCapacity> FreeLists;
668
669 // The following are the private interface used by AttributePool.
670 friend class AttributePool;
671
672 /// Allocate an attribute of the given size.
673 void *allocate(size_t size);
674
675 void deallocate(ParsedAttr *AL);
676
677 /// Reclaim all the attributes in the given pool chain, which is
678 /// non-empty. Note that the current implementation is safe
679 /// against reclaiming things which were not actually allocated
680 /// with the allocator, although of course it's important to make
681 /// sure that their allocator lives at least as long as this one.
682 void reclaimPool(AttributePool &head);
683
684public:
687};
688
691 friend class AttributeFactory;
692 friend class ParsedAttributes;
693 AttributeFactory &Factory;
695
696 void *allocate(size_t size) {
697 return Factory.allocate(size);
698 }
699
700 ParsedAttr *add(ParsedAttr *attr) {
701 Attrs.push_back(attr);
702 return attr;
703 }
704
705 void remove(ParsedAttr *attr) {
706 assert(llvm::is_contained(Attrs, attr) &&
707 "Can't take attribute from a pool that doesn't own it!");
708 Attrs.erase(llvm::find(Attrs, attr));
709 }
710
711 void takePool(AttributePool &pool);
712
713public:
714 /// Create a new pool for a factory.
715 AttributePool(AttributeFactory &factory) : Factory(factory) {}
716
717 AttributePool(const AttributePool &) = delete;
718 // The copy assignment operator is defined as deleted pending further
719 // motivation.
721
722 ~AttributePool() { Factory.reclaimPool(*this); }
723
724 /// Move the given pool's allocations to this pool.
725 AttributePool(AttributePool &&pool) = default;
726
727 // The move assignment operator is defined as deleted pending further
728 // motivation.
730
731 AttributeFactory &getFactory() const { return Factory; }
732
733 void clear() {
734 Factory.reclaimPool(*this);
735 Attrs.clear();
736 }
737
738 /// Take the given pool's allocations and add them to this pool.
740 takePool(pool);
741 pool.Attrs.clear();
742 }
743
744 /// Removes the attributes from \c List, which are owned by \c Pool, and adds
745 /// them at the end of this \c AttributePool.
746 void takeFrom(ParsedAttributesView &List, AttributePool &Pool);
747
749 AttributeScopeInfo scope, ArgsUnion *args,
750 unsigned numArgs, ParsedAttr::Form form,
751 SourceLocation ellipsisLoc = SourceLocation()) {
752 void *memory = allocate(
753 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
755 detail::PropertyData>(numArgs, 0, 0, 0,
756 0));
757 return add(new (memory) ParsedAttr(attrName, attrRange, scope, args,
758 numArgs, form, ellipsisLoc));
759 }
760
762 AttributeScopeInfo scope, IdentifierLoc *Param,
763 const AvailabilityChange &introduced,
764 const AvailabilityChange &deprecated,
765 const AvailabilityChange &obsoleted,
766 SourceLocation unavailable, const Expr *MessageExpr,
767 ParsedAttr::Form form, SourceLocation strict,
768 const Expr *ReplacementExpr,
769 IdentifierLoc *EnvironmentLoc) {
770 void *memory = allocate(AttributeFactory::AvailabilityAllocSize);
771 return add(new (memory)
772 ParsedAttr(attrName, attrRange, scope, Param, introduced,
773 deprecated, obsoleted, unavailable, MessageExpr,
774 form, strict, ReplacementExpr, EnvironmentLoc));
775 }
776
778 AttributeScopeInfo scope, IdentifierLoc *Param1,
779 IdentifierLoc *Param2, IdentifierLoc *Param3,
780 ParsedAttr::Form form) {
781 void *memory = allocate(
782 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
784 detail::PropertyData>(3, 0, 0, 0, 0));
785 return add(new (memory) ParsedAttr(attrName, attrRange, scope, Param1,
786 Param2, Param3, form));
787 }
788
790 IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope,
791 IdentifierLoc *argumentKind, ParsedType matchingCType,
792 bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form) {
793 void *memory = allocate(AttributeFactory::TypeTagForDatatypeAllocSize);
794 return add(new (memory) ParsedAttr(attrName, attrRange, scope, argumentKind,
795 matchingCType, layoutCompatible,
796 mustBeNull, form));
797 }
798
800 SourceRange attrRange,
801 AttributeScopeInfo scope, ParsedType typeArg,
802 ParsedAttr::Form formUsed,
803 SourceLocation ellipsisLoc) {
804 void *memory = allocate(
805 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
807 detail::PropertyData>(0, 0, 0, 1, 0));
808 return add(new (memory) ParsedAttr(attrName, attrRange, scope, typeArg,
809 formUsed, ellipsisLoc));
810 }
811
812 ParsedAttr *
814 AttributeScopeInfo scope, IdentifierInfo *getterId,
815 IdentifierInfo *setterId, ParsedAttr::Form formUsed) {
816 void *memory = allocate(AttributeFactory::PropertyAllocSize);
817 return add(new (memory) ParsedAttr(attrName, attrRange, scope, getterId,
818 setterId, formUsed));
819 }
820};
821
823 friend class AttributePool;
825 using SizeType = decltype(std::declval<VecTy>().size());
826
827public:
829
830 static const ParsedAttributesView &none() {
831 static const ParsedAttributesView Attrs;
832 return Attrs;
833 }
834
835 bool empty() const { return AttrList.empty(); }
836 SizeType size() const { return AttrList.size(); }
837 ParsedAttr &operator[](SizeType pos) { return *AttrList[pos]; }
838 const ParsedAttr &operator[](SizeType pos) const { return *AttrList[pos]; }
839
840 void addAtEnd(ParsedAttr *newAttr) {
841 assert(newAttr);
842 AttrList.push_back(newAttr);
843 }
844
845 void remove(ParsedAttr *ToBeRemoved) {
846 assert(is_contained(AttrList, ToBeRemoved) &&
847 "Cannot remove attribute that isn't in the list");
848 AttrList.erase(llvm::find(AttrList, ToBeRemoved));
849 }
850
851 void clearListOnly() { AttrList.clear(); }
852
853 struct iterator : llvm::iterator_adaptor_base<iterator, VecTy::iterator,
854 std::random_access_iterator_tag,
855 ParsedAttr> {
856 iterator() : iterator_adaptor_base(nullptr) {}
857 iterator(VecTy::iterator I) : iterator_adaptor_base(I) {}
858 reference operator*() const { return **I; }
860 };
862 : llvm::iterator_adaptor_base<const_iterator, VecTy::const_iterator,
863 std::random_access_iterator_tag,
864 ParsedAttr> {
865 const_iterator() : iterator_adaptor_base(nullptr) {}
866 const_iterator(VecTy::const_iterator I) : iterator_adaptor_base(I) {}
867
868 reference operator*() const { return **I; }
870 };
871
873 AttrList.insert(AttrList.begin(), B.I, E.I);
874 }
875
877 AttrList.insert(AttrList.begin(), B.I, E.I);
878 }
879
881 AttrList.insert(AttrList.end(), B.I, E.I);
882 }
883
885 AttrList.insert(AttrList.end(), B.I, E.I);
886 }
887
888 iterator begin() { return iterator(AttrList.begin()); }
889 const_iterator begin() const { return const_iterator(AttrList.begin()); }
890 iterator end() { return iterator(AttrList.end()); }
891 const_iterator end() const { return const_iterator(AttrList.end()); }
892
894 assert(!empty());
895 return *AttrList.front();
896 }
897 const ParsedAttr &front() const {
898 assert(!empty());
899 return *AttrList.front();
900 }
902 assert(!empty());
903 return *AttrList.back();
904 }
905 const ParsedAttr &back() const {
906 assert(!empty());
907 return *AttrList.back();
908 }
909
911 return llvm::any_of(AttrList, [K](const ParsedAttr *AL) {
912 return AL->getParsedKind() == K;
913 });
914 }
915
917 auto It = llvm::find_if(AttrList, [](const ParsedAttr *AL) {
918 return AL->isDeclspecPropertyAttribute();
919 });
920 if (It != AttrList.end())
921 return *It;
922 return nullptr;
923 }
924 bool hasMSPropertyAttr() const { return getMSPropertyAttr(); }
925
926private:
927 VecTy AttrList;
928};
929
932 : StringLiterals(StringLiteralBits) {}
933 bool isStringLiteralArg(unsigned I) const {
934 // If the last bit is set, assume we have a variadic parameter
935 if (I >= StringLiterals.size())
936 return StringLiterals.test(StringLiterals.size() - 1);
937 return StringLiterals.test(I);
938 }
939
940private:
941 std::bitset<32> StringLiterals;
942};
943
944/// ParsedAttributes - A collection of parsed attributes. Currently
945/// we don't differentiate between the various attribute syntaxes,
946/// which is basically silly.
947///
948/// Right now this is a very lightweight container, but the expectation
949/// is that this will become significantly more serious.
951public:
952 ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
956
957 AttributePool &getPool() const { return pool; }
958
960 assert(&Other != this &&
961 "ParsedAttributes can't take attributes from itself");
962 prepend(Other.begin(), Other.end());
963 Other.clearListOnly();
964 pool.takeAllFrom(Other.pool);
965 }
966
968 assert(&Other != this &&
969 "ParsedAttributes can't take attributes from itself");
970 append(Other.begin(), Other.end());
971 Other.clearListOnly();
972 pool.takeAllFrom(Other.pool);
973 }
974
976 assert(&Other != this &&
977 "ParsedAttributes can't take attribute from itself");
978 Other.getPool().remove(PA);
979 Other.remove(PA);
980 getPool().add(PA);
981 addAtEnd(PA);
982 }
983
984 void clear() {
986 pool.clear();
987 Range = SourceRange();
988 }
989
990 /// Add attribute with expression arguments.
992 AttributeScopeInfo scope, ArgsUnion *args,
993 unsigned numArgs, ParsedAttr::Form form,
994 SourceLocation ellipsisLoc = SourceLocation()) {
995 ParsedAttr *attr = pool.create(attrName, attrRange, scope, args, numArgs,
996 form, ellipsisLoc);
997 addAtEnd(attr);
998 return attr;
999 }
1000
1001 /// Add availability attribute.
1003 AttributeScopeInfo scope, IdentifierLoc *Param,
1004 const AvailabilityChange &introduced,
1005 const AvailabilityChange &deprecated,
1006 const AvailabilityChange &obsoleted,
1007 SourceLocation unavailable, const Expr *MessageExpr,
1008 ParsedAttr::Form form, SourceLocation strict,
1009 const Expr *ReplacementExpr,
1010 IdentifierLoc *EnvironmentLoc) {
1011 ParsedAttr *attr =
1012 pool.create(attrName, attrRange, scope, Param, introduced, deprecated,
1013 obsoleted, unavailable, MessageExpr, form, strict,
1014 ReplacementExpr, EnvironmentLoc);
1015 addAtEnd(attr);
1016 return attr;
1017 }
1018
1019 /// Add objc_bridge_related attribute.
1021 AttributeScopeInfo scope, IdentifierLoc *Param1,
1022 IdentifierLoc *Param2, IdentifierLoc *Param3,
1023 ParsedAttr::Form form) {
1024 ParsedAttr *attr =
1025 pool.create(attrName, attrRange, scope, Param1, Param2, Param3, form);
1026 addAtEnd(attr);
1027 return attr;
1028 }
1029
1030 /// Add type_tag_for_datatype attribute.
1032 IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope,
1033 IdentifierLoc *argumentKind, ParsedType matchingCType,
1034 bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form) {
1035 ParsedAttr *attr = pool.createTypeTagForDatatype(
1036 attrName, attrRange, scope, argumentKind, matchingCType,
1037 layoutCompatible, mustBeNull, form);
1038 addAtEnd(attr);
1039 return attr;
1040 }
1041
1042 /// Add an attribute with a single type argument.
1044 AttributeScopeInfo scope, ParsedType typeArg,
1045 ParsedAttr::Form formUsed,
1046 SourceLocation ellipsisLoc = SourceLocation()) {
1047 ParsedAttr *attr = pool.createTypeAttribute(attrName, attrRange, scope,
1048 typeArg, formUsed, ellipsisLoc);
1049 addAtEnd(attr);
1050 return attr;
1051 }
1052
1053 /// Add microsoft __delspec(property) attribute.
1054 ParsedAttr *
1056 AttributeScopeInfo scope, IdentifierInfo *getterId,
1057 IdentifierInfo *setterId, ParsedAttr::Form formUsed) {
1058 ParsedAttr *attr = pool.createPropertyAttribute(
1059 attrName, attrRange, scope, getterId, setterId, formUsed);
1060 addAtEnd(attr);
1061 return attr;
1062 }
1063
1064private:
1065 mutable AttributePool pool;
1066};
1067
1068/// Consumes the attributes from `Second` and concatenates them
1069/// at the end of `First`. Sets `First.Range`
1070/// to the combined range of `First` and `Second`.
1071void takeAndConcatenateAttrs(ParsedAttributes &First,
1072 ParsedAttributes &&Second);
1073
1074/// These constants match the enumerated choices of
1075/// err_attribute_argument_n_type and err_attribute_argument_type.
1084
1085/// These constants match the enumerated choices of
1086/// warn_attribute_wrong_decl_type and err_attribute_wrong_decl_type.
1109
1110} // namespace clang
1111
1112#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:239
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:635
friend class AttributePool
Definition ParsedAttr.h:670
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Definition ParsedAttr.h:748
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:761
friend class ParsedAttributes
Definition ParsedAttr.h:692
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:715
ParsedAttr * createTypeAttribute(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ParsedType typeArg, ParsedAttr::Form formUsed, SourceLocation ellipsisLoc)
Definition ParsedAttr.h:799
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:789
AttributeFactory & getFactory() const
Definition ParsedAttr.h:731
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, ParsedAttr::Form form)
Definition ParsedAttr.h:777
friend class AttributeFactory
Definition ParsedAttr.h:691
void takeAllFrom(AttributePool &pool)
Take the given pool's allocations and add them to this pool.
Definition ParsedAttr.h:739
ParsedAttr * createPropertyAttribute(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Form formUsed)
Definition ParsedAttr.h:813
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:113
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:581
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:626
bool hasMacroIdentifier() const
Returns true if this attribute was declared in a macro.
Definition ParsedAttr.h:485
ParsedAttr & operator=(ParsedAttr &&)=delete
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:558
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:525
bool isUsedAsTypeAttr() const
Definition ParsedAttr.h:359
bool isPragmaClangAttribute() const
True if the attribute is specified using 'pragma clang attribute'.
Definition ParsedAttr.h:363
AttributeCommonInfo::Kind getKind() const
Definition ParsedAttr.h:623
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:614
~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:830
const ParsedAttr & front() const
Definition ParsedAttr.h:897
void append(const_iterator B, const_iterator E)
Definition ParsedAttr.h:884
const ParsedAttr & back() const
Definition ParsedAttr.h:905
const_iterator begin() const
Definition ParsedAttr.h:889
void prepend(iterator B, iterator E)
Definition ParsedAttr.h:872
const ParsedAttr * getMSPropertyAttr() const
Definition ParsedAttr.h:916
void prepend(const_iterator B, const_iterator E)
Definition ParsedAttr.h:876
void append(iterator B, iterator E)
Definition ParsedAttr.h:880
void addAtEnd(ParsedAttr *newAttr)
Definition ParsedAttr.h:840
bool hasAttribute(ParsedAttr::Kind K) const
Definition ParsedAttr.h:910
ParsedAttr & operator[](SizeType pos)
Definition ParsedAttr.h:837
const_iterator end() const
Definition ParsedAttr.h:891
void remove(ParsedAttr *ToBeRemoved)
Definition ParsedAttr.h:845
const ParsedAttr & operator[](SizeType pos) const
Definition ParsedAttr.h:838
void takeAllPrependingFrom(ParsedAttributes &Other)
Definition ParsedAttr.h:959
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:975
AttributePool & getPool() const
Definition ParsedAttr.h:957
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:952
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:967
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:991
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:863
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:226
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
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:1775
int32_t uint32_t
#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:931
bool isStringLiteralArg(unsigned I) const
Definition ParsedAttr.h:933
const_iterator(VecTy::const_iterator I)
Definition ParsedAttr.h:866
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