Parser.h revision 43bc2a0973ffe404fabba6f8280cd6bad2c69fcb
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"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Parse/Action.h"
19eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis#include "clang/Parse/DeclSpec.h"
204cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis#include <stack>
215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
23fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar  class AttributeList;
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class DeclSpec;
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Declarator;
26e13594279a952537ac903325efff57e3edca79d9Chris Lattner  class FieldDeclarator;
27fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar  class ObjCDeclSpec;
28fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar  class PragmaHandler;
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Scope;
303cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  class DiagnosticBuilder;
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages.  After
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read.
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Parser {
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Preprocessor &PP;
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3997d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher  /// Tok - The current token we are peeking ahead.  All parsing methods assume
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// that this is valid.
41d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner  Token Tok;
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned short ParenCount, BracketCount, BraceCount;
445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Actions - These are the callbacks we invoke as we parse various constructs
465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// in the file.  This refers to the common base class between MinimalActions
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// and SemaActions for those uses that don't matter.
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Action &Actions;
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Scope *CurScope;
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Diagnostic &Diags;
529e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner
539e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  /// ScopeCache - Cache scopes to reduce malloc traffic.
549e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  enum { ScopeCacheSize = 16 };
559e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  unsigned NumCachedScopes;
569e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner  Scope *ScopeCache[ScopeCacheSize];
57662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar
58662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  /// Ident_super - IdentifierInfo for "super", to support fast
59662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  /// comparison.
60662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar  IdentifierInfo *Ident_super;
61662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar
62fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar  PragmaHandler *PackHandler;
63fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar
645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Parser(Preprocessor &PP, Action &Actions);
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ~Parser();
675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const LangOptions &getLang() const { return PP.getLangOptions(); }
695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Action &getActions() const { return Actions; }
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Type forwarding.  All of these are statically 'void*', but they may all be
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // different actual classes based on the actions in place.
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef Action::ExprTy ExprTy;
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef Action::StmtTy StmtTy;
765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef Action::DeclTy DeclTy;
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef Action::TypeTy TypeTy;
78f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor  typedef Action::BaseTy BaseTy;
797ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  typedef Action::MemInitTy MemInitTy;
80eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  typedef Action::CXXScopeTy CXXScopeTy;
817ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
8215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  typedef Action::ExprResult    ExprResult;
8315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  typedef Action::StmtResult    StmtResult;
8415faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  typedef Action::BaseResult    BaseResult;
8515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  typedef Action::MemInitResult MemInitResult;
8615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
8715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  typedef Action::OwningExprResult OwningExprResult;
8815faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl  typedef Action::OwningStmtResult OwningStmtResult;
8915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
9061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  /// Adorns a ExprResult with Actions to make it an OwningExprResult
9161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningExprResult Owned(ExprResult res) {
9261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl    return OwningExprResult(Actions, res);
9361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
9461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  /// Adorns a StmtResult with Actions to make it an OwningStmtResult
9561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult Owned(StmtResult res) {
9661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl    return OwningStmtResult(Actions, res);
9761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
9861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
9961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningExprResult ExprError() { return OwningExprResult(Actions, true); }
10061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult StmtError() { return OwningStmtResult(Actions, true); }
10161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Parsing methods.
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseTranslationUnit - All in one method that initializes parses, and
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// shuts down the parser.
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseTranslationUnit();
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Initialize - Warm up the parser.
1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Initialize();
1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1121f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff  /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
1131f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff  /// the EOF was encountered.
11489307ffaf8acf4d6fdffd72b607ca4fbcfdffc9dSteve Naroff  bool ParseTopLevelDecl(DeclTy*& Result);
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Low-Level token peeking and consumption methods.
1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //
1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenParen - Return true if the cur token is '(' or ')'.
1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenParen() const {
1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren;
1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBracket - Return true if the cur token is '[' or ']'.
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBracket() const {
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square;
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenBrace - Return true if the cur token is '{' or '}'.
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenBrace() const {
1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace;
1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isTokenStringLiteral - True if this token is a string-literal.
1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isTokenStringLiteral() const {
1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Tok.getKind() == tok::string_literal ||
1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           Tok.getKind() == tok::wide_string_literal;
1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
140eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeToken - Consume the current 'peek token' and lex the next one.
142d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu  /// This does not work with all kinds of tokens: strings and specific other
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tokens must be consumed with custom methods below.  This returns the
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// location of the consumed token.
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeToken() {
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() &&
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           !isTokenBrace() &&
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should consume special tokens with Consume*Token");
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SourceLocation L = Tok.getLocation();
1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return L;
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// current token type.  This should only be used in cases where the type of
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the token really isn't known, e.g. in error recovery.
1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeAnyToken() {
1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isTokenParen())
1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeParen();
1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBracket())
1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBracket();
1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (isTokenBrace())
1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeBrace();
164d62701bc5321049353017e9abf1963edd57646aaSteve Naroff    else if (isTokenStringLiteral())
165d62701bc5321049353017e9abf1963edd57646aaSteve Naroff      return ConsumeStringToken();
1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return ConsumeToken();
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeParen - This consume method keeps the paren count up-to-date.
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeParen() {
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenParen() && "wrong consume method");
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_paren)
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++ParenCount;
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (ParenCount)
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --ParenCount;       // Don't let unbalanced )'s drive the count negative.
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SourceLocation L = Tok.getLocation();
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return L;
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBracket - This consume method keeps the bracket count up-to-date.
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBracket() {
1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBracket() && "wrong consume method");
1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_square)
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BracketCount;
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BracketCount)
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BracketCount;     // Don't let unbalanced ]'s drive the count negative.
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SourceLocation L = Tok.getLocation();
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return L;
1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeBrace - This consume method keeps the brace count up-to-date.
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeBrace() {
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenBrace() && "wrong consume method");
2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Tok.getKind() == tok::l_brace)
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ++BraceCount;
2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else if (BraceCount)
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      --BraceCount;     // Don't let unbalanced }'s drive the count negative.
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SourceLocation L = Tok.getLocation();
2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return L;
2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ConsumeStringToken - Consume the current 'peek token', lexing a new one
2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// and returning the token kind.  This method is specific to strings, as it
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// handles string literal concatenation, as per C99 5.1.1.2, translation
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// phase #6.
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation ConsumeStringToken() {
2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isTokenStringLiteral() &&
2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Should only consume string literals with this method");
2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SourceLocation L = Tok.getLocation();
2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PP.Lex(Tok);
2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return L;
2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2236b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// GetLookAheadToken - This peeks ahead N tokens and returns that token
2246b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// without consuming any tokens.  LookAhead(0) returns 'Tok', LookAhead(1)
2256b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// returns the token after Tok, etc.
2266b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
2276b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// Note that this differs from the Preprocessor's LookAhead method, because
2286b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  /// the Parser always has one token lexed that the preprocessor doesn't.
2296b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  ///
23003db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis  const Token &GetLookAheadToken(unsigned N) {
2316b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    if (N == 0 || Tok.is(tok::eof)) return Tok;
2326b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner    return PP.LookAhead(N-1);
2336b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner  }
234f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis
235f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// NextToken - This peeks ahead one token and returns it without
236f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  /// consuming it.
237f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  const Token &NextToken() {
23803db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis    return PP.LookAhead(0);
239f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis  }
2405404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
241eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// TryAnnotateTypeOrScopeToken - If the current token position is on a
242eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// typename (possibly qualified in C++) or a C++ scope specifier not followed
243eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens
244eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// with a single annotation token representing the typename or C++ scope
245eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// respectively.
246eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// This simplifies handling of C++ scope specifiers and allows efficient
247eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// backtracking without the need to re-parse and resolve nested-names and
248eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// typenames.
24944802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// It will mainly be called when we expect to treat identifiers as typenames
25044802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// (if they are typenames). For example, in C we do not expect identifiers
25144802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// inside expressions to be treated as typenames so it will not be called
25244802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis  /// for expressions in C.
253eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  void TryAnnotateTypeOrScopeToken();
254eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
2554bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis  /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
256eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// annotates C++ scope specifiers.
2574bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis  void TryAnnotateCXXScopeToken();
258eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
2595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// TentativeParsingAction - An object that is used as a kind of "tentative
2605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// parsing transaction". It gets instantiated to mark the token position and
2615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// after the token consumption is done, Commit() or Revert() is called to
2625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// either "commit the consumed tokens" or revert to the previously marked
2635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// token position. Example:
2645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
2655404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   TentativeParsingAction TPA;
2665404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ConsumeToken();
2675404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   ....
2685404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///   TPA.Revert();
2695404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  ///
2705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  class TentativeParsingAction {
2715404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Parser &P;
2725404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    Token PrevTok;
2735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    bool isActive;
2745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
2755404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  public:
2765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    explicit TentativeParsingAction(Parser& p) : P(p) {
2775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      PrevTok = P.Tok;
2785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.EnableBacktrackAtThisPos();
2795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = true;
2805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
2815404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Commit() {
2825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
2835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.CommitBacktrackedTokens();
2845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
2855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
2865404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    void Revert() {
2875404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(isActive && "Parsing action was finished!");
2885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.PP.Backtrack();
2895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      P.Tok = PrevTok;
2905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      isActive = false;
2915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
2925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    ~TentativeParsingAction() {
2935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      assert(!isActive && "Forgot to call Commit or Revert!");
2945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    }
2955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  };
2966b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner
2976b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner
2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'),
2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this helper function matches and consumes the specified RHS token if
3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// present.  If not present, it emits the specified diagnostic indicating
3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// that the parser failed to match the RHS of the token at LHSLoc.  LHSName
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// should be the name of the unmatched LHS token.  This returns the location
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the consumed token.
3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok,
3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                     SourceLocation LHSLoc);
3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// input.  If so, it is consumed and false is returned.
3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If the input is malformed, this emits the specified diagnostic.  Next, if
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipToTok is specified, it calls SkipUntil(SkipToTok).  Finally, true is
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// returned.
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag,
3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        const char *DiagMsg = "",
3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                        tok::TokenKind SkipToTok = tok::unknown);
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Scope manipulation
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3208935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// ParseScope - Introduces a new scope for parsing. The kind of
3218935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// scope is determined by ScopeFlags. Objects of this type should
3228935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// be created on the stack to coincide with the position where the
3238935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// parser enters the new scope, and this object's constructor will
3248935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// create that new scope. Similarly, once the object is destroyed
3258935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  /// the parser will exit the scope.
3268935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  class ParseScope {
3278935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    Parser *Self;
3288935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope(const ParseScope&); // do not implement
3298935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope& operator=(const ParseScope&); // do not implement
3308935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
3318935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  public:
3328935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ParseScope - Construct a new object to manage a scope in the
3338935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // parser Self where the new Scope is created with the flags
3348935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ScopeFlags, but only when ManageScope is true (the default). If
3358935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // ManageScope is false, this object does nothing.
3368935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true)
3378935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      : Self(Self) {
3388935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (ManageScope)
3398935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->EnterScope(ScopeFlags);
3408935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      else
3418935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        this->Self = 0;
3428935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
3438935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
3448935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // Exit - Exit the scope associated with this object now, rather
3458935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    // than waiting until the object is destroyed.
3468935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    void Exit() {
3478935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      if (Self) {
3488935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self->ExitScope();
3498935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor        Self = 0;
3508935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      }
3518935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
3528935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
3538935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    ~ParseScope() {
3548935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor      Exit();
3558935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor    }
3568935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor  };
3578935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EnterScope - Start a new scope.
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EnterScope(unsigned ScopeFlags);
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ExitScope - Pop a scope off the scope stack.
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ExitScope();
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Diagnostic Emission and Error recovery.
36615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
3673cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
3683cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
36915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SkipUntil - Read tokens until we get to the specified token, then consume
37182c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff  /// it (unless DontConsume is true).  Because we cannot guarantee that the
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// token will ever occur, this skips to the next token, or to some likely
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// good stopping point.  If StopAtSemi is true, skipping will stop at a ';'
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// character.
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If SkipUntil finds the specified token, it returns true, otherwise it
3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// returns false.
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                 bool DontConsume = false) {
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SkipUntil(&T, 1, StopAtSemi, DontConsume);
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                 bool DontConsume = false) {
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    tok::TokenKind TokArray[] = {T1, T2};
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SkipUntil(TokArray, 2, StopAtSemi, DontConsume);
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                 bool StopAtSemi = true, bool DontConsume = false);
3897ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor
3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3914cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // Lexing and parsing of C++ inline methods.
3924cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
3934cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  typedef llvm::SmallVector<Token, 32> TokensTy;
3944cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  struct LexedMethod {
3954cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    Action::DeclTy *D;
3964cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    TokensTy Toks;
3974cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    explicit LexedMethod(Action::DeclTy *MD) : D(MD) {}
3984cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  };
3994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
4004cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// LexedMethodsForTopClass - During parsing of a top (non-nested) C++ class,
4014cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// its inline method definitions and the inline method definitions of its
4024cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// nested classes are lexed and stored here.
4034cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  typedef std::stack<LexedMethod> LexedMethodsForTopClass;
4044cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
4054cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// TopClassStacks - This is initialized with one LexedMethodsForTopClass used
4064cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// for lexing all top classes, until a local class in an inline method is
4074cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// encountered, at which point a new LexedMethodsForTopClass is pushed here
4084cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  /// and used until the parsing of that local class is finished.
4094cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  std::stack<LexedMethodsForTopClass> TopClassStacks;
4104cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
4114cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  LexedMethodsForTopClass &getCurTopClassStack() {
4124cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    assert(!TopClassStacks.empty() && "No lexed method stacks!");
4134cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    return TopClassStacks.top();
4144cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
4154cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
4164cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  void PushTopClassStack() {
4174cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis    TopClassStacks.push(LexedMethodsForTopClass());
4184cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  }
4194cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  void PopTopClassStack() { TopClassStacks.pop(); }
4204cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
4214cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  DeclTy *ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D);
4224cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  void ParseLexedMethodDefs();
4233f08d181f620e6bf4971c436fc9878f98a02bbe3Douglas Gregor  bool ConsumeAndStoreUntil(tok::TokenKind T, TokensTy &Toks,
4243f08d181f620e6bf4971c436fc9878f98a02bbe3Douglas Gregor                            tok::TokenKind EarlyAbortIf = tok::unknown);
4254cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
4264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.9: External Definitions.
4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  DeclTy *ParseExternalDeclaration();
4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  DeclTy *ParseDeclarationOrFunctionDefinition();
4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  DeclTy *ParseFunctionDefinition(Declarator &D);
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseKNRParamDeclarations(Declarator &D);
432effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl  OwningExprResult ParseSimpleAsm();
433effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl  OwningExprResult ParseAsmStringLiteral();
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4353536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  // Objective-C External Declarations
436dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  DeclTy *ParseObjCAtDirectives();
437dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  DeclTy *ParseObjCAtClassDeclaration(SourceLocation atLoc);
438dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff  DeclTy *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc,
439dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff                                          AttributeList *prefixAttrs = 0);
44060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  void ParseObjCClassInstanceVariables(DeclTy *interfaceDecl,
44160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                       SourceLocation atLoc);
442e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner  bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclTy*> &P,
443e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                   bool WarnOnDeclarations,
444e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner                                   SourceLocation &EndProtoLoc);
44525e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian  void ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
446c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner                                  tok::ObjCKeywordKind contextKey);
447246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar  DeclTy *ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
448246e70f69cb8aeb67225c54690f1c6b25abd5a86Daniel Dunbar                                         AttributeList *prefixAttrs = 0);
4493536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
450a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  DeclTy *ObjCImpDecl;
4510416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
452ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  DeclTy *ParseObjCAtImplementationDeclaration(SourceLocation atLoc);
453ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  DeclTy *ParseObjCAtEndDeclaration(SourceLocation atLoc);
454e992af01d14e2e31037562c123af0a71ae1ed374Fariborz Jahanian  DeclTy *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
455ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  DeclTy *ParseObjCPropertySynthesize(SourceLocation atLoc);
456ac00b7f4a933e60e2f0afd83092339160adc140cFariborz Jahanian  DeclTy *ParseObjCPropertyDynamic(SourceLocation atLoc);
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4584b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  IdentifierInfo *ParseObjCSelector(SourceLocation &MethodLocation);
45934870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  // Definitions for Objective-c context sensitive keywords recognition.
46034870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  enum ObjCTypeQual {
46134870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
46234870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner    objc_NumQuals
46334870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner  };
464a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
4650196cab54007ff072ec2642da8911c6b7e8d3fb5Fariborz Jahanian
466335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian  bool isTokIdentifier_in() const;
467d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian
468a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  TypeTy *ParseObjCTypeName(ObjCDeclSpec &DS);
469294494e1cce92043562b4680c613df7fd028c02eSteve Naroff  void ParseObjCMethodRequirement();
47025e077d59a8e8e43b65882b69610a3d5e2aaf53cFariborz Jahanian  DeclTy *ParseObjCMethodPrototype(DeclTy *classOrCat,
471c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
472bef1185418705e16012b3dd50cd7c260c8d6b79cSteve Naroff  DeclTy *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
4731f7b6f88f18d7f6b10265acec5d41c4ed1897487Fariborz Jahanian                              DeclTy *classDecl,
47400933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
475a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
476294494e1cce92043562b4680c613df7fd028c02eSteve Naroff
47771c0a951d08dc7a2a057df8c15f22b36f6aa47c7Steve Naroff  DeclTy *ParseObjCMethodDefinition();
478bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve Naroff
4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.5: Expressions.
4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseExpression();
4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseConstantExpression();
4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseAssignmentExpression();  // Expr that doesn't include commas.
4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
486b384d329e0b727d4f2effa28fbb9aba2ac420e7bFariborz Jahanian  ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec);
4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseCastExpression(bool isUnaryExpression);
4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParsePostfixExpressionSuffix(ExprResult LHS);
4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseSizeofAlignofExpression();
4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseBuiltinPrimaryExpression();
4930cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
494a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  static const unsigned ExprListSize = 12;
495a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  typedef llvm::SmallVector<ExprTy*, ExprListSize> ExprListTy;
496a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl  typedef llvm::SmallVector<SourceLocation, ExprListSize> CommaLocsTy;
4970cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis
4980cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis  /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
4990cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis  bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs);
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParenParseOption - Control what ParseParenExpression will parse.
5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ParenParseOption {
5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SimpleExpr,      // Only parse '(' expression ')'
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundStmt,    // Also allow '(' compound-statement ')'
5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CastExpr         // Also allow '(' type-name ')' <anything>
5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseParenExpression(ParenParseOption &ExprType, TypeTy *&CastTy,
5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                  SourceLocation &RParenLoc);
5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseSimpleParenExpression() {  // Parse SimpleExpr only.
5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SourceLocation RParenLoc;
5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ParseSimpleParenExpression(RParenLoc);
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseSimpleParenExpression(SourceLocation &RParenLoc) {
5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ParenParseOption Op = SimpleExpr;
5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TypeTy *CastTy;
5185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ParseParenExpression(Op, CastTy, RParenLoc);
5195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseStringLiteralExpression();
521eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
522eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
523eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  // C++ Expressions
524eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  ExprResult ParseCXXIdExpression();
5254bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis
5264bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis  /// MaybeParseCXXScopeSpecifier - Parse global scope or nested-name-specifier.
5274bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis  /// Returns true if a nested-name-specifier was parsed from the token stream.
5284bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis  bool MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS);
5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 5.2p1: C++ Casts
5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseCXXCasts();
5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
535c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // C++ 5.2p1: C++ Type Identification
536c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  ExprResult ParseCXXTypeid();
537c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
538c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  //===--------------------------------------------------------------------===//
5394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  // C++ 9.3.2: C++ 'this' pointer
5404cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  ExprResult ParseCXXThis();
5414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis
5424cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
54350dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  // C++ 15: C++ Throw Expression
54450dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  ExprResult ParseThrowExpression();
5450fe7bea6fca9737c6c145aaa4a2ad3abe595782aDouglas Gregor  bool ParseExceptionSpecification();
54650dd289f45738ed22b7583d52ed2525b927042ffChris Lattner
54750dd289f45738ed22b7583d52ed2525b927042ffChris Lattner  //===--------------------------------------------------------------------===//
5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C++ 2.13.5: C++ Boolean Literals
5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ExprResult ParseCXXBoolLiteral();
5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
552987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // C++ 5.2.3: Explicit type conversion (functional notation)
553987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
554987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
555987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
556987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// This should only be called when the current token is known to be part of
557987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  /// simple-type-specifier.
558987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
559987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
5602f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor  bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
5612f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor
562987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  //===--------------------------------------------------------------------===//
5634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // C++ 5.3.4 and 5.3.5: C++ new and delete
5644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  ExprResult ParseCXXNewExpression();
565cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool ParseExpressionListOrTypeId(ExprListTy &Exprs, Declarator &D);
5664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDirectNewDeclarator(Declarator &D);
5674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  ExprResult ParseCXXDeleteExpression();
5684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
5694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  //===--------------------------------------------------------------------===//
57071b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis  // C++ if/switch/while/for condition expression.
57171b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis  ExprResult ParseCXXCondition();
57271b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis
57371b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
57412e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  // C++ types
57512e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor
57612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  //===--------------------------------------------------------------------===//
5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7.8: Initialization.
5780eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner
5790eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  /// ParseInitializer
5800eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///       initializer: [C99 6.7.8]
5810eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         assignment-expression
5820eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ///         '{' ...
5830eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ExprResult ParseInitializer() {
5840eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    if (Tok.isNot(tok::l_brace))
5850eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner      return ParseAssignmentExpression();
5860eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner    return ParseBraceInitializer();
5870eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  }
5880eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner  ExprResult ParseBraceInitializer();
589eccc53a0a0ed1abc7bb4c04ed9566ce0c5c63140Chris Lattner  ExprResult ParseInitializerWithPotentialDesignator(InitListDesignations &D,
590eccc53a0a0ed1abc7bb4c04ed9566ce0c5c63140Chris Lattner                                                     unsigned InitNum);
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
593296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  // clang Expressions
594296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff
595296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  ExprResult ParseBlockLiteralExpression();  // ^{...}
596296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff
597296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff  //===--------------------------------------------------------------------===//
5985508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  // Objective-C Expressions
59914dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner
60014dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner  bool isTokObjCMessageIdentifierReceiver() const {
60114dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner    if (!Tok.is(tok::identifier))
60214dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner      return false;
60314dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner
60414dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner    if (Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope))
60514dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner      return true;
60614dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner
607662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar    return Tok.getIdentifierInfo() == Ident_super;
60814dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner  }
60914dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner
610a642beb9f143130588dcf622f5f7020832b22707Steve Naroff  ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
611beaf299a2701c5559a4e5d76b0c40f805afb8e6aSteve Naroff  ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
612674af9541256dc3ef803e3723027a8b028f1f7a2Chris Lattner  ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
6132a35fa9b5e0f9d9429c04adb2e1249b6fd425e7aFariborz Jahanian  ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
6142a35fa9b5e0f9d9429c04adb2e1249b6fd425e7aFariborz Jahanian  ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
6150ccb27ded12fd03eb6818a880f50901bb70254feFariborz Jahanian  ExprResult ParseObjCMessageExpression();
616699b66138ac307a32e238463e0eff513ff17d337Chris Lattner  ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
6175cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff                                            SourceLocation NameLoc,
618699b66138ac307a32e238463e0eff513ff17d337Chris Lattner                                            IdentifierInfo *ReceiverName,
619699b66138ac307a32e238463e0eff513ff17d337Chris Lattner                                            ExprTy *ReceiverExpr);
620b93fb495660665c17c7f43172ae155d6a8c32ce8Chris Lattner  ExprResult ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracloc,
6215cb93b8bf009c4b0ae09b71ba85f54b2a7ea8022Steve Naroff                                                         SourceLocation NameLoc,
622b93fb495660665c17c7f43172ae155d6a8c32ce8Chris Lattner                                                         IdentifierInfo *ReceiverName,
623b93fb495660665c17c7f43172ae155d6a8c32ce8Chris Lattner                                                         ExprTy *ReceiverExpr);
62461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
6255508518a2702b00be3b15a26d772bde968972f54Anders Carlsson  //===--------------------------------------------------------------------===//
6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.8: Statements and Blocks.
62761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl
62861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseStatement() {
62961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl    return ParseStatementOrDeclaration(true);
63061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  }
63161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseStatementOrDeclaration(bool OnlyStatement = false);
63261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseLabeledStatement();
63361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseCaseStatement();
63461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseDefaultStatement();
63561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseCompoundStatement(bool isStmtExpr = false);
63661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
63761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl  OwningStmtResult ParseIfStatement();
6389a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseSwitchStatement();
6399a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseWhileStatement();
6409a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseDoStatement();
6419a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseForStatement();
6429a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseGotoStatement();
6439a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseContinueStatement();
6449a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseBreakStatement();
6459a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseReturnStatement();
6469a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult ParseAsmStatement(bool &msAsm);
6479a920342707e384473b464528d2fd286e8c70353Sebastian Redl  OwningStmtResult FuzzyParseMicrosoftAsmStatement();
64843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl  OwningStmtResult ParseObjCAtStatement(SourceLocation atLoc);
64943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl  OwningStmtResult ParseObjCTryStmt(SourceLocation atLoc);
65043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl  OwningStmtResult ParseObjCThrowStmt(SourceLocation atLoc);
65143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl  OwningStmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6528bd36fcb4427519f41197d88b9121e2bbe9e3fc3Anders Carlsson  bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
653b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson                           llvm::SmallVectorImpl<ExprTy*> &Constraints,
654b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson                           llvm::SmallVectorImpl<ExprTy*> &Exprs);
655b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // C99 6.7: Declarations.
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  DeclTy *ParseDeclaration(unsigned Context);
6618f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  DeclTy *ParseSimpleDeclaration(unsigned Context);
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  DeclTy *ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D);
663f9ed3157c93495474003a5ec360039030fd42e9cFariborz Jahanian  DeclTy *ParseFunctionStatementBody(DeclTy *Decl,
664f9ed3157c93495474003a5ec360039030fd42e9cFariborz Jahanian                                     SourceLocation L, SourceLocation R);
6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDeclarationSpecifiers(DeclSpec &DS);
66612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor  bool MaybeParseTypeSpecifier(DeclSpec &DS, int &isInvalid,
66712e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor                               const char *&PrevSpec);
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseSpecifierQualifierList(DeclSpec &DS);
66919d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian
670a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void ParseObjCTypeQualifierList(ObjCDeclSpec &DS);
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseEnumSpecifier(DeclSpec &DS);
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseEnumBody(SourceLocation StartLoc, DeclTy *TagDecl);
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                            DeclTy *TagDecl);
676e13594279a952537ac903325efff57e3edca79d9Chris Lattner  void ParseStructDeclaration(DeclSpec &DS,
677e13594279a952537ac903325efff57e3edca79d9Chris Lattner                              llvm::SmallVectorImpl<FieldDeclarator> &Fields);
6784e6526b2de501f2bbc261fd8017c92c75bd8d8f7Steve Naroff
679eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  bool isDeclarationSpecifier();
680eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  bool isTypeSpecifierQualifier();
6815f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff  bool isTypeQualifier() const;
6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isDeclarationStatement - Disambiguates between a declaration or an
6845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// expression statement, when parsing function bodies.
6855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for declaration, false for expression.
6865404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isDeclarationStatement() {
6875404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    if (getLang().CPlusPlus)
6885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis      return isCXXDeclarationStatement();
6895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis    return isDeclarationSpecifier();
6905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  }
6915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
692bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// isSimpleDeclaration - Disambiguates between a declaration or an
693bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// expression, mainly used for the C 'clause-1' or the C++
694bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  // 'for-init-statement' part of a 'for' statement.
695bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  /// Returns true for declaration, false for expression.
696bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  bool isSimpleDeclaration() {
697bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis    if (getLang().CPlusPlus)
698bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis      return isCXXSimpleDeclaration();
699bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis    return isDeclarationSpecifier();
700bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis  }
701bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis
70278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
70378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// whether the parens contain an expression or a type-id.
70478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// Returns true for a type-id and false for an expression.
70578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  bool isTypeIdInParens() {
70678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    if (getLang().CPlusPlus)
70778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis      return isCXXTypeIdInParens();
70878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis    return isTypeSpecifierQualifier();
70978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  }
71078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
7115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXDeclarationStatement - C++-specialized function that disambiguates
7125404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a declaration or an expression statement, when parsing function
7135404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// bodies. Returns true for declaration, false for expression.
7145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isCXXDeclarationStatement();
7155404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
7165404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
7175404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// between a simple-declaration or an expression-statement.
7185404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
7195404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
7205404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns false if the statement is disambiguated as expression.
7215404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  bool isCXXSimpleDeclaration();
7225404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
7235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
7245404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// a constructor-style initializer, when parsing declaration statements.
7255404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Returns true for function declarator and false for constructor-style
726e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to
727259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis  /// indicate that the parens were disambiguated as function declarator.
7285404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
7295404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
730e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis  bool isCXXFunctionDeclarator(bool warnIfAmbiguous);
7315404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
732a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// isCXXConditionDeclaration - Disambiguates between a declaration or an
733a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// expression for a condition of a if/switch/while/for statement.
734a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
735a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
736a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis  bool isCXXConditionDeclaration();
737a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis
73878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// isCXXTypeIdInParens - Assumes that a '(' was parsed and now we want to
73978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// know whether the parens contain an expression or a type-id.
74078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// Returns true for a type-id and false for an expression.
74178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// If during the disambiguation process a parsing error is encountered,
74278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  /// the function returns true to let the declaration parsing code handle it.
74378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  bool isCXXTypeIdInParens();
74478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis
745b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult - Used as the result value for functions whose purpose is to
746b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// disambiguate C++ constructs by "tentatively parsing" them.
747b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// This is a class instead of a simple enum because the implicit enum-to-bool
748b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// conversions may cause subtle bugs.
749b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  class TPResult {
750b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    enum Result {
751b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_true,
752b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_false,
753b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_ambiguous,
754b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis      TPR_error
755b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    };
756b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    Result Res;
757b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    TPResult(Result result) : Res(result) {}
758b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  public:
759b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult True() { return TPR_true; }
760b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult False() { return TPR_false; }
761b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Ambiguous() { return TPR_ambiguous; }
762b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    static TPResult Error() { return TPR_error; }
763b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis
764b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator==(const TPResult &RHS) const { return Res == RHS.Res; }
765b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis    bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; }
766b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis  };
767b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis
768b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a
769b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// declaration specifier, TPResult::False() if it is not,
770b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// TPResult::Ambiguous() if it could be either a decl-specifier or a
771b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// function-style cast, and TPResult::Error() if a parsing error was
772b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  /// encountered.
7735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  /// Doesn't consume tokens.
774b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult isCXXDeclarationSpecifier();
7755404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
7765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // "Tentative parsing" functions, used for disambiguation. If a parsing error
777b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // is encountered they will return TPResult::Error().
778b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // Returning TPResult::True()/False() indicates that the ambiguity was
779b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates
780b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  // that more tentative parsing is necessary for disambiguation.
7815404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis  // They all consume tokens, so backtracking should be used after calling them.
7825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
783b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseDeclarationSpecifier();
784b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseSimpleDeclaration();
785b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseTypeofSpecifier();
786b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseInitDeclaratorList();
78778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis  TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true);
788b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseParameterDeclarationClause();
789b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseFunctionDeclarator();
790b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis  TPResult TryParseBracketDeclarator();
7915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
7925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis
793cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  TypeTy *ParseTypeName();
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  AttributeList *ParseAttributes();
795d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  void ParseTypeofSpecifier(DeclSpec &DS);
796eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
797eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
798eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// enter a new C++ declarator scope and exit it when the function is
799eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  /// finished.
800eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  class DeclaratorScopeObj {
801eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    Parser &P;
802751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis    CXXScopeSpec &SS;
803eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  public:
804eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) : P(p), SS(ss) {}
805eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
806eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    void EnterDeclaratorScope() {
807eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis      if (SS.isSet())
808eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis        P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS);
809eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
810eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis
811eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    ~DeclaratorScopeObj() {
812eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis      if (SS.isSet())
813eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis        P.Actions.ActOnCXXExitDeclaratorScope(SS);
814eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis    }
815eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  };
8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ParseDeclarator - Parse and verify a newly-initialized declarator.
8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDeclarator(Declarator &D);
8194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  /// A function that parses a variant of direct-declarator.
8204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
8214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  void ParseDeclaratorInternal(Declarator &D,
8224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl                               DirectDeclParseFunction DirectDeclParser);
8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseTypeQualifierListOpt(DeclSpec &DS);
8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseDirectDeclarator(Declarator &D);
8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseParenDeclarator(Declarator &D);
8267399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner  void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
8277399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner                               AttributeList *AttrList = 0,
8287399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner                               bool RequiresArg = false);
82966d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner  void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
83066d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner                                             Declarator &D);
8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ParseBracketDeclarator(Declarator &D);
8328f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner
8338f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  //===--------------------------------------------------------------------===//
8348f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  // C++ 7: Declarations [dcl.dcl]
8358f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner
8368f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner  DeclTy *ParseNamespace(unsigned Context);
837c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner  DeclTy *ParseLinkage(unsigned Context);
8388f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner
839e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
840e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 9: classes [class] and C structs/unions.
841eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis  TypeTy *ParseClassName(const CXXScopeSpec *SS = 0);
842e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  void ParseClassSpecifier(DeclSpec &DS);
8434cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType,
8444cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis                                   DeclTy *TagDecl);
8454cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis  DeclTy *ParseCXXClassMemberDeclaration(AccessSpecifier AS);
8467ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  void ParseConstructorInitializer(DeclTy *ConstructorDecl);
8477ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor  MemInitResult ParseMemInitializer(DeclTy *ConstructorDecl);
848e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor
849e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  //===--------------------------------------------------------------------===//
850e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  // C++ 10: Derived classes [class.derived]
851e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor  void ParseBaseClause(DeclTy *ClassDecl);
852f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor  BaseResult ParseBaseSpecifier(DeclTy *ClassDecl);
8531b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor  AccessSpecifier getAccessSpecifierIfPresent() const;
8541cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor
8551cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor  //===--------------------------------------------------------------------===//
8561cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor  // C++ 13.5: Overloaded operators [over.oper]
857e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  OverloadedOperatorKind TryParseOperatorFunctionId();
8582f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor  TypeTy *ParseConversionFunctionId();
859adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor
860adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  //===--------------------------------------------------------------------===//
861adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14: Templates [temp]
862adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  // C++ 14.1: Template Parameters [temp.param]
863adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  DeclTy *ParseTemplateDeclaration(unsigned Context);
864adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  bool ParseTemplateParameters(DeclTy* TempDecl);
865adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  bool ParseTemplateParameterList(DeclTy *TmpDecl);
866adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  DeclTy *ParseTemplateParameter();
867adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  DeclTy *ParseTypeParameter();
868adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  DeclTy *ParseTemplateTemplateParameter();
869adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor  DeclTy *ParseNonTypeTemplateParameter();
8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
875