11573Srgrimes//===--- Parser.h - C Language Parser ---------------------------*- C++ -*-===// 21573Srgrimes// 31573Srgrimes// The LLVM Compiler Infrastructure 41573Srgrimes// 51573Srgrimes// This file is distributed under the University of Illinois Open Source 61573Srgrimes// License. See LICENSE.TXT for details. 71573Srgrimes// 81573Srgrimes//===----------------------------------------------------------------------===// 91573Srgrimes// 101573Srgrimes// This file defines the Parser interface. 111573Srgrimes// 121573Srgrimes//===----------------------------------------------------------------------===// 131573Srgrimes 141573Srgrimes#ifndef LLVM_CLANG_PARSE_PARSER_H 151573Srgrimes#define LLVM_CLANG_PARSE_PARSER_H 161573Srgrimes 171573Srgrimes#include "clang/Basic/OpenMPKinds.h" 181573Srgrimes#include "clang/Basic/OperatorPrecedence.h" 191573Srgrimes#include "clang/Basic/Specifiers.h" 201573Srgrimes#include "clang/Lex/CodeCompletionHandler.h" 211573Srgrimes#include "clang/Lex/Preprocessor.h" 221573Srgrimes#include "clang/Sema/DeclSpec.h" 231573Srgrimes#include "clang/Sema/Sema.h" 241573Srgrimes#include "llvm/ADT/OwningPtr.h" 251573Srgrimes#include "llvm/ADT/SmallVector.h" 261573Srgrimes#include "llvm/Support/Compiler.h" 271573Srgrimes#include "llvm/Support/PrettyStackTrace.h" 281573Srgrimes#include "llvm/Support/SaveAndRestore.h" 291573Srgrimes#include <stack> 301573Srgrimes 311573Srgrimesnamespace clang { 321573Srgrimes class PragmaHandler; 331573Srgrimes class Scope; 341573Srgrimes class BalancedDelimiterTracker; 351573Srgrimes class CorrectionCandidateCallback; 361573Srgrimes class DeclGroupRef; 371573Srgrimes class DiagnosticBuilder; 381573Srgrimes class Parser; 391573Srgrimes class ParsingDeclRAIIObject; 401573Srgrimes class ParsingDeclSpec; 411573Srgrimes class ParsingDeclarator; 421573Srgrimes class ParsingFieldDeclarator; 4392986Sobrien class PragmaUnusedHandler; 4492986Sobrien class ColonProtectionRAIIObject; 451573Srgrimes class InMessageExpressionRAIIObject; 461573Srgrimes class PoisonSEHIdentifiersRAIIObject; 471573Srgrimes class VersionTuple; 481573Srgrimes 491573Srgrimes/// Parser - This implements a parser for the C family of languages. After 501573Srgrimes/// parsing units of the grammar, productions are invoked to handle whatever has 511573Srgrimes/// been read. 521573Srgrimes/// 531573Srgrimesclass Parser : public CodeCompletionHandler { 5419277Sache friend class PragmaUnusedHandler; 5519277Sache friend class ColonProtectionRAIIObject; 561573Srgrimes friend class InMessageExpressionRAIIObject; 571573Srgrimes friend class PoisonSEHIdentifiersRAIIObject; 581573Srgrimes friend class ObjCDeclContextSwitch; 591573Srgrimes friend class ParenBraceBracketBalancer; 601573Srgrimes friend class BalancedDelimiterTracker; 611573Srgrimes 621573Srgrimes Preprocessor &PP; 631573Srgrimes 641573Srgrimes /// Tok - The current token we are peeking ahead. All parsing methods assume 651573Srgrimes /// that this is valid. 661573Srgrimes Token Tok; 671573Srgrimes 681573Srgrimes // PrevTokLocation - The location of the token we previously 691573Srgrimes // consumed. This token is used for diagnostics where we expected to 701573Srgrimes // see a token following another token (e.g., the ';' at the end of 711573Srgrimes // a statement). 721573Srgrimes SourceLocation PrevTokLocation; 731573Srgrimes 741573Srgrimes unsigned short ParenCount, BracketCount, BraceCount; 751573Srgrimes 761573Srgrimes /// Actions - These are the callbacks we invoke as we parse various constructs 771573Srgrimes /// in the file. 781573Srgrimes Sema &Actions; 791573Srgrimes 801573Srgrimes DiagnosticsEngine &Diags; 811573Srgrimes 821573Srgrimes /// ScopeCache - Cache scopes to reduce malloc traffic. 831573Srgrimes enum { ScopeCacheSize = 16 }; 841573Srgrimes unsigned NumCachedScopes; 851573Srgrimes Scope *ScopeCache[ScopeCacheSize]; 8692905Sobrien 8792905Sobrien /// Identifiers used for SEH handling in Borland. These are only 8892905Sobrien /// allowed in particular circumstances 8992905Sobrien // __except block 9092905Sobrien IdentifierInfo *Ident__exception_code, 9192905Sobrien *Ident___exception_code, 9292905Sobrien *Ident_GetExceptionCode; 9392905Sobrien // __except filter expression 9492905Sobrien IdentifierInfo *Ident__exception_info, 9592905Sobrien *Ident___exception_info, 9692905Sobrien *Ident_GetExceptionInfo; 9792905Sobrien // __finally 9892905Sobrien IdentifierInfo *Ident__abnormal_termination, 9992905Sobrien *Ident___abnormal_termination, 10092905Sobrien *Ident_AbnormalTermination; 10192905Sobrien 10292905Sobrien /// Contextual keywords for Microsoft extensions. 10392905Sobrien IdentifierInfo *Ident__except; 10492905Sobrien 10592905Sobrien /// Ident_super - IdentifierInfo for "super", to support fast 10692905Sobrien /// comparison. 10792905Sobrien IdentifierInfo *Ident_super; 10892905Sobrien /// Ident_vector and Ident_pixel - cached IdentifierInfo's for 109111010Snectar /// "vector" and "pixel" fast comparison. Only present if 11017141Sjkh /// AltiVec enabled. 11192905Sobrien IdentifierInfo *Ident_vector; 11292905Sobrien IdentifierInfo *Ident_pixel; 11392905Sobrien 11417141Sjkh /// Objective-C contextual keywords. 11592905Sobrien mutable IdentifierInfo *Ident_instancetype; 11692905Sobrien 11792905Sobrien /// \brief Identifier for "introduced". 11892905Sobrien IdentifierInfo *Ident_introduced; 11992905Sobrien 12092905Sobrien /// \brief Identifier for "deprecated". 12192905Sobrien IdentifierInfo *Ident_deprecated; 12292905Sobrien 12392905Sobrien /// \brief Identifier for "obsoleted". 12492905Sobrien IdentifierInfo *Ident_obsoleted; 12592905Sobrien 12692905Sobrien /// \brief Identifier for "unavailable". 12792905Sobrien IdentifierInfo *Ident_unavailable; 12892905Sobrien 12992905Sobrien /// \brief Identifier for "message". 13092905Sobrien IdentifierInfo *Ident_message; 1311573Srgrimes 1321573Srgrimes /// C++0x contextual keywords. 1331573Srgrimes mutable IdentifierInfo *Ident_final; 1341573Srgrimes mutable IdentifierInfo *Ident_override; 1351573Srgrimes 1361573Srgrimes // C++ type trait keywords that have can be reverted to identifiers and 1371573Srgrimes // still used as type traits. 1381573Srgrimes llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertableTypeTraits; 1391573Srgrimes 1401573Srgrimes OwningPtr<PragmaHandler> AlignHandler; 1411573Srgrimes OwningPtr<PragmaHandler> GCCVisibilityHandler; 1421573Srgrimes OwningPtr<PragmaHandler> OptionsHandler; 1431573Srgrimes OwningPtr<PragmaHandler> PackHandler; 1441573Srgrimes OwningPtr<PragmaHandler> MSStructHandler; 1451573Srgrimes OwningPtr<PragmaHandler> UnusedHandler; 1461573Srgrimes OwningPtr<PragmaHandler> WeakHandler; 1471573Srgrimes OwningPtr<PragmaHandler> RedefineExtnameHandler; 1481573Srgrimes OwningPtr<PragmaHandler> FPContractHandler; 1491573Srgrimes OwningPtr<PragmaHandler> OpenCLExtensionHandler; 1501573Srgrimes OwningPtr<CommentHandler> CommentSemaHandler; 1511573Srgrimes OwningPtr<PragmaHandler> OpenMPHandler; 1521573Srgrimes OwningPtr<PragmaHandler> MSCommentHandler; 1531573Srgrimes 1541573Srgrimes /// Whether the '>' token acts as an operator or not. This will be 1551573Srgrimes /// true except when we are parsing an expression within a C++ 1561573Srgrimes /// template argument list, where the '>' closes the template 1571573Srgrimes /// argument list. 1581573Srgrimes bool GreaterThanIsOperator; 1591573Srgrimes 1601573Srgrimes /// ColonIsSacred - When this is false, we aggressively try to recover from 1611573Srgrimes /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 1621573Srgrimes /// safe in case statements and a few other things. This is managed by the 1631573Srgrimes /// ColonProtectionRAIIObject RAII object. 1641573Srgrimes bool ColonIsSacred; 1651573Srgrimes 1661573Srgrimes /// \brief When true, we are directly inside an Objective-C messsage 1671573Srgrimes /// send expression. 1681573Srgrimes /// 1691573Srgrimes /// This is managed by the \c InMessageExpressionRAIIObject class, and 1701573Srgrimes /// should not be set directly. 1711573Srgrimes bool InMessageExpression; 1721573Srgrimes 1731573Srgrimes /// The "depth" of the template parameters currently being parsed. 1741573Srgrimes unsigned TemplateParameterDepth; 17562232Sdcs 17662232Sdcs /// \brief RAII class that manages the template parameter depth. 17762232Sdcs class TemplateParameterDepthRAII { 1781573Srgrimes unsigned &Depth; 1791573Srgrimes unsigned AddedLevels; 1801573Srgrimes public: 1811573Srgrimes explicit TemplateParameterDepthRAII(unsigned &Depth) 1821573Srgrimes : Depth(Depth), AddedLevels(0) {} 1831573Srgrimes 1841573Srgrimes ~TemplateParameterDepthRAII() { 1851573Srgrimes Depth -= AddedLevels; 1861573Srgrimes } 1871573Srgrimes 1881573Srgrimes void operator++() { 1891573Srgrimes ++Depth; 1901573Srgrimes ++AddedLevels; 1911573Srgrimes } 192104358Smike unsigned getDepth() const { return Depth; } 193104358Smike }; 1941573Srgrimes 1951573Srgrimes /// Factory object for creating AttributeList objects. 1961573Srgrimes AttributeFactory AttrFactory; 19792889Sobrien 19892889Sobrien /// \brief Gathers and cleans up TemplateIdAnnotations when parsing of a 19992889Sobrien /// top-level declaration is finished. 20092889Sobrien SmallVector<TemplateIdAnnotation *, 16> TemplateIds; 2011573Srgrimes 2021573Srgrimes /// \brief Identifiers which have been declared within a tentative parse. 2031573Srgrimes SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers; 2041573Srgrimes 2051573Srgrimes IdentifierInfo *getSEHExceptKeyword(); 2061573Srgrimes 2071573Srgrimes /// True if we are within an Objective-C container while parsing C-like decls. 2081573Srgrimes /// 2091573Srgrimes /// This is necessary because Sema thinks we have left the container 2101573Srgrimes /// to parse the C-like decls, meaning Actions.getObjCDeclContext() will 2111573Srgrimes /// be NULL. 2121573Srgrimes bool ParsingInObjCContainer; 2131573Srgrimes 2141573Srgrimes bool SkipFunctionBodies; 2151573Srgrimes 2161573Srgrimespublic: 2171573Srgrimes Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies); 2181573Srgrimes ~Parser(); 2191573Srgrimes 2201573Srgrimes const LangOptions &getLangOpts() const { return PP.getLangOpts(); } 2211573Srgrimes const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 2221573Srgrimes Preprocessor &getPreprocessor() const { return PP; } 2231573Srgrimes Sema &getActions() const { return Actions; } 2241573Srgrimes AttributeFactory &getAttrFactory() { return AttrFactory; } 2251573Srgrimes 2261573Srgrimes const Token &getCurToken() const { return Tok; } 2271573Srgrimes Scope *getCurScope() const { return Actions.getCurScope(); } 2281573Srgrimes 2291573Srgrimes Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } 2301573Srgrimes 2311573Srgrimes // Type forwarding. All of these are statically 'void*', but they may all be 2321573Srgrimes // different actual classes based on the actions in place. 2331573Srgrimes typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 2341573Srgrimes typedef OpaquePtr<TemplateName> TemplateTy; 2351573Srgrimes 2361573Srgrimes typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists; 2371573Srgrimes 2381573Srgrimes typedef clang::ExprResult ExprResult; 2391573Srgrimes typedef clang::StmtResult StmtResult; 2401573Srgrimes typedef clang::BaseResult BaseResult; 2411573Srgrimes typedef clang::MemInitResult MemInitResult; 2421573Srgrimes typedef clang::TypeResult TypeResult; 2431573Srgrimes 2441573Srgrimes typedef Expr *ExprArg; 2451573Srgrimes typedef llvm::MutableArrayRef<Stmt*> MultiStmtArg; 2461573Srgrimes typedef Sema::FullExprArg FullExprArg; 2471573Srgrimes 2481573Srgrimes ExprResult ExprError() { return ExprResult(true); } 2491573Srgrimes StmtResult StmtError() { return StmtResult(true); } 25062391Sdcs 25162263Sdcs ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 25262263Sdcs StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 2531573Srgrimes 2541573Srgrimes ExprResult ExprEmpty() { return ExprResult(false); } 2551573Srgrimes 2561573Srgrimes // Parsing methods. 2571573Srgrimes 2581573Srgrimes /// Initialize - Warm up the parser. 2591573Srgrimes /// 2601573Srgrimes void Initialize(); 2611573Srgrimes 2621573Srgrimes /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 2631573Srgrimes /// the EOF was encountered. 2641573Srgrimes bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 2651573Srgrimes 2661573Srgrimes /// ConsumeToken - Consume the current 'peek token' and lex the next one. 2671573Srgrimes /// This does not work with all kinds of tokens: strings and specific other 2681573Srgrimes /// tokens must be consumed with custom methods below. This returns the 2691573Srgrimes /// location of the consumed token. 2701573Srgrimes SourceLocation ConsumeToken(bool ConsumeCodeCompletionTok = false) { 2711573Srgrimes assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 2721573Srgrimes !isTokenBrace() && 2731573Srgrimes "Should consume special tokens with Consume*Token"); 2741573Srgrimes 2751573Srgrimes if (!ConsumeCodeCompletionTok && Tok.is(tok::code_completion)) 27662232Sdcs return handleUnexpectedCodeCompletionToken(); 27762232Sdcs 27862232Sdcs PrevTokLocation = Tok.getLocation(); 27962232Sdcs PP.Lex(Tok); 28062232Sdcs return PrevTokLocation; 28162232Sdcs } 28262755Sdcs 28362232Sdcsprivate: 28462232Sdcs //===--------------------------------------------------------------------===// 28562232Sdcs // Low-Level token peeking and consumption methods. 28662232Sdcs // 2871573Srgrimes 2881573Srgrimes /// isTokenParen - Return true if the cur token is '(' or ')'. 2891573Srgrimes bool isTokenParen() const { 2901573Srgrimes return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 2911573Srgrimes } 2921573Srgrimes /// isTokenBracket - Return true if the cur token is '[' or ']'. 2931573Srgrimes bool isTokenBracket() const { 2941573Srgrimes return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 2951573Srgrimes } 2961573Srgrimes /// isTokenBrace - Return true if the cur token is '{' or '}'. 2971573Srgrimes bool isTokenBrace() const { 2981573Srgrimes return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 2991573Srgrimes } 3001573Srgrimes 3011573Srgrimes /// isTokenStringLiteral - True if this token is a string-literal. 3021573Srgrimes /// 3031573Srgrimes bool isTokenStringLiteral() const { 3041573Srgrimes return tok::isStringLiteral(Tok.getKind()); 3051573Srgrimes } 30692889Sobrien 3071573Srgrimes /// \brief Returns true if the current token is '=' or is a type of '='. 3081573Srgrimes /// For typos, give a fixit to '=' 3091573Srgrimes bool isTokenEqualOrEqualTypo(); 31092889Sobrien 3111573Srgrimes /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 3121573Srgrimes /// current token type. This should only be used in cases where the type of 31392889Sobrien /// the token really isn't known, e.g. in error recovery. 31492889Sobrien SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) { 31592889Sobrien if (isTokenParen()) 31692889Sobrien return ConsumeParen(); 31792889Sobrien else if (isTokenBracket()) 3181573Srgrimes return ConsumeBracket(); 3191573Srgrimes else if (isTokenBrace()) 3201573Srgrimes return ConsumeBrace(); 3211573Srgrimes else if (isTokenStringLiteral()) 3221573Srgrimes return ConsumeStringToken(); 3231573Srgrimes else 32417141Sjkh return ConsumeToken(ConsumeCodeCompletionTok); 3251573Srgrimes } 3261573Srgrimes 3271573Srgrimes /// ConsumeParen - This consume method keeps the paren count up-to-date. 3281573Srgrimes /// 3291573Srgrimes SourceLocation ConsumeParen() { 3301573Srgrimes assert(isTokenParen() && "wrong consume method"); 3311573Srgrimes if (Tok.getKind() == tok::l_paren) 3321573Srgrimes ++ParenCount; 3331573Srgrimes else if (ParenCount) 3341573Srgrimes --ParenCount; // Don't let unbalanced )'s drive the count negative. 3351573Srgrimes PrevTokLocation = Tok.getLocation(); 3361573Srgrimes PP.Lex(Tok); 3371573Srgrimes return PrevTokLocation; 3381573Srgrimes } 3391573Srgrimes 3401573Srgrimes /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 3411573Srgrimes /// 3421573Srgrimes SourceLocation ConsumeBracket() { 3431573Srgrimes assert(isTokenBracket() && "wrong consume method"); 3441573Srgrimes if (Tok.getKind() == tok::l_square) 3451573Srgrimes ++BracketCount; 3461573Srgrimes else if (BracketCount) 3471573Srgrimes --BracketCount; // Don't let unbalanced ]'s drive the count negative. 3481573Srgrimes 3491573Srgrimes PrevTokLocation = Tok.getLocation(); 3501573Srgrimes PP.Lex(Tok); 3511573Srgrimes return PrevTokLocation; 35292889Sobrien } 3531573Srgrimes 3541573Srgrimes /// ConsumeBrace - This consume method keeps the brace count up-to-date. 3551573Srgrimes /// 35692889Sobrien SourceLocation ConsumeBrace() { 3571573Srgrimes assert(isTokenBrace() && "wrong consume method"); 35892889Sobrien if (Tok.getKind() == tok::l_brace) 35992889Sobrien ++BraceCount; 36092889Sobrien else if (BraceCount) 36192889Sobrien --BraceCount; // Don't let unbalanced }'s drive the count negative. 36292889Sobrien 3631573Srgrimes PrevTokLocation = Tok.getLocation(); 3641573Srgrimes PP.Lex(Tok); 3651573Srgrimes return PrevTokLocation; 3661573Srgrimes } 3671573Srgrimes 3681573Srgrimes /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 3691573Srgrimes /// and returning the token kind. This method is specific to strings, as it 3701573Srgrimes /// handles string literal concatenation, as per C99 5.1.1.2, translation 37117141Sjkh /// phase #6. 3721573Srgrimes SourceLocation ConsumeStringToken() { 3731573Srgrimes assert(isTokenStringLiteral() && 3741573Srgrimes "Should only consume string literals with this method"); 3751573Srgrimes PrevTokLocation = Tok.getLocation(); 3761573Srgrimes PP.Lex(Tok); 3771573Srgrimes return PrevTokLocation; 3781573Srgrimes } 3791573Srgrimes 3801573Srgrimes /// \brief Consume the current code-completion token. 3811573Srgrimes /// 3821573Srgrimes /// This routine should be called to consume the code-completion token once 3831573Srgrimes /// a code-completion action has already been invoked. 38417141Sjkh SourceLocation ConsumeCodeCompletionToken() { 3851573Srgrimes assert(Tok.is(tok::code_completion)); 3861573Srgrimes PrevTokLocation = Tok.getLocation(); 3871573Srgrimes PP.Lex(Tok); 3881573Srgrimes return PrevTokLocation; 3891573Srgrimes } 3901573Srgrimes 3911573Srgrimes ///\ brief When we are consuming a code-completion token without having 3921573Srgrimes /// matched specific position in the grammar, provide code-completion results 3931573Srgrimes /// based on context. 3941573Srgrimes /// 3951573Srgrimes /// \returns the source location of the code-completion token. 3961573Srgrimes SourceLocation handleUnexpectedCodeCompletionToken(); 3971573Srgrimes 3981573Srgrimes /// \brief Abruptly cut off parsing; mainly used when we have reached the 3991573Srgrimes /// code-completion point. 4001573Srgrimes void cutOffParsing() { 4011573Srgrimes PP.setCodeCompletionReached(); 4021573Srgrimes // Cut off parsing by acting as if we reached the end-of-file. 4031573Srgrimes Tok.setKind(tok::eof); 4041573Srgrimes } 4051573Srgrimes 4061573Srgrimes /// \brief Handle the annotation token produced for #pragma unused(...) 4071573Srgrimes void HandlePragmaUnused(); 4081573Srgrimes 4091573Srgrimes /// \brief Handle the annotation token produced for 4101573Srgrimes /// #pragma GCC visibility... 4111573Srgrimes void HandlePragmaVisibility(); 4121573Srgrimes 4131573Srgrimes /// \brief Handle the annotation token produced for 4141573Srgrimes /// #pragma pack... 4151573Srgrimes void HandlePragmaPack(); 4161573Srgrimes 4171573Srgrimes /// \brief Handle the annotation token produced for 4181573Srgrimes /// #pragma ms_struct... 4191573Srgrimes void HandlePragmaMSStruct(); 4201573Srgrimes 4211573Srgrimes /// \brief Handle the annotation token produced for 4221573Srgrimes /// #pragma align... 4231573Srgrimes void HandlePragmaAlign(); 4241573Srgrimes 4251573Srgrimes /// \brief Handle the annotation token produced for 4261573Srgrimes /// #pragma weak id... 42717141Sjkh void HandlePragmaWeak(); 4281573Srgrimes 4291573Srgrimes /// \brief Handle the annotation token produced for 4301573Srgrimes /// #pragma weak id = id... 4311573Srgrimes void HandlePragmaWeakAlias(); 43249094Sache 4331573Srgrimes /// \brief Handle the annotation token produced for 4341573Srgrimes /// #pragma redefine_extname... 4351573Srgrimes void HandlePragmaRedefineExtname(); 4361573Srgrimes 4371573Srgrimes /// \brief Handle the annotation token produced for 4381573Srgrimes /// #pragma STDC FP_CONTRACT... 4391573Srgrimes void HandlePragmaFPContract(); 4401573Srgrimes 4411573Srgrimes /// \brief Handle the annotation token produced for 4421573Srgrimes /// #pragma OPENCL EXTENSION... 4431573Srgrimes void HandlePragmaOpenCLExtension(); 44449094Sache 4451573Srgrimes /// \brief Handle the annotation token produced for 4461573Srgrimes /// #pragma clang __debug captured 4471573Srgrimes StmtResult HandlePragmaCaptured(); 44817141Sjkh 4491573Srgrimes /// GetLookAheadToken - This peeks ahead N tokens and returns that token 4501573Srgrimes /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 4511573Srgrimes /// returns the token after Tok, etc. 4521573Srgrimes /// 4531573Srgrimes /// Note that this differs from the Preprocessor's LookAhead method, because 4541573Srgrimes /// the Parser always has one token lexed that the preprocessor doesn't. 4551573Srgrimes /// 4561573Srgrimes const Token &GetLookAheadToken(unsigned N) { 4571573Srgrimes if (N == 0 || Tok.is(tok::eof)) return Tok; 4581573Srgrimes return PP.LookAhead(N-1); 4591573Srgrimes } 4601573Srgrimes 4611573Srgrimespublic: 4621573Srgrimes /// NextToken - This peeks ahead one token and returns it without 4631573Srgrimes /// consuming it. 4641573Srgrimes const Token &NextToken() { 4651573Srgrimes return PP.LookAhead(0); 4661573Srgrimes } 4671573Srgrimes 4681573Srgrimes /// getTypeAnnotation - Read a parsed type out of an annotation token. 4691573Srgrimes static ParsedType getTypeAnnotation(Token &Tok) { 4701573Srgrimes return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); 4711573Srgrimes } 4721573Srgrimes 47349094Sacheprivate: 4741573Srgrimes static void setTypeAnnotation(Token &Tok, ParsedType T) { 47517141Sjkh Tok.setAnnotationValue(T.getAsOpaquePtr()); 4761573Srgrimes } 4771573Srgrimes 4781573Srgrimes /// \brief Read an already-translated primary expression out of an annotation 4791573Srgrimes /// token. 4801573Srgrimes static ExprResult getExprAnnotation(Token &Tok) { 4811573Srgrimes return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue()); 4821573Srgrimes } 4831573Srgrimes 48417141Sjkh /// \brief Set the primary expression corresponding to the given annotation 4851573Srgrimes /// token. 4861573Srgrimes static void setExprAnnotation(Token &Tok, ExprResult ER) { 4871573Srgrimes Tok.setAnnotationValue(ER.getAsOpaquePointer()); 4881573Srgrimes } 4891573Srgrimes 4901573Srgrimespublic: 4911573Srgrimes // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to 4921573Srgrimes // find a type name by attempting typo correction. 4931573Srgrimes bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false, 49449094Sache bool NeedType = false); 4951573Srgrimes bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext, 4961573Srgrimes bool NeedType, 4971573Srgrimes CXXScopeSpec &SS, 4981573Srgrimes bool IsNewScope); 4991573Srgrimes bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 5001573Srgrimes 50192889Sobrienprivate: 5021573Srgrimes enum AnnotatedNameKind { 5031573Srgrimes /// Annotation has failed and emitted an error. 5041573Srgrimes ANK_Error, 50592889Sobrien /// The identifier is a tentatively-declared name. 5061573Srgrimes ANK_TentativeDecl, 50717141Sjkh /// The identifier is a template name. FIXME: Add an annotation for that. 5081573Srgrimes ANK_TemplateName, 5091573Srgrimes /// The identifier can't be resolved. 5101573Srgrimes ANK_Unresolved, 5111573Srgrimes /// Annotation was successful. 5121573Srgrimes ANK_Success 5131573Srgrimes }; 51492889Sobrien AnnotatedNameKind TryAnnotateName(bool IsAddressOfOperand, 51592889Sobrien CorrectionCandidateCallback *CCC = 0); 5161573Srgrimes 5171573Srgrimes /// Push a tok::annot_cxxscope token onto the token stream. 5181573Srgrimes void AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation); 5191573Srgrimes 5201573Srgrimes /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 5211573Srgrimes /// replacing them with the non-context-sensitive keywords. This returns 5221573Srgrimes /// true if the token was replaced. 5231573Srgrimes bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 5241573Srgrimes const char *&PrevSpec, unsigned &DiagID, 5251573Srgrimes bool &isInvalid) { 52692889Sobrien if (!getLangOpts().AltiVec || 52792889Sobrien (Tok.getIdentifierInfo() != Ident_vector && 52892889Sobrien Tok.getIdentifierInfo() != Ident_pixel)) 5291573Srgrimes return false; 53092889Sobrien 53192889Sobrien return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 53292889Sobrien } 5331573Srgrimes 5341573Srgrimes /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 5351573Srgrimes /// identifier token, replacing it with the non-context-sensitive __vector. 5361573Srgrimes /// This returns true if the token was replaced. 5371573Srgrimes bool TryAltiVecVectorToken() { 5381573Srgrimes if (!getLangOpts().AltiVec || 5391573Srgrimes Tok.getIdentifierInfo() != Ident_vector) return false; 5401573Srgrimes return TryAltiVecVectorTokenOutOfLine(); 5411573Srgrimes } 5421573Srgrimes 5431573Srgrimes bool TryAltiVecVectorTokenOutOfLine(); 5441573Srgrimes bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 5451573Srgrimes const char *&PrevSpec, unsigned &DiagID, 5461573Srgrimes bool &isInvalid); 5471573Srgrimes 5481573Srgrimes /// \brief Get the TemplateIdAnnotation from the token. 5491573Srgrimes TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok); 55017141Sjkh 5511573Srgrimes /// TentativeParsingAction - An object that is used as a kind of "tentative 5521573Srgrimes /// parsing transaction". It gets instantiated to mark the token position and 5531573Srgrimes /// after the token consumption is done, Commit() or Revert() is called to 5541573Srgrimes /// either "commit the consumed tokens" or revert to the previously marked 55592889Sobrien /// token position. Example: 5561573Srgrimes /// 5571573Srgrimes /// TentativeParsingAction TPA(*this); 5581573Srgrimes /// ConsumeToken(); 55992889Sobrien /// .... 5601573Srgrimes /// TPA.Revert(); 5611573Srgrimes /// 56292889Sobrien class TentativeParsingAction { 56392889Sobrien Parser &P; 56492889Sobrien Token PrevTok; 56592889Sobrien size_t PrevTentativelyDeclaredIdentifierCount; 56692889Sobrien unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount; 56792889Sobrien bool isActive; 5681573Srgrimes 5691573Srgrimes public: 5701573Srgrimes explicit TentativeParsingAction(Parser& p) : P(p) { 5711573Srgrimes PrevTok = P.Tok; 5721573Srgrimes PrevTentativelyDeclaredIdentifierCount = 5731573Srgrimes P.TentativelyDeclaredIdentifiers.size(); 5741573Srgrimes PrevParenCount = P.ParenCount; 57517141Sjkh PrevBracketCount = P.BracketCount; 57649094Sache PrevBraceCount = P.BraceCount; 5771573Srgrimes P.PP.EnableBacktrackAtThisPos(); 5781573Srgrimes isActive = true; 5791573Srgrimes } 5801573Srgrimes void Commit() { 5811573Srgrimes assert(isActive && "Parsing action was finished!"); 5821573Srgrimes P.TentativelyDeclaredIdentifiers.resize( 5831573Srgrimes PrevTentativelyDeclaredIdentifierCount); 5841573Srgrimes P.PP.CommitBacktrackedTokens(); 5851573Srgrimes isActive = false; 5861573Srgrimes } 5871573Srgrimes void Revert() { 5881573Srgrimes assert(isActive && "Parsing action was finished!"); 5891573Srgrimes P.PP.Backtrack(); 5901573Srgrimes P.Tok = PrevTok; 5911573Srgrimes P.TentativelyDeclaredIdentifiers.resize( 5921573Srgrimes PrevTentativelyDeclaredIdentifierCount); 5931573Srgrimes P.ParenCount = PrevParenCount; 5941573Srgrimes P.BracketCount = PrevBracketCount; 5951573Srgrimes P.BraceCount = PrevBraceCount; 5961573Srgrimes isActive = false; 5971573Srgrimes } 5981573Srgrimes ~TentativeParsingAction() { 5991573Srgrimes assert(!isActive && "Forgot to call Commit or Revert!"); 6001573Srgrimes } 6011573Srgrimes }; 6021573Srgrimes 6031573Srgrimes /// ObjCDeclContextSwitch - An object used to switch context from 6041573Srgrimes /// an objective-c decl context to its enclosing decl context and 60517141Sjkh /// back. 6061573Srgrimes class ObjCDeclContextSwitch { 6071573Srgrimes Parser &P; 6081573Srgrimes Decl *DC; 6091573Srgrimes SaveAndRestore<bool> WithinObjCContainer; 6101573Srgrimes public: 6111573Srgrimes explicit ObjCDeclContextSwitch(Parser &p) 6121573Srgrimes : P(p), DC(p.getObjCDeclContext()), 6131573Srgrimes WithinObjCContainer(P.ParsingInObjCContainer, DC != 0) { 6141573Srgrimes if (DC) 6151573Srgrimes P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC)); 6161573Srgrimes } 6171573Srgrimes ~ObjCDeclContextSwitch() { 6181573Srgrimes if (DC) 6191573Srgrimes P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC)); 6201573Srgrimes } 6211573Srgrimes }; 6221573Srgrimes 6231573Srgrimes /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 6241573Srgrimes /// input. If so, it is consumed and false is returned. 6251573Srgrimes /// 6261573Srgrimes /// If the input is malformed, this emits the specified diagnostic. Next, if 6271573Srgrimes /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 6281573Srgrimes /// returned. 6291573Srgrimes bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 6301573Srgrimes const char *DiagMsg = "", 6311573Srgrimes tok::TokenKind SkipToTok = tok::unknown); 6321573Srgrimes 6331573Srgrimes /// \brief The parser expects a semicolon and, if present, will consume it. 6341573Srgrimes /// 63517141Sjkh /// If the next token is not a semicolon, this emits the specified diagnostic, 6361573Srgrimes /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior 6371573Srgrimes /// to the semicolon, consumes that extra token. 63849094Sache bool ExpectAndConsumeSemi(unsigned DiagID); 6391573Srgrimes 6401573Srgrimes /// \brief The kind of extra semi diagnostic to emit. 6411573Srgrimes enum ExtraSemiKind { 6421573Srgrimes OutsideFunction = 0, 6431573Srgrimes InsideStruct = 1, 6441573Srgrimes InstanceVariableList = 2, 6451573Srgrimes AfterMemberFunctionDefinition = 3 6461573Srgrimes }; 6471573Srgrimes 6481573Srgrimes /// \brief Consume any extra semi-colons until the end of the line. 6491573Srgrimes void ConsumeExtraSemi(ExtraSemiKind Kind, unsigned TST = TST_unspecified); 6501573Srgrimes 65149094Sachepublic: 6521573Srgrimes //===--------------------------------------------------------------------===// 65317141Sjkh // Scope manipulation 6541573Srgrimes 6551573Srgrimes /// ParseScope - Introduces a new scope for parsing. The kind of 6561573Srgrimes /// scope is determined by ScopeFlags. Objects of this type should 6571573Srgrimes /// be created on the stack to coincide with the position where the 6581573Srgrimes /// parser enters the new scope, and this object's constructor will 6591573Srgrimes /// create that new scope. Similarly, once the object is destroyed 6601573Srgrimes /// the parser will exit the scope. 6611573Srgrimes class ParseScope { 66217141Sjkh Parser *Self; 6631573Srgrimes ParseScope(const ParseScope &) LLVM_DELETED_FUNCTION; 6641573Srgrimes void operator=(const ParseScope &) LLVM_DELETED_FUNCTION; 66549094Sache 6661573Srgrimes public: 6671573Srgrimes // ParseScope - Construct a new object to manage a scope in the 6681573Srgrimes // parser Self where the new Scope is created with the flags 6691573Srgrimes // ScopeFlags, but only when ManageScope is true (the default). If 6701573Srgrimes // ManageScope is false, this object does nothing. 6711573Srgrimes ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 6721573Srgrimes : Self(Self) { 67392889Sobrien if (ManageScope) 6741573Srgrimes Self->EnterScope(ScopeFlags); 6751573Srgrimes else 6761573Srgrimes this->Self = 0; 67792889Sobrien } 6781573Srgrimes 67992889Sobrien // Exit - Exit the scope associated with this object now, rather 68092889Sobrien // than waiting until the object is destroyed. 6811573Srgrimes void Exit() { 68249094Sache if (Self) { 6831573Srgrimes Self->ExitScope(); 6841573Srgrimes Self = 0; 6851573Srgrimes } 6861573Srgrimes } 68717141Sjkh 6881573Srgrimes ~ParseScope() { 6891573Srgrimes Exit(); 6901573Srgrimes } 6911573Srgrimes }; 6921573Srgrimes 69392889Sobrien /// EnterScope - Start a new scope. 6941573Srgrimes void EnterScope(unsigned ScopeFlags); 6951573Srgrimes 6961573Srgrimes /// ExitScope - Pop a scope off the scope stack. 6971573Srgrimes void ExitScope(); 6981573Srgrimes 6991573Srgrimesprivate: 70092889Sobrien /// \brief RAII object used to modify the scope flags for the current scope. 7011573Srgrimes class ParseScopeFlags { 70292889Sobrien Scope *CurScope; 70392889Sobrien unsigned OldFlags; 7041573Srgrimes ParseScopeFlags(const ParseScopeFlags &) LLVM_DELETED_FUNCTION; 7051573Srgrimes void operator=(const ParseScopeFlags &) LLVM_DELETED_FUNCTION; 7061573Srgrimes 7071573Srgrimes public: 7081573Srgrimes ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true); 7091573Srgrimes ~ParseScopeFlags(); 7101573Srgrimes }; 7111573Srgrimes 7121573Srgrimes //===--------------------------------------------------------------------===// 7131573Srgrimes // Diagnostic Emission and Error recovery. 7141573Srgrimes 7151573Srgrimespublic: 7161573Srgrimes DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 7171573Srgrimes DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 7181573Srgrimes DiagnosticBuilder Diag(unsigned DiagID) { 7191573Srgrimes return Diag(Tok, DiagID); 7201573Srgrimes } 7211573Srgrimes 7221573Srgrimesprivate: 7231573Srgrimes void SuggestParentheses(SourceLocation Loc, unsigned DK, 7241573Srgrimes SourceRange ParenRange); 7251573Srgrimes void CheckNestedObjCContexts(SourceLocation AtLoc); 7261573Srgrimes 72717141Sjkhpublic: 7281573Srgrimes /// SkipUntil - Read tokens until we get to the specified token, then consume 7291573Srgrimes /// it (unless DontConsume is true). Because we cannot guarantee that the 7301573Srgrimes /// token will ever occur, this skips to the next token, or to some likely 7311573Srgrimes /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 7321573Srgrimes /// character. 73392889Sobrien /// 73492889Sobrien /// If SkipUntil finds the specified token, it returns true, otherwise it 7351573Srgrimes /// returns false. 7361573Srgrimes bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 7371573Srgrimes bool DontConsume = false, bool StopAtCodeCompletion = false) { 7381573Srgrimes return SkipUntil(llvm::makeArrayRef(T), StopAtSemi, DontConsume, 7391573Srgrimes StopAtCodeCompletion); 7401573Srgrimes } 7411573Srgrimes bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 7421573Srgrimes bool DontConsume = false, bool StopAtCodeCompletion = false) { 7431573Srgrimes tok::TokenKind TokArray[] = {T1, T2}; 7441573Srgrimes return SkipUntil(TokArray, StopAtSemi, DontConsume,StopAtCodeCompletion); 7451573Srgrimes } 74692889Sobrien bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, 7471573Srgrimes bool StopAtSemi = true, bool DontConsume = false, 7481573Srgrimes bool StopAtCodeCompletion = false) { 7491573Srgrimes tok::TokenKind TokArray[] = {T1, T2, T3}; 7501573Srgrimes return SkipUntil(TokArray, StopAtSemi, DontConsume,StopAtCodeCompletion); 7511573Srgrimes } 7521573Srgrimes bool SkipUntil(ArrayRef<tok::TokenKind> Toks, bool StopAtSemi = true, 7531573Srgrimes bool DontConsume = false, bool StopAtCodeCompletion = false); 7541573Srgrimes 7551573Srgrimes /// SkipMalformedDecl - Read tokens until we get to some likely good stopping 7561573Srgrimes /// point for skipping past a simple-declaration. 7571573Srgrimes void SkipMalformedDecl(); 7581573Srgrimes 7591573Srgrimesprivate: 7601573Srgrimes //===--------------------------------------------------------------------===// 7611573Srgrimes // Lexing and parsing of C++ inline methods. 7621573Srgrimes 7631573Srgrimes struct ParsingClass; 7641573Srgrimes 7651573Srgrimes /// [class.mem]p1: "... the class is regarded as complete within 7661573Srgrimes /// - function bodies 7671573Srgrimes /// - default arguments 7681573Srgrimes /// - exception-specifications (TODO: C++0x) 7691573Srgrimes /// - and brace-or-equal-initializers for non-static data members 77092889Sobrien /// (including such things in nested classes)." 7711573Srgrimes /// LateParsedDeclarations build the tree of those elements so they can 7721573Srgrimes /// be parsed after parsing the top-level class. 7731573Srgrimes class LateParsedDeclaration { 77492889Sobrien public: 77592889Sobrien virtual ~LateParsedDeclaration(); 7761573Srgrimes 77792889Sobrien virtual void ParseLexedMethodDeclarations(); 77892889Sobrien virtual void ParseLexedMemberInitializers(); 77992889Sobrien virtual void ParseLexedMethodDefs(); 7801573Srgrimes virtual void ParseLexedAttributes(); 7811573Srgrimes }; 7821573Srgrimes 7831573Srgrimes /// Inner node of the LateParsedDeclaration tree that parses 7841573Srgrimes /// all its members recursively. 7851573Srgrimes class LateParsedClass : public LateParsedDeclaration { 7861573Srgrimes public: 7871573Srgrimes LateParsedClass(Parser *P, ParsingClass *C); 7881573Srgrimes virtual ~LateParsedClass(); 7891573Srgrimes 7901573Srgrimes virtual void ParseLexedMethodDeclarations(); 7911573Srgrimes virtual void ParseLexedMemberInitializers(); 7921573Srgrimes virtual void ParseLexedMethodDefs(); 7931573Srgrimes virtual void ParseLexedAttributes(); 7941573Srgrimes 7951573Srgrimes private: 7961573Srgrimes Parser *Self; 7971573Srgrimes ParsingClass *Class; 79817141Sjkh }; 7991573Srgrimes 80017141Sjkh /// Contains the lexed tokens of an attribute with arguments that 8011573Srgrimes /// may reference member variables and so need to be parsed at the 80217141Sjkh /// end of the class declaration after parsing all other member 80317141Sjkh /// member declarations. 8041573Srgrimes /// FIXME: Perhaps we should change the name of LateParsedDeclaration to 8051573Srgrimes /// LateParsedTokens. 8061573Srgrimes struct LateParsedAttribute : public LateParsedDeclaration { 80717141Sjkh Parser *Self; 8081573Srgrimes CachedTokens Toks; 80917141Sjkh IdentifierInfo &AttrName; 8101573Srgrimes SourceLocation AttrNameLoc; 81117141Sjkh SmallVector<Decl*, 2> Decls; 81217141Sjkh 8131573Srgrimes explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name, 8141573Srgrimes SourceLocation Loc) 8151573Srgrimes : Self(P), AttrName(Name), AttrNameLoc(Loc) {} 8161573Srgrimes 8171573Srgrimes virtual void ParseLexedAttributes(); 8181573Srgrimes 8191573Srgrimes void addDecl(Decl *D) { Decls.push_back(D); } 8201573Srgrimes }; 8211573Srgrimes 8221573Srgrimes // A list of late-parsed attributes. Used by ParseGNUAttributes. 8231573Srgrimes class LateParsedAttrList: public SmallVector<LateParsedAttribute *, 2> { 8241573Srgrimes public: 8251573Srgrimes LateParsedAttrList(bool PSoon = false) : ParseSoon(PSoon) { } 82617514Sache 82717514Sache bool parseSoon() { return ParseSoon; } 82817514Sache 82924637Sache private: 83024637Sache bool ParseSoon; // Are we planning to parse these shortly after creation? 83124637Sache }; 83217514Sache 83324637Sache /// Contains the lexed tokens of a member function definition 83424637Sache /// which needs to be parsed at the end of the class declaration 83524637Sache /// after parsing all other member declarations. 83624637Sache struct LexedMethod : public LateParsedDeclaration { 83724637Sache Parser *Self; 83824637Sache Decl *D; 83924637Sache CachedTokens Toks; 84024637Sache 84117514Sache /// \brief Whether this member function had an associated template 84217514Sache /// scope. When true, D is a template declaration. 8431573Srgrimes /// otherwise, it is a member function declaration. 8441573Srgrimes bool TemplateScope; 8451573Srgrimes 8461573Srgrimes explicit LexedMethod(Parser* P, Decl *MD) 8471573Srgrimes : Self(P), D(MD), TemplateScope(false) {} 8481573Srgrimes 84992889Sobrien virtual void ParseLexedMethodDefs(); 8501573Srgrimes }; 8511573Srgrimes 8521573Srgrimes /// LateParsedDefaultArgument - Keeps track of a parameter that may 85392889Sobrien /// have a default argument that cannot be parsed yet because it 85492889Sobrien /// occurs within a member function declaration inside the class 8551573Srgrimes /// (C++ [class.mem]p2). 85692889Sobrien struct LateParsedDefaultArgument { 85792889Sobrien explicit LateParsedDefaultArgument(Decl *P, 85892889Sobrien CachedTokens *Toks = 0) 85992889Sobrien : Param(P), Toks(Toks) { } 8601573Srgrimes 86117508Sache /// Param - The parameter declaration for this parameter. 8621573Srgrimes Decl *Param; 8631573Srgrimes 8641573Srgrimes /// Toks - The sequence of tokens that comprises the default 8651573Srgrimes /// argument expression, not including the '=' or the terminating 8661573Srgrimes /// ')' or ','. This will be NULL for parameters that have no 8671573Srgrimes /// default argument. 8681573Srgrimes CachedTokens *Toks; 8691573Srgrimes }; 8701573Srgrimes 8711573Srgrimes /// LateParsedMethodDeclaration - A method declaration inside a class that 8721573Srgrimes /// contains at least one entity whose parsing needs to be delayed 87317508Sache /// until the class itself is completely-defined, such as a default 87417508Sache /// argument (C++ [class.mem]p2). 87517508Sache struct LateParsedMethodDeclaration : public LateParsedDeclaration { 87617508Sache explicit LateParsedMethodDeclaration(Parser *P, Decl *M) 87717508Sache : Self(P), Method(M), TemplateScope(false), ExceptionSpecTokens(0) { } 87817508Sache 87917508Sache virtual void ParseLexedMethodDeclarations(); 88017508Sache 88117508Sache Parser* Self; 88217508Sache 88317508Sache /// Method - The method declaration. 88417508Sache Decl *Method; 88517508Sache 88617508Sache /// \brief Whether this member function had an associated template 88717508Sache /// scope. When true, D is a template declaration. 88817508Sache /// othewise, it is a member function declaration. 88917508Sache bool TemplateScope; 89017508Sache 89117508Sache /// DefaultArgs - Contains the parameters of the function and 89217508Sache /// their default arguments. At least one of the parameters will 89317508Sache /// have a default argument, but all of the parameters of the 89417508Sache /// method will be stored so that they can be reintroduced into 89517508Sache /// scope at the appropriate times. 89617508Sache SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 89717508Sache 89817508Sache /// \brief The set of tokens that make up an exception-specification that 89917508Sache /// has not yet been parsed. 90017508Sache CachedTokens *ExceptionSpecTokens; 90117508Sache }; 90217508Sache 90317508Sache /// LateParsedMemberInitializer - An initializer for a non-static class data 90417508Sache /// member whose parsing must to be delayed until the class is completely 90517508Sache /// defined (C++11 [class.mem]p2). 90617508Sache struct LateParsedMemberInitializer : public LateParsedDeclaration { 90717508Sache LateParsedMemberInitializer(Parser *P, Decl *FD) 90817508Sache : Self(P), Field(FD) { } 90917508Sache 91017508Sache virtual void ParseLexedMemberInitializers(); 91117508Sache 91217508Sache Parser *Self; 91317508Sache 91417508Sache /// Field - The field declaration. 91517508Sache Decl *Field; 91617508Sache 91717508Sache /// CachedTokens - The sequence of tokens that comprises the initializer, 91817508Sache /// including any leading '='. 91917508Sache CachedTokens Toks; 92017508Sache }; 92117508Sache 92217508Sache /// LateParsedDeclarationsContainer - During parsing of a top (non-nested) 92317508Sache /// C++ class, its method declarations that contain parts that won't be 92417508Sache /// parsed until after the definition is completed (C++ [class.mem]p2), 92517508Sache /// the method declarations and possibly attached inline definitions 92617508Sache /// will be stored here with the tokens that will be parsed to create those 92717508Sache /// entities. 92817508Sache typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer; 92917508Sache 93017508Sache /// \brief Representation of a class that has been parsed, including 93117508Sache /// any member function declarations or definitions that need to be 93217508Sache /// parsed after the corresponding top-level class is complete. 93317508Sache struct ParsingClass { 93417508Sache ParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface) 93517508Sache : TopLevelClass(TopLevelClass), TemplateScope(false), 9361573Srgrimes IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { } 9371573Srgrimes 93817508Sache /// \brief Whether this is a "top-level" class, meaning that it is 9391573Srgrimes /// not nested within another class. 9401573Srgrimes bool TopLevelClass : 1; 9411573Srgrimes 9421573Srgrimes /// \brief Whether this class had an associated template 94392889Sobrien /// scope. When true, TagOrTemplate is a template declaration; 9441573Srgrimes /// othewise, it is a tag declaration. 9451573Srgrimes bool TemplateScope : 1; 9461573Srgrimes 9471573Srgrimes /// \brief Whether this class is an __interface. 9481573Srgrimes bool IsInterface : 1; 94992889Sobrien 95092889Sobrien /// \brief The class or class template whose definition we are parsing. 9511573Srgrimes Decl *TagOrTemplate; 95292889Sobrien 9531573Srgrimes /// LateParsedDeclarations - Method declarations, inline definitions and 9541573Srgrimes /// nested classes that contain pieces whose parsing will be delayed until 9551573Srgrimes /// the top-level class is fully defined. 9561573Srgrimes LateParsedDeclarationsContainer LateParsedDeclarations; 9571573Srgrimes }; 9581573Srgrimes 9591573Srgrimes /// \brief The stack of classes that is currently being 96092889Sobrien /// parsed. Nested and local classes will be pushed onto this stack 9611573Srgrimes /// when they are parsed, and removed afterward. 9621573Srgrimes std::stack<ParsingClass *> ClassStack; 9631573Srgrimes 96492889Sobrien ParsingClass &getCurrentClass() { 9651573Srgrimes assert(!ClassStack.empty() && "No lexed method stacks!"); 96692889Sobrien return *ClassStack.top(); 9671573Srgrimes } 96817141Sjkh 9691573Srgrimes /// \brief RAII object used to manage the parsing of a class definition. 9701573Srgrimes class ParsingClassDefinition { 9711573Srgrimes Parser &P; 9721573Srgrimes bool Popped; 9731573Srgrimes Sema::ParsingClassState State; 97417141Sjkh 9751573Srgrimes public: 9761573Srgrimes ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass, 9771573Srgrimes bool IsInterface) 9781573Srgrimes : P(P), Popped(false), 9791573Srgrimes State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) { 98092889Sobrien } 9811573Srgrimes 9821573Srgrimes /// \brief Pop this class of the stack. 9831573Srgrimes void Pop() { 98492889Sobrien assert(!Popped && "Nested class has already been popped"); 9851573Srgrimes Popped = true; 9861573Srgrimes P.PopParsingClass(State); 98792889Sobrien } 98892889Sobrien 98992889Sobrien ~ParsingClassDefinition() { 9901573Srgrimes if (!Popped) 9911573Srgrimes P.PopParsingClass(State); 9921573Srgrimes } 9931573Srgrimes }; 9941573Srgrimes 9951573Srgrimes /// \brief Contains information about any template-specific 9961573Srgrimes /// information that has been parsed prior to parsing declaration 9971573Srgrimes /// specifiers. 9981573Srgrimes struct ParsedTemplateInfo { 9991573Srgrimes ParsedTemplateInfo() 10001573Srgrimes : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 10011573Srgrimes 10021573Srgrimes ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 10031573Srgrimes bool isSpecialization, 10041573Srgrimes bool lastParameterListWasEmpty = false) 10051573Srgrimes : Kind(isSpecialization? ExplicitSpecialization : Template), 10061573Srgrimes TemplateParams(TemplateParams), 10071573Srgrimes LastParameterListWasEmpty(lastParameterListWasEmpty) { } 10081573Srgrimes 10091573Srgrimes explicit ParsedTemplateInfo(SourceLocation ExternLoc, 10101573Srgrimes SourceLocation TemplateLoc) 10111573Srgrimes : Kind(ExplicitInstantiation), TemplateParams(0), 10121573Srgrimes ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 10131573Srgrimes LastParameterListWasEmpty(false){ } 10141573Srgrimes 101549094Sache /// \brief The kind of template we are parsing. 10161573Srgrimes enum { 10171573Srgrimes /// \brief We are not parsing a template at all. 10181573Srgrimes NonTemplate = 0, 10191573Srgrimes /// \brief We are parsing a template declaration. 10201573Srgrimes Template, 10211573Srgrimes /// \brief We are parsing an explicit specialization. 10221573Srgrimes ExplicitSpecialization, 10231573Srgrimes /// \brief We are parsing an explicit instantiation. 10241573Srgrimes ExplicitInstantiation 10251573Srgrimes } Kind; 10261573Srgrimes 102792889Sobrien /// \brief The template parameter lists, for template declarations 10281573Srgrimes /// and explicit specializations. 10291573Srgrimes TemplateParameterLists *TemplateParams; 10301573Srgrimes 10311573Srgrimes /// \brief The location of the 'extern' keyword, if any, for an explicit 10321573Srgrimes /// instantiation 103392889Sobrien SourceLocation ExternLoc; 10341573Srgrimes 10351573Srgrimes /// \brief The location of the 'template' keyword, for an explicit 103692889Sobrien /// instantiation. 103792889Sobrien SourceLocation TemplateLoc; 10381573Srgrimes 10391573Srgrimes /// \brief Whether the last template parameter list was empty. 104049094Sache bool LastParameterListWasEmpty; 10411573Srgrimes 10421573Srgrimes SourceRange getSourceRange() const LLVM_READONLY; 10431573Srgrimes }; 10441573Srgrimes 10451573Srgrimes /// \brief Contains a late templated function. 10461573Srgrimes /// Will be parsed at the end of the translation unit. 10471573Srgrimes struct LateParsedTemplatedFunction { 10481573Srgrimes explicit LateParsedTemplatedFunction(Decl *MD) 10491573Srgrimes : D(MD) {} 10501573Srgrimes 10511573Srgrimes CachedTokens Toks; 10521573Srgrimes 10531573Srgrimes /// \brief The template function declaration to be late parsed. 10541573Srgrimes Decl *D; 105592889Sobrien }; 10561573Srgrimes 10571573Srgrimes void LexTemplateFunctionForLateParsing(CachedTokens &Toks); 10581573Srgrimes void ParseLateTemplatedFuncDef(LateParsedTemplatedFunction &LMT); 105992889Sobrien typedef llvm::DenseMap<const FunctionDecl*, LateParsedTemplatedFunction*> 106092889Sobrien LateParsedTemplateMapT; 10611573Srgrimes LateParsedTemplateMapT LateParsedTemplateMap; 106292889Sobrien 10631573Srgrimes static void LateTemplateParserCallback(void *P, const FunctionDecl *FD); 106449094Sache void LateTemplateParser(const FunctionDecl *FD); 10651573Srgrimes 10661573Srgrimes Sema::ParsingClassState 106749094Sache PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface); 10681573Srgrimes void DeallocateParsedClasses(ParsingClass *Class); 10691573Srgrimes void PopParsingClass(Sema::ParsingClassState); 10701573Srgrimes 10711573Srgrimes NamedDecl *ParseCXXInlineMethodDef(AccessSpecifier AS, 10721573Srgrimes AttributeList *AccessAttrs, 10731573Srgrimes ParsingDeclarator &D, 10741573Srgrimes const ParsedTemplateInfo &TemplateInfo, 107592889Sobrien const VirtSpecifiers& VS, 10761573Srgrimes FunctionDefinitionKind DefinitionKind, 10771573Srgrimes ExprResult& Init); 10781573Srgrimes void ParseCXXNonStaticMemberInitializer(Decl *VarD); 10791573Srgrimes void ParseLexedAttributes(ParsingClass &Class); 10801573Srgrimes void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D, 108192889Sobrien bool EnterScope, bool OnDefinition); 10821573Srgrimes void ParseLexedAttribute(LateParsedAttribute &LA, 108392889Sobrien bool EnterScope, bool OnDefinition); 108492889Sobrien void ParseLexedMethodDeclarations(ParsingClass &Class); 10851573Srgrimes void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); 10861573Srgrimes void ParseLexedMethodDefs(ParsingClass &Class); 10871573Srgrimes void ParseLexedMethodDef(LexedMethod &LM); 10881573Srgrimes void ParseLexedMemberInitializers(ParsingClass &Class); 10891573Srgrimes void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI); 10901573Srgrimes void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod); 10911573Srgrimes bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks); 10921573Srgrimes bool ConsumeAndStoreUntil(tok::TokenKind T1, 10931573Srgrimes CachedTokens &Toks, 10941573Srgrimes bool StopAtSemi = true, 10951573Srgrimes bool ConsumeFinalToken = true) { 10961573Srgrimes return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); 10971573Srgrimes } 10981573Srgrimes bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 10991573Srgrimes CachedTokens &Toks, 11001573Srgrimes bool StopAtSemi = true, 110192889Sobrien bool ConsumeFinalToken = true); 11021573Srgrimes 11031573Srgrimes //===--------------------------------------------------------------------===// 11041573Srgrimes // C99 6.9: External Definitions. 110592889Sobrien struct ParsedAttributesWithRange : ParsedAttributes { 11061573Srgrimes ParsedAttributesWithRange(AttributeFactory &factory) 11071573Srgrimes : ParsedAttributes(factory) {} 11081573Srgrimes 11091573Srgrimes SourceRange Range; 111092889Sobrien }; 11111573Srgrimes 11121573Srgrimes DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs, 11131573Srgrimes ParsingDeclSpec *DS = 0); 11141573Srgrimes bool isDeclarationAfterDeclarator(); 111592889Sobrien bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); 11161573Srgrimes DeclGroupPtrTy ParseDeclarationOrFunctionDefinition( 11171573Srgrimes ParsedAttributesWithRange &attrs, 11181573Srgrimes ParsingDeclSpec *DS = 0, 11191573Srgrimes AccessSpecifier AS = AS_none); 11201573Srgrimes DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs, 11211573Srgrimes ParsingDeclSpec &DS, 11221573Srgrimes AccessSpecifier AS); 11231573Srgrimes 11241573Srgrimes Decl *ParseFunctionDefinition(ParsingDeclarator &D, 11251573Srgrimes const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 11261573Srgrimes LateParsedAttrList *LateParsedAttrs = 0); 11271573Srgrimes void ParseKNRParamDeclarations(Declarator &D); 11281573Srgrimes // EndLoc, if non-NULL, is filled with the location of the last token of 11291573Srgrimes // the simple-asm. 11301573Srgrimes ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 11311573Srgrimes ExprResult ParseAsmStringLiteral(); 11321573Srgrimes 11331573Srgrimes // Objective-C External Declarations 11341573Srgrimes void MaybeSkipAttributes(tok::ObjCKeywordKind Kind); 11351573Srgrimes DeclGroupPtrTy ParseObjCAtDirectives(); 11361573Srgrimes DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); 11371573Srgrimes Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, 11381573Srgrimes ParsedAttributes &prefixAttrs); 11391573Srgrimes void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc, 11401573Srgrimes BalancedDelimiterTracker &T, 11411573Srgrimes SmallVectorImpl<Decl *> &AllIvarDecls, 11421573Srgrimes bool RBraceMissing); 11431573Srgrimes void ParseObjCClassInstanceVariables(Decl *interfaceDecl, 11441573Srgrimes tok::ObjCKeywordKind visibility, 11451573Srgrimes SourceLocation atLoc); 11461573Srgrimes bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P, 11471573Srgrimes SmallVectorImpl<SourceLocation> &PLocs, 11481573Srgrimes bool WarnOnDeclarations, 11491573Srgrimes SourceLocation &LAngleLoc, 11501573Srgrimes SourceLocation &EndProtoLoc); 11511573Srgrimes bool ParseObjCProtocolQualifiers(DeclSpec &DS); 11521573Srgrimes void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, 11531573Srgrimes Decl *CDecl); 11541573Srgrimes DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 11551573Srgrimes ParsedAttributes &prefixAttrs); 11561573Srgrimes 11571573Srgrimes struct ObjCImplParsingDataRAII { 11581573Srgrimes Parser &P; 11591573Srgrimes Decl *Dcl; 11601573Srgrimes bool HasCFunction; 11611573Srgrimes typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer; 11621573Srgrimes LateParsedObjCMethodContainer LateParsedObjCMethods; 11631573Srgrimes 11641573Srgrimes ObjCImplParsingDataRAII(Parser &parser, Decl *D) 11651573Srgrimes : P(parser), Dcl(D), HasCFunction(false) { 11661573Srgrimes P.CurParsedObjCImpl = this; 11671573Srgrimes Finished = false; 11681573Srgrimes } 11691573Srgrimes ~ObjCImplParsingDataRAII(); 11701573Srgrimes 11711573Srgrimes void finish(SourceRange AtEnd); 11721573Srgrimes bool isFinished() const { return Finished; } 117392889Sobrien 11741573Srgrimes private: 11751573Srgrimes bool Finished; 11761573Srgrimes }; 117792889Sobrien ObjCImplParsingDataRAII *CurParsedObjCImpl; 11781573Srgrimes void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl); 11791573Srgrimes 11801573Srgrimes DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc); 11811573Srgrimes DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); 11821573Srgrimes Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); 11831573Srgrimes Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); 11841573Srgrimes Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); 11851573Srgrimes 11861573Srgrimes IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 11871573Srgrimes // Definitions for Objective-c context sensitive keywords recognition. 11881573Srgrimes enum ObjCTypeQual { 118992889Sobrien objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 11901573Srgrimes objc_NumQuals 11911573Srgrimes }; 11921573Srgrimes IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 119392889Sobrien 11941573Srgrimes bool isTokIdentifier_in() const; 119592889Sobrien 119692889Sobrien ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx, 119792889Sobrien ParsedAttributes *ParamAttrs); 119892889Sobrien void ParseObjCMethodRequirement(); 119992889Sobrien Decl *ParseObjCMethodPrototype( 120092889Sobrien tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 12011573Srgrimes bool MethodDefinition = true); 12021573Srgrimes Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 12031573Srgrimes tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 12041573Srgrimes bool MethodDefinition=true); 12051573Srgrimes void ParseObjCPropertyAttribute(ObjCDeclSpec &DS); 12061573Srgrimes 12071573Srgrimes Decl *ParseObjCMethodDefinition(); 12081573Srgrimes 12091573Srgrimespublic: 121039327Simp //===--------------------------------------------------------------------===// 12111573Srgrimes // C99 6.5: Expressions. 12121573Srgrimes 12131573Srgrimes /// TypeCastState - State whether an expression is or may be a type cast. 12141573Srgrimes enum TypeCastState { 121539327Simp NotTypeCast = 0, 12161573Srgrimes MaybeTypeCast, 12171573Srgrimes IsTypeCast 12181573Srgrimes }; 12191573Srgrimes 12201573Srgrimes ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast); 12211573Srgrimes ExprResult ParseConstantExpression(TypeCastState isTypeCast = NotTypeCast); 12221573Srgrimes // Expr that doesn't include commas. 12231573Srgrimes ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast); 12241573Srgrimes 12251573Srgrimes ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl<Token> &LineToks, 12261573Srgrimes unsigned &NumLineToksConsumed, 12271573Srgrimes void *Info, 12281573Srgrimes bool IsUnevaluated); 12291573Srgrimes 12301573Srgrimesprivate: 12311573Srgrimes ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 12321573Srgrimes 12331573Srgrimes ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 12341573Srgrimes 12351573Srgrimes ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, 12361573Srgrimes prec::Level MinPrec); 12371573Srgrimes ExprResult ParseCastExpression(bool isUnaryExpression, 12381573Srgrimes bool isAddressOfOperand, 12391573Srgrimes bool &NotCastExpr, 12401573Srgrimes TypeCastState isTypeCast); 12411573Srgrimes ExprResult ParseCastExpression(bool isUnaryExpression, 12421573Srgrimes bool isAddressOfOperand = false, 12431573Srgrimes TypeCastState isTypeCast = NotTypeCast); 124492889Sobrien 12451573Srgrimes /// Returns true if the next token cannot start an expression. 12461573Srgrimes bool isNotExpressionStart(); 12471573Srgrimes 124892889Sobrien /// Returns true if the next token would start a postfix-expression 124992889Sobrien /// suffix. 12501573Srgrimes bool isPostfixExpressionSuffixStart() { 125192889Sobrien tok::TokenKind K = Tok.getKind(); 125292889Sobrien return (K == tok::l_square || K == tok::l_paren || 125392889Sobrien K == tok::period || K == tok::arrow || 12541573Srgrimes K == tok::plusplus || K == tok::minusminus); 12551573Srgrimes } 12561573Srgrimes 12571573Srgrimes ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); 12581573Srgrimes ExprResult ParseUnaryExprOrTypeTraitExpression(); 12591573Srgrimes ExprResult ParseBuiltinPrimaryExpression(); 12601573Srgrimes 12611573Srgrimes ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, 12621573Srgrimes bool &isCastExpr, 126392889Sobrien ParsedType &CastTy, 12641573Srgrimes SourceRange &CastRange); 12651573Srgrimes 12661573Srgrimes typedef SmallVector<Expr*, 20> ExprListTy; 12671573Srgrimes typedef SmallVector<SourceLocation, 20> CommaLocsTy; 12681573Srgrimes 12691573Srgrimes /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 12701573Srgrimes bool ParseExpressionList(SmallVectorImpl<Expr*> &Exprs, 12711573Srgrimes SmallVectorImpl<SourceLocation> &CommaLocs, 12721573Srgrimes void (Sema::*Completer)(Scope *S, 127392889Sobrien Expr *Data, 127492889Sobrien ArrayRef<Expr *> Args) = 0, 12751573Srgrimes Expr *Data = 0); 127692889Sobrien 127792889Sobrien /// ParenParseOption - Control what ParseParenExpression will parse. 127892889Sobrien enum ParenParseOption { 127992889Sobrien SimpleExpr, // Only parse '(' expression ')' 128092889Sobrien CompoundStmt, // Also allow '(' compound-statement ')' 12811573Srgrimes CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 12821573Srgrimes CastExpr // Also allow '(' type-name ')' <anything> 12831573Srgrimes }; 12841573Srgrimes ExprResult ParseParenExpression(ParenParseOption &ExprType, 12851573Srgrimes bool stopIfCastExpr, 12861573Srgrimes bool isTypeCast, 12871573Srgrimes ParsedType &CastTy, 12881573Srgrimes SourceLocation &RParenLoc); 12891573Srgrimes 12901573Srgrimes ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 12911573Srgrimes ParsedType &CastTy, 12921573Srgrimes BalancedDelimiterTracker &Tracker); 12931573Srgrimes ExprResult ParseCompoundLiteralExpression(ParsedType Ty, 12941573Srgrimes SourceLocation LParenLoc, 12951573Srgrimes SourceLocation RParenLoc); 12961573Srgrimes 12971573Srgrimes ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false); 12981573Srgrimes 12991573Srgrimes ExprResult ParseGenericSelectionExpression(); 13001573Srgrimes 13011573Srgrimes ExprResult ParseObjCBoolLiteral(); 13021573Srgrimes 130392889Sobrien //===--------------------------------------------------------------------===// 13041573Srgrimes // C++ Expressions 13051573Srgrimes ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 13061573Srgrimes 130792889Sobrien bool areTokensAdjacent(const Token &A, const Token &B); 130892889Sobrien 13091573Srgrimes void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr, 131092889Sobrien bool EnteringContext, IdentifierInfo &II, 131192889Sobrien CXXScopeSpec &SS); 13121573Srgrimes 13131573Srgrimes bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 13141573Srgrimes ParsedType ObjectType, 131549094Sache bool EnteringContext, 13161573Srgrimes bool *MayBePseudoDestructor = 0, 13171573Srgrimes bool IsTypename = false, 13181573Srgrimes IdentifierInfo **LastII = 0); 13191573Srgrimes 13201573Srgrimes void CheckForLParenAfterColonColon(); 13211573Srgrimes 132292889Sobrien //===--------------------------------------------------------------------===// 13231573Srgrimes // C++0x 5.1.2: Lambda expressions 13241573Srgrimes 13251573Srgrimes // [...] () -> type {...} 132692889Sobrien ExprResult ParseLambdaExpression(); 132792889Sobrien ExprResult TryParseLambdaExpression(); 13281573Srgrimes Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro); 132992889Sobrien bool TryParseLambdaIntroducer(LambdaIntroducer &Intro); 133092889Sobrien ExprResult ParseLambdaExpressionAfterIntroducer( 133192889Sobrien LambdaIntroducer &Intro); 13321573Srgrimes 13331573Srgrimes //===--------------------------------------------------------------------===// 13341573Srgrimes // C++ 5.2p1: C++ Casts 13351573Srgrimes ExprResult ParseCXXCasts(); 13361573Srgrimes 13371573Srgrimes //===--------------------------------------------------------------------===// 13381573Srgrimes // C++ 5.2p1: C++ Type Identification 13391573Srgrimes ExprResult ParseCXXTypeid(); 13401573Srgrimes 134192889Sobrien //===--------------------------------------------------------------------===// 134292889Sobrien // C++ : Microsoft __uuidof Expression 13431573Srgrimes ExprResult ParseCXXUuidof(); 13441573Srgrimes 13451573Srgrimes //===--------------------------------------------------------------------===// 134692889Sobrien // C++ 5.2.4: C++ Pseudo-Destructor Expressions 134792889Sobrien ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 134892889Sobrien tok::TokenKind OpKind, 13491573Srgrimes CXXScopeSpec &SS, 135092889Sobrien ParsedType ObjectType); 13511573Srgrimes 13521573Srgrimes //===--------------------------------------------------------------------===// 13531573Srgrimes // C++ 9.3.2: C++ 'this' pointer 13541573Srgrimes ExprResult ParseCXXThis(); 13551573Srgrimes 135639327Simp //===--------------------------------------------------------------------===// 13571573Srgrimes // C++ 15: C++ Throw Expression 13581573Srgrimes ExprResult ParseThrowExpression(); 13591573Srgrimes 13601573Srgrimes ExceptionSpecificationType tryParseExceptionSpecification( 13611573Srgrimes SourceRange &SpecificationRange, 13621573Srgrimes SmallVectorImpl<ParsedType> &DynamicExceptions, 13631573Srgrimes SmallVectorImpl<SourceRange> &DynamicExceptionRanges, 13641573Srgrimes ExprResult &NoexceptExpr); 13651573Srgrimes 136617141Sjkh // EndLoc is filled with the location of the last token of the specification. 13671573Srgrimes ExceptionSpecificationType ParseDynamicExceptionSpecification( 13681573Srgrimes SourceRange &SpecificationRange, 136992889Sobrien SmallVectorImpl<ParsedType> &Exceptions, 13701573Srgrimes SmallVectorImpl<SourceRange> &Ranges); 13711573Srgrimes 13721573Srgrimes //===--------------------------------------------------------------------===// 137392889Sobrien // C++0x 8: Function declaration trailing-return-type 137492889Sobrien TypeResult ParseTrailingReturnType(SourceRange &Range); 13751573Srgrimes 137692889Sobrien //===--------------------------------------------------------------------===// 137792889Sobrien // C++ 2.13.5: C++ Boolean Literals 13781573Srgrimes ExprResult ParseCXXBoolLiteral(); 13791573Srgrimes 13801573Srgrimes //===--------------------------------------------------------------------===// 13811573Srgrimes // C++ 5.2.3: Explicit type conversion (functional notation) 13821573Srgrimes ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 13831573Srgrimes 13841573Srgrimes /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 13851573Srgrimes /// This should only be called when the current token is known to be part of 13861573Srgrimes /// simple-type-specifier. 13871573Srgrimes void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 13881573Srgrimes 13891573Srgrimes bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 139039327Simp 13911573Srgrimes //===--------------------------------------------------------------------===// 13921573Srgrimes // C++ 5.3.4 and 5.3.5: C++ new and delete 13931573Srgrimes bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs, 13941573Srgrimes Declarator &D); 13951573Srgrimes void ParseDirectNewDeclarator(Declarator &D); 139692889Sobrien ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 13971573Srgrimes ExprResult ParseCXXDeleteExpression(bool UseGlobal, 13981573Srgrimes SourceLocation Start); 13991573Srgrimes 140092889Sobrien //===--------------------------------------------------------------------===// 140192889Sobrien // C++ if/switch/while condition expression. 14021573Srgrimes bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult, 14031573Srgrimes SourceLocation Loc, bool ConvertToBoolean); 14041573Srgrimes 14051573Srgrimes //===--------------------------------------------------------------------===// 14061573Srgrimes // C++ types 14071573Srgrimes 140892889Sobrien //===--------------------------------------------------------------------===// 14091573Srgrimes // C99 6.7.8: Initialization. 14101573Srgrimes 14111573Srgrimes /// ParseInitializer 141292889Sobrien /// initializer: [C99 6.7.8] 141392889Sobrien /// assignment-expression 14141573Srgrimes /// '{' ... 141592889Sobrien ExprResult ParseInitializer() { 14161573Srgrimes if (Tok.isNot(tok::l_brace)) 14171573Srgrimes return ParseAssignmentExpression(); 14181573Srgrimes return ParseBraceInitializer(); 14191573Srgrimes } 14201573Srgrimes bool MayBeDesignationStart(); 14211573Srgrimes ExprResult ParseBraceInitializer(); 14221573Srgrimes ExprResult ParseInitializerWithPotentialDesignator(); 14231573Srgrimes 142417141Sjkh //===--------------------------------------------------------------------===// 14251573Srgrimes // clang Expressions 14261573Srgrimes 14271573Srgrimes ExprResult ParseBlockLiteralExpression(); // ^{...} 142892889Sobrien 14291573Srgrimes //===--------------------------------------------------------------------===// 14301573Srgrimes // Objective-C Expressions 14311573Srgrimes ExprResult ParseObjCAtExpression(SourceLocation AtLocation); 14321573Srgrimes ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 14331573Srgrimes ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc); 14341573Srgrimes ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc); 143592889Sobrien ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc, bool ArgValue); 143692889Sobrien ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc); 14371573Srgrimes ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc); 14381573Srgrimes ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc); 14391573Srgrimes ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 14401573Srgrimes ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 14411573Srgrimes ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 14421573Srgrimes bool isSimpleObjCMessageExpression(); 144392889Sobrien ExprResult ParseObjCMessageExpression(); 14441573Srgrimes ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 14451573Srgrimes SourceLocation SuperLoc, 14461573Srgrimes ParsedType ReceiverType, 14471573Srgrimes ExprArg ReceiverExpr); 14481573Srgrimes ExprResult ParseAssignmentExprWithObjCMessageExprStart( 14491573Srgrimes SourceLocation LBracloc, SourceLocation SuperLoc, 145092889Sobrien ParsedType ReceiverType, ExprArg ReceiverExpr); 145192889Sobrien bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); 14521573Srgrimes 14531573Srgrimes //===--------------------------------------------------------------------===// 14541573Srgrimes // C99 6.8: Statements and Blocks. 14551573Srgrimes 14561573Srgrimes /// A SmallVector of statements, with stack size 32 (as that is the only one 14571573Srgrimes /// used.) 145892889Sobrien typedef SmallVector<Stmt*, 32> StmtVector; 14591573Srgrimes /// A SmallVector of expressions, with stack size 12 (the maximum used.) 14601573Srgrimes typedef SmallVector<Expr*, 12> ExprVector; 14611573Srgrimes /// A SmallVector of types. 146292889Sobrien typedef SmallVector<ParsedType, 12> TypeVector; 14631573Srgrimes 14641573Srgrimes StmtResult ParseStatement(SourceLocation *TrailingElseLoc = 0) { 146592889Sobrien StmtVector Stmts; 146692889Sobrien return ParseStatementOrDeclaration(Stmts, true, TrailingElseLoc); 146792889Sobrien } 146892889Sobrien StmtResult ParseStatementOrDeclaration(StmtVector &Stmts, 14691573Srgrimes bool OnlyStatement, 14701573Srgrimes SourceLocation *TrailingElseLoc = 0); 14711573Srgrimes StmtResult ParseStatementOrDeclarationAfterAttributes( 14721573Srgrimes StmtVector &Stmts, 14731573Srgrimes bool OnlyStatement, 14741573Srgrimes SourceLocation *TrailingElseLoc, 14751573Srgrimes ParsedAttributesWithRange &Attrs); 14761573Srgrimes StmtResult ParseExprStatement(); 14771573Srgrimes StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs); 147892889Sobrien StmtResult ParseCaseStatement(bool MissingCase = false, 14791573Srgrimes ExprResult Expr = ExprResult()); 14801573Srgrimes StmtResult ParseDefaultStatement(); 14811573Srgrimes StmtResult ParseCompoundStatement(bool isStmtExpr = false); 148292889Sobrien StmtResult ParseCompoundStatement(bool isStmtExpr, 14831573Srgrimes unsigned ScopeFlags); 14841573Srgrimes void ParseCompoundStatementLeadingPragmas(); 14851573Srgrimes StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 148692889Sobrien bool ParseParenExprOrCondition(ExprResult &ExprResult, 148792889Sobrien Decl *&DeclResult, 148892889Sobrien SourceLocation Loc, 148992889Sobrien bool ConvertToBoolean); 149092889Sobrien StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc); 14911573Srgrimes StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc); 14921573Srgrimes StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc); 14931573Srgrimes StmtResult ParseDoStatement(); 14941573Srgrimes StmtResult ParseForStatement(SourceLocation *TrailingElseLoc); 14951573Srgrimes StmtResult ParseGotoStatement(); 14961573Srgrimes StmtResult ParseContinueStatement(); 14971573Srgrimes StmtResult ParseBreakStatement(); 14981573Srgrimes StmtResult ParseReturnStatement(); 14991573Srgrimes StmtResult ParseAsmStatement(bool &msAsm); 150092889Sobrien StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc); 15011573Srgrimes 15021573Srgrimes /// \brief Describes the behavior that should be taken for an __if_exists 15031573Srgrimes /// block. 15041573Srgrimes enum IfExistsBehavior { 150592889Sobrien /// \brief Parse the block; this code is always used. 15061573Srgrimes IEB_Parse, 150792889Sobrien /// \brief Skip the block entirely; this code is never used. 150892889Sobrien IEB_Skip, 150992889Sobrien /// \brief Parse the block as a dependent block, which may be used in 151092889Sobrien /// some template instantiations but not others. 15111573Srgrimes IEB_Dependent 15121573Srgrimes }; 15131573Srgrimes 15141573Srgrimes /// \brief Describes the condition of a Microsoft __if_exists or 15151573Srgrimes /// __if_not_exists block. 15161573Srgrimes struct IfExistsCondition { 15171573Srgrimes /// \brief The location of the initial keyword. 15181573Srgrimes SourceLocation KeywordLoc; 15191573Srgrimes /// \brief Whether this is an __if_exists block (rather than an 15201573Srgrimes /// __if_not_exists block). 15211573Srgrimes bool IsIfExists; 15221573Srgrimes 15231573Srgrimes /// \brief Nested-name-specifier preceding the name. 15241573Srgrimes CXXScopeSpec SS; 15251573Srgrimes 15261573Srgrimes /// \brief The name we're looking for. 15271573Srgrimes UnqualifiedId Name; 152892889Sobrien 15291573Srgrimes /// \brief The behavior of this __if_exists or __if_not_exists block 15301573Srgrimes /// should. 15311573Srgrimes IfExistsBehavior Behavior; 153292889Sobrien }; 15331573Srgrimes 15341573Srgrimes bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result); 15351573Srgrimes void ParseMicrosoftIfExistsStatement(StmtVector &Stmts); 153692889Sobrien void ParseMicrosoftIfExistsExternalDeclaration(); 153792889Sobrien void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, 15381573Srgrimes AccessSpecifier& CurAS); 15391573Srgrimes bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, 15401573Srgrimes bool &InitExprsOk); 15411573Srgrimes bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names, 15421573Srgrimes SmallVectorImpl<Expr *> &Constraints, 15431573Srgrimes SmallVectorImpl<Expr *> &Exprs); 15441573Srgrimes 15451573Srgrimes //===--------------------------------------------------------------------===// 15461573Srgrimes // C++ 6: Statements and Blocks 15471573Srgrimes 15481573Srgrimes StmtResult ParseCXXTryBlock(); 15491573Srgrimes StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry = false); 15501573Srgrimes StmtResult ParseCXXCatchBlock(bool FnCatch = false); 15511573Srgrimes 155292889Sobrien //===--------------------------------------------------------------------===// 15531573Srgrimes // MS: SEH Statements and Blocks 15541573Srgrimes 15551573Srgrimes StmtResult ParseSEHTryBlock(); 15561573Srgrimes StmtResult ParseSEHTryBlockCommon(SourceLocation Loc); 15571573Srgrimes StmtResult ParseSEHExceptBlock(SourceLocation Loc); 15581573Srgrimes StmtResult ParseSEHFinallyBlock(SourceLocation Loc); 15591573Srgrimes 156092889Sobrien //===--------------------------------------------------------------------===// 15611573Srgrimes // Objective-C Statements 15621573Srgrimes 15631573Srgrimes StmtResult ParseObjCAtStatement(SourceLocation atLoc); 15641573Srgrimes StmtResult ParseObjCTryStmt(SourceLocation atLoc); 15651573Srgrimes StmtResult ParseObjCThrowStmt(SourceLocation atLoc); 15661573Srgrimes StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 15671573Srgrimes StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc); 15681573Srgrimes 15691573Srgrimes 15701573Srgrimes //===--------------------------------------------------------------------===// 15711573Srgrimes // C99 6.7: Declarations. 15721573Srgrimes 15731573Srgrimes /// A context for parsing declaration specifiers. TODO: flesh this 15741573Srgrimes /// out, there are other significant restrictions on specifiers than 15751573Srgrimes /// would be best implemented in the parser. 15761573Srgrimes enum DeclSpecContext { 15771573Srgrimes DSC_normal, // normal context 15781573Srgrimes DSC_class, // class context, enables 'friend' 15791573Srgrimes DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list 15801573Srgrimes DSC_trailing, // C++11 trailing-type-specifier in a trailing return type 15811573Srgrimes DSC_top_level // top-level/namespace declaration context 158292889Sobrien }; 15831573Srgrimes 15841573Srgrimes /// Information on a C++0x for-range-initializer found while parsing a 15851573Srgrimes /// declaration which turns out to be a for-range-declaration. 158692889Sobrien struct ForRangeInit { 15871573Srgrimes SourceLocation ColonLoc; 15881573Srgrimes ExprResult RangeExpr; 15891573Srgrimes 15901573Srgrimes bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); } 159192889Sobrien }; 159292889Sobrien 159392889Sobrien DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts, 15941573Srgrimes unsigned Context, SourceLocation &DeclEnd, 15951573Srgrimes ParsedAttributesWithRange &attrs); 15961573Srgrimes DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts, 15971573Srgrimes unsigned Context, 15981573Srgrimes SourceLocation &DeclEnd, 15991573Srgrimes ParsedAttributesWithRange &attrs, 16001573Srgrimes bool RequireSemi, 16011573Srgrimes ForRangeInit *FRI = 0); 16021573Srgrimes bool MightBeDeclarator(unsigned Context); 16031573Srgrimes DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 16041573Srgrimes bool AllowFunctionDefinitions, 16051573Srgrimes SourceLocation *DeclEnd = 0, 16061573Srgrimes ForRangeInit *FRI = 0); 16071573Srgrimes Decl *ParseDeclarationAfterDeclarator(Declarator &D, 16081573Srgrimes const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 16091573Srgrimes bool ParseAsmAttributesAfterDeclarator(Declarator &D); 16101573Srgrimes Decl *ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D, 16111573Srgrimes const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 16121573Srgrimes Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope); 16131573Srgrimes Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope); 16141573Srgrimes 16151573Srgrimes /// \brief When in code-completion, skip parsing of the function/method body 16161573Srgrimes /// unless the body contains the code-completion point. 16171573Srgrimes /// 16181573Srgrimes /// \returns true if the function body was skipped. 16191573Srgrimes bool trySkippingFunctionBody(); 16201573Srgrimes 16211573Srgrimes bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 162292889Sobrien const ParsedTemplateInfo &TemplateInfo, 16231573Srgrimes AccessSpecifier AS, DeclSpecContext DSC, 16241573Srgrimes ParsedAttributesWithRange &Attrs); 16251573Srgrimes DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 162692889Sobrien void ParseDeclarationSpecifiers(DeclSpec &DS, 162792889Sobrien const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 16281573Srgrimes AccessSpecifier AS = AS_none, 16291573Srgrimes DeclSpecContext DSC = DSC_normal, 16301573Srgrimes LateParsedAttrList *LateAttrs = 0); 16311573Srgrimes 16321573Srgrimes void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none, 16331573Srgrimes DeclSpecContext DSC = DSC_normal); 16341573Srgrimes 16351573Srgrimes void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, 16361573Srgrimes Declarator::TheContext Context); 16371573Srgrimes 16381573Srgrimes void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 16391573Srgrimes const ParsedTemplateInfo &TemplateInfo, 164092889Sobrien AccessSpecifier AS, DeclSpecContext DSC); 16411573Srgrimes void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); 16421573Srgrimes void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 16431573Srgrimes Decl *TagDecl); 164492889Sobrien 164592889Sobrien struct FieldCallback { 16461573Srgrimes virtual void invoke(ParsingFieldDeclarator &Field) = 0; 164792889Sobrien virtual ~FieldCallback() {} 16481573Srgrimes 16491573Srgrimes private: 16501573Srgrimes virtual void _anchor(); 16511573Srgrimes }; 16521573Srgrimes struct ObjCPropertyCallback; 16531573Srgrimes 16541573Srgrimes void ParseStructDeclaration(ParsingDeclSpec &DS, FieldCallback &Callback); 16551573Srgrimes 16561573Srgrimes bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false); 16571573Srgrimes bool isTypeSpecifierQualifier(); 16581573Srgrimes bool isTypeQualifier() const; 16591573Srgrimes 16601573Srgrimes /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 16611573Srgrimes /// is definitely a type-specifier. Return false if it isn't part of a type 16621573Srgrimes /// specifier or if we're not sure. 166392889Sobrien bool isKnownToBeTypeSpecifier(const Token &Tok) const; 16641573Srgrimes 16651573Srgrimes /// \brief Return true if we know that we are definitely looking at a 16661573Srgrimes /// decl-specifier, and isn't part of an expression such as a function-style 166792889Sobrien /// cast. Return false if it's no a decl-specifier, or we're not sure. 166892889Sobrien bool isKnownToBeDeclarationSpecifier() { 16691573Srgrimes if (getLangOpts().CPlusPlus) 16701573Srgrimes return isCXXDeclarationSpecifier() == TPResult::True(); 16711573Srgrimes return isDeclarationSpecifier(true); 16721573Srgrimes } 16731573Srgrimes 16741573Srgrimes /// isDeclarationStatement - Disambiguates between a declaration or an 16751573Srgrimes /// expression statement, when parsing function bodies. 16761573Srgrimes /// Returns true for declaration, false for expression. 16771573Srgrimes bool isDeclarationStatement() { 16781573Srgrimes if (getLangOpts().CPlusPlus) 16791573Srgrimes return isCXXDeclarationStatement(); 168092889Sobrien return isDeclarationSpecifier(true); 16811573Srgrimes } 16821573Srgrimes 16831573Srgrimes /// isForInitDeclaration - Disambiguates between a declaration or an 16841573Srgrimes /// expression in the context of the C 'clause-1' or the C++ 16851573Srgrimes // 'for-init-statement' part of a 'for' statement. 16861573Srgrimes /// Returns true for declaration, false for expression. 16871573Srgrimes bool isForInitDeclaration() { 16881573Srgrimes if (getLangOpts().CPlusPlus) 16891573Srgrimes return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/true); 16901573Srgrimes return isDeclarationSpecifier(true); 169192889Sobrien } 16921573Srgrimes 169392889Sobrien /// \brief Determine whether we are currently at the start of an Objective-C 16941573Srgrimes /// class message that appears to be missing the open bracket '['. 169592889Sobrien bool isStartOfObjCClassMessageMissingOpenBracket(); 169692889Sobrien 169792889Sobrien /// \brief Starting with a scope specifier, identifier, or 169892889Sobrien /// template-id that refers to the current class, determine whether 169992889Sobrien /// this is a constructor declarator. 170062391Sdcs bool isConstructorDeclarator(); 170162391Sdcs 17021573Srgrimes /// \brief Specifies the context in which type-id/expression 17031573Srgrimes /// disambiguation will occur. 17041573Srgrimes enum TentativeCXXTypeIdContext { 17051573Srgrimes TypeIdInParens, 17061573Srgrimes TypeIdAsTemplateArgument 170762391Sdcs }; 170862391Sdcs 170962391Sdcs 171062391Sdcs /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 171162391Sdcs /// whether the parens contain an expression or a type-id. 171262391Sdcs /// Returns true for a type-id and false for an expression. 17131573Srgrimes bool isTypeIdInParens(bool &isAmbiguous) { 17141573Srgrimes if (getLangOpts().CPlusPlus) 171562391Sdcs return isCXXTypeId(TypeIdInParens, isAmbiguous); 171662391Sdcs isAmbiguous = false; 17171573Srgrimes return isTypeSpecifierQualifier(); 17181573Srgrimes } 17191573Srgrimes bool isTypeIdInParens() { 17201573Srgrimes bool isAmbiguous; 17211573Srgrimes return isTypeIdInParens(isAmbiguous); 17221573Srgrimes } 17231573Srgrimes 17241573Srgrimes /// isCXXDeclarationStatement - C++-specialized function that disambiguates 17251573Srgrimes /// between a declaration or an expression statement, when parsing function 17261573Srgrimes /// bodies. Returns true for declaration, false for expression. 17271573Srgrimes bool isCXXDeclarationStatement(); 17281573Srgrimes 17291573Srgrimes /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 17301573Srgrimes /// between a simple-declaration or an expression-statement. 17311573Srgrimes /// If during the disambiguation process a parsing error is encountered, 173262391Sdcs /// the function returns true to let the declaration parsing code handle it. 17331573Srgrimes /// Returns false if the statement is disambiguated as expression. 17341573Srgrimes bool isCXXSimpleDeclaration(bool AllowForRangeDecl); 17351573Srgrimes 17361573Srgrimes /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 17371573Srgrimes /// a constructor-style initializer, when parsing declaration statements. 17381573Srgrimes /// Returns true for function declarator and false for constructor-style 17391573Srgrimes /// initializer. Sets 'IsAmbiguous' to true to indicate that this declaration 17401573Srgrimes /// might be a constructor-style initializer. 17411573Srgrimes /// If during the disambiguation process a parsing error is encountered, 17421573Srgrimes /// the function returns true to let the declaration parsing code handle it. 17431573Srgrimes bool isCXXFunctionDeclarator(bool *IsAmbiguous = 0); 1744102411Scharnier 174562391Sdcs /// isCXXConditionDeclaration - Disambiguates between a declaration or an 174662391Sdcs /// expression for a condition of a if/switch/while/for statement. 174762391Sdcs /// If during the disambiguation process a parsing error is encountered, 174862391Sdcs /// the function returns true to let the declaration parsing code handle it. 174962391Sdcs bool isCXXConditionDeclaration(); 175062391Sdcs 175162391Sdcs bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 17521573Srgrimes bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 17531573Srgrimes bool isAmbiguous; 17541573Srgrimes return isCXXTypeId(Context, isAmbiguous); 175562391Sdcs } 175662391Sdcs 175762391Sdcs /// TPResult - Used as the result value for functions whose purpose is to 175862391Sdcs /// disambiguate C++ constructs by "tentatively parsing" them. 175962391Sdcs /// This is a class instead of a simple enum because the implicit enum-to-bool 176062391Sdcs /// conversions may cause subtle bugs. 176162391Sdcs class TPResult { 176262391Sdcs enum Result { 17631573Srgrimes TPR_true, 17641573Srgrimes TPR_false, 17651573Srgrimes TPR_ambiguous, 176662391Sdcs TPR_error 176762391Sdcs }; 176862391Sdcs Result Res; 176962391Sdcs TPResult(Result result) : Res(result) {} 177062391Sdcs public: 177162391Sdcs static TPResult True() { return TPR_true; } 177262391Sdcs static TPResult False() { return TPR_false; } 177362391Sdcs static TPResult Ambiguous() { return TPR_ambiguous; } 177462391Sdcs static TPResult Error() { return TPR_error; } 177562391Sdcs 177662391Sdcs bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 177762391Sdcs bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 177862391Sdcs }; 177962391Sdcs 178062391Sdcs /// \brief Based only on the given token kind, determine whether we know that 178162391Sdcs /// we're at the start of an expression or a type-specifier-seq (which may 178262391Sdcs /// be an expression, in C++). 178362391Sdcs /// 178462391Sdcs /// This routine does not attempt to resolve any of the trick cases, e.g., 178562391Sdcs /// those involving lookup of identifiers. 178662391Sdcs /// 178762391Sdcs /// \returns \c TPR_true if this token starts an expression, \c TPR_false if 178862391Sdcs /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot 178962391Sdcs /// tell. 179062391Sdcs TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind); 179162391Sdcs 179262391Sdcs /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 179362391Sdcs /// declaration specifier, TPResult::False() if it is not, 179462391Sdcs /// TPResult::Ambiguous() if it could be either a decl-specifier or a 179562391Sdcs /// function-style cast, and TPResult::Error() if a parsing error was 179662391Sdcs /// encountered. If it could be a braced C++11 function-style cast, returns 179762391Sdcs /// BracedCastResult. 179862391Sdcs /// Doesn't consume tokens. 179962391Sdcs TPResult 180062391Sdcs isCXXDeclarationSpecifier(TPResult BracedCastResult = TPResult::False(), 180162391Sdcs bool *HasMissingTypename = 0); 180262391Sdcs 180362391Sdcs /// \brief Determine whether an identifier has been tentatively declared as a 180462391Sdcs /// non-type. Such tentative declarations should not be found to name a type 180562391Sdcs /// during a tentative parse, but also should not be annotated as a non-type. 180662391Sdcs bool isTentativelyDeclared(IdentifierInfo *II); 180762391Sdcs 180862391Sdcs // "Tentative parsing" functions, used for disambiguation. If a parsing error 180962391Sdcs // is encountered they will return TPResult::Error(). 181062391Sdcs // Returning TPResult::True()/False() indicates that the ambiguity was 181162391Sdcs // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 181262391Sdcs // that more tentative parsing is necessary for disambiguation. 181362391Sdcs // They all consume tokens, so backtracking should be used after calling them. 181462391Sdcs 181562391Sdcs TPResult TryParseDeclarationSpecifier(bool *HasMissingTypename = 0); 181662391Sdcs TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl); 181762391Sdcs TPResult TryParseTypeofSpecifier(); 181862391Sdcs TPResult TryParseProtocolQualifiers(); 181962391Sdcs TPResult TryParseInitDeclaratorList(); 182062391Sdcs TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 182162391Sdcs TPResult TryParseParameterDeclarationClause(bool *InvalidAsDeclaration = 0); 182262391Sdcs TPResult TryParseFunctionDeclarator(); 18231573Srgrimes TPResult TryParseBracketDeclarator(); 18241573Srgrimes 18251573Srgrimespublic: 182662391Sdcs TypeResult ParseTypeName(SourceRange *Range = 0, 182762391Sdcs Declarator::TheContext Context 18281573Srgrimes = Declarator::TypeNameContext, 182962391Sdcs AccessSpecifier AS = AS_none, 18301573Srgrimes Decl **OwnedType = 0, 18311573Srgrimes ParsedAttributes *Attrs = 0); 18321573Srgrimes 18331573Srgrimesprivate: 18341573Srgrimes void ParseBlockId(SourceLocation CaretLoc); 183562391Sdcs 18361573Srgrimes // Check for the start of a C++11 attribute-specifier-seq in a context where 18371573Srgrimes // an attribute is not allowed. 18381573Srgrimes bool CheckProhibitedCXX11Attribute() { 18391573Srgrimes assert(Tok.is(tok::l_square)); 18401573Srgrimes if (!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square)) 18411573Srgrimes return false; 18421573Srgrimes return DiagnoseProhibitedCXX11Attribute(); 18431573Srgrimes } 18441573Srgrimes bool DiagnoseProhibitedCXX11Attribute(); 18451573Srgrimes void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs, 18461573Srgrimes SourceLocation CorrectLocation) { 18471573Srgrimes if (!getLangOpts().CPlusPlus11) 18481573Srgrimes return; 18491573Srgrimes if ((Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square)) && 18501573Srgrimes Tok.isNot(tok::kw_alignas)) 185162391Sdcs return; 185262673Sdcs DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation); 185362391Sdcs } 185462391Sdcs void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs, 185562391Sdcs SourceLocation CorrectLocation); 185662391Sdcs 185762391Sdcs void ProhibitAttributes(ParsedAttributesWithRange &attrs) { 185862391Sdcs if (!attrs.Range.isValid()) return; 185962391Sdcs DiagnoseProhibitedAttributes(attrs); 186062391Sdcs attrs.clear(); 186162391Sdcs } 186262391Sdcs void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs); 186362391Sdcs 186462391Sdcs // Forbid C++11 attributes that appear on certain syntactic 186562391Sdcs // locations which standard permits but we don't supported yet, 186662391Sdcs // for example, attributes appertain to decl specifiers. 186762391Sdcs void ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs); 186862391Sdcs 186962391Sdcs void MaybeParseGNUAttributes(Declarator &D, 187062391Sdcs LateParsedAttrList *LateAttrs = 0) { 187162391Sdcs if (Tok.is(tok::kw___attribute)) { 187262391Sdcs ParsedAttributes attrs(AttrFactory); 187362391Sdcs SourceLocation endLoc; 187462391Sdcs ParseGNUAttributes(attrs, &endLoc, LateAttrs); 187562391Sdcs D.takeAttributes(attrs, endLoc); 187662391Sdcs } 187762391Sdcs } 187862391Sdcs void MaybeParseGNUAttributes(ParsedAttributes &attrs, 187962391Sdcs SourceLocation *endLoc = 0, 188062391Sdcs LateParsedAttrList *LateAttrs = 0) { 188162391Sdcs if (Tok.is(tok::kw___attribute)) 188262391Sdcs ParseGNUAttributes(attrs, endLoc, LateAttrs); 188362391Sdcs } 188462391Sdcs void ParseGNUAttributes(ParsedAttributes &attrs, 188562391Sdcs SourceLocation *endLoc = 0, 188662391Sdcs LateParsedAttrList *LateAttrs = 0); 188762391Sdcs void ParseGNUAttributeArgs(IdentifierInfo *AttrName, 188862391Sdcs SourceLocation AttrNameLoc, 188962391Sdcs ParsedAttributes &Attrs, 189062391Sdcs SourceLocation *EndLoc, 189162391Sdcs IdentifierInfo *ScopeName, 189262391Sdcs SourceLocation ScopeLoc, 189362391Sdcs AttributeList::Syntax Syntax); 189462855Sdcs 189562855Sdcs void MaybeParseCXX11Attributes(Declarator &D) { 189662855Sdcs if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { 189762855Sdcs ParsedAttributesWithRange attrs(AttrFactory); 189862391Sdcs SourceLocation endLoc; 189962391Sdcs ParseCXX11Attributes(attrs, &endLoc); 190062391Sdcs D.takeAttributes(attrs, endLoc); 190162391Sdcs } 190262391Sdcs } 190362391Sdcs void MaybeParseCXX11Attributes(ParsedAttributes &attrs, 190462391Sdcs SourceLocation *endLoc = 0) { 190562391Sdcs if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { 190662391Sdcs ParsedAttributesWithRange attrsWithRange(AttrFactory); 190762391Sdcs ParseCXX11Attributes(attrsWithRange, endLoc); 190862391Sdcs attrs.takeAllFrom(attrsWithRange); 190962391Sdcs } 191062391Sdcs } 191162391Sdcs void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs, 191262391Sdcs SourceLocation *endLoc = 0, 191362391Sdcs bool OuterMightBeMessageSend = false) { 191462391Sdcs if (getLangOpts().CPlusPlus11 && 191562391Sdcs isCXX11AttributeSpecifier(false, OuterMightBeMessageSend)) 191662391Sdcs ParseCXX11Attributes(attrs, endLoc); 191762391Sdcs } 191862391Sdcs 191962391Sdcs void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs, 192062391Sdcs SourceLocation *EndLoc = 0); 192162391Sdcs void ParseCXX11Attributes(ParsedAttributesWithRange &attrs, 192262391Sdcs SourceLocation *EndLoc = 0); 192362391Sdcs 192462391Sdcs IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc); 192562391Sdcs 192662391Sdcs void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs, 192762232Sdcs SourceLocation *endLoc = 0) { 192892889Sobrien if (getLangOpts().MicrosoftExt && Tok.is(tok::l_square)) 192962232Sdcs ParseMicrosoftAttributes(attrs, endLoc); 193062232Sdcs } 193162232Sdcs void ParseMicrosoftAttributes(ParsedAttributes &attrs, 193262232Sdcs SourceLocation *endLoc = 0); 193362232Sdcs void ParseMicrosoftDeclSpec(ParsedAttributes &Attrs); 193462232Sdcs bool IsSimpleMicrosoftDeclSpec(IdentifierInfo *Ident); 193562232Sdcs void ParseComplexMicrosoftDeclSpec(IdentifierInfo *Ident, 193662232Sdcs SourceLocation Loc, 193762232Sdcs ParsedAttributes &Attrs); 193862232Sdcs void ParseMicrosoftDeclSpecWithSingleArg(IdentifierInfo *AttrName, 193962232Sdcs SourceLocation AttrNameLoc, 194062232Sdcs ParsedAttributes &Attrs); 194162232Sdcs void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); 194262232Sdcs void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs); 194362232Sdcs void ParseBorlandTypeAttributes(ParsedAttributes &attrs); 194462232Sdcs void ParseOpenCLAttributes(ParsedAttributes &attrs); 194562232Sdcs void ParseOpenCLQualifiers(DeclSpec &DS); 194662232Sdcs 194762232Sdcs VersionTuple ParseVersionTuple(SourceRange &Range); 194862232Sdcs void ParseAvailabilityAttribute(IdentifierInfo &Availability, 194962848Sdcs SourceLocation AvailabilityLoc, 195062232Sdcs ParsedAttributes &attrs, 195162232Sdcs SourceLocation *endLoc); 195262754Sdcs 195362754Sdcs bool IsThreadSafetyAttribute(StringRef AttrName); 195462232Sdcs void ParseThreadSafetyAttribute(IdentifierInfo &AttrName, 195562232Sdcs SourceLocation AttrNameLoc, 195662232Sdcs ParsedAttributes &Attrs, 195762232Sdcs SourceLocation *EndLoc); 195862754Sdcs 195962232Sdcs void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, 196062232Sdcs SourceLocation AttrNameLoc, 196162232Sdcs ParsedAttributes &Attrs, 196262232Sdcs SourceLocation *EndLoc); 196362232Sdcs 196462232Sdcs void ParseTypeofSpecifier(DeclSpec &DS); 196562232Sdcs SourceLocation ParseDecltypeSpecifier(DeclSpec &DS); 196662232Sdcs void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS, 1967111010Snectar SourceLocation StartLoc, 196862232Sdcs SourceLocation EndLoc); 196962232Sdcs void ParseUnderlyingTypeSpecifier(DeclSpec &DS); 197062232Sdcs void ParseAtomicSpecifier(DeclSpec &DS); 197162232Sdcs 197292889Sobrien ExprResult ParseAlignArgument(SourceLocation Start, 197362232Sdcs SourceLocation &EllipsisLoc); 197462232Sdcs void ParseAlignmentSpecifier(ParsedAttributes &Attrs, 197562232Sdcs SourceLocation *endLoc = 0); 197662232Sdcs 197762232Sdcs VirtSpecifiers::Specifier isCXX11VirtSpecifier(const Token &Tok) const; 197862232Sdcs VirtSpecifiers::Specifier isCXX11VirtSpecifier() const { 197962232Sdcs return isCXX11VirtSpecifier(Tok); 198062232Sdcs } 198162232Sdcs void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, bool IsInterface); 198262232Sdcs 198362232Sdcs bool isCXX11FinalKeyword() const; 198462232Sdcs 198562232Sdcs /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 198662232Sdcs /// enter a new C++ declarator scope and exit it when the function is 198762232Sdcs /// finished. 198862232Sdcs class DeclaratorScopeObj { 198962232Sdcs Parser &P; 199062232Sdcs CXXScopeSpec &SS; 199162232Sdcs bool EnteredScope; 199262232Sdcs bool CreatedScope; 199362232Sdcs public: 199462232Sdcs DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 199562232Sdcs : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 199662232Sdcs 199762232Sdcs void EnterDeclaratorScope() { 199862232Sdcs assert(!EnteredScope && "Already entered the scope!"); 199962232Sdcs assert(SS.isSet() && "C++ scope was not set!"); 200062848Sdcs 200162232Sdcs CreatedScope = true; 200262232Sdcs P.EnterScope(0); // Not a decl scope. 200362232Sdcs 200462232Sdcs if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) 200562232Sdcs EnteredScope = true; 200662848Sdcs } 200762232Sdcs 200862232Sdcs ~DeclaratorScopeObj() { 200962232Sdcs if (EnteredScope) { 201062232Sdcs assert(SS.isSet() && "C++ scope was cleared ?"); 201162232Sdcs P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); 201262232Sdcs } 201362232Sdcs if (CreatedScope) 201462232Sdcs P.ExitScope(); 201562232Sdcs } 201662232Sdcs }; 201762232Sdcs 201862232Sdcs /// ParseDeclarator - Parse and verify a newly-initialized declarator. 201962232Sdcs void ParseDeclarator(Declarator &D); 202062232Sdcs /// A function that parses a variant of direct-declarator. 202162232Sdcs typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 202262232Sdcs void ParseDeclaratorInternal(Declarator &D, 202362232Sdcs DirectDeclParseFunction DirectDeclParser); 202462232Sdcs 202562232Sdcs void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 202662232Sdcs bool CXX11AttributesAllowed = true, 202762232Sdcs bool AtomicAllowed = true); 202862232Sdcs void ParseDirectDeclarator(Declarator &D); 202962232Sdcs void ParseParenDeclarator(Declarator &D); 203062232Sdcs void ParseFunctionDeclarator(Declarator &D, 203162232Sdcs ParsedAttributes &attrs, 203262232Sdcs BalancedDelimiterTracker &Tracker, 203362232Sdcs bool IsAmbiguous, 203462232Sdcs bool RequiresArg = false); 203562232Sdcs bool isFunctionDeclaratorIdentifierList(); 203662232Sdcs void ParseFunctionDeclaratorIdentifierList( 203762232Sdcs Declarator &D, 203862232Sdcs SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo); 203962232Sdcs void ParseParameterDeclarationClause( 204062232Sdcs Declarator &D, 204162232Sdcs ParsedAttributes &attrs, 204262391Sdcs SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo, 204362673Sdcs SourceLocation &EllipsisLoc); 204462232Sdcs void ParseBracketDeclarator(Declarator &D); 204562232Sdcs 204662232Sdcs //===--------------------------------------------------------------------===// 204762232Sdcs // C++ 7: Declarations [dcl.dcl] 204886208Sdcs 204986208Sdcs /// The kind of attribute specifier we have found. 205062232Sdcs enum CXX11AttributeKind { 205162232Sdcs /// This is not an attribute specifier. 205262232Sdcs CAK_NotAttributeSpecifier, 205362232Sdcs /// This should be treated as an attribute-specifier. 205462232Sdcs CAK_AttributeSpecifier, 205562232Sdcs /// The next tokens are '[[', but this is not an attribute-specifier. This 20561573Srgrimes /// is ill-formed by C++11 [dcl.attr.grammar]p6. 205792889Sobrien CAK_InvalidAttributeSpecifier 20581573Srgrimes }; 20591573Srgrimes CXX11AttributeKind 20601573Srgrimes isCXX11AttributeSpecifier(bool Disambiguate = false, 20611573Srgrimes bool OuterMightBeMessageSend = false); 206292889Sobrien 20631573Srgrimes Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, 206492889Sobrien SourceLocation InlineLoc = SourceLocation()); 206592889Sobrien void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, 206692889Sobrien std::vector<IdentifierInfo*>& Ident, 206792889Sobrien std::vector<SourceLocation>& NamespaceLoc, 20681573Srgrimes unsigned int index, SourceLocation& InlineLoc, 20691573Srgrimes ParsedAttributes& attrs, 20701573Srgrimes BalancedDelimiterTracker &Tracker); 20711573Srgrimes Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 20721573Srgrimes Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, 20731573Srgrimes const ParsedTemplateInfo &TemplateInfo, 20741573Srgrimes SourceLocation &DeclEnd, 20751573Srgrimes ParsedAttributesWithRange &attrs, 20761573Srgrimes Decl **OwnedType = 0); 20771573Srgrimes Decl *ParseUsingDirective(unsigned Context, 20781573Srgrimes SourceLocation UsingLoc, 20791573Srgrimes SourceLocation &DeclEnd, 20801573Srgrimes ParsedAttributes &attrs); 20811573Srgrimes Decl *ParseUsingDeclaration(unsigned Context, 20821573Srgrimes const ParsedTemplateInfo &TemplateInfo, 20831573Srgrimes SourceLocation UsingLoc, 20841573Srgrimes SourceLocation &DeclEnd, 20851573Srgrimes AccessSpecifier AS = AS_none, 20861573Srgrimes Decl **OwnedType = 0); 20871573Srgrimes Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 20881573Srgrimes Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, 20891573Srgrimes SourceLocation AliasLoc, IdentifierInfo *Alias, 2090 SourceLocation &DeclEnd); 2091 2092 //===--------------------------------------------------------------------===// 2093 // C++ 9: classes [class] and C structs/unions. 2094 bool isValidAfterTypeSpecifier(bool CouldBeBitfield); 2095 void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 2096 DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo, 2097 AccessSpecifier AS, bool EnteringContext, 2098 DeclSpecContext DSC, 2099 ParsedAttributesWithRange &Attributes); 2100 void ParseCXXMemberSpecification(SourceLocation StartLoc, 2101 SourceLocation AttrFixitLoc, 2102 ParsedAttributesWithRange &Attrs, 2103 unsigned TagType, 2104 Decl *TagDecl); 2105 ExprResult ParseCXXMemberInitializer(Decl *D, bool IsFunction, 2106 SourceLocation &EqualLoc); 2107 void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr, 2108 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 2109 ParsingDeclRAIIObject *DiagsFromTParams = 0); 2110 void ParseConstructorInitializer(Decl *ConstructorDecl); 2111 MemInitResult ParseMemInitializer(Decl *ConstructorDecl); 2112 void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo, 2113 Decl *ThisDecl); 2114 2115 //===--------------------------------------------------------------------===// 2116 // C++ 10: Derived classes [class.derived] 2117 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc, 2118 SourceLocation &EndLocation); 2119 void ParseBaseClause(Decl *ClassDecl); 2120 BaseResult ParseBaseSpecifier(Decl *ClassDecl); 2121 AccessSpecifier getAccessSpecifierIfPresent() const; 2122 2123 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 2124 SourceLocation TemplateKWLoc, 2125 IdentifierInfo *Name, 2126 SourceLocation NameLoc, 2127 bool EnteringContext, 2128 ParsedType ObjectType, 2129 UnqualifiedId &Id, 2130 bool AssumeTemplateId); 2131 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 2132 ParsedType ObjectType, 2133 UnqualifiedId &Result); 2134 2135 //===--------------------------------------------------------------------===// 2136 // OpenMP: Directives and clauses. 2137 DeclGroupPtrTy ParseOpenMPDeclarativeDirective(); 2138 bool ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, 2139 SmallVectorImpl<DeclarationNameInfo> &IdList); 2140public: 2141 bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 2142 bool AllowDestructorName, 2143 bool AllowConstructorName, 2144 ParsedType ObjectType, 2145 SourceLocation& TemplateKWLoc, 2146 UnqualifiedId &Result); 2147 2148private: 2149 //===--------------------------------------------------------------------===// 2150 // C++ 14: Templates [temp] 2151 2152 // C++ 14.1: Template Parameters [temp.param] 2153 Decl *ParseDeclarationStartingWithTemplate(unsigned Context, 2154 SourceLocation &DeclEnd, 2155 AccessSpecifier AS = AS_none, 2156 AttributeList *AccessAttrs = 0); 2157 Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context, 2158 SourceLocation &DeclEnd, 2159 AccessSpecifier AS, 2160 AttributeList *AccessAttrs); 2161 Decl *ParseSingleDeclarationAfterTemplate( 2162 unsigned Context, 2163 const ParsedTemplateInfo &TemplateInfo, 2164 ParsingDeclRAIIObject &DiagsFromParams, 2165 SourceLocation &DeclEnd, 2166 AccessSpecifier AS=AS_none, 2167 AttributeList *AccessAttrs = 0); 2168 bool ParseTemplateParameters(unsigned Depth, 2169 SmallVectorImpl<Decl*> &TemplateParams, 2170 SourceLocation &LAngleLoc, 2171 SourceLocation &RAngleLoc); 2172 bool ParseTemplateParameterList(unsigned Depth, 2173 SmallVectorImpl<Decl*> &TemplateParams); 2174 bool isStartOfTemplateTypeParameter(); 2175 Decl *ParseTemplateParameter(unsigned Depth, unsigned Position); 2176 Decl *ParseTypeParameter(unsigned Depth, unsigned Position); 2177 Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 2178 Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 2179 // C++ 14.3: Template arguments [temp.arg] 2180 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 2181 2182 bool ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc, 2183 bool ConsumeLastToken); 2184 bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 2185 SourceLocation TemplateNameLoc, 2186 const CXXScopeSpec &SS, 2187 bool ConsumeLastToken, 2188 SourceLocation &LAngleLoc, 2189 TemplateArgList &TemplateArgs, 2190 SourceLocation &RAngleLoc); 2191 2192 bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 2193 CXXScopeSpec &SS, 2194 SourceLocation TemplateKWLoc, 2195 UnqualifiedId &TemplateName, 2196 bool AllowTypeAnnotation = true); 2197 void AnnotateTemplateIdTokenAsType(); 2198 bool IsTemplateArgumentList(unsigned Skip = 0); 2199 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 2200 ParsedTemplateArgument ParseTemplateTemplateArgument(); 2201 ParsedTemplateArgument ParseTemplateArgument(); 2202 Decl *ParseExplicitInstantiation(unsigned Context, 2203 SourceLocation ExternLoc, 2204 SourceLocation TemplateLoc, 2205 SourceLocation &DeclEnd, 2206 AccessSpecifier AS = AS_none); 2207 2208 //===--------------------------------------------------------------------===// 2209 // Modules 2210 DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc); 2211 2212 //===--------------------------------------------------------------------===// 2213 // GNU G++: Type Traits [Type-Traits.html in the GCC manual] 2214 ExprResult ParseUnaryTypeTrait(); 2215 ExprResult ParseBinaryTypeTrait(); 2216 ExprResult ParseTypeTrait(); 2217 2218 //===--------------------------------------------------------------------===// 2219 // Embarcadero: Arary and Expression Traits 2220 ExprResult ParseArrayTypeTrait(); 2221 ExprResult ParseExpressionTrait(); 2222 2223 //===--------------------------------------------------------------------===// 2224 // Preprocessor code-completion pass-through 2225 virtual void CodeCompleteDirective(bool InConditional); 2226 virtual void CodeCompleteInConditionalExclusion(); 2227 virtual void CodeCompleteMacroName(bool IsDefinition); 2228 virtual void CodeCompletePreprocessorExpression(); 2229 virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro, 2230 MacroInfo *MacroInfo, 2231 unsigned ArgumentIndex); 2232 virtual void CodeCompleteNaturalLanguage(); 2233}; 2234 2235} // end namespace clang 2236 2237#endif 2238