Parser.h revision c9977d09a2de7f7d2245973413d4caf86c736640
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"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Lex/Preprocessor.h"
19f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor#include "clang/Lex/CodeCompletionHandler.h"
20f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "clang/Sema/Sema.h"
2119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h"
22f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "llvm/Support/PrettyStackTrace.h"
234726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek#include "llvm/ADT/OwningPtr.h"
244cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis#include <stack>
251100258c19dd8967ba078c0bc81fc06cea9d033fChris Lattner#include <list>
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
28fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar  class PragmaHandler;
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Scope;
302b5289b6fd7e3d9899868410a498c081c9595662John McCall  class DeclGroupRef;
313cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  class DiagnosticBuilder;
320102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  class Parser;
334726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  class PragmaUnusedHandler;
3408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  class ColonProtectionRAIIObject;
350fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  class InMessageExpressionRAIIObject;
360fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor
370102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// PrettyStackTraceParserEntry - If a crash happens while the parser is active,
380102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// an entry is printed for it.
390102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerclass PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry {
400102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  const Parser &P;
410102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerpublic:
420102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  PrettyStackTraceParserEntry(const Parser &p) : P(p) {}
430102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  virtual void print(llvm::raw_ostream &OS) const;
440102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner};
451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// PrecedenceLevels - These are precedences for the binary/ternary
476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// operators in the C99 grammar.  These have been named to relate
486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// with the C99 grammar productions.  Low precedences numbers bind
496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// more weakly than high numbers.
506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregornamespace prec {
516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  enum Level {
526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Unknown         = 0,    // Not binary operator.
536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Comma           = 1,    // ,
546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Assignment      = 2,    // =, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |=
556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Conditional     = 3,    // ?
566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    LogicalOr       = 4,    // ||
576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    LogicalAnd      = 5,    // &&
586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    InclusiveOr     = 6,    // |
596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    ExclusiveOr     = 7,    // ^
606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    And             = 8,    // &
616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Equality        = 9,    // ==, !=
626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Relational      = 10,   //  >=, <=, >, <
636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Shift           = 11,   // <<, >>
646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Additive        = 12,   // -, +
656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    Multiplicative  = 13,   // *, /, %
666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor    PointerToMember = 14    // .*, ->*
676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  };
686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor}
691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages.  After
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read.
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
74f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregorclass Parser : public CodeCompletionHandler {
754726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  friend class PragmaUnusedHandler;
7608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  friend class ColonProtectionRAIIObject;
770fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  friend class InMessageExpressionRAIIObject;
7836d36806f1972f7ec1d2a3f59155187278c56508Argyrios Kyrtzidis  friend class ParenBraceBracketBalancer;
790102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  PrettyStackTraceParserEntry CrashInfo;
801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Preprocessor &PP;
821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8397d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher  /// Tok - The current token we are peeking ahead.  All parsing methods assume
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// that this is valid.
85d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner  Token Tok;
861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
874b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // PrevTokLocation - The location of the token we previously
884b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // consumed. This token is used for diagnostics where we expected to
894b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // see a token following another token (e.g., the ';' at the end of
904b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // a statement).
914b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  SourceLocation PrevTokLocation;
924b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned short ParenCount, BracketCount, BraceCount;
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Actions - These are the callbacks we invoke as we parse various constructs
9687c300738174924453648c3b2d6f366c8284fac4Douglas Gregor  /// in the file.
97f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  Sema &Actions;
981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Diagnostic &Diags;
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1019e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  /// ScopeCache - Cache scopes to reduce malloc traffic.
1029e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  enum { ScopeCacheSize = 16 };
1039e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  unsigned NumCachedScopes;
1049e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  Scope *ScopeCache[ScopeCacheSize];
105662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar
106662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  /// Ident_super - IdentifierInfo for "super", to support fast
107662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  /// comparison.
108662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  IdentifierInfo *Ident_super;
10982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// Ident_vector and Ident_pixel - cached IdentifierInfo's for
11082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// "vector" and "pixel" fast comparison.  Only present if
11182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// AltiVec enabled.
11282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  IdentifierInfo *Ident_vector;
11382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  IdentifierInfo *Ident_pixel;
114662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar
1151f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson  /// C++0x contextual keywords.
1167eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson  mutable IdentifierInfo *Ident_final;
1177eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson  mutable IdentifierInfo *Ident_override;
1181f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
119cbb98edd530787c2ac019e437e7c599df8004ba7Daniel Dunbar  llvm::OwningPtr<PragmaHandler> AlignHandler;
120aa8b0d19244a6e7e8e5798fcc6aef003c274d3e0Eli Friedman  llvm::OwningPtr<PragmaHandler> GCCVisibilityHandler;
121861800c676004eabed5927f0552620d06c80a40aDaniel Dunbar  llvm::OwningPtr<PragmaHandler> OptionsHandler;
1224726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  llvm::OwningPtr<PragmaHandler> PackHandler;
1234726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  llvm::OwningPtr<PragmaHandler> UnusedHandler;
1249991479ad5dde617168cc1e4b18425cdbbfd9fa9Eli Friedman  llvm::OwningPtr<PragmaHandler> WeakHandler;
125321b8179afaf803dcc56b2a19f7b0891a03c92c8Peter Collingbourne  llvm::OwningPtr<PragmaHandler> FPContractHandler;
126f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne  llvm::OwningPtr<PragmaHandler> OpenCLExtensionHandler;
1271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// Whether the '>' token acts as an operator or not. This will be
12955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// true except when we are parsing an expression within a C++
13055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// template argument list, where the '>' closes the template
13155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// argument list.
13255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  bool GreaterThanIsOperator;
13308d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner
13408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// ColonIsSacred - When this is false, we aggressively try to recover from
13508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// code like "foo : bar" as if it were a typo for "foo :: bar".  This is not
13608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// safe in case statements and a few other things.  This is managed by the
13708d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  /// ColonProtectionRAIIObject RAII object.
13808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner  bool ColonIsSacred;
13955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
1400fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// \brief When true, we are directly inside an Ojective-C messsage
1410fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// send expression.
1420fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  ///
1430fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// This is managed by the \c InMessageExpressionRAIIObject class, and
1440fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  /// should not be set directly.
1450fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor  bool InMessageExpression;
1460fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor
147c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor  /// The "depth" of the template parameters currently being parsed.
148c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor  unsigned TemplateParameterDepth;
1498113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek
1508113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek  /// Factory object for creating AttributeList objects.
1518113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek  AttributeList::Factory AttrFactory;
1521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
154f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  Parser(Preprocessor &PP, Sema &Actions);
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ~Parser();
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const LangOptions &getLang() const { return PP.getLangOptions(); }
158444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
1590102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  Preprocessor &getPreprocessor() const { return PP; }
160f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  Sema &getActions() const { return Actions; }
1611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1620102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  const Token &getCurToken() const { return Tok; }
16323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor  Scope *getCurScope() const { return Actions.getCurScope(); }
16423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor
1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Type forwarding.  All of these are statically 'void*', but they may all be
1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // different actual classes based on the actions in place.
167ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  typedef Expr ExprTy;
168ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  typedef Stmt StmtTy;
1692b5289b6fd7e3d9899868410a498c081c9595662John McCall  typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
170ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  typedef CXXBaseSpecifier BaseTy;
171cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer MemInitTy;
172ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  typedef NestedNameSpecifier CXXScopeTy;
173ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  typedef TemplateParameterList TemplateParamsTy;
1742b5289b6fd7e3d9899868410a498c081c9595662John McCall  typedef OpaquePtr<TemplateName> TemplateTy;
1757ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
176ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  typedef llvm::SmallVector<TemplateParameterList *, 4> TemplateParameterLists;
177c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor
1789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::ExprResult        ExprResult;
1799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::StmtResult        StmtResult;
1809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::BaseResult        BaseResult;
1819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::MemInitResult     MemInitResult;
1829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef clang::TypeResult        TypeResult;
18315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
1849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef Expr *ExprArg;
1859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  typedef ASTMultiPtr<Stmt*> MultiStmtArg;
186f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::FullExprArg FullExprArg;
1871d922960e083906a586609ac6978678147250177Sebastian Redl
18860d7b3a319d84d688752be3870615ac0f111fb16John McCall  /// Adorns a ExprResult with Actions to make it an ExprResult
18960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Owned(ExprResult res) {
19060d7b3a319d84d688752be3870615ac0f111fb16John McCall    return ExprResult(res);
19161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
19260d7b3a319d84d688752be3870615ac0f111fb16John McCall  /// Adorns a StmtResult with Actions to make it an StmtResult
19360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Owned(StmtResult res) {
19460d7b3a319d84d688752be3870615ac0f111fb16John McCall    return StmtResult(res);
19561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
19661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
19760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ExprError() { return ExprResult(true); }
19860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult StmtError() { return StmtResult(true); }
199d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor
20060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); }
20160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); }
20261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
20360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ExprEmpty() { return ExprResult(false); }
2045ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Parsing methods.
2061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseTranslationUnit - All in one method that initializes parses, and
2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// shuts down the parser.
2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseTranslationUnit();
2101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Initialize - Warm up the parser.
2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Initialize();
2141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
2161f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff  /// the EOF was encountered.
217682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
2181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2193fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  DeclGroupPtrTy FinishPendingObjCActions();
22063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Low-Level token peeking and consumption methods.
2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //
2251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenParen - Return true if the cur token is '(' or ')'.
2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenParen() const {
2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren;
2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBracket - Return true if the cur token is '[' or ']'.
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBracket() const {
2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square;
2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBrace - Return true if the cur token is '{' or '}'.
2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBrace() const {
2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace;
2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenStringLiteral - True if this token is a string-literal.
2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenStringLiteral() const {
2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::string_literal ||
2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           Tok.getKind() == tok::wide_string_literal;
2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
245eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
246a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis  /// \brief Returns true if the current token is a '=' or '==' and
247a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis  /// false otherwise. If it's '==', we assume that it's a typo and we emit
248a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis  /// DiagID and a fixit hint to turn '==' -> '='.
249a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis  bool isTokenEqualOrMistypedEqualEqual(unsigned DiagID);
250a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis
2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeToken - Consume the current 'peek token' and lex the next one.
252d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu  /// This does not work with all kinds of tokens: strings and specific other
2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tokens must be consumed with custom methods below.  This returns the
2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// location of the consumed token.
2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeToken() {
2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() &&
2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           !isTokenBrace() &&
2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should consume special tokens with Consume*Token");
259dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    if (Tok.is(tok::code_completion)) {
260dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor      CodeCompletionRecovery();
261dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor      return ConsumeCodeCompletionToken();
262dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    }
263dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor
2644b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
2664b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// current token type.  This should only be used in cases where the type of
2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the token really isn't known, e.g. in error recovery.
2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeAnyToken() {
2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isTokenParen())
2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeParen();
2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBracket())
2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBracket();
2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBrace())
2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBrace();
279d62701bc5321049353017e9abf1963edd57646aaSteve Naroff    else if (isTokenStringLiteral())
280d62701bc5321049353017e9abf1963edd57646aaSteve Naroff      return ConsumeStringToken();
2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeToken();
2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeParen - This consume method keeps the paren count up-to-date.
2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeParen() {
2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenParen() && "wrong consume method");
2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_paren)
2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++ParenCount;
2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (ParenCount)
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --ParenCount;       // Don't let unbalanced )'s drive the count negative.
2934b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
2954b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBracket - This consume method keeps the bracket count up-to-date.
2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBracket() {
3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBracket() && "wrong consume method");
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_square)
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BracketCount;
3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BracketCount)
3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BracketCount;     // Don't let unbalanced ]'s drive the count negative.
3061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3074b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3094b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBrace - This consume method keeps the brace count up-to-date.
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBrace() {
3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBrace() && "wrong consume method");
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_brace)
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BraceCount;
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BraceCount)
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BraceCount;     // Don't let unbalanced }'s drive the count negative.
3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3214b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3234b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeStringToken - Consume the current 'peek token', lexing a new one
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// and returning the token kind.  This method is specific to strings, as it
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// handles string literal concatenation, as per C99 5.1.1.2, translation
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// phase #6.
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeStringToken() {
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenStringLiteral() &&
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should only consume string literals with this method");
3334b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
3354b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
338dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// \brief Consume the current code-completion token.
339dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  ///
340dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// This routine should be called to consume the code-completion token once
341dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// a code-completion action has already been invoked.
342dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  SourceLocation ConsumeCodeCompletionToken() {
343dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    assert(Tok.is(tok::code_completion));
344dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    PrevTokLocation = Tok.getLocation();
345dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    PP.Lex(Tok);
346dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor    return PrevTokLocation;
347dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  }
348dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor
349dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  ///\ brief When we are consuming a code-completion token within having
350dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// matched specific position in the grammar, provide code-completion results
351dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  /// based on context.
352dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor  void CodeCompletionRecovery();
353dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor
354b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis  /// \brief Handle the annotation token produced for #pragma unused(...)
355b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis  void HandlePragmaUnused();
356b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis
3576b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// GetLookAheadToken - This peeks ahead N tokens and returns that token
3586b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// without consuming any tokens.  LookAhead(0) returns 'Tok', LookAhead(1)
3596b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// returns the token after Tok, etc.
3606b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
3616b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// Note that this differs from the Preprocessor's LookAhead method, because
3626b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// the Parser always has one token lexed that the preprocessor doesn't.
3636b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
36403db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis  const Token &GetLookAheadToken(unsigned N) {
3656b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    if (N == 0 || Tok.is(tok::eof)) return Tok;
3666b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    return PP.LookAhead(N-1);
3676b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  }
368f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis
369f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// NextToken - This peeks ahead one token and returns it without
370f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// consuming it.
371f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  const Token &NextToken() {
37203db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis    return PP.LookAhead(0);
373f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  }
3745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
375b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  /// getTypeAnnotation - Read a parsed type out of an annotation token.
376b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  static ParsedType getTypeAnnotation(Token &Tok) {
377b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue());
378b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
379b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
380b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  static void setTypeAnnotation(Token &Tok, ParsedType T) {
381b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    Tok.setAnnotationValue(T.getAsOpaquePtr());
382b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  }
383b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall
384eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// TryAnnotateTypeOrScopeToken - If the current token position is on a
385eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// typename (possibly qualified in C++) or a C++ scope specifier not followed
386eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens
387eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// with a single annotation token representing the typename or C++ scope
388eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// respectively.
389eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// This simplifies handling of C++ scope specifiers and allows efficient
390eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// backtracking without the need to re-parse and resolve nested-names and
391eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// typenames.
39244802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// It will mainly be called when we expect to treat identifiers as typenames
39344802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// (if they are typenames). For example, in C we do not expect identifiers
39444802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// inside expressions to be treated as typenames so it will not be called
39544802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// for expressions in C.
396a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner  ///
397a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner  /// This returns true if the token was annotated.
398495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor  bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false);
399eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
4009ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall  /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but
4019ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall  /// only annotates C++ scope specifiers.  This returns true if there
4029ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall  /// was an unrecoverable error.
403495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor  bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
404eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
40582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens,
40682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// replacing them with the non-context-sensitive keywords.  This returns
40782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// true if the token was replaced.
40882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
409b3a4e432c90be98c6d918087750397e86d030368Chris Lattner                       const char *&PrevSpec, unsigned &DiagID,
410b3a4e432c90be98c6d918087750397e86d030368Chris Lattner                       bool &isInvalid) {
4111b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner    if (!getLang().AltiVec ||
4121b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner        (Tok.getIdentifierInfo() != Ident_vector &&
4131b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner         Tok.getIdentifierInfo() != Ident_pixel))
4141b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner      return false;
4151b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner
4161b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner    return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
41782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
41882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
41982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector
42082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// identifier token, replacing it with the non-context-sensitive __vector.
42182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// This returns true if the token was replaced.
42282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool TryAltiVecVectorToken() {
423b3a4e432c90be98c6d918087750397e86d030368Chris Lattner    if (!getLang().AltiVec ||
424b3a4e432c90be98c6d918087750397e86d030368Chris Lattner        Tok.getIdentifierInfo() != Ident_vector) return false;
4251b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner    return TryAltiVecVectorTokenOutOfLine();
42682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  }
4271b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner
4281b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner  bool TryAltiVecVectorTokenOutOfLine();
4291b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner  bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
4301b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner                                const char *&PrevSpec, unsigned &DiagID,
4311b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner                                bool &isInvalid);
4321b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner
4335404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// TentativeParsingAction - An object that is used as a kind of "tentative
4345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// parsing transaction". It gets instantiated to mark the token position and
4355404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// after the token consumption is done, Commit() or Revert() is called to
4365404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// either "commit the consumed tokens" or revert to the previously marked
4375404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// token position. Example:
4385404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
439314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  ///   TentativeParsingAction TPA(*this);
4405404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ConsumeToken();
4415404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ....
4425404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   TPA.Revert();
4435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
4445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  class TentativeParsingAction {
4455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Parser &P;
4465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Token PrevTok;
4475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    bool isActive;
4485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
4495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  public:
4505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    explicit TentativeParsingAction(Parser& p) : P(p) {
4515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      PrevTok = P.Tok;
4525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.EnableBacktrackAtThisPos();
4535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = true;
4545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
4555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Commit() {
4565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
4575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.CommitBacktrackedTokens();
4585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
4595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
4605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Revert() {
4615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
4625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.Backtrack();
4635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.Tok = PrevTok;
4645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
4655404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
4665404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    ~TentativeParsingAction() {
4675404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(!isActive && "Forgot to call Commit or Revert!");
4685404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
4695404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  };
4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'),
4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this helper function matches and consumes the specified RHS token if
4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// present.  If not present, it emits the specified diagnostic indicating
4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// that the parser failed to match the RHS of the token at LHSLoc.  LHSName
4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// should be the name of the unmatched LHS token.  This returns the location
4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the consumed token.
4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok,
4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                     SourceLocation LHSLoc);
4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// input.  If so, it is consumed and false is returned.
4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If the input is malformed, this emits the specified diagnostic.  Next, if
4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipToTok is specified, it calls SkipUntil(SkipToTok).  Finally, true is
4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// returned.
4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag,
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        const char *DiagMsg = "",
4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        tok::TokenKind SkipToTok = tok::unknown);
4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4919ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// \brief The parser expects a semicolon and, if present, will consume it.
4929ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  ///
4939ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// If the next token is not a semicolon, this emits the specified diagnostic,
4949ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior
4959ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  /// to the semicolon, consumes that extra token.
4969ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor  bool ExpectAndConsumeSemi(unsigned DiagID);
4979ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor
4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Scope manipulation
5001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5018935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// ParseScope - Introduces a new scope for parsing. The kind of
5028935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// scope is determined by ScopeFlags. Objects of this type should
5038935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// be created on the stack to coincide with the position where the
5048935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// parser enters the new scope, and this object's constructor will
5058935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// create that new scope. Similarly, once the object is destroyed
5068935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// the parser will exit the scope.
5078935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  class ParseScope {
5088935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    Parser *Self;
5098935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope(const ParseScope&); // do not implement
5108935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope& operator=(const ParseScope&); // do not implement
5118935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
5128935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  public:
5138935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ParseScope - Construct a new object to manage a scope in the
5148935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // parser Self where the new Scope is created with the flags
5158935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ScopeFlags, but only when ManageScope is true (the default). If
5168935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ManageScope is false, this object does nothing.
5171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true)
5188935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      : Self(Self) {
5198935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (ManageScope)
5208935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->EnterScope(ScopeFlags);
5218935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      else
5228935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        this->Self = 0;
5238935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
5248935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
5258935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // Exit - Exit the scope associated with this object now, rather
5268935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // than waiting until the object is destroyed.
5278935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    void Exit() {
5288935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (Self) {
5298935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->ExitScope();
5308935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self = 0;
5318935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      }
5328935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
5338935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
5348935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ~ParseScope() {
5358935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      Exit();
5368935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
5378935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  };
5388935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EnterScope - Start a new scope.
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EnterScope(unsigned ScopeFlags);
5411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExitScope - Pop a scope off the scope stack.
5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ExitScope();
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Diagnostic Emission and Error recovery.
54715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
5486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic:
5493cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
5503cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
55115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
5526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate:
5531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SuggestParentheses(SourceLocation Loc, unsigned DK,
5544b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor                          SourceRange ParenRange);
5554b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipUntil - Read tokens until we get to the specified token, then consume
55782c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff  /// it (unless DontConsume is true).  Because we cannot guarantee that the
5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// token will ever occur, this skips to the next token, or to some likely
5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// good stopping point.  If StopAtSemi is true, skipping will stop at a ';'
5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// character.
5611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If SkipUntil finds the specified token, it returns true, otherwise it
5631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returns false.
5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
5653437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool DontConsume = false, bool StopAtCodeCompletion = false) {
5663437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis    return SkipUntil(&T, 1, StopAtSemi, DontConsume, StopAtCodeCompletion);
5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
5693437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool DontConsume = false, bool StopAtCodeCompletion = false) {
5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    tok::TokenKind TokArray[] = {T1, T2};
5713437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis    return SkipUntil(TokArray, 2, StopAtSemi, DontConsume,StopAtCodeCompletion);
5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
5743437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool StopAtSemi = true, bool DontConsume = false,
5753437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis                 bool StopAtCodeCompletion = false);
5767ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
5784cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // Lexing and parsing of C++ inline methods.
5794cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
580d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  struct ParsingClass;
581d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
582d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// [class.mem]p1: "... the class is regarded as complete within
583d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - function bodies
584d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - default arguments
585d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - exception-specifications (TODO: C++0x)
586d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// - and brace-or-equal-initializers (TODO: C++0x)
587d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// for non-static data members (including such things in nested classes)."
588d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// LateParsedDeclarations build the tree of those elements so they can
589d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// be parsed after parsing the top-level class.
590d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  class LateParsedDeclaration {
591d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  public:
592d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual ~LateParsedDeclaration();
593d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
594d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDeclarations();
595d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDefs();
596d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  };
597d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
598d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// Inner node of the LateParsedDeclaration tree that parses
599d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// all its members recursively.
600d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  class LateParsedClass : public LateParsedDeclaration {
601d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  public:
602d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    LateParsedClass(Parser *P, ParsingClass *C);
603d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual ~LateParsedClass();
604d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
605d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDeclarations();
606d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDefs();
607d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
608d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  private:
609d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    Parser *Self;
610d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    ParsingClass *Class;
611d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  };
612d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
613d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// Contains the lexed tokens of a member function definition
614d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// which needs to be parsed at the end of the class declaration
615d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// after parsing all other member declarations.
616d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  struct LexedMethod : public LateParsedDeclaration {
617d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    Parser *Self;
618d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *D;
61972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    CachedTokens Toks;
620d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor
621d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// \brief Whether this member function had an associated template
622d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// scope. When true, D is a template declaration.
623d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// othewise, it is a member function declaration.
624d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    bool TemplateScope;
625d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor
626d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    explicit LexedMethod(Parser* P, Decl *MD)
627d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor      : Self(P), D(MD), TemplateScope(false) {}
628d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
629d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDefs();
6304cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  };
6314cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
63272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// LateParsedDefaultArgument - Keeps track of a parameter that may
63372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// have a default argument that cannot be parsed yet because it
63472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// occurs within a member function declaration inside the class
63572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// (C++ [class.mem]p2).
63672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  struct LateParsedDefaultArgument {
637d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    explicit LateParsedDefaultArgument(Decl *P,
63872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor                                       CachedTokens *Toks = 0)
63972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor      : Param(P), Toks(Toks) { }
64072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
64172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Param - The parameter declaration for this parameter.
642d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Param;
64372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
64472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Toks - The sequence of tokens that comprises the default
64572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// argument expression, not including the '=' or the terminating
64672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// ')' or ','. This will be NULL for parameters that have no
64772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// default argument.
64872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    CachedTokens *Toks;
64972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
6501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
65172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// LateParsedMethodDeclaration - A method declaration inside a class that
65272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// contains at least one entity whose parsing needs to be delayed
65372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// until the class itself is completely-defined, such as a default
65472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// argument (C++ [class.mem]p2).
655d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  struct LateParsedMethodDeclaration : public LateParsedDeclaration {
656d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    explicit LateParsedMethodDeclaration(Parser *P, Decl *M)
657d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor      : Self(P), Method(M), TemplateScope(false) { }
658d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
659d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    virtual void ParseLexedMethodDeclarations();
660d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor
661d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    Parser* Self;
66272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
66372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Method - The method declaration.
664d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *Method;
66572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
666d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// \brief Whether this member function had an associated template
667d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// scope. When true, D is a template declaration.
668d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// othewise, it is a member function declaration.
669d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    bool TemplateScope;
6701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// DefaultArgs - Contains the parameters of the function and
67272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// their default arguments. At least one of the parameters will
67372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// have a default argument, but all of the parameters of the
67472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// method will be stored so that they can be reintroduced into
6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// scope at the appropriate times.
67672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
67772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
67872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
679d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// LateParsedDeclarationsContainer - During parsing of a top (non-nested)
680d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// C++ class, its method declarations that contain parts that won't be
68172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// parsed until after the definiton is completed (C++ [class.mem]p2),
682d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// the method declarations and possibly attached inline definitions
683d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  /// will be stored here with the tokens that will be parsed to create those entities.
684d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  typedef llvm::SmallVector<LateParsedDeclaration*, 2> LateParsedDeclarationsContainer;
68572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
6866569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// \brief Representation of a class that has been parsed, including
6876569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// any member function declarations or definitions that need to be
6886569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// parsed after the corresponding top-level class is complete.
6896569d68745c8213709740337d2be52b031384f58Douglas Gregor  struct ParsingClass {
690d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    ParsingClass(Decl *TagOrTemplate, bool TopLevelClass)
6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : TopLevelClass(TopLevelClass), TemplateScope(false),
6926569d68745c8213709740337d2be52b031384f58Douglas Gregor        TagOrTemplate(TagOrTemplate) { }
6936569d68745c8213709740337d2be52b031384f58Douglas Gregor
6946569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Whether this is a "top-level" class, meaning that it is
6956569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// not nested within another class.
6966569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool TopLevelClass : 1;
6976569d68745c8213709740337d2be52b031384f58Douglas Gregor
6986569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Whether this class had an associated template
6996569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// scope. When true, TagOrTemplate is a template declaration;
7006569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// othewise, it is a tag declaration.
7016569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool TemplateScope : 1;
7026569d68745c8213709740337d2be52b031384f58Douglas Gregor
7036569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief The class or class template whose definition we are parsing.
704d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    Decl *TagOrTemplate;
70572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
706d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    /// LateParsedDeclarations - Method declarations, inline definitions and
707d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    /// nested classes that contain pieces whose parsing will be delayed until
708d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    /// the top-level class is fully defined.
709d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor    LateParsedDeclarationsContainer LateParsedDeclarations;
71072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
7114cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
7126569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// \brief The stack of classes that is currently being
7136569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// parsed. Nested and local classes will be pushed onto this stack
7146569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// when they are parsed, and removed afterward.
7156569d68745c8213709740337d2be52b031384f58Douglas Gregor  std::stack<ParsingClass *> ClassStack;
7164cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
7176569d68745c8213709740337d2be52b031384f58Douglas Gregor  ParsingClass &getCurrentClass() {
7186569d68745c8213709740337d2be52b031384f58Douglas Gregor    assert(!ClassStack.empty() && "No lexed method stacks!");
7196569d68745c8213709740337d2be52b031384f58Douglas Gregor    return *ClassStack.top();
7204cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
7214cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
72254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// \brief RAII object used to inform the actions that we're
72354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// currently parsing a declaration.  This is active when parsing a
72454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// variable's initializer, but not when parsing the body of a
72554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// class or function definition.
72654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclRAIIObject {
727f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    Sema &Actions;
728eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall    Sema::ParsingDeclState State;
72954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    bool Popped;
730c9068d7dd94d439cec66c421115d15303e481025John McCall
73154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
73254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) {
73354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      push();
73454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
73554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
736c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *Other)
737c9068d7dd94d439cec66c421115d15303e481025John McCall        : Actions(P.Actions) {
738c9068d7dd94d439cec66c421115d15303e481025John McCall      if (Other) steal(*Other);
739c9068d7dd94d439cec66c421115d15303e481025John McCall      else push();
740c9068d7dd94d439cec66c421115d15303e481025John McCall    }
741c9068d7dd94d439cec66c421115d15303e481025John McCall
742c9068d7dd94d439cec66c421115d15303e481025John McCall    /// Creates a RAII object which steals the state from a different
743c9068d7dd94d439cec66c421115d15303e481025John McCall    /// object instead of pushing.
744c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclRAIIObject(ParsingDeclRAIIObject &Other)
745c9068d7dd94d439cec66c421115d15303e481025John McCall        : Actions(Other.Actions) {
746c9068d7dd94d439cec66c421115d15303e481025John McCall      steal(Other);
747c9068d7dd94d439cec66c421115d15303e481025John McCall    }
748c9068d7dd94d439cec66c421115d15303e481025John McCall
74954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ~ParsingDeclRAIIObject() {
75054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      abort();
75154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
75254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
75354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// Resets the RAII object for a new declaration.
75454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void reset() {
75554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      abort();
75654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      push();
75754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
75854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
75954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// Signals that the context was completed without an appropriate
76054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// declaration being parsed.
76154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void abort() {
762d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall      pop(0);
76354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
76454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
765d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void complete(Decl *D) {
76654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      assert(!Popped && "ParsingDeclaration has already been popped!");
76754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      pop(D);
76854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
76954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
77054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  private:
771c9068d7dd94d439cec66c421115d15303e481025John McCall    void steal(ParsingDeclRAIIObject &Other) {
772c9068d7dd94d439cec66c421115d15303e481025John McCall      State = Other.State;
773c9068d7dd94d439cec66c421115d15303e481025John McCall      Popped = Other.Popped;
774c9068d7dd94d439cec66c421115d15303e481025John McCall      Other.Popped = true;
775c9068d7dd94d439cec66c421115d15303e481025John McCall    }
776c9068d7dd94d439cec66c421115d15303e481025John McCall
77754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void push() {
77854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      State = Actions.PushParsingDeclaration();
77954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      Popped = false;
78054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
78154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
782d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void pop(Decl *D) {
78354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      if (!Popped) {
78454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall        Actions.PopParsingDeclaration(State, D);
78554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall        Popped = true;
78654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      }
78754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
78854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
78954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
79054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// A class for parsing a DeclSpec.
79154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclSpec : public DeclSpec {
79254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject ParsingRAII;
79354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
79454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
795c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclSpec(Parser &P) : ParsingRAII(P) {}
796c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclSpec(ParsingDeclRAIIObject &RAII) : ParsingRAII(RAII) {}
797c9068d7dd94d439cec66c421115d15303e481025John McCall    ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII)
798c9068d7dd94d439cec66c421115d15303e481025John McCall      : ParsingRAII(P, RAII) {}
79954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
800d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void complete(Decl *D) {
80154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.complete(D);
80254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
80354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
80454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void abort() {
80554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.abort();
80654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
80754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
80854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
80954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// A class for parsing a declarator.
81054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclarator : public Declarator {
81154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject ParsingRAII;
81254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
81354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
81454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C)
81554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      : Declarator(DS, C), ParsingRAII(P) {
81654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
81754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
81854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    const ParsingDeclSpec &getDeclSpec() const {
81954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec());
82054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
82154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
82254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclSpec &getMutableDeclSpec() const {
82354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      return const_cast<ParsingDeclSpec&>(getDeclSpec());
82454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
82554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
82654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void clear() {
82754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      Declarator::clear();
82854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.reset();
82954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
83054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
831d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    void complete(Decl *D) {
83254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.complete(D);
83354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
83454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
83554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
8361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief RAII object used to
8376569d68745c8213709740337d2be52b031384f58Douglas Gregor  class ParsingClassDefinition {
8386569d68745c8213709740337d2be52b031384f58Douglas Gregor    Parser &P;
8396569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool Popped;
840eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall    Sema::ParsingClassState State;
8416569d68745c8213709740337d2be52b031384f58Douglas Gregor
8426569d68745c8213709740337d2be52b031384f58Douglas Gregor  public:
843d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass)
844eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall      : P(P), Popped(false),
845eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall        State(P.PushParsingClass(TagOrTemplate, TopLevelClass)) {
8466569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
8476569d68745c8213709740337d2be52b031384f58Douglas Gregor
8486569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Pop this class of the stack.
8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    void Pop() {
8506569d68745c8213709740337d2be52b031384f58Douglas Gregor      assert(!Popped && "Nested class has already been popped");
8516569d68745c8213709740337d2be52b031384f58Douglas Gregor      Popped = true;
852eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall      P.PopParsingClass(State);
8536569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
8546569d68745c8213709740337d2be52b031384f58Douglas Gregor
8551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ~ParsingClassDefinition() {
8566569d68745c8213709740337d2be52b031384f58Douglas Gregor      if (!Popped)
857eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall        P.PopParsingClass(State);
8586569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
8596569d68745c8213709740337d2be52b031384f58Douglas Gregor  };
8606569d68745c8213709740337d2be52b031384f58Douglas Gregor
8614d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// \brief Contains information about any template-specific
8624d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// information that has been parsed prior to parsing declaration
8634d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// specifiers.
8644d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  struct ParsedTemplateInfo {
8651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParsedTemplateInfo()
8664d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { }
8674d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
8684d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
869c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor                       bool isSpecialization,
870c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor                       bool lastParameterListWasEmpty = false)
8714d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      : Kind(isSpecialization? ExplicitSpecialization : Template),
872c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        TemplateParams(TemplateParams),
873c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        LastParameterListWasEmpty(lastParameterListWasEmpty) { }
8744d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
87545f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    explicit ParsedTemplateInfo(SourceLocation ExternLoc,
87645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor                                SourceLocation TemplateLoc)
8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : Kind(ExplicitInstantiation), TemplateParams(0),
878c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
879c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        LastParameterListWasEmpty(false){ }
8804d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
8814d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The kind of template we are parsing.
8824d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    enum {
8834d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are not parsing a template at all.
8844d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      NonTemplate = 0,
8854d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing a template declaration.
8864d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      Template,
8874d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing an explicit specialization.
8884d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      ExplicitSpecialization,
8894d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing an explicit instantiation.
8904d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      ExplicitInstantiation
8914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    } Kind;
8924d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
8934d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The template parameter lists, for template declarations
8944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// and explicit specializations.
8954d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    TemplateParameterLists *TemplateParams;
8964d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
89745f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    /// \brief The location of the 'extern' keyword, if any, for an explicit
89845f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    /// instantiation
89945f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    SourceLocation ExternLoc;
9001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The location of the 'template' keyword, for an explicit
9024d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// instantiation.
9034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    SourceLocation TemplateLoc;
904c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor
905c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor    /// \brief Whether the last template parameter list was empty.
906c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor    bool LastParameterListWasEmpty;
90778b810559d89e996e00684335407443936ce34a1John McCall
90878b810559d89e996e00684335407443936ce34a1John McCall    SourceRange getSourceRange() const;
9094d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  };
9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
911eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  Sema::ParsingClassState
912eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass);
91337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void DeallocateParsedClasses(ParsingClass *Class);
914eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  void PopParsingClass(Sema::ParsingClassState);
91537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor
916eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall  Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, ParsingDeclarator &D,
9174867347e82648d3baf09524b98b09c297a5a198fNico Weber                                const ParsedTemplateInfo &TemplateInfo,
9184867347e82648d3baf09524b98b09c297a5a198fNico Weber                                const VirtSpecifiers& VS);
91937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseLexedMethodDeclarations(ParsingClass &Class);
920d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
92137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseLexedMethodDefs(ParsingClass &Class);
922d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor  void ParseLexedMethodDef(LexedMethod &LM);
92314b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis  bool ConsumeAndStoreUntil(tok::TokenKind T1,
92414b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            CachedTokens &Toks,
92514b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            bool StopAtSemi = true,
92614b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            bool ConsumeFinalToken = true) {
92714b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis    return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken);
92814b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis  }
9291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
93037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                            CachedTokens &Toks,
93114b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis                            bool StopAtSemi = true,
93237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                            bool ConsumeFinalToken = true);
9334d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
9344cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.9: External Definitions.
9367f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  struct ParsedAttributesWithRange : ParsedAttributes {
9377f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    SourceRange Range;
9387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  };
9397f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
9407f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
94109a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor                                          ParsingDeclSpec *DS = 0);
942c82daefa3062721e98947e08193cd81b4e9df915Chris Lattner  bool isDeclarationAfterDeclarator() const;
943004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner  bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
9447f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsedAttributes &attrs,
9457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                                  AccessSpecifier AS = AS_none);
9463acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS,
9473acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian                                                  AccessSpecifier AS = AS_none);
9483acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian
949d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseFunctionDefinition(ParsingDeclarator &D,
95052591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor                 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseKNRParamDeclarations(Declarator &D);
952ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // EndLoc, if non-NULL, is filled with the location of the last token of
953ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // the simple-asm.
95460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0);
95560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseAsmStringLiteral();
9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9573536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  // Objective-C External Declarations
958d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtDirectives();
959d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtClassDeclaration(SourceLocation atLoc);
960d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc,
9617f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                        ParsedAttributes &prefixAttrs);
962d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
96383c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian                                       tok::ObjCKeywordKind visibility,
96460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                       SourceLocation atLoc);
965d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &P,
96671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                   llvm::SmallVectorImpl<SourceLocation> &PLocs,
9671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   bool WarnOnDeclarations,
96871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                   SourceLocation &LAngleLoc,
969e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                   SourceLocation &EndProtoLoc);
97046f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor  bool ParseObjCProtocolQualifiers(DeclSpec &DS);
971d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseObjCInterfaceDeclList(Decl *interfaceDecl,
972c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner                                  tok::ObjCKeywordKind contextKey);
973d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
9747f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                       ParsedAttributes &prefixAttrs);
9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
976d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ObjCImpDecl;
977d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  llvm::SmallVector<Decl *, 4> PendingObjCImpDecl;
9780416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
979d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtImplementationDeclaration(SourceLocation atLoc);
980d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtEndDeclaration(SourceRange atEnd);
981d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
982d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
983d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
9841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9852fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
98634870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  // Definitions for Objective-c context sensitive keywords recognition.
98734870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  enum ObjCTypeQual {
98834870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
98934870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_NumQuals
99034870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  };
991a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
993335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian  bool isTokIdentifier_in() const;
994d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian
995b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor  /// \brief The context in which we are parsing an Objective-C type name.
996b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor  enum ObjCTypeNameContext {
997b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor    OTN_ResultType,
998b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor    OTN_ParameterType
999b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor  };
1000b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor
1001b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor  ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, ObjCTypeNameContext Context);
1002294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  void ParseObjCMethodRequirement();
1003d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCMethodPrototype(Decl *classOrCat,
100490ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
100590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            bool MethodDefinition = true);
1006d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
1007d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                Decl *classDecl,
100890ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
100990ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian            bool MethodDefinition=true);
1010bdb2d5056fd675c27307b34efd371bbba6839e92Douglas Gregor  void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl);
10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1012d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseObjCMethodDefinition();
10131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.5: Expressions.
10166aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
101760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseExpression();
101860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseConstantExpression();
10192f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  // Expr that doesn't include commas.
102060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseAssignmentExpression();
10212f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl
102260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
102460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
1025adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman
102660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseRHSOfBinaryExpression(ExprResult LHS,
10276aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor                                              prec::Level MinPrec);
102860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCastExpression(bool isUnaryExpression,
1029f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis                                       bool isAddressOfOperand,
10302ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                                       bool &NotCastExpr,
1031b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType TypeOfCast);
103260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCastExpression(bool isUnaryExpression,
10332ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                                       bool isAddressOfOperand = false,
1034b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType TypeOfCast = ParsedType());
10359c72c6088d591ace8503b842d39448c2040f3033John McCall
10369c72c6088d591ace8503b842d39448c2040f3033John McCall  /// Returns true if the next token would start a postfix-expression
10379c72c6088d591ace8503b842d39448c2040f3033John McCall  /// suffix.
10389c72c6088d591ace8503b842d39448c2040f3033John McCall  bool isPostfixExpressionSuffixStart() {
10399c72c6088d591ace8503b842d39448c2040f3033John McCall    tok::TokenKind K = Tok.getKind();
10409c72c6088d591ace8503b842d39448c2040f3033John McCall    return (K == tok::l_square || K == tok::l_paren ||
10419c72c6088d591ace8503b842d39448c2040f3033John McCall            K == tok::period || K == tok::arrow ||
10429c72c6088d591ace8503b842d39448c2040f3033John McCall            K == tok::plusplus || K == tok::minusminus);
10439c72c6088d591ace8503b842d39448c2040f3033John McCall  }
10449c72c6088d591ace8503b842d39448c2040f3033John McCall
104560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParsePostfixExpressionSuffix(ExprResult LHS);
1046f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult ParseUnaryExprOrTypeTraitExpression();
104760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseBuiltinPrimaryExpression();
10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1049f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
10505ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis                                                     bool &isCastExpr,
1051b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                                     ParsedType &CastTy,
10525ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis                                                     SourceRange &CastRange);
10530cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
1054ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  typedef llvm::SmallVector<Expr*, 20> ExprListTy;
1055ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  typedef llvm::SmallVector<SourceLocation, 20> CommaLocsTy;
10560cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
10570cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis  /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
1058ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  bool ParseExpressionList(llvm::SmallVectorImpl<Expr*> &Exprs,
1059ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall                           llvm::SmallVectorImpl<SourceLocation> &CommaLocs,
1060f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                           void (Sema::*Completer)(Scope *S,
1061f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Expr *Data,
1062f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Expr **Args,
1063f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   unsigned NumArgs) = 0,
1064ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall                           Expr *Data = 0);
1065d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParenParseOption - Control what ParseParenExpression will parse.
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ParenParseOption {
10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SimpleExpr,      // Only parse '(' expression ')'
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundStmt,    // Also allow '(' compound-statement ')'
10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CastExpr         // Also allow '(' type-name ')' <anything>
10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
107360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseParenExpression(ParenParseOption &ExprType,
10740350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis                                        bool stopIfCastExpr,
1075b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                        ParsedType TypeOfCast,
1076b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                        ParsedType &CastTy,
1077d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl                                        SourceLocation &RParenLoc);
10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
1080b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                                    ParsedType &CastTy,
1081f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis                                                    SourceLocation LParenLoc,
1082f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis                                                    SourceLocation &RParenLoc);
10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCompoundLiteralExpression(ParsedType Ty,
1085d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis                                                  SourceLocation LParenLoc,
1086d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis                                                  SourceLocation RParenLoc);
10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseStringLiteralExpression();
1089eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1090eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
1091eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  // C++ Expressions
109260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
10934bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis
10941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
1095b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                      ParsedType ObjectType,
1096b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor                                      bool EnteringContext,
1097d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                      bool *MayBePseudoDestructor = 0);
10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 5.2p1: C++ Casts
110160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXCasts();
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1104c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // C++ 5.2p1: C++ Type Identification
110560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXTypeid();
1106c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
1107c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  //===--------------------------------------------------------------------===//
110801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  //  C++ : Microsoft __uuidof Expression
110901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult ParseCXXUuidof();
111001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
111101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  //===--------------------------------------------------------------------===//
1112d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor  // C++ 5.2.4: C++ Pseudo-Destructor Expressions
111360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc,
1114d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                            tok::TokenKind OpKind,
1115d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                            CXXScopeSpec &SS,
1116b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                            ParsedType ObjectType);
1117d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor
1118d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor  //===--------------------------------------------------------------------===//
11194cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // C++ 9.3.2: C++ 'this' pointer
112060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXThis();
11214cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
11224cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
112350dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  // C++ 15: C++ Throw Expression
112460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseThrowExpression();
11257acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl
11267acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl  ExceptionSpecificationType MaybeParseExceptionSpecification(
11277acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                    SourceRange &SpecificationRange,
11287acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                    llvm::SmallVectorImpl<ParsedType> &DynamicExceptions,
11297acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                    llvm::SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
11307acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                    ExprResult &NoexceptExpr);
11317acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl
1132ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // EndLoc is filled with the location of the last token of the specification.
11337acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl  ExceptionSpecificationType ParseDynamicExceptionSpecification(
11347acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                                  SourceRange &SpecificationRange,
11357acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                                  llvm::SmallVectorImpl<ParsedType> &Exceptions,
11367acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl                                  llvm::SmallVectorImpl<SourceRange> &Ranges);
113750dd289f45738ed22b7583d52ed2525b927042ffChris Lattner
113850dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  //===--------------------------------------------------------------------===//
1139dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // C++0x 8: Function declaration trailing-return-type
1140dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  TypeResult ParseTrailingReturnType();
1141dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
1142dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //===--------------------------------------------------------------------===//
11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 2.13.5: C++ Boolean Literals
114460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXBoolLiteral();
11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1147987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // C++ 5.2.3: Explicit type conversion (functional notation)
114860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
1149987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
11506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  bool isCXXSimpleTypeSpecifier() const;
11516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor
1152987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
1153987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// This should only be called when the current token is known to be part of
1154987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// simple-type-specifier.
1155987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1156987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
11572f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor  bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
11582f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor
1159987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
11604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // C++ 5.3.4 and 5.3.5: C++ new and delete
1161ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  bool ParseExpressionListOrTypeId(llvm::SmallVectorImpl<Expr*> &Exprs,
1162ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall                                   Declarator &D);
11634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDirectNewDeclarator(Declarator &D);
116460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
116560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXXDeleteExpression(bool UseGlobal,
116659232d35f5820e334b6c8b007ae8006f4390055dChris Lattner                                            SourceLocation Start);
11674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  //===--------------------------------------------------------------------===//
116999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  // C++ if/switch/while condition expression.
117060d7b3a319d84d688752be3870615ac0f111fb16John McCall  bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult,
1171586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                         SourceLocation Loc, bool ConvertToBoolean);
117271b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis
117371b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
117412e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  // C++ types
117512e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor
117612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  //===--------------------------------------------------------------------===//
11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7.8: Initialization.
11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11790eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  /// ParseInitializer
11800eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///       initializer: [C99 6.7.8]
11810eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         assignment-expression
11820eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         '{' ...
118360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseInitializer() {
11840eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    if (Tok.isNot(tok::l_brace))
118520df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl      return ParseAssignmentExpression();
11860eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    return ParseBraceInitializer();
11870eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  }
118860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseBraceInitializer();
118960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseInitializerWithPotentialDesignator();
11901d922960e083906a586609ac6978678147250177Sebastian Redl
11915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1192296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  // clang Expressions
11931d922960e083906a586609ac6978678147250177Sebastian Redl
119460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseBlockLiteralExpression();  // ^{...}
1195296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff
1196296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  //===--------------------------------------------------------------------===//
11975508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  // Objective-C Expressions
119860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
119960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
120060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
120160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
120260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
12031b730e847ded503f2e615154035c083c4f94a067Douglas Gregor  bool isSimpleObjCMessageExpression();
120460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCMessageExpression();
120560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
12062725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor                                                  SourceLocation SuperLoc,
1207b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                                  ParsedType ReceiverType,
12081d922960e083906a586609ac6978678147250177Sebastian Redl                                                  ExprArg ReceiverExpr);
120960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseAssignmentExprWithObjCMessageExprStart(
12102725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor      SourceLocation LBracloc, SourceLocation SuperLoc,
1211b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall      ParsedType ReceiverType, ExprArg ReceiverExpr);
12126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor  bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr);
121361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
12145508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  //===--------------------------------------------------------------------===//
12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.8: Statements and Blocks.
121661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
121760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseStatement() {
1218c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian    StmtVector Stmts(Actions);
1219c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian    return ParseStatementOrDeclaration(Stmts, true);
122061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
1221c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian  StmtResult ParseStatementOrDeclaration(StmtVector& Stmts,
1222c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian                                         bool OnlyStatement = false);
12237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseLabeledStatement(ParsedAttributes &Attr);
12247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseCaseStatement(ParsedAttributes &Attr);
12257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseDefaultStatement(ParsedAttributes &Attr);
12267f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseCompoundStatement(ParsedAttributes &Attr,
1227bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                          bool isStmtExpr = false);
122860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
122960d7b3a319d84d688752be3870615ac0f111fb16John McCall  bool ParseParenExprOrCondition(ExprResult &ExprResult,
1230d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                 Decl *&DeclResult,
1231586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                 SourceLocation Loc,
123244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                 bool ConvertToBoolean);
12337f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseIfStatement(ParsedAttributes &Attr);
12347f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseSwitchStatement(ParsedAttributes &Attr);
12357f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseWhileStatement(ParsedAttributes &Attr);
12367f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseDoStatement(ParsedAttributes &Attr);
12377f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseForStatement(ParsedAttributes &Attr);
12387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseGotoStatement(ParsedAttributes &Attr);
12397f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseContinueStatement(ParsedAttributes &Attr);
12407f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseBreakStatement(ParsedAttributes &Attr);
12417f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseReturnStatement(ParsedAttributes &Attr);
124260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseAsmStatement(bool &msAsm);
1243a44724d0d6d03568ec9acadc0781d612163008e1Abramo Bagnara  StmtResult FuzzyParseMicrosoftAsmStatement(SourceLocation AsmLoc);
1244ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<IdentifierInfo *> &Names,
1245ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                           llvm::SmallVectorImpl<ExprTy *> &Constraints,
1246ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                           llvm::SmallVectorImpl<ExprTy *> &Exprs);
1247a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
1248a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  //===--------------------------------------------------------------------===//
1249a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  // C++ 6: Statements and Blocks
1250a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
12517f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  StmtResult ParseCXXTryBlock(ParsedAttributes &Attr);
125260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc);
125360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseCXXCatchBlock();
1254a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
1255a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  //===--------------------------------------------------------------------===//
1256a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  // Objective-C Statements
1257a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
125860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCAtStatement(SourceLocation atLoc);
125960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCTryStmt(SourceLocation atLoc);
126060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
126160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1262b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7: Declarations.
126667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
126767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// A context for parsing declaration specifiers.  TODO: flesh this
126867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// out, there are other significant restrictions on specifiers than
126967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// would be best implemented in the parser.
127067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  enum DeclSpecContext {
127167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    DSC_normal, // normal context
12720efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    DSC_class,  // class context, enables 'friend'
12730efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor    DSC_top_level // top-level/namespace declaration context
127467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  };
12751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1276c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian  DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts,
1277c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian                                  unsigned Context, SourceLocation &DeclEnd,
12787f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                  ParsedAttributesWithRange &attrs);
1279c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian  DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts,
1280c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian                                        unsigned Context,
1281bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                        SourceLocation &DeclEnd,
12827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                        ParsedAttributes &attrs,
12835c5db553b5c256d0a6f55dde7325c1c829b88e8eChris Lattner                                        bool RequireSemi);
128454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context,
1285d8ac05753dc4506224d445ff98399c01da3136e5John McCall                                bool AllowFunctionDefinitions,
1286d8ac05753dc4506224d445ff98399c01da3136e5John McCall                                SourceLocation *DeclEnd = 0);
1287d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseDeclarationAfterDeclarator(Declarator &D,
1288e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1289c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor  Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
1290c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor  Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
1291d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl
12920fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  /// \brief When in code-completion, skip parsing of the function/method body
12930fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  /// unless the body contains the code-completion point.
12940fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  ///
12950fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis  /// \returns true if the function body was skipped.
1296b162054ba8f5b64fe87fbc4837933ab23eebd52bArgyrios Kyrtzidis  bool trySkippingFunctionBodyForCodeCompletion();
12970fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis
1298f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner  bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
12994d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                        const ParsedTemplateInfo &TemplateInfo,
1300e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner                        AccessSpecifier AS);
13010efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context);
13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void ParseDeclarationSpecifiers(DeclSpec &DS,
13034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
130467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                  AccessSpecifier AS = AS_none,
130567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                  DeclSpecContext DSC = DSC_normal);
13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid,
13077a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner                                  const char *&PrevSpec,
1308fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                  unsigned &DiagID,
1309d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1310d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                                  bool SuppressDeclarations = false);
13114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseSpecifierQualifierList(DeclSpec &DS);
13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1314b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor  void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
1315b77cab97f17f946744c920629ca17271308d8ebfDouglas Gregor                                  ObjCTypeNameContext Context);
13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13174c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
13181b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
13191b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis                AccessSpecifier AS = AS_none);
1320d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
1322d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                            Decl *TagDecl);
1323bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1324bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  struct FieldCallback {
1325d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall    virtual Decl *invoke(FieldDeclarator &Field) = 0;
13266c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall    virtual ~FieldCallback() {}
13276c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall
13286c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall  private:
13296c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall    virtual void _anchor();
1330bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  };
1331d0014540005f2a5ab837365db6bd40f479406758John McCall  struct ObjCPropertyCallback;
1332bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1333bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback);
13341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13359497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
1336eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  bool isTypeSpecifierQualifier();
13375f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff  bool isTypeQualifier() const;
1338b3a4e432c90be98c6d918087750397e86d030368Chris Lattner
1339b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  /// isKnownToBeTypeSpecifier - Return true if we know that the specified token
1340b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  /// is definitely a type-specifier.  Return false if it isn't part of a type
1341b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  /// specifier or if we're not sure.
1342b3a4e432c90be98c6d918087750397e86d030368Chris Lattner  bool isKnownToBeTypeSpecifier(const Token &Tok) const;
13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isDeclarationStatement - Disambiguates between a declaration or an
13455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// expression statement, when parsing function bodies.
13465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for declaration, false for expression.
13475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isDeclarationStatement() {
13485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    if (getLang().CPlusPlus)
13495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      return isCXXDeclarationStatement();
13509497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    return isDeclarationSpecifier(true);
13515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  }
13525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1353bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// isSimpleDeclaration - Disambiguates between a declaration or an
1354bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// expression, mainly used for the C 'clause-1' or the C++
1355bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  // 'for-init-statement' part of a 'for' statement.
1356bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// Returns true for declaration, false for expression.
1357bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  bool isSimpleDeclaration() {
1358bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis    if (getLang().CPlusPlus)
1359bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis      return isCXXSimpleDeclaration();
13609497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor    return isDeclarationSpecifier(true);
1361bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  }
1362bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis
13639497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  /// \brief Determine whether we are currently at the start of an Objective-C
13649497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  /// class message that appears to be missing the open bracket '['.
13659497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor  bool isStartOfObjCClassMessageMissingOpenBracket();
13669497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor
13670efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// \brief Starting with a scope specifier, identifier, or
13680efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// template-id that refers to the current class, determine whether
13690efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  /// this is a constructor declarator.
13700efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor  bool isConstructorDeclarator();
13710efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor
13728b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  /// \brief Specifies the context in which type-id/expression
13738b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  /// disambiguation will occur.
13748b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  enum TentativeCXXTypeIdContext {
13758b642592a35167a3780074e78674e0bece87c40cDouglas Gregor    TypeIdInParens,
13768b642592a35167a3780074e78674e0bece87c40cDouglas Gregor    TypeIdAsTemplateArgument
13778b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  };
13788b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
13798b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
138078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
138178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// whether the parens contain an expression or a type-id.
138278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// Returns true for a type-id and false for an expression.
1383f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isTypeIdInParens(bool &isAmbiguous) {
138478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    if (getLang().CPlusPlus)
1385f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis      return isCXXTypeId(TypeIdInParens, isAmbiguous);
1386f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    isAmbiguous = false;
138778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    return isTypeSpecifierQualifier();
138878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  }
1389f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isTypeIdInParens() {
1390f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    bool isAmbiguous;
1391f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    return isTypeIdInParens(isAmbiguous);
1392f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  }
139378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
13945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXDeclarationStatement - C++-specialized function that disambiguates
13955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a declaration or an expression statement, when parsing function
13965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// bodies. Returns true for declaration, false for expression.
13975404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isCXXDeclarationStatement();
13985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
13995404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
14005404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a simple-declaration or an expression-statement.
14015404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
14025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
14035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns false if the statement is disambiguated as expression.
14045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isCXXSimpleDeclaration();
14055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
14065404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
14075404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// a constructor-style initializer, when parsing declaration statements.
14085404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for function declarator and false for constructor-style
1409e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to
1410259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis  /// indicate that the parens were disambiguated as function declarator.
14115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
14125404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
1413e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  bool isCXXFunctionDeclarator(bool warnIfAmbiguous);
14145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1415a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// isCXXConditionDeclaration - Disambiguates between a declaration or an
1416a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// expression for a condition of a if/switch/while/for statement.
1417a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
1418a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
1419a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  bool isCXXConditionDeclaration();
1420a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis
1421f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous);
1422f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
1423f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    bool isAmbiguous;
1424f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    return isCXXTypeId(Context, isAmbiguous);
1425f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  }
142678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
1427b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult - Used as the result value for functions whose purpose is to
1428b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// disambiguate C++ constructs by "tentatively parsing" them.
1429b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// This is a class instead of a simple enum because the implicit enum-to-bool
1430b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// conversions may cause subtle bugs.
1431b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  class TPResult {
1432b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    enum Result {
1433b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_true,
1434b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_false,
1435b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_ambiguous,
1436b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_error
1437b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    };
1438b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    Result Res;
1439b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    TPResult(Result result) : Res(result) {}
1440b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  public:
1441b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult True() { return TPR_true; }
1442b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult False() { return TPR_false; }
1443b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Ambiguous() { return TPR_ambiguous; }
1444b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Error() { return TPR_error; }
1445b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis
1446b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator==(const TPResult &RHS) const { return Res == RHS.Res; }
1447b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; }
1448b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis  };
1449b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis
1450a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// \brief Based only on the given token kind, determine whether we know that
1451a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// we're at the start of an expression or a type-specifier-seq (which may
1452a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// be an expression, in C++).
1453a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  ///
1454a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// This routine does not attempt to resolve any of the trick cases, e.g.,
1455a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// those involving lookup of identifiers.
1456a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  ///
1457a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// \returns \c TPR_true if this token starts an expression, \c TPR_false if
1458a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot
1459a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  /// tell.
1460a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor  TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind);
1461a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor
1462b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a
1463b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// declaration specifier, TPResult::False() if it is not,
1464b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult::Ambiguous() if it could be either a decl-specifier or a
1465b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// function-style cast, and TPResult::Error() if a parsing error was
1466b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// encountered.
14675404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Doesn't consume tokens.
1468b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult isCXXDeclarationSpecifier();
1469a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor
14705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // "Tentative parsing" functions, used for disambiguation. If a parsing error
1471b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // is encountered they will return TPResult::Error().
1472b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // Returning TPResult::True()/False() indicates that the ambiguity was
1473b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates
1474b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // that more tentative parsing is necessary for disambiguation.
14755404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // They all consume tokens, so backtracking should be used after calling them.
14765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1477b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseDeclarationSpecifier();
1478b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseSimpleDeclaration();
1479b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseTypeofSpecifier();
14809bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor  TPResult TryParseProtocolQualifiers();
1481b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseInitDeclaratorList();
148278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true);
1483b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseParameterDeclarationClause();
1484b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseFunctionDeclarator();
1485b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseBracketDeclarator();
14865404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1487683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor  TypeResult ParseTypeName(SourceRange *Range = 0,
1488683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor                           Declarator::TheContext Context
1489683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor                                                 = Declarator::TypeNameContext);
149098eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump  void ParseBlockId();
14917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
14927f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
14937f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (!attrs.Range.isValid()) return;
14947f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    DiagnoseProhibitedAttributes(attrs);
14957f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
14967f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
14977f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
14987f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseGNUAttributes(Declarator &D) {
14997f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (Tok.is(tok::kw___attribute)) {
15007f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParsedAttributes attrs;
15017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      SourceLocation endLoc;
15027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseGNUAttributes(attrs, &endLoc);
15037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      D.addAttributes(attrs.getList(), endLoc);
15047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
15057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
15067f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseGNUAttributes(ParsedAttributes &attrs,
15077f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                               SourceLocation *endLoc = 0) {
15087f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (Tok.is(tok::kw___attribute))
15097f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseGNUAttributes(attrs, endLoc);
15107f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
15117f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseGNUAttributes(ParsedAttributes &attrs,
15127f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                          SourceLocation *endLoc = 0);
15137f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
15147f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseCXX0XAttributes(Declarator &D) {
15157f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
15167f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParsedAttributesWithRange attrs;
15177f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      SourceLocation endLoc;
15187f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseCXX0XAttributes(attrs, &endLoc);
15197f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      D.addAttributes(attrs.getList(), endLoc);
15207f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
15217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
15227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseCXX0XAttributes(ParsedAttributes &attrs,
15237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                 SourceLocation *endLoc = 0) {
15247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
15257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParsedAttributesWithRange attrsWithRange;
15267f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseCXX0XAttributes(attrsWithRange, endLoc);
15277f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      attrs.append(attrsWithRange.getList());
15287f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    }
15297f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
15307f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
15317f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                 SourceLocation *endLoc = 0) {
15327f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
15337f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseCXX0XAttributes(attrs, endLoc);
15347f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
15357f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
15367f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                            SourceLocation *EndLoc = 0);
15377f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
15387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
15397f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                     SourceLocation *endLoc = 0) {
15407f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall    if (getLang().Microsoft && Tok.is(tok::l_square))
15417f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall      ParseMicrosoftAttributes(attrs, endLoc);
15427f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  }
15437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseMicrosoftAttributes(ParsedAttributes &attrs,
15447f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                SourceLocation *endLoc = 0);
15457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseMicrosoftDeclSpec(ParsedAttributes &attrs);
15467f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
15477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall  void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
1548f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne  void ParseOpenCLAttributes(ParsedAttributes &attrs);
15497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
1550d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  void ParseTypeofSpecifier(DeclSpec &DS);
15516fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  void ParseDecltypeSpecifier(DeclSpec &DS);
1552bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
155360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseCXX0XAlignArgument(SourceLocation Start);
1554eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1555cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson  VirtSpecifiers::Specifier isCXX0XVirtSpecifier() const;
1556b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson  void ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS);
15571f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson
1558cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson  ClassVirtSpecifiers::Specifier isCXX0XClassVirtSpecifier() const;
1559cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson  void ParseOptionalCXX0XClassVirtSpecifierSeq(ClassVirtSpecifiers &CVS);
1560cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson
1561eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
1562eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// enter a new C++ declarator scope and exit it when the function is
1563eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// finished.
1564eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  class DeclaratorScopeObj {
1565eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    Parser &P;
1566751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis    CXXScopeSpec &SS;
1567f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis    bool EnteredScope;
1568f7f3d0db754db0500b56d49ac19f795f13965912John McCall    bool CreatedScope;
1569eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  public:
1570f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis    DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
1571f7f3d0db754db0500b56d49ac19f795f13965912John McCall      : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
1572eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1573eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    void EnterDeclaratorScope() {
15742bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis      assert(!EnteredScope && "Already entered the scope!");
1575f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      assert(SS.isSet() && "C++ scope was not set!");
1576f7f3d0db754db0500b56d49ac19f795f13965912John McCall
1577f7f3d0db754db0500b56d49ac19f795f13965912John McCall      CreatedScope = true;
1578f7f3d0db754db0500b56d49ac19f795f13965912John McCall      P.EnterScope(0); // Not a decl scope.
1579f7f3d0db754db0500b56d49ac19f795f13965912John McCall
158023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor      if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
15813fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor        EnteredScope = true;
1582eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
1583eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1584eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    ~DeclaratorScopeObj() {
1585f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      if (EnteredScope) {
1586f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis        assert(SS.isSet() && "C++ scope was cleared ?");
158723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor        P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
1588f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      }
1589f7f3d0db754db0500b56d49ac19f795f13965912John McCall      if (CreatedScope)
1590f7f3d0db754db0500b56d49ac19f795f13965912John McCall        P.ExitScope();
1591eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
1592eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  };
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseDeclarator - Parse and verify a newly-initialized declarator.
15955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDeclarator(Declarator &D);
15964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  /// A function that parses a variant of direct-declarator.
15974c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
15984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDeclaratorInternal(Declarator &D,
15994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl                               DirectDeclParseFunction DirectDeclParser);
16007f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall
1601bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true,
1602bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                 bool CXX0XAttributesAllowed = true);
16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDirectDeclarator(Declarator &D);
16045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseParenDeclarator(Declarator &D);
16057399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner  void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
16067f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                               ParsedAttributes &attrs,
16077399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner                               bool RequiresArg = false);
160866d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner  void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
160983a944763b0948c608eb48f101ec10a1ae5da46aChris Lattner                                             IdentifierInfo *FirstIdent,
161083a944763b0948c608eb48f101ec10a1ae5da46aChris Lattner                                             SourceLocation FirstIdentLoc,
161166d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner                                             Declarator &D);
16125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseBracketDeclarator(Declarator &D);
16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16148f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  //===--------------------------------------------------------------------===//
16158f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  // C++ 7: Declarations [dcl.dcl]
16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1617bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt  bool isCXX0XAttributeSpecifier(bool FullLookahead = false,
1618bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt                                 tok::TokenKind *After = 0);
1619bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt
1620d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl  Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd,
1621d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                       SourceLocation InlineLoc = SourceLocation());
1622d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context);
1623d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseUsingDirectiveOrDeclaration(unsigned Context,
162478b810559d89e996e00684335407443936ce34a1John McCall                                         const ParsedTemplateInfo &TemplateInfo,
1625d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                                         SourceLocation &DeclEnd,
16267f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                                         ParsedAttributesWithRange &attrs);
162778b810559d89e996e00684335407443936ce34a1John McCall  Decl *ParseUsingDirective(unsigned Context,
162878b810559d89e996e00684335407443936ce34a1John McCall                            SourceLocation UsingLoc,
16297f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                            SourceLocation &DeclEnd,
16307f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall                            ParsedAttributes &attrs);
163178b810559d89e996e00684335407443936ce34a1John McCall  Decl *ParseUsingDeclaration(unsigned Context,
163278b810559d89e996e00684335407443936ce34a1John McCall                              const ParsedTemplateInfo &TemplateInfo,
163378b810559d89e996e00684335407443936ce34a1John McCall                              SourceLocation UsingLoc,
1634d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                              SourceLocation &DeclEnd,
1635d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                              AccessSpecifier AS = AS_none);
1636d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
1637d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
1638d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                            SourceLocation AliasLoc, IdentifierInfo *Alias,
1639d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl                            SourceLocation &DeclEnd);
16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1641e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
1642e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 9: classes [class] and C structs/unions.
1643059101f922de6eb765601459925f4c8914420b23Douglas Gregor  TypeResult ParseClassName(SourceLocation &EndLocation, CXXScopeSpec &SS);
16444c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
16451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                           DeclSpec &DS,
16464d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1647d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                           AccessSpecifier AS = AS_none,
1648d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl                           bool SuppressDeclarations = false);
16494cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType,
1650d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                   Decl *TagDecl);
165137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseCXXClassMemberDeclaration(AccessSpecifier AS,
1652c9068d7dd94d439cec66c421115d15303e481025John McCall                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1653c9068d7dd94d439cec66c421115d15303e481025John McCall                                 ParsingDeclRAIIObject *DiagsFromTParams = 0);
1654d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseConstructorInitializer(Decl *ConstructorDecl);
1655d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  MemInitResult ParseMemInitializer(Decl *ConstructorDecl);
1656d33133cdc1af466f9c276249b2621be03867888bEli Friedman  void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
1657d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                       Decl *ThisDecl);
1658e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1659e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
1660e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 10: Derived classes [class.derived]
1661d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  void ParseBaseClause(Decl *ClassDecl);
1662d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  BaseResult ParseBaseSpecifier(Decl *ClassDecl);
16631b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor  AccessSpecifier getAccessSpecifierIfPresent() const;
16641cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor
16653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
16663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    IdentifierInfo *Name,
16673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    SourceLocation NameLoc,
16683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    bool EnteringContext,
1669b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                    ParsedType ObjectType,
1670d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                    UnqualifiedId &Id,
16710278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor                                    bool AssumeTemplateId,
16720278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor                                    SourceLocation TemplateKWLoc);
1673ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
1674b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                  ParsedType ObjectType,
1675ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                  UnqualifiedId &Result);
16763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
167702a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor                          bool AllowDestructorName,
167802a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor                          bool AllowConstructorName,
1679b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                          ParsedType ObjectType,
16803f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                          UnqualifiedId &Result);
16813f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
16821cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor  //===--------------------------------------------------------------------===//
1683adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14: Templates [temp]
1684c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor
1685adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14.1: Template Parameters [temp.param]
1686d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseDeclarationStartingWithTemplate(unsigned Context,
16874d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                                 SourceLocation &DeclEnd,
16884d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                                 AccessSpecifier AS = AS_none);
1689d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context,
169097144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner                                                     SourceLocation &DeclEnd,
16914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                                     AccessSpecifier AS);
1692d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseSingleDeclarationAfterTemplate(
16931426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       unsigned Context,
16944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                       const ParsedTemplateInfo &TemplateInfo,
1695c9068d7dd94d439cec66c421115d15303e481025John McCall                                       ParsingDeclRAIIObject &DiagsFromParams,
16961426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       SourceLocation &DeclEnd,
16971426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       AccessSpecifier AS=AS_none);
16981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseTemplateParameters(unsigned Depth,
16991f58816e6589ef15d1509c6c99bb8fabf2a4cda9John McCall                               llvm::SmallVectorImpl<Decl*> &TemplateParams,
17001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               SourceLocation &LAngleLoc,
1701c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor                               SourceLocation &RAngleLoc);
1702c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor  bool ParseTemplateParameterList(unsigned Depth,
17031f58816e6589ef15d1509c6c99bb8fabf2a4cda9John McCall                                  llvm::SmallVectorImpl<Decl*> &TemplateParams);
170498440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor  bool isStartOfTemplateTypeParameter();
1705d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTemplateParameter(unsigned Depth, unsigned Position);
1706d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTypeParameter(unsigned Depth, unsigned Position);
1707d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
1708d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
1709d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor  // C++ 14.3: Template arguments [temp.arg]
1710314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  typedef llvm::SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
1711cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
17127532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  bool ParseTemplateIdAfterTemplateName(TemplateTy Template,
17131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        SourceLocation TemplateNameLoc,
1714059101f922de6eb765601459925f4c8914420b23Douglas Gregor                                        const CXXScopeSpec &SS,
1715cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        bool ConsumeLastToken,
1716cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        SourceLocation &LAngleLoc,
1717cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        TemplateArgList &TemplateArgs,
1718cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        SourceLocation &RAngleLoc);
1719cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
1720c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner  bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
1721059101f922de6eb765601459925f4c8914420b23Douglas Gregor                               CXXScopeSpec &SS,
1722ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                               UnqualifiedId &TemplateName,
172339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                               SourceLocation TemplateKWLoc = SourceLocation(),
172439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                               bool AllowTypeAnnotation = true);
1725059101f922de6eb765601459925f4c8914420b23Douglas Gregor  void AnnotateTemplateIdTokenAsType();
1726d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor  bool IsTemplateArgumentList(unsigned Skip = 0);
1727314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
1728788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  ParsedTemplateArgument ParseTemplateTemplateArgument();
1729314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  ParsedTemplateArgument ParseTemplateArgument();
1730d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall  Decl *ParseExplicitInstantiation(SourceLocation ExternLoc,
1731d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                        SourceLocation TemplateLoc,
1732d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                        SourceLocation &DeclEnd);
173364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
173464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  //===--------------------------------------------------------------------===//
173564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // GNU G++: Type Traits [Type-Traits.html in the GCC manual]
173660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ParseUnaryTypeTrait();
17376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult ParseBinaryTypeTrait();
1738f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor
1739f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  //===--------------------------------------------------------------------===//
1740f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  // Preprocessor code-completion pass-through
1741f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  virtual void CodeCompleteDirective(bool InConditional);
1742f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor  virtual void CodeCompleteInConditionalExclusion();
17431fbb447e9d43c2c676e94081fbfee7eb6cbe933bDouglas Gregor  virtual void CodeCompleteMacroName(bool IsDefinition);
1744f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor  virtual void CodeCompletePreprocessorExpression();
1745f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor  virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro,
1746f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor                                         MacroInfo *MacroInfo,
1747f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor                                         unsigned ArgumentIndex);
174855817afdf9d453a443262a733f6caf6692dca118Douglas Gregor  virtual void CodeCompleteNaturalLanguage();
17495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
17525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1754