15 #ifndef LLVM_CLANG_SEMA_ATTRIBUTELIST_H
16 #define LLVM_CLANG_SEMA_ATTRIBUTELIST_H
23 #include "llvm/ADT/PointerUnion.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/Support/Allocator.h"
51 enum AvailabilitySlot {
52 IntroducedSlot, DeprecatedSlot, ObsoletedSlot, NumAvailabilitySlots
56 struct AvailabilityData {
57 AvailabilityChange
Changes[NumAvailabilitySlots];
60 AvailabilityData(
const AvailabilityChange &Introduced,
61 const AvailabilityChange &Deprecated,
62 const AvailabilityChange &Obsoleted,
63 SourceLocation Strict,
const Expr *ReplaceExpr)
65 Changes[IntroducedSlot] = Introduced;
66 Changes[DeprecatedSlot] = Deprecated;
67 Changes[ObsoletedSlot] = Obsoleted;
83 typedef llvm::PointerUnion<Expr*, IdentifierLoc*>
ArgsUnion;
122 unsigned AttrKind : 16;
126 unsigned NumArgs : 16;
129 unsigned SyntaxUsed : 3;
132 mutable unsigned Invalid : 1;
135 mutable unsigned UsedAsTypeAttr : 1;
139 unsigned IsAvailability : 1;
143 unsigned IsTypeTagForDatatype : 1;
147 unsigned IsProperty : 1;
150 unsigned HasParsedType : 1;
153 mutable unsigned HasProcessingCache : 1;
156 mutable unsigned ProcessingCache : 8;
162 const Expr *MessageExpr;
173 return reinterpret_cast<ArgsUnion const *
>(
this + 1);
178 AvailabilityData *getAvailabilityData() {
179 return reinterpret_cast<AvailabilityData*
>(getArgsBuffer() + NumArgs);
181 const AvailabilityData *getAvailabilityData()
const {
182 return reinterpret_cast<const AvailabilityData*
>(getArgsBuffer() + NumArgs);
201 TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() {
202 return *
reinterpret_cast<TypeTagForDatatypeData*
>(getArgsBuffer()+NumArgs);
205 const TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot()
const {
206 return *
reinterpret_cast<const TypeTagForDatatypeData*
>(getArgsBuffer()
213 return *
reinterpret_cast<ParsedType *
>(
this + 1);
217 return *
reinterpret_cast<const ParsedType *
>(
this + 1);
222 PropertyData &getPropertyDataBuffer() {
224 return *
reinterpret_cast<PropertyData*
>(
this + 1);
227 const PropertyData &getPropertyDataBuffer()
const {
229 return *
reinterpret_cast<const PropertyData*
>(
this + 1);
232 AttributeList(
const AttributeList &) =
delete;
233 void operator=(
const AttributeList &) =
delete;
234 void operator delete(
void *) =
delete;
235 ~AttributeList() =
delete;
237 size_t allocated_size()
const;
240 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
241 IdentifierInfo *scopeName, SourceLocation scopeLoc,
243 Syntax syntaxUsed, SourceLocation ellipsisLoc)
244 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
245 ScopeLoc(scopeLoc), EllipsisLoc(ellipsisLoc), NumArgs(numArgs),
246 SyntaxUsed(syntaxUsed), Invalid(
false), UsedAsTypeAttr(
false),
248 HasParsedType(
false), HasProcessingCache(
false),
249 NextInPosition(nullptr), NextInPool(nullptr) {
250 if (numArgs) memcpy(getArgsBuffer(), args, numArgs *
sizeof(
ArgsUnion));
255 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
256 IdentifierInfo *scopeName, SourceLocation scopeLoc,
257 IdentifierLoc *Parm,
const AvailabilityChange &introduced,
258 const AvailabilityChange &deprecated,
259 const AvailabilityChange &obsoleted,
260 SourceLocation unavailable,
261 const Expr *messageExpr,
262 Syntax syntaxUsed, SourceLocation strict,
263 const Expr *replacementExpr)
264 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
265 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
268 HasProcessingCache(
false), UnavailableLoc(unavailable),
269 MessageExpr(messageExpr), NextInPosition(nullptr), NextInPool(nullptr) {
271 memcpy(getArgsBuffer(), &PVal,
sizeof(
ArgsUnion));
272 new (getAvailabilityData()) AvailabilityData(
273 introduced, deprecated, obsoleted, strict, replacementExpr);
278 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
279 IdentifierInfo *scopeName, SourceLocation scopeLoc,
280 IdentifierLoc *Parm1,
281 IdentifierLoc *Parm2,
282 IdentifierLoc *Parm3,
284 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
285 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(3), SyntaxUsed(syntaxUsed),
288 HasProcessingCache(
false), NextInPosition(nullptr), NextInPool(nullptr) {
297 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
298 IdentifierInfo *scopeName, SourceLocation scopeLoc,
299 IdentifierLoc *ArgKind,
ParsedType matchingCType,
300 bool layoutCompatible,
bool mustBeNull,
Syntax syntaxUsed)
301 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
302 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
304 IsTypeTagForDatatype(
true), IsProperty(
false), HasParsedType(
false),
305 HasProcessingCache(
false), NextInPosition(nullptr), NextInPool(nullptr) {
307 memcpy(getArgsBuffer(), &PVal,
sizeof(
ArgsUnion));
308 TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot();
309 new (&ExtraData.MatchingCType)
ParsedType(matchingCType);
310 ExtraData.LayoutCompatible = layoutCompatible;
311 ExtraData.MustBeNull = mustBeNull;
316 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
317 IdentifierInfo *scopeName, SourceLocation scopeLoc,
319 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
320 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
322 IsTypeTagForDatatype(
false), IsProperty(
false), HasParsedType(
true),
323 HasProcessingCache(
false), NextInPosition(nullptr), NextInPool(nullptr){
329 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
330 IdentifierInfo *scopeName, SourceLocation scopeLoc,
331 IdentifierInfo *getterId, IdentifierInfo *setterId,
333 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
334 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
336 IsTypeTagForDatatype(
false), IsProperty(
true), HasParsedType(
false),
337 HasProcessingCache(
false), NextInPosition(nullptr), NextInPool(nullptr) {
338 new (&getPropertyDataBuffer()) PropertyData(getterId, setterId);
347 #define PARSED_ATTR(NAME) AT_##NAME,
348 #include "clang/Sema/AttrParsedAttrList.inc"
393 return ProcessingCache;
396 ProcessingCache = value;
397 HasProcessingCache =
true;
418 assert(Arg < NumArgs &&
"Arg access out of range!");
419 return getArgsBuffer()[Arg];
423 return Arg < NumArgs &&
getArg(Arg).is<
Expr*>();
437 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
438 return getAvailabilityData()->Changes[IntroducedSlot];
442 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
443 return getAvailabilityData()->Changes[DeprecatedSlot];
447 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
448 return getAvailabilityData()->Changes[ObsoletedSlot];
452 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
453 return getAvailabilityData()->StrictLoc;
457 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
458 return UnavailableLoc;
462 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
467 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
468 return getAvailabilityData()->Replacement;
472 assert(
getKind() == AT_TypeTagForDatatype &&
473 "Not a type_tag_for_datatype attribute");
478 assert(
getKind() == AT_TypeTagForDatatype &&
479 "Not a type_tag_for_datatype attribute");
484 assert(
getKind() == AT_TypeTagForDatatype &&
485 "Not a type_tag_for_datatype attribute");
486 return getTypeTagForDatatypeDataSlot().
MustBeNull;
490 assert(HasParsedType &&
"Not a type attribute");
491 return getTypeBuffer();
496 return getPropertyDataBuffer();
542 + ((
sizeof(AvailabilityData) +
sizeof(
void*) +
sizeof(
ArgsUnion) - 1)
543 /
sizeof(
void*) *
sizeof(
void*)),
548 /
sizeof(
void*) *
sizeof(
void*),
552 /
sizeof(
void*) *
sizeof(
void*)
562 InlineFreeListsCapacity =
566 llvm::BumpPtrAllocator Alloc;
576 void *allocate(
size_t size);
594 void *allocate(
size_t size) {
595 return Factory.allocate(size);
600 attr->NextInPool = Head;
622 Factory.reclaimPool(Head);
636 if (Head) Factory.reclaimPool(Head);
648 args, numArgs, syntax,
659 const Expr *MessageExpr,
665 Param, introduced, deprecated,
666 obsoleted, unavailable, MessageExpr,
667 syntax, strict, ReplacementExpr));
677 void *memory = allocate(size);
680 Param1, Param2, Param3,
688 bool layoutCompatible,
bool mustBeNull,
693 argumentKind, matchingCType,
694 layoutCompatible, mustBeNull,
702 void *memory = allocate(
sizeof(
AttributeList) +
sizeof(
void *));
705 typeArg, syntaxUsed));
730 : pool(factory), list(nullptr) {
737 bool empty()
const {
return list ==
nullptr; }
741 assert(newAttr->
getNext() ==
nullptr);
747 if (!newList)
return;
751 lastInNewList = next;
776 attrs.list =
nullptr;
777 pool.takeAllFrom(attrs.pool);
780 void clear() { list =
nullptr; pool.clear(); }
796 pool.create(attrName, attrRange, scopeName, scopeLoc, args, numArgs,
797 syntax, ellipsisLoc);
810 const Expr *MessageExpr,
814 pool.create(attrName, attrRange, scopeName, scopeLoc, Param, introduced,
815 deprecated, obsoleted, unavailable, MessageExpr, syntax,
816 strict, ReplacementExpr);
829 pool.create(attrName, attrRange, scopeName, scopeLoc,
830 Param1, Param2, Param3, syntax);
840 bool layoutCompatible,
bool mustBeNull,
843 pool.createTypeTagForDatatype(attrName, attrRange,
845 argumentKind, matchingCType,
846 layoutCompatible, mustBeNull, syntax);
857 pool.createTypeAttribute(attrName, attrRange, scopeName, scopeLoc,
858 typeArg, syntaxUsed);
870 pool.createPropertyAttribute(attrName, attrRange, scopeName, scopeLoc,
871 getterId, setterId, syntaxUsed);
AttributeList * addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, AttributeList::Syntax syntaxUsed)
Add microsoft __delspec(property) attribute.
bool isSupportedByPragmaAttribute() const
The required allocation size of an availability attribute, which we want to ensure is a multiple of s...
Represents a version number in the form major[.minor[.subminor[.build]]].
ParsedAttributes(AttributeFactory &factory)
AttributeList * createPropertyAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, AttributeList::Syntax syntaxUsed)
bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const
bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const
unsigned getSemanticSpelling() const
If the parsed attribute has a semantic equivalent, and it would have a semantic Spelling enumeration ...
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool >> &MatchRules) const
Decl - This represents one declaration (or definition), e.g.
SourceRange getRange() const
const AvailabilityChange & getAvailabilityDeprecated() const
bool isValid() const
Determine whether this availability change is valid.
unsigned getProcessingCache() const
bool isKeywordAttribute() const
static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)
bool hasCustomParsing() const
AttributeList * 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, AttributeList::Syntax syntax, SourceLocation strict, const Expr *ReplacementExpr)
bool isAlignasAttribute() const
bool isUsedAsTypeAttr() const
bool isArgIdent(unsigned Arg) const
const Expr * getReplacementExpr() const
void addAll(AttributeList *newList)
__ptr16, alignas(...), etc.
One of these records is kept for each identifier that is lexed.
void set(AttributeList *newList)
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
SourceLocation getUnavailableLoc() const
SubjectMatchRule
A list of all the recognized kinds of attributes.
AttributeList * getList() const
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an AttributeList as an argument...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isMicrosoftAttribute() const
AttributeList * addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, AttributeList::Syntax syntaxUsed)
Add an attribute with a single type argument.
AttributeList * create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, AttributeList::Syntax syntax)
bool hasVariadicArg() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
ParsedType * MatchingCType
AttributeArgumentNType
These constants match the enumerated choices of err_attribute_argument_n_type and err_attribute_argum...
bool isDeclspecPropertyAttribute() const
Is this the Microsoft __declspec(property) attribute?
bool hasParsedType() const
void takeAllFrom(ParsedAttributes &attrs)
bool hasProcessingCache() const
Scope - A scope is a transient data structure that is used while parsing the program.
Represents information about a change in availability for an entity, which is part of the encoding of...
bool getLayoutCompatible() const
AvailabilityChange Changes[NumAvailabilitySlots]
AttributeList * createTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, AttributeList::Syntax syntax)
void setInvalid(bool b=true) const
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
VersionTuple Version
The version number at which the change occurred.
unsigned LayoutCompatible
Sema - This implements semantic analysis and AST building for C.
const AvailabilityChange & getAvailabilityIntroduced() const
Exposes information about the current target.
Expr - This represents one expression.
void addAllAtEnd(AttributeList *newList)
void setProcessingCache(unsigned value) const
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
const ParsedType & getTypeArg() const
bool existsInTarget(const TargetInfo &Target) const
Wraps an identifier and optional source location for the identifier.
SourceRange VersionRange
The source range covering the version number.
AttributeList * create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, AttributeList::Syntax syntax, SourceLocation ellipsisLoc=SourceLocation())
Context-sensitive version of a keyword attribute.
IdentifierInfo * SetterId
unsigned getAttributeSpellingListIndex() const
Get an index into the attribute spelling list defined in Attr.td.
AttributeList * createTypeAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, AttributeList::Syntax syntaxUsed)
const ParsedType & getMatchingCType() const
Encodes a location in the source.
SourceLocation getEllipsisLoc() const
bool isValid() const
Return true if this is a valid SourceLocation object.
bool getMustBeNull() const
SourceLocation getBegin() const
bool isArgExpr(unsigned Arg) const
IdentifierInfo * getScopeName() const
llvm::SmallVector< ArgsUnion, 12U > ArgsVector
IdentifierLoc * getArgAsIdent(unsigned Arg) const
IdentifierInfo * GetterId
unsigned getMinArgs() const
AttributeList * 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, AttributeList::Syntax syntax, SourceLocation strict, const Expr *ReplacementExpr)
Add availability attribute.
AttributeFactory & getFactory() const
bool diagnoseLangOpts(class Sema &S) const
friend class AttributePool
const AvailabilityChange & getAvailabilityObsoleted() const
bool empty() const
Determine whether this version information is empty (e.g., all version components are zero)...
Expr * getArgAsExpr(unsigned Arg) const
void takeAllFrom(AttributePool &pool)
Take the given pool's allocations and add them to this pool.
AttributePool(AttributeFactory &factory)
Create a new pool for a factory.
void add(AttributeList *newAttr)
const Expr * getMessageExpr() const
Syntax
The style used to specify an attribute.
bool isPackExpansion() const
IdentifierInfo * getName() const
SourceLocation getStrictLoc() const
ArgsUnion getArg(unsigned Arg) const
getArg - Return the specified argument.
bool isKnownToGCC() const
void setNext(AttributeList *N)
unsigned getMaxArgs() const
SourceLocation getLoc() const
AttributeList * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, AttributeList::Syntax syntax, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
bool isCXX11Attribute() const
bool isContextSensitiveKeywordAttribute() const
AttributePool & getPool() const
Defines the clang::SourceLocation class and associated facilities.
bool isTargetSpecificAttr() const
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
PropertyData(IdentifierInfo *getterId, IdentifierInfo *setterId)
AttributePool(AttributePool &&pool)
Move the given pool's allocations to this pool.
const PropertyData & getPropertyData() const
Defines the clang::TargetInfo interface.
Defines the clang::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
bool isDeclspecAttribute() const
AttributeList * getNext() const
A trivial tuple used to represent a source range.
AttributeList * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, AttributeList::Syntax syntax)
Add objc_bridge_related attribute.
ParsedAttributes - A collection of parsed attributes.
AttributeDeclKind
These constants match the enumerated choices of warn_attribute_wrong_decl_type and err_attribute_wron...
AttributeList *& getListRef()
Returns a reference to the attribute list.
SourceLocation getScopeLoc() const
AttributeList * addNewTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, AttributeList::Syntax syntax)
Add type_tag_for_datatype attribute.
AttributeList - Represents a syntactic attribute.