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