1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | #include "clang/Parse/Parser.h" |
13 | #include "clang/AST/ASTContext.h" |
14 | #include "clang/AST/DeclTemplate.h" |
15 | #include "clang/Basic/PrettyStackTrace.h" |
16 | #include "clang/Lex/LiteralSupport.h" |
17 | #include "clang/Parse/ParseDiagnostic.h" |
18 | #include "clang/Parse/RAIIObjectsForParser.h" |
19 | #include "clang/Sema/DeclSpec.h" |
20 | #include "clang/Sema/ParsedTemplate.h" |
21 | #include "clang/Sema/Scope.h" |
22 | #include "llvm/Support/ErrorHandling.h" |
23 | |
24 | |
25 | using namespace clang; |
26 | |
27 | static int SelectDigraphErrorMessage(tok::TokenKind Kind) { |
28 | switch (Kind) { |
29 | |
30 | case tok::unknown: return 0; |
31 | |
32 | case tok::kw_const_cast: return 1; |
33 | case tok::kw_dynamic_cast: return 2; |
34 | case tok::kw_reinterpret_cast: return 3; |
35 | case tok::kw_static_cast: return 4; |
36 | default: |
37 | llvm_unreachable("Unknown type for digraph error message."); |
38 | } |
39 | } |
40 | |
41 | |
42 | bool Parser::areTokensAdjacent(const Token &First, const Token &Second) { |
43 | SourceManager &SM = PP.getSourceManager(); |
44 | SourceLocation FirstLoc = SM.getSpellingLoc(First.getLocation()); |
45 | SourceLocation FirstEnd = FirstLoc.getLocWithOffset(First.getLength()); |
46 | return FirstEnd == SM.getSpellingLoc(Second.getLocation()); |
47 | } |
48 | |
49 | |
50 | static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, |
51 | Token &ColonToken, tok::TokenKind Kind, bool AtDigraph) { |
52 | |
53 | if (!AtDigraph) |
54 | PP.Lex(DigraphToken); |
55 | PP.Lex(ColonToken); |
56 | |
57 | SourceRange Range; |
58 | Range.setBegin(DigraphToken.getLocation()); |
59 | Range.setEnd(ColonToken.getLocation()); |
60 | P.Diag(DigraphToken.getLocation(), diag::err_missing_whitespace_digraph) |
61 | << SelectDigraphErrorMessage(Kind) |
62 | << FixItHint::CreateReplacement(Range, "< ::"); |
63 | |
64 | |
65 | ColonToken.setKind(tok::coloncolon); |
66 | ColonToken.setLocation(ColonToken.getLocation().getLocWithOffset(-1)); |
67 | ColonToken.setLength(2); |
68 | DigraphToken.setKind(tok::less); |
69 | DigraphToken.setLength(1); |
70 | |
71 | |
72 | PP.EnterToken(ColonToken); |
73 | if (!AtDigraph) |
74 | PP.EnterToken(DigraphToken); |
75 | } |
76 | |
77 | |
78 | |
79 | void Parser::CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectType, |
80 | bool EnteringContext, |
81 | IdentifierInfo &II, CXXScopeSpec &SS) { |
82 | if (!Next.is(tok::l_square) || Next.getLength() != 2) |
83 | return; |
84 | |
85 | Token SecondToken = GetLookAheadToken(2); |
86 | if (!SecondToken.is(tok::colon) || !areTokensAdjacent(Next, SecondToken)) |
87 | return; |
88 | |
89 | TemplateTy Template; |
90 | UnqualifiedId TemplateName; |
91 | TemplateName.setIdentifier(&II, Tok.getLocation()); |
92 | bool MemberOfUnknownSpecialization; |
93 | if (!Actions.isTemplateName(getCurScope(), SS, , |
94 | TemplateName, ObjectType, EnteringContext, |
95 | Template, MemberOfUnknownSpecialization)) |
96 | return; |
97 | |
98 | FixDigraph(*this, PP, Next, SecondToken, tok::unknown, |
99 | ); |
100 | } |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, |
147 | ParsedType ObjectType, |
148 | bool EnteringContext, |
149 | bool *MayBePseudoDestructor, |
150 | bool IsTypename, |
151 | IdentifierInfo **LastII, |
152 | bool OnlyNamespace) { |
153 | (0) . __assert_fail ("getLangOpts().CPlusPlus && \"Call sites of this function should be guarded by checking for C++\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 154, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getLangOpts().CPlusPlus && |
154 | (0) . __assert_fail ("getLangOpts().CPlusPlus && \"Call sites of this function should be guarded by checking for C++\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 154, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Call sites of this function should be guarded by checking for C++"); |
155 | |
156 | if (Tok.is(tok::annot_cxxscope)) { |
157 | (0) . __assert_fail ("!LastII && \"want last identifier but have already annotated scope\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 157, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!LastII && "want last identifier but have already annotated scope"); |
158 | (0) . __assert_fail ("!MayBePseudoDestructor && \"unexpected annot_cxxscope\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 158, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!MayBePseudoDestructor && "unexpected annot_cxxscope"); |
159 | Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), |
160 | Tok.getAnnotationRange(), |
161 | SS); |
162 | ConsumeAnnotationToken(); |
163 | return false; |
164 | } |
165 | |
166 | if (Tok.is(tok::annot_template_id)) { |
167 | |
168 | |
169 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
170 | SS = TemplateId->SS; |
171 | } |
172 | |
173 | |
174 | bool CheckForDestructor = false; |
175 | if (MayBePseudoDestructor && *MayBePseudoDestructor) { |
176 | CheckForDestructor = true; |
177 | *MayBePseudoDestructor = false; |
178 | } |
179 | |
180 | if (LastII) |
181 | *LastII = nullptr; |
182 | |
183 | bool HasScopeSpecifier = false; |
184 | |
185 | if (Tok.is(tok::coloncolon)) { |
186 | |
187 | tok::TokenKind NextKind = NextToken().getKind(); |
188 | if (NextKind == tok::kw_new || NextKind == tok::kw_delete) |
189 | return false; |
190 | |
191 | if (NextKind == tok::l_brace) { |
192 | |
193 | |
194 | Diag(ConsumeToken(), diag::err_expected) << tok::identifier; |
195 | } else { |
196 | |
197 | if (Actions.ActOnCXXGlobalScopeSpecifier(ConsumeToken(), SS)) |
198 | return true; |
199 | |
200 | HasScopeSpecifier = true; |
201 | } |
202 | } |
203 | |
204 | if (Tok.is(tok::kw___super)) { |
205 | SourceLocation SuperLoc = ConsumeToken(); |
206 | if (!Tok.is(tok::coloncolon)) { |
207 | Diag(Tok.getLocation(), diag::err_expected_coloncolon_after_super); |
208 | return true; |
209 | } |
210 | |
211 | return Actions.ActOnSuperScopeSpecifier(SuperLoc, ConsumeToken(), SS); |
212 | } |
213 | |
214 | if (!HasScopeSpecifier && |
215 | Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) { |
216 | DeclSpec DS(AttrFactory); |
217 | SourceLocation DeclLoc = Tok.getLocation(); |
218 | SourceLocation EndLoc = ParseDecltypeSpecifier(DS); |
219 | |
220 | SourceLocation CCLoc; |
221 | |
222 | |
223 | if (DS.getTypeSpecType() == DeclSpec::TST_decltype_auto || |
224 | !TryConsumeToken(tok::coloncolon, CCLoc)) { |
225 | AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc); |
226 | return false; |
227 | } |
228 | |
229 | if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc)) |
230 | SS.SetInvalid(SourceRange(DeclLoc, CCLoc)); |
231 | |
232 | HasScopeSpecifier = true; |
233 | } |
234 | |
235 | while (true) { |
236 | if (HasScopeSpecifier) { |
237 | if (Tok.is(tok::code_completion)) { |
238 | |
239 | |
240 | Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext, |
241 | ObjectType.get()); |
242 | |
243 | |
244 | |
245 | |
246 | SS.setEndLoc(Tok.getLocation()); |
247 | cutOffParsing(); |
248 | return true; |
249 | } |
250 | |
251 | |
252 | |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | ObjectType = nullptr; |
262 | } |
263 | |
264 | |
265 | |
266 | |
267 | |
268 | |
269 | if (Tok.is(tok::kw_template)) { |
270 | |
271 | |
272 | |
273 | if (!HasScopeSpecifier && !ObjectType) |
274 | break; |
275 | |
276 | TentativeParsingAction TPA(*this); |
277 | SourceLocation TemplateKWLoc = ConsumeToken(); |
278 | |
279 | UnqualifiedId TemplateName; |
280 | if (Tok.is(tok::identifier)) { |
281 | |
282 | TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); |
283 | ConsumeToken(); |
284 | } else if (Tok.is(tok::kw_operator)) { |
285 | |
286 | |
287 | |
288 | |
289 | if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, |
290 | TemplateName)) { |
291 | TPA.Commit(); |
292 | break; |
293 | } |
294 | |
295 | if (TemplateName.getKind() != UnqualifiedIdKind::IK_OperatorFunctionId && |
296 | TemplateName.getKind() != UnqualifiedIdKind::IK_LiteralOperatorId) { |
297 | Diag(TemplateName.getSourceRange().getBegin(), |
298 | diag::err_id_after_template_in_nested_name_spec) |
299 | << TemplateName.getSourceRange(); |
300 | TPA.Commit(); |
301 | break; |
302 | } |
303 | } else { |
304 | TPA.Revert(); |
305 | break; |
306 | } |
307 | |
308 | |
309 | |
310 | |
311 | if (Tok.isNot(tok::less)) { |
312 | TPA.Revert(); |
313 | break; |
314 | } |
315 | |
316 | |
317 | TPA.Commit(); |
318 | TemplateTy Template; |
319 | if (TemplateNameKind TNK = Actions.ActOnDependentTemplateName( |
320 | getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType, |
321 | EnteringContext, Template, true)) { |
322 | if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc, |
323 | TemplateName, false)) |
324 | return true; |
325 | } else |
326 | return true; |
327 | |
328 | continue; |
329 | } |
330 | |
331 | if (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) { |
332 | |
333 | |
334 | |
335 | |
336 | |
337 | |
338 | |
339 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
340 | if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde)) { |
341 | *MayBePseudoDestructor = true; |
342 | return false; |
343 | } |
344 | |
345 | if (LastII) |
346 | *LastII = TemplateId->Name; |
347 | |
348 | |
349 | ConsumeAnnotationToken(); |
350 | |
351 | (0) . __assert_fail ("Tok.is(tok..coloncolon) && \"NextToken() not working properly!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 351, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!"); |
352 | SourceLocation CCLoc = ConsumeToken(); |
353 | |
354 | HasScopeSpecifier = true; |
355 | |
356 | ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(), |
357 | TemplateId->NumArgs); |
358 | |
359 | if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), |
360 | SS, |
361 | TemplateId->TemplateKWLoc, |
362 | TemplateId->Template, |
363 | TemplateId->TemplateNameLoc, |
364 | TemplateId->LAngleLoc, |
365 | TemplateArgsPtr, |
366 | TemplateId->RAngleLoc, |
367 | CCLoc, |
368 | EnteringContext)) { |
369 | SourceLocation StartLoc |
370 | = SS.getBeginLoc().isValid()? SS.getBeginLoc() |
371 | : TemplateId->TemplateNameLoc; |
372 | SS.SetInvalid(SourceRange(StartLoc, CCLoc)); |
373 | } |
374 | |
375 | continue; |
376 | } |
377 | |
378 | |
379 | |
380 | if (Tok.isNot(tok::identifier)) |
381 | break; |
382 | |
383 | IdentifierInfo &II = *Tok.getIdentifierInfo(); |
384 | |
385 | |
386 | |
387 | |
388 | |
389 | Token Next = NextToken(); |
390 | Sema::NestedNameSpecInfo IdInfo(&II, Tok.getLocation(), Next.getLocation(), |
391 | ObjectType); |
392 | |
393 | |
394 | |
395 | if (Next.is(tok::colon) && !ColonIsSacred) { |
396 | if (Actions.IsInvalidUnlessNestedName(getCurScope(), SS, IdInfo, |
397 | EnteringContext) && |
398 | |
399 | |
400 | |
401 | PP.LookAhead(1).is(tok::identifier)) { |
402 | Diag(Next, diag::err_unexpected_colon_in_nested_name_spec) |
403 | << FixItHint::CreateReplacement(Next.getLocation(), "::"); |
404 | |
405 | Next.setKind(tok::coloncolon); |
406 | } |
407 | } |
408 | |
409 | if (Next.is(tok::coloncolon) && GetLookAheadToken(2).is(tok::l_brace)) { |
410 | |
411 | |
412 | Token Identifier = Tok; |
413 | ConsumeToken(); |
414 | Diag(PP.getLocForEndOfToken(ConsumeToken()), diag::err_expected) |
415 | << tok::identifier; |
416 | UnconsumeToken(Identifier); |
417 | Next = NextToken(); |
418 | } |
419 | |
420 | if (Next.is(tok::coloncolon)) { |
421 | if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde) && |
422 | !Actions.isNonTypeNestedNameSpecifier(getCurScope(), SS, IdInfo)) { |
423 | *MayBePseudoDestructor = true; |
424 | return false; |
425 | } |
426 | |
427 | if (ColonIsSacred) { |
428 | const Token &Next2 = GetLookAheadToken(2); |
429 | if (Next2.is(tok::kw_private) || Next2.is(tok::kw_protected) || |
430 | Next2.is(tok::kw_public) || Next2.is(tok::kw_virtual)) { |
431 | Diag(Next2, diag::err_unexpected_token_in_nested_name_spec) |
432 | << Next2.getName() |
433 | << FixItHint::CreateReplacement(Next.getLocation(), ":"); |
434 | Token ColonColon; |
435 | PP.Lex(ColonColon); |
436 | ColonColon.setKind(tok::colon); |
437 | PP.EnterToken(ColonColon); |
438 | break; |
439 | } |
440 | } |
441 | |
442 | if (LastII) |
443 | *LastII = &II; |
444 | |
445 | |
446 | |
447 | Token Identifier = Tok; |
448 | SourceLocation IdLoc = ConsumeToken(); |
449 | (0) . __assert_fail ("Tok.isOneOf(tok..coloncolon, tok..colon) && \"NextToken() not working properly!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 450, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::coloncolon, tok::colon) && |
450 | (0) . __assert_fail ("Tok.isOneOf(tok..coloncolon, tok..colon) && \"NextToken() not working properly!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 450, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "NextToken() not working properly!"); |
451 | Token ColonColon = Tok; |
452 | SourceLocation CCLoc = ConsumeToken(); |
453 | |
454 | bool IsCorrectedToColon = false; |
455 | bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon : nullptr; |
456 | if (Actions.ActOnCXXNestedNameSpecifier( |
457 | getCurScope(), IdInfo, EnteringContext, SS, false, |
458 | CorrectionFlagPtr, OnlyNamespace)) { |
459 | |
460 | |
461 | if (CorrectionFlagPtr && IsCorrectedToColon) { |
462 | ColonColon.setKind(tok::colon); |
463 | PP.EnterToken(Tok); |
464 | PP.EnterToken(ColonColon); |
465 | Tok = Identifier; |
466 | break; |
467 | } |
468 | SS.SetInvalid(SourceRange(IdLoc, CCLoc)); |
469 | } |
470 | HasScopeSpecifier = true; |
471 | continue; |
472 | } |
473 | |
474 | CheckForTemplateAndDigraph(Next, ObjectType, EnteringContext, II, SS); |
475 | |
476 | |
477 | |
478 | if (Next.is(tok::less)) { |
479 | TemplateTy Template; |
480 | UnqualifiedId TemplateName; |
481 | TemplateName.setIdentifier(&II, Tok.getLocation()); |
482 | bool MemberOfUnknownSpecialization; |
483 | if (TemplateNameKind TNK = Actions.isTemplateName(getCurScope(), SS, |
484 | , |
485 | TemplateName, |
486 | ObjectType, |
487 | EnteringContext, |
488 | Template, |
489 | MemberOfUnknownSpecialization)) { |
490 | |
491 | |
492 | |
493 | |
494 | |
495 | |
496 | ConsumeToken(); |
497 | if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), |
498 | TemplateName, false)) |
499 | return true; |
500 | continue; |
501 | } |
502 | |
503 | if (MemberOfUnknownSpecialization && (ObjectType || SS.isSet()) && |
504 | (IsTypename || IsTemplateArgumentList(1))) { |
505 | |
506 | |
507 | |
508 | |
509 | unsigned DiagID = diag::err_missing_dependent_template_keyword; |
510 | if (getLangOpts().MicrosoftExt) |
511 | DiagID = diag::warn_missing_dependent_template_keyword; |
512 | |
513 | Diag(Tok.getLocation(), DiagID) |
514 | << II.getName() |
515 | << FixItHint::CreateInsertion(Tok.getLocation(), "template "); |
516 | |
517 | if (TemplateNameKind TNK = Actions.ActOnDependentTemplateName( |
518 | getCurScope(), SS, Tok.getLocation(), TemplateName, ObjectType, |
519 | EnteringContext, Template, true)) { |
520 | |
521 | ConsumeToken(); |
522 | if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), |
523 | TemplateName, false)) |
524 | return true; |
525 | } |
526 | else |
527 | return true; |
528 | |
529 | continue; |
530 | } |
531 | } |
532 | |
533 | |
534 | |
535 | break; |
536 | } |
537 | |
538 | |
539 | |
540 | |
541 | if (CheckForDestructor && Tok.is(tok::tilde)) |
542 | *MayBePseudoDestructor = true; |
543 | |
544 | return false; |
545 | } |
546 | |
547 | ExprResult Parser::tryParseCXXIdExpression(CXXScopeSpec &SS, bool isAddressOfOperand, |
548 | Token &Replacement) { |
549 | SourceLocation TemplateKWLoc; |
550 | UnqualifiedId Name; |
551 | if (ParseUnqualifiedId(SS, |
552 | , |
553 | , |
554 | , |
555 | , |
556 | , &TemplateKWLoc, Name)) |
557 | return ExprError(); |
558 | |
559 | |
560 | |
561 | if (isAddressOfOperand && isPostfixExpressionSuffixStart()) |
562 | isAddressOfOperand = false; |
563 | |
564 | ExprResult E = Actions.ActOnIdExpression( |
565 | getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren), |
566 | isAddressOfOperand, , , |
567 | &Replacement); |
568 | if (!E.isInvalid() && !E.isUnset() && Tok.is(tok::less)) |
569 | checkPotentialAngleBracket(E); |
570 | return E; |
571 | } |
572 | |
573 | |
574 | |
575 | |
576 | |
577 | |
578 | |
579 | |
580 | |
581 | |
582 | |
583 | |
584 | |
585 | |
586 | |
587 | |
588 | |
589 | |
590 | |
591 | |
592 | |
593 | |
594 | |
595 | |
596 | |
597 | |
598 | |
599 | |
600 | |
601 | |
602 | |
603 | |
604 | |
605 | |
606 | |
607 | |
608 | |
609 | |
610 | |
611 | |
612 | |
613 | |
614 | |
615 | ExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) { |
616 | |
617 | |
618 | |
619 | |
620 | CXXScopeSpec SS; |
621 | ParseOptionalCXXScopeSpecifier(SS, nullptr, ); |
622 | |
623 | Token Replacement; |
624 | ExprResult Result = |
625 | tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement); |
626 | if (Result.isUnset()) { |
627 | |
628 | |
629 | UnconsumeToken(Replacement); |
630 | Result = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement); |
631 | } |
632 | (0) . __assert_fail ("!Result.isUnset() && \"Typo correction suggested a keyword replacement \" \"for a previous keyword suggestion\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 633, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Result.isUnset() && "Typo correction suggested a keyword replacement " |
633 | (0) . __assert_fail ("!Result.isUnset() && \"Typo correction suggested a keyword replacement \" \"for a previous keyword suggestion\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 633, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "for a previous keyword suggestion"); |
634 | return Result; |
635 | } |
636 | |
637 | |
638 | |
639 | |
640 | |
641 | |
642 | |
643 | |
644 | |
645 | |
646 | |
647 | |
648 | |
649 | |
650 | |
651 | |
652 | |
653 | |
654 | |
655 | |
656 | |
657 | |
658 | |
659 | |
660 | |
661 | |
662 | |
663 | |
664 | |
665 | |
666 | |
667 | |
668 | |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | |
676 | ExprResult Parser::ParseLambdaExpression() { |
677 | |
678 | LambdaIntroducer Intro; |
679 | Optional<unsigned> DiagID = ParseLambdaIntroducer(Intro); |
680 | if (DiagID) { |
681 | Diag(Tok, DiagID.getValue()); |
682 | SkipUntil(tok::r_square, StopAtSemi); |
683 | SkipUntil(tok::l_brace, StopAtSemi); |
684 | SkipUntil(tok::r_brace, StopAtSemi); |
685 | return ExprError(); |
686 | } |
687 | |
688 | return ParseLambdaExpressionAfterIntroducer(Intro); |
689 | } |
690 | |
691 | |
692 | |
693 | |
694 | |
695 | |
696 | ExprResult Parser::TryParseLambdaExpression() { |
697 | (0) . __assert_fail ("getLangOpts().CPlusPlus11 && Tok.is(tok..l_square) && \"Not at the start of a possible lambda expression.\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 699, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getLangOpts().CPlusPlus11 |
698 | (0) . __assert_fail ("getLangOpts().CPlusPlus11 && Tok.is(tok..l_square) && \"Not at the start of a possible lambda expression.\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 699, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && Tok.is(tok::l_square) |
699 | (0) . __assert_fail ("getLangOpts().CPlusPlus11 && Tok.is(tok..l_square) && \"Not at the start of a possible lambda expression.\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 699, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && "Not at the start of a possible lambda expression."); |
700 | |
701 | const Token Next = NextToken(); |
702 | if (Next.is(tok::eof)) |
703 | return ExprEmpty(); |
704 | |
705 | const Token After = GetLookAheadToken(2); |
706 | |
707 | if (Next.is(tok::r_square) || |
708 | Next.is(tok::equal) || |
709 | (Next.is(tok::amp) && |
710 | (After.is(tok::r_square) || |
711 | After.is(tok::comma))) || |
712 | (Next.is(tok::identifier) && |
713 | After.is(tok::r_square))) { |
714 | return ParseLambdaExpression(); |
715 | } |
716 | |
717 | |
718 | |
719 | if (Next.is(tok::identifier) && After.is(tok::identifier)) { |
720 | return ExprEmpty(); |
721 | } |
722 | |
723 | |
724 | |
725 | |
726 | |
727 | |
728 | |
729 | LambdaIntroducer Intro; |
730 | if (TryParseLambdaIntroducer(Intro)) |
731 | return ExprEmpty(); |
732 | |
733 | return ParseLambdaExpressionAfterIntroducer(Intro); |
734 | } |
735 | |
736 | |
737 | |
738 | |
739 | |
740 | |
741 | |
742 | |
743 | |
744 | |
745 | Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, |
746 | bool *SkippedInits) { |
747 | typedef Optional<unsigned> DiagResult; |
748 | |
749 | (0) . __assert_fail ("Tok.is(tok..l_square) && \"Lambda expressions begin with '['.\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 749, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_square) && "Lambda expressions begin with '['."); |
750 | BalancedDelimiterTracker T(*this, tok::l_square); |
751 | T.consumeOpen(); |
752 | |
753 | Intro.Range.setBegin(T.getOpenLocation()); |
754 | |
755 | bool first = true; |
756 | |
757 | |
758 | if (Tok.is(tok::amp) && |
759 | (NextToken().is(tok::comma) || NextToken().is(tok::r_square))) { |
760 | Intro.Default = LCD_ByRef; |
761 | Intro.DefaultLoc = ConsumeToken(); |
762 | first = false; |
763 | } else if (Tok.is(tok::equal)) { |
764 | Intro.Default = LCD_ByCopy; |
765 | Intro.DefaultLoc = ConsumeToken(); |
766 | first = false; |
767 | } |
768 | |
769 | while (Tok.isNot(tok::r_square)) { |
770 | if (!first) { |
771 | if (Tok.isNot(tok::comma)) { |
772 | |
773 | |
774 | |
775 | |
776 | if (Tok.is(tok::code_completion) && |
777 | !(getLangOpts().ObjC && Intro.Default == LCD_None && |
778 | !Intro.Captures.empty())) { |
779 | Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, |
780 | ); |
781 | cutOffParsing(); |
782 | break; |
783 | } |
784 | |
785 | return DiagResult(diag::err_expected_comma_or_rsquare); |
786 | } |
787 | ConsumeToken(); |
788 | } |
789 | |
790 | if (Tok.is(tok::code_completion)) { |
791 | |
792 | |
793 | if (getLangOpts().ObjC && first) |
794 | Actions.CodeCompleteObjCMessageReceiver(getCurScope()); |
795 | else |
796 | Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, |
797 | ); |
798 | cutOffParsing(); |
799 | break; |
800 | } |
801 | |
802 | first = false; |
803 | |
804 | |
805 | LambdaCaptureKind Kind = LCK_ByCopy; |
806 | LambdaCaptureInitKind InitKind = LambdaCaptureInitKind::NoInit; |
807 | SourceLocation Loc; |
808 | IdentifierInfo *Id = nullptr; |
809 | SourceLocation EllipsisLoc; |
810 | ExprResult Init; |
811 | SourceLocation LocStart = Tok.getLocation(); |
812 | |
813 | if (Tok.is(tok::star)) { |
814 | Loc = ConsumeToken(); |
815 | if (Tok.is(tok::kw_this)) { |
816 | ConsumeToken(); |
817 | Kind = LCK_StarThis; |
818 | } else { |
819 | return DiagResult(diag::err_expected_star_this_capture); |
820 | } |
821 | } else if (Tok.is(tok::kw_this)) { |
822 | Kind = LCK_This; |
823 | Loc = ConsumeToken(); |
824 | } else { |
825 | if (Tok.is(tok::amp)) { |
826 | Kind = LCK_ByRef; |
827 | ConsumeToken(); |
828 | |
829 | if (Tok.is(tok::code_completion)) { |
830 | Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, |
831 | ); |
832 | cutOffParsing(); |
833 | break; |
834 | } |
835 | } |
836 | |
837 | if (Tok.is(tok::identifier)) { |
838 | Id = Tok.getIdentifierInfo(); |
839 | Loc = ConsumeToken(); |
840 | } else if (Tok.is(tok::kw_this)) { |
841 | |
842 | |
843 | |
844 | return DiagResult(diag::err_this_captured_by_reference); |
845 | } else { |
846 | return DiagResult(diag::err_expected_capture); |
847 | } |
848 | |
849 | if (Tok.is(tok::l_paren)) { |
850 | BalancedDelimiterTracker Parens(*this, tok::l_paren); |
851 | Parens.consumeOpen(); |
852 | |
853 | InitKind = LambdaCaptureInitKind::DirectInit; |
854 | |
855 | ExprVector Exprs; |
856 | CommaLocsTy Commas; |
857 | if (SkippedInits) { |
858 | Parens.skipToEnd(); |
859 | *SkippedInits = true; |
860 | } else if (ParseExpressionList(Exprs, Commas)) { |
861 | Parens.skipToEnd(); |
862 | Init = ExprError(); |
863 | } else { |
864 | Parens.consumeClose(); |
865 | Init = Actions.ActOnParenListExpr(Parens.getOpenLocation(), |
866 | Parens.getCloseLocation(), |
867 | Exprs); |
868 | } |
869 | } else if (Tok.isOneOf(tok::l_brace, tok::equal)) { |
870 | |
871 | |
872 | |
873 | EnterExpressionEvaluationContext EC( |
874 | Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
875 | |
876 | if (TryConsumeToken(tok::equal)) |
877 | InitKind = LambdaCaptureInitKind::CopyInit; |
878 | else |
879 | InitKind = LambdaCaptureInitKind::ListInit; |
880 | |
881 | if (!SkippedInits) { |
882 | Init = ParseInitializer(); |
883 | } else if (Tok.is(tok::l_brace)) { |
884 | BalancedDelimiterTracker Braces(*this, tok::l_brace); |
885 | Braces.consumeOpen(); |
886 | Braces.skipToEnd(); |
887 | *SkippedInits = true; |
888 | } else { |
889 | |
890 | |
891 | |
892 | |
893 | |
894 | |
895 | |
896 | |
897 | |
898 | |
899 | |
900 | |
901 | |
902 | |
903 | |
904 | |
905 | |
906 | |
907 | |
908 | |
909 | SourceLocation StartLoc = Tok.getLocation(); |
910 | InMessageExpressionRAIIObject MaybeInMessageExpression(*this, true); |
911 | Init = ParseInitializer(); |
912 | if (!Init.isInvalid()) |
913 | Init = Actions.CorrectDelayedTyposInExpr(Init.get()); |
914 | |
915 | if (Tok.getLocation() != StartLoc) { |
916 | |
917 | PP.RevertCachedTokens(1); |
918 | |
919 | |
920 | Tok.setLocation(StartLoc); |
921 | Tok.setKind(tok::annot_primary_expr); |
922 | setExprAnnotation(Tok, Init); |
923 | Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation()); |
924 | PP.AnnotateCachedTokens(Tok); |
925 | |
926 | |
927 | ConsumeAnnotationToken(); |
928 | } |
929 | } |
930 | } else |
931 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
932 | } |
933 | |
934 | |
935 | |
936 | |
937 | |
938 | |
939 | |
940 | |
941 | |
942 | |
943 | |
944 | |
945 | |
946 | |
947 | |
948 | |
949 | |
950 | |
951 | |
952 | |
953 | |
954 | |
955 | |
956 | |
957 | |
958 | |
959 | |
960 | |
961 | |
962 | |
963 | |
964 | |
965 | |
966 | |
967 | |
968 | |
969 | |
970 | |
971 | |
972 | ParsedType InitCaptureType; |
973 | if (!Init.isInvalid()) |
974 | Init = Actions.CorrectDelayedTyposInExpr(Init.get()); |
975 | if (Init.isUsable()) { |
976 | |
977 | |
978 | Expr *InitExpr = Init.get(); |
979 | |
980 | |
981 | InitCaptureType = Actions.actOnLambdaInitCaptureInitialization( |
982 | Loc, Kind == LCK_ByRef, Id, InitKind, InitExpr); |
983 | Init = InitExpr; |
984 | } |
985 | |
986 | SourceLocation LocEnd = PrevTokLocation; |
987 | |
988 | Intro.addCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init, |
989 | InitCaptureType, SourceRange(LocStart, LocEnd)); |
990 | } |
991 | |
992 | T.consumeClose(); |
993 | Intro.Range.setEnd(T.getCloseLocation()); |
994 | return DiagResult(); |
995 | } |
996 | |
997 | |
998 | |
999 | |
1000 | bool Parser::TryParseLambdaIntroducer(LambdaIntroducer &Intro) { |
1001 | { |
1002 | bool SkippedInits = false; |
1003 | TentativeParsingAction PA1(*this); |
1004 | |
1005 | if (ParseLambdaIntroducer(Intro, &SkippedInits)) { |
1006 | PA1.Revert(); |
1007 | return true; |
1008 | } |
1009 | |
1010 | if (!SkippedInits) { |
1011 | PA1.Commit(); |
1012 | return false; |
1013 | } |
1014 | |
1015 | PA1.Revert(); |
1016 | } |
1017 | |
1018 | |
1019 | Intro = LambdaIntroducer(); |
1020 | TentativeParsingAction PA2(*this); |
1021 | |
1022 | if (!ParseLambdaIntroducer(Intro)) { |
1023 | PA2.Commit(); |
1024 | return false; |
1025 | } |
1026 | |
1027 | PA2.Revert(); |
1028 | return true; |
1029 | } |
1030 | |
1031 | static void |
1032 | tryConsumeMutableOrConstexprToken(Parser &P, SourceLocation &MutableLoc, |
1033 | SourceLocation &ConstexprLoc, |
1034 | SourceLocation &DeclEndLoc) { |
1035 | assert(MutableLoc.isInvalid()); |
1036 | assert(ConstexprLoc.isInvalid()); |
1037 | |
1038 | |
1039 | |
1040 | |
1041 | while (true) { |
1042 | switch (P.getCurToken().getKind()) { |
1043 | case tok::kw_mutable: { |
1044 | if (MutableLoc.isValid()) { |
1045 | P.Diag(P.getCurToken().getLocation(), |
1046 | diag::err_lambda_decl_specifier_repeated) |
1047 | << 0 << FixItHint::CreateRemoval(P.getCurToken().getLocation()); |
1048 | } |
1049 | MutableLoc = P.ConsumeToken(); |
1050 | DeclEndLoc = MutableLoc; |
1051 | break ; |
1052 | } |
1053 | case tok::kw_constexpr: |
1054 | if (ConstexprLoc.isValid()) { |
1055 | P.Diag(P.getCurToken().getLocation(), |
1056 | diag::err_lambda_decl_specifier_repeated) |
1057 | << 1 << FixItHint::CreateRemoval(P.getCurToken().getLocation()); |
1058 | } |
1059 | ConstexprLoc = P.ConsumeToken(); |
1060 | DeclEndLoc = ConstexprLoc; |
1061 | break ; |
1062 | default: |
1063 | return; |
1064 | } |
1065 | } |
1066 | } |
1067 | |
1068 | static void |
1069 | addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, |
1070 | DeclSpec &DS) { |
1071 | if (ConstexprLoc.isValid()) { |
1072 | P.Diag(ConstexprLoc, !P.getLangOpts().CPlusPlus17 |
1073 | ? diag::ext_constexpr_on_lambda_cxx17 |
1074 | : diag::warn_cxx14_compat_constexpr_on_lambda); |
1075 | const char *PrevSpec = nullptr; |
1076 | unsigned DiagID = 0; |
1077 | DS.SetConstexprSpec(ConstexprLoc, PrevSpec, DiagID); |
1078 | (0) . __assert_fail ("PrevSpec == nullptr && DiagID == 0 && \"Constexpr cannot have been set previously!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1079, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PrevSpec == nullptr && DiagID == 0 && |
1079 | (0) . __assert_fail ("PrevSpec == nullptr && DiagID == 0 && \"Constexpr cannot have been set previously!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1079, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Constexpr cannot have been set previously!"); |
1080 | } |
1081 | } |
1082 | |
1083 | |
1084 | |
1085 | ExprResult Parser::ParseLambdaExpressionAfterIntroducer( |
1086 | LambdaIntroducer &Intro) { |
1087 | SourceLocation LambdaBeginLoc = Intro.Range.getBegin(); |
1088 | Diag(LambdaBeginLoc, diag::warn_cxx98_compat_lambda); |
1089 | |
1090 | PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc, |
1091 | "lambda expression parsing"); |
1092 | |
1093 | |
1094 | |
1095 | |
1096 | |
1097 | |
1098 | |
1099 | DeclSpec DS(AttrFactory); |
1100 | Declarator D(DS, DeclaratorContext::LambdaExprContext); |
1101 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
1102 | Actions.PushLambdaScope(); |
1103 | |
1104 | ParsedAttributes Attr(AttrFactory); |
1105 | SourceLocation DeclLoc = Tok.getLocation(); |
1106 | if (getLangOpts().CUDA) { |
1107 | |
1108 | |
1109 | MaybeParseGNUAttributes(D); |
1110 | } |
1111 | |
1112 | |
1113 | |
1114 | auto WarnIfHasCUDATargetAttr = [&] { |
1115 | if (getLangOpts().CUDA) |
1116 | for (const ParsedAttr &A : Attr) |
1117 | if (A.getKind() == ParsedAttr::AT_CUDADevice || |
1118 | A.getKind() == ParsedAttr::AT_CUDAHost || |
1119 | A.getKind() == ParsedAttr::AT_CUDAGlobal) |
1120 | Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position) |
1121 | << A.getName()->getName(); |
1122 | }; |
1123 | |
1124 | TypeResult TrailingReturnType; |
1125 | if (Tok.is(tok::l_paren)) { |
1126 | ParseScope PrototypeScope(this, |
1127 | Scope::FunctionPrototypeScope | |
1128 | Scope::FunctionDeclarationScope | |
1129 | Scope::DeclScope); |
1130 | |
1131 | BalancedDelimiterTracker T(*this, tok::l_paren); |
1132 | T.consumeOpen(); |
1133 | SourceLocation LParenLoc = T.getOpenLocation(); |
1134 | |
1135 | |
1136 | SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo; |
1137 | SourceLocation EllipsisLoc; |
1138 | |
1139 | if (Tok.isNot(tok::r_paren)) { |
1140 | Actions.RecordParsingTemplateParameterDepth(TemplateParameterDepth); |
1141 | ParseParameterDeclarationClause(D, Attr, ParamInfo, EllipsisLoc); |
1142 | |
1143 | |
1144 | if (Actions.getCurGenericLambda()) |
1145 | ++CurTemplateDepthTracker; |
1146 | } |
1147 | T.consumeClose(); |
1148 | SourceLocation RParenLoc = T.getCloseLocation(); |
1149 | SourceLocation DeclEndLoc = RParenLoc; |
1150 | |
1151 | |
1152 | |
1153 | MaybeParseGNUAttributes(Attr, &DeclEndLoc); |
1154 | |
1155 | |
1156 | |
1157 | MaybeParseMicrosoftDeclSpecs(Attr, &DeclEndLoc); |
1158 | |
1159 | |
1160 | SourceLocation MutableLoc; |
1161 | SourceLocation ConstexprLoc; |
1162 | tryConsumeMutableOrConstexprToken(*this, MutableLoc, ConstexprLoc, |
1163 | DeclEndLoc); |
1164 | |
1165 | addConstexprToLambdaDeclSpecifier(*this, ConstexprLoc, DS); |
1166 | |
1167 | |
1168 | ExceptionSpecificationType ESpecType = EST_None; |
1169 | SourceRange ESpecRange; |
1170 | SmallVector<ParsedType, 2> DynamicExceptions; |
1171 | SmallVector<SourceRange, 2> DynamicExceptionRanges; |
1172 | ExprResult NoexceptExpr; |
1173 | CachedTokens *ExceptionSpecTokens; |
1174 | ESpecType = tryParseExceptionSpecification(, |
1175 | ESpecRange, |
1176 | DynamicExceptions, |
1177 | DynamicExceptionRanges, |
1178 | NoexceptExpr, |
1179 | ExceptionSpecTokens); |
1180 | |
1181 | if (ESpecType != EST_None) |
1182 | DeclEndLoc = ESpecRange.getEnd(); |
1183 | |
1184 | |
1185 | MaybeParseCXX11Attributes(Attr, &DeclEndLoc); |
1186 | |
1187 | SourceLocation FunLocalRangeEnd = DeclEndLoc; |
1188 | |
1189 | |
1190 | if (Tok.is(tok::arrow)) { |
1191 | FunLocalRangeEnd = Tok.getLocation(); |
1192 | SourceRange Range; |
1193 | TrailingReturnType = |
1194 | ParseTrailingReturnType(Range, false); |
1195 | if (Range.getEnd().isValid()) |
1196 | DeclEndLoc = Range.getEnd(); |
1197 | } |
1198 | |
1199 | PrototypeScope.Exit(); |
1200 | |
1201 | WarnIfHasCUDATargetAttr(); |
1202 | |
1203 | SourceLocation NoLoc; |
1204 | D.AddTypeInfo(DeclaratorChunk::getFunction( |
1205 | , |
1206 | , LParenLoc, ParamInfo.data(), |
1207 | ParamInfo.size(), EllipsisLoc, RParenLoc, |
1208 | , |
1209 | NoLoc, MutableLoc, ESpecType, |
1210 | ESpecRange, DynamicExceptions.data(), |
1211 | DynamicExceptionRanges.data(), DynamicExceptions.size(), |
1212 | NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr, |
1213 | nullptr, |
1214 | None, LParenLoc, FunLocalRangeEnd, D, |
1215 | TrailingReturnType), |
1216 | std::move(Attr), DeclEndLoc); |
1217 | } else if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute, |
1218 | tok::kw_constexpr) || |
1219 | (Tok.is(tok::l_square) && NextToken().is(tok::l_square))) { |
1220 | |
1221 | |
1222 | unsigned TokKind = 0; |
1223 | switch (Tok.getKind()) { |
1224 | case tok::kw_mutable: TokKind = 0; break; |
1225 | case tok::arrow: TokKind = 1; break; |
1226 | case tok::kw___attribute: |
1227 | case tok::l_square: TokKind = 2; break; |
1228 | case tok::kw_constexpr: TokKind = 3; break; |
1229 | default: llvm_unreachable("Unknown token kind"); |
1230 | } |
1231 | |
1232 | Diag(Tok, diag::err_lambda_missing_parens) |
1233 | << TokKind |
1234 | << FixItHint::CreateInsertion(Tok.getLocation(), "() "); |
1235 | SourceLocation DeclEndLoc = DeclLoc; |
1236 | |
1237 | |
1238 | |
1239 | MaybeParseGNUAttributes(Attr, &DeclEndLoc); |
1240 | |
1241 | |
1242 | SourceLocation MutableLoc; |
1243 | if (Tok.is(tok::kw_mutable)) { |
1244 | MutableLoc = ConsumeToken(); |
1245 | DeclEndLoc = MutableLoc; |
1246 | } |
1247 | |
1248 | |
1249 | MaybeParseCXX11Attributes(Attr, &DeclEndLoc); |
1250 | |
1251 | |
1252 | if (Tok.is(tok::arrow)) { |
1253 | SourceRange Range; |
1254 | TrailingReturnType = |
1255 | ParseTrailingReturnType(Range, false); |
1256 | if (Range.getEnd().isValid()) |
1257 | DeclEndLoc = Range.getEnd(); |
1258 | } |
1259 | |
1260 | WarnIfHasCUDATargetAttr(); |
1261 | |
1262 | SourceLocation NoLoc; |
1263 | D.AddTypeInfo(DeclaratorChunk::getFunction( |
1264 | , |
1265 | , |
1266 | NoLoc, |
1267 | , |
1268 | , |
1269 | NoLoc, |
1270 | NoLoc, |
1271 | , |
1272 | NoLoc, MutableLoc, EST_None, |
1273 | SourceRange(), |
1274 | , |
1275 | , |
1276 | , |
1277 | , |
1278 | , |
1279 | None, DeclLoc, DeclEndLoc, D, |
1280 | TrailingReturnType), |
1281 | std::move(Attr), DeclEndLoc); |
1282 | } |
1283 | |
1284 | |
1285 | |
1286 | unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope | |
1287 | Scope::CompoundStmtScope; |
1288 | ParseScope BodyScope(this, ScopeFlags); |
1289 | |
1290 | Actions.ActOnStartOfLambdaDefinition(Intro, D, getCurScope()); |
1291 | |
1292 | |
1293 | if (!Tok.is(tok::l_brace)) { |
1294 | Diag(Tok, diag::err_expected_lambda_body); |
1295 | Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); |
1296 | return ExprError(); |
1297 | } |
1298 | |
1299 | StmtResult Stmt(ParseCompoundStatementBody()); |
1300 | BodyScope.Exit(); |
1301 | |
1302 | if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid()) |
1303 | return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get(), getCurScope()); |
1304 | |
1305 | Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); |
1306 | return ExprError(); |
1307 | } |
1308 | |
1309 | |
1310 | |
1311 | |
1312 | |
1313 | |
1314 | |
1315 | |
1316 | |
1317 | |
1318 | ExprResult Parser::ParseCXXCasts() { |
1319 | tok::TokenKind Kind = Tok.getKind(); |
1320 | const char *CastName = nullptr; |
1321 | |
1322 | switch (Kind) { |
1323 | default: llvm_unreachable("Unknown C++ cast!"); |
1324 | case tok::kw_const_cast: CastName = "const_cast"; break; |
1325 | case tok::kw_dynamic_cast: CastName = "dynamic_cast"; break; |
1326 | case tok::kw_reinterpret_cast: CastName = "reinterpret_cast"; break; |
1327 | case tok::kw_static_cast: CastName = "static_cast"; break; |
1328 | } |
1329 | |
1330 | SourceLocation OpLoc = ConsumeToken(); |
1331 | SourceLocation LAngleBracketLoc = Tok.getLocation(); |
1332 | |
1333 | |
1334 | |
1335 | if (Tok.is(tok::l_square) && Tok.getLength() == 2) { |
1336 | Token Next = NextToken(); |
1337 | if (Next.is(tok::colon) && areTokensAdjacent(Tok, Next)) |
1338 | FixDigraph(*this, PP, Tok, Next, Kind, ); |
1339 | } |
1340 | |
1341 | if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName)) |
1342 | return ExprError(); |
1343 | |
1344 | |
1345 | DeclSpec DS(AttrFactory); |
1346 | ParseSpecifierQualifierList(DS); |
1347 | |
1348 | |
1349 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); |
1350 | ParseDeclarator(DeclaratorInfo); |
1351 | |
1352 | SourceLocation RAngleBracketLoc = Tok.getLocation(); |
1353 | |
1354 | if (ExpectAndConsume(tok::greater)) |
1355 | return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << tok::less); |
1356 | |
1357 | BalancedDelimiterTracker T(*this, tok::l_paren); |
1358 | |
1359 | if (T.expectAndConsume(diag::err_expected_lparen_after, CastName)) |
1360 | return ExprError(); |
1361 | |
1362 | ExprResult Result = ParseExpression(); |
1363 | |
1364 | |
1365 | T.consumeClose(); |
1366 | |
1367 | if (!Result.isInvalid() && !DeclaratorInfo.isInvalidType()) |
1368 | Result = Actions.ActOnCXXNamedCast(OpLoc, Kind, |
1369 | LAngleBracketLoc, DeclaratorInfo, |
1370 | RAngleBracketLoc, |
1371 | T.getOpenLocation(), Result.get(), |
1372 | T.getCloseLocation()); |
1373 | |
1374 | return Result; |
1375 | } |
1376 | |
1377 | |
1378 | |
1379 | |
1380 | |
1381 | |
1382 | |
1383 | ExprResult Parser::ParseCXXTypeid() { |
1384 | (0) . __assert_fail ("Tok.is(tok..kw_typeid) && \"Not 'typeid'!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1384, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_typeid) && "Not 'typeid'!"); |
1385 | |
1386 | SourceLocation OpLoc = ConsumeToken(); |
1387 | SourceLocation LParenLoc, RParenLoc; |
1388 | BalancedDelimiterTracker T(*this, tok::l_paren); |
1389 | |
1390 | |
1391 | if (T.expectAndConsume(diag::err_expected_lparen_after, "typeid")) |
1392 | return ExprError(); |
1393 | LParenLoc = T.getOpenLocation(); |
1394 | |
1395 | ExprResult Result; |
1396 | |
1397 | |
1398 | |
1399 | |
1400 | |
1401 | |
1402 | |
1403 | |
1404 | |
1405 | |
1406 | |
1407 | |
1408 | |
1409 | |
1410 | EnterExpressionEvaluationContext Unevaluated( |
1411 | Actions, Sema::ExpressionEvaluationContext::Unevaluated, |
1412 | Sema::ReuseLambdaContextDecl); |
1413 | |
1414 | if (isTypeIdInParens()) { |
1415 | TypeResult Ty = ParseTypeName(); |
1416 | |
1417 | |
1418 | T.consumeClose(); |
1419 | RParenLoc = T.getCloseLocation(); |
1420 | if (Ty.isInvalid() || RParenLoc.isInvalid()) |
1421 | return ExprError(); |
1422 | |
1423 | Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, , |
1424 | Ty.get().getAsOpaquePtr(), RParenLoc); |
1425 | } else { |
1426 | Result = ParseExpression(); |
1427 | |
1428 | |
1429 | if (Result.isInvalid()) |
1430 | SkipUntil(tok::r_paren, StopAtSemi); |
1431 | else { |
1432 | T.consumeClose(); |
1433 | RParenLoc = T.getCloseLocation(); |
1434 | if (RParenLoc.isInvalid()) |
1435 | return ExprError(); |
1436 | |
1437 | Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, , |
1438 | Result.get(), RParenLoc); |
1439 | } |
1440 | } |
1441 | |
1442 | return Result; |
1443 | } |
1444 | |
1445 | |
1446 | |
1447 | |
1448 | |
1449 | |
1450 | ExprResult Parser::ParseCXXUuidof() { |
1451 | (0) . __assert_fail ("Tok.is(tok..kw___uuidof) && \"Not '__uuidof'!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1451, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw___uuidof) && "Not '__uuidof'!"); |
1452 | |
1453 | SourceLocation OpLoc = ConsumeToken(); |
1454 | BalancedDelimiterTracker T(*this, tok::l_paren); |
1455 | |
1456 | |
1457 | if (T.expectAndConsume(diag::err_expected_lparen_after, "__uuidof")) |
1458 | return ExprError(); |
1459 | |
1460 | ExprResult Result; |
1461 | |
1462 | if (isTypeIdInParens()) { |
1463 | TypeResult Ty = ParseTypeName(); |
1464 | |
1465 | |
1466 | T.consumeClose(); |
1467 | |
1468 | if (Ty.isInvalid()) |
1469 | return ExprError(); |
1470 | |
1471 | Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), , |
1472 | Ty.get().getAsOpaquePtr(), |
1473 | T.getCloseLocation()); |
1474 | } else { |
1475 | EnterExpressionEvaluationContext Unevaluated( |
1476 | Actions, Sema::ExpressionEvaluationContext::Unevaluated); |
1477 | Result = ParseExpression(); |
1478 | |
1479 | |
1480 | if (Result.isInvalid()) |
1481 | SkipUntil(tok::r_paren, StopAtSemi); |
1482 | else { |
1483 | T.consumeClose(); |
1484 | |
1485 | Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), |
1486 | , |
1487 | Result.get(), T.getCloseLocation()); |
1488 | } |
1489 | } |
1490 | |
1491 | return Result; |
1492 | } |
1493 | |
1494 | |
1495 | |
1496 | |
1497 | |
1498 | |
1499 | |
1500 | |
1501 | |
1502 | |
1503 | |
1504 | |
1505 | |
1506 | |
1507 | |
1508 | ExprResult |
1509 | Parser::ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc, |
1510 | tok::TokenKind OpKind, |
1511 | CXXScopeSpec &SS, |
1512 | ParsedType ObjectType) { |
1513 | |
1514 | |
1515 | |
1516 | |
1517 | |
1518 | |
1519 | |
1520 | |
1521 | UnqualifiedId FirstTypeName; |
1522 | SourceLocation CCLoc; |
1523 | if (Tok.is(tok::identifier)) { |
1524 | FirstTypeName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); |
1525 | ConsumeToken(); |
1526 | (0) . __assert_fail ("Tok.is(tok..coloncolon) &&\"ParseOptionalCXXScopeSpecifier fail\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1526, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail"); |
1527 | CCLoc = ConsumeToken(); |
1528 | } else if (Tok.is(tok::annot_template_id)) { |
1529 | |
1530 | |
1531 | FirstTypeName.setTemplateId( |
1532 | (TemplateIdAnnotation *)Tok.getAnnotationValue()); |
1533 | ConsumeAnnotationToken(); |
1534 | (0) . __assert_fail ("Tok.is(tok..coloncolon) &&\"ParseOptionalCXXScopeSpecifier fail\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1534, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail"); |
1535 | CCLoc = ConsumeToken(); |
1536 | } else { |
1537 | FirstTypeName.setIdentifier(nullptr, SourceLocation()); |
1538 | } |
1539 | |
1540 | |
1541 | (0) . __assert_fail ("Tok.is(tok..tilde) && \"ParseOptionalCXXScopeSpecifier fail\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1541, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::tilde) && "ParseOptionalCXXScopeSpecifier fail"); |
1542 | SourceLocation TildeLoc = ConsumeToken(); |
1543 | |
1544 | if (Tok.is(tok::kw_decltype) && !FirstTypeName.isValid() && SS.isEmpty()) { |
1545 | DeclSpec DS(AttrFactory); |
1546 | ParseDecltypeSpecifier(DS); |
1547 | if (DS.getTypeSpecType() == TST_error) |
1548 | return ExprError(); |
1549 | return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, OpKind, |
1550 | TildeLoc, DS); |
1551 | } |
1552 | |
1553 | if (!Tok.is(tok::identifier)) { |
1554 | Diag(Tok, diag::err_destructor_tilde_identifier); |
1555 | return ExprError(); |
1556 | } |
1557 | |
1558 | |
1559 | UnqualifiedId SecondTypeName; |
1560 | IdentifierInfo *Name = Tok.getIdentifierInfo(); |
1561 | SourceLocation NameLoc = ConsumeToken(); |
1562 | SecondTypeName.setIdentifier(Name, NameLoc); |
1563 | |
1564 | |
1565 | |
1566 | if (Tok.is(tok::less) && |
1567 | ParseUnqualifiedIdTemplateId(SS, SourceLocation(), |
1568 | Name, NameLoc, |
1569 | false, ObjectType, SecondTypeName, |
1570 | )) |
1571 | return ExprError(); |
1572 | |
1573 | return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, OpKind, |
1574 | SS, FirstTypeName, CCLoc, TildeLoc, |
1575 | SecondTypeName); |
1576 | } |
1577 | |
1578 | |
1579 | |
1580 | |
1581 | |
1582 | |
1583 | ExprResult Parser::ParseCXXBoolLiteral() { |
1584 | tok::TokenKind Kind = Tok.getKind(); |
1585 | return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind); |
1586 | } |
1587 | |
1588 | |
1589 | |
1590 | |
1591 | |
1592 | ExprResult Parser::ParseThrowExpression() { |
1593 | (0) . __assert_fail ("Tok.is(tok..kw_throw) && \"Not throw!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1593, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_throw) && "Not throw!"); |
1594 | SourceLocation ThrowLoc = ConsumeToken(); |
1595 | |
1596 | |
1597 | |
1598 | |
1599 | switch (Tok.getKind()) { |
1600 | case tok::semi: |
1601 | case tok::r_paren: |
1602 | case tok::r_square: |
1603 | case tok::r_brace: |
1604 | case tok::colon: |
1605 | case tok::comma: |
1606 | return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, nullptr); |
1607 | |
1608 | default: |
1609 | ExprResult Expr(ParseAssignmentExpression()); |
1610 | if (Expr.isInvalid()) return Expr; |
1611 | return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, Expr.get()); |
1612 | } |
1613 | } |
1614 | |
1615 | |
1616 | |
1617 | |
1618 | |
1619 | ExprResult Parser::ParseCoyieldExpression() { |
1620 | (0) . __assert_fail ("Tok.is(tok..kw_co_yield) && \"Not co_yield!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1620, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_co_yield) && "Not co_yield!"); |
1621 | |
1622 | SourceLocation Loc = ConsumeToken(); |
1623 | ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer() |
1624 | : ParseAssignmentExpression(); |
1625 | if (!Expr.isInvalid()) |
1626 | Expr = Actions.ActOnCoyieldExpr(getCurScope(), Loc, Expr.get()); |
1627 | return Expr; |
1628 | } |
1629 | |
1630 | |
1631 | |
1632 | |
1633 | |
1634 | |
1635 | ExprResult Parser::ParseCXXThis() { |
1636 | (0) . __assert_fail ("Tok.is(tok..kw_this) && \"Not 'this'!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1636, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_this) && "Not 'this'!"); |
1637 | SourceLocation ThisLoc = ConsumeToken(); |
1638 | return Actions.ActOnCXXThis(ThisLoc); |
1639 | } |
1640 | |
1641 | |
1642 | |
1643 | |
1644 | |
1645 | |
1646 | |
1647 | |
1648 | |
1649 | |
1650 | |
1651 | |
1652 | |
1653 | |
1654 | ExprResult |
1655 | Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { |
1656 | Declarator DeclaratorInfo(DS, DeclaratorContext::FunctionalCastContext); |
1657 | ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get(); |
1658 | |
1659 | (0) . __assert_fail ("(Tok.is(tok..l_paren) || (getLangOpts().CPlusPlus11 && Tok.is(tok..l_brace))) && \"Expected '(' or '{'!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1661, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((Tok.is(tok::l_paren) || |
1660 | (0) . __assert_fail ("(Tok.is(tok..l_paren) || (getLangOpts().CPlusPlus11 && Tok.is(tok..l_brace))) && \"Expected '(' or '{'!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1661, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))) |
1661 | (0) . __assert_fail ("(Tok.is(tok..l_paren) || (getLangOpts().CPlusPlus11 && Tok.is(tok..l_brace))) && \"Expected '(' or '{'!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1661, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && "Expected '(' or '{'!"); |
1662 | |
1663 | if (Tok.is(tok::l_brace)) { |
1664 | ExprResult Init = ParseBraceInitializer(); |
1665 | if (Init.isInvalid()) |
1666 | return Init; |
1667 | Expr *InitList = Init.get(); |
1668 | return Actions.ActOnCXXTypeConstructExpr( |
1669 | TypeRep, InitList->getBeginLoc(), MultiExprArg(&InitList, 1), |
1670 | InitList->getEndLoc(), ); |
1671 | } else { |
1672 | BalancedDelimiterTracker T(*this, tok::l_paren); |
1673 | T.consumeOpen(); |
1674 | |
1675 | PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.get()); |
1676 | |
1677 | ExprVector Exprs; |
1678 | CommaLocsTy CommaLocs; |
1679 | |
1680 | auto RunSignatureHelp = [&]() { |
1681 | QualType PreferredType = Actions.ProduceConstructorSignatureHelp( |
1682 | getCurScope(), TypeRep.get()->getCanonicalTypeInternal(), |
1683 | DS.getEndLoc(), Exprs, T.getOpenLocation()); |
1684 | CalledSignatureHelp = true; |
1685 | return PreferredType; |
1686 | }; |
1687 | |
1688 | if (Tok.isNot(tok::r_paren)) { |
1689 | if (ParseExpressionList(Exprs, CommaLocs, [&] { |
1690 | PreferredType.enterFunctionArgument(Tok.getLocation(), |
1691 | RunSignatureHelp); |
1692 | })) { |
1693 | if (PP.isCodeCompletionReached() && !CalledSignatureHelp) |
1694 | RunSignatureHelp(); |
1695 | SkipUntil(tok::r_paren, StopAtSemi); |
1696 | return ExprError(); |
1697 | } |
1698 | } |
1699 | |
1700 | |
1701 | T.consumeClose(); |
1702 | |
1703 | |
1704 | if (!TypeRep) |
1705 | return ExprError(); |
1706 | |
1707 | (0) . __assert_fail ("(Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&& \"Unexpected number of commas!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1708, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&& |
1708 | (0) . __assert_fail ("(Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&& \"Unexpected number of commas!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1708, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unexpected number of commas!"); |
1709 | return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(), |
1710 | Exprs, T.getCloseLocation(), |
1711 | ); |
1712 | } |
1713 | } |
1714 | |
1715 | |
1716 | |
1717 | |
1718 | |
1719 | |
1720 | |
1721 | |
1722 | |
1723 | |
1724 | |
1725 | |
1726 | |
1727 | |
1728 | |
1729 | |
1730 | |
1731 | |
1732 | |
1733 | |
1734 | |
1735 | |
1736 | |
1737 | |
1738 | |
1739 | |
1740 | Sema::ConditionResult Parser::ParseCXXCondition(StmtResult *InitStmt, |
1741 | SourceLocation Loc, |
1742 | Sema::ConditionKind CK, |
1743 | ForRangeInfo *FRI) { |
1744 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
1745 | PreferredType.enterCondition(Actions, Tok.getLocation()); |
1746 | |
1747 | if (Tok.is(tok::code_completion)) { |
1748 | Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Condition); |
1749 | cutOffParsing(); |
1750 | return Sema::ConditionError(); |
1751 | } |
1752 | |
1753 | ParsedAttributesWithRange attrs(AttrFactory); |
1754 | MaybeParseCXX11Attributes(attrs); |
1755 | |
1756 | const auto WarnOnInit = [this, &CK] { |
1757 | Diag(Tok.getLocation(), getLangOpts().CPlusPlus17 |
1758 | ? diag::warn_cxx14_compat_init_statement |
1759 | : diag::ext_init_statement) |
1760 | << (CK == Sema::ConditionKind::Switch); |
1761 | }; |
1762 | |
1763 | |
1764 | switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) { |
1765 | case ConditionOrInitStatement::Expression: { |
1766 | ProhibitAttributes(attrs); |
1767 | |
1768 | |
1769 | |
1770 | if (InitStmt && Tok.is(tok::semi)) { |
1771 | WarnOnInit(); |
1772 | SourceLocation SemiLoc = Tok.getLocation(); |
1773 | if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.isMacroID()) { |
1774 | Diag(SemiLoc, diag::warn_empty_init_statement) |
1775 | << (CK == Sema::ConditionKind::Switch) |
1776 | << FixItHint::CreateRemoval(SemiLoc); |
1777 | } |
1778 | ConsumeToken(); |
1779 | *InitStmt = Actions.ActOnNullStmt(SemiLoc); |
1780 | return ParseCXXCondition(nullptr, Loc, CK); |
1781 | } |
1782 | |
1783 | |
1784 | ExprResult Expr = ParseExpression(); |
1785 | if (Expr.isInvalid()) |
1786 | return Sema::ConditionError(); |
1787 | |
1788 | if (InitStmt && Tok.is(tok::semi)) { |
1789 | WarnOnInit(); |
1790 | *InitStmt = Actions.ActOnExprStmt(Expr.get()); |
1791 | ConsumeToken(); |
1792 | return ParseCXXCondition(nullptr, Loc, CK); |
1793 | } |
1794 | |
1795 | return Actions.ActOnCondition(getCurScope(), Loc, Expr.get(), CK); |
1796 | } |
1797 | |
1798 | case ConditionOrInitStatement::InitStmtDecl: { |
1799 | WarnOnInit(); |
1800 | SourceLocation DeclStart = Tok.getLocation(), DeclEnd; |
1801 | DeclGroupPtrTy DG = |
1802 | ParseSimpleDeclaration(DeclaratorContext::InitStmtContext, DeclEnd, |
1803 | attrs, ); |
1804 | *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd); |
1805 | return ParseCXXCondition(nullptr, Loc, CK); |
1806 | } |
1807 | |
1808 | case ConditionOrInitStatement::ForRangeDecl: { |
1809 | (0) . __assert_fail ("FRI && \"should not parse a for range declaration here\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 1809, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FRI && "should not parse a for range declaration here"); |
1810 | SourceLocation DeclStart = Tok.getLocation(), DeclEnd; |
1811 | DeclGroupPtrTy DG = ParseSimpleDeclaration( |
1812 | DeclaratorContext::ForContext, DeclEnd, attrs, false, FRI); |
1813 | FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation()); |
1814 | return Sema::ConditionResult(); |
1815 | } |
1816 | |
1817 | case ConditionOrInitStatement::ConditionDecl: |
1818 | case ConditionOrInitStatement::Error: |
1819 | break; |
1820 | } |
1821 | |
1822 | |
1823 | DeclSpec DS(AttrFactory); |
1824 | DS.takeAttributesFrom(attrs); |
1825 | ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_condition); |
1826 | |
1827 | |
1828 | Declarator DeclaratorInfo(DS, DeclaratorContext::ConditionContext); |
1829 | ParseDeclarator(DeclaratorInfo); |
1830 | |
1831 | |
1832 | if (Tok.is(tok::kw_asm)) { |
1833 | SourceLocation Loc; |
1834 | ExprResult AsmLabel(ParseSimpleAsm(&Loc)); |
1835 | if (AsmLabel.isInvalid()) { |
1836 | SkipUntil(tok::semi, StopAtSemi); |
1837 | return Sema::ConditionError(); |
1838 | } |
1839 | DeclaratorInfo.setAsmLabel(AsmLabel.get()); |
1840 | DeclaratorInfo.SetRangeEnd(Loc); |
1841 | } |
1842 | |
1843 | |
1844 | MaybeParseGNUAttributes(DeclaratorInfo); |
1845 | |
1846 | |
1847 | DeclResult Dcl = Actions.ActOnCXXConditionDeclaration(getCurScope(), |
1848 | DeclaratorInfo); |
1849 | if (Dcl.isInvalid()) |
1850 | return Sema::ConditionError(); |
1851 | Decl *DeclOut = Dcl.get(); |
1852 | |
1853 | |
1854 | |
1855 | bool CopyInitialization = isTokenEqualOrEqualTypo(); |
1856 | if (CopyInitialization) |
1857 | ConsumeToken(); |
1858 | |
1859 | ExprResult InitExpr = ExprError(); |
1860 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
1861 | Diag(Tok.getLocation(), |
1862 | diag::warn_cxx98_compat_generalized_initializer_lists); |
1863 | InitExpr = ParseBraceInitializer(); |
1864 | } else if (CopyInitialization) { |
1865 | PreferredType.enterVariableInit(Tok.getLocation(), DeclOut); |
1866 | InitExpr = ParseAssignmentExpression(); |
1867 | } else if (Tok.is(tok::l_paren)) { |
1868 | |
1869 | SourceLocation LParen = ConsumeParen(), RParen = LParen; |
1870 | if (SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch)) |
1871 | RParen = ConsumeParen(); |
1872 | Diag(DeclOut->getLocation(), |
1873 | diag::err_expected_init_in_condition_lparen) |
1874 | << SourceRange(LParen, RParen); |
1875 | } else { |
1876 | Diag(DeclOut->getLocation(), diag::err_expected_init_in_condition); |
1877 | } |
1878 | |
1879 | if (!InitExpr.isInvalid()) |
1880 | Actions.AddInitializerToDecl(DeclOut, InitExpr.get(), !CopyInitialization); |
1881 | else |
1882 | Actions.ActOnInitializerError(DeclOut); |
1883 | |
1884 | Actions.FinalizeDeclaration(DeclOut); |
1885 | return Actions.ActOnConditionVariable(DeclOut, Loc, CK); |
1886 | } |
1887 | |
1888 | |
1889 | |
1890 | |
1891 | |
1892 | |
1893 | |
1894 | |
1895 | |
1896 | |
1897 | |
1898 | |
1899 | |
1900 | |
1901 | |
1902 | |
1903 | |
1904 | |
1905 | |
1906 | |
1907 | |
1908 | |
1909 | |
1910 | |
1911 | |
1912 | |
1913 | |
1914 | void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) { |
1915 | DS.SetRangeStart(Tok.getLocation()); |
1916 | const char *PrevSpec; |
1917 | unsigned DiagID; |
1918 | SourceLocation Loc = Tok.getLocation(); |
1919 | const clang::PrintingPolicy &Policy = |
1920 | Actions.getASTContext().getPrintingPolicy(); |
1921 | |
1922 | switch (Tok.getKind()) { |
1923 | case tok::identifier: |
1924 | case tok::coloncolon: |
1925 | llvm_unreachable("Annotation token should already be formed!"); |
1926 | default: |
1927 | llvm_unreachable("Not a simple-type-specifier token!"); |
1928 | |
1929 | |
1930 | case tok::annot_typename: { |
1931 | if (getTypeAnnotation(Tok)) |
1932 | DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID, |
1933 | getTypeAnnotation(Tok), Policy); |
1934 | else |
1935 | DS.SetTypeSpecError(); |
1936 | |
1937 | DS.SetRangeEnd(Tok.getAnnotationEndLoc()); |
1938 | ConsumeAnnotationToken(); |
1939 | |
1940 | DS.Finish(Actions, Policy); |
1941 | return; |
1942 | } |
1943 | |
1944 | |
1945 | case tok::kw_short: |
1946 | DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID, Policy); |
1947 | break; |
1948 | case tok::kw_long: |
1949 | DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, DiagID, Policy); |
1950 | break; |
1951 | case tok::kw___int64: |
1952 | DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, DiagID, Policy); |
1953 | break; |
1954 | case tok::kw_signed: |
1955 | DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, DiagID); |
1956 | break; |
1957 | case tok::kw_unsigned: |
1958 | DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec, DiagID); |
1959 | break; |
1960 | case tok::kw_void: |
1961 | DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID, Policy); |
1962 | break; |
1963 | case tok::kw_char: |
1964 | DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID, Policy); |
1965 | break; |
1966 | case tok::kw_int: |
1967 | DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID, Policy); |
1968 | break; |
1969 | case tok::kw___int128: |
1970 | DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec, DiagID, Policy); |
1971 | break; |
1972 | case tok::kw_half: |
1973 | DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec, DiagID, Policy); |
1974 | break; |
1975 | case tok::kw_float: |
1976 | DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID, Policy); |
1977 | break; |
1978 | case tok::kw_double: |
1979 | DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID, Policy); |
1980 | break; |
1981 | case tok::kw__Float16: |
1982 | DS.SetTypeSpecType(DeclSpec::TST_float16, Loc, PrevSpec, DiagID, Policy); |
1983 | break; |
1984 | case tok::kw___float128: |
1985 | DS.SetTypeSpecType(DeclSpec::TST_float128, Loc, PrevSpec, DiagID, Policy); |
1986 | break; |
1987 | case tok::kw_wchar_t: |
1988 | DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID, Policy); |
1989 | break; |
1990 | case tok::kw_char8_t: |
1991 | DS.SetTypeSpecType(DeclSpec::TST_char8, Loc, PrevSpec, DiagID, Policy); |
1992 | break; |
1993 | case tok::kw_char16_t: |
1994 | DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID, Policy); |
1995 | break; |
1996 | case tok::kw_char32_t: |
1997 | DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID, Policy); |
1998 | break; |
1999 | case tok::kw_bool: |
2000 | DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID, Policy); |
2001 | break; |
2002 | #define GENERIC_IMAGE_TYPE(ImgType, Id) \ |
2003 | case tok::kw_##ImgType##_t: \ |
2004 | DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \ |
2005 | Policy); \ |
2006 | break; |
2007 | #include "clang/Basic/OpenCLImageTypes.def" |
2008 | |
2009 | case tok::annot_decltype: |
2010 | case tok::kw_decltype: |
2011 | DS.SetRangeEnd(ParseDecltypeSpecifier(DS)); |
2012 | return DS.Finish(Actions, Policy); |
2013 | |
2014 | |
2015 | case tok::kw_typeof: |
2016 | ParseTypeofSpecifier(DS); |
2017 | DS.Finish(Actions, Policy); |
2018 | return; |
2019 | } |
2020 | ConsumeAnyToken(); |
2021 | DS.SetRangeEnd(PrevTokLocation); |
2022 | DS.Finish(Actions, Policy); |
2023 | } |
2024 | |
2025 | |
2026 | |
2027 | |
2028 | |
2029 | |
2030 | |
2031 | |
2032 | |
2033 | |
2034 | |
2035 | |
2036 | bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) { |
2037 | ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_type_specifier); |
2038 | DS.Finish(Actions, Actions.getASTContext().getPrintingPolicy()); |
2039 | return false; |
2040 | } |
2041 | |
2042 | |
2043 | |
2044 | |
2045 | |
2046 | |
2047 | |
2048 | |
2049 | |
2050 | |
2051 | |
2052 | |
2053 | |
2054 | |
2055 | |
2056 | |
2057 | |
2058 | |
2059 | |
2060 | |
2061 | |
2062 | |
2063 | |
2064 | |
2065 | |
2066 | |
2067 | |
2068 | |
2069 | |
2070 | |
2071 | |
2072 | |
2073 | |
2074 | bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, |
2075 | SourceLocation TemplateKWLoc, |
2076 | IdentifierInfo *Name, |
2077 | SourceLocation NameLoc, |
2078 | bool EnteringContext, |
2079 | ParsedType ObjectType, |
2080 | UnqualifiedId &Id, |
2081 | bool AssumeTemplateId) { |
2082 | (0) . __assert_fail ("Tok.is(tok..less) && \"Expected '<' to finish parsing a template-id\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 2082, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::less) && "Expected '<' to finish parsing a template-id"); |
2083 | |
2084 | TemplateTy Template; |
2085 | TemplateNameKind TNK = TNK_Non_template; |
2086 | switch (Id.getKind()) { |
2087 | case UnqualifiedIdKind::IK_Identifier: |
2088 | case UnqualifiedIdKind::IK_OperatorFunctionId: |
2089 | case UnqualifiedIdKind::IK_LiteralOperatorId: |
2090 | if (AssumeTemplateId) { |
2091 | |
2092 | |
2093 | TNK = Actions.ActOnDependentTemplateName( |
2094 | getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext, |
2095 | Template, true); |
2096 | if (TNK == TNK_Non_template) |
2097 | return true; |
2098 | } else { |
2099 | bool MemberOfUnknownSpecialization; |
2100 | TNK = Actions.isTemplateName(getCurScope(), SS, |
2101 | TemplateKWLoc.isValid(), Id, |
2102 | ObjectType, EnteringContext, Template, |
2103 | MemberOfUnknownSpecialization); |
2104 | |
2105 | if (TNK == TNK_Non_template && MemberOfUnknownSpecialization && |
2106 | ObjectType && IsTemplateArgumentList()) { |
2107 | |
2108 | |
2109 | |
2110 | |
2111 | std::string Name; |
2112 | if (Id.getKind() == UnqualifiedIdKind::IK_Identifier) |
2113 | Name = Id.Identifier->getName(); |
2114 | else { |
2115 | Name = "operator "; |
2116 | if (Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId) |
2117 | Name += getOperatorSpelling(Id.OperatorFunctionId.Operator); |
2118 | else |
2119 | Name += Id.Identifier->getName(); |
2120 | } |
2121 | Diag(Id.StartLocation, diag::err_missing_dependent_template_keyword) |
2122 | << Name |
2123 | << FixItHint::CreateInsertion(Id.StartLocation, "template "); |
2124 | TNK = Actions.ActOnDependentTemplateName( |
2125 | getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext, |
2126 | Template, true); |
2127 | if (TNK == TNK_Non_template) |
2128 | return true; |
2129 | } |
2130 | } |
2131 | break; |
2132 | |
2133 | case UnqualifiedIdKind::IK_ConstructorName: { |
2134 | UnqualifiedId TemplateName; |
2135 | bool MemberOfUnknownSpecialization; |
2136 | TemplateName.setIdentifier(Name, NameLoc); |
2137 | TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(), |
2138 | TemplateName, ObjectType, |
2139 | EnteringContext, Template, |
2140 | MemberOfUnknownSpecialization); |
2141 | break; |
2142 | } |
2143 | |
2144 | case UnqualifiedIdKind::IK_DestructorName: { |
2145 | UnqualifiedId TemplateName; |
2146 | bool MemberOfUnknownSpecialization; |
2147 | TemplateName.setIdentifier(Name, NameLoc); |
2148 | if (ObjectType) { |
2149 | TNK = Actions.ActOnDependentTemplateName( |
2150 | getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType, |
2151 | EnteringContext, Template, true); |
2152 | if (TNK == TNK_Non_template) |
2153 | return true; |
2154 | } else { |
2155 | TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(), |
2156 | TemplateName, ObjectType, |
2157 | EnteringContext, Template, |
2158 | MemberOfUnknownSpecialization); |
2159 | |
2160 | if (TNK == TNK_Non_template && !Id.DestructorName.get()) { |
2161 | Diag(NameLoc, diag::err_destructor_template_id) |
2162 | << Name << SS.getRange(); |
2163 | return true; |
2164 | } |
2165 | } |
2166 | break; |
2167 | } |
2168 | |
2169 | default: |
2170 | return false; |
2171 | } |
2172 | |
2173 | if (TNK == TNK_Non_template) |
2174 | return false; |
2175 | |
2176 | |
2177 | SourceLocation LAngleLoc, RAngleLoc; |
2178 | TemplateArgList TemplateArgs; |
2179 | if (ParseTemplateIdAfterTemplateName(true, LAngleLoc, TemplateArgs, |
2180 | RAngleLoc)) |
2181 | return true; |
2182 | |
2183 | if (Id.getKind() == UnqualifiedIdKind::IK_Identifier || |
2184 | Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId || |
2185 | Id.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId) { |
2186 | |
2187 | |
2188 | |
2189 | |
2190 | IdentifierInfo *TemplateII = |
2191 | Id.getKind() == UnqualifiedIdKind::IK_Identifier ? Id.Identifier |
2192 | : nullptr; |
2193 | OverloadedOperatorKind OpKind = |
2194 | Id.getKind() == UnqualifiedIdKind::IK_Identifier |
2195 | ? OO_None |
2196 | : Id.OperatorFunctionId.Operator; |
2197 | |
2198 | TemplateIdAnnotation *TemplateId = TemplateIdAnnotation::Create( |
2199 | SS, TemplateKWLoc, Id.StartLocation, TemplateII, OpKind, Template, TNK, |
2200 | LAngleLoc, RAngleLoc, TemplateArgs, TemplateIds); |
2201 | |
2202 | Id.setTemplateId(TemplateId); |
2203 | return false; |
2204 | } |
2205 | |
2206 | |
2207 | ASTTemplateArgsPtr TemplateArgsPtr(TemplateArgs); |
2208 | |
2209 | |
2210 | TypeResult Type |
2211 | = Actions.ActOnTemplateIdType(SS, TemplateKWLoc, |
2212 | Template, Name, NameLoc, |
2213 | LAngleLoc, TemplateArgsPtr, RAngleLoc, |
2214 | ); |
2215 | if (Type.isInvalid()) |
2216 | return true; |
2217 | |
2218 | if (Id.getKind() == UnqualifiedIdKind::IK_ConstructorName) |
2219 | Id.setConstructorName(Type.get(), NameLoc, RAngleLoc); |
2220 | else |
2221 | Id.setDestructorName(Id.StartLocation, Type.get(), RAngleLoc); |
2222 | |
2223 | return false; |
2224 | } |
2225 | |
2226 | |
2227 | |
2228 | |
2229 | |
2230 | |
2231 | |
2232 | |
2233 | |
2234 | |
2235 | |
2236 | |
2237 | |
2238 | |
2239 | |
2240 | |
2241 | |
2242 | |
2243 | |
2244 | |
2245 | |
2246 | |
2247 | |
2248 | |
2249 | |
2250 | |
2251 | |
2252 | |
2253 | |
2254 | |
2255 | |
2256 | |
2257 | |
2258 | |
2259 | |
2260 | |
2261 | |
2262 | |
2263 | |
2264 | |
2265 | |
2266 | bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, |
2267 | ParsedType ObjectType, |
2268 | UnqualifiedId &Result) { |
2269 | (0) . __assert_fail ("Tok.is(tok..kw_operator) && \"Expected 'operator' keyword\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 2269, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_operator) && "Expected 'operator' keyword"); |
2270 | |
2271 | |
2272 | SourceLocation KeywordLoc = ConsumeToken(); |
2273 | |
2274 | |
2275 | unsigned SymbolIdx = 0; |
2276 | SourceLocation SymbolLocations[3]; |
2277 | OverloadedOperatorKind Op = OO_None; |
2278 | switch (Tok.getKind()) { |
2279 | case tok::kw_new: |
2280 | case tok::kw_delete: { |
2281 | bool isNew = Tok.getKind() == tok::kw_new; |
2282 | |
2283 | SymbolLocations[SymbolIdx++] = ConsumeToken(); |
2284 | |
2285 | if (Tok.is(tok::l_square) && |
2286 | (!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square))) { |
2287 | |
2288 | BalancedDelimiterTracker T(*this, tok::l_square); |
2289 | T.consumeOpen(); |
2290 | T.consumeClose(); |
2291 | if (T.getCloseLocation().isInvalid()) |
2292 | return true; |
2293 | |
2294 | SymbolLocations[SymbolIdx++] = T.getOpenLocation(); |
2295 | SymbolLocations[SymbolIdx++] = T.getCloseLocation(); |
2296 | Op = isNew? OO_Array_New : OO_Array_Delete; |
2297 | } else { |
2298 | Op = isNew? OO_New : OO_Delete; |
2299 | } |
2300 | break; |
2301 | } |
2302 | |
2303 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
2304 | case tok::Token: \ |
2305 | SymbolLocations[SymbolIdx++] = ConsumeToken(); \ |
2306 | Op = OO_##Name; \ |
2307 | break; |
2308 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
2309 | #include "clang/Basic/OperatorKinds.def" |
2310 | |
2311 | case tok::l_paren: { |
2312 | |
2313 | BalancedDelimiterTracker T(*this, tok::l_paren); |
2314 | T.consumeOpen(); |
2315 | T.consumeClose(); |
2316 | if (T.getCloseLocation().isInvalid()) |
2317 | return true; |
2318 | |
2319 | SymbolLocations[SymbolIdx++] = T.getOpenLocation(); |
2320 | SymbolLocations[SymbolIdx++] = T.getCloseLocation(); |
2321 | Op = OO_Call; |
2322 | break; |
2323 | } |
2324 | |
2325 | case tok::l_square: { |
2326 | |
2327 | BalancedDelimiterTracker T(*this, tok::l_square); |
2328 | T.consumeOpen(); |
2329 | T.consumeClose(); |
2330 | if (T.getCloseLocation().isInvalid()) |
2331 | return true; |
2332 | |
2333 | SymbolLocations[SymbolIdx++] = T.getOpenLocation(); |
2334 | SymbolLocations[SymbolIdx++] = T.getCloseLocation(); |
2335 | Op = OO_Subscript; |
2336 | break; |
2337 | } |
2338 | |
2339 | case tok::code_completion: { |
2340 | |
2341 | Actions.CodeCompleteOperatorName(getCurScope()); |
2342 | cutOffParsing(); |
2343 | |
2344 | return true; |
2345 | } |
2346 | |
2347 | default: |
2348 | break; |
2349 | } |
2350 | |
2351 | if (Op != OO_None) { |
2352 | |
2353 | Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations); |
2354 | return false; |
2355 | } |
2356 | |
2357 | |
2358 | |
2359 | |
2360 | |
2361 | |
2362 | |
2363 | if (getLangOpts().CPlusPlus11 && isTokenStringLiteral()) { |
2364 | Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator); |
2365 | |
2366 | SourceLocation DiagLoc; |
2367 | unsigned DiagId = 0; |
2368 | |
2369 | |
2370 | |
2371 | SmallVector<Token, 4> Toks; |
2372 | SmallVector<SourceLocation, 4> TokLocs; |
2373 | while (isTokenStringLiteral()) { |
2374 | if (!Tok.is(tok::string_literal) && !DiagId) { |
2375 | |
2376 | |
2377 | |
2378 | DiagLoc = Tok.getLocation(); |
2379 | DiagId = diag::err_literal_operator_string_prefix; |
2380 | } |
2381 | Toks.push_back(Tok); |
2382 | TokLocs.push_back(ConsumeStringToken()); |
2383 | } |
2384 | |
2385 | StringLiteralParser Literal(Toks, PP); |
2386 | if (Literal.hadError) |
2387 | return true; |
2388 | |
2389 | |
2390 | |
2391 | IdentifierInfo *II = nullptr; |
2392 | SourceLocation SuffixLoc; |
2393 | if (!Literal.getUDSuffix().empty()) { |
2394 | II = &PP.getIdentifierTable().get(Literal.getUDSuffix()); |
2395 | SuffixLoc = |
2396 | Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()], |
2397 | Literal.getUDSuffixOffset(), |
2398 | PP.getSourceManager(), getLangOpts()); |
2399 | } else if (Tok.is(tok::identifier)) { |
2400 | II = Tok.getIdentifierInfo(); |
2401 | SuffixLoc = ConsumeToken(); |
2402 | TokLocs.push_back(SuffixLoc); |
2403 | } else { |
2404 | Diag(Tok.getLocation(), diag::err_expected) << tok::identifier; |
2405 | return true; |
2406 | } |
2407 | |
2408 | |
2409 | if (!Literal.GetString().empty() || Literal.Pascal) { |
2410 | |
2411 | |
2412 | |
2413 | |
2414 | DiagLoc = TokLocs.front(); |
2415 | DiagId = diag::err_literal_operator_string_not_empty; |
2416 | } |
2417 | |
2418 | if (DiagId) { |
2419 | |
2420 | |
2421 | SmallString<32> Str; |
2422 | Str += "\"\""; |
2423 | Str += II->getName(); |
2424 | Diag(DiagLoc, DiagId) << FixItHint::CreateReplacement( |
2425 | SourceRange(TokLocs.front(), TokLocs.back()), Str); |
2426 | } |
2427 | |
2428 | Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc); |
2429 | |
2430 | return Actions.checkLiteralOperatorId(SS, Result); |
2431 | } |
2432 | |
2433 | |
2434 | |
2435 | |
2436 | |
2437 | |
2438 | |
2439 | |
2440 | |
2441 | |
2442 | |
2443 | |
2444 | |
2445 | DeclSpec DS(AttrFactory); |
2446 | if (ParseCXXTypeSpecifierSeq(DS)) |
2447 | return true; |
2448 | |
2449 | |
2450 | |
2451 | Declarator D(DS, DeclaratorContext::ConversionIdContext); |
2452 | ParseDeclaratorInternal(D, ); |
2453 | |
2454 | |
2455 | TypeResult Ty = Actions.ActOnTypeName(getCurScope(), D); |
2456 | if (Ty.isInvalid()) |
2457 | return true; |
2458 | |
2459 | |
2460 | Result.setConversionFunctionId(KeywordLoc, Ty.get(), |
2461 | D.getSourceRange().getEnd()); |
2462 | return false; |
2463 | } |
2464 | |
2465 | |
2466 | |
2467 | |
2468 | |
2469 | |
2470 | |
2471 | |
2472 | |
2473 | |
2474 | |
2475 | |
2476 | |
2477 | |
2478 | |
2479 | |
2480 | |
2481 | |
2482 | |
2483 | |
2484 | |
2485 | |
2486 | |
2487 | |
2488 | |
2489 | |
2490 | |
2491 | |
2492 | |
2493 | |
2494 | |
2495 | |
2496 | |
2497 | bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, |
2498 | bool AllowDestructorName, |
2499 | bool AllowConstructorName, |
2500 | bool AllowDeductionGuide, |
2501 | ParsedType ObjectType, |
2502 | SourceLocation *TemplateKWLoc, |
2503 | UnqualifiedId &Result) { |
2504 | if (TemplateKWLoc) |
2505 | *TemplateKWLoc = SourceLocation(); |
2506 | |
2507 | |
2508 | |
2509 | bool TemplateSpecified = false; |
2510 | if (Tok.is(tok::kw_template)) { |
2511 | if (TemplateKWLoc && (ObjectType || SS.isSet())) { |
2512 | TemplateSpecified = true; |
2513 | *TemplateKWLoc = ConsumeToken(); |
2514 | } else { |
2515 | SourceLocation TemplateLoc = ConsumeToken(); |
2516 | Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id) |
2517 | << FixItHint::CreateRemoval(TemplateLoc); |
2518 | } |
2519 | } |
2520 | |
2521 | |
2522 | |
2523 | |
2524 | if (Tok.is(tok::identifier)) { |
2525 | |
2526 | IdentifierInfo *Id = Tok.getIdentifierInfo(); |
2527 | SourceLocation IdLoc = ConsumeToken(); |
2528 | |
2529 | if (!getLangOpts().CPlusPlus) { |
2530 | |
2531 | |
2532 | Result.setIdentifier(Id, IdLoc); |
2533 | return false; |
2534 | } |
2535 | |
2536 | ParsedTemplateTy TemplateName; |
2537 | if (AllowConstructorName && |
2538 | Actions.isCurrentClassName(*Id, getCurScope(), &SS)) { |
2539 | |
2540 | ParsedType Ty = Actions.getConstructorName(*Id, IdLoc, getCurScope(), SS, |
2541 | EnteringContext); |
2542 | if (!Ty) |
2543 | return true; |
2544 | Result.setConstructorName(Ty, IdLoc, IdLoc); |
2545 | } else if (getLangOpts().CPlusPlus17 && |
2546 | AllowDeductionGuide && SS.isEmpty() && |
2547 | Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc, |
2548 | &TemplateName)) { |
2549 | |
2550 | Result.setDeductionGuideName(TemplateName, IdLoc); |
2551 | } else { |
2552 | |
2553 | Result.setIdentifier(Id, IdLoc); |
2554 | } |
2555 | |
2556 | |
2557 | TemplateTy Template; |
2558 | if (Tok.is(tok::less)) |
2559 | return ParseUnqualifiedIdTemplateId( |
2560 | SS, TemplateKWLoc ? *TemplateKWLoc : SourceLocation(), Id, IdLoc, |
2561 | EnteringContext, ObjectType, Result, TemplateSpecified); |
2562 | else if (TemplateSpecified && |
2563 | Actions.ActOnDependentTemplateName( |
2564 | getCurScope(), SS, *TemplateKWLoc, Result, ObjectType, |
2565 | EnteringContext, Template, |
2566 | true) == TNK_Non_template) |
2567 | return true; |
2568 | |
2569 | return false; |
2570 | } |
2571 | |
2572 | |
2573 | |
2574 | if (Tok.is(tok::annot_template_id)) { |
2575 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
2576 | |
2577 | |
2578 | if (AllowConstructorName && TemplateId->Name && |
2579 | Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS)) { |
2580 | if (SS.isSet()) { |
2581 | |
2582 | |
2583 | |
2584 | |
2585 | Diag(TemplateId->TemplateNameLoc, |
2586 | diag::err_out_of_line_constructor_template_id) |
2587 | << TemplateId->Name |
2588 | << FixItHint::CreateRemoval( |
2589 | SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc)); |
2590 | ParsedType Ty = Actions.getConstructorName( |
2591 | *TemplateId->Name, TemplateId->TemplateNameLoc, getCurScope(), SS, |
2592 | EnteringContext); |
2593 | if (!Ty) |
2594 | return true; |
2595 | Result.setConstructorName(Ty, TemplateId->TemplateNameLoc, |
2596 | TemplateId->RAngleLoc); |
2597 | ConsumeAnnotationToken(); |
2598 | return false; |
2599 | } |
2600 | |
2601 | Result.setConstructorTemplateId(TemplateId); |
2602 | ConsumeAnnotationToken(); |
2603 | return false; |
2604 | } |
2605 | |
2606 | |
2607 | |
2608 | Result.setTemplateId(TemplateId); |
2609 | SourceLocation TemplateLoc = TemplateId->TemplateKWLoc; |
2610 | if (TemplateLoc.isValid()) { |
2611 | if (TemplateKWLoc && (ObjectType || SS.isSet())) |
2612 | *TemplateKWLoc = TemplateLoc; |
2613 | else |
2614 | Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id) |
2615 | << FixItHint::CreateRemoval(TemplateLoc); |
2616 | } |
2617 | ConsumeAnnotationToken(); |
2618 | return false; |
2619 | } |
2620 | |
2621 | |
2622 | |
2623 | |
2624 | if (Tok.is(tok::kw_operator)) { |
2625 | if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, Result)) |
2626 | return true; |
2627 | |
2628 | |
2629 | |
2630 | |
2631 | |
2632 | |
2633 | TemplateTy Template; |
2634 | if ((Result.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId || |
2635 | Result.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId) && |
2636 | Tok.is(tok::less)) |
2637 | return ParseUnqualifiedIdTemplateId( |
2638 | SS, TemplateKWLoc ? *TemplateKWLoc : SourceLocation(), nullptr, |
2639 | SourceLocation(), EnteringContext, ObjectType, Result, |
2640 | TemplateSpecified); |
2641 | else if (TemplateSpecified && |
2642 | Actions.ActOnDependentTemplateName( |
2643 | getCurScope(), SS, *TemplateKWLoc, Result, ObjectType, |
2644 | EnteringContext, Template, |
2645 | true) == TNK_Non_template) |
2646 | return true; |
2647 | |
2648 | return false; |
2649 | } |
2650 | |
2651 | if (getLangOpts().CPlusPlus && |
2652 | (AllowDestructorName || SS.isSet()) && Tok.is(tok::tilde)) { |
2653 | |
2654 | |
2655 | |
2656 | |
2657 | |
2658 | |
2659 | SourceLocation TildeLoc = ConsumeToken(); |
2660 | |
2661 | if (SS.isEmpty() && Tok.is(tok::kw_decltype)) { |
2662 | DeclSpec DS(AttrFactory); |
2663 | SourceLocation EndLoc = ParseDecltypeSpecifier(DS); |
2664 | if (ParsedType Type = |
2665 | Actions.getDestructorTypeForDecltype(DS, ObjectType)) { |
2666 | Result.setDestructorName(TildeLoc, Type, EndLoc); |
2667 | return false; |
2668 | } |
2669 | return true; |
2670 | } |
2671 | |
2672 | |
2673 | if (Tok.isNot(tok::identifier)) { |
2674 | Diag(Tok, diag::err_destructor_tilde_identifier); |
2675 | return true; |
2676 | } |
2677 | |
2678 | |
2679 | DeclaratorScopeObj DeclScopeObj(*this, SS); |
2680 | if (!TemplateSpecified && NextToken().is(tok::coloncolon)) { |
2681 | |
2682 | |
2683 | |
2684 | ColonProtectionRAIIObject ColonRAII(*this, false); |
2685 | |
2686 | if (SS.isSet()) { |
2687 | AnnotateScopeToken(SS, ); |
2688 | SS.clear(); |
2689 | } |
2690 | if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, EnteringContext)) |
2691 | return true; |
2692 | if (SS.isNotEmpty()) |
2693 | ObjectType = nullptr; |
2694 | if (Tok.isNot(tok::identifier) || NextToken().is(tok::coloncolon) || |
2695 | !SS.isSet()) { |
2696 | Diag(TildeLoc, diag::err_destructor_tilde_scope); |
2697 | return true; |
2698 | } |
2699 | |
2700 | |
2701 | Diag(TildeLoc, diag::err_destructor_tilde_scope) |
2702 | << FixItHint::CreateRemoval(TildeLoc) |
2703 | << FixItHint::CreateInsertion(Tok.getLocation(), "~"); |
2704 | |
2705 | |
2706 | if (Actions.ShouldEnterDeclaratorScope(getCurScope(), SS)) |
2707 | DeclScopeObj.EnterDeclaratorScope(); |
2708 | } |
2709 | |
2710 | |
2711 | IdentifierInfo *ClassName = Tok.getIdentifierInfo(); |
2712 | SourceLocation ClassNameLoc = ConsumeToken(); |
2713 | |
2714 | if (Tok.is(tok::less)) { |
2715 | Result.setDestructorName(TildeLoc, nullptr, ClassNameLoc); |
2716 | return ParseUnqualifiedIdTemplateId( |
2717 | SS, TemplateKWLoc ? *TemplateKWLoc : SourceLocation(), ClassName, |
2718 | ClassNameLoc, EnteringContext, ObjectType, Result, TemplateSpecified); |
2719 | } |
2720 | |
2721 | |
2722 | ParsedType Ty = Actions.getDestructorName(TildeLoc, *ClassName, |
2723 | ClassNameLoc, getCurScope(), |
2724 | SS, ObjectType, |
2725 | EnteringContext); |
2726 | if (!Ty) |
2727 | return true; |
2728 | |
2729 | Result.setDestructorName(TildeLoc, Ty, ClassNameLoc); |
2730 | return false; |
2731 | } |
2732 | |
2733 | Diag(Tok, diag::err_expected_unqualified_id) |
2734 | << getLangOpts().CPlusPlus; |
2735 | return true; |
2736 | } |
2737 | |
2738 | |
2739 | |
2740 | |
2741 | |
2742 | |
2743 | |
2744 | |
2745 | |
2746 | |
2747 | |
2748 | |
2749 | |
2750 | |
2751 | |
2752 | |
2753 | |
2754 | |
2755 | |
2756 | |
2757 | |
2758 | |
2759 | |
2760 | |
2761 | |
2762 | |
2763 | |
2764 | |
2765 | |
2766 | ExprResult |
2767 | Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) { |
2768 | (0) . __assert_fail ("Tok.is(tok..kw_new) && \"expected 'new' token\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 2768, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_new) && "expected 'new' token"); |
2769 | ConsumeToken(); |
2770 | |
2771 | |
2772 | |
2773 | |
2774 | ExprVector PlacementArgs; |
2775 | SourceLocation PlacementLParen, PlacementRParen; |
2776 | |
2777 | SourceRange TypeIdParens; |
2778 | DeclSpec DS(AttrFactory); |
2779 | Declarator DeclaratorInfo(DS, DeclaratorContext::CXXNewContext); |
2780 | if (Tok.is(tok::l_paren)) { |
2781 | |
2782 | BalancedDelimiterTracker T(*this, tok::l_paren); |
2783 | T.consumeOpen(); |
2784 | PlacementLParen = T.getOpenLocation(); |
2785 | if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) { |
2786 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
2787 | return ExprError(); |
2788 | } |
2789 | |
2790 | T.consumeClose(); |
2791 | PlacementRParen = T.getCloseLocation(); |
2792 | if (PlacementRParen.isInvalid()) { |
2793 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
2794 | return ExprError(); |
2795 | } |
2796 | |
2797 | if (PlacementArgs.empty()) { |
2798 | |
2799 | TypeIdParens = T.getRange(); |
2800 | PlacementLParen = PlacementRParen = SourceLocation(); |
2801 | } else { |
2802 | |
2803 | if (Tok.is(tok::l_paren)) { |
2804 | BalancedDelimiterTracker T(*this, tok::l_paren); |
2805 | T.consumeOpen(); |
2806 | MaybeParseGNUAttributes(DeclaratorInfo); |
2807 | ParseSpecifierQualifierList(DS); |
2808 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
2809 | ParseDeclarator(DeclaratorInfo); |
2810 | T.consumeClose(); |
2811 | TypeIdParens = T.getRange(); |
2812 | } else { |
2813 | MaybeParseGNUAttributes(DeclaratorInfo); |
2814 | if (ParseCXXTypeSpecifierSeq(DS)) |
2815 | DeclaratorInfo.setInvalidType(true); |
2816 | else { |
2817 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
2818 | ParseDeclaratorInternal(DeclaratorInfo, |
2819 | &Parser::ParseDirectNewDeclarator); |
2820 | } |
2821 | } |
2822 | } |
2823 | } else { |
2824 | |
2825 | |
2826 | MaybeParseGNUAttributes(DeclaratorInfo); |
2827 | if (ParseCXXTypeSpecifierSeq(DS)) |
2828 | DeclaratorInfo.setInvalidType(true); |
2829 | else { |
2830 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
2831 | ParseDeclaratorInternal(DeclaratorInfo, |
2832 | &Parser::ParseDirectNewDeclarator); |
2833 | } |
2834 | } |
2835 | if (DeclaratorInfo.isInvalidType()) { |
2836 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
2837 | return ExprError(); |
2838 | } |
2839 | |
2840 | ExprResult Initializer; |
2841 | |
2842 | if (Tok.is(tok::l_paren)) { |
2843 | SourceLocation ConstructorLParen, ConstructorRParen; |
2844 | ExprVector ConstructorArgs; |
2845 | BalancedDelimiterTracker T(*this, tok::l_paren); |
2846 | T.consumeOpen(); |
2847 | ConstructorLParen = T.getOpenLocation(); |
2848 | if (Tok.isNot(tok::r_paren)) { |
2849 | CommaLocsTy CommaLocs; |
2850 | auto RunSignatureHelp = [&]() { |
2851 | ParsedType TypeRep = |
2852 | Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get(); |
2853 | QualType PreferredType = Actions.ProduceConstructorSignatureHelp( |
2854 | getCurScope(), TypeRep.get()->getCanonicalTypeInternal(), |
2855 | DeclaratorInfo.getEndLoc(), ConstructorArgs, ConstructorLParen); |
2856 | CalledSignatureHelp = true; |
2857 | return PreferredType; |
2858 | }; |
2859 | if (ParseExpressionList(ConstructorArgs, CommaLocs, [&] { |
2860 | PreferredType.enterFunctionArgument(Tok.getLocation(), |
2861 | RunSignatureHelp); |
2862 | })) { |
2863 | if (PP.isCodeCompletionReached() && !CalledSignatureHelp) |
2864 | RunSignatureHelp(); |
2865 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
2866 | return ExprError(); |
2867 | } |
2868 | } |
2869 | T.consumeClose(); |
2870 | ConstructorRParen = T.getCloseLocation(); |
2871 | if (ConstructorRParen.isInvalid()) { |
2872 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
2873 | return ExprError(); |
2874 | } |
2875 | Initializer = Actions.ActOnParenListExpr(ConstructorLParen, |
2876 | ConstructorRParen, |
2877 | ConstructorArgs); |
2878 | } else if (Tok.is(tok::l_brace) && getLangOpts().CPlusPlus11) { |
2879 | Diag(Tok.getLocation(), |
2880 | diag::warn_cxx98_compat_generalized_initializer_lists); |
2881 | Initializer = ParseBraceInitializer(); |
2882 | } |
2883 | if (Initializer.isInvalid()) |
2884 | return Initializer; |
2885 | |
2886 | return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen, |
2887 | PlacementArgs, PlacementRParen, |
2888 | TypeIdParens, DeclaratorInfo, Initializer.get()); |
2889 | } |
2890 | |
2891 | |
2892 | |
2893 | |
2894 | |
2895 | |
2896 | |
2897 | |
2898 | void Parser::ParseDirectNewDeclarator(Declarator &D) { |
2899 | |
2900 | bool first = true; |
2901 | while (Tok.is(tok::l_square)) { |
2902 | |
2903 | if (CheckProhibitedCXX11Attribute()) |
2904 | continue; |
2905 | |
2906 | BalancedDelimiterTracker T(*this, tok::l_square); |
2907 | T.consumeOpen(); |
2908 | |
2909 | ExprResult Size(first ? ParseExpression() |
2910 | : ParseConstantExpression()); |
2911 | if (Size.isInvalid()) { |
2912 | |
2913 | SkipUntil(tok::r_square, StopAtSemi); |
2914 | return; |
2915 | } |
2916 | first = false; |
2917 | |
2918 | T.consumeClose(); |
2919 | |
2920 | |
2921 | ParsedAttributes Attrs(AttrFactory); |
2922 | MaybeParseCXX11Attributes(Attrs); |
2923 | |
2924 | D.AddTypeInfo(DeclaratorChunk::getArray(0, |
2925 | , , |
2926 | Size.get(), T.getOpenLocation(), |
2927 | T.getCloseLocation()), |
2928 | std::move(Attrs), T.getCloseLocation()); |
2929 | |
2930 | if (T.getCloseLocation().isInvalid()) |
2931 | return; |
2932 | } |
2933 | } |
2934 | |
2935 | |
2936 | |
2937 | |
2938 | |
2939 | |
2940 | |
2941 | |
2942 | |
2943 | |
2944 | |
2945 | bool Parser::ParseExpressionListOrTypeId( |
2946 | SmallVectorImpl<Expr*> &PlacementArgs, |
2947 | Declarator &D) { |
2948 | |
2949 | if (isTypeIdInParens()) { |
2950 | ParseSpecifierQualifierList(D.getMutableDeclSpec()); |
2951 | D.SetSourceRange(D.getDeclSpec().getSourceRange()); |
2952 | ParseDeclarator(D); |
2953 | return D.isInvalidType(); |
2954 | } |
2955 | |
2956 | |
2957 | |
2958 | CommaLocsTy CommaLocs; |
2959 | return ParseExpressionList(PlacementArgs, CommaLocs); |
2960 | } |
2961 | |
2962 | |
2963 | |
2964 | |
2965 | |
2966 | |
2967 | |
2968 | |
2969 | |
2970 | |
2971 | |
2972 | |
2973 | ExprResult |
2974 | Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) { |
2975 | (0) . __assert_fail ("Tok.is(tok..kw_delete) && \"Expected 'delete' keyword\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 2975, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_delete) && "Expected 'delete' keyword"); |
2976 | ConsumeToken(); |
2977 | |
2978 | |
2979 | bool ArrayDelete = false; |
2980 | if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) { |
2981 | |
2982 | |
2983 | |
2984 | |
2985 | |
2986 | |
2987 | |
2988 | |
2989 | ArrayDelete = true; |
2990 | BalancedDelimiterTracker T(*this, tok::l_square); |
2991 | |
2992 | T.consumeOpen(); |
2993 | T.consumeClose(); |
2994 | if (T.getCloseLocation().isInvalid()) |
2995 | return ExprError(); |
2996 | } |
2997 | |
2998 | ExprResult Operand(ParseCastExpression(false)); |
2999 | if (Operand.isInvalid()) |
3000 | return Operand; |
3001 | |
3002 | return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.get()); |
3003 | } |
3004 | |
3005 | static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind) { |
3006 | switch (kind) { |
3007 | default: llvm_unreachable("Not a known type trait"); |
3008 | #define TYPE_TRAIT_1(Spelling, Name, Key) \ |
3009 | case tok::kw_ ## Spelling: return UTT_ ## Name; |
3010 | #define TYPE_TRAIT_2(Spelling, Name, Key) \ |
3011 | case tok::kw_ ## Spelling: return BTT_ ## Name; |
3012 | #include "clang/Basic/TokenKinds.def" |
3013 | #define TYPE_TRAIT_N(Spelling, Name, Key) \ |
3014 | case tok::kw_ ## Spelling: return TT_ ## Name; |
3015 | #include "clang/Basic/TokenKinds.def" |
3016 | } |
3017 | } |
3018 | |
3019 | static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind) { |
3020 | switch(kind) { |
3021 | default: llvm_unreachable("Not a known binary type trait"); |
3022 | case tok::kw___array_rank: return ATT_ArrayRank; |
3023 | case tok::kw___array_extent: return ATT_ArrayExtent; |
3024 | } |
3025 | } |
3026 | |
3027 | static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind) { |
3028 | switch(kind) { |
3029 | default: llvm_unreachable("Not a known unary expression trait."); |
3030 | case tok::kw___is_lvalue_expr: return ET_IsLValueExpr; |
3031 | case tok::kw___is_rvalue_expr: return ET_IsRValueExpr; |
3032 | } |
3033 | } |
3034 | |
3035 | static unsigned TypeTraitArity(tok::TokenKind kind) { |
3036 | switch (kind) { |
3037 | default: llvm_unreachable("Not a known type trait"); |
3038 | #define TYPE_TRAIT(N,Spelling,K) case tok::kw_##Spelling: return N; |
3039 | #include "clang/Basic/TokenKinds.def" |
3040 | } |
3041 | } |
3042 | |
3043 | |
3044 | |
3045 | |
3046 | |
3047 | |
3048 | |
3049 | |
3050 | |
3051 | |
3052 | |
3053 | |
3054 | ExprResult Parser::ParseTypeTrait() { |
3055 | tok::TokenKind Kind = Tok.getKind(); |
3056 | unsigned Arity = TypeTraitArity(Kind); |
3057 | |
3058 | SourceLocation Loc = ConsumeToken(); |
3059 | |
3060 | BalancedDelimiterTracker Parens(*this, tok::l_paren); |
3061 | if (Parens.expectAndConsume()) |
3062 | return ExprError(); |
3063 | |
3064 | SmallVector<ParsedType, 2> Args; |
3065 | do { |
3066 | |
3067 | TypeResult Ty = ParseTypeName(); |
3068 | if (Ty.isInvalid()) { |
3069 | Parens.skipToEnd(); |
3070 | return ExprError(); |
3071 | } |
3072 | |
3073 | |
3074 | if (Tok.is(tok::ellipsis)) { |
3075 | Ty = Actions.ActOnPackExpansion(Ty.get(), ConsumeToken()); |
3076 | if (Ty.isInvalid()) { |
3077 | Parens.skipToEnd(); |
3078 | return ExprError(); |
3079 | } |
3080 | } |
3081 | |
3082 | |
3083 | Args.push_back(Ty.get()); |
3084 | } while (TryConsumeToken(tok::comma)); |
3085 | |
3086 | if (Parens.consumeClose()) |
3087 | return ExprError(); |
3088 | |
3089 | SourceLocation EndLoc = Parens.getCloseLocation(); |
3090 | |
3091 | if (Arity && Args.size() != Arity) { |
3092 | Diag(EndLoc, diag::err_type_trait_arity) |
3093 | << Arity << 0 << (Arity > 1) << (int)Args.size() << SourceRange(Loc); |
3094 | return ExprError(); |
3095 | } |
3096 | |
3097 | if (!Arity && Args.empty()) { |
3098 | Diag(EndLoc, diag::err_type_trait_arity) |
3099 | << 1 << 1 << 1 << (int)Args.size() << SourceRange(Loc); |
3100 | return ExprError(); |
3101 | } |
3102 | |
3103 | return Actions.ActOnTypeTrait(TypeTraitFromTokKind(Kind), Loc, Args, EndLoc); |
3104 | } |
3105 | |
3106 | |
3107 | |
3108 | |
3109 | |
3110 | |
3111 | |
3112 | |
3113 | ExprResult Parser::ParseArrayTypeTrait() { |
3114 | ArrayTypeTrait ATT = ArrayTypeTraitFromTokKind(Tok.getKind()); |
3115 | SourceLocation Loc = ConsumeToken(); |
3116 | |
3117 | BalancedDelimiterTracker T(*this, tok::l_paren); |
3118 | if (T.expectAndConsume()) |
3119 | return ExprError(); |
3120 | |
3121 | TypeResult Ty = ParseTypeName(); |
3122 | if (Ty.isInvalid()) { |
3123 | SkipUntil(tok::comma, StopAtSemi); |
3124 | SkipUntil(tok::r_paren, StopAtSemi); |
3125 | return ExprError(); |
3126 | } |
3127 | |
3128 | switch (ATT) { |
3129 | case ATT_ArrayRank: { |
3130 | T.consumeClose(); |
3131 | return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), nullptr, |
3132 | T.getCloseLocation()); |
3133 | } |
3134 | case ATT_ArrayExtent: { |
3135 | if (ExpectAndConsume(tok::comma)) { |
3136 | SkipUntil(tok::r_paren, StopAtSemi); |
3137 | return ExprError(); |
3138 | } |
3139 | |
3140 | ExprResult DimExpr = ParseExpression(); |
3141 | T.consumeClose(); |
3142 | |
3143 | return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(), |
3144 | T.getCloseLocation()); |
3145 | } |
3146 | } |
3147 | llvm_unreachable("Invalid ArrayTypeTrait!"); |
3148 | } |
3149 | |
3150 | |
3151 | |
3152 | |
3153 | |
3154 | |
3155 | |
3156 | ExprResult Parser::ParseExpressionTrait() { |
3157 | ExpressionTrait ET = ExpressionTraitFromTokKind(Tok.getKind()); |
3158 | SourceLocation Loc = ConsumeToken(); |
3159 | |
3160 | BalancedDelimiterTracker T(*this, tok::l_paren); |
3161 | if (T.expectAndConsume()) |
3162 | return ExprError(); |
3163 | |
3164 | ExprResult Expr = ParseExpression(); |
3165 | |
3166 | T.consumeClose(); |
3167 | |
3168 | return Actions.ActOnExpressionTrait(ET, Loc, Expr.get(), |
3169 | T.getCloseLocation()); |
3170 | } |
3171 | |
3172 | |
3173 | |
3174 | |
3175 | |
3176 | ExprResult |
3177 | Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, |
3178 | ParsedType &CastTy, |
3179 | BalancedDelimiterTracker &Tracker, |
3180 | ColonProtectionRAIIObject &ColonProt) { |
3181 | (0) . __assert_fail ("getLangOpts().CPlusPlus && \"Should only be called for C++!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 3181, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getLangOpts().CPlusPlus && "Should only be called for C++!"); |
3182 | (0) . __assert_fail ("ExprType == CastExpr && \"Compound literals are not ambiguous!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 3182, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ExprType == CastExpr && "Compound literals are not ambiguous!"); |
3183 | (0) . __assert_fail ("isTypeIdInParens() && \"Not a type-id!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExprCXX.cpp", 3183, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isTypeIdInParens() && "Not a type-id!"); |
3184 | |
3185 | ExprResult Result(true); |
3186 | CastTy = nullptr; |
3187 | |
3188 | |
3189 | |
3190 | |
3191 | |
3192 | |
3193 | |
3194 | |
3195 | |
3196 | |
3197 | |
3198 | |
3199 | |
3200 | |
3201 | |
3202 | |
3203 | |
3204 | |
3205 | |
3206 | |
3207 | ParenParseOption ParseAs; |
3208 | CachedTokens Toks; |
3209 | |
3210 | |
3211 | |
3212 | if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) { |
3213 | |
3214 | Tracker.consumeClose(); |
3215 | return ExprError(); |
3216 | } |
3217 | |
3218 | if (Tok.is(tok::l_brace)) { |
3219 | ParseAs = CompoundLiteral; |
3220 | } else { |
3221 | bool NotCastExpr; |
3222 | if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) { |
3223 | NotCastExpr = true; |
3224 | } else { |
3225 | |
3226 | |
3227 | |
3228 | ColonProt.restore(); |
3229 | Result = ParseCastExpression(false, |
3230 | false, |
3231 | NotCastExpr, |
3232 | |
3233 | IsTypeCast); |
3234 | } |
3235 | |
3236 | |
3237 | |
3238 | ParseAs = NotCastExpr ? SimpleExpr : CastExpr; |
3239 | } |
3240 | |
3241 | |
3242 | Token AttrEnd; |
3243 | AttrEnd.startToken(); |
3244 | AttrEnd.setKind(tok::eof); |
3245 | AttrEnd.setLocation(Tok.getLocation()); |
3246 | AttrEnd.setEofData(Toks.data()); |
3247 | Toks.push_back(AttrEnd); |
3248 | |
3249 | |
3250 | Toks.push_back(Tok); |
3251 | |
3252 | |
3253 | PP.EnterTokenStream(Toks, true ); |
3254 | |
3255 | |
3256 | ConsumeAnyToken(); |
3257 | |
3258 | if (ParseAs >= CompoundLiteral) { |
3259 | |
3260 | DeclSpec DS(AttrFactory); |
3261 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); |
3262 | { |
3263 | ColonProtectionRAIIObject InnerColonProtection(*this); |
3264 | ParseSpecifierQualifierList(DS); |
3265 | ParseDeclarator(DeclaratorInfo); |
3266 | } |
3267 | |
3268 | |
3269 | Tracker.consumeClose(); |
3270 | ColonProt.restore(); |
3271 | |
3272 | |
3273 | assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData()); |
3274 | ConsumeAnyToken(); |
3275 | |
3276 | if (ParseAs == CompoundLiteral) { |
3277 | ExprType = CompoundLiteral; |
3278 | if (DeclaratorInfo.isInvalidType()) |
3279 | return ExprError(); |
3280 | |
3281 | TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
3282 | return ParseCompoundLiteralExpression(Ty.get(), |
3283 | Tracker.getOpenLocation(), |
3284 | Tracker.getCloseLocation()); |
3285 | } |
3286 | |
3287 | |
3288 | assert(ParseAs == CastExpr); |
3289 | |
3290 | if (DeclaratorInfo.isInvalidType()) |
3291 | return ExprError(); |
3292 | |
3293 | |
3294 | if (!Result.isInvalid()) |
3295 | Result = Actions.ActOnCastExpr(getCurScope(), Tracker.getOpenLocation(), |
3296 | DeclaratorInfo, CastTy, |
3297 | Tracker.getCloseLocation(), Result.get()); |
3298 | return Result; |
3299 | } |
3300 | |
3301 | |
3302 | assert(ParseAs == SimpleExpr); |
3303 | |
3304 | ExprType = SimpleExpr; |
3305 | Result = ParseExpression(); |
3306 | if (!Result.isInvalid() && Tok.is(tok::r_paren)) |
3307 | Result = Actions.ActOnParenExpr(Tracker.getOpenLocation(), |
3308 | Tok.getLocation(), Result.get()); |
3309 | |
3310 | |
3311 | if (Result.isInvalid()) { |
3312 | while (Tok.isNot(tok::eof)) |
3313 | ConsumeAnyToken(); |
3314 | assert(Tok.getEofData() == AttrEnd.getEofData()); |
3315 | ConsumeAnyToken(); |
3316 | return ExprError(); |
3317 | } |
3318 | |
3319 | Tracker.consumeClose(); |
3320 | |
3321 | assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData()); |
3322 | ConsumeAnyToken(); |
3323 | return Result; |
3324 | } |
3325 | |