14 #ifndef LLVM_CLANG_SEMA_ATTRIBUTELIST_H 15 #define LLVM_CLANG_SEMA_ATTRIBUTELIST_H 23 #include "llvm/ADT/PointerUnion.h" 24 #include "llvm/ADT/SmallVector.h" 25 #include "llvm/ADT/TinyPtrVector.h" 26 #include "llvm/Support/Allocator.h" 27 #include "llvm/Support/VersionTuple.h" 55 bool isValid()
const {
return !Version.empty(); }
73 : StrictLoc(Strict), Replacement(ReplaceExpr) {
89 : GetterId(getterId), SetterId(setterId) {}
105 using ArgsUnion = llvm::PointerUnion<Expr *, IdentifierLoc *>;
120 ParsedAttr, ArgsUnion, detail::AvailabilityData,
121 detail::TypeTagForDatatypeData, ParsedType, detail::PropertyData> {
124 size_t numTrailingObjects(OverloadToken<ArgsUnion>)
const {
return NumArgs; }
125 size_t numTrailingObjects(OverloadToken<detail::AvailabilityData>)
const {
126 return IsAvailability;
129 numTrailingObjects(OverloadToken<detail::TypeTagForDatatypeData>)
const {
130 return IsTypeTagForDatatype;
132 size_t numTrailingObjects(OverloadToken<ParsedType>)
const {
133 return HasParsedType;
135 size_t numTrailingObjects(OverloadToken<detail::PropertyData>)
const {
146 unsigned NumArgs : 16;
149 mutable unsigned Invalid : 1;
152 mutable unsigned UsedAsTypeAttr : 1;
156 unsigned IsAvailability : 1;
160 unsigned IsTypeTagForDatatype : 1;
164 unsigned IsProperty : 1;
167 unsigned HasParsedType : 1;
170 mutable unsigned HasProcessingCache : 1;
173 mutable unsigned ProcessingCache : 8;
176 mutable unsigned IsPragmaClangAttribute : 1;
182 const Expr *MessageExpr;
184 ArgsUnion *getArgsBuffer() {
return getTrailingObjects<ArgsUnion>(); }
186 return getTrailingObjects<ArgsUnion>();
190 return getTrailingObjects<detail::AvailabilityData>();
193 return getTrailingObjects<detail::AvailabilityData>();
207 EllipsisLoc(ellipsisLoc), NumArgs(numArgs), Invalid(
false),
210 HasProcessingCache(
false), IsPragmaClangAttribute(
false) {
222 const Expr *replacementExpr)
225 NumArgs(1), Invalid(
false), UsedAsTypeAttr(
false), IsAvailability(
true),
227 HasProcessingCache(
false), IsPragmaClangAttribute(
false),
228 UnavailableLoc(unavailable), MessageExpr(messageExpr) {
232 introduced, deprecated, obsoleted, strict, replacementExpr);
242 NumArgs(3), Invalid(
false), UsedAsTypeAttr(
false),
244 HasParsedType(
false), HasProcessingCache(
false),
245 IsPragmaClangAttribute(
false) {
256 bool layoutCompatible,
bool mustBeNull,
Syntax syntaxUsed)
259 NumArgs(1), Invalid(
false), UsedAsTypeAttr(
false),
260 IsAvailability(
false), IsTypeTagForDatatype(
true), IsProperty(
false),
261 HasParsedType(
false), HasProcessingCache(
false),
262 IsPragmaClangAttribute(
false) {
277 NumArgs(0), Invalid(
false), UsedAsTypeAttr(
false),
279 HasParsedType(
true), HasProcessingCache(
false),
280 IsPragmaClangAttribute(
false) {
291 NumArgs(0), Invalid(
false), UsedAsTypeAttr(
false),
292 IsAvailability(
false), IsTypeTagForDatatype(
false), IsProperty(
true),
293 HasParsedType(
false), HasProcessingCache(
false),
294 IsPragmaClangAttribute(
false) {
302 return *getTrailingObjects<detail::TypeTagForDatatypeData>();
305 return *getTrailingObjects<detail::TypeTagForDatatypeData>();
310 ParsedType &getTypeBuffer() {
return *getTrailingObjects<ParsedType>(); }
312 return *getTrailingObjects<ParsedType>();
319 return *getTrailingObjects<detail::PropertyData>();
323 return *getTrailingObjects<detail::PropertyData>();
326 size_t allocated_size()
const;
335 void operator delete(
void *) =
delete;
350 assert(hasProcessingCache());
351 return ProcessingCache;
355 ProcessingCache = value;
356 HasProcessingCache =
true;
375 assert(Arg < NumArgs &&
"Arg access out of range!");
376 return getArgsBuffer()[Arg];
380 return Arg < NumArgs && getArg(Arg).is<
Expr*>();
384 return getArg(Arg).get<
Expr*>();
396 assert(getParsedKind() == AT_Availability &&
397 "Not an availability attribute");
402 assert(getParsedKind() == AT_Availability &&
403 "Not an availability attribute");
408 assert(getParsedKind() == AT_Availability &&
409 "Not an availability attribute");
414 assert(getParsedKind() == AT_Availability &&
415 "Not an availability attribute");
416 return getAvailabilityData()->StrictLoc;
420 assert(getParsedKind() == AT_Availability &&
421 "Not an availability attribute");
422 return UnavailableLoc;
426 assert(getParsedKind() == AT_Availability &&
427 "Not an availability attribute");
432 assert(getParsedKind() == AT_Availability &&
433 "Not an availability attribute");
434 return getAvailabilityData()->Replacement;
438 assert(getParsedKind() == AT_TypeTagForDatatype &&
439 "Not a type_tag_for_datatype attribute");
440 return getTypeTagForDatatypeDataSlot().MatchingCType;
444 assert(getParsedKind() == AT_TypeTagForDatatype &&
445 "Not a type_tag_for_datatype attribute");
446 return getTypeTagForDatatypeDataSlot().LayoutCompatible;
450 assert(getParsedKind() == AT_TypeTagForDatatype &&
451 "Not a type_tag_for_datatype attribute");
452 return getTypeTagForDatatypeDataSlot().MustBeNull;
456 assert(HasParsedType &&
"Not a type attribute");
457 return getTypeBuffer();
461 assert(isDeclspecPropertyAttribute() &&
462 "Not a __delcspec(property) attribute");
463 return getPropertyDataBuffer().GetterId;
467 assert(isDeclspecPropertyAttribute() &&
468 "Not a __delcspec(property) attribute");
469 return getPropertyDataBuffer().SetterId;
477 MacroExpansionLoc = Loc;
488 assert(hasMacroIdentifier() &&
"Can only get the macro expansion location " 489 "if this attribute has a macro identifier.");
490 return MacroExpansionLoc;
493 bool isTargetSpecificAttr()
const;
494 bool isTypeAttr()
const;
495 bool isStmtAttr()
const;
497 bool hasCustomParsing()
const;
498 unsigned getMinArgs()
const;
499 unsigned getMaxArgs()
const;
500 bool hasVariadicArg()
const;
501 bool diagnoseAppertainsTo(
class Sema &S,
const Decl *D)
const;
506 bool diagnoseLangOpts(
class Sema &S)
const;
508 bool isKnownToGCC()
const;
509 bool isSupportedByPragmaAttribute()
const;
516 unsigned getSemanticSpelling()
const;
521 switch (getParsedKind()) {
522 case ParsedAttr::AT_OpenCLConstantAddressSpace:
524 case ParsedAttr::AT_OpenCLGlobalAddressSpace:
526 case ParsedAttr::AT_OpenCLLocalAddressSpace:
528 case ParsedAttr::AT_OpenCLPrivateAddressSpace:
530 case ParsedAttr::AT_OpenCLGenericAddressSpace:
549 AvailabilityAllocSize =
553 TypeTagForDatatypeAllocSize =
554 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
555 detail::TypeTagForDatatypeData, ParsedType,
556 detail::PropertyData>(1, 0, 1, 0, 0),
558 ParsedAttr::totalSizeToAlloc<
ArgsUnion, detail::AvailabilityData,
560 detail::PropertyData>(0, 0, 0, 0, 1),
570 InlineFreeListsCapacity =
571 1 + (AvailabilityAllocSize -
sizeof(
ParsedAttr)) /
sizeof(
void *)
574 llvm::BumpPtrAllocator Alloc;
584 void *allocate(
size_t size);
604 llvm::TinyPtrVector<ParsedAttr *> Attrs;
606 void *allocate(
size_t size) {
607 return Factory.allocate(size);
611 Attrs.push_back(attr);
616 assert(llvm::is_contained(Attrs, attr) &&
617 "Can't take attribute from a pool that doesn't own it!");
618 Attrs.erase(llvm::find(Attrs, attr));
637 Factory.reclaimPool(*
this);
657 void *memory = allocate(
658 ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
659 detail::TypeTagForDatatypeData, ParsedType,
662 return add(
new (memory)
ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
663 args, numArgs, syntax, ellipsisLoc));
673 const Expr *ReplacementExpr) {
676 attrName, attrRange, scopeName, scopeLoc, Param, introduced, deprecated,
677 obsoleted, unavailable, MessageExpr, syntax, strict, ReplacementExpr));
684 void *memory = allocate(
688 return add(
new (memory)
ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
689 Param1, Param2, Param3, syntax));
696 ParsedType matchingCType,
bool layoutCompatible,
699 return add(
new (memory)
ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
700 argumentKind, matchingCType,
701 layoutCompatible, mustBeNull, syntax));
709 void *memory = allocate(
713 return add(
new (memory)
ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
714 typeArg, syntaxUsed));
723 return add(
new (memory)
ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
724 getterId, setterId, syntaxUsed));
729 using VecTy = llvm::TinyPtrVector<ParsedAttr *>;
730 using SizeType = decltype(std::declval<VecTy>().size());
733 bool empty()
const {
return AttrList.empty(); }
734 SizeType
size()
const {
return AttrList.size(); }
740 AttrList.push_back(newAttr);
744 assert(is_contained(AttrList, ToBeRemoved) &&
745 "Cannot remove attribute that isn't in the list");
746 AttrList.erase(llvm::find(AttrList, ToBeRemoved));
751 struct iterator : llvm::iterator_adaptor_base<iterator, VecTy::iterator,
752 std::random_access_iterator_tag,
755 iterator(VecTy::iterator I) : iterator_adaptor_base(I) {}
760 : llvm::iterator_adaptor_base<const_iterator, VecTy::const_iterator,
761 std::random_access_iterator_tag,
771 AttrList.insert(AttrList.begin(), B.I, E.I);
775 AttrList.insert(AttrList.begin(), B.I, E.I);
779 AttrList.insert(AttrList.end(), B.I, E.I);
783 AttrList.insert(AttrList.end(), B.I, E.I);
793 return *AttrList.front();
797 return *AttrList.front();
801 return *AttrList.back();
805 return *AttrList.back();
809 return llvm::any_of(AttrList, [K](
const ParsedAttr *AL) {
834 pool.takeAllFrom(attrs.pool);
855 ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc,
856 args, numArgs, syntax, ellipsisLoc);
869 const Expr *ReplacementExpr) {
871 attrName, attrRange, scopeName, scopeLoc, Param, introduced, deprecated,
872 obsoleted, unavailable, MessageExpr, syntax, strict, ReplacementExpr);
882 ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc,
883 Param1, Param2, Param3, syntax);
893 ParsedType matchingCType,
bool layoutCompatible,
895 ParsedAttr *attr = pool.createTypeTagForDatatype(
896 attrName, attrRange, scopeName, scopeLoc, argumentKind, matchingCType,
897 layoutCompatible, mustBeNull, syntax);
907 ParsedAttr *attr = pool.createTypeAttribute(attrName, attrRange, scopeName,
908 scopeLoc, typeArg, syntaxUsed);
920 pool.createPropertyAttribute(attrName, attrRange, scopeName, scopeLoc,
921 getterId, setterId, syntaxUsed);
987 #endif // LLVM_CLANG_SEMA_ATTRIBUTELIST_H ParsedAttr * createTypeAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, ParsedAttr::Syntax syntaxUsed)
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, ParsedAttr::Syntax syntax)
const_iterator end() const
const_iterator(VecTy::const_iterator I)
ParsedAttributes(AttributeFactory &factory)
void takeOneFrom(ParsedAttributes &Attrs, ParsedAttr *PA)
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
iterator(VecTy::iterator I)
Decl - This represents one declaration (or definition), e.g.
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
Syntax
The style used to specify an attribute.
Expr * getArgAsExpr(unsigned Arg) const
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
bool getMustBeNull() const
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool hasParsedType() const
IdentifierInfo * getPropertyDataGetter() const
const_iterator begin() const
reference operator*() const
bool hasAttribute(ParsedAttr::Kind K) const
IdentifierInfo * getPropertyDataSetter() const
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
ParsedAttr & operator[](SizeType pos)
const ParsedType & getMatchingCType() const
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
One of these records is kept for each identifier that is lexed.
SubjectMatchRule
A list of all the recognized kinds of attributes.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ParsedAttr & front() const
unsigned LayoutCompatible
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
AttributeCommonInfo::Kind getKind() const
void setIsPragmaClangAttribute()
AttributeArgumentNType
These constants match the enumerated choices of err_attribute_argument_n_type and err_attribute_argum...
void takeAllFrom(ParsedAttributes &attrs)
Defines the Diagnostic-related interfaces.
void setUsedAsTypeAttr(bool Used=true)
Represents information about a change in availability for an entity, which is part of the encoding of...
IdentifierInfo * getMacroIdentifier() const
Return the macro identifier if this attribute was declared in a macro.
void addAtEnd(ParsedAttr *newAttr)
const IdentifierInfo * getAttrName() const
VersionTuple Version
The version number at which the change occurred.
void setInvalid(bool b=true) const
bool isDeclspecPropertyAttribute() const
Is this the Microsoft __declspec(property) attribute?
Sema - This implements semantic analysis and AST building for C.
A little helper class used to produce diagnostics.
AvailabilityData(const AvailabilityChange &Introduced, const AvailabilityChange &Deprecated, const AvailabilityChange &Obsoleted, SourceLocation Strict, const Expr *ReplaceExpr)
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.
void addAllAtEnd(const_iterator B, const_iterator E)
Exposes information about the current target.
void setMacroIdentifier(IdentifierInfo *MacroName, SourceLocation Loc)
Set the macro identifier info object that this parsed attribute was declared in if it was declared in...
This represents one expression.
ParsedAttr * addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Syntax syntaxUsed)
Add microsoft __delspec(property) attribute.
const AvailabilityChange & getAvailabilityObsoleted() const
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.
AttributeFactory & getFactory() const
void addAllAtEnd(iterator B, iterator E)
void addAll(iterator B, iterator E)
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
bool isValid() const
Determine whether this availability change is valid.
Wraps an identifier and optional source location for the identifier.
SourceRange VersionRange
The source range covering the version number.
bool getLayoutCompatible() const
SourceLocation getEllipsisLoc() const
ParsedAttr * createPropertyAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Syntax syntaxUsed)
Encodes a location in the source.
const ParsedType & getTypeArg() const
void addAll(const_iterator B, const_iterator E)
SourceLocation getMacroExpansionLoc() const
bool hasMacroIdentifier() const
Returns true if this attribute was declared in a macro.
ParsedAttr - Represents a syntactic attribute.
const ParsedAttr & back() const
const ParsedAttr & operator[](SizeType pos) const
bool hasProcessingCache() const
bool isUsedAsTypeAttr() const
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.
void remove(ParsedAttr *ToBeRemoved)
bool isArgExpr(unsigned Arg) const
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Describes the trailing object for Availability attribute in ParsedAttr.
void setProcessingCache(unsigned value) const
ArgsUnion getArg(unsigned Arg) const
getArg - Return the specified argument.
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
const AvailabilityChange & getAvailabilityIntroduced() const
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
bool isPackExpansion() const
void takeAllFrom(AttributePool &pool)
Take the given pool's allocations and add them to this pool.
SourceLocation getStrictLoc() const
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, ParsedAttr::Syntax syntax, SourceLocation ellipsisLoc=SourceLocation())
AttributePool(AttributeFactory &factory)
Create a new pool for a factory.
ParsedAttr * createTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, ParsedAttr::Syntax syntax)
const AvailabilityChange & getAvailabilityDeprecated() const
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, ParsedAttr::Syntax syntax)
Add objc_bridge_related attribute.
ParsedAttr * addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, ParsedAttr::Syntax syntaxUsed)
Add an attribute with a single type argument.
LangAS asOpenCLLangAS() const
If this is an OpenCL addr space attribute returns its representation in LangAS, otherwise returns def...
Defines the clang::SourceLocation class and associated facilities.
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
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)
AttributePool & getPool() const
const Expr * getMessageExpr() const
Defines the clang::TargetInfo interface.
Kind getParsedKind() const
bool isArgIdent(unsigned Arg) const
A trivial tuple used to represent a source range.
bool isPragmaClangAttribute() const
True if the attribute is specified using '#pragma clang attribute'.
SourceLocation getUnavailableLoc() const
ParsedAttributes - A collection of parsed attributes.
AttributeDeclKind
These constants match the enumerated choices of warn_attribute_wrong_decl_type and err_attribute_wron...
IdentifierLoc * getArgAsIdent(unsigned Arg) const
IdentifierInfo * SetterId
unsigned getProcessingCache() const
const Expr * getReplacementExpr() const
PropertyData(IdentifierInfo *getterId, IdentifierInfo *setterId)