1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
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 | |
22 | |
23 | |
24 | NamedDecl *Parser::ParseCXXInlineMethodDef( |
25 | AccessSpecifier AS, ParsedAttributes &AccessAttrs, ParsingDeclarator &D, |
26 | const ParsedTemplateInfo &TemplateInfo, const VirtSpecifiers &VS, |
27 | SourceLocation PureSpecLoc) { |
28 | (0) . __assert_fail ("D.isFunctionDeclarator() && \"This isn't a function declarator!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 28, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D.isFunctionDeclarator() && "This isn't a function declarator!"); |
29 | (0) . __assert_fail ("Tok.isOneOf(tok..l_brace, tok..colon, tok..kw_try, tok..equal) && \"Current token not a '{', '.', '=', or 'try'!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 30, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try, tok::equal) && |
30 | (0) . __assert_fail ("Tok.isOneOf(tok..l_brace, tok..colon, tok..kw_try, tok..equal) && \"Current token not a '{', '.', '=', or 'try'!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 30, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Current token not a '{', ':', '=', or 'try'!"); |
31 | |
32 | MultiTemplateParamsArg TemplateParams( |
33 | TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data() |
34 | : nullptr, |
35 | TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0); |
36 | |
37 | NamedDecl *FnD; |
38 | if (D.getDeclSpec().isFriendSpecified()) |
39 | FnD = Actions.ActOnFriendFunctionDecl(getCurScope(), D, |
40 | TemplateParams); |
41 | else { |
42 | FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D, |
43 | TemplateParams, nullptr, |
44 | VS, ICIS_NoInit); |
45 | if (FnD) { |
46 | Actions.ProcessDeclAttributeList(getCurScope(), FnD, AccessAttrs); |
47 | if (PureSpecLoc.isValid()) |
48 | Actions.ActOnPureSpecifier(FnD, PureSpecLoc); |
49 | } |
50 | } |
51 | |
52 | if (FnD) |
53 | HandleMemberFunctionDeclDelays(D, FnD); |
54 | |
55 | D.complete(FnD); |
56 | |
57 | if (TryConsumeToken(tok::equal)) { |
58 | if (!FnD) { |
59 | SkipUntil(tok::semi); |
60 | return nullptr; |
61 | } |
62 | |
63 | bool Delete = false; |
64 | SourceLocation KWLoc; |
65 | SourceLocation KWEndLoc = Tok.getEndLoc().getLocWithOffset(-1); |
66 | if (TryConsumeToken(tok::kw_delete, KWLoc)) { |
67 | Diag(KWLoc, getLangOpts().CPlusPlus11 |
68 | ? diag::warn_cxx98_compat_defaulted_deleted_function |
69 | : diag::ext_defaulted_deleted_function) |
70 | << 1 ; |
71 | Actions.SetDeclDeleted(FnD, KWLoc); |
72 | Delete = true; |
73 | if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) { |
74 | DeclAsFunction->setRangeEnd(KWEndLoc); |
75 | } |
76 | } else if (TryConsumeToken(tok::kw_default, KWLoc)) { |
77 | Diag(KWLoc, getLangOpts().CPlusPlus11 |
78 | ? diag::warn_cxx98_compat_defaulted_deleted_function |
79 | : diag::ext_defaulted_deleted_function) |
80 | << 0 ; |
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 | if (SkipFunctionBodies && (!FnD || Actions.canSkipFunctionBody(FnD)) && |
102 | trySkippingFunctionBody()) { |
103 | Actions.ActOnSkippedFunctionBody(FnD); |
104 | return FnD; |
105 | } |
106 | |
107 | |
108 | |
109 | |
110 | if (getLangOpts().DelayedTemplateParsing && |
111 | D.getFunctionDefinitionKind() == FDK_Definition && |
112 | !D.getDeclSpec().isConstexprSpecified() && |
113 | !(FnD && FnD->getAsFunction() && |
114 | FnD->getAsFunction()->getReturnType()->getContainedAutoType()) && |
115 | ((Actions.CurContext->isDependentContext() || |
116 | (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate && |
117 | TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization)) && |
118 | !Actions.IsInsideALocalClassWithinATemplateFunction())) { |
119 | |
120 | CachedTokens Toks; |
121 | LexTemplateFunctionForLateParsing(Toks); |
122 | |
123 | if (FnD) { |
124 | FunctionDecl *FD = FnD->getAsFunction(); |
125 | Actions.CheckForFunctionRedefinition(FD); |
126 | Actions.MarkAsLateParsedTemplate(FD, FnD, Toks); |
127 | } |
128 | |
129 | return FnD; |
130 | } |
131 | |
132 | |
133 | |
134 | LexedMethod* LM = new LexedMethod(this, FnD); |
135 | getCurrentClass().LateParsedDeclarations.push_back(LM); |
136 | LM->TemplateScope = getCurScope()->isTemplateParamScope(); |
137 | CachedTokens &Toks = LM->Toks; |
138 | |
139 | tok::TokenKind kind = Tok.getKind(); |
140 | |
141 | |
142 | if (ConsumeAndStoreFunctionPrologue(Toks)) { |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | SkipMalformedDecl(); |
149 | delete getCurrentClass().LateParsedDeclarations.back(); |
150 | getCurrentClass().LateParsedDeclarations.pop_back(); |
151 | return FnD; |
152 | } else { |
153 | |
154 | ConsumeAndStoreUntil(tok::r_brace, Toks, ); |
155 | } |
156 | |
157 | |
158 | if (kind == tok::kw_try) { |
159 | while (Tok.is(tok::kw_catch)) { |
160 | ConsumeAndStoreUntil(tok::l_brace, Toks, ); |
161 | ConsumeAndStoreUntil(tok::r_brace, Toks, ); |
162 | } |
163 | } |
164 | |
165 | if (FnD) { |
166 | FunctionDecl *FD = FnD->getAsFunction(); |
167 | |
168 | |
169 | Actions.CheckForFunctionRedefinition(FD); |
170 | FD->setWillHaveBody(true); |
171 | } else { |
172 | |
173 | |
174 | delete getCurrentClass().LateParsedDeclarations.back(); |
175 | getCurrentClass().LateParsedDeclarations.pop_back(); |
176 | } |
177 | |
178 | return FnD; |
179 | } |
180 | |
181 | |
182 | |
183 | |
184 | |
185 | void Parser::ParseCXXNonStaticMemberInitializer(Decl *VarD) { |
186 | (0) . __assert_fail ("Tok.isOneOf(tok..l_brace, tok..equal) && \"Current token not a '{' or '='!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 187, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::l_brace, tok::equal) && |
187 | (0) . __assert_fail ("Tok.isOneOf(tok..l_brace, tok..equal) && \"Current token not a '{' or '='!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 187, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Current token not a '{' or '='!"); |
188 | |
189 | LateParsedMemberInitializer *MI = |
190 | new LateParsedMemberInitializer(this, VarD); |
191 | getCurrentClass().LateParsedDeclarations.push_back(MI); |
192 | CachedTokens &Toks = MI->Toks; |
193 | |
194 | tok::TokenKind kind = Tok.getKind(); |
195 | if (kind == tok::equal) { |
196 | Toks.push_back(Tok); |
197 | ConsumeToken(); |
198 | } |
199 | |
200 | if (kind == tok::l_brace) { |
201 | |
202 | Toks.push_back(Tok); |
203 | ConsumeBrace(); |
204 | |
205 | |
206 | ConsumeAndStoreUntil(tok::r_brace, Toks, ); |
207 | } else { |
208 | |
209 | ConsumeAndStoreInitializer(Toks, CIK_DefaultInitializer); |
210 | } |
211 | |
212 | |
213 | |
214 | Token Eof; |
215 | Eof.startToken(); |
216 | Eof.setKind(tok::eof); |
217 | Eof.setLocation(Tok.getLocation()); |
218 | Eof.setEofData(VarD); |
219 | Toks.push_back(Eof); |
220 | } |
221 | |
222 | Parser::LateParsedDeclaration::~LateParsedDeclaration() {} |
223 | void Parser::LateParsedDeclaration::ParseLexedMethodDeclarations() {} |
224 | void Parser::LateParsedDeclaration::ParseLexedMemberInitializers() {} |
225 | void Parser::LateParsedDeclaration::ParseLexedMethodDefs() {} |
226 | |
227 | Parser::LateParsedClass::LateParsedClass(Parser *P, ParsingClass *C) |
228 | : Self(P), Class(C) {} |
229 | |
230 | Parser::LateParsedClass::~LateParsedClass() { |
231 | Self->DeallocateParsedClasses(Class); |
232 | } |
233 | |
234 | void Parser::LateParsedClass::ParseLexedMethodDeclarations() { |
235 | Self->ParseLexedMethodDeclarations(*Class); |
236 | } |
237 | |
238 | void Parser::LateParsedClass::ParseLexedMemberInitializers() { |
239 | Self->ParseLexedMemberInitializers(*Class); |
240 | } |
241 | |
242 | void Parser::LateParsedClass::ParseLexedMethodDefs() { |
243 | Self->ParseLexedMethodDefs(*Class); |
244 | } |
245 | |
246 | void Parser::LateParsedMethodDeclaration::ParseLexedMethodDeclarations() { |
247 | Self->ParseLexedMethodDeclaration(*this); |
248 | } |
249 | |
250 | void Parser::LexedMethod::ParseLexedMethodDefs() { |
251 | Self->ParseLexedMethodDef(*this); |
252 | } |
253 | |
254 | void Parser::LateParsedMemberInitializer::ParseLexedMemberInitializers() { |
255 | Self->ParseLexedMemberInitializer(*this); |
256 | } |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) { |
263 | bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; |
264 | ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, |
265 | HasTemplateScope); |
266 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
267 | if (HasTemplateScope) { |
268 | Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); |
269 | ++CurTemplateDepthTracker; |
270 | } |
271 | |
272 | |
273 | |
274 | bool HasClassScope = !Class.TopLevelClass; |
275 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope, |
276 | HasClassScope); |
277 | if (HasClassScope) |
278 | Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), |
279 | Class.TagOrTemplate); |
280 | |
281 | for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { |
282 | Class.LateParsedDeclarations[i]->ParseLexedMethodDeclarations(); |
283 | } |
284 | |
285 | if (HasClassScope) |
286 | Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), |
287 | Class.TagOrTemplate); |
288 | } |
289 | |
290 | void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { |
291 | |
292 | ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope); |
293 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
294 | if (LM.TemplateScope) { |
295 | Actions.ActOnReenterTemplateScope(getCurScope(), LM.Method); |
296 | ++CurTemplateDepthTracker; |
297 | } |
298 | |
299 | Actions.ActOnStartDelayedCXXMethodDeclaration(getCurScope(), LM.Method); |
300 | |
301 | |
302 | |
303 | ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope | |
304 | Scope::FunctionDeclarationScope | Scope::DeclScope); |
305 | for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) { |
306 | auto Param = cast<ParmVarDecl>(LM.DefaultArgs[I].Param); |
307 | |
308 | bool HasUnparsed = Param->hasUnparsedDefaultArg(); |
309 | Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param); |
310 | std::unique_ptr<CachedTokens> Toks = std::move(LM.DefaultArgs[I].Toks); |
311 | if (Toks) { |
312 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
313 | |
314 | |
315 | |
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 | |
325 | Toks->push_back(Tok); |
326 | PP.EnterTokenStream(*Toks, true); |
327 | |
328 | |
329 | ConsumeAnyToken(); |
330 | |
331 | |
332 | (0) . __assert_fail ("Tok.is(tok..equal) && \"Default argument not starting with '='\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 332, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::equal) && "Default argument not starting with '='"); |
333 | SourceLocation EqualLoc = ConsumeToken(); |
334 | |
335 | |
336 | |
337 | EnterExpressionEvaluationContext Eval( |
338 | Actions, |
339 | Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, 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 | |
353 | |
354 | |
355 | (0) . __assert_fail ("Toks->size() >= 3 && \"expected a token in default arg\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 355, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">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 | |
365 | |
366 | while (Tok.isNot(tok::eof)) |
367 | ConsumeAnyToken(); |
368 | |
369 | if (Tok.is(tok::eof) && Tok.getEofData() == Param) |
370 | ConsumeAnyToken(); |
371 | } else if (HasUnparsed) { |
372 | hasInheritedDefaultArg()", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 372, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Param->hasInheritedDefaultArg()); |
373 | FunctionDecl *Old = cast<FunctionDecl>(LM.Method)->getPreviousDecl(); |
374 | ParmVarDecl *OldParam = Old->getParamDecl(I); |
375 | hasUnparsedDefaultArg()", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 375, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert (!OldParam->hasUnparsedDefaultArg()); |
376 | if (OldParam->hasUninstantiatedDefaultArg()) |
377 | Param->setUninstantiatedDefaultArg( |
378 | OldParam->getUninstantiatedDefaultArg()); |
379 | else |
380 | Param->setDefaultArg(OldParam->getInit()); |
381 | } |
382 | } |
383 | |
384 | |
385 | if (CachedTokens *Toks = LM.ExceptionSpecTokens) { |
386 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
387 | |
388 | |
389 | Token LastExceptionSpecToken = Toks->back(); |
390 | Token ExceptionSpecEnd; |
391 | ExceptionSpecEnd.startToken(); |
392 | ExceptionSpecEnd.setKind(tok::eof); |
393 | ExceptionSpecEnd.setLocation(LastExceptionSpecToken.getEndLoc()); |
394 | ExceptionSpecEnd.setEofData(LM.Method); |
395 | Toks->push_back(ExceptionSpecEnd); |
396 | |
397 | |
398 | Toks->push_back(Tok); |
399 | PP.EnterTokenStream(*Toks, true); |
400 | |
401 | |
402 | ConsumeAnyToken(); |
403 | |
404 | |
405 | |
406 | |
407 | |
408 | |
409 | |
410 | CXXMethodDecl *Method; |
411 | if (FunctionTemplateDecl *FunTmpl |
412 | = dyn_cast<FunctionTemplateDecl>(LM.Method)) |
413 | Method = cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl()); |
414 | else |
415 | Method = cast<CXXMethodDecl>(LM.Method); |
416 | |
417 | Sema::CXXThisScopeRAII ThisScope(Actions, Method->getParent(), |
418 | Method->getMethodQualifiers(), |
419 | getLangOpts().CPlusPlus11); |
420 | |
421 | |
422 | SourceRange SpecificationRange; |
423 | SmallVector<ParsedType, 4> DynamicExceptions; |
424 | SmallVector<SourceRange, 4> DynamicExceptionRanges; |
425 | ExprResult NoexceptExpr; |
426 | CachedTokens *ExceptionSpecTokens; |
427 | |
428 | ExceptionSpecificationType EST |
429 | = tryParseExceptionSpecification(, SpecificationRange, |
430 | DynamicExceptions, |
431 | DynamicExceptionRanges, NoexceptExpr, |
432 | ExceptionSpecTokens); |
433 | |
434 | if (Tok.isNot(tok::eof) || Tok.getEofData() != LM.Method) |
435 | Diag(Tok.getLocation(), diag::err_except_spec_unparsed); |
436 | |
437 | |
438 | Actions.actOnDelayedExceptionSpecification(LM.Method, EST, |
439 | SpecificationRange, |
440 | DynamicExceptions, |
441 | DynamicExceptionRanges, |
442 | NoexceptExpr.isUsable()? |
443 | NoexceptExpr.get() : nullptr); |
444 | |
445 | |
446 | |
447 | while (Tok.isNot(tok::eof)) |
448 | ConsumeAnyToken(); |
449 | |
450 | |
451 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.Method) |
452 | ConsumeAnyToken(); |
453 | |
454 | delete Toks; |
455 | LM.ExceptionSpecTokens = nullptr; |
456 | } |
457 | |
458 | PrototypeScope.Exit(); |
459 | |
460 | |
461 | Actions.ActOnFinishDelayedCXXMethodDeclaration(getCurScope(), LM.Method); |
462 | } |
463 | |
464 | |
465 | |
466 | |
467 | void Parser::ParseLexedMethodDefs(ParsingClass &Class) { |
468 | bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; |
469 | ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope); |
470 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
471 | if (HasTemplateScope) { |
472 | Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); |
473 | ++CurTemplateDepthTracker; |
474 | } |
475 | bool HasClassScope = !Class.TopLevelClass; |
476 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope, |
477 | HasClassScope); |
478 | |
479 | for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { |
480 | Class.LateParsedDeclarations[i]->ParseLexedMethodDefs(); |
481 | } |
482 | } |
483 | |
484 | void Parser::ParseLexedMethodDef(LexedMethod &LM) { |
485 | |
486 | ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope); |
487 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
488 | if (LM.TemplateScope) { |
489 | Actions.ActOnReenterTemplateScope(getCurScope(), LM.D); |
490 | ++CurTemplateDepthTracker; |
491 | } |
492 | |
493 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
494 | |
495 | (0) . __assert_fail ("!LM.Toks.empty() && \"Empty body!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 495, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!LM.Toks.empty() && "Empty body!"); |
496 | Token LastBodyToken = LM.Toks.back(); |
497 | Token BodyEnd; |
498 | BodyEnd.startToken(); |
499 | BodyEnd.setKind(tok::eof); |
500 | BodyEnd.setLocation(LastBodyToken.getEndLoc()); |
501 | BodyEnd.setEofData(LM.D); |
502 | LM.Toks.push_back(BodyEnd); |
503 | |
504 | |
505 | LM.Toks.push_back(Tok); |
506 | PP.EnterTokenStream(LM.Toks, true); |
507 | |
508 | |
509 | ConsumeAnyToken(); |
510 | (0) . __assert_fail ("Tok.isOneOf(tok..l_brace, tok..colon, tok..kw_try) && \"Inline method not starting with '{', '.' or 'try'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 511, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try) |
511 | (0) . __assert_fail ("Tok.isOneOf(tok..l_brace, tok..colon, tok..kw_try) && \"Inline method not starting with '{', '.' or 'try'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 511, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && "Inline method not starting with '{', ':' or 'try'"); |
512 | |
513 | |
514 | |
515 | ParseScope FnScope(this, Scope::FnScope | Scope::DeclScope | |
516 | Scope::CompoundStmtScope); |
517 | Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D); |
518 | |
519 | if (Tok.is(tok::kw_try)) { |
520 | ParseFunctionTryBlock(LM.D, FnScope); |
521 | |
522 | while (Tok.isNot(tok::eof)) |
523 | ConsumeAnyToken(); |
524 | |
525 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) |
526 | ConsumeAnyToken(); |
527 | return; |
528 | } |
529 | if (Tok.is(tok::colon)) { |
530 | ParseConstructorInitializer(LM.D); |
531 | |
532 | |
533 | if (!Tok.is(tok::l_brace)) { |
534 | FnScope.Exit(); |
535 | Actions.ActOnFinishFunctionBody(LM.D, nullptr); |
536 | |
537 | while (Tok.isNot(tok::eof)) |
538 | ConsumeAnyToken(); |
539 | |
540 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) |
541 | ConsumeAnyToken(); |
542 | return; |
543 | } |
544 | } else |
545 | Actions.ActOnDefaultCtorInitializers(LM.D); |
546 | |
547 | (0) . __assert_fail ("(Actions.getDiagnostics().hasErrorOccurred() || !isa(LM.D) || cast(LM.D)->getTemplateParameters()->getDepth() < TemplateParameterDepth) && \"TemplateParameterDepth should be greater than the depth of \" \"current template being instantiated!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 552, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((Actions.getDiagnostics().hasErrorOccurred() || |
548 | (0) . __assert_fail ("(Actions.getDiagnostics().hasErrorOccurred() || !isa(LM.D) || cast(LM.D)->getTemplateParameters()->getDepth() < TemplateParameterDepth) && \"TemplateParameterDepth should be greater than the depth of \" \"current template being instantiated!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 552, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> !isa<FunctionTemplateDecl>(LM.D) || |
549 | (0) . __assert_fail ("(Actions.getDiagnostics().hasErrorOccurred() || !isa(LM.D) || cast(LM.D)->getTemplateParameters()->getDepth() < TemplateParameterDepth) && \"TemplateParameterDepth should be greater than the depth of \" \"current template being instantiated!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 552, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> cast<FunctionTemplateDecl>(LM.D)->getTemplateParameters()->getDepth() |
550 | (0) . __assert_fail ("(Actions.getDiagnostics().hasErrorOccurred() || !isa(LM.D) || cast(LM.D)->getTemplateParameters()->getDepth() < TemplateParameterDepth) && \"TemplateParameterDepth should be greater than the depth of \" \"current template being instantiated!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 552, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> < TemplateParameterDepth) && |
551 | (0) . __assert_fail ("(Actions.getDiagnostics().hasErrorOccurred() || !isa(LM.D) || cast(LM.D)->getTemplateParameters()->getDepth() < TemplateParameterDepth) && \"TemplateParameterDepth should be greater than the depth of \" \"current template being instantiated!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 552, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "TemplateParameterDepth should be greater than the depth of " |
552 | (0) . __assert_fail ("(Actions.getDiagnostics().hasErrorOccurred() || !isa(LM.D) || cast(LM.D)->getTemplateParameters()->getDepth() < TemplateParameterDepth) && \"TemplateParameterDepth should be greater than the depth of \" \"current template being instantiated!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 552, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "current template being instantiated!"); |
553 | |
554 | ParseFunctionStatementBody(LM.D, FnScope); |
555 | |
556 | while (Tok.isNot(tok::eof)) |
557 | ConsumeAnyToken(); |
558 | |
559 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) |
560 | ConsumeAnyToken(); |
561 | |
562 | if (auto *FD = dyn_cast_or_null<FunctionDecl>(LM.D)) |
563 | if (isa<CXXMethodDecl>(FD) || |
564 | FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend)) |
565 | Actions.ActOnFinishInlineFunctionDef(FD); |
566 | } |
567 | |
568 | |
569 | |
570 | |
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 | |
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 | |
592 | |
593 | |
594 | |
595 | |
596 | Sema::CXXThisScopeRAII ThisScope(Actions, Class.TagOrTemplate, |
597 | Qualifiers()); |
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 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
616 | |
617 | |
618 | |
619 | MI.Toks.push_back(Tok); |
620 | PP.EnterTokenStream(MI.Toks, true); |
621 | |
622 | |
623 | ConsumeAnyToken(); |
624 | |
625 | SourceLocation EqualLoc; |
626 | |
627 | Actions.ActOnStartCXXInClassMemberInitializer(); |
628 | |
629 | ExprResult Init = ParseCXXMemberInitializer(MI.Field, , |
630 | EqualLoc); |
631 | |
632 | Actions.ActOnFinishCXXInClassMemberInitializer(MI.Field, EqualLoc, |
633 | Init.get()); |
634 | |
635 | |
636 | if (Tok.isNot(tok::eof)) { |
637 | if (!Init.isInvalid()) { |
638 | SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation); |
639 | if (!EndLoc.isValid()) |
640 | EndLoc = Tok.getLocation(); |
641 | |
642 | Diag(EndLoc, diag::err_expected_semi_decl_list); |
643 | } |
644 | |
645 | |
646 | while (Tok.isNot(tok::eof)) |
647 | ConsumeAnyToken(); |
648 | } |
649 | |
650 | if (Tok.getEofData() == MI.Field) |
651 | ConsumeAnyToken(); |
652 | } |
653 | |
654 | |
655 | |
656 | |
657 | |
658 | |
659 | |
660 | bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, |
661 | CachedTokens &Toks, |
662 | bool StopAtSemi, bool ConsumeFinalToken) { |
663 | |
664 | |
665 | bool isFirstTokenConsumed = true; |
666 | while (1) { |
667 | |
668 | if (Tok.is(T1) || Tok.is(T2)) { |
669 | if (ConsumeFinalToken) { |
670 | Toks.push_back(Tok); |
671 | ConsumeAnyToken(); |
672 | } |
673 | return true; |
674 | } |
675 | |
676 | switch (Tok.getKind()) { |
677 | case tok::eof: |
678 | case tok::annot_module_begin: |
679 | case tok::annot_module_end: |
680 | case tok::annot_module_include: |
681 | |
682 | return false; |
683 | |
684 | case tok::l_paren: |
685 | |
686 | Toks.push_back(Tok); |
687 | ConsumeParen(); |
688 | ConsumeAndStoreUntil(tok::r_paren, Toks, ); |
689 | break; |
690 | case tok::l_square: |
691 | |
692 | Toks.push_back(Tok); |
693 | ConsumeBracket(); |
694 | ConsumeAndStoreUntil(tok::r_square, Toks, ); |
695 | break; |
696 | case tok::l_brace: |
697 | |
698 | Toks.push_back(Tok); |
699 | ConsumeBrace(); |
700 | ConsumeAndStoreUntil(tok::r_brace, Toks, ); |
701 | break; |
702 | |
703 | |
704 | |
705 | |
706 | |
707 | |
708 | case tok::r_paren: |
709 | if (ParenCount && !isFirstTokenConsumed) |
710 | return false; |
711 | Toks.push_back(Tok); |
712 | ConsumeParen(); |
713 | break; |
714 | case tok::r_square: |
715 | if (BracketCount && !isFirstTokenConsumed) |
716 | return false; |
717 | Toks.push_back(Tok); |
718 | ConsumeBracket(); |
719 | break; |
720 | case tok::r_brace: |
721 | if (BraceCount && !isFirstTokenConsumed) |
722 | return false; |
723 | Toks.push_back(Tok); |
724 | ConsumeBrace(); |
725 | break; |
726 | |
727 | case tok::semi: |
728 | if (StopAtSemi) |
729 | return false; |
730 | LLVM_FALLTHROUGH; |
731 | default: |
732 | |
733 | Toks.push_back(Tok); |
734 | ConsumeAnyToken(); |
735 | break; |
736 | } |
737 | isFirstTokenConsumed = false; |
738 | } |
739 | } |
740 | |
741 | |
742 | |
743 | |
744 | |
745 | |
746 | |
747 | bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { |
748 | if (Tok.is(tok::kw_try)) { |
749 | Toks.push_back(Tok); |
750 | ConsumeToken(); |
751 | } |
752 | |
753 | if (Tok.isNot(tok::colon)) { |
754 | |
755 | |
756 | |
757 | |
758 | |
759 | ConsumeAndStoreUntil(tok::l_brace, tok::r_brace, Toks, |
760 | , |
761 | ); |
762 | if (Tok.isNot(tok::l_brace)) |
763 | return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; |
764 | |
765 | Toks.push_back(Tok); |
766 | ConsumeBrace(); |
767 | return false; |
768 | } |
769 | |
770 | Toks.push_back(Tok); |
771 | ConsumeToken(); |
772 | |
773 | |
774 | |
775 | |
776 | |
777 | |
778 | |
779 | |
780 | |
781 | |
782 | |
783 | bool MightBeTemplateArgument = false; |
784 | |
785 | while (true) { |
786 | |
787 | if (Tok.is(tok::kw_decltype)) { |
788 | Toks.push_back(Tok); |
789 | SourceLocation OpenLoc = ConsumeToken(); |
790 | if (Tok.isNot(tok::l_paren)) |
791 | return Diag(Tok.getLocation(), diag::err_expected_lparen_after) |
792 | << "decltype"; |
793 | Toks.push_back(Tok); |
794 | ConsumeParen(); |
795 | if (!ConsumeAndStoreUntil(tok::r_paren, Toks, )) { |
796 | Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren; |
797 | Diag(OpenLoc, diag::note_matching) << tok::l_paren; |
798 | return true; |
799 | } |
800 | } |
801 | do { |
802 | |
803 | if (Tok.is(tok::coloncolon)) { |
804 | Toks.push_back(Tok); |
805 | ConsumeToken(); |
806 | |
807 | if (Tok.is(tok::kw_template)) { |
808 | Toks.push_back(Tok); |
809 | ConsumeToken(); |
810 | } |
811 | } |
812 | |
813 | if (Tok.is(tok::identifier)) { |
814 | Toks.push_back(Tok); |
815 | ConsumeToken(); |
816 | } else { |
817 | break; |
818 | } |
819 | } while (Tok.is(tok::coloncolon)); |
820 | |
821 | if (Tok.is(tok::code_completion)) { |
822 | Toks.push_back(Tok); |
823 | ConsumeCodeCompletionToken(); |
824 | if (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype)) { |
825 | |
826 | |
827 | continue; |
828 | } |
829 | } |
830 | |
831 | if (Tok.is(tok::comma)) { |
832 | |
833 | Toks.push_back(Tok); |
834 | ConsumeToken(); |
835 | continue; |
836 | } |
837 | if (Tok.is(tok::less)) |
838 | MightBeTemplateArgument = true; |
839 | |
840 | if (MightBeTemplateArgument) { |
841 | |
842 | |
843 | |
844 | |
845 | |
846 | |
847 | if (!ConsumeAndStoreUntil(tok::l_paren, tok::l_brace, Toks, |
848 | , |
849 | )) { |
850 | |
851 | |
852 | return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; |
853 | } |
854 | } else if (Tok.isNot(tok::l_paren) && Tok.isNot(tok::l_brace)) { |
855 | |
856 | if (getLangOpts().CPlusPlus11) |
857 | return Diag(Tok.getLocation(), diag::err_expected_either) |
858 | << tok::l_paren << tok::l_brace; |
859 | else |
860 | return Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren; |
861 | } |
862 | |
863 | tok::TokenKind kind = Tok.getKind(); |
864 | Toks.push_back(Tok); |
865 | bool IsLParen = (kind == tok::l_paren); |
866 | SourceLocation OpenLoc = Tok.getLocation(); |
867 | |
868 | if (IsLParen) { |
869 | ConsumeParen(); |
870 | } else { |
871 | (0) . __assert_fail ("kind == tok..l_brace && \"Must be left paren or brace here.\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseCXXInlineMethods.cpp", 871, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(kind == tok::l_brace && "Must be left paren or brace here."); |
872 | ConsumeBrace(); |
873 | |
874 | |
875 | if (!getLangOpts().CPlusPlus11) |
876 | return false; |
877 | |
878 | const Token &PreviousToken = Toks[Toks.size() - 2]; |
879 | if (!MightBeTemplateArgument && |
880 | !PreviousToken.isOneOf(tok::identifier, tok::greater, |
881 | tok::greatergreater)) { |
882 | |
883 | |
884 | |
885 | |
886 | |
887 | TentativeParsingAction PA(*this); |
888 | if (SkipUntil(tok::r_brace) && |
889 | !Tok.isOneOf(tok::comma, tok::ellipsis, tok::l_brace)) { |
890 | |
891 | |
892 | PA.Revert(); |
893 | return false; |
894 | } |
895 | PA.Revert(); |
896 | } |
897 | } |
898 | |
899 | |
900 | |
901 | |
902 | tok::TokenKind CloseKind = IsLParen ? tok::r_paren : tok::r_brace; |
903 | if (!ConsumeAndStoreUntil(CloseKind, Toks, )) { |
904 | Diag(Tok, diag::err_expected) << CloseKind; |
905 | Diag(OpenLoc, diag::note_matching) << kind; |
906 | return true; |
907 | } |
908 | |
909 | |
910 | if (Tok.is(tok::ellipsis)) { |
911 | Toks.push_back(Tok); |
912 | ConsumeToken(); |
913 | } |
914 | |
915 | |
916 | |
917 | if (Tok.is(tok::comma)) { |
918 | Toks.push_back(Tok); |
919 | ConsumeToken(); |
920 | } else if (Tok.is(tok::l_brace)) { |
921 | |
922 | |
923 | |
924 | |
925 | |
926 | |
927 | |
928 | |
929 | |
930 | |
931 | |
932 | |
933 | |
934 | |
935 | Toks.push_back(Tok); |
936 | ConsumeBrace(); |
937 | return false; |
938 | } else if (!MightBeTemplateArgument) { |
939 | return Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace |
940 | << tok::comma; |
941 | } |
942 | } |
943 | } |
944 | |
945 | |
946 | |
947 | bool Parser::ConsumeAndStoreConditional(CachedTokens &Toks) { |
948 | |
949 | assert(Tok.is(tok::question)); |
950 | Toks.push_back(Tok); |
951 | ConsumeToken(); |
952 | |
953 | while (Tok.isNot(tok::colon)) { |
954 | if (!ConsumeAndStoreUntil(tok::question, tok::colon, Toks, |
955 | , |
956 | )) |
957 | return false; |
958 | |
959 | |
960 | if (Tok.is(tok::question) && !ConsumeAndStoreConditional(Toks)) |
961 | return false; |
962 | } |
963 | |
964 | |
965 | Toks.push_back(Tok); |
966 | ConsumeToken(); |
967 | return true; |
968 | } |
969 | |
970 | |
971 | class Parser::UnannotatedTentativeParsingAction : public TentativeParsingAction { |
972 | public: |
973 | explicit UnannotatedTentativeParsingAction(Parser &Self, |
974 | tok::TokenKind EndKind) |
975 | : TentativeParsingAction(Self), Self(Self), EndKind(EndKind) { |
976 | |
977 | |
978 | TentativeParsingAction Inner(Self); |
979 | Self.ConsumeAndStoreUntil(EndKind, Toks, true, ); |
980 | Inner.Revert(); |
981 | } |
982 | |
983 | void RevertAnnotations() { |
984 | Revert(); |
985 | |
986 | |
987 | Self.SkipUntil(EndKind, StopAtSemi | StopBeforeMatch); |
988 | if (Toks.size()) { |
989 | auto Buffer = llvm::make_unique<Token[]>(Toks.size()); |
990 | std::copy(Toks.begin() + 1, Toks.end(), Buffer.get()); |
991 | Buffer[Toks.size() - 1] = Self.Tok; |
992 | Self.PP.EnterTokenStream(std::move(Buffer), Toks.size(), true); |
993 | |
994 | Self.Tok = Toks.front(); |
995 | } |
996 | } |
997 | |
998 | private: |
999 | Parser &Self; |
1000 | CachedTokens Toks; |
1001 | tok::TokenKind EndKind; |
1002 | }; |
1003 | |
1004 | |
1005 | |
1006 | |
1007 | |
1008 | |
1009 | |
1010 | bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, |
1011 | CachedInitKind CIK) { |
1012 | |
1013 | bool IsFirstToken = true; |
1014 | |
1015 | |
1016 | |
1017 | |
1018 | unsigned AngleCount = 0; |
1019 | unsigned KnownTemplateCount = 0; |
1020 | |
1021 | while (1) { |
1022 | switch (Tok.getKind()) { |
1023 | case tok::comma: |
1024 | |
1025 | if (!AngleCount) |
1026 | |
1027 | return true; |
1028 | if (KnownTemplateCount) |
1029 | goto consume_token; |
1030 | |
1031 | |
1032 | |
1033 | |
1034 | |
1035 | |
1036 | |
1037 | |
1038 | |
1039 | |
1040 | { |
1041 | UnannotatedTentativeParsingAction PA(*this, |
1042 | CIK == CIK_DefaultInitializer |
1043 | ? tok::semi : tok::r_paren); |
1044 | Sema::TentativeAnalysisScope Scope(Actions); |
1045 | |
1046 | TPResult Result = TPResult::Error; |
1047 | ConsumeToken(); |
1048 | switch (CIK) { |
1049 | case CIK_DefaultInitializer: |
1050 | Result = TryParseInitDeclaratorList(); |
1051 | |
1052 | |
1053 | if (Result == TPResult::Ambiguous && Tok.isNot(tok::semi)) |
1054 | Result = TPResult::False; |
1055 | break; |
1056 | |
1057 | case CIK_DefaultArgument: |
1058 | bool InvalidAsDeclaration = false; |
1059 | Result = TryParseParameterDeclarationClause( |
1060 | &InvalidAsDeclaration, ); |
1061 | |
1062 | |
1063 | if (Result == TPResult::Ambiguous && InvalidAsDeclaration) |
1064 | Result = TPResult::False; |
1065 | break; |
1066 | } |
1067 | |
1068 | |
1069 | if (Result != TPResult::False && Result != TPResult::Error) { |
1070 | PA.Revert(); |
1071 | return true; |
1072 | } |
1073 | |
1074 | |
1075 | |
1076 | |
1077 | |
1078 | PA.RevertAnnotations(); |
1079 | } |
1080 | |
1081 | |
1082 | ++KnownTemplateCount; |
1083 | goto consume_token; |
1084 | |
1085 | case tok::eof: |
1086 | case tok::annot_module_begin: |
1087 | case tok::annot_module_end: |
1088 | case tok::annot_module_include: |
1089 | |
1090 | return false; |
1091 | |
1092 | case tok::less: |
1093 | |
1094 | |
1095 | ++AngleCount; |
1096 | goto consume_token; |
1097 | |
1098 | case tok::question: |
1099 | |
1100 | |
1101 | if (!ConsumeAndStoreConditional(Toks)) |
1102 | return false; |
1103 | break; |
1104 | |
1105 | case tok::greatergreatergreater: |
1106 | if (!getLangOpts().CPlusPlus11) |
1107 | goto consume_token; |
1108 | if (AngleCount) --AngleCount; |
1109 | if (KnownTemplateCount) --KnownTemplateCount; |
1110 | LLVM_FALLTHROUGH; |
1111 | case tok::greatergreater: |
1112 | if (!getLangOpts().CPlusPlus11) |
1113 | goto consume_token; |
1114 | if (AngleCount) --AngleCount; |
1115 | if (KnownTemplateCount) --KnownTemplateCount; |
1116 | LLVM_FALLTHROUGH; |
1117 | case tok::greater: |
1118 | if (AngleCount) --AngleCount; |
1119 | if (KnownTemplateCount) --KnownTemplateCount; |
1120 | goto consume_token; |
1121 | |
1122 | case tok::kw_template: |
1123 | |
1124 | |
1125 | |
1126 | Toks.push_back(Tok); |
1127 | ConsumeToken(); |
1128 | if (Tok.is(tok::identifier)) { |
1129 | Toks.push_back(Tok); |
1130 | ConsumeToken(); |
1131 | if (Tok.is(tok::less)) { |
1132 | ++AngleCount; |
1133 | ++KnownTemplateCount; |
1134 | Toks.push_back(Tok); |
1135 | ConsumeToken(); |
1136 | } |
1137 | } |
1138 | break; |
1139 | |
1140 | case tok::kw_operator: |
1141 | |
1142 | |
1143 | Toks.push_back(Tok); |
1144 | ConsumeToken(); |
1145 | switch (Tok.getKind()) { |
1146 | case tok::comma: |
1147 | case tok::greatergreatergreater: |
1148 | case tok::greatergreater: |
1149 | case tok::greater: |
1150 | case tok::less: |
1151 | Toks.push_back(Tok); |
1152 | ConsumeToken(); |
1153 | break; |
1154 | default: |
1155 | break; |
1156 | } |
1157 | break; |
1158 | |
1159 | case tok::l_paren: |
1160 | |
1161 | Toks.push_back(Tok); |
1162 | ConsumeParen(); |
1163 | ConsumeAndStoreUntil(tok::r_paren, Toks, ); |
1164 | break; |
1165 | case tok::l_square: |
1166 | |
1167 | Toks.push_back(Tok); |
1168 | ConsumeBracket(); |
1169 | ConsumeAndStoreUntil(tok::r_square, Toks, ); |
1170 | break; |
1171 | case tok::l_brace: |
1172 | |
1173 | Toks.push_back(Tok); |
1174 | ConsumeBrace(); |
1175 | ConsumeAndStoreUntil(tok::r_brace, Toks, ); |
1176 | break; |
1177 | |
1178 | |
1179 | |
1180 | |
1181 | |
1182 | |
1183 | |
1184 | case tok::r_paren: |
1185 | if (CIK == CIK_DefaultArgument) |
1186 | return true; |
1187 | if (ParenCount && !IsFirstToken) |
1188 | return false; |
1189 | Toks.push_back(Tok); |
1190 | ConsumeParen(); |
1191 | continue; |
1192 | case tok::r_square: |
1193 | if (BracketCount && !IsFirstToken) |
1194 | return false; |
1195 | Toks.push_back(Tok); |
1196 | ConsumeBracket(); |
1197 | continue; |
1198 | case tok::r_brace: |
1199 | if (BraceCount && !IsFirstToken) |
1200 | return false; |
1201 | Toks.push_back(Tok); |
1202 | ConsumeBrace(); |
1203 | continue; |
1204 | |
1205 | case tok::code_completion: |
1206 | Toks.push_back(Tok); |
1207 | ConsumeCodeCompletionToken(); |
1208 | break; |
1209 | |
1210 | case tok::string_literal: |
1211 | case tok::wide_string_literal: |
1212 | case tok::utf8_string_literal: |
1213 | case tok::utf16_string_literal: |
1214 | case tok::utf32_string_literal: |
1215 | Toks.push_back(Tok); |
1216 | ConsumeStringToken(); |
1217 | break; |
1218 | case tok::semi: |
1219 | if (CIK == CIK_DefaultInitializer) |
1220 | return true; |
1221 | LLVM_FALLTHROUGH; |
1222 | default: |
1223 | consume_token: |
1224 | Toks.push_back(Tok); |
1225 | ConsumeToken(); |
1226 | break; |
1227 | } |
1228 | IsFirstToken = false; |
1229 | } |
1230 | } |
1231 | |