clang  9.0.0svn
DeclSpec.h
Go to the documentation of this file.
1 //===--- DeclSpec.h - Parsed declaration specifiers -------------*- 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 /// \file
10 /// This file defines the classes used to store parsed information about
11 /// declaration-specifiers and declarators.
12 ///
13 /// \verbatim
14 /// static const int volatile x, *y, *(*(*z)[10])(const void *x);
15 /// ------------------------- - -- ---------------------------
16 /// declaration-specifiers \ | /
17 /// declarators
18 /// \endverbatim
19 ///
20 //===----------------------------------------------------------------------===//
21 
22 #ifndef LLVM_CLANG_SEMA_DECLSPEC_H
23 #define LLVM_CLANG_SEMA_DECLSPEC_H
24 
25 #include "clang/AST/DeclCXX.h"
28 #include "clang/Basic/Lambda.h"
30 #include "clang/Basic/Specifiers.h"
31 #include "clang/Lex/Token.h"
32 #include "clang/Sema/Ownership.h"
33 #include "clang/Sema/ParsedAttr.h"
34 #include "llvm/ADT/SmallVector.h"
35 #include "llvm/Support/Compiler.h"
36 #include "llvm/Support/ErrorHandling.h"
37 
38 namespace clang {
39  class ASTContext;
40  class CXXRecordDecl;
41  class TypeLoc;
42  class LangOptions;
43  class IdentifierInfo;
44  class NamespaceAliasDecl;
45  class NamespaceDecl;
46  class ObjCDeclSpec;
47  class Sema;
48  class Declarator;
49  struct TemplateIdAnnotation;
50 
51 /// Represents a C++ nested-name-specifier or a global scope specifier.
52 ///
53 /// These can be in 3 states:
54 /// 1) Not present, identified by isEmpty()
55 /// 2) Present, identified by isNotEmpty()
56 /// 2.a) Valid, identified by isValid()
57 /// 2.b) Invalid, identified by isInvalid().
58 ///
59 /// isSet() is deprecated because it mostly corresponded to "valid" but was
60 /// often used as if it meant "present".
61 ///
62 /// The actual scope is described by getScopeRep().
63 class CXXScopeSpec {
64  SourceRange Range;
66 
67 public:
68  SourceRange getRange() const { return Range; }
69  void setRange(SourceRange R) { Range = R; }
70  void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
71  void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
72  SourceLocation getBeginLoc() const { return Range.getBegin(); }
73  SourceLocation getEndLoc() const { return Range.getEnd(); }
74 
75  /// Retrieve the representation of the nested-name-specifier.
77  return Builder.getRepresentation();
78  }
79 
80  /// Extend the current nested-name-specifier by another
81  /// nested-name-specifier component of the form 'type::'.
82  ///
83  /// \param Context The AST context in which this nested-name-specifier
84  /// resides.
85  ///
86  /// \param TemplateKWLoc The location of the 'template' keyword, if present.
87  ///
88  /// \param TL The TypeLoc that describes the type preceding the '::'.
89  ///
90  /// \param ColonColonLoc The location of the trailing '::'.
91  void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL,
92  SourceLocation ColonColonLoc);
93 
94  /// Extend the current nested-name-specifier by another
95  /// nested-name-specifier component of the form 'identifier::'.
96  ///
97  /// \param Context The AST context in which this nested-name-specifier
98  /// resides.
99  ///
100  /// \param Identifier The identifier.
101  ///
102  /// \param IdentifierLoc The location of the identifier.
103  ///
104  /// \param ColonColonLoc The location of the trailing '::'.
105  void Extend(ASTContext &Context, IdentifierInfo *Identifier,
107 
108  /// Extend the current nested-name-specifier by another
109  /// nested-name-specifier component of the form 'namespace::'.
110  ///
111  /// \param Context The AST context in which this nested-name-specifier
112  /// resides.
113  ///
114  /// \param Namespace The namespace.
115  ///
116  /// \param NamespaceLoc The location of the namespace name.
117  ///
118  /// \param ColonColonLoc The location of the trailing '::'.
119  void Extend(ASTContext &Context, NamespaceDecl *Namespace,
120  SourceLocation NamespaceLoc, SourceLocation ColonColonLoc);
121 
122  /// Extend the current nested-name-specifier by another
123  /// nested-name-specifier component of the form 'namespace-alias::'.
124  ///
125  /// \param Context The AST context in which this nested-name-specifier
126  /// resides.
127  ///
128  /// \param Alias The namespace alias.
129  ///
130  /// \param AliasLoc The location of the namespace alias
131  /// name.
132  ///
133  /// \param ColonColonLoc The location of the trailing '::'.
134  void Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
135  SourceLocation AliasLoc, SourceLocation ColonColonLoc);
136 
137  /// Turn this (empty) nested-name-specifier into the global
138  /// nested-name-specifier '::'.
139  void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc);
140 
141  /// Turns this (empty) nested-name-specifier into '__super'
142  /// nested-name-specifier.
143  ///
144  /// \param Context The AST context in which this nested-name-specifier
145  /// resides.
146  ///
147  /// \param RD The declaration of the class in which nested-name-specifier
148  /// appeared.
149  ///
150  /// \param SuperLoc The location of the '__super' keyword.
151  /// name.
152  ///
153  /// \param ColonColonLoc The location of the trailing '::'.
154  void MakeSuper(ASTContext &Context, CXXRecordDecl *RD,
155  SourceLocation SuperLoc, SourceLocation ColonColonLoc);
156 
157  /// Make a new nested-name-specifier from incomplete source-location
158  /// information.
159  ///
160  /// FIXME: This routine should be used very, very rarely, in cases where we
161  /// need to synthesize a nested-name-specifier. Most code should instead use
162  /// \c Adopt() with a proper \c NestedNameSpecifierLoc.
163  void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier,
164  SourceRange R);
165 
166  /// Adopt an existing nested-name-specifier (with source-range
167  /// information).
168  void Adopt(NestedNameSpecifierLoc Other);
169 
170  /// Retrieve a nested-name-specifier with location information, copied
171  /// into the given AST context.
172  ///
173  /// \param Context The context into which this nested-name-specifier will be
174  /// copied.
176 
177  /// Retrieve the location of the name in the last qualifier
178  /// in this nested name specifier.
179  ///
180  /// For example, the location of \c bar
181  /// in
182  /// \verbatim
183  /// \::foo::bar<0>::
184  /// ^~~
185  /// \endverbatim
187 
188  /// No scope specifier.
189  bool isEmpty() const { return !Range.isValid(); }
190  /// A scope specifier is present, but may be valid or invalid.
191  bool isNotEmpty() const { return !isEmpty(); }
192 
193  /// An error occurred during parsing of the scope specifier.
194  bool isInvalid() const { return isNotEmpty() && getScopeRep() == nullptr; }
195  /// A scope specifier is present, and it refers to a real scope.
196  bool isValid() const { return isNotEmpty() && getScopeRep() != nullptr; }
197 
198  /// Indicate that this nested-name-specifier is invalid.
200  assert(R.isValid() && "Must have a valid source range");
201  if (Range.getBegin().isInvalid())
202  Range.setBegin(R.getBegin());
203  Range.setEnd(R.getEnd());
204  Builder.Clear();
205  }
206 
207  /// Deprecated. Some call sites intend isNotEmpty() while others intend
208  /// isValid().
209  bool isSet() const { return getScopeRep() != nullptr; }
210 
211  void clear() {
212  Range = SourceRange();
213  Builder.Clear();
214  }
215 
216  /// Retrieve the data associated with the source-location information.
217  char *location_data() const { return Builder.getBuffer().first; }
218 
219  /// Retrieve the size of the data associated with source-location
220  /// information.
221  unsigned location_size() const { return Builder.getBuffer().second; }
222 };
223 
224 /// Captures information about "declaration specifiers".
225 ///
226 /// "Declaration specifiers" encompasses storage-class-specifiers,
227 /// type-specifiers, type-qualifiers, and function-specifiers.
228 class DeclSpec {
229 public:
230  /// storage-class-specifier
231  /// \note The order of these enumerators is important for diagnostics.
232  enum SCS {
233  SCS_unspecified = 0,
240  SCS_mutable
241  };
242 
243  // Import thread storage class specifier enumeration and constants.
244  // These can be combined with SCS_extern and SCS_static.
247  static const TSCS TSCS___thread = clang::TSCS___thread;
250 
251  // Import type specifier width enumeration and constants.
254  static const TSW TSW_short = clang::TSW_short;
255  static const TSW TSW_long = clang::TSW_long;
256  static const TSW TSW_longlong = clang::TSW_longlong;
257 
258  enum TSC {
261  TSC_complex
262  };
263 
264  // Import type specifier sign enumeration and constants.
267  static const TSS TSS_signed = clang::TSS_signed;
268  static const TSS TSS_unsigned = clang::TSS_unsigned;
269 
270  // Import type specifier type enumeration and constants.
273  static const TST TST_void = clang::TST_void;
274  static const TST TST_char = clang::TST_char;
275  static const TST TST_wchar = clang::TST_wchar;
276  static const TST TST_char8 = clang::TST_char8;
277  static const TST TST_char16 = clang::TST_char16;
278  static const TST TST_char32 = clang::TST_char32;
279  static const TST TST_int = clang::TST_int;
280  static const TST TST_int128 = clang::TST_int128;
281  static const TST TST_half = clang::TST_half;
282  static const TST TST_float = clang::TST_float;
283  static const TST TST_double = clang::TST_double;
284  static const TST TST_float16 = clang::TST_Float16;
285  static const TST TST_accum = clang::TST_Accum;
286  static const TST TST_fract = clang::TST_Fract;
287  static const TST TST_float128 = clang::TST_float128;
288  static const TST TST_bool = clang::TST_bool;
292  static const TST TST_enum = clang::TST_enum;
293  static const TST TST_union = clang::TST_union;
294  static const TST TST_struct = clang::TST_struct;
296  static const TST TST_class = clang::TST_class;
297  static const TST TST_typename = clang::TST_typename;
300  static const TST TST_decltype = clang::TST_decltype;
303  static const TST TST_auto = clang::TST_auto;
306  static const TST TST_atomic = clang::TST_atomic;
307 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
308  static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t;
309 #include "clang/Basic/OpenCLImageTypes.def"
310  static const TST TST_error = clang::TST_error;
311 
312  // type-qualifiers
313  enum TQ { // NOTE: These flags must be kept in sync with Qualifiers::TQ.
314  TQ_unspecified = 0,
315  TQ_const = 1,
316  TQ_restrict = 2,
317  TQ_volatile = 4,
318  TQ_unaligned = 8,
319  // This has no corresponding Qualifiers::TQ value, because it's not treated
320  // as a qualifier in our type system.
321  TQ_atomic = 16
322  };
323 
324  /// ParsedSpecifiers - Flags to query which specifiers were applied. This is
325  /// returned by getParsedSpecifiers.
327  PQ_None = 0,
328  PQ_StorageClassSpecifier = 1,
329  PQ_TypeSpecifier = 2,
330  PQ_TypeQualifier = 4,
331  PQ_FunctionSpecifier = 8
332  // FIXME: Attributes should be included here.
333  };
334 
335 private:
336  // storage-class-specifier
337  /*SCS*/unsigned StorageClassSpec : 3;
338  /*TSCS*/unsigned ThreadStorageClassSpec : 2;
339  unsigned SCS_extern_in_linkage_spec : 1;
340 
341  // type-specifier
342  /*TSW*/unsigned TypeSpecWidth : 2;
343  /*TSC*/unsigned TypeSpecComplex : 2;
344  /*TSS*/unsigned TypeSpecSign : 2;
345  /*TST*/unsigned TypeSpecType : 6;
346  unsigned TypeAltiVecVector : 1;
347  unsigned TypeAltiVecPixel : 1;
348  unsigned TypeAltiVecBool : 1;
349  unsigned TypeSpecOwned : 1;
350  unsigned TypeSpecPipe : 1;
351  unsigned TypeSpecSat : 1;
352 
353  // type-qualifiers
354  unsigned TypeQualifiers : 5; // Bitwise OR of TQ.
355 
356  // function-specifier
357  unsigned FS_inline_specified : 1;
358  unsigned FS_forceinline_specified: 1;
359  unsigned FS_virtual_specified : 1;
360  unsigned FS_noreturn_specified : 1;
361 
362  // friend-specifier
363  unsigned Friend_specified : 1;
364 
365  // constexpr-specifier
366  unsigned Constexpr_specified : 1;
367 
368  union {
372  };
373 
374  /// ExplicitSpecifier - Store information about explicit spicifer.
375  ExplicitSpecifier FS_explicit_specifier;
376 
377  // attributes.
378  ParsedAttributes Attrs;
379 
380  // Scope specifier for the type spec, if applicable.
381  CXXScopeSpec TypeScope;
382 
383  // SourceLocation info. These are null if the item wasn't specified or if
384  // the setting was synthesized.
385  SourceRange Range;
386 
387  SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc;
388  SourceRange TSWRange;
389  SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc, TSSatLoc;
390  /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
391  /// typename, then this is the location of the named type (if present);
392  /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
393  /// TSTNameLoc provides source range info for tag types.
394  SourceLocation TSTNameLoc;
395  SourceRange TypeofParensRange;
396  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc,
397  TQ_unalignedLoc;
398  SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc;
399  SourceLocation FS_explicitCloseParenLoc;
400  SourceLocation FS_forceinlineLoc;
401  SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc;
402  SourceLocation TQ_pipeLoc;
403 
404  WrittenBuiltinSpecs writtenBS;
405  void SaveWrittenBuiltinSpecs();
406 
407  ObjCDeclSpec *ObjCQualifiers;
408 
409  static bool isTypeRep(TST T) {
410  return (T == TST_typename || T == TST_typeofType ||
411  T == TST_underlyingType || T == TST_atomic);
412  }
413  static bool isExprRep(TST T) {
414  return (T == TST_typeofExpr || T == TST_decltype);
415  }
416 
417  DeclSpec(const DeclSpec &) = delete;
418  void operator=(const DeclSpec &) = delete;
419 public:
420  static bool isDeclRep(TST T) {
421  return (T == TST_enum || T == TST_struct ||
422  T == TST_interface || T == TST_union ||
423  T == TST_class);
424  }
425 
427  : StorageClassSpec(SCS_unspecified),
428  ThreadStorageClassSpec(TSCS_unspecified),
429  SCS_extern_in_linkage_spec(false), TypeSpecWidth(TSW_unspecified),
430  TypeSpecComplex(TSC_unspecified), TypeSpecSign(TSS_unspecified),
431  TypeSpecType(TST_unspecified), TypeAltiVecVector(false),
432  TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false),
433  TypeSpecPipe(false), TypeSpecSat(false), TypeQualifiers(TQ_unspecified),
434  FS_inline_specified(false), FS_forceinline_specified(false),
435  FS_virtual_specified(false), FS_noreturn_specified(false),
436  Friend_specified(false), Constexpr_specified(false),
437  FS_explicit_specifier(), Attrs(attrFactory), writtenBS(),
438  ObjCQualifiers(nullptr) {}
439 
440  // storage-class-specifier
441  SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
443  return (TSCS)ThreadStorageClassSpec;
444  }
445  bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
447  SCS_extern_in_linkage_spec = Value;
448  }
449 
450  SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
452  return ThreadStorageClassSpecLoc;
453  }
454 
456  StorageClassSpec = DeclSpec::SCS_unspecified;
457  ThreadStorageClassSpec = DeclSpec::TSCS_unspecified;
458  SCS_extern_in_linkage_spec = false;
459  StorageClassSpecLoc = SourceLocation();
460  ThreadStorageClassSpecLoc = SourceLocation();
461  }
462 
464  TypeSpecType = DeclSpec::TST_unspecified;
465  TypeSpecOwned = false;
466  TSTLoc = SourceLocation();
467  }
468 
469  // type-specifier
470  TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; }
471  TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
472  TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; }
473  TST getTypeSpecType() const { return (TST)TypeSpecType; }
474  bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
475  bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
476  bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
477  bool isTypeSpecOwned() const { return TypeSpecOwned; }
478  bool isTypeRep() const { return isTypeRep((TST) TypeSpecType); }
479  bool isTypeSpecPipe() const { return TypeSpecPipe; }
480  bool isTypeSpecSat() const { return TypeSpecSat; }
481 
483  assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
484  return TypeRep;
485  }
486  Decl *getRepAsDecl() const {
487  assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
488  return DeclRep;
489  }
490  Expr *getRepAsExpr() const {
491  assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
492  return ExprRep;
493  }
494  CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
495  const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
496 
497  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
498  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
499  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
500 
501  SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); }
502  SourceRange getTypeSpecWidthRange() const { return TSWRange; }
503  SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
504  SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
505  SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
506  SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
507  SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; }
508 
510  assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename);
511  return TSTNameLoc;
512  }
513 
514  SourceRange getTypeofParensRange() const { return TypeofParensRange; }
515  void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; }
516 
517  bool hasAutoTypeSpec() const {
518  return (TypeSpecType == TST_auto || TypeSpecType == TST_auto_type ||
519  TypeSpecType == TST_decltype_auto);
520  }
521 
522  bool hasTagDefinition() const;
523 
524  /// Turn a type-specifier-type into a string like "_Bool" or "union".
525  static const char *getSpecifierName(DeclSpec::TST T,
526  const PrintingPolicy &Policy);
527  static const char *getSpecifierName(DeclSpec::TQ Q);
528  static const char *getSpecifierName(DeclSpec::TSS S);
529  static const char *getSpecifierName(DeclSpec::TSC C);
530  static const char *getSpecifierName(DeclSpec::TSW W);
531  static const char *getSpecifierName(DeclSpec::SCS S);
532  static const char *getSpecifierName(DeclSpec::TSCS S);
533 
534  // type-qualifiers
535 
536  /// getTypeQualifiers - Return a set of TQs.
537  unsigned getTypeQualifiers() const { return TypeQualifiers; }
538  SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
539  SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
540  SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
541  SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; }
542  SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; }
543  SourceLocation getPipeLoc() const { return TQ_pipeLoc; }
544 
545  /// Clear out all of the type qualifiers.
547  TypeQualifiers = 0;
548  TQ_constLoc = SourceLocation();
549  TQ_restrictLoc = SourceLocation();
550  TQ_volatileLoc = SourceLocation();
551  TQ_atomicLoc = SourceLocation();
552  TQ_unalignedLoc = SourceLocation();
553  TQ_pipeLoc = SourceLocation();
554  }
555 
556  // function-specifier
557  bool isInlineSpecified() const {
558  return FS_inline_specified | FS_forceinline_specified;
559  }
561  return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc;
562  }
563 
565  return FS_explicit_specifier;
566  }
567 
568  bool isVirtualSpecified() const { return FS_virtual_specified; }
569  SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
570 
571  bool hasExplicitSpecifier() const {
572  return FS_explicit_specifier.isSpecified();
573  }
574  SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
576  return FS_explicit_specifier.getExpr()
577  ? SourceRange(FS_explicitLoc, FS_explicitCloseParenLoc)
578  : SourceRange(FS_explicitLoc);
579  }
580 
581  bool isNoreturnSpecified() const { return FS_noreturn_specified; }
582  SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; }
583 
585  FS_inline_specified = false;
586  FS_inlineLoc = SourceLocation();
587  FS_forceinline_specified = false;
588  FS_forceinlineLoc = SourceLocation();
589  FS_virtual_specified = false;
590  FS_virtualLoc = SourceLocation();
591  FS_explicit_specifier = ExplicitSpecifier();
592  FS_explicitLoc = SourceLocation();
593  FS_explicitCloseParenLoc = SourceLocation();
594  FS_noreturn_specified = false;
595  FS_noreturnLoc = SourceLocation();
596  }
597 
598  /// This method calls the passed in handler on each CVRU qual being
599  /// set.
600  /// Handle - a handler to be invoked.
601  void forEachCVRUQualifier(
602  llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
603 
604  /// This method calls the passed in handler on each qual being
605  /// set.
606  /// Handle - a handler to be invoked.
607  void forEachQualifier(
608  llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
609 
610  /// Return true if any type-specifier has been found.
611  bool hasTypeSpecifier() const {
612  return getTypeSpecType() != DeclSpec::TST_unspecified ||
613  getTypeSpecWidth() != DeclSpec::TSW_unspecified ||
614  getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
615  getTypeSpecSign() != DeclSpec::TSS_unspecified;
616  }
617 
618  /// Return a bitmask of which flavors of specifiers this
619  /// DeclSpec includes.
620  unsigned getParsedSpecifiers() const;
621 
622  /// isEmpty - Return true if this declaration specifier is completely empty:
623  /// no tokens were parsed in the production of it.
624  bool isEmpty() const {
625  return getParsedSpecifiers() == DeclSpec::PQ_None;
626  }
627 
628  void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
629  void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
630 
631  /// These methods set the specified attribute of the DeclSpec and
632  /// return false if there was no error. If an error occurs (for
633  /// example, if we tried to set "auto" on a spec with "extern"
634  /// already set), they return true and set PrevSpec and DiagID
635  /// such that
636  /// Diag(Loc, DiagID) << PrevSpec;
637  /// will yield a useful result.
638  ///
639  /// TODO: use a more general approach that still allows these
640  /// diagnostics to be ignored when desired.
641  bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
642  const char *&PrevSpec, unsigned &DiagID,
643  const PrintingPolicy &Policy);
644  bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
645  const char *&PrevSpec, unsigned &DiagID);
646  bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec,
647  unsigned &DiagID, const PrintingPolicy &Policy);
648  bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
649  unsigned &DiagID);
650  bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec,
651  unsigned &DiagID);
652  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
653  unsigned &DiagID, const PrintingPolicy &Policy);
654  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
655  unsigned &DiagID, ParsedType Rep,
656  const PrintingPolicy &Policy);
657  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
658  unsigned &DiagID, Decl *Rep, bool Owned,
659  const PrintingPolicy &Policy);
660  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
661  SourceLocation TagNameLoc, const char *&PrevSpec,
662  unsigned &DiagID, ParsedType Rep,
663  const PrintingPolicy &Policy);
664  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
665  SourceLocation TagNameLoc, const char *&PrevSpec,
666  unsigned &DiagID, Decl *Rep, bool Owned,
667  const PrintingPolicy &Policy);
668 
669  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
670  unsigned &DiagID, Expr *Rep,
671  const PrintingPolicy &policy);
672  bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
673  const char *&PrevSpec, unsigned &DiagID,
674  const PrintingPolicy &Policy);
675  bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
676  const char *&PrevSpec, unsigned &DiagID,
677  const PrintingPolicy &Policy);
678  bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
679  const char *&PrevSpec, unsigned &DiagID,
680  const PrintingPolicy &Policy);
681  bool SetTypePipe(bool isPipe, SourceLocation Loc,
682  const char *&PrevSpec, unsigned &DiagID,
683  const PrintingPolicy &Policy);
684  bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
685  unsigned &DiagID);
686  bool SetTypeSpecError();
687  void UpdateDeclRep(Decl *Rep) {
688  assert(isDeclRep((TST) TypeSpecType));
689  DeclRep = Rep;
690  }
692  assert(isTypeRep((TST) TypeSpecType));
693  TypeRep = Rep;
694  }
695  void UpdateExprRep(Expr *Rep) {
696  assert(isExprRep((TST) TypeSpecType));
697  ExprRep = Rep;
698  }
699 
700  bool SetTypeQual(TQ T, SourceLocation Loc);
701 
702  bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
703  unsigned &DiagID, const LangOptions &Lang);
704 
705  bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
706  unsigned &DiagID);
707  bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec,
708  unsigned &DiagID);
709  bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
710  unsigned &DiagID);
711  bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
712  unsigned &DiagID, ExplicitSpecifier ExplicitSpec,
713  SourceLocation CloseParenLoc);
714  bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec,
715  unsigned &DiagID);
716 
717  bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
718  unsigned &DiagID);
719  bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
720  unsigned &DiagID);
721  bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
722  unsigned &DiagID);
723 
724  bool isFriendSpecified() const { return Friend_specified; }
725  SourceLocation getFriendSpecLoc() const { return FriendLoc; }
726 
727  bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); }
728  SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; }
729 
730  bool isConstexprSpecified() const { return Constexpr_specified; }
731  SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
732 
734  Constexpr_specified = false;
735  ConstexprLoc = SourceLocation();
736  }
737 
739  return Attrs.getPool();
740  }
741 
742  /// Concatenates two attribute lists.
743  ///
744  /// The GCC attribute syntax allows for the following:
745  ///
746  /// \code
747  /// short __attribute__(( unused, deprecated ))
748  /// int __attribute__(( may_alias, aligned(16) )) var;
749  /// \endcode
750  ///
751  /// This declares 4 attributes using 2 lists. The following syntax is
752  /// also allowed and equivalent to the previous declaration.
753  ///
754  /// \code
755  /// short __attribute__((unused)) __attribute__((deprecated))
756  /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
757  /// \endcode
758  ///
760  Attrs.addAll(AL.begin(), AL.end());
761  }
762 
763  bool hasAttributes() const { return !Attrs.empty(); }
764 
765  ParsedAttributes &getAttributes() { return Attrs; }
766  const ParsedAttributes &getAttributes() const { return Attrs; }
767 
769  Attrs.takeAllFrom(attrs);
770  }
771 
772  /// Finish - This does final analysis of the declspec, issuing diagnostics for
773  /// things like "_Imaginary" (lacking an FP type). After calling this method,
774  /// DeclSpec is guaranteed self-consistent, even if an error occurred.
775  void Finish(Sema &S, const PrintingPolicy &Policy);
776 
778  return writtenBS;
779  }
780 
781  ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; }
782  void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; }
783 
784  /// Checks if this DeclSpec can stand alone, without a Declarator.
785  ///
786  /// Only tag declspecs can stand alone.
787  bool isMissingDeclaratorOk();
788 };
789 
790 /// Captures information about "declaration specifiers" specific to
791 /// Objective-C.
793 public:
794  /// ObjCDeclQualifier - Qualifier used on types in method
795  /// declarations. Not all combinations are sensible. Parameters
796  /// can be one of { in, out, inout } with one of { bycopy, byref }.
797  /// Returns can either be { oneway } or not.
798  ///
799  /// This should be kept in sync with Decl::ObjCDeclQualifier.
801  DQ_None = 0x0,
802  DQ_In = 0x1,
803  DQ_Inout = 0x2,
804  DQ_Out = 0x4,
805  DQ_Bycopy = 0x8,
806  DQ_Byref = 0x10,
807  DQ_Oneway = 0x20,
808  DQ_CSNullability = 0x40
809  };
810 
811  /// PropertyAttributeKind - list of property attributes.
812  /// Keep this list in sync with LLVM's Dwarf.h ApplePropertyAttributes.
814  DQ_PR_noattr = 0x0,
815  DQ_PR_readonly = 0x01,
816  DQ_PR_getter = 0x02,
817  DQ_PR_assign = 0x04,
818  DQ_PR_readwrite = 0x08,
819  DQ_PR_retain = 0x10,
820  DQ_PR_copy = 0x20,
821  DQ_PR_nonatomic = 0x40,
822  DQ_PR_setter = 0x80,
823  DQ_PR_atomic = 0x100,
824  DQ_PR_weak = 0x200,
825  DQ_PR_strong = 0x400,
826  DQ_PR_unsafe_unretained = 0x800,
827  DQ_PR_nullability = 0x1000,
828  DQ_PR_null_resettable = 0x2000,
829  DQ_PR_class = 0x4000
830  };
831 
833  : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr),
834  Nullability(0), GetterName(nullptr), SetterName(nullptr) { }
835 
837  return (ObjCDeclQualifier)objcDeclQualifier;
838  }
840  objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal);
841  }
843  objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier & ~DQVal);
844  }
845 
847  return ObjCPropertyAttributeKind(PropertyAttributes);
848  }
850  PropertyAttributes =
851  (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal);
852  }
853 
855  assert(((getObjCDeclQualifier() & DQ_CSNullability) ||
856  (getPropertyAttributes() & DQ_PR_nullability)) &&
857  "Objective-C declspec doesn't have nullability");
858  return static_cast<NullabilityKind>(Nullability);
859  }
860 
862  assert(((getObjCDeclQualifier() & DQ_CSNullability) ||
863  (getPropertyAttributes() & DQ_PR_nullability)) &&
864  "Objective-C declspec doesn't have nullability");
865  return NullabilityLoc;
866  }
867 
869  assert(((getObjCDeclQualifier() & DQ_CSNullability) ||
870  (getPropertyAttributes() & DQ_PR_nullability)) &&
871  "Set the nullability declspec or property attribute first");
872  Nullability = static_cast<unsigned>(kind);
873  NullabilityLoc = loc;
874  }
875 
876  const IdentifierInfo *getGetterName() const { return GetterName; }
877  IdentifierInfo *getGetterName() { return GetterName; }
878  SourceLocation getGetterNameLoc() const { return GetterNameLoc; }
880  GetterName = name;
881  GetterNameLoc = loc;
882  }
883 
884  const IdentifierInfo *getSetterName() const { return SetterName; }
885  IdentifierInfo *getSetterName() { return SetterName; }
886  SourceLocation getSetterNameLoc() const { return SetterNameLoc; }
888  SetterName = name;
889  SetterNameLoc = loc;
890  }
891 
892 private:
893  // FIXME: These two are unrelated and mutually exclusive. So perhaps
894  // we can put them in a union to reflect their mutual exclusivity
895  // (space saving is negligible).
896  unsigned objcDeclQualifier : 7;
897 
898  // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind
899  unsigned PropertyAttributes : 15;
900 
901  unsigned Nullability : 2;
902 
903  SourceLocation NullabilityLoc;
904 
905  IdentifierInfo *GetterName; // getter name or NULL if no getter
906  IdentifierInfo *SetterName; // setter name or NULL if no setter
907  SourceLocation GetterNameLoc; // location of the getter attribute's value
908  SourceLocation SetterNameLoc; // location of the setter attribute's value
909 
910 };
911 
912 /// Describes the kind of unqualified-id parsed.
913 enum class UnqualifiedIdKind {
914  /// An identifier.
916  /// An overloaded operator name, e.g., operator+.
918  /// A conversion function name, e.g., operator int.
920  /// A user-defined literal name, e.g., operator "" _i.
922  /// A constructor name.
924  /// A constructor named via a template-id.
926  /// A destructor name.
928  /// A template-id, e.g., f<int>.
930  /// An implicit 'self' parameter
932  /// A deduction-guide name (a template-name)
934 };
935 
936 /// Represents a C++ unqualified-id that has been parsed.
938 private:
939  UnqualifiedId(const UnqualifiedId &Other) = delete;
940  const UnqualifiedId &operator=(const UnqualifiedId &) = delete;
941 
942 public:
943  /// Describes the kind of unqualified-id parsed.
945 
946  struct OFI {
947  /// The kind of overloaded operator.
949 
950  /// The source locations of the individual tokens that name
951  /// the operator, e.g., the "new", "[", and "]" tokens in
952  /// operator new [].
953  ///
954  /// Different operators have different numbers of tokens in their name,
955  /// up to three. Any remaining source locations in this array will be
956  /// set to an invalid value for operators with fewer than three tokens.
957  unsigned SymbolLocations[3];
958  };
959 
960  /// Anonymous union that holds extra data associated with the
961  /// parsed unqualified-id.
962  union {
963  /// When Kind == IK_Identifier, the parsed identifier, or when
964  /// Kind == IK_UserLiteralId, the identifier suffix.
966 
967  /// When Kind == IK_OperatorFunctionId, the overloaded operator
968  /// that we parsed.
969  struct OFI OperatorFunctionId;
970 
971  /// When Kind == IK_ConversionFunctionId, the type that the
972  /// conversion function names.
974 
975  /// When Kind == IK_ConstructorName, the class-name of the type
976  /// whose constructor is being referenced.
978 
979  /// When Kind == IK_DestructorName, the type referred to by the
980  /// class-name.
982 
983  /// When Kind == IK_DeductionGuideName, the parsed template-name.
985 
986  /// When Kind == IK_TemplateId or IK_ConstructorTemplateId,
987  /// the template-id annotation that contains the template name and
988  /// template arguments.
990  };
991 
992  /// The location of the first token that describes this unqualified-id,
993  /// which will be the location of the identifier, "operator" keyword,
994  /// tilde (for a destructor), or the template name of a template-id.
996 
997  /// The location of the last token that describes this unqualified-id.
999 
1001  : Kind(UnqualifiedIdKind::IK_Identifier), Identifier(nullptr) {}
1002 
1003  /// Clear out this unqualified-id, setting it to default (invalid)
1004  /// state.
1005  void clear() {
1007  Identifier = nullptr;
1008  StartLocation = SourceLocation();
1009  EndLocation = SourceLocation();
1010  }
1011 
1012  /// Determine whether this unqualified-id refers to a valid name.
1013  bool isValid() const { return StartLocation.isValid(); }
1014 
1015  /// Determine whether this unqualified-id refers to an invalid name.
1016  bool isInvalid() const { return !isValid(); }
1017 
1018  /// Determine what kind of name we have.
1019  UnqualifiedIdKind getKind() const { return Kind; }
1021 
1022  /// Specify that this unqualified-id was parsed as an identifier.
1023  ///
1024  /// \param Id the parsed identifier.
1025  /// \param IdLoc the location of the parsed identifier.
1028  Identifier = const_cast<IdentifierInfo *>(Id);
1029  StartLocation = EndLocation = IdLoc;
1030  }
1031 
1032  /// Specify that this unqualified-id was parsed as an
1033  /// operator-function-id.
1034  ///
1035  /// \param OperatorLoc the location of the 'operator' keyword.
1036  ///
1037  /// \param Op the overloaded operator.
1038  ///
1039  /// \param SymbolLocations the locations of the individual operator symbols
1040  /// in the operator.
1041  void setOperatorFunctionId(SourceLocation OperatorLoc,
1043  SourceLocation SymbolLocations[3]);
1044 
1045  /// Specify that this unqualified-id was parsed as a
1046  /// conversion-function-id.
1047  ///
1048  /// \param OperatorLoc the location of the 'operator' keyword.
1049  ///
1050  /// \param Ty the type to which this conversion function is converting.
1051  ///
1052  /// \param EndLoc the location of the last token that makes up the type name.
1054  ParsedType Ty,
1055  SourceLocation EndLoc) {
1057  StartLocation = OperatorLoc;
1058  EndLocation = EndLoc;
1059  ConversionFunctionId = Ty;
1060  }
1061 
1062  /// Specific that this unqualified-id was parsed as a
1063  /// literal-operator-id.
1064  ///
1065  /// \param Id the parsed identifier.
1066  ///
1067  /// \param OpLoc the location of the 'operator' keyword.
1068  ///
1069  /// \param IdLoc the location of the identifier.
1071  SourceLocation IdLoc) {
1073  Identifier = const_cast<IdentifierInfo *>(Id);
1074  StartLocation = OpLoc;
1075  EndLocation = IdLoc;
1076  }
1077 
1078  /// Specify that this unqualified-id was parsed as a constructor name.
1079  ///
1080  /// \param ClassType the class type referred to by the constructor name.
1081  ///
1082  /// \param ClassNameLoc the location of the class name.
1083  ///
1084  /// \param EndLoc the location of the last token that makes up the type name.
1086  SourceLocation ClassNameLoc,
1087  SourceLocation EndLoc) {
1089  StartLocation = ClassNameLoc;
1090  EndLocation = EndLoc;
1091  ConstructorName = ClassType;
1092  }
1093 
1094  /// Specify that this unqualified-id was parsed as a
1095  /// template-id that names a constructor.
1096  ///
1097  /// \param TemplateId the template-id annotation that describes the parsed
1098  /// template-id. This UnqualifiedId instance will take ownership of the
1099  /// \p TemplateId and will free it on destruction.
1100  void setConstructorTemplateId(TemplateIdAnnotation *TemplateId);
1101 
1102  /// Specify that this unqualified-id was parsed as a destructor name.
1103  ///
1104  /// \param TildeLoc the location of the '~' that introduces the destructor
1105  /// name.
1106  ///
1107  /// \param ClassType the name of the class referred to by the destructor name.
1109  ParsedType ClassType,
1110  SourceLocation EndLoc) {
1112  StartLocation = TildeLoc;
1113  EndLocation = EndLoc;
1114  DestructorName = ClassType;
1115  }
1116 
1117  /// Specify that this unqualified-id was parsed as a template-id.
1118  ///
1119  /// \param TemplateId the template-id annotation that describes the parsed
1120  /// template-id. This UnqualifiedId instance will take ownership of the
1121  /// \p TemplateId and will free it on destruction.
1122  void setTemplateId(TemplateIdAnnotation *TemplateId);
1123 
1124  /// Specify that this unqualified-id was parsed as a template-name for
1125  /// a deduction-guide.
1126  ///
1127  /// \param Template The parsed template-name.
1128  /// \param TemplateLoc The location of the parsed template-name.
1130  SourceLocation TemplateLoc) {
1132  TemplateName = Template;
1133  StartLocation = EndLocation = TemplateLoc;
1134  }
1135 
1136  /// Return the source range that covers this unqualified-id.
1137  SourceRange getSourceRange() const LLVM_READONLY {
1138  return SourceRange(StartLocation, EndLocation);
1139  }
1140  SourceLocation getBeginLoc() const LLVM_READONLY { return StartLocation; }
1141  SourceLocation getEndLoc() const LLVM_READONLY { return EndLocation; }
1142 };
1143 
1144 /// A set of tokens that has been cached for later parsing.
1146 
1147 /// One instance of this struct is used for each type in a
1148 /// declarator that is parsed.
1149 ///
1150 /// This is intended to be a small value object.
1152  enum {
1153  Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren, Pipe
1154  } Kind;
1155 
1156  /// Loc - The place where this type was defined.
1158  /// EndLoc - If valid, the place where this chunck ends.
1160 
1162  if (EndLoc.isInvalid())
1163  return SourceRange(Loc, Loc);
1164  return SourceRange(Loc, EndLoc);
1165  }
1166 
1168 
1170  /// The type qualifiers: const/volatile/restrict/unaligned/atomic.
1171  unsigned TypeQuals : 5;
1172 
1173  /// The location of the const-qualifier, if any.
1174  unsigned ConstQualLoc;
1175 
1176  /// The location of the volatile-qualifier, if any.
1178 
1179  /// The location of the restrict-qualifier, if any.
1181 
1182  /// The location of the _Atomic-qualifier, if any.
1183  unsigned AtomicQualLoc;
1184 
1185  /// The location of the __unaligned-qualifier, if any.
1187 
1188  void destroy() {
1189  }
1190  };
1191 
1193  /// The type qualifier: restrict. [GNU] C++ extension
1194  bool HasRestrict : 1;
1195  /// True if this is an lvalue reference, false if it's an rvalue reference.
1196  bool LValueRef : 1;
1197  void destroy() {
1198  }
1199  };
1200 
1201  struct ArrayTypeInfo {
1202  /// The type qualifiers for the array:
1203  /// const/volatile/restrict/__unaligned/_Atomic.
1204  unsigned TypeQuals : 5;
1205 
1206  /// True if this dimension included the 'static' keyword.
1207  unsigned hasStatic : 1;
1208 
1209  /// True if this dimension was [*]. In this case, NumElts is null.
1210  unsigned isStar : 1;
1211 
1212  /// This is the size of the array, or null if [] or [*] was specified.
1213  /// Since the parser is multi-purpose, and we don't want to impose a root
1214  /// expression class on all clients, NumElts is untyped.
1216 
1217  void destroy() {}
1218  };
1219 
1220  /// ParamInfo - An array of paraminfo objects is allocated whenever a function
1221  /// declarator is parsed. There are two interesting styles of parameters
1222  /// here:
1223  /// K&R-style identifier lists and parameter type lists. K&R-style identifier
1224  /// lists will have information about the identifier, but no type information.
1225  /// Parameter type lists will have type info (if the actions module provides
1226  /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.
1227  struct ParamInfo {
1231 
1232  /// DefaultArgTokens - When the parameter's default argument
1233  /// cannot be parsed immediately (because it occurs within the
1234  /// declaration of a member function), it will be stored here as a
1235  /// sequence of tokens to be parsed once the class definition is
1236  /// complete. Non-NULL indicates that there is a default argument.
1237  std::unique_ptr<CachedTokens> DefaultArgTokens;
1238 
1239  ParamInfo() = default;
1241  Decl *param,
1242  std::unique_ptr<CachedTokens> DefArgTokens = nullptr)
1243  : Ident(ident), IdentLoc(iloc), Param(param),
1244  DefaultArgTokens(std::move(DefArgTokens)) {}
1245  };
1246 
1247  struct TypeAndRange {
1250  };
1251 
1253  /// hasPrototype - This is true if the function had at least one typed
1254  /// parameter. If the function is () or (a,b,c), then it has no prototype,
1255  /// and is treated as a K&R-style function.
1256  unsigned hasPrototype : 1;
1257 
1258  /// isVariadic - If this function has a prototype, and if that
1259  /// proto ends with ',...)', this is true. When true, EllipsisLoc
1260  /// contains the location of the ellipsis.
1261  unsigned isVariadic : 1;
1262 
1263  /// Can this declaration be a constructor-style initializer?
1264  unsigned isAmbiguous : 1;
1265 
1266  /// Whether the ref-qualifier (if any) is an lvalue reference.
1267  /// Otherwise, it's an rvalue reference.
1269 
1270  /// ExceptionSpecType - An ExceptionSpecificationType value.
1271  unsigned ExceptionSpecType : 4;
1272 
1273  /// DeleteParams - If this is true, we need to delete[] Params.
1274  unsigned DeleteParams : 1;
1275 
1276  /// HasTrailingReturnType - If this is true, a trailing return type was
1277  /// specified.
1279 
1280  /// The location of the left parenthesis in the source.
1281  unsigned LParenLoc;
1282 
1283  /// When isVariadic is true, the location of the ellipsis in the source.
1284  unsigned EllipsisLoc;
1285 
1286  /// The location of the right parenthesis in the source.
1287  unsigned RParenLoc;
1288 
1289  /// NumParams - This is the number of formal parameters specified by the
1290  /// declarator.
1291  unsigned NumParams;
1292 
1293  /// NumExceptionsOrDecls - This is the number of types in the
1294  /// dynamic-exception-decl, if the function has one. In C, this is the
1295  /// number of declarations in the function prototype.
1297 
1298  /// The location of the ref-qualifier, if any.
1299  ///
1300  /// If this is an invalid location, there is no ref-qualifier.
1302 
1303  /// The location of the 'mutable' qualifer in a lambda-declarator, if
1304  /// any.
1305  unsigned MutableLoc;
1306 
1307  /// The beginning location of the exception specification, if any.
1309 
1310  /// The end location of the exception specification, if any.
1312 
1313  /// Params - This is a pointer to a new[]'d array of ParamInfo objects that
1314  /// describe the parameters specified by this function declarator. null if
1315  /// there are no parameters specified.
1317 
1318  /// DeclSpec for the function with the qualifier related info.
1320 
1321  /// AtttibuteFactory for the MethodQualifiers.
1323 
1324  union {
1325  /// Pointer to a new[]'d array of TypeAndRange objects that
1326  /// contain the types in the function's dynamic exception specification
1327  /// and their locations, if there is one.
1329 
1330  /// Pointer to the expression in the noexcept-specifier of this
1331  /// function, if it has one.
1333 
1334  /// Pointer to the cached tokens for an exception-specification
1335  /// that has not yet been parsed.
1336  CachedTokens *ExceptionSpecTokens;
1337 
1338  /// Pointer to a new[]'d array of declarations that need to be available
1339  /// for lookup inside the function body, if one exists. Does not exist in
1340  /// C++.
1342  };
1343 
1344  /// If HasTrailingReturnType is true, this is the trailing return
1345  /// type specified.
1347 
1348  /// Reset the parameter list to having zero parameters.
1349  ///
1350  /// This is used in various places for error recovery.
1351  void freeParams() {
1352  for (unsigned I = 0; I < NumParams; ++I)
1353  Params[I].DefaultArgTokens.reset();
1354  if (DeleteParams) {
1355  delete[] Params;
1356  DeleteParams = false;
1357  }
1358  NumParams = 0;
1359  }
1360 
1361  void destroy() {
1362  freeParams();
1363  delete QualAttrFactory;
1364  delete MethodQualifiers;
1365  switch (getExceptionSpecType()) {
1366  default:
1367  break;
1368  case EST_Dynamic:
1369  delete[] Exceptions;
1370  break;
1371  case EST_Unparsed:
1372  delete ExceptionSpecTokens;
1373  break;
1374  case EST_None:
1375  if (NumExceptionsOrDecls != 0)
1376  delete[] DeclsInPrototype;
1377  break;
1378  }
1379  }
1380 
1382  if (!MethodQualifiers) {
1383  QualAttrFactory = new AttributeFactory();
1384  MethodQualifiers = new DeclSpec(*QualAttrFactory);
1385  }
1386  return *MethodQualifiers;
1387  }
1388 
1389  /// isKNRPrototype - Return true if this is a K&R style identifier list,
1390  /// like "void foo(a,b,c)". In a function definition, this will be followed
1391  /// by the parameter type definitions.
1392  bool isKNRPrototype() const { return !hasPrototype && NumParams != 0; }
1393 
1395  return SourceLocation::getFromRawEncoding(LParenLoc);
1396  }
1397 
1399  return SourceLocation::getFromRawEncoding(EllipsisLoc);
1400  }
1401 
1403  return SourceLocation::getFromRawEncoding(RParenLoc);
1404  }
1405 
1407  return SourceLocation::getFromRawEncoding(ExceptionSpecLocBeg);
1408  }
1409 
1411  return SourceLocation::getFromRawEncoding(ExceptionSpecLocEnd);
1412  }
1413 
1415  return SourceRange(getExceptionSpecLocBeg(), getExceptionSpecLocEnd());
1416  }
1417 
1418  /// Retrieve the location of the ref-qualifier, if any.
1420  return SourceLocation::getFromRawEncoding(RefQualifierLoc);
1421  }
1422 
1423  /// Retrieve the location of the 'const' qualifier.
1425  assert(MethodQualifiers);
1426  return MethodQualifiers->getConstSpecLoc();
1427  }
1428 
1429  /// Retrieve the location of the 'volatile' qualifier.
1431  assert(MethodQualifiers);
1432  return MethodQualifiers->getVolatileSpecLoc();
1433  }
1434 
1435  /// Retrieve the location of the 'restrict' qualifier.
1437  assert(MethodQualifiers);
1438  return MethodQualifiers->getRestrictSpecLoc();
1439  }
1440 
1441  /// Retrieve the location of the 'mutable' qualifier, if any.
1443  return SourceLocation::getFromRawEncoding(MutableLoc);
1444  }
1445 
1446  /// Determine whether this function declaration contains a
1447  /// ref-qualifier.
1448  bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
1449 
1450  /// Determine whether this lambda-declarator contains a 'mutable'
1451  /// qualifier.
1452  bool hasMutableQualifier() const { return getMutableLoc().isValid(); }
1453 
1454  /// Determine whether this method has qualifiers.
1456  return MethodQualifiers && (MethodQualifiers->getTypeQualifiers() ||
1457  MethodQualifiers->getAttributes().size());
1458  }
1459 
1460  /// Get the type of exception specification this function has.
1462  return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
1463  }
1464 
1465  /// Get the number of dynamic exception specifications.
1466  unsigned getNumExceptions() const {
1467  assert(ExceptionSpecType != EST_None);
1468  return NumExceptionsOrDecls;
1469  }
1470 
1471  /// Get the non-parameter decls defined within this function
1472  /// prototype. Typically these are tag declarations.
1474  assert(ExceptionSpecType == EST_None);
1475  return llvm::makeArrayRef(DeclsInPrototype, NumExceptionsOrDecls);
1476  }
1477 
1478  /// Determine whether this function declarator had a
1479  /// trailing-return-type.
1480  bool hasTrailingReturnType() const { return HasTrailingReturnType; }
1481 
1482  /// Get the trailing-return-type for this function declarator.
1483  ParsedType getTrailingReturnType() const { return TrailingReturnType; }
1484  };
1485 
1487  /// For now, sema will catch these as invalid.
1488  /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
1489  unsigned TypeQuals : 5;
1490 
1491  void destroy() {
1492  }
1493  };
1494 
1496  /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
1497  unsigned TypeQuals : 5;
1498  // CXXScopeSpec has a constructor, so it can't be a direct member.
1499  // So we need some pointer-aligned storage and a bit of trickery.
1500  alignas(CXXScopeSpec) char ScopeMem[sizeof(CXXScopeSpec)];
1502  return *reinterpret_cast<CXXScopeSpec *>(ScopeMem);
1503  }
1504  const CXXScopeSpec &Scope() const {
1505  return *reinterpret_cast<const CXXScopeSpec *>(ScopeMem);
1506  }
1507  void destroy() {
1508  Scope().~CXXScopeSpec();
1509  }
1510  };
1511 
1512  struct PipeTypeInfo {
1513  /// The access writes.
1514  unsigned AccessWrites : 3;
1515 
1516  void destroy() {}
1517  };
1518 
1519  union {
1527  };
1528 
1529  void destroy() {
1530  switch (Kind) {
1531  case DeclaratorChunk::Function: return Fun.destroy();
1532  case DeclaratorChunk::Pointer: return Ptr.destroy();
1533  case DeclaratorChunk::BlockPointer: return Cls.destroy();
1534  case DeclaratorChunk::Reference: return Ref.destroy();
1535  case DeclaratorChunk::Array: return Arr.destroy();
1536  case DeclaratorChunk::MemberPointer: return Mem.destroy();
1537  case DeclaratorChunk::Paren: return;
1538  case DeclaratorChunk::Pipe: return PipeInfo.destroy();
1539  }
1540  }
1541 
1542  /// If there are attributes applied to this declaratorchunk, return
1543  /// them.
1544  const ParsedAttributesView &getAttrs() const { return AttrList; }
1545  ParsedAttributesView &getAttrs() { return AttrList; }
1546 
1547  /// Return a DeclaratorChunk for a pointer.
1548  static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
1549  SourceLocation ConstQualLoc,
1550  SourceLocation VolatileQualLoc,
1551  SourceLocation RestrictQualLoc,
1552  SourceLocation AtomicQualLoc,
1553  SourceLocation UnalignedQualLoc) {
1554  DeclaratorChunk I;
1555  I.Kind = Pointer;
1556  I.Loc = Loc;
1557  I.Ptr.TypeQuals = TypeQuals;
1558  I.Ptr.ConstQualLoc = ConstQualLoc.getRawEncoding();
1559  I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding();
1560  I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding();
1561  I.Ptr.AtomicQualLoc = AtomicQualLoc.getRawEncoding();
1562  I.Ptr.UnalignedQualLoc = UnalignedQualLoc.getRawEncoding();
1563  return I;
1564  }
1565 
1566  /// Return a DeclaratorChunk for a reference.
1567  static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
1568  bool lvalue) {
1569  DeclaratorChunk I;
1570  I.Kind = Reference;
1571  I.Loc = Loc;
1572  I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
1573  I.Ref.LValueRef = lvalue;
1574  return I;
1575  }
1576 
1577  /// Return a DeclaratorChunk for an array.
1578  static DeclaratorChunk getArray(unsigned TypeQuals,
1579  bool isStatic, bool isStar, Expr *NumElts,
1580  SourceLocation LBLoc, SourceLocation RBLoc) {
1581  DeclaratorChunk I;
1582  I.Kind = Array;
1583  I.Loc = LBLoc;
1584  I.EndLoc = RBLoc;
1585  I.Arr.TypeQuals = TypeQuals;
1586  I.Arr.hasStatic = isStatic;
1587  I.Arr.isStar = isStar;
1588  I.Arr.NumElts = NumElts;
1589  return I;
1590  }
1591 
1592  /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
1593  /// "TheDeclarator" is the declarator that this will be added to.
1594  static DeclaratorChunk getFunction(bool HasProto,
1595  bool IsAmbiguous,
1596  SourceLocation LParenLoc,
1597  ParamInfo *Params, unsigned NumParams,
1598  SourceLocation EllipsisLoc,
1599  SourceLocation RParenLoc,
1600  bool RefQualifierIsLvalueRef,
1601  SourceLocation RefQualifierLoc,
1602  SourceLocation MutableLoc,
1603  ExceptionSpecificationType ESpecType,
1604  SourceRange ESpecRange,
1605  ParsedType *Exceptions,
1606  SourceRange *ExceptionRanges,
1607  unsigned NumExceptions,
1608  Expr *NoexceptExpr,
1609  CachedTokens *ExceptionSpecTokens,
1610  ArrayRef<NamedDecl *> DeclsInPrototype,
1611  SourceLocation LocalRangeBegin,
1612  SourceLocation LocalRangeEnd,
1613  Declarator &TheDeclarator,
1614  TypeResult TrailingReturnType =
1615  TypeResult(),
1616  DeclSpec *MethodQualifiers = nullptr);
1617 
1618  /// Return a DeclaratorChunk for a block.
1619  static DeclaratorChunk getBlockPointer(unsigned TypeQuals,
1620  SourceLocation Loc) {
1621  DeclaratorChunk I;
1622  I.Kind = BlockPointer;
1623  I.Loc = Loc;
1624  I.Cls.TypeQuals = TypeQuals;
1625  return I;
1626  }
1627 
1628  /// Return a DeclaratorChunk for a block.
1629  static DeclaratorChunk getPipe(unsigned TypeQuals,
1630  SourceLocation Loc) {
1631  DeclaratorChunk I;
1632  I.Kind = Pipe;
1633  I.Loc = Loc;
1634  I.Cls.TypeQuals = TypeQuals;
1635  return I;
1636  }
1637 
1639  unsigned TypeQuals,
1640  SourceLocation Loc) {
1641  DeclaratorChunk I;
1642  I.Kind = MemberPointer;
1643  I.Loc = SS.getBeginLoc();
1644  I.EndLoc = Loc;
1645  I.Mem.TypeQuals = TypeQuals;
1646  new (I.Mem.ScopeMem) CXXScopeSpec(SS);
1647  return I;
1648  }
1649 
1650  /// Return a DeclaratorChunk for a paren.
1652  SourceLocation RParenLoc) {
1653  DeclaratorChunk I;
1654  I.Kind = Paren;
1655  I.Loc = LParenLoc;
1656  I.EndLoc = RParenLoc;
1657  return I;
1658  }
1659 
1660  bool isParen() const {
1661  return Kind == Paren;
1662  }
1663 };
1664 
1665 /// A parsed C++17 decomposition declarator of the form
1666 /// '[' identifier-list ']'
1668 public:
1669  struct Binding {
1672  };
1673 
1674 private:
1675  /// The locations of the '[' and ']' tokens.
1676  SourceLocation LSquareLoc, RSquareLoc;
1677 
1678  /// The bindings.
1679  Binding *Bindings;
1680  unsigned NumBindings : 31;
1681  unsigned DeleteBindings : 1;
1682 
1683  friend class Declarator;
1684 
1685 public:
1687  : Bindings(nullptr), NumBindings(0), DeleteBindings(false) {}
1689  DecompositionDeclarator &operator=(const DecompositionDeclarator &G) = delete;
1691  if (DeleteBindings)
1692  delete[] Bindings;
1693  }
1694 
1695  void clear() {
1696  LSquareLoc = RSquareLoc = SourceLocation();
1697  if (DeleteBindings)
1698  delete[] Bindings;
1699  Bindings = nullptr;
1700  NumBindings = 0;
1701  DeleteBindings = false;
1702  }
1703 
1705  return llvm::makeArrayRef(Bindings, NumBindings);
1706  }
1707 
1708  bool isSet() const { return LSquareLoc.isValid(); }
1709 
1710  SourceLocation getLSquareLoc() const { return LSquareLoc; }
1711  SourceLocation getRSquareLoc() const { return RSquareLoc; }
1713  return SourceRange(LSquareLoc, RSquareLoc);
1714  }
1715 };
1716 
1717 /// Described the kind of function definition (if any) provided for
1718 /// a function.
1724 };
1725 
1726 enum class DeclaratorContext {
1727  FileContext, // File scope declaration.
1728  PrototypeContext, // Within a function prototype.
1729  ObjCResultContext, // An ObjC method result type.
1730  ObjCParameterContext,// An ObjC method parameter type.
1731  KNRTypeListContext, // K&R type definition list for formals.
1732  TypeNameContext, // Abstract declarator for types.
1733  FunctionalCastContext, // Type in a C++ functional cast expression.
1734  MemberContext, // Struct/Union field.
1735  BlockContext, // Declaration within a block in a function.
1736  ForContext, // Declaration within first part of a for loop.
1737  InitStmtContext, // Declaration within optional init stmt of if/switch.
1738  ConditionContext, // Condition declaration in a C++ if/switch/while/for.
1739  TemplateParamContext,// Within a template parameter list.
1740  CXXNewContext, // C++ new-expression.
1741  CXXCatchContext, // C++ catch exception-declaration
1742  ObjCCatchContext, // Objective-C catch exception-declaration
1743  BlockLiteralContext, // Block literal declarator.
1744  LambdaExprContext, // Lambda-expression declarator.
1745  LambdaExprParameterContext, // Lambda-expression parameter declarator.
1746  ConversionIdContext, // C++ conversion-type-id.
1747  TrailingReturnContext, // C++11 trailing-type-specifier.
1748  TrailingReturnVarContext, // C++11 trailing-type-specifier for variable.
1749  TemplateArgContext, // Any template argument (in template argument list).
1750  TemplateTypeArgContext, // Template type argument (in default argument).
1751  AliasDeclContext, // C++11 alias-declaration.
1752  AliasTemplateContext // C++11 alias-declaration template.
1753 };
1754 
1755 
1756 /// Information about one declarator, including the parsed type
1757 /// information and the identifier.
1758 ///
1759 /// When the declarator is fully formed, this is turned into the appropriate
1760 /// Decl object.
1761 ///
1762 /// Declarators come in two types: normal declarators and abstract declarators.
1763 /// Abstract declarators are used when parsing types, and don't have an
1764 /// identifier. Normal declarators do have ID's.
1765 ///
1766 /// Instances of this class should be a transient object that lives on the
1767 /// stack, not objects that are allocated in large quantities on the heap.
1768 class Declarator {
1769 
1770 private:
1771  const DeclSpec &DS;
1772  CXXScopeSpec SS;
1773  UnqualifiedId Name;
1774  SourceRange Range;
1775 
1776  /// Where we are parsing this declarator.
1777  DeclaratorContext Context;
1778 
1779  /// The C++17 structured binding, if any. This is an alternative to a Name.
1780  DecompositionDeclarator BindingGroup;
1781 
1782  /// DeclTypeInfo - This holds each type that the declarator includes as it is
1783  /// parsed. This is pushed from the identifier out, which means that element
1784  /// #0 will be the most closely bound to the identifier, and
1785  /// DeclTypeInfo.back() will be the least closely bound.
1786  SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
1787 
1788  /// InvalidType - Set by Sema::GetTypeForDeclarator().
1789  unsigned InvalidType : 1;
1790 
1791  /// GroupingParens - Set by Parser::ParseParenDeclarator().
1792  unsigned GroupingParens : 1;
1793 
1794  /// FunctionDefinition - Is this Declarator for a function or member
1795  /// definition and, if so, what kind?
1796  ///
1797  /// Actually a FunctionDefinitionKind.
1798  unsigned FunctionDefinition : 2;
1799 
1800  /// Is this Declarator a redeclaration?
1801  unsigned Redeclaration : 1;
1802 
1803  /// true if the declaration is preceded by \c __extension__.
1804  unsigned Extension : 1;
1805 
1806  /// Indicates whether this is an Objective-C instance variable.
1807  unsigned ObjCIvar : 1;
1808 
1809  /// Indicates whether this is an Objective-C 'weak' property.
1810  unsigned ObjCWeakProperty : 1;
1811 
1812  /// Indicates whether the InlineParams / InlineBindings storage has been used.
1813  unsigned InlineStorageUsed : 1;
1814 
1815  /// Attrs - Attributes.
1816  ParsedAttributes Attrs;
1817 
1818  /// The asm label, if specified.
1819  Expr *AsmLabel;
1820 
1821 #ifndef _MSC_VER
1822  union {
1823 #endif
1824  /// InlineParams - This is a local array used for the first function decl
1825  /// chunk to avoid going to the heap for the common case when we have one
1826  /// function chunk in the declarator.
1827  DeclaratorChunk::ParamInfo InlineParams[16];
1829 #ifndef _MSC_VER
1830  };
1831 #endif
1832 
1833  /// If this is the second or subsequent declarator in this declaration,
1834  /// the location of the comma before this declarator.
1835  SourceLocation CommaLoc;
1836 
1837  /// If provided, the source location of the ellipsis used to describe
1838  /// this declarator as a parameter pack.
1839  SourceLocation EllipsisLoc;
1840 
1841  friend struct DeclaratorChunk;
1842 
1843 public:
1845  : DS(ds), Range(ds.getSourceRange()), Context(C),
1846  InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
1847  GroupingParens(false), FunctionDefinition(FDK_Declaration),
1848  Redeclaration(false), Extension(false), ObjCIvar(false),
1849  ObjCWeakProperty(false), InlineStorageUsed(false),
1850  Attrs(ds.getAttributePool().getFactory()), AsmLabel(nullptr) {}
1851 
1853  clear();
1854  }
1855  /// getDeclSpec - Return the declaration-specifier that this declarator was
1856  /// declared with.
1857  const DeclSpec &getDeclSpec() const { return DS; }
1858 
1859  /// getMutableDeclSpec - Return a non-const version of the DeclSpec. This
1860  /// should be used with extreme care: declspecs can often be shared between
1861  /// multiple declarators, so mutating the DeclSpec affects all of the
1862  /// Declarators. This should only be done when the declspec is known to not
1863  /// be shared or when in error recovery etc.
1864  DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); }
1865 
1867  return Attrs.getPool();
1868  }
1869 
1870  /// getCXXScopeSpec - Return the C++ scope specifier (global scope or
1871  /// nested-name-specifier) that is part of the declarator-id.
1872  const CXXScopeSpec &getCXXScopeSpec() const { return SS; }
1873  CXXScopeSpec &getCXXScopeSpec() { return SS; }
1874 
1875  /// Retrieve the name specified by this declarator.
1876  UnqualifiedId &getName() { return Name; }
1877 
1879  return BindingGroup;
1880  }
1881 
1882  DeclaratorContext getContext() const { return Context; }
1883 
1884  bool isPrototypeContext() const {
1885  return (Context == DeclaratorContext::PrototypeContext ||
1889  }
1890 
1891  /// Get the source range that spans this declarator.
1892  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
1893  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
1894  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
1895 
1896  void SetSourceRange(SourceRange R) { Range = R; }
1897  /// SetRangeBegin - Set the start of the source range to Loc, unless it's
1898  /// invalid.
1900  if (!Loc.isInvalid())
1901  Range.setBegin(Loc);
1902  }
1903  /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
1905  if (!Loc.isInvalid())
1906  Range.setEnd(Loc);
1907  }
1908  /// ExtendWithDeclSpec - Extend the declarator source range to include the
1909  /// given declspec, unless its location is invalid. Adopts the range start if
1910  /// the current range start is invalid.
1911  void ExtendWithDeclSpec(const DeclSpec &DS) {
1912  SourceRange SR = DS.getSourceRange();
1913  if (Range.getBegin().isInvalid())
1914  Range.setBegin(SR.getBegin());
1915  if (!SR.getEnd().isInvalid())
1916  Range.setEnd(SR.getEnd());
1917  }
1918 
1919  /// Reset the contents of this Declarator.
1920  void clear() {
1921  SS.clear();
1922  Name.clear();
1923  Range = DS.getSourceRange();
1924  BindingGroup.clear();
1925 
1926  for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
1927  DeclTypeInfo[i].destroy();
1928  DeclTypeInfo.clear();
1929  Attrs.clear();
1930  AsmLabel = nullptr;
1931  InlineStorageUsed = false;
1932  ObjCIvar = false;
1933  ObjCWeakProperty = false;
1934  CommaLoc = SourceLocation();
1935  EllipsisLoc = SourceLocation();
1936  }
1937 
1938  /// mayOmitIdentifier - Return true if the identifier is either optional or
1939  /// not allowed. This is true for typenames, prototypes, and template
1940  /// parameter lists.
1941  bool mayOmitIdentifier() const {
1942  switch (Context) {
1950  return false;
1951 
1971  return true;
1972  }
1973  llvm_unreachable("unknown context kind!");
1974  }
1975 
1976  /// mayHaveIdentifier - Return true if the identifier is either optional or
1977  /// required. This is true for normal declarators and prototypes, but not
1978  /// typenames.
1979  bool mayHaveIdentifier() const {
1980  switch (Context) {
1993  return true;
1994 
2009  return false;
2010  }
2011  llvm_unreachable("unknown context kind!");
2012  }
2013 
2014  /// Return true if the context permits a C++17 decomposition declarator.
2016  switch (Context) {
2018  // FIXME: It's not clear that the proposal meant to allow file-scope
2019  // structured bindings, but it does.
2024  return true;
2025 
2029  // Maybe one day...
2030  return false;
2031 
2032  // These contexts don't allow any kind of non-abstract declarator.
2051  return false;
2052  }
2053  llvm_unreachable("unknown context kind!");
2054  }
2055 
2056  /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be
2057  /// followed by a C++ direct initializer, e.g. "int x(1);".
2059  if (hasGroupingParens()) return false;
2060 
2061  if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
2062  return false;
2063 
2064  if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern &&
2065  Context != DeclaratorContext::FileContext)
2066  return false;
2067 
2068  // Special names can't have direct initializers.
2070  return false;
2071 
2072  switch (Context) {
2078  return true;
2079 
2081  // This may not be followed by a direct initializer, but it can't be a
2082  // function declaration either, and we'd prefer to perform a tentative
2083  // parse in order to produce the right diagnostic.
2084  return true;
2085 
2106  return false;
2107  }
2108  llvm_unreachable("unknown context kind!");
2109  }
2110 
2111  /// isPastIdentifier - Return true if we have parsed beyond the point where
2112  /// the name would appear. (This may happen even if we haven't actually parsed
2113  /// a name, perhaps because this context doesn't require one.)
2114  bool isPastIdentifier() const { return Name.isValid(); }
2115 
2116  /// hasName - Whether this declarator has a name, which might be an
2117  /// identifier (accessible via getIdentifier()) or some kind of
2118  /// special C++ name (constructor, destructor, etc.), or a structured
2119  /// binding (which is not exactly a name, but occupies the same position).
2120  bool hasName() const {
2121  return Name.getKind() != UnqualifiedIdKind::IK_Identifier ||
2122  Name.Identifier || isDecompositionDeclarator();
2123  }
2124 
2125  /// Return whether this declarator is a decomposition declarator.
2127  return BindingGroup.isSet();
2128  }
2129 
2132  return Name.Identifier;
2133 
2134  return nullptr;
2135  }
2137 
2138  /// Set the name of this declarator to be the given identifier.
2140  Name.setIdentifier(Id, IdLoc);
2141  }
2142 
2143  /// Set the decomposition bindings for this declarator.
2144  void
2145  setDecompositionBindings(SourceLocation LSquareLoc,
2147  SourceLocation RSquareLoc);
2148 
2149  /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
2150  /// EndLoc, which should be the last token of the chunk.
2151  /// This function takes attrs by R-Value reference because it takes ownership
2152  /// of those attributes from the parameter.
2154  SourceLocation EndLoc) {
2155  DeclTypeInfo.push_back(TI);
2156  DeclTypeInfo.back().getAttrs().addAll(attrs.begin(), attrs.end());
2157  getAttributePool().takeAllFrom(attrs.getPool());
2158 
2159  if (!EndLoc.isInvalid())
2160  SetRangeEnd(EndLoc);
2161  }
2162 
2163  /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
2164  /// EndLoc, which should be the last token of the chunk.
2165  void AddTypeInfo(const DeclaratorChunk &TI, SourceLocation EndLoc) {
2166  DeclTypeInfo.push_back(TI);
2167 
2168  if (!EndLoc.isInvalid())
2169  SetRangeEnd(EndLoc);
2170  }
2171 
2172  /// Add a new innermost chunk to this declarator.
2174  DeclTypeInfo.insert(DeclTypeInfo.begin(), TI);
2175  }
2176 
2177  /// Return the number of types applied to this declarator.
2178  unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); }
2179 
2180  /// Return the specified TypeInfo from this declarator. TypeInfo #0 is
2181  /// closest to the identifier.
2182  const DeclaratorChunk &getTypeObject(unsigned i) const {
2183  assert(i < DeclTypeInfo.size() && "Invalid type chunk");
2184  return DeclTypeInfo[i];
2185  }
2187  assert(i < DeclTypeInfo.size() && "Invalid type chunk");
2188  return DeclTypeInfo[i];
2189  }
2190 
2192  typedef llvm::iterator_range<type_object_iterator> type_object_range;
2193 
2194  /// Returns the range of type objects, from the identifier outwards.
2195  type_object_range type_objects() const {
2196  return type_object_range(DeclTypeInfo.begin(), DeclTypeInfo.end());
2197  }
2198 
2200  assert(!DeclTypeInfo.empty() && "No type chunks to drop.");
2201  DeclTypeInfo.front().destroy();
2202  DeclTypeInfo.erase(DeclTypeInfo.begin());
2203  }
2204 
2205  /// Return the innermost (closest to the declarator) chunk of this
2206  /// declarator that is not a parens chunk, or null if there are no
2207  /// non-parens chunks.
2209  for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
2210  if (!DeclTypeInfo[i].isParen())
2211  return &DeclTypeInfo[i];
2212  }
2213  return nullptr;
2214  }
2215 
2216  /// Return the outermost (furthest from the declarator) chunk of
2217  /// this declarator that is not a parens chunk, or null if there are
2218  /// no non-parens chunks.
2220  for (unsigned i = DeclTypeInfo.size(), i_end = 0; i != i_end; --i) {
2221  if (!DeclTypeInfo[i-1].isParen())
2222  return &DeclTypeInfo[i-1];
2223  }
2224  return nullptr;
2225  }
2226 
2227  /// isArrayOfUnknownBound - This method returns true if the declarator
2228  /// is a declarator for an array of unknown bound (looking through
2229  /// parentheses).
2230  bool isArrayOfUnknownBound() const {
2231  const DeclaratorChunk *chunk = getInnermostNonParenChunk();
2232  return (chunk && chunk->Kind == DeclaratorChunk::Array &&
2233  !chunk->Arr.NumElts);
2234  }
2235 
2236  /// isFunctionDeclarator - This method returns true if the declarator
2237  /// is a function declarator (looking through parentheses).
2238  /// If true is returned, then the reference type parameter idx is
2239  /// assigned with the index of the declaration chunk.
2240  bool isFunctionDeclarator(unsigned& idx) const {
2241  for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
2242  switch (DeclTypeInfo[i].Kind) {
2244  idx = i;
2245  return true;
2247  continue;
2253  case DeclaratorChunk::Pipe:
2254  return false;
2255  }
2256  llvm_unreachable("Invalid type chunk");
2257  }
2258  return false;
2259  }
2260 
2261  /// isFunctionDeclarator - Once this declarator is fully parsed and formed,
2262  /// this method returns true if the identifier is a function declarator
2263  /// (looking through parentheses).
2264  bool isFunctionDeclarator() const {
2265  unsigned index;
2266  return isFunctionDeclarator(index);
2267  }
2268 
2269  /// getFunctionTypeInfo - Retrieves the function type info object
2270  /// (looking through parentheses).
2272  assert(isFunctionDeclarator() && "Not a function declarator!");
2273  unsigned index = 0;
2274  isFunctionDeclarator(index);
2275  return DeclTypeInfo[index].Fun;
2276  }
2277 
2278  /// getFunctionTypeInfo - Retrieves the function type info object
2279  /// (looking through parentheses).
2281  return const_cast<Declarator*>(this)->getFunctionTypeInfo();
2282  }
2283 
2284  /// Determine whether the declaration that will be produced from
2285  /// this declaration will be a function.
2286  ///
2287  /// A declaration can declare a function even if the declarator itself
2288  /// isn't a function declarator, if the type specifier refers to a function
2289  /// type. This routine checks for both cases.
2290  bool isDeclarationOfFunction() const;
2291 
2292  /// Return true if this declaration appears in a context where a
2293  /// function declarator would be a function declaration.
2295  if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
2296  return false;
2297 
2298  switch (Context) {
2304  return true;
2305 
2327  return false;
2328  }
2329  llvm_unreachable("unknown context kind!");
2330  }
2331 
2332  /// Determine whether this declaration appears in a context where an
2333  /// expression could appear.
2334  bool isExpressionContext() const {
2335  switch (Context) {
2339 
2340  // FIXME: sizeof(...) permits an expression.
2342 
2360  return false;
2361 
2367  return true;
2368  }
2369 
2370  llvm_unreachable("unknown context kind!");
2371  }
2372 
2373  /// Return true if a function declarator at this position would be a
2374  /// function declaration.
2376  if (!isFunctionDeclarationContext())
2377  return false;
2378 
2379  for (unsigned I = 0, N = getNumTypeObjects(); I != N; ++I)
2380  if (getTypeObject(I).Kind != DeclaratorChunk::Paren)
2381  return false;
2382 
2383  return true;
2384  }
2385 
2386  /// Determine whether a trailing return type was written (at any
2387  /// level) within this declarator.
2388  bool hasTrailingReturnType() const {
2389  for (const auto &Chunk : type_objects())
2390  if (Chunk.Kind == DeclaratorChunk::Function &&
2391  Chunk.Fun.hasTrailingReturnType())
2392  return true;
2393  return false;
2394  }
2395 
2396  /// takeAttributes - Takes attributes from the given parsed-attributes
2397  /// set and add them to this declarator.
2398  ///
2399  /// These examples both add 3 attributes to "var":
2400  /// short int var __attribute__((aligned(16),common,deprecated));
2401  /// short int x, __attribute__((aligned(16)) var
2402  /// __attribute__((common,deprecated));
2403  ///
2404  /// Also extends the range of the declarator.
2406  Attrs.takeAllFrom(attrs);
2407 
2408  if (!lastLoc.isInvalid())
2409  SetRangeEnd(lastLoc);
2410  }
2411 
2412  const ParsedAttributes &getAttributes() const { return Attrs; }
2413  ParsedAttributes &getAttributes() { return Attrs; }
2414 
2415  /// hasAttributes - do we contain any attributes?
2416  bool hasAttributes() const {
2417  if (!getAttributes().empty() || getDeclSpec().hasAttributes())
2418  return true;
2419  for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
2420  if (!getTypeObject(i).getAttrs().empty())
2421  return true;
2422  return false;
2423  }
2424 
2425  /// Return a source range list of C++11 attributes associated
2426  /// with the declarator.
2428  for (const ParsedAttr &AL : Attrs)
2429  if (AL.isCXX11Attribute())
2430  Ranges.push_back(AL.getRange());
2431  }
2432 
2433  void setAsmLabel(Expr *E) { AsmLabel = E; }
2434  Expr *getAsmLabel() const { return AsmLabel; }
2435 
2436  void setExtension(bool Val = true) { Extension = Val; }
2437  bool getExtension() const { return Extension; }
2438 
2439  void setObjCIvar(bool Val = true) { ObjCIvar = Val; }
2440  bool isObjCIvar() const { return ObjCIvar; }
2441 
2442  void setObjCWeakProperty(bool Val = true) { ObjCWeakProperty = Val; }
2443  bool isObjCWeakProperty() const { return ObjCWeakProperty; }
2444 
2445  void setInvalidType(bool Val = true) { InvalidType = Val; }
2446  bool isInvalidType() const {
2447  return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error;
2448  }
2449 
2450  void setGroupingParens(bool flag) { GroupingParens = flag; }
2451  bool hasGroupingParens() const { return GroupingParens; }
2452 
2453  bool isFirstDeclarator() const { return !CommaLoc.isValid(); }
2454  SourceLocation getCommaLoc() const { return CommaLoc; }
2455  void setCommaLoc(SourceLocation CL) { CommaLoc = CL; }
2456 
2457  bool hasEllipsis() const { return EllipsisLoc.isValid(); }
2458  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2459  void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; }
2460 
2462  FunctionDefinition = Val;
2463  }
2464 
2465  bool isFunctionDefinition() const {
2466  return getFunctionDefinitionKind() != FDK_Declaration;
2467  }
2468 
2470  return (FunctionDefinitionKind)FunctionDefinition;
2471  }
2472 
2473  /// Returns true if this declares a real member and not a friend.
2475  return getContext() == DeclaratorContext::MemberContext &&
2476  !getDeclSpec().isFriendSpecified();
2477  }
2478 
2479  /// Returns true if this declares a static member. This cannot be called on a
2480  /// declarator outside of a MemberContext because we won't know until
2481  /// redeclaration time if the decl is static.
2482  bool isStaticMember();
2483 
2484  /// Returns true if this declares a constructor or a destructor.
2485  bool isCtorOrDtor();
2486 
2487  void setRedeclaration(bool Val) { Redeclaration = Val; }
2488  bool isRedeclaration() const { return Redeclaration; }
2489 };
2490 
2491 /// This little struct is used to capture information about
2492 /// structure field declarators, which is basically just a bitfield size.
2496  explicit FieldDeclarator(const DeclSpec &DS)
2497  : D(DS, DeclaratorContext::MemberContext),
2498  BitfieldSize(nullptr) {}
2499 };
2500 
2501 /// Represents a C++11 virt-specifier-seq.
2503 public:
2504  enum Specifier {
2505  VS_None = 0,
2506  VS_Override = 1,
2507  VS_Final = 2,
2508  VS_Sealed = 4,
2509  // Represents the __final keyword, which is legal for gcc in pre-C++11 mode.
2510  VS_GNU_Final = 8
2511  };
2512 
2513  VirtSpecifiers() : Specifiers(0), LastSpecifier(VS_None) { }
2514 
2515  bool SetSpecifier(Specifier VS, SourceLocation Loc,
2516  const char *&PrevSpec);
2517 
2518  bool isUnset() const { return Specifiers == 0; }
2519 
2520  bool isOverrideSpecified() const { return Specifiers & VS_Override; }
2521  SourceLocation getOverrideLoc() const { return VS_overrideLoc; }
2522 
2523  bool isFinalSpecified() const { return Specifiers & (VS_Final | VS_Sealed | VS_GNU_Final); }
2524  bool isFinalSpelledSealed() const { return Specifiers & VS_Sealed; }
2525  SourceLocation getFinalLoc() const { return VS_finalLoc; }
2526 
2527  void clear() { Specifiers = 0; }
2528 
2529  static const char *getSpecifierName(Specifier VS);
2530 
2531  SourceLocation getFirstLocation() const { return FirstLocation; }
2532  SourceLocation getLastLocation() const { return LastLocation; }
2533  Specifier getLastSpecifier() const { return LastSpecifier; }
2534 
2535 private:
2536  unsigned Specifiers;
2537  Specifier LastSpecifier;
2538 
2539  SourceLocation VS_overrideLoc, VS_finalLoc;
2540  SourceLocation FirstLocation;
2541  SourceLocation LastLocation;
2542 };
2543 
2545  NoInit, //!< [a]
2546  CopyInit, //!< [a = b], [a = {b}]
2547  DirectInit, //!< [a(b)]
2548  ListInit //!< [a{b}]
2549 };
2550 
2551 /// Represents a complete lambda introducer.
2553  /// An individual capture in a lambda introducer.
2554  struct LambdaCapture {
2563 
2565  IdentifierInfo *Id, SourceLocation EllipsisLoc,
2566  LambdaCaptureInitKind InitKind, ExprResult Init,
2567  ParsedType InitCaptureType,
2568  SourceRange ExplicitRange)
2569  : Kind(Kind), Loc(Loc), Id(Id), EllipsisLoc(EllipsisLoc),
2570  InitKind(InitKind), Init(Init), InitCaptureType(InitCaptureType),
2571  ExplicitRange(ExplicitRange) {}
2572  };
2573 
2578 
2580  : Default(LCD_None) {}
2581 
2582  /// Append a capture in a lambda introducer.
2584  SourceLocation Loc,
2585  IdentifierInfo* Id,
2586  SourceLocation EllipsisLoc,
2587  LambdaCaptureInitKind InitKind,
2588  ExprResult Init,
2589  ParsedType InitCaptureType,
2590  SourceRange ExplicitRange) {
2591  Captures.push_back(LambdaCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init,
2592  InitCaptureType, ExplicitRange));
2593  }
2594 };
2595 
2596 } // end namespace clang
2597 
2598 #endif // LLVM_CLANG_SEMA_DECLSPEC_H
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
Definition: DeclSpec.h:1483
void ClearFunctionSpecs()
Definition: DeclSpec.h:584
AttributePool & getAttributePool() const
Definition: DeclSpec.h:1866
void setConstructorName(ParsedType ClassType, SourceLocation ClassNameLoc, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a constructor name.
Definition: DeclSpec.h:1085
unsigned UnalignedQualLoc
The location of the __unaligned-qualifier, if any.
Definition: DeclSpec.h:1186
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
Definition: DeclSpec.h:2271
unsigned MutableLoc
The location of the &#39;mutable&#39; qualifer in a lambda-declarator, if any.
Definition: DeclSpec.h:1305
unsigned RefQualifierIsLValueRef
Whether the ref-qualifier (if any) is an lvalue reference.
Definition: DeclSpec.h:1268
StringRef Identifier
Definition: Format.cpp:1714
no exception specification
void setKind(UnqualifiedIdKind kind)
Definition: DeclSpec.h:1020
SourceLocation getLastQualifierNameLoc() const
Retrieve the location of the name in the last qualifier in this nested name specifier.
Definition: DeclSpec.cpp:135
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into &#39;__super&#39; nested-name-specifier.
Definition: DeclSpec.cpp:106
void clear()
Reset the contents of this Declarator.
Definition: DeclSpec.h:1920
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
Definition: DeclSpec.h:1137
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: DeclSpec.h:836
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
Definition: DeclSpec.h:995
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
Definition: DeclSpec.h:2182
SizeType size() const
Definition: ParsedAttr.h:817
ThreadStorageClassSpecifier TSCS
Definition: DeclSpec.h:245
IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId, the identifier suffix.
Definition: DeclSpec.h:965
NullabilityKind
Describes the nullability of a particular type.
Definition: Specifiers.h:293
UnionParsedType TypeRep
Definition: DeclSpec.h:369
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:189
void setEndLoc(SourceLocation Loc)
Definition: DeclSpec.h:71
void setPropertyAttributes(ObjCPropertyAttributeKind PRVal)
Definition: DeclSpec.h:849
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
unsigned ExceptionSpecLocBeg
The beginning location of the exception specification, if any.
Definition: DeclSpec.h:1308
Captures information about "declaration specifiers" specific to Objective-C.
Definition: DeclSpec.h:792
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition: Lambda.h:22
unsigned EllipsisLoc
When isVariadic is true, the location of the ellipsis in the source.
Definition: DeclSpec.h:1284
bool isOverrideSpecified() const
Definition: DeclSpec.h:2520
SourceLocation getVolatileQualifierLoc() const
Retrieve the location of the &#39;volatile&#39; qualifier.
Definition: DeclSpec.h:1430
A constructor named via a template-id.
SourceLocation getLParenLoc() const
Definition: DeclSpec.h:1394
Declarator(const DeclSpec &ds, DeclaratorContext C)
Definition: DeclSpec.h:1844
bool hasTrailingReturnType() const
Determine whether a trailing return type was written (at any level) within this declarator.
Definition: DeclSpec.h:2388
TypeSpecifierType TST
Definition: DeclSpec.h:271
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclSpec.h:1893
One instance of this struct is used for each type in a declarator that is parsed. ...
Definition: DeclSpec.h:1151
Represent a C++ namespace.
Definition: Decl.h:514
SourceLocation EndLoc
EndLoc - If valid, the place where this chunck ends.
Definition: DeclSpec.h:1159
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
Definition: DeclSpec.h:2240
unsigned NumExceptionsOrDecls
NumExceptionsOrDecls - This is the number of types in the dynamic-exception-decl, if the function has...
Definition: DeclSpec.h:1296
NamedDecl ** DeclsInPrototype
Pointer to a new[]&#39;d array of declarations that need to be available for lookup inside the function b...
Definition: DeclSpec.h:1341
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclSpec.h:1894
LambdaCaptureInitKind InitKind
Definition: DeclSpec.h:2559
bool isTypeSpecSat() const
Definition: DeclSpec.h:480
std::unique_ptr< CachedTokens > DefaultArgTokens
DefaultArgTokens - When the parameter&#39;s default argument cannot be parsed immediately (because it occ...
Definition: DeclSpec.h:1237
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1998
bool hasExplicitSpecifier() const
Definition: DeclSpec.h:571
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name&#39;s to...
An overloaded operator name, e.g., operator+.
TSCS getThreadStorageClassSpec() const
Definition: DeclSpec.h:442
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:221
void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
Definition: DeclSpec.h:2139
SourceLocation getEndLoc() const
Definition: DeclSpec.h:73
unsigned RefQualifierLoc
The location of the ref-qualifier, if any.
Definition: DeclSpec.h:1301
SourceLocation getEllipsisLoc() const
Definition: DeclSpec.h:1398
const ParsedAttributes & getAttributes() const
Definition: DeclSpec.h:2412
SourceLocation getOverrideLoc() const
Definition: DeclSpec.h:2521
unsigned RestrictQualLoc
The location of the restrict-qualifier, if any.
Definition: DeclSpec.h:1180
bool isKNRPrototype() const
isKNRPrototype - Return true if this is a K&R style identifier list, like "void foo(a,b,c)".
Definition: DeclSpec.h:1392
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:124
std::pair< char *, unsigned > getBuffer() const
Retrieve the underlying buffer.
static const TSCS TSCS_unspecified
Definition: DeclSpec.h:246
bool isFunctionDeclarationContext() const
Return true if this declaration appears in a context where a function declarator would be a function ...
Definition: DeclSpec.h:2294
void setObjCQualifiers(ObjCDeclSpec *quals)
Definition: DeclSpec.h:782
unsigned isStar
True if this dimension was [*]. In this case, NumElts is null.
Definition: DeclSpec.h:1210
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1768
void setTypeofParensRange(SourceRange range)
Definition: DeclSpec.h:515
ObjCDeclSpec * getObjCQualifiers() const
Definition: DeclSpec.h:781
TypeSpecifierType
Specifies the kind of type.
Definition: Specifiers.h:52
SourceLocation getFinalLoc() const
Definition: DeclSpec.h:2525
RangeSelector range(RangeSelector Begin, RangeSelector End)
Selects from the start of Begin and to the end of End.
void setBegin(SourceLocation b)
bool hasTypeSpecifier() const
Return true if any type-specifier has been found.
Definition: DeclSpec.h:611
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:37
CharSourceRange getSourceRange(const SourceRange &Range)
Returns the token CharSourceRange corresponding to Range.
Definition: FixIt.h:32
bool hasMethodTypeQualifiers() const
Determine whether this method has qualifiers.
Definition: DeclSpec.h:1455
unsigned getNumExceptions() const
Get the number of dynamic exception specifications.
Definition: DeclSpec.h:1466
const IdentifierInfo * getSetterName() const
Definition: DeclSpec.h:884
enum clang::DeclaratorChunk::@217 Kind
bool mayOmitIdentifier() const
mayOmitIdentifier - Return true if the identifier is either optional or not allowed.
Definition: DeclSpec.h:1941
Information about a template-id annotation token.
IdentifierInfo * getGetterName()
Definition: DeclSpec.h:877
SourceRange getTypeSpecWidthRange() const
Definition: DeclSpec.h:502
bool isUnset() const
Definition: DeclSpec.h:2518
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:56
SourceLocation getFriendSpecLoc() const
Definition: DeclSpec.h:725
bool isRedeclaration() const
Definition: DeclSpec.h:2488
TemplateIdAnnotation * TemplateId
When Kind == IK_TemplateId or IK_ConstructorTemplateId, the template-id annotation that contains the ...
Definition: DeclSpec.h:989
C11 _Thread_local.
Definition: Specifiers.h:209
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
Definition: DeclSpec.h:1332
One of these records is kept for each identifier that is lexed.
SmallVectorImpl< DeclaratorChunk >::const_iterator type_object_iterator
Definition: DeclSpec.h:2191
SourceLocation getSetterNameLoc() const
Definition: DeclSpec.h:886
SourceLocation getExceptionSpecLocBeg() const
Definition: DeclSpec.h:1406
const WrittenBuiltinSpecs & getWrittenBuiltinSpecs() const
Definition: DeclSpec.h:777
UnionParsedType ConversionFunctionId
When Kind == IK_ConversionFunctionId, the type that the conversion function names.
Definition: DeclSpec.h:973
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclSpec.h:1141
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
void DropFirstTypeObject()
Definition: DeclSpec.h:2199
A C++ nested-name-specifier augmented with source location information.
SourceLocation getTypeSpecTypeLoc() const
Definition: DeclSpec.h:505
void setConversionFunctionId(SourceLocation OperatorLoc, ParsedType Ty, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a conversion-function-id.
Definition: DeclSpec.h:1053
TypeSpecifierSign
Specifies the signedness of a type, e.g., signed or unsigned.
Definition: Specifiers.h:40
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
DeclSpec(AttributeFactory &attrFactory)
Definition: DeclSpec.h:426
LambdaCaptureKind
The different capture forms in a lambda introducer.
Definition: Lambda.h:33
UnionParsedTemplateTy TemplateName
When Kind == IK_DeductionGuideName, the parsed template-name.
Definition: DeclSpec.h:984
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
OverloadedOperatorKind Operator
The kind of overloaded operator.
Definition: DeclSpec.h:948
Definition: Format.h:2222
bool isParen() const
Definition: DeclSpec.h:1660
bool isFunctionDefinition() const
Definition: DeclSpec.h:2465
bool hasAutoTypeSpec() const
Definition: DeclSpec.h:517
void clearObjCDeclQualifier(ObjCDeclQualifier DQVal)
Definition: DeclSpec.h:842
static const TST TST_error
Definition: DeclSpec.h:310
ExplicitSpecifier getExplicitSpecifier() const
Definition: DeclSpec.h:564
static const TSW TSW_unspecified
Definition: DeclSpec.h:253
void ClearStorageClassSpecs()
Definition: DeclSpec.h:455
static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, SourceLocation ConstQualLoc, SourceLocation VolatileQualLoc, SourceLocation RestrictQualLoc, SourceLocation AtomicQualLoc, SourceLocation UnalignedQualLoc)
Return a DeclaratorChunk for a pointer.
Definition: DeclSpec.h:1548
TSC getTypeSpecComplex() const
Definition: DeclSpec.h:471
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
SourceLocation getRestrictQualifierLoc() const
Retrieve the location of the &#39;restrict&#39; qualifier.
Definition: DeclSpec.h:1436
A user-defined literal name, e.g., operator "" _i.
void SetSourceRange(SourceRange R)
Definition: DeclSpec.h:1896
This little struct is used to capture information about structure field declarators, which is basically just a bitfield size.
Definition: DeclSpec.h:2493
bool isInvalidType() const
Definition: DeclSpec.h:2446
bool isFinalSpelledSealed() const
Definition: DeclSpec.h:2524
PointerTypeInfo Ptr
Definition: DeclSpec.h:1520
UnionParsedType DestructorName
When Kind == IK_DestructorName, the type referred to by the class-name.
Definition: DeclSpec.h:981
void setExternInLinkageSpec(bool Value)
Definition: DeclSpec.h:446
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:937
void setObjCWeakProperty(bool Val=true)
Definition: DeclSpec.h:2442
ObjCPropertyAttributeKind
PropertyAttributeKind - list of property attributes.
Definition: DeclSpec.h:813
bool isFunctionDeclaratorAFunctionDeclaration() const
Return true if a function declarator at this position would be a function declaration.
Definition: DeclSpec.h:2375
unsigned ConstQualLoc
The location of the const-qualifier, if any.
Definition: DeclSpec.h:1174
void setExtension(bool Val=true)
Definition: DeclSpec.h:2436
bool isFunctionDeclarator() const
isFunctionDeclarator - Once this declarator is fully parsed and formed, this method returns true if t...
Definition: DeclSpec.h:2264
ParamInfo(IdentifierInfo *ident, SourceLocation iloc, Decl *param, std::unique_ptr< CachedTokens > DefArgTokens=nullptr)
Definition: DeclSpec.h:1240
void SetRangeBegin(SourceLocation Loc)
SetRangeBegin - Set the start of the source range to Loc, unless it&#39;s invalid.
Definition: DeclSpec.h:1899
bool isTypeSpecPipe() const
Definition: DeclSpec.h:479
SCS
storage-class-specifier
Definition: DeclSpec.h:232
ArrayTypeInfo Arr
Definition: DeclSpec.h:1522
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Definition: DeclSpec.h:2178
void setRedeclaration(bool Val)
Definition: DeclSpec.h:2487
const ParsedAttributes & getAttributes() const
Definition: DeclSpec.h:766
void AddInnermostTypeInfo(const DeclaratorChunk &TI)
Add a new innermost chunk to this declarator.
Definition: DeclSpec.h:2173
void takeAllFrom(ParsedAttributes &attrs)
Definition: ParsedAttr.h:913
unsigned HasTrailingReturnType
HasTrailingReturnType - If this is true, a trailing return type was specified.
Definition: DeclSpec.h:1278
TSS getTypeSpecSign() const
Definition: DeclSpec.h:472
bool hasAttributes() const
Definition: DeclSpec.h:763
ActionResult< ParsedType > TypeResult
Definition: Ownership.h:265
unsigned RParenLoc
The location of the right parenthesis in the source.
Definition: DeclSpec.h:1287
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
Definition: DeclSpec.h:199
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
bool isNoreturnSpecified() const
Definition: DeclSpec.h:581
void UpdateExprRep(Expr *Rep)
Definition: DeclSpec.h:695
SourceLocation getConstSpecLoc() const
Definition: DeclSpec.h:538
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
Definition: DeclSpec.h:1872
SourceLocation getLSquareLoc() const
Definition: DeclSpec.h:1710
LambdaCaptureInitKind
Definition: DeclSpec.h:2544
bool isTypeRep() const
Definition: DeclSpec.h:478
SourceRange getSourceRange() const LLVM_READONLY
Definition: DeclSpec.h:497
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Definition: DeclSpec.cpp:142
IdentifierInfo * getIdentifier() const
Definition: DeclSpec.h:2130
UnionParsedType ConstructorName
When Kind == IK_ConstructorName, the class-name of the type whose constructor is being referenced...
Definition: DeclSpec.h:977
Class that aids in the construction of nested-name-specifiers along with source-location information ...
bool isExpressionContext() const
Determine whether this declaration appears in a context where an expression could appear...
Definition: DeclSpec.h:2334
bool isExternInLinkageSpec() const
Definition: DeclSpec.h:445
bool isFinalSpecified() const
Definition: DeclSpec.h:2523
SourceLocation getTypeSpecComplexLoc() const
Definition: DeclSpec.h:503
unsigned AccessWrites
The access writes.
Definition: DeclSpec.h:1514
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
Definition: DeclSpec.h:1864
SourceLocation getAltiVecLoc() const
Definition: DeclSpec.h:506
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:328
SourceLocation getUnalignedSpecLoc() const
Definition: DeclSpec.h:542
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Definition: DeclSpec.cpp:118
void setSetterName(IdentifierInfo *name, SourceLocation loc)
Definition: DeclSpec.h:887
void ClearConstexprSpec()
Definition: DeclSpec.h:733
bool mayBeFollowedByCXXDirectInit() const
mayBeFollowedByCXXDirectInit - Return true if the declarator can be followed by a C++ direct initiali...
Definition: DeclSpec.h:2058
bool isTypeAltiVecPixel() const
Definition: DeclSpec.h:475
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclSpec.h:1140
bool isPastIdentifier() const
isPastIdentifier - Return true if we have parsed beyond the point where the name would appear...
Definition: DeclSpec.h:2114
IdentifierInfo * getSetterName()
Definition: DeclSpec.h:885
void SetRangeStart(SourceLocation Loc)
Definition: DeclSpec.h:628
void addCapture(LambdaCaptureKind Kind, SourceLocation Loc, IdentifierInfo *Id, SourceLocation EllipsisLoc, LambdaCaptureInitKind InitKind, ExprResult Init, ParsedType InitCaptureType, SourceRange ExplicitRange)
Append a capture in a lambda introducer.
Definition: DeclSpec.h:2583
DeclSpec * MethodQualifiers
DeclSpec for the function with the qualifier related info.
Definition: DeclSpec.h:1319
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1291
const ParsedAttributesView & getAttrs() const
If there are attributes applied to this declaratorchunk, return them.
Definition: DeclSpec.h:1544
unsigned TypeQuals
The type qualifiers: const/volatile/restrict/unaligned/atomic.
Definition: DeclSpec.h:1171
bool getExtension() const
Definition: DeclSpec.h:2437
bool mayHaveDecompositionDeclarator() const
Return true if the context permits a C++17 decomposition declarator.
Definition: DeclSpec.h:2015
A conversion function name, e.g., operator int.
SourceRange getRange() const
Definition: DeclSpec.h:68
SmallVector< LambdaCapture, 4 > Captures
Definition: DeclSpec.h:2577
TST getTypeSpecType() const
Definition: DeclSpec.h:473
static bool isDeclRep(TST T)
Definition: DeclSpec.h:420
ParsedAttributes & getAttributes()
Definition: DeclSpec.h:2413
llvm::iterator_range< type_object_iterator > type_object_range
Definition: DeclSpec.h:2192
SourceRange getSourceRange() const
Definition: DeclSpec.h:1161
unsigned hasStatic
True if this dimension included the &#39;static&#39; keyword.
Definition: DeclSpec.h:1207
This represents one expression.
Definition: Expr.h:108
void setDeductionGuideName(ParsedTemplateTy Template, SourceLocation TemplateLoc)
Specify that this unqualified-id was parsed as a template-name for a deduction-guide.
Definition: DeclSpec.h:1129
UnqualifiedIdKind
Describes the kind of unqualified-id parsed.
Definition: DeclSpec.h:913
int Id
Definition: ASTDiff.cpp:190
bool isDecompositionDeclarator() const
Return whether this declarator is a decomposition declarator.
Definition: DeclSpec.h:2126
An individual capture in a lambda introducer.
Definition: DeclSpec.h:2554
DeclaratorChunk & getTypeObject(unsigned i)
Definition: DeclSpec.h:2186
unsigned VolatileQualLoc
The location of the volatile-qualifier, if any.
Definition: DeclSpec.h:1177
TypeSpecifierWidth TSW
Definition: DeclSpec.h:252
static DeclaratorChunk getPipe(unsigned TypeQuals, SourceLocation Loc)
Return a DeclaratorChunk for a block.
Definition: DeclSpec.h:1629
Specifier getLastSpecifier() const
Definition: DeclSpec.h:2533
bool isTypeAltiVecVector() const
Definition: DeclSpec.h:474
void freeParams()
Reset the parameter list to having zero parameters.
Definition: DeclSpec.h:1351
SourceLocation getVolatileSpecLoc() const
Definition: DeclSpec.h:540
SourceLocation getThreadStorageClassSpecLoc() const
Definition: DeclSpec.h:451
void ClearTypeQualifiers()
Clear out all of the type qualifiers.
Definition: DeclSpec.h:546
void clear()
Clear out this unqualified-id, setting it to default (invalid) state.
Definition: DeclSpec.h:1005
Defines an enumeration for C++ overloaded operators.
void setAsmLabel(Expr *E)
Definition: DeclSpec.h:2433
void setRange(SourceRange R)
Definition: DeclSpec.h:69
const DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo() const
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
Definition: DeclSpec.h:2280
SourceLocation getBeginLoc() const
Definition: DeclSpec.h:72
bool hasEllipsis() const
Definition: DeclSpec.h:2457
bool isConstexprSpecified() const
Definition: DeclSpec.h:730
A parsed C++17 decomposition declarator of the form &#39;[&#39; identifier-list &#39;]&#39;.
Definition: DeclSpec.h:1667
void addAll(iterator B, iterator E)
Definition: ParsedAttr.h:853
Represents a C++ template name within the type system.
Definition: TemplateName.h:187
const Expr * getExpr() const
Definition: DeclCXX.h:2007
SourceLocation getStorageClassSpecLoc() const
Definition: DeclSpec.h:450
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
Definition: DeclSpec.h:1019
void UpdateTypeRep(ParsedType Rep)
Definition: DeclSpec.h:691
CachedTokens * ExceptionSpecTokens
Pointer to the cached tokens for an exception-specification that has not yet been parsed...
Definition: DeclSpec.h:1336
bool hasAttributes() const
hasAttributes - do we contain any attributes?
Definition: DeclSpec.h:2416
bool LValueRef
True if this is an lvalue reference, false if it&#39;s an rvalue reference.
Definition: DeclSpec.h:1196
SourceLocation Loc
Loc - The place where this type was defined.
Definition: DeclSpec.h:1157
bool hasMutableQualifier() const
Determine whether this lambda-declarator contains a &#39;mutable&#39; qualifier.
Definition: DeclSpec.h:1452
DeclaratorContext
Definition: DeclSpec.h:1726
void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc, SourceLocation IdLoc)
Specific that this unqualified-id was parsed as a literal-operator-id.
Definition: DeclSpec.h:1070
void setEllipsisLoc(SourceLocation EL)
Definition: DeclSpec.h:2459
SourceLocation getEnd() const
ParsedAttributesView AttrList
Definition: DeclSpec.h:1167
const DeclaratorChunk * getOutermostNonParenChunk() const
Return the outermost (furthest from the declarator) chunk of this declarator that is not a parens chu...
Definition: DeclSpec.h:2219
bool isFriendSpecified() const
Definition: DeclSpec.h:724
Wraps an identifier and optional source location for the identifier.
Definition: ParsedAttr.h:94
SourceLocation getCommaLoc() const
Definition: DeclSpec.h:2454
bool isObjCIvar() const
Definition: DeclSpec.h:2440
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
Definition: DeclSpec.h:1013
bool isFirstDeclarator() const
Definition: DeclSpec.h:2453
UnionParsedType TrailingReturnType
If HasTrailingReturnType is true, this is the trailing return type specified.
Definition: DeclSpec.h:1346
SourceLocation getRSquareLoc() const
Definition: DeclSpec.h:1711
TypeAndRange * Exceptions
Pointer to a new[]&#39;d array of TypeAndRange objects that contain the types in the function&#39;s dynamic e...
Definition: DeclSpec.h:1328
SourceLocation getRefQualifierLoc() const
Retrieve the location of the ref-qualifier, if any.
Definition: DeclSpec.h:1419
NullabilityKind getNullability() const
Definition: DeclSpec.h:854
bool hasGroupingParens() const
Definition: DeclSpec.h:2451
SourceLocation getNoreturnSpecLoc() const
Definition: DeclSpec.h:582
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:76
ParsedAttributesView & getAttrs()
Definition: DeclSpec.h:1545
static DeclaratorChunk getParen(SourceLocation LParenLoc, SourceLocation RParenLoc)
Return a DeclaratorChunk for a paren.
Definition: DeclSpec.h:1651
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:217
ObjCDeclQualifier
ObjCDeclQualifier - Qualifier used on types in method declarations.
Definition: DeclSpec.h:800
UnqualifiedIdKind Kind
Describes the kind of unqualified-id parsed.
Definition: DeclSpec.h:944
#define false
Definition: stdbool.h:17
SourceLocation DefaultLoc
Definition: DeclSpec.h:2575
bool isArrayOfUnknownBound() const
isArrayOfUnknownBound - This method returns true if the declarator is a declarator for an array of un...
Definition: DeclSpec.h:2230
Kind
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:153
static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, bool lvalue)
Return a DeclaratorChunk for a reference.
Definition: DeclSpec.h:1567
SCS getStorageClassSpec() const
Definition: DeclSpec.h:441
SourceLocation getRParenLoc() const
Definition: DeclSpec.h:1402
Expr * getAsmLabel() const
Definition: DeclSpec.h:2434
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
Definition: DeclSpec.h:2120
Encodes a location in the source.
bool isTypeSpecOwned() const
Definition: DeclSpec.h:477
ReferenceTypeInfo Ref
Definition: DeclSpec.h:1521
ParsedSpecifiers
ParsedSpecifiers - Flags to query which specifiers were applied.
Definition: DeclSpec.h:326
FunctionDefinitionKind getFunctionDefinitionKind() const
Definition: DeclSpec.h:2469
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
Definition: DeclSpec.h:1876
FunctionTypeInfo Fun
Definition: DeclSpec.h:1523
bool isModulePrivateSpecified() const
Definition: DeclSpec.h:727
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclSpec.h:499
Defines several types used to describe C++ lambda expressions that are shared between the parser and ...
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:116
NestedNameSpecifier * getRepresentation() const
Retrieve the representation of the nested-name-specifier.
char ScopeMem[sizeof(CXXScopeSpec)]
Definition: DeclSpec.h:1500
const DecompositionDeclarator & getDecompositionDeclarator() const
Definition: DeclSpec.h:1878
void setGroupingParens(bool flag)
Definition: DeclSpec.h:2450
GNU __thread.
Definition: Specifiers.h:203
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
AttributeFactory * QualAttrFactory
AtttibuteFactory for the MethodQualifiers.
Definition: DeclSpec.h:1322
LambdaCapture(LambdaCaptureKind Kind, SourceLocation Loc, IdentifierInfo *Id, SourceLocation EllipsisLoc, LambdaCaptureInitKind InitKind, ExprResult Init, ParsedType InitCaptureType, SourceRange ExplicitRange)
Definition: DeclSpec.h:2564
ObjCPropertyAttributeKind getPropertyAttributes() const
Definition: DeclSpec.h:846
MemberPointerTypeInfo Mem
Definition: DeclSpec.h:1525
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
Definition: DeclSpec.h:1480
Decl * getRepAsDecl() const
Definition: DeclSpec.h:486
Represents a C++11 virt-specifier-seq.
Definition: DeclSpec.h:2502
void AddTypeInfo(const DeclaratorChunk &TI, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
Definition: DeclSpec.h:2165
bool isInvalid() const
Determine whether this unqualified-id refers to an invalid name.
Definition: DeclSpec.h:1016
FunctionDefinitionKind
Described the kind of function definition (if any) provided for a function.
Definition: DeclSpec.h:1719
bool HasRestrict
The type qualifier: restrict. [GNU] C++ extension.
Definition: DeclSpec.h:1194
unsigned TypeQuals
The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
Definition: DeclSpec.h:1497
SourceLocation getConstQualifierLoc() const
Retrieve the location of the &#39;const&#39; qualifier.
Definition: DeclSpec.h:1424
PipeTypeInfo PipeInfo
Definition: DeclSpec.h:1526
SourceLocation getInlineSpecLoc() const
Definition: DeclSpec.h:560
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic, bool isStar, Expr *NumElts, SourceLocation LBLoc, SourceLocation RBLoc)
Return a DeclaratorChunk for an array.
Definition: DeclSpec.h:1578
Decl * DeclRep
Definition: DeclSpec.h:370
bool isInvalid() const
An error occurred during parsing of the scope specifier.
Definition: DeclSpec.h:194
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
Definition: DeclSpec.h:2461
SourceLocation getLastLocation() const
Definition: DeclSpec.h:2532
C++11 thread_local.
Definition: Specifiers.h:206
Defines various enumerations that describe declaration and type specifiers.
SourceLocation getModulePrivateSpecLoc() const
Definition: DeclSpec.h:728
bool isObjCWeakProperty() const
Definition: DeclSpec.h:2443
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
Definition: DeclSpec.h:1892
void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc)
takeAttributes - Takes attributes from the given parsed-attributes set and add them to this declarato...
Definition: DeclSpec.h:2405
TSW getTypeSpecWidth() const
Definition: DeclSpec.h:470
Dataflow Directional Tag Classes.
unsigned TypeQuals
The type qualifiers for the array: const/volatile/restrict/__unaligned/_Atomic.
Definition: DeclSpec.h:1204
bool isValid() const
Return true if this is a valid SourceLocation object.
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
Definition: DeclSpec.h:1145
FieldDeclarator(const DeclSpec &DS)
Definition: DeclSpec.h:2496
static const TSS TSS_unspecified
Definition: DeclSpec.h:266
SourceLocation getTypeSpecWidthLoc() const
Definition: DeclSpec.h:501
LambdaCaptureDefault Default
Definition: DeclSpec.h:2576
void setObjCIvar(bool Val=true)
Definition: DeclSpec.h:2439
SourceLocation getTypeSpecSatLoc() const
Definition: DeclSpec.h:507
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
unsigned isVariadic
isVariadic - If this function has a prototype, and if that proto ends with &#39;,...)&#39;, this is true.
Definition: DeclSpec.h:1261
const DeclaratorChunk * getInnermostNonParenChunk() const
Return the innermost (closest to the declarator) chunk of this declarator that is not a parens chunk...
Definition: DeclSpec.h:2208
unsigned DeleteParams
DeleteParams - If this is true, we need to delete[] Params.
Definition: DeclSpec.h:1274
SourceLocation getPipeLoc() const
Definition: DeclSpec.h:543
SourceLocation getTypeSpecSignLoc() const
Definition: DeclSpec.h:504
void setObjCDeclQualifier(ObjCDeclQualifier DQVal)
Definition: DeclSpec.h:839
bool isTypeAltiVecBool() const
Definition: DeclSpec.h:476
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclSpec.h:498
static const TST TST_unspecified
Definition: DeclSpec.h:272
bool isValid() const
A scope specifier is present, and it refers to a real scope.
Definition: DeclSpec.h:196
const CXXScopeSpec & getTypeSpecScope() const
Definition: DeclSpec.h:495
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
Definition: DeclSpec.h:537
void takeAttributesFrom(ParsedAttributes &attrs)
Definition: DeclSpec.h:768
SourceLocation getNullabilityLoc() const
Definition: DeclSpec.h:861
SourceLocation getVirtualSpecLoc() const
Definition: DeclSpec.h:569
unsigned hasPrototype
hasPrototype - This is true if the function had at least one typed parameter.
Definition: DeclSpec.h:1256
SourceLocation getGetterNameLoc() const
Definition: DeclSpec.h:878
unsigned LParenLoc
The location of the left parenthesis in the source.
Definition: DeclSpec.h:1281
void setNullability(SourceLocation loc, NullabilityKind kind)
Definition: DeclSpec.h:868
type_object_range type_objects() const
Returns the range of type objects, from the identifier outwards.
Definition: DeclSpec.h:2195
CXXScopeSpec & getCXXScopeSpec()
Definition: DeclSpec.h:1873
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it&#39;s invalid.
Definition: DeclSpec.h:1904
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
unsigned AtomicQualLoc
The location of the _Atomic-qualifier, if any.
Definition: DeclSpec.h:1183
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
Definition: DeclSpec.h:1461
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
Definition: DeclSpec.h:2153
SourceLocation getTypeSpecTypeNameLoc() const
Definition: DeclSpec.h:509
CXXScopeSpec & getTypeSpecScope()
Definition: DeclSpec.h:494
BlockPointerTypeInfo Cls
Definition: DeclSpec.h:1524
SourceRange getExceptionSpecRange() const
Definition: DeclSpec.h:1414
SourceLocation getIdentifierLoc() const
Definition: DeclSpec.h:2136
Structure that packs information about the type specifiers that were written in a particular type spe...
Definition: Specifiers.h:95
bool isSet() const
Deprecated.
Definition: DeclSpec.h:209
void getCXX11AttributeRanges(SmallVectorImpl< SourceRange > &Ranges)
Return a source range list of C++11 attributes associated with the declarator.
Definition: DeclSpec.h:2427
SourceRange getSourceRange() const
Definition: DeclSpec.h:1712
void setInvalidType(bool Val=true)
Definition: DeclSpec.h:2445
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
unsigned TypeQuals
For now, sema will catch these as invalid.
Definition: DeclSpec.h:1489
static DeclaratorChunk getBlockPointer(unsigned TypeQuals, SourceLocation Loc)
Return a DeclaratorChunk for a block.
Definition: DeclSpec.h:1619
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form &#39;type...
Definition: DeclSpec.cpp:46
unsigned ExceptionSpecType
ExceptionSpecType - An ExceptionSpecificationType value.
Definition: DeclSpec.h:1271
const CXXScopeSpec & Scope() const
Definition: DeclSpec.h:1504
ThreadStorageClassSpecifier
Thread storage-class-specifier.
Definition: Specifiers.h:200
Captures information about "declaration specifiers".
Definition: DeclSpec.h:228
SourceLocation getRestrictSpecLoc() const
Definition: DeclSpec.h:539
void setEnd(SourceLocation e)
void UpdateDeclRep(Decl *Rep)
Definition: DeclSpec.h:687
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
Definition: ParsedAttr.h:629
SourceLocation getEllipsisLoc() const
Definition: DeclSpec.h:2458
bool isValid() const
SourceLocation getMutableLoc() const
Retrieve the location of the &#39;mutable&#39; qualifier, if any.
Definition: DeclSpec.h:1442
TypeSpecifierWidth
Specifies the width of a type, e.g., short, long, or long long.
Definition: Specifiers.h:32
Expr * NumElts
This is the size of the array, or null if [] or [*] was specified.
Definition: DeclSpec.h:1215
void ClearTypeSpecType()
Definition: DeclSpec.h:463
bool mayHaveIdentifier() const
mayHaveIdentifier - Return true if the identifier is either optional or required. ...
Definition: DeclSpec.h:1979
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
Definition: DeclSpec.h:191
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition: DeclSpec.h:1857
bool isVirtualSpecified() const
Definition: DeclSpec.h:568
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:60
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier &#39;::&#39;.
Definition: DeclSpec.cpp:96
bool isSpecified() const
Return true if the ExplicitSpecifier isn&#39;t defaulted.
Definition: DeclCXX.h:2011
A template-id, e.g., f<int>.
SourceLocation getFirstLocation() const
Definition: DeclSpec.h:2531
AttributePool & getPool() const
Definition: ParsedAttr.h:911
ParsedType getRepAsType() const
Definition: DeclSpec.h:482
bool isInlineSpecified() const
Definition: DeclSpec.h:557
Represents a complete lambda introducer.
Definition: DeclSpec.h:2552
void ExtendWithDeclSpec(const DeclSpec &DS)
ExtendWithDeclSpec - Extend the declarator source range to include the given declspec, unless its location is invalid.
Definition: DeclSpec.h:1911
SourceLocation getAtomicSpecLoc() const
Definition: DeclSpec.h:541
Expr * ExprRep
Definition: DeclSpec.h:371
void setBeginLoc(SourceLocation Loc)
Definition: DeclSpec.h:70
SourceLocation getExplicitSpecLoc() const
Definition: DeclSpec.h:574
SourceLocation getConstexprSpecLoc() const
Definition: DeclSpec.h:731
TypeSpecifierSign TSS
Definition: DeclSpec.h:265
bool hasRefQualifier() const
Determine whether this function declaration contains a ref-qualifier.
Definition: DeclSpec.h:1448
ArrayRef< NamedDecl * > getDeclsInPrototype() const
Get the non-parameter decls defined within this function prototype.
Definition: DeclSpec.h:1473
bool isEmpty() const
isEmpty - Return true if this declaration specifier is completely empty: no tokens were parsed in the...
Definition: DeclSpec.h:624
const IdentifierInfo * getGetterName() const
Definition: DeclSpec.h:876
ParamInfo - An array of paraminfo objects is allocated whenever a function declarator is parsed...
Definition: DeclSpec.h:1227
ArrayRef< Binding > bindings() const
Definition: DeclSpec.h:1704
DeclaratorContext getContext() const
Definition: DeclSpec.h:1882
SourceLocation getExceptionSpecLocEnd() const
Definition: DeclSpec.h:1410
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Definition: Decl.h:248
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Definition: DeclSpec.h:1026
unsigned ExceptionSpecLocEnd
The end location of the exception specification, if any.
Definition: DeclSpec.h:1311
Expr * getRepAsExpr() const
Definition: DeclSpec.h:490
Represents a C++ namespace alias.
Definition: DeclCXX.h:3145
void setGetterName(IdentifierInfo *name, SourceLocation loc)
Definition: DeclSpec.h:879
SourceLocation EndLocation
The location of the last token that describes this unqualified-id.
Definition: DeclSpec.h:998
void setDestructorName(SourceLocation TildeLoc, ParsedType ClassType, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a destructor name.
Definition: DeclSpec.h:1108
bool isFirstDeclarationOfMember()
Returns true if this declares a real member and not a friend.
Definition: DeclSpec.h:2474
void SetRangeEnd(SourceLocation Loc)
Definition: DeclSpec.h:629
bool isPrototypeContext() const
Definition: DeclSpec.h:1884
void addAttributes(ParsedAttributesView &AL)
Concatenates two attribute lists.
Definition: DeclSpec.h:759
AttributePool & getAttributePool() const
Definition: DeclSpec.h:738
SourceLocation getBegin() const
ParsedAttributes - A collection of parsed attributes.
Definition: ParsedAttr.h:906
void setCommaLoc(SourceLocation CL)
Definition: DeclSpec.h:2455
An implicit &#39;self&#39; parameter.
SourceRange getExplicitSpecRange() const
Definition: DeclSpec.h:575
A deduction-guide name (a template-name)
ParamInfo * Params
Params - This is a pointer to a new[]&#39;d array of ParamInfo objects that describe the parameters speci...
Definition: DeclSpec.h:1316
ParsedAttributes & getAttributes()
Definition: DeclSpec.h:765
SourceRange getTypeofParensRange() const
Definition: DeclSpec.h:514
void Clear()
Clear out this builder, and prepare it to build another nested-name-specifier with source-location in...
static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, unsigned TypeQuals, SourceLocation Loc)
Definition: DeclSpec.h:1638
unsigned isAmbiguous
Can this declaration be a constructor-style initializer?
Definition: DeclSpec.h:1264