15 #ifndef LLVM_CLANG_SEMA_ATTRIBUTELIST_H
16 #define LLVM_CLANG_SEMA_ATTRIBUTELIST_H
21 #include "llvm/ADT/PointerUnion.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/Triple.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;
141 return reinterpret_cast<ArgsUnion*
>(
this+1);
144 return reinterpret_cast<ArgsUnion const *
>(
this+1);
147 enum AvailabilitySlot {
148 IntroducedSlot, DeprecatedSlot, ObsoletedSlot
153 AvailabilityChange &getAvailabilitySlot(AvailabilitySlot index) {
154 return reinterpret_cast<AvailabilityChange*
>(getArgsBuffer()
157 const AvailabilityChange &getAvailabilitySlot(AvailabilitySlot index)
const {
158 return reinterpret_cast<const AvailabilityChange*
>(getArgsBuffer()
178 TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() {
179 return *
reinterpret_cast<TypeTagForDatatypeData*
>(getArgsBuffer()+NumArgs);
182 const TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot()
const {
183 return *
reinterpret_cast<const TypeTagForDatatypeData*
>(getArgsBuffer()
190 return *
reinterpret_cast<ParsedType *
>(
this + 1);
194 return *
reinterpret_cast<const ParsedType *
>(
this + 1);
199 PropertyData &getPropertyDataBuffer() {
201 return *
reinterpret_cast<PropertyData*
>(
this + 1);
204 const PropertyData &getPropertyDataBuffer()
const {
206 return *
reinterpret_cast<const PropertyData*
>(
this + 1);
209 AttributeList(
const AttributeList &) =
delete;
210 void operator=(
const AttributeList &) =
delete;
211 void operator delete(
void *) =
delete;
212 ~AttributeList() =
delete;
214 size_t allocated_size()
const;
217 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
218 IdentifierInfo *scopeName, SourceLocation scopeLoc,
220 Syntax syntaxUsed, SourceLocation ellipsisLoc)
221 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
222 ScopeLoc(scopeLoc), EllipsisLoc(ellipsisLoc), NumArgs(numArgs),
223 SyntaxUsed(syntaxUsed), Invalid(
false), UsedAsTypeAttr(
false),
225 HasParsedType(
false), NextInPosition(nullptr), NextInPool(nullptr) {
226 if (numArgs) memcpy(getArgsBuffer(), args, numArgs *
sizeof(
ArgsUnion));
231 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
232 IdentifierInfo *scopeName, SourceLocation scopeLoc,
233 IdentifierLoc *Parm,
const AvailabilityChange &introduced,
234 const AvailabilityChange &deprecated,
235 const AvailabilityChange &obsoleted,
236 SourceLocation unavailable,
237 const Expr *messageExpr,
239 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
240 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
243 UnavailableLoc(unavailable), MessageExpr(messageExpr),
244 NextInPosition(nullptr), NextInPool(nullptr) {
246 memcpy(getArgsBuffer(), &PVal,
sizeof(
ArgsUnion));
247 new (&getAvailabilitySlot(IntroducedSlot)) AvailabilityChange(introduced);
248 new (&getAvailabilitySlot(DeprecatedSlot)) AvailabilityChange(deprecated);
249 new (&getAvailabilitySlot(ObsoletedSlot)) AvailabilityChange(obsoleted);
254 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
255 IdentifierInfo *scopeName, SourceLocation scopeLoc,
256 IdentifierLoc *Parm1,
257 IdentifierLoc *Parm2,
258 IdentifierLoc *Parm3,
260 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
261 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(3), SyntaxUsed(syntaxUsed),
264 NextInPosition(nullptr), NextInPool(nullptr) {
266 Args.push_back(Parm1);
267 Args.push_back(Parm2);
268 Args.push_back(Parm3);
269 memcpy(getArgsBuffer(), &Args[0], 3 *
sizeof(
ArgsUnion));
274 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
275 IdentifierInfo *scopeName, SourceLocation scopeLoc,
276 IdentifierLoc *ArgKind,
ParsedType matchingCType,
277 bool layoutCompatible,
bool mustBeNull,
Syntax syntaxUsed)
278 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
279 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
281 IsTypeTagForDatatype(
true), IsProperty(
false), HasParsedType(
false),
282 NextInPosition(nullptr), NextInPool(nullptr) {
284 memcpy(getArgsBuffer(), &PVal,
sizeof(
ArgsUnion));
285 TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot();
286 new (&ExtraData.MatchingCType)
ParsedType(matchingCType);
287 ExtraData.LayoutCompatible = layoutCompatible;
288 ExtraData.MustBeNull = mustBeNull;
293 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
294 IdentifierInfo *scopeName, SourceLocation scopeLoc,
296 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
297 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
299 IsTypeTagForDatatype(
false), IsProperty(
false), HasParsedType(
true),
300 NextInPosition(nullptr), NextInPool(nullptr) {
306 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
307 IdentifierInfo *scopeName, SourceLocation scopeLoc,
308 IdentifierInfo *getterId, IdentifierInfo *setterId,
310 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
311 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
313 IsTypeTagForDatatype(
false), IsProperty(
true), HasParsedType(
false),
314 NextInPosition(nullptr), NextInPool(nullptr) {
315 new (&getPropertyDataBuffer()) PropertyData(getterId, setterId);
324 #define PARSED_ATTR(NAME) AT_##NAME,
325 #include "clang/Sema/AttrParsedAttrList.inc"
384 assert(Arg < NumArgs &&
"Arg access out of range!");
385 return getArgsBuffer()[Arg];
389 return Arg < NumArgs &&
getArg(Arg).is<
Expr*>();
403 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
404 return getAvailabilitySlot(IntroducedSlot);
408 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
409 return getAvailabilitySlot(DeprecatedSlot);
413 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
414 return getAvailabilitySlot(ObsoletedSlot);
418 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
419 return UnavailableLoc;
423 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
428 assert(
getKind() == AT_TypeTagForDatatype &&
429 "Not a type_tag_for_datatype attribute");
434 assert(
getKind() == AT_TypeTagForDatatype &&
435 "Not a type_tag_for_datatype attribute");
440 assert(
getKind() == AT_TypeTagForDatatype &&
441 "Not a type_tag_for_datatype attribute");
442 return getTypeTagForDatatypeDataSlot().
MustBeNull;
446 assert(HasParsedType &&
"Not a type attribute");
447 return getTypeBuffer();
452 return getPropertyDataBuffer();
494 /
sizeof(
void*) *
sizeof(
void*)),
499 /
sizeof(
void*) *
sizeof(
void*),
503 /
sizeof(
void*) *
sizeof(
void*)
513 InlineFreeListsCapacity =
517 llvm::BumpPtrAllocator Alloc;
527 void *allocate(
size_t size);
545 void *allocate(
size_t size) {
546 return Factory.allocate(size);
551 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.
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.
void set(AttributeList *newList)
OpaquePtr< QualType > ParsedType
SourceLocation getUnavailableLoc() const
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
bool existsInTarget(const llvm::Triple &T) const
ParsedType * MatchingCType
bool isDeclspecPropertyAttribute() const
Is this the Microsoft __declspec(property) attribute?
bool hasParsedType() const
void takeAllFrom(ParsedAttributes &attrs)
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
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
const ParsedType & getTypeArg() 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. This index is used by an attribute ...
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. The SourceManager can decode this to get at the full include stack...
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
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
PropertyData(IdentifierInfo *getterId, IdentifierInfo *setterId)
const PropertyData & getPropertyData() const
Defines the clang::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
AttributePool(AttributePool &pool)
Move the given pool's allocations to this pool.
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.
AttributeList *& getListRef()
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.