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