Parser.h revision ebcb57a8d298862c65043e88b2429591ab3c58d3
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;
150006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian
151006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian  /// \brief Identifier for "message".
152006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian  IdentifierInfo *Ident_message;
153b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor
154a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// C++0x contextual keywords.
1557eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson  mutable IdentifierInfo *Ident_final;
1567eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson  mutable IdentifierInfo *Ident_override;
1571f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
1586f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<PragmaHandler> AlignHandler;
1596f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<PragmaHandler> GCCVisibilityHandler;
1606f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<PragmaHandler> OptionsHandler;
1616f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<PragmaHandler> PackHandler;
1626f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<PragmaHandler> MSStructHandler;
1636f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<PragmaHandler> UnusedHandler;
1646f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<PragmaHandler> WeakHandler;
1655f3c163b7b19a0c7e02509a0984ee1256bca890dDavid Chisnall  OwningPtr<PragmaHandler> RedefineExtnameHandler;
1666f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<PragmaHandler> FPContractHandler;
1676f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<PragmaHandler> OpenCLExtensionHandler;
1681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// Whether the '>' token acts as an operator or not. This will be
17055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// true except when we are parsing an expression within a C++
17155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// template argument list, where the '>' closes the template
17255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// argument list.
17355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  bool GreaterThanIsOperator;
174a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
17508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// ColonIsSacred - When this is false, we aggressively try to recover from
17608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// code like "foo : bar" as if it were a typo for "foo :: bar".  This is not
17708d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// safe in case statements and a few other things.  This is managed by the
17808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// ColonProtectionRAIIObject RAII object.
17908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  bool ColonIsSacred;
18055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
181a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// \brief When true, we are directly inside an Objective-C messsage
1820fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// send expression.
1830fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  ///
1840fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// This is managed by the \c InMessageExpressionRAIIObject class, and
1850fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// should not be set directly.
1860fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  bool InMessageExpression;
187a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
188c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor  /// The "depth" of the template parameters currently being parsed.
189c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor  unsigned TemplateParameterDepth;
190a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1918113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek  /// Factory object for creating AttributeList objects.
1920b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall  AttributeFactory AttrFactory;
1931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19425a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// \brief Gathers and cleans up objects when parsing of a top-level
19525a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// declaration is finished.
19625a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  DelayedCleanupPool TopLevelDeclCleanupPool;
19725a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis
198b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor  IdentifierInfo *getSEHExceptKeyword();
199a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
201f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  Parser(Preprocessor &PP, Sema &Actions);
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ~Parser();
2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const LangOptions &getLang() const { return PP.getLangOptions(); }
205444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
2060102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  Preprocessor &getPreprocessor() const { return PP; }
207f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  Sema &getActions() const { return Actions; }
2081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2090102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  const Token &getCurToken() const { return Tok; }
21023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  Scope *getCurScope() const { return Actions.getCurScope(); }
211a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
212a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  Decl  *getObjCDeclContext() const { return Actions.getObjCDeclContext(); }
213a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Type forwarding.  All of these are statically 'void*', but they may all be
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // different actual classes based on the actions in place.
2162b5289b6fd7e3d9899868410a498c081c9595662John McCall  typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
2172b5289b6fd7e3d9899868410a498c081c9595662John McCall  typedef OpaquePtr<TemplateName> TemplateTy;
2187ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
219686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists;
220c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor
2219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::ExprResult        ExprResult;
2229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::StmtResult        StmtResult;
2239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::BaseResult        BaseResult;
2249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::MemInitResult     MemInitResult;
2259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::TypeResult        TypeResult;
22615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
2279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef Expr *ExprArg;
2289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef ASTMultiPtr<Stmt*> MultiStmtArg;
229f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::FullExprArg FullExprArg;
2301d922960e083906a586609ac6978678147250177Sebastian Redl
23160d7b3a319d84d688752be3870615ac0f111fb16John McCall  /// Adorns a ExprResult with Actions to make it an ExprResult
23260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Owned(ExprResult res) {
23360d7b3a319d84d688752be3870615ac0f111fb16John McCall    return ExprResult(res);
23461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
23560d7b3a319d84d688752be3870615ac0f111fb16John McCall  /// Adorns a StmtResult with Actions to make it an StmtResult
23660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Owned(StmtResult res) {
23760d7b3a319d84d688752be3870615ac0f111fb16John McCall    return StmtResult(res);
23861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
23961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
24060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ExprError() { return ExprResult(true); }
24160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult StmtError() { return StmtResult(true); }
242d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor
24360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); }
24460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); }
24561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
24660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ExprEmpty() { return ExprResult(false); }
2475ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis
2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Parsing methods.
2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseTranslationUnit - All in one method that initializes parses, and
2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// shuts down the parser.
2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseTranslationUnit();
2531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Initialize - Warm up the parser.
2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Initialize();
2571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
2591f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff  /// the EOF was encountered.
260682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
2611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Low-Level token peeking and consumption methods.
2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //
2661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenParen - Return true if the cur token is '(' or ')'.
2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenParen() const {
2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren;
2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBracket - Return true if the cur token is '[' or ']'.
2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBracket() const {
2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square;
2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBrace - Return true if the cur token is '{' or '}'.
2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBrace() const {
2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace;
2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenStringLiteral - True if this token is a string-literal.
2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenStringLiteral() const {
2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::string_literal ||
2845cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor           Tok.getKind() == tok::wide_string_literal ||
2855cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor           Tok.getKind() == tok::utf8_string_literal ||
2865cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor           Tok.getKind() == tok::utf16_string_literal ||
2875cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor           Tok.getKind() == tok::utf32_string_literal;
2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
289eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
290fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu  /// \brief Returns true if the current token is '=' or is a type of '='.
291fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu  /// For typos, give a fixit to '='
292fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu  bool isTokenEqualOrEqualTypo();
293a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeToken - Consume the current 'peek token' and lex the next one.
295d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu  /// This does not work with all kinds of tokens: strings and specific other
2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tokens must be consumed with custom methods below.  This returns the
2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// location of the consumed token.
2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeToken() {
2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() &&
3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           !isTokenBrace() &&
3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should consume special tokens with Consume*Token");
3027d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis
3037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    if (Tok.is(tok::code_completion))
3047d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis      return handleUnexpectedCodeCompletionToken();
3057d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis
3064b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3084b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// current token type.  This should only be used in cases where the type of
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the token really isn't known, e.g. in error recovery.
3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeAnyToken() {
3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isTokenParen())
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeParen();
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBracket())
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBracket();
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBrace())
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBrace();
321d62701bc5321049353017e9abf1963edd57646aaSteve Naroff    else if (isTokenStringLiteral())
322d62701bc5321049353017e9abf1963edd57646aaSteve Naroff      return ConsumeStringToken();
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeToken();
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeParen - This consume method keeps the paren count up-to-date.
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeParen() {
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenParen() && "wrong consume method");
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_paren)
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++ParenCount;
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (ParenCount)
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --ParenCount;       // Don't let unbalanced )'s drive the count negative.
3354b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3374b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBracket - This consume method keeps the bracket count up-to-date.
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBracket() {
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBracket() && "wrong consume method");
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_square)
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BracketCount;
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BracketCount)
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BracketCount;     // Don't let unbalanced ]'s drive the count negative.
3481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3494b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3514b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBrace - This consume method keeps the brace count up-to-date.
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBrace() {
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBrace() && "wrong consume method");
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_brace)
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BraceCount;
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BraceCount)
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BraceCount;     // Don't let unbalanced }'s drive the count negative.
3621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3634b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3654b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeStringToken - Consume the current 'peek token', lexing a new one
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// and returning the token kind.  This method is specific to strings, as it
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// handles string literal concatenation, as per C99 5.1.1.2, translation
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// phase #6.
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeStringToken() {
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenStringLiteral() &&
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should only consume string literals with this method");
3754b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3774b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
380dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// \brief Consume the current code-completion token.
381dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  ///
382dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// This routine should be called to consume the code-completion token once
383dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// a code-completion action has already been invoked.
384dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  SourceLocation ConsumeCodeCompletionToken() {
385dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    assert(Tok.is(tok::code_completion));
386dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    PrevTokLocation = Tok.getLocation();
387dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    PP.Lex(Tok);
388a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    return PrevTokLocation;
389dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  }
390a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
3917d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  ///\ brief When we are consuming a code-completion token without having
392dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// matched specific position in the grammar, provide code-completion results
393dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// based on context.
3947d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  ///
3957d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  /// \returns the source location of the code-completion token.
3967d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  SourceLocation handleUnexpectedCodeCompletionToken();
3977d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis
3987d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  /// \brief Abruptly cut off parsing; mainly used when we have reached the
3997d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  /// code-completion point.
4007d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  void cutOffParsing() {
4017d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    PP.setCodeCompletionReached();
4027d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    // Cut off parsing by acting as if we reached the end-of-file.
4037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis    Tok.setKind(tok::eof);
4047d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis  }
405dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor
406b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis  /// \brief Handle the annotation token produced for #pragma unused(...)
407b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis  void HandlePragmaUnused();
408b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis
409426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola  /// \brief Handle the annotation token produced for
410426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola  /// #pragma GCC visibility...
411426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola  void HandlePragmaVisibility();
412426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola
413aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman  /// \brief Handle the annotation token produced for
414aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman  /// #pragma pack...
415aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman  void HandlePragmaPack();
416aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman
4176b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// GetLookAheadToken - This peeks ahead N tokens and returns that token
4186b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// without consuming any tokens.  LookAhead(0) returns 'Tok', LookAhead(1)
4196b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// returns the token after Tok, etc.
4206b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
4216b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// Note that this differs from the Preprocessor's LookAhead method, because
4226b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// the Parser always has one token lexed that the preprocessor doesn't.
4236b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
42403db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis  const Token &GetLookAheadToken(unsigned N) {
4256b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    if (N == 0 || Tok.is(tok::eof)) return Tok;
4266b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    return PP.LookAhead(N-1);
4276b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  }
428f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis
429f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// NextToken - This peeks ahead one token and returns it without
430f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// consuming it.
431f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  const Token &NextToken() {
43203db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis    return PP.LookAhead(0);
433f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  }
4345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
435d3891e9fb7eb25436e5c537189030bed0d5a1dcfDouglas Gregor  class BalancedDelimiterTracker;
436d3891e9fb7eb25436e5c537189030bed0d5a1dcfDouglas Gregor
437a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// \brief Tracks information about the current nesting depth of
4384a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  /// opening delimiters of each kind.
4394a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  class DelimiterTracker {
4404a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  private:
4414a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    friend class Parser;
442d3891e9fb7eb25436e5c537189030bed0d5a1dcfDouglas Gregor    friend class BalancedDelimiterTracker;
4434a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4444a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    unsigned Paren, Brace, Square, Less, LLLess;
4454a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    unsigned& get(tok::TokenKind t) {
4464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      switch (t) {
4474a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      default: llvm_unreachable("Unexpected balanced token");
4484a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_brace:  return Brace;
4494a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_paren:  return Paren;
4504a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_square: return Square;
4514a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::less:  return Less;
4524a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::lesslessless:  return LLLess;
4534a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      }
4544a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4554a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    void push(tok::TokenKind t) {
4574a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      get(t)++;
4584a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4594a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4604a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    void pop(tok::TokenKind t) {
4614a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      get(t)--;
4624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4634a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4644a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    unsigned getDepth(tok::TokenKind t) {
4654a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      return get(t);
4664a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4674a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4684a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  public:
4694a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    DelimiterTracker() : Paren(0), Brace(0), Square(0), Less(0), LLLess(0) { }
4704a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  };
4714a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4724a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  /// \brief RAII class that helps handle the parsing of an open/close delimiter
4734a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  /// pair, such as braces { ... } or parentheses ( ... ).
4744a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  class BalancedDelimiterTracker {
4754a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    tok::TokenKind Kind, Close;
4764a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    Parser& P;
4774a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    bool Cleanup;
4784a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    const unsigned MaxDepth;
4794a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    SourceLocation LOpen, LClose;
480a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
4814a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    void assignClosingDelimiter() {
4824a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      switch (Kind) {
4834a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      default: llvm_unreachable("Unexpected balanced token");
4844a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_brace:  Close = tok::r_brace; break;
4854a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_paren:  Close = tok::r_paren; break;
4864a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::l_square: Close = tok::r_square; break;
4874a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::less:  Close = tok::greater; break;
4884a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      case tok::lesslessless:  Close = tok::greatergreatergreater; break;
4894a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      }
4904a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4914a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4924a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  public:
493a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    BalancedDelimiterTracker(Parser& p, tok::TokenKind k)
4944a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      : Kind(k), P(p), Cleanup(false), MaxDepth(256) {
4954a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      assignClosingDelimiter();
4964a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
4974a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
4984a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    ~BalancedDelimiterTracker() {
4994a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor      if (Cleanup)
5004a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor        P.QuantityTracker.pop(Kind);
5014a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    }
5024a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
5034a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    SourceLocation getOpenLocation() const { return LOpen; }
5044a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    SourceLocation getCloseLocation() const { return LClose; }
5054a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    SourceRange getRange() const { return SourceRange(LOpen, LClose); }
5064a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
5074a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    bool consumeOpen();
508a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    bool expectAndConsume(unsigned DiagID,
509a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                          const char *Msg = "",
5104a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                          tok::TokenKind SkipToTok = tok::unknown);
5114a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor    bool consumeClose();
5123896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    void skipToEnd();
5134a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  };
5144a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
5154a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  DelimiterTracker QuantityTracker;
5164a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor
517b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  /// getTypeAnnotation - Read a parsed type out of an annotation token.
518b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  static ParsedType getTypeAnnotation(Token &Tok) {
519b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue());
520b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
521b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
522b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  static void setTypeAnnotation(Token &Tok, ParsedType T) {
523b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    Tok.setAnnotationValue(T.getAsOpaquePtr());
524b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
525a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5265ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  /// \brief Read an already-translated primary expression out of an annotation
5275ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  /// token.
5285ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  static ExprResult getExprAnnotation(Token &Tok) {
5295ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor    if (Tok.getAnnotationValue())
5305ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor      return ExprResult((Expr *)Tok.getAnnotationValue());
531a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5325ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor    return ExprResult(true);
5335ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  }
534a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5355ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  /// \brief Set the primary expression corresponding to the given annotation
5365ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  /// token.
5375ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  static void setExprAnnotation(Token &Tok, ExprResult ER) {
5385ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor    if (ER.isInvalid())
5395ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor      Tok.setAnnotationValue(0);
5405ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor    else
5415ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor      Tok.setAnnotationValue(ER.get());
5425ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  }
543b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
544fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain  // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to
545fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain  // find a type name by attempting typo correction.
546fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain  bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false,
547fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain                                   bool NeedType = false);
548495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor  bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
549eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
55082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens,
55182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// replacing them with the non-context-sensitive keywords.  This returns
55282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// true if the token was replaced.
55382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
554b3a4e432c90be98c6d918087750397e86d030368Chris Lattner                       const char *&PrevSpec, unsigned &DiagID,
555b3a4e432c90be98c6d918087750397e86d030368Chris Lattner                       bool &isInvalid) {
5561b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner    if (!getLang().AltiVec ||
5571b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner        (Tok.getIdentifierInfo() != Ident_vector &&
5581b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner         Tok.getIdentifierInfo() != Ident_pixel))
5591b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner      return false;
560a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5611b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner    return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
56282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
56382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
56482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector
56582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// identifier token, replacing it with the non-context-sensitive __vector.
56682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// This returns true if the token was replaced.
56782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool TryAltiVecVectorToken() {
568b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    if (!getLang().AltiVec ||
569b3a4e432c90be98c6d918087750397e86d030368Chris Lattner        Tok.getIdentifierInfo() != Ident_vector) return false;
5701b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner    return TryAltiVecVectorTokenOutOfLine();
57182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
572a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
5731b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner  bool TryAltiVecVectorTokenOutOfLine();
5741b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner  bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
5751b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner                                const char *&PrevSpec, unsigned &DiagID,
5761b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner                                bool &isInvalid);
57725a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis
57825a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// \brief Get the TemplateIdAnnotation from the token and put it in the
57925a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// cleanup pool so that it gets destroyed when parsing the current top level
58025a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  /// declaration is finished.
58125a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis  TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok);
58225a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis
5835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// TentativeParsingAction - An object that is used as a kind of "tentative
5845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// parsing transaction". It gets instantiated to mark the token position and
5855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// after the token consumption is done, Commit() or Revert() is called to
5865404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// either "commit the consumed tokens" or revert to the previously marked
5875404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// token position. Example:
5885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
589314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  ///   TentativeParsingAction TPA(*this);
5905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ConsumeToken();
5915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ....
5925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   TPA.Revert();
5935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
5945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  class TentativeParsingAction {
5955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Parser &P;
5965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Token PrevTok;
5975404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    bool isActive;
5985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
5995404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  public:
6005404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    explicit TentativeParsingAction(Parser& p) : P(p) {
6015404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      PrevTok = P.Tok;
6025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.EnableBacktrackAtThisPos();
6035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = true;
6045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
6055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Commit() {
6065404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
6075404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.CommitBacktrackedTokens();
6085404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
6095404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
6105404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Revert() {
6115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
6125404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.Backtrack();
6135404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.Tok = PrevTok;
6145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
6155404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
6165404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    ~TentativeParsingAction() {
6175404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(!isActive && "Forgot to call Commit or Revert!");
6185404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
6195404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  };
6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6219735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  /// ObjCDeclContextSwitch - An object used to switch context from
6229735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  /// an objective-c decl context to its enclosing decl context and
6239735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  /// back.
6249735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  class ObjCDeclContextSwitch {
6259735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    Parser &P;
6269735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    Decl *DC;
6279735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  public:
628a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    explicit ObjCDeclContextSwitch(Parser &p) : P(p),
6299735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian               DC(p.getObjCDeclContext()) {
6309735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian      if (DC)
631458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis        P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC));
6329735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    }
6339735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    ~ObjCDeclContextSwitch() {
6349735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian      if (DC)
635458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis        P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC));
6369735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian    }
6379735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian  };
6381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// input.  If so, it is consumed and false is returned.
6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If the input is malformed, this emits the specified diagnostic.  Next, if
6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipToTok is specified, it calls SkipUntil(SkipToTok).  Finally, true is
6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// returned.
6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag,
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        const char *DiagMsg = "",
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        tok::TokenKind SkipToTok = tok::unknown);
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6499ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// \brief The parser expects a semicolon and, if present, will consume it.
6509ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  ///
6519ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// If the next token is not a semicolon, this emits the specified diagnostic,
6529ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior
6539ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// to the semicolon, consumes that extra token.
6549ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  bool ExpectAndConsumeSemi(unsigned DiagID);
655a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Scope manipulation
6581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6598935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// ParseScope - Introduces a new scope for parsing. The kind of
6608935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// scope is determined by ScopeFlags. Objects of this type should
6618935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// be created on the stack to coincide with the position where the
6628935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// parser enters the new scope, and this object's constructor will
6638935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// create that new scope. Similarly, once the object is destroyed
6648935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// the parser will exit the scope.
6658935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  class ParseScope {
6668935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    Parser *Self;
6678935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope(const ParseScope&); // do not implement
6688935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope& operator=(const ParseScope&); // do not implement
6698935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
6708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  public:
6718935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ParseScope - Construct a new object to manage a scope in the
6728935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // parser Self where the new Scope is created with the flags
6738935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ScopeFlags, but only when ManageScope is true (the default). If
6748935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ManageScope is false, this object does nothing.
6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true)
6768935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      : Self(Self) {
6778935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (ManageScope)
6788935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->EnterScope(ScopeFlags);
6798935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      else
6808935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        this->Self = 0;
6818935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
6828935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
6838935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // Exit - Exit the scope associated with this object now, rather
6848935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // than waiting until the object is destroyed.
6858935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    void Exit() {
6868935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (Self) {
6878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->ExitScope();
6888935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self = 0;
6898935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      }
6908935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
6918935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
6928935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ~ParseScope() {
6938935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      Exit();
6948935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
6958935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  };
6968935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EnterScope - Start a new scope.
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EnterScope(unsigned ScopeFlags);
6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExitScope - Pop a scope off the scope stack.
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ExitScope();
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7037a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// \brief RAII object used to modify the scope flags for the current scope.
7047a614d8380297fcd2bc23986241905d97222948cRichard Smith  class ParseScopeFlags {
7057a614d8380297fcd2bc23986241905d97222948cRichard Smith    Scope *CurScope;
7067a614d8380297fcd2bc23986241905d97222948cRichard Smith    unsigned OldFlags;
7077a614d8380297fcd2bc23986241905d97222948cRichard Smith    ParseScopeFlags(const ParseScopeFlags &); // do not implement
7087a614d8380297fcd2bc23986241905d97222948cRichard Smith    void operator=(const ParseScopeFlags &); // do not implement
7097a614d8380297fcd2bc23986241905d97222948cRichard Smith
7107a614d8380297fcd2bc23986241905d97222948cRichard Smith  public:
7117a614d8380297fcd2bc23986241905d97222948cRichard Smith    ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true);
7127a614d8380297fcd2bc23986241905d97222948cRichard Smith    ~ParseScopeFlags();
7137a614d8380297fcd2bc23986241905d97222948cRichard Smith  };
7147a614d8380297fcd2bc23986241905d97222948cRichard Smith
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Diagnostic Emission and Error recovery.
71715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
7186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic:
7193cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
7203cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
72115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
7226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate:
7231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SuggestParentheses(SourceLocation Loc, unsigned DK,
7244b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor                          SourceRange ParenRange);
725d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  void CheckNestedObjCContexts(SourceLocation AtLoc);
7264b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipUntil - Read tokens until we get to the specified token, then consume
72882c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff  /// it (unless DontConsume is true).  Because we cannot guarantee that the
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// token will ever occur, this skips to the next token, or to some likely
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// good stopping point.  If StopAtSemi is true, skipping will stop at a ';'
7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// character.
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If SkipUntil finds the specified token, it returns true, otherwise it
7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returns false.
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
7363437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool DontConsume = false, bool StopAtCodeCompletion = false) {
7373437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis    return SkipUntil(&T, 1, StopAtSemi, DontConsume, StopAtCodeCompletion);
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
7403437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool DontConsume = false, bool StopAtCodeCompletion = false) {
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    tok::TokenKind TokArray[] = {T1, T2};
7423437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis    return SkipUntil(TokArray, 2, StopAtSemi, DontConsume,StopAtCodeCompletion);
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
7453437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool StopAtSemi = true, bool DontConsume = false,
7463437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool StopAtCodeCompletion = false);
7477ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
7494cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // Lexing and parsing of C++ inline methods.
7504cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
751d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  struct ParsingClass;
752d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
753d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// [class.mem]p1: "... the class is regarded as complete within
754d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - function bodies
755d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - default arguments
756d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - exception-specifications (TODO: C++0x)
7577a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// - and brace-or-equal-initializers for non-static data members
7587a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// (including such things in nested classes)."
759d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// LateParsedDeclarations build the tree of those elements so they can
760d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// be parsed after parsing the top-level class.
761d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  class LateParsedDeclaration {
762d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  public:
763d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual ~LateParsedDeclaration();
764d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
765d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDeclarations();
7667a614d8380297fcd2bc23986241905d97222948cRichard Smith    virtual void ParseLexedMemberInitializers();
767d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDefs();
768eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    virtual void ParseLexedAttributes();
769d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  };
770d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
771d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// Inner node of the LateParsedDeclaration tree that parses
772d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// all its members recursively.
773d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  class LateParsedClass : public LateParsedDeclaration {
774d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  public:
775d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    LateParsedClass(Parser *P, ParsingClass *C);
776d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual ~LateParsedClass();
777d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
778d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDeclarations();
7797a614d8380297fcd2bc23986241905d97222948cRichard Smith    virtual void ParseLexedMemberInitializers();
780d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDefs();
781eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    virtual void ParseLexedAttributes();
782d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
783d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  private:
784d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    Parser *Self;
785d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    ParsingClass *Class;
786d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  };
787d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
788a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// Contains the lexed tokens of an attribute with arguments that
789a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// may reference member variables and so need to be parsed at the
790a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// end of the class declaration after parsing all other member
791eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  /// member declarations.
792eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  /// FIXME: Perhaps we should change the name of LateParsedDeclaration to
793eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  /// LateParsedTokens.
794eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  struct LateParsedAttribute : public LateParsedDeclaration {
795eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    Parser *Self;
796eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    CachedTokens Toks;
797eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    IdentifierInfo &AttrName;
798eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    SourceLocation AttrNameLoc;
7992287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins    SmallVector<Decl*, 2> Decls;
800eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
801a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name,
802eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                                 SourceLocation Loc)
8032287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins      : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
804eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
805eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski    virtual void ParseLexedAttributes();
806eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
8072287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins    void addDecl(Decl *D) { Decls.push_back(D); }
808eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  };
809eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
810eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  /// A list of late parsed attributes.  Used by ParseGNUAttributes.
811eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  typedef llvm::SmallVector<LateParsedAttribute*, 2> LateParsedAttrList;
812eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
813eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski
814d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// Contains the lexed tokens of a member function definition
815d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// which needs to be parsed at the end of the class declaration
816d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// after parsing all other member declarations.
817d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  struct LexedMethod : public LateParsedDeclaration {
818d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    Parser *Self;
819d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *D;
82072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    CachedTokens Toks;
821d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor
822d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// \brief Whether this member function had an associated template
823d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// scope. When true, D is a template declaration.
824d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// othewise, it is a member function declaration.
825d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    bool TemplateScope;
826d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor
827d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    explicit LexedMethod(Parser* P, Decl *MD)
828d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor      : Self(P), D(MD), TemplateScope(false) {}
829d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
830d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDefs();
8314cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  };
8324cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
83372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// LateParsedDefaultArgument - Keeps track of a parameter that may
83472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// have a default argument that cannot be parsed yet because it
83572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// occurs within a member function declaration inside the class
83672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// (C++ [class.mem]p2).
83772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  struct LateParsedDefaultArgument {
838d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    explicit LateParsedDefaultArgument(Decl *P,
83972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor                                       CachedTokens *Toks = 0)
84072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor      : Param(P), Toks(Toks) { }
84172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
84272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Param - The parameter declaration for this parameter.
843d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Param;
84472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
84572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Toks - The sequence of tokens that comprises the default
84672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// argument expression, not including the '=' or the terminating
84772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// ')' or ','. This will be NULL for parameters that have no
84872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// default argument.
84972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    CachedTokens *Toks;
85072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// LateParsedMethodDeclaration - A method declaration inside a class that
85372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// contains at least one entity whose parsing needs to be delayed
85472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// until the class itself is completely-defined, such as a default
85572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// argument (C++ [class.mem]p2).
856d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  struct LateParsedMethodDeclaration : public LateParsedDeclaration {
857d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    explicit LateParsedMethodDeclaration(Parser *P, Decl *M)
858d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor      : Self(P), Method(M), TemplateScope(false) { }
859d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
860d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDeclarations();
861d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
862d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    Parser* Self;
86372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
86472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Method - The method declaration.
865d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Method;
86672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
867d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// \brief Whether this member function had an associated template
868d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// scope. When true, D is a template declaration.
869d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// othewise, it is a member function declaration.
870d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    bool TemplateScope;
8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// DefaultArgs - Contains the parameters of the function and
87372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// their default arguments. At least one of the parameters will
87472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// have a default argument, but all of the parameters of the
87572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// method will be stored so that they can be reintroduced into
8761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// scope at the appropriate times.
877686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
87872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
87972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
8807a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// LateParsedMemberInitializer - An initializer for a non-static class data
8817a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// member whose parsing must to be delayed until the class is completely
8827a614d8380297fcd2bc23986241905d97222948cRichard Smith  /// defined (C++11 [class.mem]p2).
8837a614d8380297fcd2bc23986241905d97222948cRichard Smith  struct LateParsedMemberInitializer : public LateParsedDeclaration {
8847a614d8380297fcd2bc23986241905d97222948cRichard Smith    LateParsedMemberInitializer(Parser *P, Decl *FD)
8857a614d8380297fcd2bc23986241905d97222948cRichard Smith      : Self(P), Field(FD) { }
8867a614d8380297fcd2bc23986241905d97222948cRichard Smith
8877a614d8380297fcd2bc23986241905d97222948cRichard Smith    virtual void ParseLexedMemberInitializers();
8887a614d8380297fcd2bc23986241905d97222948cRichard Smith
8897a614d8380297fcd2bc23986241905d97222948cRichard Smith    Parser *Self;
8907a614d8380297fcd2bc23986241905d97222948cRichard Smith
8917a614d8380297fcd2bc23986241905d97222948cRichard Smith    /// Field - The field declaration.
8927a614d8380297fcd2bc23986241905d97222948cRichard Smith    Decl *Field;
8937a614d8380297fcd2bc23986241905d97222948cRichard Smith
8947a614d8380297fcd2bc23986241905d97222948cRichard Smith    /// CachedTokens - The sequence of tokens that comprises the initializer,
8957a614d8380297fcd2bc23986241905d97222948cRichard Smith    /// including any leading '='.
8967a614d8380297fcd2bc23986241905d97222948cRichard Smith    CachedTokens Toks;
8977a614d8380297fcd2bc23986241905d97222948cRichard Smith  };
8987a614d8380297fcd2bc23986241905d97222948cRichard Smith
899d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// LateParsedDeclarationsContainer - During parsing of a top (non-nested)
900d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// C++ class, its method declarations that contain parts that won't be
901fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// parsed until after the definition is completed (C++ [class.mem]p2),
902d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// the method declarations and possibly attached inline definitions
903a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// will be stored here with the tokens that will be parsed to create those
904a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// entities.
905a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer;
90672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
9076569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// \brief Representation of a class that has been parsed, including
9086569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// any member function declarations or definitions that need to be
9096569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// parsed after the corresponding top-level class is complete.
9106569d68745c8213709740337d2be52b031384f58Douglas Gregor  struct ParsingClass {
911d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    ParsingClass(Decl *TagOrTemplate, bool TopLevelClass)
9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : TopLevelClass(TopLevelClass), TemplateScope(false),
9136569d68745c8213709740337d2be52b031384f58Douglas Gregor        TagOrTemplate(TagOrTemplate) { }
9146569d68745c8213709740337d2be52b031384f58Douglas Gregor
9156569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Whether this is a "top-level" class, meaning that it is
9166569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// not nested within another class.
9176569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool TopLevelClass : 1;
9186569d68745c8213709740337d2be52b031384f58Douglas Gregor
9196569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Whether this class had an associated template
9206569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// scope. When true, TagOrTemplate is a template declaration;
9216569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// othewise, it is a tag declaration.
9226569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool TemplateScope : 1;
9236569d68745c8213709740337d2be52b031384f58Douglas Gregor
9246569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief The class or class template whose definition we are parsing.
925d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *TagOrTemplate;
92672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
927d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    /// LateParsedDeclarations - Method declarations, inline definitions and
928d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    /// nested classes that contain pieces whose parsing will be delayed until
929d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    /// the top-level class is fully defined.
930d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    LateParsedDeclarationsContainer LateParsedDeclarations;
93172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
9324cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
9336569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// \brief The stack of classes that is currently being
9346569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// parsed. Nested and local classes will be pushed onto this stack
9356569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// when they are parsed, and removed afterward.
9366569d68745c8213709740337d2be52b031384f58Douglas Gregor  std::stack<ParsingClass *> ClassStack;
9374cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
9386569d68745c8213709740337d2be52b031384f58Douglas Gregor  ParsingClass &getCurrentClass() {
9396569d68745c8213709740337d2be52b031384f58Douglas Gregor    assert(!ClassStack.empty() && "No lexed method stacks!");
9406569d68745c8213709740337d2be52b031384f58Douglas Gregor    return *ClassStack.top();
9414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
9424cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
94354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// \brief RAII object used to inform the actions that we're
94454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// currently parsing a declaration.  This is active when parsing a
94554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// variable's initializer, but not when parsing the body of a
94654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// class or function definition.
94754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclRAIIObject {
948f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    Sema &Actions;
949eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall    Sema::ParsingDeclState State;
95054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    bool Popped;
951c9068d7dd94d439cec66c421115d15303e481025John McCall
95254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
95354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) {
95454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      push();
95554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
95654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
957c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *Other)
958c9068d7dd94d439cec66c421115d15303e481025John McCall        : Actions(P.Actions) {
959c9068d7dd94d439cec66c421115d15303e481025John McCall      if (Other) steal(*Other);
960c9068d7dd94d439cec66c421115d15303e481025John McCall      else push();
961c9068d7dd94d439cec66c421115d15303e481025John McCall    }
962c9068d7dd94d439cec66c421115d15303e481025John McCall
963c9068d7dd94d439cec66c421115d15303e481025John McCall    /// Creates a RAII object which steals the state from a different
964c9068d7dd94d439cec66c421115d15303e481025John McCall    /// object instead of pushing.
965c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclRAIIObject(ParsingDeclRAIIObject &Other)
966c9068d7dd94d439cec66c421115d15303e481025John McCall        : Actions(Other.Actions) {
967c9068d7dd94d439cec66c421115d15303e481025John McCall      steal(Other);
968c9068d7dd94d439cec66c421115d15303e481025John McCall    }
969c9068d7dd94d439cec66c421115d15303e481025John McCall
97054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ~ParsingDeclRAIIObject() {
97154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      abort();
97254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
97354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
97454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// Resets the RAII object for a new declaration.
97554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void reset() {
97654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      abort();
97754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      push();
97854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
97954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
98054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// Signals that the context was completed without an appropriate
98154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// declaration being parsed.
98254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void abort() {
983d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      pop(0);
98454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
98554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
986d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void complete(Decl *D) {
98754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      assert(!Popped && "ParsingDeclaration has already been popped!");
98854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      pop(D);
98954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
99054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
99154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  private:
992c9068d7dd94d439cec66c421115d15303e481025John McCall    void steal(ParsingDeclRAIIObject &Other) {
993c9068d7dd94d439cec66c421115d15303e481025John McCall      State = Other.State;
994c9068d7dd94d439cec66c421115d15303e481025John McCall      Popped = Other.Popped;
995c9068d7dd94d439cec66c421115d15303e481025John McCall      Other.Popped = true;
996c9068d7dd94d439cec66c421115d15303e481025John McCall    }
997a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
99854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void push() {
99954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      State = Actions.PushParsingDeclaration();
100054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      Popped = false;
100154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
100254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
1003d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void pop(Decl *D) {
100454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      if (!Popped) {
100554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall        Actions.PopParsingDeclaration(State, D);
100654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall        Popped = true;
100754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      }
100854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
100954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
101054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
101154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// A class for parsing a DeclSpec.
101254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclSpec : public DeclSpec {
101354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject ParsingRAII;
101454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
101554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
10160b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    ParsingDeclSpec(Parser &P) : DeclSpec(P.AttrFactory), ParsingRAII(P) {}
1017c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII)
10180b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      : DeclSpec(P.AttrFactory), ParsingRAII(P, RAII) {}
101954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
1020d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void complete(Decl *D) {
102154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.complete(D);
102254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
102354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
102454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void abort() {
102554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.abort();
102654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
102754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
102854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
102954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// A class for parsing a declarator.
103054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclarator : public Declarator {
103154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject ParsingRAII;
103254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
103354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
103454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C)
103554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      : Declarator(DS, C), ParsingRAII(P) {
103654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
103754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
103854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    const ParsingDeclSpec &getDeclSpec() const {
103954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec());
104054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
104154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
104254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclSpec &getMutableDeclSpec() const {
104354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      return const_cast<ParsingDeclSpec&>(getDeclSpec());
104454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
104554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
104654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void clear() {
104754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      Declarator::clear();
104854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.reset();
104954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
105054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
1051d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void complete(Decl *D) {
105254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.complete(D);
105354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
105454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
105554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
10561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief RAII object used to
10576569d68745c8213709740337d2be52b031384f58Douglas Gregor  class ParsingClassDefinition {
10586569d68745c8213709740337d2be52b031384f58Douglas Gregor    Parser &P;
10596569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool Popped;
1060eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall    Sema::ParsingClassState State;
10616569d68745c8213709740337d2be52b031384f58Douglas Gregor
10626569d68745c8213709740337d2be52b031384f58Douglas Gregor  public:
1063d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass)
1064eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall      : P(P), Popped(false),
1065eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall        State(P.PushParsingClass(TagOrTemplate, TopLevelClass)) {
10666569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
10676569d68745c8213709740337d2be52b031384f58Douglas Gregor
10686569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Pop this class of the stack.
10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    void Pop() {
10706569d68745c8213709740337d2be52b031384f58Douglas Gregor      assert(!Popped && "Nested class has already been popped");
10716569d68745c8213709740337d2be52b031384f58Douglas Gregor      Popped = true;
1072eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall      P.PopParsingClass(State);
10736569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
10746569d68745c8213709740337d2be52b031384f58Douglas Gregor
10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ~ParsingClassDefinition() {
10766569d68745c8213709740337d2be52b031384f58Douglas Gregor      if (!Popped)
1077eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall        P.PopParsingClass(State);
10786569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
10796569d68745c8213709740337d2be52b031384f58Douglas Gregor  };
10806569d68745c8213709740337d2be52b031384f58Douglas Gregor
10814d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// \brief Contains information about any template-specific
10824d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// information that has been parsed prior to parsing declaration
10834d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// specifiers.
10844d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  struct ParsedTemplateInfo {
10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParsedTemplateInfo()
10864d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { }
10874d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
10884d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
1089c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor                       bool isSpecialization,
1090c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor                       bool lastParameterListWasEmpty = false)
10914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      : Kind(isSpecialization? ExplicitSpecialization : Template),
1092a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie        TemplateParams(TemplateParams),
1093c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        LastParameterListWasEmpty(lastParameterListWasEmpty) { }
10944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
109545f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    explicit ParsedTemplateInfo(SourceLocation ExternLoc,
109645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor                                SourceLocation TemplateLoc)
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : Kind(ExplicitInstantiation), TemplateParams(0),
1098c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1099c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        LastParameterListWasEmpty(false){ }
11004d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
11014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The kind of template we are parsing.
11024d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    enum {
11034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are not parsing a template at all.
11044d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      NonTemplate = 0,
11054d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing a template declaration.
11064d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      Template,
11074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing an explicit specialization.
11084d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      ExplicitSpecialization,
11094d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing an explicit instantiation.
11104d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      ExplicitInstantiation
11114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    } Kind;
11124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
11134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The template parameter lists, for template declarations
11144d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// and explicit specializations.
11154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    TemplateParameterLists *TemplateParams;
11164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
111745f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    /// \brief The location of the 'extern' keyword, if any, for an explicit
111845f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    /// instantiation
111945f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    SourceLocation ExternLoc;
11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11214d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The location of the 'template' keyword, for an explicit
11224d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// instantiation.
11234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    SourceLocation TemplateLoc;
1124a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1125c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor    /// \brief Whether the last template parameter list was empty.
1126c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor    bool LastParameterListWasEmpty;
112778b810559d89e996e00684335407443936ce34a1John McCall
112878b810559d89e996e00684335407443936ce34a1John McCall    SourceRange getSourceRange() const;
11294d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  };
11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11318387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  /// \brief Contains a late templated function.
11328387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  /// Will be parsed at the end of the translation unit.
11338387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  struct LateParsedTemplatedFunction {
1134e1fca502e7f1349e9b4520a4ca9a02413bcf2b14Francois Pichet    explicit LateParsedTemplatedFunction(Decl *MD)
11358387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet      : D(MD) {}
11368387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet
11378387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet    CachedTokens Toks;
1138a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
11398387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet    /// \brief The template function declaration to be late parsed.
1140a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    Decl *D;
11418387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  };
11428387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet
11438387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  void LexTemplateFunctionForLateParsing(CachedTokens &Toks);
11448387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  void ParseLateTemplatedFuncDef(LateParsedTemplatedFunction &LMT);
11458387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  typedef llvm::DenseMap<const FunctionDecl*, LateParsedTemplatedFunction*>
11468387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet    LateParsedTemplateMapT;
11478387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet  LateParsedTemplateMapT LateParsedTemplateMap;
11488387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet
11494a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet  static void LateTemplateParserCallback(void *P, const FunctionDecl *FD);
11504a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet  void LateTemplateParser(const FunctionDecl *FD);
11518387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet
1152eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  Sema::ParsingClassState
1153eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass);
115437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void DeallocateParsedClasses(ParsingClass *Class);
1155eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  void PopParsingClass(Sema::ParsingClassState);
115637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor
11575f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen  Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, AttributeList *AccessAttrs,
11585f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                ParsingDeclarator &D,
11594867347e82648d3baf09524b98b09c297a5a198fNico Weber                                const ParsedTemplateInfo &TemplateInfo,
1160a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie                                const VirtSpecifiers& VS,
116145fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor                                FunctionDefinitionKind DefinitionKind,
116245fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor                                ExprResult& Init);
11637a614d8380297fcd2bc23986241905d97222948cRichard Smith  void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1164eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  void ParseLexedAttributes(ParsingClass &Class);
1165c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins  void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1166c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins                               bool EnterScope, bool OnDefinition);
1167c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins  void ParseLexedAttribute(LateParsedAttribute &LA,
1168c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins                           bool EnterScope, bool OnDefinition);
116937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseLexedMethodDeclarations(ParsingClass &Class);
1170d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
117137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseLexedMethodDefs(ParsingClass &Class);
1172d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  void ParseLexedMethodDef(LexedMethod &LM);
11737a614d8380297fcd2bc23986241905d97222948cRichard Smith  void ParseLexedMemberInitializers(ParsingClass &Class);
11747a614d8380297fcd2bc23986241905d97222948cRichard Smith  void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1175140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  Decl *ParseLexedObjCMethodDefs(LexedMethod &LM);
1176a891a32d3762ee641a29c091d286f2a7432671a5Sebastian Redl  bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks);
117714b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis  bool ConsumeAndStoreUntil(tok::TokenKind T1,
117814b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            CachedTokens &Toks,
117914b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            bool StopAtSemi = true,
118014b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            bool ConsumeFinalToken = true) {
118114b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis    return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken);
118214b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis  }
11831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
118437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                            CachedTokens &Toks,
118514b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            bool StopAtSemi = true,
118637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                            bool ConsumeFinalToken = true);
11874d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
11884cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
11895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.9: External Definitions.
11907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct ParsedAttributesWithRange : ParsedAttributes {
11910b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall    ParsedAttributesWithRange(AttributeFactory &factory)
11920b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      : ParsedAttributes(factory) {}
11930b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall
11947f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    SourceRange Range;
11957f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  };
11967f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
11977f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
119809a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor                                          ParsingDeclSpec *DS = 0);
1199e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt  bool isDeclarationAfterDeclarator();
1200004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner  bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
12017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsedAttributes &attrs,
12027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                                  AccessSpecifier AS = AS_none);
12033acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS,
12043acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian                                                  AccessSpecifier AS = AS_none);
1205a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1206d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseFunctionDefinition(ParsingDeclarator &D,
1207c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins                 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1208c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins                 LateParsedAttrList *LateParsedAttrs = 0);
12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseKNRParamDeclarations(Declarator &D);
1210ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // EndLoc, if non-NULL, is filled with the location of the last token of
1211ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // the simple-asm.
121260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0);
121360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseAsmStringLiteral();
12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12153536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  // Objective-C External Declarations
1216bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor  DeclGroupPtrTy ParseObjCAtDirectives();
1217bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor  DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
1218d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen  Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
12197f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                        ParsedAttributes &prefixAttrs);
1220d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
122183c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian                                       tok::ObjCKeywordKind visibility,
122260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                       SourceLocation atLoc);
1223686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P,
1224686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                   SmallVectorImpl<SourceLocation> &PLocs,
12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   bool WarnOnDeclarations,
122671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                   SourceLocation &LAngleLoc,
1227e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                   SourceLocation &EndProtoLoc);
122846f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor  bool ParseObjCProtocolQualifiers(DeclSpec &DS);
12292f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian  void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey,
12302f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian                                  Decl *CDecl);
1231bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor  DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
1232bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor                                                ParsedAttributes &prefixAttrs);
12331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1234849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  struct ObjCImplParsingDataRAII {
1235849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    Parser &P;
1236849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    Decl *Dcl;
1237849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer;
1238849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    LateParsedObjCMethodContainer LateParsedObjCMethods;
1239849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1240849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    ObjCImplParsingDataRAII(Parser &parser, Decl *D)
1241849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      : P(parser), Dcl(D) {
1242849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      P.CurParsedObjCImpl = this;
1243849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis      Finished = false;
1244849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    }
1245849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    ~ObjCImplParsingDataRAII();
1246849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1247849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    void finish(SourceRange AtEnd);
1248849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    bool isFinished() const { return Finished; }
1249849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis
1250849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  private:
1251849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis    bool Finished;
1252849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  };
1253849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  ObjCImplParsingDataRAII *CurParsedObjCImpl;
12540416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
1255849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis  DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc);
1256140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian  DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd);
1257d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1258d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1259d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12612fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
126234870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  // Definitions for Objective-c context sensitive keywords recognition.
126334870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  enum ObjCTypeQual {
126434870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
126534870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_NumQuals
126634870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  };
1267a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1269335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian  bool isTokIdentifier_in() const;
1270d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian
1271cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx,
1272cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                               ParsedAttributes *ParamAttrs);
1273294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  void ParseObjCMethodRequirement();
1274a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  Decl *ParseObjCMethodPrototype(
127590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
127690ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            bool MethodDefinition = true);
1277d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
127890ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
127990ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            bool MethodDefinition=true);
1280a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian  void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1282d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCMethodDefinition();
12831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.5: Expressions.
1286a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1287cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain  /// TypeCastState - State whether an expression is or may be a type cast.
1288cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain  enum TypeCastState {
1289cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain    NotTypeCast = 0,
1290cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain    MaybeTypeCast,
1291cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain    IsTypeCast
1292cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain  };
1293cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain
1294cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain  ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast);
1295e43fe993a079795ac3d2ba7c9ec5e2a0c8069918Kaelyn Uhrain  ExprResult ParseConstantExpression(TypeCastState isTypeCast = NotTypeCast);
12962f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  // Expr that doesn't include commas.
1297cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain  ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast);
12982f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl
129960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
130160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
1302adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman
130360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseRHSOfBinaryExpression(ExprResult LHS,
1304312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                        prec::Level MinPrec);
130560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCastExpression(bool isUnaryExpression,
1306312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                 bool isAddressOfOperand,
1307312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                 bool &NotCastExpr,
1308cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain                                 TypeCastState isTypeCast);
130960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCastExpression(bool isUnaryExpression,
1310312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                 bool isAddressOfOperand = false,
1311cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain                                 TypeCastState isTypeCast = NotTypeCast);
13129c72c6088d591ace8503b842d39448c2040f3033John McCall
13139c72c6088d591ace8503b842d39448c2040f3033John McCall  /// Returns true if the next token would start a postfix-expression
13149c72c6088d591ace8503b842d39448c2040f3033John McCall  /// suffix.
13159c72c6088d591ace8503b842d39448c2040f3033John McCall  bool isPostfixExpressionSuffixStart() {
13169c72c6088d591ace8503b842d39448c2040f3033John McCall    tok::TokenKind K = Tok.getKind();
13179c72c6088d591ace8503b842d39448c2040f3033John McCall    return (K == tok::l_square || K == tok::l_paren ||
13189c72c6088d591ace8503b842d39448c2040f3033John McCall            K == tok::period || K == tok::arrow ||
13199c72c6088d591ace8503b842d39448c2040f3033John McCall            K == tok::plusplus || K == tok::minusminus);
13209c72c6088d591ace8503b842d39448c2040f3033John McCall  }
13219c72c6088d591ace8503b842d39448c2040f3033John McCall
132260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParsePostfixExpressionSuffix(ExprResult LHS);
1323f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult ParseUnaryExprOrTypeTraitExpression();
132460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseBuiltinPrimaryExpression();
13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1326f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
13275ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis                                                     bool &isCastExpr,
1328b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                                     ParsedType &CastTy,
13295ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis                                                     SourceRange &CastRange);
13300cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
1331686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<Expr*, 20> ExprListTy;
1332686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<SourceLocation, 20> CommaLocsTy;
13330cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
13340cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis  /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
1335686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool ParseExpressionList(SmallVectorImpl<Expr*> &Exprs,
1336686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                           SmallVectorImpl<SourceLocation> &CommaLocs,
1337f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                           void (Sema::*Completer)(Scope *S,
1338f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Expr *Data,
133913a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charles                                             llvm::ArrayRef<Expr *> Args) = 0,
1340ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall                           Expr *Data = 0);
1341d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl
13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParenParseOption - Control what ParseParenExpression will parse.
13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ParenParseOption {
13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SimpleExpr,      // Only parse '(' expression ')'
13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundStmt,    // Also allow '(' compound-statement ')'
13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
13475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CastExpr         // Also allow '(' type-name ')' <anything>
13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
134960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseParenExpression(ParenParseOption &ExprType,
13500350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis                                        bool stopIfCastExpr,
13510a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis                                        bool isTypeCast,
1352b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                        ParsedType &CastTy,
1353d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl                                        SourceLocation &RParenLoc);
13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
135560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
13564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                            ParsedType &CastTy,
13574a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                                            BalancedDelimiterTracker &Tracker);
135860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCompoundLiteralExpression(ParsedType Ty,
1359d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis                                                  SourceLocation LParenLoc,
1360d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis                                                  SourceLocation RParenLoc);
13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
136299831e4677a7e2e051af636221694d60ba31fcdbRichard Smith  ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false);
1363eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1364f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ExprResult ParseGenericSelectionExpression();
1365ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
1366ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult ParseObjCBoolLiteral();
1367f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
1368eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
1369eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  // C++ Expressions
137060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
13714bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis
1372950be71c745409e373ae8a834490f9026c8ac222Richard Trieu  void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr,
1373950be71c745409e373ae8a834490f9026c8ac222Richard Trieu                                  bool EnteringContext, IdentifierInfo &II,
1374950be71c745409e373ae8a834490f9026c8ac222Richard Trieu                                  CXXScopeSpec &SS);
1375950be71c745409e373ae8a834490f9026c8ac222Richard Trieu
13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
1377b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                      ParsedType ObjectType,
1378b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor                                      bool EnteringContext,
13794147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet                                      bool *MayBePseudoDestructor = 0,
13804147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet                                      bool IsTypename = false);
13811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1383ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  // C++0x 5.1.2: Lambda expressions
1384ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor
1385ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  // [...] () -> type {...}
1386ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  ExprResult ParseLambdaExpression();
1387ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  ExprResult TryParseLambdaExpression();
1388ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  llvm::Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro);
1389ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  bool TryParseLambdaIntroducer(LambdaIntroducer &Intro);
1390ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  ExprResult ParseLambdaExpressionAfterIntroducer(
1391ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor               LambdaIntroducer &Intro);
1392ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor
1393ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  //===--------------------------------------------------------------------===//
13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 5.2p1: C++ Casts
139560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXCasts();
13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1398c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // C++ 5.2p1: C++ Type Identification
139960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXTypeid();
1400c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
1401c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  //===--------------------------------------------------------------------===//
140201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  //  C++ : Microsoft __uuidof Expression
140301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult ParseCXXUuidof();
140401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
140501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  //===--------------------------------------------------------------------===//
1406d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor  // C++ 5.2.4: C++ Pseudo-Destructor Expressions
140760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc,
1408d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                            tok::TokenKind OpKind,
1409d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                            CXXScopeSpec &SS,
1410b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                            ParsedType ObjectType);
1411d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor
1412d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor  //===--------------------------------------------------------------------===//
14134cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // C++ 9.3.2: C++ 'this' pointer
141460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXThis();
14154cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
14164cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
141750dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  // C++ 15: C++ Throw Expression
141860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseThrowExpression();
14197acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl
14207acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl  ExceptionSpecificationType MaybeParseExceptionSpecification(
14217acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                    SourceRange &SpecificationRange,
1422686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                    SmallVectorImpl<ParsedType> &DynamicExceptions,
1423686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                    SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
14247acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                    ExprResult &NoexceptExpr);
14257acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl
1426ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // EndLoc is filled with the location of the last token of the specification.
14277acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl  ExceptionSpecificationType ParseDynamicExceptionSpecification(
14287acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                                  SourceRange &SpecificationRange,
1429686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                  SmallVectorImpl<ParsedType> &Exceptions,
1430686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                  SmallVectorImpl<SourceRange> &Ranges);
143150dd289f45738ed22b7583d52ed2525b927042ffChris Lattner
143250dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  //===--------------------------------------------------------------------===//
1433dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // C++0x 8: Function declaration trailing-return-type
1434ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor  TypeResult ParseTrailingReturnType(SourceRange &Range);
1435dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
1436dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //===--------------------------------------------------------------------===//
14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 2.13.5: C++ Boolean Literals
143860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXBoolLiteral();
14395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1441987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // C++ 5.2.3: Explicit type conversion (functional notation)
144260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
1443987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
14446aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  bool isCXXSimpleTypeSpecifier() const;
14456aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
1446987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
1447987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// This should only be called when the current token is known to be part of
1448987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// simple-type-specifier.
1449987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1450987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
14512f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor  bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
14522f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor
1453987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
14544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // C++ 5.3.4 and 5.3.5: C++ new and delete
1455686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
1456ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall                                   Declarator &D);
14574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDirectNewDeclarator(Declarator &D);
145860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
145960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXDeleteExpression(bool UseGlobal,
146059232d35f5820e334b6c8b007ae8006f4390055dChris Lattner                                            SourceLocation Start);
14614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
14624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  //===--------------------------------------------------------------------===//
146399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  // C++ if/switch/while condition expression.
146460d7b3a319d84d688752be3870615ac0f111fb16John McCall  bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult,
1465586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                         SourceLocation Loc, bool ConvertToBoolean);
146671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis
146771b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
146812e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  // C++ types
146912e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor
147012e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  //===--------------------------------------------------------------------===//
14715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7.8: Initialization.
14721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14730eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  /// ParseInitializer
14740eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///       initializer: [C99 6.7.8]
14750eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         assignment-expression
14760eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         '{' ...
147760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseInitializer() {
14780eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    if (Tok.isNot(tok::l_brace))
147920df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl      return ParseAssignmentExpression();
14800eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    return ParseBraceInitializer();
14810eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  }
1482b3f323d6c41cb614a249dbc4af7493762786521aDouglas Gregor  bool MayBeDesignationStart();
148360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseBraceInitializer();
148460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseInitializerWithPotentialDesignator();
14851d922960e083906a586609ac6978678147250177Sebastian Redl
14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1487296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  // clang Expressions
14881d922960e083906a586609ac6978678147250177Sebastian Redl
148960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseBlockLiteralExpression();  // ^{...}
1490296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff
1491296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  //===--------------------------------------------------------------------===//
14925508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  // Objective-C Expressions
149360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
149460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
1495ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
1496ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
1497ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc, bool ArgValue);
1498ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
1499ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
150060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
150160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
150260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
15031b730e847ded503f2e615154035c083c4f94a067Douglas Gregor  bool isSimpleObjCMessageExpression();
150460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCMessageExpression();
150560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
15065cb94a78202ccb1007df0be86884297761f4a53aNico Weber                                            SourceLocation SuperLoc,
15075cb94a78202ccb1007df0be86884297761f4a53aNico Weber                                            ParsedType ReceiverType,
15085cb94a78202ccb1007df0be86884297761f4a53aNico Weber                                            ExprArg ReceiverExpr);
150960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseAssignmentExprWithObjCMessageExprStart(
15102725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      SourceLocation LBracloc, SourceLocation SuperLoc,
1511b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      ParsedType ReceiverType, ExprArg ReceiverExpr);
15126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr);
1513ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
15145508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  //===--------------------------------------------------------------------===//
15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.8: Statements and Blocks.
151661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
15175cb94a78202ccb1007df0be86884297761f4a53aNico Weber  StmtResult ParseStatement(SourceLocation *TrailingElseLoc = NULL) {
1518c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian    StmtVector Stmts(Actions);
15195cb94a78202ccb1007df0be86884297761f4a53aNico Weber    return ParseStatementOrDeclaration(Stmts, true, TrailingElseLoc);
152061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
1521c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian  StmtResult ParseStatementOrDeclaration(StmtVector& Stmts,
15225cb94a78202ccb1007df0be86884297761f4a53aNico Weber                                         bool OnlyStatement,
15235cb94a78202ccb1007df0be86884297761f4a53aNico Weber                                        SourceLocation *TrailingElseLoc = NULL);
15245ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor  StmtResult ParseExprStatement(ParsedAttributes &Attrs);
15257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseLabeledStatement(ParsedAttributes &Attr);
1526bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu  StmtResult ParseCaseStatement(ParsedAttributes &Attr,
1527bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu                                bool MissingCase = false,
1528bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu                                ExprResult Expr = ExprResult());
15297f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseDefaultStatement(ParsedAttributes &Attr);
15307f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseCompoundStatement(ParsedAttributes &Attr,
1531312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor                                    bool isStmtExpr = false);
1532bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  StmtResult ParseCompoundStatement(ParsedAttributes &Attr,
1533bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor                                    bool isStmtExpr,
1534bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor                                    unsigned ScopeFlags);
153560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
153660d7b3a319d84d688752be3870615ac0f111fb16John McCall  bool ParseParenExprOrCondition(ExprResult &ExprResult,
1537d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                 Decl *&DeclResult,
1538586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                 SourceLocation Loc,
153944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                 bool ConvertToBoolean);
15405cb94a78202ccb1007df0be86884297761f4a53aNico Weber  StmtResult ParseIfStatement(ParsedAttributes &Attr,
15415cb94a78202ccb1007df0be86884297761f4a53aNico Weber                              SourceLocation *TrailingElseLoc);
15425cb94a78202ccb1007df0be86884297761f4a53aNico Weber  StmtResult ParseSwitchStatement(ParsedAttributes &Attr,
15435cb94a78202ccb1007df0be86884297761f4a53aNico Weber                                  SourceLocation *TrailingElseLoc);
15445cb94a78202ccb1007df0be86884297761f4a53aNico Weber  StmtResult ParseWhileStatement(ParsedAttributes &Attr,
15455cb94a78202ccb1007df0be86884297761f4a53aNico Weber                                 SourceLocation *TrailingElseLoc);
15467f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseDoStatement(ParsedAttributes &Attr);
15475cb94a78202ccb1007df0be86884297761f4a53aNico Weber  StmtResult ParseForStatement(ParsedAttributes &Attr,
15485cb94a78202ccb1007df0be86884297761f4a53aNico Weber                               SourceLocation *TrailingElseLoc);
15497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseGotoStatement(ParsedAttributes &Attr);
15507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseContinueStatement(ParsedAttributes &Attr);
15517f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseBreakStatement(ParsedAttributes &Attr);
15527f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseReturnStatement(ParsedAttributes &Attr);
155360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseAsmStatement(bool &msAsm);
15543fedbe1f71c18fba01d39109d606f421a0103a2aEli Friedman  StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
1555a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
15563896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  /// \brief Describes the behavior that should be taken for an __if_exists
15573896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  /// block.
15583896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  enum IfExistsBehavior {
15593896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief Parse the block; this code is always used.
15603896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    IEB_Parse,
15613896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief Skip the block entirely; this code is never used.
15623896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    IEB_Skip,
15633896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief Parse the block as a dependent block, which may be used in
15643896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// some template instantiations but not others.
15653896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    IEB_Dependent
15663896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  };
1567a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1568a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  /// \brief Describes the condition of a Microsoft __if_exists or
15693896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  /// __if_not_exists block.
15703896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  struct IfExistsCondition {
15713896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief The location of the initial keyword.
15723896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    SourceLocation KeywordLoc;
1573a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie    /// \brief Whether this is an __if_exists block (rather than an
15743896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// __if_not_exists block).
15753896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    bool IsIfExists;
1576a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
15773896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief Nested-name-specifier preceding the name.
15783896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    CXXScopeSpec SS;
1579a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
15803896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief The name we're looking for.
15813896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    UnqualifiedId Name;
15823896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor
15833896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// \brief The behavior of this __if_exists or __if_not_exists block
15843896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    /// should.
15853896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor    IfExistsBehavior Behavior;
15863896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor};
1587a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
15883896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor  bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result);
15891e862693c63067ae467b0b3884c44f753cd6e821Francois Pichet  void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
1590563a645de82231a55e221fe655b7188bf8369662Francois Pichet  void ParseMicrosoftIfExistsExternalDeclaration();
1591563a645de82231a55e221fe655b7188bf8369662Francois Pichet  void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType,
1592563a645de82231a55e221fe655b7188bf8369662Francois Pichet                                              AccessSpecifier& CurAS);
15939d24a8be93b28488dbfb9bbe8aa6fe35b21a5b0cFrancois Pichet  bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
15949d24a8be93b28488dbfb9bbe8aa6fe35b21a5b0cFrancois Pichet                                              bool &InitExprsOk);
1595f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu  bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
1596f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu                           SmallVectorImpl<Expr *> &Constraints,
1597f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu                           SmallVectorImpl<Expr *> &Exprs);
1598a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
1599a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  //===--------------------------------------------------------------------===//
1600a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  // C++ 6: Statements and Blocks
1601a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
16027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseCXXTryBlock(ParsedAttributes &Attr);
160360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc);
160460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseCXXCatchBlock();
1605a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
1606a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  //===--------------------------------------------------------------------===//
160728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  // MS: SEH Statements and Blocks
160828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
160928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult ParseSEHTryBlock(ParsedAttributes &Attr);
161028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult ParseSEHTryBlockCommon(SourceLocation Loc);
161128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult ParseSEHExceptBlock(SourceLocation Loc);
161228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
161328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
161428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  //===--------------------------------------------------------------------===//
1615a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  // Objective-C Statements
1616a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
161760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCAtStatement(SourceLocation atLoc);
161860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCTryStmt(SourceLocation atLoc);
161960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
162060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1621f85e193739c953358c865005855253af4f68a497John McCall  StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
1622b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7: Declarations.
162667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
162767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// A context for parsing declaration specifiers.  TODO: flesh this
162867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// out, there are other significant restrictions on specifiers than
162967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// would be best implemented in the parser.
163067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  enum DeclSpecContext {
163167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    DSC_normal, // normal context
16320efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    DSC_class,  // class context, enables 'friend'
16330efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    DSC_top_level // top-level/namespace declaration context
163467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  };
16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1636ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// Information on a C++0x for-range-initializer found while parsing a
1637ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// declaration which turns out to be a for-range-declaration.
1638ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct ForRangeInit {
1639ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    SourceLocation ColonLoc;
1640ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    ExprResult RangeExpr;
1641ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
1642ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
1643ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
1644ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
1645c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian  DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts,
1646c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian                                  unsigned Context, SourceLocation &DeclEnd,
16477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                  ParsedAttributesWithRange &attrs);
1648c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian  DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts,
1649c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian                                        unsigned Context,
1650bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                        SourceLocation &DeclEnd,
16517f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                        ParsedAttributes &attrs,
1652ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                        bool RequireSemi,
1653ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                        ForRangeInit *FRI = 0);
16540706df40064d4d7559b4304af79d519033414b84Richard Smith  bool MightBeDeclarator(unsigned Context);
165554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context,
1656d8ac05753dc4506224d445ff98399c01da3136e5John McCall                                bool AllowFunctionDefinitions,
1657ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                SourceLocation *DeclEnd = 0,
1658ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                ForRangeInit *FRI = 0);
1659d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseDeclarationAfterDeclarator(Declarator &D,
1660e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1661c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins  bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1662ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  Decl *ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D,
1663ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1664c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor  Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
1665c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor  Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
1666d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl
16670fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  /// \brief When in code-completion, skip parsing of the function/method body
16680fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  /// unless the body contains the code-completion point.
16690fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  ///
16700fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  /// \returns true if the function body was skipped.
1671b162054ba8f5b64fe87fbc4837933ab23eebd52bArgyrios Kyrtzidis  bool trySkippingFunctionBodyForCodeCompletion();
16720fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis
1673f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner  bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
16744d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                        const ParsedTemplateInfo &TemplateInfo,
1675e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner                        AccessSpecifier AS);
16760efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context);
16771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void ParseDeclarationSpecifiers(DeclSpec &DS,
16784d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
167967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                  AccessSpecifier AS = AS_none,
16802287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins                                  DeclSpecContext DSC = DSC_normal,
16812287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins                                  LateParsedAttrList *LateAttrs = 0);
16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid,
16837a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner                                  const char *&PrevSpec,
1684fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                  unsigned &DiagID,
1685d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1686d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                                  bool SuppressDeclarations = false);
16874d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
1688c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith  void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none);
16891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1690cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall  void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
1691cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall                                  Declarator::TheContext Context);
16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16934c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
16941b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
16951b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis                AccessSpecifier AS = AS_none);
1696d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
1698d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                            Decl *TagDecl);
1699bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1700bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  struct FieldCallback {
1701d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    virtual Decl *invoke(FieldDeclarator &Field) = 0;
17026c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall    virtual ~FieldCallback() {}
17036c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall
17046c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall  private:
17056c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall    virtual void _anchor();
1706bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  };
1707d0014540005f2a5ab837365db6bd40f479406758John McCall  struct ObjCPropertyCallback;
1708bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1709bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback);
17101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17119497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
1712eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  bool isTypeSpecifierQualifier();
17135f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff  bool isTypeQualifier() const;
1714a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
1715b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  /// isKnownToBeTypeSpecifier - Return true if we know that the specified token
1716b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  /// is definitely a type-specifier.  Return false if it isn't part of a type
1717b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  /// specifier or if we're not sure.
1718b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  bool isKnownToBeTypeSpecifier(const Token &Tok) const;
17195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17205404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isDeclarationStatement - Disambiguates between a declaration or an
17215404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// expression statement, when parsing function bodies.
17225404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for declaration, false for expression.
17235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isDeclarationStatement() {
17245404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    if (getLang().CPlusPlus)
17255404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      return isCXXDeclarationStatement();
17269497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    return isDeclarationSpecifier(true);
17275404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  }
17285404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
17299490ab433deef70105d817616928d700f87642d9Eli Friedman  /// isForInitDeclaration - Disambiguates between a declaration or an
17309490ab433deef70105d817616928d700f87642d9Eli Friedman  /// expression in the context of the C 'clause-1' or the C++
1731bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  // 'for-init-statement' part of a 'for' statement.
1732bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// Returns true for declaration, false for expression.
17339490ab433deef70105d817616928d700f87642d9Eli Friedman  bool isForInitDeclaration() {
1734bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis    if (getLang().CPlusPlus)
17359490ab433deef70105d817616928d700f87642d9Eli Friedman      return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/true);
17369497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    return isDeclarationSpecifier(true);
1737bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  }
1738bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis
17399497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  /// \brief Determine whether we are currently at the start of an Objective-C
17409497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  /// class message that appears to be missing the open bracket '['.
17419497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  bool isStartOfObjCClassMessageMissingOpenBracket();
1742a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
17430efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// \brief Starting with a scope specifier, identifier, or
17440efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// template-id that refers to the current class, determine whether
17450efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// this is a constructor declarator.
17460efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  bool isConstructorDeclarator();
17470efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor
17488b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  /// \brief Specifies the context in which type-id/expression
17498b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  /// disambiguation will occur.
17508b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  enum TentativeCXXTypeIdContext {
17518b642592a35167a3780074e78674e0bece87c40cDouglas Gregor    TypeIdInParens,
17528b642592a35167a3780074e78674e0bece87c40cDouglas Gregor    TypeIdAsTemplateArgument
17538b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  };
17548b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
17558b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
175678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
175778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// whether the parens contain an expression or a type-id.
175878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// Returns true for a type-id and false for an expression.
1759f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isTypeIdInParens(bool &isAmbiguous) {
176078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    if (getLang().CPlusPlus)
1761f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis      return isCXXTypeId(TypeIdInParens, isAmbiguous);
1762f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    isAmbiguous = false;
176378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    return isTypeSpecifierQualifier();
176478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  }
1765f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isTypeIdInParens() {
1766f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    bool isAmbiguous;
1767f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    return isTypeIdInParens(isAmbiguous);
1768f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  }
176978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
17705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXDeclarationStatement - C++-specialized function that disambiguates
17715404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a declaration or an expression statement, when parsing function
17725404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// bodies. Returns true for declaration, false for expression.
17735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isCXXDeclarationStatement();
17745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
17755404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
17765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a simple-declaration or an expression-statement.
17775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
17785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
17795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns false if the statement is disambiguated as expression.
17809490ab433deef70105d817616928d700f87642d9Eli Friedman  bool isCXXSimpleDeclaration(bool AllowForRangeDecl);
17815404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
17825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
17835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// a constructor-style initializer, when parsing declaration statements.
17845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for function declarator and false for constructor-style
1785e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to
1786259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis  /// indicate that the parens were disambiguated as function declarator.
17875404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
17885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
1789e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  bool isCXXFunctionDeclarator(bool warnIfAmbiguous);
17905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1791a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// isCXXConditionDeclaration - Disambiguates between a declaration or an
1792a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// expression for a condition of a if/switch/while/for statement.
1793a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
1794a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
1795a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  bool isCXXConditionDeclaration();
1796a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis
1797f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous);
1798f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
1799f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    bool isAmbiguous;
1800f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    return isCXXTypeId(Context, isAmbiguous);
1801f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  }
180278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
1803b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult - Used as the result value for functions whose purpose is to
1804b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// disambiguate C++ constructs by "tentatively parsing" them.
1805b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// This is a class instead of a simple enum because the implicit enum-to-bool
1806b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// conversions may cause subtle bugs.
1807b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  class TPResult {
1808b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    enum Result {
1809b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_true,
1810b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_false,
1811b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_ambiguous,
1812b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_error
1813b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    };
1814b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    Result Res;
1815b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    TPResult(Result result) : Res(result) {}
1816b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  public:
1817b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult True() { return TPR_true; }
1818b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult False() { return TPR_false; }
1819b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Ambiguous() { return TPR_ambiguous; }
1820b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Error() { return TPR_error; }
1821b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis
1822b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator==(const TPResult &RHS) const { return Res == RHS.Res; }
1823b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; }
1824b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis  };
1825b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis
1826a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// \brief Based only on the given token kind, determine whether we know that
1827a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// we're at the start of an expression or a type-specifier-seq (which may
1828a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// be an expression, in C++).
1829a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  ///
1830a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// This routine does not attempt to resolve any of the trick cases, e.g.,
1831a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// those involving lookup of identifiers.
1832a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  ///
1833a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// \returns \c TPR_true if this token starts an expression, \c TPR_false if
1834a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot
1835a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// tell.
1836a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind);
1837a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor
1838b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a
1839b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// declaration specifier, TPResult::False() if it is not,
1840b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult::Ambiguous() if it could be either a decl-specifier or a
1841b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// function-style cast, and TPResult::Error() if a parsing error was
1842d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith  /// encountered. If it could be a braced C++11 function-style cast, returns
1843d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith  /// BracedCastResult.
18445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Doesn't consume tokens.
1845d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith  TPResult
1846d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith  isCXXDeclarationSpecifier(TPResult BracedCastResult = TPResult::False());
1847a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
18485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // "Tentative parsing" functions, used for disambiguation. If a parsing error
1849b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // is encountered they will return TPResult::Error().
1850b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // Returning TPResult::True()/False() indicates that the ambiguity was
1851b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates
1852b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // that more tentative parsing is necessary for disambiguation.
18535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // They all consume tokens, so backtracking should be used after calling them.
18545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1855b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseDeclarationSpecifier();
18569490ab433deef70105d817616928d700f87642d9Eli Friedman  TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl);
1857b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseTypeofSpecifier();
18589bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor  TPResult TryParseProtocolQualifiers();
1859b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseInitDeclaratorList();
186078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true);
1861b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseParameterDeclarationClause();
1862b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseFunctionDeclarator();
1863b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseBracketDeclarator();
18645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1865683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor  TypeResult ParseTypeName(SourceRange *Range = 0,
1866683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor                           Declarator::TheContext Context
1867f85e193739c953358c865005855253af4f68a497John McCall                             = Declarator::TypeNameContext,
1868c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                           AccessSpecifier AS = AS_none,
1869c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                           Decl **OwnedType = 0);
187098eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump  void ParseBlockId();
18717f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
18727f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
18737f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (!attrs.Range.isValid()) return;
18747f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    DiagnoseProhibitedAttributes(attrs);
18757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18767f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
18777f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
1878eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  void MaybeParseGNUAttributes(Declarator &D,
1879eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                               LateParsedAttrList *LateAttrs = 0) {
18807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (Tok.is(tok::kw___attribute)) {
18810b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      ParsedAttributes attrs(AttrFactory);
18827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      SourceLocation endLoc;
1883eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski      ParseGNUAttributes(attrs, &endLoc, LateAttrs);
18840b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      D.takeAttributes(attrs, endLoc);
18857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
18867f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseGNUAttributes(ParsedAttributes &attrs,
1888eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                               SourceLocation *endLoc = 0,
1889eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                               LateParsedAttrList *LateAttrs = 0) {
18907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (Tok.is(tok::kw___attribute))
1891eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski      ParseGNUAttributes(attrs, endLoc, LateAttrs);
18927f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
18937f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseGNUAttributes(ParsedAttributes &attrs,
1894eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                          SourceLocation *endLoc = 0,
1895eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                          LateParsedAttrList *LateAttrs = 0);
1896eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski  void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
1897eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                             SourceLocation AttrNameLoc,
1898eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                             ParsedAttributes &Attrs,
1899eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski                             SourceLocation *EndLoc);
19007f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
19017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseCXX0XAttributes(Declarator &D) {
19027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
19030b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      ParsedAttributesWithRange attrs(AttrFactory);
19047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      SourceLocation endLoc;
19057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseCXX0XAttributes(attrs, &endLoc);
19060b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      D.takeAttributes(attrs, endLoc);
19077f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
19087f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
19097f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseCXX0XAttributes(ParsedAttributes &attrs,
19107f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                 SourceLocation *endLoc = 0) {
19117f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
19120b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      ParsedAttributesWithRange attrsWithRange(AttrFactory);
19137f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseCXX0XAttributes(attrsWithRange, endLoc);
19140b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall      attrs.takeAllFrom(attrsWithRange);
19157f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
19167f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
19177f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
19187f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                 SourceLocation *endLoc = 0) {
19197f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
19207f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseCXX0XAttributes(attrs, endLoc);
19217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
19223497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne
19233497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne  void ParseCXX0XAttributeSpecifier(ParsedAttributes &attrs,
19243497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne                                    SourceLocation *EndLoc = 0);
19257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
19267f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                            SourceLocation *EndLoc = 0);
19277f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
19287f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
19297f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                     SourceLocation *endLoc = 0) {
193062ec1f2fd7368542bb926c04797fb07023547694Francois Pichet    if (getLang().MicrosoftExt && Tok.is(tok::l_square))
19317f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseMicrosoftAttributes(attrs, endLoc);
19327f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
19337f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseMicrosoftAttributes(ParsedAttributes &attrs,
19347f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                SourceLocation *endLoc = 0);
19357f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseMicrosoftDeclSpec(ParsedAttributes &attrs);
19367f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
19377f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
1938f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne  void ParseOpenCLAttributes(ParsedAttributes &attrs);
1939207f4d8543529221932af82836016a2ef066c917Peter Collingbourne  void ParseOpenCLQualifiers(DeclSpec &DS);
19407f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
19410a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  VersionTuple ParseVersionTuple(SourceRange &Range);
19420a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  void ParseAvailabilityAttribute(IdentifierInfo &Availability,
19430a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor                                  SourceLocation AvailabilityLoc,
19440a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor                                  ParsedAttributes &attrs,
19450a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor                                  SourceLocation *endLoc);
19460a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
1947b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski  bool IsThreadSafetyAttribute(llvm::StringRef AttrName);
1948b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski  void ParseThreadSafetyAttribute(IdentifierInfo &AttrName,
1949b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski                                  SourceLocation AttrNameLoc,
1950b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski                                  ParsedAttributes &Attrs,
1951b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski                                  SourceLocation *EndLoc);
1952b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski
1953b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski
1954d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  void ParseTypeofSpecifier(DeclSpec &DS);
195542d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie  SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
195642d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie  void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
195742d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie                                         SourceLocation StartLoc,
195842d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie                                         SourceLocation EndLoc);
1959db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt  void ParseUnderlyingTypeSpecifier(DeclSpec &DS);
1960b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  void ParseAtomicSpecifier(DeclSpec &DS);
1961b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
19620b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne  ExprResult ParseAlignArgument(SourceLocation Start,
19630b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne                                SourceLocation &EllipsisLoc);
196482d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne  void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
196582d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne                               SourceLocation *endLoc = 0);
1966eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
19671c94c16317c1a35c1549e022958188eea2567089Richard Smith  VirtSpecifiers::Specifier isCXX0XVirtSpecifier(const Token &Tok) const;
19681c94c16317c1a35c1549e022958188eea2567089Richard Smith  VirtSpecifiers::Specifier isCXX0XVirtSpecifier() const {
19691c94c16317c1a35c1549e022958188eea2567089Richard Smith    return isCXX0XVirtSpecifier(Tok);
19701c94c16317c1a35c1549e022958188eea2567089Richard Smith  }
1971b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  void ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS);
19721f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
19738a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson  bool isCXX0XFinalKeyword() const;
1974cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson
1975eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
1976eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// enter a new C++ declarator scope and exit it when the function is
1977eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// finished.
1978eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  class DeclaratorScopeObj {
1979eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    Parser &P;
1980751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis    CXXScopeSpec &SS;
1981f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis    bool EnteredScope;
1982f7f3d0db754db0500b56d49ac19f795f13965912John McCall    bool CreatedScope;
1983eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  public:
1984f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis    DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
1985f7f3d0db754db0500b56d49ac19f795f13965912John McCall      : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
1986eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1987eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    void EnterDeclaratorScope() {
19882bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis      assert(!EnteredScope && "Already entered the scope!");
1989f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      assert(SS.isSet() && "C++ scope was not set!");
1990f7f3d0db754db0500b56d49ac19f795f13965912John McCall
1991f7f3d0db754db0500b56d49ac19f795f13965912John McCall      CreatedScope = true;
1992f7f3d0db754db0500b56d49ac19f795f13965912John McCall      P.EnterScope(0); // Not a decl scope.
1993f7f3d0db754db0500b56d49ac19f795f13965912John McCall
199423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
19953fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor        EnteredScope = true;
1996eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
1997eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1998eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    ~DeclaratorScopeObj() {
1999f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      if (EnteredScope) {
2000f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis        assert(SS.isSet() && "C++ scope was cleared ?");
200123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor        P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2002f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      }
2003f7f3d0db754db0500b56d49ac19f795f13965912John McCall      if (CreatedScope)
2004f7f3d0db754db0500b56d49ac19f795f13965912John McCall        P.ExitScope();
2005eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
2006eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  };
20071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseDeclarator - Parse and verify a newly-initialized declarator.
20095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDeclarator(Declarator &D);
20104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  /// A function that parses a variant of direct-declarator.
20114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
20124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDeclaratorInternal(Declarator &D,
20134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl                               DirectDeclParseFunction DirectDeclParser);
20147f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
2015bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true,
2016bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                 bool CXX0XAttributesAllowed = true);
20175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDirectDeclarator(Declarator &D);
20185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseParenDeclarator(Declarator &D);
20194a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor  void ParseFunctionDeclarator(Declarator &D,
20207f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                               ParsedAttributes &attrs,
20214a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                               BalancedDelimiterTracker &Tracker,
20227399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner                               bool RequiresArg = false);
20233fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor  bool isFunctionDeclaratorIdentifierList();
20243fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor  void ParseFunctionDeclaratorIdentifierList(
20253fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor         Declarator &D,
2026686775deca8b8685eb90801495880e3abdd844c2Chris Lattner         SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo);
20273fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor  void ParseParameterDeclarationClause(
20283fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor         Declarator &D,
20293fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor         ParsedAttributes &attrs,
2030686775deca8b8685eb90801495880e3abdd844c2Chris Lattner         SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo,
20313fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor         SourceLocation &EllipsisLoc);
20325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseBracketDeclarator(Declarator &D);
20331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20348f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  //===--------------------------------------------------------------------===//
20358f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  // C++ 7: Declarations [dcl.dcl]
20361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2037a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  bool isCXX0XAttributeSpecifier(bool FullLookahead = false,
2038bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                 tok::TokenKind *After = 0);
2039a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
2040d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl  Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd,
2041d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                       SourceLocation InlineLoc = SourceLocation());
2042f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu  void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc,
2043f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu                           std::vector<IdentifierInfo*>& Ident,
2044f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu                           std::vector<SourceLocation>& NamespaceLoc,
2045f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu                           unsigned int index, SourceLocation& InlineLoc,
20464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                           ParsedAttributes& attrs,
20474a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor                           BalancedDelimiterTracker &Tracker);
2048d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context);
2049d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseUsingDirectiveOrDeclaration(unsigned Context,
205078b810559d89e996e00684335407443936ce34a1John McCall                                         const ParsedTemplateInfo &TemplateInfo,
2051d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                                         SourceLocation &DeclEnd,
2052c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                                         ParsedAttributesWithRange &attrs,
2053c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                                         Decl **OwnedType = 0);
205478b810559d89e996e00684335407443936ce34a1John McCall  Decl *ParseUsingDirective(unsigned Context,
205578b810559d89e996e00684335407443936ce34a1John McCall                            SourceLocation UsingLoc,
20567f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                            SourceLocation &DeclEnd,
20577f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                            ParsedAttributes &attrs);
205878b810559d89e996e00684335407443936ce34a1John McCall  Decl *ParseUsingDeclaration(unsigned Context,
205978b810559d89e996e00684335407443936ce34a1John McCall                              const ParsedTemplateInfo &TemplateInfo,
206078b810559d89e996e00684335407443936ce34a1John McCall                              SourceLocation UsingLoc,
2061d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                              SourceLocation &DeclEnd,
2062c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                              AccessSpecifier AS = AS_none,
2063c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith                              Decl **OwnedType = 0);
2064d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
2065d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
2066d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                            SourceLocation AliasLoc, IdentifierInfo *Alias,
2067d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                            SourceLocation &DeclEnd);
20681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2069e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
2070e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 9: classes [class] and C structs/unions.
20714c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
20721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                           DeclSpec &DS,
20734d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2074d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                           AccessSpecifier AS = AS_none,
2075efaa93aaa2653f4eb40e6a22e504a448da94aaf8Douglas Gregor                           bool EnteringContext = false,
2076d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                           bool SuppressDeclarations = false);
20774cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType,
2078d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                   Decl *TagDecl);
2079552e29985a710f4ced62b39d70557501bd31ca9bDouglas Gregor  ExprResult ParseCXXMemberInitializer(Decl *D, bool IsFunction,
20807a614d8380297fcd2bc23986241905d97222948cRichard Smith                                       SourceLocation &EqualLoc);
20815f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen  void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr,
2082c9068d7dd94d439cec66c421115d15303e481025John McCall                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2083c9068d7dd94d439cec66c421115d15303e481025John McCall                                 ParsingDeclRAIIObject *DiagsFromTParams = 0);
2084d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseConstructorInitializer(Decl *ConstructorDecl);
2085d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  MemInitResult ParseMemInitializer(Decl *ConstructorDecl);
2086d33133cdc1af466f9c276249b2621be03867888bEli Friedman  void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
2087d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                       Decl *ThisDecl);
2088e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
2089e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
2090e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 10: Derived classes [class.derived]
2091a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
209222216eb4fb0936d2488fc03abd285d135c36ff01David Blaikie                                    SourceLocation &EndLocation);
2093d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseBaseClause(Decl *ClassDecl);
2094d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  BaseResult ParseBaseSpecifier(Decl *ClassDecl);
20951b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor  AccessSpecifier getAccessSpecifierIfPresent() const;
20961cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor
2097a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie  bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
2098e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                    SourceLocation TemplateKWLoc,
20993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    IdentifierInfo *Name,
21003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    SourceLocation NameLoc,
21013f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    bool EnteringContext,
2102b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                    ParsedType ObjectType,
2103d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                    UnqualifiedId &Id,
2104e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                    bool AssumeTemplateId);
2105ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
2106b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                  ParsedType ObjectType,
2107ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                  UnqualifiedId &Result);
21083f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
210902a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor                          bool AllowDestructorName,
211002a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor                          bool AllowConstructorName,
2111b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                          ParsedType ObjectType,
2112e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                          SourceLocation& TemplateKWLoc,
21133f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                          UnqualifiedId &Result);
2114a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
21151cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor  //===--------------------------------------------------------------------===//
2116adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14: Templates [temp]
2117c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor
2118adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14.1: Template Parameters [temp.param]
2119d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseDeclarationStartingWithTemplate(unsigned Context,
21205f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                             SourceLocation &DeclEnd,
21215f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                             AccessSpecifier AS = AS_none,
21225f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                             AttributeList *AccessAttrs = 0);
2123d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context,
21245f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                                 SourceLocation &DeclEnd,
21255f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                                 AccessSpecifier AS,
21265f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                                 AttributeList *AccessAttrs);
2127d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseSingleDeclarationAfterTemplate(
21281426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       unsigned Context,
21294d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                       const ParsedTemplateInfo &TemplateInfo,
2130c9068d7dd94d439cec66c421115d15303e481025John McCall                                       ParsingDeclRAIIObject &DiagsFromParams,
21311426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       SourceLocation &DeclEnd,
21325f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                       AccessSpecifier AS=AS_none,
21335f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen                                       AttributeList *AccessAttrs = 0);
21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseTemplateParameters(unsigned Depth,
2135686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               SmallVectorImpl<Decl*> &TemplateParams,
21361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               SourceLocation &LAngleLoc,
2137c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor                               SourceLocation &RAngleLoc);
2138c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor  bool ParseTemplateParameterList(unsigned Depth,
2139686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                  SmallVectorImpl<Decl*> &TemplateParams);
214098440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor  bool isStartOfTemplateTypeParameter();
2141d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTemplateParameter(unsigned Depth, unsigned Position);
2142d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTypeParameter(unsigned Depth, unsigned Position);
2143d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
2144d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
2145d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor  // C++ 14.3: Template arguments [temp.arg]
2146686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
2147cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
21487532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  bool ParseTemplateIdAfterTemplateName(TemplateTy Template,
21491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        SourceLocation TemplateNameLoc,
2150059101f922de6eb765601459925f4c8914420b23Douglas Gregor                                        const CXXScopeSpec &SS,
2151cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        bool ConsumeLastToken,
2152cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        SourceLocation &LAngleLoc,
2153cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        TemplateArgList &TemplateArgs,
2154cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        SourceLocation &RAngleLoc);
2155cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
2156c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner  bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
2157059101f922de6eb765601459925f4c8914420b23Douglas Gregor                               CXXScopeSpec &SS,
2158e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                               SourceLocation TemplateKWLoc,
2159ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                               UnqualifiedId &TemplateName,
216039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                               bool AllowTypeAnnotation = true);
2161059101f922de6eb765601459925f4c8914420b23Douglas Gregor  void AnnotateTemplateIdTokenAsType();
2162d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor  bool IsTemplateArgumentList(unsigned Skip = 0);
2163314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
2164788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  ParsedTemplateArgument ParseTemplateTemplateArgument();
2165314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  ParsedTemplateArgument ParseTemplateArgument();
21669241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis  Decl *ParseExplicitInstantiation(unsigned Context,
21679241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis                                   SourceLocation ExternLoc,
21689241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis                                   SourceLocation TemplateLoc,
21699241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis                                   SourceLocation &DeclEnd,
21709241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis                                   AccessSpecifier AS = AS_none);
217164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
217264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  //===--------------------------------------------------------------------===//
21736aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor  // Modules
21745948ae1021122164b22f74353bb7fe325a64f616Douglas Gregor  DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc);
2175a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie
21766aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor  //===--------------------------------------------------------------------===//
217764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // GNU G++: Type Traits [Type-Traits.html in the GCC manual]
217860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseUnaryTypeTrait();
21796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult ParseBinaryTypeTrait();
21804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  ExprResult ParseTypeTrait();
21814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2182f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  //===--------------------------------------------------------------------===//
218321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  // Embarcadero: Arary and Expression Traits
218421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ExprResult ParseArrayTypeTrait();
2185552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExprResult ParseExpressionTrait();
2186552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2187552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  //===--------------------------------------------------------------------===//
2188f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  // Preprocessor code-completion pass-through
2189f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  virtual void CodeCompleteDirective(bool InConditional);
2190f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  virtual void CodeCompleteInConditionalExclusion();
21911fbb447e9d43c2c676e94081fbfee7eb6cbe933bDouglas Gregor  virtual void CodeCompleteMacroName(bool IsDefinition);
2192f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor  virtual void CodeCompletePreprocessorExpression();
2193f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor  virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro,
2194f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor                                         MacroInfo *MacroInfo,
2195f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor                                         unsigned ArgumentIndex);
219655817afdf9d453a443262a733f6caf6692dca118Douglas Gregor  virtual void CodeCompleteNaturalLanguage();
21975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
22005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2202