Parser.h revision 1ac7104947020a60430ba6f519cd5869af77046f
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
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Lex/Preprocessor.h"
1806c0fecd197fef21e265a41bca8dc5022de1f864Douglas Gregor#include "clang/Parse/AccessSpecifier.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Parse/Action.h"
20eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis#include "clang/Parse/DeclSpec.h"
214726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek#include "llvm/ADT/OwningPtr.h"
224cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis#include <stack>
231100258c19dd8967ba078c0bc81fc06cea9d033fChris Lattner#include <list>
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
26fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar  class AttributeList;
27fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar  class PragmaHandler;
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Scope;
293cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  class DiagnosticBuilder;
300102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  class Parser;
314726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  class PragmaUnusedHandler;
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
330102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// PrettyStackTraceParserEntry - If a crash happens while the parser is active,
340102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// an entry is printed for it.
350102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerclass PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry {
360102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  const Parser &P;
370102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerpublic:
380102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  PrettyStackTraceParserEntry(const Parser &p) : P(p) {}
390102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  virtual void print(llvm::raw_ostream &OS) const;
400102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner};
411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages.  After
445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read.
465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Parser {
484726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  friend class PragmaUnusedHandler;
490102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  PrettyStackTraceParserEntry CrashInfo;
501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Preprocessor &PP;
521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5397d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher  /// Tok - The current token we are peeking ahead.  All parsing methods assume
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// that this is valid.
55d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner  Token Tok;
561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
574b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // PrevTokLocation - The location of the token we previously
584b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // consumed. This token is used for diagnostics where we expected to
594b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // see a token following another token (e.g., the ';' at the end of
604b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  // a statement).
614b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  SourceLocation PrevTokLocation;
624b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned short ParenCount, BracketCount, BraceCount;
645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Actions - These are the callbacks we invoke as we parse various constructs
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// in the file.  This refers to the common base class between MinimalActions
675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// and SemaActions for those uses that don't matter.
685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Action &Actions;
691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Scope *CurScope;
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Diagnostic &Diags;
721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
739e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  /// ScopeCache - Cache scopes to reduce malloc traffic.
749e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  enum { ScopeCacheSize = 16 };
759e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  unsigned NumCachedScopes;
769e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  Scope *ScopeCache[ScopeCacheSize];
77662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar
78662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  /// Ident_super - IdentifierInfo for "super", to support fast
79662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  /// comparison.
80662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  IdentifierInfo *Ident_super;
81662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar
824726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  llvm::OwningPtr<PragmaHandler> PackHandler;
834726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek  llvm::OwningPtr<PragmaHandler> UnusedHandler;
849991479ad5dde617168cc1e4b18425cdbbfd9fa9Eli Friedman  llvm::OwningPtr<PragmaHandler> WeakHandler;
852e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor  llvm::OwningPtr<clang::CommentHandler> CommentHandler;
861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// Whether the '>' token acts as an operator or not. This will be
8855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// true except when we are parsing an expression within a C++
8955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// template argument list, where the '>' closes the template
9055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// argument list.
9155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  bool GreaterThanIsOperator;
9255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
93c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor  /// The "depth" of the template parameters currently being parsed.
94c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor  unsigned TemplateParameterDepth;
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96f02da89d7bddc319be52605d36442518647116b4Douglas Gregor  /// \brief RAII object that makes '>' behave either as an operator
97f02da89d7bddc319be52605d36442518647116b4Douglas Gregor  /// or as the closing angle bracket for a template argument list.
98f02da89d7bddc319be52605d36442518647116b4Douglas Gregor  struct GreaterThanIsOperatorScope {
9955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor    bool &GreaterThanIsOperator;
10055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor    bool OldGreaterThanIsOperator;
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102f02da89d7bddc319be52605d36442518647116b4Douglas Gregor    GreaterThanIsOperatorScope(bool &GTIO, bool Val)
1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
104f02da89d7bddc319be52605d36442518647116b4Douglas Gregor      GreaterThanIsOperator = Val;
10555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor    }
10655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
107f02da89d7bddc319be52605d36442518647116b4Douglas Gregor    ~GreaterThanIsOperatorScope() {
10855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor      GreaterThanIsOperator = OldGreaterThanIsOperator;
10955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor    }
11055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  };
1111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Parser(Preprocessor &PP, Action &Actions);
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ~Parser();
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const LangOptions &getLang() const { return PP.getLangOptions(); }
117444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
1180102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  Preprocessor &getPreprocessor() const { return PP; }
1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Action &getActions() const { return Actions; }
1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1210102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner  const Token &getCurToken() const { return Tok; }
1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Type forwarding.  All of these are statically 'void*', but they may all be
1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // different actual classes based on the actions in place.
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef Action::ExprTy ExprTy;
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef Action::StmtTy StmtTy;
127b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  typedef Action::DeclPtrTy DeclPtrTy;
128682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  typedef Action::DeclGroupPtrTy DeclGroupPtrTy;
1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef Action::TypeTy TypeTy;
130f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor  typedef Action::BaseTy BaseTy;
1317ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  typedef Action::MemInitTy MemInitTy;
132eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  typedef Action::CXXScopeTy CXXScopeTy;
133c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor  typedef Action::TemplateParamsTy TemplateParamsTy;
1347532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  typedef Action::TemplateTy TemplateTy;
1357ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
136c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor  typedef llvm::SmallVector<TemplateParamsTy *, 4> TemplateParameterLists;
137c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor
138d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor  typedef Action::ExprResult        ExprResult;
139d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor  typedef Action::StmtResult        StmtResult;
140d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor  typedef Action::BaseResult        BaseResult;
141d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor  typedef Action::MemInitResult     MemInitResult;
142809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor  typedef Action::TypeResult        TypeResult;
14315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
14415faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  typedef Action::OwningExprResult OwningExprResult;
14515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  typedef Action::OwningStmtResult OwningStmtResult;
14615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
1471d922960e083906a586609ac6978678147250177Sebastian Redl  typedef Action::ExprArg ExprArg;
148a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl  typedef Action::MultiStmtArg MultiStmtArg;
149a99fad8ff134273fe85f2970c7d89133d1218900Anders Carlsson  typedef Action::FullExprArg FullExprArg;
1501d922960e083906a586609ac6978678147250177Sebastian Redl
15161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  /// Adorns a ExprResult with Actions to make it an OwningExprResult
15261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningExprResult Owned(ExprResult res) {
15361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl    return OwningExprResult(Actions, res);
15461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
15561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  /// Adorns a StmtResult with Actions to make it an OwningStmtResult
15661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult Owned(StmtResult res) {
15761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl    return OwningStmtResult(Actions, res);
15861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
15961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
16061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningExprResult ExprError() { return OwningExprResult(Actions, true); }
16161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult StmtError() { return OwningStmtResult(Actions, true); }
162d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor
1632f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); }
1642f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningStmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); }
16561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
1665ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis  OwningExprResult ExprEmpty() { return OwningExprResult(Actions, false); }
1675ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Parsing methods.
1691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseTranslationUnit - All in one method that initializes parses, and
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// shuts down the parser.
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseTranslationUnit();
1731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Initialize - Warm up the parser.
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Initialize();
1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
1791f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff  /// the EOF was encountered.
180682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
1811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1821ac7104947020a60430ba6f519cd5869af77046fFariborz Jahanian  DeclGroupPtrTy RetrievePendingObjCImpDecl();
18363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Low-Level token peeking and consumption methods.
1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //
1881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenParen - Return true if the cur token is '(' or ')'.
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenParen() const {
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren;
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBracket - Return true if the cur token is '[' or ']'.
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBracket() const {
1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square;
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBrace - Return true if the cur token is '{' or '}'.
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBrace() const {
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace;
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenStringLiteral - True if this token is a string-literal.
2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenStringLiteral() const {
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::string_literal ||
2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           Tok.getKind() == tok::wide_string_literal;
2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
208eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeToken - Consume the current 'peek token' and lex the next one.
210d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu  /// This does not work with all kinds of tokens: strings and specific other
2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tokens must be consumed with custom methods below.  This returns the
2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// location of the consumed token.
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeToken() {
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() &&
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           !isTokenBrace() &&
2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should consume special tokens with Consume*Token");
2174b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
2194b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// current token type.  This should only be used in cases where the type of
2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the token really isn't known, e.g. in error recovery.
2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeAnyToken() {
2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isTokenParen())
2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeParen();
2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBracket())
2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBracket();
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBrace())
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBrace();
232d62701bc5321049353017e9abf1963edd57646aaSteve Naroff    else if (isTokenStringLiteral())
233d62701bc5321049353017e9abf1963edd57646aaSteve Naroff      return ConsumeStringToken();
2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeToken();
2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeParen - This consume method keeps the paren count up-to-date.
2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeParen() {
2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenParen() && "wrong consume method");
2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_paren)
2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++ParenCount;
2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (ParenCount)
2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --ParenCount;       // Don't let unbalanced )'s drive the count negative.
2464b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
2484b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBracket - This consume method keeps the bracket count up-to-date.
2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBracket() {
2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBracket() && "wrong consume method");
2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_square)
2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BracketCount;
2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BracketCount)
2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BracketCount;     // Don't let unbalanced ]'s drive the count negative.
2591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2604b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
2624b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBrace - This consume method keeps the brace count up-to-date.
2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBrace() {
2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBrace() && "wrong consume method");
2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_brace)
2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BraceCount;
2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BraceCount)
2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BraceCount;     // Don't let unbalanced }'s drive the count negative.
2731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2744b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
2764b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeStringToken - Consume the current 'peek token', lexing a new one
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// and returning the token kind.  This method is specific to strings, as it
2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// handles string literal concatenation, as per C99 5.1.1.2, translation
2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// phase #6.
2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeStringToken() {
2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenStringLiteral() &&
2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should only consume string literals with this method");
2864b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    PrevTokLocation = Tok.getLocation();
2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
2884b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor    return PrevTokLocation;
2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2916b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// GetLookAheadToken - This peeks ahead N tokens and returns that token
2926b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// without consuming any tokens.  LookAhead(0) returns 'Tok', LookAhead(1)
2936b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// returns the token after Tok, etc.
2946b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
2956b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// Note that this differs from the Preprocessor's LookAhead method, because
2966b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// the Parser always has one token lexed that the preprocessor doesn't.
2976b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
29803db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis  const Token &GetLookAheadToken(unsigned N) {
2996b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    if (N == 0 || Tok.is(tok::eof)) return Tok;
3006b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    return PP.LookAhead(N-1);
3016b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  }
302f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis
303f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// NextToken - This peeks ahead one token and returns it without
304f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// consuming it.
305f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  const Token &NextToken() {
30603db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis    return PP.LookAhead(0);
307f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  }
3085404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
309eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// TryAnnotateTypeOrScopeToken - If the current token position is on a
310eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// typename (possibly qualified in C++) or a C++ scope specifier not followed
311eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens
312eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// with a single annotation token representing the typename or C++ scope
313eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// respectively.
314eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// This simplifies handling of C++ scope specifiers and allows efficient
315eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// backtracking without the need to re-parse and resolve nested-names and
316eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// typenames.
31744802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// It will mainly be called when we expect to treat identifiers as typenames
31844802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// (if they are typenames). For example, in C we do not expect identifiers
31944802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// inside expressions to be treated as typenames so it will not be called
32044802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// for expressions in C.
321a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner  ///
322a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner  /// This returns true if the token was annotated.
323495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor  bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false);
324eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
3254bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis  /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
3265e02c47a7085831586344a9728763cb50540c7f7Chris Lattner  /// annotates C++ scope specifiers.  This returns true if the token was
3275e02c47a7085831586344a9728763cb50540c7f7Chris Lattner  /// annotated.
328495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor  bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
329eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
3305404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// TentativeParsingAction - An object that is used as a kind of "tentative
3315404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// parsing transaction". It gets instantiated to mark the token position and
3325404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// after the token consumption is done, Commit() or Revert() is called to
3335404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// either "commit the consumed tokens" or revert to the previously marked
3345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// token position. Example:
3355404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
336314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  ///   TentativeParsingAction TPA(*this);
3375404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ConsumeToken();
3385404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ....
3395404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   TPA.Revert();
3405404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
3415404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  class TentativeParsingAction {
3425404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Parser &P;
3435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Token PrevTok;
3445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    bool isActive;
3455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
3465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  public:
3475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    explicit TentativeParsingAction(Parser& p) : P(p) {
3485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      PrevTok = P.Tok;
3495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.EnableBacktrackAtThisPos();
3505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = true;
3515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
3525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Commit() {
3535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
3545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.CommitBacktrackedTokens();
3555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
3565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
3575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Revert() {
3585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
3595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.Backtrack();
3605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.Tok = PrevTok;
3615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
3625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
3635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    ~TentativeParsingAction() {
3645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(!isActive && "Forgot to call Commit or Revert!");
3655404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
3665404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  };
3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'),
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this helper function matches and consumes the specified RHS token if
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// present.  If not present, it emits the specified diagnostic indicating
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// that the parser failed to match the RHS of the token at LHSLoc.  LHSName
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// should be the name of the unmatched LHS token.  This returns the location
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the consumed token.
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok,
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                     SourceLocation LHSLoc);
3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// input.  If so, it is consumed and false is returned.
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If the input is malformed, this emits the specified diagnostic.  Next, if
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipToTok is specified, it calls SkipUntil(SkipToTok).  Finally, true is
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// returned.
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag,
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        const char *DiagMsg = "",
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        tok::TokenKind SkipToTok = tok::unknown);
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Scope manipulation
3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3918935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// ParseScope - Introduces a new scope for parsing. The kind of
3928935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// scope is determined by ScopeFlags. Objects of this type should
3938935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// be created on the stack to coincide with the position where the
3948935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// parser enters the new scope, and this object's constructor will
3958935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// create that new scope. Similarly, once the object is destroyed
3968935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// the parser will exit the scope.
3978935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  class ParseScope {
3988935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    Parser *Self;
3998935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope(const ParseScope&); // do not implement
4008935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope& operator=(const ParseScope&); // do not implement
4018935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
4028935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  public:
4038935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ParseScope - Construct a new object to manage a scope in the
4048935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // parser Self where the new Scope is created with the flags
4058935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ScopeFlags, but only when ManageScope is true (the default). If
4068935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ManageScope is false, this object does nothing.
4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true)
4088935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      : Self(Self) {
4098935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (ManageScope)
4108935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->EnterScope(ScopeFlags);
4118935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      else
4128935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        this->Self = 0;
4138935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
4148935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
4158935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // Exit - Exit the scope associated with this object now, rather
4168935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // than waiting until the object is destroyed.
4178935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    void Exit() {
4188935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (Self) {
4198935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->ExitScope();
4208935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self = 0;
4218935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      }
4228935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
4238935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
4248935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ~ParseScope() {
4258935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      Exit();
4268935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
4278935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  };
4288935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EnterScope - Start a new scope.
4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EnterScope(unsigned ScopeFlags);
4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExitScope - Pop a scope off the scope stack.
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ExitScope();
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Diagnostic Emission and Error recovery.
43715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
4383cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
4393cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
44015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
4411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SuggestParentheses(SourceLocation Loc, unsigned DK,
4424b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor                          SourceRange ParenRange);
4434b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipUntil - Read tokens until we get to the specified token, then consume
44582c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff  /// it (unless DontConsume is true).  Because we cannot guarantee that the
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// token will ever occur, this skips to the next token, or to some likely
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// good stopping point.  If StopAtSemi is true, skipping will stop at a ';'
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// character.
4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If SkipUntil finds the specified token, it returns true, otherwise it
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returns false.
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                 bool DontConsume = false) {
4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SkipUntil(&T, 1, StopAtSemi, DontConsume);
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                 bool DontConsume = false) {
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    tok::TokenKind TokArray[] = {T1, T2};
4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SkipUntil(TokArray, 2, StopAtSemi, DontConsume);
4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                 bool StopAtSemi = true, bool DontConsume = false);
4637ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4654cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // Lexing and parsing of C++ inline methods.
4664cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
4674cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  struct LexedMethod {
468b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    Action::DeclPtrTy D;
46972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    CachedTokens Toks;
470d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor
471d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// \brief Whether this member function had an associated template
472d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// scope. When true, D is a template declaration.
473d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// othewise, it is a member function declaration.
474d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    bool TemplateScope;
475d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor
476d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    explicit LexedMethod(Action::DeclPtrTy MD) : D(MD), TemplateScope(false) {}
4774cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  };
4784cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
47972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// LateParsedDefaultArgument - Keeps track of a parameter that may
48072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// have a default argument that cannot be parsed yet because it
48172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// occurs within a member function declaration inside the class
48272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// (C++ [class.mem]p2).
48372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  struct LateParsedDefaultArgument {
4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    explicit LateParsedDefaultArgument(Action::DeclPtrTy P,
48572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor                                       CachedTokens *Toks = 0)
48672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor      : Param(P), Toks(Toks) { }
48772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
48872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Param - The parameter declaration for this parameter.
489b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    Action::DeclPtrTy Param;
49072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
49172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Toks - The sequence of tokens that comprises the default
49272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// argument expression, not including the '=' or the terminating
49372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// ')' or ','. This will be NULL for parameters that have no
49472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// default argument.
49572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    CachedTokens *Toks;
49672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
4971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// LateParsedMethodDeclaration - A method declaration inside a class that
49972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// contains at least one entity whose parsing needs to be delayed
50072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// until the class itself is completely-defined, such as a default
50172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// argument (C++ [class.mem]p2).
50272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  struct LateParsedMethodDeclaration {
5031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    explicit LateParsedMethodDeclaration(Action::DeclPtrTy M)
504d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor      : Method(M), TemplateScope(false) { }
50572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
50672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// Method - The method declaration.
507b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner    Action::DeclPtrTy Method;
50872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
509d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// \brief Whether this member function had an associated template
510d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// scope. When true, D is a template declaration.
511d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    /// othewise, it is a member function declaration.
512d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor    bool TemplateScope;
5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// DefaultArgs - Contains the parameters of the function and
51572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// their default arguments. At least one of the parameters will
51672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// have a default argument, but all of the parameters of the
51772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// method will be stored so that they can be reintroduced into
5181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// scope at the appropriate times.
51972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
52072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
52172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
52272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// LateParsedMethodDecls - During parsing of a top (non-nested) C++
52372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// class, its method declarations that contain parts that won't be
52472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// parsed until after the definiton is completed (C++ [class.mem]p2),
52572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// the method declarations will be stored here with the tokens that
52672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  /// will be parsed to create those entities.
52772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  typedef std::list<LateParsedMethodDeclaration> LateParsedMethodDecls;
52872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
5294cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// LexedMethodsForTopClass - During parsing of a top (non-nested) C++ class,
5304cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// its inline method definitions and the inline method definitions of its
5314cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// nested classes are lexed and stored here.
53272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  typedef std::list<LexedMethod> LexedMethodsForTopClass;
53372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
5346569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// \brief Representation of a class that has been parsed, including
5356569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// any member function declarations or definitions that need to be
5366569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// parsed after the corresponding top-level class is complete.
5376569d68745c8213709740337d2be52b031384f58Douglas Gregor  struct ParsingClass {
5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass)
5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : TopLevelClass(TopLevelClass), TemplateScope(false),
5406569d68745c8213709740337d2be52b031384f58Douglas Gregor        TagOrTemplate(TagOrTemplate) { }
5416569d68745c8213709740337d2be52b031384f58Douglas Gregor
5426569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Whether this is a "top-level" class, meaning that it is
5436569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// not nested within another class.
5446569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool TopLevelClass : 1;
5456569d68745c8213709740337d2be52b031384f58Douglas Gregor
5466569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Whether this class had an associated template
5476569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// scope. When true, TagOrTemplate is a template declaration;
5486569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// othewise, it is a tag declaration.
5496569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool TemplateScope : 1;
5506569d68745c8213709740337d2be52b031384f58Douglas Gregor
5516569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief The class or class template whose definition we are parsing.
5526569d68745c8213709740337d2be52b031384f58Douglas Gregor    DeclPtrTy TagOrTemplate;
55372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
55472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// MethodDecls - Method declarations that contain pieces whose
55572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// parsing will be delayed until the class is fully defined.
55672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    LateParsedMethodDecls MethodDecls;
55772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor
55872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// MethodDefs - Methods whose definitions will be parsed once the
55972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    /// class has been fully defined.
56072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor    LexedMethodsForTopClass MethodDefs;
5616569d68745c8213709740337d2be52b031384f58Douglas Gregor
5626569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Nested classes inside this class.
5636569d68745c8213709740337d2be52b031384f58Douglas Gregor    llvm::SmallVector<ParsingClass*, 4> NestedClasses;
56472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor  };
5654cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
5666569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// \brief The stack of classes that is currently being
5676569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// parsed. Nested and local classes will be pushed onto this stack
5686569d68745c8213709740337d2be52b031384f58Douglas Gregor  /// when they are parsed, and removed afterward.
5696569d68745c8213709740337d2be52b031384f58Douglas Gregor  std::stack<ParsingClass *> ClassStack;
5704cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
5716569d68745c8213709740337d2be52b031384f58Douglas Gregor  ParsingClass &getCurrentClass() {
5726569d68745c8213709740337d2be52b031384f58Douglas Gregor    assert(!ClassStack.empty() && "No lexed method stacks!");
5736569d68745c8213709740337d2be52b031384f58Douglas Gregor    return *ClassStack.top();
5744cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
5754cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
57654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// \brief RAII object used to inform the actions that we're
57754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// currently parsing a declaration.  This is active when parsing a
57854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// variable's initializer, but not when parsing the body of a
57954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// class or function definition.
58054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclRAIIObject {
58154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    Action &Actions;
58254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    Action::ParsingDeclStackState State;
58354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    bool Popped;
58454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
58554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
58654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) {
58754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      push();
58854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
58954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
59054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ~ParsingDeclRAIIObject() {
59154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      abort();
59254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
59354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
59454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// Resets the RAII object for a new declaration.
59554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void reset() {
59654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      abort();
59754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      push();
59854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
59954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
60054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// Signals that the context was completed without an appropriate
60154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    /// declaration being parsed.
60254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void abort() {
60354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      pop(DeclPtrTy());
60454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
60554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
60654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void complete(DeclPtrTy D) {
60754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      assert(!Popped && "ParsingDeclaration has already been popped!");
60854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      pop(D);
60954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
61054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
61154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  private:
61254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void push() {
61354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      State = Actions.PushParsingDeclaration();
61454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      Popped = false;
61554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
61654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
61754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void pop(DeclPtrTy D) {
61854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      if (!Popped) {
61954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall        Actions.PopParsingDeclaration(State, D);
62054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall        Popped = true;
62154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      }
62254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
62354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
62454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
62554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// A class for parsing a DeclSpec.
62654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclSpec : public DeclSpec {
62754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject ParsingRAII;
62854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
62954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
63054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclSpec(Parser &P) : ParsingRAII(P) {
63154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
63254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
63354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void complete(DeclPtrTy D) {
63454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.complete(D);
63554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
63654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
63754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void abort() {
63854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.abort();
63954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
64054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
64154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
64254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  /// A class for parsing a declarator.
64354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  class ParsingDeclarator : public Declarator {
64454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclRAIIObject ParsingRAII;
64554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
64654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  public:
64754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C)
64854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      : Declarator(DS, C), ParsingRAII(P) {
64954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
65054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
65154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    const ParsingDeclSpec &getDeclSpec() const {
65254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec());
65354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
65454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
65554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    ParsingDeclSpec &getMutableDeclSpec() const {
65654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      return const_cast<ParsingDeclSpec&>(getDeclSpec());
65754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
65854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
65954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void clear() {
66054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      Declarator::clear();
66154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.reset();
66254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
66354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
66454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    void complete(DeclPtrTy D) {
66554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall      ParsingRAII.complete(D);
66654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall    }
66754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  };
66854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall
6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief RAII object used to
6706569d68745c8213709740337d2be52b031384f58Douglas Gregor  class ParsingClassDefinition {
6716569d68745c8213709740337d2be52b031384f58Douglas Gregor    Parser &P;
6726569d68745c8213709740337d2be52b031384f58Douglas Gregor    bool Popped;
6736569d68745c8213709740337d2be52b031384f58Douglas Gregor
6746569d68745c8213709740337d2be52b031384f58Douglas Gregor  public:
6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParsingClassDefinition(Parser &P, DeclPtrTy TagOrTemplate, bool TopLevelClass)
6761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : P(P), Popped(false) {
6776569d68745c8213709740337d2be52b031384f58Douglas Gregor      P.PushParsingClass(TagOrTemplate, TopLevelClass);
6786569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
6796569d68745c8213709740337d2be52b031384f58Douglas Gregor
6806569d68745c8213709740337d2be52b031384f58Douglas Gregor    /// \brief Pop this class of the stack.
6811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    void Pop() {
6826569d68745c8213709740337d2be52b031384f58Douglas Gregor      assert(!Popped && "Nested class has already been popped");
6836569d68745c8213709740337d2be52b031384f58Douglas Gregor      Popped = true;
6846569d68745c8213709740337d2be52b031384f58Douglas Gregor      P.PopParsingClass();
6856569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
6866569d68745c8213709740337d2be52b031384f58Douglas Gregor
6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ~ParsingClassDefinition() {
6886569d68745c8213709740337d2be52b031384f58Douglas Gregor      if (!Popped)
6891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        P.PopParsingClass();
6906569d68745c8213709740337d2be52b031384f58Douglas Gregor    }
6916569d68745c8213709740337d2be52b031384f58Douglas Gregor  };
6926569d68745c8213709740337d2be52b031384f58Douglas Gregor
6934d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// \brief Contains information about any template-specific
6944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// information that has been parsed prior to parsing declaration
6954d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  /// specifiers.
6964d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  struct ParsedTemplateInfo {
6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ParsedTemplateInfo()
6984d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { }
6994d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
7004d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
701c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor                       bool isSpecialization,
702c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor                       bool lastParameterListWasEmpty = false)
7034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      : Kind(isSpecialization? ExplicitSpecialization : Template),
704c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        TemplateParams(TemplateParams),
705c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        LastParameterListWasEmpty(lastParameterListWasEmpty) { }
7064d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
70745f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    explicit ParsedTemplateInfo(SourceLocation ExternLoc,
70845f965581935791a018df829a14dff53c1dd8f47Douglas Gregor                                SourceLocation TemplateLoc)
7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : Kind(ExplicitInstantiation), TemplateParams(0),
710c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
711c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor        LastParameterListWasEmpty(false){ }
7124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
7134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The kind of template we are parsing.
7144d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    enum {
7154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are not parsing a template at all.
7164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      NonTemplate = 0,
7174d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing a template declaration.
7184d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      Template,
7194d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing an explicit specialization.
7204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      ExplicitSpecialization,
7214d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      /// \brief We are parsing an explicit instantiation.
7224d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor      ExplicitInstantiation
7234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    } Kind;
7244d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
7254d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The template parameter lists, for template declarations
7264d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// and explicit specializations.
7274d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    TemplateParameterLists *TemplateParams;
7284d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
72945f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    /// \brief The location of the 'extern' keyword, if any, for an explicit
73045f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    /// instantiation
73145f965581935791a018df829a14dff53c1dd8f47Douglas Gregor    SourceLocation ExternLoc;
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7334d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// \brief The location of the 'template' keyword, for an explicit
7344d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    /// instantiation.
7354d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor    SourceLocation TemplateLoc;
736c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor
737c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor    /// \brief Whether the last template parameter list was empty.
738c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor    bool LastParameterListWasEmpty;
7394d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  };
7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void PushParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass);
74237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void DeallocateParsedClasses(ParsingClass *Class);
74337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void PopParsingClass();
74437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor
74537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  DeclPtrTy ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D,
74637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                                    const ParsedTemplateInfo &TemplateInfo);
74737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseLexedMethodDeclarations(ParsingClass &Class);
74837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseLexedMethodDefs(ParsingClass &Class);
7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
75037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                            CachedTokens &Toks,
75137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                            tok::TokenKind EarlyAbortIf = tok::unknown,
75237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                            bool ConsumeFinalToken = true);
7534d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
7544cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.9: External Definitions.
756682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  DeclGroupPtrTy ParseExternalDeclaration();
7571426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor  bool isDeclarationAfterDeclarator();
7581426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor  bool isStartOfFunctionDefinition();
759682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(
7605aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson            AccessSpecifier AS = AS_none);
7611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  DeclPtrTy ParseFunctionDefinition(ParsingDeclarator &D,
76352591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor                 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseKNRParamDeclarations(Declarator &D);
765ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // EndLoc, if non-NULL, is filled with the location of the last token of
766ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // the simple-asm.
767ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  OwningExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0);
768effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl  OwningExprResult ParseAsmStringLiteral();
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7703536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  // Objective-C External Declarations
7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclPtrTy ParseObjCAtDirectives();
772b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclPtrTy ParseObjCAtInterfaceDeclaration(SourceLocation atLoc,
774dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff                                          AttributeList *prefixAttrs = 0);
7751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
77660fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                       SourceLocation atLoc);
777b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &P,
77871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                   llvm::SmallVectorImpl<SourceLocation> &PLocs,
7791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   bool WarnOnDeclarations,
78071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis                                   SourceLocation &LAngleLoc,
781e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                   SourceLocation &EndProtoLoc);
782b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  void ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
783c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner                                  tok::ObjCKeywordKind contextKey);
784b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
785b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                           AttributeList *prefixAttrs = 0);
7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
787b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ObjCImpDecl;
78863e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian  llvm::SmallVector<DeclPtrTy, 4> PendingObjCImpDecl;
7890416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
790b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCAtImplementationDeclaration(SourceLocation atLoc);
791b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCAtEndDeclaration(SourceLocation atLoc);
792b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCAtAliasDeclaration(SourceLocation atLoc);
793b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCPropertySynthesize(SourceLocation atLoc);
794b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCPropertyDynamic(SourceLocation atLoc);
7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7962fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner  IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
79734870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  // Definitions for Objective-c context sensitive keywords recognition.
79834870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  enum ObjCTypeQual {
79934870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
80034870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_NumQuals
80134870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  };
802a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
8031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
804335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian  bool isTokIdentifier_in() const;
805d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian
806a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  TypeTy *ParseObjCTypeName(ObjCDeclSpec &DS);
807294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  void ParseObjCMethodRequirement();
808b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCMethodPrototype(DeclPtrTy classOrCat,
809c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
810b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
811b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                DeclPtrTy classDecl,
81200933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
813a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
8141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
815b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseObjCMethodDefinition();
8161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.5: Expressions.
8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8202f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult ParseExpression();
8212f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult ParseConstantExpression();
8222f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  // Expr that doesn't include commas.
8232f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult ParseAssignmentExpression();
8242f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl
825d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl  OwningExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
827adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman  OwningExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
828adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman
829d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl  OwningExprResult ParseRHSOfBinaryExpression(OwningExprResult LHS,
830d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl                                              unsigned MinPrec);
831ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl  OwningExprResult ParseCastExpression(bool isUnaryExpression,
832f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis                                       bool isAddressOfOperand,
8332ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                                       bool &NotCastExpr,
8342ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                                       bool parseParenAsExprList);
835f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  OwningExprResult ParseCastExpression(bool isUnaryExpression,
8362ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                                       bool isAddressOfOperand = false,
8372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                                       bool parseParenAsExprList = false);
8382f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult ParsePostfixExpressionSuffix(OwningExprResult LHS);
839d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl  OwningExprResult ParseSizeofAlignofExpression();
840d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl  OwningExprResult ParseBuiltinPrimaryExpression();
8411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8425ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis  OwningExprResult ParseExprAfterTypeofSizeofAlignof(const Token &OpTok,
8435ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis                                                     bool &isCastExpr,
8445ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis                                                     TypeTy *&CastTy,
8455ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis                                                     SourceRange &CastRange);
8460cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
847a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  static const unsigned ExprListSize = 12;
848a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  typedef llvm::SmallVector<ExprTy*, ExprListSize> ExprListTy;
849a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  typedef llvm::SmallVector<SourceLocation, ExprListSize> CommaLocsTy;
8500cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
8510cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis  /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
8529c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor  bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs,
8539c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor                           void (Action::*Completer)(Scope *S, void *Data,
8549c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor                                                     ExprTy **Args,
8559c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor                                                     unsigned NumArgs) = 0,
8569c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor                           void *Data = 0);
857d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl
8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParenParseOption - Control what ParseParenExpression will parse.
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ParenParseOption {
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SimpleExpr,      // Only parse '(' expression ')'
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundStmt,    // Also allow '(' compound-statement ')'
8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CastExpr         // Also allow '(' type-name ')' <anything>
8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
865d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl  OwningExprResult ParseParenExpression(ParenParseOption &ExprType,
8660350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis                                        bool stopIfCastExpr,
8672ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                                        bool parseAsExprList,
868d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl                                        TypeTy *&CastTy,
869d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl                                        SourceLocation &RParenLoc);
8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
871f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  OwningExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
872f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis                                                    TypeTy *&CastTy,
873f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis                                                    SourceLocation LParenLoc,
874f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis                                                    SourceLocation &RParenLoc);
8751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
876d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis  OwningExprResult ParseCompoundLiteralExpression(TypeTy *Ty,
877d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis                                                  SourceLocation LParenLoc,
878d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis                                                  SourceLocation RParenLoc);
8791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
88020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult ParseStringLiteralExpression();
881eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
882eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
883eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  // C++ Expressions
884ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl  OwningExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
8854bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis
8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
8872dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor                                      TypeTy *ObjectType,
8882dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor                                      bool EnteringContext);
8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 5.2p1: C++ Casts
89220df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult ParseCXXCasts();
8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
895c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // C++ 5.2p1: C++ Type Identification
89620df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult ParseCXXTypeid();
897c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
898c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  //===--------------------------------------------------------------------===//
8994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // C++ 9.3.2: C++ 'this' pointer
90020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult ParseCXXThis();
9014cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
9024cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
90350dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  // C++ 15: C++ Throw Expression
90420df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult ParseThrowExpression();
905ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // EndLoc is filled with the location of the last token of the specification.
9067dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl  bool ParseExceptionSpecification(SourceLocation &EndLoc,
907ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl                                   llvm::SmallVector<TypeTy*, 2> &Exceptions,
908ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl                                   llvm::SmallVector<SourceRange, 2> &Ranges,
9097dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl                                   bool &hasAnyExceptionSpec);
91050dd289f45738ed22b7583d52ed2525b927042ffChris Lattner
91150dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  //===--------------------------------------------------------------------===//
9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 2.13.5: C++ Boolean Literals
91320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult ParseCXXBoolLiteral();
9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
916987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // C++ 5.2.3: Explicit type conversion (functional notation)
91720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
918987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
919987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
920987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// This should only be called when the current token is known to be part of
921987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// simple-type-specifier.
922987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
923987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
9242f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor  bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
9252f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor
926987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
9274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // C++ 5.3.4 and 5.3.5: C++ new and delete
928cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool ParseExpressionListOrTypeId(ExprListTy &Exprs, Declarator &D);
9294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDirectNewDeclarator(Declarator &D);
93059232d35f5820e334b6c8b007ae8006f4390055dChris Lattner  OwningExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
93159232d35f5820e334b6c8b007ae8006f4390055dChris Lattner  OwningExprResult ParseCXXDeleteExpression(bool UseGlobal,
93259232d35f5820e334b6c8b007ae8006f4390055dChris Lattner                                            SourceLocation Start);
9334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  //===--------------------------------------------------------------------===//
93571b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis  // C++ if/switch/while/for condition expression.
9362f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl  OwningExprResult ParseCXXCondition();
93771b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis
93871b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
93912e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  // C++ types
94012e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor
94112e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  //===--------------------------------------------------------------------===//
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7.8: Initialization.
9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9440eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  /// ParseInitializer
9450eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///       initializer: [C99 6.7.8]
9460eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         assignment-expression
9470eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         '{' ...
94820df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult ParseInitializer() {
9490eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    if (Tok.isNot(tok::l_brace))
95020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl      return ParseAssignmentExpression();
9510eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    return ParseBraceInitializer();
9520eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  }
95320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl  OwningExprResult ParseBraceInitializer();
9545908a9293b88a3da57ae59b522275d05e1ab11e0Douglas Gregor  OwningExprResult ParseInitializerWithPotentialDesignator();
9551d922960e083906a586609ac6978678147250177Sebastian Redl
9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
957296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  // clang Expressions
9581d922960e083906a586609ac6978678147250177Sebastian Redl
9591d922960e083906a586609ac6978678147250177Sebastian Redl  OwningExprResult ParseBlockLiteralExpression();  // ^{...}
960296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff
961296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  //===--------------------------------------------------------------------===//
9625508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  // Objective-C Expressions
9631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96414dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner  bool isTokObjCMessageIdentifierReceiver() const {
96514dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner    if (!Tok.is(tok::identifier))
96614dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner      return false;
9671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96847246be8ac5b0ddde6c402b8fc6946b6135487b5Chris Lattner    IdentifierInfo *II = Tok.getIdentifierInfo();
969b696ea3a0693798daeafd896d77f0b8f1fec3cc5Douglas Gregor    if (Actions.getTypeName(*II, Tok.getLocation(), CurScope))
97014dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner      return true;
9711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97247246be8ac5b0ddde6c402b8fc6946b6135487b5Chris Lattner    return II == Ident_super;
97314dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner  }
9741d922960e083906a586609ac6978678147250177Sebastian Redl
9751d922960e083906a586609ac6978678147250177Sebastian Redl  OwningExprResult ParseObjCAtExpression(SourceLocation AtLocation);
9761d922960e083906a586609ac6978678147250177Sebastian Redl  OwningExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
9771d922960e083906a586609ac6978678147250177Sebastian Redl  OwningExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
9781d922960e083906a586609ac6978678147250177Sebastian Redl  OwningExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
9791d922960e083906a586609ac6978678147250177Sebastian Redl  OwningExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
9801d922960e083906a586609ac6978678147250177Sebastian Redl  OwningExprResult ParseObjCMessageExpression();
9811d922960e083906a586609ac6978678147250177Sebastian Redl  OwningExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
9821d922960e083906a586609ac6978678147250177Sebastian Redl                                                  SourceLocation NameLoc,
9831d922960e083906a586609ac6978678147250177Sebastian Redl                                                  IdentifierInfo *ReceiverName,
9841d922960e083906a586609ac6978678147250177Sebastian Redl                                                  ExprArg ReceiverExpr);
9851d922960e083906a586609ac6978678147250177Sebastian Redl  OwningExprResult ParseAssignmentExprWithObjCMessageExprStart(
9861d922960e083906a586609ac6978678147250177Sebastian Redl      SourceLocation LBracloc, SourceLocation NameLoc,
9871d922960e083906a586609ac6978678147250177Sebastian Redl      IdentifierInfo *ReceiverName, ExprArg ReceiverExpr);
98861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
9895508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  //===--------------------------------------------------------------------===//
9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.8: Statements and Blocks.
99161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
99261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseStatement() {
99361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl    return ParseStatementOrDeclaration(true);
99461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
99561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseStatementOrDeclaration(bool OnlyStatement = false);
99661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseLabeledStatement();
99761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseCaseStatement();
99861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseDefaultStatement();
99961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseCompoundStatement(bool isStmtExpr = false);
100061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
1001ff871fb8f9c5906a4dee78afd81f60c3837e16cbChris Lattner  bool ParseParenExprOrCondition(OwningExprResult &CondExp,
1002989135901c750af61ef012b6b0a0368be415bc46Chris Lattner                                 bool OnlyAllowCondition = false,
1003989135901c750af61ef012b6b0a0368be415bc46Chris Lattner                                 SourceLocation *LParenLoc = 0,
1004989135901c750af61ef012b6b0a0368be415bc46Chris Lattner                                 SourceLocation *RParenLoc = 0);
100561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseIfStatement();
10069a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseSwitchStatement();
10079a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseWhileStatement();
10089a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseDoStatement();
10099a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseForStatement();
10109a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseGotoStatement();
10119a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseContinueStatement();
10129a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseBreakStatement();
10139a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseReturnStatement();
10149a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseAsmStatement(bool &msAsm);
10159a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult FuzzyParseMicrosoftAsmStatement();
1016a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
1017a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl                           llvm::SmallVectorImpl<ExprTy*> &Constraints,
1018a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl                           llvm::SmallVectorImpl<ExprTy*> &Exprs);
1019a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
1020a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  //===--------------------------------------------------------------------===//
1021a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  // C++ 6: Statements and Blocks
1022a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
1023a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  OwningStmtResult ParseCXXTryBlock();
1024d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl  OwningStmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc);
1025a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  OwningStmtResult ParseCXXCatchBlock();
1026a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
1027a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  //===--------------------------------------------------------------------===//
1028a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl  // Objective-C Statements
1029a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl
103043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl  OwningStmtResult ParseObjCAtStatement(SourceLocation atLoc);
103143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl  OwningStmtResult ParseObjCTryStmt(SourceLocation atLoc);
103243bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl  OwningStmtResult ParseObjCThrowStmt(SourceLocation atLoc);
103343bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl  OwningStmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1034b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
10375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7: Declarations.
103867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall
103967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// A context for parsing declaration specifiers.  TODO: flesh this
104067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// out, there are other significant restrictions on specifiers than
104167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  /// would be best implemented in the parser.
104267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  enum DeclSpecContext {
104367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    DSC_normal, // normal context
104467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall    DSC_class   // class context, enables 'friend'
104567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall  };
10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
104797144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd);
1048cd1477562e7cf03279850885583d615e1f631dd4Chris Lattner  DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context,
1049d8ac05753dc4506224d445ff98399c01da3136e5John McCall                                        SourceLocation &DeclEnd);
105054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall  DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context,
1051d8ac05753dc4506224d445ff98399c01da3136e5John McCall                                bool AllowFunctionDefinitions,
1052d8ac05753dc4506224d445ff98399c01da3136e5John McCall                                SourceLocation *DeclEnd = 0);
1053e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor  DeclPtrTy ParseDeclarationAfterDeclarator(Declarator &D,
1054e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1055b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseFunctionStatementBody(DeclPtrTy Decl);
1056d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl  DeclPtrTy ParseFunctionTryBlock(DeclPtrTy Decl);
1057d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl
1058f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner  bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
10594d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                        const ParsedTemplateInfo &TemplateInfo,
1060e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner                        AccessSpecifier AS);
10611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void ParseDeclarationSpecifiers(DeclSpec &DS,
10624d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
106367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                  AccessSpecifier AS = AS_none,
106467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall                                  DeclSpecContext DSC = DSC_normal);
10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid,
10667a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner                                  const char *&PrevSpec,
1067fec54013fcd0eb72642741584ca04c1bc292bef8John McCall                                  unsigned &DiagID,
10684d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
10694d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor
10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseSpecifierQualifierList(DeclSpec &DS);
10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1072a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void ParseObjCTypeQualifierList(ObjCDeclSpec &DS);
10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10744c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
10754c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner                          AccessSpecifier AS = AS_none);
1076b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  void ParseEnumBody(SourceLocation StartLoc, DeclPtrTy TagDecl);
10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
1078b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                            DeclPtrTy TagDecl);
1079bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1080bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  struct FieldCallback {
1081bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall    virtual DeclPtrTy invoke(FieldDeclarator &Field) = 0;
10826c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall    virtual ~FieldCallback() {}
10836c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall
10846c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall  private:
10856c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall    virtual void _anchor();
1086bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  };
1087bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall
1088bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall  void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback);
10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1090eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  bool isDeclarationSpecifier();
1091eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  bool isTypeSpecifierQualifier();
10925f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff  bool isTypeQualifier() const;
10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isDeclarationStatement - Disambiguates between a declaration or an
10955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// expression statement, when parsing function bodies.
10965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for declaration, false for expression.
10975404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isDeclarationStatement() {
10985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    if (getLang().CPlusPlus)
10995404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      return isCXXDeclarationStatement();
11005404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    return isDeclarationSpecifier();
11015404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  }
11025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1103bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// isSimpleDeclaration - Disambiguates between a declaration or an
1104bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// expression, mainly used for the C 'clause-1' or the C++
1105bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  // 'for-init-statement' part of a 'for' statement.
1106bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// Returns true for declaration, false for expression.
1107bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  bool isSimpleDeclaration() {
1108bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis    if (getLang().CPlusPlus)
1109bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis      return isCXXSimpleDeclaration();
1110bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis    return isDeclarationSpecifier();
1111bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  }
1112bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis
11138b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  /// \brief Specifies the context in which type-id/expression
11148b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  /// disambiguation will occur.
11158b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  enum TentativeCXXTypeIdContext {
11168b642592a35167a3780074e78674e0bece87c40cDouglas Gregor    TypeIdInParens,
11178b642592a35167a3780074e78674e0bece87c40cDouglas Gregor    TypeIdAsTemplateArgument
11188b642592a35167a3780074e78674e0bece87c40cDouglas Gregor  };
11198b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
11208b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
112178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
112278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// whether the parens contain an expression or a type-id.
112378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// Returns true for a type-id and false for an expression.
1124f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isTypeIdInParens(bool &isAmbiguous) {
112578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    if (getLang().CPlusPlus)
1126f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis      return isCXXTypeId(TypeIdInParens, isAmbiguous);
1127f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    isAmbiguous = false;
112878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    return isTypeSpecifierQualifier();
112978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  }
1130f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isTypeIdInParens() {
1131f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    bool isAmbiguous;
1132f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    return isTypeIdInParens(isAmbiguous);
1133f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  }
113478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
11355404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXDeclarationStatement - C++-specialized function that disambiguates
11365404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a declaration or an expression statement, when parsing function
11375404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// bodies. Returns true for declaration, false for expression.
11385404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isCXXDeclarationStatement();
11395404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
11405404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
11415404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a simple-declaration or an expression-statement.
11425404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
11435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
11445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns false if the statement is disambiguated as expression.
11455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isCXXSimpleDeclaration();
11465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
11475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
11485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// a constructor-style initializer, when parsing declaration statements.
11495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for function declarator and false for constructor-style
1150e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to
1151259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis  /// indicate that the parens were disambiguated as function declarator.
11525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
11535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
1154e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  bool isCXXFunctionDeclarator(bool warnIfAmbiguous);
11555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1156a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// isCXXConditionDeclaration - Disambiguates between a declaration or an
1157a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// expression for a condition of a if/switch/while/for statement.
1158a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
1159a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
1160a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  bool isCXXConditionDeclaration();
1161a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis
1162f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous);
1163f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
1164f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    bool isAmbiguous;
1165f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis    return isCXXTypeId(Context, isAmbiguous);
1166f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis  }
116778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
1168b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult - Used as the result value for functions whose purpose is to
1169b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// disambiguate C++ constructs by "tentatively parsing" them.
1170b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// This is a class instead of a simple enum because the implicit enum-to-bool
1171b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// conversions may cause subtle bugs.
1172b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  class TPResult {
1173b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    enum Result {
1174b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_true,
1175b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_false,
1176b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_ambiguous,
1177b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_error
1178b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    };
1179b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    Result Res;
1180b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    TPResult(Result result) : Res(result) {}
1181b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  public:
1182b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult True() { return TPR_true; }
1183b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult False() { return TPR_false; }
1184b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Ambiguous() { return TPR_ambiguous; }
1185b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Error() { return TPR_error; }
1186b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis
1187b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator==(const TPResult &RHS) const { return Res == RHS.Res; }
1188b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; }
1189b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis  };
1190b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis
1191b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a
1192b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// declaration specifier, TPResult::False() if it is not,
1193b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult::Ambiguous() if it could be either a decl-specifier or a
1194b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// function-style cast, and TPResult::Error() if a parsing error was
1195b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// encountered.
11965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Doesn't consume tokens.
1197b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult isCXXDeclarationSpecifier();
11985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
11995404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // "Tentative parsing" functions, used for disambiguation. If a parsing error
1200b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // is encountered they will return TPResult::Error().
1201b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // Returning TPResult::True()/False() indicates that the ambiguity was
1202b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates
1203b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // that more tentative parsing is necessary for disambiguation.
12045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // They all consume tokens, so backtracking should be used after calling them.
12055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1206b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseDeclarationSpecifier();
1207b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseSimpleDeclaration();
1208b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseTypeofSpecifier();
1209b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseInitDeclaratorList();
121078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true);
1211b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseParameterDeclarationClause();
1212b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseFunctionDeclarator();
1213b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseBracketDeclarator();
12145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
1215ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl  TypeResult ParseTypeName(SourceRange *Range = 0);
121698eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump  void ParseBlockId();
1217ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // EndLoc, if non-NULL, is filled with the location of the last token of
1218ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  // the attribute list.
1219ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl  AttributeList *ParseAttributes(SourceLocation *EndLoc = 0);
1220290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman  AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0);
1221290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman  AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0);
1222d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  void ParseTypeofSpecifier(DeclSpec &DS);
12236fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson  void ParseDecltypeSpecifier(DeclSpec &DS);
1224eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1225eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
1226eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// enter a new C++ declarator scope and exit it when the function is
1227eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// finished.
1228eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  class DeclaratorScopeObj {
1229eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    Parser &P;
1230751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis    CXXScopeSpec &SS;
1231f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis    bool EnteredScope;
1232f7f3d0db754db0500b56d49ac19f795f13965912John McCall    bool CreatedScope;
1233eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  public:
1234f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis    DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
1235f7f3d0db754db0500b56d49ac19f795f13965912John McCall      : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
1236eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1237eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    void EnterDeclaratorScope() {
12382bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis      assert(!EnteredScope && "Already entered the scope!");
1239f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      assert(SS.isSet() && "C++ scope was not set!");
1240f7f3d0db754db0500b56d49ac19f795f13965912John McCall
1241f7f3d0db754db0500b56d49ac19f795f13965912John McCall      CreatedScope = true;
1242f7f3d0db754db0500b56d49ac19f795f13965912John McCall      P.EnterScope(0); // Not a decl scope.
1243f7f3d0db754db0500b56d49ac19f795f13965912John McCall
12447dfd0fb08300b60a9657748bda7d8b3ceb07babeDouglas Gregor      if (P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS))
12457dfd0fb08300b60a9657748bda7d8b3ceb07babeDouglas Gregor        SS.setScopeRep(0);
12467dfd0fb08300b60a9657748bda7d8b3ceb07babeDouglas Gregor
12473fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor      if (!SS.isInvalid())
12483fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor        EnteredScope = true;
1249eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
1250eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1251eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    ~DeclaratorScopeObj() {
1252f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      if (EnteredScope) {
1253f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis        assert(SS.isSet() && "C++ scope was cleared ?");
12540a59acb9ae36077ce46fb2807956c5e84f0f6837Douglas Gregor        P.Actions.ActOnCXXExitDeclaratorScope(P.CurScope, SS);
1255f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis      }
1256f7f3d0db754db0500b56d49ac19f795f13965912John McCall      if (CreatedScope)
1257f7f3d0db754db0500b56d49ac19f795f13965912John McCall        P.ExitScope();
1258eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
1259eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  };
12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseDeclarator - Parse and verify a newly-initialized declarator.
12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDeclarator(Declarator &D);
12634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  /// A function that parses a variant of direct-declarator.
12644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
12654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDeclaratorInternal(Declarator &D,
12664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl                               DirectDeclParseFunction DirectDeclParser);
126785b5a45803784a5465f69baf6f8d6e1eacaa5af5Chris Lattner  void ParseTypeQualifierListOpt(DeclSpec &DS, bool AttributesAllowed = true);
12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDirectDeclarator(Declarator &D);
12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseParenDeclarator(Declarator &D);
12707399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner  void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
12717399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner                               AttributeList *AttrList = 0,
12727399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner                               bool RequiresArg = false);
127366d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner  void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
127466d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner                                             Declarator &D);
12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseBracketDeclarator(Declarator &D);
12761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12778f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  //===--------------------------------------------------------------------===//
12788f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  // C++ 7: Declarations [dcl.dcl]
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
128097144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclPtrTy ParseNamespace(unsigned Context, SourceLocation &DeclEnd);
1281b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseLinkage(unsigned Context);
128297144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclPtrTy ParseUsingDirectiveOrDeclaration(unsigned Context,
128397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner                                             SourceLocation &DeclEnd);
128497144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclPtrTy ParseUsingDirective(unsigned Context, SourceLocation UsingLoc,
128597144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner                                SourceLocation &DeclEnd);
128697144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclPtrTy ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc,
1287595adc1795cc2c079ef5876100e01acd10a0504aAnders Carlsson                                  SourceLocation &DeclEnd,
1288595adc1795cc2c079ef5876100e01acd10a0504aAnders Carlsson                                  AccessSpecifier AS = AS_none);
128997144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner  DeclPtrTy ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
129003bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson  DeclPtrTy ParseNamespaceAlias(SourceLocation NamespaceLoc,
129197144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner                                SourceLocation AliasLoc, IdentifierInfo *Alias,
129297144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner                                SourceLocation &DeclEnd);
12931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1294e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
1295e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 9: classes [class] and C structs/unions.
12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeResult ParseClassName(SourceLocation &EndLocation,
1297d33c868d386ef47c2942e2dbff0d9955a8591fa9Fariborz Jahanian                            const CXXScopeSpec *SS = 0,
1298d33c868d386ef47c2942e2dbff0d9955a8591fa9Fariborz Jahanian                            bool DestrExpected = false);
12994c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner  void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
13001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                           DeclSpec &DS,
13014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
130206c0fecd197fef21e265a41bca8dc5022de1f864Douglas Gregor                           AccessSpecifier AS = AS_none);
13034cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType,
1304b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner                                   DeclPtrTy TagDecl);
130537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor  void ParseCXXClassMemberDeclaration(AccessSpecifier AS,
130637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1307b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  void ParseConstructorInitializer(DeclPtrTy ConstructorDecl);
1308b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  MemInitResult ParseMemInitializer(DeclPtrTy ConstructorDecl);
1309d33133cdc1af466f9c276249b2621be03867888bEli Friedman  void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
1310d33133cdc1af466f9c276249b2621be03867888bEli Friedman                                       DeclPtrTy ThisDecl);
1311e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
1312e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
1313e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 10: Derived classes [class.derived]
1314b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  void ParseBaseClause(DeclPtrTy ClassDecl);
1315b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  BaseResult ParseBaseSpecifier(DeclPtrTy ClassDecl);
13161b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor  AccessSpecifier getAccessSpecifierIfPresent() const;
13171cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor
13183f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
13193f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    IdentifierInfo *Name,
13203f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    SourceLocation NameLoc,
13213f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    bool EnteringContext,
13222d1c21414199a7452f122598189363a3922605b1Douglas Gregor                                    TypeTy *ObjectType,
13233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                                    UnqualifiedId &Id);
1324ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
1325ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                  TypeTy *ObjectType,
1326ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                  UnqualifiedId &Result);
13273f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor  bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
132802a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor                          bool AllowDestructorName,
132902a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor                          bool AllowConstructorName,
13302d1c21414199a7452f122598189363a3922605b1Douglas Gregor                          TypeTy *ObjectType,
13313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor                          UnqualifiedId &Result);
13323f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor
13331cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor  //===--------------------------------------------------------------------===//
1334adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14: Templates [temp]
1335b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  typedef llvm::SmallVector<DeclPtrTy, 4> TemplateParameterList;
1336c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor
1337adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14.1: Template Parameters [temp.param]
13384d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor  DeclPtrTy ParseDeclarationStartingWithTemplate(unsigned Context,
13394d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                                 SourceLocation &DeclEnd,
13404d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                                 AccessSpecifier AS = AS_none);
1341b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseTemplateDeclarationOrSpecialization(unsigned Context,
134297144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner                                                     SourceLocation &DeclEnd,
13434d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                                     AccessSpecifier AS);
13441426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor  DeclPtrTy ParseSingleDeclarationAfterTemplate(
13451426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       unsigned Context,
13464d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                       const ParsedTemplateInfo &TemplateInfo,
13471426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       SourceLocation &DeclEnd,
13481426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor                                       AccessSpecifier AS=AS_none);
13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ParseTemplateParameters(unsigned Depth,
1350c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor                               TemplateParameterList &TemplateParams,
13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               SourceLocation &LAngleLoc,
1352c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor                               SourceLocation &RAngleLoc);
1353c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor  bool ParseTemplateParameterList(unsigned Depth,
1354c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor                                  TemplateParameterList &TemplateParams);
1355b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseTemplateParameter(unsigned Depth, unsigned Position);
1356b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseTypeParameter(unsigned Depth, unsigned Position);
1357b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
1358b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner  DeclPtrTy ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
1359d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor  // C++ 14.3: Template arguments [temp.arg]
1360314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  typedef llvm::SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
1361cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
13627532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  bool ParseTemplateIdAfterTemplateName(TemplateTy Template,
13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        SourceLocation TemplateNameLoc,
1364cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        const CXXScopeSpec *SS,
1365cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        bool ConsumeLastToken,
1366cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        SourceLocation &LAngleLoc,
1367cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        TemplateArgList &TemplateArgs,
1368cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor                                        SourceLocation &RAngleLoc);
1369cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor
1370c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner  bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
137139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                               const CXXScopeSpec *SS,
1372ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                               UnqualifiedId &TemplateName,
137339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                               SourceLocation TemplateKWLoc = SourceLocation(),
137439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor                               bool AllowTypeAnnotation = true);
137531a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor  void AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS = 0);
1376314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
1377788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  ParsedTemplateArgument ParseTemplateTemplateArgument();
1378314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor  ParsedTemplateArgument ParseTemplateArgument();
137945f965581935791a018df829a14dff53c1dd8f47Douglas Gregor  DeclPtrTy ParseExplicitInstantiation(SourceLocation ExternLoc,
13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                       SourceLocation TemplateLoc,
13814d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor                                       SourceLocation &DeclEnd);
138264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
138364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  //===--------------------------------------------------------------------===//
138464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // GNU G++: Type Traits [Type-Traits.html in the GCC manual]
138564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  OwningExprResult ParseUnaryTypeTrait();
13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1391