1//===--- Parser.h - C Language Parser ---------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Parser interface. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_PARSE_PARSER_H 15#define LLVM_CLANG_PARSE_PARSER_H 16 17#include "clang/Basic/OpenMPKinds.h" 18#include "clang/Basic/OperatorPrecedence.h" 19#include "clang/Basic/Specifiers.h" 20#include "clang/Lex/CodeCompletionHandler.h" 21#include "clang/Lex/Preprocessor.h" 22#include "clang/Sema/DeclSpec.h" 23#include "clang/Sema/Sema.h" 24#include "llvm/ADT/OwningPtr.h" 25#include "llvm/ADT/SmallVector.h" 26#include "llvm/Support/Compiler.h" 27#include "llvm/Support/PrettyStackTrace.h" 28#include "llvm/Support/SaveAndRestore.h" 29#include <stack> 30 31namespace clang { 32 class PragmaHandler; 33 class Scope; 34 class BalancedDelimiterTracker; 35 class CorrectionCandidateCallback; 36 class DeclGroupRef; 37 class DiagnosticBuilder; 38 class Parser; 39 class ParsingDeclRAIIObject; 40 class ParsingDeclSpec; 41 class ParsingDeclarator; 42 class ParsingFieldDeclarator; 43 class PragmaUnusedHandler; 44 class ColonProtectionRAIIObject; 45 class InMessageExpressionRAIIObject; 46 class PoisonSEHIdentifiersRAIIObject; 47 class VersionTuple; 48 49/// Parser - This implements a parser for the C family of languages. After 50/// parsing units of the grammar, productions are invoked to handle whatever has 51/// been read. 52/// 53class Parser : public CodeCompletionHandler { 54 friend class PragmaUnusedHandler; 55 friend class ColonProtectionRAIIObject; 56 friend class InMessageExpressionRAIIObject; 57 friend class PoisonSEHIdentifiersRAIIObject; 58 friend class ObjCDeclContextSwitch; 59 friend class ParenBraceBracketBalancer; 60 friend class BalancedDelimiterTracker; 61 62 Preprocessor &PP; 63 64 /// Tok - The current token we are peeking ahead. All parsing methods assume 65 /// that this is valid. 66 Token Tok; 67 68 // PrevTokLocation - The location of the token we previously 69 // consumed. This token is used for diagnostics where we expected to 70 // see a token following another token (e.g., the ';' at the end of 71 // a statement). 72 SourceLocation PrevTokLocation; 73 74 unsigned short ParenCount, BracketCount, BraceCount; 75 76 /// Actions - These are the callbacks we invoke as we parse various constructs 77 /// in the file. 78 Sema &Actions; 79 80 DiagnosticsEngine &Diags; 81 82 /// ScopeCache - Cache scopes to reduce malloc traffic. 83 enum { ScopeCacheSize = 16 }; 84 unsigned NumCachedScopes; 85 Scope *ScopeCache[ScopeCacheSize]; 86 87 /// Identifiers used for SEH handling in Borland. These are only 88 /// allowed in particular circumstances 89 // __except block 90 IdentifierInfo *Ident__exception_code, 91 *Ident___exception_code, 92 *Ident_GetExceptionCode; 93 // __except filter expression 94 IdentifierInfo *Ident__exception_info, 95 *Ident___exception_info, 96 *Ident_GetExceptionInfo; 97 // __finally 98 IdentifierInfo *Ident__abnormal_termination, 99 *Ident___abnormal_termination, 100 *Ident_AbnormalTermination; 101 102 /// Contextual keywords for Microsoft extensions. 103 IdentifierInfo *Ident__except; 104 105 /// Ident_super - IdentifierInfo for "super", to support fast 106 /// comparison. 107 IdentifierInfo *Ident_super; 108 /// Ident_vector and Ident_pixel - cached IdentifierInfo's for 109 /// "vector" and "pixel" fast comparison. Only present if 110 /// AltiVec enabled. 111 IdentifierInfo *Ident_vector; 112 IdentifierInfo *Ident_pixel; 113 114 /// Objective-C contextual keywords. 115 mutable IdentifierInfo *Ident_instancetype; 116 117 /// \brief Identifier for "introduced". 118 IdentifierInfo *Ident_introduced; 119 120 /// \brief Identifier for "deprecated". 121 IdentifierInfo *Ident_deprecated; 122 123 /// \brief Identifier for "obsoleted". 124 IdentifierInfo *Ident_obsoleted; 125 126 /// \brief Identifier for "unavailable". 127 IdentifierInfo *Ident_unavailable; 128 129 /// \brief Identifier for "message". 130 IdentifierInfo *Ident_message; 131 132 /// C++0x contextual keywords. 133 mutable IdentifierInfo *Ident_final; 134 mutable IdentifierInfo *Ident_override; 135 136 // C++ type trait keywords that have can be reverted to identifiers and 137 // still used as type traits. 138 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertableTypeTraits; 139 140 OwningPtr<PragmaHandler> AlignHandler; 141 OwningPtr<PragmaHandler> GCCVisibilityHandler; 142 OwningPtr<PragmaHandler> OptionsHandler; 143 OwningPtr<PragmaHandler> PackHandler; 144 OwningPtr<PragmaHandler> MSStructHandler; 145 OwningPtr<PragmaHandler> UnusedHandler; 146 OwningPtr<PragmaHandler> WeakHandler; 147 OwningPtr<PragmaHandler> RedefineExtnameHandler; 148 OwningPtr<PragmaHandler> FPContractHandler; 149 OwningPtr<PragmaHandler> OpenCLExtensionHandler; 150 OwningPtr<CommentHandler> CommentSemaHandler; 151 OwningPtr<PragmaHandler> OpenMPHandler; 152 OwningPtr<PragmaHandler> MSCommentHandler; 153 154 /// Whether the '>' token acts as an operator or not. This will be 155 /// true except when we are parsing an expression within a C++ 156 /// template argument list, where the '>' closes the template 157 /// argument list. 158 bool GreaterThanIsOperator; 159 160 /// ColonIsSacred - When this is false, we aggressively try to recover from 161 /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 162 /// safe in case statements and a few other things. This is managed by the 163 /// ColonProtectionRAIIObject RAII object. 164 bool ColonIsSacred; 165 166 /// \brief When true, we are directly inside an Objective-C messsage 167 /// send expression. 168 /// 169 /// This is managed by the \c InMessageExpressionRAIIObject class, and 170 /// should not be set directly. 171 bool InMessageExpression; 172 173 /// The "depth" of the template parameters currently being parsed. 174 unsigned TemplateParameterDepth; 175 176 /// \brief RAII class that manages the template parameter depth. 177 class TemplateParameterDepthRAII { 178 unsigned &Depth; 179 unsigned AddedLevels; 180 public: 181 explicit TemplateParameterDepthRAII(unsigned &Depth) 182 : Depth(Depth), AddedLevels(0) {} 183 184 ~TemplateParameterDepthRAII() { 185 Depth -= AddedLevels; 186 } 187 188 void operator++() { 189 ++Depth; 190 ++AddedLevels; 191 } 192 unsigned getDepth() const { return Depth; } 193 }; 194 195 /// Factory object for creating AttributeList objects. 196 AttributeFactory AttrFactory; 197 198 /// \brief Gathers and cleans up TemplateIdAnnotations when parsing of a 199 /// top-level declaration is finished. 200 SmallVector<TemplateIdAnnotation *, 16> TemplateIds; 201 202 /// \brief Identifiers which have been declared within a tentative parse. 203 SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers; 204 205 IdentifierInfo *getSEHExceptKeyword(); 206 207 /// True if we are within an Objective-C container while parsing C-like decls. 208 /// 209 /// This is necessary because Sema thinks we have left the container 210 /// to parse the C-like decls, meaning Actions.getObjCDeclContext() will 211 /// be NULL. 212 bool ParsingInObjCContainer; 213 214 bool SkipFunctionBodies; 215 216public: 217 Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies); 218 ~Parser(); 219 220 const LangOptions &getLangOpts() const { return PP.getLangOpts(); } 221 const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 222 Preprocessor &getPreprocessor() const { return PP; } 223 Sema &getActions() const { return Actions; } 224 AttributeFactory &getAttrFactory() { return AttrFactory; } 225 226 const Token &getCurToken() const { return Tok; } 227 Scope *getCurScope() const { return Actions.getCurScope(); } 228 229 Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } 230 231 // Type forwarding. All of these are statically 'void*', but they may all be 232 // different actual classes based on the actions in place. 233 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 234 typedef OpaquePtr<TemplateName> TemplateTy; 235 236 typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists; 237 238 typedef clang::ExprResult ExprResult; 239 typedef clang::StmtResult StmtResult; 240 typedef clang::BaseResult BaseResult; 241 typedef clang::MemInitResult MemInitResult; 242 typedef clang::TypeResult TypeResult; 243 244 typedef Expr *ExprArg; 245 typedef llvm::MutableArrayRef<Stmt*> MultiStmtArg; 246 typedef Sema::FullExprArg FullExprArg; 247 248 ExprResult ExprError() { return ExprResult(true); } 249 StmtResult StmtError() { return StmtResult(true); } 250 251 ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 252 StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 253 254 ExprResult ExprEmpty() { return ExprResult(false); } 255 256 // Parsing methods. 257 258 /// Initialize - Warm up the parser. 259 /// 260 void Initialize(); 261 262 /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 263 /// the EOF was encountered. 264 bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 265 266 /// ConsumeToken - Consume the current 'peek token' and lex the next one. 267 /// This does not work with all kinds of tokens: strings and specific other 268 /// tokens must be consumed with custom methods below. This returns the 269 /// location of the consumed token. 270 SourceLocation ConsumeToken(bool ConsumeCodeCompletionTok = false) { 271 assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 272 !isTokenBrace() && 273 "Should consume special tokens with Consume*Token"); 274 275 if (!ConsumeCodeCompletionTok && Tok.is(tok::code_completion)) 276 return handleUnexpectedCodeCompletionToken(); 277 278 PrevTokLocation = Tok.getLocation(); 279 PP.Lex(Tok); 280 return PrevTokLocation; 281 } 282 283private: 284 //===--------------------------------------------------------------------===// 285 // Low-Level token peeking and consumption methods. 286 // 287 288 /// isTokenParen - Return true if the cur token is '(' or ')'. 289 bool isTokenParen() const { 290 return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 291 } 292 /// isTokenBracket - Return true if the cur token is '[' or ']'. 293 bool isTokenBracket() const { 294 return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 295 } 296 /// isTokenBrace - Return true if the cur token is '{' or '}'. 297 bool isTokenBrace() const { 298 return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 299 } 300 301 /// isTokenStringLiteral - True if this token is a string-literal. 302 /// 303 bool isTokenStringLiteral() const { 304 return tok::isStringLiteral(Tok.getKind()); 305 } 306 307 /// \brief Returns true if the current token is '=' or is a type of '='. 308 /// For typos, give a fixit to '=' 309 bool isTokenEqualOrEqualTypo(); 310 311 /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 312 /// current token type. This should only be used in cases where the type of 313 /// the token really isn't known, e.g. in error recovery. 314 SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) { 315 if (isTokenParen()) 316 return ConsumeParen(); 317 else if (isTokenBracket()) 318 return ConsumeBracket(); 319 else if (isTokenBrace()) 320 return ConsumeBrace(); 321 else if (isTokenStringLiteral()) 322 return ConsumeStringToken(); 323 else 324 return ConsumeToken(ConsumeCodeCompletionTok); 325 } 326 327 /// ConsumeParen - This consume method keeps the paren count up-to-date. 328 /// 329 SourceLocation ConsumeParen() { 330 assert(isTokenParen() && "wrong consume method"); 331 if (Tok.getKind() == tok::l_paren) 332 ++ParenCount; 333 else if (ParenCount) 334 --ParenCount; // Don't let unbalanced )'s drive the count negative. 335 PrevTokLocation = Tok.getLocation(); 336 PP.Lex(Tok); 337 return PrevTokLocation; 338 } 339 340 /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 341 /// 342 SourceLocation ConsumeBracket() { 343 assert(isTokenBracket() && "wrong consume method"); 344 if (Tok.getKind() == tok::l_square) 345 ++BracketCount; 346 else if (BracketCount) 347 --BracketCount; // Don't let unbalanced ]'s drive the count negative. 348 349 PrevTokLocation = Tok.getLocation(); 350 PP.Lex(Tok); 351 return PrevTokLocation; 352 } 353 354 /// ConsumeBrace - This consume method keeps the brace count up-to-date. 355 /// 356 SourceLocation ConsumeBrace() { 357 assert(isTokenBrace() && "wrong consume method"); 358 if (Tok.getKind() == tok::l_brace) 359 ++BraceCount; 360 else if (BraceCount) 361 --BraceCount; // Don't let unbalanced }'s drive the count negative. 362 363 PrevTokLocation = Tok.getLocation(); 364 PP.Lex(Tok); 365 return PrevTokLocation; 366 } 367 368 /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 369 /// and returning the token kind. This method is specific to strings, as it 370 /// handles string literal concatenation, as per C99 5.1.1.2, translation 371 /// phase #6. 372 SourceLocation ConsumeStringToken() { 373 assert(isTokenStringLiteral() && 374 "Should only consume string literals with this method"); 375 PrevTokLocation = Tok.getLocation(); 376 PP.Lex(Tok); 377 return PrevTokLocation; 378 } 379 380 /// \brief Consume the current code-completion token. 381 /// 382 /// This routine should be called to consume the code-completion token once 383 /// a code-completion action has already been invoked. 384 SourceLocation ConsumeCodeCompletionToken() { 385 assert(Tok.is(tok::code_completion)); 386 PrevTokLocation = Tok.getLocation(); 387 PP.Lex(Tok); 388 return PrevTokLocation; 389 } 390 391 ///\ brief When we are consuming a code-completion token without having 392 /// matched specific position in the grammar, provide code-completion results 393 /// based on context. 394 /// 395 /// \returns the source location of the code-completion token. 396 SourceLocation handleUnexpectedCodeCompletionToken(); 397 398 /// \brief Abruptly cut off parsing; mainly used when we have reached the 399 /// code-completion point. 400 void cutOffParsing() { 401 PP.setCodeCompletionReached(); 402 // Cut off parsing by acting as if we reached the end-of-file. 403 Tok.setKind(tok::eof); 404 } 405 406 /// \brief Handle the annotation token produced for #pragma unused(...) 407 void HandlePragmaUnused(); 408 409 /// \brief Handle the annotation token produced for 410 /// #pragma GCC visibility... 411 void HandlePragmaVisibility(); 412 413 /// \brief Handle the annotation token produced for 414 /// #pragma pack... 415 void HandlePragmaPack(); 416 417 /// \brief Handle the annotation token produced for 418 /// #pragma ms_struct... 419 void HandlePragmaMSStruct(); 420 421 /// \brief Handle the annotation token produced for 422 /// #pragma align... 423 void HandlePragmaAlign(); 424 425 /// \brief Handle the annotation token produced for 426 /// #pragma weak id... 427 void HandlePragmaWeak(); 428 429 /// \brief Handle the annotation token produced for 430 /// #pragma weak id = id... 431 void HandlePragmaWeakAlias(); 432 433 /// \brief Handle the annotation token produced for 434 /// #pragma redefine_extname... 435 void HandlePragmaRedefineExtname(); 436 437 /// \brief Handle the annotation token produced for 438 /// #pragma STDC FP_CONTRACT... 439 void HandlePragmaFPContract(); 440 441 /// \brief Handle the annotation token produced for 442 /// #pragma OPENCL EXTENSION... 443 void HandlePragmaOpenCLExtension(); 444 445 /// \brief Handle the annotation token produced for 446 /// #pragma clang __debug captured 447 StmtResult HandlePragmaCaptured(); 448 449 /// GetLookAheadToken - This peeks ahead N tokens and returns that token 450 /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 451 /// returns the token after Tok, etc. 452 /// 453 /// Note that this differs from the Preprocessor's LookAhead method, because 454 /// the Parser always has one token lexed that the preprocessor doesn't. 455 /// 456 const Token &GetLookAheadToken(unsigned N) { 457 if (N == 0 || Tok.is(tok::eof)) return Tok; 458 return PP.LookAhead(N-1); 459 } 460 461public: 462 /// NextToken - This peeks ahead one token and returns it without 463 /// consuming it. 464 const Token &NextToken() { 465 return PP.LookAhead(0); 466 } 467 468 /// getTypeAnnotation - Read a parsed type out of an annotation token. 469 static ParsedType getTypeAnnotation(Token &Tok) { 470 return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); 471 } 472 473private: 474 static void setTypeAnnotation(Token &Tok, ParsedType T) { 475 Tok.setAnnotationValue(T.getAsOpaquePtr()); 476 } 477 478 /// \brief Read an already-translated primary expression out of an annotation 479 /// token. 480 static ExprResult getExprAnnotation(Token &Tok) { 481 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue()); 482 } 483 484 /// \brief Set the primary expression corresponding to the given annotation 485 /// token. 486 static void setExprAnnotation(Token &Tok, ExprResult ER) { 487 Tok.setAnnotationValue(ER.getAsOpaquePointer()); 488 } 489 490public: 491 // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to 492 // find a type name by attempting typo correction. 493 bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false, 494 bool NeedType = false); 495 bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext, 496 bool NeedType, 497 CXXScopeSpec &SS, 498 bool IsNewScope); 499 bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 500 501private: 502 enum AnnotatedNameKind { 503 /// Annotation has failed and emitted an error. 504 ANK_Error, 505 /// The identifier is a tentatively-declared name. 506 ANK_TentativeDecl, 507 /// The identifier is a template name. FIXME: Add an annotation for that. 508 ANK_TemplateName, 509 /// The identifier can't be resolved. 510 ANK_Unresolved, 511 /// Annotation was successful. 512 ANK_Success 513 }; 514 AnnotatedNameKind TryAnnotateName(bool IsAddressOfOperand, 515 CorrectionCandidateCallback *CCC = 0); 516 517 /// Push a tok::annot_cxxscope token onto the token stream. 518 void AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation); 519 520 /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 521 /// replacing them with the non-context-sensitive keywords. This returns 522 /// true if the token was replaced. 523 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 524 const char *&PrevSpec, unsigned &DiagID, 525 bool &isInvalid) { 526 if (!getLangOpts().AltiVec || 527 (Tok.getIdentifierInfo() != Ident_vector && 528 Tok.getIdentifierInfo() != Ident_pixel)) 529 return false; 530 531 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 532 } 533 534 /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 535 /// identifier token, replacing it with the non-context-sensitive __vector. 536 /// This returns true if the token was replaced. 537 bool TryAltiVecVectorToken() { 538 if (!getLangOpts().AltiVec || 539 Tok.getIdentifierInfo() != Ident_vector) return false; 540 return TryAltiVecVectorTokenOutOfLine(); 541 } 542 543 bool TryAltiVecVectorTokenOutOfLine(); 544 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 545 const char *&PrevSpec, unsigned &DiagID, 546 bool &isInvalid); 547 548 /// \brief Get the TemplateIdAnnotation from the token. 549 TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok); 550 551 /// TentativeParsingAction - An object that is used as a kind of "tentative 552 /// parsing transaction". It gets instantiated to mark the token position and 553 /// after the token consumption is done, Commit() or Revert() is called to 554 /// either "commit the consumed tokens" or revert to the previously marked 555 /// token position. Example: 556 /// 557 /// TentativeParsingAction TPA(*this); 558 /// ConsumeToken(); 559 /// .... 560 /// TPA.Revert(); 561 /// 562 class TentativeParsingAction { 563 Parser &P; 564 Token PrevTok; 565 size_t PrevTentativelyDeclaredIdentifierCount; 566 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount; 567 bool isActive; 568 569 public: 570 explicit TentativeParsingAction(Parser& p) : P(p) { 571 PrevTok = P.Tok; 572 PrevTentativelyDeclaredIdentifierCount = 573 P.TentativelyDeclaredIdentifiers.size(); 574 PrevParenCount = P.ParenCount; 575 PrevBracketCount = P.BracketCount; 576 PrevBraceCount = P.BraceCount; 577 P.PP.EnableBacktrackAtThisPos(); 578 isActive = true; 579 } 580 void Commit() { 581 assert(isActive && "Parsing action was finished!"); 582 P.TentativelyDeclaredIdentifiers.resize( 583 PrevTentativelyDeclaredIdentifierCount); 584 P.PP.CommitBacktrackedTokens(); 585 isActive = false; 586 } 587 void Revert() { 588 assert(isActive && "Parsing action was finished!"); 589 P.PP.Backtrack(); 590 P.Tok = PrevTok; 591 P.TentativelyDeclaredIdentifiers.resize( 592 PrevTentativelyDeclaredIdentifierCount); 593 P.ParenCount = PrevParenCount; 594 P.BracketCount = PrevBracketCount; 595 P.BraceCount = PrevBraceCount; 596 isActive = false; 597 } 598 ~TentativeParsingAction() { 599 assert(!isActive && "Forgot to call Commit or Revert!"); 600 } 601 }; 602 603 /// ObjCDeclContextSwitch - An object used to switch context from 604 /// an objective-c decl context to its enclosing decl context and 605 /// back. 606 class ObjCDeclContextSwitch { 607 Parser &P; 608 Decl *DC; 609 SaveAndRestore<bool> WithinObjCContainer; 610 public: 611 explicit ObjCDeclContextSwitch(Parser &p) 612 : P(p), DC(p.getObjCDeclContext()), 613 WithinObjCContainer(P.ParsingInObjCContainer, DC != 0) { 614 if (DC) 615 P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC)); 616 } 617 ~ObjCDeclContextSwitch() { 618 if (DC) 619 P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC)); 620 } 621 }; 622 623 /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 624 /// input. If so, it is consumed and false is returned. 625 /// 626 /// If the input is malformed, this emits the specified diagnostic. Next, if 627 /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 628 /// returned. 629 bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 630 const char *DiagMsg = "", 631 tok::TokenKind SkipToTok = tok::unknown); 632 633 /// \brief The parser expects a semicolon and, if present, will consume it. 634 /// 635 /// If the next token is not a semicolon, this emits the specified diagnostic, 636 /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior 637 /// to the semicolon, consumes that extra token. 638 bool ExpectAndConsumeSemi(unsigned DiagID); 639 640 /// \brief The kind of extra semi diagnostic to emit. 641 enum ExtraSemiKind { 642 OutsideFunction = 0, 643 InsideStruct = 1, 644 InstanceVariableList = 2, 645 AfterMemberFunctionDefinition = 3 646 }; 647 648 /// \brief Consume any extra semi-colons until the end of the line. 649 void ConsumeExtraSemi(ExtraSemiKind Kind, unsigned TST = TST_unspecified); 650 651public: 652 //===--------------------------------------------------------------------===// 653 // Scope manipulation 654 655 /// ParseScope - Introduces a new scope for parsing. The kind of 656 /// scope is determined by ScopeFlags. Objects of this type should 657 /// be created on the stack to coincide with the position where the 658 /// parser enters the new scope, and this object's constructor will 659 /// create that new scope. Similarly, once the object is destroyed 660 /// the parser will exit the scope. 661 class ParseScope { 662 Parser *Self; 663 ParseScope(const ParseScope &) LLVM_DELETED_FUNCTION; 664 void operator=(const ParseScope &) LLVM_DELETED_FUNCTION; 665 666 public: 667 // ParseScope - Construct a new object to manage a scope in the 668 // parser Self where the new Scope is created with the flags 669 // ScopeFlags, but only when ManageScope is true (the default). If 670 // ManageScope is false, this object does nothing. 671 ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 672 : Self(Self) { 673 if (ManageScope) 674 Self->EnterScope(ScopeFlags); 675 else 676 this->Self = 0; 677 } 678 679 // Exit - Exit the scope associated with this object now, rather 680 // than waiting until the object is destroyed. 681 void Exit() { 682 if (Self) { 683 Self->ExitScope(); 684 Self = 0; 685 } 686 } 687 688 ~ParseScope() { 689 Exit(); 690 } 691 }; 692 693 /// EnterScope - Start a new scope. 694 void EnterScope(unsigned ScopeFlags); 695 696 /// ExitScope - Pop a scope off the scope stack. 697 void ExitScope(); 698 699private: 700 /// \brief RAII object used to modify the scope flags for the current scope. 701 class ParseScopeFlags { 702 Scope *CurScope; 703 unsigned OldFlags; 704 ParseScopeFlags(const ParseScopeFlags &) LLVM_DELETED_FUNCTION; 705 void operator=(const ParseScopeFlags &) LLVM_DELETED_FUNCTION; 706 707 public: 708 ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true); 709 ~ParseScopeFlags(); 710 }; 711 712 //===--------------------------------------------------------------------===// 713 // Diagnostic Emission and Error recovery. 714 715public: 716 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 717 DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 718 DiagnosticBuilder Diag(unsigned DiagID) { 719 return Diag(Tok, DiagID); 720 } 721 722private: 723 void SuggestParentheses(SourceLocation Loc, unsigned DK, 724 SourceRange ParenRange); 725 void CheckNestedObjCContexts(SourceLocation AtLoc); 726 727public: 728 /// SkipUntil - Read tokens until we get to the specified token, then consume 729 /// it (unless DontConsume is true). Because we cannot guarantee that the 730 /// token will ever occur, this skips to the next token, or to some likely 731 /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 732 /// character. 733 /// 734 /// If SkipUntil finds the specified token, it returns true, otherwise it 735 /// returns false. 736 bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 737 bool DontConsume = false, bool StopAtCodeCompletion = false) { 738 return SkipUntil(llvm::makeArrayRef(T), StopAtSemi, DontConsume, 739 StopAtCodeCompletion); 740 } 741 bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 742 bool DontConsume = false, bool StopAtCodeCompletion = false) { 743 tok::TokenKind TokArray[] = {T1, T2}; 744 return SkipUntil(TokArray, StopAtSemi, DontConsume,StopAtCodeCompletion); 745 } 746 bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, 747 bool StopAtSemi = true, bool DontConsume = false, 748 bool StopAtCodeCompletion = false) { 749 tok::TokenKind TokArray[] = {T1, T2, T3}; 750 return SkipUntil(TokArray, StopAtSemi, DontConsume,StopAtCodeCompletion); 751 } 752 bool SkipUntil(ArrayRef<tok::TokenKind> Toks, bool StopAtSemi = true, 753 bool DontConsume = false, bool StopAtCodeCompletion = false); 754 755 /// SkipMalformedDecl - Read tokens until we get to some likely good stopping 756 /// point for skipping past a simple-declaration. 757 void SkipMalformedDecl(); 758 759private: 760 //===--------------------------------------------------------------------===// 761 // Lexing and parsing of C++ inline methods. 762 763 struct ParsingClass; 764 765 /// [class.mem]p1: "... the class is regarded as complete within 766 /// - function bodies 767 /// - default arguments 768 /// - exception-specifications (TODO: C++0x) 769 /// - and brace-or-equal-initializers for non-static data members 770 /// (including such things in nested classes)." 771 /// LateParsedDeclarations build the tree of those elements so they can 772 /// be parsed after parsing the top-level class. 773 class LateParsedDeclaration { 774 public: 775 virtual ~LateParsedDeclaration(); 776 777 virtual void ParseLexedMethodDeclarations(); 778 virtual void ParseLexedMemberInitializers(); 779 virtual void ParseLexedMethodDefs(); 780 virtual void ParseLexedAttributes(); 781 }; 782 783 /// Inner node of the LateParsedDeclaration tree that parses 784 /// all its members recursively. 785 class LateParsedClass : public LateParsedDeclaration { 786 public: 787 LateParsedClass(Parser *P, ParsingClass *C); 788 virtual ~LateParsedClass(); 789 790 virtual void ParseLexedMethodDeclarations(); 791 virtual void ParseLexedMemberInitializers(); 792 virtual void ParseLexedMethodDefs(); 793 virtual void ParseLexedAttributes(); 794 795 private: 796 Parser *Self; 797 ParsingClass *Class; 798 }; 799 800 /// Contains the lexed tokens of an attribute with arguments that 801 /// may reference member variables and so need to be parsed at the 802 /// end of the class declaration after parsing all other member 803 /// member declarations. 804 /// FIXME: Perhaps we should change the name of LateParsedDeclaration to 805 /// LateParsedTokens. 806 struct LateParsedAttribute : public LateParsedDeclaration { 807 Parser *Self; 808 CachedTokens Toks; 809 IdentifierInfo &AttrName; 810 SourceLocation AttrNameLoc; 811 SmallVector<Decl*, 2> Decls; 812 813 explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name, 814 SourceLocation Loc) 815 : Self(P), AttrName(Name), AttrNameLoc(Loc) {} 816 817 virtual void ParseLexedAttributes(); 818 819 void addDecl(Decl *D) { Decls.push_back(D); } 820 }; 821 822 // A list of late-parsed attributes. Used by ParseGNUAttributes. 823 class LateParsedAttrList: public SmallVector<LateParsedAttribute *, 2> { 824 public: 825 LateParsedAttrList(bool PSoon = false) : ParseSoon(PSoon) { } 826 827 bool parseSoon() { return ParseSoon; } 828 829 private: 830 bool ParseSoon; // Are we planning to parse these shortly after creation? 831 }; 832 833 /// Contains the lexed tokens of a member function definition 834 /// which needs to be parsed at the end of the class declaration 835 /// after parsing all other member declarations. 836 struct LexedMethod : public LateParsedDeclaration { 837 Parser *Self; 838 Decl *D; 839 CachedTokens Toks; 840 841 /// \brief Whether this member function had an associated template 842 /// scope. When true, D is a template declaration. 843 /// otherwise, it is a member function declaration. 844 bool TemplateScope; 845 846 explicit LexedMethod(Parser* P, Decl *MD) 847 : Self(P), D(MD), TemplateScope(false) {} 848 849 virtual void ParseLexedMethodDefs(); 850 }; 851 852 /// LateParsedDefaultArgument - Keeps track of a parameter that may 853 /// have a default argument that cannot be parsed yet because it 854 /// occurs within a member function declaration inside the class 855 /// (C++ [class.mem]p2). 856 struct LateParsedDefaultArgument { 857 explicit LateParsedDefaultArgument(Decl *P, 858 CachedTokens *Toks = 0) 859 : Param(P), Toks(Toks) { } 860 861 /// Param - The parameter declaration for this parameter. 862 Decl *Param; 863 864 /// Toks - The sequence of tokens that comprises the default 865 /// argument expression, not including the '=' or the terminating 866 /// ')' or ','. This will be NULL for parameters that have no 867 /// default argument. 868 CachedTokens *Toks; 869 }; 870 871 /// LateParsedMethodDeclaration - A method declaration inside a class that 872 /// contains at least one entity whose parsing needs to be delayed 873 /// until the class itself is completely-defined, such as a default 874 /// argument (C++ [class.mem]p2). 875 struct LateParsedMethodDeclaration : public LateParsedDeclaration { 876 explicit LateParsedMethodDeclaration(Parser *P, Decl *M) 877 : Self(P), Method(M), TemplateScope(false), ExceptionSpecTokens(0) { } 878 879 virtual void ParseLexedMethodDeclarations(); 880 881 Parser* Self; 882 883 /// Method - The method declaration. 884 Decl *Method; 885 886 /// \brief Whether this member function had an associated template 887 /// scope. When true, D is a template declaration. 888 /// othewise, it is a member function declaration. 889 bool TemplateScope; 890 891 /// DefaultArgs - Contains the parameters of the function and 892 /// their default arguments. At least one of the parameters will 893 /// have a default argument, but all of the parameters of the 894 /// method will be stored so that they can be reintroduced into 895 /// scope at the appropriate times. 896 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 897 898 /// \brief The set of tokens that make up an exception-specification that 899 /// has not yet been parsed. 900 CachedTokens *ExceptionSpecTokens; 901 }; 902 903 /// LateParsedMemberInitializer - An initializer for a non-static class data 904 /// member whose parsing must to be delayed until the class is completely 905 /// defined (C++11 [class.mem]p2). 906 struct LateParsedMemberInitializer : public LateParsedDeclaration { 907 LateParsedMemberInitializer(Parser *P, Decl *FD) 908 : Self(P), Field(FD) { } 909 910 virtual void ParseLexedMemberInitializers(); 911 912 Parser *Self; 913 914 /// Field - The field declaration. 915 Decl *Field; 916 917 /// CachedTokens - The sequence of tokens that comprises the initializer, 918 /// including any leading '='. 919 CachedTokens Toks; 920 }; 921 922 /// LateParsedDeclarationsContainer - During parsing of a top (non-nested) 923 /// C++ class, its method declarations that contain parts that won't be 924 /// parsed until after the definition is completed (C++ [class.mem]p2), 925 /// the method declarations and possibly attached inline definitions 926 /// will be stored here with the tokens that will be parsed to create those 927 /// entities. 928 typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer; 929 930 /// \brief Representation of a class that has been parsed, including 931 /// any member function declarations or definitions that need to be 932 /// parsed after the corresponding top-level class is complete. 933 struct ParsingClass { 934 ParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface) 935 : TopLevelClass(TopLevelClass), TemplateScope(false), 936 IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { } 937 938 /// \brief Whether this is a "top-level" class, meaning that it is 939 /// not nested within another class. 940 bool TopLevelClass : 1; 941 942 /// \brief Whether this class had an associated template 943 /// scope. When true, TagOrTemplate is a template declaration; 944 /// othewise, it is a tag declaration. 945 bool TemplateScope : 1; 946 947 /// \brief Whether this class is an __interface. 948 bool IsInterface : 1; 949 950 /// \brief The class or class template whose definition we are parsing. 951 Decl *TagOrTemplate; 952 953 /// LateParsedDeclarations - Method declarations, inline definitions and 954 /// nested classes that contain pieces whose parsing will be delayed until 955 /// the top-level class is fully defined. 956 LateParsedDeclarationsContainer LateParsedDeclarations; 957 }; 958 959 /// \brief The stack of classes that is currently being 960 /// parsed. Nested and local classes will be pushed onto this stack 961 /// when they are parsed, and removed afterward. 962 std::stack<ParsingClass *> ClassStack; 963 964 ParsingClass &getCurrentClass() { 965 assert(!ClassStack.empty() && "No lexed method stacks!"); 966 return *ClassStack.top(); 967 } 968 969 /// \brief RAII object used to manage the parsing of a class definition. 970 class ParsingClassDefinition { 971 Parser &P; 972 bool Popped; 973 Sema::ParsingClassState State; 974 975 public: 976 ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass, 977 bool IsInterface) 978 : P(P), Popped(false), 979 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) { 980 } 981 982 /// \brief Pop this class of the stack. 983 void Pop() { 984 assert(!Popped && "Nested class has already been popped"); 985 Popped = true; 986 P.PopParsingClass(State); 987 } 988 989 ~ParsingClassDefinition() { 990 if (!Popped) 991 P.PopParsingClass(State); 992 } 993 }; 994 995 /// \brief Contains information about any template-specific 996 /// information that has been parsed prior to parsing declaration 997 /// specifiers. 998 struct ParsedTemplateInfo { 999 ParsedTemplateInfo() 1000 : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 1001 1002 ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 1003 bool isSpecialization, 1004 bool lastParameterListWasEmpty = false) 1005 : Kind(isSpecialization? ExplicitSpecialization : Template), 1006 TemplateParams(TemplateParams), 1007 LastParameterListWasEmpty(lastParameterListWasEmpty) { } 1008 1009 explicit ParsedTemplateInfo(SourceLocation ExternLoc, 1010 SourceLocation TemplateLoc) 1011 : Kind(ExplicitInstantiation), TemplateParams(0), 1012 ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 1013 LastParameterListWasEmpty(false){ } 1014 1015 /// \brief The kind of template we are parsing. 1016 enum { 1017 /// \brief We are not parsing a template at all. 1018 NonTemplate = 0, 1019 /// \brief We are parsing a template declaration. 1020 Template, 1021 /// \brief We are parsing an explicit specialization. 1022 ExplicitSpecialization, 1023 /// \brief We are parsing an explicit instantiation. 1024 ExplicitInstantiation 1025 } Kind; 1026 1027 /// \brief The template parameter lists, for template declarations 1028 /// and explicit specializations. 1029 TemplateParameterLists *TemplateParams; 1030 1031 /// \brief The location of the 'extern' keyword, if any, for an explicit 1032 /// instantiation 1033 SourceLocation ExternLoc; 1034 1035 /// \brief The location of the 'template' keyword, for an explicit 1036 /// instantiation. 1037 SourceLocation TemplateLoc; 1038 1039 /// \brief Whether the last template parameter list was empty. 1040 bool LastParameterListWasEmpty; 1041 1042 SourceRange getSourceRange() const LLVM_READONLY; 1043 }; 1044 1045 /// \brief Contains a late templated function. 1046 /// Will be parsed at the end of the translation unit. 1047 struct LateParsedTemplatedFunction { 1048 explicit LateParsedTemplatedFunction(Decl *MD) 1049 : D(MD) {} 1050 1051 CachedTokens Toks; 1052 1053 /// \brief The template function declaration to be late parsed. 1054 Decl *D; 1055 }; 1056 1057 void LexTemplateFunctionForLateParsing(CachedTokens &Toks); 1058 void ParseLateTemplatedFuncDef(LateParsedTemplatedFunction &LMT); 1059 typedef llvm::DenseMap<const FunctionDecl*, LateParsedTemplatedFunction*> 1060 LateParsedTemplateMapT; 1061 LateParsedTemplateMapT LateParsedTemplateMap; 1062 1063 static void LateTemplateParserCallback(void *P, const FunctionDecl *FD); 1064 void LateTemplateParser(const FunctionDecl *FD); 1065 1066 Sema::ParsingClassState 1067 PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface); 1068 void DeallocateParsedClasses(ParsingClass *Class); 1069 void PopParsingClass(Sema::ParsingClassState); 1070 1071 NamedDecl *ParseCXXInlineMethodDef(AccessSpecifier AS, 1072 AttributeList *AccessAttrs, 1073 ParsingDeclarator &D, 1074 const ParsedTemplateInfo &TemplateInfo, 1075 const VirtSpecifiers& VS, 1076 FunctionDefinitionKind DefinitionKind, 1077 ExprResult& Init); 1078 void ParseCXXNonStaticMemberInitializer(Decl *VarD); 1079 void ParseLexedAttributes(ParsingClass &Class); 1080 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D, 1081 bool EnterScope, bool OnDefinition); 1082 void ParseLexedAttribute(LateParsedAttribute &LA, 1083 bool EnterScope, bool OnDefinition); 1084 void ParseLexedMethodDeclarations(ParsingClass &Class); 1085 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); 1086 void ParseLexedMethodDefs(ParsingClass &Class); 1087 void ParseLexedMethodDef(LexedMethod &LM); 1088 void ParseLexedMemberInitializers(ParsingClass &Class); 1089 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI); 1090 void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod); 1091 bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks); 1092 bool ConsumeAndStoreUntil(tok::TokenKind T1, 1093 CachedTokens &Toks, 1094 bool StopAtSemi = true, 1095 bool ConsumeFinalToken = true) { 1096 return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); 1097 } 1098 bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 1099 CachedTokens &Toks, 1100 bool StopAtSemi = true, 1101 bool ConsumeFinalToken = true); 1102 1103 //===--------------------------------------------------------------------===// 1104 // C99 6.9: External Definitions. 1105 struct ParsedAttributesWithRange : ParsedAttributes { 1106 ParsedAttributesWithRange(AttributeFactory &factory) 1107 : ParsedAttributes(factory) {} 1108 1109 SourceRange Range; 1110 }; 1111 1112 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs, 1113 ParsingDeclSpec *DS = 0); 1114 bool isDeclarationAfterDeclarator(); 1115 bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); 1116 DeclGroupPtrTy ParseDeclarationOrFunctionDefinition( 1117 ParsedAttributesWithRange &attrs, 1118 ParsingDeclSpec *DS = 0, 1119 AccessSpecifier AS = AS_none); 1120 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs, 1121 ParsingDeclSpec &DS, 1122 AccessSpecifier AS); 1123 1124 Decl *ParseFunctionDefinition(ParsingDeclarator &D, 1125 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1126 LateParsedAttrList *LateParsedAttrs = 0); 1127 void ParseKNRParamDeclarations(Declarator &D); 1128 // EndLoc, if non-NULL, is filled with the location of the last token of 1129 // the simple-asm. 1130 ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 1131 ExprResult ParseAsmStringLiteral(); 1132 1133 // Objective-C External Declarations 1134 void MaybeSkipAttributes(tok::ObjCKeywordKind Kind); 1135 DeclGroupPtrTy ParseObjCAtDirectives(); 1136 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); 1137 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, 1138 ParsedAttributes &prefixAttrs); 1139 void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc, 1140 BalancedDelimiterTracker &T, 1141 SmallVectorImpl<Decl *> &AllIvarDecls, 1142 bool RBraceMissing); 1143 void ParseObjCClassInstanceVariables(Decl *interfaceDecl, 1144 tok::ObjCKeywordKind visibility, 1145 SourceLocation atLoc); 1146 bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P, 1147 SmallVectorImpl<SourceLocation> &PLocs, 1148 bool WarnOnDeclarations, 1149 SourceLocation &LAngleLoc, 1150 SourceLocation &EndProtoLoc); 1151 bool ParseObjCProtocolQualifiers(DeclSpec &DS); 1152 void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, 1153 Decl *CDecl); 1154 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 1155 ParsedAttributes &prefixAttrs); 1156 1157 struct ObjCImplParsingDataRAII { 1158 Parser &P; 1159 Decl *Dcl; 1160 bool HasCFunction; 1161 typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer; 1162 LateParsedObjCMethodContainer LateParsedObjCMethods; 1163 1164 ObjCImplParsingDataRAII(Parser &parser, Decl *D) 1165 : P(parser), Dcl(D), HasCFunction(false) { 1166 P.CurParsedObjCImpl = this; 1167 Finished = false; 1168 } 1169 ~ObjCImplParsingDataRAII(); 1170 1171 void finish(SourceRange AtEnd); 1172 bool isFinished() const { return Finished; } 1173 1174 private: 1175 bool Finished; 1176 }; 1177 ObjCImplParsingDataRAII *CurParsedObjCImpl; 1178 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl); 1179 1180 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc); 1181 DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); 1182 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); 1183 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); 1184 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); 1185 1186 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 1187 // Definitions for Objective-c context sensitive keywords recognition. 1188 enum ObjCTypeQual { 1189 objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 1190 objc_NumQuals 1191 }; 1192 IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 1193 1194 bool isTokIdentifier_in() const; 1195 1196 ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx, 1197 ParsedAttributes *ParamAttrs); 1198 void ParseObjCMethodRequirement(); 1199 Decl *ParseObjCMethodPrototype( 1200 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 1201 bool MethodDefinition = true); 1202 Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 1203 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 1204 bool MethodDefinition=true); 1205 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS); 1206 1207 Decl *ParseObjCMethodDefinition(); 1208 1209public: 1210 //===--------------------------------------------------------------------===// 1211 // C99 6.5: Expressions. 1212 1213 /// TypeCastState - State whether an expression is or may be a type cast. 1214 enum TypeCastState { 1215 NotTypeCast = 0, 1216 MaybeTypeCast, 1217 IsTypeCast 1218 }; 1219 1220 ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast); 1221 ExprResult ParseConstantExpression(TypeCastState isTypeCast = NotTypeCast); 1222 // Expr that doesn't include commas. 1223 ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast); 1224 1225 ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl<Token> &LineToks, 1226 unsigned &NumLineToksConsumed, 1227 void *Info, 1228 bool IsUnevaluated); 1229 1230private: 1231 ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 1232 1233 ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 1234 1235 ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, 1236 prec::Level MinPrec); 1237 ExprResult ParseCastExpression(bool isUnaryExpression, 1238 bool isAddressOfOperand, 1239 bool &NotCastExpr, 1240 TypeCastState isTypeCast); 1241 ExprResult ParseCastExpression(bool isUnaryExpression, 1242 bool isAddressOfOperand = false, 1243 TypeCastState isTypeCast = NotTypeCast); 1244 1245 /// Returns true if the next token cannot start an expression. 1246 bool isNotExpressionStart(); 1247 1248 /// Returns true if the next token would start a postfix-expression 1249 /// suffix. 1250 bool isPostfixExpressionSuffixStart() { 1251 tok::TokenKind K = Tok.getKind(); 1252 return (K == tok::l_square || K == tok::l_paren || 1253 K == tok::period || K == tok::arrow || 1254 K == tok::plusplus || K == tok::minusminus); 1255 } 1256 1257 ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); 1258 ExprResult ParseUnaryExprOrTypeTraitExpression(); 1259 ExprResult ParseBuiltinPrimaryExpression(); 1260 1261 ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, 1262 bool &isCastExpr, 1263 ParsedType &CastTy, 1264 SourceRange &CastRange); 1265 1266 typedef SmallVector<Expr*, 20> ExprListTy; 1267 typedef SmallVector<SourceLocation, 20> CommaLocsTy; 1268 1269 /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 1270 bool ParseExpressionList(SmallVectorImpl<Expr*> &Exprs, 1271 SmallVectorImpl<SourceLocation> &CommaLocs, 1272 void (Sema::*Completer)(Scope *S, 1273 Expr *Data, 1274 ArrayRef<Expr *> Args) = 0, 1275 Expr *Data = 0); 1276 1277 /// ParenParseOption - Control what ParseParenExpression will parse. 1278 enum ParenParseOption { 1279 SimpleExpr, // Only parse '(' expression ')' 1280 CompoundStmt, // Also allow '(' compound-statement ')' 1281 CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 1282 CastExpr // Also allow '(' type-name ')' <anything> 1283 }; 1284 ExprResult ParseParenExpression(ParenParseOption &ExprType, 1285 bool stopIfCastExpr, 1286 bool isTypeCast, 1287 ParsedType &CastTy, 1288 SourceLocation &RParenLoc); 1289 1290 ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 1291 ParsedType &CastTy, 1292 BalancedDelimiterTracker &Tracker); 1293 ExprResult ParseCompoundLiteralExpression(ParsedType Ty, 1294 SourceLocation LParenLoc, 1295 SourceLocation RParenLoc); 1296 1297 ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false); 1298 1299 ExprResult ParseGenericSelectionExpression(); 1300 1301 ExprResult ParseObjCBoolLiteral(); 1302 1303 //===--------------------------------------------------------------------===// 1304 // C++ Expressions 1305 ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 1306 1307 bool areTokensAdjacent(const Token &A, const Token &B); 1308 1309 void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr, 1310 bool EnteringContext, IdentifierInfo &II, 1311 CXXScopeSpec &SS); 1312 1313 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 1314 ParsedType ObjectType, 1315 bool EnteringContext, 1316 bool *MayBePseudoDestructor = 0, 1317 bool IsTypename = false, 1318 IdentifierInfo **LastII = 0); 1319 1320 void CheckForLParenAfterColonColon(); 1321 1322 //===--------------------------------------------------------------------===// 1323 // C++0x 5.1.2: Lambda expressions 1324 1325 // [...] () -> type {...} 1326 ExprResult ParseLambdaExpression(); 1327 ExprResult TryParseLambdaExpression(); 1328 Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro); 1329 bool TryParseLambdaIntroducer(LambdaIntroducer &Intro); 1330 ExprResult ParseLambdaExpressionAfterIntroducer( 1331 LambdaIntroducer &Intro); 1332 1333 //===--------------------------------------------------------------------===// 1334 // C++ 5.2p1: C++ Casts 1335 ExprResult ParseCXXCasts(); 1336 1337 //===--------------------------------------------------------------------===// 1338 // C++ 5.2p1: C++ Type Identification 1339 ExprResult ParseCXXTypeid(); 1340 1341 //===--------------------------------------------------------------------===// 1342 // C++ : Microsoft __uuidof Expression 1343 ExprResult ParseCXXUuidof(); 1344 1345 //===--------------------------------------------------------------------===// 1346 // C++ 5.2.4: C++ Pseudo-Destructor Expressions 1347 ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 1348 tok::TokenKind OpKind, 1349 CXXScopeSpec &SS, 1350 ParsedType ObjectType); 1351 1352 //===--------------------------------------------------------------------===// 1353 // C++ 9.3.2: C++ 'this' pointer 1354 ExprResult ParseCXXThis(); 1355 1356 //===--------------------------------------------------------------------===// 1357 // C++ 15: C++ Throw Expression 1358 ExprResult ParseThrowExpression(); 1359 1360 ExceptionSpecificationType tryParseExceptionSpecification( 1361 SourceRange &SpecificationRange, 1362 SmallVectorImpl<ParsedType> &DynamicExceptions, 1363 SmallVectorImpl<SourceRange> &DynamicExceptionRanges, 1364 ExprResult &NoexceptExpr); 1365 1366 // EndLoc is filled with the location of the last token of the specification. 1367 ExceptionSpecificationType ParseDynamicExceptionSpecification( 1368 SourceRange &SpecificationRange, 1369 SmallVectorImpl<ParsedType> &Exceptions, 1370 SmallVectorImpl<SourceRange> &Ranges); 1371 1372 //===--------------------------------------------------------------------===// 1373 // C++0x 8: Function declaration trailing-return-type 1374 TypeResult ParseTrailingReturnType(SourceRange &Range); 1375 1376 //===--------------------------------------------------------------------===// 1377 // C++ 2.13.5: C++ Boolean Literals 1378 ExprResult ParseCXXBoolLiteral(); 1379 1380 //===--------------------------------------------------------------------===// 1381 // C++ 5.2.3: Explicit type conversion (functional notation) 1382 ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 1383 1384 /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 1385 /// This should only be called when the current token is known to be part of 1386 /// simple-type-specifier. 1387 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 1388 1389 bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 1390 1391 //===--------------------------------------------------------------------===// 1392 // C++ 5.3.4 and 5.3.5: C++ new and delete 1393 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs, 1394 Declarator &D); 1395 void ParseDirectNewDeclarator(Declarator &D); 1396 ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 1397 ExprResult ParseCXXDeleteExpression(bool UseGlobal, 1398 SourceLocation Start); 1399 1400 //===--------------------------------------------------------------------===// 1401 // C++ if/switch/while condition expression. 1402 bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult, 1403 SourceLocation Loc, bool ConvertToBoolean); 1404 1405 //===--------------------------------------------------------------------===// 1406 // C++ types 1407 1408 //===--------------------------------------------------------------------===// 1409 // C99 6.7.8: Initialization. 1410 1411 /// ParseInitializer 1412 /// initializer: [C99 6.7.8] 1413 /// assignment-expression 1414 /// '{' ... 1415 ExprResult ParseInitializer() { 1416 if (Tok.isNot(tok::l_brace)) 1417 return ParseAssignmentExpression(); 1418 return ParseBraceInitializer(); 1419 } 1420 bool MayBeDesignationStart(); 1421 ExprResult ParseBraceInitializer(); 1422 ExprResult ParseInitializerWithPotentialDesignator(); 1423 1424 //===--------------------------------------------------------------------===// 1425 // clang Expressions 1426 1427 ExprResult ParseBlockLiteralExpression(); // ^{...} 1428 1429 //===--------------------------------------------------------------------===// 1430 // Objective-C Expressions 1431 ExprResult ParseObjCAtExpression(SourceLocation AtLocation); 1432 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 1433 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc); 1434 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc); 1435 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc, bool ArgValue); 1436 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc); 1437 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc); 1438 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc); 1439 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 1440 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 1441 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 1442 bool isSimpleObjCMessageExpression(); 1443 ExprResult ParseObjCMessageExpression(); 1444 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 1445 SourceLocation SuperLoc, 1446 ParsedType ReceiverType, 1447 ExprArg ReceiverExpr); 1448 ExprResult ParseAssignmentExprWithObjCMessageExprStart( 1449 SourceLocation LBracloc, SourceLocation SuperLoc, 1450 ParsedType ReceiverType, ExprArg ReceiverExpr); 1451 bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); 1452 1453 //===--------------------------------------------------------------------===// 1454 // C99 6.8: Statements and Blocks. 1455 1456 /// A SmallVector of statements, with stack size 32 (as that is the only one 1457 /// used.) 1458 typedef SmallVector<Stmt*, 32> StmtVector; 1459 /// A SmallVector of expressions, with stack size 12 (the maximum used.) 1460 typedef SmallVector<Expr*, 12> ExprVector; 1461 /// A SmallVector of types. 1462 typedef SmallVector<ParsedType, 12> TypeVector; 1463 1464 StmtResult ParseStatement(SourceLocation *TrailingElseLoc = 0) { 1465 StmtVector Stmts; 1466 return ParseStatementOrDeclaration(Stmts, true, TrailingElseLoc); 1467 } 1468 StmtResult ParseStatementOrDeclaration(StmtVector &Stmts, 1469 bool OnlyStatement, 1470 SourceLocation *TrailingElseLoc = 0); 1471 StmtResult ParseStatementOrDeclarationAfterAttributes( 1472 StmtVector &Stmts, 1473 bool OnlyStatement, 1474 SourceLocation *TrailingElseLoc, 1475 ParsedAttributesWithRange &Attrs); 1476 StmtResult ParseExprStatement(); 1477 StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs); 1478 StmtResult ParseCaseStatement(bool MissingCase = false, 1479 ExprResult Expr = ExprResult()); 1480 StmtResult ParseDefaultStatement(); 1481 StmtResult ParseCompoundStatement(bool isStmtExpr = false); 1482 StmtResult ParseCompoundStatement(bool isStmtExpr, 1483 unsigned ScopeFlags); 1484 void ParseCompoundStatementLeadingPragmas(); 1485 StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 1486 bool ParseParenExprOrCondition(ExprResult &ExprResult, 1487 Decl *&DeclResult, 1488 SourceLocation Loc, 1489 bool ConvertToBoolean); 1490 StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc); 1491 StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc); 1492 StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc); 1493 StmtResult ParseDoStatement(); 1494 StmtResult ParseForStatement(SourceLocation *TrailingElseLoc); 1495 StmtResult ParseGotoStatement(); 1496 StmtResult ParseContinueStatement(); 1497 StmtResult ParseBreakStatement(); 1498 StmtResult ParseReturnStatement(); 1499 StmtResult ParseAsmStatement(bool &msAsm); 1500 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc); 1501 1502 /// \brief Describes the behavior that should be taken for an __if_exists 1503 /// block. 1504 enum IfExistsBehavior { 1505 /// \brief Parse the block; this code is always used. 1506 IEB_Parse, 1507 /// \brief Skip the block entirely; this code is never used. 1508 IEB_Skip, 1509 /// \brief Parse the block as a dependent block, which may be used in 1510 /// some template instantiations but not others. 1511 IEB_Dependent 1512 }; 1513 1514 /// \brief Describes the condition of a Microsoft __if_exists or 1515 /// __if_not_exists block. 1516 struct IfExistsCondition { 1517 /// \brief The location of the initial keyword. 1518 SourceLocation KeywordLoc; 1519 /// \brief Whether this is an __if_exists block (rather than an 1520 /// __if_not_exists block). 1521 bool IsIfExists; 1522 1523 /// \brief Nested-name-specifier preceding the name. 1524 CXXScopeSpec SS; 1525 1526 /// \brief The name we're looking for. 1527 UnqualifiedId Name; 1528 1529 /// \brief The behavior of this __if_exists or __if_not_exists block 1530 /// should. 1531 IfExistsBehavior Behavior; 1532 }; 1533 1534 bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result); 1535 void ParseMicrosoftIfExistsStatement(StmtVector &Stmts); 1536 void ParseMicrosoftIfExistsExternalDeclaration(); 1537 void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, 1538 AccessSpecifier& CurAS); 1539 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, 1540 bool &InitExprsOk); 1541 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names, 1542 SmallVectorImpl<Expr *> &Constraints, 1543 SmallVectorImpl<Expr *> &Exprs); 1544 1545 //===--------------------------------------------------------------------===// 1546 // C++ 6: Statements and Blocks 1547 1548 StmtResult ParseCXXTryBlock(); 1549 StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry = false); 1550 StmtResult ParseCXXCatchBlock(bool FnCatch = false); 1551 1552 //===--------------------------------------------------------------------===// 1553 // MS: SEH Statements and Blocks 1554 1555 StmtResult ParseSEHTryBlock(); 1556 StmtResult ParseSEHTryBlockCommon(SourceLocation Loc); 1557 StmtResult ParseSEHExceptBlock(SourceLocation Loc); 1558 StmtResult ParseSEHFinallyBlock(SourceLocation Loc); 1559 1560 //===--------------------------------------------------------------------===// 1561 // Objective-C Statements 1562 1563 StmtResult ParseObjCAtStatement(SourceLocation atLoc); 1564 StmtResult ParseObjCTryStmt(SourceLocation atLoc); 1565 StmtResult ParseObjCThrowStmt(SourceLocation atLoc); 1566 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1567 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc); 1568 1569 1570 //===--------------------------------------------------------------------===// 1571 // C99 6.7: Declarations. 1572 1573 /// A context for parsing declaration specifiers. TODO: flesh this 1574 /// out, there are other significant restrictions on specifiers than 1575 /// would be best implemented in the parser. 1576 enum DeclSpecContext { 1577 DSC_normal, // normal context 1578 DSC_class, // class context, enables 'friend' 1579 DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list 1580 DSC_trailing, // C++11 trailing-type-specifier in a trailing return type 1581 DSC_top_level // top-level/namespace declaration context 1582 }; 1583 1584 /// Information on a C++0x for-range-initializer found while parsing a 1585 /// declaration which turns out to be a for-range-declaration. 1586 struct ForRangeInit { 1587 SourceLocation ColonLoc; 1588 ExprResult RangeExpr; 1589 1590 bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); } 1591 }; 1592 1593 DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts, 1594 unsigned Context, SourceLocation &DeclEnd, 1595 ParsedAttributesWithRange &attrs); 1596 DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts, 1597 unsigned Context, 1598 SourceLocation &DeclEnd, 1599 ParsedAttributesWithRange &attrs, 1600 bool RequireSemi, 1601 ForRangeInit *FRI = 0); 1602 bool MightBeDeclarator(unsigned Context); 1603 DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1604 bool AllowFunctionDefinitions, 1605 SourceLocation *DeclEnd = 0, 1606 ForRangeInit *FRI = 0); 1607 Decl *ParseDeclarationAfterDeclarator(Declarator &D, 1608 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1609 bool ParseAsmAttributesAfterDeclarator(Declarator &D); 1610 Decl *ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D, 1611 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1612 Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope); 1613 Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope); 1614 1615 /// \brief When in code-completion, skip parsing of the function/method body 1616 /// unless the body contains the code-completion point. 1617 /// 1618 /// \returns true if the function body was skipped. 1619 bool trySkippingFunctionBody(); 1620 1621 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 1622 const ParsedTemplateInfo &TemplateInfo, 1623 AccessSpecifier AS, DeclSpecContext DSC, 1624 ParsedAttributesWithRange &Attrs); 1625 DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 1626 void ParseDeclarationSpecifiers(DeclSpec &DS, 1627 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1628 AccessSpecifier AS = AS_none, 1629 DeclSpecContext DSC = DSC_normal, 1630 LateParsedAttrList *LateAttrs = 0); 1631 1632 void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none, 1633 DeclSpecContext DSC = DSC_normal); 1634 1635 void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, 1636 Declarator::TheContext Context); 1637 1638 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 1639 const ParsedTemplateInfo &TemplateInfo, 1640 AccessSpecifier AS, DeclSpecContext DSC); 1641 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); 1642 void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1643 Decl *TagDecl); 1644 1645 struct FieldCallback { 1646 virtual void invoke(ParsingFieldDeclarator &Field) = 0; 1647 virtual ~FieldCallback() {} 1648 1649 private: 1650 virtual void _anchor(); 1651 }; 1652 struct ObjCPropertyCallback; 1653 1654 void ParseStructDeclaration(ParsingDeclSpec &DS, FieldCallback &Callback); 1655 1656 bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false); 1657 bool isTypeSpecifierQualifier(); 1658 bool isTypeQualifier() const; 1659 1660 /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 1661 /// is definitely a type-specifier. Return false if it isn't part of a type 1662 /// specifier or if we're not sure. 1663 bool isKnownToBeTypeSpecifier(const Token &Tok) const; 1664 1665 /// \brief Return true if we know that we are definitely looking at a 1666 /// decl-specifier, and isn't part of an expression such as a function-style 1667 /// cast. Return false if it's no a decl-specifier, or we're not sure. 1668 bool isKnownToBeDeclarationSpecifier() { 1669 if (getLangOpts().CPlusPlus) 1670 return isCXXDeclarationSpecifier() == TPResult::True(); 1671 return isDeclarationSpecifier(true); 1672 } 1673 1674 /// isDeclarationStatement - Disambiguates between a declaration or an 1675 /// expression statement, when parsing function bodies. 1676 /// Returns true for declaration, false for expression. 1677 bool isDeclarationStatement() { 1678 if (getLangOpts().CPlusPlus) 1679 return isCXXDeclarationStatement(); 1680 return isDeclarationSpecifier(true); 1681 } 1682 1683 /// isForInitDeclaration - Disambiguates between a declaration or an 1684 /// expression in the context of the C 'clause-1' or the C++ 1685 // 'for-init-statement' part of a 'for' statement. 1686 /// Returns true for declaration, false for expression. 1687 bool isForInitDeclaration() { 1688 if (getLangOpts().CPlusPlus) 1689 return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/true); 1690 return isDeclarationSpecifier(true); 1691 } 1692 1693 /// \brief Determine whether we are currently at the start of an Objective-C 1694 /// class message that appears to be missing the open bracket '['. 1695 bool isStartOfObjCClassMessageMissingOpenBracket(); 1696 1697 /// \brief Starting with a scope specifier, identifier, or 1698 /// template-id that refers to the current class, determine whether 1699 /// this is a constructor declarator. 1700 bool isConstructorDeclarator(); 1701 1702 /// \brief Specifies the context in which type-id/expression 1703 /// disambiguation will occur. 1704 enum TentativeCXXTypeIdContext { 1705 TypeIdInParens, 1706 TypeIdAsTemplateArgument 1707 }; 1708 1709 1710 /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 1711 /// whether the parens contain an expression or a type-id. 1712 /// Returns true for a type-id and false for an expression. 1713 bool isTypeIdInParens(bool &isAmbiguous) { 1714 if (getLangOpts().CPlusPlus) 1715 return isCXXTypeId(TypeIdInParens, isAmbiguous); 1716 isAmbiguous = false; 1717 return isTypeSpecifierQualifier(); 1718 } 1719 bool isTypeIdInParens() { 1720 bool isAmbiguous; 1721 return isTypeIdInParens(isAmbiguous); 1722 } 1723 1724 /// isCXXDeclarationStatement - C++-specialized function that disambiguates 1725 /// between a declaration or an expression statement, when parsing function 1726 /// bodies. Returns true for declaration, false for expression. 1727 bool isCXXDeclarationStatement(); 1728 1729 /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 1730 /// between a simple-declaration or an expression-statement. 1731 /// If during the disambiguation process a parsing error is encountered, 1732 /// the function returns true to let the declaration parsing code handle it. 1733 /// Returns false if the statement is disambiguated as expression. 1734 bool isCXXSimpleDeclaration(bool AllowForRangeDecl); 1735 1736 /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 1737 /// a constructor-style initializer, when parsing declaration statements. 1738 /// Returns true for function declarator and false for constructor-style 1739 /// initializer. Sets 'IsAmbiguous' to true to indicate that this declaration 1740 /// might be a constructor-style initializer. 1741 /// If during the disambiguation process a parsing error is encountered, 1742 /// the function returns true to let the declaration parsing code handle it. 1743 bool isCXXFunctionDeclarator(bool *IsAmbiguous = 0); 1744 1745 /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1746 /// expression for a condition of a if/switch/while/for statement. 1747 /// If during the disambiguation process a parsing error is encountered, 1748 /// the function returns true to let the declaration parsing code handle it. 1749 bool isCXXConditionDeclaration(); 1750 1751 bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1752 bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1753 bool isAmbiguous; 1754 return isCXXTypeId(Context, isAmbiguous); 1755 } 1756 1757 /// TPResult - Used as the result value for functions whose purpose is to 1758 /// disambiguate C++ constructs by "tentatively parsing" them. 1759 /// This is a class instead of a simple enum because the implicit enum-to-bool 1760 /// conversions may cause subtle bugs. 1761 class TPResult { 1762 enum Result { 1763 TPR_true, 1764 TPR_false, 1765 TPR_ambiguous, 1766 TPR_error 1767 }; 1768 Result Res; 1769 TPResult(Result result) : Res(result) {} 1770 public: 1771 static TPResult True() { return TPR_true; } 1772 static TPResult False() { return TPR_false; } 1773 static TPResult Ambiguous() { return TPR_ambiguous; } 1774 static TPResult Error() { return TPR_error; } 1775 1776 bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 1777 bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 1778 }; 1779 1780 /// \brief Based only on the given token kind, determine whether we know that 1781 /// we're at the start of an expression or a type-specifier-seq (which may 1782 /// be an expression, in C++). 1783 /// 1784 /// This routine does not attempt to resolve any of the trick cases, e.g., 1785 /// those involving lookup of identifiers. 1786 /// 1787 /// \returns \c TPR_true if this token starts an expression, \c TPR_false if 1788 /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot 1789 /// tell. 1790 TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind); 1791 1792 /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 1793 /// declaration specifier, TPResult::False() if it is not, 1794 /// TPResult::Ambiguous() if it could be either a decl-specifier or a 1795 /// function-style cast, and TPResult::Error() if a parsing error was 1796 /// encountered. If it could be a braced C++11 function-style cast, returns 1797 /// BracedCastResult. 1798 /// Doesn't consume tokens. 1799 TPResult 1800 isCXXDeclarationSpecifier(TPResult BracedCastResult = TPResult::False(), 1801 bool *HasMissingTypename = 0); 1802 1803 /// \brief Determine whether an identifier has been tentatively declared as a 1804 /// non-type. Such tentative declarations should not be found to name a type 1805 /// during a tentative parse, but also should not be annotated as a non-type. 1806 bool isTentativelyDeclared(IdentifierInfo *II); 1807 1808 // "Tentative parsing" functions, used for disambiguation. If a parsing error 1809 // is encountered they will return TPResult::Error(). 1810 // Returning TPResult::True()/False() indicates that the ambiguity was 1811 // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 1812 // that more tentative parsing is necessary for disambiguation. 1813 // They all consume tokens, so backtracking should be used after calling them. 1814 1815 TPResult TryParseDeclarationSpecifier(bool *HasMissingTypename = 0); 1816 TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl); 1817 TPResult TryParseTypeofSpecifier(); 1818 TPResult TryParseProtocolQualifiers(); 1819 TPResult TryParseInitDeclaratorList(); 1820 TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 1821 TPResult TryParseParameterDeclarationClause(bool *InvalidAsDeclaration = 0); 1822 TPResult TryParseFunctionDeclarator(); 1823 TPResult TryParseBracketDeclarator(); 1824 1825public: 1826 TypeResult ParseTypeName(SourceRange *Range = 0, 1827 Declarator::TheContext Context 1828 = Declarator::TypeNameContext, 1829 AccessSpecifier AS = AS_none, 1830 Decl **OwnedType = 0, 1831 ParsedAttributes *Attrs = 0); 1832 1833private: 1834 void ParseBlockId(SourceLocation CaretLoc); 1835 1836 // Check for the start of a C++11 attribute-specifier-seq in a context where 1837 // an attribute is not allowed. 1838 bool CheckProhibitedCXX11Attribute() { 1839 assert(Tok.is(tok::l_square)); 1840 if (!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square)) 1841 return false; 1842 return DiagnoseProhibitedCXX11Attribute(); 1843 } 1844 bool DiagnoseProhibitedCXX11Attribute(); 1845 void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs, 1846 SourceLocation CorrectLocation) { 1847 if (!getLangOpts().CPlusPlus11) 1848 return; 1849 if ((Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square)) && 1850 Tok.isNot(tok::kw_alignas)) 1851 return; 1852 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation); 1853 } 1854 void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs, 1855 SourceLocation CorrectLocation); 1856 1857 void ProhibitAttributes(ParsedAttributesWithRange &attrs) { 1858 if (!attrs.Range.isValid()) return; 1859 DiagnoseProhibitedAttributes(attrs); 1860 attrs.clear(); 1861 } 1862 void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs); 1863 1864 // Forbid C++11 attributes that appear on certain syntactic 1865 // locations which standard permits but we don't supported yet, 1866 // for example, attributes appertain to decl specifiers. 1867 void ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs); 1868 1869 void MaybeParseGNUAttributes(Declarator &D, 1870 LateParsedAttrList *LateAttrs = 0) { 1871 if (Tok.is(tok::kw___attribute)) { 1872 ParsedAttributes attrs(AttrFactory); 1873 SourceLocation endLoc; 1874 ParseGNUAttributes(attrs, &endLoc, LateAttrs); 1875 D.takeAttributes(attrs, endLoc); 1876 } 1877 } 1878 void MaybeParseGNUAttributes(ParsedAttributes &attrs, 1879 SourceLocation *endLoc = 0, 1880 LateParsedAttrList *LateAttrs = 0) { 1881 if (Tok.is(tok::kw___attribute)) 1882 ParseGNUAttributes(attrs, endLoc, LateAttrs); 1883 } 1884 void ParseGNUAttributes(ParsedAttributes &attrs, 1885 SourceLocation *endLoc = 0, 1886 LateParsedAttrList *LateAttrs = 0); 1887 void ParseGNUAttributeArgs(IdentifierInfo *AttrName, 1888 SourceLocation AttrNameLoc, 1889 ParsedAttributes &Attrs, 1890 SourceLocation *EndLoc, 1891 IdentifierInfo *ScopeName, 1892 SourceLocation ScopeLoc, 1893 AttributeList::Syntax Syntax); 1894 1895 void MaybeParseCXX11Attributes(Declarator &D) { 1896 if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { 1897 ParsedAttributesWithRange attrs(AttrFactory); 1898 SourceLocation endLoc; 1899 ParseCXX11Attributes(attrs, &endLoc); 1900 D.takeAttributes(attrs, endLoc); 1901 } 1902 } 1903 void MaybeParseCXX11Attributes(ParsedAttributes &attrs, 1904 SourceLocation *endLoc = 0) { 1905 if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { 1906 ParsedAttributesWithRange attrsWithRange(AttrFactory); 1907 ParseCXX11Attributes(attrsWithRange, endLoc); 1908 attrs.takeAllFrom(attrsWithRange); 1909 } 1910 } 1911 void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs, 1912 SourceLocation *endLoc = 0, 1913 bool OuterMightBeMessageSend = false) { 1914 if (getLangOpts().CPlusPlus11 && 1915 isCXX11AttributeSpecifier(false, OuterMightBeMessageSend)) 1916 ParseCXX11Attributes(attrs, endLoc); 1917 } 1918 1919 void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs, 1920 SourceLocation *EndLoc = 0); 1921 void ParseCXX11Attributes(ParsedAttributesWithRange &attrs, 1922 SourceLocation *EndLoc = 0); 1923 1924 IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc); 1925 1926 void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs, 1927 SourceLocation *endLoc = 0) { 1928 if (getLangOpts().MicrosoftExt && Tok.is(tok::l_square)) 1929 ParseMicrosoftAttributes(attrs, endLoc); 1930 } 1931 void ParseMicrosoftAttributes(ParsedAttributes &attrs, 1932 SourceLocation *endLoc = 0); 1933 void ParseMicrosoftDeclSpec(ParsedAttributes &Attrs); 1934 bool IsSimpleMicrosoftDeclSpec(IdentifierInfo *Ident); 1935 void ParseComplexMicrosoftDeclSpec(IdentifierInfo *Ident, 1936 SourceLocation Loc, 1937 ParsedAttributes &Attrs); 1938 void ParseMicrosoftDeclSpecWithSingleArg(IdentifierInfo *AttrName, 1939 SourceLocation AttrNameLoc, 1940 ParsedAttributes &Attrs); 1941 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); 1942 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs); 1943 void ParseBorlandTypeAttributes(ParsedAttributes &attrs); 1944 void ParseOpenCLAttributes(ParsedAttributes &attrs); 1945 void ParseOpenCLQualifiers(DeclSpec &DS); 1946 1947 VersionTuple ParseVersionTuple(SourceRange &Range); 1948 void ParseAvailabilityAttribute(IdentifierInfo &Availability, 1949 SourceLocation AvailabilityLoc, 1950 ParsedAttributes &attrs, 1951 SourceLocation *endLoc); 1952 1953 bool IsThreadSafetyAttribute(StringRef AttrName); 1954 void ParseThreadSafetyAttribute(IdentifierInfo &AttrName, 1955 SourceLocation AttrNameLoc, 1956 ParsedAttributes &Attrs, 1957 SourceLocation *EndLoc); 1958 1959 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, 1960 SourceLocation AttrNameLoc, 1961 ParsedAttributes &Attrs, 1962 SourceLocation *EndLoc); 1963 1964 void ParseTypeofSpecifier(DeclSpec &DS); 1965 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS); 1966 void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS, 1967 SourceLocation StartLoc, 1968 SourceLocation EndLoc); 1969 void ParseUnderlyingTypeSpecifier(DeclSpec &DS); 1970 void ParseAtomicSpecifier(DeclSpec &DS); 1971 1972 ExprResult ParseAlignArgument(SourceLocation Start, 1973 SourceLocation &EllipsisLoc); 1974 void ParseAlignmentSpecifier(ParsedAttributes &Attrs, 1975 SourceLocation *endLoc = 0); 1976 1977 VirtSpecifiers::Specifier isCXX11VirtSpecifier(const Token &Tok) const; 1978 VirtSpecifiers::Specifier isCXX11VirtSpecifier() const { 1979 return isCXX11VirtSpecifier(Tok); 1980 } 1981 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, bool IsInterface); 1982 1983 bool isCXX11FinalKeyword() const; 1984 1985 /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 1986 /// enter a new C++ declarator scope and exit it when the function is 1987 /// finished. 1988 class DeclaratorScopeObj { 1989 Parser &P; 1990 CXXScopeSpec &SS; 1991 bool EnteredScope; 1992 bool CreatedScope; 1993 public: 1994 DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 1995 : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 1996 1997 void EnterDeclaratorScope() { 1998 assert(!EnteredScope && "Already entered the scope!"); 1999 assert(SS.isSet() && "C++ scope was not set!"); 2000 2001 CreatedScope = true; 2002 P.EnterScope(0); // Not a decl scope. 2003 2004 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) 2005 EnteredScope = true; 2006 } 2007 2008 ~DeclaratorScopeObj() { 2009 if (EnteredScope) { 2010 assert(SS.isSet() && "C++ scope was cleared ?"); 2011 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); 2012 } 2013 if (CreatedScope) 2014 P.ExitScope(); 2015 } 2016 }; 2017 2018 /// ParseDeclarator - Parse and verify a newly-initialized declarator. 2019 void ParseDeclarator(Declarator &D); 2020 /// A function that parses a variant of direct-declarator. 2021 typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 2022 void ParseDeclaratorInternal(Declarator &D, 2023 DirectDeclParseFunction DirectDeclParser); 2024 2025 void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 2026 bool CXX11AttributesAllowed = true, 2027 bool AtomicAllowed = true); 2028 void ParseDirectDeclarator(Declarator &D); 2029 void ParseParenDeclarator(Declarator &D); 2030 void ParseFunctionDeclarator(Declarator &D, 2031 ParsedAttributes &attrs, 2032 BalancedDelimiterTracker &Tracker, 2033 bool IsAmbiguous, 2034 bool RequiresArg = false); 2035 bool isFunctionDeclaratorIdentifierList(); 2036 void ParseFunctionDeclaratorIdentifierList( 2037 Declarator &D, 2038 SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo); 2039 void ParseParameterDeclarationClause( 2040 Declarator &D, 2041 ParsedAttributes &attrs, 2042 SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo, 2043 SourceLocation &EllipsisLoc); 2044 void ParseBracketDeclarator(Declarator &D); 2045 2046 //===--------------------------------------------------------------------===// 2047 // C++ 7: Declarations [dcl.dcl] 2048 2049 /// The kind of attribute specifier we have found. 2050 enum CXX11AttributeKind { 2051 /// This is not an attribute specifier. 2052 CAK_NotAttributeSpecifier, 2053 /// This should be treated as an attribute-specifier. 2054 CAK_AttributeSpecifier, 2055 /// The next tokens are '[[', but this is not an attribute-specifier. This 2056 /// is ill-formed by C++11 [dcl.attr.grammar]p6. 2057 CAK_InvalidAttributeSpecifier 2058 }; 2059 CXX11AttributeKind 2060 isCXX11AttributeSpecifier(bool Disambiguate = false, 2061 bool OuterMightBeMessageSend = false); 2062 2063 Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, 2064 SourceLocation InlineLoc = SourceLocation()); 2065 void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, 2066 std::vector<IdentifierInfo*>& Ident, 2067 std::vector<SourceLocation>& NamespaceLoc, 2068 unsigned int index, SourceLocation& InlineLoc, 2069 ParsedAttributes& attrs, 2070 BalancedDelimiterTracker &Tracker); 2071 Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 2072 Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, 2073 const ParsedTemplateInfo &TemplateInfo, 2074 SourceLocation &DeclEnd, 2075 ParsedAttributesWithRange &attrs, 2076 Decl **OwnedType = 0); 2077 Decl *ParseUsingDirective(unsigned Context, 2078 SourceLocation UsingLoc, 2079 SourceLocation &DeclEnd, 2080 ParsedAttributes &attrs); 2081 Decl *ParseUsingDeclaration(unsigned Context, 2082 const ParsedTemplateInfo &TemplateInfo, 2083 SourceLocation UsingLoc, 2084 SourceLocation &DeclEnd, 2085 AccessSpecifier AS = AS_none, 2086 Decl **OwnedType = 0); 2087 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 2088 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, 2089 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