clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ParseExprCXX.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangParse/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangParse/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangParse/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangParse/../include -I /usr/src/gnu/usr.bin/clang/libclangParse/obj -I /usr/src/gnu/usr.bin/clang/libclangParse/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangParse/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libclangParse/../../../llvm/clang/lib/Parse/ParseExprCXX.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | #include "clang/AST/ASTContext.h" |
| 13 | #include "clang/AST/Decl.h" |
| 14 | #include "clang/AST/DeclTemplate.h" |
| 15 | #include "clang/AST/ExprCXX.h" |
| 16 | #include "clang/Basic/PrettyStackTrace.h" |
| 17 | #include "clang/Lex/LiteralSupport.h" |
| 18 | #include "clang/Parse/ParseDiagnostic.h" |
| 19 | #include "clang/Parse/Parser.h" |
| 20 | #include "clang/Parse/RAIIObjectsForParser.h" |
| 21 | #include "clang/Sema/DeclSpec.h" |
| 22 | #include "clang/Sema/ParsedTemplate.h" |
| 23 | #include "clang/Sema/Scope.h" |
| 24 | #include "llvm/Support/ErrorHandling.h" |
| 25 | #include <numeric> |
| 26 | |
| 27 | using namespace clang; |
| 28 | |
| 29 | static int SelectDigraphErrorMessage(tok::TokenKind Kind) { |
| 30 | switch (Kind) { |
| 31 | |
| 32 | case tok::unknown: return 0; |
| 33 | |
| 34 | case tok::kw_addrspace_cast: return 1; |
| 35 | case tok::kw_const_cast: return 2; |
| 36 | case tok::kw_dynamic_cast: return 3; |
| 37 | case tok::kw_reinterpret_cast: return 4; |
| 38 | case tok::kw_static_cast: return 5; |
| 39 | default: |
| 40 | llvm_unreachable("Unknown type for digraph error message."); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | |
| 45 | bool Parser::areTokensAdjacent(const Token &First, const Token &Second) { |
| 46 | SourceManager &SM = PP.getSourceManager(); |
| 47 | SourceLocation FirstLoc = SM.getSpellingLoc(First.getLocation()); |
| 48 | SourceLocation FirstEnd = FirstLoc.getLocWithOffset(First.getLength()); |
| 49 | return FirstEnd == SM.getSpellingLoc(Second.getLocation()); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, |
| 54 | Token &ColonToken, tok::TokenKind Kind, bool AtDigraph) { |
| 55 | |
| 56 | if (!AtDigraph) |
| 57 | PP.Lex(DigraphToken); |
| 58 | PP.Lex(ColonToken); |
| 59 | |
| 60 | SourceRange Range; |
| 61 | Range.setBegin(DigraphToken.getLocation()); |
| 62 | Range.setEnd(ColonToken.getLocation()); |
| 63 | P.Diag(DigraphToken.getLocation(), diag::err_missing_whitespace_digraph) |
| 64 | << SelectDigraphErrorMessage(Kind) |
| 65 | << FixItHint::CreateReplacement(Range, "< ::"); |
| 66 | |
| 67 | |
| 68 | ColonToken.setKind(tok::coloncolon); |
| 69 | ColonToken.setLocation(ColonToken.getLocation().getLocWithOffset(-1)); |
| 70 | ColonToken.setLength(2); |
| 71 | DigraphToken.setKind(tok::less); |
| 72 | DigraphToken.setLength(1); |
| 73 | |
| 74 | |
| 75 | PP.EnterToken(ColonToken, true); |
| 76 | if (!AtDigraph) |
| 77 | PP.EnterToken(DigraphToken, true); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | |
| 82 | void Parser::CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectType, |
| 83 | bool EnteringContext, |
| 84 | IdentifierInfo &II, CXXScopeSpec &SS) { |
| 85 | if (!Next.is(tok::l_square) || Next.getLength() != 2) |
| 86 | return; |
| 87 | |
| 88 | Token SecondToken = GetLookAheadToken(2); |
| 89 | if (!SecondToken.is(tok::colon) || !areTokensAdjacent(Next, SecondToken)) |
| 90 | return; |
| 91 | |
| 92 | TemplateTy Template; |
| 93 | UnqualifiedId TemplateName; |
| 94 | TemplateName.setIdentifier(&II, Tok.getLocation()); |
| 95 | bool MemberOfUnknownSpecialization; |
| 96 | if (!Actions.isTemplateName(getCurScope(), SS, false, |
| 97 | TemplateName, ObjectType, EnteringContext, |
| 98 | Template, MemberOfUnknownSpecialization)) |
| 99 | return; |
| 100 | |
| 101 | FixDigraph(*this, PP, Next, SecondToken, tok::unknown, |
| 102 | false); |
| 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 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | bool Parser::ParseOptionalCXXScopeSpecifier( |
| 155 | CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, |
| 156 | bool EnteringContext, bool *MayBePseudoDestructor, bool IsTypename, |
| 157 | IdentifierInfo **LastII, bool OnlyNamespace, bool InUsingDeclaration) { |
| 158 | assert(getLangOpts().CPlusPlus && |
| 159 | "Call sites of this function should be guarded by checking for C++"); |
| 160 | |
| 161 | if (Tok.is(tok::annot_cxxscope)) { |
| 162 | assert(!LastII && "want last identifier but have already annotated scope"); |
| 163 | assert(!MayBePseudoDestructor && "unexpected annot_cxxscope"); |
| 164 | Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), |
| 165 | Tok.getAnnotationRange(), |
| 166 | SS); |
| 167 | ConsumeAnnotationToken(); |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | bool CheckForDestructor = false; |
| 173 | if (MayBePseudoDestructor && *MayBePseudoDestructor) { |
| 174 | CheckForDestructor = true; |
| 175 | *MayBePseudoDestructor = false; |
| 176 | } |
| 177 | |
| 178 | if (LastII) |
| 179 | *LastII = nullptr; |
| 180 | |
| 181 | bool HasScopeSpecifier = false; |
| 182 | |
| 183 | if (Tok.is(tok::coloncolon)) { |
| 184 | |
| 185 | tok::TokenKind NextKind = NextToken().getKind(); |
| 186 | if (NextKind == tok::kw_new || NextKind == tok::kw_delete) |
| 187 | return false; |
| 188 | |
| 189 | if (NextKind == tok::l_brace) { |
| 190 | |
| 191 | |
| 192 | Diag(ConsumeToken(), diag::err_expected) << tok::identifier; |
| 193 | } else { |
| 194 | |
| 195 | if (Actions.ActOnCXXGlobalScopeSpecifier(ConsumeToken(), SS)) |
| 196 | return true; |
| 197 | |
| 198 | HasScopeSpecifier = true; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if (Tok.is(tok::kw___super)) { |
| 203 | SourceLocation SuperLoc = ConsumeToken(); |
| 204 | if (!Tok.is(tok::coloncolon)) { |
| 205 | Diag(Tok.getLocation(), diag::err_expected_coloncolon_after_super); |
| 206 | return true; |
| 207 | } |
| 208 | |
| 209 | return Actions.ActOnSuperScopeSpecifier(SuperLoc, ConsumeToken(), SS); |
| 210 | } |
| 211 | |
| 212 | if (!HasScopeSpecifier && |
| 213 | Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) { |
| 214 | DeclSpec DS(AttrFactory); |
| 215 | SourceLocation DeclLoc = Tok.getLocation(); |
| 216 | SourceLocation EndLoc = ParseDecltypeSpecifier(DS); |
| 217 | |
| 218 | SourceLocation CCLoc; |
| 219 | |
| 220 | |
| 221 | if (DS.getTypeSpecType() == DeclSpec::TST_decltype_auto || |
| 222 | !TryConsumeToken(tok::coloncolon, CCLoc)) { |
| 223 | AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc); |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc)) |
| 228 | SS.SetInvalid(SourceRange(DeclLoc, CCLoc)); |
| 229 | |
| 230 | HasScopeSpecifier = true; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | auto SavedType = PreferredType; |
| 235 | while (true) { |
| 236 | if (HasScopeSpecifier) { |
| 237 | if (Tok.is(tok::code_completion)) { |
| 238 | cutOffParsing(); |
| 239 | |
| 240 | |
| 241 | Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext, |
| 242 | InUsingDeclaration, ObjectType.get(), |
| 243 | SavedType.get(SS.getBeginLoc())); |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | SS.setEndLoc(Tok.getLocation()); |
| 249 | return true; |
| 250 | } |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | ObjectType = nullptr; |
| 263 | } |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | if (Tok.is(tok::kw_template)) { |
| 271 | |
| 272 | |
| 273 | |
| 274 | if (!HasScopeSpecifier && !ObjectType) |
| 275 | break; |
| 276 | |
| 277 | TentativeParsingAction TPA(*this); |
| 278 | SourceLocation TemplateKWLoc = ConsumeToken(); |
| 279 | |
| 280 | UnqualifiedId TemplateName; |
| 281 | if (Tok.is(tok::identifier)) { |
| 282 | |
| 283 | TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 284 | ConsumeToken(); |
| 285 | } else if (Tok.is(tok::kw_operator)) { |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, |
| 291 | TemplateName)) { |
| 292 | TPA.Commit(); |
| 293 | break; |
| 294 | } |
| 295 | |
| 296 | if (TemplateName.getKind() != UnqualifiedIdKind::IK_OperatorFunctionId && |
| 297 | TemplateName.getKind() != UnqualifiedIdKind::IK_LiteralOperatorId) { |
| 298 | Diag(TemplateName.getSourceRange().getBegin(), |
| 299 | diag::err_id_after_template_in_nested_name_spec) |
| 300 | << TemplateName.getSourceRange(); |
| 301 | TPA.Commit(); |
| 302 | break; |
| 303 | } |
| 304 | } else { |
| 305 | TPA.Revert(); |
| 306 | break; |
| 307 | } |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | if (Tok.isNot(tok::less)) { |
| 313 | TPA.Revert(); |
| 314 | break; |
| 315 | } |
| 316 | |
| 317 | |
| 318 | TPA.Commit(); |
| 319 | TemplateTy Template; |
| 320 | TemplateNameKind TNK = Actions.ActOnTemplateName( |
| 321 | getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType, |
| 322 | EnteringContext, Template, true); |
| 323 | if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc, |
| 324 | TemplateName, false)) |
| 325 | return true; |
| 326 | |
| 327 | continue; |
| 328 | } |
| 329 | |
| 330 | if (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) { |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
| 339 | if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde)) { |
| 340 | *MayBePseudoDestructor = true; |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | if (LastII) |
| 345 | *LastII = TemplateId->Name; |
| 346 | |
| 347 | |
| 348 | ConsumeAnnotationToken(); |
| 349 | |
| 350 | assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!"); |
| 351 | SourceLocation CCLoc = ConsumeToken(); |
| 352 | |
| 353 | HasScopeSpecifier = true; |
| 354 | |
| 355 | ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(), |
| 356 | TemplateId->NumArgs); |
| 357 | |
| 358 | if (TemplateId->isInvalid() || |
| 359 | 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 | *MayBePseudoDestructor = true; |
| 423 | return false; |
| 424 | } |
| 425 | |
| 426 | if (ColonIsSacred) { |
| 427 | const Token &Next2 = GetLookAheadToken(2); |
| 428 | if (Next2.is(tok::kw_private) || Next2.is(tok::kw_protected) || |
| 429 | Next2.is(tok::kw_public) || Next2.is(tok::kw_virtual)) { |
| 430 | Diag(Next2, diag::err_unexpected_token_in_nested_name_spec) |
| 431 | << Next2.getName() |
| 432 | << FixItHint::CreateReplacement(Next.getLocation(), ":"); |
| 433 | Token ColonColon; |
| 434 | PP.Lex(ColonColon); |
| 435 | ColonColon.setKind(tok::colon); |
| 436 | PP.EnterToken(ColonColon, true); |
| 437 | break; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | if (LastII) |
| 442 | *LastII = &II; |
| 443 | |
| 444 | |
| 445 | |
| 446 | Token Identifier = Tok; |
| 447 | SourceLocation IdLoc = ConsumeToken(); |
| 448 | assert(Tok.isOneOf(tok::coloncolon, tok::colon) && |
| 449 | "NextToken() not working properly!"); |
| 450 | Token ColonColon = Tok; |
| 451 | SourceLocation CCLoc = ConsumeToken(); |
| 452 | |
| 453 | bool IsCorrectedToColon = false; |
| 454 | bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon : nullptr; |
| 455 | if (Actions.ActOnCXXNestedNameSpecifier( |
| 456 | getCurScope(), IdInfo, EnteringContext, SS, false, |
| 457 | CorrectionFlagPtr, OnlyNamespace)) { |
| 458 | |
| 459 | |
| 460 | if (CorrectionFlagPtr && IsCorrectedToColon) { |
| 461 | ColonColon.setKind(tok::colon); |
| 462 | PP.EnterToken(Tok, true); |
| 463 | PP.EnterToken(ColonColon, true); |
| 464 | Tok = Identifier; |
| 465 | break; |
| 466 | } |
| 467 | SS.SetInvalid(SourceRange(IdLoc, CCLoc)); |
| 468 | } |
| 469 | HasScopeSpecifier = true; |
| 470 | continue; |
| 471 | } |
| 472 | |
| 473 | CheckForTemplateAndDigraph(Next, ObjectType, EnteringContext, II, SS); |
| 474 | |
| 475 | |
| 476 | |
| 477 | if (Next.is(tok::less)) { |
| 478 | |
| 479 | TemplateTy Template; |
| 480 | UnqualifiedId TemplateName; |
| 481 | TemplateName.setIdentifier(&II, Tok.getLocation()); |
| 482 | bool MemberOfUnknownSpecialization; |
| 483 | if (TemplateNameKind TNK = Actions.isTemplateName(getCurScope(), SS, |
| 484 | false, |
| 485 | TemplateName, |
| 486 | ObjectType, |
| 487 | EnteringContext, |
| 488 | Template, |
| 489 | MemberOfUnknownSpecialization)) { |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | if (!IsTypename && TNK == TNK_Undeclared_template && |
| 495 | isTemplateArgumentList(1) == TPResult::False) |
| 496 | break; |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | ConsumeToken(); |
| 506 | if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), |
| 507 | TemplateName, false)) |
| 508 | return true; |
| 509 | continue; |
| 510 | } |
| 511 | |
| 512 | if (MemberOfUnknownSpecialization && (ObjectType || SS.isSet()) && |
| 513 | (IsTypename || isTemplateArgumentList(1) == TPResult::True)) { |
| 514 | |
| 515 | |
| 516 | if (!ObjectHadErrors) { |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | unsigned DiagID = diag::err_missing_dependent_template_keyword; |
| 522 | if (getLangOpts().MicrosoftExt) |
| 523 | DiagID = diag::warn_missing_dependent_template_keyword; |
| 524 | |
| 525 | Diag(Tok.getLocation(), DiagID) |
| 526 | << II.getName() |
| 527 | << FixItHint::CreateInsertion(Tok.getLocation(), "template "); |
| 528 | } |
| 529 | |
| 530 | SourceLocation TemplateNameLoc = ConsumeToken(); |
| 531 | |
| 532 | TemplateNameKind TNK = Actions.ActOnTemplateName( |
| 533 | getCurScope(), SS, TemplateNameLoc, TemplateName, ObjectType, |
| 534 | EnteringContext, Template, true); |
| 535 | if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), |
| 536 | TemplateName, false)) |
| 537 | return true; |
| 538 | |
| 539 | continue; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | |
| 544 | |
| 545 | break; |
| 546 | } |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | if (CheckForDestructor && !HasScopeSpecifier && Tok.is(tok::tilde)) |
| 552 | *MayBePseudoDestructor = true; |
| 553 | |
| 554 | return false; |
| 555 | } |
| 556 | |
| 557 | ExprResult Parser::tryParseCXXIdExpression(CXXScopeSpec &SS, |
| 558 | bool isAddressOfOperand, |
| 559 | Token &Replacement) { |
| 560 | ExprResult E; |
| 561 | |
| 562 | |
| 563 | switch (Tok.getKind()) { |
| 564 | case tok::annot_non_type: { |
| 565 | NamedDecl *ND = getNonTypeAnnotation(Tok); |
| 566 | SourceLocation Loc = ConsumeAnnotationToken(); |
| 567 | E = Actions.ActOnNameClassifiedAsNonType(getCurScope(), SS, ND, Loc, Tok); |
| 568 | break; |
| 569 | } |
| 570 | |
| 571 | case tok::annot_non_type_dependent: { |
| 572 | IdentifierInfo *II = getIdentifierAnnotation(Tok); |
| 573 | SourceLocation Loc = ConsumeAnnotationToken(); |
| 574 | |
| 575 | |
| 576 | |
| 577 | if (isAddressOfOperand && isPostfixExpressionSuffixStart()) |
| 578 | isAddressOfOperand = false; |
| 579 | |
| 580 | E = Actions.ActOnNameClassifiedAsDependentNonType(SS, II, Loc, |
| 581 | isAddressOfOperand); |
| 582 | break; |
| 583 | } |
| 584 | |
| 585 | case tok::annot_non_type_undeclared: { |
| 586 | assert(SS.isEmpty() && |
| 587 | "undeclared non-type annotation should be unqualified"); |
| 588 | IdentifierInfo *II = getIdentifierAnnotation(Tok); |
| 589 | SourceLocation Loc = ConsumeAnnotationToken(); |
| 590 | E = Actions.ActOnNameClassifiedAsUndeclaredNonType(II, Loc); |
| 591 | break; |
| 592 | } |
| 593 | |
| 594 | default: |
| 595 | SourceLocation TemplateKWLoc; |
| 596 | UnqualifiedId Name; |
| 597 | if (ParseUnqualifiedId(SS, nullptr, |
| 598 | false, |
| 599 | false, |
| 600 | false, |
| 601 | false, |
| 602 | false, &TemplateKWLoc, Name)) |
| 603 | return ExprError(); |
| 604 | |
| 605 | |
| 606 | |
| 607 | if (isAddressOfOperand && isPostfixExpressionSuffixStart()) |
| 608 | isAddressOfOperand = false; |
| 609 | |
| 610 | E = Actions.ActOnIdExpression( |
| 611 | getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren), |
| 612 | isAddressOfOperand, nullptr, false, |
| 613 | &Replacement); |
| 614 | break; |
| 615 | } |
| 616 | |
| 617 | if (!E.isInvalid() && !E.isUnset() && Tok.is(tok::less)) |
| 618 | checkPotentialAngleBracket(E); |
| 619 | return E; |
| 620 | } |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 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 | ExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) { |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | CXXScopeSpec SS; |
| 670 | ParseOptionalCXXScopeSpecifier(SS, nullptr, |
| 671 | false, |
| 672 | false); |
| 673 | |
| 674 | Token Replacement; |
| 675 | ExprResult Result = |
| 676 | tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement); |
| 677 | if (Result.isUnset()) { |
| 678 | |
| 679 | |
| 680 | UnconsumeToken(Replacement); |
| 681 | Result = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement); |
| 682 | } |
| 683 | assert(!Result.isUnset() && "Typo correction suggested a keyword replacement " |
| 684 | "for a previous keyword suggestion"); |
| 685 | return Result; |
| 686 | } |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | ExprResult Parser::ParseLambdaExpression() { |
| 734 | |
| 735 | LambdaIntroducer Intro; |
| 736 | if (ParseLambdaIntroducer(Intro)) { |
| 737 | SkipUntil(tok::r_square, StopAtSemi); |
| 738 | SkipUntil(tok::l_brace, StopAtSemi); |
| 739 | SkipUntil(tok::r_brace, StopAtSemi); |
| 740 | return ExprError(); |
| 741 | } |
| 742 | |
| 743 | return ParseLambdaExpressionAfterIntroducer(Intro); |
| 744 | } |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | ExprResult Parser::TryParseLambdaExpression() { |
| 751 | assert(getLangOpts().CPlusPlus11 |
| 752 | && Tok.is(tok::l_square) |
| 753 | && "Not at the start of a possible lambda expression."); |
| 754 | |
| 755 | const Token Next = NextToken(); |
| 756 | if (Next.is(tok::eof)) |
| 757 | return ExprEmpty(); |
| 758 | |
| 759 | const Token After = GetLookAheadToken(2); |
| 760 | |
| 761 | if (Next.is(tok::r_square) || |
| 762 | Next.is(tok::equal) || |
| 763 | (Next.is(tok::amp) && |
| 764 | After.isOneOf(tok::r_square, tok::comma)) || |
| 765 | (Next.is(tok::identifier) && |
| 766 | After.is(tok::r_square)) || |
| 767 | Next.is(tok::ellipsis)) { |
| 768 | return ParseLambdaExpression(); |
| 769 | } |
| 770 | |
| 771 | |
| 772 | |
| 773 | if (Next.is(tok::identifier) && After.is(tok::identifier)) |
| 774 | return ExprEmpty(); |
| 775 | |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | LambdaIntroducer Intro; |
| 782 | { |
| 783 | TentativeParsingAction TPA(*this); |
| 784 | LambdaIntroducerTentativeParse Tentative; |
| 785 | if (ParseLambdaIntroducer(Intro, &Tentative)) { |
| 786 | TPA.Commit(); |
| 787 | return ExprError(); |
| 788 | } |
| 789 | |
| 790 | switch (Tentative) { |
| 791 | case LambdaIntroducerTentativeParse::Success: |
| 792 | TPA.Commit(); |
| 793 | break; |
| 794 | |
| 795 | case LambdaIntroducerTentativeParse::Incomplete: |
| 796 | |
| 797 | |
| 798 | TPA.Revert(); |
| 799 | Intro = LambdaIntroducer(); |
| 800 | if (ParseLambdaIntroducer(Intro)) |
| 801 | return ExprError(); |
| 802 | break; |
| 803 | |
| 804 | case LambdaIntroducerTentativeParse::MessageSend: |
| 805 | case LambdaIntroducerTentativeParse::Invalid: |
| 806 | |
| 807 | TPA.Revert(); |
| 808 | return ExprEmpty(); |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | return ParseLambdaExpressionAfterIntroducer(Intro); |
| 813 | } |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | bool Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, |
| 825 | LambdaIntroducerTentativeParse *Tentative) { |
| 826 | if (Tentative) |
| 827 | *Tentative = LambdaIntroducerTentativeParse::Success; |
| 828 | |
| 829 | assert(Tok.is(tok::l_square) && "Lambda expressions begin with '['."); |
| 830 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 831 | T.consumeOpen(); |
| 832 | |
| 833 | Intro.Range.setBegin(T.getOpenLocation()); |
| 834 | |
| 835 | bool First = true; |
| 836 | |
| 837 | |
| 838 | |
| 839 | auto Invalid = [&](llvm::function_ref<void()> Action) { |
| 840 | if (Tentative) { |
| 841 | *Tentative = LambdaIntroducerTentativeParse::Invalid; |
| 842 | return false; |
| 843 | } |
| 844 | Action(); |
| 845 | return true; |
| 846 | }; |
| 847 | |
| 848 | |
| 849 | |
| 850 | auto NonTentativeAction = [&](llvm::function_ref<void()> Action) { |
| 851 | if (Tentative) |
| 852 | *Tentative = LambdaIntroducerTentativeParse::Incomplete; |
| 853 | else |
| 854 | Action(); |
| 855 | }; |
| 856 | |
| 857 | |
| 858 | if (Tok.is(tok::amp) && |
| 859 | (NextToken().is(tok::comma) || NextToken().is(tok::r_square))) { |
| 860 | Intro.Default = LCD_ByRef; |
| 861 | Intro.DefaultLoc = ConsumeToken(); |
| 862 | First = false; |
| 863 | if (!Tok.getIdentifierInfo()) { |
| 864 | |
| 865 | |
| 866 | Tentative = nullptr; |
| 867 | } |
| 868 | } else if (Tok.is(tok::equal)) { |
| 869 | Intro.Default = LCD_ByCopy; |
| 870 | Intro.DefaultLoc = ConsumeToken(); |
| 871 | First = false; |
| 872 | Tentative = nullptr; |
| 873 | } |
| 874 | |
| 875 | while (Tok.isNot(tok::r_square)) { |
| 876 | if (!First) { |
| 877 | if (Tok.isNot(tok::comma)) { |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | if (Tok.is(tok::code_completion) && |
| 883 | !(getLangOpts().ObjC && Tentative)) { |
| 884 | cutOffParsing(); |
| 885 | Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, |
| 886 | false); |
| 887 | break; |
| 888 | } |
| 889 | |
| 890 | return Invalid([&] { |
| 891 | Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare); |
| 892 | }); |
| 893 | } |
| 894 | ConsumeToken(); |
| 895 | } |
| 896 | |
| 897 | if (Tok.is(tok::code_completion)) { |
| 898 | cutOffParsing(); |
| 899 | |
| 900 | |
| 901 | if (getLangOpts().ObjC && Tentative && First) |
| 902 | Actions.CodeCompleteObjCMessageReceiver(getCurScope()); |
| 903 | else |
| 904 | Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, |
| 905 | false); |
| 906 | break; |
| 907 | } |
| 908 | |
| 909 | First = false; |
| 910 | |
| 911 | |
| 912 | LambdaCaptureKind Kind = LCK_ByCopy; |
| 913 | LambdaCaptureInitKind InitKind = LambdaCaptureInitKind::NoInit; |
| 914 | SourceLocation Loc; |
| 915 | IdentifierInfo *Id = nullptr; |
| 916 | SourceLocation EllipsisLocs[4]; |
| 917 | ExprResult Init; |
| 918 | SourceLocation LocStart = Tok.getLocation(); |
| 919 | |
| 920 | if (Tok.is(tok::star)) { |
| 921 | Loc = ConsumeToken(); |
| 922 | if (Tok.is(tok::kw_this)) { |
| 923 | ConsumeToken(); |
| 924 | Kind = LCK_StarThis; |
| 925 | } else { |
| 926 | return Invalid([&] { |
| 927 | Diag(Tok.getLocation(), diag::err_expected_star_this_capture); |
| 928 | }); |
| 929 | } |
| 930 | } else if (Tok.is(tok::kw_this)) { |
| 931 | Kind = LCK_This; |
| 932 | Loc = ConsumeToken(); |
| 933 | } else if (Tok.isOneOf(tok::amp, tok::equal) && |
| 934 | NextToken().isOneOf(tok::comma, tok::r_square) && |
| 935 | Intro.Default == LCD_None) { |
| 936 | |
| 937 | |
| 938 | |
| 939 | |
| 940 | return Invalid( |
| 941 | [&] { Diag(Tok.getLocation(), diag::err_capture_default_first); }); |
| 942 | } else { |
| 943 | TryConsumeToken(tok::ellipsis, EllipsisLocs[0]); |
| 944 | |
| 945 | if (Tok.is(tok::amp)) { |
| 946 | Kind = LCK_ByRef; |
| 947 | ConsumeToken(); |
| 948 | |
| 949 | if (Tok.is(tok::code_completion)) { |
| 950 | cutOffParsing(); |
| 951 | Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, |
| 952 | true); |
| 953 | break; |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | TryConsumeToken(tok::ellipsis, EllipsisLocs[1]); |
| 958 | |
| 959 | if (Tok.is(tok::identifier)) { |
| 960 | Id = Tok.getIdentifierInfo(); |
| 961 | Loc = ConsumeToken(); |
| 962 | } else if (Tok.is(tok::kw_this)) { |
| 963 | return Invalid([&] { |
| 964 | |
| 965 | Diag(Tok.getLocation(), diag::err_this_captured_by_reference); |
| 966 | }); |
| 967 | } else { |
| 968 | return Invalid([&] { |
| 969 | Diag(Tok.getLocation(), diag::err_expected_capture); |
| 970 | }); |
| 971 | } |
| 972 | |
| 973 | TryConsumeToken(tok::ellipsis, EllipsisLocs[2]); |
| 974 | |
| 975 | if (Tok.is(tok::l_paren)) { |
| 976 | BalancedDelimiterTracker Parens(*this, tok::l_paren); |
| 977 | Parens.consumeOpen(); |
| 978 | |
| 979 | InitKind = LambdaCaptureInitKind::DirectInit; |
| 980 | |
| 981 | ExprVector Exprs; |
| 982 | CommaLocsTy Commas; |
| 983 | if (Tentative) { |
| 984 | Parens.skipToEnd(); |
| 985 | *Tentative = LambdaIntroducerTentativeParse::Incomplete; |
| 986 | } else if (ParseExpressionList(Exprs, Commas)) { |
| 987 | Parens.skipToEnd(); |
| 988 | Init = ExprError(); |
| 989 | } else { |
| 990 | Parens.consumeClose(); |
| 991 | Init = Actions.ActOnParenListExpr(Parens.getOpenLocation(), |
| 992 | Parens.getCloseLocation(), |
| 993 | Exprs); |
| 994 | } |
| 995 | } else if (Tok.isOneOf(tok::l_brace, tok::equal)) { |
| 996 | |
| 997 | |
| 998 | |
| 999 | EnterExpressionEvaluationContext EC( |
| 1000 | Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| 1001 | |
| 1002 | if (TryConsumeToken(tok::equal)) |
| 1003 | InitKind = LambdaCaptureInitKind::CopyInit; |
| 1004 | else |
| 1005 | InitKind = LambdaCaptureInitKind::ListInit; |
| 1006 | |
| 1007 | if (!Tentative) { |
| 1008 | Init = ParseInitializer(); |
| 1009 | } else if (Tok.is(tok::l_brace)) { |
| 1010 | BalancedDelimiterTracker Braces(*this, tok::l_brace); |
| 1011 | Braces.consumeOpen(); |
| 1012 | Braces.skipToEnd(); |
| 1013 | *Tentative = LambdaIntroducerTentativeParse::Incomplete; |
| 1014 | } else { |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | |
| 1019 | |
| 1020 | |
| 1021 | |
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 | |
| 1026 | |
| 1027 | |
| 1028 | |
| 1029 | |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | SourceLocation StartLoc = Tok.getLocation(); |
| 1036 | InMessageExpressionRAIIObject MaybeInMessageExpression(*this, true); |
| 1037 | Init = ParseInitializer(); |
| 1038 | if (!Init.isInvalid()) |
| 1039 | Init = Actions.CorrectDelayedTyposInExpr(Init.get()); |
| 1040 | |
| 1041 | if (Tok.getLocation() != StartLoc) { |
| 1042 | |
| 1043 | PP.RevertCachedTokens(1); |
| 1044 | |
| 1045 | |
| 1046 | Tok.setLocation(StartLoc); |
| 1047 | Tok.setKind(tok::annot_primary_expr); |
| 1048 | setExprAnnotation(Tok, Init); |
| 1049 | Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation()); |
| 1050 | PP.AnnotateCachedTokens(Tok); |
| 1051 | |
| 1052 | |
| 1053 | ConsumeAnnotationToken(); |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | TryConsumeToken(tok::ellipsis, EllipsisLocs[3]); |
| 1059 | } |
| 1060 | |
| 1061 | |
| 1062 | if (Tentative && Tok.is(tok::identifier) && |
| 1063 | NextToken().isOneOf(tok::colon, tok::r_square)) { |
| 1064 | |
| 1065 | *Tentative = LambdaIntroducerTentativeParse::MessageSend; |
| 1066 | return false; |
| 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | SourceLocation EllipsisLoc; |
| 1071 | if (std::any_of(std::begin(EllipsisLocs), std::end(EllipsisLocs), |
| 1072 | [](SourceLocation Loc) { return Loc.isValid(); })) { |
| 1073 | |
| 1074 | |
| 1075 | bool InitCapture = InitKind != LambdaCaptureInitKind::NoInit; |
| 1076 | SourceLocation *ExpectedEllipsisLoc = |
| 1077 | !InitCapture ? &EllipsisLocs[2] : |
| 1078 | Kind == LCK_ByRef ? &EllipsisLocs[1] : |
| 1079 | &EllipsisLocs[0]; |
| 1080 | EllipsisLoc = *ExpectedEllipsisLoc; |
| 1081 | |
| 1082 | unsigned DiagID = 0; |
| 1083 | if (EllipsisLoc.isInvalid()) { |
| 1084 | DiagID = diag::err_lambda_capture_misplaced_ellipsis; |
| 1085 | for (SourceLocation Loc : EllipsisLocs) { |
| 1086 | if (Loc.isValid()) |
| 1087 | EllipsisLoc = Loc; |
| 1088 | } |
| 1089 | } else { |
| 1090 | unsigned NumEllipses = std::accumulate( |
| 1091 | std::begin(EllipsisLocs), std::end(EllipsisLocs), 0, |
| 1092 | [](int N, SourceLocation Loc) { return N + Loc.isValid(); }); |
| 1093 | if (NumEllipses > 1) |
| 1094 | DiagID = diag::err_lambda_capture_multiple_ellipses; |
| 1095 | } |
| 1096 | if (DiagID) { |
| 1097 | NonTentativeAction([&] { |
| 1098 | |
| 1099 | SourceLocation DiagLoc; |
| 1100 | for (SourceLocation &Loc : EllipsisLocs) { |
| 1101 | if (&Loc != ExpectedEllipsisLoc && Loc.isValid()) { |
| 1102 | DiagLoc = Loc; |
| 1103 | break; |
| 1104 | } |
| 1105 | } |
| 1106 | assert(DiagLoc.isValid() && "no location for diagnostic"); |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | auto &&D = Diag(DiagLoc, DiagID); |
| 1111 | if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) { |
| 1112 | SourceLocation ExpectedLoc = |
| 1113 | InitCapture ? Loc |
| 1114 | : Lexer::getLocForEndOfToken( |
| 1115 | Loc, 0, PP.getSourceManager(), getLangOpts()); |
| 1116 | D << InitCapture << FixItHint::CreateInsertion(ExpectedLoc, "..."); |
| 1117 | } |
| 1118 | for (SourceLocation &Loc : EllipsisLocs) { |
| 1119 | if (&Loc != ExpectedEllipsisLoc && Loc.isValid()) |
| 1120 | D << FixItHint::CreateRemoval(Loc); |
| 1121 | } |
| 1122 | }); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | ParsedType InitCaptureType; |
| 1131 | if (Init.isUsable()) |
| 1132 | Init = Actions.CorrectDelayedTyposInExpr(Init.get()); |
| 1133 | if (Init.isUsable()) { |
| 1134 | NonTentativeAction([&] { |
| 1135 | |
| 1136 | |
| 1137 | Expr *InitExpr = Init.get(); |
| 1138 | |
| 1139 | |
| 1140 | InitCaptureType = Actions.actOnLambdaInitCaptureInitialization( |
| 1141 | Loc, Kind == LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr); |
| 1142 | Init = InitExpr; |
| 1143 | }); |
| 1144 | } |
| 1145 | |
| 1146 | SourceLocation LocEnd = PrevTokLocation; |
| 1147 | |
| 1148 | Intro.addCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init, |
| 1149 | InitCaptureType, SourceRange(LocStart, LocEnd)); |
| 1150 | } |
| 1151 | |
| 1152 | T.consumeClose(); |
| 1153 | Intro.Range.setEnd(T.getCloseLocation()); |
| 1154 | return false; |
| 1155 | } |
| 1156 | |
| 1157 | static void tryConsumeLambdaSpecifierToken(Parser &P, |
| 1158 | SourceLocation &MutableLoc, |
| 1159 | SourceLocation &ConstexprLoc, |
| 1160 | SourceLocation &ConstevalLoc, |
| 1161 | SourceLocation &DeclEndLoc) { |
| 1162 | assert(MutableLoc.isInvalid()); |
| 1163 | assert(ConstexprLoc.isInvalid()); |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | while (true) { |
| 1169 | switch (P.getCurToken().getKind()) { |
| 1170 | case tok::kw_mutable: { |
| 1171 | if (MutableLoc.isValid()) { |
| 1172 | P.Diag(P.getCurToken().getLocation(), |
| 1173 | diag::err_lambda_decl_specifier_repeated) |
| 1174 | << 0 << FixItHint::CreateRemoval(P.getCurToken().getLocation()); |
| 1175 | } |
| 1176 | MutableLoc = P.ConsumeToken(); |
| 1177 | DeclEndLoc = MutableLoc; |
| 1178 | break ; |
| 1179 | } |
| 1180 | case tok::kw_constexpr: |
| 1181 | if (ConstexprLoc.isValid()) { |
| 1182 | P.Diag(P.getCurToken().getLocation(), |
| 1183 | diag::err_lambda_decl_specifier_repeated) |
| 1184 | << 1 << FixItHint::CreateRemoval(P.getCurToken().getLocation()); |
| 1185 | } |
| 1186 | ConstexprLoc = P.ConsumeToken(); |
| 1187 | DeclEndLoc = ConstexprLoc; |
| 1188 | break ; |
| 1189 | case tok::kw_consteval: |
| 1190 | if (ConstevalLoc.isValid()) { |
| 1191 | P.Diag(P.getCurToken().getLocation(), |
| 1192 | diag::err_lambda_decl_specifier_repeated) |
| 1193 | << 2 << FixItHint::CreateRemoval(P.getCurToken().getLocation()); |
| 1194 | } |
| 1195 | ConstevalLoc = P.ConsumeToken(); |
| 1196 | DeclEndLoc = ConstevalLoc; |
| 1197 | break ; |
| 1198 | default: |
| 1199 | return; |
| 1200 | } |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | static void |
| 1205 | addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, |
| 1206 | DeclSpec &DS) { |
| 1207 | if (ConstexprLoc.isValid()) { |
| 1208 | P.Diag(ConstexprLoc, !P.getLangOpts().CPlusPlus17 |
| 1209 | ? diag::ext_constexpr_on_lambda_cxx17 |
| 1210 | : diag::warn_cxx14_compat_constexpr_on_lambda); |
| 1211 | const char *PrevSpec = nullptr; |
| 1212 | unsigned DiagID = 0; |
| 1213 | DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, ConstexprLoc, PrevSpec, |
| 1214 | DiagID); |
| 1215 | assert(PrevSpec == nullptr && DiagID == 0 && |
| 1216 | "Constexpr cannot have been set previously!"); |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | static void addConstevalToLambdaDeclSpecifier(Parser &P, |
| 1221 | SourceLocation ConstevalLoc, |
| 1222 | DeclSpec &DS) { |
| 1223 | if (ConstevalLoc.isValid()) { |
| 1224 | P.Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval); |
| 1225 | const char *PrevSpec = nullptr; |
| 1226 | unsigned DiagID = 0; |
| 1227 | DS.SetConstexprSpec(ConstexprSpecKind::Consteval, ConstevalLoc, PrevSpec, |
| 1228 | DiagID); |
| 1229 | if (DiagID != 0) |
| 1230 | P.Diag(ConstevalLoc, DiagID) << PrevSpec; |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | ExprResult Parser::ParseLambdaExpressionAfterIntroducer( |
| 1237 | LambdaIntroducer &Intro) { |
| 1238 | SourceLocation LambdaBeginLoc = Intro.Range.getBegin(); |
| 1239 | Diag(LambdaBeginLoc, diag::warn_cxx98_compat_lambda); |
| 1240 | |
| 1241 | PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc, |
| 1242 | "lambda expression parsing"); |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | DeclSpec DS(AttrFactory); |
| 1251 | Declarator D(DS, DeclaratorContext::LambdaExpr); |
| 1252 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
| 1253 | Actions.PushLambdaScope(); |
| 1254 | |
| 1255 | ParsedAttributes Attr(AttrFactory); |
| 1256 | if (getLangOpts().CUDA) { |
| 1257 | |
| 1258 | |
| 1259 | MaybeParseGNUAttributes(D); |
| 1260 | } |
| 1261 | |
| 1262 | |
| 1263 | |
| 1264 | auto WarnIfHasCUDATargetAttr = [&] { |
| 1265 | if (getLangOpts().CUDA) |
| 1266 | for (const ParsedAttr &A : Attr) |
| 1267 | if (A.getKind() == ParsedAttr::AT_CUDADevice || |
| 1268 | A.getKind() == ParsedAttr::AT_CUDAHost || |
| 1269 | A.getKind() == ParsedAttr::AT_CUDAGlobal) |
| 1270 | Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position) |
| 1271 | << A.getAttrName()->getName(); |
| 1272 | }; |
| 1273 | |
| 1274 | MultiParseScope TemplateParamScope(*this); |
| 1275 | if (Tok.is(tok::less)) { |
| 1276 | Diag(Tok, getLangOpts().CPlusPlus20 |
| 1277 | ? diag::warn_cxx17_compat_lambda_template_parameter_list |
| 1278 | : diag::ext_lambda_template_parameter_list); |
| 1279 | |
| 1280 | SmallVector<NamedDecl*, 4> TemplateParams; |
| 1281 | SourceLocation LAngleLoc, RAngleLoc; |
| 1282 | if (ParseTemplateParameters(TemplateParamScope, |
| 1283 | CurTemplateDepthTracker.getDepth(), |
| 1284 | TemplateParams, LAngleLoc, RAngleLoc)) { |
| 1285 | Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); |
| 1286 | return ExprError(); |
| 1287 | } |
| 1288 | |
| 1289 | if (TemplateParams.empty()) { |
| 1290 | Diag(RAngleLoc, |
| 1291 | diag::err_lambda_template_parameter_list_empty); |
| 1292 | } else { |
| 1293 | ExprResult RequiresClause; |
| 1294 | if (TryConsumeToken(tok::kw_requires)) { |
| 1295 | RequiresClause = |
| 1296 | Actions.ActOnRequiresClause(ParseConstraintLogicalOrExpression( |
| 1297 | false)); |
| 1298 | if (RequiresClause.isInvalid()) |
| 1299 | SkipUntil({tok::l_brace, tok::l_paren}, StopAtSemi | StopBeforeMatch); |
| 1300 | } |
| 1301 | |
| 1302 | Actions.ActOnLambdaExplicitTemplateParameterList( |
| 1303 | LAngleLoc, TemplateParams, RAngleLoc, RequiresClause); |
| 1304 | ++CurTemplateDepthTracker; |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | if (isCXX11AttributeSpecifier()) { |
| 1313 | Diag(Tok, getLangOpts().CPlusPlus2b |
| 1314 | ? diag::warn_cxx20_compat_decl_attrs_on_lambda |
| 1315 | : diag::ext_decl_attrs_on_lambda); |
| 1316 | MaybeParseCXX11Attributes(D); |
| 1317 | } |
| 1318 | |
| 1319 | TypeResult TrailingReturnType; |
| 1320 | SourceLocation TrailingReturnTypeLoc; |
| 1321 | |
| 1322 | auto ParseLambdaSpecifiers = |
| 1323 | [&](SourceLocation LParenLoc, SourceLocation RParenLoc, |
| 1324 | MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo, |
| 1325 | SourceLocation EllipsisLoc) { |
| 1326 | SourceLocation DeclEndLoc = RParenLoc; |
| 1327 | |
| 1328 | |
| 1329 | |
| 1330 | |
| 1331 | MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attr); |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | SourceLocation MutableLoc; |
| 1336 | SourceLocation ConstexprLoc; |
| 1337 | SourceLocation ConstevalLoc; |
| 1338 | tryConsumeLambdaSpecifierToken(*this, MutableLoc, ConstexprLoc, |
| 1339 | ConstevalLoc, DeclEndLoc); |
| 1340 | |
| 1341 | addConstexprToLambdaDeclSpecifier(*this, ConstexprLoc, DS); |
| 1342 | addConstevalToLambdaDeclSpecifier(*this, ConstevalLoc, DS); |
| 1343 | |
| 1344 | ExceptionSpecificationType ESpecType = EST_None; |
| 1345 | SourceRange ESpecRange; |
| 1346 | SmallVector<ParsedType, 2> DynamicExceptions; |
| 1347 | SmallVector<SourceRange, 2> DynamicExceptionRanges; |
| 1348 | ExprResult NoexceptExpr; |
| 1349 | CachedTokens *ExceptionSpecTokens; |
| 1350 | ESpecType = tryParseExceptionSpecification( |
| 1351 | false, ESpecRange, DynamicExceptions, |
| 1352 | DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens); |
| 1353 | |
| 1354 | if (ESpecType != EST_None) |
| 1355 | DeclEndLoc = ESpecRange.getEnd(); |
| 1356 | |
| 1357 | |
| 1358 | MaybeParseCXX11Attributes(Attr, &DeclEndLoc); |
| 1359 | |
| 1360 | |
| 1361 | if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local, |
| 1362 | tok::kw___constant, tok::kw___generic)) { |
| 1363 | ParseOpenCLQualifiers(DS.getAttributes()); |
| 1364 | ConsumeToken(); |
| 1365 | } |
| 1366 | |
| 1367 | SourceLocation FunLocalRangeEnd = DeclEndLoc; |
| 1368 | |
| 1369 | |
| 1370 | if (Tok.is(tok::arrow)) { |
| 1371 | FunLocalRangeEnd = Tok.getLocation(); |
| 1372 | SourceRange Range; |
| 1373 | TrailingReturnType = ParseTrailingReturnType( |
| 1374 | Range, false); |
| 1375 | TrailingReturnTypeLoc = Range.getBegin(); |
| 1376 | if (Range.getEnd().isValid()) |
| 1377 | DeclEndLoc = Range.getEnd(); |
| 1378 | } |
| 1379 | |
| 1380 | SourceLocation NoLoc; |
| 1381 | D.AddTypeInfo( |
| 1382 | DeclaratorChunk::getFunction( |
| 1383 | true, |
| 1384 | false, LParenLoc, ParamInfo.data(), |
| 1385 | ParamInfo.size(), EllipsisLoc, RParenLoc, |
| 1386 | true, |
| 1387 | NoLoc, MutableLoc, ESpecType, ESpecRange, |
| 1388 | DynamicExceptions.data(), DynamicExceptionRanges.data(), |
| 1389 | DynamicExceptions.size(), |
| 1390 | NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr, |
| 1391 | nullptr, |
| 1392 | None, LParenLoc, FunLocalRangeEnd, D, |
| 1393 | TrailingReturnType, TrailingReturnTypeLoc, &DS), |
| 1394 | std::move(Attr), DeclEndLoc); |
| 1395 | }; |
| 1396 | |
| 1397 | if (Tok.is(tok::l_paren)) { |
| 1398 | ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope | |
| 1399 | Scope::FunctionDeclarationScope | |
| 1400 | Scope::DeclScope); |
| 1401 | |
| 1402 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1403 | T.consumeOpen(); |
| 1404 | SourceLocation LParenLoc = T.getOpenLocation(); |
| 1405 | |
| 1406 | |
| 1407 | SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo; |
| 1408 | SourceLocation EllipsisLoc; |
| 1409 | |
| 1410 | if (Tok.isNot(tok::r_paren)) { |
| 1411 | Actions.RecordParsingTemplateParameterDepth( |
| 1412 | CurTemplateDepthTracker.getOriginalDepth()); |
| 1413 | |
| 1414 | ParseParameterDeclarationClause(D.getContext(), Attr, ParamInfo, |
| 1415 | EllipsisLoc); |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | |
| 1420 | |
| 1421 | if (Actions.getCurGenericLambda()) |
| 1422 | CurTemplateDepthTracker.setAddedDepth(1); |
| 1423 | } |
| 1424 | |
| 1425 | T.consumeClose(); |
| 1426 | |
| 1427 | |
| 1428 | ParseLambdaSpecifiers(LParenLoc, T.getCloseLocation(), |
| 1429 | ParamInfo, EllipsisLoc); |
| 1430 | |
| 1431 | |
| 1432 | if (Tok.is(tok::kw_requires)) |
| 1433 | ParseTrailingRequiresClause(D); |
| 1434 | } else if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute, |
| 1435 | tok::kw_constexpr, tok::kw_consteval, |
| 1436 | tok::kw___private, tok::kw___global, tok::kw___local, |
| 1437 | tok::kw___constant, tok::kw___generic, |
| 1438 | tok::kw_requires, tok::kw_noexcept) || |
| 1439 | (Tok.is(tok::l_square) && NextToken().is(tok::l_square))) { |
| 1440 | if (!getLangOpts().CPlusPlus2b) |
| 1441 | |
| 1442 | |
| 1443 | |
| 1444 | Diag(Tok, diag::ext_lambda_missing_parens) |
| 1445 | << FixItHint::CreateInsertion(Tok.getLocation(), "() "); |
| 1446 | |
| 1447 | SourceLocation NoLoc; |
| 1448 | |
| 1449 | std::vector<DeclaratorChunk::ParamInfo> EmptyParamInfo; |
| 1450 | ParseLambdaSpecifiers(NoLoc, NoLoc, |
| 1451 | EmptyParamInfo, NoLoc); |
| 1452 | } |
| 1453 | |
| 1454 | WarnIfHasCUDATargetAttr(); |
| 1455 | |
| 1456 | |
| 1457 | |
| 1458 | unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope | |
| 1459 | Scope::CompoundStmtScope; |
| 1460 | ParseScope BodyScope(this, ScopeFlags); |
| 1461 | |
| 1462 | Actions.ActOnStartOfLambdaDefinition(Intro, D, getCurScope()); |
| 1463 | |
| 1464 | |
| 1465 | if (!Tok.is(tok::l_brace)) { |
| 1466 | Diag(Tok, diag::err_expected_lambda_body); |
| 1467 | Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); |
| 1468 | return ExprError(); |
| 1469 | } |
| 1470 | |
| 1471 | StmtResult Stmt(ParseCompoundStatementBody()); |
| 1472 | BodyScope.Exit(); |
| 1473 | TemplateParamScope.Exit(); |
| 1474 | |
| 1475 | if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid()) |
| 1476 | return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get(), getCurScope()); |
| 1477 | |
| 1478 | Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); |
| 1479 | return ExprError(); |
| 1480 | } |
| 1481 | |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | ExprResult Parser::ParseCXXCasts() { |
| 1494 | tok::TokenKind Kind = Tok.getKind(); |
| 1495 | const char *CastName = nullptr; |
| 1496 | |
| 1497 | switch (Kind) { |
| 1498 | default: llvm_unreachable("Unknown C++ cast!"); |
| 1499 | case tok::kw_addrspace_cast: CastName = "addrspace_cast"; break; |
| 1500 | case tok::kw_const_cast: CastName = "const_cast"; break; |
| 1501 | case tok::kw_dynamic_cast: CastName = "dynamic_cast"; break; |
| 1502 | case tok::kw_reinterpret_cast: CastName = "reinterpret_cast"; break; |
| 1503 | case tok::kw_static_cast: CastName = "static_cast"; break; |
| 1504 | } |
| 1505 | |
| 1506 | SourceLocation OpLoc = ConsumeToken(); |
| 1507 | SourceLocation LAngleBracketLoc = Tok.getLocation(); |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | if (Tok.is(tok::l_square) && Tok.getLength() == 2) { |
| 1512 | Token Next = NextToken(); |
| 1513 | if (Next.is(tok::colon) && areTokensAdjacent(Tok, Next)) |
| 1514 | FixDigraph(*this, PP, Tok, Next, Kind, true); |
| 1515 | } |
| 1516 | |
| 1517 | if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName)) |
| 1518 | return ExprError(); |
| 1519 | |
| 1520 | |
| 1521 | DeclSpec DS(AttrFactory); |
| 1522 | ParseSpecifierQualifierList(DS); |
| 1523 | |
| 1524 | |
| 1525 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); |
| 1526 | ParseDeclarator(DeclaratorInfo); |
| 1527 | |
| 1528 | SourceLocation RAngleBracketLoc = Tok.getLocation(); |
| 1529 | |
| 1530 | if (ExpectAndConsume(tok::greater)) |
| 1531 | return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << tok::less); |
| 1532 | |
| 1533 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1534 | |
| 1535 | if (T.expectAndConsume(diag::err_expected_lparen_after, CastName)) |
| 1536 | return ExprError(); |
| 1537 | |
| 1538 | ExprResult Result = ParseExpression(); |
| 1539 | |
| 1540 | |
| 1541 | T.consumeClose(); |
| 1542 | |
| 1543 | if (!Result.isInvalid() && !DeclaratorInfo.isInvalidType()) |
| 1544 | Result = Actions.ActOnCXXNamedCast(OpLoc, Kind, |
| 1545 | LAngleBracketLoc, DeclaratorInfo, |
| 1546 | RAngleBracketLoc, |
| 1547 | T.getOpenLocation(), Result.get(), |
| 1548 | T.getCloseLocation()); |
| 1549 | |
| 1550 | return Result; |
| 1551 | } |
| 1552 | |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | |
| 1557 | |
| 1558 | |
| 1559 | ExprResult Parser::ParseCXXTypeid() { |
| 1560 | assert(Tok.is(tok::kw_typeid) && "Not 'typeid'!"); |
| 1561 | |
| 1562 | SourceLocation OpLoc = ConsumeToken(); |
| 1563 | SourceLocation LParenLoc, RParenLoc; |
| 1564 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1565 | |
| 1566 | |
| 1567 | if (T.expectAndConsume(diag::err_expected_lparen_after, "typeid")) |
| 1568 | return ExprError(); |
| 1569 | LParenLoc = T.getOpenLocation(); |
| 1570 | |
| 1571 | ExprResult Result; |
| 1572 | |
| 1573 | |
| 1574 | |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | EnterExpressionEvaluationContext Unevaluated( |
| 1587 | Actions, Sema::ExpressionEvaluationContext::Unevaluated, |
| 1588 | Sema::ReuseLambdaContextDecl); |
| 1589 | |
| 1590 | if (isTypeIdInParens()) { |
| 1591 | TypeResult Ty = ParseTypeName(); |
| 1592 | |
| 1593 | |
| 1594 | T.consumeClose(); |
| 1595 | RParenLoc = T.getCloseLocation(); |
| 1596 | if (Ty.isInvalid() || RParenLoc.isInvalid()) |
| 1597 | return ExprError(); |
| 1598 | |
| 1599 | Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, true, |
| 1600 | Ty.get().getAsOpaquePtr(), RParenLoc); |
| 1601 | } else { |
| 1602 | Result = ParseExpression(); |
| 1603 | |
| 1604 | |
| 1605 | if (Result.isInvalid()) |
| 1606 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1607 | else { |
| 1608 | T.consumeClose(); |
| 1609 | RParenLoc = T.getCloseLocation(); |
| 1610 | if (RParenLoc.isInvalid()) |
| 1611 | return ExprError(); |
| 1612 | |
| 1613 | Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, false, |
| 1614 | Result.get(), RParenLoc); |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | return Result; |
| 1619 | } |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | ExprResult Parser::ParseCXXUuidof() { |
| 1627 | assert(Tok.is(tok::kw___uuidof) && "Not '__uuidof'!"); |
| 1628 | |
| 1629 | SourceLocation OpLoc = ConsumeToken(); |
| 1630 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1631 | |
| 1632 | |
| 1633 | if (T.expectAndConsume(diag::err_expected_lparen_after, "__uuidof")) |
| 1634 | return ExprError(); |
| 1635 | |
| 1636 | ExprResult Result; |
| 1637 | |
| 1638 | if (isTypeIdInParens()) { |
| 1639 | TypeResult Ty = ParseTypeName(); |
| 1640 | |
| 1641 | |
| 1642 | T.consumeClose(); |
| 1643 | |
| 1644 | if (Ty.isInvalid()) |
| 1645 | return ExprError(); |
| 1646 | |
| 1647 | Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), true, |
| 1648 | Ty.get().getAsOpaquePtr(), |
| 1649 | T.getCloseLocation()); |
| 1650 | } else { |
| 1651 | EnterExpressionEvaluationContext Unevaluated( |
| 1652 | Actions, Sema::ExpressionEvaluationContext::Unevaluated); |
| 1653 | Result = ParseExpression(); |
| 1654 | |
| 1655 | |
| 1656 | if (Result.isInvalid()) |
| 1657 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1658 | else { |
| 1659 | T.consumeClose(); |
| 1660 | |
| 1661 | Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), |
| 1662 | false, |
| 1663 | Result.get(), T.getCloseLocation()); |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | return Result; |
| 1668 | } |
| 1669 | |
| 1670 | |
| 1671 | |
| 1672 | |
| 1673 | |
| 1674 | |
| 1675 | |
| 1676 | |
| 1677 | |
| 1678 | |
| 1679 | |
| 1680 | |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | |
| 1689 | |
| 1690 | |
| 1691 | |
| 1692 | |
| 1693 | |
| 1694 | |
| 1695 | |
| 1696 | |
| 1697 | |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | ExprResult |
| 1702 | Parser::ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc, |
| 1703 | tok::TokenKind OpKind, |
| 1704 | CXXScopeSpec &SS, |
| 1705 | ParsedType ObjectType) { |
| 1706 | |
| 1707 | |
| 1708 | UnqualifiedId FirstTypeName; |
| 1709 | SourceLocation CCLoc; |
| 1710 | if (Tok.is(tok::identifier)) { |
| 1711 | FirstTypeName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 1712 | ConsumeToken(); |
| 1713 | assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail"); |
| 1714 | CCLoc = ConsumeToken(); |
| 1715 | } else if (Tok.is(tok::annot_template_id)) { |
| 1716 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
| 1717 | |
| 1718 | if (TemplateId->isInvalid()) |
| 1719 | return ExprError(); |
| 1720 | FirstTypeName.setTemplateId(TemplateId); |
| 1721 | ConsumeAnnotationToken(); |
| 1722 | assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail"); |
| 1723 | CCLoc = ConsumeToken(); |
| 1724 | } else { |
| 1725 | assert(SS.isEmpty() && "missing last component of nested name specifier"); |
| 1726 | FirstTypeName.setIdentifier(nullptr, SourceLocation()); |
| 1727 | } |
| 1728 | |
| 1729 | |
| 1730 | assert(Tok.is(tok::tilde) && "ParseOptionalCXXScopeSpecifier fail"); |
| 1731 | SourceLocation TildeLoc = ConsumeToken(); |
| 1732 | |
| 1733 | if (Tok.is(tok::kw_decltype) && !FirstTypeName.isValid()) { |
| 1734 | DeclSpec DS(AttrFactory); |
| 1735 | ParseDecltypeSpecifier(DS); |
| 1736 | if (DS.getTypeSpecType() == TST_error) |
| 1737 | return ExprError(); |
| 1738 | return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, OpKind, |
| 1739 | TildeLoc, DS); |
| 1740 | } |
| 1741 | |
| 1742 | if (!Tok.is(tok::identifier)) { |
| 1743 | Diag(Tok, diag::err_destructor_tilde_identifier); |
| 1744 | return ExprError(); |
| 1745 | } |
| 1746 | |
| 1747 | |
| 1748 | UnqualifiedId SecondTypeName; |
| 1749 | IdentifierInfo *Name = Tok.getIdentifierInfo(); |
| 1750 | SourceLocation NameLoc = ConsumeToken(); |
| 1751 | SecondTypeName.setIdentifier(Name, NameLoc); |
| 1752 | |
| 1753 | |
| 1754 | |
| 1755 | |
| 1756 | |
| 1757 | |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | if (Tok.is(tok::less) && |
| 1762 | ParseUnqualifiedIdTemplateId( |
| 1763 | SS, ObjectType, Base && Base->containsErrors(), SourceLocation(), |
| 1764 | Name, NameLoc, false, SecondTypeName, |
| 1765 | true)) |
| 1766 | return ExprError(); |
| 1767 | |
| 1768 | return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, OpKind, |
| 1769 | SS, FirstTypeName, CCLoc, TildeLoc, |
| 1770 | SecondTypeName); |
| 1771 | } |
| 1772 | |
| 1773 | |
| 1774 | |
| 1775 | |
| 1776 | |
| 1777 | |
| 1778 | ExprResult Parser::ParseCXXBoolLiteral() { |
| 1779 | tok::TokenKind Kind = Tok.getKind(); |
| 1780 | return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind); |
| 1781 | } |
| 1782 | |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | ExprResult Parser::ParseThrowExpression() { |
| 1788 | assert(Tok.is(tok::kw_throw) && "Not throw!"); |
| 1789 | SourceLocation ThrowLoc = ConsumeToken(); |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | |
| 1794 | switch (Tok.getKind()) { |
| 1795 | case tok::semi: |
| 1796 | case tok::r_paren: |
| 1797 | case tok::r_square: |
| 1798 | case tok::r_brace: |
| 1799 | case tok::colon: |
| 1800 | case tok::comma: |
| 1801 | return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, nullptr); |
| 1802 | |
| 1803 | default: |
| 1804 | ExprResult Expr(ParseAssignmentExpression()); |
| 1805 | if (Expr.isInvalid()) return Expr; |
| 1806 | return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, Expr.get()); |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | |
| 1811 | |
| 1812 | |
| 1813 | |
| 1814 | ExprResult Parser::ParseCoyieldExpression() { |
| 1815 | assert(Tok.is(tok::kw_co_yield) && "Not co_yield!"); |
| 1816 | |
| 1817 | SourceLocation Loc = ConsumeToken(); |
| 1818 | ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer() |
| 1819 | : ParseAssignmentExpression(); |
| 1820 | if (!Expr.isInvalid()) |
| 1821 | Expr = Actions.ActOnCoyieldExpr(getCurScope(), Loc, Expr.get()); |
| 1822 | return Expr; |
| 1823 | } |
| 1824 | |
| 1825 | |
| 1826 | |
| 1827 | |
| 1828 | |
| 1829 | |
| 1830 | ExprResult Parser::ParseCXXThis() { |
| 1831 | assert(Tok.is(tok::kw_this) && "Not 'this'!"); |
| 1832 | SourceLocation ThisLoc = ConsumeToken(); |
| 1833 | return Actions.ActOnCXXThis(ThisLoc); |
| 1834 | } |
| 1835 | |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | |
| 1846 | |
| 1847 | |
| 1848 | |
| 1849 | ExprResult |
| 1850 | Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { |
| 1851 | Declarator DeclaratorInfo(DS, DeclaratorContext::FunctionalCast); |
| 1852 | ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get(); |
| 1853 | |
| 1854 | assert((Tok.is(tok::l_paren) || |
| 1855 | (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))) |
| 1856 | && "Expected '(' or '{'!"); |
| 1857 | |
| 1858 | if (Tok.is(tok::l_brace)) { |
| 1859 | PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.get()); |
| 1860 | ExprResult Init = ParseBraceInitializer(); |
| 1861 | if (Init.isInvalid()) |
| 1862 | return Init; |
| 1863 | Expr *InitList = Init.get(); |
| 1864 | return Actions.ActOnCXXTypeConstructExpr( |
| 1865 | TypeRep, InitList->getBeginLoc(), MultiExprArg(&InitList, 1), |
| 1866 | InitList->getEndLoc(), true); |
| 1867 | } else { |
| 1868 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1869 | T.consumeOpen(); |
| 1870 | |
| 1871 | PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.get()); |
| 1872 | |
| 1873 | ExprVector Exprs; |
| 1874 | CommaLocsTy CommaLocs; |
| 1875 | |
| 1876 | auto RunSignatureHelp = [&]() { |
| 1877 | QualType PreferredType; |
| 1878 | if (TypeRep) |
| 1879 | PreferredType = Actions.ProduceConstructorSignatureHelp( |
| 1880 | getCurScope(), TypeRep.get()->getCanonicalTypeInternal(), |
| 1881 | DS.getEndLoc(), Exprs, T.getOpenLocation()); |
| 1882 | CalledSignatureHelp = true; |
| 1883 | return PreferredType; |
| 1884 | }; |
| 1885 | |
| 1886 | if (Tok.isNot(tok::r_paren)) { |
| 1887 | if (ParseExpressionList(Exprs, CommaLocs, [&] { |
| 1888 | PreferredType.enterFunctionArgument(Tok.getLocation(), |
| 1889 | RunSignatureHelp); |
| 1890 | })) { |
| 1891 | if (PP.isCodeCompletionReached() && !CalledSignatureHelp) |
| 1892 | RunSignatureHelp(); |
| 1893 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1894 | return ExprError(); |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | |
| 1899 | T.consumeClose(); |
| 1900 | |
| 1901 | |
| 1902 | if (!TypeRep) |
| 1903 | return ExprError(); |
| 1904 | |
| 1905 | assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&& |
| 1906 | "Unexpected number of commas!"); |
| 1907 | return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(), |
| 1908 | Exprs, T.getCloseLocation(), |
| 1909 | false); |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | |
| 1921 | |
| 1922 | |
| 1923 | |
| 1924 | |
| 1925 | |
| 1926 | |
| 1927 | |
| 1928 | |
| 1929 | |
| 1930 | |
| 1931 | |
| 1932 | |
| 1933 | |
| 1934 | |
| 1935 | |
| 1936 | |
| 1937 | |
| 1938 | |
| 1939 | |
| 1940 | |
| 1941 | Sema::ConditionResult Parser::ParseCXXCondition(StmtResult *InitStmt, |
| 1942 | SourceLocation Loc, |
| 1943 | Sema::ConditionKind CK, |
| 1944 | ForRangeInfo *FRI, |
| 1945 | bool EnterForConditionScope) { |
| 1946 | |
| 1947 | struct ForConditionScopeRAII { |
| 1948 | Scope *S; |
| 1949 | void enter(bool IsConditionVariable) { |
| 1950 | if (S) { |
| 1951 | S->AddFlags(Scope::BreakScope | Scope::ContinueScope); |
| 1952 | S->setIsConditionVarScope(IsConditionVariable); |
| 1953 | } |
| 1954 | } |
| 1955 | ~ForConditionScopeRAII() { |
| 1956 | if (S) |
| 1957 | S->setIsConditionVarScope(false); |
| 1958 | } |
| 1959 | } ForConditionScope{EnterForConditionScope ? getCurScope() : nullptr}; |
| 1 | Assuming 'EnterForConditionScope' is false | |
|
| |
| |
| 1960 | |
| 1961 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
| 1962 | PreferredType.enterCondition(Actions, Tok.getLocation()); |
| 1963 | |
| 1964 | if (Tok.is(tok::code_completion)) { |
| |
| |
| 11 | | Returning from 'Token::is' | |
|
| |
| 1965 | cutOffParsing(); |
| 1966 | Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Condition); |
| 1967 | return Sema::ConditionError(); |
| 1968 | } |
| 1969 | |
| 1970 | ParsedAttributesWithRange attrs(AttrFactory); |
| 1971 | MaybeParseCXX11Attributes(attrs); |
| 1972 | |
| 1973 | const auto WarnOnInit = [this, &CK] { |
| 1974 | Diag(Tok.getLocation(), getLangOpts().CPlusPlus17 |
| 1975 | ? diag::warn_cxx14_compat_init_statement |
| 1976 | : diag::ext_init_statement) |
| 1977 | << (CK == Sema::ConditionKind::Switch); |
| 1978 | }; |
| 1979 | |
| 1980 | |
| 1981 | switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) { |
| 4 | | Control jumps to 'case InitStmtDecl:' at line 2018 | |
|
| 13 | | Control jumps to 'case InitStmtDecl:' at line 2018 | |
|
| 1982 | case ConditionOrInitStatement::Expression: { |
| 1983 | |
| 1984 | ForConditionScope.enter(false); |
| 1985 | |
| 1986 | ProhibitAttributes(attrs); |
| 1987 | |
| 1988 | |
| 1989 | |
| 1990 | if (InitStmt && Tok.is(tok::semi)) { |
| 1991 | WarnOnInit(); |
| 1992 | SourceLocation SemiLoc = Tok.getLocation(); |
| 1993 | if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.isMacroID()) { |
| 1994 | Diag(SemiLoc, diag::warn_empty_init_statement) |
| 1995 | << (CK == Sema::ConditionKind::Switch) |
| 1996 | << FixItHint::CreateRemoval(SemiLoc); |
| 1997 | } |
| 1998 | ConsumeToken(); |
| 1999 | *InitStmt = Actions.ActOnNullStmt(SemiLoc); |
| 2000 | return ParseCXXCondition(nullptr, Loc, CK); |
| 2001 | } |
| 2002 | |
| 2003 | |
| 2004 | ExprResult Expr = ParseExpression(); |
| 2005 | if (Expr.isInvalid()) |
| 2006 | return Sema::ConditionError(); |
| 2007 | |
| 2008 | if (InitStmt && Tok.is(tok::semi)) { |
| 2009 | WarnOnInit(); |
| 2010 | *InitStmt = Actions.ActOnExprStmt(Expr.get()); |
| 2011 | ConsumeToken(); |
| 2012 | return ParseCXXCondition(nullptr, Loc, CK); |
| 2013 | } |
| 2014 | |
| 2015 | return Actions.ActOnCondition(getCurScope(), Loc, Expr.get(), CK); |
| 2016 | } |
| 2017 | |
| 2018 | case ConditionOrInitStatement::InitStmtDecl: { |
| 2019 | WarnOnInit(); |
| 2020 | SourceLocation DeclStart = Tok.getLocation(), DeclEnd; |
| 2021 | DeclGroupPtrTy DG = ParseSimpleDeclaration( |
| 2022 | DeclaratorContext::SelectionInit, DeclEnd, attrs, true); |
| 2023 | *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd); |
| 14 | | Called C++ object pointer is null |
|
| 2024 | return ParseCXXCondition(nullptr, Loc, CK); |
| 5 | | Passing null pointer value via 1st parameter 'InitStmt' | |
|
| 6 | | Calling 'Parser::ParseCXXCondition' | |
|
| 2025 | } |
| 2026 | |
| 2027 | case ConditionOrInitStatement::ForRangeDecl: { |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | assert(FRI && "should not parse a for range declaration here"); |
| 2032 | SourceLocation DeclStart = Tok.getLocation(), DeclEnd; |
| 2033 | DeclGroupPtrTy DG = ParseSimpleDeclaration(DeclaratorContext::ForInit, |
| 2034 | DeclEnd, attrs, false, FRI); |
| 2035 | FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation()); |
| 2036 | assert((FRI->ColonLoc.isValid() || !DG) && |
| 2037 | "cannot find for range declaration"); |
| 2038 | return Sema::ConditionResult(); |
| 2039 | } |
| 2040 | |
| 2041 | case ConditionOrInitStatement::ConditionDecl: |
| 2042 | case ConditionOrInitStatement::Error: |
| 2043 | break; |
| 2044 | } |
| 2045 | |
| 2046 | |
| 2047 | ForConditionScope.enter(true); |
| 2048 | |
| 2049 | |
| 2050 | DeclSpec DS(AttrFactory); |
| 2051 | DS.takeAttributesFrom(attrs); |
| 2052 | ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_condition); |
| 2053 | |
| 2054 | |
| 2055 | Declarator DeclaratorInfo(DS, DeclaratorContext::Condition); |
| 2056 | ParseDeclarator(DeclaratorInfo); |
| 2057 | |
| 2058 | |
| 2059 | if (Tok.is(tok::kw_asm)) { |
| 2060 | SourceLocation Loc; |
| 2061 | ExprResult AsmLabel(ParseSimpleAsm( true, &Loc)); |
| 2062 | if (AsmLabel.isInvalid()) { |
| 2063 | SkipUntil(tok::semi, StopAtSemi); |
| 2064 | return Sema::ConditionError(); |
| 2065 | } |
| 2066 | DeclaratorInfo.setAsmLabel(AsmLabel.get()); |
| 2067 | DeclaratorInfo.SetRangeEnd(Loc); |
| 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | MaybeParseGNUAttributes(DeclaratorInfo); |
| 2072 | |
| 2073 | |
| 2074 | DeclResult Dcl = Actions.ActOnCXXConditionDeclaration(getCurScope(), |
| 2075 | DeclaratorInfo); |
| 2076 | if (Dcl.isInvalid()) |
| 2077 | return Sema::ConditionError(); |
| 2078 | Decl *DeclOut = Dcl.get(); |
| 2079 | |
| 2080 | |
| 2081 | |
| 2082 | bool CopyInitialization = isTokenEqualOrEqualTypo(); |
| 2083 | if (CopyInitialization) |
| 2084 | ConsumeToken(); |
| 2085 | |
| 2086 | ExprResult InitExpr = ExprError(); |
| 2087 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 2088 | Diag(Tok.getLocation(), |
| 2089 | diag::warn_cxx98_compat_generalized_initializer_lists); |
| 2090 | InitExpr = ParseBraceInitializer(); |
| 2091 | } else if (CopyInitialization) { |
| 2092 | PreferredType.enterVariableInit(Tok.getLocation(), DeclOut); |
| 2093 | InitExpr = ParseAssignmentExpression(); |
| 2094 | } else if (Tok.is(tok::l_paren)) { |
| 2095 | |
| 2096 | SourceLocation LParen = ConsumeParen(), RParen = LParen; |
| 2097 | if (SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch)) |
| 2098 | RParen = ConsumeParen(); |
| 2099 | Diag(DeclOut->getLocation(), |
| 2100 | diag::err_expected_init_in_condition_lparen) |
| 2101 | << SourceRange(LParen, RParen); |
| 2102 | } else { |
| 2103 | Diag(DeclOut->getLocation(), diag::err_expected_init_in_condition); |
| 2104 | } |
| 2105 | |
| 2106 | if (!InitExpr.isInvalid()) |
| 2107 | Actions.AddInitializerToDecl(DeclOut, InitExpr.get(), !CopyInitialization); |
| 2108 | else |
| 2109 | Actions.ActOnInitializerError(DeclOut); |
| 2110 | |
| 2111 | Actions.FinalizeDeclaration(DeclOut); |
| 2112 | return Actions.ActOnConditionVariable(DeclOut, Loc, CK); |
| 2113 | } |
| 2114 | |
| 2115 | |
| 2116 | |
| 2117 | |
| 2118 | |
| 2119 | |
| 2120 | |
| 2121 | |
| 2122 | |
| 2123 | |
| 2124 | |
| 2125 | |
| 2126 | |
| 2127 | |
| 2128 | |
| 2129 | |
| 2130 | |
| 2131 | |
| 2132 | |
| 2133 | |
| 2134 | |
| 2135 | |
| 2136 | |
| 2137 | |
| 2138 | |
| 2139 | |
| 2140 | |
| 2141 | void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) { |
| 2142 | DS.SetRangeStart(Tok.getLocation()); |
| 2143 | const char *PrevSpec; |
| 2144 | unsigned DiagID; |
| 2145 | SourceLocation Loc = Tok.getLocation(); |
| 2146 | const clang::PrintingPolicy &Policy = |
| 2147 | Actions.getASTContext().getPrintingPolicy(); |
| 2148 | |
| 2149 | switch (Tok.getKind()) { |
| 2150 | case tok::identifier: |
| 2151 | case tok::coloncolon: |
| 2152 | llvm_unreachable("Annotation token should already be formed!"); |
| 2153 | default: |
| 2154 | llvm_unreachable("Not a simple-type-specifier token!"); |
| 2155 | |
| 2156 | |
| 2157 | case tok::annot_typename: { |
| 2158 | DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID, |
| 2159 | getTypeAnnotation(Tok), Policy); |
| 2160 | DS.SetRangeEnd(Tok.getAnnotationEndLoc()); |
| 2161 | ConsumeAnnotationToken(); |
| 2162 | |
| 2163 | DS.Finish(Actions, Policy); |
| 2164 | return; |
| 2165 | } |
| 2166 | |
| 2167 | case tok::kw__ExtInt: { |
| 2168 | ExprResult ER = ParseExtIntegerArgument(); |
| 2169 | if (ER.isInvalid()) |
| 2170 | DS.SetTypeSpecError(); |
| 2171 | else |
| 2172 | DS.SetExtIntType(Loc, ER.get(), PrevSpec, DiagID, Policy); |
| 2173 | |
| 2174 | |
| 2175 | DS.SetRangeEnd(PrevTokLocation); |
| 2176 | DS.Finish(Actions, Policy); |
| 2177 | return; |
| 2178 | } |
| 2179 | |
| 2180 | |
| 2181 | case tok::kw_short: |
| 2182 | DS.SetTypeSpecWidth(TypeSpecifierWidth::Short, Loc, PrevSpec, DiagID, |
| 2183 | Policy); |
| 2184 | break; |
| 2185 | case tok::kw_long: |
| 2186 | DS.SetTypeSpecWidth(TypeSpecifierWidth::Long, Loc, PrevSpec, DiagID, |
| 2187 | Policy); |
| 2188 | break; |
| 2189 | case tok::kw___int64: |
| 2190 | DS.SetTypeSpecWidth(TypeSpecifierWidth::LongLong, Loc, PrevSpec, DiagID, |
| 2191 | Policy); |
| 2192 | break; |
| 2193 | case tok::kw_signed: |
| 2194 | DS.SetTypeSpecSign(TypeSpecifierSign::Signed, Loc, PrevSpec, DiagID); |
| 2195 | break; |
| 2196 | case tok::kw_unsigned: |
| 2197 | DS.SetTypeSpecSign(TypeSpecifierSign::Unsigned, Loc, PrevSpec, DiagID); |
| 2198 | break; |
| 2199 | case tok::kw_void: |
| 2200 | DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID, Policy); |
| 2201 | break; |
| 2202 | case tok::kw_char: |
| 2203 | DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID, Policy); |
| 2204 | break; |
| 2205 | case tok::kw_int: |
| 2206 | DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID, Policy); |
| 2207 | break; |
| 2208 | case tok::kw___int128: |
| 2209 | DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec, DiagID, Policy); |
| 2210 | break; |
| 2211 | case tok::kw___bf16: |
| 2212 | DS.SetTypeSpecType(DeclSpec::TST_BFloat16, Loc, PrevSpec, DiagID, Policy); |
| 2213 | break; |
| 2214 | case tok::kw_half: |
| 2215 | DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec, DiagID, Policy); |
| 2216 | break; |
| 2217 | case tok::kw_float: |
| 2218 | DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID, Policy); |
| 2219 | break; |
| 2220 | case tok::kw_double: |
| 2221 | DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID, Policy); |
| 2222 | break; |
| 2223 | case tok::kw__Float16: |
| 2224 | DS.SetTypeSpecType(DeclSpec::TST_float16, Loc, PrevSpec, DiagID, Policy); |
| 2225 | break; |
| 2226 | case tok::kw___float128: |
| 2227 | DS.SetTypeSpecType(DeclSpec::TST_float128, Loc, PrevSpec, DiagID, Policy); |
| 2228 | break; |
| 2229 | case tok::kw_wchar_t: |
| 2230 | DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID, Policy); |
| 2231 | break; |
| 2232 | case tok::kw_char8_t: |
| 2233 | DS.SetTypeSpecType(DeclSpec::TST_char8, Loc, PrevSpec, DiagID, Policy); |
| 2234 | break; |
| 2235 | case tok::kw_char16_t: |
| 2236 | DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID, Policy); |
| 2237 | break; |
| 2238 | case tok::kw_char32_t: |
| 2239 | DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID, Policy); |
| 2240 | break; |
| 2241 | case tok::kw_bool: |
| 2242 | DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID, Policy); |
| 2243 | break; |
| 2244 | #define GENERIC_IMAGE_TYPE(ImgType, Id) \ |
| 2245 | case tok::kw_##ImgType##_t: \ |
| 2246 | DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \ |
| 2247 | Policy); \ |
| 2248 | break; |
| 2249 | #include "clang/Basic/OpenCLImageTypes.def" |
| 2250 | |
| 2251 | case tok::annot_decltype: |
| 2252 | case tok::kw_decltype: |
| 2253 | DS.SetRangeEnd(ParseDecltypeSpecifier(DS)); |
| 2254 | return DS.Finish(Actions, Policy); |
| 2255 | |
| 2256 | |
| 2257 | case tok::kw_typeof: |
| 2258 | ParseTypeofSpecifier(DS); |
| 2259 | DS.Finish(Actions, Policy); |
| 2260 | return; |
| 2261 | } |
| 2262 | ConsumeAnyToken(); |
| 2263 | DS.SetRangeEnd(PrevTokLocation); |
| 2264 | DS.Finish(Actions, Policy); |
| 2265 | } |
| 2266 | |
| 2267 | |
| 2268 | |
| 2269 | |
| 2270 | |
| 2271 | |
| 2272 | |
| 2273 | |
| 2274 | |
| 2275 | |
| 2276 | |
| 2277 | |
| 2278 | bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) { |
| 2279 | ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_type_specifier); |
| 2280 | DS.Finish(Actions, Actions.getASTContext().getPrintingPolicy()); |
| 2281 | return false; |
| 2282 | } |
| 2283 | |
| 2284 | |
| 2285 | |
| 2286 | |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | |
| 2292 | |
| 2293 | |
| 2294 | |
| 2295 | |
| 2296 | |
| 2297 | |
| 2298 | |
| 2299 | |
| 2300 | |
| 2301 | |
| 2302 | |
| 2303 | |
| 2304 | |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | |
| 2312 | |
| 2313 | |
| 2314 | |
| 2315 | |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | bool Parser::ParseUnqualifiedIdTemplateId( |
| 2320 | CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, |
| 2321 | SourceLocation TemplateKWLoc, IdentifierInfo *Name, SourceLocation NameLoc, |
| 2322 | bool EnteringContext, UnqualifiedId &Id, bool AssumeTemplateId) { |
| 2323 | assert(Tok.is(tok::less) && "Expected '<' to finish parsing a template-id"); |
| 2324 | |
| 2325 | TemplateTy Template; |
| 2326 | TemplateNameKind TNK = TNK_Non_template; |
| 2327 | switch (Id.getKind()) { |
| 2328 | case UnqualifiedIdKind::IK_Identifier: |
| 2329 | case UnqualifiedIdKind::IK_OperatorFunctionId: |
| 2330 | case UnqualifiedIdKind::IK_LiteralOperatorId: |
| 2331 | if (AssumeTemplateId) { |
| 2332 | |
| 2333 | |
| 2334 | TNK = Actions.ActOnTemplateName(getCurScope(), SS, TemplateKWLoc, Id, |
| 2335 | ObjectType, EnteringContext, Template, |
| 2336 | true); |
| 2337 | } else { |
| 2338 | bool MemberOfUnknownSpecialization; |
| 2339 | TNK = Actions.isTemplateName(getCurScope(), SS, |
| 2340 | TemplateKWLoc.isValid(), Id, |
| 2341 | ObjectType, EnteringContext, Template, |
| 2342 | MemberOfUnknownSpecialization); |
| 2343 | |
| 2344 | |
| 2345 | |
| 2346 | if (TNK == TNK_Undeclared_template && |
| 2347 | isTemplateArgumentList(0) == TPResult::False) |
| 2348 | return false; |
| 2349 | |
| 2350 | if (TNK == TNK_Non_template && MemberOfUnknownSpecialization && |
| 2351 | ObjectType && isTemplateArgumentList(0) == TPResult::True) { |
| 2352 | |
| 2353 | |
| 2354 | if (!ObjectHadErrors) { |
| 2355 | |
| 2356 | |
| 2357 | |
| 2358 | |
| 2359 | std::string Name; |
| 2360 | if (Id.getKind() == UnqualifiedIdKind::IK_Identifier) |
| 2361 | Name = std::string(Id.Identifier->getName()); |
| 2362 | else { |
| 2363 | Name = "operator "; |
| 2364 | if (Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId) |
| 2365 | Name += getOperatorSpelling(Id.OperatorFunctionId.Operator); |
| 2366 | else |
| 2367 | Name += Id.Identifier->getName(); |
| 2368 | } |
| 2369 | Diag(Id.StartLocation, diag::err_missing_dependent_template_keyword) |
| 2370 | << Name |
| 2371 | << FixItHint::CreateInsertion(Id.StartLocation, "template "); |
| 2372 | } |
| 2373 | TNK = Actions.ActOnTemplateName( |
| 2374 | getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext, |
| 2375 | Template, true); |
| 2376 | } else if (TNK == TNK_Non_template) { |
| 2377 | return false; |
| 2378 | } |
| 2379 | } |
| 2380 | break; |
| 2381 | |
| 2382 | case UnqualifiedIdKind::IK_ConstructorName: { |
| 2383 | UnqualifiedId TemplateName; |
| 2384 | bool MemberOfUnknownSpecialization; |
| 2385 | TemplateName.setIdentifier(Name, NameLoc); |
| 2386 | TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(), |
| 2387 | TemplateName, ObjectType, |
| 2388 | EnteringContext, Template, |
| 2389 | MemberOfUnknownSpecialization); |
| 2390 | if (TNK == TNK_Non_template) |
| 2391 | return false; |
| 2392 | break; |
| 2393 | } |
| 2394 | |
| 2395 | case UnqualifiedIdKind::IK_DestructorName: { |
| 2396 | UnqualifiedId TemplateName; |
| 2397 | bool MemberOfUnknownSpecialization; |
| 2398 | TemplateName.setIdentifier(Name, NameLoc); |
| 2399 | if (ObjectType) { |
| 2400 | TNK = Actions.ActOnTemplateName( |
| 2401 | getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType, |
| 2402 | EnteringContext, Template, true); |
| 2403 | } else { |
| 2404 | TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(), |
| 2405 | TemplateName, ObjectType, |
| 2406 | EnteringContext, Template, |
| 2407 | MemberOfUnknownSpecialization); |
| 2408 | |
| 2409 | if (TNK == TNK_Non_template && !Id.DestructorName.get()) { |
| 2410 | Diag(NameLoc, diag::err_destructor_template_id) |
| 2411 | << Name << SS.getRange(); |
| 2412 | |
| 2413 | } |
| 2414 | } |
| 2415 | break; |
| 2416 | } |
| 2417 | |
| 2418 | default: |
| 2419 | return false; |
| 2420 | } |
| 2421 | |
| 2422 | |
| 2423 | SourceLocation LAngleLoc, RAngleLoc; |
| 2424 | TemplateArgList TemplateArgs; |
| 2425 | if (ParseTemplateIdAfterTemplateName(true, LAngleLoc, TemplateArgs, |
| 2426 | RAngleLoc)) |
| 2427 | return true; |
| 2428 | |
| 2429 | |
| 2430 | if (TNK == TNK_Non_template) |
| 2431 | return true; |
| 2432 | |
| 2433 | if (Id.getKind() == UnqualifiedIdKind::IK_Identifier || |
| 2434 | Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId || |
| 2435 | Id.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId) { |
| 2436 | |
| 2437 | |
| 2438 | |
| 2439 | |
| 2440 | IdentifierInfo *TemplateII = |
| 2441 | Id.getKind() == UnqualifiedIdKind::IK_Identifier ? Id.Identifier |
| 2442 | : nullptr; |
| 2443 | OverloadedOperatorKind OpKind = |
| 2444 | Id.getKind() == UnqualifiedIdKind::IK_Identifier |
| 2445 | ? OO_None |
| 2446 | : Id.OperatorFunctionId.Operator; |
| 2447 | |
| 2448 | TemplateIdAnnotation *TemplateId = TemplateIdAnnotation::Create( |
| 2449 | TemplateKWLoc, Id.StartLocation, TemplateII, OpKind, Template, TNK, |
| 2450 | LAngleLoc, RAngleLoc, TemplateArgs, false, TemplateIds); |
| 2451 | |
| 2452 | Id.setTemplateId(TemplateId); |
| 2453 | return false; |
| 2454 | } |
| 2455 | |
| 2456 | |
| 2457 | ASTTemplateArgsPtr TemplateArgsPtr(TemplateArgs); |
| 2458 | |
| 2459 | |
| 2460 | TypeResult Type = Actions.ActOnTemplateIdType( |
| 2461 | getCurScope(), SS, TemplateKWLoc, Template, Name, NameLoc, LAngleLoc, |
| 2462 | TemplateArgsPtr, RAngleLoc, true); |
| 2463 | if (Type.isInvalid()) |
| 2464 | return true; |
| 2465 | |
| 2466 | if (Id.getKind() == UnqualifiedIdKind::IK_ConstructorName) |
| 2467 | Id.setConstructorName(Type.get(), NameLoc, RAngleLoc); |
| 2468 | else |
| 2469 | Id.setDestructorName(Id.StartLocation, Type.get(), RAngleLoc); |
| 2470 | |
| 2471 | return false; |
| 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 | |
| 2498 | |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | |
| 2503 | |
| 2504 | |
| 2505 | |
| 2506 | |
| 2507 | |
| 2508 | |
| 2509 | |
| 2510 | |
| 2511 | |
| 2512 | |
| 2513 | |
| 2514 | bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, |
| 2515 | ParsedType ObjectType, |
| 2516 | UnqualifiedId &Result) { |
| 2517 | assert(Tok.is(tok::kw_operator) && "Expected 'operator' keyword"); |
| 2518 | |
| 2519 | |
| 2520 | SourceLocation KeywordLoc = ConsumeToken(); |
| 2521 | |
| 2522 | |
| 2523 | unsigned SymbolIdx = 0; |
| 2524 | SourceLocation SymbolLocations[3]; |
| 2525 | OverloadedOperatorKind Op = OO_None; |
| 2526 | switch (Tok.getKind()) { |
| 2527 | case tok::kw_new: |
| 2528 | case tok::kw_delete: { |
| 2529 | bool isNew = Tok.getKind() == tok::kw_new; |
| 2530 | |
| 2531 | SymbolLocations[SymbolIdx++] = ConsumeToken(); |
| 2532 | |
| 2533 | if (Tok.is(tok::l_square) && |
| 2534 | (!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square))) { |
| 2535 | |
| 2536 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 2537 | T.consumeOpen(); |
| 2538 | T.consumeClose(); |
| 2539 | if (T.getCloseLocation().isInvalid()) |
| 2540 | return true; |
| 2541 | |
| 2542 | SymbolLocations[SymbolIdx++] = T.getOpenLocation(); |
| 2543 | SymbolLocations[SymbolIdx++] = T.getCloseLocation(); |
| 2544 | Op = isNew? OO_Array_New : OO_Array_Delete; |
| 2545 | } else { |
| 2546 | Op = isNew? OO_New : OO_Delete; |
| 2547 | } |
| 2548 | break; |
| 2549 | } |
| 2550 | |
| 2551 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 2552 | case tok::Token: \ |
| 2553 | SymbolLocations[SymbolIdx++] = ConsumeToken(); \ |
| 2554 | Op = OO_##Name; \ |
| 2555 | break; |
| 2556 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 2557 | #include "clang/Basic/OperatorKinds.def" |
| 2558 | |
| 2559 | case tok::l_paren: { |
| 2560 | |
| 2561 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2562 | T.consumeOpen(); |
| 2563 | T.consumeClose(); |
| 2564 | if (T.getCloseLocation().isInvalid()) |
| 2565 | return true; |
| 2566 | |
| 2567 | SymbolLocations[SymbolIdx++] = T.getOpenLocation(); |
| 2568 | SymbolLocations[SymbolIdx++] = T.getCloseLocation(); |
| 2569 | Op = OO_Call; |
| 2570 | break; |
| 2571 | } |
| 2572 | |
| 2573 | case tok::l_square: { |
| 2574 | |
| 2575 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 2576 | T.consumeOpen(); |
| 2577 | T.consumeClose(); |
| 2578 | if (T.getCloseLocation().isInvalid()) |
| 2579 | return true; |
| 2580 | |
| 2581 | SymbolLocations[SymbolIdx++] = T.getOpenLocation(); |
| 2582 | SymbolLocations[SymbolIdx++] = T.getCloseLocation(); |
| 2583 | Op = OO_Subscript; |
| 2584 | break; |
| 2585 | } |
| 2586 | |
| 2587 | case tok::code_completion: { |
| 2588 | |
| 2589 | cutOffParsing(); |
| 2590 | |
| 2591 | Actions.CodeCompleteOperatorName(getCurScope()); |
| 2592 | return true; |
| 2593 | } |
| 2594 | |
| 2595 | default: |
| 2596 | break; |
| 2597 | } |
| 2598 | |
| 2599 | if (Op != OO_None) { |
| 2600 | |
| 2601 | Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations); |
| 2602 | return false; |
| 2603 | } |
| 2604 | |
| 2605 | |
| 2606 | |
| 2607 | |
| 2608 | |
| 2609 | |
| 2610 | |
| 2611 | if (getLangOpts().CPlusPlus11 && isTokenStringLiteral()) { |
| 2612 | Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator); |
| 2613 | |
| 2614 | SourceLocation DiagLoc; |
| 2615 | unsigned DiagId = 0; |
| 2616 | |
| 2617 | |
| 2618 | |
| 2619 | SmallVector<Token, 4> Toks; |
| 2620 | SmallVector<SourceLocation, 4> TokLocs; |
| 2621 | while (isTokenStringLiteral()) { |
| 2622 | if (!Tok.is(tok::string_literal) && !DiagId) { |
| 2623 | |
| 2624 | |
| 2625 | |
| 2626 | DiagLoc = Tok.getLocation(); |
| 2627 | DiagId = diag::err_literal_operator_string_prefix; |
| 2628 | } |
| 2629 | Toks.push_back(Tok); |
| 2630 | TokLocs.push_back(ConsumeStringToken()); |
| 2631 | } |
| 2632 | |
| 2633 | StringLiteralParser Literal(Toks, PP); |
| 2634 | if (Literal.hadError) |
| 2635 | return true; |
| 2636 | |
| 2637 | |
| 2638 | |
| 2639 | bool IsUDSuffix = !Literal.getUDSuffix().empty(); |
| 2640 | IdentifierInfo *II = nullptr; |
| 2641 | SourceLocation SuffixLoc; |
| 2642 | if (IsUDSuffix) { |
| 2643 | II = &PP.getIdentifierTable().get(Literal.getUDSuffix()); |
| 2644 | SuffixLoc = |
| 2645 | Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()], |
| 2646 | Literal.getUDSuffixOffset(), |
| 2647 | PP.getSourceManager(), getLangOpts()); |
| 2648 | } else if (Tok.is(tok::identifier)) { |
| 2649 | II = Tok.getIdentifierInfo(); |
| 2650 | SuffixLoc = ConsumeToken(); |
| 2651 | TokLocs.push_back(SuffixLoc); |
| 2652 | } else { |
| 2653 | Diag(Tok.getLocation(), diag::err_expected) << tok::identifier; |
| 2654 | return true; |
| 2655 | } |
| 2656 | |
| 2657 | |
| 2658 | if (!Literal.GetString().empty() || Literal.Pascal) { |
| 2659 | |
| 2660 | |
| 2661 | |
| 2662 | |
| 2663 | DiagLoc = TokLocs.front(); |
| 2664 | DiagId = diag::err_literal_operator_string_not_empty; |
| 2665 | } |
| 2666 | |
| 2667 | if (DiagId) { |
| 2668 | |
| 2669 | |
| 2670 | SmallString<32> Str; |
| 2671 | Str += "\"\""; |
| 2672 | Str += II->getName(); |
| 2673 | Diag(DiagLoc, DiagId) << FixItHint::CreateReplacement( |
| 2674 | SourceRange(TokLocs.front(), TokLocs.back()), Str); |
| 2675 | } |
| 2676 | |
| 2677 | Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc); |
| 2678 | |
| 2679 | return Actions.checkLiteralOperatorId(SS, Result, IsUDSuffix); |
| 2680 | } |
| 2681 | |
| 2682 | |
| 2683 | |
| 2684 | |
| 2685 | |
| 2686 | |
| 2687 | |
| 2688 | |
| 2689 | |
| 2690 | |
| 2691 | |
| 2692 | |
| 2693 | |
| 2694 | DeclSpec DS(AttrFactory); |
| 2695 | if (ParseCXXTypeSpecifierSeq(DS)) |
| 2696 | return true; |
| 2697 | |
| 2698 | |
| 2699 | |
| 2700 | Declarator D(DS, DeclaratorContext::ConversionId); |
| 2701 | ParseDeclaratorInternal(D, nullptr); |
| 2702 | |
| 2703 | |
| 2704 | TypeResult Ty = Actions.ActOnTypeName(getCurScope(), D); |
| 2705 | if (Ty.isInvalid()) |
| 2706 | return true; |
| 2707 | |
| 2708 | |
| 2709 | Result.setConversionFunctionId(KeywordLoc, Ty.get(), |
| 2710 | D.getSourceRange().getEnd()); |
| 2711 | return false; |
| 2712 | } |
| 2713 | |
| 2714 | |
| 2715 | |
| 2716 | |
| 2717 | |
| 2718 | |
| 2719 | |
| 2720 | |
| 2721 | |
| 2722 | |
| 2723 | |
| 2724 | |
| 2725 | |
| 2726 | |
| 2727 | |
| 2728 | |
| 2729 | |
| 2730 | |
| 2731 | |
| 2732 | |
| 2733 | |
| 2734 | |
| 2735 | |
| 2736 | |
| 2737 | |
| 2738 | |
| 2739 | |
| 2740 | |
| 2741 | |
| 2742 | |
| 2743 | |
| 2744 | |
| 2745 | |
| 2746 | |
| 2747 | |
| 2748 | |
| 2749 | |
| 2750 | bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, |
| 2751 | bool ObjectHadErrors, bool EnteringContext, |
| 2752 | bool AllowDestructorName, |
| 2753 | bool AllowConstructorName, |
| 2754 | bool AllowDeductionGuide, |
| 2755 | SourceLocation *TemplateKWLoc, |
| 2756 | UnqualifiedId &Result) { |
| 2757 | if (TemplateKWLoc) |
| 2758 | *TemplateKWLoc = SourceLocation(); |
| 2759 | |
| 2760 | |
| 2761 | |
| 2762 | bool TemplateSpecified = false; |
| 2763 | if (Tok.is(tok::kw_template)) { |
| 2764 | if (TemplateKWLoc && (ObjectType || SS.isSet())) { |
| 2765 | TemplateSpecified = true; |
| 2766 | *TemplateKWLoc = ConsumeToken(); |
| 2767 | } else { |
| 2768 | SourceLocation TemplateLoc = ConsumeToken(); |
| 2769 | Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id) |
| 2770 | << FixItHint::CreateRemoval(TemplateLoc); |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | |
| 2775 | |
| 2776 | |
| 2777 | if (Tok.is(tok::identifier)) { |
| 2778 | |
| 2779 | IdentifierInfo *Id = Tok.getIdentifierInfo(); |
| 2780 | SourceLocation IdLoc = ConsumeToken(); |
| 2781 | |
| 2782 | if (!getLangOpts().CPlusPlus) { |
| 2783 | |
| 2784 | |
| 2785 | Result.setIdentifier(Id, IdLoc); |
| 2786 | return false; |
| 2787 | } |
| 2788 | |
| 2789 | ParsedTemplateTy TemplateName; |
| 2790 | if (AllowConstructorName && |
| 2791 | Actions.isCurrentClassName(*Id, getCurScope(), &SS)) { |
| 2792 | |
| 2793 | ParsedType Ty = Actions.getConstructorName(*Id, IdLoc, getCurScope(), SS, |
| 2794 | EnteringContext); |
| 2795 | if (!Ty) |
| 2796 | return true; |
| 2797 | Result.setConstructorName(Ty, IdLoc, IdLoc); |
| 2798 | } else if (getLangOpts().CPlusPlus17 && |
| 2799 | AllowDeductionGuide && SS.isEmpty() && |
| 2800 | Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc, |
| 2801 | &TemplateName)) { |
| 2802 | |
| 2803 | Result.setDeductionGuideName(TemplateName, IdLoc); |
| 2804 | } else { |
| 2805 | |
| 2806 | Result.setIdentifier(Id, IdLoc); |
| 2807 | } |
| 2808 | |
| 2809 | |
| 2810 | TemplateTy Template; |
| 2811 | if (Tok.is(tok::less)) |
| 2812 | return ParseUnqualifiedIdTemplateId( |
| 2813 | SS, ObjectType, ObjectHadErrors, |
| 2814 | TemplateKWLoc ? *TemplateKWLoc : SourceLocation(), Id, IdLoc, |
| 2815 | EnteringContext, Result, TemplateSpecified); |
| 2816 | else if (TemplateSpecified && |
| 2817 | Actions.ActOnTemplateName( |
| 2818 | getCurScope(), SS, *TemplateKWLoc, Result, ObjectType, |
| 2819 | EnteringContext, Template, |
| 2820 | true) == TNK_Non_template) |
| 2821 | return true; |
| 2822 | |
| 2823 | return false; |
| 2824 | } |
| 2825 | |
| 2826 | |
| 2827 | |
| 2828 | if (Tok.is(tok::annot_template_id)) { |
| 2829 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
| 2830 | |
| 2831 | |
| 2832 | |
| 2833 | if (TemplateId->isInvalid()) { |
| 2834 | ConsumeAnnotationToken(); |
| 2835 | return true; |
| 2836 | } |
| 2837 | |
| 2838 | |
| 2839 | if (AllowConstructorName && TemplateId->Name && |
| 2840 | Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS)) { |
| 2841 | if (SS.isSet()) { |
| 2842 | |
| 2843 | |
| 2844 | |
| 2845 | |
| 2846 | Diag(TemplateId->TemplateNameLoc, |
| 2847 | diag::err_out_of_line_constructor_template_id) |
| 2848 | << TemplateId->Name |
| 2849 | << FixItHint::CreateRemoval( |
| 2850 | SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc)); |
| 2851 | ParsedType Ty = Actions.getConstructorName( |
| 2852 | *TemplateId->Name, TemplateId->TemplateNameLoc, getCurScope(), SS, |
| 2853 | EnteringContext); |
| 2854 | if (!Ty) |
| 2855 | return true; |
| 2856 | Result.setConstructorName(Ty, TemplateId->TemplateNameLoc, |
| 2857 | TemplateId->RAngleLoc); |
| 2858 | ConsumeAnnotationToken(); |
| 2859 | return false; |
| 2860 | } |
| 2861 | |
| 2862 | Result.setConstructorTemplateId(TemplateId); |
| 2863 | ConsumeAnnotationToken(); |
| 2864 | return false; |
| 2865 | } |
| 2866 | |
| 2867 | |
| 2868 | |
| 2869 | Result.setTemplateId(TemplateId); |
| 2870 | SourceLocation TemplateLoc = TemplateId->TemplateKWLoc; |
| 2871 | if (TemplateLoc.isValid()) { |
| 2872 | if (TemplateKWLoc && (ObjectType || SS.isSet())) |
| 2873 | *TemplateKWLoc = TemplateLoc; |
| 2874 | else |
| 2875 | Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id) |
| 2876 | << FixItHint::CreateRemoval(TemplateLoc); |
| 2877 | } |
| 2878 | ConsumeAnnotationToken(); |
| 2879 | return false; |
| 2880 | } |
| 2881 | |
| 2882 | |
| 2883 | |
| 2884 | |
| 2885 | if (Tok.is(tok::kw_operator)) { |
| 2886 | if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, Result)) |
| 2887 | return true; |
| 2888 | |
| 2889 | |
| 2890 | |
| 2891 | |
| 2892 | |
| 2893 | |
| 2894 | TemplateTy Template; |
| 2895 | if ((Result.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId || |
| 2896 | Result.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId) && |
| 2897 | Tok.is(tok::less)) |
| 2898 | return ParseUnqualifiedIdTemplateId( |
| 2899 | SS, ObjectType, ObjectHadErrors, |
| 2900 | TemplateKWLoc ? *TemplateKWLoc : SourceLocation(), nullptr, |
| 2901 | SourceLocation(), EnteringContext, Result, TemplateSpecified); |
| 2902 | else if (TemplateSpecified && |
| 2903 | Actions.ActOnTemplateName( |
| 2904 | getCurScope(), SS, *TemplateKWLoc, Result, ObjectType, |
| 2905 | EnteringContext, Template, |
| 2906 | true) == TNK_Non_template) |
| 2907 | return true; |
| 2908 | |
| 2909 | return false; |
| 2910 | } |
| 2911 | |
| 2912 | if (getLangOpts().CPlusPlus && |
| 2913 | (AllowDestructorName || SS.isSet()) && Tok.is(tok::tilde)) { |
| 2914 | |
| 2915 | |
| 2916 | |
| 2917 | |
| 2918 | |
| 2919 | |
| 2920 | SourceLocation TildeLoc = ConsumeToken(); |
| 2921 | |
| 2922 | if (TemplateSpecified) { |
| 2923 | |
| 2924 | |
| 2925 | |
| 2926 | |
| 2927 | |
| 2928 | |
| 2929 | |
| 2930 | |
| 2931 | |
| 2932 | |
| 2933 | Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name) |
| 2934 | << Tok.getLocation(); |
| 2935 | return true; |
| 2936 | } |
| 2937 | |
| 2938 | if (SS.isEmpty() && Tok.is(tok::kw_decltype)) { |
| 2939 | DeclSpec DS(AttrFactory); |
| 2940 | SourceLocation EndLoc = ParseDecltypeSpecifier(DS); |
| 2941 | if (ParsedType Type = |
| 2942 | Actions.getDestructorTypeForDecltype(DS, ObjectType)) { |
| 2943 | Result.setDestructorName(TildeLoc, Type, EndLoc); |
| 2944 | return false; |
| 2945 | } |
| 2946 | return true; |
| 2947 | } |
| 2948 | |
| 2949 | |
| 2950 | if (Tok.isNot(tok::identifier)) { |
| 2951 | Diag(Tok, diag::err_destructor_tilde_identifier); |
| 2952 | return true; |
| 2953 | } |
| 2954 | |
| 2955 | |
| 2956 | DeclaratorScopeObj DeclScopeObj(*this, SS); |
| 2957 | if (NextToken().is(tok::coloncolon)) { |
| 2958 | |
| 2959 | |
| 2960 | |
| 2961 | ColonProtectionRAIIObject ColonRAII(*this, false); |
| 2962 | |
| 2963 | if (SS.isSet()) { |
| 2964 | AnnotateScopeToken(SS, true); |
| 2965 | SS.clear(); |
| 2966 | } |
| 2967 | if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors, |
| 2968 | EnteringContext)) |
| 2969 | return true; |
| 2970 | if (SS.isNotEmpty()) |
| 2971 | ObjectType = nullptr; |
| 2972 | if (Tok.isNot(tok::identifier) || NextToken().is(tok::coloncolon) || |
| 2973 | !SS.isSet()) { |
| 2974 | Diag(TildeLoc, diag::err_destructor_tilde_scope); |
| 2975 | return true; |
| 2976 | } |
| 2977 | |
| 2978 | |
| 2979 | Diag(TildeLoc, diag::err_destructor_tilde_scope) |
| 2980 | << FixItHint::CreateRemoval(TildeLoc) |
| 2981 | << FixItHint::CreateInsertion(Tok.getLocation(), "~"); |
| 2982 | |
| 2983 | |
| 2984 | if (Actions.ShouldEnterDeclaratorScope(getCurScope(), SS)) |
| 2985 | DeclScopeObj.EnterDeclaratorScope(); |
| 2986 | } |
| 2987 | |
| 2988 | |
| 2989 | IdentifierInfo *ClassName = Tok.getIdentifierInfo(); |
| 2990 | SourceLocation ClassNameLoc = ConsumeToken(); |
| 2991 | |
| 2992 | if (Tok.is(tok::less)) { |
| 2993 | Result.setDestructorName(TildeLoc, nullptr, ClassNameLoc); |
| 2994 | return ParseUnqualifiedIdTemplateId( |
| 2995 | SS, ObjectType, ObjectHadErrors, |
| 2996 | TemplateKWLoc ? *TemplateKWLoc : SourceLocation(), ClassName, |
| 2997 | ClassNameLoc, EnteringContext, Result, TemplateSpecified); |
| 2998 | } |
| 2999 | |
| 3000 | |
| 3001 | ParsedType Ty = Actions.getDestructorName(TildeLoc, *ClassName, |
| 3002 | ClassNameLoc, getCurScope(), |
| 3003 | SS, ObjectType, |
| 3004 | EnteringContext); |
| 3005 | if (!Ty) |
| 3006 | return true; |
| 3007 | |
| 3008 | Result.setDestructorName(TildeLoc, Ty, ClassNameLoc); |
| 3009 | return false; |
| 3010 | } |
| 3011 | |
| 3012 | Diag(Tok, diag::err_expected_unqualified_id) |
| 3013 | << getLangOpts().CPlusPlus; |
| 3014 | return true; |
| 3015 | } |
| 3016 | |
| 3017 | |
| 3018 | |
| 3019 | |
| 3020 | |
| 3021 | |
| 3022 | |
| 3023 | |
| 3024 | |
| 3025 | |
| 3026 | |
| 3027 | |
| 3028 | |
| 3029 | |
| 3030 | |
| 3031 | |
| 3032 | |
| 3033 | |
| 3034 | |
| 3035 | |
| 3036 | |
| 3037 | |
| 3038 | |
| 3039 | |
| 3040 | |
| 3041 | |
| 3042 | |
| 3043 | |
| 3044 | |
| 3045 | ExprResult |
| 3046 | Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) { |
| 3047 | assert(Tok.is(tok::kw_new) && "expected 'new' token"); |
| 3048 | ConsumeToken(); |
| 3049 | |
| 3050 | |
| 3051 | |
| 3052 | |
| 3053 | ExprVector PlacementArgs; |
| 3054 | SourceLocation PlacementLParen, PlacementRParen; |
| 3055 | |
| 3056 | SourceRange TypeIdParens; |
| 3057 | DeclSpec DS(AttrFactory); |
| 3058 | Declarator DeclaratorInfo(DS, DeclaratorContext::CXXNew); |
| 3059 | if (Tok.is(tok::l_paren)) { |
| 3060 | |
| 3061 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3062 | T.consumeOpen(); |
| 3063 | PlacementLParen = T.getOpenLocation(); |
| 3064 | if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) { |
| 3065 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
| 3066 | return ExprError(); |
| 3067 | } |
| 3068 | |
| 3069 | T.consumeClose(); |
| 3070 | PlacementRParen = T.getCloseLocation(); |
| 3071 | if (PlacementRParen.isInvalid()) { |
| 3072 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
| 3073 | return ExprError(); |
| 3074 | } |
| 3075 | |
| 3076 | if (PlacementArgs.empty()) { |
| 3077 | |
| 3078 | TypeIdParens = T.getRange(); |
| 3079 | PlacementLParen = PlacementRParen = SourceLocation(); |
| 3080 | } else { |
| 3081 | |
| 3082 | if (Tok.is(tok::l_paren)) { |
| 3083 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3084 | T.consumeOpen(); |
| 3085 | MaybeParseGNUAttributes(DeclaratorInfo); |
| 3086 | ParseSpecifierQualifierList(DS); |
| 3087 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
| 3088 | ParseDeclarator(DeclaratorInfo); |
| 3089 | T.consumeClose(); |
| 3090 | TypeIdParens = T.getRange(); |
| 3091 | } else { |
| 3092 | MaybeParseGNUAttributes(DeclaratorInfo); |
| 3093 | if (ParseCXXTypeSpecifierSeq(DS)) |
| 3094 | DeclaratorInfo.setInvalidType(true); |
| 3095 | else { |
| 3096 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
| 3097 | ParseDeclaratorInternal(DeclaratorInfo, |
| 3098 | &Parser::ParseDirectNewDeclarator); |
| 3099 | } |
| 3100 | } |
| 3101 | } |
| 3102 | } else { |
| 3103 | |
| 3104 | |
| 3105 | MaybeParseGNUAttributes(DeclaratorInfo); |
| 3106 | if (ParseCXXTypeSpecifierSeq(DS)) |
| 3107 | DeclaratorInfo.setInvalidType(true); |
| 3108 | else { |
| 3109 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
| 3110 | ParseDeclaratorInternal(DeclaratorInfo, |
| 3111 | &Parser::ParseDirectNewDeclarator); |
| 3112 | } |
| 3113 | } |
| 3114 | if (DeclaratorInfo.isInvalidType()) { |
| 3115 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
| 3116 | return ExprError(); |
| 3117 | } |
| 3118 | |
| 3119 | ExprResult Initializer; |
| 3120 | |
| 3121 | if (Tok.is(tok::l_paren)) { |
| 3122 | SourceLocation ConstructorLParen, ConstructorRParen; |
| 3123 | ExprVector ConstructorArgs; |
| 3124 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3125 | T.consumeOpen(); |
| 3126 | ConstructorLParen = T.getOpenLocation(); |
| 3127 | if (Tok.isNot(tok::r_paren)) { |
| 3128 | CommaLocsTy CommaLocs; |
| 3129 | auto RunSignatureHelp = [&]() { |
| 3130 | ParsedType TypeRep = |
| 3131 | Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get(); |
| 3132 | QualType PreferredType; |
| 3133 | |
| 3134 | |
| 3135 | |
| 3136 | if (TypeRep) |
| 3137 | PreferredType = Actions.ProduceConstructorSignatureHelp( |
| 3138 | getCurScope(), TypeRep.get()->getCanonicalTypeInternal(), |
| 3139 | DeclaratorInfo.getEndLoc(), ConstructorArgs, ConstructorLParen); |
| 3140 | CalledSignatureHelp = true; |
| 3141 | return PreferredType; |
| 3142 | }; |
| 3143 | if (ParseExpressionList(ConstructorArgs, CommaLocs, [&] { |
| 3144 | PreferredType.enterFunctionArgument(Tok.getLocation(), |
| 3145 | RunSignatureHelp); |
| 3146 | })) { |
| 3147 | if (PP.isCodeCompletionReached() && !CalledSignatureHelp) |
| 3148 | RunSignatureHelp(); |
| 3149 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
| 3150 | return ExprError(); |
| 3151 | } |
| 3152 | } |
| 3153 | T.consumeClose(); |
| 3154 | ConstructorRParen = T.getCloseLocation(); |
| 3155 | if (ConstructorRParen.isInvalid()) { |
| 3156 | SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch); |
| 3157 | return ExprError(); |
| 3158 | } |
| 3159 | Initializer = Actions.ActOnParenListExpr(ConstructorLParen, |
| 3160 | ConstructorRParen, |
| 3161 | ConstructorArgs); |
| 3162 | } else if (Tok.is(tok::l_brace) && getLangOpts().CPlusPlus11) { |
| 3163 | Diag(Tok.getLocation(), |
| 3164 | diag::warn_cxx98_compat_generalized_initializer_lists); |
| 3165 | Initializer = ParseBraceInitializer(); |
| 3166 | } |
| 3167 | if (Initializer.isInvalid()) |
| 3168 | return Initializer; |
| 3169 | |
| 3170 | return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen, |
| 3171 | PlacementArgs, PlacementRParen, |
| 3172 | TypeIdParens, DeclaratorInfo, Initializer.get()); |
| 3173 | } |
| 3174 | |
| 3175 | |
| 3176 | |
| 3177 | |
| 3178 | |
| 3179 | |
| 3180 | |
| 3181 | |
| 3182 | void Parser::ParseDirectNewDeclarator(Declarator &D) { |
| 3183 | |
| 3184 | bool First = true; |
| 3185 | while (Tok.is(tok::l_square)) { |
| 3186 | |
| 3187 | if (CheckProhibitedCXX11Attribute()) |
| 3188 | continue; |
| 3189 | |
| 3190 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 3191 | T.consumeOpen(); |
| 3192 | |
| 3193 | ExprResult Size = |
| 3194 | First ? (Tok.is(tok::r_square) ? ExprResult() : ParseExpression()) |
| 3195 | : ParseConstantExpression(); |
| 3196 | if (Size.isInvalid()) { |
| 3197 | |
| 3198 | SkipUntil(tok::r_square, StopAtSemi); |
| 3199 | return; |
| 3200 | } |
| 3201 | First = false; |
| 3202 | |
| 3203 | T.consumeClose(); |
| 3204 | |
| 3205 | |
| 3206 | ParsedAttributes Attrs(AttrFactory); |
| 3207 | MaybeParseCXX11Attributes(Attrs); |
| 3208 | |
| 3209 | D.AddTypeInfo(DeclaratorChunk::getArray(0, |
| 3210 | false, false, |
| 3211 | Size.get(), T.getOpenLocation(), |
| 3212 | T.getCloseLocation()), |
| 3213 | std::move(Attrs), T.getCloseLocation()); |
| 3214 | |
| 3215 | if (T.getCloseLocation().isInvalid()) |
| 3216 | return; |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | |
| 3221 | |
| 3222 | |
| 3223 | |
| 3224 | |
| 3225 | |
| 3226 | |
| 3227 | |
| 3228 | |
| 3229 | |
| 3230 | bool Parser::ParseExpressionListOrTypeId( |
| 3231 | SmallVectorImpl<Expr*> &PlacementArgs, |
| 3232 | Declarator &D) { |
| 3233 | |
| 3234 | if (isTypeIdInParens()) { |
| 3235 | ParseSpecifierQualifierList(D.getMutableDeclSpec()); |
| 3236 | D.SetSourceRange(D.getDeclSpec().getSourceRange()); |
| 3237 | ParseDeclarator(D); |
| 3238 | return D.isInvalidType(); |
| 3239 | } |
| 3240 | |
| 3241 | |
| 3242 | |
| 3243 | CommaLocsTy CommaLocs; |
| 3244 | return ParseExpressionList(PlacementArgs, CommaLocs); |
| 3245 | } |
| 3246 | |
| 3247 | |
| 3248 | |
| 3249 | |
| 3250 | |
| 3251 | |
| 3252 | |
| 3253 | |
| 3254 | |
| 3255 | |
| 3256 | |
| 3257 | |
| 3258 | ExprResult |
| 3259 | Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) { |
| 3260 | assert(Tok.is(tok::kw_delete) && "Expected 'delete' keyword"); |
| 3261 | ConsumeToken(); |
| 3262 | |
| 3263 | |
| 3264 | bool ArrayDelete = false; |
| 3265 | if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) { |
| 3266 | |
| 3267 | |
| 3268 | |
| 3269 | |
| 3270 | |
| 3271 | |
| 3272 | |
| 3273 | const Token Next = GetLookAheadToken(2); |
| 3274 | |
| 3275 | |
| 3276 | if (Next.isOneOf(tok::l_brace, tok::less) || |
| 3277 | (Next.is(tok::l_paren) && |
| 3278 | (GetLookAheadToken(3).is(tok::r_paren) || |
| 3279 | (GetLookAheadToken(3).is(tok::identifier) && |
| 3280 | GetLookAheadToken(4).is(tok::identifier))))) { |
| 3281 | TentativeParsingAction TPA(*this); |
| 3282 | SourceLocation LSquareLoc = Tok.getLocation(); |
| 3283 | SourceLocation RSquareLoc = NextToken().getLocation(); |
| 3284 | |
| 3285 | |
| 3286 | |
| 3287 | SkipUntil({tok::l_brace, tok::less}, StopBeforeMatch); |
| 3288 | SourceLocation RBraceLoc; |
| 3289 | bool EmitFixIt = false; |
| 3290 | if (Tok.is(tok::l_brace)) { |
| 3291 | ConsumeBrace(); |
| 3292 | SkipUntil(tok::r_brace, StopBeforeMatch); |
| 3293 | RBraceLoc = Tok.getLocation(); |
| 3294 | EmitFixIt = true; |
| 3295 | } |
| 3296 | |
| 3297 | TPA.Revert(); |
| 3298 | |
| 3299 | if (EmitFixIt) |
| 3300 | Diag(Start, diag::err_lambda_after_delete) |
| 3301 | << SourceRange(Start, RSquareLoc) |
| 3302 | << FixItHint::CreateInsertion(LSquareLoc, "(") |
| 3303 | << FixItHint::CreateInsertion( |
| 3304 | Lexer::getLocForEndOfToken( |
| 3305 | RBraceLoc, 0, Actions.getSourceManager(), getLangOpts()), |
| 3306 | ")"); |
| 3307 | else |
| 3308 | Diag(Start, diag::err_lambda_after_delete) |
| 3309 | << SourceRange(Start, RSquareLoc); |
| 3310 | |
| 3311 | |
| 3312 | |
| 3313 | ExprResult Lambda = ParseLambdaExpression(); |
| 3314 | if (Lambda.isInvalid()) |
| 3315 | return ExprError(); |
| 3316 | |
| 3317 | |
| 3318 | Lambda = ParsePostfixExpressionSuffix(Lambda); |
| 3319 | if (Lambda.isInvalid()) |
| 3320 | return ExprError(); |
| 3321 | return Actions.ActOnCXXDelete(Start, UseGlobal, false, |
| 3322 | Lambda.get()); |
| 3323 | } |
| 3324 | |
| 3325 | ArrayDelete = true; |
| 3326 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 3327 | |
| 3328 | T.consumeOpen(); |
| 3329 | T.consumeClose(); |
| 3330 | if (T.getCloseLocation().isInvalid()) |
| 3331 | return ExprError(); |
| 3332 | } |
| 3333 | |
| 3334 | ExprResult Operand(ParseCastExpression(AnyCastExpr)); |
| 3335 | if (Operand.isInvalid()) |
| 3336 | return Operand; |
| 3337 | |
| 3338 | return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.get()); |
| 3339 | } |
| 3340 | |
| 3341 | |
| 3342 | |
| 3343 | |
| 3344 | |
| 3345 | |
| 3346 | |
| 3347 | |
| 3348 | |
| 3349 | |
| 3350 | |
| 3351 | |
| 3352 | |
| 3353 | |
| 3354 | |
| 3355 | |
| 3356 | |
| 3357 | |
| 3358 | |
| 3359 | |
| 3360 | |
| 3361 | |
| 3362 | |
| 3363 | |
| 3364 | |
| 3365 | ExprResult Parser::ParseRequiresExpression() { |
| 3366 | assert(Tok.is(tok::kw_requires) && "Expected 'requires' keyword"); |
| 3367 | SourceLocation RequiresKWLoc = ConsumeToken(); |
| 3368 | |
| 3369 | llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls; |
| 3370 | if (Tok.is(tok::l_paren)) { |
| 3371 | |
| 3372 | ParseScope LocalParametersScope(this, Scope::FunctionPrototypeScope | |
| 3373 | Scope::DeclScope); |
| 3374 | BalancedDelimiterTracker Parens(*this, tok::l_paren); |
| 3375 | Parens.consumeOpen(); |
| 3376 | if (!Tok.is(tok::r_paren)) { |
| 3377 | ParsedAttributes FirstArgAttrs(getAttrFactory()); |
| 3378 | SourceLocation EllipsisLoc; |
| 3379 | llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters; |
| 3380 | ParseParameterDeclarationClause(DeclaratorContext::RequiresExpr, |
| 3381 | FirstArgAttrs, LocalParameters, |
| 3382 | EllipsisLoc); |
| 3383 | if (EllipsisLoc.isValid()) |
| 3384 | Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis); |
| 3385 | for (auto &ParamInfo : LocalParameters) |
| 3386 | LocalParameterDecls.push_back(cast<ParmVarDecl>(ParamInfo.Param)); |
| 3387 | } |
| 3388 | Parens.consumeClose(); |
| 3389 | } |
| 3390 | |
| 3391 | BalancedDelimiterTracker Braces(*this, tok::l_brace); |
| 3392 | if (Braces.expectAndConsume()) |
| 3393 | return ExprError(); |
| 3394 | |
| 3395 | |
| 3396 | llvm::SmallVector<concepts::Requirement *, 2> Requirements; |
| 3397 | |
| 3398 | |
| 3399 | |
| 3400 | EnterExpressionEvaluationContext Ctx( |
| 3401 | Actions, Sema::ExpressionEvaluationContext::Unevaluated); |
| 3402 | |
| 3403 | ParseScope BodyScope(this, Scope::DeclScope); |
| 3404 | RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr( |
| 3405 | RequiresKWLoc, LocalParameterDecls, getCurScope()); |
| 3406 | |
| 3407 | if (Tok.is(tok::r_brace)) { |
| 3408 | |
| 3409 | |
| 3410 | |
| 3411 | |
| 3412 | |
| 3413 | |
| 3414 | Diag(Tok, diag::err_empty_requires_expr); |
| 3415 | |
| 3416 | } else { |
| 3417 | while (!Tok.is(tok::r_brace)) { |
| 3418 | switch (Tok.getKind()) { |
| 3419 | case tok::l_brace: { |
| 3420 | |
| 3421 | |
| 3422 | |
| 3423 | |
| 3424 | |
| 3425 | |
| 3426 | |
| 3427 | |
| 3428 | |
| 3429 | BalancedDelimiterTracker ExprBraces(*this, tok::l_brace); |
| 3430 | ExprBraces.consumeOpen(); |
| 3431 | ExprResult Expression = |
| 3432 | Actions.CorrectDelayedTyposInExpr(ParseExpression()); |
| 3433 | if (!Expression.isUsable()) { |
| 3434 | ExprBraces.skipToEnd(); |
| 3435 | SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch); |
| 3436 | break; |
| 3437 | } |
| 3438 | if (ExprBraces.consumeClose()) |
| 3439 | ExprBraces.skipToEnd(); |
| 3440 | |
| 3441 | concepts::Requirement *Req = nullptr; |
| 3442 | SourceLocation NoexceptLoc; |
| 3443 | TryConsumeToken(tok::kw_noexcept, NoexceptLoc); |
| 3444 | if (Tok.is(tok::semi)) { |
| 3445 | Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc); |
| 3446 | if (Req) |
| 3447 | Requirements.push_back(Req); |
| 3448 | break; |
| 3449 | } |
| 3450 | if (!TryConsumeToken(tok::arrow)) |
| 3451 | |
| 3452 | Diag(Tok, diag::err_requires_expr_missing_arrow) |
| 3453 | << FixItHint::CreateInsertion(Tok.getLocation(), "->"); |
| 3454 | |
| 3455 | if (TryAnnotateTypeConstraint()) { |
| 3456 | SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch); |
| 3457 | break; |
| 3458 | } |
| 3459 | if (!isTypeConstraintAnnotation()) { |
| 3460 | Diag(Tok, diag::err_requires_expr_expected_type_constraint); |
| 3461 | SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch); |
| 3462 | break; |
| 3463 | } |
| 3464 | CXXScopeSpec SS; |
| 3465 | if (Tok.is(tok::annot_cxxscope)) { |
| 3466 | Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), |
| 3467 | Tok.getAnnotationRange(), |
| 3468 | SS); |
| 3469 | ConsumeAnnotationToken(); |
| 3470 | } |
| 3471 | |
| 3472 | Req = Actions.ActOnCompoundRequirement( |
| 3473 | Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok), |
| 3474 | TemplateParameterDepth); |
| 3475 | ConsumeAnnotationToken(); |
| 3476 | if (Req) |
| 3477 | Requirements.push_back(Req); |
| 3478 | break; |
| 3479 | } |
| 3480 | default: { |
| 3481 | bool PossibleRequiresExprInSimpleRequirement = false; |
| 3482 | if (Tok.is(tok::kw_requires)) { |
| 3483 | auto IsNestedRequirement = [&] { |
| 3484 | RevertingTentativeParsingAction TPA(*this); |
| 3485 | ConsumeToken(); |
| 3486 | if (Tok.is(tok::l_brace)) |
| 3487 | |
| 3488 | |
| 3489 | |
| 3490 | |
| 3491 | |
| 3492 | return false; |
| 3493 | if (Tok.is(tok::l_paren)) { |
| 3494 | |
| 3495 | ConsumeParen(); |
| 3496 | auto Res = TryParseParameterDeclarationClause(); |
| 3497 | if (Res != TPResult::False) { |
| 3498 | |
| 3499 | |
| 3500 | |
| 3501 | unsigned Depth = 1; |
| 3502 | while (Depth != 0) { |
| 3503 | if (Tok.is(tok::l_paren)) |
| 3504 | Depth++; |
| 3505 | else if (Tok.is(tok::r_paren)) |
| 3506 | Depth--; |
| 3507 | ConsumeAnyToken(); |
| 3508 | } |
| 3509 | |
| 3510 | |
| 3511 | |
| 3512 | |
| 3513 | |
| 3514 | |
| 3515 | |
| 3516 | if (Tok.is(tok::l_brace)) |
| 3517 | |
| 3518 | |
| 3519 | |
| 3520 | return false; |
| 3521 | } |
| 3522 | } |
| 3523 | return true; |
| 3524 | }; |
| 3525 | if (IsNestedRequirement()) { |
| 3526 | ConsumeToken(); |
| 3527 | |
| 3528 | |
| 3529 | |
| 3530 | |
| 3531 | ExprResult ConstraintExpr = |
| 3532 | Actions.CorrectDelayedTyposInExpr(ParseConstraintExpression()); |
| 3533 | if (ConstraintExpr.isInvalid() || !ConstraintExpr.isUsable()) { |
| 3534 | SkipUntil(tok::semi, tok::r_brace, |
| 3535 | SkipUntilFlags::StopBeforeMatch); |
| 3536 | break; |
| 3537 | } |
| 3538 | if (auto *Req = |
| 3539 | Actions.ActOnNestedRequirement(ConstraintExpr.get())) |
| 3540 | Requirements.push_back(Req); |
| 3541 | else { |
| 3542 | SkipUntil(tok::semi, tok::r_brace, |
| 3543 | SkipUntilFlags::StopBeforeMatch); |
| 3544 | break; |
| 3545 | } |
| 3546 | break; |
| 3547 | } else |
| 3548 | PossibleRequiresExprInSimpleRequirement = true; |
| 3549 | } else if (Tok.is(tok::kw_typename)) { |
| 3550 | |
| 3551 | |
| 3552 | TentativeParsingAction TPA(*this); |
| 3553 | |
| 3554 | |
| 3555 | SourceLocation TypenameKWLoc = ConsumeToken(); |
| 3556 | if (TryAnnotateCXXScopeToken()) { |
| 3557 | TPA.Commit(); |
| 3558 | SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch); |
| 3559 | break; |
| 3560 | } |
| 3561 | CXXScopeSpec SS; |
| 3562 | if (Tok.is(tok::annot_cxxscope)) { |
| 3563 | Actions.RestoreNestedNameSpecifierAnnotation( |
| 3564 | Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS); |
| 3565 | ConsumeAnnotationToken(); |
| 3566 | } |
| 3567 | |
| 3568 | if (Tok.isOneOf(tok::identifier, tok::annot_template_id) && |
| 3569 | !NextToken().isOneOf(tok::l_brace, tok::l_paren)) { |
| 3570 | TPA.Commit(); |
| 3571 | SourceLocation NameLoc = Tok.getLocation(); |
| 3572 | IdentifierInfo *II = nullptr; |
| 3573 | TemplateIdAnnotation *TemplateId = nullptr; |
| 3574 | if (Tok.is(tok::identifier)) { |
| 3575 | II = Tok.getIdentifierInfo(); |
| 3576 | ConsumeToken(); |
| 3577 | } else { |
| 3578 | TemplateId = takeTemplateIdAnnotation(Tok); |
| 3579 | ConsumeAnnotationToken(); |
| 3580 | if (TemplateId->isInvalid()) |
| 3581 | break; |
| 3582 | } |
| 3583 | |
| 3584 | if (auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS, |
| 3585 | NameLoc, II, |
| 3586 | TemplateId)) { |
| 3587 | Requirements.push_back(Req); |
| 3588 | } |
| 3589 | break; |
| 3590 | } |
| 3591 | TPA.Revert(); |
| 3592 | } |
| 3593 | |
| 3594 | |
| 3595 | |
| 3596 | |
| 3597 | SourceLocation StartLoc = Tok.getLocation(); |
| 3598 | ExprResult Expression = |
| 3599 | Actions.CorrectDelayedTyposInExpr(ParseExpression()); |
| 3600 | if (!Expression.isUsable()) { |
| 3601 | SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch); |
| 3602 | break; |
| 3603 | } |
| 3604 | if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement) |
| 3605 | Diag(StartLoc, diag::warn_requires_expr_in_simple_requirement) |
| 3606 | << FixItHint::CreateInsertion(StartLoc, "requires"); |
| 3607 | if (auto *Req = Actions.ActOnSimpleRequirement(Expression.get())) |
| 3608 | Requirements.push_back(Req); |
| 3609 | else { |
| 3610 | SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch); |
| 3611 | break; |
| 3612 | } |
| 3613 | |
| 3614 | if (Tok.is(tok::kw_noexcept)) { |
| 3615 | Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept) |
| 3616 | << FixItHint::CreateInsertion(StartLoc, "{") |
| 3617 | << FixItHint::CreateInsertion(Tok.getLocation(), "}"); |
| 3618 | SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch); |
| 3619 | break; |
| 3620 | } |
| 3621 | break; |
| 3622 | } |
| 3623 | } |
| 3624 | if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) { |
| 3625 | SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch); |
| 3626 | TryConsumeToken(tok::semi); |
| 3627 | break; |
| 3628 | } |
| 3629 | } |
| 3630 | if (Requirements.empty()) { |
| 3631 | |
| 3632 | |
| 3633 | |
| 3634 | Braces.consumeClose(); |
| 3635 | Actions.ActOnFinishRequiresExpr(); |
| 3636 | return ExprError(); |
| 3637 | } |
| 3638 | } |
| 3639 | Braces.consumeClose(); |
| 3640 | Actions.ActOnFinishRequiresExpr(); |
| 3641 | return Actions.ActOnRequiresExpr(RequiresKWLoc, Body, LocalParameterDecls, |
| 3642 | Requirements, Braces.getCloseLocation()); |
| 3643 | } |
| 3644 | |
| 3645 | static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind) { |
| 3646 | switch (kind) { |
| 3647 | default: llvm_unreachable("Not a known type trait"); |
| 3648 | #define TYPE_TRAIT_1(Spelling, Name, Key) \ |
| 3649 | case tok::kw_ ## Spelling: return UTT_ ## Name; |
| 3650 | #define TYPE_TRAIT_2(Spelling, Name, Key) \ |
| 3651 | case tok::kw_ ## Spelling: return BTT_ ## Name; |
| 3652 | #include "clang/Basic/TokenKinds.def" |
| 3653 | #define TYPE_TRAIT_N(Spelling, Name, Key) \ |
| 3654 | case tok::kw_ ## Spelling: return TT_ ## Name; |
| 3655 | #include "clang/Basic/TokenKinds.def" |
| 3656 | } |
| 3657 | } |
| 3658 | |
| 3659 | static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind) { |
| 3660 | switch (kind) { |
| 3661 | default: |
| 3662 | llvm_unreachable("Not a known array type trait"); |
| 3663 | #define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \ |
| 3664 | case tok::kw_##Spelling: \ |
| 3665 | return ATT_##Name; |
| 3666 | #include "clang/Basic/TokenKinds.def" |
| 3667 | } |
| 3668 | } |
| 3669 | |
| 3670 | static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind) { |
| 3671 | switch (kind) { |
| 3672 | default: |
| 3673 | llvm_unreachable("Not a known unary expression trait."); |
| 3674 | #define EXPRESSION_TRAIT(Spelling, Name, Key) \ |
| 3675 | case tok::kw_##Spelling: \ |
| 3676 | return ET_##Name; |
| 3677 | #include "clang/Basic/TokenKinds.def" |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | static unsigned TypeTraitArity(tok::TokenKind kind) { |
| 3682 | switch (kind) { |
| 3683 | default: llvm_unreachable("Not a known type trait"); |
| 3684 | #define TYPE_TRAIT(N,Spelling,K) case tok::kw_##Spelling: return N; |
| 3685 | #include "clang/Basic/TokenKinds.def" |
| 3686 | } |
| 3687 | } |
| 3688 | |
| 3689 | |
| 3690 | |
| 3691 | |
| 3692 | |
| 3693 | |
| 3694 | |
| 3695 | |
| 3696 | |
| 3697 | |
| 3698 | |
| 3699 | |
| 3700 | ExprResult Parser::ParseTypeTrait() { |
| 3701 | tok::TokenKind Kind = Tok.getKind(); |
| 3702 | unsigned Arity = TypeTraitArity(Kind); |
| 3703 | |
| 3704 | SourceLocation Loc = ConsumeToken(); |
| 3705 | |
| 3706 | BalancedDelimiterTracker Parens(*this, tok::l_paren); |
| 3707 | if (Parens.expectAndConsume()) |
| 3708 | return ExprError(); |
| 3709 | |
| 3710 | SmallVector<ParsedType, 2> Args; |
| 3711 | do { |
| 3712 | |
| 3713 | TypeResult Ty = ParseTypeName(); |
| 3714 | if (Ty.isInvalid()) { |
| 3715 | Parens.skipToEnd(); |
| 3716 | return ExprError(); |
| 3717 | } |
| 3718 | |
| 3719 | |
| 3720 | if (Tok.is(tok::ellipsis)) { |
| 3721 | Ty = Actions.ActOnPackExpansion(Ty.get(), ConsumeToken()); |
| 3722 | if (Ty.isInvalid()) { |
| 3723 | Parens.skipToEnd(); |
| 3724 | return ExprError(); |
| 3725 | } |
| 3726 | } |
| 3727 | |
| 3728 | |
| 3729 | Args.push_back(Ty.get()); |
| 3730 | } while (TryConsumeToken(tok::comma)); |
| 3731 | |
| 3732 | if (Parens.consumeClose()) |
| 3733 | return ExprError(); |
| 3734 | |
| 3735 | SourceLocation EndLoc = Parens.getCloseLocation(); |
| 3736 | |
| 3737 | if (Arity && Args.size() != Arity) { |
| 3738 | Diag(EndLoc, diag::err_type_trait_arity) |
| 3739 | << Arity << 0 << (Arity > 1) << (int)Args.size() << SourceRange(Loc); |
| 3740 | return ExprError(); |
| 3741 | } |
| 3742 | |
| 3743 | if (!Arity && Args.empty()) { |
| 3744 | Diag(EndLoc, diag::err_type_trait_arity) |
| 3745 | << 1 << 1 << 1 << (int)Args.size() << SourceRange(Loc); |
| 3746 | return ExprError(); |
| 3747 | } |
| 3748 | |
| 3749 | return Actions.ActOnTypeTrait(TypeTraitFromTokKind(Kind), Loc, Args, EndLoc); |
| 3750 | } |
| 3751 | |
| 3752 | |
| 3753 | |
| 3754 | |
| 3755 | |
| 3756 | |
| 3757 | |
| 3758 | |
| 3759 | ExprResult Parser::ParseArrayTypeTrait() { |
| 3760 | ArrayTypeTrait ATT = ArrayTypeTraitFromTokKind(Tok.getKind()); |
| 3761 | SourceLocation Loc = ConsumeToken(); |
| 3762 | |
| 3763 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3764 | if (T.expectAndConsume()) |
| 3765 | return ExprError(); |
| 3766 | |
| 3767 | TypeResult Ty = ParseTypeName(); |
| 3768 | if (Ty.isInvalid()) { |
| 3769 | SkipUntil(tok::comma, StopAtSemi); |
| 3770 | SkipUntil(tok::r_paren, StopAtSemi); |
| 3771 | return ExprError(); |
| 3772 | } |
| 3773 | |
| 3774 | switch (ATT) { |
| 3775 | case ATT_ArrayRank: { |
| 3776 | T.consumeClose(); |
| 3777 | return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), nullptr, |
| 3778 | T.getCloseLocation()); |
| 3779 | } |
| 3780 | case ATT_ArrayExtent: { |
| 3781 | if (ExpectAndConsume(tok::comma)) { |
| 3782 | SkipUntil(tok::r_paren, StopAtSemi); |
| 3783 | return ExprError(); |
| 3784 | } |
| 3785 | |
| 3786 | ExprResult DimExpr = ParseExpression(); |
| 3787 | T.consumeClose(); |
| 3788 | |
| 3789 | return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(), |
| 3790 | T.getCloseLocation()); |
| 3791 | } |
| 3792 | } |
| 3793 | llvm_unreachable("Invalid ArrayTypeTrait!"); |
| 3794 | } |
| 3795 | |
| 3796 | |
| 3797 | |
| 3798 | |
| 3799 | |
| 3800 | |
| 3801 | |
| 3802 | ExprResult Parser::ParseExpressionTrait() { |
| 3803 | ExpressionTrait ET = ExpressionTraitFromTokKind(Tok.getKind()); |
| 3804 | SourceLocation Loc = ConsumeToken(); |
| 3805 | |
| 3806 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3807 | if (T.expectAndConsume()) |
| 3808 | return ExprError(); |
| 3809 | |
| 3810 | ExprResult Expr = ParseExpression(); |
| 3811 | |
| 3812 | T.consumeClose(); |
| 3813 | |
| 3814 | return Actions.ActOnExpressionTrait(ET, Loc, Expr.get(), |
| 3815 | T.getCloseLocation()); |
| 3816 | } |
| 3817 | |
| 3818 | |
| 3819 | |
| 3820 | |
| 3821 | |
| 3822 | ExprResult |
| 3823 | Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, |
| 3824 | ParsedType &CastTy, |
| 3825 | BalancedDelimiterTracker &Tracker, |
| 3826 | ColonProtectionRAIIObject &ColonProt) { |
| 3827 | assert(getLangOpts().CPlusPlus && "Should only be called for C++!"); |
| 3828 | assert(ExprType == CastExpr && "Compound literals are not ambiguous!"); |
| 3829 | assert(isTypeIdInParens() && "Not a type-id!"); |
| 3830 | |
| 3831 | ExprResult Result(true); |
| 3832 | CastTy = nullptr; |
| 3833 | |
| 3834 | |
| 3835 | |
| 3836 | |
| 3837 | |
| 3838 | |
| 3839 | |
| 3840 | |
| 3841 | |
| 3842 | |
| 3843 | |
| 3844 | |
| 3845 | |
| 3846 | |
| 3847 | |
| 3848 | |
| 3849 | |
| 3850 | |
| 3851 | |
| 3852 | |
| 3853 | ParenParseOption ParseAs; |
| 3854 | CachedTokens Toks; |
| 3855 | |
| 3856 | |
| 3857 | |
| 3858 | if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) { |
| 3859 | |
| 3860 | Tracker.consumeClose(); |
| 3861 | return ExprError(); |
| 3862 | } |
| 3863 | |
| 3864 | if (Tok.is(tok::l_brace)) { |
| 3865 | ParseAs = CompoundLiteral; |
| 3866 | } else { |
| 3867 | bool NotCastExpr; |
| 3868 | if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) { |
| 3869 | NotCastExpr = true; |
| 3870 | } else { |
| 3871 | |
| 3872 | |
| 3873 | |
| 3874 | ColonProt.restore(); |
| 3875 | Result = ParseCastExpression(AnyCastExpr, |
| 3876 | false, |
| 3877 | NotCastExpr, |
| 3878 | |
| 3879 | IsTypeCast); |
| 3880 | } |
| 3881 | |
| 3882 | |
| 3883 | |
| 3884 | ParseAs = NotCastExpr ? SimpleExpr : CastExpr; |
| 3885 | } |
| 3886 | |
| 3887 | |
| 3888 | Token AttrEnd; |
| 3889 | AttrEnd.startToken(); |
| 3890 | AttrEnd.setKind(tok::eof); |
| 3891 | AttrEnd.setLocation(Tok.getLocation()); |
| 3892 | AttrEnd.setEofData(Toks.data()); |
| 3893 | Toks.push_back(AttrEnd); |
| 3894 | |
| 3895 | |
| 3896 | Toks.push_back(Tok); |
| 3897 | |
| 3898 | |
| 3899 | PP.EnterTokenStream(Toks, true, |
| 3900 | true); |
| 3901 | |
| 3902 | |
| 3903 | ConsumeAnyToken(); |
| 3904 | |
| 3905 | if (ParseAs >= CompoundLiteral) { |
| 3906 | |
| 3907 | DeclSpec DS(AttrFactory); |
| 3908 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); |
| 3909 | { |
| 3910 | ColonProtectionRAIIObject InnerColonProtection(*this); |
| 3911 | ParseSpecifierQualifierList(DS); |
| 3912 | ParseDeclarator(DeclaratorInfo); |
| 3913 | } |
| 3914 | |
| 3915 | |
| 3916 | Tracker.consumeClose(); |
| 3917 | ColonProt.restore(); |
| 3918 | |
| 3919 | |
| 3920 | assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData()); |
| 3921 | ConsumeAnyToken(); |
| 3922 | |
| 3923 | if (ParseAs == CompoundLiteral) { |
| 3924 | ExprType = CompoundLiteral; |
| 3925 | if (DeclaratorInfo.isInvalidType()) |
| 3926 | return ExprError(); |
| 3927 | |
| 3928 | TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 3929 | return ParseCompoundLiteralExpression(Ty.get(), |
| 3930 | Tracker.getOpenLocation(), |
| 3931 | Tracker.getCloseLocation()); |
| 3932 | } |
| 3933 | |
| 3934 | |
| 3935 | assert(ParseAs == CastExpr); |
| 3936 | |
| 3937 | if (DeclaratorInfo.isInvalidType()) |
| 3938 | return ExprError(); |
| 3939 | |
| 3940 | |
| 3941 | if (!Result.isInvalid()) |
| 3942 | Result = Actions.ActOnCastExpr(getCurScope(), Tracker.getOpenLocation(), |
| 3943 | DeclaratorInfo, CastTy, |
| 3944 | Tracker.getCloseLocation(), Result.get()); |
| 3945 | return Result; |
| 3946 | } |
| 3947 | |
| 3948 | |
| 3949 | assert(ParseAs == SimpleExpr); |
| 3950 | |
| 3951 | ExprType = SimpleExpr; |
| 3952 | Result = ParseExpression(); |
| 3953 | if (!Result.isInvalid() && Tok.is(tok::r_paren)) |
| 3954 | Result = Actions.ActOnParenExpr(Tracker.getOpenLocation(), |
| 3955 | Tok.getLocation(), Result.get()); |
| 3956 | |
| 3957 | |
| 3958 | if (Result.isInvalid()) { |
| 3959 | while (Tok.isNot(tok::eof)) |
| 3960 | ConsumeAnyToken(); |
| 3961 | assert(Tok.getEofData() == AttrEnd.getEofData()); |
| 3962 | ConsumeAnyToken(); |
| 3963 | return ExprError(); |
| 3964 | } |
| 3965 | |
| 3966 | Tracker.consumeClose(); |
| 3967 | |
| 3968 | assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData()); |
| 3969 | ConsumeAnyToken(); |
| 3970 | return Result; |
| 3971 | } |
| 3972 | |
| 3973 | |
| 3974 | ExprResult Parser::ParseBuiltinBitCast() { |
| 3975 | SourceLocation KWLoc = ConsumeToken(); |
| 3976 | |
| 3977 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3978 | if (T.expectAndConsume(diag::err_expected_lparen_after, "__builtin_bit_cast")) |
| 3979 | return ExprError(); |
| 3980 | |
| 3981 | |
| 3982 | DeclSpec DS(AttrFactory); |
| 3983 | ParseSpecifierQualifierList(DS); |
| 3984 | |
| 3985 | |
| 3986 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); |
| 3987 | ParseDeclarator(DeclaratorInfo); |
| 3988 | |
| 3989 | if (ExpectAndConsume(tok::comma)) { |
| 3990 | Diag(Tok.getLocation(), diag::err_expected) << tok::comma; |
| 3991 | SkipUntil(tok::r_paren, StopAtSemi); |
| 3992 | return ExprError(); |
| 3993 | } |
| 3994 | |
| 3995 | ExprResult Operand = ParseExpression(); |
| 3996 | |
| 3997 | if (T.consumeClose()) |
| 3998 | return ExprError(); |
| 3999 | |
| 4000 | if (Operand.isInvalid() || DeclaratorInfo.isInvalidType()) |
| 4001 | return ExprError(); |
| 4002 | |
| 4003 | return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand, |
| 4004 | T.getCloseLocation()); |
| 4005 | } |