DeclSpec.h revision f88c400085eac7068399d0a01dbad89f8c579f07
1//===--- DeclSpec.h - Parsed declaration specifiers -------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the classes used to store parsed information about
11// declaration-specifiers and declarators.
12//
13//   static const int volatile x, *y, *(*(*z)[10])(const void *x);
14//   ------------------------- -  --  ---------------------------
15//     declaration-specifiers  \  |   /
16//                            declarators
17//
18//===----------------------------------------------------------------------===//
19
20#ifndef LLVM_CLANG_SEMA_DECLSPEC_H
21#define LLVM_CLANG_SEMA_DECLSPEC_H
22
23#include "clang/Sema/AttributeList.h"
24#include "clang/Sema/Ownership.h"
25#include "clang/AST/NestedNameSpecifier.h"
26#include "clang/Lex/Token.h"
27#include "clang/Basic/ExceptionSpecificationType.h"
28#include "clang/Basic/OperatorKinds.h"
29#include "clang/Basic/Specifiers.h"
30#include "llvm/ADT/SmallVector.h"
31#include "llvm/Support/ErrorHandling.h"
32
33namespace clang {
34  class ASTContext;
35  class TypeLoc;
36  class LangOptions;
37  class DiagnosticsEngine;
38  class IdentifierInfo;
39  class NamespaceAliasDecl;
40  class NamespaceDecl;
41  class NestedNameSpecifier;
42  class NestedNameSpecifierLoc;
43  class ObjCDeclSpec;
44  class Preprocessor;
45  class Sema;
46  class Declarator;
47  struct TemplateIdAnnotation;
48
49/// CXXScopeSpec - Represents a C++ nested-name-specifier or a global scope
50/// specifier.  These can be in 3 states:
51///   1) Not present, identified by isEmpty()
52///   2) Present, identified by isNotEmpty()
53///      2.a) Valid, idenified by isValid()
54///      2.b) Invalid, identified by isInvalid().
55///
56/// isSet() is deprecated because it mostly corresponded to "valid" but was
57/// often used as if it meant "present".
58///
59/// The actual scope is described by getScopeRep().
60class CXXScopeSpec {
61  SourceRange Range;
62  NestedNameSpecifierLocBuilder Builder;
63
64public:
65  const SourceRange &getRange() const { return Range; }
66  void setRange(const SourceRange &R) { Range = R; }
67  void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
68  void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
69  SourceLocation getBeginLoc() const { return Range.getBegin(); }
70  SourceLocation getEndLoc() const { return Range.getEnd(); }
71
72  /// \brief Retrieve the representation of the nested-name-specifier.
73  NestedNameSpecifier *getScopeRep() const {
74    return Builder.getRepresentation();
75  }
76
77  /// \brief Extend the current nested-name-specifier by another
78  /// nested-name-specifier component of the form 'type::'.
79  ///
80  /// \param Context The AST context in which this nested-name-specifier
81  /// resides.
82  ///
83  /// \param TemplateKWLoc The location of the 'template' keyword, if present.
84  ///
85  /// \param TL The TypeLoc that describes the type preceding the '::'.
86  ///
87  /// \param ColonColonLoc The location of the trailing '::'.
88  void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL,
89              SourceLocation ColonColonLoc);
90
91  /// \brief Extend the current nested-name-specifier by another
92  /// nested-name-specifier component of the form 'identifier::'.
93  ///
94  /// \param Context The AST context in which this nested-name-specifier
95  /// resides.
96  ///
97  /// \param Identifier The identifier.
98  ///
99  /// \param IdentifierLoc The location of the identifier.
100  ///
101  /// \param ColonColonLoc The location of the trailing '::'.
102  void Extend(ASTContext &Context, IdentifierInfo *Identifier,
103              SourceLocation IdentifierLoc, SourceLocation ColonColonLoc);
104
105  /// \brief Extend the current nested-name-specifier by another
106  /// nested-name-specifier component of the form 'namespace::'.
107  ///
108  /// \param Context The AST context in which this nested-name-specifier
109  /// resides.
110  ///
111  /// \param Namespace The namespace.
112  ///
113  /// \param NamespaceLoc The location of the namespace name.
114  ///
115  /// \param ColonColonLoc The location of the trailing '::'.
116  void Extend(ASTContext &Context, NamespaceDecl *Namespace,
117              SourceLocation NamespaceLoc, SourceLocation ColonColonLoc);
118
119  /// \brief Extend the current nested-name-specifier by another
120  /// nested-name-specifier component of the form 'namespace-alias::'.
121  ///
122  /// \param Context The AST context in which this nested-name-specifier
123  /// resides.
124  ///
125  /// \param Alias The namespace alias.
126  ///
127  /// \param AliasLoc The location of the namespace alias
128  /// name.
129  ///
130  /// \param ColonColonLoc The location of the trailing '::'.
131  void Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
132              SourceLocation AliasLoc, SourceLocation ColonColonLoc);
133
134  /// \brief Turn this (empty) nested-name-specifier into the global
135  /// nested-name-specifier '::'.
136  void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc);
137
138  /// \brief Make a new nested-name-specifier from incomplete source-location
139  /// information.
140  ///
141  /// FIXME: This routine should be used very, very rarely, in cases where we
142  /// need to synthesize a nested-name-specifier. Most code should instead use
143  /// \c Adopt() with a proper \c NestedNameSpecifierLoc.
144  void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier,
145                   SourceRange R);
146
147  /// \brief Adopt an existing nested-name-specifier (with source-range
148  /// information).
149  void Adopt(NestedNameSpecifierLoc Other);
150
151  /// \brief Retrieve a nested-name-specifier with location information, copied
152  /// into the given AST context.
153  ///
154  /// \param Context The context into which this nested-name-specifier will be
155  /// copied.
156  NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const;
157
158  /// \brief Retrieve the location of the name in the last qualifier
159  /// in this nested name specifier.  For example:
160  ///   ::foo::bar<0>::
161  ///          ^~~
162  SourceLocation getLastQualifierNameLoc() const;
163
164  /// No scope specifier.
165  bool isEmpty() const { return !Range.isValid(); }
166  /// A scope specifier is present, but may be valid or invalid.
167  bool isNotEmpty() const { return !isEmpty(); }
168
169  /// An error occurred during parsing of the scope specifier.
170  bool isInvalid() const { return isNotEmpty() && getScopeRep() == 0; }
171  /// A scope specifier is present, and it refers to a real scope.
172  bool isValid() const { return isNotEmpty() && getScopeRep() != 0; }
173
174  /// \brief Indicate that this nested-name-specifier is invalid.
175  void SetInvalid(SourceRange R) {
176    assert(R.isValid() && "Must have a valid source range");
177    if (Range.getBegin().isInvalid())
178      Range.setBegin(R.getBegin());
179    Range.setEnd(R.getEnd());
180    Builder.Clear();
181  }
182
183  /// Deprecated.  Some call sites intend isNotEmpty() while others intend
184  /// isValid().
185  bool isSet() const { return getScopeRep() != 0; }
186
187  void clear() {
188    Range = SourceRange();
189    Builder.Clear();
190  }
191
192  /// \brief Retrieve the data associated with the source-location information.
193  char *location_data() const { return Builder.getBuffer().first; }
194
195  /// \brief Retrieve the size of the data associated with source-location
196  /// information.
197  unsigned location_size() const { return Builder.getBuffer().second; }
198};
199
200/// DeclSpec - This class captures information about "declaration specifiers",
201/// which encompasses storage-class-specifiers, type-specifiers,
202/// type-qualifiers, and function-specifiers.
203class DeclSpec {
204public:
205  // storage-class-specifier
206  // Note: The order of these enumerators is important for diagnostics.
207  enum SCS {
208    SCS_unspecified = 0,
209    SCS_typedef,
210    SCS_extern,
211    SCS_static,
212    SCS_auto,
213    SCS_register,
214    SCS_private_extern,
215    SCS_mutable
216  };
217
218  // Import type specifier width enumeration and constants.
219  typedef TypeSpecifierWidth TSW;
220  static const TSW TSW_unspecified = clang::TSW_unspecified;
221  static const TSW TSW_short = clang::TSW_short;
222  static const TSW TSW_long = clang::TSW_long;
223  static const TSW TSW_longlong = clang::TSW_longlong;
224
225  enum TSC {
226    TSC_unspecified,
227    TSC_imaginary,
228    TSC_complex
229  };
230
231  // Import type specifier sign enumeration and constants.
232  typedef TypeSpecifierSign TSS;
233  static const TSS TSS_unspecified = clang::TSS_unspecified;
234  static const TSS TSS_signed = clang::TSS_signed;
235  static const TSS TSS_unsigned = clang::TSS_unsigned;
236
237  // Import type specifier type enumeration and constants.
238  typedef TypeSpecifierType TST;
239  static const TST TST_unspecified = clang::TST_unspecified;
240  static const TST TST_void = clang::TST_void;
241  static const TST TST_char = clang::TST_char;
242  static const TST TST_wchar = clang::TST_wchar;
243  static const TST TST_char16 = clang::TST_char16;
244  static const TST TST_char32 = clang::TST_char32;
245  static const TST TST_int = clang::TST_int;
246  static const TST TST_half = clang::TST_half;
247  static const TST TST_float = clang::TST_float;
248  static const TST TST_double = clang::TST_double;
249  static const TST TST_bool = clang::TST_bool;
250  static const TST TST_decimal32 = clang::TST_decimal32;
251  static const TST TST_decimal64 = clang::TST_decimal64;
252  static const TST TST_decimal128 = clang::TST_decimal128;
253  static const TST TST_enum = clang::TST_enum;
254  static const TST TST_union = clang::TST_union;
255  static const TST TST_struct = clang::TST_struct;
256  static const TST TST_class = clang::TST_class;
257  static const TST TST_typename = clang::TST_typename;
258  static const TST TST_typeofType = clang::TST_typeofType;
259  static const TST TST_typeofExpr = clang::TST_typeofExpr;
260  static const TST TST_decltype = clang::TST_decltype;
261  static const TST TST_underlyingType = clang::TST_underlyingType;
262  static const TST TST_auto = clang::TST_auto;
263  static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
264  static const TST TST_atomic = clang::TST_atomic;
265  static const TST TST_error = clang::TST_error;
266
267  // type-qualifiers
268  enum TQ {   // NOTE: These flags must be kept in sync with Qualifiers::TQ.
269    TQ_unspecified = 0,
270    TQ_const       = 1,
271    TQ_restrict    = 2,
272    TQ_volatile    = 4
273  };
274
275  /// ParsedSpecifiers - Flags to query which specifiers were applied.  This is
276  /// returned by getParsedSpecifiers.
277  enum ParsedSpecifiers {
278    PQ_None                  = 0,
279    PQ_StorageClassSpecifier = 1,
280    PQ_TypeSpecifier         = 2,
281    PQ_TypeQualifier         = 4,
282    PQ_FunctionSpecifier     = 8
283  };
284
285private:
286  // storage-class-specifier
287  /*SCS*/unsigned StorageClassSpec : 3;
288  unsigned SCS_thread_specified : 1;
289  unsigned SCS_extern_in_linkage_spec : 1;
290
291  // type-specifier
292  /*TSW*/unsigned TypeSpecWidth : 2;
293  /*TSC*/unsigned TypeSpecComplex : 2;
294  /*TSS*/unsigned TypeSpecSign : 2;
295  /*TST*/unsigned TypeSpecType : 5;
296  unsigned TypeAltiVecVector : 1;
297  unsigned TypeAltiVecPixel : 1;
298  unsigned TypeAltiVecBool : 1;
299  unsigned TypeSpecOwned : 1;
300
301  // type-qualifiers
302  unsigned TypeQualifiers : 3;  // Bitwise OR of TQ.
303
304  // function-specifier
305  unsigned FS_inline_specified : 1;
306  unsigned FS_virtual_specified : 1;
307  unsigned FS_explicit_specified : 1;
308
309  // friend-specifier
310  unsigned Friend_specified : 1;
311
312  // constexpr-specifier
313  unsigned Constexpr_specified : 1;
314
315  /*SCS*/unsigned StorageClassSpecAsWritten : 3;
316
317  union {
318    UnionParsedType TypeRep;
319    Decl *DeclRep;
320    Expr *ExprRep;
321  };
322
323  // attributes.
324  ParsedAttributes Attrs;
325
326  // Scope specifier for the type spec, if applicable.
327  CXXScopeSpec TypeScope;
328
329  // List of protocol qualifiers for objective-c classes.  Used for
330  // protocol-qualified interfaces "NString<foo>" and protocol-qualified id
331  // "id<foo>".
332  Decl * const *ProtocolQualifiers;
333  unsigned NumProtocolQualifiers;
334  SourceLocation ProtocolLAngleLoc;
335  SourceLocation *ProtocolLocs;
336
337  // SourceLocation info.  These are null if the item wasn't specified or if
338  // the setting was synthesized.
339  SourceRange Range;
340
341  SourceLocation StorageClassSpecLoc, SCS_threadLoc;
342  SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc;
343  /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
344  /// typename, then this is the location of the named type (if present);
345  /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
346  /// TSTNameLoc provides source range info for tag types.
347  SourceLocation TSTNameLoc;
348  SourceRange TypeofParensRange;
349  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc;
350  SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc;
351  SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc;
352
353  WrittenBuiltinSpecs writtenBS;
354  void SaveWrittenBuiltinSpecs();
355  void SaveStorageSpecifierAsWritten();
356
357  ObjCDeclSpec *ObjCQualifiers;
358
359  static bool isTypeRep(TST T) {
360    return (T == TST_typename || T == TST_typeofType ||
361            T == TST_underlyingType || T == TST_atomic);
362  }
363  static bool isExprRep(TST T) {
364    return (T == TST_typeofExpr || T == TST_decltype);
365  }
366  static bool isDeclRep(TST T) {
367    return (T == TST_enum || T == TST_struct ||
368            T == TST_union || T == TST_class);
369  }
370
371  DeclSpec(const DeclSpec&);       // DO NOT IMPLEMENT
372  void operator=(const DeclSpec&); // DO NOT IMPLEMENT
373public:
374
375  DeclSpec(AttributeFactory &attrFactory)
376    : StorageClassSpec(SCS_unspecified),
377      SCS_thread_specified(false),
378      SCS_extern_in_linkage_spec(false),
379      TypeSpecWidth(TSW_unspecified),
380      TypeSpecComplex(TSC_unspecified),
381      TypeSpecSign(TSS_unspecified),
382      TypeSpecType(TST_unspecified),
383      TypeAltiVecVector(false),
384      TypeAltiVecPixel(false),
385      TypeAltiVecBool(false),
386      TypeSpecOwned(false),
387      TypeQualifiers(TQ_unspecified),
388      FS_inline_specified(false),
389      FS_virtual_specified(false),
390      FS_explicit_specified(false),
391      Friend_specified(false),
392      Constexpr_specified(false),
393      StorageClassSpecAsWritten(SCS_unspecified),
394      Attrs(attrFactory),
395      ProtocolQualifiers(0),
396      NumProtocolQualifiers(0),
397      ProtocolLocs(0),
398      writtenBS(),
399      ObjCQualifiers(0) {
400  }
401  ~DeclSpec() {
402    delete [] ProtocolQualifiers;
403    delete [] ProtocolLocs;
404  }
405  // storage-class-specifier
406  SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
407  bool isThreadSpecified() const { return SCS_thread_specified; }
408  bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
409  void setExternInLinkageSpec(bool Value) {
410    SCS_extern_in_linkage_spec = Value;
411  }
412
413  SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
414  SourceLocation getThreadSpecLoc() const { return SCS_threadLoc; }
415
416  void ClearStorageClassSpecs() {
417    StorageClassSpec     = DeclSpec::SCS_unspecified;
418    SCS_thread_specified = false;
419    SCS_extern_in_linkage_spec = false;
420    StorageClassSpecLoc  = SourceLocation();
421    SCS_threadLoc        = SourceLocation();
422  }
423
424  // type-specifier
425  TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; }
426  TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
427  TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; }
428  TST getTypeSpecType() const { return (TST)TypeSpecType; }
429  bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
430  bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
431  bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
432  bool isTypeSpecOwned() const { return TypeSpecOwned; }
433  ParsedType getRepAsType() const {
434    assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
435    return TypeRep;
436  }
437  Decl *getRepAsDecl() const {
438    assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
439    return DeclRep;
440  }
441  Expr *getRepAsExpr() const {
442    assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
443    return ExprRep;
444  }
445  CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
446  const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
447
448  const SourceRange &getSourceRange() const { return Range; }
449  SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; }
450  SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
451  SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
452  SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
453  SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
454
455  SourceLocation getTypeSpecTypeNameLoc() const {
456    assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename);
457    return TSTNameLoc;
458  }
459
460  SourceRange getTypeofParensRange() const { return TypeofParensRange; }
461  void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; }
462
463  /// getSpecifierName - Turn a type-specifier-type into a string like "_Bool"
464  /// or "union".
465  static const char *getSpecifierName(DeclSpec::TST T);
466  static const char *getSpecifierName(DeclSpec::TQ Q);
467  static const char *getSpecifierName(DeclSpec::TSS S);
468  static const char *getSpecifierName(DeclSpec::TSC C);
469  static const char *getSpecifierName(DeclSpec::TSW W);
470  static const char *getSpecifierName(DeclSpec::SCS S);
471
472  // type-qualifiers
473
474  /// getTypeQualifiers - Return a set of TQs.
475  unsigned getTypeQualifiers() const { return TypeQualifiers; }
476  SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
477  SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
478  SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
479
480  /// \brief Clear out all of the type qualifiers.
481  void ClearTypeQualifiers() {
482    TypeQualifiers = 0;
483    TQ_constLoc = SourceLocation();
484    TQ_restrictLoc = SourceLocation();
485    TQ_volatileLoc = SourceLocation();
486  }
487
488  // function-specifier
489  bool isInlineSpecified() const { return FS_inline_specified; }
490  SourceLocation getInlineSpecLoc() const { return FS_inlineLoc; }
491
492  bool isVirtualSpecified() const { return FS_virtual_specified; }
493  SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
494
495  bool isExplicitSpecified() const { return FS_explicit_specified; }
496  SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
497
498  void ClearFunctionSpecs() {
499    FS_inline_specified = false;
500    FS_inlineLoc = SourceLocation();
501    FS_virtual_specified = false;
502    FS_virtualLoc = SourceLocation();
503    FS_explicit_specified = false;
504    FS_explicitLoc = SourceLocation();
505  }
506
507  /// hasTypeSpecifier - Return true if any type-specifier has been found.
508  bool hasTypeSpecifier() const {
509    return getTypeSpecType() != DeclSpec::TST_unspecified ||
510           getTypeSpecWidth() != DeclSpec::TSW_unspecified ||
511           getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
512           getTypeSpecSign() != DeclSpec::TSS_unspecified;
513  }
514
515  /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
516  /// DeclSpec includes.
517  ///
518  unsigned getParsedSpecifiers() const;
519
520  SCS getStorageClassSpecAsWritten() const {
521    return (SCS)StorageClassSpecAsWritten;
522  }
523
524  /// isEmpty - Return true if this declaration specifier is completely empty:
525  /// no tokens were parsed in the production of it.
526  bool isEmpty() const {
527    return getParsedSpecifiers() == DeclSpec::PQ_None;
528  }
529
530  void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
531  void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
532
533  /// These methods set the specified attribute of the DeclSpec and
534  /// return false if there was no error.  If an error occurs (for
535  /// example, if we tried to set "auto" on a spec with "extern"
536  /// already set), they return true and set PrevSpec and DiagID
537  /// such that
538  ///   Diag(Loc, DiagID) << PrevSpec;
539  /// will yield a useful result.
540  ///
541  /// TODO: use a more general approach that still allows these
542  /// diagnostics to be ignored when desired.
543  bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
544                           const char *&PrevSpec, unsigned &DiagID);
545  bool SetStorageClassSpecThread(SourceLocation Loc, const char *&PrevSpec,
546                                 unsigned &DiagID);
547  bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec,
548                        unsigned &DiagID);
549  bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
550                          unsigned &DiagID);
551  bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec,
552                       unsigned &DiagID);
553  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
554                       unsigned &DiagID);
555  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
556                       unsigned &DiagID, ParsedType Rep);
557  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
558                       unsigned &DiagID, Decl *Rep, bool Owned);
559  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
560                       SourceLocation TagNameLoc, const char *&PrevSpec,
561                       unsigned &DiagID, ParsedType Rep);
562  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
563                       SourceLocation TagNameLoc, const char *&PrevSpec,
564                       unsigned &DiagID, Decl *Rep, bool Owned);
565
566  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
567                       unsigned &DiagID, Expr *Rep);
568  bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
569                       const char *&PrevSpec, unsigned &DiagID);
570  bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
571                       const char *&PrevSpec, unsigned &DiagID);
572  bool SetTypeSpecError();
573  void UpdateDeclRep(Decl *Rep) {
574    assert(isDeclRep((TST) TypeSpecType));
575    DeclRep = Rep;
576  }
577  void UpdateTypeRep(ParsedType Rep) {
578    assert(isTypeRep((TST) TypeSpecType));
579    TypeRep = Rep;
580  }
581  void UpdateExprRep(Expr *Rep) {
582    assert(isExprRep((TST) TypeSpecType));
583    ExprRep = Rep;
584  }
585
586  bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
587                   unsigned &DiagID, const LangOptions &Lang);
588
589  bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
590                             unsigned &DiagID);
591  bool SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
592                              unsigned &DiagID);
593  bool SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
594                               unsigned &DiagID);
595
596  bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
597                     unsigned &DiagID);
598  bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
599                            unsigned &DiagID);
600  bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
601                        unsigned &DiagID);
602
603  bool isFriendSpecified() const { return Friend_specified; }
604  SourceLocation getFriendSpecLoc() const { return FriendLoc; }
605
606  bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); }
607  SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; }
608
609  bool isConstexprSpecified() const { return Constexpr_specified; }
610  SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
611
612  AttributePool &getAttributePool() const {
613    return Attrs.getPool();
614  }
615
616  /// AddAttributes - contatenates two attribute lists.
617  /// The GCC attribute syntax allows for the following:
618  ///
619  /// short __attribute__(( unused, deprecated ))
620  /// int __attribute__(( may_alias, aligned(16) )) var;
621  ///
622  /// This declares 4 attributes using 2 lists. The following syntax is
623  /// also allowed and equivalent to the previous declaration.
624  ///
625  /// short __attribute__((unused)) __attribute__((deprecated))
626  /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
627  ///
628  void addAttributes(AttributeList *AL) {
629    Attrs.addAll(AL);
630  }
631  void setAttributes(AttributeList *AL) {
632    Attrs.set(AL);
633  }
634
635  bool hasAttributes() const { return !Attrs.empty(); }
636
637  ParsedAttributes &getAttributes() { return Attrs; }
638  const ParsedAttributes &getAttributes() const { return Attrs; }
639
640  /// TakeAttributes - Return the current attribute list and remove them from
641  /// the DeclSpec so that it doesn't own them.
642  ParsedAttributes takeAttributes() {
643    // The non-const "copy" constructor clears the operand automatically.
644    return Attrs;
645  }
646
647  void takeAttributesFrom(ParsedAttributes &attrs) {
648    Attrs.takeAllFrom(attrs);
649  }
650
651  typedef Decl * const *ProtocolQualifierListTy;
652  ProtocolQualifierListTy getProtocolQualifiers() const {
653    return ProtocolQualifiers;
654  }
655  SourceLocation *getProtocolLocs() const { return ProtocolLocs; }
656  unsigned getNumProtocolQualifiers() const {
657    return NumProtocolQualifiers;
658  }
659  SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; }
660  void setProtocolQualifiers(Decl * const *Protos, unsigned NP,
661                             SourceLocation *ProtoLocs,
662                             SourceLocation LAngleLoc);
663
664  /// Finish - This does final analysis of the declspec, issuing diagnostics for
665  /// things like "_Imaginary" (lacking an FP type).  After calling this method,
666  /// DeclSpec is guaranteed self-consistent, even if an error occurred.
667  void Finish(DiagnosticsEngine &D, Preprocessor &PP);
668
669  const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
670    return writtenBS;
671  }
672
673  ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; }
674  void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; }
675
676  /// isMissingDeclaratorOk - This checks if this DeclSpec can stand alone,
677  /// without a Declarator. Only tag declspecs can stand alone.
678  bool isMissingDeclaratorOk();
679};
680
681/// ObjCDeclSpec - This class captures information about
682/// "declaration specifiers" specific to objective-c
683class ObjCDeclSpec {
684public:
685  /// ObjCDeclQualifier - Qualifier used on types in method
686  /// declarations.  Not all combinations are sensible.  Parameters
687  /// can be one of { in, out, inout } with one of { bycopy, byref }.
688  /// Returns can either be { oneway } or not.
689  ///
690  /// This should be kept in sync with Decl::ObjCDeclQualifier.
691  enum ObjCDeclQualifier {
692    DQ_None = 0x0,
693    DQ_In = 0x1,
694    DQ_Inout = 0x2,
695    DQ_Out = 0x4,
696    DQ_Bycopy = 0x8,
697    DQ_Byref = 0x10,
698    DQ_Oneway = 0x20
699  };
700
701  /// PropertyAttributeKind - list of property attributes.
702  enum ObjCPropertyAttributeKind {
703    DQ_PR_noattr = 0x0,
704    DQ_PR_readonly = 0x01,
705    DQ_PR_getter = 0x02,
706    DQ_PR_assign = 0x04,
707    DQ_PR_readwrite = 0x08,
708    DQ_PR_retain = 0x10,
709    DQ_PR_copy = 0x20,
710    DQ_PR_nonatomic = 0x40,
711    DQ_PR_setter = 0x80,
712    DQ_PR_atomic = 0x100,
713    DQ_PR_weak =   0x200,
714    DQ_PR_strong = 0x400,
715    DQ_PR_unsafe_unretained = 0x800
716  };
717
718
719  ObjCDeclSpec()
720    : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr),
721      GetterName(0), SetterName(0) { }
722  ObjCDeclQualifier getObjCDeclQualifier() const { return objcDeclQualifier; }
723  void setObjCDeclQualifier(ObjCDeclQualifier DQVal) {
724    objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal);
725  }
726
727  ObjCPropertyAttributeKind getPropertyAttributes() const {
728    return ObjCPropertyAttributeKind(PropertyAttributes);
729  }
730  void setPropertyAttributes(ObjCPropertyAttributeKind PRVal) {
731    PropertyAttributes =
732      (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal);
733  }
734
735  const IdentifierInfo *getGetterName() const { return GetterName; }
736  IdentifierInfo *getGetterName() { return GetterName; }
737  void setGetterName(IdentifierInfo *name) { GetterName = name; }
738
739  const IdentifierInfo *getSetterName() const { return SetterName; }
740  IdentifierInfo *getSetterName() { return SetterName; }
741  void setSetterName(IdentifierInfo *name) { SetterName = name; }
742
743private:
744  // FIXME: These two are unrelated and mutially exclusive. So perhaps
745  // we can put them in a union to reflect their mutual exclusiveness
746  // (space saving is negligible).
747  ObjCDeclQualifier objcDeclQualifier : 6;
748
749  // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind
750  unsigned PropertyAttributes : 12;
751  IdentifierInfo *GetterName;    // getter name of NULL if no getter
752  IdentifierInfo *SetterName;    // setter name of NULL if no setter
753};
754
755/// \brief Represents a C++ unqualified-id that has been parsed.
756class UnqualifiedId {
757private:
758  const UnqualifiedId &operator=(const UnqualifiedId &); // DO NOT IMPLEMENT
759
760public:
761  /// \brief Describes the kind of unqualified-id parsed.
762  enum IdKind {
763    /// \brief An identifier.
764    IK_Identifier,
765    /// \brief An overloaded operator name, e.g., operator+.
766    IK_OperatorFunctionId,
767    /// \brief A conversion function name, e.g., operator int.
768    IK_ConversionFunctionId,
769    /// \brief A user-defined literal name, e.g., operator "" _i.
770    IK_LiteralOperatorId,
771    /// \brief A constructor name.
772    IK_ConstructorName,
773    /// \brief A constructor named via a template-id.
774    IK_ConstructorTemplateId,
775    /// \brief A destructor name.
776    IK_DestructorName,
777    /// \brief A template-id, e.g., f<int>.
778    IK_TemplateId,
779    /// \brief An implicit 'self' parameter
780    IK_ImplicitSelfParam
781  } Kind;
782
783  /// \brief Anonymous union that holds extra data associated with the
784  /// parsed unqualified-id.
785  union {
786    /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind
787    /// == IK_UserLiteralId, the identifier suffix.
788    IdentifierInfo *Identifier;
789
790    /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator
791    /// that we parsed.
792    struct {
793      /// \brief The kind of overloaded operator.
794      OverloadedOperatorKind Operator;
795
796      /// \brief The source locations of the individual tokens that name
797      /// the operator, e.g., the "new", "[", and "]" tokens in
798      /// operator new [].
799      ///
800      /// Different operators have different numbers of tokens in their name,
801      /// up to three. Any remaining source locations in this array will be
802      /// set to an invalid value for operators with fewer than three tokens.
803      unsigned SymbolLocations[3];
804    } OperatorFunctionId;
805
806    /// \brief When Kind == IK_ConversionFunctionId, the type that the
807    /// conversion function names.
808    UnionParsedType ConversionFunctionId;
809
810    /// \brief When Kind == IK_ConstructorName, the class-name of the type
811    /// whose constructor is being referenced.
812    UnionParsedType ConstructorName;
813
814    /// \brief When Kind == IK_DestructorName, the type referred to by the
815    /// class-name.
816    UnionParsedType DestructorName;
817
818    /// \brief When Kind == IK_TemplateId or IK_ConstructorTemplateId,
819    /// the template-id annotation that contains the template name and
820    /// template arguments.
821    TemplateIdAnnotation *TemplateId;
822  };
823
824  /// \brief The location of the first token that describes this unqualified-id,
825  /// which will be the location of the identifier, "operator" keyword,
826  /// tilde (for a destructor), or the template name of a template-id.
827  SourceLocation StartLocation;
828
829  /// \brief The location of the last token that describes this unqualified-id.
830  SourceLocation EndLocation;
831
832  UnqualifiedId() : Kind(IK_Identifier), Identifier(0) { }
833
834  /// \brief Do not use this copy constructor. It is temporary, and only
835  /// exists because we are holding FieldDeclarators in a SmallVector when we
836  /// don't actually need them.
837  ///
838  /// FIXME: Kill this copy constructor.
839  UnqualifiedId(const UnqualifiedId &Other)
840    : Kind(IK_Identifier), Identifier(Other.Identifier),
841      StartLocation(Other.StartLocation), EndLocation(Other.EndLocation) {
842    assert(Other.Kind == IK_Identifier && "Cannot copy non-identifiers");
843  }
844
845  /// \brief Destroy this unqualified-id.
846  ~UnqualifiedId() { clear(); }
847
848  /// \brief Clear out this unqualified-id, setting it to default (invalid)
849  /// state.
850  void clear();
851
852  /// \brief Determine whether this unqualified-id refers to a valid name.
853  bool isValid() const { return StartLocation.isValid(); }
854
855  /// \brief Determine whether this unqualified-id refers to an invalid name.
856  bool isInvalid() const { return !isValid(); }
857
858  /// \brief Determine what kind of name we have.
859  IdKind getKind() const { return Kind; }
860  void setKind(IdKind kind) { Kind = kind; }
861
862  /// \brief Specify that this unqualified-id was parsed as an identifier.
863  ///
864  /// \param Id the parsed identifier.
865  /// \param IdLoc the location of the parsed identifier.
866  void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
867    Kind = IK_Identifier;
868    Identifier = const_cast<IdentifierInfo *>(Id);
869    StartLocation = EndLocation = IdLoc;
870  }
871
872  /// \brief Specify that this unqualified-id was parsed as an
873  /// operator-function-id.
874  ///
875  /// \param OperatorLoc the location of the 'operator' keyword.
876  ///
877  /// \param Op the overloaded operator.
878  ///
879  /// \param SymbolLocations the locations of the individual operator symbols
880  /// in the operator.
881  void setOperatorFunctionId(SourceLocation OperatorLoc,
882                             OverloadedOperatorKind Op,
883                             SourceLocation SymbolLocations[3]);
884
885  /// \brief Specify that this unqualified-id was parsed as a
886  /// conversion-function-id.
887  ///
888  /// \param OperatorLoc the location of the 'operator' keyword.
889  ///
890  /// \param Ty the type to which this conversion function is converting.
891  ///
892  /// \param EndLoc the location of the last token that makes up the type name.
893  void setConversionFunctionId(SourceLocation OperatorLoc,
894                               ParsedType Ty,
895                               SourceLocation EndLoc) {
896    Kind = IK_ConversionFunctionId;
897    StartLocation = OperatorLoc;
898    EndLocation = EndLoc;
899    ConversionFunctionId = Ty;
900  }
901
902  /// \brief Specific that this unqualified-id was parsed as a
903  /// literal-operator-id.
904  ///
905  /// \param Id the parsed identifier.
906  ///
907  /// \param OpLoc the location of the 'operator' keyword.
908  ///
909  /// \param IdLoc the location of the identifier.
910  void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc,
911                              SourceLocation IdLoc) {
912    Kind = IK_LiteralOperatorId;
913    Identifier = const_cast<IdentifierInfo *>(Id);
914    StartLocation = OpLoc;
915    EndLocation = IdLoc;
916  }
917
918  /// \brief Specify that this unqualified-id was parsed as a constructor name.
919  ///
920  /// \param ClassType the class type referred to by the constructor name.
921  ///
922  /// \param ClassNameLoc the location of the class name.
923  ///
924  /// \param EndLoc the location of the last token that makes up the type name.
925  void setConstructorName(ParsedType ClassType,
926                          SourceLocation ClassNameLoc,
927                          SourceLocation EndLoc) {
928    Kind = IK_ConstructorName;
929    StartLocation = ClassNameLoc;
930    EndLocation = EndLoc;
931    ConstructorName = ClassType;
932  }
933
934  /// \brief Specify that this unqualified-id was parsed as a
935  /// template-id that names a constructor.
936  ///
937  /// \param TemplateId the template-id annotation that describes the parsed
938  /// template-id. This UnqualifiedId instance will take ownership of the
939  /// \p TemplateId and will free it on destruction.
940  void setConstructorTemplateId(TemplateIdAnnotation *TemplateId);
941
942  /// \brief Specify that this unqualified-id was parsed as a destructor name.
943  ///
944  /// \param TildeLoc the location of the '~' that introduces the destructor
945  /// name.
946  ///
947  /// \param ClassType the name of the class referred to by the destructor name.
948  void setDestructorName(SourceLocation TildeLoc,
949                         ParsedType ClassType,
950                         SourceLocation EndLoc) {
951    Kind = IK_DestructorName;
952    StartLocation = TildeLoc;
953    EndLocation = EndLoc;
954    DestructorName = ClassType;
955  }
956
957  /// \brief Specify that this unqualified-id was parsed as a template-id.
958  ///
959  /// \param TemplateId the template-id annotation that describes the parsed
960  /// template-id. This UnqualifiedId instance will take ownership of the
961  /// \p TemplateId and will free it on destruction.
962  void setTemplateId(TemplateIdAnnotation *TemplateId);
963
964  /// \brief Return the source range that covers this unqualified-id.
965  SourceRange getSourceRange() const {
966    return SourceRange(StartLocation, EndLocation);
967  }
968};
969
970/// CachedTokens - A set of tokens that has been cached for later
971/// parsing.
972typedef SmallVector<Token, 4> CachedTokens;
973
974/// DeclaratorChunk - One instance of this struct is used for each type in a
975/// declarator that is parsed.
976///
977/// This is intended to be a small value object.
978struct DeclaratorChunk {
979  enum {
980    Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren
981  } Kind;
982
983  /// Loc - The place where this type was defined.
984  SourceLocation Loc;
985  /// EndLoc - If valid, the place where this chunck ends.
986  SourceLocation EndLoc;
987
988  struct TypeInfoCommon {
989    AttributeList *AttrList;
990  };
991
992  struct PointerTypeInfo : TypeInfoCommon {
993    /// The type qualifiers: const/volatile/restrict.
994    unsigned TypeQuals : 3;
995
996    /// The location of the const-qualifier, if any.
997    unsigned ConstQualLoc;
998
999    /// The location of the volatile-qualifier, if any.
1000    unsigned VolatileQualLoc;
1001
1002    /// The location of the restrict-qualifier, if any.
1003    unsigned RestrictQualLoc;
1004
1005    void destroy() {
1006    }
1007  };
1008
1009  struct ReferenceTypeInfo : TypeInfoCommon {
1010    /// The type qualifier: restrict. [GNU] C++ extension
1011    bool HasRestrict : 1;
1012    /// True if this is an lvalue reference, false if it's an rvalue reference.
1013    bool LValueRef : 1;
1014    void destroy() {
1015    }
1016  };
1017
1018  struct ArrayTypeInfo : TypeInfoCommon {
1019    /// The type qualifiers for the array: const/volatile/restrict.
1020    unsigned TypeQuals : 3;
1021
1022    /// True if this dimension included the 'static' keyword.
1023    bool hasStatic : 1;
1024
1025    /// True if this dimension was [*].  In this case, NumElts is null.
1026    bool isStar : 1;
1027
1028    /// This is the size of the array, or null if [] or [*] was specified.
1029    /// Since the parser is multi-purpose, and we don't want to impose a root
1030    /// expression class on all clients, NumElts is untyped.
1031    Expr *NumElts;
1032
1033    void destroy() {}
1034  };
1035
1036  /// ParamInfo - An array of paraminfo objects is allocated whenever a function
1037  /// declarator is parsed.  There are two interesting styles of arguments here:
1038  /// K&R-style identifier lists and parameter type lists.  K&R-style identifier
1039  /// lists will have information about the identifier, but no type information.
1040  /// Parameter type lists will have type info (if the actions module provides
1041  /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.
1042  struct ParamInfo {
1043    IdentifierInfo *Ident;
1044    SourceLocation IdentLoc;
1045    Decl *Param;
1046
1047    /// DefaultArgTokens - When the parameter's default argument
1048    /// cannot be parsed immediately (because it occurs within the
1049    /// declaration of a member function), it will be stored here as a
1050    /// sequence of tokens to be parsed once the class definition is
1051    /// complete. Non-NULL indicates that there is a default argument.
1052    CachedTokens *DefaultArgTokens;
1053
1054    ParamInfo() {}
1055    ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
1056              Decl *param,
1057              CachedTokens *DefArgTokens = 0)
1058      : Ident(ident), IdentLoc(iloc), Param(param),
1059        DefaultArgTokens(DefArgTokens) {}
1060  };
1061
1062  struct TypeAndRange {
1063    ParsedType Ty;
1064    SourceRange Range;
1065  };
1066
1067  struct FunctionTypeInfo : TypeInfoCommon {
1068    /// hasPrototype - This is true if the function had at least one typed
1069    /// argument.  If the function is () or (a,b,c), then it has no prototype,
1070    /// and is treated as a K&R-style function.
1071    unsigned hasPrototype : 1;
1072
1073    /// isVariadic - If this function has a prototype, and if that
1074    /// proto ends with ',...)', this is true. When true, EllipsisLoc
1075    /// contains the location of the ellipsis.
1076    unsigned isVariadic : 1;
1077
1078    /// \brief Whether the ref-qualifier (if any) is an lvalue reference.
1079    /// Otherwise, it's an rvalue reference.
1080    unsigned RefQualifierIsLValueRef : 1;
1081
1082    /// The type qualifiers: const/volatile/restrict.
1083    /// The qualifier bitmask values are the same as in QualType.
1084    unsigned TypeQuals : 3;
1085
1086    /// ExceptionSpecType - An ExceptionSpecificationType value.
1087    unsigned ExceptionSpecType : 3;
1088
1089    /// DeleteArgInfo - If this is true, we need to delete[] ArgInfo.
1090    unsigned DeleteArgInfo : 1;
1091
1092    /// When isVariadic is true, the location of the ellipsis in the source.
1093    unsigned EllipsisLoc;
1094
1095    /// NumArgs - This is the number of formal arguments provided for the
1096    /// declarator.
1097    unsigned NumArgs;
1098
1099    /// NumExceptions - This is the number of types in the dynamic-exception-
1100    /// decl, if the function has one.
1101    unsigned NumExceptions;
1102
1103    /// \brief The location of the ref-qualifier, if any.
1104    ///
1105    /// If this is an invalid location, there is no ref-qualifier.
1106    unsigned RefQualifierLoc;
1107
1108    /// \brief The location of the const-qualifier, if any.
1109    ///
1110    /// If this is an invalid location, there is no const-qualifier.
1111    unsigned ConstQualifierLoc;
1112
1113    /// \brief The location of the volatile-qualifier, if any.
1114    ///
1115    /// If this is an invalid location, there is no volatile-qualifier.
1116    unsigned VolatileQualifierLoc;
1117
1118    /// \brief The location of the 'mutable' qualifer in a lambda-declarator, if
1119    /// any.
1120    unsigned MutableLoc;
1121
1122    /// \brief When ExceptionSpecType isn't EST_None or EST_Delayed, the
1123    /// location of the keyword introducing the spec.
1124    unsigned ExceptionSpecLoc;
1125
1126    /// ArgInfo - This is a pointer to a new[]'d array of ParamInfo objects that
1127    /// describe the arguments for this function declarator.  This is null if
1128    /// there are no arguments specified.
1129    ParamInfo *ArgInfo;
1130
1131    union {
1132      /// \brief Pointer to a new[]'d array of TypeAndRange objects that
1133      /// contain the types in the function's dynamic exception specification
1134      /// and their locations, if there is one.
1135      TypeAndRange *Exceptions;
1136
1137      /// \brief Pointer to the expression in the noexcept-specifier of this
1138      /// function, if it has one.
1139      Expr *NoexceptExpr;
1140    };
1141
1142    /// TrailingReturnType - If this isn't null, it's the trailing return type
1143    /// specified. This is actually a ParsedType, but stored as void* to
1144    /// allow union storage.
1145    void *TrailingReturnType;
1146
1147    /// freeArgs - reset the argument list to having zero arguments.  This is
1148    /// used in various places for error recovery.
1149    void freeArgs() {
1150      if (DeleteArgInfo) {
1151        delete[] ArgInfo;
1152        DeleteArgInfo = false;
1153      }
1154      NumArgs = 0;
1155    }
1156
1157    void destroy() {
1158      if (DeleteArgInfo)
1159        delete[] ArgInfo;
1160      if (getExceptionSpecType() == EST_Dynamic)
1161        delete[] Exceptions;
1162    }
1163
1164    /// isKNRPrototype - Return true if this is a K&R style identifier list,
1165    /// like "void foo(a,b,c)".  In a function definition, this will be followed
1166    /// by the argument type definitions.
1167    bool isKNRPrototype() const {
1168      return !hasPrototype && NumArgs != 0;
1169    }
1170
1171    SourceLocation getEllipsisLoc() const {
1172      return SourceLocation::getFromRawEncoding(EllipsisLoc);
1173    }
1174    SourceLocation getExceptionSpecLoc() const {
1175      return SourceLocation::getFromRawEncoding(ExceptionSpecLoc);
1176    }
1177
1178    /// \brief Retrieve the location of the ref-qualifier, if any.
1179    SourceLocation getRefQualifierLoc() const {
1180      return SourceLocation::getFromRawEncoding(RefQualifierLoc);
1181    }
1182
1183    /// \brief Retrieve the location of the ref-qualifier, if any.
1184    SourceLocation getConstQualifierLoc() const {
1185      return SourceLocation::getFromRawEncoding(ConstQualifierLoc);
1186    }
1187
1188    /// \brief Retrieve the location of the ref-qualifier, if any.
1189    SourceLocation getVolatileQualifierLoc() const {
1190      return SourceLocation::getFromRawEncoding(VolatileQualifierLoc);
1191    }
1192
1193    /// \brief Retrieve the location of the 'mutable' qualifier, if any.
1194    SourceLocation getMutableLoc() const {
1195      return SourceLocation::getFromRawEncoding(MutableLoc);
1196    }
1197
1198    /// \brief Determine whether this function declaration contains a
1199    /// ref-qualifier.
1200    bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
1201
1202    /// \brief Determine whether this lambda-declarator contains a 'mutable'
1203    /// qualifier.
1204    bool hasMutableQualifier() const { return getMutableLoc().isValid(); }
1205
1206    /// \brief Get the type of exception specification this function has.
1207    ExceptionSpecificationType getExceptionSpecType() const {
1208      return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
1209    }
1210  };
1211
1212  struct BlockPointerTypeInfo : TypeInfoCommon {
1213    /// For now, sema will catch these as invalid.
1214    /// The type qualifiers: const/volatile/restrict.
1215    unsigned TypeQuals : 3;
1216
1217    void destroy() {
1218    }
1219  };
1220
1221  struct MemberPointerTypeInfo : TypeInfoCommon {
1222    /// The type qualifiers: const/volatile/restrict.
1223    unsigned TypeQuals : 3;
1224    // CXXScopeSpec has a constructor, so it can't be a direct member.
1225    // So we need some pointer-aligned storage and a bit of trickery.
1226    union {
1227      void *Aligner;
1228      char Mem[sizeof(CXXScopeSpec)];
1229    } ScopeMem;
1230    CXXScopeSpec &Scope() {
1231      return *reinterpret_cast<CXXScopeSpec*>(ScopeMem.Mem);
1232    }
1233    const CXXScopeSpec &Scope() const {
1234      return *reinterpret_cast<const CXXScopeSpec*>(ScopeMem.Mem);
1235    }
1236    void destroy() {
1237      Scope().~CXXScopeSpec();
1238    }
1239  };
1240
1241  union {
1242    TypeInfoCommon        Common;
1243    PointerTypeInfo       Ptr;
1244    ReferenceTypeInfo     Ref;
1245    ArrayTypeInfo         Arr;
1246    FunctionTypeInfo      Fun;
1247    BlockPointerTypeInfo  Cls;
1248    MemberPointerTypeInfo Mem;
1249  };
1250
1251  void destroy() {
1252    switch (Kind) {
1253    default: llvm_unreachable("Unknown decl type!");
1254    case DeclaratorChunk::Function:      return Fun.destroy();
1255    case DeclaratorChunk::Pointer:       return Ptr.destroy();
1256    case DeclaratorChunk::BlockPointer:  return Cls.destroy();
1257    case DeclaratorChunk::Reference:     return Ref.destroy();
1258    case DeclaratorChunk::Array:         return Arr.destroy();
1259    case DeclaratorChunk::MemberPointer: return Mem.destroy();
1260    case DeclaratorChunk::Paren:         return;
1261    }
1262  }
1263
1264  /// getAttrs - If there are attributes applied to this declaratorchunk, return
1265  /// them.
1266  const AttributeList *getAttrs() const {
1267    return Common.AttrList;
1268  }
1269
1270  AttributeList *&getAttrListRef() {
1271    return Common.AttrList;
1272  }
1273
1274  /// getPointer - Return a DeclaratorChunk for a pointer.
1275  ///
1276  static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
1277                                    SourceLocation ConstQualLoc,
1278                                    SourceLocation VolatileQualLoc,
1279                                    SourceLocation RestrictQualLoc) {
1280    DeclaratorChunk I;
1281    I.Kind                = Pointer;
1282    I.Loc                 = Loc;
1283    I.Ptr.TypeQuals       = TypeQuals;
1284    I.Ptr.ConstQualLoc    = ConstQualLoc.getRawEncoding();
1285    I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding();
1286    I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding();
1287    I.Ptr.AttrList        = 0;
1288    return I;
1289  }
1290
1291  /// getReference - Return a DeclaratorChunk for a reference.
1292  ///
1293  static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
1294                                      bool lvalue) {
1295    DeclaratorChunk I;
1296    I.Kind            = Reference;
1297    I.Loc             = Loc;
1298    I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
1299    I.Ref.LValueRef   = lvalue;
1300    I.Ref.AttrList    = 0;
1301    return I;
1302  }
1303
1304  /// getArray - Return a DeclaratorChunk for an array.
1305  ///
1306  static DeclaratorChunk getArray(unsigned TypeQuals,
1307                                  bool isStatic, bool isStar, Expr *NumElts,
1308                                  SourceLocation LBLoc, SourceLocation RBLoc) {
1309    DeclaratorChunk I;
1310    I.Kind          = Array;
1311    I.Loc           = LBLoc;
1312    I.EndLoc        = RBLoc;
1313    I.Arr.AttrList  = 0;
1314    I.Arr.TypeQuals = TypeQuals;
1315    I.Arr.hasStatic = isStatic;
1316    I.Arr.isStar    = isStar;
1317    I.Arr.NumElts   = NumElts;
1318    return I;
1319  }
1320
1321  /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
1322  /// "TheDeclarator" is the declarator that this will be added to.
1323  static DeclaratorChunk getFunction(bool hasProto, bool isVariadic,
1324                                     SourceLocation EllipsisLoc,
1325                                     ParamInfo *ArgInfo, unsigned NumArgs,
1326                                     unsigned TypeQuals,
1327                                     bool RefQualifierIsLvalueRef,
1328                                     SourceLocation RefQualifierLoc,
1329                                     SourceLocation ConstQualifierLoc,
1330                                     SourceLocation VolatileQualifierLoc,
1331                                     SourceLocation MutableLoc,
1332                                     ExceptionSpecificationType ESpecType,
1333                                     SourceLocation ESpecLoc,
1334                                     ParsedType *Exceptions,
1335                                     SourceRange *ExceptionRanges,
1336                                     unsigned NumExceptions,
1337                                     Expr *NoexceptExpr,
1338                                     SourceLocation LocalRangeBegin,
1339                                     SourceLocation LocalRangeEnd,
1340                                     Declarator &TheDeclarator,
1341                                     ParsedType TrailingReturnType =
1342                                                    ParsedType());
1343
1344  /// getBlockPointer - Return a DeclaratorChunk for a block.
1345  ///
1346  static DeclaratorChunk getBlockPointer(unsigned TypeQuals,
1347                                         SourceLocation Loc) {
1348    DeclaratorChunk I;
1349    I.Kind          = BlockPointer;
1350    I.Loc           = Loc;
1351    I.Cls.TypeQuals = TypeQuals;
1352    I.Cls.AttrList  = 0;
1353    return I;
1354  }
1355
1356  static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS,
1357                                          unsigned TypeQuals,
1358                                          SourceLocation Loc) {
1359    DeclaratorChunk I;
1360    I.Kind          = MemberPointer;
1361    I.Loc           = Loc;
1362    I.Mem.TypeQuals = TypeQuals;
1363    I.Mem.AttrList  = 0;
1364    new (I.Mem.ScopeMem.Mem) CXXScopeSpec(SS);
1365    return I;
1366  }
1367
1368  /// getParen - Return a DeclaratorChunk for a paren.
1369  ///
1370  static DeclaratorChunk getParen(SourceLocation LParenLoc,
1371                                  SourceLocation RParenLoc) {
1372    DeclaratorChunk I;
1373    I.Kind          = Paren;
1374    I.Loc           = LParenLoc;
1375    I.EndLoc        = RParenLoc;
1376    I.Common.AttrList = 0;
1377    return I;
1378  }
1379
1380};
1381
1382/// \brief Described the kind of function definition (if any) provided for
1383/// a function.
1384enum FunctionDefinitionKind {
1385  FDK_Declaration,
1386  FDK_Definition,
1387  FDK_Defaulted,
1388  FDK_Deleted
1389};
1390
1391/// Declarator - Information about one declarator, including the parsed type
1392/// information and the identifier.  When the declarator is fully formed, this
1393/// is turned into the appropriate Decl object.
1394///
1395/// Declarators come in two types: normal declarators and abstract declarators.
1396/// Abstract declarators are used when parsing types, and don't have an
1397/// identifier.  Normal declarators do have ID's.
1398///
1399/// Instances of this class should be a transient object that lives on the
1400/// stack, not objects that are allocated in large quantities on the heap.
1401class Declarator {
1402public:
1403  enum TheContext {
1404    FileContext,         // File scope declaration.
1405    PrototypeContext,    // Within a function prototype.
1406    ObjCResultContext,   // An ObjC method result type.
1407    ObjCParameterContext,// An ObjC method parameter type.
1408    KNRTypeListContext,  // K&R type definition list for formals.
1409    TypeNameContext,     // Abstract declarator for types.
1410    MemberContext,       // Struct/Union field.
1411    BlockContext,        // Declaration within a block in a function.
1412    ForContext,          // Declaration within first part of a for loop.
1413    ConditionContext,    // Condition declaration in a C++ if/switch/while/for.
1414    TemplateParamContext,// Within a template parameter list.
1415    CXXNewContext,       // C++ new-expression.
1416    CXXCatchContext,     // C++ catch exception-declaration
1417    ObjCCatchContext,    // Objective-C catch exception-declaration
1418    BlockLiteralContext,  // Block literal declarator.
1419    LambdaExprContext,   // Lambda-expression declarator.
1420    TemplateTypeArgContext, // Template type argument.
1421    AliasDeclContext,    // C++0x alias-declaration.
1422    AliasTemplateContext // C++0x alias-declaration template.
1423  };
1424
1425private:
1426  const DeclSpec &DS;
1427  CXXScopeSpec SS;
1428  UnqualifiedId Name;
1429  SourceRange Range;
1430
1431  /// Context - Where we are parsing this declarator.
1432  ///
1433  TheContext Context;
1434
1435  /// DeclTypeInfo - This holds each type that the declarator includes as it is
1436  /// parsed.  This is pushed from the identifier out, which means that element
1437  /// #0 will be the most closely bound to the identifier, and
1438  /// DeclTypeInfo.back() will be the least closely bound.
1439  SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
1440
1441  /// InvalidType - Set by Sema::GetTypeForDeclarator().
1442  bool InvalidType : 1;
1443
1444  /// GroupingParens - Set by Parser::ParseParenDeclarator().
1445  bool GroupingParens : 1;
1446
1447  /// FunctionDefinition - Is this Declarator for a function or member
1448  /// definition and, if so, what kind?
1449  ///
1450  /// Actually a FunctionDefinitionKind.
1451  unsigned FunctionDefinition : 2;
1452
1453  // Redeclaration - Is this Declarator is a redeclaration.
1454  bool Redeclaration : 1;
1455
1456  /// Attrs - Attributes.
1457  ParsedAttributes Attrs;
1458
1459  /// AsmLabel - The asm label, if specified.
1460  Expr *AsmLabel;
1461
1462  /// InlineParams - This is a local array used for the first function decl
1463  /// chunk to avoid going to the heap for the common case when we have one
1464  /// function chunk in the declarator.
1465  DeclaratorChunk::ParamInfo InlineParams[16];
1466  bool InlineParamsUsed;
1467
1468  /// Extension - true if the declaration is preceded by __extension__.
1469  bool Extension : 1;
1470
1471  /// \brief If provided, the source location of the ellipsis used to describe
1472  /// this declarator as a parameter pack.
1473  SourceLocation EllipsisLoc;
1474
1475  friend struct DeclaratorChunk;
1476
1477public:
1478  Declarator(const DeclSpec &ds, TheContext C)
1479    : DS(ds), Range(ds.getSourceRange()), Context(C),
1480      InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
1481      GroupingParens(false), FunctionDefinition(FDK_Declaration),
1482      Redeclaration(false),
1483      Attrs(ds.getAttributePool().getFactory()), AsmLabel(0),
1484      InlineParamsUsed(false), Extension(false) {
1485  }
1486
1487  ~Declarator() {
1488    clear();
1489  }
1490
1491  /// getDeclSpec - Return the declaration-specifier that this declarator was
1492  /// declared with.
1493  const DeclSpec &getDeclSpec() const { return DS; }
1494
1495  /// getMutableDeclSpec - Return a non-const version of the DeclSpec.  This
1496  /// should be used with extreme care: declspecs can often be shared between
1497  /// multiple declarators, so mutating the DeclSpec affects all of the
1498  /// Declarators.  This should only be done when the declspec is known to not
1499  /// be shared or when in error recovery etc.
1500  DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); }
1501
1502  AttributePool &getAttributePool() const {
1503    return Attrs.getPool();
1504  }
1505
1506  /// getCXXScopeSpec - Return the C++ scope specifier (global scope or
1507  /// nested-name-specifier) that is part of the declarator-id.
1508  const CXXScopeSpec &getCXXScopeSpec() const { return SS; }
1509  CXXScopeSpec &getCXXScopeSpec() { return SS; }
1510
1511  /// \brief Retrieve the name specified by this declarator.
1512  UnqualifiedId &getName() { return Name; }
1513
1514  TheContext getContext() const { return Context; }
1515
1516  bool isPrototypeContext() const {
1517    return (Context == PrototypeContext ||
1518            Context == ObjCParameterContext ||
1519            Context == ObjCResultContext);
1520  }
1521
1522  /// getSourceRange - Get the source range that spans this declarator.
1523  const SourceRange &getSourceRange() const { return Range; }
1524
1525  void SetSourceRange(SourceRange R) { Range = R; }
1526  /// SetRangeBegin - Set the start of the source range to Loc, unless it's
1527  /// invalid.
1528  void SetRangeBegin(SourceLocation Loc) {
1529    if (!Loc.isInvalid())
1530      Range.setBegin(Loc);
1531  }
1532  /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
1533  void SetRangeEnd(SourceLocation Loc) {
1534    if (!Loc.isInvalid())
1535      Range.setEnd(Loc);
1536  }
1537  /// ExtendWithDeclSpec - Extend the declarator source range to include the
1538  /// given declspec, unless its location is invalid. Adopts the range start if
1539  /// the current range start is invalid.
1540  void ExtendWithDeclSpec(const DeclSpec &DS) {
1541    const SourceRange &SR = DS.getSourceRange();
1542    if (Range.getBegin().isInvalid())
1543      Range.setBegin(SR.getBegin());
1544    if (!SR.getEnd().isInvalid())
1545      Range.setEnd(SR.getEnd());
1546  }
1547
1548  /// clear - Reset the contents of this Declarator.
1549  void clear() {
1550    SS.clear();
1551    Name.clear();
1552    Range = DS.getSourceRange();
1553
1554    for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
1555      DeclTypeInfo[i].destroy();
1556    DeclTypeInfo.clear();
1557    Attrs.clear();
1558    AsmLabel = 0;
1559    InlineParamsUsed = false;
1560  }
1561
1562  /// mayOmitIdentifier - Return true if the identifier is either optional or
1563  /// not allowed.  This is true for typenames, prototypes, and template
1564  /// parameter lists.
1565  bool mayOmitIdentifier() const {
1566    switch (Context) {
1567    case FileContext:
1568    case KNRTypeListContext:
1569    case MemberContext:
1570    case BlockContext:
1571    case ForContext:
1572    case ConditionContext:
1573      return false;
1574
1575    case TypeNameContext:
1576    case AliasDeclContext:
1577    case AliasTemplateContext:
1578    case PrototypeContext:
1579    case ObjCParameterContext:
1580    case ObjCResultContext:
1581    case TemplateParamContext:
1582    case CXXNewContext:
1583    case CXXCatchContext:
1584    case ObjCCatchContext:
1585    case BlockLiteralContext:
1586    case LambdaExprContext:
1587    case TemplateTypeArgContext:
1588      return true;
1589    }
1590    llvm_unreachable("unknown context kind!");
1591  }
1592
1593  /// mayHaveIdentifier - Return true if the identifier is either optional or
1594  /// required.  This is true for normal declarators and prototypes, but not
1595  /// typenames.
1596  bool mayHaveIdentifier() const {
1597    switch (Context) {
1598    case FileContext:
1599    case KNRTypeListContext:
1600    case MemberContext:
1601    case BlockContext:
1602    case ForContext:
1603    case ConditionContext:
1604    case PrototypeContext:
1605    case TemplateParamContext:
1606    case CXXCatchContext:
1607    case ObjCCatchContext:
1608      return true;
1609
1610    case TypeNameContext:
1611    case CXXNewContext:
1612    case AliasDeclContext:
1613    case AliasTemplateContext:
1614    case ObjCParameterContext:
1615    case ObjCResultContext:
1616    case BlockLiteralContext:
1617    case LambdaExprContext:
1618    case TemplateTypeArgContext:
1619      return false;
1620    }
1621    llvm_unreachable("unknown context kind!");
1622  }
1623
1624  /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be
1625  /// followed by a C++ direct initializer, e.g. "int x(1);".
1626  bool mayBeFollowedByCXXDirectInit() const {
1627    if (hasGroupingParens()) return false;
1628
1629    switch (Context) {
1630    case FileContext:
1631    case BlockContext:
1632    case ForContext:
1633      return true;
1634
1635    case KNRTypeListContext:
1636    case MemberContext:
1637    case ConditionContext:
1638    case PrototypeContext:
1639    case ObjCParameterContext:
1640    case ObjCResultContext:
1641    case TemplateParamContext:
1642    case CXXCatchContext:
1643    case ObjCCatchContext:
1644    case TypeNameContext:
1645    case CXXNewContext:
1646    case AliasDeclContext:
1647    case AliasTemplateContext:
1648    case BlockLiteralContext:
1649    case LambdaExprContext:
1650    case TemplateTypeArgContext:
1651      return false;
1652    }
1653    llvm_unreachable("unknown context kind!");
1654  }
1655
1656  /// isPastIdentifier - Return true if we have parsed beyond the point where
1657  /// the
1658  bool isPastIdentifier() const { return Name.isValid(); }
1659
1660  /// hasName - Whether this declarator has a name, which might be an
1661  /// identifier (accessible via getIdentifier()) or some kind of
1662  /// special C++ name (constructor, destructor, etc.).
1663  bool hasName() const {
1664    return Name.getKind() != UnqualifiedId::IK_Identifier || Name.Identifier;
1665  }
1666
1667  IdentifierInfo *getIdentifier() const {
1668    if (Name.getKind() == UnqualifiedId::IK_Identifier)
1669      return Name.Identifier;
1670
1671    return 0;
1672  }
1673  SourceLocation getIdentifierLoc() const { return Name.StartLocation; }
1674
1675  /// \brief Set the name of this declarator to be the given identifier.
1676  void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) {
1677    Name.setIdentifier(Id, IdLoc);
1678  }
1679
1680  /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
1681  /// EndLoc, which should be the last token of the chunk.
1682  void AddTypeInfo(const DeclaratorChunk &TI,
1683                   ParsedAttributes &attrs,
1684                   SourceLocation EndLoc) {
1685    DeclTypeInfo.push_back(TI);
1686    DeclTypeInfo.back().getAttrListRef() = attrs.getList();
1687    getAttributePool().takeAllFrom(attrs.getPool());
1688
1689    if (!EndLoc.isInvalid())
1690      SetRangeEnd(EndLoc);
1691  }
1692
1693  /// AddInnermostTypeInfo - Add a new innermost chunk to this declarator.
1694  void AddInnermostTypeInfo(const DeclaratorChunk &TI) {
1695    DeclTypeInfo.insert(DeclTypeInfo.begin(), TI);
1696  }
1697
1698  /// getNumTypeObjects() - Return the number of types applied to this
1699  /// declarator.
1700  unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); }
1701
1702  /// Return the specified TypeInfo from this declarator.  TypeInfo #0 is
1703  /// closest to the identifier.
1704  const DeclaratorChunk &getTypeObject(unsigned i) const {
1705    assert(i < DeclTypeInfo.size() && "Invalid type chunk");
1706    return DeclTypeInfo[i];
1707  }
1708  DeclaratorChunk &getTypeObject(unsigned i) {
1709    assert(i < DeclTypeInfo.size() && "Invalid type chunk");
1710    return DeclTypeInfo[i];
1711  }
1712
1713  void DropFirstTypeObject()
1714  {
1715    assert(!DeclTypeInfo.empty() && "No type chunks to drop.");
1716    DeclTypeInfo.front().destroy();
1717    DeclTypeInfo.erase(DeclTypeInfo.begin());
1718  }
1719
1720  /// isArrayOfUnknownBound - This method returns true if the declarator
1721  /// is a declarator for an array of unknown bound (looking through
1722  /// parentheses).
1723  bool isArrayOfUnknownBound() const {
1724    for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
1725      switch (DeclTypeInfo[i].Kind) {
1726      case DeclaratorChunk::Paren:
1727        continue;
1728      case DeclaratorChunk::Function:
1729      case DeclaratorChunk::Pointer:
1730      case DeclaratorChunk::Reference:
1731      case DeclaratorChunk::BlockPointer:
1732      case DeclaratorChunk::MemberPointer:
1733        return false;
1734      case DeclaratorChunk::Array:
1735        return !DeclTypeInfo[i].Arr.NumElts;
1736      }
1737      llvm_unreachable("Invalid type chunk");
1738      return false;
1739    }
1740    return false;
1741  }
1742
1743  /// isFunctionDeclarator - This method returns true if the declarator
1744  /// is a function declarator (looking through parentheses).
1745  /// If true is returned, then the reference type parameter idx is
1746  /// assigned with the index of the declaration chunk.
1747  bool isFunctionDeclarator(unsigned& idx) const {
1748    for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
1749      switch (DeclTypeInfo[i].Kind) {
1750      case DeclaratorChunk::Function:
1751        idx = i;
1752        return true;
1753      case DeclaratorChunk::Paren:
1754        continue;
1755      case DeclaratorChunk::Pointer:
1756      case DeclaratorChunk::Reference:
1757      case DeclaratorChunk::Array:
1758      case DeclaratorChunk::BlockPointer:
1759      case DeclaratorChunk::MemberPointer:
1760        return false;
1761      }
1762      llvm_unreachable("Invalid type chunk");
1763      return false;
1764    }
1765    return false;
1766  }
1767
1768  /// isFunctionDeclarator - Once this declarator is fully parsed and formed,
1769  /// this method returns true if the identifier is a function declarator
1770  /// (looking through parentheses).
1771  bool isFunctionDeclarator() const {
1772    unsigned index;
1773    return isFunctionDeclarator(index);
1774  }
1775
1776  /// getFunctionTypeInfo - Retrieves the function type info object
1777  /// (looking through parentheses).
1778  DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() {
1779    assert(isFunctionDeclarator() && "Not a function declarator!");
1780    unsigned index = 0;
1781    isFunctionDeclarator(index);
1782    return DeclTypeInfo[index].Fun;
1783  }
1784
1785  /// getFunctionTypeInfo - Retrieves the function type info object
1786  /// (looking through parentheses).
1787  const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const {
1788    return const_cast<Declarator*>(this)->getFunctionTypeInfo();
1789  }
1790
1791  /// \brief Determine whether the declaration that will be produced from
1792  /// this declaration will be a function.
1793  ///
1794  /// A declaration can declare a function even if the declarator itself
1795  /// isn't a function declarator, if the type specifier refers to a function
1796  /// type. This routine checks for both cases.
1797  bool isDeclarationOfFunction() const;
1798
1799  /// takeAttributes - Takes attributes from the given parsed-attributes
1800  /// set and add them to this declarator.
1801  ///
1802  /// These examples both add 3 attributes to "var":
1803  ///  short int var __attribute__((aligned(16),common,deprecated));
1804  ///  short int x, __attribute__((aligned(16)) var
1805  ///                                 __attribute__((common,deprecated));
1806  ///
1807  /// Also extends the range of the declarator.
1808  void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc) {
1809    Attrs.takeAllFrom(attrs);
1810
1811    if (!lastLoc.isInvalid())
1812      SetRangeEnd(lastLoc);
1813  }
1814
1815  const AttributeList *getAttributes() const { return Attrs.getList(); }
1816  AttributeList *getAttributes() { return Attrs.getList(); }
1817
1818  AttributeList *&getAttrListRef() { return Attrs.getListRef(); }
1819
1820  /// hasAttributes - do we contain any attributes?
1821  bool hasAttributes() const {
1822    if (getAttributes() || getDeclSpec().hasAttributes()) return true;
1823    for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
1824      if (getTypeObject(i).getAttrs())
1825        return true;
1826    return false;
1827  }
1828
1829  void setAsmLabel(Expr *E) { AsmLabel = E; }
1830  Expr *getAsmLabel() const { return AsmLabel; }
1831
1832  void setExtension(bool Val = true) { Extension = Val; }
1833  bool getExtension() const { return Extension; }
1834
1835  void setInvalidType(bool Val = true) { InvalidType = Val; }
1836  bool isInvalidType() const {
1837    return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error;
1838  }
1839
1840  void setGroupingParens(bool flag) { GroupingParens = flag; }
1841  bool hasGroupingParens() const { return GroupingParens; }
1842
1843  bool hasEllipsis() const { return EllipsisLoc.isValid(); }
1844  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
1845  void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; }
1846
1847  void setFunctionDefinitionKind(FunctionDefinitionKind Val) {
1848    FunctionDefinition = Val;
1849  }
1850
1851  bool isFunctionDefinition() const {
1852    return getFunctionDefinitionKind() != FDK_Declaration;
1853  }
1854
1855  FunctionDefinitionKind getFunctionDefinitionKind() const {
1856    return (FunctionDefinitionKind)FunctionDefinition;
1857  }
1858
1859  void setRedeclaration(bool Val) { Redeclaration = Val; }
1860  bool isRedeclaration() const { return Redeclaration; }
1861};
1862
1863/// FieldDeclarator - This little struct is used to capture information about
1864/// structure field declarators, which is basically just a bitfield size.
1865struct FieldDeclarator {
1866  Declarator D;
1867  Expr *BitfieldSize;
1868  explicit FieldDeclarator(DeclSpec &DS) : D(DS, Declarator::MemberContext) {
1869    BitfieldSize = 0;
1870  }
1871};
1872
1873/// VirtSpecifiers - Represents a C++0x virt-specifier-seq.
1874class VirtSpecifiers {
1875public:
1876  enum Specifier {
1877    VS_None = 0,
1878    VS_Override = 1,
1879    VS_Final = 2
1880  };
1881
1882  VirtSpecifiers() : Specifiers(0) { }
1883
1884  bool SetSpecifier(Specifier VS, SourceLocation Loc,
1885                    const char *&PrevSpec);
1886
1887  bool isOverrideSpecified() const { return Specifiers & VS_Override; }
1888  SourceLocation getOverrideLoc() const { return VS_overrideLoc; }
1889
1890  bool isFinalSpecified() const { return Specifiers & VS_Final; }
1891  SourceLocation getFinalLoc() const { return VS_finalLoc; }
1892
1893  void clear() { Specifiers = 0; }
1894
1895  static const char *getSpecifierName(Specifier VS);
1896
1897  SourceLocation getLastLocation() const { return LastLocation; }
1898
1899private:
1900  unsigned Specifiers;
1901
1902  SourceLocation VS_overrideLoc, VS_finalLoc;
1903  SourceLocation LastLocation;
1904};
1905
1906/// LambdaCaptureDefault - The default, if any, capture method for a
1907/// lambda expression.
1908enum LambdaCaptureDefault {
1909  LCD_None,
1910  LCD_ByCopy,
1911  LCD_ByRef
1912};
1913
1914/// LambdaCaptureKind - The different capture forms in a lambda
1915/// introducer: 'this' or a copied or referenced variable.
1916enum LambdaCaptureKind {
1917  LCK_This,
1918  LCK_ByCopy,
1919  LCK_ByRef
1920};
1921
1922/// LambdaCapture - An individual capture in a lambda introducer.
1923struct LambdaCapture {
1924  LambdaCaptureKind Kind;
1925  SourceLocation Loc;
1926  IdentifierInfo* Id;
1927
1928  LambdaCapture(LambdaCaptureKind Kind,
1929                     SourceLocation Loc,
1930                     IdentifierInfo* Id = 0)
1931    : Kind(Kind), Loc(Loc), Id(Id)
1932  {}
1933};
1934
1935/// LambdaIntroducer - Represents a complete lambda introducer.
1936struct LambdaIntroducer {
1937  SourceRange Range;
1938  LambdaCaptureDefault Default;
1939  llvm::SmallVector<LambdaCapture, 4> Captures;
1940
1941  LambdaIntroducer()
1942    : Default(LCD_None) {}
1943
1944  /// addCapture - Append a capture in a lambda introducer.
1945  void addCapture(LambdaCaptureKind Kind,
1946                  SourceLocation Loc,
1947                  IdentifierInfo* Id = 0) {
1948    Captures.push_back(LambdaCapture(Kind, Loc, Id));
1949  }
1950
1951};
1952
1953} // end namespace clang
1954
1955#endif
1956