/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Parse/ParseCXXInlineMethods.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- ParseCXXInlineMethods.cpp - C++ class inline methods parsing------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file implements parsing for C++ class inline methods. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/Parse/Parser.h" |
14 | | #include "clang/AST/DeclTemplate.h" |
15 | | #include "clang/Parse/ParseDiagnostic.h" |
16 | | #include "clang/Parse/RAIIObjectsForParser.h" |
17 | | #include "clang/Sema/DeclSpec.h" |
18 | | #include "clang/Sema/Scope.h" |
19 | | using namespace clang; |
20 | | |
21 | | /// ParseCXXInlineMethodDef - We parsed and verified that the specified |
22 | | /// Declarator is a well formed C++ inline method definition. Now lex its body |
23 | | /// and store its tokens for parsing after the C++ class is complete. |
24 | | NamedDecl *Parser::ParseCXXInlineMethodDef( |
25 | | AccessSpecifier AS, const ParsedAttributesView &AccessAttrs, |
26 | | ParsingDeclarator &D, const ParsedTemplateInfo &TemplateInfo, |
27 | 919k | const VirtSpecifiers &VS, SourceLocation PureSpecLoc) { |
28 | 919k | assert(D.isFunctionDeclarator() && "This isn't a function declarator!"); |
29 | 0 | assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try, tok::equal) && |
30 | 919k | "Current token not a '{', ':', '=', or 'try'!"); |
31 | | |
32 | 0 | MultiTemplateParamsArg TemplateParams( |
33 | 919k | TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data()135k |
34 | 919k | : nullptr783k , |
35 | 919k | TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size()135k : 0783k ); |
36 | | |
37 | 919k | NamedDecl *FnD; |
38 | 919k | if (D.getDeclSpec().isFriendSpecified()) |
39 | 22.4k | FnD = Actions.ActOnFriendFunctionDecl(getCurScope(), D, |
40 | 22.4k | TemplateParams); |
41 | 896k | else { |
42 | 896k | FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D, |
43 | 896k | TemplateParams, nullptr, |
44 | 896k | VS, ICIS_NoInit); |
45 | 896k | if (FnD) { |
46 | 896k | Actions.ProcessDeclAttributeList(getCurScope(), FnD, AccessAttrs); |
47 | 896k | if (PureSpecLoc.isValid()) |
48 | 3 | Actions.ActOnPureSpecifier(FnD, PureSpecLoc); |
49 | 896k | } |
50 | 896k | } |
51 | | |
52 | 919k | if (FnD) |
53 | 919k | HandleMemberFunctionDeclDelays(D, FnD); |
54 | | |
55 | 919k | D.complete(FnD); |
56 | | |
57 | 919k | if (TryConsumeToken(tok::equal)) { |
58 | 52.6k | if (!FnD) { |
59 | 1 | SkipUntil(tok::semi); |
60 | 1 | return nullptr; |
61 | 1 | } |
62 | | |
63 | 52.6k | bool Delete = false; |
64 | 52.6k | SourceLocation KWLoc; |
65 | 52.6k | SourceLocation KWEndLoc = Tok.getEndLoc().getLocWithOffset(-1); |
66 | 52.6k | if (TryConsumeToken(tok::kw_delete, KWLoc)) { |
67 | 22.5k | Diag(KWLoc, getLangOpts().CPlusPlus11 |
68 | 22.5k | ? diag::warn_cxx98_compat_defaulted_deleted_function22.4k |
69 | 22.5k | : diag::ext_defaulted_deleted_function47 ) |
70 | 22.5k | << 1 /* deleted */; |
71 | 22.5k | Actions.SetDeclDeleted(FnD, KWLoc); |
72 | 22.5k | Delete = true; |
73 | 22.5k | if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) { |
74 | 20.4k | DeclAsFunction->setRangeEnd(KWEndLoc); |
75 | 20.4k | } |
76 | 30.0k | } else if (TryConsumeToken(tok::kw_default, KWLoc)) { |
77 | 30.0k | Diag(KWLoc, getLangOpts().CPlusPlus11 |
78 | 30.0k | ? diag::warn_cxx98_compat_defaulted_deleted_function30.0k |
79 | 30.0k | : diag::ext_defaulted_deleted_function9 ) |
80 | 30.0k | << 0 /* defaulted */; |
81 | 30.0k | Actions.SetDeclDefaulted(FnD, KWLoc); |
82 | 30.0k | if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) { |
83 | 30.0k | DeclAsFunction->setRangeEnd(KWEndLoc); |
84 | 30.0k | } |
85 | 30.0k | } else { |
86 | 0 | llvm_unreachable("function definition after = not 'delete' or 'default'"); |
87 | 0 | } |
88 | | |
89 | 52.6k | if (Tok.is(tok::comma)) { |
90 | 0 | Diag(KWLoc, diag::err_default_delete_in_multiple_declaration) |
91 | 0 | << Delete; |
92 | 0 | SkipUntil(tok::semi); |
93 | 52.6k | } else if (ExpectAndConsume(tok::semi, diag::err_expected_after, |
94 | 52.6k | Delete ? "delete"22.5k : "default"30.0k )) { |
95 | 1 | SkipUntil(tok::semi); |
96 | 1 | } |
97 | | |
98 | 52.6k | return FnD; |
99 | 52.6k | } |
100 | | |
101 | 866k | if (SkipFunctionBodies && (399 !FnD399 || Actions.canSkipFunctionBody(FnD)399 ) && |
102 | 866k | trySkippingFunctionBody()392 ) { |
103 | 333 | Actions.ActOnSkippedFunctionBody(FnD); |
104 | 333 | return FnD; |
105 | 333 | } |
106 | | |
107 | | // In delayed template parsing mode, if we are within a class template |
108 | | // or if we are about to parse function member template then consume |
109 | | // the tokens and store them for parsing at the end of the translation unit. |
110 | 866k | if (getLangOpts().DelayedTemplateParsing && |
111 | 866k | D.getFunctionDefinitionKind() == FunctionDefinitionKind::Definition887 && |
112 | 866k | !D.getDeclSpec().hasConstexprSpecifier()887 && |
113 | 866k | !(867 FnD867 && FnD->getAsFunction()867 && |
114 | 867 | FnD->getAsFunction()->getReturnType()->getContainedAutoType()) && |
115 | 866k | (764 (764 Actions.CurContext->isDependentContext()764 || |
116 | 764 | (518 TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate518 && |
117 | 518 | TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization41 )) && |
118 | 764 | !Actions.IsInsideALocalClassWithinATemplateFunction()283 )) { |
119 | | |
120 | 263 | CachedTokens Toks; |
121 | 263 | LexTemplateFunctionForLateParsing(Toks); |
122 | | |
123 | 263 | if (FnD) { |
124 | 263 | FunctionDecl *FD = FnD->getAsFunction(); |
125 | 263 | Actions.CheckForFunctionRedefinition(FD); |
126 | 263 | Actions.MarkAsLateParsedTemplate(FD, FnD, Toks); |
127 | 263 | } |
128 | | |
129 | 263 | return FnD; |
130 | 263 | } |
131 | | |
132 | | // Consume the tokens and store them for later parsing. |
133 | | |
134 | 866k | LexedMethod* LM = new LexedMethod(this, FnD); |
135 | 866k | getCurrentClass().LateParsedDeclarations.push_back(LM); |
136 | 866k | CachedTokens &Toks = LM->Toks; |
137 | | |
138 | 866k | tok::TokenKind kind = Tok.getKind(); |
139 | | // Consume everything up to (and including) the left brace of the |
140 | | // function body. |
141 | 866k | if (ConsumeAndStoreFunctionPrologue(Toks)) { |
142 | | // We didn't find the left-brace we expected after the |
143 | | // constructor initializer. |
144 | | |
145 | | // If we're code-completing and the completion point was in the broken |
146 | | // initializer, we want to parse it even though that will fail. |
147 | 18 | if (PP.isCodeCompletionEnabled() && |
148 | 18 | llvm::any_of(Toks, [](const Token &Tok) 2 { |
149 | 6 | return Tok.is(tok::code_completion); |
150 | 6 | })) { |
151 | | // If we gave up at the completion point, the initializer list was |
152 | | // likely truncated, so don't eat more tokens. We'll hit some extra |
153 | | // errors, but they should be ignored in code completion. |
154 | 2 | return FnD; |
155 | 2 | } |
156 | | |
157 | | // We already printed an error, and it's likely impossible to recover, |
158 | | // so don't try to parse this method later. |
159 | | // Skip over the rest of the decl and back to somewhere that looks |
160 | | // reasonable. |
161 | 16 | SkipMalformedDecl(); |
162 | 16 | delete getCurrentClass().LateParsedDeclarations.back(); |
163 | 16 | getCurrentClass().LateParsedDeclarations.pop_back(); |
164 | 16 | return FnD; |
165 | 865k | } else { |
166 | | // Consume everything up to (and including) the matching right brace. |
167 | 865k | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
168 | 865k | } |
169 | | |
170 | | // If we're in a function-try-block, we need to store all the catch blocks. |
171 | 865k | if (kind == tok::kw_try) { |
172 | 74 | while (Tok.is(tok::kw_catch)) { |
173 | 37 | ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false); |
174 | 37 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
175 | 37 | } |
176 | 37 | } |
177 | | |
178 | 865k | if (FnD) { |
179 | 865k | FunctionDecl *FD = FnD->getAsFunction(); |
180 | | // Track that this function will eventually have a body; Sema needs |
181 | | // to know this. |
182 | 865k | Actions.CheckForFunctionRedefinition(FD); |
183 | 865k | FD->setWillHaveBody(true); |
184 | 865k | } else { |
185 | | // If semantic analysis could not build a function declaration, |
186 | | // just throw away the late-parsed declaration. |
187 | 30 | delete getCurrentClass().LateParsedDeclarations.back(); |
188 | 30 | getCurrentClass().LateParsedDeclarations.pop_back(); |
189 | 30 | } |
190 | | |
191 | 865k | return FnD; |
192 | 866k | } |
193 | | |
194 | | /// ParseCXXNonStaticMemberInitializer - We parsed and verified that the |
195 | | /// specified Declarator is a well formed C++ non-static data member |
196 | | /// declaration. Now lex its initializer and store its tokens for parsing |
197 | | /// after the class is complete. |
198 | 4.78k | void Parser::ParseCXXNonStaticMemberInitializer(Decl *VarD) { |
199 | 4.78k | assert(Tok.isOneOf(tok::l_brace, tok::equal) && |
200 | 4.78k | "Current token not a '{' or '='!"); |
201 | | |
202 | 0 | LateParsedMemberInitializer *MI = |
203 | 4.78k | new LateParsedMemberInitializer(this, VarD); |
204 | 4.78k | getCurrentClass().LateParsedDeclarations.push_back(MI); |
205 | 4.78k | CachedTokens &Toks = MI->Toks; |
206 | | |
207 | 4.78k | tok::TokenKind kind = Tok.getKind(); |
208 | 4.78k | if (kind == tok::equal) { |
209 | 4.68k | Toks.push_back(Tok); |
210 | 4.68k | ConsumeToken(); |
211 | 4.68k | } |
212 | | |
213 | 4.78k | if (kind == tok::l_brace) { |
214 | | // Begin by storing the '{' token. |
215 | 103 | Toks.push_back(Tok); |
216 | 103 | ConsumeBrace(); |
217 | | |
218 | | // Consume everything up to (and including) the matching right brace. |
219 | 103 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/true); |
220 | 4.68k | } else { |
221 | | // Consume everything up to (but excluding) the comma or semicolon. |
222 | 4.68k | ConsumeAndStoreInitializer(Toks, CIK_DefaultInitializer); |
223 | 4.68k | } |
224 | | |
225 | | // Store an artificial EOF token to ensure that we don't run off the end of |
226 | | // the initializer when we come to parse it. |
227 | 4.78k | Token Eof; |
228 | 4.78k | Eof.startToken(); |
229 | 4.78k | Eof.setKind(tok::eof); |
230 | 4.78k | Eof.setLocation(Tok.getLocation()); |
231 | 4.78k | Eof.setEofData(VarD); |
232 | 4.78k | Toks.push_back(Eof); |
233 | 4.78k | } |
234 | | |
235 | 1.01M | Parser::LateParsedDeclaration::~LateParsedDeclaration() {} |
236 | 876k | void Parser::LateParsedDeclaration::ParseLexedMethodDeclarations() {} |
237 | 992k | void Parser::LateParsedDeclaration::ParseLexedMemberInitializers() {} |
238 | 131k | void Parser::LateParsedDeclaration::ParseLexedMethodDefs() {} |
239 | 991k | void Parser::LateParsedDeclaration::ParseLexedAttributes() {} |
240 | 997k | void Parser::LateParsedDeclaration::ParseLexedPragmas() {} |
241 | | |
242 | | Parser::LateParsedClass::LateParsedClass(Parser *P, ParsingClass *C) |
243 | 7.49k | : Self(P), Class(C) {} |
244 | | |
245 | 7.49k | Parser::LateParsedClass::~LateParsedClass() { |
246 | 7.49k | Self->DeallocateParsedClasses(Class); |
247 | 7.49k | } |
248 | | |
249 | 7.49k | void Parser::LateParsedClass::ParseLexedMethodDeclarations() { |
250 | 7.49k | Self->ParseLexedMethodDeclarations(*Class); |
251 | 7.49k | } |
252 | | |
253 | 7.49k | void Parser::LateParsedClass::ParseLexedMemberInitializers() { |
254 | 7.49k | Self->ParseLexedMemberInitializers(*Class); |
255 | 7.49k | } |
256 | | |
257 | 7.49k | void Parser::LateParsedClass::ParseLexedMethodDefs() { |
258 | 7.49k | Self->ParseLexedMethodDefs(*Class); |
259 | 7.49k | } |
260 | | |
261 | 7.49k | void Parser::LateParsedClass::ParseLexedAttributes() { |
262 | 7.49k | Self->ParseLexedAttributes(*Class); |
263 | 7.49k | } |
264 | | |
265 | 7.49k | void Parser::LateParsedClass::ParseLexedPragmas() { |
266 | 7.49k | Self->ParseLexedPragmas(*Class); |
267 | 7.49k | } |
268 | | |
269 | 120k | void Parser::LateParsedMethodDeclaration::ParseLexedMethodDeclarations() { |
270 | 120k | Self->ParseLexedMethodDeclaration(*this); |
271 | 120k | } |
272 | | |
273 | 865k | void Parser::LexedMethod::ParseLexedMethodDefs() { |
274 | 865k | Self->ParseLexedMethodDef(*this); |
275 | 865k | } |
276 | | |
277 | 4.78k | void Parser::LateParsedMemberInitializer::ParseLexedMemberInitializers() { |
278 | 4.78k | Self->ParseLexedMemberInitializer(*this); |
279 | 4.78k | } |
280 | | |
281 | 5.62k | void Parser::LateParsedAttribute::ParseLexedAttributes() { |
282 | 5.62k | Self->ParseLexedAttribute(*this, true, false); |
283 | 5.62k | } |
284 | | |
285 | 86 | void Parser::LateParsedPragma::ParseLexedPragmas() { |
286 | 86 | Self->ParseLexedPragma(*this); |
287 | 86 | } |
288 | | |
289 | | /// Utility to re-enter a possibly-templated scope while parsing its |
290 | | /// late-parsed components. |
291 | | struct Parser::ReenterTemplateScopeRAII { |
292 | | Parser &P; |
293 | | MultiParseScope Scopes; |
294 | | TemplateParameterDepthRAII CurTemplateDepthTracker; |
295 | | |
296 | | ReenterTemplateScopeRAII(Parser &P, Decl *MaybeTemplated, bool Enter = true) |
297 | 4.75M | : P(P), Scopes(P), CurTemplateDepthTracker(P.TemplateParameterDepth) { |
298 | 4.75M | if (Enter) { |
299 | 1.03M | CurTemplateDepthTracker.addDepth( |
300 | 1.03M | P.ReenterTemplateScopes(Scopes, MaybeTemplated)); |
301 | 1.03M | } |
302 | 4.75M | } |
303 | | }; |
304 | | |
305 | | /// Utility to re-enter a class scope while parsing its late-parsed components. |
306 | | struct Parser::ReenterClassScopeRAII : ReenterTemplateScopeRAII { |
307 | | ParsingClass &Class; |
308 | | |
309 | | ReenterClassScopeRAII(Parser &P, ParsingClass &Class) |
310 | | : ReenterTemplateScopeRAII(P, Class.TagOrTemplate, |
311 | | /*Enter=*/!Class.TopLevelClass), |
312 | 3.75M | Class(Class) { |
313 | | // If this is the top-level class, we're still within its scope. |
314 | 3.75M | if (Class.TopLevelClass) |
315 | 3.71M | return; |
316 | | |
317 | | // Re-enter the class scope itself. |
318 | 37.4k | Scopes.Enter(Scope::ClassScope|Scope::DeclScope); |
319 | 37.4k | P.Actions.ActOnStartDelayedMemberDeclarations(P.getCurScope(), |
320 | 37.4k | Class.TagOrTemplate); |
321 | 37.4k | } |
322 | 3.75M | ~ReenterClassScopeRAII() { |
323 | 3.75M | if (Class.TopLevelClass) |
324 | 3.71M | return; |
325 | | |
326 | 37.4k | P.Actions.ActOnFinishDelayedMemberDeclarations(P.getCurScope(), |
327 | 37.4k | Class.TagOrTemplate); |
328 | 37.4k | } |
329 | | }; |
330 | | |
331 | | /// ParseLexedMethodDeclarations - We finished parsing the member |
332 | | /// specification of a top (non-nested) C++ class. Now go over the |
333 | | /// stack of method declarations with some parts for which parsing was |
334 | | /// delayed (such as default arguments) and parse them. |
335 | 751k | void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) { |
336 | 751k | ReenterClassScopeRAII InClassScope(*this, Class); |
337 | | |
338 | 751k | for (LateParsedDeclaration *LateD : Class.LateParsedDeclarations) |
339 | 1.00M | LateD->ParseLexedMethodDeclarations(); |
340 | 751k | } |
341 | | |
342 | 120k | void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { |
343 | | // If this is a member template, introduce the template parameter scope. |
344 | 120k | ReenterTemplateScopeRAII InFunctionTemplateScope(*this, LM.Method); |
345 | | |
346 | | // Start the delayed C++ method declaration |
347 | 120k | Actions.ActOnStartDelayedCXXMethodDeclaration(getCurScope(), LM.Method); |
348 | | |
349 | | // Introduce the parameters into scope and parse their default |
350 | | // arguments. |
351 | 120k | InFunctionTemplateScope.Scopes.Enter(Scope::FunctionPrototypeScope | |
352 | 120k | Scope::FunctionDeclarationScope | |
353 | 120k | Scope::DeclScope); |
354 | 326k | for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I205k ) { |
355 | 205k | auto Param = cast<ParmVarDecl>(LM.DefaultArgs[I].Param); |
356 | | // Introduce the parameter into scope. |
357 | 205k | bool HasUnparsed = Param->hasUnparsedDefaultArg(); |
358 | 205k | Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param); |
359 | 205k | std::unique_ptr<CachedTokens> Toks = std::move(LM.DefaultArgs[I].Toks); |
360 | 205k | if (Toks) { |
361 | 76.2k | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
362 | | |
363 | | // Mark the end of the default argument so that we know when to stop when |
364 | | // we parse it later on. |
365 | 76.2k | Token LastDefaultArgToken = Toks->back(); |
366 | 76.2k | Token DefArgEnd; |
367 | 76.2k | DefArgEnd.startToken(); |
368 | 76.2k | DefArgEnd.setKind(tok::eof); |
369 | 76.2k | DefArgEnd.setLocation(LastDefaultArgToken.getEndLoc()); |
370 | 76.2k | DefArgEnd.setEofData(Param); |
371 | 76.2k | Toks->push_back(DefArgEnd); |
372 | | |
373 | | // Parse the default argument from its saved token stream. |
374 | 76.2k | Toks->push_back(Tok); // So that the current token doesn't get lost |
375 | 76.2k | PP.EnterTokenStream(*Toks, true, /*IsReinject*/ true); |
376 | | |
377 | | // Consume the previously-pushed token. |
378 | 76.2k | ConsumeAnyToken(); |
379 | | |
380 | | // Consume the '='. |
381 | 76.2k | assert(Tok.is(tok::equal) && "Default argument not starting with '='"); |
382 | 0 | SourceLocation EqualLoc = ConsumeToken(); |
383 | | |
384 | | // The argument isn't actually potentially evaluated unless it is |
385 | | // used. |
386 | 76.2k | EnterExpressionEvaluationContext Eval( |
387 | 76.2k | Actions, |
388 | 76.2k | Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, Param); |
389 | | |
390 | 76.2k | ExprResult DefArgResult; |
391 | 76.2k | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)76.1k ) { |
392 | 1.01k | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
393 | 1.01k | DefArgResult = ParseBraceInitializer(); |
394 | 1.01k | } else |
395 | 75.2k | DefArgResult = ParseAssignmentExpression(); |
396 | 76.2k | DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult); |
397 | 76.2k | if (DefArgResult.isInvalid()) { |
398 | 26 | Actions.ActOnParamDefaultArgumentError(Param, EqualLoc); |
399 | 76.2k | } else { |
400 | 76.2k | if (Tok.isNot(tok::eof) || Tok.getEofData() != Param76.2k ) { |
401 | | // The last two tokens are the terminator and the saved value of |
402 | | // Tok; the last token in the default argument is the one before |
403 | | // those. |
404 | 2 | assert(Toks->size() >= 3 && "expected a token in default arg"); |
405 | 0 | Diag(Tok.getLocation(), diag::err_default_arg_unparsed) |
406 | 2 | << SourceRange(Tok.getLocation(), |
407 | 2 | (*Toks)[Toks->size() - 3].getLocation()); |
408 | 2 | } |
409 | 0 | Actions.ActOnParamDefaultArgument(Param, EqualLoc, |
410 | 76.2k | DefArgResult.get()); |
411 | 76.2k | } |
412 | | |
413 | | // There could be leftover tokens (e.g. because of an error). |
414 | | // Skip through until we reach the 'end of default argument' token. |
415 | 76.2k | while (Tok.isNot(tok::eof)) |
416 | 7 | ConsumeAnyToken(); |
417 | | |
418 | 76.2k | if (Tok.is(tok::eof) && Tok.getEofData() == Param) |
419 | 76.2k | ConsumeAnyToken(); |
420 | 129k | } else if (HasUnparsed) { |
421 | 7 | assert(Param->hasInheritedDefaultArg()); |
422 | 0 | const FunctionDecl *Old; |
423 | 7 | if (const auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(LM.Method)) |
424 | 1 | Old = |
425 | 1 | cast<FunctionDecl>(FunTmpl->getTemplatedDecl())->getPreviousDecl(); |
426 | 6 | else |
427 | 6 | Old = cast<FunctionDecl>(LM.Method)->getPreviousDecl(); |
428 | 7 | if (Old) { |
429 | 5 | ParmVarDecl *OldParam = const_cast<ParmVarDecl*>(Old->getParamDecl(I)); |
430 | 5 | assert(!OldParam->hasUnparsedDefaultArg()); |
431 | 5 | if (OldParam->hasUninstantiatedDefaultArg()) |
432 | 4 | Param->setUninstantiatedDefaultArg( |
433 | 4 | OldParam->getUninstantiatedDefaultArg()); |
434 | 1 | else |
435 | 1 | Param->setDefaultArg(OldParam->getInit()); |
436 | 5 | } |
437 | 7 | } |
438 | 205k | } |
439 | | |
440 | | // Parse a delayed exception-specification, if there is one. |
441 | 120k | if (CachedTokens *Toks = LM.ExceptionSpecTokens) { |
442 | 52.5k | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
443 | | |
444 | | // Add the 'stop' token. |
445 | 52.5k | Token LastExceptionSpecToken = Toks->back(); |
446 | 52.5k | Token ExceptionSpecEnd; |
447 | 52.5k | ExceptionSpecEnd.startToken(); |
448 | 52.5k | ExceptionSpecEnd.setKind(tok::eof); |
449 | 52.5k | ExceptionSpecEnd.setLocation(LastExceptionSpecToken.getEndLoc()); |
450 | 52.5k | ExceptionSpecEnd.setEofData(LM.Method); |
451 | 52.5k | Toks->push_back(ExceptionSpecEnd); |
452 | | |
453 | | // Parse the default argument from its saved token stream. |
454 | 52.5k | Toks->push_back(Tok); // So that the current token doesn't get lost |
455 | 52.5k | PP.EnterTokenStream(*Toks, true, /*IsReinject*/true); |
456 | | |
457 | | // Consume the previously-pushed token. |
458 | 52.5k | ConsumeAnyToken(); |
459 | | |
460 | | // C++11 [expr.prim.general]p3: |
461 | | // If a declaration declares a member function or member function |
462 | | // template of a class X, the expression this is a prvalue of type |
463 | | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
464 | | // and the end of the function-definition, member-declarator, or |
465 | | // declarator. |
466 | 52.5k | CXXMethodDecl *Method; |
467 | 52.5k | if (FunctionTemplateDecl *FunTmpl |
468 | 52.5k | = dyn_cast<FunctionTemplateDecl>(LM.Method)) |
469 | 17.5k | Method = dyn_cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl()); |
470 | 34.9k | else |
471 | 34.9k | Method = dyn_cast<CXXMethodDecl>(LM.Method); |
472 | | |
473 | 52.5k | Sema::CXXThisScopeRAII ThisScope( |
474 | 52.5k | Actions, Method ? Method->getParent()52.5k : nullptr2 , |
475 | 52.5k | Method ? Method->getMethodQualifiers()52.5k : Qualifiers{}2 , |
476 | 52.5k | Method && getLangOpts().CPlusPlus1152.5k ); |
477 | | |
478 | | // Parse the exception-specification. |
479 | 52.5k | SourceRange SpecificationRange; |
480 | 52.5k | SmallVector<ParsedType, 4> DynamicExceptions; |
481 | 52.5k | SmallVector<SourceRange, 4> DynamicExceptionRanges; |
482 | 52.5k | ExprResult NoexceptExpr; |
483 | 52.5k | CachedTokens *ExceptionSpecTokens; |
484 | | |
485 | 52.5k | ExceptionSpecificationType EST |
486 | 52.5k | = tryParseExceptionSpecification(/*Delayed=*/false, SpecificationRange, |
487 | 52.5k | DynamicExceptions, |
488 | 52.5k | DynamicExceptionRanges, NoexceptExpr, |
489 | 52.5k | ExceptionSpecTokens); |
490 | | |
491 | 52.5k | if (Tok.isNot(tok::eof) || Tok.getEofData() != LM.Method) |
492 | 0 | Diag(Tok.getLocation(), diag::err_except_spec_unparsed); |
493 | | |
494 | | // Attach the exception-specification to the method. |
495 | 52.5k | Actions.actOnDelayedExceptionSpecification(LM.Method, EST, |
496 | 52.5k | SpecificationRange, |
497 | 52.5k | DynamicExceptions, |
498 | 52.5k | DynamicExceptionRanges, |
499 | 52.5k | NoexceptExpr.isUsable()? |
500 | 51.1k | NoexceptExpr.get() : nullptr1.41k ); |
501 | | |
502 | | // There could be leftover tokens (e.g. because of an error). |
503 | | // Skip through until we reach the original token position. |
504 | 52.5k | while (Tok.isNot(tok::eof)) |
505 | 0 | ConsumeAnyToken(); |
506 | | |
507 | | // Clean up the remaining EOF token. |
508 | 52.5k | if (Tok.is(tok::eof) && Tok.getEofData() == LM.Method) |
509 | 52.5k | ConsumeAnyToken(); |
510 | | |
511 | 52.5k | delete Toks; |
512 | 52.5k | LM.ExceptionSpecTokens = nullptr; |
513 | 52.5k | } |
514 | | |
515 | 120k | InFunctionTemplateScope.Scopes.Exit(); |
516 | | |
517 | | // Finish the delayed C++ method declaration. |
518 | 120k | Actions.ActOnFinishDelayedCXXMethodDeclaration(getCurScope(), LM.Method); |
519 | 120k | } |
520 | | |
521 | | /// ParseLexedMethodDefs - We finished parsing the member specification of a top |
522 | | /// (non-nested) C++ class. Now go over the stack of lexed methods that were |
523 | | /// collected during its parsing and parse them all. |
524 | 751k | void Parser::ParseLexedMethodDefs(ParsingClass &Class) { |
525 | 751k | ReenterClassScopeRAII InClassScope(*this, Class); |
526 | | |
527 | 751k | for (LateParsedDeclaration *D : Class.LateParsedDeclarations) |
528 | 1.00M | D->ParseLexedMethodDefs(); |
529 | 751k | } |
530 | | |
531 | 865k | void Parser::ParseLexedMethodDef(LexedMethod &LM) { |
532 | | // If this is a member template, introduce the template parameter scope. |
533 | 865k | ReenterTemplateScopeRAII InFunctionTemplateScope(*this, LM.D); |
534 | | |
535 | 865k | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
536 | | |
537 | 865k | assert(!LM.Toks.empty() && "Empty body!"); |
538 | 0 | Token LastBodyToken = LM.Toks.back(); |
539 | 865k | Token BodyEnd; |
540 | 865k | BodyEnd.startToken(); |
541 | 865k | BodyEnd.setKind(tok::eof); |
542 | 865k | BodyEnd.setLocation(LastBodyToken.getEndLoc()); |
543 | 865k | BodyEnd.setEofData(LM.D); |
544 | 865k | LM.Toks.push_back(BodyEnd); |
545 | | // Append the current token at the end of the new token stream so that it |
546 | | // doesn't get lost. |
547 | 865k | LM.Toks.push_back(Tok); |
548 | 865k | PP.EnterTokenStream(LM.Toks, true, /*IsReinject*/true); |
549 | | |
550 | | // Consume the previously pushed token. |
551 | 865k | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
552 | 865k | assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try) |
553 | 865k | && "Inline method not starting with '{', ':' or 'try'"); |
554 | | |
555 | | // Parse the method body. Function body parsing code is similar enough |
556 | | // to be re-used for method bodies as well. |
557 | 0 | ParseScope FnScope(this, Scope::FnScope | Scope::DeclScope | |
558 | 865k | Scope::CompoundStmtScope); |
559 | 865k | Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D); |
560 | | |
561 | 865k | if (Tok.is(tok::kw_try)) { |
562 | 37 | ParseFunctionTryBlock(LM.D, FnScope); |
563 | | |
564 | 37 | while (Tok.isNot(tok::eof)) |
565 | 0 | ConsumeAnyToken(); |
566 | | |
567 | 37 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) |
568 | 37 | ConsumeAnyToken(); |
569 | 37 | return; |
570 | 37 | } |
571 | 865k | if (Tok.is(tok::colon)) { |
572 | 156k | ParseConstructorInitializer(LM.D); |
573 | | |
574 | | // Error recovery. |
575 | 156k | if (!Tok.is(tok::l_brace)) { |
576 | 29 | FnScope.Exit(); |
577 | 29 | Actions.ActOnFinishFunctionBody(LM.D, nullptr); |
578 | | |
579 | 29 | while (Tok.isNot(tok::eof)) |
580 | 0 | ConsumeAnyToken(); |
581 | | |
582 | 29 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) |
583 | 2 | ConsumeAnyToken(); |
584 | 29 | return; |
585 | 29 | } |
586 | 156k | } else |
587 | 709k | Actions.ActOnDefaultCtorInitializers(LM.D); |
588 | | |
589 | 865k | assert((Actions.getDiagnostics().hasErrorOccurred() || |
590 | 865k | !isa<FunctionTemplateDecl>(LM.D) || |
591 | 865k | cast<FunctionTemplateDecl>(LM.D)->getTemplateParameters()->getDepth() |
592 | 865k | < TemplateParameterDepth) && |
593 | 865k | "TemplateParameterDepth should be greater than the depth of " |
594 | 865k | "current template being instantiated!"); |
595 | | |
596 | 0 | ParseFunctionStatementBody(LM.D, FnScope); |
597 | | |
598 | 865k | while (Tok.isNot(tok::eof)) |
599 | 0 | ConsumeAnyToken(); |
600 | | |
601 | 865k | if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) |
602 | 865k | ConsumeAnyToken(); |
603 | | |
604 | 865k | if (auto *FD = dyn_cast_or_null<FunctionDecl>(LM.D)) |
605 | 732k | if (isa<CXXMethodDecl>(FD) || |
606 | 732k | FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend)21.2k ) |
607 | 732k | Actions.ActOnFinishInlineFunctionDef(FD); |
608 | 865k | } |
609 | | |
610 | | /// ParseLexedMemberInitializers - We finished parsing the member specification |
611 | | /// of a top (non-nested) C++ class. Now go over the stack of lexed data member |
612 | | /// initializers that were collected during its parsing and parse them all. |
613 | 751k | void Parser::ParseLexedMemberInitializers(ParsingClass &Class) { |
614 | 751k | ReenterClassScopeRAII InClassScope(*this, Class); |
615 | | |
616 | 751k | if (!Class.LateParsedDeclarations.empty()) { |
617 | | // C++11 [expr.prim.general]p4: |
618 | | // Otherwise, if a member-declarator declares a non-static data member |
619 | | // (9.2) of a class X, the expression this is a prvalue of type "pointer |
620 | | // to X" within the optional brace-or-equal-initializer. It shall not |
621 | | // appear elsewhere in the member-declarator. |
622 | | // FIXME: This should be done in ParseLexedMemberInitializer, not here. |
623 | 171k | Sema::CXXThisScopeRAII ThisScope(Actions, Class.TagOrTemplate, |
624 | 171k | Qualifiers()); |
625 | | |
626 | 171k | for (LateParsedDeclaration *D : Class.LateParsedDeclarations) |
627 | 1.00M | D->ParseLexedMemberInitializers(); |
628 | 171k | } |
629 | | |
630 | 751k | Actions.ActOnFinishDelayedMemberInitializers(Class.TagOrTemplate); |
631 | 751k | } |
632 | | |
633 | 4.78k | void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) { |
634 | 4.78k | if (!MI.Field || MI.Field->isInvalidDecl()4.77k ) |
635 | 24 | return; |
636 | | |
637 | 4.76k | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
638 | | |
639 | | // Append the current token at the end of the new token stream so that it |
640 | | // doesn't get lost. |
641 | 4.76k | MI.Toks.push_back(Tok); |
642 | 4.76k | PP.EnterTokenStream(MI.Toks, true, /*IsReinject*/true); |
643 | | |
644 | | // Consume the previously pushed token. |
645 | 4.76k | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
646 | | |
647 | 4.76k | SourceLocation EqualLoc; |
648 | | |
649 | 4.76k | Actions.ActOnStartCXXInClassMemberInitializer(); |
650 | | |
651 | 4.76k | ExprResult Init = ParseCXXMemberInitializer(MI.Field, /*IsFunction=*/false, |
652 | 4.76k | EqualLoc); |
653 | | |
654 | 4.76k | Actions.ActOnFinishCXXInClassMemberInitializer(MI.Field, EqualLoc, |
655 | 4.76k | Init.get()); |
656 | | |
657 | | // The next token should be our artificial terminating EOF token. |
658 | 4.76k | if (Tok.isNot(tok::eof)) { |
659 | 19 | if (!Init.isInvalid()) { |
660 | 8 | SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation); |
661 | 8 | if (!EndLoc.isValid()) |
662 | 0 | EndLoc = Tok.getLocation(); |
663 | | // No fixit; we can't recover as if there were a semicolon here. |
664 | 8 | Diag(EndLoc, diag::err_expected_semi_decl_list); |
665 | 8 | } |
666 | | |
667 | | // Consume tokens until we hit the artificial EOF. |
668 | 46 | while (Tok.isNot(tok::eof)) |
669 | 27 | ConsumeAnyToken(); |
670 | 19 | } |
671 | | // Make sure this is *our* artificial EOF token. |
672 | 4.76k | if (Tok.getEofData() == MI.Field) |
673 | 4.76k | ConsumeAnyToken(); |
674 | 4.76k | } |
675 | | |
676 | | /// Wrapper class which calls ParseLexedAttribute, after setting up the |
677 | | /// scope appropriately. |
678 | 751k | void Parser::ParseLexedAttributes(ParsingClass &Class) { |
679 | 751k | ReenterClassScopeRAII InClassScope(*this, Class); |
680 | | |
681 | 751k | for (LateParsedDeclaration *LateD : Class.LateParsedDeclarations) |
682 | 1.00M | LateD->ParseLexedAttributes(); |
683 | 751k | } |
684 | | |
685 | | /// Parse all attributes in LAs, and attach them to Decl D. |
686 | | void Parser::ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D, |
687 | 2.99M | bool EnterScope, bool OnDefinition) { |
688 | 2.99M | assert(LAs.parseSoon() && |
689 | 2.99M | "Attribute list should be marked for immediate parsing."); |
690 | 3.00M | for (unsigned i = 0, ni = LAs.size(); i < ni; ++i5.59k ) { |
691 | 5.59k | if (D) |
692 | 5.58k | LAs[i]->addDecl(D); |
693 | 5.59k | ParseLexedAttribute(*LAs[i], EnterScope, OnDefinition); |
694 | 5.59k | delete LAs[i]; |
695 | 5.59k | } |
696 | 2.99M | LAs.clear(); |
697 | 2.99M | } |
698 | | |
699 | | /// Finish parsing an attribute for which parsing was delayed. |
700 | | /// This will be called at the end of parsing a class declaration |
701 | | /// for each LateParsedAttribute. We consume the saved tokens and |
702 | | /// create an attribute with the arguments filled in. We add this |
703 | | /// to the Attribute list for the decl. |
704 | | void Parser::ParseLexedAttribute(LateParsedAttribute &LA, |
705 | 11.2k | bool EnterScope, bool OnDefinition) { |
706 | | // Create a fake EOF so that attribute parsing won't go off the end of the |
707 | | // attribute. |
708 | 11.2k | Token AttrEnd; |
709 | 11.2k | AttrEnd.startToken(); |
710 | 11.2k | AttrEnd.setKind(tok::eof); |
711 | 11.2k | AttrEnd.setLocation(Tok.getLocation()); |
712 | 11.2k | AttrEnd.setEofData(LA.Toks.data()); |
713 | 11.2k | LA.Toks.push_back(AttrEnd); |
714 | | |
715 | | // Append the current token at the end of the new token stream so that it |
716 | | // doesn't get lost. |
717 | 11.2k | LA.Toks.push_back(Tok); |
718 | 11.2k | PP.EnterTokenStream(LA.Toks, true, /*IsReinject=*/true); |
719 | | // Consume the previously pushed token. |
720 | 11.2k | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
721 | | |
722 | 11.2k | ParsedAttributes Attrs(AttrFactory); |
723 | | |
724 | 11.2k | if (LA.Decls.size() > 0) { |
725 | 11.2k | Decl *D = LA.Decls[0]; |
726 | 11.2k | NamedDecl *ND = dyn_cast<NamedDecl>(D); |
727 | 11.2k | RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext()); |
728 | | |
729 | | // Allow 'this' within late-parsed attributes. |
730 | 11.2k | Sema::CXXThisScopeRAII ThisScope(Actions, RD, Qualifiers(), |
731 | 11.2k | ND && ND->isCXXInstanceMember()); |
732 | | |
733 | 11.2k | if (LA.Decls.size() == 1) { |
734 | | // If the Decl is templatized, add template parameters to scope. |
735 | 11.1k | ReenterTemplateScopeRAII InDeclScope(*this, D, EnterScope); |
736 | | |
737 | | // If the Decl is on a function, add function parameters to the scope. |
738 | 11.1k | bool HasFunScope = EnterScope && D->isFunctionOrFunctionTemplate()6.33k ; |
739 | 11.1k | if (HasFunScope) { |
740 | 5.67k | InDeclScope.Scopes.Enter(Scope::FnScope | Scope::DeclScope | |
741 | 5.67k | Scope::CompoundStmtScope); |
742 | 5.67k | Actions.ActOnReenterFunctionContext(Actions.CurScope, D); |
743 | 5.67k | } |
744 | | |
745 | 11.1k | ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, nullptr, |
746 | 11.1k | nullptr, SourceLocation(), ParsedAttr::AS_GNU, |
747 | 11.1k | nullptr); |
748 | | |
749 | 11.1k | if (HasFunScope) |
750 | 5.67k | Actions.ActOnExitFunctionContext(); |
751 | 11.1k | } else { |
752 | | // If there are multiple decls, then the decl cannot be within the |
753 | | // function scope. |
754 | 7 | ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, nullptr, |
755 | 7 | nullptr, SourceLocation(), ParsedAttr::AS_GNU, |
756 | 7 | nullptr); |
757 | 7 | } |
758 | 11.2k | } else { |
759 | 8 | Diag(Tok, diag::warn_attribute_no_decl) << LA.AttrName.getName(); |
760 | 8 | } |
761 | | |
762 | 11.2k | if (OnDefinition && !Attrs.empty()4.87k && !Attrs.begin()->isCXX11Attribute()4.86k && |
763 | 11.2k | Attrs.begin()->isKnownToGCC()4.86k ) |
764 | 0 | Diag(Tok, diag::warn_attribute_on_function_definition) |
765 | 0 | << &LA.AttrName; |
766 | | |
767 | 22.4k | for (unsigned i = 0, ni = LA.Decls.size(); i < ni; ++i11.2k ) |
768 | 11.2k | Actions.ActOnFinishDelayedAttribute(getCurScope(), LA.Decls[i], Attrs); |
769 | | |
770 | | // Due to a parsing error, we either went over the cached tokens or |
771 | | // there are still cached tokens left, so we skip the leftover tokens. |
772 | 22.4k | while (Tok.isNot(tok::eof)) |
773 | 11.2k | ConsumeAnyToken(); |
774 | | |
775 | 11.2k | if (Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData()) |
776 | 11.2k | ConsumeAnyToken(); |
777 | 11.2k | } |
778 | | |
779 | 751k | void Parser::ParseLexedPragmas(ParsingClass &Class) { |
780 | 751k | ReenterClassScopeRAII InClassScope(*this, Class); |
781 | | |
782 | 751k | for (LateParsedDeclaration *D : Class.LateParsedDeclarations) |
783 | 1.00M | D->ParseLexedPragmas(); |
784 | 751k | } |
785 | | |
786 | 86 | void Parser::ParseLexedPragma(LateParsedPragma &LP) { |
787 | 86 | PP.EnterToken(Tok, /*IsReinject=*/true); |
788 | 86 | PP.EnterTokenStream(LP.toks(), /*DisableMacroExpansion=*/true, |
789 | 86 | /*IsReinject=*/true); |
790 | | |
791 | | // Consume the previously pushed token. |
792 | 86 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
793 | 86 | assert(Tok.isAnnotation() && "Expected annotation token."); |
794 | 0 | switch (Tok.getKind()) { |
795 | 0 | case tok::annot_attr_openmp: |
796 | 86 | case tok::annot_pragma_openmp: { |
797 | 86 | AccessSpecifier AS = LP.getAccessSpecifier(); |
798 | 86 | ParsedAttributes Attrs(AttrFactory); |
799 | 86 | (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs); |
800 | 86 | break; |
801 | 0 | } |
802 | 0 | default: |
803 | 0 | llvm_unreachable("Unexpected token."); |
804 | 86 | } |
805 | 86 | } |
806 | | |
807 | | /// ConsumeAndStoreUntil - Consume and store the token at the passed token |
808 | | /// container until the token 'T' is reached (which gets |
809 | | /// consumed/stored too, if ConsumeFinalToken). |
810 | | /// If StopAtSemi is true, then we will stop early at a ';' character. |
811 | | /// Returns true if token 'T1' or 'T2' was found. |
812 | | /// NOTE: This is a specialized version of Parser::SkipUntil. |
813 | | bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, |
814 | | CachedTokens &Toks, |
815 | 3.30M | bool StopAtSemi, bool ConsumeFinalToken) { |
816 | | // We always want this function to consume at least one token if the first |
817 | | // token isn't T and if not at EOF. |
818 | 3.30M | bool isFirstTokenConsumed = true; |
819 | 14.2M | while (true) { |
820 | | // If we found one of the tokens, stop and return true. |
821 | 14.2M | if (Tok.is(T1) || Tok.is(T2)10.9M ) { |
822 | 3.30M | if (ConsumeFinalToken) { |
823 | 2.58M | Toks.push_back(Tok); |
824 | 2.58M | ConsumeAnyToken(); |
825 | 2.58M | } |
826 | 3.30M | return true; |
827 | 3.30M | } |
828 | | |
829 | 10.9M | switch (Tok.getKind()) { |
830 | 154 | case tok::eof: |
831 | 154 | case tok::annot_module_begin: |
832 | 154 | case tok::annot_module_end: |
833 | 154 | case tok::annot_module_include: |
834 | | // Ran out of tokens. |
835 | 154 | return false; |
836 | | |
837 | 1.35M | case tok::l_paren: |
838 | | // Recursively consume properly-nested parens. |
839 | 1.35M | Toks.push_back(Tok); |
840 | 1.35M | ConsumeParen(); |
841 | 1.35M | ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false); |
842 | 1.35M | break; |
843 | 27.5k | case tok::l_square: |
844 | | // Recursively consume properly-nested square brackets. |
845 | 27.5k | Toks.push_back(Tok); |
846 | 27.5k | ConsumeBracket(); |
847 | 27.5k | ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false); |
848 | 27.5k | break; |
849 | 43.5k | case tok::l_brace: |
850 | | // Recursively consume properly-nested braces. |
851 | 43.5k | Toks.push_back(Tok); |
852 | 43.5k | ConsumeBrace(); |
853 | 43.5k | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
854 | 43.5k | break; |
855 | | |
856 | | // Okay, we found a ']' or '}' or ')', which we think should be balanced. |
857 | | // Since the user wasn't looking for this token (if they were, it would |
858 | | // already be handled), this isn't balanced. If there is a LHS token at a |
859 | | // higher level, we will assume that this matches the unbalanced token |
860 | | // and return it. Otherwise, this is a spurious RHS token, which we skip. |
861 | 7 | case tok::r_paren: |
862 | 7 | if (ParenCount && !isFirstTokenConsumed) |
863 | 6 | return false; // Matches something. |
864 | 1 | Toks.push_back(Tok); |
865 | 1 | ConsumeParen(); |
866 | 1 | break; |
867 | 33 | case tok::r_square: |
868 | 33 | if (BracketCount && !isFirstTokenConsumed0 ) |
869 | 0 | return false; // Matches something. |
870 | 33 | Toks.push_back(Tok); |
871 | 33 | ConsumeBracket(); |
872 | 33 | break; |
873 | 97 | case tok::r_brace: |
874 | 97 | if (BraceCount && !isFirstTokenConsumed) |
875 | 97 | return false; // Matches something. |
876 | 0 | Toks.push_back(Tok); |
877 | 0 | ConsumeBrace(); |
878 | 0 | break; |
879 | | |
880 | 1.08M | case tok::semi: |
881 | 1.08M | if (StopAtSemi) |
882 | 12 | return false; |
883 | 1.08M | LLVM_FALLTHROUGH1.08M ;1.08M |
884 | 9.53M | default: |
885 | | // consume this token. |
886 | 9.53M | Toks.push_back(Tok); |
887 | 9.53M | ConsumeAnyToken(/*ConsumeCodeCompletionTok*/true); |
888 | 9.53M | break; |
889 | 10.9M | } |
890 | 10.9M | isFirstTokenConsumed = false; |
891 | 10.9M | } |
892 | 3.30M | } |
893 | | |
894 | | /// Consume tokens and store them in the passed token container until |
895 | | /// we've passed the try keyword and constructor initializers and have consumed |
896 | | /// the opening brace of the function body. The opening brace will be consumed |
897 | | /// if and only if there was no error. |
898 | | /// |
899 | | /// \return True on error. |
900 | 869k | bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { |
901 | 869k | if (Tok.is(tok::kw_try)) { |
902 | 79 | Toks.push_back(Tok); |
903 | 79 | ConsumeToken(); |
904 | 79 | } |
905 | | |
906 | 869k | if (Tok.isNot(tok::colon)) { |
907 | | // Easy case, just a function body. |
908 | | |
909 | | // Grab any remaining garbage to be diagnosed later. We stop when we reach a |
910 | | // brace: an opening one is the function body, while a closing one probably |
911 | | // means we've reached the end of the class. |
912 | 712k | ConsumeAndStoreUntil(tok::l_brace, tok::r_brace, Toks, |
913 | 712k | /*StopAtSemi=*/true, |
914 | 712k | /*ConsumeFinalToken=*/false); |
915 | 712k | if (Tok.isNot(tok::l_brace)) |
916 | 1 | return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; |
917 | | |
918 | 712k | Toks.push_back(Tok); |
919 | 712k | ConsumeBrace(); |
920 | 712k | return false; |
921 | 712k | } |
922 | | |
923 | 156k | Toks.push_back(Tok); |
924 | 156k | ConsumeToken(); |
925 | | |
926 | | // We can't reliably skip over a mem-initializer-id, because it could be |
927 | | // a template-id involving not-yet-declared names. Given: |
928 | | // |
929 | | // S ( ) : a < b < c > ( e ) |
930 | | // |
931 | | // 'e' might be an initializer or part of a template argument, depending |
932 | | // on whether 'b' is a template. |
933 | | |
934 | | // Track whether we might be inside a template argument. We can give |
935 | | // significantly better diagnostics if we know that we're not. |
936 | 156k | bool MightBeTemplateArgument = false; |
937 | | |
938 | 205k | while (true) { |
939 | | // Skip over the mem-initializer-id, if possible. |
940 | 205k | if (Tok.is(tok::kw_decltype)) { |
941 | 12 | Toks.push_back(Tok); |
942 | 12 | SourceLocation OpenLoc = ConsumeToken(); |
943 | 12 | if (Tok.isNot(tok::l_paren)) |
944 | 1 | return Diag(Tok.getLocation(), diag::err_expected_lparen_after) |
945 | 1 | << "decltype"; |
946 | 11 | Toks.push_back(Tok); |
947 | 11 | ConsumeParen(); |
948 | 11 | if (!ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/true)) { |
949 | 1 | Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren; |
950 | 1 | Diag(OpenLoc, diag::note_matching) << tok::l_paren; |
951 | 1 | return true; |
952 | 1 | } |
953 | 11 | } |
954 | 207k | do 205k { |
955 | | // Walk over a component of a nested-name-specifier. |
956 | 207k | if (Tok.is(tok::coloncolon)) { |
957 | 1.69k | Toks.push_back(Tok); |
958 | 1.69k | ConsumeToken(); |
959 | | |
960 | 1.69k | if (Tok.is(tok::kw_template)) { |
961 | 2 | Toks.push_back(Tok); |
962 | 2 | ConsumeToken(); |
963 | 2 | } |
964 | 1.69k | } |
965 | | |
966 | 207k | if (Tok.is(tok::identifier)) { |
967 | 207k | Toks.push_back(Tok); |
968 | 207k | ConsumeToken(); |
969 | 207k | } else { |
970 | 221 | break; |
971 | 221 | } |
972 | 207k | } while (Tok.is(tok::coloncolon)207k ); |
973 | | |
974 | 205k | if (Tok.is(tok::code_completion)) { |
975 | 49 | Toks.push_back(Tok); |
976 | 49 | ConsumeCodeCompletionToken(); |
977 | 49 | if (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype)) { |
978 | | // Could be the start of another member initializer (the ',' has not |
979 | | // been written yet) |
980 | 23 | continue; |
981 | 23 | } |
982 | 49 | } |
983 | | |
984 | 205k | if (Tok.is(tok::comma)) { |
985 | | // The initialization is missing, we'll diagnose it later. |
986 | 21 | Toks.push_back(Tok); |
987 | 21 | ConsumeToken(); |
988 | 21 | continue; |
989 | 21 | } |
990 | 205k | if (Tok.is(tok::less)) |
991 | 4.88k | MightBeTemplateArgument = true; |
992 | | |
993 | 205k | if (MightBeTemplateArgument) { |
994 | | // We may be inside a template argument list. Grab up to the start of the |
995 | | // next parenthesized initializer or braced-init-list. This *might* be the |
996 | | // initializer, or it might be a subexpression in the template argument |
997 | | // list. |
998 | | // FIXME: Count angle brackets, and clear MightBeTemplateArgument |
999 | | // if all angles are closed. |
1000 | 5.34k | if (!ConsumeAndStoreUntil(tok::l_paren, tok::l_brace, Toks, |
1001 | 5.34k | /*StopAtSemi=*/true, |
1002 | 5.34k | /*ConsumeFinalToken=*/false)) { |
1003 | | // We're not just missing the initializer, we're also missing the |
1004 | | // function body! |
1005 | 0 | return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; |
1006 | 0 | } |
1007 | 200k | } else if (Tok.isNot(tok::l_paren) && Tok.isNot(tok::l_brace)595 ) { |
1008 | | // We found something weird in a mem-initializer-id. |
1009 | 4 | if (getLangOpts().CPlusPlus11) |
1010 | 4 | return Diag(Tok.getLocation(), diag::err_expected_either) |
1011 | 4 | << tok::l_paren << tok::l_brace; |
1012 | 0 | else |
1013 | 0 | return Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren; |
1014 | 4 | } |
1015 | | |
1016 | 205k | tok::TokenKind kind = Tok.getKind(); |
1017 | 205k | Toks.push_back(Tok); |
1018 | 205k | bool IsLParen = (kind == tok::l_paren); |
1019 | 205k | SourceLocation OpenLoc = Tok.getLocation(); |
1020 | | |
1021 | 205k | if (IsLParen) { |
1022 | 205k | ConsumeParen(); |
1023 | 205k | } else { |
1024 | 612 | assert(kind == tok::l_brace && "Must be left paren or brace here."); |
1025 | 0 | ConsumeBrace(); |
1026 | | // In C++03, this has to be the start of the function body, which |
1027 | | // means the initializer is malformed; we'll diagnose it later. |
1028 | 612 | if (!getLangOpts().CPlusPlus11) |
1029 | 63 | return false; |
1030 | | |
1031 | 549 | const Token &PreviousToken = Toks[Toks.size() - 2]; |
1032 | 549 | if (!MightBeTemplateArgument && |
1033 | 549 | !PreviousToken.isOneOf(tok::identifier, tok::greater, |
1034 | 528 | tok::greatergreater)) { |
1035 | | // If the opening brace is not preceded by one of these tokens, we are |
1036 | | // missing the mem-initializer-id. In order to recover better, we need |
1037 | | // to use heuristics to determine if this '{' is most likely the |
1038 | | // beginning of a brace-init-list or the function body. |
1039 | | // Check the token after the corresponding '}'. |
1040 | 89 | TentativeParsingAction PA(*this); |
1041 | 89 | if (SkipUntil(tok::r_brace) && |
1042 | 89 | !Tok.isOneOf(tok::comma, tok::ellipsis, tok::l_brace)) { |
1043 | | // Consider there was a malformed initializer and this is the start |
1044 | | // of the function body. We'll diagnose it later. |
1045 | 89 | PA.Revert(); |
1046 | 89 | return false; |
1047 | 89 | } |
1048 | 0 | PA.Revert(); |
1049 | 0 | } |
1050 | 549 | } |
1051 | | |
1052 | | // Grab the initializer (or the subexpression of the template argument). |
1053 | | // FIXME: If we support lambdas here, we'll need to set StopAtSemi to false |
1054 | | // if we might be inside the braces of a lambda-expression. |
1055 | 205k | tok::TokenKind CloseKind = IsLParen ? tok::r_paren205k : tok::r_brace460 ; |
1056 | 205k | if (!ConsumeAndStoreUntil(CloseKind, Toks, /*StopAtSemi=*/true)) { |
1057 | 7 | Diag(Tok, diag::err_expected) << CloseKind; |
1058 | 7 | Diag(OpenLoc, diag::note_matching) << kind; |
1059 | 7 | return true; |
1060 | 7 | } |
1061 | | |
1062 | | // Grab pack ellipsis, if present. |
1063 | 205k | if (Tok.is(tok::ellipsis)) { |
1064 | 2.76k | Toks.push_back(Tok); |
1065 | 2.76k | ConsumeToken(); |
1066 | 2.76k | } |
1067 | | |
1068 | | // If we know we just consumed a mem-initializer, we must have ',' or '{' |
1069 | | // next. |
1070 | 205k | if (Tok.is(tok::comma)) { |
1071 | 49.1k | Toks.push_back(Tok); |
1072 | 49.1k | ConsumeToken(); |
1073 | 156k | } else if (Tok.is(tok::l_brace)) { |
1074 | | // This is the function body if the ')' or '}' is immediately followed by |
1075 | | // a '{'. That cannot happen within a template argument, apart from the |
1076 | | // case where a template argument contains a compound literal: |
1077 | | // |
1078 | | // S ( ) : a < b < c > ( d ) { } |
1079 | | // // End of declaration, or still inside the template argument? |
1080 | | // |
1081 | | // ... and the case where the template argument contains a lambda: |
1082 | | // |
1083 | | // S ( ) : a < 0 && b < c > ( d ) + [ ] ( ) { return 0; } |
1084 | | // ( ) > ( ) { } |
1085 | | // |
1086 | | // FIXME: Disambiguate these cases. Note that the latter case is probably |
1087 | | // going to be made ill-formed by core issue 1607. |
1088 | 156k | Toks.push_back(Tok); |
1089 | 156k | ConsumeBrace(); |
1090 | 156k | return false; |
1091 | 156k | } else if (21 !MightBeTemplateArgument21 ) { |
1092 | 8 | return Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace |
1093 | 8 | << tok::comma; |
1094 | 8 | } |
1095 | 205k | } |
1096 | 156k | } |
1097 | | |
1098 | | /// Consume and store tokens from the '?' to the ':' in a conditional |
1099 | | /// expression. |
1100 | 4 | bool Parser::ConsumeAndStoreConditional(CachedTokens &Toks) { |
1101 | | // Consume '?'. |
1102 | 4 | assert(Tok.is(tok::question)); |
1103 | 0 | Toks.push_back(Tok); |
1104 | 4 | ConsumeToken(); |
1105 | | |
1106 | 8 | while (Tok.isNot(tok::colon)) { |
1107 | 4 | if (!ConsumeAndStoreUntil(tok::question, tok::colon, Toks, |
1108 | 4 | /*StopAtSemi=*/true, |
1109 | 4 | /*ConsumeFinalToken=*/false)) |
1110 | 0 | return false; |
1111 | | |
1112 | | // If we found a nested conditional, consume it. |
1113 | 4 | if (Tok.is(tok::question) && !ConsumeAndStoreConditional(Toks)0 ) |
1114 | 0 | return false; |
1115 | 4 | } |
1116 | | |
1117 | | // Consume ':'. |
1118 | 4 | Toks.push_back(Tok); |
1119 | 4 | ConsumeToken(); |
1120 | 4 | return true; |
1121 | 4 | } |
1122 | | |
1123 | | /// A tentative parsing action that can also revert token annotations. |
1124 | | class Parser::UnannotatedTentativeParsingAction : public TentativeParsingAction { |
1125 | | public: |
1126 | | explicit UnannotatedTentativeParsingAction(Parser &Self, |
1127 | | tok::TokenKind EndKind) |
1128 | 505 | : TentativeParsingAction(Self), Self(Self), EndKind(EndKind) { |
1129 | | // Stash away the old token stream, so we can restore it once the |
1130 | | // tentative parse is complete. |
1131 | 505 | TentativeParsingAction Inner(Self); |
1132 | 505 | Self.ConsumeAndStoreUntil(EndKind, Toks, true, /*ConsumeFinalToken*/false); |
1133 | 505 | Inner.Revert(); |
1134 | 505 | } |
1135 | | |
1136 | 505 | void RevertAnnotations() { |
1137 | 505 | Revert(); |
1138 | | |
1139 | | // Put back the original tokens. |
1140 | 505 | Self.SkipUntil(EndKind, StopAtSemi | StopBeforeMatch); |
1141 | 505 | if (Toks.size()) { |
1142 | 505 | auto Buffer = std::make_unique<Token[]>(Toks.size()); |
1143 | 505 | std::copy(Toks.begin() + 1, Toks.end(), Buffer.get()); |
1144 | 505 | Buffer[Toks.size() - 1] = Self.Tok; |
1145 | 505 | Self.PP.EnterTokenStream(std::move(Buffer), Toks.size(), true, |
1146 | 505 | /*IsReinject*/ true); |
1147 | | |
1148 | 505 | Self.Tok = Toks.front(); |
1149 | 505 | } |
1150 | 505 | } |
1151 | | |
1152 | | private: |
1153 | | Parser &Self; |
1154 | | CachedTokens Toks; |
1155 | | tok::TokenKind EndKind; |
1156 | | }; |
1157 | | |
1158 | | /// ConsumeAndStoreInitializer - Consume and store the token at the passed token |
1159 | | /// container until the end of the current initializer expression (either a |
1160 | | /// default argument or an in-class initializer for a non-static data member). |
1161 | | /// |
1162 | | /// Returns \c true if we reached the end of something initializer-shaped, |
1163 | | /// \c false if we bailed out. |
1164 | | bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, |
1165 | 80.9k | CachedInitKind CIK) { |
1166 | | // We always want this function to consume at least one token if not at EOF. |
1167 | 80.9k | bool IsFirstToken = true; |
1168 | | |
1169 | | // Number of possible unclosed <s we've seen so far. These might be templates, |
1170 | | // and might not, but if there were none of them (or we know for sure that |
1171 | | // we're within a template), we can avoid a tentative parse. |
1172 | 80.9k | unsigned AngleCount = 0; |
1173 | 80.9k | unsigned KnownTemplateCount = 0; |
1174 | | |
1175 | 267k | while (true) { |
1176 | 267k | switch (Tok.getKind()) { |
1177 | 8.67k | case tok::comma: |
1178 | | // If we might be in a template, perform a tentative parse to check. |
1179 | 8.67k | if (!AngleCount) |
1180 | | // Not a template argument: this is the end of the initializer. |
1181 | 8.15k | return true; |
1182 | 518 | if (KnownTemplateCount) |
1183 | 13 | goto consume_token; |
1184 | | |
1185 | | // We hit a comma inside angle brackets. This is the hard case. The |
1186 | | // rule we follow is: |
1187 | | // * For a default argument, if the tokens after the comma form a |
1188 | | // syntactically-valid parameter-declaration-clause, in which each |
1189 | | // parameter has an initializer, then this comma ends the default |
1190 | | // argument. |
1191 | | // * For a default initializer, if the tokens after the comma form a |
1192 | | // syntactically-valid init-declarator-list, then this comma ends |
1193 | | // the default initializer. |
1194 | 505 | { |
1195 | 505 | UnannotatedTentativeParsingAction PA(*this, |
1196 | 505 | CIK == CIK_DefaultInitializer |
1197 | 505 | ? tok::semi457 : tok::r_paren48 ); |
1198 | 505 | Sema::TentativeAnalysisScope Scope(Actions); |
1199 | | |
1200 | 505 | TPResult Result = TPResult::Error; |
1201 | 505 | ConsumeToken(); |
1202 | 505 | switch (CIK) { |
1203 | 457 | case CIK_DefaultInitializer: |
1204 | 457 | Result = TryParseInitDeclaratorList(); |
1205 | | // If we parsed a complete, ambiguous init-declarator-list, this |
1206 | | // is only syntactically-valid if it's followed by a semicolon. |
1207 | 457 | if (Result == TPResult::Ambiguous && Tok.isNot(tok::semi)442 ) |
1208 | 434 | Result = TPResult::False; |
1209 | 457 | break; |
1210 | | |
1211 | 48 | case CIK_DefaultArgument: |
1212 | 48 | bool InvalidAsDeclaration = false; |
1213 | 48 | Result = TryParseParameterDeclarationClause( |
1214 | 48 | &InvalidAsDeclaration, /*VersusTemplateArg=*/true); |
1215 | | // If this is an expression or a declaration with a missing |
1216 | | // 'typename', assume it's not a declaration. |
1217 | 48 | if (Result == TPResult::Ambiguous && InvalidAsDeclaration0 ) |
1218 | 0 | Result = TPResult::False; |
1219 | 48 | break; |
1220 | 505 | } |
1221 | | |
1222 | | // Put the token stream back and undo any annotations we performed |
1223 | | // after the comma. They may reflect a different parse than the one |
1224 | | // we will actually perform at the end of the class. |
1225 | 505 | PA.RevertAnnotations(); |
1226 | | |
1227 | | // If what follows could be a declaration, it is a declaration. |
1228 | 505 | if (Result != TPResult::False && Result != TPResult::Error28 ) |
1229 | 26 | return true; |
1230 | 505 | } |
1231 | | |
1232 | | // Keep going. We know we're inside a template argument list now. |
1233 | 479 | ++KnownTemplateCount; |
1234 | 479 | goto consume_token; |
1235 | | |
1236 | 1 | case tok::eof: |
1237 | 1 | case tok::annot_module_begin: |
1238 | 1 | case tok::annot_module_end: |
1239 | 1 | case tok::annot_module_include: |
1240 | | // Ran out of tokens. |
1241 | 1 | return false; |
1242 | | |
1243 | 1.53k | case tok::less: |
1244 | | // FIXME: A '<' can only start a template-id if it's preceded by an |
1245 | | // identifier, an operator-function-id, or a literal-operator-id. |
1246 | 1.53k | ++AngleCount; |
1247 | 1.53k | goto consume_token; |
1248 | | |
1249 | 4 | case tok::question: |
1250 | | // In 'a ? b : c', 'b' can contain an unparenthesized comma. If it does, |
1251 | | // that is *never* the end of the initializer. Skip to the ':'. |
1252 | 4 | if (!ConsumeAndStoreConditional(Toks)) |
1253 | 0 | return false; |
1254 | 4 | break; |
1255 | | |
1256 | 4 | case tok::greatergreatergreater: |
1257 | 0 | if (!getLangOpts().CPlusPlus11) |
1258 | 0 | goto consume_token; |
1259 | 0 | if (AngleCount) --AngleCount; |
1260 | 0 | if (KnownTemplateCount) --KnownTemplateCount; |
1261 | 0 | LLVM_FALLTHROUGH; |
1262 | 7 | case tok::greatergreater: |
1263 | 7 | if (!getLangOpts().CPlusPlus11) |
1264 | 0 | goto consume_token; |
1265 | 7 | if (AngleCount) --AngleCount6 ; |
1266 | 7 | if (KnownTemplateCount) --KnownTemplateCount6 ; |
1267 | 7 | LLVM_FALLTHROUGH; |
1268 | 1.52k | case tok::greater: |
1269 | 1.52k | if (AngleCount) --AngleCount1.51k ; |
1270 | 1.52k | if (KnownTemplateCount) --KnownTemplateCount486 ; |
1271 | 1.52k | goto consume_token; |
1272 | | |
1273 | 14 | case tok::kw_template: |
1274 | | // 'template' identifier '<' is known to start a template argument list, |
1275 | | // and can be used to disambiguate the parse. |
1276 | | // FIXME: Support all forms of 'template' unqualified-id '<'. |
1277 | 14 | Toks.push_back(Tok); |
1278 | 14 | ConsumeToken(); |
1279 | 14 | if (Tok.is(tok::identifier)) { |
1280 | 14 | Toks.push_back(Tok); |
1281 | 14 | ConsumeToken(); |
1282 | 14 | if (Tok.is(tok::less)) { |
1283 | 14 | ++AngleCount; |
1284 | 14 | ++KnownTemplateCount; |
1285 | 14 | Toks.push_back(Tok); |
1286 | 14 | ConsumeToken(); |
1287 | 14 | } |
1288 | 14 | } |
1289 | 14 | break; |
1290 | | |
1291 | 20 | case tok::kw_operator: |
1292 | | // If 'operator' precedes other punctuation, that punctuation loses |
1293 | | // its special behavior. |
1294 | 20 | Toks.push_back(Tok); |
1295 | 20 | ConsumeToken(); |
1296 | 20 | switch (Tok.getKind()) { |
1297 | 6 | case tok::comma: |
1298 | 6 | case tok::greatergreatergreater: |
1299 | 8 | case tok::greatergreater: |
1300 | 14 | case tok::greater: |
1301 | 19 | case tok::less: |
1302 | 19 | Toks.push_back(Tok); |
1303 | 19 | ConsumeToken(); |
1304 | 19 | break; |
1305 | 1 | default: |
1306 | 1 | break; |
1307 | 20 | } |
1308 | 20 | break; |
1309 | | |
1310 | 12.8k | case tok::l_paren: |
1311 | | // Recursively consume properly-nested parens. |
1312 | 12.8k | Toks.push_back(Tok); |
1313 | 12.8k | ConsumeParen(); |
1314 | 12.8k | ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false); |
1315 | 12.8k | break; |
1316 | 268 | case tok::l_square: |
1317 | | // Recursively consume properly-nested square brackets. |
1318 | 268 | Toks.push_back(Tok); |
1319 | 268 | ConsumeBracket(); |
1320 | 268 | ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false); |
1321 | 268 | break; |
1322 | 1.99k | case tok::l_brace: |
1323 | | // Recursively consume properly-nested braces. |
1324 | 1.99k | Toks.push_back(Tok); |
1325 | 1.99k | ConsumeBrace(); |
1326 | 1.99k | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
1327 | 1.99k | break; |
1328 | | |
1329 | | // Okay, we found a ']' or '}' or ')', which we think should be balanced. |
1330 | | // Since the user wasn't looking for this token (if they were, it would |
1331 | | // already be handled), this isn't balanced. If there is a LHS token at a |
1332 | | // higher level, we will assume that this matches the unbalanced token |
1333 | | // and return it. Otherwise, this is a spurious RHS token, which we |
1334 | | // consume and pass on to downstream code to diagnose. |
1335 | 68.1k | case tok::r_paren: |
1336 | 68.1k | if (CIK == CIK_DefaultArgument) |
1337 | 68.1k | return true; // End of the default argument. |
1338 | 6 | if (ParenCount && !IsFirstToken0 ) |
1339 | 0 | return false; |
1340 | 6 | Toks.push_back(Tok); |
1341 | 6 | ConsumeParen(); |
1342 | 6 | continue; |
1343 | 6 | case tok::r_square: |
1344 | 6 | if (BracketCount && !IsFirstToken0 ) |
1345 | 0 | return false; |
1346 | 6 | Toks.push_back(Tok); |
1347 | 6 | ConsumeBracket(); |
1348 | 6 | continue; |
1349 | 7 | case tok::r_brace: |
1350 | 7 | if (BraceCount && !IsFirstToken) |
1351 | 4 | return false; |
1352 | 3 | Toks.push_back(Tok); |
1353 | 3 | ConsumeBrace(); |
1354 | 3 | continue; |
1355 | | |
1356 | 0 | case tok::code_completion: |
1357 | 0 | Toks.push_back(Tok); |
1358 | 0 | ConsumeCodeCompletionToken(); |
1359 | 0 | break; |
1360 | | |
1361 | 44 | case tok::string_literal: |
1362 | 44 | case tok::wide_string_literal: |
1363 | 44 | case tok::utf8_string_literal: |
1364 | 44 | case tok::utf16_string_literal: |
1365 | 44 | case tok::utf32_string_literal: |
1366 | 44 | Toks.push_back(Tok); |
1367 | 44 | ConsumeStringToken(); |
1368 | 44 | break; |
1369 | 4.61k | case tok::semi: |
1370 | 4.61k | if (CIK == CIK_DefaultInitializer) |
1371 | 4.61k | return true; // End of the default initializer. |
1372 | 4.61k | LLVM_FALLTHROUGH0 ;0 |
1373 | 168k | default: |
1374 | 171k | consume_token: |
1375 | 171k | Toks.push_back(Tok); |
1376 | 171k | ConsumeToken(); |
1377 | 171k | break; |
1378 | 267k | } |
1379 | 186k | IsFirstToken = false; |
1380 | 186k | } |
1381 | 80.9k | } |