Parser.h revision e1fca502e7f1349e9b4520a4ca9a02413bcf2b14
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Parser.h - C Language Parser ---------------------------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Parser interface.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_PARSE_PARSER_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_PARSE_PARSER_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17ad2b804faf29042e6c4e331d0987f103f1e2fd31John McCall#include "clang/Basic/Specifiers.h"
1825a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis#include "clang/Basic/DelayedCleanupPool.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Lex/Preprocessor.h"
20f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor#include "clang/Lex/CodeCompletionHandler.h"
21f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "clang/Sema/Sema.h"
2219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h"
23f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "llvm/Support/PrettyStackTrace.h"
244726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek#include "llvm/ADT/OwningPtr.h"
25eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski#include "llvm/ADT/SmallVector.h"
264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis#include <stack>
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
29fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar  class PragmaHandler;
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Scope;
312b5289b6fd7e3d9899868410a498c081c9595662John McCall  class DeclGroupRef;
323cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  class DiagnosticBuilder;
330102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  class Parser;
344726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  class PragmaUnusedHandler;
3508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  class ColonProtectionRAIIObject;
360fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  class InMessageExpressionRAIIObject;
3728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  class PoisonSEHIdentifiersRAIIObject;
380a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  class VersionTuple;
39a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
400102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// PrettyStackTraceParserEntry - If a crash happens while the parser is active,
410102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// an entry is printed for it.
420102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerclass PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry {
430102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  const Parser &P;
440102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerpublic:
450102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  PrettyStackTraceParserEntry(const Parser &p) : P(p) {}
468cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  virtual void print(raw_ostream &OS) const;
470102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner};
481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// PrecedenceLevels - These are precedences for the binary/ternary
506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// operators in the C99 grammar.  These have been named to relate
516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// with the C99 grammar productions.  Low precedences numbers bind
526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// more weakly than high numbers.
536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregornamespace prec {
546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  enum Level {
556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Unknown         = 0,    // Not binary operator.
566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Comma           = 1,    // ,
576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Assignment      = 2,    // =, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |=
586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Conditional     = 3,    // ?
596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    LogicalOr       = 4,    // ||
606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    LogicalAnd      = 5,    // &&
616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    InclusiveOr     = 6,    // |
626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    ExclusiveOr     = 7,    // ^
636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    And             = 8,    // &
646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Equality        = 9,    // ==, !=
656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Relational      = 10,   //  >=, <=, >, <
666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Shift           = 11,   // <<, >>
676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Additive        = 12,   // -, +
686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Multiplicative  = 13,   // *, /, %
696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    PointerToMember = 14    // .*, ->*
706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  };
716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor}
721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages.  After
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read.
765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
77f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregorclass Parser : public CodeCompletionHandler {
784726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  friend class PragmaUnusedHandler;
7908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  friend class ColonProtectionRAIIObject;
800fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  friend class InMessageExpressionRAIIObject;
8128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  friend class PoisonSEHIdentifiersRAIIObject;
8236d36806f1972f7ec1d2a3f59155187278c56508Argyrios Kyrtzidis  friend class ParenBraceBracketBalancer;
831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Preprocessor &PP;
851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8697d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher  /// Tok - The current token we are peeking ahead.  All parsing methods assume
875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// that this is valid.
88d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner  Token Tok;
891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
904b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // PrevTokLocation - The location of the token we previously
914b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // consumed. This token is used for diagnostics where we expected to
924b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // see a token following another token (e.g., the ';' at the end of
934b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // a statement).
944b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  SourceLocation PrevTokLocation;
954b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned short ParenCount, BracketCount, BraceCount;
975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Actions - These are the callbacks we invoke as we parse various constructs
99a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// in the file.
100f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  Sema &Actions;
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine &Diags;
1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1049e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  /// ScopeCache - Cache scopes to reduce malloc traffic.
1059e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  enum { ScopeCacheSize = 16 };
1069e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  unsigned NumCachedScopes;
1079e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  Scope *ScopeCache[ScopeCacheSize];
108662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar
10928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// Identifiers used for SEH handling in Borland. These are only
11028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  /// allowed in particular circumstances
111a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  // __except block
112a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  IdentifierInfo *Ident__exception_code,
113a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                 *Ident___exception_code,
114a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                 *Ident_GetExceptionCode;
115a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  // __except filter expression
116a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  IdentifierInfo *Ident__exception_info,
117a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                 *Ident___exception_info,
118a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                 *Ident_GetExceptionInfo;
119a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  // __finally
120a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  IdentifierInfo *Ident__abnormal_termination,
121a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                 *Ident___abnormal_termination,
122a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                 *Ident_AbnormalTermination;
12328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
124b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor  /// Contextual keywords for Microsoft extensions.
125b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor  IdentifierInfo *Ident__except;
126a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
127662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  /// Ident_super - IdentifierInfo for "super", to support fast
128662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  /// comparison.
129662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  IdentifierInfo *Ident_super;
13082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// Ident_vector and Ident_pixel - cached IdentifierInfo's for
13182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// "vector" and "pixel" fast comparison.  Only present if
13282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// AltiVec enabled.
13382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  IdentifierInfo *Ident_vector;
13482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  IdentifierInfo *Ident_pixel;
135662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar
136e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor  /// Objective-C contextual keywords.
137e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor  mutable IdentifierInfo *Ident_instancetype;
138a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1390a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// \brief Identifier for "introduced".
1400a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  IdentifierInfo *Ident_introduced;
1410a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
1420a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// \brief Identifier for "deprecated".
1430a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  IdentifierInfo *Ident_deprecated;
1440a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
1450a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// \brief Identifier for "obsoleted".
1460a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  IdentifierInfo *Ident_obsoleted;
1470a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
148b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor  /// \brief Identifier for "unavailable".
149b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor  IdentifierInfo *Ident_unavailable;
150b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor
151a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// C++0x contextual keywords.
1527eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson  mutable IdentifierInfo *Ident_final;
1537eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson  mutable IdentifierInfo *Ident_override;
1541f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
155cbb98edd530787c2ac019e437e7c599df8004ba7Daniel Dunbar  llvm::OwningPtr<PragmaHandler> AlignHandler;
156aa8b0d19244a6e7e8e5798fcc6aef003c274d3e0Eli Friedman  llvm::OwningPtr<PragmaHandler> GCCVisibilityHandler;
157861800c676004eabed5927f0552620d06c80a40aDaniel Dunbar  llvm::OwningPtr<PragmaHandler> OptionsHandler;
1584726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  llvm::OwningPtr<PragmaHandler> PackHandler;
15962c9258f4a71569a66d805fc7776526a2c76b34eFariborz Jahanian  llvm::OwningPtr<PragmaHandler> MSStructHandler;
1604726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  llvm::OwningPtr<PragmaHandler> UnusedHandler;
1619991479ad5dde617168cc1e4b18425cdbbfd9fa9Eli Friedman  llvm::OwningPtr<PragmaHandler> WeakHandler;
162321b8179afaf803dcc56b2a19f7b0891a03c92c8Peter Collingbourne  llvm::OwningPtr<PragmaHandler> FPContractHandler;
163f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne  llvm::OwningPtr<PragmaHandler> OpenCLExtensionHandler;
1641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// Whether the '>' token acts as an operator or not. This will be
16655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// true except when we are parsing an expression within a C++
16755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// template argument list, where the '>' closes the template
16855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// argument list.
16955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  bool GreaterThanIsOperator;
170a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
17108d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// ColonIsSacred - When this is false, we aggressively try to recover from
17208d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// code like "foo : bar" as if it were a typo for "foo :: bar".  This is not
17308d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// safe in case statements and a few other things.  This is managed by the
17408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// ColonProtectionRAIIObject RAII object.
17508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  bool ColonIsSacred;
17655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
177a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// \brief When true, we are directly inside an Objective-C messsage
1780fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// send expression.
1790fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  ///
1800fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// This is managed by the \c InMessageExpressionRAIIObject class, and
1810fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// should not be set directly.
1820fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  bool InMessageExpression;
183a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
184c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor  /// The "depth" of the template parameters currently being parsed.
185c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor  unsigned TemplateParameterDepth;
186a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1878113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek  /// Factory object for creating AttributeList objects.
1880b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  AttributeFactory AttrFactory;
1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19025a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// \brief Gathers and cleans up objects when parsing of a top-level
19125a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// declaration is finished.
19225a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  DelayedCleanupPool TopLevelDeclCleanupPool;
19325a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis
194b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor  IdentifierInfo *getSEHExceptKeyword();
195a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
197f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  Parser(Preprocessor &PP, Sema &Actions);
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ~Parser();
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const LangOptions &getLang() const { return PP.getLangOptions(); }
201444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
2020102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  Preprocessor &getPreprocessor() const { return PP; }
203f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  Sema &getActions() const { return Actions; }
2041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2050102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  const Token &getCurToken() const { return Tok; }
20623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  Scope *getCurScope() const { return Actions.getCurScope(); }
207a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
208a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  Decl  *getObjCDeclContext() const { return Actions.getObjCDeclContext(); }
209a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Type forwarding.  All of these are statically 'void*', but they may all be
2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // different actual classes based on the actions in place.
2122b5289b6fd7e3d9899868410a498c081c9595662John McCall  typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
2132b5289b6fd7e3d9899868410a498c081c9595662John McCall  typedef OpaquePtr<TemplateName> TemplateTy;
2147ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
215686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists;
216c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor
2179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::ExprResult        ExprResult;
2189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::StmtResult        StmtResult;
2199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::BaseResult        BaseResult;
2209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::MemInitResult     MemInitResult;
2219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::TypeResult        TypeResult;
22215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
2239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef Expr *ExprArg;
2249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef ASTMultiPtr<Stmt*> MultiStmtArg;
225f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::FullExprArg FullExprArg;
2261d922960e083906a586609ac6978678147250177Sebastian Redl
22760d7b3a319d84d688752be3870615ac0f111fb16John McCall  /// Adorns a ExprResult with Actions to make it an ExprResult
22860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Owned(ExprResult res) {
22960d7b3a319d84d688752be3870615ac0f111fb16John McCall    return ExprResult(res);
23061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
23160d7b3a319d84d688752be3870615ac0f111fb16John McCall  /// Adorns a StmtResult with Actions to make it an StmtResult
23260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Owned(StmtResult res) {
23360d7b3a319d84d688752be3870615ac0f111fb16John McCall    return StmtResult(res);
23461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
23561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
23660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ExprError() { return ExprResult(true); }
23760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult StmtError() { return StmtResult(true); }
238d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor
23960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); }
24060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); }
24161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
24260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ExprEmpty() { return ExprResult(false); }
2435ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis
2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Parsing methods.
2451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseTranslationUnit - All in one method that initializes parses, and
2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// shuts down the parser.
2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseTranslationUnit();
2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Initialize - Warm up the parser.
2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Initialize();
2531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
2551f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff  /// the EOF was encountered.
256682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
2571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2583fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  DeclGroupPtrTy FinishPendingObjCActions();
25963e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Low-Level token peeking and consumption methods.
2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //
2641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenParen - Return true if the cur token is '(' or ')'.
2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenParen() const {
2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren;
2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBracket - Return true if the cur token is '[' or ']'.
2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBracket() const {
2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square;
2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBrace - Return true if the cur token is '{' or '}'.
2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBrace() const {
2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace;
2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenStringLiteral - True if this token is a string-literal.
2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenStringLiteral() const {
2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::string_literal ||
2825cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor           Tok.getKind() == tok::wide_string_literal ||
2835cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor           Tok.getKind() == tok::utf8_string_literal ||
2845cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor           Tok.getKind() == tok::utf16_string_literal ||
2855cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor           Tok.getKind() == tok::utf32_string_literal;
2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
287eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
288a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis  /// \brief Returns true if the current token is a '=' or '==' and
289a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis  /// false otherwise. If it's '==', we assume that it's a typo and we emit
290a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis  /// DiagID and a fixit hint to turn '==' -> '='.
291a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis  bool isTokenEqualOrMistypedEqualEqual(unsigned DiagID);
292a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis
2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeToken - Consume the current 'peek token' and lex the next one.
294d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu  /// This does not work with all kinds of tokens: strings and specific other
2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tokens must be consumed with custom methods below.  This returns the
2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// location of the consumed token.
2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeToken() {
2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() &&
2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           !isTokenBrace() &&
3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should consume special tokens with Consume*Token");
3017d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis
3027d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    if (Tok.is(tok::code_completion))
3037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return handleUnexpectedCodeCompletionToken();
3047d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis
3054b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3074b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// current token type.  This should only be used in cases where the type of
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the token really isn't known, e.g. in error recovery.
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeAnyToken() {
3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isTokenParen())
3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeParen();
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBracket())
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBracket();
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBrace())
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBrace();
320d62701bc5321049353017e9abf1963edd57646aaSteve Naroff    else if (isTokenStringLiteral())
321d62701bc5321049353017e9abf1963edd57646aaSteve Naroff      return ConsumeStringToken();
3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeToken();
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeParen - This consume method keeps the paren count up-to-date.
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeParen() {
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenParen() && "wrong consume method");
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_paren)
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++ParenCount;
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (ParenCount)
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --ParenCount;       // Don't let unbalanced )'s drive the count negative.
3344b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3364b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBracket - This consume method keeps the bracket count up-to-date.
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBracket() {
3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBracket() && "wrong consume method");
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_square)
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BracketCount;
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BracketCount)
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BracketCount;     // Don't let unbalanced ]'s drive the count negative.
3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3484b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3504b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBrace - This consume method keeps the brace count up-to-date.
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBrace() {
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBrace() && "wrong consume method");
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_brace)
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BraceCount;
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BraceCount)
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BraceCount;     // Don't let unbalanced }'s drive the count negative.
3611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3624b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3644b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeStringToken - Consume the current 'peek token', lexing a new one
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// and returning the token kind.  This method is specific to strings, as it
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// handles string literal concatenation, as per C99 5.1.1.2, translation
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// phase #6.
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeStringToken() {
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenStringLiteral() &&
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should only consume string literals with this method");
3744b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3764b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
379dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// \brief Consume the current code-completion token.
380dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  ///
381dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// This routine should be called to consume the code-completion token once
382dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// a code-completion action has already been invoked.
383dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  SourceLocation ConsumeCodeCompletionToken() {
384dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    assert(Tok.is(tok::code_completion));
385dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    PrevTokLocation = Tok.getLocation();
386dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    PP.Lex(Tok);
387a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    return PrevTokLocation;
388dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  }
389a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
3907d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  ///\ brief When we are consuming a code-completion token without having
391dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// matched specific position in the grammar, provide code-completion results
392dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// based on context.
3937d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  ///
3947d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  /// \returns the source location of the code-completion token.
3957d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  SourceLocation handleUnexpectedCodeCompletionToken();
3967d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis
3977d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  /// \brief Abruptly cut off parsing; mainly used when we have reached the
3987d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  /// code-completion point.
3997d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  void cutOffParsing() {
4007d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    PP.setCodeCompletionReached();
4017d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    // Cut off parsing by acting as if we reached the end-of-file.
4027d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    Tok.setKind(tok::eof);
4037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  }
404dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor
4052fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis  /// \brief Clear and free the cached objc methods.
4062fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis  void clearLateParsedObjCMethods();
4072fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis
408b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis  /// \brief Handle the annotation token produced for #pragma unused(...)
409b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis  void HandlePragmaUnused();
410b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis
4116b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// GetLookAheadToken - This peeks ahead N tokens and returns that token
4126b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// without consuming any tokens.  LookAhead(0) returns 'Tok', LookAhead(1)
4136b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// returns the token after Tok, etc.
4146b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
4156b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// Note that this differs from the Preprocessor's LookAhead method, because
4166b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// the Parser always has one token lexed that the preprocessor doesn't.
4176b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
41803db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis  const Token &GetLookAheadToken(unsigned N) {
4196b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    if (N == 0 || Tok.is(tok::eof)) return Tok;
4206b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    return PP.LookAhead(N-1);
4216b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  }
422f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis
423f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// NextToken - This peeks ahead one token and returns it without
424f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// consuming it.
425f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  const Token &NextToken() {
42603db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis    return PP.LookAhead(0);
427f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  }
4285404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
429d3891e9fb7eb25436e5c537189030bed0d5a1dcfDouglas Gregor  class BalancedDelimiterTracker;
430d3891e9fb7eb25436e5c537189030bed0d5a1dcfDouglas Gregor
431a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// \brief Tracks information about the current nesting depth of
4324a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  /// opening delimiters of each kind.
4334a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  class DelimiterTracker {
4344a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  private:
4354a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    friend class Parser;
436d3891e9fb7eb25436e5c537189030bed0d5a1dcfDouglas Gregor    friend class BalancedDelimiterTracker;
4374a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4384a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    unsigned Paren, Brace, Square, Less, LLLess;
4394a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    unsigned& get(tok::TokenKind t) {
4404a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      switch (t) {
4414a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      default: llvm_unreachable("Unexpected balanced token");
4424a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_brace:  return Brace;
4434a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_paren:  return Paren;
4444a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_square: return Square;
4454a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::less:  return Less;
4464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::lesslessless:  return LLLess;
4474a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      }
4484a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4494a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4504a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    void push(tok::TokenKind t) {
4514a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      get(t)++;
4524a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4534a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4544a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    void pop(tok::TokenKind t) {
4554a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      get(t)--;
4564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4574a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4584a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    unsigned getDepth(tok::TokenKind t) {
4594a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      return get(t);
4604a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4614a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  public:
4634a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    DelimiterTracker() : Paren(0), Brace(0), Square(0), Less(0), LLLess(0) { }
4644a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  };
4654a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4664a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  /// \brief RAII class that helps handle the parsing of an open/close delimiter
4674a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  /// pair, such as braces { ... } or parentheses ( ... ).
4684a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  class BalancedDelimiterTracker {
4694a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    tok::TokenKind Kind, Close;
4704a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    Parser& P;
4714a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    bool Cleanup;
4724a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    const unsigned MaxDepth;
4734a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    SourceLocation LOpen, LClose;
474a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
4754a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    void assignClosingDelimiter() {
4764a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      switch (Kind) {
4774a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      default: llvm_unreachable("Unexpected balanced token");
4784a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_brace:  Close = tok::r_brace; break;
4794a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_paren:  Close = tok::r_paren; break;
4804a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_square: Close = tok::r_square; break;
4814a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::less:  Close = tok::greater; break;
4824a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::lesslessless:  Close = tok::greatergreatergreater; break;
4834a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      }
4844a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4854a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4864a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  public:
487a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    BalancedDelimiterTracker(Parser& p, tok::TokenKind k)
4884a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      : Kind(k), P(p), Cleanup(false), MaxDepth(256) {
4894a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      assignClosingDelimiter();
4904a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4914a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4924a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    ~BalancedDelimiterTracker() {
4934a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      if (Cleanup)
4944a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor        P.QuantityTracker.pop(Kind);
4954a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4964a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4974a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    SourceLocation getOpenLocation() const { return LOpen; }
4984a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    SourceLocation getCloseLocation() const { return LClose; }
4994a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    SourceRange getRange() const { return SourceRange(LOpen, LClose); }
5004a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
5014a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    bool consumeOpen();
502a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    bool expectAndConsume(unsigned DiagID,
503a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                          const char *Msg = "",
5044a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                          tok::TokenKind SkipToTok = tok::unknown);
5054a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    bool consumeClose();
5063896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    void skipToEnd();
5074a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  };
5084a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
5094a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  DelimiterTracker QuantityTracker;
5104a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
511b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  /// getTypeAnnotation - Read a parsed type out of an annotation token.
512b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  static ParsedType getTypeAnnotation(Token &Tok) {
513b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue());
514b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
515b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
516b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  static void setTypeAnnotation(Token &Tok, ParsedType T) {
517b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    Tok.setAnnotationValue(T.getAsOpaquePtr());
518b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
519a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5205ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  /// \brief Read an already-translated primary expression out of an annotation
5215ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  /// token.
5225ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  static ExprResult getExprAnnotation(Token &Tok) {
5235ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor    if (Tok.getAnnotationValue())
5245ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor      return ExprResult((Expr *)Tok.getAnnotationValue());
525a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5265ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor    return ExprResult(true);
5275ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  }
528a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5295ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  /// \brief Set the primary expression corresponding to the given annotation
5305ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  /// token.
5315ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  static void setExprAnnotation(Token &Tok, ExprResult ER) {
5325ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor    if (ER.isInvalid())
5335ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor      Tok.setAnnotationValue(0);
5345ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor    else
5355ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor      Tok.setAnnotationValue(ER.get());
5365ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  }
537b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
538fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain  // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to
539fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain  // find a type name by attempting typo correction.
540fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain  bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false,
541fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain                                   bool NeedType = false);
542495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor  bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
543eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
54482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens,
54582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// replacing them with the non-context-sensitive keywords.  This returns
54682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// true if the token was replaced.
54782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
548b3a4e432c90be98c6d918087750397e86d030368Chris Lattner                       const char *&PrevSpec, unsigned &DiagID,
549b3a4e432c90be98c6d918087750397e86d030368Chris Lattner                       bool &isInvalid) {
5501b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner    if (!getLang().AltiVec ||
5511b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner        (Tok.getIdentifierInfo() != Ident_vector &&
5521b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner         Tok.getIdentifierInfo() != Ident_pixel))
5531b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner      return false;
554a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5551b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner    return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
55682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
55782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
55882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector
55982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// identifier token, replacing it with the non-context-sensitive __vector.
56082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// This returns true if the token was replaced.
56182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool TryAltiVecVectorToken() {
562b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    if (!getLang().AltiVec ||
563b3a4e432c90be98c6d918087750397e86d030368Chris Lattner        Tok.getIdentifierInfo() != Ident_vector) return false;
5641b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner    return TryAltiVecVectorTokenOutOfLine();
56582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
566a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5671b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner  bool TryAltiVecVectorTokenOutOfLine();
5681b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner  bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
5691b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner                                const char *&PrevSpec, unsigned &DiagID,
5701b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner                                bool &isInvalid);
57125a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis
57225a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// \brief Get the TemplateIdAnnotation from the token and put it in the
57325a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// cleanup pool so that it gets destroyed when parsing the current top level
57425a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// declaration is finished.
57525a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok);
57625a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis
5775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// TentativeParsingAction - An object that is used as a kind of "tentative
5785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// parsing transaction". It gets instantiated to mark the token position and
5795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// after the token consumption is done, Commit() or Revert() is called to
5805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// either "commit the consumed tokens" or revert to the previously marked
5815404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// token position. Example:
5825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
583314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  ///   TentativeParsingAction TPA(*this);
5845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ConsumeToken();
5855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ....
5865404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   TPA.Revert();
5875404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
5885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  class TentativeParsingAction {
5895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Parser &P;
5905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Token PrevTok;
5915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    bool isActive;
5925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
5935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  public:
5945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    explicit TentativeParsingAction(Parser& p) : P(p) {
5955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      PrevTok = P.Tok;
5965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.EnableBacktrackAtThisPos();
5975404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = true;
5985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
5995404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Commit() {
6005404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
6015404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.CommitBacktrackedTokens();
6025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
6035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
6045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Revert() {
6055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
6065404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.Backtrack();
6075404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.Tok = PrevTok;
6085404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
6095404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
6105404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    ~TentativeParsingAction() {
6115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(!isActive && "Forgot to call Commit or Revert!");
6125404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
6135404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  };
6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6159735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  /// ObjCDeclContextSwitch - An object used to switch context from
6169735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  /// an objective-c decl context to its enclosing decl context and
6179735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  /// back.
6189735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  class ObjCDeclContextSwitch {
6199735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    Parser &P;
6209735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    Decl *DC;
6219735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  public:
622a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    explicit ObjCDeclContextSwitch(Parser &p) : P(p),
6239735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian               DC(p.getObjCDeclContext()) {
6249735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian      if (DC)
625458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis        P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC));
6269735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    }
6279735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    ~ObjCDeclContextSwitch() {
6289735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian      if (DC)
629458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis        P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC));
6309735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    }
6319735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  };
6321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// input.  If so, it is consumed and false is returned.
6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If the input is malformed, this emits the specified diagnostic.  Next, if
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipToTok is specified, it calls SkipUntil(SkipToTok).  Finally, true is
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// returned.
6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag,
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        const char *DiagMsg = "",
6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        tok::TokenKind SkipToTok = tok::unknown);
6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6439ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// \brief The parser expects a semicolon and, if present, will consume it.
6449ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  ///
6459ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// If the next token is not a semicolon, this emits the specified diagnostic,
6469ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior
6479ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// to the semicolon, consumes that extra token.
6489ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  bool ExpectAndConsumeSemi(unsigned DiagID);
649a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Scope manipulation
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6538935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// ParseScope - Introduces a new scope for parsing. The kind of
6548935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// scope is determined by ScopeFlags. Objects of this type should
6558935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// be created on the stack to coincide with the position where the
6568935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// parser enters the new scope, and this object's constructor will
6578935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// create that new scope. Similarly, once the object is destroyed
6588935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// the parser will exit the scope.
6598935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  class ParseScope {
6608935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    Parser *Self;
6618935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope(const ParseScope&); // do not implement
6628935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope& operator=(const ParseScope&); // do not implement
6638935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
6648935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  public:
6658935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ParseScope - Construct a new object to manage a scope in the
6668935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // parser Self where the new Scope is created with the flags
6678935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ScopeFlags, but only when ManageScope is true (the default). If
6688935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ManageScope is false, this object does nothing.
6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true)
6708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      : Self(Self) {
6718935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (ManageScope)
6728935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->EnterScope(ScopeFlags);
6738935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      else
6748935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        this->Self = 0;
6758935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
6768935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
6778935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // Exit - Exit the scope associated with this object now, rather
6788935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // than waiting until the object is destroyed.
6798935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    void Exit() {
6808935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (Self) {
6818935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->ExitScope();
6828935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self = 0;
6838935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      }
6848935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
6858935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
6868935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ~ParseScope() {
6878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      Exit();
6888935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
6898935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  };
6908935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EnterScope - Start a new scope.
6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EnterScope(unsigned ScopeFlags);
6931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExitScope - Pop a scope off the scope stack.
6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ExitScope();
6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6977a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// \brief RAII object used to modify the scope flags for the current scope.
6987a614d8380297fcd2bc23986241905d97222948cRichard Smith  class ParseScopeFlags {
6997a614d8380297fcd2bc23986241905d97222948cRichard Smith    Scope *CurScope;
7007a614d8380297fcd2bc23986241905d97222948cRichard Smith    unsigned OldFlags;
7017a614d8380297fcd2bc23986241905d97222948cRichard Smith    ParseScopeFlags(const ParseScopeFlags &); // do not implement
7027a614d8380297fcd2bc23986241905d97222948cRichard Smith    void operator=(const ParseScopeFlags &); // do not implement
7037a614d8380297fcd2bc23986241905d97222948cRichard Smith
7047a614d8380297fcd2bc23986241905d97222948cRichard Smith  public:
7057a614d8380297fcd2bc23986241905d97222948cRichard Smith    ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true);
7067a614d8380297fcd2bc23986241905d97222948cRichard Smith    ~ParseScopeFlags();
7077a614d8380297fcd2bc23986241905d97222948cRichard Smith  };
7087a614d8380297fcd2bc23986241905d97222948cRichard Smith
7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Diagnostic Emission and Error recovery.
71115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
7126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic:
7133cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
7143cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
71515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
7166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate:
7171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SuggestParentheses(SourceLocation Loc, unsigned DK,
7184b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor                          SourceRange ParenRange);
719d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  void CheckNestedObjCContexts(SourceLocation AtLoc);
7204b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipUntil - Read tokens until we get to the specified token, then consume
72282c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff  /// it (unless DontConsume is true).  Because we cannot guarantee that the
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// token will ever occur, this skips to the next token, or to some likely
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// good stopping point.  If StopAtSemi is true, skipping will stop at a ';'
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// character.
7261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If SkipUntil finds the specified token, it returns true, otherwise it
7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returns false.
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
7303437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool DontConsume = false, bool StopAtCodeCompletion = false) {
7313437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis    return SkipUntil(&T, 1, StopAtSemi, DontConsume, StopAtCodeCompletion);
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
7343437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool DontConsume = false, bool StopAtCodeCompletion = false) {
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    tok::TokenKind TokArray[] = {T1, T2};
7363437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis    return SkipUntil(TokArray, 2, StopAtSemi, DontConsume,StopAtCodeCompletion);
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
7393437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool StopAtSemi = true, bool DontConsume = false,
7403437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool StopAtCodeCompletion = false);
7417ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
7434cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // Lexing and parsing of C++ inline methods.
7444cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
745d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  struct ParsingClass;
746d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
747d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// [class.mem]p1: "... the class is regarded as complete within
748d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - function bodies
749d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - default arguments
750d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - exception-specifications (TODO: C++0x)
7517a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// - and brace-or-equal-initializers for non-static data members
7527a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// (including such things in nested classes)."
753d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// LateParsedDeclarations build the tree of those elements so they can
754d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// be parsed after parsing the top-level class.
755d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  class LateParsedDeclaration {
756d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  public:
757d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual ~LateParsedDeclaration();
758d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
759d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDeclarations();
7607a614d8380297fcd2bc23986241905d97222948cRichard Smith    virtual void ParseLexedMemberInitializers();
761d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDefs();
762eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    virtual void ParseLexedAttributes();
763d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  };
764d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
765d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// Inner node of the LateParsedDeclaration tree that parses
766d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// all its members recursively.
767d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  class LateParsedClass : public LateParsedDeclaration {
768d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  public:
769d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    LateParsedClass(Parser *P, ParsingClass *C);
770d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual ~LateParsedClass();
771d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
772d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDeclarations();
7737a614d8380297fcd2bc23986241905d97222948cRichard Smith    virtual void ParseLexedMemberInitializers();
774d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDefs();
775eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    virtual void ParseLexedAttributes();
776d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
777d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  private:
778d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    Parser *Self;
779d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    ParsingClass *Class;
780d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  };
781d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
782a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// Contains the lexed tokens of an attribute with arguments that
783a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// may reference member variables and so need to be parsed at the
784a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// end of the class declaration after parsing all other member
785eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  /// member declarations.
786eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  /// FIXME: Perhaps we should change the name of LateParsedDeclaration to
787eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  /// LateParsedTokens.
788eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  struct LateParsedAttribute : public LateParsedDeclaration {
789eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    Parser *Self;
790eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    CachedTokens Toks;
791eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    IdentifierInfo &AttrName;
792eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    SourceLocation AttrNameLoc;
793eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    Decl *D;
794eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
795a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name,
796eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                                 SourceLocation Loc)
797eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski      : Self(P), AttrName(Name), AttrNameLoc(Loc), D(0)  {}
798eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
799eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    virtual void ParseLexedAttributes();
800eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
801eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    void setDecl(Decl *Dec) { D = Dec; }
802eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  };
803eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
804eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  /// A list of late parsed attributes.  Used by ParseGNUAttributes.
805eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  typedef llvm::SmallVector<LateParsedAttribute*, 2> LateParsedAttrList;
806eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
807eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
808d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// Contains the lexed tokens of a member function definition
809d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// which needs to be parsed at the end of the class declaration
810d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// after parsing all other member declarations.
811d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  struct LexedMethod : public LateParsedDeclaration {
812d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    Parser *Self;
813d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *D;
81472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    CachedTokens Toks;
815d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor
816d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// \brief Whether this member function had an associated template
817d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// scope. When true, D is a template declaration.
818d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// othewise, it is a member function declaration.
819d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    bool TemplateScope;
820d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor
821d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    explicit LexedMethod(Parser* P, Decl *MD)
822d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor      : Self(P), D(MD), TemplateScope(false) {}
823d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
824d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDefs();
8254cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  };
8264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
82772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// LateParsedDefaultArgument - Keeps track of a parameter that may
82872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// have a default argument that cannot be parsed yet because it
82972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// occurs within a member function declaration inside the class
83072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// (C++ [class.mem]p2).
83172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  struct LateParsedDefaultArgument {
832d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    explicit LateParsedDefaultArgument(Decl *P,
83372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor                                       CachedTokens *Toks = 0)
83472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor      : Param(P), Toks(Toks) { }
83572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
83672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Param - The parameter declaration for this parameter.
837d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Param;
83872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
83972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Toks - The sequence of tokens that comprises the default
84072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// argument expression, not including the '=' or the terminating
84172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// ')' or ','. This will be NULL for parameters that have no
84272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// default argument.
84372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    CachedTokens *Toks;
84472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
8451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
84672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// LateParsedMethodDeclaration - A method declaration inside a class that
84772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// contains at least one entity whose parsing needs to be delayed
84872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// until the class itself is completely-defined, such as a default
84972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// argument (C++ [class.mem]p2).
850d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  struct LateParsedMethodDeclaration : public LateParsedDeclaration {
851d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    explicit LateParsedMethodDeclaration(Parser *P, Decl *M)
852d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor      : Self(P), Method(M), TemplateScope(false) { }
853d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
854d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDeclarations();
855d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
856d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    Parser* Self;
85772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
85872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Method - The method declaration.
859d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Method;
86072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
861d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// \brief Whether this member function had an associated template
862d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// scope. When true, D is a template declaration.
863d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// othewise, it is a member function declaration.
864d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    bool TemplateScope;
8651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
86672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// DefaultArgs - Contains the parameters of the function and
86772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// their default arguments. At least one of the parameters will
86872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// have a default argument, but all of the parameters of the
86972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// method will be stored so that they can be reintroduced into
8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// scope at the appropriate times.
871686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
87272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
87372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
8747a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// LateParsedMemberInitializer - An initializer for a non-static class data
8757a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// member whose parsing must to be delayed until the class is completely
8767a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// defined (C++11 [class.mem]p2).
8777a614d8380297fcd2bc23986241905d97222948cRichard Smith  struct LateParsedMemberInitializer : public LateParsedDeclaration {
8787a614d8380297fcd2bc23986241905d97222948cRichard Smith    LateParsedMemberInitializer(Parser *P, Decl *FD)
8797a614d8380297fcd2bc23986241905d97222948cRichard Smith      : Self(P), Field(FD) { }
8807a614d8380297fcd2bc23986241905d97222948cRichard Smith
8817a614d8380297fcd2bc23986241905d97222948cRichard Smith    virtual void ParseLexedMemberInitializers();
8827a614d8380297fcd2bc23986241905d97222948cRichard Smith
8837a614d8380297fcd2bc23986241905d97222948cRichard Smith    Parser *Self;
8847a614d8380297fcd2bc23986241905d97222948cRichard Smith
8857a614d8380297fcd2bc23986241905d97222948cRichard Smith    /// Field - The field declaration.
8867a614d8380297fcd2bc23986241905d97222948cRichard Smith    Decl *Field;
8877a614d8380297fcd2bc23986241905d97222948cRichard Smith
8887a614d8380297fcd2bc23986241905d97222948cRichard Smith    /// CachedTokens - The sequence of tokens that comprises the initializer,
8897a614d8380297fcd2bc23986241905d97222948cRichard Smith    /// including any leading '='.
8907a614d8380297fcd2bc23986241905d97222948cRichard Smith    CachedTokens Toks;
8917a614d8380297fcd2bc23986241905d97222948cRichard Smith  };
8927a614d8380297fcd2bc23986241905d97222948cRichard Smith
893d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// LateParsedDeclarationsContainer - During parsing of a top (non-nested)
894d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// C++ class, its method declarations that contain parts that won't be
895fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// parsed until after the definition is completed (C++ [class.mem]p2),
896d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// the method declarations and possibly attached inline definitions
897a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// will be stored here with the tokens that will be parsed to create those
898a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// entities.
899a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer;
90072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
9016569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// \brief Representation of a class that has been parsed, including
9026569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// any member function declarations or definitions that need to be
9036569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// parsed after the corresponding top-level class is complete.
9046569d68745c8213709740337d2be52b031384f58Douglas Gregor  struct ParsingClass {
905d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    ParsingClass(Decl *TagOrTemplate, bool TopLevelClass)
9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : TopLevelClass(TopLevelClass), TemplateScope(false),
9076569d68745c8213709740337d2be52b031384f58Douglas Gregor        TagOrTemplate(TagOrTemplate) { }
9086569d68745c8213709740337d2be52b031384f58Douglas Gregor
9096569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Whether this is a "top-level" class, meaning that it is
9106569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// not nested within another class.
9116569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool TopLevelClass : 1;
9126569d68745c8213709740337d2be52b031384f58Douglas Gregor
9136569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Whether this class had an associated template
9146569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// scope. When true, TagOrTemplate is a template declaration;
9156569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// othewise, it is a tag declaration.
9166569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool TemplateScope : 1;
9176569d68745c8213709740337d2be52b031384f58Douglas Gregor
9186569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief The class or class template whose definition we are parsing.
919d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *TagOrTemplate;
92072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
921d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    /// LateParsedDeclarations - Method declarations, inline definitions and
922d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    /// nested classes that contain pieces whose parsing will be delayed until
923d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    /// the top-level class is fully defined.
924d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    LateParsedDeclarationsContainer LateParsedDeclarations;
92572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
9264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
9276569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// \brief The stack of classes that is currently being
9286569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// parsed. Nested and local classes will be pushed onto this stack
9296569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// when they are parsed, and removed afterward.
9306569d68745c8213709740337d2be52b031384f58Douglas Gregor  std::stack<ParsingClass *> ClassStack;
9314cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
9326569d68745c8213709740337d2be52b031384f58Douglas Gregor  ParsingClass &getCurrentClass() {
9336569d68745c8213709740337d2be52b031384f58Douglas Gregor    assert(!ClassStack.empty() && "No lexed method stacks!");
9346569d68745c8213709740337d2be52b031384f58Douglas Gregor    return *ClassStack.top();
9354cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
9364cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
93754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// \brief RAII object used to inform the actions that we're
93854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// currently parsing a declaration.  This is active when parsing a
93954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// variable's initializer, but not when parsing the body of a
94054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// class or function definition.
94154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclRAIIObject {
942f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    Sema &Actions;
943eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall    Sema::ParsingDeclState State;
94454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    bool Popped;
945c9068d7dd94d439cec66c421115d15303e481025John McCall
94654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
94754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) {
94854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      push();
94954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
95054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
951c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *Other)
952c9068d7dd94d439cec66c421115d15303e481025John McCall        : Actions(P.Actions) {
953c9068d7dd94d439cec66c421115d15303e481025John McCall      if (Other) steal(*Other);
954c9068d7dd94d439cec66c421115d15303e481025John McCall      else push();
955c9068d7dd94d439cec66c421115d15303e481025John McCall    }
956c9068d7dd94d439cec66c421115d15303e481025John McCall
957c9068d7dd94d439cec66c421115d15303e481025John McCall    /// Creates a RAII object which steals the state from a different
958c9068d7dd94d439cec66c421115d15303e481025John McCall    /// object instead of pushing.
959c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclRAIIObject(ParsingDeclRAIIObject &Other)
960c9068d7dd94d439cec66c421115d15303e481025John McCall        : Actions(Other.Actions) {
961c9068d7dd94d439cec66c421115d15303e481025John McCall      steal(Other);
962c9068d7dd94d439cec66c421115d15303e481025John McCall    }
963c9068d7dd94d439cec66c421115d15303e481025John McCall
96454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ~ParsingDeclRAIIObject() {
96554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      abort();
96654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
96754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
96854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// Resets the RAII object for a new declaration.
96954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void reset() {
97054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      abort();
97154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      push();
97254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
97354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
97454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// Signals that the context was completed without an appropriate
97554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// declaration being parsed.
97654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void abort() {
977d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      pop(0);
97854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
97954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
980d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void complete(Decl *D) {
98154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      assert(!Popped && "ParsingDeclaration has already been popped!");
98254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      pop(D);
98354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
98454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
98554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  private:
986c9068d7dd94d439cec66c421115d15303e481025John McCall    void steal(ParsingDeclRAIIObject &Other) {
987c9068d7dd94d439cec66c421115d15303e481025John McCall      State = Other.State;
988c9068d7dd94d439cec66c421115d15303e481025John McCall      Popped = Other.Popped;
989c9068d7dd94d439cec66c421115d15303e481025John McCall      Other.Popped = true;
990c9068d7dd94d439cec66c421115d15303e481025John McCall    }
991a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
99254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void push() {
99354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      State = Actions.PushParsingDeclaration();
99454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      Popped = false;
99554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
99654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
997d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void pop(Decl *D) {
99854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      if (!Popped) {
99954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall        Actions.PopParsingDeclaration(State, D);
100054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall        Popped = true;
100154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      }
100254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
100354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
100454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
100554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// A class for parsing a DeclSpec.
100654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclSpec : public DeclSpec {
100754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject ParsingRAII;
100854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
100954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
10100b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    ParsingDeclSpec(Parser &P) : DeclSpec(P.AttrFactory), ParsingRAII(P) {}
1011c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII)
10120b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      : DeclSpec(P.AttrFactory), ParsingRAII(P, RAII) {}
101354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
1014d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void complete(Decl *D) {
101554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.complete(D);
101654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
101754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
101854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void abort() {
101954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.abort();
102054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
102154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
102254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
102354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// A class for parsing a declarator.
102454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclarator : public Declarator {
102554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject ParsingRAII;
102654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
102754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
102854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C)
102954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      : Declarator(DS, C), ParsingRAII(P) {
103054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
103154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
103254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    const ParsingDeclSpec &getDeclSpec() const {
103354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec());
103454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
103554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
103654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclSpec &getMutableDeclSpec() const {
103754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      return const_cast<ParsingDeclSpec&>(getDeclSpec());
103854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
103954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
104054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void clear() {
104154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      Declarator::clear();
104254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.reset();
104354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
104454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
1045d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void complete(Decl *D) {
104654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.complete(D);
104754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
104854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
104954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
10501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief RAII object used to
10516569d68745c8213709740337d2be52b031384f58Douglas Gregor  class ParsingClassDefinition {
10526569d68745c8213709740337d2be52b031384f58Douglas Gregor    Parser &P;
10536569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool Popped;
1054eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall    Sema::ParsingClassState State;
10556569d68745c8213709740337d2be52b031384f58Douglas Gregor
10566569d68745c8213709740337d2be52b031384f58Douglas Gregor  public:
1057d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass)
1058eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall      : P(P), Popped(false),
1059eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall        State(P.PushParsingClass(TagOrTemplate, TopLevelClass)) {
10606569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
10616569d68745c8213709740337d2be52b031384f58Douglas Gregor
10626569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Pop this class of the stack.
10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    void Pop() {
10646569d68745c8213709740337d2be52b031384f58Douglas Gregor      assert(!Popped && "Nested class has already been popped");
10656569d68745c8213709740337d2be52b031384f58Douglas Gregor      Popped = true;
1066eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall      P.PopParsingClass(State);
10676569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
10686569d68745c8213709740337d2be52b031384f58Douglas Gregor
10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ~ParsingClassDefinition() {
10706569d68745c8213709740337d2be52b031384f58Douglas Gregor      if (!Popped)
1071eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall        P.PopParsingClass(State);
10726569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
10736569d68745c8213709740337d2be52b031384f58Douglas Gregor  };
10746569d68745c8213709740337d2be52b031384f58Douglas Gregor
10754d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// \brief Contains information about any template-specific
10764d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// information that has been parsed prior to parsing declaration
10774d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// specifiers.
10784d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  struct ParsedTemplateInfo {
10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParsedTemplateInfo()
10804d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { }
10814d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
10824d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
1083c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor                       bool isSpecialization,
1084c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor                       bool lastParameterListWasEmpty = false)
10854d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      : Kind(isSpecialization? ExplicitSpecialization : Template),
1086a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie        TemplateParams(TemplateParams),
1087c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        LastParameterListWasEmpty(lastParameterListWasEmpty) { }
10884d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
108945f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    explicit ParsedTemplateInfo(SourceLocation ExternLoc,
109045f965581935791a018df829a14dff53c1dd8f47Douglas Gregor                                SourceLocation TemplateLoc)
10911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : Kind(ExplicitInstantiation), TemplateParams(0),
1092c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1093c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        LastParameterListWasEmpty(false){ }
10944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
10954d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The kind of template we are parsing.
10964d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    enum {
10974d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are not parsing a template at all.
10984d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      NonTemplate = 0,
10994d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing a template declaration.
11004d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      Template,
11014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing an explicit specialization.
11024d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      ExplicitSpecialization,
11034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing an explicit instantiation.
11044d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      ExplicitInstantiation
11054d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    } Kind;
11064d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
11074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The template parameter lists, for template declarations
11084d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// and explicit specializations.
11094d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    TemplateParameterLists *TemplateParams;
11104d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
111145f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    /// \brief The location of the 'extern' keyword, if any, for an explicit
111245f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    /// instantiation
111345f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    SourceLocation ExternLoc;
11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The location of the 'template' keyword, for an explicit
11164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// instantiation.
11174d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    SourceLocation TemplateLoc;
1118a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1119c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor    /// \brief Whether the last template parameter list was empty.
1120c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor    bool LastParameterListWasEmpty;
112178b810559d89e996e00684335407443936ce34a1John McCall
112278b810559d89e996e00684335407443936ce34a1John McCall    SourceRange getSourceRange() const;
11234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  };
11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11258387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  /// \brief Contains a late templated function.
11268387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  /// Will be parsed at the end of the translation unit.
11278387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  struct LateParsedTemplatedFunction {
1128e1fca502e7f1349e9b4520a4ca9a02413bcf2b14Francois Pichet    explicit LateParsedTemplatedFunction(Decl *MD)
11298387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet      : D(MD) {}
11308387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet
11318387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet    CachedTokens Toks;
1132a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
11338387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet    /// \brief The template function declaration to be late parsed.
1134a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    Decl *D;
11358387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  };
11368387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet
11378387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  void LexTemplateFunctionForLateParsing(CachedTokens &Toks);
11388387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  void ParseLateTemplatedFuncDef(LateParsedTemplatedFunction &LMT);
11398387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  typedef llvm::DenseMap<const FunctionDecl*, LateParsedTemplatedFunction*>
11408387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet    LateParsedTemplateMapT;
11418387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  LateParsedTemplateMapT LateParsedTemplateMap;
11428387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet
11434a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet  static void LateTemplateParserCallback(void *P, const FunctionDecl *FD);
11444a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet  void LateTemplateParser(const FunctionDecl *FD);
11458387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet
1146eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  Sema::ParsingClassState
1147eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass);
114837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void DeallocateParsedClasses(ParsingClass *Class);
1149eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  void PopParsingClass(Sema::ParsingClassState);
115037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor
11515f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen  Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, AttributeList *AccessAttrs,
11525f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                ParsingDeclarator &D,
11534867347e82648d3baf09524b98b09c297a5a198fNico Weber                                const ParsedTemplateInfo &TemplateInfo,
1154a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                                const VirtSpecifiers& VS,
115545fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor                                FunctionDefinitionKind DefinitionKind,
115645fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor                                ExprResult& Init);
11577a614d8380297fcd2bc23986241905d97222948cRichard Smith  void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1158eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  void ParseLexedAttributes(ParsingClass &Class);
1159eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  void ParseLexedAttribute(LateParsedAttribute &LA);
116037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseLexedMethodDeclarations(ParsingClass &Class);
1161d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
116237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseLexedMethodDefs(ParsingClass &Class);
1163d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  void ParseLexedMethodDef(LexedMethod &LM);
11647a614d8380297fcd2bc23986241905d97222948cRichard Smith  void ParseLexedMemberInitializers(ParsingClass &Class);
11657a614d8380297fcd2bc23986241905d97222948cRichard Smith  void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1166140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  Decl *ParseLexedObjCMethodDefs(LexedMethod &LM);
1167a891a32d3762ee641a29c091d286f2a7432671a5Sebastian Redl  bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks);
116814b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis  bool ConsumeAndStoreUntil(tok::TokenKind T1,
116914b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            CachedTokens &Toks,
117014b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            bool StopAtSemi = true,
117114b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            bool ConsumeFinalToken = true) {
117214b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis    return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken);
117314b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis  }
11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
117537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                            CachedTokens &Toks,
117614b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            bool StopAtSemi = true,
117737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                            bool ConsumeFinalToken = true);
11784d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
11794cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.9: External Definitions.
11817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct ParsedAttributesWithRange : ParsedAttributes {
11820b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    ParsedAttributesWithRange(AttributeFactory &factory)
11830b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      : ParsedAttributes(factory) {}
11840b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall
11857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    SourceRange Range;
11867f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  };
11877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
11887f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
118909a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor                                          ParsingDeclSpec *DS = 0);
1190e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt  bool isDeclarationAfterDeclarator();
1191004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner  bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
11927f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsedAttributes &attrs,
11937f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                                  AccessSpecifier AS = AS_none);
11943acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS,
11953acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian                                                  AccessSpecifier AS = AS_none);
1196a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1197d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseFunctionDefinition(ParsingDeclarator &D,
119852591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor                 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseKNRParamDeclarations(Declarator &D);
1200ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // EndLoc, if non-NULL, is filled with the location of the last token of
1201ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // the simple-asm.
120260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0);
120360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseAsmStringLiteral();
12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12053536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  // Objective-C External Declarations
120695ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian  Parser::DeclGroupPtrTy ParseObjCAtDirectives();
120795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian  Parser::DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
1208d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
12097f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                        ParsedAttributes &prefixAttrs);
1210d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
121183c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian                                       tok::ObjCKeywordKind visibility,
121260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                       SourceLocation atLoc);
1213686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P,
1214686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                   SmallVectorImpl<SourceLocation> &PLocs,
12151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   bool WarnOnDeclarations,
121671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                   SourceLocation &LAngleLoc,
1217e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                   SourceLocation &EndProtoLoc);
121846f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor  bool ParseObjCProtocolQualifiers(DeclSpec &DS);
12192f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian  void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey,
12202f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian                                  Decl *CDecl);
1221d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
12227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                       ParsedAttributes &prefixAttrs);
12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1224d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ObjCImpDecl;
1225686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Decl *, 4> PendingObjCImpDecl;
1226140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  typedef SmallVector<LexedMethod*, 2> LateParsedObjCMethodContainer;
1227140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  LateParsedObjCMethodContainer LateParsedObjCMethods;
12280416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
1229d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  Decl *ParseObjCAtImplementationDeclaration(SourceLocation AtLoc);
1230140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd);
1231d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1232d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1233d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12352fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
123634870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  // Definitions for Objective-c context sensitive keywords recognition.
123734870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  enum ObjCTypeQual {
123834870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
123934870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_NumQuals
124034870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  };
1241a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1243335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian  bool isTokIdentifier_in() const;
1244d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian
1245cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx,
1246cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                               ParsedAttributes *ParamAttrs);
1247294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  void ParseObjCMethodRequirement();
1248a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  Decl *ParseObjCMethodPrototype(
124990ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
125090ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            bool MethodDefinition = true);
1251d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
125290ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
125390ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            bool MethodDefinition=true);
1254a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
12551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1256d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCMethodDefinition();
12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.5: Expressions.
1260a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
12615ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  ExprResult ParseExpression();
126260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseConstantExpression();
12632f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  // Expr that doesn't include commas.
12645ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  ExprResult ParseAssignmentExpression();
12652f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl
126660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
126860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
1269adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman
127060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseRHSOfBinaryExpression(ExprResult LHS,
1271312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                        prec::Level MinPrec);
127260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCastExpression(bool isUnaryExpression,
1273312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                 bool isAddressOfOperand,
1274312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                 bool &NotCastExpr,
12750a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis                                 bool isTypeCast);
127660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCastExpression(bool isUnaryExpression,
1277312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                 bool isAddressOfOperand = false,
12780a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis                                 bool isTypeCast = false);
12799c72c6088d591ace8503b842d39448c2040f3033John McCall
12809c72c6088d591ace8503b842d39448c2040f3033John McCall  /// Returns true if the next token would start a postfix-expression
12819c72c6088d591ace8503b842d39448c2040f3033John McCall  /// suffix.
12829c72c6088d591ace8503b842d39448c2040f3033John McCall  bool isPostfixExpressionSuffixStart() {
12839c72c6088d591ace8503b842d39448c2040f3033John McCall    tok::TokenKind K = Tok.getKind();
12849c72c6088d591ace8503b842d39448c2040f3033John McCall    return (K == tok::l_square || K == tok::l_paren ||
12859c72c6088d591ace8503b842d39448c2040f3033John McCall            K == tok::period || K == tok::arrow ||
12869c72c6088d591ace8503b842d39448c2040f3033John McCall            K == tok::plusplus || K == tok::minusminus);
12879c72c6088d591ace8503b842d39448c2040f3033John McCall  }
12889c72c6088d591ace8503b842d39448c2040f3033John McCall
128960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParsePostfixExpressionSuffix(ExprResult LHS);
1290f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult ParseUnaryExprOrTypeTraitExpression();
129160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseBuiltinPrimaryExpression();
12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1293f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
12945ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis                                                     bool &isCastExpr,
1295b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                                     ParsedType &CastTy,
12965ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis                                                     SourceRange &CastRange);
12970cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
1298686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<Expr*, 20> ExprListTy;
1299686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<SourceLocation, 20> CommaLocsTy;
13000cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
13010cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis  /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
1302686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool ParseExpressionList(SmallVectorImpl<Expr*> &Exprs,
1303686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                           SmallVectorImpl<SourceLocation> &CommaLocs,
1304f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                           void (Sema::*Completer)(Scope *S,
1305f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Expr *Data,
1306f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Expr **Args,
1307f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   unsigned NumArgs) = 0,
1308ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall                           Expr *Data = 0);
1309d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParenParseOption - Control what ParseParenExpression will parse.
13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ParenParseOption {
13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SimpleExpr,      // Only parse '(' expression ')'
13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundStmt,    // Also allow '(' compound-statement ')'
13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CastExpr         // Also allow '(' type-name ')' <anything>
13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
131760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseParenExpression(ParenParseOption &ExprType,
13180350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis                                        bool stopIfCastExpr,
13190a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis                                        bool isTypeCast,
1320b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                        ParsedType &CastTy,
1321d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl                                        SourceLocation &RParenLoc);
13221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
132360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
13244a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                            ParsedType &CastTy,
13254a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                            BalancedDelimiterTracker &Tracker);
132660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCompoundLiteralExpression(ParsedType Ty,
1327d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis                                                  SourceLocation LParenLoc,
1328d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis                                                  SourceLocation RParenLoc);
13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
133060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseStringLiteralExpression();
1331eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1332f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ExprResult ParseGenericSelectionExpression();
1333f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
1334eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
1335eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  // C++ Expressions
133660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
13374bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis
1338950be71c745409e373ae8a834490f9026c8ac222Richard Trieu  void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr,
1339950be71c745409e373ae8a834490f9026c8ac222Richard Trieu                                  bool EnteringContext, IdentifierInfo &II,
1340950be71c745409e373ae8a834490f9026c8ac222Richard Trieu                                  CXXScopeSpec &SS);
1341950be71c745409e373ae8a834490f9026c8ac222Richard Trieu
13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
1343b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                      ParsedType ObjectType,
1344b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor                                      bool EnteringContext,
13454147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet                                      bool *MayBePseudoDestructor = 0,
13464147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet                                      bool IsTypename = false);
13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1349ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  // C++0x 5.1.2: Lambda expressions
1350ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor
1351ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  // [...] () -> type {...}
1352ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  ExprResult ParseLambdaExpression();
1353ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  ExprResult TryParseLambdaExpression();
1354ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  llvm::Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro);
1355ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  bool TryParseLambdaIntroducer(LambdaIntroducer &Intro);
1356ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  ExprResult ParseLambdaExpressionAfterIntroducer(
1357ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor               LambdaIntroducer &Intro);
1358ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor
1359ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  //===--------------------------------------------------------------------===//
13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 5.2p1: C++ Casts
136160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXCasts();
13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1364c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // C++ 5.2p1: C++ Type Identification
136560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXTypeid();
1366c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
1367c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  //===--------------------------------------------------------------------===//
136801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  //  C++ : Microsoft __uuidof Expression
136901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult ParseCXXUuidof();
137001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
137101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  //===--------------------------------------------------------------------===//
1372d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor  // C++ 5.2.4: C++ Pseudo-Destructor Expressions
137360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc,
1374d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                            tok::TokenKind OpKind,
1375d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                            CXXScopeSpec &SS,
1376b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                            ParsedType ObjectType);
1377d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor
1378d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor  //===--------------------------------------------------------------------===//
13794cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // C++ 9.3.2: C++ 'this' pointer
138060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXThis();
13814cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
13824cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
138350dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  // C++ 15: C++ Throw Expression
138460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseThrowExpression();
13857acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl
13867acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl  ExceptionSpecificationType MaybeParseExceptionSpecification(
13877acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                    SourceRange &SpecificationRange,
1388686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                    SmallVectorImpl<ParsedType> &DynamicExceptions,
1389686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                    SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
13907acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                    ExprResult &NoexceptExpr);
13917acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl
1392ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // EndLoc is filled with the location of the last token of the specification.
13937acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl  ExceptionSpecificationType ParseDynamicExceptionSpecification(
13947acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                                  SourceRange &SpecificationRange,
1395686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                  SmallVectorImpl<ParsedType> &Exceptions,
1396686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                  SmallVectorImpl<SourceRange> &Ranges);
139750dd289f45738ed22b7583d52ed2525b927042ffChris Lattner
139850dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  //===--------------------------------------------------------------------===//
1399dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // C++0x 8: Function declaration trailing-return-type
1400ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  TypeResult ParseTrailingReturnType(SourceRange &Range);
1401dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
1402dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //===--------------------------------------------------------------------===//
14035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 2.13.5: C++ Boolean Literals
140460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXBoolLiteral();
14055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1407987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // C++ 5.2.3: Explicit type conversion (functional notation)
140860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
1409987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
14106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  bool isCXXSimpleTypeSpecifier() const;
14116aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
1412987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
1413987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// This should only be called when the current token is known to be part of
1414987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// simple-type-specifier.
1415987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1416987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
14172f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor  bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
14182f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor
1419987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
14204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // C++ 5.3.4 and 5.3.5: C++ new and delete
1421686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
1422ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall                                   Declarator &D);
14234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDirectNewDeclarator(Declarator &D);
142460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
142560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXDeleteExpression(bool UseGlobal,
142659232d35f5820e334b6c8b007ae8006f4390055dChris Lattner                                            SourceLocation Start);
14274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
14284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  //===--------------------------------------------------------------------===//
142999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  // C++ if/switch/while condition expression.
143060d7b3a319d84d688752be3870615ac0f111fb16John McCall  bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult,
1431586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                         SourceLocation Loc, bool ConvertToBoolean);
143271b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis
143371b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
143412e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  // C++ types
143512e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor
143612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  //===--------------------------------------------------------------------===//
14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7.8: Initialization.
14381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14390eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  /// ParseInitializer
14400eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///       initializer: [C99 6.7.8]
14410eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         assignment-expression
14420eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         '{' ...
144360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseInitializer() {
14440eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    if (Tok.isNot(tok::l_brace))
144520df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl      return ParseAssignmentExpression();
14460eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    return ParseBraceInitializer();
14470eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  }
144860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseBraceInitializer();
144960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseInitializerWithPotentialDesignator();
14501d922960e083906a586609ac6978678147250177Sebastian Redl
14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1452296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  // clang Expressions
14531d922960e083906a586609ac6978678147250177Sebastian Redl
145460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseBlockLiteralExpression();  // ^{...}
1455296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff
1456296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  //===--------------------------------------------------------------------===//
14575508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  // Objective-C Expressions
145860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
145960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
146060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
146160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
146260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
14631b730e847ded503f2e615154035c083c4f94a067Douglas Gregor  bool isSimpleObjCMessageExpression();
146460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCMessageExpression();
146560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
14662725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                                  SourceLocation SuperLoc,
1467b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                                  ParsedType ReceiverType,
14681d922960e083906a586609ac6978678147250177Sebastian Redl                                                  ExprArg ReceiverExpr);
146960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseAssignmentExprWithObjCMessageExprStart(
14702725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      SourceLocation LBracloc, SourceLocation SuperLoc,
1471b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      ParsedType ReceiverType, ExprArg ReceiverExpr);
14726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr);
147361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
14745508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  //===--------------------------------------------------------------------===//
14755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.8: Statements and Blocks.
147661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
147760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseStatement() {
1478c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian    StmtVector Stmts(Actions);
1479c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian    return ParseStatementOrDeclaration(Stmts, true);
148061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
1481c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian  StmtResult ParseStatementOrDeclaration(StmtVector& Stmts,
1482c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian                                         bool OnlyStatement = false);
14835ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  StmtResult ParseExprStatement(ParsedAttributes &Attrs);
14847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseLabeledStatement(ParsedAttributes &Attr);
1485bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu  StmtResult ParseCaseStatement(ParsedAttributes &Attr,
1486bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu                                bool MissingCase = false,
1487bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu                                ExprResult Expr = ExprResult());
14887f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseDefaultStatement(ParsedAttributes &Attr);
14897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseCompoundStatement(ParsedAttributes &Attr,
1490312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                    bool isStmtExpr = false);
1491bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  StmtResult ParseCompoundStatement(ParsedAttributes &Attr,
1492bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor                                    bool isStmtExpr,
1493bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor                                    unsigned ScopeFlags);
149460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
149560d7b3a319d84d688752be3870615ac0f111fb16John McCall  bool ParseParenExprOrCondition(ExprResult &ExprResult,
1496d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                 Decl *&DeclResult,
1497586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                 SourceLocation Loc,
149844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                 bool ConvertToBoolean);
14997f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseIfStatement(ParsedAttributes &Attr);
15007f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseSwitchStatement(ParsedAttributes &Attr);
15017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseWhileStatement(ParsedAttributes &Attr);
15027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseDoStatement(ParsedAttributes &Attr);
15037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseForStatement(ParsedAttributes &Attr);
15047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseGotoStatement(ParsedAttributes &Attr);
15057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseContinueStatement(ParsedAttributes &Attr);
15067f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseBreakStatement(ParsedAttributes &Attr);
15077f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseReturnStatement(ParsedAttributes &Attr);
150860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseAsmStatement(bool &msAsm);
15093fedbe1f71c18fba01d39109d606f421a0103a2aEli Friedman  StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
1510a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
15113896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  /// \brief Describes the behavior that should be taken for an __if_exists
15123896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  /// block.
15133896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  enum IfExistsBehavior {
15143896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief Parse the block; this code is always used.
15153896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    IEB_Parse,
15163896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief Skip the block entirely; this code is never used.
15173896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    IEB_Skip,
15183896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief Parse the block as a dependent block, which may be used in
15193896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// some template instantiations but not others.
15203896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    IEB_Dependent
15213896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  };
1522a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1523a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// \brief Describes the condition of a Microsoft __if_exists or
15243896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  /// __if_not_exists block.
15253896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  struct IfExistsCondition {
15263896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief The location of the initial keyword.
15273896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    SourceLocation KeywordLoc;
1528a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    /// \brief Whether this is an __if_exists block (rather than an
15293896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// __if_not_exists block).
15303896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    bool IsIfExists;
1531a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
15323896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief Nested-name-specifier preceding the name.
15333896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    CXXScopeSpec SS;
1534a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
15353896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief The name we're looking for.
15363896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    UnqualifiedId Name;
15373896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor
15383896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief The behavior of this __if_exists or __if_not_exists block
15393896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// should.
15403896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    IfExistsBehavior Behavior;
15413896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor};
1542a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
15433896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result);
15441e862693c63067ae467b0b3884c44f753cd6e821Francois Pichet  void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
1545563a645de82231a55e221fe655b7188bf8369662Francois Pichet  void ParseMicrosoftIfExistsExternalDeclaration();
1546563a645de82231a55e221fe655b7188bf8369662Francois Pichet  void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType,
1547563a645de82231a55e221fe655b7188bf8369662Francois Pichet                                              AccessSpecifier& CurAS);
1548f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu  bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
1549f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu                           SmallVectorImpl<Expr *> &Constraints,
1550f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu                           SmallVectorImpl<Expr *> &Exprs);
1551a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
1552a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  //===--------------------------------------------------------------------===//
1553a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  // C++ 6: Statements and Blocks
1554a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
15557f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseCXXTryBlock(ParsedAttributes &Attr);
155660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc);
155760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseCXXCatchBlock();
1558a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
1559a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  //===--------------------------------------------------------------------===//
156028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  // MS: SEH Statements and Blocks
156128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
156228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult ParseSEHTryBlock(ParsedAttributes &Attr);
156328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult ParseSEHTryBlockCommon(SourceLocation Loc);
156428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult ParseSEHExceptBlock(SourceLocation Loc);
156528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
156628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
156728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  //===--------------------------------------------------------------------===//
1568a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  // Objective-C Statements
1569a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
157060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCAtStatement(SourceLocation atLoc);
157160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCTryStmt(SourceLocation atLoc);
157260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
157360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1574f85e193739c953358c865005855253af4f68a497John McCall  StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
1575b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7: Declarations.
157967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
158067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// A context for parsing declaration specifiers.  TODO: flesh this
158167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// out, there are other significant restrictions on specifiers than
158267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// would be best implemented in the parser.
158367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  enum DeclSpecContext {
158467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    DSC_normal, // normal context
15850efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    DSC_class,  // class context, enables 'friend'
15860efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    DSC_top_level // top-level/namespace declaration context
158767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  };
15881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1589ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// Information on a C++0x for-range-initializer found while parsing a
1590ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// declaration which turns out to be a for-range-declaration.
1591ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct ForRangeInit {
1592ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    SourceLocation ColonLoc;
1593ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    ExprResult RangeExpr;
1594ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
1595ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
1596ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
1597ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
1598c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian  DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts,
1599c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian                                  unsigned Context, SourceLocation &DeclEnd,
16007f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                  ParsedAttributesWithRange &attrs);
1601c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian  DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts,
1602c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian                                        unsigned Context,
1603bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                        SourceLocation &DeclEnd,
16047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                        ParsedAttributes &attrs,
1605ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                        bool RequireSemi,
1606ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                        ForRangeInit *FRI = 0);
16070706df40064d4d7559b4304af79d519033414b84Richard Smith  bool MightBeDeclarator(unsigned Context);
160854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context,
1609d8ac05753dc4506224d445ff98399c01da3136e5John McCall                                bool AllowFunctionDefinitions,
1610ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                SourceLocation *DeclEnd = 0,
1611ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                ForRangeInit *FRI = 0);
1612d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseDeclarationAfterDeclarator(Declarator &D,
1613e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1614ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  bool ParseAttributesAfterDeclarator(Declarator &D);
1615ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  Decl *ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D,
1616ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1617c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor  Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
1618c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor  Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
1619d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl
16200fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  /// \brief When in code-completion, skip parsing of the function/method body
16210fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  /// unless the body contains the code-completion point.
16220fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  ///
16230fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  /// \returns true if the function body was skipped.
1624b162054ba8f5b64fe87fbc4837933ab23eebd52bArgyrios Kyrtzidis  bool trySkippingFunctionBodyForCodeCompletion();
16250fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis
1626f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner  bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
16274d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                        const ParsedTemplateInfo &TemplateInfo,
1628e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner                        AccessSpecifier AS);
16290efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context);
16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void ParseDeclarationSpecifiers(DeclSpec &DS,
16314d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
163267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                  AccessSpecifier AS = AS_none,
163367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                  DeclSpecContext DSC = DSC_normal);
16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid,
16357a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner                                  const char *&PrevSpec,
1636fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                  unsigned &DiagID,
1637d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1638d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                                  bool SuppressDeclarations = false);
16394d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
1640c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith  void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none);
16411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1642cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
1643cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                                  Declarator::TheContext Context);
16445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16454c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
16461b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
16471b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis                AccessSpecifier AS = AS_none);
1648d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
1650d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                            Decl *TagDecl);
1651bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1652bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  struct FieldCallback {
1653d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    virtual Decl *invoke(FieldDeclarator &Field) = 0;
16546c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall    virtual ~FieldCallback() {}
16556c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall
16566c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall  private:
16576c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall    virtual void _anchor();
1658bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  };
1659d0014540005f2a5ab837365db6bd40f479406758John McCall  struct ObjCPropertyCallback;
1660bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1661bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback);
16621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16639497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
1664eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  bool isTypeSpecifierQualifier();
16655f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff  bool isTypeQualifier() const;
1666a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1667b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  /// isKnownToBeTypeSpecifier - Return true if we know that the specified token
1668b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  /// is definitely a type-specifier.  Return false if it isn't part of a type
1669b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  /// specifier or if we're not sure.
1670b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  bool isKnownToBeTypeSpecifier(const Token &Tok) const;
16715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16725404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isDeclarationStatement - Disambiguates between a declaration or an
16735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// expression statement, when parsing function bodies.
16745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for declaration, false for expression.
16755404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isDeclarationStatement() {
16765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    if (getLang().CPlusPlus)
16775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      return isCXXDeclarationStatement();
16789497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    return isDeclarationSpecifier(true);
16795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  }
16805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1681bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// isSimpleDeclaration - Disambiguates between a declaration or an
1682bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// expression, mainly used for the C 'clause-1' or the C++
1683bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  // 'for-init-statement' part of a 'for' statement.
1684bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// Returns true for declaration, false for expression.
1685bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  bool isSimpleDeclaration() {
1686bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis    if (getLang().CPlusPlus)
1687bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis      return isCXXSimpleDeclaration();
16889497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    return isDeclarationSpecifier(true);
1689bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  }
1690bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis
16919497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  /// \brief Determine whether we are currently at the start of an Objective-C
16929497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  /// class message that appears to be missing the open bracket '['.
16939497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  bool isStartOfObjCClassMessageMissingOpenBracket();
1694a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
16950efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// \brief Starting with a scope specifier, identifier, or
16960efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// template-id that refers to the current class, determine whether
16970efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// this is a constructor declarator.
16980efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  bool isConstructorDeclarator();
16990efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor
17008b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  /// \brief Specifies the context in which type-id/expression
17018b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  /// disambiguation will occur.
17028b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  enum TentativeCXXTypeIdContext {
17038b642592a35167a3780074e78674e0bece87c40cDouglas Gregor    TypeIdInParens,
17048b642592a35167a3780074e78674e0bece87c40cDouglas Gregor    TypeIdAsTemplateArgument
17058b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  };
17068b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
17078b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
170878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
170978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// whether the parens contain an expression or a type-id.
171078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// Returns true for a type-id and false for an expression.
1711f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isTypeIdInParens(bool &isAmbiguous) {
171278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    if (getLang().CPlusPlus)
1713f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis      return isCXXTypeId(TypeIdInParens, isAmbiguous);
1714f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    isAmbiguous = false;
171578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    return isTypeSpecifierQualifier();
171678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  }
1717f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isTypeIdInParens() {
1718f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    bool isAmbiguous;
1719f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    return isTypeIdInParens(isAmbiguous);
1720f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  }
172178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
17225404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXDeclarationStatement - C++-specialized function that disambiguates
17235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a declaration or an expression statement, when parsing function
17245404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// bodies. Returns true for declaration, false for expression.
17255404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isCXXDeclarationStatement();
17265404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
17275404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
17285404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a simple-declaration or an expression-statement.
17295404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
17305404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
17315404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns false if the statement is disambiguated as expression.
17325404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isCXXSimpleDeclaration();
17335404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
17345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
17355404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// a constructor-style initializer, when parsing declaration statements.
17365404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for function declarator and false for constructor-style
1737e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to
1738259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis  /// indicate that the parens were disambiguated as function declarator.
17395404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
17405404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
1741e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  bool isCXXFunctionDeclarator(bool warnIfAmbiguous);
17425404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1743a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// isCXXConditionDeclaration - Disambiguates between a declaration or an
1744a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// expression for a condition of a if/switch/while/for statement.
1745a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
1746a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
1747a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  bool isCXXConditionDeclaration();
1748a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis
1749f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous);
1750f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
1751f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    bool isAmbiguous;
1752f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    return isCXXTypeId(Context, isAmbiguous);
1753f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  }
175478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
1755b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult - Used as the result value for functions whose purpose is to
1756b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// disambiguate C++ constructs by "tentatively parsing" them.
1757b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// This is a class instead of a simple enum because the implicit enum-to-bool
1758b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// conversions may cause subtle bugs.
1759b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  class TPResult {
1760b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    enum Result {
1761b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_true,
1762b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_false,
1763b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_ambiguous,
1764b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_error
1765b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    };
1766b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    Result Res;
1767b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    TPResult(Result result) : Res(result) {}
1768b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  public:
1769b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult True() { return TPR_true; }
1770b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult False() { return TPR_false; }
1771b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Ambiguous() { return TPR_ambiguous; }
1772b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Error() { return TPR_error; }
1773b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis
1774b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator==(const TPResult &RHS) const { return Res == RHS.Res; }
1775b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; }
1776b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis  };
1777b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis
1778a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// \brief Based only on the given token kind, determine whether we know that
1779a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// we're at the start of an expression or a type-specifier-seq (which may
1780a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// be an expression, in C++).
1781a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  ///
1782a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// This routine does not attempt to resolve any of the trick cases, e.g.,
1783a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// those involving lookup of identifiers.
1784a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  ///
1785a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// \returns \c TPR_true if this token starts an expression, \c TPR_false if
1786a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot
1787a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// tell.
1788a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind);
1789a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor
1790b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a
1791b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// declaration specifier, TPResult::False() if it is not,
1792b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult::Ambiguous() if it could be either a decl-specifier or a
1793b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// function-style cast, and TPResult::Error() if a parsing error was
1794b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// encountered.
17955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Doesn't consume tokens.
1796b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult isCXXDeclarationSpecifier();
1797a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
17985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // "Tentative parsing" functions, used for disambiguation. If a parsing error
1799b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // is encountered they will return TPResult::Error().
1800b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // Returning TPResult::True()/False() indicates that the ambiguity was
1801b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates
1802b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // that more tentative parsing is necessary for disambiguation.
18035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // They all consume tokens, so backtracking should be used after calling them.
18045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1805b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseDeclarationSpecifier();
1806b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseSimpleDeclaration();
1807b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseTypeofSpecifier();
18089bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor  TPResult TryParseProtocolQualifiers();
1809b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseInitDeclaratorList();
181078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true);
1811b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseParameterDeclarationClause();
1812b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseFunctionDeclarator();
1813b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseBracketDeclarator();
18145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1815683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor  TypeResult ParseTypeName(SourceRange *Range = 0,
1816683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor                           Declarator::TheContext Context
1817f85e193739c953358c865005855253af4f68a497John McCall                             = Declarator::TypeNameContext,
1818c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                           AccessSpecifier AS = AS_none,
1819c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                           Decl **OwnedType = 0);
182098eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump  void ParseBlockId();
18217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
18227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
18237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (!attrs.Range.isValid()) return;
18247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    DiagnoseProhibitedAttributes(attrs);
18257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18267f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
18277f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
1828eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  void MaybeParseGNUAttributes(Declarator &D,
1829eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                               LateParsedAttrList *LateAttrs = 0) {
18307f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (Tok.is(tok::kw___attribute)) {
18310b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      ParsedAttributes attrs(AttrFactory);
18327f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      SourceLocation endLoc;
1833eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski      ParseGNUAttributes(attrs, &endLoc, LateAttrs);
18340b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      D.takeAttributes(attrs, endLoc);
18357f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
18367f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18377f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseGNUAttributes(ParsedAttributes &attrs,
1838eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                               SourceLocation *endLoc = 0,
1839eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                               LateParsedAttrList *LateAttrs = 0) {
18407f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (Tok.is(tok::kw___attribute))
1841eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski      ParseGNUAttributes(attrs, endLoc, LateAttrs);
18427f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseGNUAttributes(ParsedAttributes &attrs,
1844eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                          SourceLocation *endLoc = 0,
1845eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                          LateParsedAttrList *LateAttrs = 0);
1846eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
1847eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                             SourceLocation AttrNameLoc,
1848eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                             ParsedAttributes &Attrs,
1849eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                             SourceLocation *EndLoc);
18507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
18517f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseCXX0XAttributes(Declarator &D) {
18527f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
18530b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      ParsedAttributesWithRange attrs(AttrFactory);
18547f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      SourceLocation endLoc;
18557f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseCXX0XAttributes(attrs, &endLoc);
18560b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      D.takeAttributes(attrs, endLoc);
18577f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
18587f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18597f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseCXX0XAttributes(ParsedAttributes &attrs,
18607f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                 SourceLocation *endLoc = 0) {
18617f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
18620b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      ParsedAttributesWithRange attrsWithRange(AttrFactory);
18637f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseCXX0XAttributes(attrsWithRange, endLoc);
18640b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      attrs.takeAllFrom(attrsWithRange);
18657f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
18667f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18677f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
18687f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                 SourceLocation *endLoc = 0) {
18697f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
18707f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseCXX0XAttributes(attrs, endLoc);
18717f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18723497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne
18733497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne  void ParseCXX0XAttributeSpecifier(ParsedAttributes &attrs,
18743497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne                                    SourceLocation *EndLoc = 0);
18757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
18767f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                            SourceLocation *EndLoc = 0);
18777f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
18787f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
18797f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                     SourceLocation *endLoc = 0) {
188062ec1f2fd7368542bb926c04797fb07023547694Francois Pichet    if (getLang().MicrosoftExt && Tok.is(tok::l_square))
18817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseMicrosoftAttributes(attrs, endLoc);
18827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseMicrosoftAttributes(ParsedAttributes &attrs,
18847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                SourceLocation *endLoc = 0);
18857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseMicrosoftDeclSpec(ParsedAttributes &attrs);
18867f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
18877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
1888f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne  void ParseOpenCLAttributes(ParsedAttributes &attrs);
1889207f4d8543529221932af82836016a2ef066c917Peter Collingbourne  void ParseOpenCLQualifiers(DeclSpec &DS);
18907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
18910a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  VersionTuple ParseVersionTuple(SourceRange &Range);
18920a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  void ParseAvailabilityAttribute(IdentifierInfo &Availability,
18930a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor                                  SourceLocation AvailabilityLoc,
18940a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor                                  ParsedAttributes &attrs,
18950a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor                                  SourceLocation *endLoc);
18960a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
1897b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski  bool IsThreadSafetyAttribute(llvm::StringRef AttrName);
1898b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski  void ParseThreadSafetyAttribute(IdentifierInfo &AttrName,
1899b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski                                  SourceLocation AttrNameLoc,
1900b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski                                  ParsedAttributes &Attrs,
1901b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski                                  SourceLocation *EndLoc);
1902b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski
1903b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski
1904d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  void ParseTypeofSpecifier(DeclSpec &DS);
190542d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie  SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
190642d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie  void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
190742d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie                                         SourceLocation StartLoc,
190842d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie                                         SourceLocation EndLoc);
1909db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt  void ParseUnderlyingTypeSpecifier(DeclSpec &DS);
1910b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  void ParseAtomicSpecifier(DeclSpec &DS);
1911b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
19120b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne  ExprResult ParseAlignArgument(SourceLocation Start,
19130b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne                                SourceLocation &EllipsisLoc);
191482d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne  void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
191582d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne                               SourceLocation *endLoc = 0);
1916eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1917cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson  VirtSpecifiers::Specifier isCXX0XVirtSpecifier() const;
1918b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  void ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS);
19191f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
19208a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson  bool isCXX0XFinalKeyword() const;
1921cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson
1922eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
1923eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// enter a new C++ declarator scope and exit it when the function is
1924eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// finished.
1925eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  class DeclaratorScopeObj {
1926eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    Parser &P;
1927751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis    CXXScopeSpec &SS;
1928f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis    bool EnteredScope;
1929f7f3d0db754db0500b56d49ac19f795f13965912John McCall    bool CreatedScope;
1930eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  public:
1931f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis    DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
1932f7f3d0db754db0500b56d49ac19f795f13965912John McCall      : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
1933eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1934eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    void EnterDeclaratorScope() {
19352bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis      assert(!EnteredScope && "Already entered the scope!");
1936f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      assert(SS.isSet() && "C++ scope was not set!");
1937f7f3d0db754db0500b56d49ac19f795f13965912John McCall
1938f7f3d0db754db0500b56d49ac19f795f13965912John McCall      CreatedScope = true;
1939f7f3d0db754db0500b56d49ac19f795f13965912John McCall      P.EnterScope(0); // Not a decl scope.
1940f7f3d0db754db0500b56d49ac19f795f13965912John McCall
194123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
19423fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor        EnteredScope = true;
1943eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
1944eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1945eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    ~DeclaratorScopeObj() {
1946f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      if (EnteredScope) {
1947f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis        assert(SS.isSet() && "C++ scope was cleared ?");
194823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor        P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
1949f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      }
1950f7f3d0db754db0500b56d49ac19f795f13965912John McCall      if (CreatedScope)
1951f7f3d0db754db0500b56d49ac19f795f13965912John McCall        P.ExitScope();
1952eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
1953eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  };
19541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseDeclarator - Parse and verify a newly-initialized declarator.
19565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDeclarator(Declarator &D);
19574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  /// A function that parses a variant of direct-declarator.
19584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
19594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDeclaratorInternal(Declarator &D,
19604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl                               DirectDeclParseFunction DirectDeclParser);
19617f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
1962bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true,
1963bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                 bool CXX0XAttributesAllowed = true);
19645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDirectDeclarator(Declarator &D);
19655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseParenDeclarator(Declarator &D);
19664a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  void ParseFunctionDeclarator(Declarator &D,
19677f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                               ParsedAttributes &attrs,
19684a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                               BalancedDelimiterTracker &Tracker,
19697399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner                               bool RequiresArg = false);
19703fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor  bool isFunctionDeclaratorIdentifierList();
19713fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor  void ParseFunctionDeclaratorIdentifierList(
19723fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor         Declarator &D,
1973686775deca8b8685eb90801495880e3abdd844c2Chris Lattner         SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo);
19743fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor  void ParseParameterDeclarationClause(
19753fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor         Declarator &D,
19763fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor         ParsedAttributes &attrs,
1977686775deca8b8685eb90801495880e3abdd844c2Chris Lattner         SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo,
19783fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor         SourceLocation &EllipsisLoc);
19795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseBracketDeclarator(Declarator &D);
19801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19818f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  //===--------------------------------------------------------------------===//
19828f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  // C++ 7: Declarations [dcl.dcl]
19831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1984a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  bool isCXX0XAttributeSpecifier(bool FullLookahead = false,
1985bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                 tok::TokenKind *After = 0);
1986a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1987d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl  Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd,
1988d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                       SourceLocation InlineLoc = SourceLocation());
1989f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu  void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc,
1990f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu                           std::vector<IdentifierInfo*>& Ident,
1991f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu                           std::vector<SourceLocation>& NamespaceLoc,
1992f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu                           unsigned int index, SourceLocation& InlineLoc,
19934a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                           ParsedAttributes& attrs,
19944a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                           BalancedDelimiterTracker &Tracker);
1995d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context);
1996d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseUsingDirectiveOrDeclaration(unsigned Context,
199778b810559d89e996e00684335407443936ce34a1John McCall                                         const ParsedTemplateInfo &TemplateInfo,
1998d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                                         SourceLocation &DeclEnd,
1999c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                                         ParsedAttributesWithRange &attrs,
2000c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                                         Decl **OwnedType = 0);
200178b810559d89e996e00684335407443936ce34a1John McCall  Decl *ParseUsingDirective(unsigned Context,
200278b810559d89e996e00684335407443936ce34a1John McCall                            SourceLocation UsingLoc,
20037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                            SourceLocation &DeclEnd,
20047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                            ParsedAttributes &attrs);
200578b810559d89e996e00684335407443936ce34a1John McCall  Decl *ParseUsingDeclaration(unsigned Context,
200678b810559d89e996e00684335407443936ce34a1John McCall                              const ParsedTemplateInfo &TemplateInfo,
200778b810559d89e996e00684335407443936ce34a1John McCall                              SourceLocation UsingLoc,
2008d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                              SourceLocation &DeclEnd,
2009c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                              AccessSpecifier AS = AS_none,
2010c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                              Decl **OwnedType = 0);
2011d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
2012d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
2013d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                            SourceLocation AliasLoc, IdentifierInfo *Alias,
2014d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                            SourceLocation &DeclEnd);
20151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2016e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
2017e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 9: classes [class] and C structs/unions.
20184c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
20191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                           DeclSpec &DS,
20204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2021d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                           AccessSpecifier AS = AS_none,
2022efaa93aaa2653f4eb40e6a22e504a448da94aaf8Douglas Gregor                           bool EnteringContext = false,
2023d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                           bool SuppressDeclarations = false);
20244cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType,
2025d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                   Decl *TagDecl);
20267a614d8380297fcd2bc23986241905d97222948cRichard Smith  ExprResult ParseCXXMemberInitializer(bool IsFunction,
20277a614d8380297fcd2bc23986241905d97222948cRichard Smith                                       SourceLocation &EqualLoc);
20285f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen  void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr,
2029c9068d7dd94d439cec66c421115d15303e481025John McCall                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2030c9068d7dd94d439cec66c421115d15303e481025John McCall                                 ParsingDeclRAIIObject *DiagsFromTParams = 0);
2031d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseConstructorInitializer(Decl *ConstructorDecl);
2032d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  MemInitResult ParseMemInitializer(Decl *ConstructorDecl);
2033d33133cdc1af466f9c276249b2621be03867888bEli Friedman  void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
2034d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                       Decl *ThisDecl);
2035e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
2036e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
2037e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 10: Derived classes [class.derived]
2038a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
203922216eb4fb0936d2488fc03abd285d135c36ff01David Blaikie                                    SourceLocation &EndLocation);
2040d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseBaseClause(Decl *ClassDecl);
2041d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  BaseResult ParseBaseSpecifier(Decl *ClassDecl);
20421b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor  AccessSpecifier getAccessSpecifierIfPresent() const;
20431cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor
2044a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
20453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    IdentifierInfo *Name,
20463f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    SourceLocation NameLoc,
20473f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    bool EnteringContext,
2048b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                    ParsedType ObjectType,
2049d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                    UnqualifiedId &Id,
20500278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor                                    bool AssumeTemplateId,
20510278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor                                    SourceLocation TemplateKWLoc);
2052ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
2053b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                  ParsedType ObjectType,
2054ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                  UnqualifiedId &Result);
20553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
205602a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor                          bool AllowDestructorName,
205702a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor                          bool AllowConstructorName,
2058b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                          ParsedType ObjectType,
20593f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                          UnqualifiedId &Result);
2060a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
20611cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor  //===--------------------------------------------------------------------===//
2062adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14: Templates [temp]
2063c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor
2064adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14.1: Template Parameters [temp.param]
2065d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseDeclarationStartingWithTemplate(unsigned Context,
20665f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                             SourceLocation &DeclEnd,
20675f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                             AccessSpecifier AS = AS_none,
20685f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                             AttributeList *AccessAttrs = 0);
2069d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context,
20705f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                                 SourceLocation &DeclEnd,
20715f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                                 AccessSpecifier AS,
20725f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                                 AttributeList *AccessAttrs);
2073d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseSingleDeclarationAfterTemplate(
20741426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       unsigned Context,
20754d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                       const ParsedTemplateInfo &TemplateInfo,
2076c9068d7dd94d439cec66c421115d15303e481025John McCall                                       ParsingDeclRAIIObject &DiagsFromParams,
20771426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       SourceLocation &DeclEnd,
20785f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                       AccessSpecifier AS=AS_none,
20795f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                       AttributeList *AccessAttrs = 0);
20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseTemplateParameters(unsigned Depth,
2081686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               SmallVectorImpl<Decl*> &TemplateParams,
20821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               SourceLocation &LAngleLoc,
2083c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor                               SourceLocation &RAngleLoc);
2084c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor  bool ParseTemplateParameterList(unsigned Depth,
2085686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                  SmallVectorImpl<Decl*> &TemplateParams);
208698440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor  bool isStartOfTemplateTypeParameter();
2087d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTemplateParameter(unsigned Depth, unsigned Position);
2088d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTypeParameter(unsigned Depth, unsigned Position);
2089d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
2090d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
2091d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor  // C++ 14.3: Template arguments [temp.arg]
2092686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
2093cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
20947532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  bool ParseTemplateIdAfterTemplateName(TemplateTy Template,
20951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        SourceLocation TemplateNameLoc,
2096059101f922de6eb765601459925f4c8914420b23Douglas Gregor                                        const CXXScopeSpec &SS,
2097cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        bool ConsumeLastToken,
2098cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        SourceLocation &LAngleLoc,
2099cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        TemplateArgList &TemplateArgs,
2100cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        SourceLocation &RAngleLoc);
2101cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
2102c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner  bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
2103059101f922de6eb765601459925f4c8914420b23Douglas Gregor                               CXXScopeSpec &SS,
2104ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                               UnqualifiedId &TemplateName,
210539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                               SourceLocation TemplateKWLoc = SourceLocation(),
210639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                               bool AllowTypeAnnotation = true);
2107059101f922de6eb765601459925f4c8914420b23Douglas Gregor  void AnnotateTemplateIdTokenAsType();
2108d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor  bool IsTemplateArgumentList(unsigned Skip = 0);
2109314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
2110788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  ParsedTemplateArgument ParseTemplateTemplateArgument();
2111314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  ParsedTemplateArgument ParseTemplateArgument();
2112d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseExplicitInstantiation(SourceLocation ExternLoc,
2113d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                        SourceLocation TemplateLoc,
2114d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                        SourceLocation &DeclEnd);
211564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
211664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  //===--------------------------------------------------------------------===//
21176aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor  // Modules
21186aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor  DeclGroupPtrTy ParseModuleImport();
2119a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
21206aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor  //===--------------------------------------------------------------------===//
212164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // GNU G++: Type Traits [Type-Traits.html in the GCC manual]
212260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseUnaryTypeTrait();
21236ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult ParseBinaryTypeTrait();
2124f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor
2125f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  //===--------------------------------------------------------------------===//
212621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  // Embarcadero: Arary and Expression Traits
212721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ExprResult ParseArrayTypeTrait();
2128552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExprResult ParseExpressionTrait();
2129552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2130552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  //===--------------------------------------------------------------------===//
2131f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  // Preprocessor code-completion pass-through
2132f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  virtual void CodeCompleteDirective(bool InConditional);
2133f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  virtual void CodeCompleteInConditionalExclusion();
21341fbb447e9d43c2c676e94081fbfee7eb6cbe933bDouglas Gregor  virtual void CodeCompleteMacroName(bool IsDefinition);
2135f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor  virtual void CodeCompletePreprocessorExpression();
2136f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor  virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro,
2137f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor                                         MacroInfo *MacroInfo,
2138f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor                                         unsigned ArgumentIndex);
213955817afdf9d453a443262a733f6caf6692dca118Douglas Gregor  virtual void CodeCompleteNaturalLanguage();
21405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
21435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2145