15 #ifndef LLVM_CLANG_SEMA_ATTRIBUTELIST_H
16 #define LLVM_CLANG_SEMA_ATTRIBUTELIST_H
22 #include "llvm/ADT/PointerUnion.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/Support/Allocator.h"
60 typedef llvm::PointerUnion<Expr*, IdentifierLoc*>
ArgsUnion;
99 unsigned NumArgs : 15;
102 unsigned SyntaxUsed : 3;
105 mutable unsigned Invalid : 1;
108 mutable unsigned UsedAsTypeAttr : 1;
112 unsigned IsAvailability : 1;
116 unsigned IsTypeTagForDatatype : 1;
120 unsigned IsProperty : 1;
123 unsigned HasParsedType : 1;
125 unsigned AttrKind : 8;
131 const Expr *MessageExpr;
142 return reinterpret_cast<ArgsUnion const *
>(
this + 1);
145 enum AvailabilitySlot {
146 IntroducedSlot, DeprecatedSlot, ObsoletedSlot
151 AvailabilityChange &getAvailabilitySlot(AvailabilitySlot index) {
152 return reinterpret_cast<AvailabilityChange*
>(getArgsBuffer()
155 const AvailabilityChange &getAvailabilitySlot(AvailabilitySlot index)
const {
156 return reinterpret_cast<const AvailabilityChange*
>(getArgsBuffer()
176 TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() {
177 return *
reinterpret_cast<TypeTagForDatatypeData*
>(getArgsBuffer()+NumArgs);
180 const TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot()
const {
181 return *
reinterpret_cast<const TypeTagForDatatypeData*
>(getArgsBuffer()
188 return *
reinterpret_cast<ParsedType *
>(
this + 1);
192 return *
reinterpret_cast<const ParsedType *
>(
this + 1);
197 PropertyData &getPropertyDataBuffer() {
199 return *
reinterpret_cast<PropertyData*
>(
this + 1);
202 const PropertyData &getPropertyDataBuffer()
const {
204 return *
reinterpret_cast<const PropertyData*
>(
this + 1);
207 AttributeList(
const AttributeList &) =
delete;
208 void operator=(
const AttributeList &) =
delete;
209 void operator delete(
void *) =
delete;
210 ~AttributeList() =
delete;
212 size_t allocated_size()
const;
215 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
216 IdentifierInfo *scopeName, SourceLocation scopeLoc,
218 Syntax syntaxUsed, SourceLocation ellipsisLoc)
219 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
220 ScopeLoc(scopeLoc), EllipsisLoc(ellipsisLoc), NumArgs(numArgs),
221 SyntaxUsed(syntaxUsed), Invalid(
false), UsedAsTypeAttr(
false),
223 HasParsedType(
false), NextInPosition(nullptr), NextInPool(nullptr) {
224 if (numArgs) memcpy(getArgsBuffer(), args, numArgs *
sizeof(
ArgsUnion));
229 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
230 IdentifierInfo *scopeName, SourceLocation scopeLoc,
231 IdentifierLoc *Parm,
const AvailabilityChange &introduced,
232 const AvailabilityChange &deprecated,
233 const AvailabilityChange &obsoleted,
234 SourceLocation unavailable,
235 const Expr *messageExpr,
237 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
238 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
241 UnavailableLoc(unavailable), MessageExpr(messageExpr),
242 NextInPosition(nullptr), NextInPool(nullptr) {
244 memcpy(getArgsBuffer(), &PVal,
sizeof(
ArgsUnion));
245 new (&getAvailabilitySlot(IntroducedSlot)) AvailabilityChange(introduced);
246 new (&getAvailabilitySlot(DeprecatedSlot)) AvailabilityChange(deprecated);
247 new (&getAvailabilitySlot(ObsoletedSlot)) AvailabilityChange(obsoleted);
252 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
253 IdentifierInfo *scopeName, SourceLocation scopeLoc,
254 IdentifierLoc *Parm1,
255 IdentifierLoc *Parm2,
256 IdentifierLoc *Parm3,
258 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
259 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(3), SyntaxUsed(syntaxUsed),
262 NextInPosition(nullptr), NextInPool(nullptr) {
264 Args.push_back(Parm1);
265 Args.push_back(Parm2);
266 Args.push_back(Parm3);
267 memcpy(getArgsBuffer(), &Args[0], 3 *
sizeof(
ArgsUnion));
272 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
273 IdentifierInfo *scopeName, SourceLocation scopeLoc,
274 IdentifierLoc *ArgKind,
ParsedType matchingCType,
275 bool layoutCompatible,
bool mustBeNull,
Syntax syntaxUsed)
276 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
277 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
279 IsTypeTagForDatatype(
true), IsProperty(
false), HasParsedType(
false),
280 NextInPosition(nullptr), NextInPool(nullptr) {
282 memcpy(getArgsBuffer(), &PVal,
sizeof(
ArgsUnion));
283 TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot();
284 new (&ExtraData.MatchingCType)
ParsedType(matchingCType);
285 ExtraData.LayoutCompatible = layoutCompatible;
286 ExtraData.MustBeNull = mustBeNull;
291 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
292 IdentifierInfo *scopeName, SourceLocation scopeLoc,
294 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
295 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
297 IsTypeTagForDatatype(
false), IsProperty(
false), HasParsedType(
true),
298 NextInPosition(nullptr), NextInPool(nullptr) {
304 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
305 IdentifierInfo *scopeName, SourceLocation scopeLoc,
306 IdentifierInfo *getterId, IdentifierInfo *setterId,
308 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
309 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
311 IsTypeTagForDatatype(
false), IsProperty(
true), HasParsedType(
false),
312 NextInPosition(nullptr), NextInPool(nullptr) {
313 new (&getPropertyDataBuffer()) PropertyData(getterId, setterId);
322 #define PARSED_ATTR(NAME) AT_##NAME,
323 #include "clang/Sema/AttrParsedAttrList.inc"
382 assert(Arg <
NumArgs &&
"Arg access out of range!");
383 return getArgsBuffer()[Arg];
401 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
402 return getAvailabilitySlot(IntroducedSlot);
406 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
407 return getAvailabilitySlot(DeprecatedSlot);
411 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
412 return getAvailabilitySlot(ObsoletedSlot);
416 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
417 return UnavailableLoc;
421 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
426 assert(
getKind() == AT_TypeTagForDatatype &&
427 "Not a type_tag_for_datatype attribute");
432 assert(
getKind() == AT_TypeTagForDatatype &&
433 "Not a type_tag_for_datatype attribute");
438 assert(
getKind() == AT_TypeTagForDatatype &&
439 "Not a type_tag_for_datatype attribute");
440 return getTypeTagForDatatypeDataSlot().
MustBeNull;
444 assert(HasParsedType &&
"Not a type attribute");
445 return getTypeBuffer();
450 return getPropertyDataBuffer();
492 /
sizeof(
void*) *
sizeof(
void*)),
497 /
sizeof(
void*) *
sizeof(
void*),
501 /
sizeof(
void*) *
sizeof(
void*)
511 InlineFreeListsCapacity =
515 llvm::BumpPtrAllocator Alloc;
525 void *allocate(
size_t size);
543 void *allocate(
size_t size) {
544 return Factory.allocate(size);
549 attr->NextInPool = Head;
571 Factory.reclaimPool(Head);
585 if (Head) Factory.reclaimPool(Head);
597 args, numArgs, syntax,
608 const Expr *MessageExpr,
613 Param, introduced, deprecated,
614 obsoleted, unavailable, MessageExpr,
625 void *memory = allocate(size);
628 Param1, Param2, Param3,
636 bool layoutCompatible,
bool mustBeNull,
641 argumentKind, matchingCType,
642 layoutCompatible, mustBeNull,
650 void *memory = allocate(
sizeof(
AttributeList) +
sizeof(
void *));
653 typeArg, syntaxUsed));
678 : pool(factory), list(nullptr) {
685 bool empty()
const {
return list ==
nullptr; }
689 assert(newAttr->
getNext() ==
nullptr);
695 if (!newList)
return;
699 lastInNewList = next;
711 attrs.list =
nullptr;
712 pool.takeAllFrom(attrs.pool);
715 void clear() { list =
nullptr; pool.clear(); }
729 pool.create(attrName, attrRange, scopeName, scopeLoc, args, numArgs,
730 syntax, ellipsisLoc);
743 const Expr *MessageExpr,
746 pool.create(attrName, attrRange, scopeName, scopeLoc, Param, introduced,
747 deprecated, obsoleted, unavailable, MessageExpr, syntax);
760 pool.create(attrName, attrRange, scopeName, scopeLoc,
761 Param1, Param2, Param3, syntax);
771 bool layoutCompatible,
bool mustBeNull,
774 pool.createTypeTagForDatatype(attrName, attrRange,
776 argumentKind, matchingCType,
777 layoutCompatible, mustBeNull, syntax);
788 pool.createTypeAttribute(attrName, attrRange, scopeName, scopeLoc,
789 typeArg, syntaxUsed);
801 pool.createPropertyAttribute(attrName, attrRange, scopeName, scopeLoc,
802 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.
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
unsigned getSemanticSpelling() const
If the parsed attribute has a semantic equivalent, and it would have a semantic Spelling enumeration ...
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)
Add availability attribute.
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.
bool isKeywordAttribute() const
static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)
bool hasCustomParsing() const
bool isAlignasAttribute() const
bool isUsedAsTypeAttr() const
bool isArgIdent(unsigned Arg) 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
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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 ...
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
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)
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
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)
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.
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
const ParsedType & getTypeArg() const
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
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())
The required allocation size of an availability attribute, which we want to ensure is a multiple of s...
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
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
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.