clang  19.0.0git
ParsedAttr.h
Go to the documentation of this file.
1 //======- ParsedAttr.h - Parsed attribute sets ------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ParsedAttr class, which is used to collect
10 // parsed attributes.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_SEMA_PARSEDATTR_H
15 #define LLVM_CLANG_SEMA_PARSEDATTR_H
16 
19 #include "clang/Basic/Diagnostic.h"
22 #include "clang/Sema/Ownership.h"
23 #include "llvm/ADT/PointerUnion.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/Support/Allocator.h"
26 #include "llvm/Support/VersionTuple.h"
27 #include <bitset>
28 #include <cassert>
29 #include <cstddef>
30 #include <cstring>
31 #include <utility>
32 
33 namespace clang {
34 
35 class ASTContext;
36 class Decl;
37 class Expr;
38 class IdentifierInfo;
39 class LangOptions;
40 class Sema;
41 class Stmt;
42 class TargetInfo;
43 struct IdentifierLoc;
44 
45 /// Represents information about a change in availability for
46 /// an entity, which is part of the encoding of the 'availability'
47 /// attribute.
49  /// The location of the keyword indicating the kind of change.
51 
52  /// The version number at which the change occurred.
53  VersionTuple Version;
54 
55  /// The source range covering the version number.
57 
58  /// Determine whether this availability change is valid.
59  bool isValid() const { return !Version.empty(); }
60 };
61 
62 namespace detail {
65 };
66 
67 /// Describes the trailing object for Availability attribute in ParsedAttr.
71  const Expr *Replacement;
73 
76  const AvailabilityChange &Obsoleted, SourceLocation Strict,
77  const Expr *ReplaceExpr, const IdentifierLoc *EnvironmentLoc)
78  : StrictLoc(Strict), Replacement(ReplaceExpr),
80  Changes[IntroducedSlot] = Introduced;
82  Changes[ObsoletedSlot] = Obsoleted;
83  }
84 };
85 
88  LLVM_PREFERRED_TYPE(bool)
90  LLVM_PREFERRED_TYPE(bool)
91  unsigned MustBeNull : 1;
92 };
93 struct PropertyData {
94  IdentifierInfo *GetterId, *SetterId;
95 
97  : GetterId(getterId), SetterId(setterId) {}
98 };
99 
100 } // namespace detail
101 
102 /// Wraps an identifier and optional source location for the identifier.
106 
108  IdentifierInfo *Ident);
109 };
110 
111 /// A union of the various pointer types that can be passed to an
112 /// ParsedAttr as an argument.
113 using ArgsUnion = llvm::PointerUnion<Expr *, IdentifierLoc *>;
115 
116 /// ParsedAttr - Represents a syntactic attribute.
117 ///
118 /// For a GNU attribute, there are four forms of this construct:
119 ///
120 /// 1: __attribute__(( const )). ParmName/Args/NumArgs will all be unused.
121 /// 2: __attribute__(( mode(byte) )). ParmName used, Args/NumArgs unused.
122 /// 3: __attribute__(( format(printf, 1, 2) )). ParmName/Args/NumArgs all used.
123 /// 4: __attribute__(( aligned(16) )). ParmName is unused, Args/Num used.
124 ///
125 class ParsedAttr final
126  : public AttributeCommonInfo,
127  private llvm::TrailingObjects<
128  ParsedAttr, ArgsUnion, detail::AvailabilityData,
129  detail::TypeTagForDatatypeData, ParsedType, detail::PropertyData> {
130  friend TrailingObjects;
131 
132  size_t numTrailingObjects(OverloadToken<ArgsUnion>) const { return NumArgs; }
133  size_t numTrailingObjects(OverloadToken<detail::AvailabilityData>) const {
134  return IsAvailability;
135  }
136  size_t
137  numTrailingObjects(OverloadToken<detail::TypeTagForDatatypeData>) const {
138  return IsTypeTagForDatatype;
139  }
140  size_t numTrailingObjects(OverloadToken<ParsedType>) const {
141  return HasParsedType;
142  }
143  size_t numTrailingObjects(OverloadToken<detail::PropertyData>) const {
144  return IsProperty;
145  }
146 
147 private:
148  IdentifierInfo *MacroII = nullptr;
149  SourceLocation MacroExpansionLoc;
150  SourceLocation EllipsisLoc;
151 
152  /// The number of expression arguments this attribute has.
153  /// The expressions themselves are stored after the object.
154  unsigned NumArgs : 16;
155 
156  /// True if already diagnosed as invalid.
157  LLVM_PREFERRED_TYPE(bool)
158  mutable unsigned Invalid : 1;
159 
160  /// True if this attribute was used as a type attribute.
161  LLVM_PREFERRED_TYPE(bool)
162  mutable unsigned UsedAsTypeAttr : 1;
163 
164  /// True if this has the extra information associated with an
165  /// availability attribute.
166  LLVM_PREFERRED_TYPE(bool)
167  unsigned IsAvailability : 1;
168 
169  /// True if this has extra information associated with a
170  /// type_tag_for_datatype attribute.
171  LLVM_PREFERRED_TYPE(bool)
172  unsigned IsTypeTagForDatatype : 1;
173 
174  /// True if this has extra information associated with a
175  /// Microsoft __delcspec(property) attribute.
176  LLVM_PREFERRED_TYPE(bool)
177  unsigned IsProperty : 1;
178 
179  /// True if this has a ParsedType
180  LLVM_PREFERRED_TYPE(bool)
181  unsigned HasParsedType : 1;
182 
183  /// True if the processing cache is valid.
184  LLVM_PREFERRED_TYPE(bool)
185  mutable unsigned HasProcessingCache : 1;
186 
187  /// A cached value.
188  mutable unsigned ProcessingCache : 8;
189 
190  /// True if the attribute is specified using '#pragma clang attribute'.
191  LLVM_PREFERRED_TYPE(bool)
192  mutable unsigned IsPragmaClangAttribute : 1;
193 
194  /// The location of the 'unavailable' keyword in an
195  /// availability attribute.
196  SourceLocation UnavailableLoc;
197 
198  const Expr *MessageExpr;
199 
200  const ParsedAttrInfo &Info;
201 
202  ArgsUnion *getArgsBuffer() { return getTrailingObjects<ArgsUnion>(); }
203  ArgsUnion const *getArgsBuffer() const {
204  return getTrailingObjects<ArgsUnion>();
205  }
206 
207  detail::AvailabilityData *getAvailabilityData() {
208  return getTrailingObjects<detail::AvailabilityData>();
209  }
210  const detail::AvailabilityData *getAvailabilityData() const {
211  return getTrailingObjects<detail::AvailabilityData>();
212  }
213 
214 private:
215  friend class AttributeFactory;
216  friend class AttributePool;
217 
218  /// Constructor for attributes with expression arguments.
219  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
220  IdentifierInfo *scopeName, SourceLocation scopeLoc,
221  ArgsUnion *args, unsigned numArgs, Form formUsed,
222  SourceLocation ellipsisLoc)
223  : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
224  EllipsisLoc(ellipsisLoc), NumArgs(numArgs), Invalid(false),
225  UsedAsTypeAttr(false), IsAvailability(false),
226  IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
227  HasProcessingCache(false), IsPragmaClangAttribute(false),
228  Info(ParsedAttrInfo::get(*this)) {
229  if (numArgs)
230  memcpy(getArgsBuffer(), args, numArgs * sizeof(ArgsUnion));
231  }
232 
233  /// Constructor for availability attributes.
234  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
235  IdentifierInfo *scopeName, SourceLocation scopeLoc,
236  IdentifierLoc *Parm, const AvailabilityChange &introduced,
237  const AvailabilityChange &deprecated,
238  const AvailabilityChange &obsoleted, SourceLocation unavailable,
239  const Expr *messageExpr, Form formUsed, SourceLocation strict,
240  const Expr *replacementExpr, const IdentifierLoc *environmentLoc)
241  : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
242  NumArgs(1), Invalid(false), UsedAsTypeAttr(false), IsAvailability(true),
243  IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
244  HasProcessingCache(false), IsPragmaClangAttribute(false),
245  UnavailableLoc(unavailable), MessageExpr(messageExpr),
246  Info(ParsedAttrInfo::get(*this)) {
247  ArgsUnion PVal(Parm);
248  memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion));
249  new (getAvailabilityData())
250  detail::AvailabilityData(introduced, deprecated, obsoleted, strict,
251  replacementExpr, environmentLoc);
252  }
253 
254  /// Constructor for objc_bridge_related attributes.
255  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
256  IdentifierInfo *scopeName, SourceLocation scopeLoc,
257  IdentifierLoc *Parm1, IdentifierLoc *Parm2, IdentifierLoc *Parm3,
258  Form formUsed)
259  : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
260  NumArgs(3), Invalid(false), UsedAsTypeAttr(false),
261  IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false),
262  HasParsedType(false), HasProcessingCache(false),
263  IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
264  ArgsUnion *Args = getArgsBuffer();
265  Args[0] = Parm1;
266  Args[1] = Parm2;
267  Args[2] = Parm3;
268  }
269 
270  /// Constructor for type_tag_for_datatype attribute.
271  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
272  IdentifierInfo *scopeName, SourceLocation scopeLoc,
273  IdentifierLoc *ArgKind, ParsedType matchingCType,
274  bool layoutCompatible, bool mustBeNull, Form formUsed)
275  : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
276  NumArgs(1), Invalid(false), UsedAsTypeAttr(false),
277  IsAvailability(false), IsTypeTagForDatatype(true), IsProperty(false),
278  HasParsedType(false), HasProcessingCache(false),
279  IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
280  ArgsUnion PVal(ArgKind);
281  memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion));
282  detail::TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot();
283  new (&ExtraData.MatchingCType) ParsedType(matchingCType);
284  ExtraData.LayoutCompatible = layoutCompatible;
285  ExtraData.MustBeNull = mustBeNull;
286  }
287 
288  /// Constructor for attributes with a single type argument.
289  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
290  IdentifierInfo *scopeName, SourceLocation scopeLoc,
291  ParsedType typeArg, Form formUsed, SourceLocation ellipsisLoc)
292  : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
293  EllipsisLoc(ellipsisLoc), NumArgs(0), Invalid(false),
294  UsedAsTypeAttr(false), IsAvailability(false),
295  IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(true),
296  HasProcessingCache(false), IsPragmaClangAttribute(false),
297  Info(ParsedAttrInfo::get(*this)) {
298  new (&getTypeBuffer()) ParsedType(typeArg);
299  }
300 
301  /// Constructor for microsoft __declspec(property) attribute.
302  ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
303  IdentifierInfo *scopeName, SourceLocation scopeLoc,
304  IdentifierInfo *getterId, IdentifierInfo *setterId, Form formUsed)
305  : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed),
306  NumArgs(0), Invalid(false), UsedAsTypeAttr(false),
307  IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(true),
308  HasParsedType(false), HasProcessingCache(false),
309  IsPragmaClangAttribute(false), Info(ParsedAttrInfo::get(*this)) {
310  new (&getPropertyDataBuffer()) detail::PropertyData(getterId, setterId);
311  }
312 
313  /// Type tag information is stored immediately following the arguments, if
314  /// any, at the end of the object. They are mutually exclusive with
315  /// availability slots.
316  detail::TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() {
317  return *getTrailingObjects<detail::TypeTagForDatatypeData>();
318  }
319  const detail::TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() const {
320  return *getTrailingObjects<detail::TypeTagForDatatypeData>();
321  }
322 
323  /// The type buffer immediately follows the object and are mutually exclusive
324  /// with arguments.
325  ParsedType &getTypeBuffer() { return *getTrailingObjects<ParsedType>(); }
326  const ParsedType &getTypeBuffer() const {
327  return *getTrailingObjects<ParsedType>();
328  }
329 
330  /// The property data immediately follows the object is mutually exclusive
331  /// with arguments.
332  detail::PropertyData &getPropertyDataBuffer() {
333  assert(IsProperty);
334  return *getTrailingObjects<detail::PropertyData>();
335  }
336  const detail::PropertyData &getPropertyDataBuffer() const {
337  assert(IsProperty);
338  return *getTrailingObjects<detail::PropertyData>();
339  }
340 
341  size_t allocated_size() const;
342 
343 public:
344  ParsedAttr(const ParsedAttr &) = delete;
345  ParsedAttr(ParsedAttr &&) = delete;
346  ParsedAttr &operator=(const ParsedAttr &) = delete;
348  ~ParsedAttr() = delete;
349 
350  void operator delete(void *) = delete;
351 
352  bool hasParsedType() const { return HasParsedType; }
353 
354  /// Is this the Microsoft __declspec(property) attribute?
356  return IsProperty;
357  }
358 
359  bool isInvalid() const { return Invalid; }
360  void setInvalid(bool b = true) const { Invalid = b; }
361 
362  bool hasProcessingCache() const { return HasProcessingCache; }
363 
364  unsigned getProcessingCache() const {
365  assert(hasProcessingCache());
366  return ProcessingCache;
367  }
368 
369  void setProcessingCache(unsigned value) const {
370  ProcessingCache = value;
371  HasProcessingCache = true;
372  }
373 
374  bool isUsedAsTypeAttr() const { return UsedAsTypeAttr; }
375  void setUsedAsTypeAttr(bool Used = true) { UsedAsTypeAttr = Used; }
376 
377  /// True if the attribute is specified using '#pragma clang attribute'.
378  bool isPragmaClangAttribute() const { return IsPragmaClangAttribute; }
379 
380  void setIsPragmaClangAttribute() { IsPragmaClangAttribute = true; }
381 
382  bool isPackExpansion() const { return EllipsisLoc.isValid(); }
383  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
384 
385  /// getNumArgs - Return the number of actual arguments to this attribute.
386  unsigned getNumArgs() const { return NumArgs; }
387 
388  /// getArg - Return the specified argument.
389  ArgsUnion getArg(unsigned Arg) const {
390  assert(Arg < NumArgs && "Arg access out of range!");
391  return getArgsBuffer()[Arg];
392  }
393 
394  bool isArgExpr(unsigned Arg) const {
395  return Arg < NumArgs && getArg(Arg).is<Expr*>();
396  }
397 
398  Expr *getArgAsExpr(unsigned Arg) const {
399  return getArg(Arg).get<Expr*>();
400  }
401 
402  bool isArgIdent(unsigned Arg) const {
403  return Arg < NumArgs && getArg(Arg).is<IdentifierLoc*>();
404  }
405 
406  IdentifierLoc *getArgAsIdent(unsigned Arg) const {
407  return getArg(Arg).get<IdentifierLoc*>();
408  }
409 
411  assert(getParsedKind() == AT_Availability &&
412  "Not an availability attribute");
413  return getAvailabilityData()->Changes[detail::IntroducedSlot];
414  }
415 
417  assert(getParsedKind() == AT_Availability &&
418  "Not an availability attribute");
419  return getAvailabilityData()->Changes[detail::DeprecatedSlot];
420  }
421 
423  assert(getParsedKind() == AT_Availability &&
424  "Not an availability attribute");
425  return getAvailabilityData()->Changes[detail::ObsoletedSlot];
426  }
427 
429  assert(getParsedKind() == AT_Availability &&
430  "Not an availability attribute");
431  return getAvailabilityData()->StrictLoc;
432  }
433 
435  assert(getParsedKind() == AT_Availability &&
436  "Not an availability attribute");
437  return UnavailableLoc;
438  }
439 
440  const Expr * getMessageExpr() const {
441  assert(getParsedKind() == AT_Availability &&
442  "Not an availability attribute");
443  return MessageExpr;
444  }
445 
446  const Expr *getReplacementExpr() const {
447  assert(getParsedKind() == AT_Availability &&
448  "Not an availability attribute");
449  return getAvailabilityData()->Replacement;
450  }
451 
452  const IdentifierLoc *getEnvironment() const {
453  assert(getParsedKind() == AT_Availability &&
454  "Not an availability attribute");
455  return getAvailabilityData()->EnvironmentLoc;
456  }
457 
458  const ParsedType &getMatchingCType() const {
459  assert(getParsedKind() == AT_TypeTagForDatatype &&
460  "Not a type_tag_for_datatype attribute");
461  return getTypeTagForDatatypeDataSlot().MatchingCType;
462  }
463 
464  bool getLayoutCompatible() const {
465  assert(getParsedKind() == AT_TypeTagForDatatype &&
466  "Not a type_tag_for_datatype attribute");
467  return getTypeTagForDatatypeDataSlot().LayoutCompatible;
468  }
469 
470  bool getMustBeNull() const {
471  assert(getParsedKind() == AT_TypeTagForDatatype &&
472  "Not a type_tag_for_datatype attribute");
473  return getTypeTagForDatatypeDataSlot().MustBeNull;
474  }
475 
476  const ParsedType &getTypeArg() const {
477  assert(HasParsedType && "Not a type attribute");
478  return getTypeBuffer();
479  }
480 
482  assert(isDeclspecPropertyAttribute() &&
483  "Not a __delcspec(property) attribute");
484  return getPropertyDataBuffer().GetterId;
485  }
486 
488  assert(isDeclspecPropertyAttribute() &&
489  "Not a __delcspec(property) attribute");
490  return getPropertyDataBuffer().SetterId;
491  }
492 
493  /// Set the macro identifier info object that this parsed attribute was
494  /// declared in if it was declared in a macro. Also set the expansion location
495  /// of the macro.
497  MacroII = MacroName;
498  MacroExpansionLoc = Loc;
499  }
500 
501  /// Returns true if this attribute was declared in a macro.
502  bool hasMacroIdentifier() const { return MacroII != nullptr; }
503 
504  /// Return the macro identifier if this attribute was declared in a macro.
505  /// nullptr is returned if it was not declared in a macro.
506  IdentifierInfo *getMacroIdentifier() const { return MacroII; }
507 
509  assert(hasMacroIdentifier() && "Can only get the macro expansion location "
510  "if this attribute has a macro identifier.");
511  return MacroExpansionLoc;
512  }
513 
514  /// Check if the attribute has exactly as many args as Num. May output an
515  /// error. Returns false if a diagnostic is produced.
516  bool checkExactlyNumArgs(class Sema &S, unsigned Num) const;
517  /// Check if the attribute has at least as many args as Num. May output an
518  /// error. Returns false if a diagnostic is produced.
519  bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const;
520  /// Check if the attribute has at most as many args as Num. May output an
521  /// error. Returns false if a diagnostic is produced.
522  bool checkAtMostNumArgs(class Sema &S, unsigned Num) const;
523 
524  bool isTargetSpecificAttr() const;
525  bool isTypeAttr() const;
526  bool isStmtAttr() const;
527 
528  bool hasCustomParsing() const;
529  bool acceptsExprPack() const;
530  bool isParamExpr(size_t N) const;
531  unsigned getMinArgs() const;
532  unsigned getMaxArgs() const;
533  unsigned getNumArgMembers() const;
534  bool hasVariadicArg() const;
535  void handleAttrWithDelayedArgs(Sema &S, Decl *D) const;
536  bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const;
537  bool diagnoseAppertainsTo(class Sema &S, const Stmt *St) const;
538  bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const;
539  // This function stub exists for parity with the declaration checking code so
540  // that checkCommonAttributeFeatures() can work generically on declarations
541  // or statements.
542  bool diagnoseMutualExclusion(class Sema &S, const Stmt *St) const {
543  return true;
544  }
545  bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const;
546  void getMatchRules(const LangOptions &LangOpts,
547  SmallVectorImpl<std::pair<attr::SubjectMatchRule, bool>>
548  &MatchRules) const;
549  bool diagnoseLangOpts(class Sema &S) const;
550  bool existsInTarget(const TargetInfo &Target) const;
551  bool isKnownToGCC() const;
552  bool isSupportedByPragmaAttribute() const;
553  bool supportsNonconformingLambdaSyntax() const;
554 
555  /// Returns whether a [[]] attribute, if specified ahead of a declaration,
556  /// should be applied to the decl-specifier-seq instead (i.e. whether it
557  /// "slides" to the decl-specifier-seq).
558  ///
559  /// By the standard, attributes specified before the declaration always
560  /// appertain to the declaration, but historically we have allowed some of
561  /// these attributes to slide to the decl-specifier-seq, so we need to keep
562  /// supporting this behavior.
563  ///
564  /// This may only be called if isStandardAttributeSyntax() returns true.
565  bool slidesFromDeclToDeclSpecLegacyBehavior() const;
566 
567  /// If the parsed attribute has a semantic equivalent, and it would
568  /// have a semantic Spelling enumeration (due to having semantically-distinct
569  /// spelling variations), return the value of that semantic spelling. If the
570  /// parsed attribute does not have a semantic equivalent, or would not have
571  /// a Spelling enumeration, the value UINT_MAX is returned.
572  unsigned getSemanticSpelling() const;
573 
574  /// If this is an OpenCL address space attribute, returns its representation
575  /// in LangAS, otherwise returns default address space.
577  switch (getParsedKind()) {
578  case ParsedAttr::AT_OpenCLConstantAddressSpace:
580  case ParsedAttr::AT_OpenCLGlobalAddressSpace:
581  return LangAS::opencl_global;
582  case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
584  case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
586  case ParsedAttr::AT_OpenCLLocalAddressSpace:
587  return LangAS::opencl_local;
588  case ParsedAttr::AT_OpenCLPrivateAddressSpace:
589  return LangAS::opencl_private;
590  case ParsedAttr::AT_OpenCLGenericAddressSpace:
591  return LangAS::opencl_generic;
592  default:
593  return LangAS::Default;
594  }
595  }
596 
597  /// If this is an OpenCL address space attribute, returns its SYCL
598  /// representation in LangAS, otherwise returns default address space.
600  switch (getKind()) {
601  // FIXME: there are uses of `opencl_constant` attribute in SYCL mode.
602  // See https://github.com/intel/llvm/issues/3062 for more details.
603  case ParsedAttr::AT_OpenCLConstantAddressSpace:
605  case ParsedAttr::AT_OpenCLGlobalAddressSpace:
606  return LangAS::sycl_global;
607  case ParsedAttr::AT_OpenCLGlobalDeviceAddressSpace:
609  case ParsedAttr::AT_OpenCLGlobalHostAddressSpace:
611  case ParsedAttr::AT_OpenCLLocalAddressSpace:
612  return LangAS::sycl_local;
613  case ParsedAttr::AT_OpenCLPrivateAddressSpace:
614  return LangAS::sycl_private;
615  case ParsedAttr::AT_OpenCLGenericAddressSpace:
616  default:
617  return LangAS::Default;
618  }
619  }
620 
621  /// If this is an HLSL address space attribute, returns its representation
622  /// in LangAS, otherwise returns default address space.
624  switch (getParsedKind()) {
625  case ParsedAttr::AT_HLSLGroupSharedAddressSpace:
627  default:
628  return LangAS::Default;
629  }
630  }
631 
633  return AttributeCommonInfo::Kind(Info.AttrKind);
634  }
635  const ParsedAttrInfo &getInfo() const { return Info; }
636 };
637 
638 class AttributePool;
639 /// A factory, from which one makes pools, from which one creates
640 /// individual attributes which are deallocated with the pool.
641 ///
642 /// Note that it's tolerably cheap to create and destroy one of
643 /// these as long as you don't actually allocate anything in it.
645 public:
646  enum {
647  AvailabilityAllocSize =
648  ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
650  detail::PropertyData>(1, 1, 0, 0, 0),
651  TypeTagForDatatypeAllocSize =
652  ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
654  detail::PropertyData>(1, 0, 1, 0, 0),
655  PropertyAllocSize =
656  ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
658  detail::PropertyData>(0, 0, 0, 0, 1),
659  };
660 
661 private:
662  enum {
663  /// The number of free lists we want to be sure to support
664  /// inline. This is just enough that availability attributes
665  /// don't surpass it. It's actually very unlikely we'll see an
666  /// attribute that needs more than that; on x86-64 you'd need 10
667  /// expression arguments, and on i386 you'd need 19.
668  InlineFreeListsCapacity =
669  1 + (AvailabilityAllocSize - sizeof(ParsedAttr)) / sizeof(void *)
670  };
671 
672  llvm::BumpPtrAllocator Alloc;
673 
674  /// Free lists. The index is determined by the following formula:
675  /// (size - sizeof(ParsedAttr)) / sizeof(void*)
676  SmallVector<SmallVector<ParsedAttr *, 8>, InlineFreeListsCapacity> FreeLists;
677 
678  // The following are the private interface used by AttributePool.
679  friend class AttributePool;
680 
681  /// Allocate an attribute of the given size.
682  void *allocate(size_t size);
683 
684  void deallocate(ParsedAttr *AL);
685 
686  /// Reclaim all the attributes in the given pool chain, which is
687  /// non-empty. Note that the current implementation is safe
688  /// against reclaiming things which were not actually allocated
689  /// with the allocator, although of course it's important to make
690  /// sure that their allocator lives at least as long as this one.
691  void reclaimPool(AttributePool &head);
692 
693 public:
696 };
697 
700  friend class AttributeFactory;
701  friend class ParsedAttributes;
702  AttributeFactory &Factory;
704 
705  void *allocate(size_t size) {
706  return Factory.allocate(size);
707  }
708 
709  ParsedAttr *add(ParsedAttr *attr) {
710  Attrs.push_back(attr);
711  return attr;
712  }
713 
714  void remove(ParsedAttr *attr) {
715  assert(llvm::is_contained(Attrs, attr) &&
716  "Can't take attribute from a pool that doesn't own it!");
717  Attrs.erase(llvm::find(Attrs, attr));
718  }
719 
720  void takePool(AttributePool &pool);
721 
722 public:
723  /// Create a new pool for a factory.
724  AttributePool(AttributeFactory &factory) : Factory(factory) {}
725 
726  AttributePool(const AttributePool &) = delete;
727  // The copy assignment operator is defined as deleted pending further
728  // motivation.
730 
731  ~AttributePool() { Factory.reclaimPool(*this); }
732 
733  /// Move the given pool's allocations to this pool.
734  AttributePool(AttributePool &&pool) = default;
735 
736  // The move assignment operator is defined as deleted pending further
737  // motivation.
739 
740  AttributeFactory &getFactory() const { return Factory; }
741 
742  void clear() {
743  Factory.reclaimPool(*this);
744  Attrs.clear();
745  }
746 
747  /// Take the given pool's allocations and add them to this pool.
749  takePool(pool);
750  pool.Attrs.clear();
751  }
752 
753  /// Removes the attributes from \c List, which are owned by \c Pool, and adds
754  /// them at the end of this \c AttributePool.
755  void takeFrom(ParsedAttributesView &List, AttributePool &Pool);
756 
758  IdentifierInfo *scopeName, SourceLocation scopeLoc,
759  ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form,
760  SourceLocation ellipsisLoc = SourceLocation()) {
761  void *memory = allocate(
762  ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
764  detail::PropertyData>(numArgs, 0, 0, 0,
765  0));
766  return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
767  args, numArgs, form, ellipsisLoc));
768  }
769 
771  IdentifierInfo *scopeName, SourceLocation scopeLoc,
772  IdentifierLoc *Param, const AvailabilityChange &introduced,
773  const AvailabilityChange &deprecated,
774  const AvailabilityChange &obsoleted,
775  SourceLocation unavailable, const Expr *MessageExpr,
776  ParsedAttr::Form form, SourceLocation strict,
777  const Expr *ReplacementExpr,
778  IdentifierLoc *EnvironmentLoc) {
779  void *memory = allocate(AttributeFactory::AvailabilityAllocSize);
780  return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
781  Param, introduced, deprecated, obsoleted,
782  unavailable, MessageExpr, form, strict,
783  ReplacementExpr, EnvironmentLoc));
784  }
785 
787  IdentifierInfo *scopeName, SourceLocation scopeLoc,
788  IdentifierLoc *Param1, IdentifierLoc *Param2,
789  IdentifierLoc *Param3, ParsedAttr::Form form) {
790  void *memory = allocate(
791  ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
793  detail::PropertyData>(3, 0, 0, 0, 0));
794  return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
795  Param1, Param2, Param3, form));
796  }
797 
798  ParsedAttr *
800  IdentifierInfo *scopeName, SourceLocation scopeLoc,
801  IdentifierLoc *argumentKind,
802  ParsedType matchingCType, bool layoutCompatible,
803  bool mustBeNull, ParsedAttr::Form form) {
804  void *memory = allocate(AttributeFactory::TypeTagForDatatypeAllocSize);
805  return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
806  argumentKind, matchingCType,
807  layoutCompatible, mustBeNull, form));
808  }
809 
811  SourceRange attrRange,
812  IdentifierInfo *scopeName,
813  SourceLocation scopeLoc, ParsedType typeArg,
814  ParsedAttr::Form formUsed,
815  SourceLocation ellipsisLoc) {
816  void *memory = allocate(
817  ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
819  detail::PropertyData>(0, 0, 0, 1, 0));
820  return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
821  typeArg, formUsed, ellipsisLoc));
822  }
823 
824  ParsedAttr *
826  IdentifierInfo *scopeName, SourceLocation scopeLoc,
827  IdentifierInfo *getterId, IdentifierInfo *setterId,
828  ParsedAttr::Form formUsed) {
829  void *memory = allocate(AttributeFactory::PropertyAllocSize);
830  return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc,
831  getterId, setterId, formUsed));
832  }
833 };
834 
836  friend class AttributePool;
838  using SizeType = decltype(std::declval<VecTy>().size());
839 
840 public:
842 
843  static const ParsedAttributesView &none() {
844  static const ParsedAttributesView Attrs;
845  return Attrs;
846  }
847 
848  bool empty() const { return AttrList.empty(); }
849  SizeType size() const { return AttrList.size(); }
850  ParsedAttr &operator[](SizeType pos) { return *AttrList[pos]; }
851  const ParsedAttr &operator[](SizeType pos) const { return *AttrList[pos]; }
852 
853  void addAtEnd(ParsedAttr *newAttr) {
854  assert(newAttr);
855  AttrList.push_back(newAttr);
856  }
857 
858  void remove(ParsedAttr *ToBeRemoved) {
859  assert(is_contained(AttrList, ToBeRemoved) &&
860  "Cannot remove attribute that isn't in the list");
861  AttrList.erase(llvm::find(AttrList, ToBeRemoved));
862  }
863 
864  void clearListOnly() { AttrList.clear(); }
865 
866  struct iterator : llvm::iterator_adaptor_base<iterator, VecTy::iterator,
867  std::random_access_iterator_tag,
868  ParsedAttr> {
869  iterator() : iterator_adaptor_base(nullptr) {}
870  iterator(VecTy::iterator I) : iterator_adaptor_base(I) {}
871  reference operator*() const { return **I; }
872  friend class ParsedAttributesView;
873  };
875  : llvm::iterator_adaptor_base<const_iterator, VecTy::const_iterator,
876  std::random_access_iterator_tag,
877  ParsedAttr> {
878  const_iterator() : iterator_adaptor_base(nullptr) {}
879  const_iterator(VecTy::const_iterator I) : iterator_adaptor_base(I) {}
880 
881  reference operator*() const { return **I; }
882  friend class ParsedAttributesView;
883  };
884 
885  void addAll(iterator B, iterator E) {
886  AttrList.insert(AttrList.begin(), B.I, E.I);
887  }
888 
890  AttrList.insert(AttrList.begin(), B.I, E.I);
891  }
892 
894  AttrList.insert(AttrList.end(), B.I, E.I);
895  }
896 
898  AttrList.insert(AttrList.end(), B.I, E.I);
899  }
900 
901  iterator begin() { return iterator(AttrList.begin()); }
902  const_iterator begin() const { return const_iterator(AttrList.begin()); }
903  iterator end() { return iterator(AttrList.end()); }
904  const_iterator end() const { return const_iterator(AttrList.end()); }
905 
907  assert(!empty());
908  return *AttrList.front();
909  }
910  const ParsedAttr &front() const {
911  assert(!empty());
912  return *AttrList.front();
913  }
915  assert(!empty());
916  return *AttrList.back();
917  }
918  const ParsedAttr &back() const {
919  assert(!empty());
920  return *AttrList.back();
921  }
922 
924  return llvm::any_of(AttrList, [K](const ParsedAttr *AL) {
925  return AL->getParsedKind() == K;
926  });
927  }
928 
929  const ParsedAttr *getMSPropertyAttr() const {
930  auto It = llvm::find_if(AttrList, [](const ParsedAttr *AL) {
931  return AL->isDeclspecPropertyAttribute();
932  });
933  if (It != AttrList.end())
934  return *It;
935  return nullptr;
936  }
937  bool hasMSPropertyAttr() const { return getMSPropertyAttr(); }
938 
939 private:
940  VecTy AttrList;
941 };
942 
944  ParsedAttributeArgumentsProperties(uint32_t StringLiteralBits)
945  : StringLiterals(StringLiteralBits) {}
946  bool isStringLiteralArg(unsigned I) const {
947  // If the last bit is set, assume we have a variadic parameter
948  if (I >= StringLiterals.size())
949  return StringLiterals.test(StringLiterals.size() - 1);
950  return StringLiterals.test(I);
951  }
952 
953 private:
954  std::bitset<32> StringLiterals;
955 };
956 
957 /// ParsedAttributes - A collection of parsed attributes. Currently
958 /// we don't differentiate between the various attribute syntaxes,
959 /// which is basically silly.
960 ///
961 /// Right now this is a very lightweight container, but the expectation
962 /// is that this will become significantly more serious.
964 public:
965  ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
969 
970  AttributePool &getPool() const { return pool; }
971 
973  assert(&Other != this &&
974  "ParsedAttributes can't take attributes from itself");
975  addAll(Other.begin(), Other.end());
976  Other.clearListOnly();
977  pool.takeAllFrom(Other.pool);
978  }
979 
981  assert(&Other != this &&
982  "ParsedAttributes can't take attribute from itself");
983  Other.getPool().remove(PA);
984  Other.remove(PA);
985  getPool().add(PA);
986  addAtEnd(PA);
987  }
988 
989  void clear() {
990  clearListOnly();
991  pool.clear();
992  Range = SourceRange();
993  }
994 
995  /// Add attribute with expression arguments.
997  IdentifierInfo *scopeName, SourceLocation scopeLoc,
998  ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form,
999  SourceLocation ellipsisLoc = SourceLocation()) {
1000  ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc,
1001  args, numArgs, form, ellipsisLoc);
1002  addAtEnd(attr);
1003  return attr;
1004  }
1005 
1006  /// Add availability attribute.
1008  IdentifierInfo *scopeName, SourceLocation scopeLoc,
1009  IdentifierLoc *Param, const AvailabilityChange &introduced,
1010  const AvailabilityChange &deprecated,
1011  const AvailabilityChange &obsoleted,
1012  SourceLocation unavailable, const Expr *MessageExpr,
1013  ParsedAttr::Form form, SourceLocation strict,
1014  const Expr *ReplacementExpr,
1015  IdentifierLoc *EnvironmentLoc) {
1016  ParsedAttr *attr =
1017  pool.create(attrName, attrRange, scopeName, scopeLoc, Param, introduced,
1018  deprecated, obsoleted, unavailable, MessageExpr, form,
1019  strict, ReplacementExpr, EnvironmentLoc);
1020  addAtEnd(attr);
1021  return attr;
1022  }
1023 
1024  /// Add objc_bridge_related attribute.
1026  IdentifierInfo *scopeName, SourceLocation scopeLoc,
1027  IdentifierLoc *Param1, IdentifierLoc *Param2,
1028  IdentifierLoc *Param3, ParsedAttr::Form form) {
1029  ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc,
1030  Param1, Param2, Param3, form);
1031  addAtEnd(attr);
1032  return attr;
1033  }
1034 
1035  /// Add type_tag_for_datatype attribute.
1036  ParsedAttr *
1038  IdentifierInfo *scopeName, SourceLocation scopeLoc,
1039  IdentifierLoc *argumentKind,
1040  ParsedType matchingCType, bool layoutCompatible,
1041  bool mustBeNull, ParsedAttr::Form form) {
1042  ParsedAttr *attr = pool.createTypeTagForDatatype(
1043  attrName, attrRange, scopeName, scopeLoc, argumentKind, matchingCType,
1044  layoutCompatible, mustBeNull, form);
1045  addAtEnd(attr);
1046  return attr;
1047  }
1048 
1049  /// Add an attribute with a single type argument.
1051  IdentifierInfo *scopeName, SourceLocation scopeLoc,
1052  ParsedType typeArg, ParsedAttr::Form formUsed,
1053  SourceLocation ellipsisLoc = SourceLocation()) {
1054  ParsedAttr *attr =
1055  pool.createTypeAttribute(attrName, attrRange, scopeName, scopeLoc,
1056  typeArg, formUsed, ellipsisLoc);
1057  addAtEnd(attr);
1058  return attr;
1059  }
1060 
1061  /// Add microsoft __delspec(property) attribute.
1062  ParsedAttr *
1064  IdentifierInfo *scopeName, SourceLocation scopeLoc,
1065  IdentifierInfo *getterId, IdentifierInfo *setterId,
1066  ParsedAttr::Form formUsed) {
1067  ParsedAttr *attr = pool.createPropertyAttribute(
1068  attrName, attrRange, scopeName, scopeLoc, getterId, setterId, formUsed);
1069  addAtEnd(attr);
1070  return attr;
1071  }
1072 
1073 private:
1074  mutable AttributePool pool;
1075 };
1076 
1077 /// Consumes the attributes from `First` and `Second` and concatenates them into
1078 /// `Result`. Sets `Result.Range` to the combined range of `First` and `Second`.
1079 void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &Second,
1080  ParsedAttributes &Result);
1081 
1082 /// These constants match the enumerated choices of
1083 /// err_attribute_argument_n_type and err_attribute_argument_type.
1091 };
1092 
1093 /// These constants match the enumerated choices of
1094 /// warn_attribute_wrong_decl_type and err_attribute_wrong_decl_type.
1109 };
1110 
1112  const ParsedAttr &At) {
1113  DB.AddTaggedVal(reinterpret_cast<uint64_t>(At.getAttrName()),
1115  return DB;
1116 }
1117 
1119  const ParsedAttr *At) {
1120  DB.AddTaggedVal(reinterpret_cast<uint64_t>(At->getAttrName()),
1122  return DB;
1123 }
1124 
1125 /// AttributeCommonInfo has a non-explicit constructor which takes an
1126 /// SourceRange as its only argument, this constructor has many uses so making
1127 /// it explicit is hard. This constructor causes ambiguity with
1128 /// DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, SourceRange R).
1129 /// We use SFINAE to disable any conversion and remove any ambiguity.
1130 template <
1131  typename ACI,
1132  std::enable_if_t<std::is_same<ACI, AttributeCommonInfo>::value, int> = 0>
1134  const ACI &CI) {
1135  DB.AddTaggedVal(reinterpret_cast<uint64_t>(CI.getAttrName()),
1137  return DB;
1138 }
1139 
1140 template <
1141  typename ACI,
1142  std::enable_if_t<std::is_same<ACI, AttributeCommonInfo>::value, int> = 0>
1144  const ACI *CI) {
1145  DB.AddTaggedVal(reinterpret_cast<uint64_t>(CI->getAttrName()),
1147  return DB;
1148 }
1149 
1150 } // namespace clang
1151 
1152 #endif // LLVM_CLANG_SEMA_PARSEDATTR_H
Defines the Diagnostic-related interfaces.
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1125
llvm::MachO::Target Target
Definition: MachO.h:50
SourceRange Range
Definition: SemaObjC.cpp:754
SourceLocation Loc
Definition: SemaObjC.cpp:755
Defines the clang::SourceLocation class and associated facilities.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__device__ __2f16 b
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
Combines information about the source-code form of an attribute, including its syntax and spelling.
const IdentifierInfo * getAttrName() const
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
Definition: ParsedAttr.h:644
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::Form form, SourceLocation strict, const Expr *ReplacementExpr, IdentifierLoc *EnvironmentLoc)
Definition: ParsedAttr.h:770
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, ParsedAttr::Form form)
Definition: ParsedAttr.h:786
AttributeFactory & getFactory() const
Definition: ParsedAttr.h:740
ParsedAttr * createPropertyAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Form formUsed)
Definition: ParsedAttr.h:825
AttributePool(AttributePool &&pool)=default
Move the given pool's allocations to this pool.
AttributePool(AttributeFactory &factory)
Create a new pool for a factory.
Definition: ParsedAttr.h:724
ParsedAttr * create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Definition: ParsedAttr.h:757
AttributePool & operator=(const AttributePool &)=delete
ParsedAttr * createTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form)
Definition: ParsedAttr.h:799
AttributePool(const AttributePool &)=delete
AttributePool & operator=(AttributePool &&pool)=delete
void takeAllFrom(AttributePool &pool)
Take the given pool's allocations and add them to this pool.
Definition: ParsedAttr.h:748
ParsedAttr * createTypeAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, ParsedAttr::Form formUsed, SourceLocation ellipsisLoc)
Definition: ParsedAttr.h:810
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
@ ak_identifierinfo
IdentifierInfo.
Definition: Diagnostic.h:222
This represents one expression.
Definition: Expr.h:110
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:482
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:129
bool isPackExpansion() const
Definition: ParsedAttr.h:382
IdentifierInfo * getMacroIdentifier() const
Return the macro identifier if this attribute was declared in a macro.
Definition: ParsedAttr.h:506
const ParsedType & getMatchingCType() const
Definition: ParsedAttr.h:458
IdentifierLoc * getArgAsIdent(unsigned Arg) const
Definition: ParsedAttr.h:406
ParsedAttr(ParsedAttr &&)=delete
LangAS asSYCLLangAS() const
If this is an OpenCL address space attribute, returns its SYCL representation in LangAS,...
Definition: ParsedAttr.h:599
bool hasParsedType() const
Definition: ParsedAttr.h:352
const IdentifierLoc * getEnvironment() const
Definition: ParsedAttr.h:452
Expr * getArgAsExpr(unsigned Arg) const
Definition: ParsedAttr.h:398
void setInvalid(bool b=true) const
Definition: ParsedAttr.h:360
ParsedAttr & operator=(ParsedAttr &&)=delete
bool hasMacroIdentifier() const
Returns true if this attribute was declared in a macro.
Definition: ParsedAttr.h:502
const ParsedAttrInfo & getInfo() const
Definition: ParsedAttr.h:635
bool hasProcessingCache() const
Definition: ParsedAttr.h:362
SourceLocation getUnavailableLoc() const
Definition: ParsedAttr.h:434
unsigned getProcessingCache() const
Definition: ParsedAttr.h:364
LangAS asOpenCLLangAS() const
If this is an OpenCL address space attribute, returns its representation in LangAS,...
Definition: ParsedAttr.h:576
SourceLocation getStrictLoc() const
Definition: ParsedAttr.h:428
ParsedAttr & operator=(const ParsedAttr &)=delete
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
Definition: ParsedAttr.h:386
bool isArgIdent(unsigned Arg) const
Definition: ParsedAttr.h:402
IdentifierInfo * getPropertyDataSetter() const
Definition: ParsedAttr.h:487
bool getMustBeNull() const
Definition: ParsedAttr.h:470
bool diagnoseMutualExclusion(class Sema &S, const Stmt *St) const
Definition: ParsedAttr.h:542
bool isUsedAsTypeAttr() const
Definition: ParsedAttr.h:374
bool isPragmaClangAttribute() const
True if the attribute is specified using '#pragma clang attribute'.
Definition: ParsedAttr.h:378
const AvailabilityChange & getAvailabilityObsoleted() const
Definition: ParsedAttr.h:422
AttributeCommonInfo::Kind getKind() const
Definition: ParsedAttr.h:632
void setProcessingCache(unsigned value) const
Definition: ParsedAttr.h:369
const Expr * getMessageExpr() const
Definition: ParsedAttr.h:440
SourceLocation getMacroExpansionLoc() const
Definition: ParsedAttr.h:508
ParsedAttr(const ParsedAttr &)=delete
bool isArgExpr(unsigned Arg) const
Definition: ParsedAttr.h:394
const AvailabilityChange & getAvailabilityDeprecated() const
Definition: ParsedAttr.h:416
bool getLayoutCompatible() const
Definition: ParsedAttr.h:464
void setUsedAsTypeAttr(bool Used=true)
Definition: ParsedAttr.h:375
bool isDeclspecPropertyAttribute() const
Is this the Microsoft __declspec(property) attribute?
Definition: ParsedAttr.h:355
const Expr * getReplacementExpr() const
Definition: ParsedAttr.h:446
IdentifierInfo * getPropertyDataGetter() const
Definition: ParsedAttr.h:481
ArgsUnion getArg(unsigned Arg) const
getArg - Return the specified argument.
Definition: ParsedAttr.h:389
SourceLocation getEllipsisLoc() const
Definition: ParsedAttr.h:383
void setMacroIdentifier(IdentifierInfo *MacroName, SourceLocation Loc)
Set the macro identifier info object that this parsed attribute was declared in if it was declared in...
Definition: ParsedAttr.h:496
LangAS asHLSLLangAS() const
If this is an HLSL address space attribute, returns its representation in LangAS, otherwise returns d...
Definition: ParsedAttr.h:623
const AvailabilityChange & getAvailabilityIntroduced() const
Definition: ParsedAttr.h:410
~ParsedAttr()=delete
bool isInvalid() const
Definition: ParsedAttr.h:359
void setIsPragmaClangAttribute()
Definition: ParsedAttr.h:380
const ParsedType & getTypeArg() const
Definition: ParsedAttr.h:476
static const ParsedAttributesView & none()
Definition: ParsedAttr.h:843
bool hasMSPropertyAttr() const
Definition: ParsedAttr.h:937
const_iterator begin() const
Definition: ParsedAttr.h:902
void addAll(const_iterator B, const_iterator E)
Definition: ParsedAttr.h:889
void addAllAtEnd(const_iterator B, const_iterator E)
Definition: ParsedAttr.h:897
void addAtEnd(ParsedAttr *newAttr)
Definition: ParsedAttr.h:853
void addAll(iterator B, iterator E)
Definition: ParsedAttr.h:885
bool hasAttribute(ParsedAttr::Kind K) const
Definition: ParsedAttr.h:923
ParsedAttr & operator[](SizeType pos)
Definition: ParsedAttr.h:850
const ParsedAttr & operator[](SizeType pos) const
Definition: ParsedAttr.h:851
const ParsedAttr & front() const
Definition: ParsedAttr.h:910
const_iterator end() const
Definition: ParsedAttr.h:904
const ParsedAttr * getMSPropertyAttr() const
Definition: ParsedAttr.h:929
void remove(ParsedAttr *ToBeRemoved)
Definition: ParsedAttr.h:858
void addAllAtEnd(iterator B, iterator E)
Definition: ParsedAttr.h:893
SizeType size() const
Definition: ParsedAttr.h:849
const ParsedAttr & back() const
Definition: ParsedAttr.h:918
ParsedAttributes - A collection of parsed attributes.
Definition: ParsedAttr.h:963
ParsedAttributes & operator=(const ParsedAttributes &)=delete
void takeOneFrom(ParsedAttributes &Other, ParsedAttr *PA)
Definition: ParsedAttr.h:980
ParsedAttr * addNewTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form)
Add type_tag_for_datatype attribute.
Definition: ParsedAttr.h:1037
ParsedAttr * addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Form formUsed)
Add microsoft __delspec(property) attribute.
Definition: ParsedAttr.h:1063
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::Form form, SourceLocation strict, const Expr *ReplacementExpr, IdentifierLoc *EnvironmentLoc)
Add availability attribute.
Definition: ParsedAttr.h:1007
ParsedAttr * addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, ParsedAttr::Form formUsed, SourceLocation ellipsisLoc=SourceLocation())
Add an attribute with a single type argument.
Definition: ParsedAttr.h:1050
ParsedAttributes(const ParsedAttributes &)=delete
AttributePool & getPool() const
Definition: ParsedAttr.h:970
void takeAllFrom(ParsedAttributes &Other)
Definition: ParsedAttr.h:972
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, IdentifierLoc *Param3, ParsedAttr::Form form)
Add objc_bridge_related attribute.
Definition: ParsedAttr.h:1025
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
Definition: ParsedAttr.h:996
ParsedAttributes(AttributeFactory &factory)
Definition: ParsedAttr.h:965
ParsedAttributes(ParsedAttributes &&G)=default
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:462
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition: Stmt.h:84
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1121
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
Definition: Diagnostic.h:1195
Exposes information about the current target.
Definition: TargetInfo.h:218
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
SubjectMatchRule
A list of all the recognized kinds of attributes.
@ NumAvailabilitySlots
Definition: ParsedAttr.h:64
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
ASTEdit remove(RangeSelector S)
Removes the source selected by S.
The JSON file list parser is used to communicate input to InstallAPI.
AttributeDeclKind
These constants match the enumerated choices of warn_attribute_wrong_decl_type and err_attribute_wron...
Definition: ParsedAttr.h:1095
@ ExpectedFunctionMethodOrParameter
Definition: ParsedAttr.h:1101
@ ExpectedFunctionWithProtoType
Definition: ParsedAttr.h:1108
@ ExpectedFunctionMethodOrBlock
Definition: ParsedAttr.h:1100
@ ExpectedTypeOrNamespace
Definition: ParsedAttr.h:1105
@ ExpectedVariableFieldOrTag
Definition: ParsedAttr.h:1104
@ ExpectedVariableOrField
Definition: ParsedAttr.h:1103
@ ExpectedUnion
Definition: ParsedAttr.h:1097
@ ExpectedFunctionOrMethod
Definition: ParsedAttr.h:1099
@ ExpectedVariable
Definition: ParsedAttr.h:1102
@ ExpectedVariableOrFunction
Definition: ParsedAttr.h:1098
@ ExpectedKernelFunction
Definition: ParsedAttr.h:1107
@ ExpectedFunctionVariableOrClass
Definition: ParsedAttr.h:1106
@ ExpectedFunction
Definition: ParsedAttr.h:1096
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
Definition: ParsedAttr.h:113
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &Second, ParsedAttributes &Result)
Consumes the attributes from First and Second and concatenates them into Result.
Definition: ParsedAttr.cpp:318
AttributeArgumentNType
These constants match the enumerated choices of err_attribute_argument_n_type and err_attribute_argum...
Definition: ParsedAttr.h:1084
@ AANT_ArgumentIntegerConstant
Definition: ParsedAttr.h:1086
@ AANT_ArgumentBuiltinFunction
Definition: ParsedAttr.h:1090
@ AANT_ArgumentIntOrBool
Definition: ParsedAttr.h:1085
@ AANT_ArgumentConstantExpr
Definition: ParsedAttr.h:1089
@ AANT_ArgumentIdentifier
Definition: ParsedAttr.h:1088
@ AANT_ArgumentString
Definition: ParsedAttr.h:1087
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition: Ownership.h:229
@ Other
Other implicit parameter.
unsigned long uint64_t
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
Represents information about a change in availability for an entity, which is part of the encoding of...
Definition: ParsedAttr.h:48
VersionTuple Version
The version number at which the change occurred.
Definition: ParsedAttr.h:53
bool isValid() const
Determine whether this availability change is valid.
Definition: ParsedAttr.h:59
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
Definition: ParsedAttr.h:50
SourceRange VersionRange
The source range covering the version number.
Definition: ParsedAttr.h:56
Wraps an identifier and optional source location for the identifier.
Definition: ParsedAttr.h:103
SourceLocation Loc
Definition: ParsedAttr.h:104
IdentifierInfo * Ident
Definition: ParsedAttr.h:105
unsigned AttrKind
Corresponds to the Kind enum.
ParsedAttributeArgumentsProperties(uint32_t StringLiteralBits)
Definition: ParsedAttr.h:944
bool isStringLiteralArg(unsigned I) const
Definition: ParsedAttr.h:946
const_iterator(VecTy::const_iterator I)
Definition: ParsedAttr.h:879
Describes the trailing object for Availability attribute in ParsedAttr.
Definition: ParsedAttr.h:68
AvailabilityData(const AvailabilityChange &Introduced, const AvailabilityChange &Deprecated, const AvailabilityChange &Obsoleted, SourceLocation Strict, const Expr *ReplaceExpr, const IdentifierLoc *EnvironmentLoc)
Definition: ParsedAttr.h:74
const IdentifierLoc * EnvironmentLoc
Definition: ParsedAttr.h:72
AvailabilityChange Changes[NumAvailabilitySlots]
Definition: ParsedAttr.h:69
PropertyData(IdentifierInfo *getterId, IdentifierInfo *setterId)
Definition: ParsedAttr.h:96
IdentifierInfo * GetterId
Definition: ParsedAttr.h:94