DeclSpec.h revision f52516038ab5d0b1b90a6dd32f46b7d6dabd04c8
15df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//===--- DeclSpec.h - Parsed declaration specifiers -------------*- C++ -*-===//
25df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//
35df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//                     The LLVM Compiler Infrastructure
45df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//
55df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul// This file is distributed under the University of Illinois Open Source
65df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul// License. See LICENSE.TXT for details.
75df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//
85df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//===----------------------------------------------------------------------===//
95df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//
105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul// This file defines the classes used to store parsed information about
115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul// declaration-specifiers and declarators.
125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//
135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//   static const int volatile x, *y, *(*(*z)[10])(const void *x);
145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//   ------------------------- -  --  ---------------------------
155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//     declaration-specifiers  \  |   /
165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//                            declarators
175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//
185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul//===----------------------------------------------------------------------===//
195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#ifndef LLVM_CLANG_SEMA_DECLSPEC_H
215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define LLVM_CLANG_SEMA_DECLSPEC_H
225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#include "clang/Sema/AttributeList.h"
245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#include "clang/Sema/Ownership.h"
255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#include "clang/AST/NestedNameSpecifier.h"
265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#include "clang/Lex/Token.h"
275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#include "clang/Basic/ExceptionSpecificationType.h"
285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#include "clang/Basic/OperatorKinds.h"
295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#include "clang/Basic/Specifiers.h"
305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#include "llvm/ADT/SmallVector.h"
315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#include "llvm/Support/ErrorHandling.h"
325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulnamespace clang {
345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class ASTContext;
355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class TypeLoc;
365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class LangOptions;
375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class Diagnostic;
385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class IdentifierInfo;
395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class NamespaceAliasDecl;
405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class NamespaceDecl;
415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class NestedNameSpecifier;
425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class NestedNameSpecifierLoc;
435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class Preprocessor;
445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  class Declarator;
455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  struct TemplateIdAnnotation;
465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// CXXScopeSpec - Represents a C++ nested-name-specifier or a global scope
485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// specifier.  These can be in 3 states:
495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul///   1) Not present, identified by isEmpty()
505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul///   2) Present, identified by isNotEmpty()
515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul///      2.a) Valid, idenified by isValid()
525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul///      2.b) Invalid, identified by isInvalid().
535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul///
545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// isSet() is deprecated because it mostly corresponded to "valid" but was
555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// often used as if it meant "present".
565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul///
575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// The actual scope is described by getScopeRep().
585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulclass CXXScopeSpec {
595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceRange Range;
6057c9814b9e87924696df4c741861c29d4236d1ebKeith Whitwell  NestedNameSpecifierLocBuilder Builder;
6157c9814b9e87924696df4c741861c29d4236d1ebKeith Whitwell
625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulpublic:
635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  const SourceRange &getRange() const { return Range; }
645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setRange(const SourceRange &R) { Range = R; }
655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getBeginLoc() const { return Range.getBegin(); }
685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getEndLoc() const { return Range.getEnd(); }
695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Retrieve the representation of the nested-name-specifier.
715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  NestedNameSpecifier *getScopeRep() const {
725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return Builder.getRepresentation();
735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Extend the current nested-name-specifier by another
765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// nested-name-specifier component of the form 'type::'.
775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Context The AST context in which this nested-name-specifier
795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// resides.
805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param TemplateKWLoc The location of the 'template' keyword, if present.
825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param TL The TypeLoc that describes the type preceding the '::'.
845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param ColonColonLoc The location of the trailing '::'.
865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL,
875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul              SourceLocation ColonColonLoc);
885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Extend the current nested-name-specifier by another
905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// nested-name-specifier component of the form 'identifier::'.
915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Context The AST context in which this nested-name-specifier
935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// resides.
945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Identifier The identifier.
965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param IdentifierLoc The location of the identifier.
985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param ColonColonLoc The location of the trailing '::'.
10099ef0a03292e7dc6aa2465aaaa620f394d2c286bAlan Hourihane  void Extend(ASTContext &Context, IdentifierInfo *Identifier,
1015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul              SourceLocation IdentifierLoc, SourceLocation ColonColonLoc);
1025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Extend the current nested-name-specifier by another
1045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// nested-name-specifier component of the form 'namespace::'.
1055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Context The AST context in which this nested-name-specifier
1075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// resides.
1085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Namespace The namespace.
1105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param NamespaceLoc The location of the namespace name.
1125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param ColonColonLoc The location of the trailing '::'.
1145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void Extend(ASTContext &Context, NamespaceDecl *Namespace,
1155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul              SourceLocation NamespaceLoc, SourceLocation ColonColonLoc);
1165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Extend the current nested-name-specifier by another
1185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// nested-name-specifier component of the form 'namespace-alias::'.
1195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Context The AST context in which this nested-name-specifier
1215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// resides.
1225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Alias The namespace alias.
1245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param AliasLoc The location of the namespace alias
1265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// name.
1275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param ColonColonLoc The location of the trailing '::'.
1295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
1305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul              SourceLocation AliasLoc, SourceLocation ColonColonLoc);
1315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Turn this (empty) nested-name-specifier into the global
1335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// nested-name-specifier '::'.
1345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc);
1355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Make a new nested-name-specifier from incomplete source-location
1375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// information.
1385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// FIXME: This routine should be used very, very rarely, in cases where we
1405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// need to synthesize a nested-name-specifier. Most code should instead use
1415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \c Adopt() with a proper \c NestedNameSpecifierLoc.
1425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier,
1435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                   SourceRange R);
1445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Adopt an existing nested-name-specifier (with source-range
1465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// information).
1475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void Adopt(NestedNameSpecifierLoc Other);
1485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Retrieve a nested-name-specifier with location information, copied
1505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// into the given AST context.
1515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
1525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Context The context into which this nested-name-specifier will be
1535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// copied.
1545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const;
1555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// No scope specifier.
1575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isEmpty() const { return !Range.isValid(); }
1585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// A scope specifier is present, but may be valid or invalid.
1595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isNotEmpty() const { return !isEmpty(); }
1605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// An error occured during parsing of the scope specifier.
1625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isInvalid() const { return isNotEmpty() && getScopeRep() == 0; }
1635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// A scope specifier is present, and it refers to a real scope.
1645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isValid() const { return isNotEmpty() && getScopeRep() != 0; }
1655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Indicate that this nested-name-specifier is invalid.
1675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void SetInvalid(SourceRange R) {
1685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    assert(R.isValid() && "Must have a valid source range");
1695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    if (Range.getBegin().isInvalid())
1705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      Range.setBegin(R.getBegin());
1715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Range.setEnd(R.getEnd());
1725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Builder.Clear();
1735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
1745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// Deprecated.  Some call sites intend isNotEmpty() while others intend
1765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// isValid().
1775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isSet() const { return getScopeRep() != 0; }
1785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void clear() {
1805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Range = SourceRange();
1815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Builder.Clear();
1825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
1835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Retrieve the data associated with the source-location information.
1855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  char *location_data() const { return Builder.getBuffer().first; }
1865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Retrieve the size of the data associated with source-location
18822d1acf2ee25280c3294c2cfded232e612ffac2eFelix Kuehling  /// information.
1895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned location_size() const { return Builder.getBuffer().second; }
1905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul};
1915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// DeclSpec - This class captures information about "declaration specifiers",
1935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// which encompasses storage-class-specifiers, type-specifiers,
1945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// type-qualifiers, and function-specifiers.
1955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulclass DeclSpec {
1965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulpublic:
1975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // storage-class-specifier
1985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // Note: The order of these enumerators is important for diagnostics.
1995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  enum SCS {
2005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_unspecified = 0,
2015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_typedef,
2025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_extern,
2035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_static,
2045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_auto,
2055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_register,
2065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_private_extern,
2075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_mutable
2085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  };
2095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // Import type specifier width enumeration and constants.
2115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  typedef TypeSpecifierWidth TSW;
2125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TSW TSW_unspecified = clang::TSW_unspecified;
2135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TSW TSW_short = clang::TSW_short;
2145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TSW TSW_long = clang::TSW_long;
2155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TSW TSW_longlong = clang::TSW_longlong;
2165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  enum TSC {
2185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    TSC_unspecified,
2195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    TSC_imaginary,
2205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    TSC_complex
2215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  };
2225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // Import type specifier sign enumeration and constants.
2245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  typedef TypeSpecifierSign TSS;
2255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TSS TSS_unspecified = clang::TSS_unspecified;
2265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TSS TSS_signed = clang::TSS_signed;
2275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TSS TSS_unsigned = clang::TSS_unsigned;
2285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // Import type specifier type enumeration and constants.
2305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  typedef TypeSpecifierType TST;
2315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_unspecified = clang::TST_unspecified;
2325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_void = clang::TST_void;
2335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_char = clang::TST_char;
2345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_wchar = clang::TST_wchar;
2355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_char16 = clang::TST_char16;
2365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_char32 = clang::TST_char32;
2375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_int = clang::TST_int;
2385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_float = clang::TST_float;
2395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_double = clang::TST_double;
2405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_bool = clang::TST_bool;
2415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_decimal32 = clang::TST_decimal32;
2425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_decimal64 = clang::TST_decimal64;
2435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_decimal128 = clang::TST_decimal128;
2445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_enum = clang::TST_enum;
2455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_union = clang::TST_union;
2465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_struct = clang::TST_struct;
2475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_class = clang::TST_class;
2485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_typename = clang::TST_typename;
2495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_typeofType = clang::TST_typeofType;
2505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_typeofExpr = clang::TST_typeofExpr;
2515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_decltype = clang::TST_decltype;
2525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_auto = clang::TST_auto;
2535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const TST TST_error = clang::TST_error;
2545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // type-qualifiers
2565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  enum TQ {   // NOTE: These flags must be kept in sync with Qualifiers::TQ.
2575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    TQ_unspecified = 0,
2585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    TQ_const       = 1,
2595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    TQ_restrict    = 2,
2605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    TQ_volatile    = 4
2615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  };
2625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// ParsedSpecifiers - Flags to query which specifiers were applied.  This is
2645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// returned by getParsedSpecifiers.
2655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  enum ParsedSpecifiers {
2665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    PQ_None                  = 0,
2675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    PQ_StorageClassSpecifier = 1,
2685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    PQ_TypeSpecifier         = 2,
2695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    PQ_TypeQualifier         = 4,
2705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    PQ_FunctionSpecifier     = 8
2715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  };
2725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulprivate:
2745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // storage-class-specifier
2765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /*SCS*/unsigned StorageClassSpec : 3;
2775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned SCS_thread_specified : 1;
2785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned SCS_extern_in_linkage_spec : 1;
2795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // type-specifier
2815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /*TSW*/unsigned TypeSpecWidth : 2;
2825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /*TSC*/unsigned TypeSpecComplex : 2;
2835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /*TSS*/unsigned TypeSpecSign : 2;
2845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /*TST*/unsigned TypeSpecType : 5;
2855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned TypeAltiVecVector : 1;
2865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned TypeAltiVecPixel : 1;
2875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned TypeAltiVecBool : 1;
2885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned TypeSpecOwned : 1;
2895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // type-qualifiers
2915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned TypeQualifiers : 3;  // Bitwise OR of TQ.
2925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // function-specifier
2945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned FS_inline_specified : 1;
2955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned FS_virtual_specified : 1;
2965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned FS_explicit_specified : 1;
2975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // friend-specifier
2995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned Friend_specified : 1;
3005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // constexpr-specifier
3025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned Constexpr_specified : 1;
3035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /*SCS*/unsigned StorageClassSpecAsWritten : 3;
3055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  union {
3075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    UnionParsedType TypeRep;
3085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Decl *DeclRep;
3095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Expr *ExprRep;
3105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  };
3115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // attributes.
3135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ParsedAttributes Attrs;
3145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // Scope specifier for the type spec, if applicable.
3165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  CXXScopeSpec TypeScope;
3175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // List of protocol qualifiers for objective-c classes.  Used for
3195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // protocol-qualified interfaces "NString<foo>" and protocol-qualified id
3205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // "id<foo>".
3215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  Decl * const *ProtocolQualifiers;
3225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned NumProtocolQualifiers;
3235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation ProtocolLAngleLoc;
3245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation *ProtocolLocs;
3255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // SourceLocation info.  These are null if the item wasn't specified or if
3275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // the setting was synthesized.
3285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceRange Range;
3295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation StorageClassSpecLoc, SCS_threadLoc;
3315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc;
3325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceRange TypeofParensRange;
3335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc;
3345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc;
3355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation FriendLoc, ConstexprLoc;
3365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  WrittenBuiltinSpecs writtenBS;
3385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void SaveWrittenBuiltinSpecs();
3395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void SaveStorageSpecifierAsWritten();
3405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static bool isTypeRep(TST T) {
3425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return (T == TST_typename || T == TST_typeofType);
3435d00e131d8a264498b8d050c3eded093ee5c42f2Michel Dänzer  }
3445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static bool isExprRep(TST T) {
3455d00e131d8a264498b8d050c3eded093ee5c42f2Michel Dänzer    return (T == TST_typeofExpr || T == TST_decltype);
3465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
3475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static bool isDeclRep(TST T) {
3485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return (T == TST_enum || T == TST_struct ||
3495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul            T == TST_union || T == TST_class);
3505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
3515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  DeclSpec(const DeclSpec&);       // DO NOT IMPLEMENT
3535d00e131d8a264498b8d050c3eded093ee5c42f2Michel Dänzer  void operator=(const DeclSpec&); // DO NOT IMPLEMENT
3545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulpublic:
3555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  DeclSpec()
3575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    : StorageClassSpec(SCS_unspecified),
3585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      SCS_thread_specified(false),
3595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      SCS_extern_in_linkage_spec(false),
3605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TypeSpecWidth(TSW_unspecified),
3615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TypeSpecComplex(TSC_unspecified),
3625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TypeSpecSign(TSS_unspecified),
3635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TypeSpecType(TST_unspecified),
3645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TypeAltiVecVector(false),
3655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TypeAltiVecPixel(false),
3665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TypeAltiVecBool(false),
3675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TypeSpecOwned(false),
3685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TypeQualifiers(TSS_unspecified),
3695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      FS_inline_specified(false),
3705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      FS_virtual_specified(false),
3715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      FS_explicit_specified(false),
3725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      Friend_specified(false),
3735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      Constexpr_specified(false),
3745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      StorageClassSpecAsWritten(SCS_unspecified),
3755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ProtocolQualifiers(0),
3765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      NumProtocolQualifiers(0),
3775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ProtocolLocs(0),
3785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      writtenBS() {
3795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
3805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ~DeclSpec() {
3815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    delete [] ProtocolQualifiers;
3825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    delete [] ProtocolLocs;
3835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
3845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // storage-class-specifier
3855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
3865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isThreadSpecified() const { return SCS_thread_specified; }
3875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
3885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setExternInLinkageSpec(bool Value) {
3895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_extern_in_linkage_spec = Value;
3905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
3915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
3935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getThreadSpecLoc() const { return SCS_threadLoc; }
3945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void ClearStorageClassSpecs() {
3965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    StorageClassSpec     = DeclSpec::SCS_unspecified;
3975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_thread_specified = false;
3985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_extern_in_linkage_spec = false;
3995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    StorageClassSpecLoc  = SourceLocation();
4005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    SCS_threadLoc        = SourceLocation();
4015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
4025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // type-specifier
4045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; }
4055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
4065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; }
4075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  TST getTypeSpecType() const { return (TST)TypeSpecType; }
4085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
4095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
4105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
4115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isTypeSpecOwned() const { return TypeSpecOwned; }
4125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ParsedType getRepAsType() const {
4135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
4145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return TypeRep;
4155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
4165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  Decl *getRepAsDecl() const {
4175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
4185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return DeclRep;
4195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
4205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  Expr *getRepAsExpr() const {
4215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
4225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return ExprRep;
4235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
4245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
4255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
4265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  const SourceRange &getSourceRange() const { return Range; }
4285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; }
4295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
4305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
4315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
4325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
4335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceRange getTypeofParensRange() const { return TypeofParensRange; }
4355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; }
4365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// getSpecifierName - Turn a type-specifier-type into a string like "_Bool"
4385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// or "union".
4395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const char *getSpecifierName(DeclSpec::TST T);
4405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const char *getSpecifierName(DeclSpec::TQ Q);
4415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const char *getSpecifierName(DeclSpec::TSS S);
4425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const char *getSpecifierName(DeclSpec::TSC C);
4435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const char *getSpecifierName(DeclSpec::TSW W);
4445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  static const char *getSpecifierName(DeclSpec::SCS S);
4455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // type-qualifiers
4475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// getTypeQualifiers - Return a set of TQs.
4495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned getTypeQualifiers() const { return TypeQualifiers; }
4505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
451bcc6eddd335e97d49ed2ef3a1440f94d58dce12dJon Smirl  SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
4525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
4535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // function-specifier
4555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isInlineSpecified() const { return FS_inline_specified; }
4565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getInlineSpecLoc() const { return FS_inlineLoc; }
4575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isVirtualSpecified() const { return FS_virtual_specified; }
4595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
4605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isExplicitSpecified() const { return FS_explicit_specified; }
4625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
4635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void ClearFunctionSpecs() {
4655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    FS_inline_specified = false;
4665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    FS_inlineLoc = SourceLocation();
4675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    FS_virtual_specified = false;
4685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    FS_virtualLoc = SourceLocation();
4695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    FS_explicit_specified = false;
4705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    FS_explicitLoc = SourceLocation();
4715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
4725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// hasTypeSpecifier - Return true if any type-specifier has been found.
4745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool hasTypeSpecifier() const {
4755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return getTypeSpecType() != DeclSpec::TST_unspecified ||
4765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul           getTypeSpecWidth() != DeclSpec::TSW_unspecified ||
4775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul           getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
4785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul           getTypeSpecSign() != DeclSpec::TSS_unspecified;
4795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
4805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
4825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// DeclSpec includes.
4835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
4845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned getParsedSpecifiers() const;
4855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SCS getStorageClassSpecAsWritten() const {
4875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return (SCS)StorageClassSpecAsWritten;
4885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
4895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// isEmpty - Return true if this declaration specifier is completely empty:
4915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// no tokens were parsed in the production of it.
4925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isEmpty() const {
4935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return getParsedSpecifiers() == DeclSpec::PQ_None;
4945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
4955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
4975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
4985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// These methods set the specified attribute of the DeclSpec and
5005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// return false if there was no error.  If an error occurs (for
5015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// example, if we tried to set "auto" on a spec with "extern"
5025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// already set), they return true and set PrevSpec and DiagID
5035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// such that
5045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///   Diag(Loc, DiagID) << PrevSpec;
5055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// will yield a useful result.
5065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
5075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// TODO: use a more general approach that still allows these
5085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// diagnostics to be ignored when desired.
5095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetStorageClassSpec(SCS S, SourceLocation Loc, const char *&PrevSpec,
51057c9814b9e87924696df4c741861c29d4236d1ebKeith Whitwell                           unsigned &DiagID, const LangOptions &Lang);
51157c9814b9e87924696df4c741861c29d4236d1ebKeith Whitwell  bool SetStorageClassSpecThread(SourceLocation Loc, const char *&PrevSpec,
51257c9814b9e87924696df4c741861c29d4236d1ebKeith Whitwell                                 unsigned &DiagID);
51357c9814b9e87924696df4c741861c29d4236d1ebKeith Whitwell  bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec,
51457c9814b9e87924696df4c741861c29d4236d1ebKeith Whitwell                        unsigned &DiagID);
5155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
5165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                          unsigned &DiagID);
5175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec,
5185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                       unsigned &DiagID);
5195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
5205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                       unsigned &DiagID);
5215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
5225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                       unsigned &DiagID, ParsedType Rep);
5235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
5245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                       unsigned &DiagID, Decl *Rep, bool Owned);
5255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
5265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                       unsigned &DiagID, Expr *Rep);
5275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
5285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                       const char *&PrevSpec, unsigned &DiagID);
5295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
5305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                       const char *&PrevSpec, unsigned &DiagID);
5315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeSpecError();
5325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void UpdateDeclRep(Decl *Rep) {
5335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    assert(isDeclRep((TST) TypeSpecType));
5345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DeclRep = Rep;
5355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
5365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void UpdateTypeRep(ParsedType Rep) {
5375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    assert(isTypeRep((TST) TypeSpecType));
5385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    TypeRep = Rep;
5395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
5405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void UpdateExprRep(Expr *Rep) {
5415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    assert(isExprRep((TST) TypeSpecType));
5425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    ExprRep = Rep;
5435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
5445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
5465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                   unsigned &DiagID, const LangOptions &Lang);
5475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
5495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                             unsigned &DiagID);
5505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
5515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                              unsigned &DiagID);
5525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
5535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                               unsigned &DiagID);
5545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
5565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                     unsigned &DiagID);
5575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
5595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                        unsigned &DiagID);
5605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isFriendSpecified() const { return Friend_specified; }
5625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getFriendSpecLoc() const { return FriendLoc; }
5635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isConstexprSpecified() const { return Constexpr_specified; }
5655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
5665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// AddAttributes - contatenates two attribute lists.
5685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// The GCC attribute syntax allows for the following:
5695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
5705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// short __attribute__(( unused, deprecated ))
5715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// int __attribute__(( may_alias, aligned(16) )) var;
5725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
5735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// This declares 4 attributes using 2 lists. The following syntax is
5745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// also allowed and equivalent to the previous declaration.
5755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
5765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// short __attribute__((unused)) __attribute__((deprecated))
5775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
5785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
5795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void addAttributes(AttributeList *AL) {
5805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Attrs.append(AL);
5815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
5825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void aetAttributes(AttributeList *AL) {
5835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Attrs.set(AL);
5845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
5855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool hasAttributes() const { return !Attrs.empty(); }
5875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ParsedAttributes &getAttributes() { return Attrs; }
5895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  const ParsedAttributes &getAttributes() const { return Attrs; }
5905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// TakeAttributes - Return the current attribute list and remove them from
5925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// the DeclSpec so that it doesn't own them.
5935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ParsedAttributes takeAttributes() {
5945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    ParsedAttributes saved = Attrs;
5955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Attrs.clear();
5965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return saved;
5975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
5985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void takeAttributesFrom(ParsedAttributes &attrs) {
6005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Attrs.append(attrs.getList());
6015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    attrs.clear();
6025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
6035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  typedef Decl * const *ProtocolQualifierListTy;
6055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ProtocolQualifierListTy getProtocolQualifiers() const {
6065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return ProtocolQualifiers;
6075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
6085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation *getProtocolLocs() const { return ProtocolLocs; }
6095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned getNumProtocolQualifiers() const {
6105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return NumProtocolQualifiers;
6115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
6125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; }
6135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setProtocolQualifiers(Decl * const *Protos, unsigned NP,
6145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                             SourceLocation *ProtoLocs,
6155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                             SourceLocation LAngleLoc);
6165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// Finish - This does final analysis of the declspec, issuing diagnostics for
6185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// things like "_Imaginary" (lacking an FP type).  After calling this method,
6195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// DeclSpec is guaranteed self-consistent, even if an error occurred.
6205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void Finish(Diagnostic &D, Preprocessor &PP);
6215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
6235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return writtenBS;
6245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
6255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// isMissingDeclaratorOk - This checks if this DeclSpec can stand alone,
6275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// without a Declarator. Only tag declspecs can stand alone.
6285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isMissingDeclaratorOk();
6295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul};
6305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// ObjCDeclSpec - This class captures information about
6325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// "declaration specifiers" specific to objective-c
6335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulclass ObjCDeclSpec {
6345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulpublic:
6355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// ObjCDeclQualifier - Qualifier used on types in method declarations
6365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  enum ObjCDeclQualifier {
6375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_None = 0x0,
6385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_In = 0x1,
6395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_Inout = 0x2,
6405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_Out = 0x4,
6415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_Bycopy = 0x8,
6425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_Byref = 0x10,
6435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_Oneway = 0x20
6445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  };
6455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// PropertyAttributeKind - list of property attributes.
6475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  enum ObjCPropertyAttributeKind { DQ_PR_noattr = 0x0,
6485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_PR_readonly = 0x01,
6495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_PR_getter = 0x02,
6505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_PR_assign = 0x04,
6515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_PR_readwrite = 0x08,
6525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_PR_retain = 0x10,
6535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_PR_copy = 0x20,
6545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_PR_nonatomic = 0x40,
6555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_PR_setter = 0x80,
6565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    DQ_PR_atomic = 0x100
6575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  };
6585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ObjCDeclSpec()
6615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr),
6625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GetterName(0), SetterName(0) { }
6635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ObjCDeclQualifier getObjCDeclQualifier() const { return objcDeclQualifier; }
6645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setObjCDeclQualifier(ObjCDeclQualifier DQVal) {
6655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal);
6665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
6675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ObjCPropertyAttributeKind getPropertyAttributes() const {
6695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    return ObjCPropertyAttributeKind(PropertyAttributes);
6705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
6715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setPropertyAttributes(ObjCPropertyAttributeKind PRVal) {
6725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    PropertyAttributes =
6735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal);
6745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
6755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  const IdentifierInfo *getGetterName() const { return GetterName; }
6775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  IdentifierInfo *getGetterName() { return GetterName; }
6785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setGetterName(IdentifierInfo *name) { GetterName = name; }
6795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  const IdentifierInfo *getSetterName() const { return SetterName; }
6815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  IdentifierInfo *getSetterName() { return SetterName; }
6825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setSetterName(IdentifierInfo *name) { SetterName = name; }
6835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulprivate:
6845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // FIXME: These two are unrelated and mutially exclusive. So perhaps
6855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // we can put them in a union to reflect their mutual exclusiveness
6865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // (space saving is negligible).
6875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ObjCDeclQualifier objcDeclQualifier : 6;
6885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind
6905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  unsigned PropertyAttributes : 9;
6915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  IdentifierInfo *GetterName;    // getter name of NULL if no getter
6925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  IdentifierInfo *SetterName;    // setter name of NULL if no setter
6935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul};
6945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/// \brief Represents a C++ unqualified-id that has been parsed.
6965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulclass UnqualifiedId {
6975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulprivate:
6985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  const UnqualifiedId &operator=(const UnqualifiedId &); // DO NOT IMPLEMENT
6995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulpublic:
7015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Describes the kind of unqualified-id parsed.
702d907a75498360fb96ec2314bb0abb105be74d500Alan Hourihane  enum IdKind {
703d3fd7ba8af15bead2f770d68a893449adeb11397Brian Paul    /// \brief An identifier.
7045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    IK_Identifier,
7055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief An overloaded operator name, e.g., operator+.
7065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    IK_OperatorFunctionId,
7075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief A conversion function name, e.g., operator int.
7085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    IK_ConversionFunctionId,
7095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief A user-defined literal name, e.g., operator "" _i.
7105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    IK_LiteralOperatorId,
7115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief A constructor name.
7125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    IK_ConstructorName,
7135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief A constructor named via a template-id.
7145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    IK_ConstructorTemplateId,
7155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief A destructor name.
7165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    IK_DestructorName,
7175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief A template-id, e.g., f<int>.
7185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    IK_TemplateId
7195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  } Kind;
7205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Anonymous union that holds extra data associated with the
7225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// parsed unqualified-id.
7235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  union {
7245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind
7255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// == IK_UserLiteralId, the identifier suffix.
7265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    IdentifierInfo *Identifier;
7275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator
7295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// that we parsed.
7305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    struct {
7315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /// \brief The kind of overloaded operator.
7325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      OverloadedOperatorKind Operator;
7335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /// \brief The source locations of the individual tokens that name
7355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /// the operator, e.g., the "new", "[", and "]" tokens in
7365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /// operator new [].
7375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ///
7385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /// Different operators have different numbers of tokens in their name,
7395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /// up to three. Any remaining source locations in this array will be
7405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /// set to an invalid value for operators with fewer than three tokens.
7415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      unsigned SymbolLocations[3];
7425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    } OperatorFunctionId;
7435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief When Kind == IK_ConversionFunctionId, the type that the
7455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// conversion function names.
7465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    UnionParsedType ConversionFunctionId;
7475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief When Kind == IK_ConstructorName, the class-name of the type
7495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// whose constructor is being referenced.
7505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    UnionParsedType ConstructorName;
7515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
752afa446db83ecf5dcb38ce46648fb12911628de32Ian Romanick    /// \brief When Kind == IK_DestructorName, the type referred to by the
753afa446db83ecf5dcb38ce46648fb12911628de32Ian Romanick    /// class-name.
7545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    UnionParsedType DestructorName;
7555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// \brief When Kind == IK_TemplateId or IK_ConstructorTemplateId,
7575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// the template-id annotation that contains the template name and
7585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    /// template arguments.
7595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    TemplateIdAnnotation *TemplateId;
7605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  };
7615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief The location of the first token that describes this unqualified-id,
7635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// which will be the location of the identifier, "operator" keyword,
7645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// tilde (for a destructor), or the template name of a template-id.
7655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation StartLocation;
7665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief The location of the last token that describes this unqualified-id.
7685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  SourceLocation EndLocation;
7695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  UnqualifiedId() : Kind(IK_Identifier), Identifier(0) { }
7715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Do not use this copy constructor. It is temporary, and only
7735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// exists because we are holding FieldDeclarators in a SmallVector when we
7745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// don't actually need them.
7755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
776bcc6eddd335e97d49ed2ef3a1440f94d58dce12dJon Smirl  /// FIXME: Kill this copy constructor.
777bcc6eddd335e97d49ed2ef3a1440f94d58dce12dJon Smirl  UnqualifiedId(const UnqualifiedId &Other)
778bcc6eddd335e97d49ed2ef3a1440f94d58dce12dJon Smirl    : Kind(IK_Identifier), Identifier(Other.Identifier),
779bcc6eddd335e97d49ed2ef3a1440f94d58dce12dJon Smirl      StartLocation(Other.StartLocation), EndLocation(Other.EndLocation) {
7805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    assert(Other.Kind == IK_Identifier && "Cannot copy non-identifiers");
7815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
7825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Destroy this unqualified-id.
7845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ~UnqualifiedId() { clear(); }
7855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Clear out this unqualified-id, setting it to default (invalid)
7875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// state.
7885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void clear();
7895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Determine whether this unqualified-id refers to a valid name.
7915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isValid() const { return StartLocation.isValid(); }
7925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Determine whether this unqualified-id refers to an invalid name.
7945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  bool isInvalid() const { return !isValid(); }
7955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Determine what kind of name we have.
7975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  IdKind getKind() const { return Kind; }
7985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Specify that this unqualified-id was parsed as an identifier.
8005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Id the parsed identifier.
8025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param IdLoc the location of the parsed identifier.
8035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
8045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Kind = IK_Identifier;
8055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Identifier = const_cast<IdentifierInfo *>(Id);
8065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    StartLocation = EndLocation = IdLoc;
8075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
8085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Specify that this unqualified-id was parsed as an
8105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// operator-function-id.
8115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param OperatorLoc the location of the 'operator' keyword.
8135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Op the overloaded operator.
8155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param SymbolLocations the locations of the individual operator symbols
8175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// in the operator.
8185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setOperatorFunctionId(SourceLocation OperatorLoc,
8195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                             OverloadedOperatorKind Op,
8205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                             SourceLocation SymbolLocations[3]);
8215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Specify that this unqualified-id was parsed as a
8235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// conversion-function-id.
8245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param OperatorLoc the location of the 'operator' keyword.
8265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Ty the type to which this conversion function is converting.
8285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param EndLoc the location of the last token that makes up the type name.
8305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setConversionFunctionId(SourceLocation OperatorLoc,
8315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                               ParsedType Ty,
8325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                               SourceLocation EndLoc) {
8335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Kind = IK_ConversionFunctionId;
8345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    StartLocation = OperatorLoc;
8355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    EndLocation = EndLoc;
8365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    ConversionFunctionId = Ty;
8375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  }
8385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \brief Specific that this unqualified-id was parsed as a
8405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// literal-operator-id.
8415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param Id the parsed identifier.
8435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param OpLoc the location of the 'operator' keyword.
8455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  ///
8465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  /// \param IdLoc the location of the identifier.
8475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul  void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc,
848                              SourceLocation IdLoc) {
849    Kind = IK_LiteralOperatorId;
850    Identifier = const_cast<IdentifierInfo *>(Id);
851    StartLocation = OpLoc;
852    EndLocation = IdLoc;
853  }
854
855  /// \brief Specify that this unqualified-id was parsed as a constructor name.
856  ///
857  /// \param ClassType the class type referred to by the constructor name.
858  ///
859  /// \param ClassNameLoc the location of the class name.
860  ///
861  /// \param EndLoc the location of the last token that makes up the type name.
862  void setConstructorName(ParsedType ClassType,
863                          SourceLocation ClassNameLoc,
864                          SourceLocation EndLoc) {
865    Kind = IK_ConstructorName;
866    StartLocation = ClassNameLoc;
867    EndLocation = EndLoc;
868    ConstructorName = ClassType;
869  }
870
871  /// \brief Specify that this unqualified-id was parsed as a
872  /// template-id that names a constructor.
873  ///
874  /// \param TemplateId the template-id annotation that describes the parsed
875  /// template-id. This UnqualifiedId instance will take ownership of the
876  /// \p TemplateId and will free it on destruction.
877  void setConstructorTemplateId(TemplateIdAnnotation *TemplateId);
878
879  /// \brief Specify that this unqualified-id was parsed as a destructor name.
880  ///
881  /// \param TildeLoc the location of the '~' that introduces the destructor
882  /// name.
883  ///
884  /// \param ClassType the name of the class referred to by the destructor name.
885  void setDestructorName(SourceLocation TildeLoc,
886                         ParsedType ClassType,
887                         SourceLocation EndLoc) {
888    Kind = IK_DestructorName;
889    StartLocation = TildeLoc;
890    EndLocation = EndLoc;
891    DestructorName = ClassType;
892  }
893
894  /// \brief Specify that this unqualified-id was parsed as a template-id.
895  ///
896  /// \param TemplateId the template-id annotation that describes the parsed
897  /// template-id. This UnqualifiedId instance will take ownership of the
898  /// \p TemplateId and will free it on destruction.
899  void setTemplateId(TemplateIdAnnotation *TemplateId);
900
901  /// \brief Return the source range that covers this unqualified-id.
902  SourceRange getSourceRange() const {
903    return SourceRange(StartLocation, EndLocation);
904  }
905};
906
907/// CachedTokens - A set of tokens that has been cached for later
908/// parsing.
909typedef llvm::SmallVector<Token, 4> CachedTokens;
910
911/// DeclaratorChunk - One instance of this struct is used for each type in a
912/// declarator that is parsed.
913///
914/// This is intended to be a small value object.
915struct DeclaratorChunk {
916  enum {
917    Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren
918  } Kind;
919
920  /// Loc - The place where this type was defined.
921  SourceLocation Loc;
922  /// EndLoc - If valid, the place where this chunck ends.
923  SourceLocation EndLoc;
924
925  struct TypeInfoCommon {
926    AttributeList *AttrList;
927  };
928
929  struct PointerTypeInfo : TypeInfoCommon {
930    /// The type qualifiers: const/volatile/restrict.
931    unsigned TypeQuals : 3;
932
933    /// The location of the const-qualifier, if any.
934    unsigned ConstQualLoc;
935
936    /// The location of the volatile-qualifier, if any.
937    unsigned VolatileQualLoc;
938
939    /// The location of the restrict-qualifier, if any.
940    unsigned RestrictQualLoc;
941
942    void destroy() {
943    }
944  };
945
946  struct ReferenceTypeInfo : TypeInfoCommon {
947    /// The type qualifier: restrict. [GNU] C++ extension
948    bool HasRestrict : 1;
949    /// True if this is an lvalue reference, false if it's an rvalue reference.
950    bool LValueRef : 1;
951    void destroy() {
952    }
953  };
954
955  struct ArrayTypeInfo : TypeInfoCommon {
956    /// The type qualifiers for the array: const/volatile/restrict.
957    unsigned TypeQuals : 3;
958
959    /// True if this dimension included the 'static' keyword.
960    bool hasStatic : 1;
961
962    /// True if this dimension was [*].  In this case, NumElts is null.
963    bool isStar : 1;
964
965    /// This is the size of the array, or null if [] or [*] was specified.
966    /// Since the parser is multi-purpose, and we don't want to impose a root
967    /// expression class on all clients, NumElts is untyped.
968    Expr *NumElts;
969
970    void destroy() {}
971  };
972
973  /// ParamInfo - An array of paraminfo objects is allocated whenever a function
974  /// declarator is parsed.  There are two interesting styles of arguments here:
975  /// K&R-style identifier lists and parameter type lists.  K&R-style identifier
976  /// lists will have information about the identifier, but no type information.
977  /// Parameter type lists will have type info (if the actions module provides
978  /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.
979  struct ParamInfo {
980    IdentifierInfo *Ident;
981    SourceLocation IdentLoc;
982    Decl *Param;
983
984    /// DefaultArgTokens - When the parameter's default argument
985    /// cannot be parsed immediately (because it occurs within the
986    /// declaration of a member function), it will be stored here as a
987    /// sequence of tokens to be parsed once the class definition is
988    /// complete. Non-NULL indicates that there is a default argument.
989    CachedTokens *DefaultArgTokens;
990
991    ParamInfo() {}
992    ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
993              Decl *param,
994              CachedTokens *DefArgTokens = 0)
995      : Ident(ident), IdentLoc(iloc), Param(param),
996        DefaultArgTokens(DefArgTokens) {}
997  };
998
999  struct TypeAndRange {
1000    ParsedType Ty;
1001    SourceRange Range;
1002  };
1003
1004  struct FunctionTypeInfo : TypeInfoCommon {
1005    /// hasPrototype - This is true if the function had at least one typed
1006    /// argument.  If the function is () or (a,b,c), then it has no prototype,
1007    /// and is treated as a K&R-style function.
1008    unsigned hasPrototype : 1;
1009
1010    /// isVariadic - If this function has a prototype, and if that
1011    /// proto ends with ',...)', this is true. When true, EllipsisLoc
1012    /// contains the location of the ellipsis.
1013    unsigned isVariadic : 1;
1014
1015    /// \brief Whether the ref-qualifier (if any) is an lvalue reference.
1016    /// Otherwise, it's an rvalue reference.
1017    unsigned RefQualifierIsLValueRef : 1;
1018
1019    /// The type qualifiers: const/volatile/restrict.
1020    /// The qualifier bitmask values are the same as in QualType.
1021    unsigned TypeQuals : 3;
1022
1023    /// ExceptionSpecType - An ExceptionSpecificationType value.
1024    unsigned ExceptionSpecType : 3;
1025
1026    /// DeleteArgInfo - If this is true, we need to delete[] ArgInfo.
1027    unsigned DeleteArgInfo : 1;
1028
1029    /// When isVariadic is true, the location of the ellipsis in the source.
1030    unsigned EllipsisLoc;
1031
1032    /// NumArgs - This is the number of formal arguments provided for the
1033    /// declarator.
1034    unsigned NumArgs;
1035
1036    /// NumExceptions - This is the number of types in the dynamic-exception-
1037    /// decl, if the function has one.
1038    unsigned NumExceptions;
1039
1040    /// \brief The location of the ref-qualifier, if any.
1041    ///
1042    /// If this is an invalid location, there is no ref-qualifier.
1043    unsigned RefQualifierLoc;
1044
1045    /// \brief When ExceptionSpecType isn't EST_None, the location of the
1046    /// keyword introducing the spec.
1047    unsigned ExceptionSpecLoc;
1048
1049    /// ArgInfo - This is a pointer to a new[]'d array of ParamInfo objects that
1050    /// describe the arguments for this function declarator.  This is null if
1051    /// there are no arguments specified.
1052    ParamInfo *ArgInfo;
1053
1054    union {
1055      /// \brief Pointer to a new[]'d array of TypeAndRange objects that
1056      /// contain the types in the function's dynamic exception specification
1057      /// and their locations, if there is one.
1058      TypeAndRange *Exceptions;
1059
1060      /// \brief Pointer to the expression in the noexcept-specifier of this
1061      /// function, if it has one.
1062      Expr *NoexceptExpr;
1063    };
1064
1065    /// TrailingReturnType - If this isn't null, it's the trailing return type
1066    /// specified. This is actually a ParsedType, but stored as void* to
1067    /// allow union storage.
1068    void *TrailingReturnType;
1069
1070    /// freeArgs - reset the argument list to having zero arguments.  This is
1071    /// used in various places for error recovery.
1072    void freeArgs() {
1073      if (DeleteArgInfo) {
1074        delete[] ArgInfo;
1075        DeleteArgInfo = false;
1076      }
1077      NumArgs = 0;
1078    }
1079
1080    void destroy() {
1081      if (DeleteArgInfo)
1082        delete[] ArgInfo;
1083      if (getExceptionSpecType() == EST_Dynamic)
1084        delete[] Exceptions;
1085    }
1086
1087    /// isKNRPrototype - Return true if this is a K&R style identifier list,
1088    /// like "void foo(a,b,c)".  In a function definition, this will be followed
1089    /// by the argument type definitions.
1090    bool isKNRPrototype() const {
1091      return !hasPrototype && NumArgs != 0;
1092    }
1093
1094    SourceLocation getEllipsisLoc() const {
1095      return SourceLocation::getFromRawEncoding(EllipsisLoc);
1096    }
1097    SourceLocation getExceptionSpecLoc() const {
1098      return SourceLocation::getFromRawEncoding(ExceptionSpecLoc);
1099    }
1100
1101    /// \brief Retrieve the location of the ref-qualifier, if any.
1102    SourceLocation getRefQualifierLoc() const {
1103      return SourceLocation::getFromRawEncoding(RefQualifierLoc);
1104    }
1105
1106    /// \brief Determine whether this function declaration contains a
1107    /// ref-qualifier.
1108    bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
1109
1110    /// \brief Get the type of exception specification this function has.
1111    ExceptionSpecificationType getExceptionSpecType() const {
1112      return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
1113    }
1114  };
1115
1116  struct BlockPointerTypeInfo : TypeInfoCommon {
1117    /// For now, sema will catch these as invalid.
1118    /// The type qualifiers: const/volatile/restrict.
1119    unsigned TypeQuals : 3;
1120
1121    void destroy() {
1122    }
1123  };
1124
1125  struct MemberPointerTypeInfo : TypeInfoCommon {
1126    /// The type qualifiers: const/volatile/restrict.
1127    unsigned TypeQuals : 3;
1128    // CXXScopeSpec has a constructor, so it can't be a direct member.
1129    // So we need some pointer-aligned storage and a bit of trickery.
1130    union {
1131      void *Aligner;
1132      char Mem[sizeof(CXXScopeSpec)];
1133    } ScopeMem;
1134    CXXScopeSpec &Scope() {
1135      return *reinterpret_cast<CXXScopeSpec*>(ScopeMem.Mem);
1136    }
1137    const CXXScopeSpec &Scope() const {
1138      return *reinterpret_cast<const CXXScopeSpec*>(ScopeMem.Mem);
1139    }
1140    void destroy() {
1141      Scope().~CXXScopeSpec();
1142    }
1143  };
1144
1145  union {
1146    TypeInfoCommon        Common;
1147    PointerTypeInfo       Ptr;
1148    ReferenceTypeInfo     Ref;
1149    ArrayTypeInfo         Arr;
1150    FunctionTypeInfo      Fun;
1151    BlockPointerTypeInfo  Cls;
1152    MemberPointerTypeInfo Mem;
1153  };
1154
1155  void destroy() {
1156    switch (Kind) {
1157    default: assert(0 && "Unknown decl type!");
1158    case DeclaratorChunk::Function:      return Fun.destroy();
1159    case DeclaratorChunk::Pointer:       return Ptr.destroy();
1160    case DeclaratorChunk::BlockPointer:  return Cls.destroy();
1161    case DeclaratorChunk::Reference:     return Ref.destroy();
1162    case DeclaratorChunk::Array:         return Arr.destroy();
1163    case DeclaratorChunk::MemberPointer: return Mem.destroy();
1164    case DeclaratorChunk::Paren:         return;
1165    }
1166  }
1167
1168  /// getAttrs - If there are attributes applied to this declaratorchunk, return
1169  /// them.
1170  const AttributeList *getAttrs() const {
1171    return Common.AttrList;
1172  }
1173
1174  AttributeList *&getAttrListRef() {
1175    return Common.AttrList;
1176  }
1177
1178  /// getPointer - Return a DeclaratorChunk for a pointer.
1179  ///
1180  static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
1181                                    SourceLocation ConstQualLoc,
1182                                    SourceLocation VolatileQualLoc,
1183                                    SourceLocation RestrictQualLoc,
1184                                    const ParsedAttributes &attrs) {
1185    DeclaratorChunk I;
1186    I.Kind                = Pointer;
1187    I.Loc                 = Loc;
1188    I.Ptr.TypeQuals       = TypeQuals;
1189    I.Ptr.ConstQualLoc    = ConstQualLoc.getRawEncoding();
1190    I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding();
1191    I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding();
1192    I.Ptr.AttrList        = attrs.getList();
1193    return I;
1194  }
1195
1196  /// getReference - Return a DeclaratorChunk for a reference.
1197  ///
1198  static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
1199                                      const ParsedAttributes &attrs,
1200                                      bool lvalue) {
1201    DeclaratorChunk I;
1202    I.Kind            = Reference;
1203    I.Loc             = Loc;
1204    I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
1205    I.Ref.LValueRef   = lvalue;
1206    I.Ref.AttrList    = attrs.getList();
1207    return I;
1208  }
1209
1210  /// getArray - Return a DeclaratorChunk for an array.
1211  ///
1212  static DeclaratorChunk getArray(unsigned TypeQuals,
1213                                  const ParsedAttributes &attrs,
1214                                  bool isStatic, bool isStar, Expr *NumElts,
1215                                  SourceLocation LBLoc, SourceLocation RBLoc) {
1216    DeclaratorChunk I;
1217    I.Kind          = Array;
1218    I.Loc           = LBLoc;
1219    I.EndLoc        = RBLoc;
1220    I.Arr.AttrList  = attrs.getList();
1221    I.Arr.TypeQuals = TypeQuals;
1222    I.Arr.hasStatic = isStatic;
1223    I.Arr.isStar    = isStar;
1224    I.Arr.NumElts   = NumElts;
1225    return I;
1226  }
1227
1228  /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
1229  /// "TheDeclarator" is the declarator that this will be added to.
1230  static DeclaratorChunk getFunction(const ParsedAttributes &attrs,
1231                                     bool hasProto, bool isVariadic,
1232                                     SourceLocation EllipsisLoc,
1233                                     ParamInfo *ArgInfo, unsigned NumArgs,
1234                                     unsigned TypeQuals,
1235                                     bool RefQualifierIsLvalueRef,
1236                                     SourceLocation RefQualifierLoc,
1237                                     ExceptionSpecificationType ESpecType,
1238                                     SourceLocation ESpecLoc,
1239                                     ParsedType *Exceptions,
1240                                     SourceRange *ExceptionRanges,
1241                                     unsigned NumExceptions,
1242                                     Expr *NoexceptExpr,
1243                                     SourceLocation LPLoc, SourceLocation RPLoc,
1244                                     Declarator &TheDeclarator,
1245                                     ParsedType TrailingReturnType =
1246                                                    ParsedType());
1247
1248  /// getBlockPointer - Return a DeclaratorChunk for a block.
1249  ///
1250  static DeclaratorChunk getBlockPointer(unsigned TypeQuals, SourceLocation Loc,
1251                                         const ParsedAttributes &attrs) {
1252    DeclaratorChunk I;
1253    I.Kind          = BlockPointer;
1254    I.Loc           = Loc;
1255    I.Cls.TypeQuals = TypeQuals;
1256    I.Cls.AttrList  = attrs.getList();
1257    return I;
1258  }
1259
1260  static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS,
1261                                          unsigned TypeQuals,
1262                                          SourceLocation Loc,
1263                                          const ParsedAttributes &attrs) {
1264    DeclaratorChunk I;
1265    I.Kind          = MemberPointer;
1266    I.Loc           = Loc;
1267    I.Mem.TypeQuals = TypeQuals;
1268    I.Mem.AttrList  = attrs.getList();
1269    new (I.Mem.ScopeMem.Mem) CXXScopeSpec(SS);
1270    return I;
1271  }
1272
1273  /// getParen - Return a DeclaratorChunk for a paren.
1274  ///
1275  static DeclaratorChunk getParen(SourceLocation LParenLoc,
1276                                  SourceLocation RParenLoc) {
1277    DeclaratorChunk I;
1278    I.Kind          = Paren;
1279    I.Loc           = LParenLoc;
1280    I.EndLoc        = RParenLoc;
1281    I.Common.AttrList = 0;
1282    return I;
1283  }
1284
1285};
1286
1287/// Declarator - Information about one declarator, including the parsed type
1288/// information and the identifier.  When the declarator is fully formed, this
1289/// is turned into the appropriate Decl object.
1290///
1291/// Declarators come in two types: normal declarators and abstract declarators.
1292/// Abstract declarators are used when parsing types, and don't have an
1293/// identifier.  Normal declarators do have ID's.
1294///
1295/// Instances of this class should be a transient object that lives on the
1296/// stack, not objects that are allocated in large quantities on the heap.
1297class Declarator {
1298public:
1299  enum TheContext {
1300    FileContext,         // File scope declaration.
1301    PrototypeContext,    // Within a function prototype.
1302    KNRTypeListContext,  // K&R type definition list for formals.
1303    TypeNameContext,     // Abstract declarator for types.
1304    MemberContext,       // Struct/Union field.
1305    BlockContext,        // Declaration within a block in a function.
1306    ForContext,          // Declaration within first part of a for loop.
1307    ConditionContext,    // Condition declaration in a C++ if/switch/while/for.
1308    TemplateParamContext,// Within a template parameter list.
1309    CXXCatchContext,     // C++ catch exception-declaration
1310    BlockLiteralContext,  // Block literal declarator.
1311    TemplateTypeArgContext // Template type argument.
1312  };
1313
1314private:
1315  const DeclSpec &DS;
1316  CXXScopeSpec SS;
1317  UnqualifiedId Name;
1318  SourceRange Range;
1319
1320  /// Context - Where we are parsing this declarator.
1321  ///
1322  TheContext Context;
1323
1324  /// DeclTypeInfo - This holds each type that the declarator includes as it is
1325  /// parsed.  This is pushed from the identifier out, which means that element
1326  /// #0 will be the most closely bound to the identifier, and
1327  /// DeclTypeInfo.back() will be the least closely bound.
1328  llvm::SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
1329
1330  /// InvalidType - Set by Sema::GetTypeForDeclarator().
1331  bool InvalidType : 1;
1332
1333  /// GroupingParens - Set by Parser::ParseParenDeclarator().
1334  bool GroupingParens : 1;
1335
1336  /// AttrList - Attributes.
1337  AttributeList *AttrList;
1338
1339  /// AsmLabel - The asm label, if specified.
1340  Expr *AsmLabel;
1341
1342  /// InlineParams - This is a local array used for the first function decl
1343  /// chunk to avoid going to the heap for the common case when we have one
1344  /// function chunk in the declarator.
1345  DeclaratorChunk::ParamInfo InlineParams[16];
1346  bool InlineParamsUsed;
1347
1348  /// Extension - true if the declaration is preceded by __extension__.
1349  bool Extension : 1;
1350
1351  /// \brief If provided, the source location of the ellipsis used to describe
1352  /// this declarator as a parameter pack.
1353  SourceLocation EllipsisLoc;
1354
1355  friend struct DeclaratorChunk;
1356
1357public:
1358  Declarator(const DeclSpec &ds, TheContext C)
1359    : DS(ds), Range(ds.getSourceRange()), Context(C),
1360      InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
1361      GroupingParens(false), AttrList(0), AsmLabel(0),
1362      InlineParamsUsed(false), Extension(false) {
1363  }
1364
1365  ~Declarator() {
1366    clear();
1367  }
1368
1369  /// getDeclSpec - Return the declaration-specifier that this declarator was
1370  /// declared with.
1371  const DeclSpec &getDeclSpec() const { return DS; }
1372
1373  /// getMutableDeclSpec - Return a non-const version of the DeclSpec.  This
1374  /// should be used with extreme care: declspecs can often be shared between
1375  /// multiple declarators, so mutating the DeclSpec affects all of the
1376  /// Declarators.  This should only be done when the declspec is known to not
1377  /// be shared or when in error recovery etc.
1378  DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); }
1379
1380  /// getCXXScopeSpec - Return the C++ scope specifier (global scope or
1381  /// nested-name-specifier) that is part of the declarator-id.
1382  const CXXScopeSpec &getCXXScopeSpec() const { return SS; }
1383  CXXScopeSpec &getCXXScopeSpec() { return SS; }
1384
1385  /// \brief Retrieve the name specified by this declarator.
1386  UnqualifiedId &getName() { return Name; }
1387
1388  TheContext getContext() const { return Context; }
1389
1390  /// getSourceRange - Get the source range that spans this declarator.
1391  const SourceRange &getSourceRange() const { return Range; }
1392
1393  void SetSourceRange(SourceRange R) { Range = R; }
1394  /// SetRangeBegin - Set the start of the source range to Loc, unless it's
1395  /// invalid.
1396  void SetRangeBegin(SourceLocation Loc) {
1397    if (!Loc.isInvalid())
1398      Range.setBegin(Loc);
1399  }
1400  /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
1401  void SetRangeEnd(SourceLocation Loc) {
1402    if (!Loc.isInvalid())
1403      Range.setEnd(Loc);
1404  }
1405  /// ExtendWithDeclSpec - Extend the declarator source range to include the
1406  /// given declspec, unless its location is invalid. Adopts the range start if
1407  /// the current range start is invalid.
1408  void ExtendWithDeclSpec(const DeclSpec &DS) {
1409    const SourceRange &SR = DS.getSourceRange();
1410    if (Range.getBegin().isInvalid())
1411      Range.setBegin(SR.getBegin());
1412    if (!SR.getEnd().isInvalid())
1413      Range.setEnd(SR.getEnd());
1414  }
1415
1416  /// clear - Reset the contents of this Declarator.
1417  void clear() {
1418    SS.clear();
1419    Name.clear();
1420    Range = DS.getSourceRange();
1421
1422    for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
1423      DeclTypeInfo[i].destroy();
1424    DeclTypeInfo.clear();
1425    AttrList = 0;
1426    AsmLabel = 0;
1427    InlineParamsUsed = false;
1428  }
1429
1430  /// mayOmitIdentifier - Return true if the identifier is either optional or
1431  /// not allowed.  This is true for typenames, prototypes, and template
1432  /// parameter lists.
1433  bool mayOmitIdentifier() const {
1434    return Context == TypeNameContext || Context == PrototypeContext ||
1435           Context == TemplateParamContext || Context == CXXCatchContext ||
1436           Context == BlockLiteralContext || Context == TemplateTypeArgContext;
1437  }
1438
1439  /// mayHaveIdentifier - Return true if the identifier is either optional or
1440  /// required.  This is true for normal declarators and prototypes, but not
1441  /// typenames.
1442  bool mayHaveIdentifier() const {
1443    return Context != TypeNameContext && Context != BlockLiteralContext &&
1444           Context != TemplateTypeArgContext;
1445  }
1446
1447  /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be
1448  /// followed by a C++ direct initializer, e.g. "int x(1);".
1449  bool mayBeFollowedByCXXDirectInit() const {
1450    return !hasGroupingParens() &&
1451           (Context == FileContext  ||
1452            Context == BlockContext ||
1453            Context == ForContext);
1454  }
1455
1456  /// isPastIdentifier - Return true if we have parsed beyond the point where
1457  /// the
1458  bool isPastIdentifier() const { return Name.isValid(); }
1459
1460  /// hasName - Whether this declarator has a name, which might be an
1461  /// identifier (accessible via getIdentifier()) or some kind of
1462  /// special C++ name (constructor, destructor, etc.).
1463  bool hasName() const {
1464    return Name.getKind() != UnqualifiedId::IK_Identifier || Name.Identifier;
1465  }
1466
1467  IdentifierInfo *getIdentifier() const {
1468    if (Name.getKind() == UnqualifiedId::IK_Identifier)
1469      return Name.Identifier;
1470
1471    return 0;
1472  }
1473  SourceLocation getIdentifierLoc() const { return Name.StartLocation; }
1474
1475  /// \brief Set the name of this declarator to be the given identifier.
1476  void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) {
1477    Name.setIdentifier(Id, IdLoc);
1478  }
1479
1480  /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
1481  /// EndLoc, which should be the last token of the chunk.
1482  void AddTypeInfo(const DeclaratorChunk &TI, SourceLocation EndLoc) {
1483    DeclTypeInfo.push_back(TI);
1484    if (!EndLoc.isInvalid())
1485      SetRangeEnd(EndLoc);
1486  }
1487
1488  /// AddInnermostTypeInfo - Add a new innermost chunk to this declarator.
1489  void AddInnermostTypeInfo(const DeclaratorChunk &TI) {
1490    DeclTypeInfo.insert(DeclTypeInfo.begin(), TI);
1491  }
1492
1493  /// getNumTypeObjects() - Return the number of types applied to this
1494  /// declarator.
1495  unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); }
1496
1497  /// Return the specified TypeInfo from this declarator.  TypeInfo #0 is
1498  /// closest to the identifier.
1499  const DeclaratorChunk &getTypeObject(unsigned i) const {
1500    assert(i < DeclTypeInfo.size() && "Invalid type chunk");
1501    return DeclTypeInfo[i];
1502  }
1503  DeclaratorChunk &getTypeObject(unsigned i) {
1504    assert(i < DeclTypeInfo.size() && "Invalid type chunk");
1505    return DeclTypeInfo[i];
1506  }
1507
1508  void DropFirstTypeObject()
1509  {
1510    assert(!DeclTypeInfo.empty() && "No type chunks to drop.");
1511    DeclTypeInfo.front().destroy();
1512    DeclTypeInfo.erase(DeclTypeInfo.begin());
1513  }
1514
1515  /// isFunctionDeclarator - This method returns true if the declarator
1516  /// is a function declarator (looking through parentheses).
1517  /// If true is returned, then the reference type parameter idx is
1518  /// assigned with the index of the declaration chunk.
1519  bool isFunctionDeclarator(unsigned& idx) const {
1520    for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
1521      switch (DeclTypeInfo[i].Kind) {
1522      case DeclaratorChunk::Function:
1523        idx = i;
1524        return true;
1525      case DeclaratorChunk::Paren:
1526        continue;
1527      case DeclaratorChunk::Pointer:
1528      case DeclaratorChunk::Reference:
1529      case DeclaratorChunk::Array:
1530      case DeclaratorChunk::BlockPointer:
1531      case DeclaratorChunk::MemberPointer:
1532        return false;
1533      }
1534      llvm_unreachable("Invalid type chunk");
1535      return false;
1536    }
1537    return false;
1538  }
1539
1540  /// isFunctionDeclarator - Once this declarator is fully parsed and formed,
1541  /// this method returns true if the identifier is a function declarator
1542  /// (looking through parentheses).
1543  bool isFunctionDeclarator() const {
1544    unsigned index;
1545    return isFunctionDeclarator(index);
1546  }
1547
1548  /// getFunctionTypeInfo - Retrieves the function type info object
1549  /// (looking through parentheses).
1550  DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() {
1551    assert(isFunctionDeclarator() && "Not a function declarator!");
1552    unsigned index = 0;
1553    isFunctionDeclarator(index);
1554    return DeclTypeInfo[index].Fun;
1555  }
1556
1557  /// getFunctionTypeInfo - Retrieves the function type info object
1558  /// (looking through parentheses).
1559  const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const {
1560    return const_cast<Declarator*>(this)->getFunctionTypeInfo();
1561  }
1562
1563  /// AddAttributes - simply adds the attribute list to the Declarator.
1564  /// These examples both add 3 attributes to "var":
1565  ///  short int var __attribute__((aligned(16),common,deprecated));
1566  ///  short int x, __attribute__((aligned(16)) var
1567  ///                                 __attribute__((common,deprecated));
1568  ///
1569  /// Also extends the range of the declarator.
1570  void addAttributes(AttributeList *alist, SourceLocation LastLoc) {
1571    AttrList = addAttributeLists(AttrList, alist);
1572
1573    if (!LastLoc.isInvalid())
1574      SetRangeEnd(LastLoc);
1575  }
1576
1577  void addAttributes(const ParsedAttributes &attrs) {
1578    addAttributes(attrs.getList(), SourceLocation());
1579  }
1580
1581  const AttributeList *getAttributes() const { return AttrList; }
1582  AttributeList *getAttributes() { return AttrList; }
1583
1584  AttributeList *&getAttrListRef() { return AttrList; }
1585
1586  /// hasAttributes - do we contain any attributes?
1587  bool hasAttributes() const {
1588    if (getAttributes() || getDeclSpec().hasAttributes()) return true;
1589    for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
1590      if (getTypeObject(i).getAttrs())
1591        return true;
1592    return false;
1593  }
1594
1595  void setAsmLabel(Expr *E) { AsmLabel = E; }
1596  Expr *getAsmLabel() const { return AsmLabel; }
1597
1598  void setExtension(bool Val = true) { Extension = Val; }
1599  bool getExtension() const { return Extension; }
1600
1601  void setInvalidType(bool Val = true) { InvalidType = Val; }
1602  bool isInvalidType() const {
1603    return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error;
1604  }
1605
1606  void setGroupingParens(bool flag) { GroupingParens = flag; }
1607  bool hasGroupingParens() const { return GroupingParens; }
1608
1609  bool hasEllipsis() const { return EllipsisLoc.isValid(); }
1610  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
1611  void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; }
1612};
1613
1614/// FieldDeclarator - This little struct is used to capture information about
1615/// structure field declarators, which is basically just a bitfield size.
1616struct FieldDeclarator {
1617  Declarator D;
1618  Expr *BitfieldSize;
1619  explicit FieldDeclarator(DeclSpec &DS) : D(DS, Declarator::MemberContext) {
1620    BitfieldSize = 0;
1621  }
1622};
1623
1624/// VirtSpecifiers - Represents a C++0x virt-specifier-seq.
1625class VirtSpecifiers {
1626public:
1627  enum Specifier {
1628    VS_None = 0,
1629    VS_Override = 1,
1630    VS_Final = 2,
1631    VS_New = 4
1632  };
1633
1634  VirtSpecifiers() : Specifiers(0) { }
1635
1636  bool SetSpecifier(Specifier VS, SourceLocation Loc,
1637                    const char *&PrevSpec);
1638
1639  bool isOverrideSpecified() const { return Specifiers & VS_Override; }
1640  SourceLocation getOverrideLoc() const { return VS_overrideLoc; }
1641
1642  bool isFinalSpecified() const { return Specifiers & VS_Final; }
1643  SourceLocation getFinalLoc() const { return VS_finalLoc; }
1644
1645  bool isNewSpecified() const { return Specifiers & VS_New; }
1646  SourceLocation getNewLoc() const { return VS_newLoc; }
1647
1648  void clear() { Specifiers = 0; }
1649
1650  static const char *getSpecifierName(Specifier VS);
1651
1652  SourceLocation getLastLocation() const { return LastLocation; }
1653
1654private:
1655  unsigned Specifiers;
1656
1657  SourceLocation VS_overrideLoc, VS_finalLoc, VS_newLoc;
1658  SourceLocation LastLocation;
1659};
1660
1661/// ClassVirtSpecifiers - Represents a C++0x class-virt-specifier-seq.
1662class ClassVirtSpecifiers {
1663public:
1664  enum Specifier {
1665    CVS_None = 0,
1666    CVS_Final = 1,
1667    CVS_Explicit = 2
1668  };
1669
1670  ClassVirtSpecifiers() : Specifiers(0) { }
1671
1672  bool SetSpecifier(Specifier CVS, SourceLocation Loc,
1673                    const char *&PrevSpec);
1674
1675  bool isFinalSpecified() const { return Specifiers & CVS_Final; }
1676  SourceLocation getFinalLoc() const { return CVS_finalLoc; }
1677
1678  bool isExplicitSpecified() const { return Specifiers & CVS_Explicit; }
1679  SourceLocation getExplicitLoc() const { return CVS_explicitLoc; }
1680
1681  static const char *getSpecifierName(Specifier CVS);
1682
1683private:
1684  unsigned Specifiers;
1685
1686  SourceLocation CVS_finalLoc, CVS_explicitLoc;
1687};
1688
1689} // end namespace clang
1690
1691#endif
1692