Parser.h revision 199482
165557Sjasone//===--- Parser.h - C Language Parser ---------------------------*- C++ -*-===//
2181695Sattilio//
3181695Sattilio//                     The LLVM Compiler Infrastructure
4181695Sattilio//
5181695Sattilio// This file is distributed under the University of Illinois Open Source
665557Sjasone// License. See LICENSE.TXT for details.
765557Sjasone//
865557Sjasone//===----------------------------------------------------------------------===//
965557Sjasone//
1065557Sjasone//  This file defines the Parser interface.
1165557Sjasone//
1265557Sjasone//===----------------------------------------------------------------------===//
1365557Sjasone
1465557Sjasone#ifndef LLVM_CLANG_PARSE_PARSER_H
1565557Sjasone#define LLVM_CLANG_PARSE_PARSER_H
1665557Sjasone
1765557Sjasone#include "clang/Lex/Preprocessor.h"
1865557Sjasone#include "clang/Parse/AccessSpecifier.h"
1965557Sjasone#include "clang/Parse/Action.h"
2065557Sjasone#include "clang/Parse/DeclSpec.h"
2165557Sjasone#include "llvm/ADT/OwningPtr.h"
2265557Sjasone#include <stack>
2365557Sjasone#include <list>
2465557Sjasone
2565557Sjasonenamespace clang {
2665557Sjasone  class AttributeList;
2765557Sjasone  class PragmaHandler;
2865557Sjasone  class Scope;
2965557Sjasone  class DiagnosticBuilder;
3065557Sjasone  class Parser;
3165557Sjasone  class PragmaUnusedHandler;
3267352Sjhb
3365557Sjasone/// PrettyStackTraceParserEntry - If a crash happens while the parser is active,
3465557Sjasone/// an entry is printed for it.
3565557Sjasoneclass PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry {
3674912Sjhb  const Parser &P;
3774912Sjhbpublic:
3874912Sjhb  PrettyStackTraceParserEntry(const Parser &p) : P(p) {}
3972200Sbmilekic  virtual void print(llvm::raw_ostream &OS) const;
4072200Sbmilekic};
4172200Sbmilekic
4265557Sjasone
4365557Sjasone/// Parser - This implements a parser for the C family of languages.  After
4465557Sjasone/// parsing units of the grammar, productions are invoked to handle whatever has
4565557Sjasone/// been read.
4665557Sjasone///
4765557Sjasoneclass Parser {
4865557Sjasone  friend class PragmaUnusedHandler;
4965557Sjasone  PrettyStackTraceParserEntry CrashInfo;
5065557Sjasone
5165557Sjasone  Preprocessor &PP;
5265557Sjasone
5365557Sjasone  /// Tok - The current token we are peeking ahead.  All parsing methods assume
5465557Sjasone  /// that this is valid.
5565557Sjasone  Token Tok;
5665557Sjasone
5765557Sjasone  // PrevTokLocation - The location of the token we previously
5865557Sjasone  // consumed. This token is used for diagnostics where we expected to
5965557Sjasone  // see a token following another token (e.g., the ';' at the end of
6065557Sjasone  // a statement).
61111881Sjhb  SourceLocation PrevTokLocation;
62111881Sjhb
63111881Sjhb  unsigned short ParenCount, BracketCount, BraceCount;
64111881Sjhb
65111881Sjhb  /// Actions - These are the callbacks we invoke as we parse various constructs
66111881Sjhb  /// in the file.  This refers to the common base class between MinimalActions
67111881Sjhb  /// and SemaActions for those uses that don't matter.
68111881Sjhb  Action &Actions;
69111881Sjhb
70111881Sjhb  Scope *CurScope;
71111881Sjhb  Diagnostic &Diags;
72111881Sjhb
73111881Sjhb  /// ScopeCache - Cache scopes to reduce malloc traffic.
74111881Sjhb  enum { ScopeCacheSize = 16 };
75111881Sjhb  unsigned NumCachedScopes;
76111881Sjhb  Scope *ScopeCache[ScopeCacheSize];
77111881Sjhb
78111881Sjhb  /// Ident_super - IdentifierInfo for "super", to support fast
79111881Sjhb  /// comparison.
80111881Sjhb  IdentifierInfo *Ident_super;
81111881Sjhb
82111881Sjhb  llvm::OwningPtr<PragmaHandler> PackHandler;
83111881Sjhb  llvm::OwningPtr<PragmaHandler> UnusedHandler;
84111881Sjhb  llvm::OwningPtr<PragmaHandler> WeakHandler;
85111881Sjhb  llvm::OwningPtr<clang::CommentHandler> CommentHandler;
86111881Sjhb
87116182Sobrien  /// Whether the '>' token acts as an operator or not. This will be
88116182Sobrien  /// true except when we are parsing an expression within a C++
89116182Sobrien  /// template argument list, where the '>' closes the template
9068790Sjhb  /// argument list.
91168856Sjkoshy  bool GreaterThanIsOperator;
92181695Sattilio
9367676Sjhb  /// The "depth" of the template parameters currently being parsed.
9467676Sjhb  unsigned TemplateParameterDepth;
9565557Sjasone
9667352Sjhb  /// \brief RAII object that makes '>' behave either as an operator
97131930Smarcel  /// or as the closing angle bracket for a template argument list.
9867352Sjhb  struct GreaterThanIsOperatorScope {
9974912Sjhb    bool &GreaterThanIsOperator;
10074912Sjhb    bool OldGreaterThanIsOperator;
10167352Sjhb
10274912Sjhb    GreaterThanIsOperatorScope(bool &GTIO, bool Val)
103164033Srwatson      : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
10465557Sjasone      GreaterThanIsOperator = Val;
105178841Sattilio    }
106183955Sattilio
107181695Sattilio    ~GreaterThanIsOperatorScope() {
10867676Sjhb      GreaterThanIsOperator = OldGreaterThanIsOperator;
10965557Sjasone    }
11065557Sjasone  };
111181695Sattilio
11268790Sjhbpublic:
113181695Sattilio  Parser(Preprocessor &PP, Action &Actions);
11468790Sjhb  ~Parser();
115111881Sjhb
116111881Sjhb  const LangOptions &getLang() const { return PP.getLangOptions(); }
117181695Sattilio  const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
118181695Sattilio  Preprocessor &getPreprocessor() const { return PP; }
119181695Sattilio  Action &getActions() const { return Actions; }
120181695Sattilio
121154818Sjhb  const Token &getCurToken() const { return Tok; }
122154790Sjhb
123154790Sjhb  // Type forwarding.  All of these are statically 'void*', but they may all be
124154790Sjhb  // different actual classes based on the actions in place.
125154790Sjhb  typedef Action::ExprTy ExprTy;
126154790Sjhb  typedef Action::StmtTy StmtTy;
127154790Sjhb  typedef Action::DeclPtrTy DeclPtrTy;
128178165Sattilio  typedef Action::DeclGroupPtrTy DeclGroupPtrTy;
129178165Sattilio  typedef Action::TypeTy TypeTy;
130187511Sthompsa  typedef Action::BaseTy BaseTy;
131178165Sattilio  typedef Action::MemInitTy MemInitTy;
132105508Sphk  typedef Action::CXXScopeTy CXXScopeTy;
133105508Sphk  typedef Action::TemplateParamsTy TemplateParamsTy;
134105508Sphk  typedef Action::TemplateTy TemplateTy;
135181695Sattilio
136181695Sattilio  typedef llvm::SmallVector<TemplateParamsTy *, 4> TemplateParameterLists;
137181695Sattilio
138179025Sattilio  typedef Action::ExprResult        ExprResult;
139181695Sattilio  typedef Action::StmtResult        StmtResult;
140181695Sattilio  typedef Action::BaseResult        BaseResult;
141181695Sattilio  typedef Action::MemInitResult     MemInitResult;
142181695Sattilio  typedef Action::TypeResult        TypeResult;
143181695Sattilio
144181695Sattilio  typedef Action::OwningExprResult OwningExprResult;
145181695Sattilio  typedef Action::OwningStmtResult OwningStmtResult;
14665557Sjasone
147181695Sattilio  typedef Action::ExprArg ExprArg;
148181695Sattilio  typedef Action::MultiStmtArg MultiStmtArg;
14974912Sjhb  typedef Action::FullExprArg FullExprArg;
15067352Sjhb
151181695Sattilio  /// Adorns a ExprResult with Actions to make it an OwningExprResult
152181695Sattilio  OwningExprResult Owned(ExprResult res) {
15371352Sjasone    return OwningExprResult(Actions, res);
154181695Sattilio  }
15571352Sjasone  /// Adorns a StmtResult with Actions to make it an OwningStmtResult
156181695Sattilio  OwningStmtResult Owned(StmtResult res) {
157181695Sattilio    return OwningStmtResult(Actions, res);
158181695Sattilio  }
159178165Sattilio
160181695Sattilio  OwningExprResult ExprError() { return OwningExprResult(Actions, true); }
161181695Sattilio  OwningStmtResult StmtError() { return OwningStmtResult(Actions, true); }
162181695Sattilio
163181695Sattilio  OwningExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); }
164181695Sattilio  OwningStmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); }
165181695Sattilio
166181695Sattilio  OwningExprResult ExprEmpty() { return OwningExprResult(Actions, false); }
167181695Sattilio
168181695Sattilio  // Parsing methods.
169181695Sattilio
170181695Sattilio  /// ParseTranslationUnit - All in one method that initializes parses, and
171181695Sattilio  /// shuts down the parser.
172181695Sattilio  void ParseTranslationUnit();
173181695Sattilio
174181695Sattilio  /// Initialize - Warm up the parser.
175181695Sattilio  ///
176181695Sattilio  void Initialize();
177181695Sattilio
17871352Sjasone  /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
179181695Sattilio  /// the EOF was encountered.
180181695Sattilio  bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
181181695Sattilio
182181695Sattilio  DeclGroupPtrTy RetrievePendingObjCImpDecl();
183181695Sattilio
184181695Sattilioprivate:
185181695Sattilio  //===--------------------------------------------------------------------===//
186181695Sattilio  // Low-Level token peeking and consumption methods.
187181695Sattilio  //
188181695Sattilio
189181695Sattilio  /// isTokenParen - Return true if the cur token is '(' or ')'.
190178165Sattilio  bool isTokenParen() const {
191178165Sattilio    return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren;
192178165Sattilio  }
193178165Sattilio  /// isTokenBracket - Return true if the cur token is '[' or ']'.
194178165Sattilio  bool isTokenBracket() const {
195178165Sattilio    return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square;
196178165Sattilio  }
197181695Sattilio  /// isTokenBrace - Return true if the cur token is '{' or '}'.
198181695Sattilio  bool isTokenBrace() const {
199181695Sattilio    return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace;
200181695Sattilio  }
201178165Sattilio
202178165Sattilio  /// isTokenStringLiteral - True if this token is a string-literal.
203178165Sattilio  ///
204178165Sattilio  bool isTokenStringLiteral() const {
205178165Sattilio    return Tok.getKind() == tok::string_literal ||
206178165Sattilio           Tok.getKind() == tok::wide_string_literal;
207178165Sattilio  }
208178165Sattilio
209178165Sattilio  /// ConsumeToken - Consume the current 'peek token' and lex the next one.
210178165Sattilio  /// This does not work with all kinds of tokens: strings and specific other
211178165Sattilio  /// tokens must be consumed with custom methods below.  This returns the
212178165Sattilio  /// location of the consumed token.
213178165Sattilio  SourceLocation ConsumeToken() {
214178165Sattilio    assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() &&
215178165Sattilio           !isTokenBrace() &&
216178165Sattilio           "Should consume special tokens with Consume*Token");
217178165Sattilio    PrevTokLocation = Tok.getLocation();
218178165Sattilio    PP.Lex(Tok);
219181695Sattilio    return PrevTokLocation;
220181695Sattilio  }
221181695Sattilio
222181695Sattilio  /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
22374912Sjhb  /// current token type.  This should only be used in cases where the type of
224181695Sattilio  /// the token really isn't known, e.g. in error recovery.
225181695Sattilio  SourceLocation ConsumeAnyToken() {
226181695Sattilio    if (isTokenParen())
227181695Sattilio      return ConsumeParen();
228181695Sattilio    else if (isTokenBracket())
229181695Sattilio      return ConsumeBracket();
230181695Sattilio    else if (isTokenBrace())
231181695Sattilio      return ConsumeBrace();
232181695Sattilio    else if (isTokenStringLiteral())
233181695Sattilio      return ConsumeStringToken();
234181695Sattilio    else
235181695Sattilio      return ConsumeToken();
236181695Sattilio  }
237181695Sattilio
238188056Simp  /// ConsumeParen - This consume method keeps the paren count up-to-date.
239188056Simp  ///
24074912Sjhb  SourceLocation ConsumeParen() {
24171352Sjasone    assert(isTokenParen() && "wrong consume method");
242181695Sattilio    if (Tok.getKind() == tok::l_paren)
243181695Sattilio      ++ParenCount;
244181695Sattilio    else if (ParenCount)
245181695Sattilio      --ParenCount;       // Don't let unbalanced )'s drive the count negative.
246181695Sattilio    PrevTokLocation = Tok.getLocation();
247181695Sattilio    PP.Lex(Tok);
248181695Sattilio    return PrevTokLocation;
249181695Sattilio  }
250181695Sattilio
251181695Sattilio  /// ConsumeBracket - This consume method keeps the bracket count up-to-date.
25274912Sjhb  ///
25371352Sjasone  SourceLocation ConsumeBracket() {
254181695Sattilio    assert(isTokenBracket() && "wrong consume method");
255181695Sattilio    if (Tok.getKind() == tok::l_square)
256181695Sattilio      ++BracketCount;
257181695Sattilio    else if (BracketCount)
258181695Sattilio      --BracketCount;     // Don't let unbalanced ]'s drive the count negative.
259181695Sattilio
260181695Sattilio    PrevTokLocation = Tok.getLocation();
26171352Sjasone    PP.Lex(Tok);
262181695Sattilio    return PrevTokLocation;
263181695Sattilio  }
264181695Sattilio
265181695Sattilio  /// ConsumeBrace - This consume method keeps the brace count up-to-date.
266181695Sattilio  ///
267181695Sattilio  SourceLocation ConsumeBrace() {
268181695Sattilio    assert(isTokenBrace() && "wrong consume method");
269181695Sattilio    if (Tok.getKind() == tok::l_brace)
270181695Sattilio      ++BraceCount;
271181695Sattilio    else if (BraceCount)
272181695Sattilio      --BraceCount;     // Don't let unbalanced }'s drive the count negative.
273181695Sattilio
274181695Sattilio    PrevTokLocation = Tok.getLocation();
275181695Sattilio    PP.Lex(Tok);
276181695Sattilio    return PrevTokLocation;
277181695Sattilio  }
278181695Sattilio
279105508Sphk  /// ConsumeStringToken - Consume the current 'peek token', lexing a new one
28074912Sjhb  /// and returning the token kind.  This method is specific to strings, as it
281181695Sattilio  /// handles string literal concatenation, as per C99 5.1.1.2, translation
282181695Sattilio  /// phase #6.
28374912Sjhb  SourceLocation ConsumeStringToken() {
284105508Sphk    assert(isTokenStringLiteral() &&
28571352Sjasone           "Should only consume string literals with this method");
286179025Sattilio    PrevTokLocation = Tok.getLocation();
287179025Sattilio    PP.Lex(Tok);
288179025Sattilio    return PrevTokLocation;
289179025Sattilio  }
290179025Sattilio
291181695Sattilio  /// GetLookAheadToken - This peeks ahead N tokens and returns that token
292181695Sattilio  /// without consuming any tokens.  LookAhead(0) returns 'Tok', LookAhead(1)
293181695Sattilio  /// returns the token after Tok, etc.
294181695Sattilio  ///
295181695Sattilio  /// Note that this differs from the Preprocessor's LookAhead method, because
296181695Sattilio  /// the Parser always has one token lexed that the preprocessor doesn't.
297181695Sattilio  ///
298181695Sattilio  const Token &GetLookAheadToken(unsigned N) {
299181695Sattilio    if (N == 0 || Tok.is(tok::eof)) return Tok;
300181695Sattilio    return PP.LookAhead(N-1);
301181695Sattilio  }
302181695Sattilio
303181695Sattilio  /// NextToken - This peeks ahead one token and returns it without
304181695Sattilio  /// consuming it.
305181695Sattilio  const Token &NextToken() {
306181695Sattilio    return PP.LookAhead(0);
307181695Sattilio  }
308181695Sattilio
309181695Sattilio  /// TryAnnotateTypeOrScopeToken - If the current token position is on a
310181695Sattilio  /// typename (possibly qualified in C++) or a C++ scope specifier not followed
311181695Sattilio  /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens
312181695Sattilio  /// with a single annotation token representing the typename or C++ scope
313181695Sattilio  /// respectively.
314181695Sattilio  /// This simplifies handling of C++ scope specifiers and allows efficient
315181695Sattilio  /// backtracking without the need to re-parse and resolve nested-names and
316181695Sattilio  /// typenames.
317181695Sattilio  /// It will mainly be called when we expect to treat identifiers as typenames
318181695Sattilio  /// (if they are typenames). For example, in C we do not expect identifiers
319181695Sattilio  /// inside expressions to be treated as typenames so it will not be called
320181695Sattilio  /// for expressions in C.
321181695Sattilio  ///
322181695Sattilio  /// This returns true if the token was annotated.
323181695Sattilio  bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false);
324181695Sattilio
325181695Sattilio  /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
326181695Sattilio  /// annotates C++ scope specifiers.  This returns true if the token was
327181695Sattilio  /// annotated.
328181695Sattilio  bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
329112117Sjhb
330112117Sjhb  /// TentativeParsingAction - An object that is used as a kind of "tentative
331112117Sjhb  /// parsing transaction". It gets instantiated to mark the token position and
332179025Sattilio  /// after the token consumption is done, Commit() or Revert() is called to
333181695Sattilio  /// either "commit the consumed tokens" or revert to the previously marked
334181695Sattilio  /// token position. Example:
335181695Sattilio  ///
336181695Sattilio  ///   TentativeParsingAction TPA(*this);
337112117Sjhb  ///   ConsumeToken();
338112117Sjhb  ///   ....
339181695Sattilio  ///   TPA.Revert();
340181695Sattilio  ///
341112562Sjhb  class TentativeParsingAction {
342181695Sattilio    Parser &P;
343181695Sattilio    Token PrevTok;
344181695Sattilio    bool isActive;
345181695Sattilio
346181695Sattilio  public:
347181695Sattilio    explicit TentativeParsingAction(Parser& p) : P(p) {
348181695Sattilio      PrevTok = P.Tok;
349181695Sattilio      P.PP.EnableBacktrackAtThisPos();
350181695Sattilio      isActive = true;
351181695Sattilio    }
352181695Sattilio    void Commit() {
353181695Sattilio      assert(isActive && "Parsing action was finished!");
35474912Sjhb      P.PP.CommitBacktrackedTokens();
355181695Sattilio      isActive = false;
356181695Sattilio    }
357181695Sattilio    void Revert() {
358181695Sattilio      assert(isActive && "Parsing action was finished!");
359181695Sattilio      P.PP.Backtrack();
360181695Sattilio      P.Tok = PrevTok;
36174912Sjhb      isActive = false;
362181695Sattilio    }
363181695Sattilio    ~TentativeParsingAction() {
364181695Sattilio      assert(!isActive && "Forgot to call Commit or Revert!");
365181695Sattilio    }
366181695Sattilio  };
367181695Sattilio
368181695Sattilio
369181695Sattilio  /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'),
370111881Sjhb  /// this helper function matches and consumes the specified RHS token if
371187511Sthompsa  /// present.  If not present, it emits the specified diagnostic indicating
372181695Sattilio  /// that the parser failed to match the RHS of the token at LHSLoc.  LHSName
373181695Sattilio  /// should be the name of the unmatched LHS token.  This returns the location
374181695Sattilio  /// of the consumed token.
375181695Sattilio  SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok,
376181695Sattilio                                     SourceLocation LHSLoc);
377100011Smp
37872200Sbmilekic  /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
379188056Simp  /// input.  If so, it is consumed and false is returned.
38072200Sbmilekic  ///
381112562Sjhb  /// If the input is malformed, this emits the specified diagnostic.  Next, if
382183329Sjhb  /// SkipToTok is specified, it calls SkipUntil(SkipToTok).  Finally, true is
383183329Sjhb  /// returned.
384183329Sjhb  bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag,
385183329Sjhb                        const char *DiagMsg = "",
386183329Sjhb                        tok::TokenKind SkipToTok = tok::unknown);
387112562Sjhb
38877843Speter  //===--------------------------------------------------------------------===//
389134873Sjmg  // Scope manipulation
390134873Sjmg
391112562Sjhb  /// ParseScope - Introduces a new scope for parsing. The kind of
39271352Sjasone  /// scope is determined by ScopeFlags. Objects of this type should
393131930Smarcel  /// be created on the stack to coincide with the position where the
39472200Sbmilekic  /// parser enters the new scope, and this object's constructor will
395181695Sattilio  /// create that new scope. Similarly, once the object is destroyed
396131930Smarcel  /// the parser will exit the scope.
397151623Sjhb  class ParseScope {
39865557Sjasone    Parser *Self;
39965557Sjasone    ParseScope(const ParseScope&); // do not implement
400131930Smarcel    ParseScope& operator=(const ParseScope&); // do not implement
401131930Smarcel
40267676Sjhb  public:
403131930Smarcel    // ParseScope - Construct a new object to manage a scope in the
40465557Sjasone    // parser Self where the new Scope is created with the flags
405134873Sjmg    // ScopeFlags, but only when ManageScope is true (the default). If
406134873Sjmg    // ManageScope is false, this object does nothing.
407110779Speter    ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true)
408110779Speter      : Self(Self) {
409181695Sattilio      if (ManageScope)
410110779Speter        Self->EnterScope(ScopeFlags);
411151623Sjhb      else
412110779Speter        this->Self = 0;
413110779Speter    }
414110779Speter
415134873Sjmg    // Exit - Exit the scope associated with this object now, rather
416134873Sjmg    // than waiting until the object is destroyed.
417131930Smarcel    void Exit() {
41865557Sjasone      if (Self) {
41967676Sjhb        Self->ExitScope();
42077843Speter        Self = 0;
42167676Sjhb      }
42277843Speter    }
42365557Sjasone
424134873Sjmg    ~ParseScope() {
425181695Sattilio      Exit();
426181695Sattilio    }
42765557Sjasone  };
428181695Sattilio
429181695Sattilio  /// EnterScope - Start a new scope.
430181695Sattilio  void EnterScope(unsigned ScopeFlags);
431181695Sattilio
432181695Sattilio  /// ExitScope - Pop a scope off the scope stack.
433181695Sattilio  void ExitScope();
434181695Sattilio
435181695Sattilio  //===--------------------------------------------------------------------===//
436181695Sattilio  // Diagnostic Emission and Error recovery.
437181695Sattilio
438181695Sattilio  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
439181695Sattilio  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
44074912Sjhb
441181695Sattilio  void SuggestParentheses(SourceLocation Loc, unsigned DK,
442181695Sattilio                          SourceRange ParenRange);
44374912Sjhb
44474912Sjhb  /// SkipUntil - Read tokens until we get to the specified token, then consume
445181695Sattilio  /// it (unless DontConsume is true).  Because we cannot guarantee that the
446181695Sattilio  /// token will ever occur, this skips to the next token, or to some likely
44774912Sjhb  /// good stopping point.  If StopAtSemi is true, skipping will stop at a ';'
44874912Sjhb  /// character.
449181695Sattilio  ///
450181695Sattilio  /// If SkipUntil finds the specified token, it returns true, otherwise it
45174912Sjhb  /// returns false.
452179025Sattilio  bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
453179025Sattilio                 bool DontConsume = false) {
45465557Sjasone    return SkipUntil(&T, 1, StopAtSemi, DontConsume);
455181695Sattilio  }
456149441Struckman  bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
457149441Struckman                 bool DontConsume = false) {
458149441Struckman    tok::TokenKind TokArray[] = {T1, T2};
459149441Struckman    return SkipUntil(TokArray, 2, StopAtSemi, DontConsume);
460149441Struckman  }
461181695Sattilio  bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
462181695Sattilio                 bool StopAtSemi = true, bool DontConsume = false);
46374912Sjhb
464181695Sattilio  //===--------------------------------------------------------------------===//
46565557Sjasone  // Lexing and parsing of C++ inline methods.
466181695Sattilio
467181695Sattilio  struct LexedMethod {
468181695Sattilio    Action::DeclPtrTy D;
469181695Sattilio    CachedTokens Toks;
470181695Sattilio
471181695Sattilio    /// \brief Whether this member function had an associated template
472196891Santoine    /// scope. When true, D is a template declaration.
473196891Santoine    /// othewise, it is a member function declaration.
474181695Sattilio    bool TemplateScope;
475181695Sattilio
47674912Sjhb    explicit LexedMethod(Action::DeclPtrTy MD) : D(MD), TemplateScope(false) {}
477149738Sjhb  };
478149738Sjhb
479149738Sjhb  /// LateParsedDefaultArgument - Keeps track of a parameter that may
48074912Sjhb  /// have a default argument that cannot be parsed yet because it
48174912Sjhb  /// occurs within a member function declaration inside the class
482168402Spjd  /// (C++ [class.mem]p2).
483149738Sjhb  struct LateParsedDefaultArgument {
484149738Sjhb    explicit LateParsedDefaultArgument(Action::DeclPtrTy P,
485149738Sjhb                                       CachedTokens *Toks = 0)
486149738Sjhb      : Param(P), Toks(Toks) { }
487111951Sjhb
488108184Skris    /// Param - The parameter declaration for this parameter.
48996122Salfred    Action::DeclPtrTy Param;
49091140Stanimura
49174912Sjhb    /// Toks - The sequence of tokens that comprises the default
49291140Stanimura    /// argument expression, not including the '=' or the terminating
493177299Spjd    /// ')' or ','. This will be NULL for parameters that have no
494168856Sjkoshy    /// default argument.
495168856Sjkoshy    CachedTokens *Toks;
496168856Sjkoshy  };
49774912Sjhb
49875464Sjhb  /// LateParsedMethodDeclaration - A method declaration inside a class that
499130022Srwatson  /// contains at least one entity whose parsing needs to be delayed
500130022Srwatson  /// until the class itself is completely-defined, such as a default
501130022Srwatson  /// argument (C++ [class.mem]p2).
502130396Srwatson  struct LateParsedMethodDeclaration {
503130396Srwatson    explicit LateParsedMethodDeclaration(Action::DeclPtrTy M)
504130022Srwatson      : Method(M), TemplateScope(false) { }
505130022Srwatson
506130022Srwatson    /// Method - The method declaration.
507130022Srwatson    Action::DeclPtrTy Method;
508130022Srwatson
509130396Srwatson    /// \brief Whether this member function had an associated template
510185747Skmacy    /// scope. When true, D is a template declaration.
511130022Srwatson    /// othewise, it is a member function declaration.
512130022Srwatson    bool TemplateScope;
513130022Srwatson
514130022Srwatson    /// DefaultArgs - Contains the parameters of the function and
515191672Sbms    /// their default arguments. At least one of the parameters will
516191672Sbms    /// have a default argument, but all of the parameters of the
517148682Srwatson    /// method will be stored so that they can be reintroduced into
518178285Srwatson    /// scope at the appropriate times.
519148682Srwatson    llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
520148682Srwatson  };
521148682Srwatson
522148682Srwatson  /// LateParsedMethodDecls - During parsing of a top (non-nested) C++
523148682Srwatson  /// class, its method declarations that contain parts that won't be
524191672Sbms  /// parsed until after the definiton is completed (C++ [class.mem]p2),
525191672Sbms  /// the method declarations will be stored here with the tokens that
526191672Sbms  /// will be parsed to create those entities.
527191672Sbms  typedef std::list<LateParsedMethodDeclaration> LateParsedMethodDecls;
528191672Sbms
529191672Sbms  /// LexedMethodsForTopClass - During parsing of a top (non-nested) C++ class,
530191672Sbms  /// its inline method definitions and the inline method definitions of its
531191672Sbms  /// nested classes are lexed and stored here.
532191672Sbms  typedef std::list<LexedMethod> LexedMethodsForTopClass;
533130022Srwatson
534130396Srwatson  /// \brief Representation of a class that has been parsed, including
535189544Srwatson  /// any member function declarations or definitions that need to be
536189544Srwatson  /// parsed after the corresponding top-level class is complete.
537130396Srwatson  struct ParsingClass {
538130396Srwatson    ParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass)
539130031Sjhb      : TopLevelClass(TopLevelClass), TemplateScope(false),
540130022Srwatson        TagOrTemplate(TagOrTemplate) { }
541130022Srwatson
542130022Srwatson    /// \brief Whether this is a "top-level" class, meaning that it is
543178285Srwatson    /// not nested within another class.
544178285Srwatson    bool TopLevelClass : 1;
545130396Srwatson
546130022Srwatson    /// \brief Whether this class had an associated template
547130022Srwatson    /// scope. When true, TagOrTemplate is a template declaration;
548130022Srwatson    /// othewise, it is a tag declaration.
549130022Srwatson    bool TemplateScope : 1;
550178285Srwatson
551178285Srwatson    /// \brief The class or class template whose definition we are parsing.
552130396Srwatson    DeclPtrTy TagOrTemplate;
553130022Srwatson
554130022Srwatson    /// MethodDecls - Method declarations that contain pieces whose
555130022Srwatson    /// parsing will be delayed until the class is fully defined.
556130022Srwatson    LateParsedMethodDecls MethodDecls;
557130022Srwatson
558130022Srwatson    /// MethodDefs - Methods whose definitions will be parsed once the
559130031Sjhb    /// class has been fully defined.
560130022Srwatson    LexedMethodsForTopClass MethodDefs;
561132639Srwatson
562132639Srwatson    /// \brief Nested classes inside this class.
563132639Srwatson    llvm::SmallVector<ParsingClass*, 4> NestedClasses;
564132639Srwatson  };
565132639Srwatson
566132639Srwatson  /// \brief The stack of classes that is currently being
567134971Srwatson  /// parsed. Nested and local classes will be pushed onto this stack
568134971Srwatson  /// when they are parsed, and removed afterward.
569134971Srwatson  std::stack<ParsingClass *> ClassStack;
570134971Srwatson
571134971Srwatson  ParsingClass &getCurrentClass() {
572144832Spjd    assert(!ClassStack.empty() && "No lexed method stacks!");
573143335Srwatson    return *ClassStack.top();
574143335Srwatson  }
575143335Srwatson
576143335Srwatson  /// \brief RAII object used to inform the actions that we're
577143335Srwatson  /// currently parsing a declaration.  This is active when parsing a
578134971Srwatson  /// variable's initializer, but not when parsing the body of a
579170530Ssam  /// class or function definition.
580134971Srwatson  class ParsingDeclRAIIObject {
581170530Ssam    Action &Actions;
582170530Ssam    Action::ParsingDeclStackState State;
583170530Ssam    bool Popped;
584170530Ssam
585170530Ssam  public:
586170530Ssam    ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) {
587170530Ssam      push();
588170530Ssam    }
589170530Ssam
590170530Ssam    ~ParsingDeclRAIIObject() {
591170530Ssam      abort();
592168217Swkoszek    }
593168217Swkoszek
594168217Swkoszek    /// Resets the RAII object for a new declaration.
595168217Swkoszek    void reset() {
596168217Swkoszek      abort();
597168217Swkoszek      push();
598144836Spjd    }
599144836Spjd
600145425Sjeff    /// Signals that the context was completed without an appropriate
601145425Sjeff    /// declaration being parsed.
602145425Sjeff    void abort() {
603144836Spjd      pop(DeclPtrTy());
604144836Spjd    }
605144836Spjd
606166421Skib    void complete(DeclPtrTy D) {
607166421Skib      assert(!Popped && "ParsingDeclaration has already been popped!");
608166421Skib      pop(D);
609166421Skib    }
610166421Skib
611166421Skib  private:
612166421Skib    void push() {
613192416Skmacy      State = Actions.PushParsingDeclaration();
614192416Skmacy      Popped = false;
615192416Skmacy    }
616192416Skmacy
617192416Skmacy    void pop(DeclPtrTy D) {
618192416Skmacy      if (!Popped) {
619192416Skmacy        Actions.PopParsingDeclaration(State, D);
62075464Sjhb        Popped = true;
62175464Sjhb      }
62284331Sjhb    }
62384331Sjhb  };
62472224Sjhb
625150582Sjhb  /// A class for parsing a DeclSpec.
62674912Sjhb  class ParsingDeclSpec : public DeclSpec {
627173877Sattilio    ParsingDeclRAIIObject ParsingRAII;
62872224Sjhb
62974912Sjhb  public:
63072224Sjhb    ParsingDeclSpec(Parser &P) : ParsingRAII(P) {
631170848Smarius    }
632170848Smarius
633170848Smarius    void complete(DeclPtrTy D) {
634170848Smarius      ParsingRAII.complete(D);
635157584Smarcel    }
636124972Sru
637161638Sssouhlal    void abort() {
638122001Sjhb      ParsingRAII.abort();
639168856Sjkoshy    }
640168856Sjkoshy  };
641168856Sjkoshy
642170302Sjeff  /// A class for parsing a declarator.
643126324Sjhb  class ParsingDeclarator : public Declarator {
644170302Sjeff    ParsingDeclRAIIObject ParsingRAII;
645173877Sattilio
646170302Sjeff  public:
647170302Sjeff    ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C)
64874912Sjhb      : Declarator(DS, C), ParsingRAII(P) {
649122514Sjhb    }
65074912Sjhb
651136374Srwatson    const ParsingDeclSpec &getDeclSpec() const {
652162285Sscottl      return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec());
653169803Sjeff    }
654172256Sattilio
655172256Sattilio    ParsingDeclSpec &getMutableDeclSpec() const {
656172256Sattilio      return const_cast<ParsingDeclSpec&>(getDeclSpec());
657176771Sraj    }
658176771Sraj
659176771Sraj    void clear() {
66065557Sjasone      Declarator::clear();
66165557Sjasone      ParsingRAII.reset();
66265557Sjasone    }
663178149Sattilio
66488322Sjhb    void complete(DeclPtrTy D) {
665172256Sattilio      ParsingRAII.complete(D);
666108187Sjake    }
66799862Speter  };
668172256Sattilio
669172256Sattilio  /// \brief RAII object used to
670172256Sattilio  class ParsingClassDefinition {
671108187Sjake    Parser &P;
67278785Sjhb    bool Popped;
673178149Sattilio
674172256Sattilio  public:
675170302Sjeff    ParsingClassDefinition(Parser &P, DeclPtrTy TagOrTemplate, bool TopLevelClass)
676103786Sjeff      : P(P), Popped(false) {
677104951Speter      P.PushParsingClass(TagOrTemplate, TopLevelClass);
678104951Speter    }
679104951Speter
680115425Speter    /// \brief Pop this class of the stack.
681111068Speter    void Pop() {
682143204Swpaul      assert(!Popped && "Nested class has already been popped");
683111068Speter      Popped = true;
684144966Svkashyap      P.PopParsingClass();
685144966Svkashyap    }
686144966Svkashyap
687144966Svkashyap    ~ParsingClassDefinition() {
688144966Svkashyap      if (!Popped)
689168856Sjkoshy        P.PopParsingClass();
690168856Sjkoshy    }
691168856Sjkoshy  };
692170302Sjeff
69374912Sjhb  /// \brief Contains information about any template-specific
69474912Sjhb  /// information that has been parsed prior to parsing declaration
69565557Sjasone  /// specifiers.
69665557Sjasone  struct ParsedTemplateInfo {
697105508Sphk    ParsedTemplateInfo()
69865557Sjasone      : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { }
69965557Sjasone
70065557Sjasone    ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
70165557Sjasone                       bool isSpecialization,
70265856Sjhb                       bool lastParameterListWasEmpty = false)
70365557Sjasone      : Kind(isSpecialization? ExplicitSpecialization : Template),
70472200Sbmilekic        TemplateParams(TemplateParams),
70572200Sbmilekic        LastParameterListWasEmpty(lastParameterListWasEmpty) { }
706105508Sphk
70765557Sjasone    explicit ParsedTemplateInfo(SourceLocation ExternLoc,
70874912Sjhb                                SourceLocation TemplateLoc)
70974912Sjhb      : Kind(ExplicitInstantiation), TemplateParams(0),
71074912Sjhb        ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
71174912Sjhb        LastParameterListWasEmpty(false){ }
71274912Sjhb
71374912Sjhb    /// \brief The kind of template we are parsing.
714151629Sjhb    enum {
715151629Sjhb      /// \brief We are not parsing a template at all.
716151629Sjhb      NonTemplate = 0,
717151629Sjhb      /// \brief We are parsing a template declaration.
718151629Sjhb      Template,
719151629Sjhb      /// \brief We are parsing an explicit specialization.
720153133Sjhb      ExplicitSpecialization,
721153133Sjhb      /// \brief We are parsing an explicit instantiation.
722153133Sjhb      ExplicitInstantiation
72374912Sjhb    } Kind;
72471352Sjasone
72574912Sjhb    /// \brief The template parameter lists, for template declarations
72665557Sjasone    /// and explicit specializations.
72774912Sjhb    TemplateParameterLists *TemplateParams;
72874912Sjhb
72974912Sjhb    /// \brief The location of the 'extern' keyword, if any, for an explicit
73074912Sjhb    /// instantiation
73165557Sjasone    SourceLocation ExternLoc;
732184214Sdes
733181695Sattilio    /// \brief The location of the 'template' keyword, for an explicit
734181695Sattilio    /// instantiation.
73574912Sjhb    SourceLocation TemplateLoc;
73674912Sjhb
73774912Sjhb    /// \brief Whether the last template parameter list was empty.
73874912Sjhb    bool LastParameterListWasEmpty;
73974912Sjhb  };
74074912Sjhb
74174912Sjhb  void PushParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass);
74287593Sobrien  void DeallocateParsedClasses(ParsingClass *Class);
74393811Sjhb  void PopParsingClass();
744164159Skmacy
745181695Sattilio  DeclPtrTy ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D,
746181695Sattilio                                    const ParsedTemplateInfo &TemplateInfo);
747181695Sattilio  void ParseLexedMethodDeclarations(ParsingClass &Class);
748181695Sattilio  void ParseLexedMethodDefs(ParsingClass &Class);
749181695Sattilio  bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
750181695Sattilio                            CachedTokens &Toks,
751181695Sattilio                            tok::TokenKind EarlyAbortIf = tok::unknown,
752181695Sattilio                            bool ConsumeFinalToken = true);
753181695Sattilio
754181695Sattilio  //===--------------------------------------------------------------------===//
755181695Sattilio  // C99 6.9: External Definitions.
756181695Sattilio  DeclGroupPtrTy ParseExternalDeclaration();
757181695Sattilio  bool isDeclarationAfterDeclarator();
758181695Sattilio  bool isStartOfFunctionDefinition();
759181695Sattilio  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(
760181695Sattilio            AccessSpecifier AS = AS_none);
76174912Sjhb
76274912Sjhb  DeclPtrTy ParseFunctionDefinition(ParsingDeclarator &D,
763181695Sattilio                 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
76474912Sjhb  void ParseKNRParamDeclarations(Declarator &D);
76574912Sjhb  // EndLoc, if non-NULL, is filled with the location of the last token of
76674912Sjhb  // the simple-asm.
76774912Sjhb  OwningExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0);
76875569Sjhb  OwningExprResult ParseAsmStringLiteral();
76975569Sjhb
77074912Sjhb  // Objective-C External Declarations
77174912Sjhb  DeclPtrTy ParseObjCAtDirectives();
77274912Sjhb  DeclPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
77375569Sjhb  DeclPtrTy ParseObjCAtInterfaceDeclaration(SourceLocation atLoc,
77475569Sjhb                                          AttributeList *prefixAttrs = 0);
77574912Sjhb  void ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
776181695Sattilio                                       SourceLocation atLoc);
77774912Sjhb  bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &P,
77865557Sjasone                                   llvm::SmallVectorImpl<SourceLocation> &PLocs,
77965557Sjasone                                   bool WarnOnDeclarations,
780151629Sjhb                                   SourceLocation &LAngleLoc,
78165557Sjasone                                   SourceLocation &EndProtoLoc);
78274912Sjhb  void ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
783179025Sattilio                                  tok::ObjCKeywordKind contextKey);
784179025Sattilio  DeclPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
785153133Sjhb                                           AttributeList *prefixAttrs = 0);
786153133Sjhb
787153133Sjhb  DeclPtrTy ObjCImpDecl;
788179025Sattilio  llvm::SmallVector<DeclPtrTy, 4> PendingObjCImpDecl;
789179025Sattilio
79074912Sjhb  DeclPtrTy ParseObjCAtImplementationDeclaration(SourceLocation atLoc);
79174912Sjhb  DeclPtrTy ParseObjCAtEndDeclaration(SourceLocation atLoc);
79274912Sjhb  DeclPtrTy ParseObjCAtAliasDeclaration(SourceLocation atLoc);
793151629Sjhb  DeclPtrTy ParseObjCPropertySynthesize(SourceLocation atLoc);
79474912Sjhb  DeclPtrTy ParseObjCPropertyDynamic(SourceLocation atLoc);
79574912Sjhb
79665557Sjasone  IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
797177253Srwatson  // Definitions for Objective-c context sensitive keywords recognition.
798177253Srwatson  enum ObjCTypeQual {
79965557Sjasone    objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
80074912Sjhb    objc_NumQuals
801179025Sattilio  };
80274912Sjhb  IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
80374912Sjhb
80474912Sjhb  bool isTokIdentifier_in() const;
805153133Sjhb
806154077Sjhb  TypeTy *ParseObjCTypeName(ObjCDeclSpec &DS);
80774912Sjhb  void ParseObjCMethodRequirement();
80874912Sjhb  DeclPtrTy ParseObjCMethodPrototype(DeclPtrTy classOrCat,
80982284Sjhb            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
81074912Sjhb  DeclPtrTy ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
81174912Sjhb                                DeclPtrTy classDecl,
81274912Sjhb            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
81382284Sjhb  void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
81474912Sjhb
81582244Sjhb  DeclPtrTy ParseObjCMethodDefinition();
81682244Sjhb
81782284Sjhb  //===--------------------------------------------------------------------===//
81882244Sjhb  // C99 6.5: Expressions.
81982244Sjhb
820153133Sjhb  OwningExprResult ParseExpression();
821153133Sjhb  OwningExprResult ParseConstantExpression();
822153133Sjhb  // Expr that doesn't include commas.
823153133Sjhb  OwningExprResult ParseAssignmentExpression();
824153133Sjhb
825153133Sjhb  OwningExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
826153133Sjhb
827182446Sattilio  OwningExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
828153133Sjhb
829153133Sjhb  OwningExprResult ParseRHSOfBinaryExpression(OwningExprResult LHS,
830153133Sjhb                                              unsigned MinPrec);
831179025Sattilio  OwningExprResult ParseCastExpression(bool isUnaryExpression,
832179025Sattilio                                       bool isAddressOfOperand,
833179025Sattilio                                       bool &NotCastExpr,
834179025Sattilio                                       bool parseParenAsExprList);
835179025Sattilio  OwningExprResult ParseCastExpression(bool isUnaryExpression,
836153133Sjhb                                       bool isAddressOfOperand = false,
837179025Sattilio                                       bool parseParenAsExprList = false);
83874912Sjhb  OwningExprResult ParsePostfixExpressionSuffix(OwningExprResult LHS);
83974912Sjhb  OwningExprResult ParseSizeofAlignofExpression();
84074912Sjhb  OwningExprResult ParseBuiltinPrimaryExpression();
84174912Sjhb
84274912Sjhb  OwningExprResult ParseExprAfterTypeofSizeofAlignof(const Token &OpTok,
843154077Sjhb                                                     bool &isCastExpr,
84475362Sjhb                                                     TypeTy *&CastTy,
84574912Sjhb                                                     SourceRange &CastRange);
846154077Sjhb
847181695Sattilio  static const unsigned ExprListSize = 12;
84874912Sjhb  typedef llvm::SmallVector<ExprTy*, ExprListSize> ExprListTy;
84974912Sjhb  typedef llvm::SmallVector<SourceLocation, ExprListSize> CommaLocsTy;
850154077Sjhb
85174912Sjhb  /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
85276272Sjhb  bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs,
853181695Sattilio                           void (Action::*Completer)(Scope *S, void *Data,
854181695Sattilio                                                     ExprTy **Args,
855181695Sattilio                                                     unsigned NumArgs) = 0,
856112117Sjhb                           void *Data = 0);
857181695Sattilio
858181695Sattilio  /// ParenParseOption - Control what ParseParenExpression will parse.
859181695Sattilio  enum ParenParseOption {
860181695Sattilio    SimpleExpr,      // Only parse '(' expression ')'
861181695Sattilio    CompoundStmt,    // Also allow '(' compound-statement ')'
862181695Sattilio    CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
863181695Sattilio    CastExpr         // Also allow '(' type-name ')' <anything>
86474912Sjhb  };
86574912Sjhb  OwningExprResult ParseParenExpression(ParenParseOption &ExprType,
866112115Sjhb                                        bool stopIfCastExpr,
86771352Sjasone                                        bool parseAsExprList,
868181695Sattilio                                        TypeTy *&CastTy,
869149979Struckman                                        SourceLocation &RParenLoc);
870181695Sattilio
871149979Struckman  OwningExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
872149979Struckman                                                    TypeTy *&CastTy,
873149979Struckman                                                    SourceLocation LParenLoc,
874149979Struckman                                                    SourceLocation &RParenLoc);
875181695Sattilio
876181695Sattilio  OwningExprResult ParseCompoundLiteralExpression(TypeTy *Ty,
877149979Struckman                                                  SourceLocation LParenLoc,
878149979Struckman                                                  SourceLocation RParenLoc);
879181695Sattilio
880149979Struckman  OwningExprResult ParseStringLiteralExpression();
881149979Struckman
882181695Sattilio  //===--------------------------------------------------------------------===//
883181695Sattilio  // C++ Expressions
884181695Sattilio  OwningExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
885181695Sattilio
886181695Sattilio  bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
887149979Struckman                                      TypeTy *ObjectType,
888149979Struckman                                      bool EnteringContext);
889149979Struckman
890149979Struckman  //===--------------------------------------------------------------------===//
891181695Sattilio  // C++ 5.2p1: C++ Casts
892149979Struckman  OwningExprResult ParseCXXCasts();
893149979Struckman
894149979Struckman  //===--------------------------------------------------------------------===//
895181695Sattilio  // C++ 5.2p1: C++ Type Identification
896181695Sattilio  OwningExprResult ParseCXXTypeid();
897181695Sattilio
898181695Sattilio  //===--------------------------------------------------------------------===//
899181695Sattilio  // C++ 9.3.2: C++ 'this' pointer
900181695Sattilio  OwningExprResult ParseCXXThis();
901181695Sattilio
902181695Sattilio  //===--------------------------------------------------------------------===//
903181695Sattilio  // C++ 15: C++ Throw Expression
904181695Sattilio  OwningExprResult ParseThrowExpression();
905149979Struckman  // EndLoc is filled with the location of the last token of the specification.
906149979Struckman  bool ParseExceptionSpecification(SourceLocation &EndLoc,
907149979Struckman                                   llvm::SmallVector<TypeTy*, 2> &Exceptions,
908181695Sattilio                                   llvm::SmallVector<SourceRange, 2> &Ranges,
909181695Sattilio                                   bool &hasAnyExceptionSpec);
910149979Struckman
911181695Sattilio  //===--------------------------------------------------------------------===//
912149979Struckman  // C++ 2.13.5: C++ Boolean Literals
913181695Sattilio  OwningExprResult ParseCXXBoolLiteral();
914181695Sattilio
915181695Sattilio  //===--------------------------------------------------------------------===//
916181695Sattilio  // C++ 5.2.3: Explicit type conversion (functional notation)
917181695Sattilio  OwningExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
918181695Sattilio
919181695Sattilio  /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
920181695Sattilio  /// This should only be called when the current token is known to be part of
921181695Sattilio  /// simple-type-specifier.
922181695Sattilio  void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
923181695Sattilio
924181695Sattilio  bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
925181695Sattilio
926149979Struckman  //===--------------------------------------------------------------------===//
927181695Sattilio  // C++ 5.3.4 and 5.3.5: C++ new and delete
928181695Sattilio  bool ParseExpressionListOrTypeId(ExprListTy &Exprs, Declarator &D);
929181695Sattilio  void ParseDirectNewDeclarator(Declarator &D);
930181695Sattilio  OwningExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
931181695Sattilio  OwningExprResult ParseCXXDeleteExpression(bool UseGlobal,
932181695Sattilio                                            SourceLocation Start);
933181695Sattilio
934149979Struckman  //===--------------------------------------------------------------------===//
935149979Struckman  // C++ if/switch/while/for condition expression.
936149979Struckman  OwningExprResult ParseCXXCondition();
937149979Struckman
938181695Sattilio  //===--------------------------------------------------------------------===//
939181695Sattilio  // C++ types
94071352Sjasone
941112118Sjhb  //===--------------------------------------------------------------------===//
94271352Sjasone  // C99 6.7.8: Initialization.
94374912Sjhb
944181695Sattilio  /// ParseInitializer
94571352Sjasone  ///       initializer: [C99 6.7.8]
946181695Sattilio  ///         assignment-expression
947181695Sattilio  ///         '{' ...
948181695Sattilio  OwningExprResult ParseInitializer() {
94971352Sjasone    if (Tok.isNot(tok::l_brace))
95074912Sjhb      return ParseAssignmentExpression();
95172224Sjhb    return ParseBraceInitializer();
95274912Sjhb  }
953181695Sattilio  OwningExprResult ParseBraceInitializer();
954178841Sattilio  OwningExprResult ParseInitializerWithPotentialDesignator();
95574912Sjhb
95674912Sjhb  //===--------------------------------------------------------------------===//
957181695Sattilio  // clang Expressions
958181695Sattilio
95974912Sjhb  OwningExprResult ParseBlockLiteralExpression();  // ^{...}
960112118Sjhb
961181695Sattilio  //===--------------------------------------------------------------------===//
962112118Sjhb  // Objective-C Expressions
963112118Sjhb
96472224Sjhb  bool isTokObjCMessageIdentifierReceiver() const {
96574930Sjhb    if (!Tok.is(tok::identifier))
96674912Sjhb      return false;
96774912Sjhb
96874912Sjhb    IdentifierInfo *II = Tok.getIdentifierInfo();
969181695Sattilio    if (Actions.getTypeName(*II, Tok.getLocation(), CurScope))
97074912Sjhb      return true;
97174912Sjhb
97274930Sjhb    return II == Ident_super;
97372224Sjhb  }
97474912Sjhb
975181695Sattilio  OwningExprResult ParseObjCAtExpression(SourceLocation AtLocation);
97672224Sjhb  OwningExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
97772224Sjhb  OwningExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
97874930Sjhb  OwningExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
97972224Sjhb  OwningExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
98074912Sjhb  OwningExprResult ParseObjCMessageExpression();
98174912Sjhb  OwningExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
98297948Sjhb                                                  SourceLocation NameLoc,
98371352Sjasone                                                  IdentifierInfo *ReceiverName,
984181695Sattilio                                                  ExprArg ReceiverExpr);
985181695Sattilio  OwningExprResult ParseAssignmentExprWithObjCMessageExprStart(
98671352Sjasone      SourceLocation LBracloc, SourceLocation NameLoc,
98771352Sjasone      IdentifierInfo *ReceiverName, ExprArg ReceiverExpr);
988112115Sjhb
98971352Sjasone  //===--------------------------------------------------------------------===//
990112116Sjhb  // C99 6.8: Statements and Blocks.
991112116Sjhb
992112116Sjhb  OwningStmtResult ParseStatement() {
993112116Sjhb    return ParseStatementOrDeclaration(true);
994112116Sjhb  }
995112116Sjhb  OwningStmtResult ParseStatementOrDeclaration(bool OnlyStatement = false);
996112116Sjhb  OwningStmtResult ParseLabeledStatement();
997112116Sjhb  OwningStmtResult ParseCaseStatement();
998112116Sjhb  OwningStmtResult ParseDefaultStatement();
999112116Sjhb  OwningStmtResult ParseCompoundStatement(bool isStmtExpr = false);
1000112116Sjhb  OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
1001112116Sjhb  bool ParseParenExprOrCondition(OwningExprResult &CondExp,
1002125160Sjhb                                 bool OnlyAllowCondition = false,
1003125160Sjhb                                 SourceLocation *LParenLoc = 0,
1004125160Sjhb                                 SourceLocation *RParenLoc = 0);
1005125160Sjhb  OwningStmtResult ParseIfStatement();
1006182473Sattilio  OwningStmtResult ParseSwitchStatement();
1007125160Sjhb  OwningStmtResult ParseWhileStatement();
1008125160Sjhb  OwningStmtResult ParseDoStatement();
1009125160Sjhb  OwningStmtResult ParseForStatement();
1010125160Sjhb  OwningStmtResult ParseGotoStatement();
1011125160Sjhb  OwningStmtResult ParseContinueStatement();
1012125160Sjhb  OwningStmtResult ParseBreakStatement();
1013125160Sjhb  OwningStmtResult ParseReturnStatement();
1014181695Sattilio  OwningStmtResult ParseAsmStatement(bool &msAsm);
1015125160Sjhb  OwningStmtResult FuzzyParseMicrosoftAsmStatement();
1016125160Sjhb  bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
1017125160Sjhb                           llvm::SmallVectorImpl<ExprTy*> &Constraints,
1018125160Sjhb                           llvm::SmallVectorImpl<ExprTy*> &Exprs);
1019125160Sjhb
1020125160Sjhb  //===--------------------------------------------------------------------===//
1021182473Sattilio  // C++ 6: Statements and Blocks
1022182473Sattilio
1023125160Sjhb  OwningStmtResult ParseCXXTryBlock();
1024125160Sjhb  OwningStmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc);
1025125160Sjhb  OwningStmtResult ParseCXXCatchBlock();
1026125160Sjhb
1027125160Sjhb  //===--------------------------------------------------------------------===//
1028125160Sjhb  // Objective-C Statements
1029179025Sattilio
1030181695Sattilio  OwningStmtResult ParseObjCAtStatement(SourceLocation atLoc);
1031125160Sjhb  OwningStmtResult ParseObjCTryStmt(SourceLocation atLoc);
1032125160Sjhb  OwningStmtResult ParseObjCThrowStmt(SourceLocation atLoc);
1033125160Sjhb  OwningStmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1034125160Sjhb
103565557Sjasone
1036125160Sjhb  //===--------------------------------------------------------------------===//
1037182914Sjhb  // C99 6.7: Declarations.
103865557Sjasone
1039183955Sattilio  /// A context for parsing declaration specifiers.  TODO: flesh this
1040182914Sjhb  /// out, there are other significant restrictions on specifiers than
104174912Sjhb  /// would be best implemented in the parser.
104265856Sjhb  enum DeclSpecContext {
104383366Sjulian    DSC_normal, // normal context
104474912Sjhb    DSC_class   // class context, enables 'friend'
104565557Sjasone  };
1046182446Sattilio
104780747Sjhb  DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd);
104871320Sjasone  DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context,
1049125160Sjhb                                        SourceLocation &DeclEnd);
105074912Sjhb  DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context,
1051154077Sjhb                                bool AllowFunctionDefinitions,
105283366Sjulian                                SourceLocation *DeclEnd = 0);
1053112116Sjhb  DeclPtrTy ParseDeclarationAfterDeclarator(Declarator &D,
105465557Sjasone               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
105574912Sjhb  DeclPtrTy ParseFunctionStatementBody(DeclPtrTy Decl);
1056181695Sattilio  DeclPtrTy ParseFunctionTryBlock(DeclPtrTy Decl);
105793676Sjhb
105893676Sjhb  bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1059131884Sjhb                        const ParsedTemplateInfo &TemplateInfo,
106093676Sjhb                        AccessSpecifier AS);
106193676Sjhb  void ParseDeclarationSpecifiers(DeclSpec &DS,
1062136304Sgreen                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
106374912Sjhb                                  AccessSpecifier AS = AS_none,
106474912Sjhb                                  DeclSpecContext DSC = DSC_normal);
1065131884Sjhb  bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid,
1066131884Sjhb                                  const char *&PrevSpec,
1067131884Sjhb                                  unsigned &DiagID,
1068131884Sjhb               const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1069131884Sjhb
1070183955Sattilio  void ParseSpecifierQualifierList(DeclSpec &DS);
1071183955Sattilio
1072131884Sjhb  void ParseObjCTypeQualifierList(ObjCDeclSpec &DS);
1073131884Sjhb
1074181695Sattilio  void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1075131884Sjhb                          AccessSpecifier AS = AS_none);
1076131884Sjhb  void ParseEnumBody(SourceLocation StartLoc, DeclPtrTy TagDecl);
1077183955Sattilio  void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
1078183955Sattilio                            DeclPtrTy TagDecl);
1079183955Sattilio
1080183955Sattilio  struct FieldCallback {
1081183955Sattilio    virtual DeclPtrTy invoke(FieldDeclarator &Field) = 0;
1082131884Sjhb    virtual ~FieldCallback() {}
1083183955Sattilio
1084183955Sattilio  private:
1085183955Sattilio    virtual void _anchor();
1086183955Sattilio  };
1087131884Sjhb
1088183955Sattilio  void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback);
1089183955Sattilio
1090131884Sjhb  bool isDeclarationSpecifier();
109165557Sjasone  bool isTypeSpecifierQualifier();
109276772Sjhb  bool isTypeQualifier() const;
1093125160Sjhb
1094125160Sjhb  /// isDeclarationStatement - Disambiguates between a declaration or an
1095125160Sjhb  /// expression statement, when parsing function bodies.
109676272Sjhb  /// Returns true for declaration, false for expression.
1097183955Sattilio  bool isDeclarationStatement() {
109876272Sjhb    if (getLang().CPlusPlus)
109976272Sjhb      return isCXXDeclarationStatement();
110076272Sjhb    return isDeclarationSpecifier();
110176272Sjhb  }
110276272Sjhb
110376272Sjhb  /// isSimpleDeclaration - Disambiguates between a declaration or an
110476272Sjhb  /// expression, mainly used for the C 'clause-1' or the C++
110576272Sjhb  // 'for-init-statement' part of a 'for' statement.
110676272Sjhb  /// Returns true for declaration, false for expression.
110776272Sjhb  bool isSimpleDeclaration() {
110876272Sjhb    if (getLang().CPlusPlus)
110976272Sjhb      return isCXXSimpleDeclaration();
111076272Sjhb    return isDeclarationSpecifier();
111176272Sjhb  }
111276272Sjhb
111376272Sjhb  /// \brief Specifies the context in which type-id/expression
111476272Sjhb  /// disambiguation will occur.
111576272Sjhb  enum TentativeCXXTypeIdContext {
111676272Sjhb    TypeIdInParens,
111776272Sjhb    TypeIdAsTemplateArgument
111876272Sjhb  };
1119182914Sjhb
1120182914Sjhb
1121183955Sattilio  /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
1122182914Sjhb  /// whether the parens contain an expression or a type-id.
1123183955Sattilio  /// Returns true for a type-id and false for an expression.
1124183955Sattilio  bool isTypeIdInParens(bool &isAmbiguous) {
1125183955Sattilio    if (getLang().CPlusPlus)
1126183955Sattilio      return isCXXTypeId(TypeIdInParens, isAmbiguous);
1127183955Sattilio    isAmbiguous = false;
1128182984Sattilio    return isTypeSpecifierQualifier();
1129182914Sjhb  }
1130182914Sjhb  bool isTypeIdInParens() {
1131183955Sattilio    bool isAmbiguous;
1132182914Sjhb    return isTypeIdInParens(isAmbiguous);
1133183955Sattilio  }
1134183955Sattilio
1135183955Sattilio  /// isCXXDeclarationStatement - C++-specialized function that disambiguates
1136182914Sjhb  /// between a declaration or an expression statement, when parsing function
1137182914Sjhb  /// bodies. Returns true for declaration, false for expression.
1138182914Sjhb  bool isCXXDeclarationStatement();
1139182914Sjhb
1140181695Sattilio  /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
1141181695Sattilio  /// between a simple-declaration or an expression-statement.
1142181695Sattilio  /// If during the disambiguation process a parsing error is encountered,
1143182914Sjhb  /// the function returns true to let the declaration parsing code handle it.
1144181695Sattilio  /// Returns false if the statement is disambiguated as expression.
1145181695Sattilio  bool isCXXSimpleDeclaration();
1146181695Sattilio
1147181695Sattilio  /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
114874912Sjhb  /// a constructor-style initializer, when parsing declaration statements.
114974912Sjhb  /// Returns true for function declarator and false for constructor-style
115074912Sjhb  /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to
115174912Sjhb  /// indicate that the parens were disambiguated as function declarator.
1152181695Sattilio  /// If during the disambiguation process a parsing error is encountered,
1153181695Sattilio  /// the function returns true to let the declaration parsing code handle it.
115474912Sjhb  bool isCXXFunctionDeclarator(bool warnIfAmbiguous);
1155181695Sattilio
1156181695Sattilio  /// isCXXConditionDeclaration - Disambiguates between a declaration or an
1157181695Sattilio  /// expression for a condition of a if/switch/while/for statement.
1158181695Sattilio  /// If during the disambiguation process a parsing error is encountered,
1159181695Sattilio  /// the function returns true to let the declaration parsing code handle it.
1160181695Sattilio  bool isCXXConditionDeclaration();
1161183574Sjhb
1162183574Sjhb  bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous);
1163181695Sattilio  bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
1164183574Sjhb    bool isAmbiguous;
1165183574Sjhb    return isCXXTypeId(Context, isAmbiguous);
1166181695Sattilio  }
1167181695Sattilio
1168181695Sattilio  /// TPResult - Used as the result value for functions whose purpose is to
1169181695Sattilio  /// disambiguate C++ constructs by "tentatively parsing" them.
1170125160Sjhb  /// This is a class instead of a simple enum because the implicit enum-to-bool
117165557Sjasone  /// conversions may cause subtle bugs.
1172181695Sattilio  class TPResult {
1173181695Sattilio    enum Result {
117465557Sjasone      TPR_true,
1175111881Sjhb      TPR_false,
1176111881Sjhb      TPR_ambiguous,
1177111881Sjhb      TPR_error
1178111881Sjhb    };
1179181695Sattilio    Result Res;
1180181695Sattilio    TPResult(Result result) : Res(result) {}
1181181695Sattilio  public:
1182183955Sattilio    static TPResult True() { return TPR_true; }
118374912Sjhb    static TPResult False() { return TPR_false; }
118465557Sjasone    static TPResult Ambiguous() { return TPR_ambiguous; }
118574912Sjhb    static TPResult Error() { return TPR_error; }
118676272Sjhb
118774912Sjhb    bool operator==(const TPResult &RHS) const { return Res == RHS.Res; }
118874912Sjhb    bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; }
1189182914Sjhb  };
1190182914Sjhb
1191182914Sjhb  /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a
1192182914Sjhb  /// declaration specifier, TPResult::False() if it is not,
1193182914Sjhb  /// TPResult::Ambiguous() if it could be either a decl-specifier or a
1194182914Sjhb  /// function-style cast, and TPResult::Error() if a parsing error was
1195182914Sjhb  /// encountered.
1196182914Sjhb  /// Doesn't consume tokens.
119774912Sjhb  TPResult isCXXDeclarationSpecifier();
119874912Sjhb
119974912Sjhb  // "Tentative parsing" functions, used for disambiguation. If a parsing error
1200182914Sjhb  // is encountered they will return TPResult::Error().
120174912Sjhb  // Returning TPResult::True()/False() indicates that the ambiguity was
120276272Sjhb  // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates
120374912Sjhb  // that more tentative parsing is necessary for disambiguation.
120474912Sjhb  // They all consume tokens, so backtracking should be used after calling them.
120574912Sjhb
1206181695Sattilio  TPResult TryParseDeclarationSpecifier();
120776272Sjhb  TPResult TryParseSimpleDeclaration();
1208111881Sjhb  TPResult TryParseTypeofSpecifier();
120976272Sjhb  TPResult TryParseInitDeclaratorList();
121076272Sjhb  TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true);
1211111881Sjhb  TPResult TryParseParameterDeclarationClause();
1212167787Sjhb  TPResult TryParseFunctionDeclarator();
121376272Sjhb  TPResult TryParseBracketDeclarator();
1214181695Sattilio
121593690Sjhb  TypeResult ParseTypeName(SourceRange *Range = 0);
121693690Sjhb  void ParseBlockId();
1217111881Sjhb  // EndLoc, if non-NULL, is filled with the location of the last token of
121893690Sjhb  // the attribute list.
1219111881Sjhb  AttributeList *ParseAttributes(SourceLocation *EndLoc = 0);
1220167787Sjhb  AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0);
1221111881Sjhb  AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0);
1222181695Sattilio  void ParseTypeofSpecifier(DeclSpec &DS);
1223111881Sjhb  void ParseDecltypeSpecifier(DeclSpec &DS);
1224111881Sjhb
1225111881Sjhb  /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
1226111881Sjhb  /// enter a new C++ declarator scope and exit it when the function is
1227111881Sjhb  /// finished.
1228111881Sjhb  class DeclaratorScopeObj {
1229149738Sjhb    Parser &P;
1230111881Sjhb    CXXScopeSpec &SS;
1231149738Sjhb    bool EnteredScope;
1232181695Sattilio    bool CreatedScope;
1233149738Sjhb  public:
1234150179Sjhb    DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
1235150179Sjhb      : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
1236150179Sjhb
1237150179Sjhb    void EnterDeclaratorScope() {
1238167787Sjhb      assert(!EnteredScope && "Already entered the scope!");
1239150179Sjhb      assert(SS.isSet() && "C++ scope was not set!");
1240181695Sattilio
1241150179Sjhb      CreatedScope = true;
1242149738Sjhb      P.EnterScope(0); // Not a decl scope.
1243149738Sjhb
1244149738Sjhb      if (P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS))
124574912Sjhb        SS.setScopeRep(0);
1246149738Sjhb
1247181695Sattilio      if (!SS.isInvalid())
124874912Sjhb        EnteredScope = true;
124974912Sjhb    }
125074912Sjhb
125174912Sjhb    ~DeclaratorScopeObj() {
1252105508Sphk      if (EnteredScope) {
1253181695Sattilio        assert(SS.isSet() && "C++ scope was cleared ?");
1254125160Sjhb        P.Actions.ActOnCXXExitDeclaratorScope(P.CurScope, SS);
1255125160Sjhb      }
1256125160Sjhb      if (CreatedScope)
1257125160Sjhb        P.ExitScope();
1258125160Sjhb    }
125965557Sjasone  };
1260181695Sattilio
1261105508Sphk  /// ParseDeclarator - Parse and verify a newly-initialized declarator.
1262181695Sattilio  void ParseDeclarator(Declarator &D);
1263181695Sattilio  /// A function that parses a variant of direct-declarator.
1264181695Sattilio  typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
1265181695Sattilio  void ParseDeclaratorInternal(Declarator &D,
1266181695Sattilio                               DirectDeclParseFunction DirectDeclParser);
1267181695Sattilio  void ParseTypeQualifierListOpt(DeclSpec &DS, bool AttributesAllowed = true);
1268181695Sattilio  void ParseDirectDeclarator(Declarator &D);
1269181695Sattilio  void ParseParenDeclarator(Declarator &D);
1270181695Sattilio  void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
1271181695Sattilio                               AttributeList *AttrList = 0,
1272181695Sattilio                               bool RequiresArg = false);
1273181695Sattilio  void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
127474912Sjhb                                             Declarator &D);
127574912Sjhb  void ParseBracketDeclarator(Declarator &D);
127674912Sjhb
1277150179Sjhb  //===--------------------------------------------------------------------===//
1278150179Sjhb  // C++ 7: Declarations [dcl.dcl]
1279150179Sjhb
1280150179Sjhb  DeclPtrTy ParseNamespace(unsigned Context, SourceLocation &DeclEnd);
1281150179Sjhb  DeclPtrTy ParseLinkage(unsigned Context);
1282167787Sjhb  DeclPtrTy ParseUsingDirectiveOrDeclaration(unsigned Context,
1283150179Sjhb                                             SourceLocation &DeclEnd);
1284150179Sjhb  DeclPtrTy ParseUsingDirective(unsigned Context, SourceLocation UsingLoc,
1285150179Sjhb                                SourceLocation &DeclEnd);
1286150179Sjhb  DeclPtrTy ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc,
1287181695Sattilio                                  SourceLocation &DeclEnd,
128874912Sjhb                                  AccessSpecifier AS = AS_none);
128974912Sjhb  DeclPtrTy ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
129074912Sjhb  DeclPtrTy ParseNamespaceAlias(SourceLocation NamespaceLoc,
129174912Sjhb                                SourceLocation AliasLoc, IdentifierInfo *Alias,
129274912Sjhb                                SourceLocation &DeclEnd);
129376272Sjhb
129476272Sjhb  //===--------------------------------------------------------------------===//
129576272Sjhb  // C++ 9: classes [class] and C structs/unions.
129674912Sjhb  TypeResult ParseClassName(SourceLocation &EndLocation,
129774912Sjhb                            const CXXScopeSpec *SS = 0,
129874912Sjhb                            bool DestrExpected = false);
129974912Sjhb  void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
1300106781Sjhb                           DeclSpec &DS,
1301125160Sjhb                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1302125160Sjhb                           AccessSpecifier AS = AS_none);
130374912Sjhb  void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType,
130476272Sjhb                                   DeclPtrTy TagDecl);
130593811Sjhb  void ParseCXXClassMemberDeclaration(AccessSpecifier AS,
130693811Sjhb                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1307179025Sattilio  void ParseConstructorInitializer(DeclPtrTy ConstructorDecl);
130893811Sjhb  MemInitResult ParseMemInitializer(DeclPtrTy ConstructorDecl);
1309179025Sattilio  void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
131076272Sjhb                                       DeclPtrTy ThisDecl);
131193811Sjhb
131293811Sjhb  //===--------------------------------------------------------------------===//
1313179025Sattilio  // C++ 10: Derived classes [class.derived]
1314179025Sattilio  void ParseBaseClause(DeclPtrTy ClassDecl);
131593811Sjhb  BaseResult ParseBaseSpecifier(DeclPtrTy ClassDecl);
131693811Sjhb  AccessSpecifier getAccessSpecifierIfPresent() const;
1317179025Sattilio
131893811Sjhb  bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
1319179025Sattilio                                    IdentifierInfo *Name,
132076272Sjhb                                    SourceLocation NameLoc,
1321181695Sattilio                                    bool EnteringContext,
1322125160Sjhb                                    TypeTy *ObjectType,
132365557Sjasone                                    UnqualifiedId &Id);
132465557Sjasone  bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
1325181695Sattilio                                  TypeTy *ObjectType,
132678871Sjhb                                  UnqualifiedId &Result);
1327125160Sjhb  bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
1328125160Sjhb                          bool AllowDestructorName,
1329125160Sjhb                          bool AllowConstructorName,
1330125160Sjhb                          TypeTy *ObjectType,
133178871Sjhb                          UnqualifiedId &Result);
1332125160Sjhb
1333182914Sjhb  //===--------------------------------------------------------------------===//
1334112117Sjhb  // C++ 14: Templates [temp]
133587593Sobrien  typedef llvm::SmallVector<DeclPtrTy, 4> TemplateParameterList;
1336182914Sjhb
1337182914Sjhb  // C++ 14.1: Template Parameters [temp.param]
1338181695Sattilio  DeclPtrTy ParseDeclarationStartingWithTemplate(unsigned Context,
1339181695Sattilio                                                 SourceLocation &DeclEnd,
1340112117Sjhb                                                 AccessSpecifier AS = AS_none);
1341125160Sjhb  DeclPtrTy ParseTemplateDeclarationOrSpecialization(unsigned Context,
1342125160Sjhb                                                     SourceLocation &DeclEnd,
1343125160Sjhb                                                     AccessSpecifier AS);
1344125160Sjhb  DeclPtrTy ParseSingleDeclarationAfterTemplate(
1345125160Sjhb                                       unsigned Context,
1346125160Sjhb                                       const ParsedTemplateInfo &TemplateInfo,
1347125160Sjhb                                       SourceLocation &DeclEnd,
1348125160Sjhb                                       AccessSpecifier AS=AS_none);
1349125160Sjhb  bool ParseTemplateParameters(unsigned Depth,
1350125160Sjhb                               TemplateParameterList &TemplateParams,
1351182446Sattilio                               SourceLocation &LAngleLoc,
1352125160Sjhb                               SourceLocation &RAngleLoc);
1353125160Sjhb  bool ParseTemplateParameterList(unsigned Depth,
1354125160Sjhb                                  TemplateParameterList &TemplateParams);
1355125160Sjhb  DeclPtrTy ParseTemplateParameter(unsigned Depth, unsigned Position);
1356125160Sjhb  DeclPtrTy ParseTypeParameter(unsigned Depth, unsigned Position);
1357125160Sjhb  DeclPtrTy ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
1358125160Sjhb  DeclPtrTy ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
1359154077Sjhb  // C++ 14.3: Template arguments [temp.arg]
1360125160Sjhb  typedef llvm::SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
1361125160Sjhb
1362125160Sjhb  bool ParseTemplateIdAfterTemplateName(TemplateTy Template,
1363125160Sjhb                                        SourceLocation TemplateNameLoc,
1364125160Sjhb                                        const CXXScopeSpec *SS,
1365125160Sjhb                                        bool ConsumeLastToken,
1366125160Sjhb                                        SourceLocation &LAngleLoc,
1367125160Sjhb                                        TemplateArgList &TemplateArgs,
1368125160Sjhb                                        SourceLocation &RAngleLoc);
1369125160Sjhb
1370125160Sjhb  bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
1371125160Sjhb                               const CXXScopeSpec *SS,
1372125160Sjhb                               UnqualifiedId &TemplateName,
1373125160Sjhb                               SourceLocation TemplateKWLoc = SourceLocation(),
1374110779Speter                               bool AllowTypeAnnotation = true);
1375125160Sjhb  void AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS = 0);
1376125160Sjhb  bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
137765557Sjasone  ParsedTemplateArgument ParseTemplateTemplateArgument();
137865557Sjasone  ParsedTemplateArgument ParseTemplateArgument();
1379125160Sjhb  DeclPtrTy ParseExplicitInstantiation(SourceLocation ExternLoc,
1380125160Sjhb                                       SourceLocation TemplateLoc,
138174912Sjhb                                       SourceLocation &DeclEnd);
138276272Sjhb
138378785Sjhb  //===--------------------------------------------------------------------===//
138478785Sjhb  // GNU G++: Type Traits [Type-Traits.html in the GCC manual]
138565557Sjasone  OwningExprResult ParseUnaryTypeTrait();
138678785Sjhb};
138787593Sobrien
138884680Sjhb}  // end namespace clang
138978785Sjhb
139065557Sjasone#endif
1391125160Sjhb