DeclSpec.h revision 7604f64a865bdba86c05cab76bcd47fd10372eb8
119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall//===--- DeclSpec.h - Parsed declaration specifiers -------------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
1019510856727e0e14a3696b2a72c35163bff2a71fJohn McCall// This file defines the classes used to store parsed information about
1119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall// declaration-specifiers and declarators.
1219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall//
1319510856727e0e14a3696b2a72c35163bff2a71fJohn McCall//   static const int volatile x, *y, *(*(*z)[10])(const void *x);
1419510856727e0e14a3696b2a72c35163bff2a71fJohn McCall//   ------------------------- -  --  ---------------------------
1519510856727e0e14a3696b2a72c35163bff2a71fJohn McCall//     declaration-specifiers  \  |   /
1619510856727e0e14a3696b2a72c35163bff2a71fJohn McCall//                            declarators
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2019510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#ifndef LLVM_CLANG_SEMA_DECLSPEC_H
2119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#define LLVM_CLANG_SEMA_DECLSPEC_H
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2319510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/AttributeList.h"
24b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall#include "clang/Sema/Ownership.h"
255f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
2672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor#include "clang/Lex/Token.h"
278b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl#include "clang/Basic/ExceptionSpecificationType.h"
288f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner#include "clang/Basic/OperatorKinds.h"
29ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor#include "clang/Basic/Specifiers.h"
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h"
31075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara#include "llvm/Support/ErrorHandling.h"
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
342e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  class ASTContext;
352e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  class TypeLoc;
3643af76e845c95be160c088ec11ba3c43e2527fa8Sebastian Redl  class LangOptions;
37e4858a65a93fb36c099d8dd2ea0a98e33e77687eDaniel Dunbar  class Diagnostic;
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class IdentifierInfo;
3914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  class NamespaceAliasDecl;
402e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  class NamespaceDecl;
41ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  class NestedNameSpecifier;
42c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  class NestedNameSpecifierLoc;
438f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner  class Preprocessor;
448f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner  class Declarator;
45314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  struct TemplateIdAnnotation;
46595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin
47aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall/// CXXScopeSpec - Represents a C++ nested-name-specifier or a global scope
48595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// specifier.  These can be in 3 states:
49595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin///   1) Not present, identified by isEmpty()
50595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin///   2) Present, identified by isNotEmpty()
51595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin///      2.a) Valid, idenified by isValid()
52595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin///      2.b) Invalid, identified by isInvalid().
53595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin///
54595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// isSet() is deprecated because it mostly corresponded to "valid" but was
55595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// often used as if it meant "present".
56595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin///
57595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// The actual scope is described by getScopeRep().
58aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCallclass CXXScopeSpec {
595f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  SourceRange Range;
605f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  NestedNameSpecifierLocBuilder Builder;
61aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall
62c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregorpublic:
63aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  const SourceRange &getRange() const { return Range; }
64aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  void setRange(const SourceRange &R) { Range = R; }
65aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
66aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
67aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  SourceLocation getBeginLoc() const { return Range.getBegin(); }
68aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  SourceLocation getEndLoc() const { return Range.getEnd(); }
69aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall
705f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  /// \brief Retrieve the representation of the nested-name-specifier.
715f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  NestedNameSpecifier *getScopeRep() const {
725f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor    return Builder.getRepresentation();
735f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  }
74aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall
752e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \brief Extend the current nested-name-specifier by another
762e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// nested-name-specifier component of the form 'type::'.
772e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
782e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param Context The AST context in which this nested-name-specifier
792e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// resides.
802e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
812e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param TemplateKWLoc The location of the 'template' keyword, if present.
822e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
832e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param TL The TypeLoc that describes the type preceding the '::'.
842e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
852e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param ColonColonLoc The location of the trailing '::'.
862e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL,
872e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor              SourceLocation ColonColonLoc);
882e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
892e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \brief Extend the current nested-name-specifier by another
902e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// nested-name-specifier component of the form 'identifier::'.
912e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
922e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param Context The AST context in which this nested-name-specifier
932e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// resides.
942e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
952e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param Identifier The identifier.
962e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
972e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param IdentifierLoc The location of the identifier.
982e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
992e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param ColonColonLoc The location of the trailing '::'.
1002e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  void Extend(ASTContext &Context, IdentifierInfo *Identifier,
1012e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor              SourceLocation IdentifierLoc, SourceLocation ColonColonLoc);
1022e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
1032e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \brief Extend the current nested-name-specifier by another
10414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// nested-name-specifier component of the form 'namespace::'.
1052e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
1062e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param Context The AST context in which this nested-name-specifier
1072e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// resides.
1082e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
1092e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param Namespace The namespace.
1102e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
11114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// \param NamespaceLoc The location of the namespace name.
1122e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  ///
1132e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \param ColonColonLoc The location of the trailing '::'.
1142e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  void Extend(ASTContext &Context, NamespaceDecl *Namespace,
1152e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor              SourceLocation NamespaceLoc, SourceLocation ColonColonLoc);
1162e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
11714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// \brief Extend the current nested-name-specifier by another
11814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// nested-name-specifier component of the form 'namespace-alias::'.
11914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  ///
12014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// \param Context The AST context in which this nested-name-specifier
12114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// resides.
12214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  ///
12314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// \param Alias The namespace alias.
12414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  ///
12514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// \param AliasLoc The location of the namespace alias
12614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// name.
12714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  ///
12814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  /// \param ColonColonLoc The location of the trailing '::'.
12914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor  void Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
13014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor              SourceLocation AliasLoc, SourceLocation ColonColonLoc);
13114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor
1322e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \brief Turn this (empty) nested-name-specifier into the global
1332e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// nested-name-specifier '::'.
1342e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc);
1352e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
136c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// \brief Make a new nested-name-specifier from incomplete source-location
137c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// information.
138c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  ///
139c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// FIXME: This routine should be used very, very rarely, in cases where we
140c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// need to synthesize a nested-name-specifier. Most code should instead use
141c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// \c Adopt() with a proper \c NestedNameSpecifierLoc.
142c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier,
143c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor                   SourceRange R);
144c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
145c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// \brief Adopt an existing nested-name-specifier (with source-range
146c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// information).
147c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  void Adopt(NestedNameSpecifierLoc Other);
1489ddba32f25c0315cd3a6c7b63e0275b27cc1d973Douglas Gregor
149c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// \brief Retrieve a nested-name-specifier with location information, copied
150c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// into the given AST context.
151c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  ///
152c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// \param Context The context into which this nested-name-specifier will be
153c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// copied.
154c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const;
155c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
156595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin  /// No scope specifier.
157aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  bool isEmpty() const { return !Range.isValid(); }
158595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin  /// A scope specifier is present, but may be valid or invalid.
159aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  bool isNotEmpty() const { return !isEmpty(); }
160aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall
161fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// An error occurred during parsing of the scope specifier.
1625f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  bool isInvalid() const { return isNotEmpty() && getScopeRep() == 0; }
163595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin  /// A scope specifier is present, and it refers to a real scope.
1645f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  bool isValid() const { return isNotEmpty() && getScopeRep() != 0; }
165aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall
1662e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  /// \brief Indicate that this nested-name-specifier is invalid.
1672e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  void SetInvalid(SourceRange R) {
1682e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor    assert(R.isValid() && "Must have a valid source range");
1692e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor    if (Range.getBegin().isInvalid())
1702e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor      Range.setBegin(R.getBegin());
1712e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor    Range.setEnd(R.getEnd());
1725f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor    Builder.Clear();
1732e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor  }
1742e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor
175595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin  /// Deprecated.  Some call sites intend isNotEmpty() while others intend
176595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin  /// isValid().
1775f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  bool isSet() const { return getScopeRep() != 0; }
178aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall
179aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  void clear() {
180aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall    Range = SourceRange();
1815f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor    Builder.Clear();
182aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  }
183c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
184c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// \brief Retrieve the data associated with the source-location information.
1855f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  char *location_data() const { return Builder.getBuffer().first; }
186c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor
187c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// \brief Retrieve the size of the data associated with source-location
188c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor  /// information.
1895f791bb44417ecc201ed57a85d0fe02001d8a615Douglas Gregor  unsigned location_size() const { return Builder.getBuffer().second; }
190aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall};
191aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclSpec - This class captures information about "declaration specifiers",
1937a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek/// which encompasses storage-class-specifiers, type-specifiers,
1947a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek/// type-qualifiers, and function-specifiers.
1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclSpec {
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // storage-class-specifier
198160b5630aa781ac348303e1ae088d27016637778Douglas Gregor  // Note: The order of these enumerators is important for diagnostics.
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum SCS {
200160b5630aa781ac348303e1ae088d27016637778Douglas Gregor    SCS_unspecified = 0,
2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SCS_typedef,
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SCS_extern,
2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SCS_static,
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SCS_auto,
205d6326c6fe586ba178734c49ba33a2c1af021822cSteve Naroff    SCS_register,
206669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl    SCS_private_extern,
207669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl    SCS_mutable
2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
2091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
210ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  // Import type specifier width enumeration and constants.
211ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  typedef TypeSpecifierWidth TSW;
212ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TSW TSW_unspecified = clang::TSW_unspecified;
213ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TSW TSW_short = clang::TSW_short;
214ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TSW TSW_long = clang::TSW_long;
215ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TSW TSW_longlong = clang::TSW_longlong;
216ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TSC {
2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TSC_unspecified,
2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TSC_imaginary,
2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TSC_complex
2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
223ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  // Import type specifier sign enumeration and constants.
224ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  typedef TypeSpecifierSign TSS;
225ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TSS TSS_unspecified = clang::TSS_unspecified;
226ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TSS TSS_signed = clang::TSS_signed;
227ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TSS TSS_unsigned = clang::TSS_unsigned;
228ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
229ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  // Import type specifier type enumeration and constants.
230ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  typedef TypeSpecifierType TST;
231ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_unspecified = clang::TST_unspecified;
232ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_void = clang::TST_void;
233ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_char = clang::TST_char;
234ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_wchar = clang::TST_wchar;
235ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_char16 = clang::TST_char16;
236ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_char32 = clang::TST_char32;
237ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_int = clang::TST_int;
238ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_float = clang::TST_float;
239ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_double = clang::TST_double;
240ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_bool = clang::TST_bool;
241ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_decimal32 = clang::TST_decimal32;
242ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_decimal64 = clang::TST_decimal64;
243ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_decimal128 = clang::TST_decimal128;
244ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_enum = clang::TST_enum;
245ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_union = clang::TST_union;
246ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_struct = clang::TST_struct;
247ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_class = clang::TST_class;
248ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_typename = clang::TST_typename;
249ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_typeofType = clang::TST_typeofType;
250ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_typeofExpr = clang::TST_typeofExpr;
251ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_decltype = clang::TST_decltype;
252ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_auto = clang::TST_auto;
253a5fc472b353b88be3b4981da946fb01f5a5cc0c6John McCall  static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
254ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  static const TST TST_error = clang::TST_error;
2551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type-qualifiers
2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum TQ {   // NOTE: These flags must be kept in sync with Qualifiers::TQ.
2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TQ_unspecified = 0,
2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TQ_const       = 1,
2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TQ_restrict    = 2,
2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TQ_volatile    = 4
2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParsedSpecifiers - Flags to query which specifiers were applied.  This is
2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// returned by getParsedSpecifiers.
2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ParsedSpecifiers {
2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PQ_None                  = 0,
2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PQ_StorageClassSpecifier = 1,
2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PQ_TypeSpecifier         = 2,
2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PQ_TypeQualifier         = 4,
2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PQ_FunctionSpecifier     = 8
2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
2731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // storage-class-specifier
2762efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner  /*SCS*/unsigned StorageClassSpec : 3;
2777f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned SCS_thread_specified : 1;
2787f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned SCS_extern_in_linkage_spec : 1;
2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type-specifier
2812efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner  /*TSW*/unsigned TypeSpecWidth : 2;
2822efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner  /*TSC*/unsigned TypeSpecComplex : 2;
2832efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner  /*TSS*/unsigned TypeSpecSign : 2;
28499dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner  /*TST*/unsigned TypeSpecType : 5;
2857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned TypeAltiVecVector : 1;
2867f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned TypeAltiVecPixel : 1;
2877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned TypeAltiVecBool : 1;
2887f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned TypeSpecOwned : 1;
289402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor
2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type-qualifiers
2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned TypeQualifiers : 3;  // Bitwise OR of TQ.
2921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // function-specifier
2947f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned FS_inline_specified : 1;
2957f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned FS_virtual_specified : 1;
2967f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned FS_explicit_specified : 1;
2971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
298f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson  // friend-specifier
2997f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned Friend_specified : 1;
3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3012ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  // constexpr-specifier
3027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  unsigned Constexpr_specified : 1;
3032ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl
30416573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor  /*SCS*/unsigned StorageClassSpecAsWritten : 3;
30516573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor
306b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  union {
307b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    UnionParsedType TypeRep;
308b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    Decl *DeclRep;
309b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    Expr *ExprRep;
310b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  };
3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // attributes.
3137f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ParsedAttributes Attrs;
3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
315aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  // Scope specifier for the type spec, if applicable.
316aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  CXXScopeSpec TypeScope;
317aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall
3181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // List of protocol qualifiers for objective-c classes.  Used for
31928c0b7df574599d4c19a4c09ca61bb3d70a338ccChris Lattner  // protocol-qualified interfaces "NString<foo>" and protocol-qualified id
32028c0b7df574599d4c19a4c09ca61bb3d70a338ccChris Lattner  // "id<foo>".
321d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl * const *ProtocolQualifiers;
322ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner  unsigned NumProtocolQualifiers;
32371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation ProtocolLAngleLoc;
32471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation *ProtocolLocs;
3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // SourceLocation info.  These are null if the item wasn't specified or if
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // the setting was synthesized.
32881c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  SourceRange Range;
3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation StorageClassSpecLoc, SCS_threadLoc;
33182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc;
3320daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
3330daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  /// typename, then this is the location of the named type (if present);
3340daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
3350daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  /// TSTNameLoc provides source range info for tag types.
3360daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  SourceLocation TSTNameLoc;
337cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceRange TypeofParensRange;
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc;
339b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc;
3402ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  SourceLocation FriendLoc, ConstexprLoc;
3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
342ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  WrittenBuiltinSpecs writtenBS;
343ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void SaveWrittenBuiltinSpecs();
34435f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  void SaveStorageSpecifierAsWritten();
345ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
346b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  static bool isTypeRep(TST T) {
347b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return (T == TST_typename || T == TST_typeofType);
348b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
349b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  static bool isExprRep(TST T) {
350b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return (T == TST_typeofExpr || T == TST_decltype);
351b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
352b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  static bool isDeclRep(TST T) {
353b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return (T == TST_enum || T == TST_struct ||
354b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall            T == TST_union || T == TST_class);
355b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
356b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
357ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner  DeclSpec(const DeclSpec&);       // DO NOT IMPLEMENT
358ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner  void operator=(const DeclSpec&); // DO NOT IMPLEMENT
3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3610b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  DeclSpec(AttributeFactory &attrFactory)
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : StorageClassSpec(SCS_unspecified),
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      SCS_thread_specified(false),
36435f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara      SCS_extern_in_linkage_spec(false),
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecWidth(TSW_unspecified),
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecComplex(TSC_unspecified),
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecSign(TSS_unspecified),
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeSpecType(TST_unspecified),
36982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson      TypeAltiVecVector(false),
37082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson      TypeAltiVecPixel(false),
371788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      TypeAltiVecBool(false),
372402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor      TypeSpecOwned(false),
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      TypeQualifiers(TSS_unspecified),
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      FS_inline_specified(false),
375b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor      FS_virtual_specified(false),
376b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor      FS_explicit_specified(false),
377f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson      Friend_specified(false),
3782ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl      Constexpr_specified(false),
37916573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor      StorageClassSpecAsWritten(SCS_unspecified),
3800b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      Attrs(attrFactory),
381ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner      ProtocolQualifiers(0),
38271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis      NumProtocolQualifiers(0),
383b91570a51f9c9583bb27fdfe43ce9c487623999aJohn McCall      ProtocolLocs(0),
384b91570a51f9c9583bb27fdfe43ce9c487623999aJohn McCall      writtenBS() {
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ~DeclSpec() {
387ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner    delete [] ProtocolQualifiers;
38871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis    delete [] ProtocolLocs;
3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // storage-class-specifier
3912efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner  SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isThreadSpecified() const { return SCS_thread_specified; }
39335f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
39435f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  void setExternInLinkageSpec(bool Value) {
39535f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    SCS_extern_in_linkage_spec = Value;
39635f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara  }
3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getThreadSpecLoc() const { return SCS_threadLoc; }
4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ClearStorageClassSpecs() {
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    StorageClassSpec     = DeclSpec::SCS_unspecified;
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SCS_thread_specified = false;
40435f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara    SCS_extern_in_linkage_spec = false;
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    StorageClassSpecLoc  = SourceLocation();
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SCS_threadLoc        = SourceLocation();
4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type-specifier
4102efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner  TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; }
4112efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner  TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
4122efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner  TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; }
4132efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner  TST getTypeSpecType() const { return (TST)TypeSpecType; }
41482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
41582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
416788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
417402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor  bool isTypeSpecOwned() const { return TypeSpecOwned; }
418b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType getRepAsType() const {
419b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
420b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return TypeRep;
421b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
422b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  Decl *getRepAsDecl() const {
423b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
424b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return DeclRep;
425b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
426b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  Expr *getRepAsExpr() const {
427b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
428b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return ExprRep;
429b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
430aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
431aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall  const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
4321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  const SourceRange &getSourceRange() const { return Range; }
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; }
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
43882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
4391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4400daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  SourceLocation getTypeSpecTypeNameLoc() const {
4410daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara    assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename);
4420daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara    return TSTNameLoc;
4430daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  }
4440daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara
445cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceRange getTypeofParensRange() const { return TypeofParensRange; }
446cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; }
447cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getSpecifierName - Turn a type-specifier-type into a string like "_Bool"
4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// or "union".
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getSpecifierName(DeclSpec::TST T);
45132d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  static const char *getSpecifierName(DeclSpec::TQ Q);
45232d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  static const char *getSpecifierName(DeclSpec::TSS S);
45332d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  static const char *getSpecifierName(DeclSpec::TSC C);
45432d335e63bd287e5c9297532171284cdf4c7888cJohn McCall  static const char *getSpecifierName(DeclSpec::TSW W);
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getSpecifierName(DeclSpec::SCS S);
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type-qualifiers
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getTypeQualifiers - Return a set of TQs.
4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getTypeQualifiers() const { return TypeQualifiers; }
4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4657604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor  /// \brief Clear out all of the type qualifiers.
4667604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor  void ClearTypeQualifiers() {
4677604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor    TypeQualifiers = 0;
4687604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor    TQ_constLoc = SourceLocation();
4697604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor    TQ_restrictLoc = SourceLocation();
4707604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor    TQ_volatileLoc = SourceLocation();
4717604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor  }
4727604f64a865bdba86c05cab76bcd47fd10372eb8Douglas Gregor
4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // function-specifier
4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isInlineSpecified() const { return FS_inline_specified; }
4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getInlineSpecLoc() const { return FS_inlineLoc; }
476b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor
477b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  bool isVirtualSpecified() const { return FS_virtual_specified; }
478b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
479b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor
480b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  bool isExplicitSpecified() const { return FS_explicit_specified; }
481b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor  SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
482b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor
4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ClearFunctionSpecs() {
4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    FS_inline_specified = false;
4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    FS_inlineLoc = SourceLocation();
486b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor    FS_virtual_specified = false;
487b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor    FS_virtualLoc = SourceLocation();
488b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor    FS_explicit_specified = false;
489b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor    FS_explicitLoc = SourceLocation();
4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// hasTypeSpecifier - Return true if any type-specifier has been found.
4935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool hasTypeSpecifier() const {
4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypeSpecType() != DeclSpec::TST_unspecified ||
4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           getTypeSpecWidth() != DeclSpec::TSW_unspecified ||
4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           getTypeSpecSign() != DeclSpec::TSS_unspecified;
4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// DeclSpec includes.
5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getParsedSpecifiers() const;
5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50516573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor  SCS getStorageClassSpecAsWritten() const {
50616573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor    return (SCS)StorageClassSpecAsWritten;
50716573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor  }
50816573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor
5092a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner  /// isEmpty - Return true if this declaration specifier is completely empty:
5102a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner  /// no tokens were parsed in the production of it.
5112a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner  bool isEmpty() const {
5122a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner    return getParsedSpecifiers() == DeclSpec::PQ_None;
5132a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner  }
5141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51581c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
51681c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner  void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
5171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
518fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  /// These methods set the specified attribute of the DeclSpec and
519fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  /// return false if there was no error.  If an error occurs (for
520fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  /// example, if we tried to set "auto" on a spec with "extern"
521fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  /// already set), they return true and set PrevSpec and DiagID
522fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  /// such that
523fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  ///   Diag(Loc, DiagID) << PrevSpec;
524fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  /// will yield a useful result.
525fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  ///
526fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  /// TODO: use a more general approach that still allows these
527fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  /// diagnostics to be ignored when desired.
528fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  bool SetStorageClassSpec(SCS S, SourceLocation Loc, const char *&PrevSpec,
529e2f82f71385051ce5abfba317d2f592aa332c588Peter Collingbourne                           unsigned &DiagID, const LangOptions &Lang);
530fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  bool SetStorageClassSpecThread(SourceLocation Loc, const char *&PrevSpec,
531fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                 unsigned &DiagID);
532fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec,
533fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                        unsigned &DiagID);
534fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
535fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                          unsigned &DiagID);
536fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec,
537fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                       unsigned &DiagID);
5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
539b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                       unsigned &DiagID);
540b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
541b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                       unsigned &DiagID, ParsedType Rep);
542b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
543b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                       unsigned &DiagID, Decl *Rep, bool Owned);
5440daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
5450daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                       SourceLocation TagNameLoc, const char *&PrevSpec,
5460daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                       unsigned &DiagID, ParsedType Rep);
5470daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
5480daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                       SourceLocation TagNameLoc, const char *&PrevSpec,
5490daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara                       unsigned &DiagID, Decl *Rep, bool Owned);
5500daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara
551b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
552b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                       unsigned &DiagID, Expr *Rep);
55382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
55482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                       const char *&PrevSpec, unsigned &DiagID);
55582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
55682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                       const char *&PrevSpec, unsigned &DiagID);
557ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor  bool SetTypeSpecError();
558b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  void UpdateDeclRep(Decl *Rep) {
559b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    assert(isDeclRep((TST) TypeSpecType));
560b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    DeclRep = Rep;
561b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
562b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  void UpdateTypeRep(ParsedType Rep) {
563b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    assert(isTypeRep((TST) TypeSpecType));
564b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    TypeRep = Rep;
565b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
566b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  void UpdateExprRep(Expr *Rep) {
567b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    assert(isExprRep((TST) TypeSpecType));
568b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ExprRep = Rep;
569b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
5701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
572fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                   unsigned &DiagID, const LangOptions &Lang);
5731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
574fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
575fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                             unsigned &DiagID);
576fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  bool SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
577fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                              unsigned &DiagID);
578fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  bool SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
579fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                               unsigned &DiagID);
5801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
581fec54013fcd0eb72642741584ca04c1bc292bef8John McCall  bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
582fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                     unsigned &DiagID);
583fec54013fcd0eb72642741584ca04c1bc292bef8John McCall
5842ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
5852ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl                        unsigned &DiagID);
5862ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl
587908116859ed8c166c1c0712992e504edd0c5a6e1Anders Carlsson  bool isFriendSpecified() const { return Friend_specified; }
58866e9977ddd6b197317d149213b76a9af0d3df4deAnders Carlsson  SourceLocation getFriendSpecLoc() const { return FriendLoc; }
589908116859ed8c166c1c0712992e504edd0c5a6e1Anders Carlsson
5902ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  bool isConstexprSpecified() const { return Constexpr_specified; }
5912ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl  SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
5922ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl
5930b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  AttributePool &getAttributePool() const {
5940b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    return Attrs.getPool();
5950b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  }
5960b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall
5971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// AddAttributes - contatenates two attribute lists.
5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// The GCC attribute syntax allows for the following:
5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
6001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// short __attribute__(( unused, deprecated ))
6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// int __attribute__(( may_alias, aligned(16) )) var;
6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This declares 4 attributes using 2 lists. The following syntax is
6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// also allowed and equivalent to the previous declaration.
6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// short __attribute__((unused)) __attribute__((deprecated))
6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
6097f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void addAttributes(AttributeList *AL) {
6100b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    Attrs.addAll(AL);
6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6120b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  void setAttributes(AttributeList *AL) {
6137f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    Attrs.set(AL);
6147f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
6157f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
6167f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  bool hasAttributes() const { return !Attrs.empty(); }
6177f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
6187f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ParsedAttributes &getAttributes() { return Attrs; }
6197f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  const ParsedAttributes &getAttributes() const { return Attrs; }
6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6217654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner  /// TakeAttributes - Return the current attribute list and remove them from
6227654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner  /// the DeclSpec so that it doesn't own them.
6237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  ParsedAttributes takeAttributes() {
6240b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    // The non-const "copy" constructor clears the operand automatically.
6250b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    return Attrs;
6267f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
6277f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
6287f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void takeAttributesFrom(ParsedAttributes &attrs) {
6290b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    Attrs.takeAllFrom(attrs);
6307654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner  }
6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
632d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  typedef Decl * const *ProtocolQualifierListTy;
633ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner  ProtocolQualifierListTy getProtocolQualifiers() const {
6344b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    return ProtocolQualifiers;
6354b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  }
63671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation *getProtocolLocs() const { return ProtocolLocs; }
6377654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner  unsigned getNumProtocolQualifiers() const {
638ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner    return NumProtocolQualifiers;
6394b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  }
64071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis  SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; }
641d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void setProtocolQualifiers(Decl * const *Protos, unsigned NP,
64271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                             SourceLocation *ProtoLocs,
643e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis                             SourceLocation LAngleLoc);
6441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Finish - This does final analysis of the declspec, issuing diagnostics for
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// things like "_Imaginary" (lacking an FP type).  After calling this method,
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// DeclSpec is guaranteed self-consistent, even if an error occurred.
6489b3064b55f3c858923734e8b1c9831777fc22554Douglas Gregor  void Finish(Diagnostic &D, Preprocessor &PP);
649a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl
650ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
651ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return writtenBS;
652ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
653ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
654a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl  /// isMissingDeclaratorOk - This checks if this DeclSpec can stand alone,
655a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl  /// without a Declarator. Only tag declspecs can stand alone.
656a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl  bool isMissingDeclaratorOk();
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCDeclSpec - This class captures information about
66019d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian/// "declaration specifiers" specific to objective-c
661a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCDeclSpec {
66219d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanianpublic:
66309e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall  /// ObjCDeclQualifier - Qualifier used on types in method
66409e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall  /// declarations.  Not all combinations are sensible.  Parameters
66509e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall  /// can be one of { in, out, inout } with one of { bycopy, byref }.
66609e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall  /// Returns can either be { oneway } or not.
66709e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall  ///
66809e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall  /// This should be kept in sync with Decl::ObjCDeclQualifier.
669a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  enum ObjCDeclQualifier {
67019d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian    DQ_None = 0x0,
67119d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian    DQ_In = 0x1,
67219d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian    DQ_Inout = 0x2,
67319d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian    DQ_Out = 0x4,
67419d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian    DQ_Bycopy = 0x8,
67519d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian    DQ_Byref = 0x10,
67619d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian    DQ_Oneway = 0x20
67719d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian  };
6781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
679564576b225386cbff375351597dd5e2a92872d38Fariborz Jahanian  /// PropertyAttributeKind - list of property attributes.
68009e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall  enum ObjCPropertyAttributeKind {
68109e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall    DQ_PR_noattr = 0x0,
6821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DQ_PR_readonly = 0x01,
6831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DQ_PR_getter = 0x02,
6841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DQ_PR_assign = 0x04,
6851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DQ_PR_readwrite = 0x08,
68682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian    DQ_PR_retain = 0x10,
6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DQ_PR_copy = 0x20,
68882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian    DQ_PR_nonatomic = 0x40,
689dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian    DQ_PR_setter = 0x80,
690dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian    DQ_PR_atomic = 0x100
69182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  };
6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
694e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner  ObjCDeclSpec()
695e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner    : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr),
696e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner      GetterName(0), SetterName(0) { }
697a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCDeclQualifier getObjCDeclQualifier() const { return objcDeclQualifier; }
698e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner  void setObjCDeclQualifier(ObjCDeclQualifier DQVal) {
699e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner    objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal);
700e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner  }
7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
702e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner  ObjCPropertyAttributeKind getPropertyAttributes() const {
703e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner    return ObjCPropertyAttributeKind(PropertyAttributes);
704e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner  }
7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setPropertyAttributes(ObjCPropertyAttributeKind PRVal) {
7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    PropertyAttributes =
707e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner      (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal);
70882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  const IdentifierInfo *getGetterName() const { return GetterName; }
71182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  IdentifierInfo *getGetterName() { return GetterName; }
71282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  void setGetterName(IdentifierInfo *name) { GetterName = name; }
7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  const IdentifierInfo *getSetterName() const { return SetterName; }
71582a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  IdentifierInfo *getSetterName() { return SetterName; }
71682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  void setSetterName(IdentifierInfo *name) { SetterName = name; }
71719d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanianprivate:
7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: These two are unrelated and mutially exclusive. So perhaps
71982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  // we can put them in a union to reflect their mutual exclusiveness
72082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  // (space saving is negligible).
721a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCDeclQualifier objcDeclQualifier : 6;
7221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
723ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind
724dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian  unsigned PropertyAttributes : 9;
72582a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  IdentifierInfo *GetterName;    // getter name of NULL if no getter
72682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  IdentifierInfo *SetterName;    // setter name of NULL if no setter
72719d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian};
728eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
7293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \brief Represents a C++ unqualified-id that has been parsed.
7303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorclass UnqualifiedId {
7313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorprivate:
7323f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  const UnqualifiedId &operator=(const UnqualifiedId &); // DO NOT IMPLEMENT
7333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
7343f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorpublic:
7353f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Describes the kind of unqualified-id parsed.
7363f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  enum IdKind {
7373f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief An identifier.
7383f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    IK_Identifier,
7393f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief An overloaded operator name, e.g., operator+.
7403f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    IK_OperatorFunctionId,
7413f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief A conversion function name, e.g., operator int.
7423f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    IK_ConversionFunctionId,
7430486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt    /// \brief A user-defined literal name, e.g., operator "" _i.
7440486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt    IK_LiteralOperatorId,
7453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief A constructor name.
7463f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    IK_ConstructorName,
7470efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    /// \brief A constructor named via a template-id.
7480efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    IK_ConstructorTemplateId,
7493f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief A destructor name.
7503f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    IK_DestructorName,
7513f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief A template-id, e.g., f<int>.
7523f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    IK_TemplateId
7533f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  } Kind;
7543f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
7553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Anonymous union that holds extra data associated with the
7563f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// parsed unqualified-id.
7573f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  union {
7580486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt    /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind
7590486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt    /// == IK_UserLiteralId, the identifier suffix.
7603f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    IdentifierInfo *Identifier;
7613f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
7623f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator
7633f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// that we parsed.
7643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    struct {
7653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      /// \brief The kind of overloaded operator.
7663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      OverloadedOperatorKind Operator;
7673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
7683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      /// \brief The source locations of the individual tokens that name
7693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      /// the operator, e.g., the "new", "[", and "]" tokens in
7703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      /// operator new [].
7713f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      ///
7723f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      /// Different operators have different numbers of tokens in their name,
7733f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      /// up to three. Any remaining source locations in this array will be
7743f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      /// set to an invalid value for operators with fewer than three tokens.
7753f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      unsigned SymbolLocations[3];
7763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    } OperatorFunctionId;
7773f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
7783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief When Kind == IK_ConversionFunctionId, the type that the
7793f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// conversion function names.
780b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    UnionParsedType ConversionFunctionId;
7813f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
7823f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief When Kind == IK_ConstructorName, the class-name of the type
7833f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// whose constructor is being referenced.
784b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    UnionParsedType ConstructorName;
7853f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
7863f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// \brief When Kind == IK_DestructorName, the type referred to by the
7873f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    /// class-name.
788b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    UnionParsedType DestructorName;
7893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
7900efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    /// \brief When Kind == IK_TemplateId or IK_ConstructorTemplateId,
7910efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    /// the template-id annotation that contains the template name and
7920efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    /// template arguments.
7933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    TemplateIdAnnotation *TemplateId;
7943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  };
7953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
7963f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief The location of the first token that describes this unqualified-id,
7973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// which will be the location of the identifier, "operator" keyword,
7983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// tilde (for a destructor), or the template name of a template-id.
7993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  SourceLocation StartLocation;
8003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8013f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief The location of the last token that describes this unqualified-id.
8023f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  SourceLocation EndLocation;
8033f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8043f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  UnqualifiedId() : Kind(IK_Identifier), Identifier(0) { }
8053f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8063f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Do not use this copy constructor. It is temporary, and only
8073f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// exists because we are holding FieldDeclarators in a SmallVector when we
8083f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// don't actually need them.
8093f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8103f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// FIXME: Kill this copy constructor.
8113f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  UnqualifiedId(const UnqualifiedId &Other)
8123f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    : Kind(IK_Identifier), Identifier(Other.Identifier),
8133f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      StartLocation(Other.StartLocation), EndLocation(Other.EndLocation) {
8143f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    assert(Other.Kind == IK_Identifier && "Cannot copy non-identifiers");
8153f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  }
8163f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8173f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Destroy this unqualified-id.
8183f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ~UnqualifiedId() { clear(); }
8193f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8203f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Clear out this unqualified-id, setting it to default (invalid)
8213f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// state.
8223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  void clear();
8233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Determine whether this unqualified-id refers to a valid name.
8253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool isValid() const { return StartLocation.isValid(); }
8263f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8273f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Determine whether this unqualified-id refers to an invalid name.
8283f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool isInvalid() const { return !isValid(); }
8293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Determine what kind of name we have.
8313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  IdKind getKind() const { return Kind; }
8323f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Specify that this unqualified-id was parsed as an identifier.
8343f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8353f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param Id the parsed identifier.
8363f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param IdLoc the location of the parsed identifier.
837014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor  void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
8383f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    Kind = IK_Identifier;
839014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor    Identifier = const_cast<IdentifierInfo *>(Id);
8403f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    StartLocation = EndLocation = IdLoc;
8413f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  }
8423f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8433f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Specify that this unqualified-id was parsed as an
8443f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// operator-function-id.
8453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8463f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param OperatorLoc the location of the 'operator' keyword.
8473f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8483f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param Op the overloaded operator.
8493f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8503f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param SymbolLocations the locations of the individual operator symbols
8513f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// in the operator.
8523f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  void setOperatorFunctionId(SourceLocation OperatorLoc,
8533f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                             OverloadedOperatorKind Op,
8543f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                             SourceLocation SymbolLocations[3]);
8553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8563f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Specify that this unqualified-id was parsed as a
8573f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// conversion-function-id.
8583f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8593f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param OperatorLoc the location of the 'operator' keyword.
8603f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8613f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param Ty the type to which this conversion function is converting.
8623f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8633f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param EndLoc the location of the last token that makes up the type name.
8643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  void setConversionFunctionId(SourceLocation OperatorLoc,
865b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                               ParsedType Ty,
8663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                               SourceLocation EndLoc) {
8673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    Kind = IK_ConversionFunctionId;
8683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    StartLocation = OperatorLoc;
8693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    EndLocation = EndLoc;
8703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    ConversionFunctionId = Ty;
8713f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  }
8720486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt
8730486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  /// \brief Specific that this unqualified-id was parsed as a
8740486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  /// literal-operator-id.
8750486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  ///
8760486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  /// \param Id the parsed identifier.
8770486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  ///
8780486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  /// \param OpLoc the location of the 'operator' keyword.
8790486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  ///
8800486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  /// \param IdLoc the location of the identifier.
8810486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc,
8820486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt                              SourceLocation IdLoc) {
8830486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt    Kind = IK_LiteralOperatorId;
8840486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt    Identifier = const_cast<IdentifierInfo *>(Id);
8850486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt    StartLocation = OpLoc;
8860486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt    EndLocation = IdLoc;
8870486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt  }
8883f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
8893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Specify that this unqualified-id was parsed as a constructor name.
8903f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8913f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param ClassType the class type referred to by the constructor name.
8923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param ClassNameLoc the location of the class name.
8943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
8953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param EndLoc the location of the last token that makes up the type name.
896b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  void setConstructorName(ParsedType ClassType,
8973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                          SourceLocation ClassNameLoc,
8983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                          SourceLocation EndLoc) {
8993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    Kind = IK_ConstructorName;
9003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    StartLocation = ClassNameLoc;
9013f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    EndLocation = EndLoc;
9023f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    ConstructorName = ClassType;
9033f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  }
9043f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
9050efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// \brief Specify that this unqualified-id was parsed as a
9060efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// template-id that names a constructor.
9070efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  ///
9080efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// \param TemplateId the template-id annotation that describes the parsed
9090efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// template-id. This UnqualifiedId instance will take ownership of the
9100efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// \p TemplateId and will free it on destruction.
9110efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  void setConstructorTemplateId(TemplateIdAnnotation *TemplateId);
9120efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor
9133f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Specify that this unqualified-id was parsed as a destructor name.
9143f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
9153f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param TildeLoc the location of the '~' that introduces the destructor
9163f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// name.
9173f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
9183f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param ClassType the name of the class referred to by the destructor name.
919b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  void setDestructorName(SourceLocation TildeLoc,
920b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                         ParsedType ClassType,
9213f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                         SourceLocation EndLoc) {
9223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    Kind = IK_DestructorName;
9233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    StartLocation = TildeLoc;
9243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    EndLocation = EndLoc;
9253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    DestructorName = ClassType;
9263f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  }
9273f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
9283f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Specify that this unqualified-id was parsed as a template-id.
9293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  ///
9303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \param TemplateId the template-id annotation that describes the parsed
9313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// template-id. This UnqualifiedId instance will take ownership of the
9323f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \p TemplateId and will free it on destruction.
933314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  void setTemplateId(TemplateIdAnnotation *TemplateId);
9343f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
9353f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Return the source range that covers this unqualified-id.
9363f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  SourceRange getSourceRange() const {
9373f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    return SourceRange(StartLocation, EndLocation);
9383f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  }
9393f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor};
9403f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
94172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor/// CachedTokens - A set of tokens that has been cached for later
94272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor/// parsing.
94372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregortypedef llvm::SmallVector<Token, 4> CachedTokens;
94472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclaratorChunk - One instance of this struct is used for each type in a
9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// declarator that is parsed.
9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// This is intended to be a small value object.
9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerstruct DeclaratorChunk {
9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum {
951075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren
9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  } Kind;
953f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Loc - The place where this type was defined.
9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
9567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// EndLoc - If valid, the place where this chunck ends.
9577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation EndLoc;
9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9597f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct TypeInfoCommon {
9607f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    AttributeList *AttrList;
9617f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  };
9627f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
9637f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct PointerTypeInfo : TypeInfoCommon {
9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// The type qualifiers: const/volatile/restrict.
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    unsigned TypeQuals : 3;
966d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth
967d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    /// The location of the const-qualifier, if any.
968d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    unsigned ConstQualLoc;
969d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth
970d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    /// The location of the volatile-qualifier, if any.
971d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    unsigned VolatileQualLoc;
972d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth
973d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    /// The location of the restrict-qualifier, if any.
974d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    unsigned RestrictQualLoc;
975d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth
9767654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner    void destroy() {
9777654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner    }
9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct ReferenceTypeInfo : TypeInfoCommon {
9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// The type qualifier: restrict. [GNU] C++ extension
98205532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl    bool HasRestrict : 1;
98305532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl    /// True if this is an lvalue reference, false if it's an rvalue reference.
98405532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl    bool LValueRef : 1;
9857654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner    void destroy() {
9867654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner    }
9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct ArrayTypeInfo : TypeInfoCommon {
9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// The type qualifiers for the array: const/volatile/restrict.
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    unsigned TypeQuals : 3;
9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// True if this dimension included the 'static' keyword.
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    bool hasStatic : 1;
9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// True if this dimension was [*].  In this case, NumElts is null.
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    bool isStar : 1;
9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// This is the size of the array, or null if [] or [*] was specified.
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// Since the parser is multi-purpose, and we don't want to impose a root
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// expression class on all clients, NumElts is untyped.
1002ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    Expr *NumElts;
10037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    void destroy() {}
10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParamInfo - An array of paraminfo objects is allocated whenever a function
10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// declarator is parsed.  There are two interesting styles of arguments here:
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// K&R-style identifier lists and parameter type lists.  K&R-style identifier
10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// lists will have information about the identifier, but no type information.
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Parameter type lists will have type info (if the actions module provides
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  struct ParamInfo {
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    IdentifierInfo *Ident;
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SourceLocation IdentLoc;
1016d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Param;
101772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
101872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// DefaultArgTokens - When the parameter's default argument
101972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// cannot be parsed immediately (because it occurs within the
102072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// declaration of a member function), it will be stored here as a
102172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// sequence of tokens to be parsed once the class definition is
102272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// complete. Non-NULL indicates that there is a default argument.
10235af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    CachedTokens *DefaultArgTokens;
102472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ParamInfo() {}
1026b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
1027d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall              Decl *param,
102872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor              CachedTokens *DefArgTokens = 0)
10291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : Ident(ident), IdentLoc(iloc), Param(param),
103072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor        DefaultArgTokens(DefArgTokens) {}
10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1032ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl
1033ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl  struct TypeAndRange {
1034b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType Ty;
1035ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl    SourceRange Range;
1036ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl  };
1037ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl
10387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct FunctionTypeInfo : TypeInfoCommon {
10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// hasPrototype - This is true if the function had at least one typed
10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// argument.  If the function is () or (a,b,c), then it has no prototype,
10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// and is treated as a K&R-style function.
10427f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    unsigned hasPrototype : 1;
10437dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl
1044965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor    /// isVariadic - If this function has a prototype, and if that
1045965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor    /// proto ends with ',...)', this is true. When true, EllipsisLoc
1046965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor    /// contains the location of the ellipsis.
10477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    unsigned isVariadic : 1;
10485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
104983f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    /// \brief Whether the ref-qualifier (if any) is an lvalue reference.
105083f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    /// Otherwise, it's an rvalue reference.
105183f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    unsigned RefQualifierIsLValueRef : 1;
105283f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor
1053971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis    /// The type qualifiers: const/volatile/restrict.
10541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// The qualifier bitmask values are the same as in QualType.
1055971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis    unsigned TypeQuals : 3;
1056971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
10576e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    /// ExceptionSpecType - An ExceptionSpecificationType value.
10586e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    unsigned ExceptionSpecType : 3;
10597dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl
10605af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    /// DeleteArgInfo - If this is true, we need to delete[] ArgInfo.
10617f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    unsigned DeleteArgInfo : 1;
10625af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner
10637dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl    /// When isVariadic is true, the location of the ellipsis in the source.
10647dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl    unsigned EllipsisLoc;
10657dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// NumArgs - This is the number of formal arguments provided for the
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// declarator.
10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    unsigned NumArgs;
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10706e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    /// NumExceptions - This is the number of types in the dynamic-exception-
10716e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    /// decl, if the function has one.
10727dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl    unsigned NumExceptions;
10737dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl
107483f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    /// \brief The location of the ref-qualifier, if any.
107583f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    ///
107683f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    /// If this is an invalid location, there is no ref-qualifier.
107783f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    unsigned RefQualifierLoc;
10786e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl
10796e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    /// \brief When ExceptionSpecType isn't EST_None, the location of the
10803cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl    /// keyword introducing the spec.
10816e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    unsigned ExceptionSpecLoc;
10823cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl
10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// ArgInfo - This is a pointer to a new[]'d array of ParamInfo objects that
10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// describe the arguments for this function declarator.  This is null if
10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// there are no arguments specified.
10865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ParamInfo *ArgInfo;
10877dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl
10886e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    union {
10896e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      /// \brief Pointer to a new[]'d array of TypeAndRange objects that
10906e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      /// contain the types in the function's dynamic exception specification
10916e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      /// and their locations, if there is one.
10926e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      TypeAndRange *Exceptions;
10936e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl
10946e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      /// \brief Pointer to the expression in the noexcept-specifier of this
10956e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      /// function, if it has one.
10966e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      Expr *NoexceptExpr;
10976e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    };
10987dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl
1099dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    /// TrailingReturnType - If this isn't null, it's the trailing return type
1100dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    /// specified. This is actually a ParsedType, but stored as void* to
1101dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    /// allow union storage.
1102dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    void *TrailingReturnType;
1103dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
11041833a83368bda46b76388069e52b27f12e60dc9cChris Lattner    /// freeArgs - reset the argument list to having zero arguments.  This is
11051833a83368bda46b76388069e52b27f12e60dc9cChris Lattner    /// used in various places for error recovery.
11061833a83368bda46b76388069e52b27f12e60dc9cChris Lattner    void freeArgs() {
11071833a83368bda46b76388069e52b27f12e60dc9cChris Lattner      if (DeleteArgInfo) {
11081833a83368bda46b76388069e52b27f12e60dc9cChris Lattner        delete[] ArgInfo;
11091833a83368bda46b76388069e52b27f12e60dc9cChris Lattner        DeleteArgInfo = false;
11101833a83368bda46b76388069e52b27f12e60dc9cChris Lattner      }
11111833a83368bda46b76388069e52b27f12e60dc9cChris Lattner      NumArgs = 0;
11121833a83368bda46b76388069e52b27f12e60dc9cChris Lattner    }
11137dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl
11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    void destroy() {
11155af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      if (DeleteArgInfo)
11165af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner        delete[] ArgInfo;
11176e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      if (getExceptionSpecType() == EST_Dynamic)
11186e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl        delete[] Exceptions;
11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1120965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor
1121004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner    /// isKNRPrototype - Return true if this is a K&R style identifier list,
1122004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner    /// like "void foo(a,b,c)".  In a function definition, this will be followed
1123004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner    /// by the argument type definitions.
1124004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner    bool isKNRPrototype() const {
1125004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner      return !hasPrototype && NumArgs != 0;
1126004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner    }
1127004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner
1128965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor    SourceLocation getEllipsisLoc() const {
1129965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor      return SourceLocation::getFromRawEncoding(EllipsisLoc);
1130965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor    }
11316e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    SourceLocation getExceptionSpecLoc() const {
11326e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      return SourceLocation::getFromRawEncoding(ExceptionSpecLoc);
11333cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl    }
11346e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl
113583f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    /// \brief Retrieve the location of the ref-qualifier, if any.
113683f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    SourceLocation getRefQualifierLoc() const {
113783f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor      return SourceLocation::getFromRawEncoding(RefQualifierLoc);
113883f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    }
11396e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl
114083f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    /// \brief Determine whether this function declaration contains a
114183f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    /// ref-qualifier.
114283f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor    bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
11436e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl
11446e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    /// \brief Get the type of exception specification this function has.
11456e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    ExceptionSpecificationType getExceptionSpecType() const {
11466e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl      return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
11476e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl    }
11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
11495618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
11507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct BlockPointerTypeInfo : TypeInfoCommon {
11515618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff    /// For now, sema will catch these as invalid.
11525618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff    /// The type qualifiers: const/volatile/restrict.
11535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff    unsigned TypeQuals : 3;
11547f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
115575b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump    void destroy() {
115675b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump    }
11575618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  };
11585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
11597f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct MemberPointerTypeInfo : TypeInfoCommon {
1160f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    /// The type qualifiers: const/volatile/restrict.
1161f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    unsigned TypeQuals : 3;
1162f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    // CXXScopeSpec has a constructor, so it can't be a direct member.
1163f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    // So we need some pointer-aligned storage and a bit of trickery.
1164f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    union {
1165f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl      void *Aligner;
1166f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl      char Mem[sizeof(CXXScopeSpec)];
1167f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    } ScopeMem;
1168f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    CXXScopeSpec &Scope() {
1169f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl      return *reinterpret_cast<CXXScopeSpec*>(ScopeMem.Mem);
1170f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    }
1171f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    const CXXScopeSpec &Scope() const {
1172f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl      return *reinterpret_cast<const CXXScopeSpec*>(ScopeMem.Mem);
1173f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    }
1174f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    void destroy() {
1175f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl      Scope().~CXXScopeSpec();
1176f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    }
1177f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  };
1178f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  union {
1180711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    TypeInfoCommon        Common;
1181f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointerTypeInfo       Ptr;
1182f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ReferenceTypeInfo     Ref;
1183f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ArrayTypeInfo         Arr;
1184f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    FunctionTypeInfo      Fun;
1185f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    BlockPointerTypeInfo  Cls;
1186f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    MemberPointerTypeInfo Mem;
11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1188f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
11895af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  void destroy() {
11905af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    switch (Kind) {
11915af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    default: assert(0 && "Unknown decl type!");
1192f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    case DeclaratorChunk::Function:      return Fun.destroy();
1193f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    case DeclaratorChunk::Pointer:       return Ptr.destroy();
1194f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    case DeclaratorChunk::BlockPointer:  return Cls.destroy();
1195f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    case DeclaratorChunk::Reference:     return Ref.destroy();
1196f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    case DeclaratorChunk::Array:         return Arr.destroy();
1197f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    case DeclaratorChunk::MemberPointer: return Mem.destroy();
1198075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    case DeclaratorChunk::Paren:         return;
11995af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    }
12005af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  }
1201f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1202e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner  /// getAttrs - If there are attributes applied to this declaratorchunk, return
1203e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner  /// them.
1204e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner  const AttributeList *getAttrs() const {
1205711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    return Common.AttrList;
1206e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner  }
1207f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1208711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  AttributeList *&getAttrListRef() {
1209711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    return Common.AttrList;
1210711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  }
1211f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
12125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getPointer - Return a DeclaratorChunk for a pointer.
12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
12147654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner  static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
1215d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth                                    SourceLocation ConstQualLoc,
1216d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth                                    SourceLocation VolatileQualLoc,
12170b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall                                    SourceLocation RestrictQualLoc) {
12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DeclaratorChunk I;
1219d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    I.Kind                = Pointer;
1220d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    I.Loc                 = Loc;
1221d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    I.Ptr.TypeQuals       = TypeQuals;
1222d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    I.Ptr.ConstQualLoc    = ConstQualLoc.getRawEncoding();
1223d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding();
1224d067c07c6cbf099b25aba38bcb66f38e79d0c420Chandler Carruth    I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding();
12250b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    I.Ptr.AttrList        = 0;
12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return I;
12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getReference - Return a DeclaratorChunk for a reference.
12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
12317654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner  static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
12327f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                      bool lvalue) {
12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DeclaratorChunk I;
12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    I.Kind            = Reference;
12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    I.Loc             = Loc;
12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
123705532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl    I.Ref.LValueRef   = lvalue;
12380b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    I.Ref.AttrList    = 0;
12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return I;
12405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArray - Return a DeclaratorChunk for an array.
12435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
12447f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  static DeclaratorChunk getArray(unsigned TypeQuals,
12457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                  bool isStatic, bool isStar, Expr *NumElts,
12467e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                                  SourceLocation LBLoc, SourceLocation RBLoc) {
12475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DeclaratorChunk I;
12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    I.Kind          = Array;
12497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    I.Loc           = LBLoc;
12507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    I.EndLoc        = RBLoc;
12510b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    I.Arr.AttrList  = 0;
12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    I.Arr.TypeQuals = TypeQuals;
12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    I.Arr.hasStatic = isStatic;
12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    I.Arr.isStar    = isStar;
12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    I.Arr.NumElts   = NumElts;
12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return I;
12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12595af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
12605af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  /// "TheDeclarator" is the declarator that this will be added to.
12610b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  static DeclaratorChunk getFunction(bool hasProto, bool isVariadic,
1262965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor                                     SourceLocation EllipsisLoc,
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                     ParamInfo *ArgInfo, unsigned NumArgs,
126483f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor                                     unsigned TypeQuals,
126583f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor                                     bool RefQualifierIsLvalueRef,
126683f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor                                     SourceLocation RefQualifierLoc,
12676e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                     ExceptionSpecificationType ESpecType,
12686e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                     SourceLocation ESpecLoc,
1269b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                     ParsedType *Exceptions,
1270ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl                                     SourceRange *ExceptionRanges,
127182bf01061b97404fed8c422fc0eda0a380689cc9Argyrios Kyrtzidis                                     unsigned NumExceptions,
12726e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                     Expr *NoexceptExpr,
1273796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara                                     SourceLocation LocalRangeBegin,
1274796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara                                     SourceLocation LocalRangeEnd,
1275dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor                                     Declarator &TheDeclarator,
12766e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                     ParsedType TrailingReturnType =
12776e5d319b671dbb0ecf70619834aa23c853d17621Sebastian Redl                                                    ParsedType());
12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  /// getBlockPointer - Return a DeclaratorChunk for a block.
12805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  ///
12810b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  static DeclaratorChunk getBlockPointer(unsigned TypeQuals,
12820b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall                                         SourceLocation Loc) {
12835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff    DeclaratorChunk I;
12845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff    I.Kind          = BlockPointer;
12855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff    I.Loc           = Loc;
12865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff    I.Cls.TypeQuals = TypeQuals;
12870b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    I.Cls.AttrList  = 0;
12885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff    return I;
12895618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
1290f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1291f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS,
1292f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                                          unsigned TypeQuals,
12930b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall                                          SourceLocation Loc) {
1294f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    DeclaratorChunk I;
1295f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    I.Kind          = MemberPointer;
1296f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    I.Loc           = Loc;
1297f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    I.Mem.TypeQuals = TypeQuals;
12980b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    I.Mem.AttrList  = 0;
1299f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    new (I.Mem.ScopeMem.Mem) CXXScopeSpec(SS);
1300f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return I;
1301f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1302075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1303075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// getParen - Return a DeclaratorChunk for a paren.
1304075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ///
1305075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static DeclaratorChunk getParen(SourceLocation LParenLoc,
1306075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                                  SourceLocation RParenLoc) {
1307075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    DeclaratorChunk I;
1308075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    I.Kind          = Paren;
1309075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    I.Loc           = LParenLoc;
1310075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    I.EndLoc        = RParenLoc;
1311711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    I.Common.AttrList = 0;
1312075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return I;
1313075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1314075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Declarator - Information about one declarator, including the parsed type
13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information and the identifier.  When the declarator is fully formed, this
13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is turned into the appropriate Decl object.
13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Declarators come in two types: normal declarators and abstract declarators.
13225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Abstract declarators are used when parsing types, and don't have an
13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// identifier.  Normal declarators do have ID's.
13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1325e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner/// Instances of this class should be a transient object that lives on the
1326e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner/// stack, not objects that are allocated in large quantities on the heap.
13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Declarator {
13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13292d3dfd70eee48005f253b72d288e0eb4ed754fe0Zhongxing Xu  enum TheContext {
13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    FileContext,         // File scope declaration.
13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PrototypeContext,    // Within a function prototype.
1332c05a94b7accd4035bf5d5897c434c445b22da855John McCall    ObjCPrototypeContext,// Within a method prototype.
13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    KNRTypeListContext,  // K&R type definition list for formals.
13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TypeNameContext,     // Abstract declarator for types.
13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MemberContext,       // Struct/Union field.
13365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    BlockContext,        // Declaration within a block in a function.
133771b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis    ForContext,          // Declaration within first part of a for loop.
133826236e8b7507017fded05da3474d842e802a1679Douglas Gregor    ConditionContext,    // Condition declaration in a C++ if/switch/while/for.
1339a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl    TemplateParamContext,// Within a template parameter list.
134098eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump    CXXCatchContext,     // C++ catch exception-declaration
1341683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor    BlockLiteralContext,  // Block literal declarator.
1342162e1c1b487352434552147967c3dd296ebee2f7Richard Smith    TemplateTypeArgContext, // Template type argument.
13433e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    AliasDeclContext,    // C++0x alias-declaration.
13443e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    AliasTemplateContext // C++0x alias-declaration template.
13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
134642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor
13475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
13485af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  const DeclSpec &DS;
13495af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  CXXScopeSpec SS;
13503f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  UnqualifiedId Name;
1351ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  SourceRange Range;
1352ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl
13535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Context - Where we are parsing this declarator.
13545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
13555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TheContext Context;
135642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor
13575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// DeclTypeInfo - This holds each type that the declarator includes as it is
13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// parsed.  This is pushed from the identifier out, which means that element
13595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// #0 will be the most closely bound to the identifier, and
13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// DeclTypeInfo.back() will be the least closely bound.
13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1363ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// InvalidType - Set by Sema::GetTypeForDeclarator().
136473a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis  bool InvalidType : 1;
136573a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis
136673a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis  /// GroupingParens - Set by Parser::ParseParenDeclarator().
136773a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis  bool GroupingParens : 1;
1368e1223f7246c2c297f7b62816fd8c6a0a14151977Steve Naroff
13690b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  /// Attrs - Attributes.
13700b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  ParsedAttributes Attrs;
13711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1372914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar  /// AsmLabel - The asm label, if specified.
1373b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  Expr *AsmLabel;
137442a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor
13755af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  /// InlineParams - This is a local array used for the first function decl
13765af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  /// chunk to avoid going to the heap for the common case when we have one
13775af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  /// function chunk in the declarator.
13785af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  DeclaratorChunk::ParamInfo InlineParams[16];
13795af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner  bool InlineParamsUsed;
1380ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl
138191a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor  /// Extension - true if the declaration is preceded by __extension__.
138291a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor  bool Extension : 1;
138391a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor
1384a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor  /// \brief If provided, the source location of the ellipsis used to describe
1385a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor  /// this declarator as a parameter pack.
1386a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor  SourceLocation EllipsisLoc;
1387a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor
138843af76e845c95be160c088ec11ba3c43e2527fa8Sebastian Redl  friend struct DeclaratorChunk;
1389ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl
13905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1391e1449e51016fa7868d241c9e451253929d188bb9Argyrios Kyrtzidis  Declarator(const DeclSpec &ds, TheContext C)
13923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    : DS(ds), Range(ds.getSourceRange()), Context(C),
1393ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor      InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
13940b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      GroupingParens(false), Attrs(ds.getAttributePool().getFactory()),
13950b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      AsmLabel(0), InlineParamsUsed(false), Extension(false) {
13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ~Declarator() {
13995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    clear();
14005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getDeclSpec - Return the declaration-specifier that this declarator was
14035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// declared with.
1404985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner  const DeclSpec &getDeclSpec() const { return DS; }
14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1406985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner  /// getMutableDeclSpec - Return a non-const version of the DeclSpec.  This
1407985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner  /// should be used with extreme care: declspecs can often be shared between
1408985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner  /// multiple declarators, so mutating the DeclSpec affects all of the
1409985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner  /// Declarators.  This should only be done when the declspec is known to not
1410985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner  /// be shared or when in error recovery etc.
1411e1449e51016fa7868d241c9e451253929d188bb9Argyrios Kyrtzidis  DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); }
1412985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner
14130b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  AttributePool &getAttributePool() const {
14140b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    return Attrs.getPool();
14150b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  }
14160b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall
1417eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// getCXXScopeSpec - Return the C++ scope specifier (global scope or
1418eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// nested-name-specifier) that is part of the declarator-id.
1419eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  const CXXScopeSpec &getCXXScopeSpec() const { return SS; }
1420eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  CXXScopeSpec &getCXXScopeSpec() { return SS; }
1421eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
14223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Retrieve the name specified by this declarator.
14233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  UnqualifiedId &getName() { return Name; }
14243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
14255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TheContext getContext() const { return Context; }
142642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor
1427c05a94b7accd4035bf5d5897c434c445b22da855John McCall  bool isPrototypeContext() const {
1428c05a94b7accd4035bf5d5897c434c445b22da855John McCall    return (Context == PrototypeContext || Context == ObjCPrototypeContext);
1429c05a94b7accd4035bf5d5897c434c445b22da855John McCall  }
1430c05a94b7accd4035bf5d5897c434c445b22da855John McCall
1431ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// getSourceRange - Get the source range that spans this declarator.
1432ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  const SourceRange &getSourceRange() const { return Range; }
1433ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl
1434ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  void SetSourceRange(SourceRange R) { Range = R; }
1435ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// SetRangeBegin - Set the start of the source range to Loc, unless it's
1436ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// invalid.
1437ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  void SetRangeBegin(SourceLocation Loc) {
1438ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl    if (!Loc.isInvalid())
1439ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl      Range.setBegin(Loc);
1440ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  }
1441ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
1442ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  void SetRangeEnd(SourceLocation Loc) {
1443ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl    if (!Loc.isInvalid())
1444ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl      Range.setEnd(Loc);
1445ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  }
1446ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// ExtendWithDeclSpec - Extend the declarator source range to include the
1447ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// given declspec, unless its location is invalid. Adopts the range start if
1448ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// the current range start is invalid.
1449ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  void ExtendWithDeclSpec(const DeclSpec &DS) {
1450ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl    const SourceRange &SR = DS.getSourceRange();
1451ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl    if (Range.getBegin().isInvalid())
1452ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl      Range.setBegin(SR.getBegin());
1453ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl    if (!SR.getEnd().isInvalid())
1454ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl      Range.setEnd(SR.getEnd());
1455ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  }
1456ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl
14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// clear - Reset the contents of this Declarator.
14585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void clear() {
1459eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    SS.clear();
14603f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    Name.clear();
1461ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl    Range = DS.getSourceRange();
1462db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor
14635af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
14645af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner      DeclTypeInfo[i].destroy();
14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DeclTypeInfo.clear();
14660b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    Attrs.clear();
1467107450c6d846b2da5ecefbb088942e9478a83de7Argyrios Kyrtzidis    AsmLabel = 0;
14685af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner    InlineParamsUsed = false;
14695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// mayOmitIdentifier - Return true if the identifier is either optional or
14721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// not allowed.  This is true for typenames, prototypes, and template
147326236e8b7507017fded05da3474d842e802a1679Douglas Gregor  /// parameter lists.
14745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool mayOmitIdentifier() const {
1475c05a94b7accd4035bf5d5897c434c445b22da855John McCall    switch (Context) {
1476c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case FileContext:
1477c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case KNRTypeListContext:
1478c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case MemberContext:
1479c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case BlockContext:
1480c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case ForContext:
1481c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case ConditionContext:
1482c05a94b7accd4035bf5d5897c434c445b22da855John McCall      return false;
1483c05a94b7accd4035bf5d5897c434c445b22da855John McCall
1484c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case TypeNameContext:
1485162e1c1b487352434552147967c3dd296ebee2f7Richard Smith    case AliasDeclContext:
14863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    case AliasTemplateContext:
1487c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case PrototypeContext:
1488c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case ObjCPrototypeContext:
1489c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case TemplateParamContext:
1490c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case CXXCatchContext:
1491c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case BlockLiteralContext:
1492c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case TemplateTypeArgContext:
1493c05a94b7accd4035bf5d5897c434c445b22da855John McCall      return true;
1494c05a94b7accd4035bf5d5897c434c445b22da855John McCall    }
1495c05a94b7accd4035bf5d5897c434c445b22da855John McCall    llvm_unreachable("unknown context kind!");
14965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// mayHaveIdentifier - Return true if the identifier is either optional or
14995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// required.  This is true for normal declarators and prototypes, but not
15005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// typenames.
15015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool mayHaveIdentifier() const {
1502c05a94b7accd4035bf5d5897c434c445b22da855John McCall    switch (Context) {
1503c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case FileContext:
1504c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case KNRTypeListContext:
1505c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case MemberContext:
1506c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case BlockContext:
1507c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case ForContext:
1508c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case ConditionContext:
1509c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case PrototypeContext:
1510c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case TemplateParamContext:
1511c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case CXXCatchContext:
1512c05a94b7accd4035bf5d5897c434c445b22da855John McCall      return true;
1513c05a94b7accd4035bf5d5897c434c445b22da855John McCall
1514c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case TypeNameContext:
1515162e1c1b487352434552147967c3dd296ebee2f7Richard Smith    case AliasDeclContext:
15163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    case AliasTemplateContext:
1517c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case ObjCPrototypeContext:
1518c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case BlockLiteralContext:
1519c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case TemplateTypeArgContext:
1520c05a94b7accd4035bf5d5897c434c445b22da855John McCall      return false;
1521c05a94b7accd4035bf5d5897c434c445b22da855John McCall    }
1522c05a94b7accd4035bf5d5897c434c445b22da855John McCall    llvm_unreachable("unknown context kind!");
15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
152473a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis
152573a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis  /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be
152673a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis  /// followed by a C++ direct initializer, e.g. "int x(1);".
152773a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis  bool mayBeFollowedByCXXDirectInit() const {
1528c05a94b7accd4035bf5d5897c434c445b22da855John McCall    if (hasGroupingParens()) return false;
1529c05a94b7accd4035bf5d5897c434c445b22da855John McCall
1530c05a94b7accd4035bf5d5897c434c445b22da855John McCall    switch (Context) {
1531c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case FileContext:
1532c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case BlockContext:
1533c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case ForContext:
1534c05a94b7accd4035bf5d5897c434c445b22da855John McCall      return true;
1535c05a94b7accd4035bf5d5897c434c445b22da855John McCall
1536c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case KNRTypeListContext:
1537c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case MemberContext:
1538c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case ConditionContext:
1539c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case PrototypeContext:
1540c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case ObjCPrototypeContext:
1541c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case TemplateParamContext:
1542c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case CXXCatchContext:
1543c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case TypeNameContext:
1544162e1c1b487352434552147967c3dd296ebee2f7Richard Smith    case AliasDeclContext:
15453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    case AliasTemplateContext:
1546c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case BlockLiteralContext:
1547c05a94b7accd4035bf5d5897c434c445b22da855John McCall    case TemplateTypeArgContext:
1548c05a94b7accd4035bf5d5897c434c445b22da855John McCall      return false;
1549c05a94b7accd4035bf5d5897c434c445b22da855John McCall    }
1550c05a94b7accd4035bf5d5897c434c445b22da855John McCall    llvm_unreachable("unknown context kind!");
155173a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis  }
15521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPastIdentifier - Return true if we have parsed beyond the point where
15545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the
15553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool isPastIdentifier() const { return Name.isValid(); }
155610bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor
155710bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor  /// hasName - Whether this declarator has a name, which might be an
155810bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor  /// identifier (accessible via getIdentifier()) or some kind of
155910bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor  /// special C++ name (constructor, destructor, etc.).
15603f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool hasName() const {
15613f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    return Name.getKind() != UnqualifiedId::IK_Identifier || Name.Identifier;
156242a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor  }
156342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor
15643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  IdentifierInfo *getIdentifier() const {
15653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    if (Name.getKind() == UnqualifiedId::IK_Identifier)
15663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor      return Name.Identifier;
15673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
15683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    return 0;
1569e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  }
15703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  SourceLocation getIdentifierLoc() const { return Name.StartLocation; }
1571ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl
15723f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  /// \brief Set the name of this declarator to be the given identifier.
15733f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) {
15743f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor    Name.setIdentifier(Id, IdLoc);
1575db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor  }
15763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
1577ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
1578ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// EndLoc, which should be the last token of the chunk.
15790b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  void AddTypeInfo(const DeclaratorChunk &TI,
15800b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall                   ParsedAttributes &attrs,
15810b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall                   SourceLocation EndLoc) {
15825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DeclTypeInfo.push_back(TI);
15830b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    DeclTypeInfo.back().getAttrListRef() = attrs.getList();
15840b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    getAttributePool().takeAllFrom(attrs.getPool());
15850b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall
1586ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl    if (!EndLoc.isInvalid())
1587ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl      SetRangeEnd(EndLoc);
15885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1589ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl
1590711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  /// AddInnermostTypeInfo - Add a new innermost chunk to this declarator.
1591711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  void AddInnermostTypeInfo(const DeclaratorChunk &TI) {
1592711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    DeclTypeInfo.insert(DeclTypeInfo.begin(), TI);
1593711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  }
1594711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
15955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumTypeObjects() - Return the number of types applied to this
15965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// declarator.
15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); }
15981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Return the specified TypeInfo from this declarator.  TypeInfo #0 is
16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// closest to the identifier.
16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const DeclaratorChunk &getTypeObject(unsigned i) const {
16025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < DeclTypeInfo.size() && "Invalid type chunk");
16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return DeclTypeInfo[i];
16045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  DeclaratorChunk &getTypeObject(unsigned i) {
16065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < DeclTypeInfo.size() && "Invalid type chunk");
16075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return DeclTypeInfo[i];
16085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16108ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl  void DropFirstTypeObject()
16118ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl  {
16128ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl    assert(!DeclTypeInfo.empty() && "No type chunks to drop.");
16138ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl    DeclTypeInfo.front().destroy();
16148ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl    DeclTypeInfo.erase(DeclTypeInfo.begin());
16158ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl  }
16168ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl
1617075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// isFunctionDeclarator - This method returns true if the declarator
1618075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// is a function declarator (looking through parentheses).
1619075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// If true is returned, then the reference type parameter idx is
1620075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// assigned with the index of the declaration chunk.
1621075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  bool isFunctionDeclarator(unsigned& idx) const {
1622075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
1623075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      switch (DeclTypeInfo[i].Kind) {
1624075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      case DeclaratorChunk::Function:
1625075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara        idx = i;
1626075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara        return true;
1627075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      case DeclaratorChunk::Paren:
1628075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara        continue;
1629075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      case DeclaratorChunk::Pointer:
1630075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      case DeclaratorChunk::Reference:
1631075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      case DeclaratorChunk::Array:
1632075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      case DeclaratorChunk::BlockPointer:
1633075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      case DeclaratorChunk::MemberPointer:
1634075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara        return false;
1635075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      }
1636075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      llvm_unreachable("Invalid type chunk");
1637075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      return false;
1638075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    }
1639075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return false;
1640075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1641075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
16425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isFunctionDeclarator - Once this declarator is fully parsed and formed,
1643075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// this method returns true if the identifier is a function declarator
1644075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// (looking through parentheses).
16455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFunctionDeclarator() const {
1646075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    unsigned index;
1647075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return isFunctionDeclarator(index);
1648075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1649075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1650075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// getFunctionTypeInfo - Retrieves the function type info object
1651075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// (looking through parentheses).
1652075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() {
1653075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    assert(isFunctionDeclarator() && "Not a function declarator!");
16545aea91b09bdb36fba4e36c2766f3d5f9127d1e61Douglas Gregor    unsigned index = 0;
1655075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    isFunctionDeclarator(index);
1656075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return DeclTypeInfo[index].Fun;
1657075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1658075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1659075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// getFunctionTypeInfo - Retrieves the function type info object
1660075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// (looking through parentheses).
1661075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const {
1662075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return const_cast<Declarator*>(this)->getFunctionTypeInfo();
16635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16650b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  /// takeAttributes - Takes attributes from the given parsed-attributes
16660b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  /// set and add them to this declarator.
16670b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  ///
1668aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner  /// These examples both add 3 attributes to "var":
1669aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner  ///  short int var __attribute__((aligned(16),common,deprecated));
1670aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner  ///  short int x, __attribute__((aligned(16)) var
1671aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner  ///                                 __attribute__((common,deprecated));
16725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1673ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  /// Also extends the range of the declarator.
16740b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc) {
16750b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    Attrs.takeAllFrom(attrs);
16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16770b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    if (!lastLoc.isInvalid())
16780b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      SetRangeEnd(lastLoc);
16797f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
16807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
16810b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  const AttributeList *getAttributes() const { return Attrs.getList(); }
16820b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  AttributeList *getAttributes() { return Attrs.getList(); }
1683914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar
16840b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  AttributeList *&getAttrListRef() { return Attrs.getListRef(); }
1685711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
1686478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn  /// hasAttributes - do we contain any attributes?
1687478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn  bool hasAttributes() const {
16887f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getAttributes() || getDeclSpec().hasAttributes()) return true;
1689478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn    for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
1690478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn      if (getTypeObject(i).getAttrs())
1691478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn        return true;
1692478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn    return false;
1693478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn  }
1694478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn
1695b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  void setAsmLabel(Expr *E) { AsmLabel = E; }
1696b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  Expr *getAsmLabel() const { return AsmLabel; }
1697914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar
169891a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor  void setExtension(bool Val = true) { Extension = Val; }
169991a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor  bool getExtension() const { return Extension; }
170091a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor
1701eaaebc7cf10dc1a2016183a262ad3256bc468759Chris Lattner  void setInvalidType(bool Val = true) { InvalidType = Val; }
17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isInvalidType() const {
17031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error;
1704cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor  }
170573a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis
170673a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis  void setGroupingParens(bool flag) { GroupingParens = flag; }
170773a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis  bool hasGroupingParens() const { return GroupingParens; }
1708a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor
1709a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor  bool hasEllipsis() const { return EllipsisLoc.isValid(); }
1710a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
1711a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor  void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; }
17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1714e13594279a952537ac903325efff57e3edca79d9Chris Lattner/// FieldDeclarator - This little struct is used to capture information about
1715e13594279a952537ac903325efff57e3edca79d9Chris Lattner/// structure field declarators, which is basically just a bitfield size.
1716e13594279a952537ac903325efff57e3edca79d9Chris Lattnerstruct FieldDeclarator {
1717e13594279a952537ac903325efff57e3edca79d9Chris Lattner  Declarator D;
1718b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  Expr *BitfieldSize;
1719ebe457c3443af253bc14ae77c2013b088370a66bChris Lattner  explicit FieldDeclarator(DeclSpec &DS) : D(DS, Declarator::MemberContext) {
1720e13594279a952537ac903325efff57e3edca79d9Chris Lattner    BitfieldSize = 0;
1721e13594279a952537ac903325efff57e3edca79d9Chris Lattner  }
1722e13594279a952537ac903325efff57e3edca79d9Chris Lattner};
1723b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1724c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson/// VirtSpecifiers - Represents a C++0x virt-specifier-seq.
1725b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonclass VirtSpecifiers {
1726b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonpublic:
1727cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson  enum Specifier {
1728b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    VS_None = 0,
1729b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson    VS_Override = 1,
1730b1f39680a2e3bce508dba0600665860e5ba5fb70Anders Carlsson    VS_Final = 2
1731b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  };
1732b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1733b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  VirtSpecifiers() : Specifiers(0) { }
1734b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1735cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson  bool SetSpecifier(Specifier VS, SourceLocation Loc,
173646127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson                    const char *&PrevSpec);
1737b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1738aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson  bool isOverrideSpecified() const { return Specifiers & VS_Override; }
1739aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson  SourceLocation getOverrideLoc() const { return VS_overrideLoc; }
1740aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson
1741aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson  bool isFinalSpecified() const { return Specifiers & VS_Final; }
1742aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson  SourceLocation getFinalLoc() const { return VS_finalLoc; }
1743aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson
17444867347e82648d3baf09524b98b09c297a5a198fNico Weber  void clear() { Specifiers = 0; }
17454867347e82648d3baf09524b98b09c297a5a198fNico Weber
1746ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson  static const char *getSpecifierName(Specifier VS);
1747ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson
1748f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor  SourceLocation getLastLocation() const { return LastLocation; }
1749f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor
1750b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonprivate:
1751b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  unsigned Specifiers;
1752b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
1753b1f39680a2e3bce508dba0600665860e5ba5fb70Anders Carlsson  SourceLocation VS_overrideLoc, VS_finalLoc;
1754f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8Douglas Gregor  SourceLocation LastLocation;
1755b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson};
1756b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson
175737387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff} // end namespace clang
17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1760