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"
50 enum AvailabilitySlot {
51 IntroducedSlot, DeprecatedSlot, ObsoletedSlot, NumAvailabilitySlots
55 struct AvailabilityData {
56 AvailabilityChange
Changes[NumAvailabilitySlots];
59 AvailabilityData(
const AvailabilityChange &Introduced,
60 const AvailabilityChange &Deprecated,
61 const AvailabilityChange &Obsoleted,
62 SourceLocation Strict,
const Expr *ReplaceExpr)
64 Changes[IntroducedSlot] = Introduced;
65 Changes[DeprecatedSlot] = Deprecated;
66 Changes[ObsoletedSlot] = Obsoleted;
82 typedef llvm::PointerUnion<Expr*, IdentifierLoc*>
ArgsUnion;
119 unsigned AttrKind : 16;
123 unsigned NumArgs : 16;
126 unsigned SyntaxUsed : 3;
129 mutable unsigned Invalid : 1;
132 mutable unsigned UsedAsTypeAttr : 1;
136 unsigned IsAvailability : 1;
140 unsigned IsTypeTagForDatatype : 1;
144 unsigned IsProperty : 1;
147 unsigned HasParsedType : 1;
150 mutable unsigned HasProcessingCache : 1;
153 mutable unsigned ProcessingCache : 8;
159 const Expr *MessageExpr;
170 return reinterpret_cast<ArgsUnion const *
>(
this + 1);
175 AvailabilityData *getAvailabilityData() {
176 return reinterpret_cast<AvailabilityData*
>(getArgsBuffer() + NumArgs);
178 const AvailabilityData *getAvailabilityData()
const {
179 return reinterpret_cast<const AvailabilityData*
>(getArgsBuffer() + NumArgs);
198 TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() {
199 return *
reinterpret_cast<TypeTagForDatatypeData*
>(getArgsBuffer()+NumArgs);
202 const TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot()
const {
203 return *
reinterpret_cast<const TypeTagForDatatypeData*
>(getArgsBuffer()
210 return *
reinterpret_cast<ParsedType *
>(
this + 1);
214 return *
reinterpret_cast<const ParsedType *
>(
this + 1);
219 PropertyData &getPropertyDataBuffer() {
221 return *
reinterpret_cast<PropertyData*
>(
this + 1);
224 const PropertyData &getPropertyDataBuffer()
const {
226 return *
reinterpret_cast<const PropertyData*
>(
this + 1);
229 AttributeList(
const AttributeList &) =
delete;
230 void operator=(
const AttributeList &) =
delete;
231 void operator delete(
void *) =
delete;
232 ~AttributeList() =
delete;
234 size_t allocated_size()
const;
237 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
238 IdentifierInfo *scopeName, SourceLocation scopeLoc,
240 Syntax syntaxUsed, SourceLocation ellipsisLoc)
241 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
242 ScopeLoc(scopeLoc), EllipsisLoc(ellipsisLoc), NumArgs(numArgs),
243 SyntaxUsed(syntaxUsed), Invalid(
false), UsedAsTypeAttr(
false),
245 HasParsedType(
false), HasProcessingCache(
false),
246 NextInPosition(nullptr), NextInPool(nullptr) {
247 if (numArgs) memcpy(getArgsBuffer(), args, numArgs *
sizeof(
ArgsUnion));
252 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
253 IdentifierInfo *scopeName, SourceLocation scopeLoc,
254 IdentifierLoc *Parm,
const AvailabilityChange &introduced,
255 const AvailabilityChange &deprecated,
256 const AvailabilityChange &obsoleted,
257 SourceLocation unavailable,
258 const Expr *messageExpr,
259 Syntax syntaxUsed, SourceLocation strict,
260 const Expr *replacementExpr)
261 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
262 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
265 HasProcessingCache(
false), UnavailableLoc(unavailable),
266 MessageExpr(messageExpr), NextInPosition(nullptr), NextInPool(nullptr) {
268 memcpy(getArgsBuffer(), &PVal,
sizeof(
ArgsUnion));
269 new (getAvailabilityData()) AvailabilityData(
270 introduced, deprecated, obsoleted, strict, replacementExpr);
275 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
276 IdentifierInfo *scopeName, SourceLocation scopeLoc,
277 IdentifierLoc *Parm1,
278 IdentifierLoc *Parm2,
279 IdentifierLoc *Parm3,
281 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
282 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(3), SyntaxUsed(syntaxUsed),
285 HasProcessingCache(
false), NextInPosition(nullptr), NextInPool(nullptr) {
294 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
295 IdentifierInfo *scopeName, SourceLocation scopeLoc,
296 IdentifierLoc *ArgKind,
ParsedType matchingCType,
297 bool layoutCompatible,
bool mustBeNull,
Syntax syntaxUsed)
298 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
299 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
301 IsTypeTagForDatatype(
true), IsProperty(
false), HasParsedType(
false),
302 HasProcessingCache(
false), NextInPosition(nullptr), NextInPool(nullptr) {
304 memcpy(getArgsBuffer(), &PVal,
sizeof(
ArgsUnion));
305 TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot();
306 new (&ExtraData.MatchingCType)
ParsedType(matchingCType);
307 ExtraData.LayoutCompatible = layoutCompatible;
308 ExtraData.MustBeNull = mustBeNull;
313 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
314 IdentifierInfo *scopeName, SourceLocation scopeLoc,
316 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
317 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
319 IsTypeTagForDatatype(
false), IsProperty(
false), HasParsedType(
true),
320 HasProcessingCache(
false), NextInPosition(nullptr), NextInPool(nullptr){
326 AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
327 IdentifierInfo *scopeName, SourceLocation scopeLoc,
328 IdentifierInfo *getterId, IdentifierInfo *setterId,
330 : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
331 ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
333 IsTypeTagForDatatype(
false), IsProperty(
true), HasParsedType(
false),
334 HasProcessingCache(
false), NextInPosition(nullptr), NextInPool(nullptr) {
335 new (&getPropertyDataBuffer()) PropertyData(getterId, setterId);
344 #define PARSED_ATTR(NAME) AT_##NAME,
345 #include "clang/Sema/AttrParsedAttrList.inc"
389 return ProcessingCache;
392 ProcessingCache = value;
393 HasProcessingCache =
true;
414 assert(Arg <
NumArgs &&
"Arg access out of range!");
415 return getArgsBuffer()[Arg];
433 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
434 return getAvailabilityData()->Changes[IntroducedSlot];
438 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
439 return getAvailabilityData()->Changes[DeprecatedSlot];
443 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
444 return getAvailabilityData()->Changes[ObsoletedSlot];
448 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
449 return getAvailabilityData()->StrictLoc;
453 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
454 return UnavailableLoc;
458 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
463 assert(
getKind() == AT_Availability &&
"Not an availability attribute");
464 return getAvailabilityData()->Replacement;
468 assert(
getKind() == AT_TypeTagForDatatype &&
469 "Not a type_tag_for_datatype attribute");
474 assert(
getKind() == AT_TypeTagForDatatype &&
475 "Not a type_tag_for_datatype attribute");
480 assert(
getKind() == AT_TypeTagForDatatype &&
481 "Not a type_tag_for_datatype attribute");
482 return getTypeTagForDatatypeDataSlot().
MustBeNull;
486 assert(HasParsedType &&
"Not a type attribute");
487 return getTypeBuffer();
492 return getPropertyDataBuffer();
533 + ((
sizeof(AvailabilityData) +
sizeof(
void*) +
sizeof(
ArgsUnion) - 1)
534 /
sizeof(
void*) *
sizeof(
void*)),
539 /
sizeof(
void*) *
sizeof(
void*),
543 /
sizeof(
void*) *
sizeof(
void*)
553 InlineFreeListsCapacity =
557 llvm::BumpPtrAllocator Alloc;
567 void *allocate(
size_t size);
585 void *allocate(
size_t size) {
586 return Factory.allocate(size);
591 attr->NextInPool = Head;
613 Factory.reclaimPool(Head);
627 if (Head) Factory.reclaimPool(Head);
639 args, numArgs, syntax,
650 const Expr *MessageExpr,
656 Param, introduced, deprecated,
657 obsoleted, unavailable, MessageExpr,
658 syntax, strict, ReplacementExpr));
668 void *memory = allocate(size);
671 Param1, Param2, Param3,
679 bool layoutCompatible,
bool mustBeNull,
684 argumentKind, matchingCType,
685 layoutCompatible, mustBeNull,
693 void *memory = allocate(
sizeof(
AttributeList) +
sizeof(
void *));
696 typeArg, syntaxUsed));
721 : pool(factory), list(nullptr) {
728 bool empty()
const {
return list ==
nullptr; }
732 assert(newAttr->
getNext() ==
nullptr);
738 if (!newList)
return;
742 lastInNewList = next;
754 attrs.list =
nullptr;
755 pool.takeAllFrom(attrs.pool);
758 void clear() { list =
nullptr; pool.clear(); }
772 pool.create(attrName, attrRange, scopeName, scopeLoc, args, numArgs,
773 syntax, ellipsisLoc);
786 const Expr *MessageExpr,
790 pool.create(attrName, attrRange, scopeName, scopeLoc, Param, introduced,
791 deprecated, obsoleted, unavailable, MessageExpr, syntax,
792 strict, ReplacementExpr);
805 pool.create(attrName, attrRange, scopeName, scopeLoc,
806 Param1, Param2, Param3, syntax);
816 bool layoutCompatible,
bool mustBeNull,
819 pool.createTypeTagForDatatype(attrName, attrRange,
821 argumentKind, matchingCType,
822 layoutCompatible, mustBeNull, syntax);
833 pool.createTypeAttribute(attrName, attrRange, scopeName, scopeLoc,
834 typeArg, syntaxUsed);
846 pool.createPropertyAttribute(attrName, attrRange, scopeName, scopeLoc,
847 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 ...
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
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)
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 setProcessingCache(unsigned value) const
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())
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
The required allocation size of an availability attribute, which we want to ensure is a multiple of s...
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.