zcov: / include/clang/Parse/Parser.h


Files: 1 Branches Taken: 74.2% 92 / 124
Generated: 2010-02-10 01:31 Branches Executed: 94.4% 117 / 124
Line Coverage: 97.8% 269 / 275


Programs: 24 Runs 36216


       1                 : //===--- Parser.h - C Language Parser ---------------------------*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : //  This file defines the Parser interface.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #ifndef LLVM_CLANG_PARSE_PARSER_H
      15                 : #define LLVM_CLANG_PARSE_PARSER_H
      16                 : 
      17                 : #include "clang/Basic/Specifiers.h"
      18                 : #include "clang/Lex/Preprocessor.h"
      19                 : #include "clang/Parse/Action.h"
      20                 : #include "clang/Parse/DeclSpec.h"
      21                 : #include "llvm/ADT/OwningPtr.h"
      22                 : #include <stack>
      23                 : #include <list>
      24                 : 
      25                 : namespace clang {
      26                 :   class AttributeList;
      27                 :   struct CXX0XAttributeList;
      28                 :   class PragmaHandler;
      29                 :   class Scope;
      30                 :   class DiagnosticBuilder;
      31                 :   class Parser;
      32                 :   class PragmaUnusedHandler;
      33                 :   class ColonProtectionRAIIObject;
      34                 : 
      35                 : /// PrettyStackTraceParserEntry - If a crash happens while the parser is active,
      36                 : /// an entry is printed for it.
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                     2251: branch 6 taken
      37             2251: class PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry {
      38                 :   const Parser &P;
      39                 : public:
      40             2251:   PrettyStackTraceParserEntry(const Parser &p) : P(p) {}
      41                 :   virtual void print(llvm::raw_ostream &OS) const;
      42                 : };
      43                 : 
      44                 : 
      45                 : /// Parser - This implements a parser for the C family of languages.  After
      46                 : /// parsing units of the grammar, productions are invoked to handle whatever has
      47                 : /// been read.
      48                 : ///
      49                 : class Parser {
      50                 :   friend class PragmaUnusedHandler;
      51                 :   friend class ColonProtectionRAIIObject;
      52                 :   PrettyStackTraceParserEntry CrashInfo;
      53                 : 
      54                 :   Preprocessor &PP;
      55                 : 
      56                 :   /// Tok - The current token we are peeking ahead.  All parsing methods assume
      57                 :   /// that this is valid.
      58                 :   Token Tok;
      59                 : 
      60                 :   // PrevTokLocation - The location of the token we previously
      61                 :   // consumed. This token is used for diagnostics where we expected to
      62                 :   // see a token following another token (e.g., the ';' at the end of
      63                 :   // a statement).
      64                 :   SourceLocation PrevTokLocation;
      65                 : 
      66                 :   unsigned short ParenCount, BracketCount, BraceCount;
      67                 : 
      68                 :   /// Actions - These are the callbacks we invoke as we parse various constructs
      69                 :   /// in the file.  This refers to the common base class between MinimalActions
      70                 :   /// and SemaActions for those uses that don't matter.
      71                 :   Action &Actions;
      72                 : 
      73                 :   Scope *CurScope;
      74                 :   Diagnostic &Diags;
      75                 : 
      76                 :   /// ScopeCache - Cache scopes to reduce malloc traffic.
      77                 :   enum { ScopeCacheSize = 16 };
      78                 :   unsigned NumCachedScopes;
      79                 :   Scope *ScopeCache[ScopeCacheSize];
      80                 : 
      81                 :   /// Ident_super - IdentifierInfo for "super", to support fast
      82                 :   /// comparison.
      83                 :   IdentifierInfo *Ident_super;
      84                 :   /// Ident_vector and Ident_pixel - cached IdentifierInfo's for
      85                 :   /// "vector" and "pixel" fast comparison.  Only present if
      86                 :   /// AltiVec enabled.
      87                 :   IdentifierInfo *Ident_vector;
      88                 :   IdentifierInfo *Ident_pixel;
      89                 : 
      90                 :   llvm::OwningPtr<PragmaHandler> PackHandler;
      91                 :   llvm::OwningPtr<PragmaHandler> UnusedHandler;
      92                 :   llvm::OwningPtr<PragmaHandler> WeakHandler;
      93                 :   llvm::OwningPtr<clang::CommentHandler> CommentHandler;
      94                 : 
      95                 :   /// Whether the '>' token acts as an operator or not. This will be
      96                 :   /// true except when we are parsing an expression within a C++
      97                 :   /// template argument list, where the '>' closes the template
      98                 :   /// argument list.
      99                 :   bool GreaterThanIsOperator;
     100                 :   
     101                 :   /// ColonIsSacred - When this is false, we aggressively try to recover from
     102                 :   /// code like "foo : bar" as if it were a typo for "foo :: bar".  This is not
     103                 :   /// safe in case statements and a few other things.  This is managed by the
     104                 :   /// ColonProtectionRAIIObject RAII object.
     105                 :   bool ColonIsSacred;
     106                 : 
     107                 :   /// The "depth" of the template parameters currently being parsed.
     108                 :   unsigned TemplateParameterDepth;
     109                 : 
     110                 : public:
     111                 :   Parser(Preprocessor &PP, Action &Actions);
     112                 :   ~Parser();
     113                 : 
     114           861691:   const LangOptions &getLang() const { return PP.getLangOptions(); }
     115                 :   const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
     116                0:   Preprocessor &getPreprocessor() const { return PP; }
     117                2:   Action &getActions() const { return Actions; }
     118                 : 
     119                0:   const Token &getCurToken() const { return Tok; }
     120                 : 
     121                 :   // Type forwarding.  All of these are statically 'void*', but they may all be
     122                 :   // different actual classes based on the actions in place.
     123                 :   typedef Action::ExprTy ExprTy;
     124                 :   typedef Action::StmtTy StmtTy;
     125                 :   typedef Action::DeclPtrTy DeclPtrTy;
     126                 :   typedef Action::DeclGroupPtrTy DeclGroupPtrTy;
     127                 :   typedef Action::TypeTy TypeTy;
     128                 :   typedef Action::BaseTy BaseTy;
     129                 :   typedef Action::MemInitTy MemInitTy;
     130                 :   typedef Action::CXXScopeTy CXXScopeTy;
     131                 :   typedef Action::TemplateParamsTy TemplateParamsTy;
     132                 :   typedef Action::TemplateTy TemplateTy;
     133                 : 
     134                 :   typedef llvm::SmallVector<TemplateParamsTy *, 4> TemplateParameterLists;
     135                 : 
     136                 :   typedef Action::ExprResult        ExprResult;
     137                 :   typedef Action::StmtResult        StmtResult;
     138                 :   typedef Action::BaseResult        BaseResult;
     139                 :   typedef Action::MemInitResult     MemInitResult;
     140                 :   typedef Action::TypeResult        TypeResult;
     141                 : 
     142                 :   typedef Action::OwningExprResult OwningExprResult;
     143                 :   typedef Action::OwningStmtResult OwningStmtResult;
     144                 : 
     145                 :   typedef Action::ExprArg ExprArg;
     146                 :   typedef Action::MultiStmtArg MultiStmtArg;
     147                 :   typedef Action::FullExprArg FullExprArg;
     148                 : 
     149                 :   /// Adorns a ExprResult with Actions to make it an OwningExprResult
     150             1995:   OwningExprResult Owned(ExprResult res) {
     151             1995:     return OwningExprResult(Actions, res);
     152                 :   }
     153                 :   /// Adorns a StmtResult with Actions to make it an OwningStmtResult
     154                 :   OwningStmtResult Owned(StmtResult res) {
     155                 :     return OwningStmtResult(Actions, res);
     156                 :   }
     157                 : 
     158              250:   OwningExprResult ExprError() { return OwningExprResult(Actions, true); }
     159              823:   OwningStmtResult StmtError() { return OwningStmtResult(Actions, true); }
     160                 : 
     161                5:   OwningExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); }
     162                2:   OwningStmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); }
     163                 : 
     164              443:   OwningExprResult ExprEmpty() { return OwningExprResult(Actions, false); }
     165                 : 
     166                 :   // Parsing methods.
     167                 : 
     168                 :   /// ParseTranslationUnit - All in one method that initializes parses, and
     169                 :   /// shuts down the parser.
     170                 :   void ParseTranslationUnit();
     171                 : 
     172                 :   /// Initialize - Warm up the parser.
     173                 :   ///
     174                 :   void Initialize();
     175                 : 
     176                 :   /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
     177                 :   /// the EOF was encountered.
     178                 :   bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
     179                 : 
     180                 :   DeclGroupPtrTy RetrievePendingObjCImpDecl();
     181                 : 
     182                 : private:
     183                 :   //===--------------------------------------------------------------------===//
     184                 :   // Low-Level token peeking and consumption methods.
     185                 :   //
     186                 : 
     187                 :   /// isTokenParen - Return true if the cur token is '(' or ')'.
     188           594379:   bool isTokenParen() const {
                   529622: branch 1 taken
                    64757: branch 2 taken
                    76052: branch 4 taken
                   453570: branch 5 taken
     189           594379:     return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren;
     190                 :   }
     191                 :   /// isTokenBracket - Return true if the cur token is '[' or ']'.
     192           464090:   bool isTokenBracket() const {
                   458822: branch 1 taken
                     5268: branch 2 taken
                     8817: branch 4 taken
                   450005: branch 5 taken
     193           464090:     return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square;
     194                 :   }
     195                 :   /// isTokenBrace - Return true if the cur token is '{' or '}'.
     196           488950:   bool isTokenBrace() const {
                   469281: branch 1 taken
                    19669: branch 2 taken
                    27155: branch 4 taken
                   442126: branch 5 taken
     197           488950:     return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace;
     198                 :   }
     199                 : 
     200                 :   /// isTokenStringLiteral - True if this token is a string-literal.
     201                 :   ///
     202           448648:   bool isTokenStringLiteral() const {
     203                 :     return Tok.getKind() == tok::string_literal ||
                   444058: branch 1 taken
                     4590: branch 2 taken
                       63: branch 4 taken
                   443995: branch 5 taken
     204           448648:            Tok.getKind() == tok::wide_string_literal;
     205                 :   }
     206                 : 
     207                 :   /// ConsumeToken - Consume the current 'peek token' and lex the next one.
     208                 :   /// This does not work with all kinds of tokens: strings and specific other
     209                 :   /// tokens must be consumed with custom methods below.  This returns the
     210                 :   /// location of the consumed token.
     211           403413:   SourceLocation ConsumeToken() {
     212                 :     assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() &&
     213                 :            !isTokenBrace() &&
                   403413: branch 1 taken
                        0: branch 2 not taken
                   403413: branch 4 taken
                        0: branch 5 not taken
                   403413: branch 7 taken
                        0: branch 8 not taken
                   403413: branch 10 taken
                        0: branch 11 not taken
     214           403413:            "Should consume special tokens with Consume*Token");
     215           403413:     PrevTokLocation = Tok.getLocation();
     216           403413:     PP.Lex(Tok);
     217           403413:     return PrevTokLocation;
     218                 :   }
     219                 : 
     220                 :   /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
     221                 :   /// current token type.  This should only be used in cases where the type of
     222                 :   /// the token really isn't known, e.g. in error recovery.
     223            81887:   SourceLocation ConsumeAnyToken() {
                    31730: branch 1 taken
                    50157: branch 2 taken
     224            81887:     if (isTokenParen())
     225            31730:       return ConsumeParen();
                     3565: branch 1 taken
                    46592: branch 2 taken
     226            50157:     else if (isTokenBracket())
     227             3565:       return ConsumeBracket();
                     7879: branch 1 taken
                    38713: branch 2 taken
     228            46592:     else if (isTokenBrace())
     229             7879:       return ConsumeBrace();
                        0: branch 1 not taken
                    38713: branch 2 taken
     230            38713:     else if (isTokenStringLiteral())
     231                0:       return ConsumeStringToken();
     232                 :     else
     233            38713:       return ConsumeToken();
     234                 :   }
     235                 : 
     236                 :   /// ConsumeParen - This consume method keeps the paren count up-to-date.
     237                 :   ///
     238           109079:   SourceLocation ConsumeParen() {
                   109079: branch 1 taken
                        0: branch 2 not taken
     239           109079:     assert(isTokenParen() && "wrong consume method");
                    56982: branch 1 taken
                    52097: branch 2 taken
     240           109079:     if (Tok.getKind() == tok::l_paren)
     241            56982:       ++ParenCount;
                    52088: branch 0 taken
                        9: branch 1 taken
     242            52097:     else if (ParenCount)
     243            52088:       --ParenCount;       // Don't let unbalanced )'s drive the count negative.
     244           109079:     PrevTokLocation = Tok.getLocation();
     245           109079:     PP.Lex(Tok);
     246           109079:     return PrevTokLocation;
     247                 :   }
     248                 : 
     249                 :   /// ConsumeBracket - This consume method keeps the bracket count up-to-date.
     250                 :   ///
     251            10520:   SourceLocation ConsumeBracket() {
                    10520: branch 1 taken
                        0: branch 2 not taken
     252            10520:     assert(isTokenBracket() && "wrong consume method");
                     5266: branch 1 taken
                     5254: branch 2 taken
     253            10520:     if (Tok.getKind() == tok::l_square)
     254             5266:       ++BracketCount;
                     5253: branch 0 taken
                        1: branch 1 taken
     255             5254:     else if (BracketCount)
     256             5253:       --BracketCount;     // Don't let unbalanced ]'s drive the count negative.
     257                 : 
     258            10520:     PrevTokLocation = Tok.getLocation();
     259            10520:     PP.Lex(Tok);
     260            10520:     return PrevTokLocation;
     261                 :   }
     262                 : 
     263                 :   /// ConsumeBrace - This consume method keeps the brace count up-to-date.
     264                 :   ///
     265            38945:   SourceLocation ConsumeBrace() {
                    38945: branch 1 taken
                        0: branch 2 not taken
     266            38945:     assert(isTokenBrace() && "wrong consume method");
                    19506: branch 1 taken
                    19439: branch 2 taken
     267            38945:     if (Tok.getKind() == tok::l_brace)
     268            19506:       ++BraceCount;
                    19437: branch 0 taken
                        2: branch 1 taken
     269            19439:     else if (BraceCount)
     270            19437:       --BraceCount;     // Don't let unbalanced }'s drive the count negative.
     271                 : 
     272            38945:     PrevTokLocation = Tok.getLocation();
     273            38945:     PP.Lex(Tok);
     274            38945:     return PrevTokLocation;
     275                 :   }
     276                 : 
     277                 :   /// ConsumeStringToken - Consume the current 'peek token', lexing a new one
     278                 :   /// and returning the token kind.  This method is specific to strings, as it
     279                 :   /// handles string literal concatenation, as per C99 5.1.1.2, translation
     280                 :   /// phase #6.
     281             2322:   SourceLocation ConsumeStringToken() {
     282                 :     assert(isTokenStringLiteral() &&
                     2322: branch 1 taken
                        0: branch 2 not taken
     283             2322:            "Should only consume string literals with this method");
     284             2322:     PrevTokLocation = Tok.getLocation();
     285             2322:     PP.Lex(Tok);
     286             2322:     return PrevTokLocation;
     287                 :   }
     288                 : 
     289                 :   /// GetLookAheadToken - This peeks ahead N tokens and returns that token
     290                 :   /// without consuming any tokens.  LookAhead(0) returns 'Tok', LookAhead(1)
     291                 :   /// returns the token after Tok, etc.
     292                 :   ///
     293                 :   /// Note that this differs from the Preprocessor's LookAhead method, because
     294                 :   /// the Parser always has one token lexed that the preprocessor doesn't.
     295                 :   ///
     296             2763:   const Token &GetLookAheadToken(unsigned N) {
                     2763: branch 0 taken
                        0: branch 1 not taken
                        0: branch 3 not taken
                     2763: branch 4 taken
                        0: branch 5 not taken
                     2763: branch 6 taken
     297             2763:     if (N == 0 || Tok.is(tok::eof)) return Tok;
     298             2763:     return PP.LookAhead(N-1);
     299                 :   }
     300                 : 
     301                 :   /// NextToken - This peeks ahead one token and returns it without
     302                 :   /// consuming it.
     303           110347:   const Token &NextToken() {
     304           110347:     return PP.LookAhead(0);
     305                 :   }
     306                 : 
     307                 :   /// TryAnnotateTypeOrScopeToken - If the current token position is on a
     308                 :   /// typename (possibly qualified in C++) or a C++ scope specifier not followed
     309                 :   /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens
     310                 :   /// with a single annotation token representing the typename or C++ scope
     311                 :   /// respectively.
     312                 :   /// This simplifies handling of C++ scope specifiers and allows efficient
     313                 :   /// backtracking without the need to re-parse and resolve nested-names and
     314                 :   /// typenames.
     315                 :   /// It will mainly be called when we expect to treat identifiers as typenames
     316                 :   /// (if they are typenames). For example, in C we do not expect identifiers
     317                 :   /// inside expressions to be treated as typenames so it will not be called
     318                 :   /// for expressions in C.
     319                 :   ///
     320                 :   /// This returns true if the token was annotated.
     321                 :   bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false);
     322                 : 
     323                 :   /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
     324                 :   /// annotates C++ scope specifiers.  This returns true if the token was
     325                 :   /// annotated.
     326                 :   bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
     327                 : 
     328                 :   /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens,
     329                 :   /// replacing them with the non-context-sensitive keywords.  This returns
     330                 :   /// true if the token was replaced.
     331                 :   bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
     332             9307:       const char *&PrevSpec, unsigned &DiagID, bool &isInvalid) {
                       77: branch 1 taken
                     9230: branch 2 taken
     333             9307:     if (getLang().AltiVec) {
                       60: branch 1 taken
                       17: branch 2 taken
     334               77:       if (Tok.getIdentifierInfo() == Ident_vector) {
     335               60:         const Token nextToken = NextToken();
                       58: branch 1 taken
                        2: branch 2 taken
                        0: branch 3 not taken
     336               60:         switch (nextToken.getKind()) {
     337                 :           case tok::kw_short:
     338                 :           case tok::kw_long:
     339                 :           case tok::kw_signed:
     340                 :           case tok::kw_unsigned:
     341                 :           case tok::kw_void:
     342                 :           case tok::kw_char:
     343                 :           case tok::kw_int:
     344                 :           case tok::kw_float:
     345                 :           case tok::kw_double:
     346                 :           case tok::kw_bool:
     347                 :           case tok::kw___pixel:
     348               58:             isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID);
     349               58:             return true;
     350                 :           case tok::identifier:
                        2: branch 1 taken
                        0: branch 2 not taken
     351                2:             if (nextToken.getIdentifierInfo() == Ident_pixel) {
     352                2:               isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID);
     353                2:               return true;
     354                 :             }
     355                 :             break;
     356                 :           default:
     357                 :             break;
     358                 :         }
                        4: branch 1 taken
                       13: branch 2 taken
                        4: branch 4 taken
                        0: branch 5 not taken
                        4: branch 6 taken
                       13: branch 7 taken
     359               17:       } else if ((Tok.getIdentifierInfo() == Ident_pixel) &&
     360                 :           DS.isTypeAltiVecVector()) {
     361                4:         isInvalid = DS.SetTypeAltiVecPixel(true, Loc, PrevSpec, DiagID);
     362                4:         return true;
     363                 :       }
     364                 :     }
     365             9243:     return false;
     366                 :   }
     367                 : 
     368                 :   /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector
     369                 :   /// identifier token, replacing it with the non-context-sensitive __vector.
     370                 :   /// This returns true if the token was replaced.
     371            18870:   bool TryAltiVecVectorToken() {
                       41: branch 1 taken
                    18829: branch 2 taken
     372            18870:     if (getLang().AltiVec) {
                        6: branch 1 taken
                       35: branch 2 taken
     373               41:       if (Tok.getIdentifierInfo() == Ident_vector) {
     374                6:         const Token nextToken = NextToken();
                        6: branch 1 taken
                        0: branch 2 not taken
                        0: branch 3 not taken
     375                6:         switch (nextToken.getKind()) {
     376                 :           case tok::kw_short:
     377                 :           case tok::kw_long:
     378                 :           case tok::kw_signed:
     379                 :           case tok::kw_unsigned:
     380                 :           case tok::kw_void:
     381                 :           case tok::kw_char:
     382                 :           case tok::kw_int:
     383                 :           case tok::kw_float:
     384                 :           case tok::kw_double:
     385                 :           case tok::kw_bool:
     386                 :           case tok::kw___pixel:
     387                6:             Tok.setKind(tok::kw___vector);
     388                6:             return true;
     389                 :           case tok::identifier:
                        0: branch 1 not taken
                        0: branch 2 not taken
     390                0:             if (nextToken.getIdentifierInfo() == Ident_pixel) {
     391                0:               Tok.setKind(tok::kw___vector);
     392                0:               return true;
     393                 :             }
     394                 :             break;
     395                 :           default:
     396                 :             break;
     397                 :         }
     398                 :       }
     399                 :     }
     400            18864:     return false;
     401                 :   }
     402                 : 
     403                 :   /// TentativeParsingAction - An object that is used as a kind of "tentative
     404                 :   /// parsing transaction". It gets instantiated to mark the token position and
     405                 :   /// after the token consumption is done, Commit() or Revert() is called to
     406                 :   /// either "commit the consumed tokens" or revert to the previously marked
     407                 :   /// token position. Example:
     408                 :   ///
     409                 :   ///   TentativeParsingAction TPA(*this);
     410                 :   ///   ConsumeToken();
     411                 :   ///   ....
     412                 :   ///   TPA.Revert();
     413                 :   ///
     414                 :   class TentativeParsingAction {
     415                 :     Parser &P;
     416                 :     Token PrevTok;
     417                 :     bool isActive;
     418                 : 
     419                 :   public:
     420             5985:     explicit TentativeParsingAction(Parser& p) : P(p) {
     421             5985:       PrevTok = P.Tok;
     422             5985:       P.PP.EnableBacktrackAtThisPos();
     423             5985:       isActive = true;
     424             5985:     }
     425               83:     void Commit() {
                        0: branch 0 not taken
                       83: branch 1 taken
     426               83:       assert(isActive && "Parsing action was finished!");
     427               83:       P.PP.CommitBacktrackedTokens();
     428               83:       isActive = false;
     429               83:     }
     430             5902:     void Revert() {
                        0: branch 0 not taken
                     5902: branch 1 taken
     431             5902:       assert(isActive && "Parsing action was finished!");
     432             5902:       P.PP.Backtrack();
     433             5902:       P.Tok = PrevTok;
     434             5902:       isActive = false;
     435             5902:     }
     436             5985:     ~TentativeParsingAction() {
                        0: branch 0 not taken
                     5985: branch 1 taken
     437             5985:       assert(!isActive && "Forgot to call Commit or Revert!");
     438             5985:     }
     439                 :   };
     440                 : 
     441                 : 
     442                 :   /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'),
     443                 :   /// this helper function matches and consumes the specified RHS token if
     444                 :   /// present.  If not present, it emits the specified diagnostic indicating
     445                 :   /// that the parser failed to match the RHS of the token at LHSLoc.  LHSName
     446                 :   /// should be the name of the unmatched LHS token.  This returns the location
     447                 :   /// of the consumed token.
     448                 :   SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok,
     449                 :                                      SourceLocation LHSLoc);
     450                 : 
     451                 :   /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
     452                 :   /// input.  If so, it is consumed and false is returned.
     453                 :   ///
     454                 :   /// If the input is malformed, this emits the specified diagnostic.  Next, if
     455                 :   /// SkipToTok is specified, it calls SkipUntil(SkipToTok).  Finally, true is
     456                 :   /// returned.
     457                 :   bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag,
     458                 :                         const char *DiagMsg = "",
     459                 :                         tok::TokenKind SkipToTok = tok::unknown);
     460                 : 
     461                 :   //===--------------------------------------------------------------------===//
     462                 :   // Scope manipulation
     463                 : 
     464                 :   /// ParseScope - Introduces a new scope for parsing. The kind of
     465                 :   /// scope is determined by ScopeFlags. Objects of this type should
     466                 :   /// be created on the stack to coincide with the position where the
     467                 :   /// parser enters the new scope, and this object's constructor will
     468                 :   /// create that new scope. Similarly, once the object is destroyed
     469                 :   /// the parser will exit the scope.
     470                 :   class ParseScope {
     471                 :     Parser *Self;
     472                 :     ParseScope(const ParseScope&); // do not implement
     473                 :     ParseScope& operator=(const ParseScope&); // do not implement
     474                 : 
     475                 :   public:
     476                 :     // ParseScope - Construct a new object to manage a scope in the
     477                 :     // parser Self where the new Scope is created with the flags
     478                 :     // ScopeFlags, but only when ManageScope is true (the default). If
     479                 :     // ManageScope is false, this object does nothing.
     480            47420:     ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true)
     481            47420:       : Self(Self) {
                    32595: branch 0 taken
                    14825: branch 1 taken
     482            47420:       if (ManageScope)
     483            32595:         Self->EnterScope(ScopeFlags);
     484                 :       else
     485            14825:         this->Self = 0;
     486            47420:     }
     487                 : 
     488                 :     // Exit - Exit the scope associated with this object now, rather
     489                 :     // than waiting until the object is destroyed.
     490            68176:     void Exit() {
                    32595: branch 0 taken
                    35581: branch 1 taken
     491            68176:       if (Self) {
     492            32595:         Self->ExitScope();
     493            32595:         Self = 0;
     494                 :       }
     495            68176:     }
     496                 : 
     497            47420:     ~ParseScope() {
     498            47420:       Exit();
     499            47420:     }
     500                 :   };
     501                 : 
     502                 :   /// EnterScope - Start a new scope.
     503                 :   void EnterScope(unsigned ScopeFlags);
     504                 : 
     505                 :   /// ExitScope - Pop a scope off the scope stack.
     506                 :   void ExitScope();
     507                 : 
     508                 :   //===--------------------------------------------------------------------===//
     509                 :   // Diagnostic Emission and Error recovery.
     510                 : 
     511                 :   DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
     512                 :   DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
     513                 : 
     514                 :   void SuggestParentheses(SourceLocation Loc, unsigned DK,
     515                 :                           SourceRange ParenRange);
     516                 : 
     517                 :   /// SkipUntil - Read tokens until we get to the specified token, then consume
     518                 :   /// it (unless DontConsume is true).  Because we cannot guarantee that the
     519                 :   /// token will ever occur, this skips to the next token, or to some likely
     520                 :   /// good stopping point.  If StopAtSemi is true, skipping will stop at a ';'
     521                 :   /// character.
     522                 :   ///
     523                 :   /// If SkipUntil finds the specified token, it returns true, otherwise it
     524                 :   /// returns false.
     525                 :   bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
     526             1748:                  bool DontConsume = false) {
     527             1748:     return SkipUntil(&T, 1, StopAtSemi, DontConsume);
     528                 :   }
     529                 :   bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
     530               21:                  bool DontConsume = false) {
     531               21:     tok::TokenKind TokArray[] = {T1, T2};
     532               21:     return SkipUntil(TokArray, 2, StopAtSemi, DontConsume);
     533                 :   }
     534                 :   bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
     535                 :                  bool StopAtSemi = true, bool DontConsume = false);
     536                 : 
     537                 :   //===--------------------------------------------------------------------===//
     538                 :   // Lexing and parsing of C++ inline methods.
     539                 : 
     540             3153:   struct LexedMethod {
     541                 :     Action::DeclPtrTy D;
     542                 :     CachedTokens Toks;
     543                 : 
     544                 :     /// \brief Whether this member function had an associated template
     545                 :     /// scope. When true, D is a template declaration.
     546                 :     /// othewise, it is a member function declaration.
     547                 :     bool TemplateScope;
     548                 : 
     549             1051:     explicit LexedMethod(Action::DeclPtrTy MD) : D(MD), TemplateScope(false) {}
     550                 :   };
     551                 : 
     552                 :   /// LateParsedDefaultArgument - Keeps track of a parameter that may
     553                 :   /// have a default argument that cannot be parsed yet because it
     554                 :   /// occurs within a member function declaration inside the class
     555                 :   /// (C++ [class.mem]p2).
     556              107:   struct LateParsedDefaultArgument {
     557                 :     explicit LateParsedDefaultArgument(Action::DeclPtrTy P,
     558              107:                                        CachedTokens *Toks = 0)
     559              107:       : Param(P), Toks(Toks) { }
     560                 : 
     561                 :     /// Param - The parameter declaration for this parameter.
     562                 :     Action::DeclPtrTy Param;
     563                 : 
     564                 :     /// Toks - The sequence of tokens that comprises the default
     565                 :     /// argument expression, not including the '=' or the terminating
     566                 :     /// ')' or ','. This will be NULL for parameters that have no
     567                 :     /// default argument.
     568                 :     CachedTokens *Toks;
     569                 :   };
     570                 : 
     571                 :   /// LateParsedMethodDeclaration - A method declaration inside a class that
     572                 :   /// contains at least one entity whose parsing needs to be delayed
     573                 :   /// until the class itself is completely-defined, such as a default
     574                 :   /// argument (C++ [class.mem]p2).
     575              204:   struct LateParsedMethodDeclaration {
     576               68:     explicit LateParsedMethodDeclaration(Action::DeclPtrTy M)
     577               68:       : Method(M), TemplateScope(false) { }
     578                 : 
     579                 :     /// Method - The method declaration.
     580                 :     Action::DeclPtrTy Method;
     581                 : 
     582                 :     /// \brief Whether this member function had an associated template
     583                 :     /// scope. When true, D is a template declaration.
     584                 :     /// othewise, it is a member function declaration.
     585                 :     bool TemplateScope;
     586                 : 
     587                 :     /// DefaultArgs - Contains the parameters of the function and
     588                 :     /// their default arguments. At least one of the parameters will
     589                 :     /// have a default argument, but all of the parameters of the
     590                 :     /// method will be stored so that they can be reintroduced into
     591                 :     /// scope at the appropriate times.
     592                 :     llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
     593                 :   };
     594                 : 
     595                 :   /// LateParsedMethodDecls - During parsing of a top (non-nested) C++
     596                 :   /// class, its method declarations that contain parts that won't be
     597                 :   /// parsed until after the definiton is completed (C++ [class.mem]p2),
     598                 :   /// the method declarations will be stored here with the tokens that
     599                 :   /// will be parsed to create those entities.
     600                 :   typedef std::list<LateParsedMethodDeclaration> LateParsedMethodDecls;
     601                 : 
     602                 :   /// LexedMethodsForTopClass - During parsing of a top (non-nested) C++ class,
     603                 :   /// its inline method definitions and the inline method definitions of its
     604                 :   /// nested classes are lexed and stored here.
     605                 :   typedef std::list<LexedMethod> LexedMethodsForTopClass;
     606                 : 
     607                 :   /// \brief Representation of a class that has been parsed, including
     608                 :   /// any member function declarations or definitions that need to be
     609                 :   /// parsed after the corresponding top-level class is complete.
     610             3403:   struct ParsingClass {
     611             3403:     ParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass)
     612                 :       : TopLevelClass(TopLevelClass), TemplateScope(false),
     613             3403:         TagOrTemplate(TagOrTemplate) { }
     614                 : 
     615                 :     /// \brief Whether this is a "top-level" class, meaning that it is
     616                 :     /// not nested within another class.
     617                 :     bool TopLevelClass : 1;
     618                 : 
     619                 :     /// \brief Whether this class had an associated template
     620                 :     /// scope. When true, TagOrTemplate is a template declaration;
     621                 :     /// othewise, it is a tag declaration.
     622                 :     bool TemplateScope : 1;
     623                 : 
     624                 :     /// \brief The class or class template whose definition we are parsing.
     625                 :     DeclPtrTy TagOrTemplate;
     626                 : 
     627                 :     /// MethodDecls - Method declarations that contain pieces whose
     628                 :     /// parsing will be delayed until the class is fully defined.
     629                 :     LateParsedMethodDecls MethodDecls;
     630                 : 
     631                 :     /// MethodDefs - Methods whose definitions will be parsed once the
     632                 :     /// class has been fully defined.
     633                 :     LexedMethodsForTopClass MethodDefs;
     634                 : 
     635                 :     /// \brief Nested classes inside this class.
     636                 :     llvm::SmallVector<ParsingClass*, 4> NestedClasses;
     637                 :   };
     638                 : 
     639                 :   /// \brief The stack of classes that is currently being
     640                 :   /// parsed. Nested and local classes will be pushed onto this stack
     641                 :   /// when they are parsed, and removed afterward.
     642                 :   std::stack<ParsingClass *> ClassStack;
     643                 : 
     644             9640:   ParsingClass &getCurrentClass() {
                     9640: branch 1 taken
                        0: branch 2 not taken
     645             9640:     assert(!ClassStack.empty() && "No lexed method stacks!");
     646             9640:     return *ClassStack.top();
     647                 :   }
     648                 : 
     649                 :   /// \brief RAII object used to inform the actions that we're
     650                 :   /// currently parsing a declaration.  This is active when parsing a
     651                 :   /// variable's initializer, but not when parsing the body of a
     652                 :   /// class or function definition.
     653                 :   class ParsingDeclRAIIObject {
     654                 :     Action &Actions;
     655                 :     Action::ParsingDeclStackState State;
     656                 :     bool Popped;
     657                 :     
     658                 :   public:
     659            74592:     ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) {
     660            74592:       push();
     661            74592:     }
     662                 : 
     663            74592:     ~ParsingDeclRAIIObject() {
     664            74592:       abort();
     665            74592:     }
     666                 : 
     667                 :     /// Resets the RAII object for a new declaration.
     668              429:     void reset() {
     669              429:       abort();
     670              429:       push();
     671              429:     }
     672                 : 
     673                 :     /// Signals that the context was completed without an appropriate
     674                 :     /// declaration being parsed.
     675            82292:     void abort() {
     676            82292:       pop(DeclPtrTy());
     677            82292:     }
     678                 : 
     679            42103:     void complete(DeclPtrTy D) {
                    42103: branch 1 taken
                        0: branch 1 not taken
     680            42103:       assert(!Popped && "ParsingDeclaration has already been popped!");
     681            42103:       pop(D);
     682            42103:     }
     683                 : 
     684                 :   private:
     685            75021:     void push() {
     686            75021:       State = Actions.PushParsingDeclaration();
     687            75021:       Popped = false;
     688            75021:     }
     689                 : 
     690           124395:     void pop(DeclPtrTy D) {
                    75021: branch 0 taken
                    49374: branch 1 taken
     691           124395:       if (!Popped) {
     692            75021:         Actions.PopParsingDeclaration(State, D);
     693            75021:         Popped = true;
     694                 :       }
     695           124395:     }
     696                 :   };
     697                 : 
     698                 :   /// A class for parsing a DeclSpec.
     699            36265:   class ParsingDeclSpec : public DeclSpec {
     700                 :     ParsingDeclRAIIObject ParsingRAII;
     701                 : 
     702                 :   public:
     703            36265:     ParsingDeclSpec(Parser &P) : ParsingRAII(P) {
     704            36265:     }
     705                 : 
     706             4780:     void complete(DeclPtrTy D) {
     707             4780:       ParsingRAII.complete(D);
     708             4780:     }
     709                 : 
     710             7271:     void abort() {
     711             7271:       ParsingRAII.abort();
     712             7271:     }
     713                 :   };
     714                 : 
     715                 :   /// A class for parsing a declarator.
     716            31461:   class ParsingDeclarator : public Declarator {
     717                 :     ParsingDeclRAIIObject ParsingRAII;
     718                 : 
     719                 :   public:
     720            31461:     ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C)
     721            31461:       : Declarator(DS, C), ParsingRAII(P) {
     722            31461:     }
     723                 : 
     724             8952:     const ParsingDeclSpec &getDeclSpec() const {
     725             8952:       return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec());
     726                 :     }
     727                 : 
     728             7211:     ParsingDeclSpec &getMutableDeclSpec() const {
     729             7211:       return const_cast<ParsingDeclSpec&>(getDeclSpec());
     730                 :     }
     731                 : 
     732              429:     void clear() {
     733              429:       Declarator::clear();
     734              429:       ParsingRAII.reset();
     735              429:     }
     736                 : 
     737            30459:     void complete(DeclPtrTy D) {
     738            30459:       ParsingRAII.complete(D);
     739            30459:     }
     740                 :   };
     741                 : 
     742                 :   /// \brief RAII object used to
     743                 :   class ParsingClassDefinition {
     744                 :     Parser &P;
     745                 :     bool Popped;
     746                 : 
     747                 :   public:
     748             3403:     ParsingClassDefinition(Parser &P, DeclPtrTy TagOrTemplate, bool TopLevelClass)
     749             3403:       : P(P), Popped(false) {
     750             3403:       P.PushParsingClass(TagOrTemplate, TopLevelClass);
     751             3403:     }
     752                 : 
     753                 :     /// \brief Pop this class of the stack.
     754             3394:     void Pop() {
                        0: branch 0 not taken
                     3394: branch 1 taken
     755             3394:       assert(!Popped && "Nested class has already been popped");
     756             3394:       Popped = true;
     757             3394:       P.PopParsingClass();
     758             3394:     }
     759                 : 
     760             3403:     ~ParsingClassDefinition() {
                        9: branch 0 taken
                     3394: branch 1 taken
     761             3403:       if (!Popped)
     762                9:         P.PopParsingClass();
     763             3403:     }
     764                 :   };
     765                 : 
     766                 :   /// \brief Contains information about any template-specific
     767                 :   /// information that has been parsed prior to parsing declaration
     768                 :   /// specifiers.
     769                 :   struct ParsedTemplateInfo {
     770            93663:     ParsedTemplateInfo()
     771            93663:       : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { }
     772                 : 
     773                 :     ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
     774                 :                        bool isSpecialization,
     775             1830:                        bool lastParameterListWasEmpty = false)
     776                 :       : Kind(isSpecialization? ExplicitSpecialization : Template),
     777                 :         TemplateParams(TemplateParams), 
                      206: branch 0 taken
                     1624: branch 1 taken
     778             1830:         LastParameterListWasEmpty(lastParameterListWasEmpty) { }
     779                 : 
     780                 :     explicit ParsedTemplateInfo(SourceLocation ExternLoc,
     781              377:                                 SourceLocation TemplateLoc)
     782                 :       : Kind(ExplicitInstantiation), TemplateParams(0),
     783                 :         ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
     784              377:         LastParameterListWasEmpty(false){ }
     785                 : 
     786                 :     /// \brief The kind of template we are parsing.
     787                 :     enum {
     788                 :       /// \brief We are not parsing a template at all.
     789                 :       NonTemplate = 0,
     790                 :       /// \brief We are parsing a template declaration.
     791                 :       Template,
     792                 :       /// \brief We are parsing an explicit specialization.
     793                 :       ExplicitSpecialization,
     794                 :       /// \brief We are parsing an explicit instantiation.
     795                 :       ExplicitInstantiation
     796                 :     } Kind;
     797                 : 
     798                 :     /// \brief The template parameter lists, for template declarations
     799                 :     /// and explicit specializations.
     800                 :     TemplateParameterLists *TemplateParams;
     801                 : 
     802                 :     /// \brief The location of the 'extern' keyword, if any, for an explicit
     803                 :     /// instantiation
     804                 :     SourceLocation ExternLoc;
     805                 : 
     806                 :     /// \brief The location of the 'template' keyword, for an explicit
     807                 :     /// instantiation.
     808                 :     SourceLocation TemplateLoc;
     809                 :     
     810                 :     /// \brief Whether the last template parameter list was empty.
     811                 :     bool LastParameterListWasEmpty;
     812                 :   };
     813                 : 
     814                 :   void PushParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass);
     815                 :   void DeallocateParsedClasses(ParsingClass *Class);
     816                 :   void PopParsingClass();
     817                 : 
     818                 :   DeclPtrTy ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D,
     819                 :                                     const ParsedTemplateInfo &TemplateInfo);
     820                 :   void ParseLexedMethodDeclarations(ParsingClass &Class);
     821                 :   void ParseLexedMethodDefs(ParsingClass &Class);
     822                 :   bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
     823                 :                             CachedTokens &Toks,
     824                 :                             tok::TokenKind EarlyAbortIf = tok::unknown,
     825                 :                             bool ConsumeFinalToken = true);
     826                 : 
     827                 :   //===--------------------------------------------------------------------===//
     828                 :   // C99 6.9: External Definitions.
     829                 :   DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr);
     830                 :   bool isDeclarationAfterDeclarator();
     831                 :   bool isStartOfFunctionDefinition();
     832                 :   DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr,
     833                 :             AccessSpecifier AS = AS_none);
     834                 :   DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS,
     835                 :                                                   AttributeList *Attr,
     836                 :                                                   AccessSpecifier AS = AS_none);
     837                 :   
     838                 :   DeclPtrTy ParseFunctionDefinition(ParsingDeclarator &D,
     839                 :                  const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
     840                 :   void ParseKNRParamDeclarations(Declarator &D);
     841                 :   // EndLoc, if non-NULL, is filled with the location of the last token of
     842                 :   // the simple-asm.
     843                 :   OwningExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0);
     844                 :   OwningExprResult ParseAsmStringLiteral();
     845                 : 
     846                 :   // Objective-C External Declarations
     847                 :   DeclPtrTy ParseObjCAtDirectives();
     848                 :   DeclPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
     849                 :   DeclPtrTy ParseObjCAtInterfaceDeclaration(SourceLocation atLoc,
     850                 :                                           AttributeList *prefixAttrs = 0);
     851                 :   void ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
     852                 :                                        SourceLocation atLoc);
     853                 :   bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &P,
     854                 :                                    llvm::SmallVectorImpl<SourceLocation> &PLocs,
     855                 :                                    bool WarnOnDeclarations,
     856                 :                                    SourceLocation &LAngleLoc,
     857                 :                                    SourceLocation &EndProtoLoc);
     858                 :   void ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
     859                 :                                   tok::ObjCKeywordKind contextKey);
     860                 :   DeclPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
     861                 :                                            AttributeList *prefixAttrs = 0);
     862                 : 
     863                 :   DeclPtrTy ObjCImpDecl;
     864                 :   llvm::SmallVector<DeclPtrTy, 4> PendingObjCImpDecl;
     865                 : 
     866                 :   DeclPtrTy ParseObjCAtImplementationDeclaration(SourceLocation atLoc);
     867                 :   DeclPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd);
     868                 :   DeclPtrTy ParseObjCAtAliasDeclaration(SourceLocation atLoc);
     869                 :   DeclPtrTy ParseObjCPropertySynthesize(SourceLocation atLoc);
     870                 :   DeclPtrTy ParseObjCPropertyDynamic(SourceLocation atLoc);
     871                 : 
     872                 :   IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
     873                 :   // Definitions for Objective-c context sensitive keywords recognition.
     874                 :   enum ObjCTypeQual {
     875                 :     objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
     876                 :     objc_NumQuals
     877                 :   };
     878                 :   IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
     879                 : 
     880                 :   bool isTokIdentifier_in() const;
     881                 : 
     882                 :   TypeTy *ParseObjCTypeName(ObjCDeclSpec &DS);
     883                 :   void ParseObjCMethodRequirement();
     884                 :   DeclPtrTy ParseObjCMethodPrototype(DeclPtrTy classOrCat,
     885                 :             tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
     886                 :   DeclPtrTy ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
     887                 :                                 DeclPtrTy classDecl,
     888                 :             tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
     889                 :   void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, DeclPtrTy ClassDecl,
     890                 :                                   DeclPtrTy *Methods, unsigned NumMethods);
     891                 : 
     892                 :   DeclPtrTy ParseObjCMethodDefinition();
     893                 : 
     894                 :   //===--------------------------------------------------------------------===//
     895                 :   // C99 6.5: Expressions.
     896                 : 
     897                 :   OwningExprResult ParseExpression();
     898                 :   OwningExprResult ParseConstantExpression();
     899                 :   // Expr that doesn't include commas.
     900                 :   OwningExprResult ParseAssignmentExpression();
     901                 : 
     902                 :   OwningExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
     903                 : 
     904                 :   OwningExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
     905                 : 
     906                 :   OwningExprResult ParseRHSOfBinaryExpression(OwningExprResult LHS,
     907                 :                                               unsigned MinPrec);
     908                 :   OwningExprResult ParseCastExpression(bool isUnaryExpression,
     909                 :                                        bool isAddressOfOperand,
     910                 :                                        bool &NotCastExpr,
     911                 :                                        TypeTy *TypeOfCast);
     912                 :   OwningExprResult ParseCastExpression(bool isUnaryExpression,
     913                 :                                        bool isAddressOfOperand = false,
     914                 :                                        TypeTy *TypeOfCast = 0);
     915                 :   OwningExprResult ParsePostfixExpressionSuffix(OwningExprResult LHS);
     916                 :   OwningExprResult ParseSizeofAlignofExpression();
     917                 :   OwningExprResult ParseBuiltinPrimaryExpression();
     918                 : 
     919                 :   OwningExprResult ParseExprAfterTypeofSizeofAlignof(const Token &OpTok,
     920                 :                                                      bool &isCastExpr,
     921                 :                                                      TypeTy *&CastTy,
     922                 :                                                      SourceRange &CastRange);
     923                 : 
     924                 :   static const unsigned ExprListSize = 12;
     925                 :   typedef llvm::SmallVector<ExprTy*, ExprListSize> ExprListTy;
     926                 :   typedef llvm::SmallVector<SourceLocation, ExprListSize> CommaLocsTy;
     927                 : 
     928                 :   /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
     929                 :   bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs,
     930                 :                            void (Action::*Completer)(Scope *S, void *Data,
     931                 :                                                      ExprTy **Args,
     932                 :                                                      unsigned NumArgs) = 0,
     933                 :                            void *Data = 0);
     934                 : 
     935                 :   /// ParenParseOption - Control what ParseParenExpression will parse.
     936                 :   enum ParenParseOption {
     937                 :     SimpleExpr,      // Only parse '(' expression ')'
     938                 :     CompoundStmt,    // Also allow '(' compound-statement ')'
     939                 :     CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
     940                 :     CastExpr         // Also allow '(' type-name ')' <anything>
     941                 :   };
     942                 :   OwningExprResult ParseParenExpression(ParenParseOption &ExprType,
     943                 :                                         bool stopIfCastExpr,
     944                 :                                         TypeTy *TypeOfCast,
     945                 :                                         TypeTy *&CastTy,
     946                 :                                         SourceLocation &RParenLoc);
     947                 : 
     948                 :   OwningExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
     949                 :                                                     TypeTy *&CastTy,
     950                 :                                                     SourceLocation LParenLoc,
     951                 :                                                     SourceLocation &RParenLoc);
     952                 : 
     953                 :   OwningExprResult ParseCompoundLiteralExpression(TypeTy *Ty,
     954                 :                                                   SourceLocation LParenLoc,
     955                 :                                                   SourceLocation RParenLoc);
     956                 : 
     957                 :   OwningExprResult ParseStringLiteralExpression();
     958                 : 
     959                 :   //===--------------------------------------------------------------------===//
     960                 :   // C++ Expressions
     961                 :   OwningExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
     962                 : 
     963                 :   bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
     964                 :                                       TypeTy *ObjectType,
     965                 :                                       bool EnteringContext);
     966                 : 
     967                 :   //===--------------------------------------------------------------------===//
     968                 :   // C++ 5.2p1: C++ Casts
     969                 :   OwningExprResult ParseCXXCasts();
     970                 : 
     971                 :   //===--------------------------------------------------------------------===//
     972                 :   // C++ 5.2p1: C++ Type Identification
     973                 :   OwningExprResult ParseCXXTypeid();
     974                 : 
     975                 :   //===--------------------------------------------------------------------===//
     976                 :   // C++ 9.3.2: C++ 'this' pointer
     977                 :   OwningExprResult ParseCXXThis();
     978                 : 
     979                 :   //===--------------------------------------------------------------------===//
     980                 :   // C++ 15: C++ Throw Expression
     981                 :   OwningExprResult ParseThrowExpression();
     982                 :   // EndLoc is filled with the location of the last token of the specification.
     983                 :   bool ParseExceptionSpecification(SourceLocation &EndLoc,
     984                 :                                    llvm::SmallVector<TypeTy*, 2> &Exceptions,
     985                 :                                    llvm::SmallVector<SourceRange, 2> &Ranges,
     986                 :                                    bool &hasAnyExceptionSpec);
     987                 : 
     988                 :   //===--------------------------------------------------------------------===//
     989                 :   // C++ 2.13.5: C++ Boolean Literals
     990                 :   OwningExprResult ParseCXXBoolLiteral();
     991                 : 
     992                 :   //===--------------------------------------------------------------------===//
     993                 :   // C++ 5.2.3: Explicit type conversion (functional notation)
     994                 :   OwningExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
     995                 : 
     996                 :   /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
     997                 :   /// This should only be called when the current token is known to be part of
     998                 :   /// simple-type-specifier.
     999                 :   void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
    1000                 : 
    1001                 :   bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
    1002                 : 
    1003                 :   //===--------------------------------------------------------------------===//
    1004                 :   // C++ 5.3.4 and 5.3.5: C++ new and delete
    1005                 :   bool ParseExpressionListOrTypeId(ExprListTy &Exprs, Declarator &D);
    1006                 :   void ParseDirectNewDeclarator(Declarator &D);
    1007                 :   OwningExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
    1008                 :   OwningExprResult ParseCXXDeleteExpression(bool UseGlobal,
    1009                 :                                             SourceLocation Start);
    1010                 : 
    1011                 :   //===--------------------------------------------------------------------===//
    1012                 :   // C++ if/switch/while condition expression.
    1013                 :   bool ParseCXXCondition(OwningExprResult &ExprResult, DeclPtrTy &DeclResult);
    1014                 : 
    1015                 :   //===--------------------------------------------------------------------===//
    1016                 :   // C++ types
    1017                 : 
    1018                 :   //===--------------------------------------------------------------------===//
    1019                 :   // C99 6.7.8: Initialization.
    1020                 : 
    1021                 :   /// ParseInitializer
    1022                 :   ///       initializer: [C99 6.7.8]
    1023                 :   ///         assignment-expression
    1024                 :   ///         '{' ...
    1025             8282:   OwningExprResult ParseInitializer() {
                     7367: branch 1 taken
                      915: branch 2 taken
    1026             8282:     if (Tok.isNot(tok::l_brace))
    1027             7367:       return ParseAssignmentExpression();
    1028              915:     return ParseBraceInitializer();
    1029                 :   }
    1030                 :   OwningExprResult ParseBraceInitializer();
    1031                 :   OwningExprResult ParseInitializerWithPotentialDesignator();
    1032                 : 
    1033                 :   //===--------------------------------------------------------------------===//
    1034                 :   // clang Expressions
    1035                 : 
    1036                 :   OwningExprResult ParseBlockLiteralExpression();  // ^{...}
    1037                 : 
    1038                 :   //===--------------------------------------------------------------------===//
    1039                 :   // Objective-C Expressions
    1040                 : 
    1041             1704:   bool isTokObjCMessageIdentifierReceiver() const {
                      432: branch 1 taken
                     1272: branch 2 taken
    1042             1704:     if (!Tok.is(tok::identifier))
    1043              432:       return false;
    1044                 : 
    1045             1272:     IdentifierInfo *II = Tok.getIdentifierInfo();
                      448: branch 2 taken
                      824: branch 3 taken
    1046             1272:     if (Actions.getTypeName(*II, Tok.getLocation(), CurScope))
    1047              448:       return true;
    1048                 : 
    1049              824:     return II == Ident_super;
    1050                 :   }
    1051                 : 
    1052                 :   OwningExprResult ParseObjCAtExpression(SourceLocation AtLocation);
    1053                 :   OwningExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
    1054                 :   OwningExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
    1055                 :   OwningExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
    1056                 :   OwningExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
    1057                 :   OwningExprResult ParseObjCMessageExpression();
    1058                 :   OwningExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
    1059                 :                                                   SourceLocation NameLoc,
    1060                 :                                                   IdentifierInfo *ReceiverName,
    1061                 :                                                   ExprArg ReceiverExpr);
    1062                 :   OwningExprResult ParseAssignmentExprWithObjCMessageExprStart(
    1063                 :       SourceLocation LBracloc, SourceLocation NameLoc,
    1064                 :       IdentifierInfo *ReceiverName, ExprArg ReceiverExpr);
    1065                 : 
    1066                 :   //===--------------------------------------------------------------------===//
    1067                 :   // C99 6.8: Statements and Blocks.
    1068                 : 
    1069             2890:   OwningStmtResult ParseStatement() {
    1070             2890:     return ParseStatementOrDeclaration(true);
    1071                 :   }
    1072                 :   OwningStmtResult ParseStatementOrDeclaration(bool OnlyStatement = false);
    1073                 :   OwningStmtResult ParseLabeledStatement(AttributeList *Attr);
    1074                 :   OwningStmtResult ParseCaseStatement(AttributeList *Attr);
    1075                 :   OwningStmtResult ParseDefaultStatement(AttributeList *Attr);
    1076                 :   OwningStmtResult ParseCompoundStatement(AttributeList *Attr,
    1077                 :                                           bool isStmtExpr = false);
    1078                 :   OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
    1079                 :   bool ParseParenExprOrCondition(OwningExprResult &ExprResult,
    1080                 :                                  DeclPtrTy &DeclResult);
    1081                 :   OwningStmtResult ParseIfStatement(AttributeList *Attr);
    1082                 :   OwningStmtResult ParseSwitchStatement(AttributeList *Attr);
    1083                 :   OwningStmtResult ParseWhileStatement(AttributeList *Attr);
    1084                 :   OwningStmtResult ParseDoStatement(AttributeList *Attr);
    1085                 :   OwningStmtResult ParseForStatement(AttributeList *Attr);
    1086                 :   OwningStmtResult ParseGotoStatement(AttributeList *Attr);
    1087                 :   OwningStmtResult ParseContinueStatement(AttributeList *Attr);
    1088                 :   OwningStmtResult ParseBreakStatement(AttributeList *Attr);
    1089                 :   OwningStmtResult ParseReturnStatement(AttributeList *Attr);
    1090                 :   OwningStmtResult ParseAsmStatement(bool &msAsm);
    1091                 :   OwningStmtResult FuzzyParseMicrosoftAsmStatement();
    1092                 :   bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<IdentifierInfo *> &Names,
    1093                 :                            llvm::SmallVectorImpl<ExprTy *> &Constraints,
    1094                 :                            llvm::SmallVectorImpl<ExprTy *> &Exprs);
    1095                 : 
    1096                 :   //===--------------------------------------------------------------------===//
    1097                 :   // C++ 6: Statements and Blocks
    1098                 : 
    1099                 :   OwningStmtResult ParseCXXTryBlock(AttributeList *Attr);
    1100                 :   OwningStmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc);
    1101                 :   OwningStmtResult ParseCXXCatchBlock();
    1102                 : 
    1103                 :   //===--------------------------------------------------------------------===//
    1104                 :   // Objective-C Statements
    1105                 : 
    1106                 :   OwningStmtResult ParseObjCAtStatement(SourceLocation atLoc);
    1107                 :   OwningStmtResult ParseObjCTryStmt(SourceLocation atLoc);
    1108                 :   OwningStmtResult ParseObjCThrowStmt(SourceLocation atLoc);
    1109                 :   OwningStmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
    1110                 : 
    1111                 : 
    1112                 :   //===--------------------------------------------------------------------===//
    1113                 :   // C99 6.7: Declarations.
    1114                 : 
    1115                 :   /// A context for parsing declaration specifiers.  TODO: flesh this
    1116                 :   /// out, there are other significant restrictions on specifiers than
    1117                 :   /// would be best implemented in the parser.
    1118                 :   enum DeclSpecContext {
    1119                 :     DSC_normal, // normal context
    1120                 :     DSC_class,  // class context, enables 'friend'
    1121                 :     DSC_top_level // top-level/namespace declaration context
    1122                 :   };
    1123                 : 
    1124                 :   DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd,
    1125                 :                                   CXX0XAttributeList Attr);
    1126                 :   DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context,
    1127                 :                                         SourceLocation &DeclEnd,
    1128                 :                                         AttributeList *Attr);
    1129                 :   DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context,
    1130                 :                                 bool AllowFunctionDefinitions,
    1131                 :                                 SourceLocation *DeclEnd = 0);
    1132                 :   DeclPtrTy ParseDeclarationAfterDeclarator(Declarator &D,
    1133                 :                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
    1134                 :   DeclPtrTy ParseFunctionStatementBody(DeclPtrTy Decl);
    1135                 :   DeclPtrTy ParseFunctionTryBlock(DeclPtrTy Decl);
    1136                 : 
    1137                 :   bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
    1138                 :                         const ParsedTemplateInfo &TemplateInfo,
    1139                 :                         AccessSpecifier AS);
    1140                 :   DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context);
    1141                 :   void ParseDeclarationSpecifiers(DeclSpec &DS,
    1142                 :                 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
    1143                 :                                   AccessSpecifier AS = AS_none,
    1144                 :                                   DeclSpecContext DSC = DSC_normal);
    1145                 :   bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid,
    1146                 :                                   const char *&PrevSpec,
    1147                 :                                   unsigned &DiagID,
    1148                 :                const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
    1149                 :                                   bool SuppressDeclarations = false);
    1150                 : 
    1151                 :   void ParseSpecifierQualifierList(DeclSpec &DS);
    1152                 : 
    1153                 :   void ParseObjCTypeQualifierList(ObjCDeclSpec &DS);
    1154                 : 
    1155                 :   void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
    1156                 :                           AccessSpecifier AS = AS_none);
    1157                 :   void ParseEnumBody(SourceLocation StartLoc, DeclPtrTy TagDecl);
    1158                 :   void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
    1159                 :                             DeclPtrTy TagDecl);
    1160                 : 
    1161             3582:   struct FieldCallback {
    1162                 :     virtual DeclPtrTy invoke(FieldDeclarator &Field) = 0;
                        0: branch 0 not taken
                     3582: branch 1 taken
                        0: branch 4 not taken
    1163             3582:     virtual ~FieldCallback() {}
    1164                 : 
    1165                 :   private:
    1166                 :     virtual void _anchor();
    1167                 :   };
    1168                 :   struct ObjCPropertyCallback;
    1169                 : 
    1170                 :   void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback);
    1171                 : 
    1172                 :   bool isDeclarationSpecifier();
    1173                 :   bool isTypeSpecifierQualifier();
    1174                 :   bool isTypeQualifier() const;
    1175                 : 
    1176                 :   /// isDeclarationStatement - Disambiguates between a declaration or an
    1177                 :   /// expression statement, when parsing function bodies.
    1178                 :   /// Returns true for declaration, false for expression.
    1179            15463:   bool isDeclarationStatement() {
                     4968: branch 1 taken
                    10495: branch 2 taken
    1180            15463:     if (getLang().CPlusPlus)
    1181             4968:       return isCXXDeclarationStatement();
    1182            10495:     return isDeclarationSpecifier();
    1183                 :   }
    1184                 : 
    1185                 :   /// isSimpleDeclaration - Disambiguates between a declaration or an
    1186                 :   /// expression, mainly used for the C 'clause-1' or the C++
    1187                 :   // 'for-init-statement' part of a 'for' statement.
    1188                 :   /// Returns true for declaration, false for expression.
    1189              226:   bool isSimpleDeclaration() {
                       60: branch 1 taken
                      166: branch 2 taken
    1190              226:     if (getLang().CPlusPlus)
    1191               60:       return isCXXSimpleDeclaration();
    1192              166:     return isDeclarationSpecifier();
    1193                 :   }
    1194                 : 
    1195                 :   /// \brief Starting with a scope specifier, identifier, or
    1196                 :   /// template-id that refers to the current class, determine whether
    1197                 :   /// this is a constructor declarator.
    1198                 :   bool isConstructorDeclarator();
    1199                 : 
    1200                 :   /// \brief Specifies the context in which type-id/expression
    1201                 :   /// disambiguation will occur.
    1202                 :   enum TentativeCXXTypeIdContext {
    1203                 :     TypeIdInParens,
    1204                 :     TypeIdAsTemplateArgument
    1205                 :   };
    1206                 : 
    1207                 : 
    1208                 :   /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
    1209                 :   /// whether the parens contain an expression or a type-id.
    1210                 :   /// Returns true for a type-id and false for an expression.
    1211             9602:   bool isTypeIdInParens(bool &isAmbiguous) {
                     3247: branch 1 taken
                        0: branch 2 not taken
    1212             9602:     if (getLang().CPlusPlus)
    1213             3247:       return isCXXTypeId(TypeIdInParens, isAmbiguous);
    1214             6355:     isAmbiguous = false;
    1215             6355:     return isTypeSpecifierQualifier();
    1216                 :   }
    1217              158:   bool isTypeIdInParens() {
    1218                 :     bool isAmbiguous;
    1219              158:     return isTypeIdInParens(isAmbiguous);
    1220                 :   }
    1221                 : 
    1222                 :   /// isCXXDeclarationStatement - C++-specialized function that disambiguates
    1223                 :   /// between a declaration or an expression statement, when parsing function
    1224                 :   /// bodies. Returns true for declaration, false for expression.
    1225                 :   bool isCXXDeclarationStatement();
    1226                 : 
    1227                 :   /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
    1228                 :   /// between a simple-declaration or an expression-statement.
    1229                 :   /// If during the disambiguation process a parsing error is encountered,
    1230                 :   /// the function returns true to let the declaration parsing code handle it.
    1231                 :   /// Returns false if the statement is disambiguated as expression.
    1232                 :   bool isCXXSimpleDeclaration();
    1233                 : 
    1234                 :   /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
    1235                 :   /// a constructor-style initializer, when parsing declaration statements.
    1236                 :   /// Returns true for function declarator and false for constructor-style
    1237                 :   /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to
    1238                 :   /// indicate that the parens were disambiguated as function declarator.
    1239                 :   /// If during the disambiguation process a parsing error is encountered,
    1240                 :   /// the function returns true to let the declaration parsing code handle it.
    1241                 :   bool isCXXFunctionDeclarator(bool warnIfAmbiguous);
    1242                 : 
    1243                 :   /// isCXXConditionDeclaration - Disambiguates between a declaration or an
    1244                 :   /// expression for a condition of a if/switch/while/for statement.
    1245                 :   /// If during the disambiguation process a parsing error is encountered,
    1246                 :   /// the function returns true to let the declaration parsing code handle it.
    1247                 :   bool isCXXConditionDeclaration();
    1248                 : 
    1249                 :   bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous);
    1250             3145:   bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
    1251                 :     bool isAmbiguous;
    1252             3145:     return isCXXTypeId(Context, isAmbiguous);
    1253                 :   }
    1254                 : 
    1255                 :   /// TPResult - Used as the result value for functions whose purpose is to
    1256                 :   /// disambiguate C++ constructs by "tentatively parsing" them.
    1257                 :   /// This is a class instead of a simple enum because the implicit enum-to-bool
    1258                 :   /// conversions may cause subtle bugs.
    1259                 :   class TPResult {
    1260                 :     enum Result {
    1261                 :       TPR_true,
    1262                 :       TPR_false,
    1263                 :       TPR_ambiguous,
    1264                 :       TPR_error
    1265                 :     };
    1266                 :     Result Res;
    1267            68821:     TPResult(Result result) : Res(result) {}
    1268                 :   public:
    1269            16013:     static TPResult True() { return TPR_true; }
    1270            16772:     static TPResult False() { return TPR_false; }
    1271            31134:     static TPResult Ambiguous() { return TPR_ambiguous; }
    1272             4902:     static TPResult Error() { return TPR_error; }
    1273                 : 
    1274            19367:     bool operator==(const TPResult &RHS) const { return Res == RHS.Res; }
    1275            30038:     bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; }
    1276                 :   };
    1277                 : 
    1278                 :   /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a
    1279                 :   /// declaration specifier, TPResult::False() if it is not,
    1280                 :   /// TPResult::Ambiguous() if it could be either a decl-specifier or a
    1281                 :   /// function-style cast, and TPResult::Error() if a parsing error was
    1282                 :   /// encountered.
    1283                 :   /// Doesn't consume tokens.
    1284                 :   TPResult isCXXDeclarationSpecifier();
    1285                 : 
    1286                 :   // "Tentative parsing" functions, used for disambiguation. If a parsing error
    1287                 :   // is encountered they will return TPResult::Error().
    1288                 :   // Returning TPResult::True()/False() indicates that the ambiguity was
    1289                 :   // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates
    1290                 :   // that more tentative parsing is necessary for disambiguation.
    1291                 :   // They all consume tokens, so backtracking should be used after calling them.
    1292                 : 
    1293                 :   TPResult TryParseDeclarationSpecifier();
    1294                 :   TPResult TryParseSimpleDeclaration();
    1295                 :   TPResult TryParseTypeofSpecifier();
    1296                 :   TPResult TryParseInitDeclaratorList();
    1297                 :   TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true);
    1298                 :   TPResult TryParseParameterDeclarationClause();
    1299                 :   TPResult TryParseFunctionDeclarator();
    1300                 :   TPResult TryParseBracketDeclarator();
    1301                 : 
    1302                 :   TypeResult ParseTypeName(SourceRange *Range = 0);
    1303                 :   void ParseBlockId();
    1304                 :   // EndLoc, if non-NULL, is filled with the location of the last token of
    1305                 :   // the attribute list.
    1306                 :   CXX0XAttributeList ParseCXX0XAttributes(SourceLocation *EndLoc = 0);
    1307                 :   AttributeList *ParseGNUAttributes(SourceLocation *EndLoc = 0);
    1308                 :   AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0);
    1309                 :   AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0);
    1310                 :   void ParseTypeofSpecifier(DeclSpec &DS);
    1311                 :   void ParseDecltypeSpecifier(DeclSpec &DS);
    1312                 :   
    1313                 :   OwningExprResult ParseCXX0XAlignArgument(SourceLocation Start);
    1314                 : 
    1315                 :   /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
    1316                 :   /// enter a new C++ declarator scope and exit it when the function is
    1317                 :   /// finished.
    1318                 :   class DeclaratorScopeObj {
    1319                 :     Parser &P;
    1320                 :     CXXScopeSpec &SS;
    1321                 :     bool EnteredScope;
    1322                 :     bool CreatedScope;
    1323                 :   public:
    1324            65201:     DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
    1325            65201:       : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
    1326                 : 
    1327              496:     void EnterDeclaratorScope() {
                        0: branch 0 not taken
    1328              496:       assert(!EnteredScope && "Already entered the scope!");
    1329              496:       assert(SS.isSet() && "C++ scope was not set!");
    1330                 : 
    1331              496:       CreatedScope = true;
    1332              496:       P.EnterScope(0); // Not a decl scope.
    1333                 : 
    1334              496:       if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS))
    1335              489:         EnteredScope = true;
    1336              496:     }
    1337                 : 
    1338            65201:     ~DeclaratorScopeObj() {
    1339            65201:       if (EnteredScope) {
    1340              489:         assert(SS.isSet() && "C++ scope was cleared ?");
    1341              489:         P.Actions.ActOnCXXExitDeclaratorScope(P.CurScope, SS);
    1342                 :       }
    1343            65201:       if (CreatedScope)
    1344              496:         P.ExitScope();
    1345            65201:     }
    1346                 :   };
    1347                 : 
    1348                 :   /// ParseDeclarator - Parse and verify a newly-initialized declarator.
    1349                 :   void ParseDeclarator(Declarator &D);
    1350                 :   /// A function that parses a variant of direct-declarator.
    1351                 :   typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
    1352                 :   void ParseDeclaratorInternal(Declarator &D,
    1353                 :                                DirectDeclParseFunction DirectDeclParser);
    1354                 :   void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true,
    1355                 :                                  bool CXX0XAttributesAllowed = true);
    1356                 :   void ParseDirectDeclarator(Declarator &D);
    1357                 :   void ParseParenDeclarator(Declarator &D);
    1358                 :   void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
    1359                 :                                AttributeList *AttrList = 0,
    1360                 :                                bool RequiresArg = false);
    1361                 :   void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
    1362                 :                                              Declarator &D);
    1363                 :   void ParseBracketDeclarator(Declarator &D);
    1364                 : 
    1365                 :   //===--------------------------------------------------------------------===//
    1366                 :   // C++ 7: Declarations [dcl.dcl]
    1367                 : 
    1368                 :   bool isCXX0XAttributeSpecifier(bool FullLookahead = false, 
    1369                 :                                  tok::TokenKind *After = 0);
    1370                 :   
    1371                 :   DeclPtrTy ParseNamespace(unsigned Context, SourceLocation &DeclEnd);
    1372                 :   DeclPtrTy ParseLinkage(ParsingDeclSpec &DS, unsigned Context);
    1373                 :   DeclPtrTy ParseUsingDirectiveOrDeclaration(unsigned Context,
    1374                 :                                              SourceLocation &DeclEnd,
    1375                 :                                              CXX0XAttributeList Attrs);
    1376                 :   DeclPtrTy ParseUsingDirective(unsigned Context, SourceLocation UsingLoc,
    1377                 :                                 SourceLocation &DeclEnd,
    1378                 :                                 AttributeList *Attr);
    1379                 :   DeclPtrTy ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc,
    1380                 :                                   SourceLocation &DeclEnd,
    1381                 :                                   AccessSpecifier AS = AS_none);
    1382                 :   DeclPtrTy ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
    1383                 :   DeclPtrTy ParseNamespaceAlias(SourceLocation NamespaceLoc,
    1384                 :                                 SourceLocation AliasLoc, IdentifierInfo *Alias,
    1385                 :                                 SourceLocation &DeclEnd);
    1386                 : 
    1387                 :   //===--------------------------------------------------------------------===//
    1388                 :   // C++ 9: classes [class] and C structs/unions.
    1389                 :   TypeResult ParseClassName(SourceLocation &EndLocation,
    1390                 :                             const CXXScopeSpec *SS = 0,
    1391                 :                             bool DestrExpected = false);
    1392                 :   void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
    1393                 :                            DeclSpec &DS,
    1394                 :                 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
    1395                 :                            AccessSpecifier AS = AS_none,
    1396                 :                            bool SuppressDeclarations = false);
    1397                 :   void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType,
    1398                 :                                    DeclPtrTy TagDecl);
    1399                 :   void ParseCXXClassMemberDeclaration(AccessSpecifier AS,
    1400                 :                 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
    1401                 :   void ParseConstructorInitializer(DeclPtrTy ConstructorDecl);
    1402                 :   MemInitResult ParseMemInitializer(DeclPtrTy ConstructorDecl);
    1403                 :   void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
    1404                 :                                        DeclPtrTy ThisDecl);
    1405                 : 
    1406                 :   //===--------------------------------------------------------------------===//
    1407                 :   // C++ 10: Derived classes [class.derived]
    1408                 :   void ParseBaseClause(DeclPtrTy ClassDecl);
    1409                 :   BaseResult ParseBaseSpecifier(DeclPtrTy ClassDecl);
    1410                 :   AccessSpecifier getAccessSpecifierIfPresent() const;
    1411                 : 
    1412                 :   bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 
    1413                 :                                     IdentifierInfo *Name,
    1414                 :                                     SourceLocation NameLoc,
    1415                 :                                     bool EnteringContext,
    1416                 :                                     TypeTy *ObjectType,
    1417                 :                                     UnqualifiedId &Id);
    1418                 :   bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
    1419                 :                                   TypeTy *ObjectType,
    1420                 :                                   UnqualifiedId &Result);
    1421                 :   bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
    1422                 :                           bool AllowDestructorName,
    1423                 :                           bool AllowConstructorName,
    1424                 :                           TypeTy *ObjectType,
    1425                 :                           UnqualifiedId &Result);
    1426                 :     
    1427                 :   //===--------------------------------------------------------------------===//
    1428                 :   // C++ 14: Templates [temp]
    1429                 :   typedef llvm::SmallVector<DeclPtrTy, 4> TemplateParameterList;
    1430                 : 
    1431                 :   // C++ 14.1: Template Parameters [temp.param]
    1432                 :   DeclPtrTy ParseDeclarationStartingWithTemplate(unsigned Context,
    1433                 :                                                  SourceLocation &DeclEnd,
    1434                 :                                                  AccessSpecifier AS = AS_none);
    1435                 :   DeclPtrTy ParseTemplateDeclarationOrSpecialization(unsigned Context,
    1436                 :                                                      SourceLocation &DeclEnd,
    1437                 :                                                      AccessSpecifier AS);
    1438                 :   DeclPtrTy ParseSingleDeclarationAfterTemplate(
    1439                 :                                        unsigned Context,
    1440                 :                                        const ParsedTemplateInfo &TemplateInfo,
    1441                 :                                        SourceLocation &DeclEnd,
    1442                 :                                        AccessSpecifier AS=AS_none);
    1443                 :   bool ParseTemplateParameters(unsigned Depth,
    1444                 :                                TemplateParameterList &TemplateParams,
    1445                 :                                SourceLocation &LAngleLoc,
    1446                 :                                SourceLocation &RAngleLoc);
    1447                 :   bool ParseTemplateParameterList(unsigned Depth,
    1448                 :                                   TemplateParameterList &TemplateParams);
    1449                 :   bool isStartOfTemplateTypeParameter();
    1450                 :   DeclPtrTy ParseTemplateParameter(unsigned Depth, unsigned Position);
    1451                 :   DeclPtrTy ParseTypeParameter(unsigned Depth, unsigned Position);
    1452                 :   DeclPtrTy ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
    1453                 :   DeclPtrTy ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
    1454                 :   // C++ 14.3: Template arguments [temp.arg]
    1455                 :   typedef llvm::SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
    1456                 : 
    1457                 :   bool ParseTemplateIdAfterTemplateName(TemplateTy Template,
    1458                 :                                         SourceLocation TemplateNameLoc,
    1459                 :                                         const CXXScopeSpec *SS,
    1460                 :                                         bool ConsumeLastToken,
    1461                 :                                         SourceLocation &LAngleLoc,
    1462                 :                                         TemplateArgList &TemplateArgs,
    1463                 :                                         SourceLocation &RAngleLoc);
    1464                 : 
    1465                 :   bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
    1466                 :                                const CXXScopeSpec *SS,
    1467                 :                                UnqualifiedId &TemplateName,
    1468                 :                                SourceLocation TemplateKWLoc = SourceLocation(),
    1469                 :                                bool AllowTypeAnnotation = true);
    1470                 :   void AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS = 0);
    1471                 :   bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
    1472                 :   ParsedTemplateArgument ParseTemplateTemplateArgument();
    1473                 :   ParsedTemplateArgument ParseTemplateArgument();
    1474                 :   DeclPtrTy ParseExplicitInstantiation(SourceLocation ExternLoc,
    1475                 :                                        SourceLocation TemplateLoc,
    1476                 :                                        SourceLocation &DeclEnd);
    1477                 : 
    1478                 :   //===--------------------------------------------------------------------===//
    1479                 :   // GNU G++: Type Traits [Type-Traits.html in the GCC manual]
    1480                 :   OwningExprResult ParseUnaryTypeTrait();
    1481                 : };
    1482                 : 
    1483                 : }  // end namespace clang
    1484                 : 
    1485                 : #endif

Generated: 2010-02-10 01:31 by zcov