1 //===--- ParseCXXInlineMethods.cpp - C++ class inline methods parsing------===// 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 implements parsing for C++ class inline methods. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/Parse/Parser.h" 15 #include "RAIIObjectsForParser.h" 16 #include "clang/AST/DeclTemplate.h" 17 #include "clang/Parse/ParseDiagnostic.h" 18 #include "clang/Sema/DeclSpec.h" 19 #include "clang/Sema/Scope.h" 20 using namespace clang; 21 22 /// ParseCXXInlineMethodDef - We parsed and verified that the specified 23 /// Declarator is a well formed C++ inline method definition. Now lex its body 24 /// and store its tokens for parsing after the C++ class is complete. 25 NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, 26 AttributeList *AccessAttrs, 27 ParsingDeclarator &D, 28 const ParsedTemplateInfo &TemplateInfo, 29 const VirtSpecifiers& VS, 30 SourceLocation PureSpecLoc) { 31 assert(D.isFunctionDeclarator() && "This isn't a function declarator!"); 32 assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try, tok::equal) && 33 "Current token not a '{', ':', '=', or 'try'!"); 34 35 MultiTemplateParamsArg TemplateParams( 36 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data() 37 : nullptr, 38 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0); 39 40 NamedDecl *FnD; 41 if (D.getDeclSpec().isFriendSpecified()) 42 FnD = Actions.ActOnFriendFunctionDecl(getCurScope(), D, 43 TemplateParams); 44 else { 45 FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D, 46 TemplateParams, nullptr, 47 VS, ICIS_NoInit); 48 if (FnD) { 49 Actions.ProcessDeclAttributeList(getCurScope(), FnD, AccessAttrs); 50 if (PureSpecLoc.isValid()) 51 Actions.ActOnPureSpecifier(FnD, PureSpecLoc); 52 } 53 } 54 55 HandleMemberFunctionDeclDelays(D, FnD); 56 57 D.complete(FnD); 58 59 if (TryConsumeToken(tok::equal)) { 60 if (!FnD) { 61 SkipUntil(tok::semi); 62 return nullptr; 63 } 64 65 bool Delete = false; 66 SourceLocation KWLoc; 67 SourceLocation KWEndLoc = Tok.getEndLoc().getLocWithOffset(-1); 68 if (TryConsumeToken(tok::kw_delete, KWLoc)) { 69 Diag(KWLoc, getLangOpts().CPlusPlus11 70 ? diag::warn_cxx98_compat_deleted_function 71 : diag::ext_deleted_function); 72 Actions.SetDeclDeleted(FnD, KWLoc); 73 Delete = true; 74 if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) { 75 DeclAsFunction->setRangeEnd(KWEndLoc); 76 } 77 } else if (TryConsumeToken(tok::kw_default, KWLoc)) { 78 Diag(KWLoc, getLangOpts().CPlusPlus11 79 ? diag::warn_cxx98_compat_defaulted_function 80 : diag::ext_defaulted_function); 81 Actions.SetDeclDefaulted(FnD, KWLoc); 82 if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) { 83 DeclAsFunction->setRangeEnd(KWEndLoc); 84 } 85 } else { 86 llvm_unreachable("function definition after = not 'delete' or 'default'"); 87 } 88 89 if (Tok.is(tok::comma)) { 90 Diag(KWLoc, diag::err_default_delete_in_multiple_declaration) 91 << Delete; 92 SkipUntil(tok::semi); 93 } else if (ExpectAndConsume(tok::semi, diag::err_expected_after, 94 Delete ? "delete" : "default")) { 95 SkipUntil(tok::semi); 96 } 97 98 return FnD; 99 } 100 101 // In delayed template parsing mode, if we are within a class template 102 // or if we are about to parse function member template then consume 103 // the tokens and store them for parsing at the end of the translation unit. 104 if (getLangOpts().DelayedTemplateParsing && 105 D.getFunctionDefinitionKind() == FDK_Definition && 106 !D.getDeclSpec().isConstexprSpecified() && 107 !(FnD && FnD->getAsFunction() && 108 FnD->getAsFunction()->getReturnType()->getContainedAutoType()) && 109 ((Actions.CurContext->isDependentContext() || 110 (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate && 111 TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization)) && 112 !Actions.IsInsideALocalClassWithinATemplateFunction())) { 113 114 CachedTokens Toks; 115 LexTemplateFunctionForLateParsing(Toks); 116 117 if (FnD) { 118 FunctionDecl *FD = FnD->getAsFunction(); 119 Actions.CheckForFunctionRedefinition(FD); 120 Actions.MarkAsLateParsedTemplate(FD, FnD, Toks); 121 } 122 123 return FnD; 124 } 125 126 // Consume the tokens and store them for later parsing. 127 128 LexedMethod* LM = new LexedMethod(this, FnD); 129 getCurrentClass().LateParsedDeclarations.push_back(LM); 130 LM->TemplateScope = getCurScope()->isTemplateParamScope(); 131 CachedTokens &Toks = LM->Toks; 132 133 tok::TokenKind kind = Tok.getKind(); 134 // Consume everything up to (and including) the left brace of the 135 // function body. 136 if (ConsumeAndStoreFunctionPrologue(Toks)) { 137 // We didn't find the left-brace we expected after the 138 // constructor initializer; we already printed an error, and it's likely 139 // impossible to recover, so don't try to parse this method later. 140 // Skip over the rest of the decl and back to somewhere that looks 141 // reasonable. 142 SkipMalformedDecl(); 143 delete getCurrentClass().LateParsedDeclarations.back(); 144 getCurrentClass().LateParsedDeclarations.pop_back(); 145 return FnD; 146 } else { 147 // Consume everything up to (and including) the matching right brace. 148 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); 149 } 150 151 // If we're in a function-try-block, we need to store all the catch blocks. 152 if (kind == tok::kw_try) { 153 while (Tok.is(tok::kw_catch)) { 154 ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false); 155 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); 156 } 157 } 158 159 if (FnD) { 160 // If this is a friend function, mark that it's late-parsed so that 161 // it's still known to be a definition even before we attach the 162 // parsed body. Sema needs to treat friend function definitions 163 // differently during template instantiation, and it's possible for 164 // the containing class to be instantiated before all its member 165 // function definitions are parsed. 166 // 167 // If you remove this, you can remove the code that clears the flag 168 // after parsing the member. 169 if (D.getDeclSpec().isFriendSpecified()) { 170 FunctionDecl *FD = FnD->getAsFunction(); 171 Actions.CheckForFunctionRedefinition(FD); 172 FD->setLateTemplateParsed(true); 173 } 174 } else { 175 // If semantic analysis could not build a function declaration, 176 // just throw away the late-parsed declaration. 177 delete getCurrentClass().LateParsedDeclarations.back(); 178 getCurrentClass().LateParsedDeclarations.pop_back(); 179 } 180 181 return FnD; 182 } 183 184 /// ParseCXXNonStaticMemberInitializer - We parsed and verified that the 185 /// specified Declarator is a well formed C++ non-static data member 186 /// declaration. Now lex its initializer and store its tokens for parsing 187 /// after the class is complete. 188 void Parser::ParseCXXNonStaticMemberInitializer(Decl *VarD) { 189 assert(Tok.isOneOf(tok::l_brace, tok::equal) && 190 "Current token not a '{' or '='!"); 191 192 LateParsedMemberInitializer *MI = 193 new LateParsedMemberInitializer(this, VarD); 194 getCurrentClass().LateParsedDeclarations.push_back(MI); 195 CachedTokens &Toks = MI->Toks; 196 197 tok::TokenKind kind = Tok.getKind(); 198 if (kind == tok::equal) { 199 Toks.push_back(Tok); 200 ConsumeToken(); 201 } 202 203 if (kind == tok::l_brace) { 204 // Begin by storing the '{' token. 205 Toks.push_back(Tok); 206 ConsumeBrace(); 207 208 // Consume everything up to (and including) the matching right brace. 209 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/true); 210 } else { 211 // Consume everything up to (but excluding) the comma or semicolon. 212 ConsumeAndStoreInitializer(Toks, CIK_DefaultInitializer); 213 } 214 215 // Store an artificial EOF token to ensure that we don't run off the end of 216 // the initializer when we come to parse it. 217 Token Eof; 218 Eof.startToken(); 219 Eof.setKind(tok::eof); 220 Eof.setLocation(Tok.getLocation()); 221 Eof.setEofData(VarD); 222 Toks.push_back(Eof); 223 } 224 225 Parser::LateParsedDeclaration::~LateParsedDeclaration() {} 226 void Parser::LateParsedDeclaration::ParseLexedMethodDeclarations() {} 227 void Parser::LateParsedDeclaration::ParseLexedMemberInitializers() {} 228 void Parser::LateParsedDeclaration::ParseLexedMethodDefs() {} 229 230 Parser::LateParsedClass::LateParsedClass(Parser *P, ParsingClass *C) 231 : Self(P), Class(C) {} 232 233 Parser::LateParsedClass::~LateParsedClass() { 234 Self->DeallocateParsedClasses(Class); 235 } 236 237 void Parser::LateParsedClass::ParseLexedMethodDeclarations() { 238 Self->ParseLexedMethodDeclarations(*Class); 239 } 240 241 void Parser::LateParsedClass::ParseLexedMemberInitializers() { 242 Self->ParseLexedMemberInitializers(*Class); 243 } 244 245 void Parser::LateParsedClass::ParseLexedMethodDefs() { 246 Self->ParseLexedMethodDefs(*Class); 247 } 248 249 void Parser::LateParsedMethodDeclaration::ParseLexedMethodDeclarations() { 250 Self->ParseLexedMethodDeclaration(*this); 251 } 252 253 void Parser::LexedMethod::ParseLexedMethodDefs() { 254 Self->ParseLexedMethodDef(*this); 255 } 256 257 void Parser::LateParsedMemberInitializer::ParseLexedMemberInitializers() { 258 Self->ParseLexedMemberInitializer(*this); 259 } 260 261 /// ParseLexedMethodDeclarations - We finished parsing the member 262 /// specification of a top (non-nested) C++ class. Now go over the 263 /// stack of method declarations with some parts for which parsing was 264 /// delayed (such as default arguments) and parse them. 265 void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) { 266 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; 267 ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, 268 HasTemplateScope); 269 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); 270 if (HasTemplateScope) { 271 Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); 272 ++CurTemplateDepthTracker; 273 } 274 275 // The current scope is still active if we're the top-level class. 276 // Otherwise we'll need to push and enter a new scope. 277 bool HasClassScope = !Class.TopLevelClass; 278 ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope, 279 HasClassScope); 280 if (HasClassScope) 281 Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), 282 Class.TagOrTemplate); 283 284 for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { 285 Class.LateParsedDeclarations[i]->ParseLexedMethodDeclarations(); 286 } 287 288 if (HasClassScope) 289 Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), 290 Class.TagOrTemplate); 291 } 292 293 void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { 294 // If this is a member template, introduce the template parameter scope. 295 ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope); 296 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); 297 if (LM.TemplateScope) { 298 Actions.ActOnReenterTemplateScope(getCurScope(), LM.Method); 299 ++CurTemplateDepthTracker; 300 } 301 // Start the delayed C++ method declaration 302 Actions.ActOnStartDelayedCXXMethodDeclaration(getCurScope(), LM.Method); 303 304 // Introduce the parameters into scope and parse their default 305 // arguments. 306 ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope | 307 Scope::FunctionDeclarationScope | Scope::DeclScope); 308 for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) { 309 auto Param = cast<ParmVarDecl>(LM.DefaultArgs[I].Param); 310 // Introduce the parameter into scope. 311 bool HasUnparsed = Param->hasUnparsedDefaultArg(); 312 Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param); 313 if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) { 314 // Mark the end of the default argument so that we know when to stop when 315 // we parse it later on. 316 Token LastDefaultArgToken = Toks->back(); 317 Token DefArgEnd; 318 DefArgEnd.startToken(); 319 DefArgEnd.setKind(tok::eof); 320 DefArgEnd.setLocation(LastDefaultArgToken.getEndLoc()); 321 DefArgEnd.setEofData(Param); 322 Toks->push_back(DefArgEnd); 323 324 // Parse the default argument from its saved token stream. 325 Toks->push_back(Tok); // So that the current token doesn't get lost 326 PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false); 327 328 // Consume the previously-pushed token. 329 ConsumeAnyToken(); 330 331 // Consume the '='. 332 assert(Tok.is(tok::equal) && "Default argument not starting with '='"); 333 SourceLocation EqualLoc = ConsumeToken(); 334 335 // The argument isn't actually potentially evaluated unless it is 336 // used. 337 EnterExpressionEvaluationContext Eval(Actions, 338 Sema::PotentiallyEvaluatedIfUsed, 339 Param); 340 341 ExprResult DefArgResult; 342 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { 343 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); 344 DefArgResult = ParseBraceInitializer(); 345 } else 346 DefArgResult = ParseAssignmentExpression(); 347 DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult); 348 if (DefArgResult.isInvalid()) { 349 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc); 350 } else { 351 if (Tok.isNot(tok::eof) || Tok.getEofData() != Param) { 352 // The last two tokens are the terminator and the saved value of 353 // Tok; the last token in the default argument is the one before 354 // those. 355 assert(Toks->size() >= 3 && "expected a token in default arg"); 356 Diag(Tok.getLocation(), diag::err_default_arg_unparsed) 357 << SourceRange(Tok.getLocation(), 358 (*Toks)[Toks->size() - 3].getLocation()); 359 } 360 Actions.ActOnParamDefaultArgument(Param, EqualLoc, 361 DefArgResult.get()); 362 } 363 364 // There could be leftover tokens (e.g. because of an error). 365 // Skip through until we reach the 'end of default argument' token. 366 while (Tok.isNot(tok::eof)) 367 ConsumeAnyToken(); 368 369 if (Tok.is(tok::eof) && Tok.getEofData() == Param) 370 ConsumeAnyToken(); 371 372 delete Toks; 373 LM.DefaultArgs[I].Toks = nullptr; 374 } else if (HasUnparsed) { 375 assert(Param->hasInheritedDefaultArg()); 376 FunctionDecl *Old = cast<FunctionDecl>(LM.Method)->getPreviousDecl(); 377 ParmVarDecl *OldParam = Old->getParamDecl(I); 378 assert (!OldParam->hasUnparsedDefaultArg()); 379 if (OldParam->hasUninstantiatedDefaultArg()) 380 Param->setUninstantiatedDefaultArg( 381 Param->getUninstantiatedDefaultArg()); 382 else 383 Param->setDefaultArg(OldParam->getInit()); 384 } 385 } 386 387 // Parse a delayed exception-specification, if there is one. 388 if (CachedTokens *Toks = LM.ExceptionSpecTokens) { 389 // Add the 'stop' token. 390 Token LastExceptionSpecToken = Toks->back(); 391 Token ExceptionSpecEnd; 392 ExceptionSpecEnd.startToken(); 393 ExceptionSpecEnd.setKind(tok::eof); 394 ExceptionSpecEnd.setLocation(LastExceptionSpecToken.getEndLoc()); 395 ExceptionSpecEnd.setEofData(LM.Method); 396 Toks->push_back(ExceptionSpecEnd); 397 398 // Parse the default argument from its saved token stream. 399 Toks->push_back(Tok); // So that the current token doesn't get lost 400 PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false); 401 402 // Consume the previously-pushed token. 403 ConsumeAnyToken(); 404 405 // C++11 [expr.prim.general]p3: 406 // If a declaration declares a member function or member function 407 // template of a class X, the expression this is a prvalue of type 408 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq 409 // and the end of the function-definition, member-declarator, or 410 // declarator. 411 CXXMethodDecl *Method; 412 if (FunctionTemplateDecl *FunTmpl 413 = dyn_cast<FunctionTemplateDecl>(LM.Method)) 414 Method = cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl()); 415 else 416 Method = cast<CXXMethodDecl>(LM.Method); 417 418 Sema::CXXThisScopeRAII ThisScope(Actions, Method->getParent(), 419 Method->getTypeQualifiers(), 420 getLangOpts().CPlusPlus11); 421 422 // Parse the exception-specification. 423 SourceRange SpecificationRange; 424 SmallVector<ParsedType, 4> DynamicExceptions; 425 SmallVector<SourceRange, 4> DynamicExceptionRanges; 426 ExprResult NoexceptExpr; 427 CachedTokens *ExceptionSpecTokens; 428 429 ExceptionSpecificationType EST 430 = tryParseExceptionSpecification(/*Delayed=*/false, SpecificationRange, 431 DynamicExceptions, 432 DynamicExceptionRanges, NoexceptExpr, 433 ExceptionSpecTokens); 434 435 if (Tok.isNot(tok::eof) || Tok.getEofData() != LM.Method) 436 Diag(Tok.getLocation(), diag::err_except_spec_unparsed); 437 438 // Attach the exception-specification to the method. 439 Actions.actOnDelayedExceptionSpecification(LM.Method, EST, 440 SpecificationRange, 441 DynamicExceptions, 442 DynamicExceptionRanges, 443 NoexceptExpr.isUsable()? 444 NoexceptExpr.get() : nullptr); 445 446 // There could be leftover tokens (e.g. because of an error). 447 // Skip through until we reach the original token position. 448 while (Tok.isNot(tok::eof)) 449 ConsumeAnyToken(); 450 451 // Clean up the remaining EOF token. 452 if (Tok.is(tok::eof) && Tok.getEofData() == LM.Method) 453 ConsumeAnyToken(); 454 455 delete Toks; 456 LM.ExceptionSpecTokens = nullptr; 457 } 458 459 PrototypeScope.Exit(); 460 461 // Finish the delayed C++ method declaration. 462 Actions.ActOnFinishDelayedCXXMethodDeclaration(getCurScope(), LM.Method); 463 } 464 465 /// ParseLexedMethodDefs - We finished parsing the member specification of a top 466 /// (non-nested) C++ class. Now go over the stack of lexed methods that were 467 /// collected during its parsing and parse them all. 468 void Parser::ParseLexedMethodDefs(ParsingClass &Class) { 469 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; 470 ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope); 471 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); 472 if (HasTemplateScope) { 473 Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); 474 ++CurTemplateDepthTracker; 475 } 476 bool HasClassScope = !Class.TopLevelClass; 477 ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope, 478 HasClassScope); 479 480 for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { 481 Class.LateParsedDeclarations[i]->ParseLexedMethodDefs(); 482 } 483 } 484 485 void Parser::ParseLexedMethodDef(LexedMethod &LM) { 486 // If this is a member template, introduce the template parameter scope. 487 ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope); 488 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); 489 if (LM.TemplateScope) { 490 Actions.ActOnReenterTemplateScope(getCurScope(), LM.D); 491 ++CurTemplateDepthTracker; 492 } 493 494 assert(!LM.Toks.empty() && "Empty body!"); 495 Token LastBodyToken = LM.Toks.back(); 496 Token BodyEnd; 497 BodyEnd.startToken(); 498 BodyEnd.setKind(tok::eof); 499 BodyEnd.setLocation(LastBodyToken.getEndLoc()); 500 BodyEnd.setEofData(LM.D); 501 LM.Toks.push_back(BodyEnd); 502 // Append the current token at the end of the new token stream so that it 503 // doesn't get lost. 504 LM.Toks.push_back(Tok); 505 PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false); 506 507 // Consume the previously pushed token. 508 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); 509 assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try) 510 && "Inline method not starting with '{', ':' or 'try'"); 511 512 // Parse the method body. Function body parsing code is similar enough 513 // to be re-used for method bodies as well. 514 ParseScope FnScope(this, Scope::FnScope|Scope::DeclScope); 515 Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D); 516 517 if (Tok.is(tok::kw_try)) { 518 ParseFunctionTryBlock(LM.D, FnScope); 519 520 while (Tok.isNot(tok::eof)) 521 ConsumeAnyToken(); 522 523 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) 524 ConsumeAnyToken(); 525 return; 526 } 527 if (Tok.is(tok::colon)) { 528 ParseConstructorInitializer(LM.D); 529 530 // Error recovery. 531 if (!Tok.is(tok::l_brace)) { 532 FnScope.Exit(); 533 Actions.ActOnFinishFunctionBody(LM.D, nullptr); 534 535 while (Tok.isNot(tok::eof)) 536 ConsumeAnyToken(); 537 538 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) 539 ConsumeAnyToken(); 540 return; 541 } 542 } else 543 Actions.ActOnDefaultCtorInitializers(LM.D); 544 545 assert((Actions.getDiagnostics().hasErrorOccurred() || 546 !isa<FunctionTemplateDecl>(LM.D) || 547 cast<FunctionTemplateDecl>(LM.D)->getTemplateParameters()->getDepth() 548 < TemplateParameterDepth) && 549 "TemplateParameterDepth should be greater than the depth of " 550 "current template being instantiated!"); 551 552 ParseFunctionStatementBody(LM.D, FnScope); 553 554 // Clear the late-template-parsed bit if we set it before. 555 if (LM.D) 556 LM.D->getAsFunction()->setLateTemplateParsed(false); 557 558 while (Tok.isNot(tok::eof)) 559 ConsumeAnyToken(); 560 561 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) 562 ConsumeAnyToken(); 563 564 if (CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(LM.D)) 565 Actions.ActOnFinishInlineMethodDef(MD); 566 } 567 568 /// ParseLexedMemberInitializers - We finished parsing the member specification 569 /// of a top (non-nested) C++ class. Now go over the stack of lexed data member 570 /// initializers that were collected during its parsing and parse them all. 571 void Parser::ParseLexedMemberInitializers(ParsingClass &Class) { 572 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; 573 ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, 574 HasTemplateScope); 575 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); 576 if (HasTemplateScope) { 577 Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); 578 ++CurTemplateDepthTracker; 579 } 580 // Set or update the scope flags. 581 bool AlreadyHasClassScope = Class.TopLevelClass; 582 unsigned ScopeFlags = Scope::ClassScope|Scope::DeclScope; 583 ParseScope ClassScope(this, ScopeFlags, !AlreadyHasClassScope); 584 ParseScopeFlags ClassScopeFlags(this, ScopeFlags, AlreadyHasClassScope); 585 586 if (!AlreadyHasClassScope) 587 Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), 588 Class.TagOrTemplate); 589 590 if (!Class.LateParsedDeclarations.empty()) { 591 // C++11 [expr.prim.general]p4: 592 // Otherwise, if a member-declarator declares a non-static data member 593 // (9.2) of a class X, the expression this is a prvalue of type "pointer 594 // to X" within the optional brace-or-equal-initializer. It shall not 595 // appear elsewhere in the member-declarator. 596 Sema::CXXThisScopeRAII ThisScope(Actions, Class.TagOrTemplate, 597 /*TypeQuals=*/(unsigned)0); 598 599 for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { 600 Class.LateParsedDeclarations[i]->ParseLexedMemberInitializers(); 601 } 602 } 603 604 if (!AlreadyHasClassScope) 605 Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), 606 Class.TagOrTemplate); 607 608 Actions.ActOnFinishDelayedMemberInitializers(Class.TagOrTemplate); 609 } 610 611 void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) { 612 if (!MI.Field || MI.Field->isInvalidDecl()) 613 return; 614 615 // Append the current token at the end of the new token stream so that it 616 // doesn't get lost. 617 MI.Toks.push_back(Tok); 618 PP.EnterTokenStream(MI.Toks.data(), MI.Toks.size(), true, false); 619 620 // Consume the previously pushed token. 621 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); 622 623 SourceLocation EqualLoc; 624 625 Actions.ActOnStartCXXInClassMemberInitializer(); 626 627 ExprResult Init = ParseCXXMemberInitializer(MI.Field, /*IsFunction=*/false, 628 EqualLoc); 629 630 Actions.ActOnFinishCXXInClassMemberInitializer(MI.Field, EqualLoc, 631 Init.get()); 632 633 // The next token should be our artificial terminating EOF token. 634 if (Tok.isNot(tok::eof)) { 635 if (!Init.isInvalid()) { 636 SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation); 637 if (!EndLoc.isValid()) 638 EndLoc = Tok.getLocation(); 639 // No fixit; we can't recover as if there were a semicolon here. 640 Diag(EndLoc, diag::err_expected_semi_decl_list); 641 } 642 643 // Consume tokens until we hit the artificial EOF. 644 while (Tok.isNot(tok::eof)) 645 ConsumeAnyToken(); 646 } 647 // Make sure this is *our* artificial EOF token. 648 if (Tok.getEofData() == MI.Field) 649 ConsumeAnyToken(); 650 } 651 652 /// ConsumeAndStoreUntil - Consume and store the token at the passed token 653 /// container until the token 'T' is reached (which gets 654 /// consumed/stored too, if ConsumeFinalToken). 655 /// If StopAtSemi is true, then we will stop early at a ';' character. 656 /// Returns true if token 'T1' or 'T2' was found. 657 /// NOTE: This is a specialized version of Parser::SkipUntil. 658 bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 659 CachedTokens &Toks, 660 bool StopAtSemi, bool ConsumeFinalToken) { 661 // We always want this function to consume at least one token if the first 662 // token isn't T and if not at EOF. 663 bool isFirstTokenConsumed = true; 664 while (1) { 665 // If we found one of the tokens, stop and return true. 666 if (Tok.is(T1) || Tok.is(T2)) { 667 if (ConsumeFinalToken) { 668 Toks.push_back(Tok); 669 ConsumeAnyToken(); 670 } 671 return true; 672 } 673 674 switch (Tok.getKind()) { 675 case tok::eof: 676 case tok::annot_module_begin: 677 case tok::annot_module_end: 678 case tok::annot_module_include: 679 // Ran out of tokens. 680 return false; 681 682 case tok::l_paren: 683 // Recursively consume properly-nested parens. 684 Toks.push_back(Tok); 685 ConsumeParen(); 686 ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false); 687 break; 688 case tok::l_square: 689 // Recursively consume properly-nested square brackets. 690 Toks.push_back(Tok); 691 ConsumeBracket(); 692 ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false); 693 break; 694 case tok::l_brace: 695 // Recursively consume properly-nested braces. 696 Toks.push_back(Tok); 697 ConsumeBrace(); 698 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); 699 break; 700 701 // Okay, we found a ']' or '}' or ')', which we think should be balanced. 702 // Since the user wasn't looking for this token (if they were, it would 703 // already be handled), this isn't balanced. If there is a LHS token at a 704 // higher level, we will assume that this matches the unbalanced token 705 // and return it. Otherwise, this is a spurious RHS token, which we skip. 706 case tok::r_paren: 707 if (ParenCount && !isFirstTokenConsumed) 708 return false; // Matches something. 709 Toks.push_back(Tok); 710 ConsumeParen(); 711 break; 712 case tok::r_square: 713 if (BracketCount && !isFirstTokenConsumed) 714 return false; // Matches something. 715 Toks.push_back(Tok); 716 ConsumeBracket(); 717 break; 718 case tok::r_brace: 719 if (BraceCount && !isFirstTokenConsumed) 720 return false; // Matches something. 721 Toks.push_back(Tok); 722 ConsumeBrace(); 723 break; 724 725 case tok::code_completion: 726 Toks.push_back(Tok); 727 ConsumeCodeCompletionToken(); 728 break; 729 730 case tok::string_literal: 731 case tok::wide_string_literal: 732 case tok::utf8_string_literal: 733 case tok::utf16_string_literal: 734 case tok::utf32_string_literal: 735 Toks.push_back(Tok); 736 ConsumeStringToken(); 737 break; 738 case tok::semi: 739 if (StopAtSemi) 740 return false; 741 // FALL THROUGH. 742 default: 743 // consume this token. 744 Toks.push_back(Tok); 745 ConsumeToken(); 746 break; 747 } 748 isFirstTokenConsumed = false; 749 } 750 } 751 752 /// \brief Consume tokens and store them in the passed token container until 753 /// we've passed the try keyword and constructor initializers and have consumed 754 /// the opening brace of the function body. The opening brace will be consumed 755 /// if and only if there was no error. 756 /// 757 /// \return True on error. 758 bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { 759 if (Tok.is(tok::kw_try)) { 760 Toks.push_back(Tok); 761 ConsumeToken(); 762 } 763 764 if (Tok.isNot(tok::colon)) { 765 // Easy case, just a function body. 766 767 // Grab any remaining garbage to be diagnosed later. We stop when we reach a 768 // brace: an opening one is the function body, while a closing one probably 769 // means we've reached the end of the class. 770 ConsumeAndStoreUntil(tok::l_brace, tok::r_brace, Toks, 771 /*StopAtSemi=*/true, 772 /*ConsumeFinalToken=*/false); 773 if (Tok.isNot(tok::l_brace)) 774 return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; 775 776 Toks.push_back(Tok); 777 ConsumeBrace(); 778 return false; 779 } 780 781 Toks.push_back(Tok); 782 ConsumeToken(); 783 784 // We can't reliably skip over a mem-initializer-id, because it could be 785 // a template-id involving not-yet-declared names. Given: 786 // 787 // S ( ) : a < b < c > ( e ) 788 // 789 // 'e' might be an initializer or part of a template argument, depending 790 // on whether 'b' is a template. 791 792 // Track whether we might be inside a template argument. We can give 793 // significantly better diagnostics if we know that we're not. 794 bool MightBeTemplateArgument = false; 795 796 while (true) { 797 // Skip over the mem-initializer-id, if possible. 798 if (Tok.is(tok::kw_decltype)) { 799 Toks.push_back(Tok); 800 SourceLocation OpenLoc = ConsumeToken(); 801 if (Tok.isNot(tok::l_paren)) 802 return Diag(Tok.getLocation(), diag::err_expected_lparen_after) 803 << "decltype"; 804 Toks.push_back(Tok); 805 ConsumeParen(); 806 if (!ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/true)) { 807 Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren; 808 Diag(OpenLoc, diag::note_matching) << tok::l_paren; 809 return true; 810 } 811 } 812 do { 813 // Walk over a component of a nested-name-specifier. 814 if (Tok.is(tok::coloncolon)) { 815 Toks.push_back(Tok); 816 ConsumeToken(); 817 818 if (Tok.is(tok::kw_template)) { 819 Toks.push_back(Tok); 820 ConsumeToken(); 821 } 822 } 823 824 if (Tok.isOneOf(tok::identifier, tok::kw_template)) { 825 Toks.push_back(Tok); 826 ConsumeToken(); 827 } else if (Tok.is(tok::code_completion)) { 828 Toks.push_back(Tok); 829 ConsumeCodeCompletionToken(); 830 // Consume the rest of the initializers permissively. 831 // FIXME: We should be able to perform code-completion here even if 832 // there isn't a subsequent '{' token. 833 MightBeTemplateArgument = true; 834 break; 835 } else { 836 break; 837 } 838 } while (Tok.is(tok::coloncolon)); 839 840 if (Tok.is(tok::less)) 841 MightBeTemplateArgument = true; 842 843 if (MightBeTemplateArgument) { 844 // We may be inside a template argument list. Grab up to the start of the 845 // next parenthesized initializer or braced-init-list. This *might* be the 846 // initializer, or it might be a subexpression in the template argument 847 // list. 848 // FIXME: Count angle brackets, and clear MightBeTemplateArgument 849 // if all angles are closed. 850 if (!ConsumeAndStoreUntil(tok::l_paren, tok::l_brace, Toks, 851 /*StopAtSemi=*/true, 852 /*ConsumeFinalToken=*/false)) { 853 // We're not just missing the initializer, we're also missing the 854 // function body! 855 return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; 856 } 857 } else if (Tok.isNot(tok::l_paren) && Tok.isNot(tok::l_brace)) { 858 // We found something weird in a mem-initializer-id. 859 if (getLangOpts().CPlusPlus11) 860 return Diag(Tok.getLocation(), diag::err_expected_either) 861 << tok::l_paren << tok::l_brace; 862 else 863 return Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren; 864 } 865 866 tok::TokenKind kind = Tok.getKind(); 867 Toks.push_back(Tok); 868 bool IsLParen = (kind == tok::l_paren); 869 SourceLocation OpenLoc = Tok.getLocation(); 870 871 if (IsLParen) { 872 ConsumeParen(); 873 } else { 874 assert(kind == tok::l_brace && "Must be left paren or brace here."); 875 ConsumeBrace(); 876 // In C++03, this has to be the start of the function body, which 877 // means the initializer is malformed; we'll diagnose it later. 878 if (!getLangOpts().CPlusPlus11) 879 return false; 880 } 881 882 // Grab the initializer (or the subexpression of the template argument). 883 // FIXME: If we support lambdas here, we'll need to set StopAtSemi to false 884 // if we might be inside the braces of a lambda-expression. 885 tok::TokenKind CloseKind = IsLParen ? tok::r_paren : tok::r_brace; 886 if (!ConsumeAndStoreUntil(CloseKind, Toks, /*StopAtSemi=*/true)) { 887 Diag(Tok, diag::err_expected) << CloseKind; 888 Diag(OpenLoc, diag::note_matching) << kind; 889 return true; 890 } 891 892 // Grab pack ellipsis, if present. 893 if (Tok.is(tok::ellipsis)) { 894 Toks.push_back(Tok); 895 ConsumeToken(); 896 } 897 898 // If we know we just consumed a mem-initializer, we must have ',' or '{' 899 // next. 900 if (Tok.is(tok::comma)) { 901 Toks.push_back(Tok); 902 ConsumeToken(); 903 } else if (Tok.is(tok::l_brace)) { 904 // This is the function body if the ')' or '}' is immediately followed by 905 // a '{'. That cannot happen within a template argument, apart from the 906 // case where a template argument contains a compound literal: 907 // 908 // S ( ) : a < b < c > ( d ) { } 909 // // End of declaration, or still inside the template argument? 910 // 911 // ... and the case where the template argument contains a lambda: 912 // 913 // S ( ) : a < 0 && b < c > ( d ) + [ ] ( ) { return 0; } 914 // ( ) > ( ) { } 915 // 916 // FIXME: Disambiguate these cases. Note that the latter case is probably 917 // going to be made ill-formed by core issue 1607. 918 Toks.push_back(Tok); 919 ConsumeBrace(); 920 return false; 921 } else if (!MightBeTemplateArgument) { 922 return Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace 923 << tok::comma; 924 } 925 } 926 } 927 928 /// \brief Consume and store tokens from the '?' to the ':' in a conditional 929 /// expression. 930 bool Parser::ConsumeAndStoreConditional(CachedTokens &Toks) { 931 // Consume '?'. 932 assert(Tok.is(tok::question)); 933 Toks.push_back(Tok); 934 ConsumeToken(); 935 936 while (Tok.isNot(tok::colon)) { 937 if (!ConsumeAndStoreUntil(tok::question, tok::colon, Toks, 938 /*StopAtSemi=*/true, 939 /*ConsumeFinalToken=*/false)) 940 return false; 941 942 // If we found a nested conditional, consume it. 943 if (Tok.is(tok::question) && !ConsumeAndStoreConditional(Toks)) 944 return false; 945 } 946 947 // Consume ':'. 948 Toks.push_back(Tok); 949 ConsumeToken(); 950 return true; 951 } 952 953 /// \brief A tentative parsing action that can also revert token annotations. 954 class Parser::UnannotatedTentativeParsingAction : public TentativeParsingAction { 955 public: 956 explicit UnannotatedTentativeParsingAction(Parser &Self, 957 tok::TokenKind EndKind) 958 : TentativeParsingAction(Self), Self(Self), EndKind(EndKind) { 959 // Stash away the old token stream, so we can restore it once the 960 // tentative parse is complete. 961 TentativeParsingAction Inner(Self); 962 Self.ConsumeAndStoreUntil(EndKind, Toks, true, /*ConsumeFinalToken*/false); 963 Inner.Revert(); 964 } 965 966 void RevertAnnotations() { 967 Revert(); 968 969 // Put back the original tokens. 970 Self.SkipUntil(EndKind, StopAtSemi | StopBeforeMatch); 971 if (Toks.size()) { 972 Token *Buffer = new Token[Toks.size()]; 973 std::copy(Toks.begin() + 1, Toks.end(), Buffer); 974 Buffer[Toks.size() - 1] = Self.Tok; 975 Self.PP.EnterTokenStream(Buffer, Toks.size(), true, /*Owned*/true); 976 977 Self.Tok = Toks.front(); 978 } 979 } 980 981 private: 982 Parser &Self; 983 CachedTokens Toks; 984 tok::TokenKind EndKind; 985 }; 986 987 /// ConsumeAndStoreInitializer - Consume and store the token at the passed token 988 /// container until the end of the current initializer expression (either a 989 /// default argument or an in-class initializer for a non-static data member). 990 /// 991 /// Returns \c true if we reached the end of something initializer-shaped, 992 /// \c false if we bailed out. 993 bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, 994 CachedInitKind CIK) { 995 // We always want this function to consume at least one token if not at EOF. 996 bool IsFirstToken = true; 997 998 // Number of possible unclosed <s we've seen so far. These might be templates, 999 // and might not, but if there were none of them (or we know for sure that 1000 // we're within a template), we can avoid a tentative parse. 1001 unsigned AngleCount = 0; 1002 unsigned KnownTemplateCount = 0; 1003 1004 while (1) { 1005 switch (Tok.getKind()) { 1006 case tok::comma: 1007 // If we might be in a template, perform a tentative parse to check. 1008 if (!AngleCount) 1009 // Not a template argument: this is the end of the initializer. 1010 return true; 1011 if (KnownTemplateCount) 1012 goto consume_token; 1013 1014 // We hit a comma inside angle brackets. This is the hard case. The 1015 // rule we follow is: 1016 // * For a default argument, if the tokens after the comma form a 1017 // syntactically-valid parameter-declaration-clause, in which each 1018 // parameter has an initializer, then this comma ends the default 1019 // argument. 1020 // * For a default initializer, if the tokens after the comma form a 1021 // syntactically-valid init-declarator-list, then this comma ends 1022 // the default initializer. 1023 { 1024 UnannotatedTentativeParsingAction PA(*this, 1025 CIK == CIK_DefaultInitializer 1026 ? tok::semi : tok::r_paren); 1027 Sema::TentativeAnalysisScope Scope(Actions); 1028 1029 TPResult Result = TPResult::Error; 1030 ConsumeToken(); 1031 switch (CIK) { 1032 case CIK_DefaultInitializer: 1033 Result = TryParseInitDeclaratorList(); 1034 // If we parsed a complete, ambiguous init-declarator-list, this 1035 // is only syntactically-valid if it's followed by a semicolon. 1036 if (Result == TPResult::Ambiguous && Tok.isNot(tok::semi)) 1037 Result = TPResult::False; 1038 break; 1039 1040 case CIK_DefaultArgument: 1041 bool InvalidAsDeclaration = false; 1042 Result = TryParseParameterDeclarationClause( 1043 &InvalidAsDeclaration, /*VersusTemplateArgument=*/true); 1044 // If this is an expression or a declaration with a missing 1045 // 'typename', assume it's not a declaration. 1046 if (Result == TPResult::Ambiguous && InvalidAsDeclaration) 1047 Result = TPResult::False; 1048 break; 1049 } 1050 1051 // If what follows could be a declaration, it is a declaration. 1052 if (Result != TPResult::False && Result != TPResult::Error) { 1053 PA.Revert(); 1054 return true; 1055 } 1056 1057 // In the uncommon case that we decide the following tokens are part 1058 // of a template argument, revert any annotations we've performed in 1059 // those tokens. We're not going to look them up until we've parsed 1060 // the rest of the class, and that might add more declarations. 1061 PA.RevertAnnotations(); 1062 } 1063 1064 // Keep going. We know we're inside a template argument list now. 1065 ++KnownTemplateCount; 1066 goto consume_token; 1067 1068 case tok::eof: 1069 case tok::annot_module_begin: 1070 case tok::annot_module_end: 1071 case tok::annot_module_include: 1072 // Ran out of tokens. 1073 return false; 1074 1075 case tok::less: 1076 // FIXME: A '<' can only start a template-id if it's preceded by an 1077 // identifier, an operator-function-id, or a literal-operator-id. 1078 ++AngleCount; 1079 goto consume_token; 1080 1081 case tok::question: 1082 // In 'a ? b : c', 'b' can contain an unparenthesized comma. If it does, 1083 // that is *never* the end of the initializer. Skip to the ':'. 1084 if (!ConsumeAndStoreConditional(Toks)) 1085 return false; 1086 break; 1087 1088 case tok::greatergreatergreater: 1089 if (!getLangOpts().CPlusPlus11) 1090 goto consume_token; 1091 if (AngleCount) --AngleCount; 1092 if (KnownTemplateCount) --KnownTemplateCount; 1093 // Fall through. 1094 case tok::greatergreater: 1095 if (!getLangOpts().CPlusPlus11) 1096 goto consume_token; 1097 if (AngleCount) --AngleCount; 1098 if (KnownTemplateCount) --KnownTemplateCount; 1099 // Fall through. 1100 case tok::greater: 1101 if (AngleCount) --AngleCount; 1102 if (KnownTemplateCount) --KnownTemplateCount; 1103 goto consume_token; 1104 1105 case tok::kw_template: 1106 // 'template' identifier '<' is known to start a template argument list, 1107 // and can be used to disambiguate the parse. 1108 // FIXME: Support all forms of 'template' unqualified-id '<'. 1109 Toks.push_back(Tok); 1110 ConsumeToken(); 1111 if (Tok.is(tok::identifier)) { 1112 Toks.push_back(Tok); 1113 ConsumeToken(); 1114 if (Tok.is(tok::less)) { 1115 ++AngleCount; 1116 ++KnownTemplateCount; 1117 Toks.push_back(Tok); 1118 ConsumeToken(); 1119 } 1120 } 1121 break; 1122 1123 case tok::kw_operator: 1124 // If 'operator' precedes other punctuation, that punctuation loses 1125 // its special behavior. 1126 Toks.push_back(Tok); 1127 ConsumeToken(); 1128 switch (Tok.getKind()) { 1129 case tok::comma: 1130 case tok::greatergreatergreater: 1131 case tok::greatergreater: 1132 case tok::greater: 1133 case tok::less: 1134 Toks.push_back(Tok); 1135 ConsumeToken(); 1136 break; 1137 default: 1138 break; 1139 } 1140 break; 1141 1142 case tok::l_paren: 1143 // Recursively consume properly-nested parens. 1144 Toks.push_back(Tok); 1145 ConsumeParen(); 1146 ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false); 1147 break; 1148 case tok::l_square: 1149 // Recursively consume properly-nested square brackets. 1150 Toks.push_back(Tok); 1151 ConsumeBracket(); 1152 ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false); 1153 break; 1154 case tok::l_brace: 1155 // Recursively consume properly-nested braces. 1156 Toks.push_back(Tok); 1157 ConsumeBrace(); 1158 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); 1159 break; 1160 1161 // Okay, we found a ']' or '}' or ')', which we think should be balanced. 1162 // Since the user wasn't looking for this token (if they were, it would 1163 // already be handled), this isn't balanced. If there is a LHS token at a 1164 // higher level, we will assume that this matches the unbalanced token 1165 // and return it. Otherwise, this is a spurious RHS token, which we 1166 // consume and pass on to downstream code to diagnose. 1167 case tok::r_paren: 1168 if (CIK == CIK_DefaultArgument) 1169 return true; // End of the default argument. 1170 if (ParenCount && !IsFirstToken) 1171 return false; 1172 Toks.push_back(Tok); 1173 ConsumeParen(); 1174 continue; 1175 case tok::r_square: 1176 if (BracketCount && !IsFirstToken) 1177 return false; 1178 Toks.push_back(Tok); 1179 ConsumeBracket(); 1180 continue; 1181 case tok::r_brace: 1182 if (BraceCount && !IsFirstToken) 1183 return false; 1184 Toks.push_back(Tok); 1185 ConsumeBrace(); 1186 continue; 1187 1188 case tok::code_completion: 1189 Toks.push_back(Tok); 1190 ConsumeCodeCompletionToken(); 1191 break; 1192 1193 case tok::string_literal: 1194 case tok::wide_string_literal: 1195 case tok::utf8_string_literal: 1196 case tok::utf16_string_literal: 1197 case tok::utf32_string_literal: 1198 Toks.push_back(Tok); 1199 ConsumeStringToken(); 1200 break; 1201 case tok::semi: 1202 if (CIK == CIK_DefaultInitializer) 1203 return true; // End of the default initializer. 1204 // FALL THROUGH. 1205 default: 1206 consume_token: 1207 Toks.push_back(Tok); 1208 ConsumeToken(); 1209 break; 1210 } 1211 IsFirstToken = false; 1212 } 1213 } 1214