| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #include "clang/Parse/Parser.h" |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/PrettyDeclStackTrace.h" |
| 16 | #include "clang/Basic/CharInfo.h" |
| 17 | #include "clang/Parse/ParseDiagnostic.h" |
| 18 | #include "clang/Parse/RAIIObjectsForParser.h" |
| 19 | #include "clang/Sema/DeclSpec.h" |
| 20 | #include "clang/Sema/Scope.h" |
| 21 | #include "llvm/ADT/SmallVector.h" |
| 22 | #include "llvm/ADT/StringExtras.h" |
| 23 | |
| 24 | using namespace clang; |
| 25 | |
| 26 | |
| 27 | void Parser::MaybeSkipAttributes(tok::ObjCKeywordKind Kind) { |
| 28 | ParsedAttributes attrs(AttrFactory); |
| 29 | if (Tok.is(tok::kw___attribute)) { |
| 30 | if (Kind == tok::objc_interface || Kind == tok::objc_protocol) |
| 31 | Diag(Tok, diag::err_objc_postfix_attribute_hint) |
| 32 | << (Kind == tok::objc_protocol); |
| 33 | else |
| 34 | Diag(Tok, diag::err_objc_postfix_attribute); |
| 35 | ParseGNUAttributes(attrs); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | Parser::DeclGroupPtrTy |
| 48 | Parser::ParseObjCAtDirectives(ParsedAttributesWithRange &Attrs) { |
| 49 | SourceLocation AtLoc = ConsumeToken(); |
| 50 | |
| 51 | if (Tok.is(tok::code_completion)) { |
| 52 | Actions.CodeCompleteObjCAtDirective(getCurScope()); |
| 53 | cutOffParsing(); |
| 54 | return nullptr; |
| 55 | } |
| 56 | |
| 57 | Decl *SingleDecl = nullptr; |
| 58 | switch (Tok.getObjCKeywordID()) { |
| 59 | case tok::objc_class: |
| 60 | return ParseObjCAtClassDeclaration(AtLoc); |
| 61 | case tok::objc_interface: |
| 62 | SingleDecl = ParseObjCAtInterfaceDeclaration(AtLoc, Attrs); |
| 63 | break; |
| 64 | case tok::objc_protocol: |
| 65 | return ParseObjCAtProtocolDeclaration(AtLoc, Attrs); |
| 66 | case tok::objc_implementation: |
| 67 | return ParseObjCAtImplementationDeclaration(AtLoc); |
| 68 | case tok::objc_end: |
| 69 | return ParseObjCAtEndDeclaration(AtLoc); |
| 70 | case tok::objc_compatibility_alias: |
| 71 | SingleDecl = ParseObjCAtAliasDeclaration(AtLoc); |
| 72 | break; |
| 73 | case tok::objc_synthesize: |
| 74 | SingleDecl = ParseObjCPropertySynthesize(AtLoc); |
| 75 | break; |
| 76 | case tok::objc_dynamic: |
| 77 | SingleDecl = ParseObjCPropertyDynamic(AtLoc); |
| 78 | break; |
| 79 | case tok::objc_import: |
| 80 | if (getLangOpts().Modules || getLangOpts().DebuggerSupport) { |
| 81 | SingleDecl = ParseModuleImport(AtLoc); |
| 82 | break; |
| 83 | } |
| 84 | Diag(AtLoc, diag::err_atimport); |
| 85 | SkipUntil(tok::semi); |
| 86 | return Actions.ConvertDeclToDeclGroup(nullptr); |
| 87 | default: |
| 88 | Diag(AtLoc, diag::err_unexpected_at); |
| 89 | SkipUntil(tok::semi); |
| 90 | SingleDecl = nullptr; |
| 91 | break; |
| 92 | } |
| 93 | return Actions.ConvertDeclToDeclGroup(SingleDecl); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | class Parser::ObjCTypeParamListScope { |
| 98 | Sema &Actions; |
| 99 | Scope *S; |
| 100 | ObjCTypeParamList *Params; |
| 101 | |
| 102 | public: |
| 103 | ObjCTypeParamListScope(Sema &Actions, Scope *S) |
| 104 | : Actions(Actions), S(S), Params(nullptr) {} |
| 105 | |
| 106 | ~ObjCTypeParamListScope() { |
| 107 | leave(); |
| 108 | } |
| 109 | |
| 110 | void enter(ObjCTypeParamList *P) { |
| 111 | assert(!Params); |
| 112 | Params = P; |
| 113 | } |
| 114 | |
| 115 | void leave() { |
| 116 | if (Params) |
| 117 | Actions.popObjCTypeParamList(S, Params); |
| 118 | Params = nullptr; |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | Parser::DeclGroupPtrTy |
| 130 | Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { |
| 131 | ConsumeToken(); |
| 132 | SmallVector<IdentifierInfo *, 8> ClassNames; |
| 133 | SmallVector<SourceLocation, 8> ClassLocs; |
| 134 | SmallVector<ObjCTypeParamList *, 8> ClassTypeParams; |
| 135 | |
| 136 | while (1) { |
| 137 | MaybeSkipAttributes(tok::objc_class); |
| 138 | if (expectIdentifier()) { |
| 139 | SkipUntil(tok::semi); |
| 140 | return Actions.ConvertDeclToDeclGroup(nullptr); |
| 141 | } |
| 142 | ClassNames.push_back(Tok.getIdentifierInfo()); |
| 143 | ClassLocs.push_back(Tok.getLocation()); |
| 144 | ConsumeToken(); |
| 145 | |
| 146 | |
| 147 | ObjCTypeParamList *TypeParams = nullptr; |
| 148 | if (Tok.is(tok::less)) |
| 149 | TypeParams = parseObjCTypeParamList(); |
| 150 | ClassTypeParams.push_back(TypeParams); |
| 151 | if (!TryConsumeToken(tok::comma)) |
| 152 | break; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | if (ExpectAndConsume(tok::semi, diag::err_expected_after, "@class")) |
| 157 | return Actions.ConvertDeclToDeclGroup(nullptr); |
| 158 | |
| 159 | return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), |
| 160 | ClassLocs.data(), |
| 161 | ClassTypeParams, |
| 162 | ClassNames.size()); |
| 163 | } |
| 164 | |
| 165 | void Parser::CheckNestedObjCContexts(SourceLocation AtLoc) |
| 166 | { |
| 167 | Sema::ObjCContainerKind ock = Actions.getObjCContainerKind(); |
| 168 | if (ock == Sema::OCK_None) |
| 169 | return; |
| 170 | |
| 171 | Decl *Decl = Actions.getObjCDeclContext(); |
| 172 | if (CurParsedObjCImpl) { |
| 173 | CurParsedObjCImpl->finish(AtLoc); |
| 174 | } else { |
| 175 | Actions.ActOnAtEnd(getCurScope(), AtLoc); |
| 176 | } |
| 177 | Diag(AtLoc, diag::err_objc_missing_end) |
| 178 | << FixItHint::CreateInsertion(AtLoc, "@end\n"); |
| 179 | if (Decl) |
| 180 | Diag(Decl->getBeginLoc(), diag::note_objc_container_start) << (int)ock; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, |
| 213 | ParsedAttributes &attrs) { |
| 214 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_interface) && \"ParseObjCAtInterfaceDeclaration(). Expected @interface\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 215, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isObjCAtKeyword(tok::objc_interface) && |
| 215 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_interface) && \"ParseObjCAtInterfaceDeclaration(). Expected @interface\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 215, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "ParseObjCAtInterfaceDeclaration(): Expected @interface"); |
| 216 | CheckNestedObjCContexts(AtLoc); |
| 217 | ConsumeToken(); |
| 218 | |
| 219 | |
| 220 | if (Tok.is(tok::code_completion)) { |
| 221 | Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); |
| 222 | cutOffParsing(); |
| 223 | return nullptr; |
| 224 | } |
| 225 | |
| 226 | MaybeSkipAttributes(tok::objc_interface); |
| 227 | |
| 228 | if (expectIdentifier()) |
| 229 | return nullptr; |
| 230 | |
| 231 | |
| 232 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
| 233 | SourceLocation nameLoc = ConsumeToken(); |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | SourceLocation LAngleLoc, EndProtoLoc; |
| 239 | SmallVector<IdentifierLocPair, 8> ProtocolIdents; |
| 240 | ObjCTypeParamList *typeParameterList = nullptr; |
| 241 | ObjCTypeParamListScope typeParamScope(Actions, getCurScope()); |
| 242 | if (Tok.is(tok::less)) |
| 243 | typeParameterList = parseObjCTypeParamListOrProtocolRefs( |
| 244 | typeParamScope, LAngleLoc, ProtocolIdents, EndProtoLoc); |
| 245 | |
| 246 | if (Tok.is(tok::l_paren) && |
| 247 | !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { |
| 248 | |
| 249 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 250 | T.consumeOpen(); |
| 251 | |
| 252 | SourceLocation categoryLoc; |
| 253 | IdentifierInfo *categoryId = nullptr; |
| 254 | if (Tok.is(tok::code_completion)) { |
| 255 | Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); |
| 256 | cutOffParsing(); |
| 257 | return nullptr; |
| 258 | } |
| 259 | |
| 260 | |
| 261 | if (Tok.is(tok::identifier)) { |
| 262 | categoryId = Tok.getIdentifierInfo(); |
| 263 | categoryLoc = ConsumeToken(); |
| 264 | } |
| 265 | else if (!getLangOpts().ObjC) { |
| 266 | Diag(Tok, diag::err_expected) |
| 267 | << tok::identifier; |
| 268 | return nullptr; |
| 269 | } |
| 270 | |
| 271 | T.consumeClose(); |
| 272 | if (T.getCloseLocation().isInvalid()) |
| 273 | return nullptr; |
| 274 | |
| 275 | |
| 276 | (0) . __assert_fail ("LAngleLoc.isInvalid() && \"Cannot have already parsed protocols\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 276, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(LAngleLoc.isInvalid() && "Cannot have already parsed protocols"); |
| 277 | SmallVector<Decl *, 8> ProtocolRefs; |
| 278 | SmallVector<SourceLocation, 8> ProtocolLocs; |
| 279 | if (Tok.is(tok::less) && |
| 280 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, true, |
| 281 | LAngleLoc, EndProtoLoc, |
| 282 | )) |
| 283 | return nullptr; |
| 284 | |
| 285 | Decl *CategoryType = Actions.ActOnStartCategoryInterface( |
| 286 | AtLoc, nameId, nameLoc, typeParameterList, categoryId, categoryLoc, |
| 287 | ProtocolRefs.data(), ProtocolRefs.size(), ProtocolLocs.data(), |
| 288 | EndProtoLoc, attrs); |
| 289 | |
| 290 | if (Tok.is(tok::l_brace)) |
| 291 | ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, AtLoc); |
| 292 | |
| 293 | ParseObjCInterfaceDeclList(tok::objc_not_keyword, CategoryType); |
| 294 | |
| 295 | return CategoryType; |
| 296 | } |
| 297 | |
| 298 | IdentifierInfo *superClassId = nullptr; |
| 299 | SourceLocation superClassLoc; |
| 300 | SourceLocation typeArgsLAngleLoc; |
| 301 | SmallVector<ParsedType, 4> typeArgs; |
| 302 | SourceLocation typeArgsRAngleLoc; |
| 303 | SmallVector<Decl *, 4> protocols; |
| 304 | SmallVector<SourceLocation, 4> protocolLocs; |
| 305 | if (Tok.is(tok::colon)) { |
| 306 | ConsumeToken(); |
| 307 | |
| 308 | |
| 309 | if (Tok.is(tok::code_completion)) { |
| 310 | Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); |
| 311 | cutOffParsing(); |
| 312 | return nullptr; |
| 313 | } |
| 314 | |
| 315 | if (expectIdentifier()) |
| 316 | return nullptr; |
| 317 | superClassId = Tok.getIdentifierInfo(); |
| 318 | superClassLoc = ConsumeToken(); |
| 319 | |
| 320 | |
| 321 | if (Tok.is(tok::less)) { |
| 322 | parseObjCTypeArgsOrProtocolQualifiers( |
| 323 | nullptr, typeArgsLAngleLoc, typeArgs, typeArgsRAngleLoc, LAngleLoc, |
| 324 | protocols, protocolLocs, EndProtoLoc, |
| 325 | , |
| 326 | ); |
| 327 | if (Tok.is(tok::eof)) |
| 328 | return nullptr; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | |
| 333 | if (LAngleLoc.isValid()) { |
| 334 | if (!ProtocolIdents.empty()) { |
| 335 | |
| 336 | |
| 337 | for (const auto &pair : ProtocolIdents) { |
| 338 | protocolLocs.push_back(pair.second); |
| 339 | } |
| 340 | Actions.FindProtocolDeclaration(, |
| 341 | , |
| 342 | ProtocolIdents, protocols); |
| 343 | } |
| 344 | } else if (protocols.empty() && Tok.is(tok::less) && |
| 345 | ParseObjCProtocolReferences(protocols, protocolLocs, true, true, |
| 346 | LAngleLoc, EndProtoLoc, |
| 347 | )) { |
| 348 | return nullptr; |
| 349 | } |
| 350 | |
| 351 | if (Tok.isNot(tok::less)) |
| 352 | Actions.ActOnTypedefedProtocols(protocols, protocolLocs, |
| 353 | superClassId, superClassLoc); |
| 354 | |
| 355 | Decl *ClsType = Actions.ActOnStartClassInterface( |
| 356 | getCurScope(), AtLoc, nameId, nameLoc, typeParameterList, superClassId, |
| 357 | superClassLoc, typeArgs, |
| 358 | SourceRange(typeArgsLAngleLoc, typeArgsRAngleLoc), protocols.data(), |
| 359 | protocols.size(), protocolLocs.data(), EndProtoLoc, attrs); |
| 360 | |
| 361 | if (Tok.is(tok::l_brace)) |
| 362 | ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, AtLoc); |
| 363 | |
| 364 | ParseObjCInterfaceDeclList(tok::objc_interface, ClsType); |
| 365 | |
| 366 | return ClsType; |
| 367 | } |
| 368 | |
| 369 | |
| 370 | |
| 371 | static void addContextSensitiveTypeNullability(Parser &P, |
| 372 | Declarator &D, |
| 373 | NullabilityKind nullability, |
| 374 | SourceLocation nullabilityLoc, |
| 375 | bool &addedToDeclSpec) { |
| 376 | |
| 377 | auto getNullabilityAttr = [&](AttributePool &Pool) -> ParsedAttr * { |
| 378 | return Pool.create(P.getNullabilityKeyword(nullability), |
| 379 | SourceRange(nullabilityLoc), nullptr, SourceLocation(), |
| 380 | nullptr, 0, ParsedAttr::AS_ContextSensitiveKeyword); |
| 381 | }; |
| 382 | |
| 383 | if (D.getNumTypeObjects() > 0) { |
| 384 | |
| 385 | D.getTypeObject(0).getAttrs().addAtEnd( |
| 386 | getNullabilityAttr(D.getAttributePool())); |
| 387 | } else if (!addedToDeclSpec) { |
| 388 | |
| 389 | |
| 390 | D.getMutableDeclSpec().getAttributes().addAtEnd( |
| 391 | getNullabilityAttr(D.getMutableDeclSpec().getAttributes().getPool())); |
| 392 | addedToDeclSpec = true; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs( |
| 421 | ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc, |
| 422 | SmallVectorImpl<IdentifierLocPair> &protocolIdents, |
| 423 | SourceLocation &rAngleLoc, bool mayBeProtocolList) { |
| 424 | (0) . __assert_fail ("Tok.is(tok..less) && \"Not at the beginning of a type parameter list\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 424, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::less) && "Not at the beginning of a type parameter list"); |
| 425 | |
| 426 | |
| 427 | GreaterThanIsOperatorScope G(GreaterThanIsOperator, false); |
| 428 | |
| 429 | |
| 430 | |
| 431 | SmallVector<Decl *, 4> typeParams; |
| 432 | auto makeProtocolIdentsIntoTypeParameters = [&]() { |
| 433 | unsigned index = 0; |
| 434 | for (const auto &pair : protocolIdents) { |
| 435 | DeclResult typeParam = Actions.actOnObjCTypeParam( |
| 436 | getCurScope(), ObjCTypeParamVariance::Invariant, SourceLocation(), |
| 437 | index++, pair.first, pair.second, SourceLocation(), nullptr); |
| 438 | if (typeParam.isUsable()) |
| 439 | typeParams.push_back(typeParam.get()); |
| 440 | } |
| 441 | |
| 442 | protocolIdents.clear(); |
| 443 | mayBeProtocolList = false; |
| 444 | }; |
| 445 | |
| 446 | bool invalid = false; |
| 447 | lAngleLoc = ConsumeToken(); |
| 448 | |
| 449 | do { |
| 450 | |
| 451 | SourceLocation varianceLoc; |
| 452 | ObjCTypeParamVariance variance = ObjCTypeParamVariance::Invariant; |
| 453 | if (Tok.is(tok::kw___covariant) || Tok.is(tok::kw___contravariant)) { |
| 454 | variance = Tok.is(tok::kw___covariant) |
| 455 | ? ObjCTypeParamVariance::Covariant |
| 456 | : ObjCTypeParamVariance::Contravariant; |
| 457 | varianceLoc = ConsumeToken(); |
| 458 | |
| 459 | |
| 460 | |
| 461 | if (mayBeProtocolList) { |
| 462 | |
| 463 | |
| 464 | makeProtocolIdentsIntoTypeParameters(); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | |
| 469 | if (!Tok.is(tok::identifier)) { |
| 470 | |
| 471 | if (Tok.is(tok::code_completion)) { |
| 472 | |
| 473 | |
| 474 | Actions.CodeCompleteObjCProtocolReferences(protocolIdents); |
| 475 | cutOffParsing(); |
| 476 | |
| 477 | |
| 478 | return nullptr; |
| 479 | } |
| 480 | |
| 481 | Diag(Tok, diag::err_objc_expected_type_parameter); |
| 482 | invalid = true; |
| 483 | break; |
| 484 | } |
| 485 | |
| 486 | IdentifierInfo *paramName = Tok.getIdentifierInfo(); |
| 487 | SourceLocation paramLoc = ConsumeToken(); |
| 488 | |
| 489 | |
| 490 | SourceLocation colonLoc; |
| 491 | TypeResult boundType; |
| 492 | if (TryConsumeToken(tok::colon, colonLoc)) { |
| 493 | |
| 494 | |
| 495 | if (mayBeProtocolList) { |
| 496 | |
| 497 | |
| 498 | makeProtocolIdentsIntoTypeParameters(); |
| 499 | } |
| 500 | |
| 501 | |
| 502 | boundType = ParseTypeName(); |
| 503 | if (boundType.isInvalid()) |
| 504 | invalid = true; |
| 505 | } else if (mayBeProtocolList) { |
| 506 | |
| 507 | |
| 508 | protocolIdents.push_back(std::make_pair(paramName, paramLoc)); |
| 509 | continue; |
| 510 | } |
| 511 | |
| 512 | |
| 513 | DeclResult typeParam = Actions.actOnObjCTypeParam( |
| 514 | getCurScope(), variance, varianceLoc, typeParams.size(), paramName, |
| 515 | paramLoc, colonLoc, boundType.isUsable() ? boundType.get() : nullptr); |
| 516 | if (typeParam.isUsable()) |
| 517 | typeParams.push_back(typeParam.get()); |
| 518 | } while (TryConsumeToken(tok::comma)); |
| 519 | |
| 520 | |
| 521 | if (invalid) { |
| 522 | SkipUntil(tok::greater, tok::at, StopBeforeMatch); |
| 523 | if (Tok.is(tok::greater)) |
| 524 | ConsumeToken(); |
| 525 | } else if (ParseGreaterThanInTemplateList(rAngleLoc, |
| 526 | , |
| 527 | )) { |
| 528 | Diag(lAngleLoc, diag::note_matching) << "'<'"; |
| 529 | SkipUntil({tok::greater, tok::greaterequal, tok::at, tok::minus, |
| 530 | tok::minus, tok::plus, tok::colon, tok::l_paren, tok::l_brace, |
| 531 | tok::comma, tok::semi }, |
| 532 | StopBeforeMatch); |
| 533 | if (Tok.is(tok::greater)) |
| 534 | ConsumeToken(); |
| 535 | } |
| 536 | |
| 537 | if (mayBeProtocolList) { |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | if (Tok.isNot(tok::colon) && Tok.isNot(tok::l_paren)) { |
| 543 | |
| 544 | |
| 545 | |
| 546 | return nullptr; |
| 547 | } |
| 548 | |
| 549 | |
| 550 | |
| 551 | makeProtocolIdentsIntoTypeParameters(); |
| 552 | } |
| 553 | |
| 554 | |
| 555 | ObjCTypeParamList *list = Actions.actOnObjCTypeParamList( |
| 556 | getCurScope(), |
| 557 | lAngleLoc, |
| 558 | typeParams, |
| 559 | rAngleLoc); |
| 560 | Scope.enter(list); |
| 561 | |
| 562 | |
| 563 | |
| 564 | lAngleLoc = SourceLocation(); |
| 565 | rAngleLoc = SourceLocation(); |
| 566 | return invalid ? nullptr : list; |
| 567 | } |
| 568 | |
| 569 | |
| 570 | ObjCTypeParamList *Parser::parseObjCTypeParamList() { |
| 571 | SourceLocation lAngleLoc; |
| 572 | SmallVector<IdentifierLocPair, 1> protocolIdents; |
| 573 | SourceLocation rAngleLoc; |
| 574 | |
| 575 | ObjCTypeParamListScope Scope(Actions, getCurScope()); |
| 576 | return parseObjCTypeParamListOrProtocolRefs(Scope, lAngleLoc, protocolIdents, |
| 577 | rAngleLoc, |
| 578 | ); |
| 579 | } |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | void Parser::ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, |
| 594 | Decl *CDecl) { |
| 595 | SmallVector<Decl *, 32> allMethods; |
| 596 | SmallVector<DeclGroupPtrTy, 8> allTUVariables; |
| 597 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; |
| 598 | |
| 599 | SourceRange AtEnd; |
| 600 | |
| 601 | while (1) { |
| 602 | |
| 603 | if (Tok.isOneOf(tok::minus, tok::plus)) { |
| 604 | if (Decl *methodPrototype = |
| 605 | ParseObjCMethodPrototype(MethodImplKind, false)) |
| 606 | allMethods.push_back(methodPrototype); |
| 607 | |
| 608 | |
| 609 | if (ExpectAndConsumeSemi(diag::err_expected_semi_after_method_proto)) { |
| 610 | |
| 611 | SkipUntil(tok::at, StopAtSemi | StopBeforeMatch); |
| 612 | if (Tok.is(tok::semi)) |
| 613 | ConsumeToken(); |
| 614 | } |
| 615 | continue; |
| 616 | } |
| 617 | if (Tok.is(tok::l_paren)) { |
| 618 | Diag(Tok, diag::err_expected_minus_or_plus); |
| 619 | ParseObjCMethodDecl(Tok.getLocation(), |
| 620 | tok::minus, |
| 621 | MethodImplKind, false); |
| 622 | continue; |
| 623 | } |
| 624 | |
| 625 | if (Tok.is(tok::semi)) { |
| 626 | |
| 627 | |
| 628 | ConsumeToken(); |
| 629 | continue; |
| 630 | } |
| 631 | |
| 632 | |
| 633 | if (isEofOrEom()) |
| 634 | break; |
| 635 | |
| 636 | |
| 637 | if (Tok.is(tok::code_completion)) { |
| 638 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
| 639 | CurParsedObjCImpl? Sema::PCC_ObjCImplementation |
| 640 | : Sema::PCC_ObjCInterface); |
| 641 | return cutOffParsing(); |
| 642 | } |
| 643 | |
| 644 | |
| 645 | if (Tok.isNot(tok::at)) { |
| 646 | |
| 647 | |
| 648 | |
| 649 | if (Tok.is(tok::r_brace)) |
| 650 | break; |
| 651 | |
| 652 | ParsedAttributesWithRange attrs(AttrFactory); |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | if (Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) { |
| 658 | SourceLocation DeclEnd; |
| 659 | allTUVariables.push_back( |
| 660 | ParseDeclaration(DeclaratorContext::FileContext, DeclEnd, attrs)); |
| 661 | continue; |
| 662 | } |
| 663 | |
| 664 | allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(attrs)); |
| 665 | continue; |
| 666 | } |
| 667 | |
| 668 | |
| 669 | SourceLocation AtLoc = ConsumeToken(); |
| 670 | if (Tok.is(tok::code_completion)) { |
| 671 | Actions.CodeCompleteObjCAtDirective(getCurScope()); |
| 672 | return cutOffParsing(); |
| 673 | } |
| 674 | |
| 675 | tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); |
| 676 | |
| 677 | if (DirectiveKind == tok::objc_end) { |
| 678 | AtEnd.setBegin(AtLoc); |
| 679 | AtEnd.setEnd(Tok.getLocation()); |
| 680 | break; |
| 681 | } else if (DirectiveKind == tok::objc_not_keyword) { |
| 682 | Diag(Tok, diag::err_objc_unknown_at); |
| 683 | SkipUntil(tok::semi); |
| 684 | continue; |
| 685 | } |
| 686 | |
| 687 | |
| 688 | ConsumeToken(); |
| 689 | |
| 690 | switch (DirectiveKind) { |
| 691 | default: |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | Diag(AtLoc, diag::err_objc_illegal_interface_qual); |
| 697 | |
| 698 | SkipUntil(tok::r_brace, tok::at, StopAtSemi); |
| 699 | break; |
| 700 | |
| 701 | case tok::objc_implementation: |
| 702 | case tok::objc_interface: |
| 703 | Diag(AtLoc, diag::err_objc_missing_end) |
| 704 | << FixItHint::CreateInsertion(AtLoc, "@end\n"); |
| 705 | Diag(CDecl->getBeginLoc(), diag::note_objc_container_start) |
| 706 | << (int)Actions.getObjCContainerKind(); |
| 707 | ConsumeToken(); |
| 708 | break; |
| 709 | |
| 710 | case tok::objc_required: |
| 711 | case tok::objc_optional: |
| 712 | |
| 713 | |
| 714 | if (contextKey != tok::objc_protocol) |
| 715 | Diag(AtLoc, diag::err_objc_directive_only_in_protocol); |
| 716 | else |
| 717 | MethodImplKind = DirectiveKind; |
| 718 | break; |
| 719 | |
| 720 | case tok::objc_property: |
| 721 | if (!getLangOpts().ObjC) |
| 722 | Diag(AtLoc, diag::err_objc_properties_require_objc2); |
| 723 | |
| 724 | ObjCDeclSpec OCDS; |
| 725 | SourceLocation LParenLoc; |
| 726 | |
| 727 | if (Tok.is(tok::l_paren)) { |
| 728 | LParenLoc = Tok.getLocation(); |
| 729 | ParseObjCPropertyAttribute(OCDS); |
| 730 | } |
| 731 | |
| 732 | bool addedToDeclSpec = false; |
| 733 | auto ObjCPropertyCallback = [&](ParsingFieldDeclarator &FD) { |
| 734 | if (FD.D.getIdentifier() == nullptr) { |
| 735 | Diag(AtLoc, diag::err_objc_property_requires_field_name) |
| 736 | << FD.D.getSourceRange(); |
| 737 | return; |
| 738 | } |
| 739 | if (FD.BitfieldSize) { |
| 740 | Diag(AtLoc, diag::err_objc_property_bitfield) |
| 741 | << FD.D.getSourceRange(); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | |
| 746 | |
| 747 | if (OCDS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nullability) |
| 748 | addContextSensitiveTypeNullability(*this, FD.D, OCDS.getNullability(), |
| 749 | OCDS.getNullabilityLoc(), |
| 750 | addedToDeclSpec); |
| 751 | |
| 752 | |
| 753 | IdentifierInfo *SelName = |
| 754 | OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); |
| 755 | |
| 756 | Selector GetterSel = PP.getSelectorTable().getNullarySelector(SelName); |
| 757 | IdentifierInfo *SetterName = OCDS.getSetterName(); |
| 758 | Selector SetterSel; |
| 759 | if (SetterName) |
| 760 | SetterSel = PP.getSelectorTable().getSelector(1, &SetterName); |
| 761 | else |
| 762 | SetterSel = SelectorTable::constructSetterSelector( |
| 763 | PP.getIdentifierTable(), PP.getSelectorTable(), |
| 764 | FD.D.getIdentifier()); |
| 765 | Decl *Property = Actions.ActOnProperty( |
| 766 | getCurScope(), AtLoc, LParenLoc, FD, OCDS, GetterSel, SetterSel, |
| 767 | MethodImplKind); |
| 768 | |
| 769 | FD.complete(Property); |
| 770 | }; |
| 771 | |
| 772 | |
| 773 | ParsingDeclSpec DS(*this); |
| 774 | ParseStructDeclaration(DS, ObjCPropertyCallback); |
| 775 | |
| 776 | ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list); |
| 777 | break; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | |
| 782 | |
| 783 | if (Tok.is(tok::code_completion)) { |
| 784 | Actions.CodeCompleteObjCAtDirective(getCurScope()); |
| 785 | return cutOffParsing(); |
| 786 | } else if (Tok.isObjCAtKeyword(tok::objc_end)) { |
| 787 | ConsumeToken(); |
| 788 | } else { |
| 789 | Diag(Tok, diag::err_objc_missing_end) |
| 790 | << FixItHint::CreateInsertion(Tok.getLocation(), "\n@end\n"); |
| 791 | Diag(CDecl->getBeginLoc(), diag::note_objc_container_start) |
| 792 | << (int)Actions.getObjCContainerKind(); |
| 793 | AtEnd.setBegin(Tok.getLocation()); |
| 794 | AtEnd.setEnd(Tok.getLocation()); |
| 795 | } |
| 796 | |
| 797 | |
| 798 | |
| 799 | Actions.ActOnAtEnd(getCurScope(), AtEnd, allMethods, allTUVariables); |
| 800 | } |
| 801 | |
| 802 | |
| 803 | static void diagnoseRedundantPropertyNullability(Parser &P, |
| 804 | ObjCDeclSpec &DS, |
| 805 | NullabilityKind nullability, |
| 806 | SourceLocation nullabilityLoc){ |
| 807 | if (DS.getNullability() == nullability) { |
| 808 | P.Diag(nullabilityLoc, diag::warn_nullability_duplicate) |
| 809 | << DiagNullabilityKind(nullability, true) |
| 810 | << SourceRange(DS.getNullabilityLoc()); |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | P.Diag(nullabilityLoc, diag::err_nullability_conflicting) |
| 815 | << DiagNullabilityKind(nullability, true) |
| 816 | << DiagNullabilityKind(DS.getNullability(), true) |
| 817 | << SourceRange(DS.getNullabilityLoc()); |
| 818 | } |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { |
| 846 | assert(Tok.getKind() == tok::l_paren); |
| 847 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 848 | T.consumeOpen(); |
| 849 | |
| 850 | while (1) { |
| 851 | if (Tok.is(tok::code_completion)) { |
| 852 | Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); |
| 853 | return cutOffParsing(); |
| 854 | } |
| 855 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 856 | |
| 857 | |
| 858 | if (!II) { |
| 859 | T.consumeClose(); |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | SourceLocation AttrName = ConsumeToken(); |
| 864 | |
| 865 | if (II->isStr("readonly")) |
| 866 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); |
| 867 | else if (II->isStr("assign")) |
| 868 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); |
| 869 | else if (II->isStr("unsafe_unretained")) |
| 870 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_unsafe_unretained); |
| 871 | else if (II->isStr("readwrite")) |
| 872 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); |
| 873 | else if (II->isStr("retain")) |
| 874 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); |
| 875 | else if (II->isStr("strong")) |
| 876 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_strong); |
| 877 | else if (II->isStr("copy")) |
| 878 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); |
| 879 | else if (II->isStr("nonatomic")) |
| 880 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); |
| 881 | else if (II->isStr("atomic")) |
| 882 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_atomic); |
| 883 | else if (II->isStr("weak")) |
| 884 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_weak); |
| 885 | else if (II->isStr("getter") || II->isStr("setter")) { |
| 886 | bool IsSetter = II->getNameStart()[0] == 's'; |
| 887 | |
| 888 | |
| 889 | unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter : |
| 890 | diag::err_objc_expected_equal_for_getter; |
| 891 | |
| 892 | if (ExpectAndConsume(tok::equal, DiagID)) { |
| 893 | SkipUntil(tok::r_paren, StopAtSemi); |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | if (Tok.is(tok::code_completion)) { |
| 898 | if (IsSetter) |
| 899 | Actions.CodeCompleteObjCPropertySetter(getCurScope()); |
| 900 | else |
| 901 | Actions.CodeCompleteObjCPropertyGetter(getCurScope()); |
| 902 | return cutOffParsing(); |
| 903 | } |
| 904 | |
| 905 | SourceLocation SelLoc; |
| 906 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(SelLoc); |
| 907 | |
| 908 | if (!SelIdent) { |
| 909 | Diag(Tok, diag::err_objc_expected_selector_for_getter_setter) |
| 910 | << IsSetter; |
| 911 | SkipUntil(tok::r_paren, StopAtSemi); |
| 912 | return; |
| 913 | } |
| 914 | |
| 915 | if (IsSetter) { |
| 916 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); |
| 917 | DS.setSetterName(SelIdent, SelLoc); |
| 918 | |
| 919 | if (ExpectAndConsume(tok::colon, |
| 920 | diag::err_expected_colon_after_setter_name)) { |
| 921 | SkipUntil(tok::r_paren, StopAtSemi); |
| 922 | return; |
| 923 | } |
| 924 | } else { |
| 925 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); |
| 926 | DS.setGetterName(SelIdent, SelLoc); |
| 927 | } |
| 928 | } else if (II->isStr("nonnull")) { |
| 929 | if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nullability) |
| 930 | diagnoseRedundantPropertyNullability(*this, DS, |
| 931 | NullabilityKind::NonNull, |
| 932 | Tok.getLocation()); |
| 933 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nullability); |
| 934 | DS.setNullability(Tok.getLocation(), NullabilityKind::NonNull); |
| 935 | } else if (II->isStr("nullable")) { |
| 936 | if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nullability) |
| 937 | diagnoseRedundantPropertyNullability(*this, DS, |
| 938 | NullabilityKind::Nullable, |
| 939 | Tok.getLocation()); |
| 940 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nullability); |
| 941 | DS.setNullability(Tok.getLocation(), NullabilityKind::Nullable); |
| 942 | } else if (II->isStr("null_unspecified")) { |
| 943 | if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nullability) |
| 944 | diagnoseRedundantPropertyNullability(*this, DS, |
| 945 | NullabilityKind::Unspecified, |
| 946 | Tok.getLocation()); |
| 947 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nullability); |
| 948 | DS.setNullability(Tok.getLocation(), NullabilityKind::Unspecified); |
| 949 | } else if (II->isStr("null_resettable")) { |
| 950 | if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nullability) |
| 951 | diagnoseRedundantPropertyNullability(*this, DS, |
| 952 | NullabilityKind::Unspecified, |
| 953 | Tok.getLocation()); |
| 954 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nullability); |
| 955 | DS.setNullability(Tok.getLocation(), NullabilityKind::Unspecified); |
| 956 | |
| 957 | |
| 958 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_null_resettable); |
| 959 | } else if (II->isStr("class")) { |
| 960 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_class); |
| 961 | } else { |
| 962 | Diag(AttrName, diag::err_objc_expected_property_attr) << II; |
| 963 | SkipUntil(tok::r_paren, StopAtSemi); |
| 964 | return; |
| 965 | } |
| 966 | |
| 967 | if (Tok.isNot(tok::comma)) |
| 968 | break; |
| 969 | |
| 970 | ConsumeToken(); |
| 971 | } |
| 972 | |
| 973 | T.consumeClose(); |
| 974 | } |
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | Decl *Parser::ParseObjCMethodPrototype(tok::ObjCKeywordKind MethodImplKind, |
| 987 | bool MethodDefinition) { |
| 988 | (0) . __assert_fail ("Tok.isOneOf(tok..minus, tok..plus) && \"expected +/-\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 988, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::minus, tok::plus) && "expected +/-"); |
| 989 | |
| 990 | tok::TokenKind methodType = Tok.getKind(); |
| 991 | SourceLocation mLoc = ConsumeToken(); |
| 992 | Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind, |
| 993 | MethodDefinition); |
| 994 | |
| 995 | |
| 996 | return MDecl; |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | |
| 1006 | |
| 1007 | IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { |
| 1008 | |
| 1009 | switch (Tok.getKind()) { |
| 1010 | default: |
| 1011 | return nullptr; |
| 1012 | case tok::colon: |
| 1013 | |
| 1014 | SelectorLoc = Tok.getLocation(); |
| 1015 | return nullptr; |
| 1016 | case tok::ampamp: |
| 1017 | case tok::ampequal: |
| 1018 | case tok::amp: |
| 1019 | case tok::pipe: |
| 1020 | case tok::tilde: |
| 1021 | case tok::exclaim: |
| 1022 | case tok::exclaimequal: |
| 1023 | case tok::pipepipe: |
| 1024 | case tok::pipeequal: |
| 1025 | case tok::caret: |
| 1026 | case tok::caretequal: { |
| 1027 | std::string ThisTok(PP.getSpelling(Tok)); |
| 1028 | if (isLetter(ThisTok[0])) { |
| 1029 | IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok); |
| 1030 | Tok.setKind(tok::identifier); |
| 1031 | SelectorLoc = ConsumeToken(); |
| 1032 | return II; |
| 1033 | } |
| 1034 | return nullptr; |
| 1035 | } |
| 1036 | |
| 1037 | case tok::identifier: |
| 1038 | case tok::kw_asm: |
| 1039 | case tok::kw_auto: |
| 1040 | case tok::kw_bool: |
| 1041 | case tok::kw_break: |
| 1042 | case tok::kw_case: |
| 1043 | case tok::kw_catch: |
| 1044 | case tok::kw_char: |
| 1045 | case tok::kw_class: |
| 1046 | case tok::kw_const: |
| 1047 | case tok::kw_const_cast: |
| 1048 | case tok::kw_continue: |
| 1049 | case tok::kw_default: |
| 1050 | case tok::kw_delete: |
| 1051 | case tok::kw_do: |
| 1052 | case tok::kw_double: |
| 1053 | case tok::kw_dynamic_cast: |
| 1054 | case tok::kw_else: |
| 1055 | case tok::kw_enum: |
| 1056 | case tok::kw_explicit: |
| 1057 | case tok::kw_export: |
| 1058 | case tok::kw_extern: |
| 1059 | case tok::kw_false: |
| 1060 | case tok::kw_float: |
| 1061 | case tok::kw_for: |
| 1062 | case tok::kw_friend: |
| 1063 | case tok::kw_goto: |
| 1064 | case tok::kw_if: |
| 1065 | case tok::kw_inline: |
| 1066 | case tok::kw_int: |
| 1067 | case tok::kw_long: |
| 1068 | case tok::kw_mutable: |
| 1069 | case tok::kw_namespace: |
| 1070 | case tok::kw_new: |
| 1071 | case tok::kw_operator: |
| 1072 | case tok::kw_private: |
| 1073 | case tok::kw_protected: |
| 1074 | case tok::kw_public: |
| 1075 | case tok::kw_register: |
| 1076 | case tok::kw_reinterpret_cast: |
| 1077 | case tok::kw_restrict: |
| 1078 | case tok::kw_return: |
| 1079 | case tok::kw_short: |
| 1080 | case tok::kw_signed: |
| 1081 | case tok::kw_sizeof: |
| 1082 | case tok::kw_static: |
| 1083 | case tok::kw_static_cast: |
| 1084 | case tok::kw_struct: |
| 1085 | case tok::kw_switch: |
| 1086 | case tok::kw_template: |
| 1087 | case tok::kw_this: |
| 1088 | case tok::kw_throw: |
| 1089 | case tok::kw_true: |
| 1090 | case tok::kw_try: |
| 1091 | case tok::kw_typedef: |
| 1092 | case tok::kw_typeid: |
| 1093 | case tok::kw_typename: |
| 1094 | case tok::kw_typeof: |
| 1095 | case tok::kw_union: |
| 1096 | case tok::kw_unsigned: |
| 1097 | case tok::kw_using: |
| 1098 | case tok::kw_virtual: |
| 1099 | case tok::kw_void: |
| 1100 | case tok::kw_volatile: |
| 1101 | case tok::kw_wchar_t: |
| 1102 | case tok::kw_while: |
| 1103 | case tok::kw__Bool: |
| 1104 | case tok::kw__Complex: |
| 1105 | case tok::kw___alignof: |
| 1106 | case tok::kw___auto_type: |
| 1107 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1108 | SelectorLoc = ConsumeToken(); |
| 1109 | return II; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | |
| 1115 | bool Parser::isTokIdentifier_in() const { |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | return (getLangOpts().ObjC && Tok.is(tok::identifier) && |
| 1120 | Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); |
| 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, |
| 1143 | DeclaratorContext Context) { |
| 1144 | assert(Context == DeclaratorContext::ObjCParameterContext || |
| 1145 | Context == DeclaratorContext::ObjCResultContext); |
| 1146 | |
| 1147 | while (1) { |
| 1148 | if (Tok.is(tok::code_completion)) { |
| 1149 | Actions.CodeCompleteObjCPassingType(getCurScope(), DS, |
| 1150 | Context == DeclaratorContext::ObjCParameterContext); |
| 1151 | return cutOffParsing(); |
| 1152 | } |
| 1153 | |
| 1154 | if (Tok.isNot(tok::identifier)) |
| 1155 | return; |
| 1156 | |
| 1157 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1158 | for (unsigned i = 0; i != objc_NumQuals; ++i) { |
| 1159 | if (II != ObjCTypeQuals[i] || |
| 1160 | NextToken().is(tok::less) || |
| 1161 | NextToken().is(tok::coloncolon)) |
| 1162 | continue; |
| 1163 | |
| 1164 | ObjCDeclSpec::ObjCDeclQualifier Qual; |
| 1165 | NullabilityKind Nullability; |
| 1166 | switch (i) { |
| 1167 | default: llvm_unreachable("Unknown decl qualifier"); |
| 1168 | case objc_in: Qual = ObjCDeclSpec::DQ_In; break; |
| 1169 | case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; |
| 1170 | case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; |
| 1171 | case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; |
| 1172 | case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; |
| 1173 | case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; |
| 1174 | |
| 1175 | case objc_nonnull: |
| 1176 | Qual = ObjCDeclSpec::DQ_CSNullability; |
| 1177 | Nullability = NullabilityKind::NonNull; |
| 1178 | break; |
| 1179 | |
| 1180 | case objc_nullable: |
| 1181 | Qual = ObjCDeclSpec::DQ_CSNullability; |
| 1182 | Nullability = NullabilityKind::Nullable; |
| 1183 | break; |
| 1184 | |
| 1185 | case objc_null_unspecified: |
| 1186 | Qual = ObjCDeclSpec::DQ_CSNullability; |
| 1187 | Nullability = NullabilityKind::Unspecified; |
| 1188 | break; |
| 1189 | } |
| 1190 | |
| 1191 | |
| 1192 | DS.setObjCDeclQualifier(Qual); |
| 1193 | if (Qual == ObjCDeclSpec::DQ_CSNullability) |
| 1194 | DS.setNullability(Tok.getLocation(), Nullability); |
| 1195 | |
| 1196 | ConsumeToken(); |
| 1197 | II = nullptr; |
| 1198 | break; |
| 1199 | } |
| 1200 | |
| 1201 | |
| 1202 | if (II) return; |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | static void takeDeclAttributes(ParsedAttributesView &attrs, |
| 1209 | ParsedAttributesView &from) { |
| 1210 | for (auto &AL : llvm::reverse(from)) { |
| 1211 | if (!AL.isUsedAsTypeAttr()) { |
| 1212 | from.remove(&AL); |
| 1213 | attrs.addAtEnd(&AL); |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | static void takeDeclAttributes(ParsedAttributes &attrs, |
| 1221 | Declarator &D) { |
| 1222 | |
| 1223 | attrs.getPool().takeAllFrom(D.getAttributePool()); |
| 1224 | attrs.getPool().takeAllFrom(D.getDeclSpec().getAttributePool()); |
| 1225 | |
| 1226 | |
| 1227 | takeDeclAttributes(attrs, D.getMutableDeclSpec().getAttributes()); |
| 1228 | takeDeclAttributes(attrs, D.getAttributes()); |
| 1229 | for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) |
| 1230 | takeDeclAttributes(attrs, D.getTypeObject(i).getAttrs()); |
| 1231 | } |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, |
| 1238 | DeclaratorContext context, |
| 1239 | ParsedAttributes *paramAttrs) { |
| 1240 | assert(context == DeclaratorContext::ObjCParameterContext || |
| 1241 | context == DeclaratorContext::ObjCResultContext); |
| 1242 | assert((paramAttrs != nullptr) == |
| 1243 | (context == DeclaratorContext::ObjCParameterContext)); |
| 1244 | |
| 1245 | (0) . __assert_fail ("Tok.is(tok..l_paren) && \"expected (\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 1245, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_paren) && "expected ("); |
| 1246 | |
| 1247 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1248 | T.consumeOpen(); |
| 1249 | |
| 1250 | SourceLocation TypeStartLoc = Tok.getLocation(); |
| 1251 | ObjCDeclContextSwitch ObjCDC(*this); |
| 1252 | |
| 1253 | |
| 1254 | ParseObjCTypeQualifierList(DS, context); |
| 1255 | |
| 1256 | ParsedType Ty; |
| 1257 | if (isTypeSpecifierQualifier() || isObjCInstancetype()) { |
| 1258 | |
| 1259 | DeclSpec declSpec(AttrFactory); |
| 1260 | declSpec.setObjCQualifiers(&DS); |
| 1261 | DeclSpecContext dsContext = DeclSpecContext::DSC_normal; |
| 1262 | if (context == DeclaratorContext::ObjCResultContext) |
| 1263 | dsContext = DeclSpecContext::DSC_objc_method_result; |
| 1264 | ParseSpecifierQualifierList(declSpec, AS_none, dsContext); |
| 1265 | Declarator declarator(declSpec, context); |
| 1266 | ParseDeclarator(declarator); |
| 1267 | |
| 1268 | |
| 1269 | if (!declarator.isInvalidType()) { |
| 1270 | |
| 1271 | bool addedToDeclSpec = false; |
| 1272 | if (DS.getObjCDeclQualifier() & ObjCDeclSpec::DQ_CSNullability) |
| 1273 | addContextSensitiveTypeNullability(*this, declarator, |
| 1274 | DS.getNullability(), |
| 1275 | DS.getNullabilityLoc(), |
| 1276 | addedToDeclSpec); |
| 1277 | |
| 1278 | TypeResult type = Actions.ActOnTypeName(getCurScope(), declarator); |
| 1279 | if (!type.isInvalid()) |
| 1280 | Ty = type.get(); |
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | if (context == DeclaratorContext::ObjCParameterContext) |
| 1285 | takeDeclAttributes(*paramAttrs, declarator); |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | if (Tok.is(tok::r_paren)) |
| 1290 | T.consumeClose(); |
| 1291 | else if (Tok.getLocation() == TypeStartLoc) { |
| 1292 | |
| 1293 | Diag(Tok, diag::err_expected_type); |
| 1294 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1295 | } else { |
| 1296 | |
| 1297 | |
| 1298 | T.consumeClose(); |
| 1299 | } |
| 1300 | return Ty; |
| 1301 | } |
| 1302 | |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | |
| 1330 | |
| 1331 | Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, |
| 1332 | tok::TokenKind mType, |
| 1333 | tok::ObjCKeywordKind MethodImplKind, |
| 1334 | bool MethodDefinition) { |
| 1335 | ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent); |
| 1336 | |
| 1337 | if (Tok.is(tok::code_completion)) { |
| 1338 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
| 1339 | ); |
| 1340 | cutOffParsing(); |
| 1341 | return nullptr; |
| 1342 | } |
| 1343 | |
| 1344 | |
| 1345 | ParsedType ReturnType; |
| 1346 | ObjCDeclSpec DSRet; |
| 1347 | if (Tok.is(tok::l_paren)) |
| 1348 | ReturnType = ParseObjCTypeName(DSRet, DeclaratorContext::ObjCResultContext, |
| 1349 | nullptr); |
| 1350 | |
| 1351 | |
| 1352 | ParsedAttributes methodAttrs(AttrFactory); |
| 1353 | if (getLangOpts().ObjC) |
| 1354 | MaybeParseGNUAttributes(methodAttrs); |
| 1355 | MaybeParseCXX11Attributes(methodAttrs); |
| 1356 | |
| 1357 | if (Tok.is(tok::code_completion)) { |
| 1358 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
| 1359 | ReturnType); |
| 1360 | cutOffParsing(); |
| 1361 | return nullptr; |
| 1362 | } |
| 1363 | |
| 1364 | |
| 1365 | SourceLocation selLoc; |
| 1366 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); |
| 1367 | |
| 1368 | |
| 1369 | if (!SelIdent && Tok.isNot(tok::colon)) { |
| 1370 | Diag(Tok, diag::err_expected_selector_for_method) |
| 1371 | << SourceRange(mLoc, Tok.getLocation()); |
| 1372 | |
| 1373 | SkipUntil(tok::at, StopAtSemi | StopBeforeMatch); |
| 1374 | return nullptr; |
| 1375 | } |
| 1376 | |
| 1377 | SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; |
| 1378 | if (Tok.isNot(tok::colon)) { |
| 1379 | |
| 1380 | if (getLangOpts().ObjC) |
| 1381 | MaybeParseGNUAttributes(methodAttrs); |
| 1382 | MaybeParseCXX11Attributes(methodAttrs); |
| 1383 | |
| 1384 | Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); |
| 1385 | Decl *Result = Actions.ActOnMethodDeclaration( |
| 1386 | getCurScope(), mLoc, Tok.getLocation(), mType, DSRet, ReturnType, |
| 1387 | selLoc, Sel, nullptr, CParamInfo.data(), CParamInfo.size(), methodAttrs, |
| 1388 | MethodImplKind, false, MethodDefinition); |
| 1389 | PD.complete(Result); |
| 1390 | return Result; |
| 1391 | } |
| 1392 | |
| 1393 | SmallVector<IdentifierInfo *, 12> KeyIdents; |
| 1394 | SmallVector<SourceLocation, 12> KeyLocs; |
| 1395 | SmallVector<Sema::ObjCArgInfo, 12> ArgInfos; |
| 1396 | ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope | |
| 1397 | Scope::FunctionDeclarationScope | Scope::DeclScope); |
| 1398 | |
| 1399 | AttributePool allParamAttrs(AttrFactory); |
| 1400 | while (1) { |
| 1401 | ParsedAttributes paramAttrs(AttrFactory); |
| 1402 | Sema::ObjCArgInfo ArgInfo; |
| 1403 | |
| 1404 | |
| 1405 | if (ExpectAndConsume(tok::colon)) |
| 1406 | break; |
| 1407 | |
| 1408 | ArgInfo.Type = nullptr; |
| 1409 | if (Tok.is(tok::l_paren)) |
| 1410 | ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, |
| 1411 | DeclaratorContext::ObjCParameterContext, |
| 1412 | ¶mAttrs); |
| 1413 | |
| 1414 | |
| 1415 | |
| 1416 | if (getLangOpts().ObjC) |
| 1417 | MaybeParseGNUAttributes(paramAttrs); |
| 1418 | MaybeParseCXX11Attributes(paramAttrs); |
| 1419 | ArgInfo.ArgAttrs = paramAttrs; |
| 1420 | |
| 1421 | |
| 1422 | if (Tok.is(tok::code_completion)) { |
| 1423 | KeyIdents.push_back(SelIdent); |
| 1424 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 1425 | mType == tok::minus, |
| 1426 | , |
| 1427 | ReturnType, KeyIdents); |
| 1428 | cutOffParsing(); |
| 1429 | return nullptr; |
| 1430 | } |
| 1431 | |
| 1432 | if (expectIdentifier()) |
| 1433 | break; |
| 1434 | |
| 1435 | ArgInfo.Name = Tok.getIdentifierInfo(); |
| 1436 | ArgInfo.NameLoc = Tok.getLocation(); |
| 1437 | ConsumeToken(); |
| 1438 | |
| 1439 | ArgInfos.push_back(ArgInfo); |
| 1440 | KeyIdents.push_back(SelIdent); |
| 1441 | KeyLocs.push_back(selLoc); |
| 1442 | |
| 1443 | |
| 1444 | allParamAttrs.takeAllFrom(paramAttrs.getPool()); |
| 1445 | |
| 1446 | |
| 1447 | if (Tok.is(tok::code_completion)) { |
| 1448 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 1449 | mType == tok::minus, |
| 1450 | , |
| 1451 | ReturnType, KeyIdents); |
| 1452 | cutOffParsing(); |
| 1453 | return nullptr; |
| 1454 | } |
| 1455 | |
| 1456 | |
| 1457 | SelIdent = ParseObjCSelectorPiece(selLoc); |
| 1458 | if (!SelIdent && Tok.isNot(tok::colon)) |
| 1459 | break; |
| 1460 | if (!SelIdent) { |
| 1461 | SourceLocation ColonLoc = Tok.getLocation(); |
| 1462 | if (PP.getLocForEndOfToken(ArgInfo.NameLoc) == ColonLoc) { |
| 1463 | Diag(ArgInfo.NameLoc, diag::warn_missing_selector_name) << ArgInfo.Name; |
| 1464 | Diag(ArgInfo.NameLoc, diag::note_missing_selector_name) << ArgInfo.Name; |
| 1465 | Diag(ColonLoc, diag::note_force_empty_selector_name) << ArgInfo.Name; |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | } |
| 1470 | |
| 1471 | bool isVariadic = false; |
| 1472 | bool cStyleParamWarned = false; |
| 1473 | |
| 1474 | while (Tok.is(tok::comma)) { |
| 1475 | ConsumeToken(); |
| 1476 | if (Tok.is(tok::ellipsis)) { |
| 1477 | isVariadic = true; |
| 1478 | ConsumeToken(); |
| 1479 | break; |
| 1480 | } |
| 1481 | if (!cStyleParamWarned) { |
| 1482 | Diag(Tok, diag::warn_cstyle_param); |
| 1483 | cStyleParamWarned = true; |
| 1484 | } |
| 1485 | DeclSpec DS(AttrFactory); |
| 1486 | ParseDeclarationSpecifiers(DS); |
| 1487 | |
| 1488 | Declarator ParmDecl(DS, DeclaratorContext::PrototypeContext); |
| 1489 | ParseDeclarator(ParmDecl); |
| 1490 | IdentifierInfo *ParmII = ParmDecl.getIdentifier(); |
| 1491 | Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); |
| 1492 | CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, |
| 1493 | ParmDecl.getIdentifierLoc(), |
| 1494 | Param, |
| 1495 | nullptr)); |
| 1496 | } |
| 1497 | |
| 1498 | |
| 1499 | |
| 1500 | if (getLangOpts().ObjC) |
| 1501 | MaybeParseGNUAttributes(methodAttrs); |
| 1502 | MaybeParseCXX11Attributes(methodAttrs); |
| 1503 | |
| 1504 | if (KeyIdents.size() == 0) |
| 1505 | return nullptr; |
| 1506 | |
| 1507 | Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), |
| 1508 | &KeyIdents[0]); |
| 1509 | Decl *Result = Actions.ActOnMethodDeclaration( |
| 1510 | getCurScope(), mLoc, Tok.getLocation(), mType, DSRet, ReturnType, KeyLocs, |
| 1511 | Sel, &ArgInfos[0], CParamInfo.data(), CParamInfo.size(), methodAttrs, |
| 1512 | MethodImplKind, isVariadic, MethodDefinition); |
| 1513 | |
| 1514 | PD.complete(Result); |
| 1515 | return Result; |
| 1516 | } |
| 1517 | |
| 1518 | |
| 1519 | |
| 1520 | |
| 1521 | bool Parser:: |
| 1522 | ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &Protocols, |
| 1523 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
| 1524 | bool WarnOnDeclarations, bool ForObjCContainer, |
| 1525 | SourceLocation &LAngleLoc, SourceLocation &EndLoc, |
| 1526 | bool consumeLastToken) { |
| 1527 | (0) . __assert_fail ("Tok.is(tok..less) && \"expected <\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 1527, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::less) && "expected <"); |
| 1528 | |
| 1529 | LAngleLoc = ConsumeToken(); |
| 1530 | |
| 1531 | SmallVector<IdentifierLocPair, 8> ProtocolIdents; |
| 1532 | |
| 1533 | while (1) { |
| 1534 | if (Tok.is(tok::code_completion)) { |
| 1535 | Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents); |
| 1536 | cutOffParsing(); |
| 1537 | return true; |
| 1538 | } |
| 1539 | |
| 1540 | if (expectIdentifier()) { |
| 1541 | SkipUntil(tok::greater, StopAtSemi); |
| 1542 | return true; |
| 1543 | } |
| 1544 | ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), |
| 1545 | Tok.getLocation())); |
| 1546 | ProtocolLocs.push_back(Tok.getLocation()); |
| 1547 | ConsumeToken(); |
| 1548 | |
| 1549 | if (!TryConsumeToken(tok::comma)) |
| 1550 | break; |
| 1551 | } |
| 1552 | |
| 1553 | |
| 1554 | if (ParseGreaterThanInTemplateList(EndLoc, consumeLastToken, |
| 1555 | )) |
| 1556 | return true; |
| 1557 | |
| 1558 | |
| 1559 | Actions.FindProtocolDeclaration(WarnOnDeclarations, ForObjCContainer, |
| 1560 | ProtocolIdents, Protocols); |
| 1561 | return false; |
| 1562 | } |
| 1563 | |
| 1564 | TypeResult Parser::parseObjCProtocolQualifierType(SourceLocation &rAngleLoc) { |
| 1565 | (0) . __assert_fail ("Tok.is(tok..less) && \"Protocol qualifiers start with '<'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 1565, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::less) && "Protocol qualifiers start with '<'"); |
| 1566 | (0) . __assert_fail ("getLangOpts().ObjC && \"Protocol qualifiers only exist in Objective-C\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 1566, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getLangOpts().ObjC && "Protocol qualifiers only exist in Objective-C"); |
| 1567 | |
| 1568 | SourceLocation lAngleLoc; |
| 1569 | SmallVector<Decl *, 8> protocols; |
| 1570 | SmallVector<SourceLocation, 8> protocolLocs; |
| 1571 | (void)ParseObjCProtocolReferences(protocols, protocolLocs, false, false, |
| 1572 | lAngleLoc, rAngleLoc, |
| 1573 | ); |
| 1574 | TypeResult result = Actions.actOnObjCProtocolQualifierType(lAngleLoc, |
| 1575 | protocols, |
| 1576 | protocolLocs, |
| 1577 | rAngleLoc); |
| 1578 | if (result.isUsable()) { |
| 1579 | Diag(lAngleLoc, diag::warn_objc_protocol_qualifier_missing_id) |
| 1580 | << FixItHint::CreateInsertion(lAngleLoc, "id") |
| 1581 | << SourceRange(lAngleLoc, rAngleLoc); |
| 1582 | } |
| 1583 | |
| 1584 | return result; |
| 1585 | } |
| 1586 | |
| 1587 | |
| 1588 | |
| 1589 | |
| 1590 | |
| 1591 | |
| 1592 | void Parser::parseObjCTypeArgsOrProtocolQualifiers( |
| 1593 | ParsedType baseType, |
| 1594 | SourceLocation &typeArgsLAngleLoc, |
| 1595 | SmallVectorImpl<ParsedType> &typeArgs, |
| 1596 | SourceLocation &typeArgsRAngleLoc, |
| 1597 | SourceLocation &protocolLAngleLoc, |
| 1598 | SmallVectorImpl<Decl *> &protocols, |
| 1599 | SmallVectorImpl<SourceLocation> &protocolLocs, |
| 1600 | SourceLocation &protocolRAngleLoc, |
| 1601 | bool consumeLastToken, |
| 1602 | bool warnOnIncompleteProtocols) { |
| 1603 | (0) . __assert_fail ("Tok.is(tok..less) && \"Not at the start of type args or protocols\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 1603, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::less) && "Not at the start of type args or protocols"); |
| 1604 | SourceLocation lAngleLoc = ConsumeToken(); |
| 1605 | |
| 1606 | |
| 1607 | |
| 1608 | bool allSingleIdentifiers = true; |
| 1609 | SmallVector<IdentifierInfo *, 4> identifiers; |
| 1610 | SmallVectorImpl<SourceLocation> &identifierLocs = protocolLocs; |
| 1611 | |
| 1612 | |
| 1613 | |
| 1614 | do { |
| 1615 | |
| 1616 | if (Tok.is(tok::identifier) && |
| 1617 | (NextToken().is(tok::comma) || |
| 1618 | NextToken().is(tok::greater) || |
| 1619 | NextToken().is(tok::greatergreater))) { |
| 1620 | identifiers.push_back(Tok.getIdentifierInfo()); |
| 1621 | identifierLocs.push_back(ConsumeToken()); |
| 1622 | continue; |
| 1623 | } |
| 1624 | |
| 1625 | if (Tok.is(tok::code_completion)) { |
| 1626 | |
| 1627 | SmallVector<IdentifierLocPair, 4> identifierLocPairs; |
| 1628 | for (unsigned i = 0, n = identifiers.size(); i != n; ++i) { |
| 1629 | identifierLocPairs.push_back(IdentifierLocPair(identifiers[i], |
| 1630 | identifierLocs[i])); |
| 1631 | } |
| 1632 | |
| 1633 | QualType BaseT = Actions.GetTypeFromParser(baseType); |
| 1634 | if (!BaseT.isNull() && BaseT->acceptsObjCTypeParams()) { |
| 1635 | Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type); |
| 1636 | } else { |
| 1637 | Actions.CodeCompleteObjCProtocolReferences(identifierLocPairs); |
| 1638 | } |
| 1639 | cutOffParsing(); |
| 1640 | return; |
| 1641 | } |
| 1642 | |
| 1643 | allSingleIdentifiers = false; |
| 1644 | break; |
| 1645 | } while (TryConsumeToken(tok::comma)); |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | if (allSingleIdentifiers) { |
| 1650 | |
| 1651 | SourceLocation rAngleLoc; |
| 1652 | (void)ParseGreaterThanInTemplateList(rAngleLoc, consumeLastToken, |
| 1653 | ); |
| 1654 | |
| 1655 | |
| 1656 | Actions.actOnObjCTypeArgsOrProtocolQualifiers(getCurScope(), |
| 1657 | baseType, |
| 1658 | lAngleLoc, |
| 1659 | identifiers, |
| 1660 | identifierLocs, |
| 1661 | rAngleLoc, |
| 1662 | typeArgsLAngleLoc, |
| 1663 | typeArgs, |
| 1664 | typeArgsRAngleLoc, |
| 1665 | protocolLAngleLoc, |
| 1666 | protocols, |
| 1667 | protocolRAngleLoc, |
| 1668 | warnOnIncompleteProtocols); |
| 1669 | return; |
| 1670 | } |
| 1671 | |
| 1672 | |
| 1673 | |
| 1674 | |
| 1675 | |
| 1676 | |
| 1677 | |
| 1678 | bool invalid = false; |
| 1679 | IdentifierInfo *foundProtocolId = nullptr, *foundValidTypeId = nullptr; |
| 1680 | SourceLocation foundProtocolSrcLoc, foundValidTypeSrcLoc; |
| 1681 | SmallVector<IdentifierInfo *, 2> unknownTypeArgs; |
| 1682 | SmallVector<SourceLocation, 2> unknownTypeArgsLoc; |
| 1683 | |
| 1684 | for (unsigned i = 0, n = identifiers.size(); i != n; ++i) { |
| 1685 | ParsedType typeArg |
| 1686 | = Actions.getTypeName(*identifiers[i], identifierLocs[i], getCurScope()); |
| 1687 | if (typeArg) { |
| 1688 | DeclSpec DS(AttrFactory); |
| 1689 | const char *prevSpec = nullptr; |
| 1690 | unsigned diagID; |
| 1691 | DS.SetTypeSpecType(TST_typename, identifierLocs[i], prevSpec, diagID, |
| 1692 | typeArg, Actions.getASTContext().getPrintingPolicy()); |
| 1693 | |
| 1694 | |
| 1695 | Declarator D(DS, DeclaratorContext::TypeNameContext); |
| 1696 | TypeResult fullTypeArg = Actions.ActOnTypeName(getCurScope(), D); |
| 1697 | if (fullTypeArg.isUsable()) { |
| 1698 | typeArgs.push_back(fullTypeArg.get()); |
| 1699 | if (!foundValidTypeId) { |
| 1700 | foundValidTypeId = identifiers[i]; |
| 1701 | foundValidTypeSrcLoc = identifierLocs[i]; |
| 1702 | } |
| 1703 | } else { |
| 1704 | invalid = true; |
| 1705 | unknownTypeArgs.push_back(identifiers[i]); |
| 1706 | unknownTypeArgsLoc.push_back(identifierLocs[i]); |
| 1707 | } |
| 1708 | } else { |
| 1709 | invalid = true; |
| 1710 | if (!Actions.LookupProtocol(identifiers[i], identifierLocs[i])) { |
| 1711 | unknownTypeArgs.push_back(identifiers[i]); |
| 1712 | unknownTypeArgsLoc.push_back(identifierLocs[i]); |
| 1713 | } else if (!foundProtocolId) { |
| 1714 | foundProtocolId = identifiers[i]; |
| 1715 | foundProtocolSrcLoc = identifierLocs[i]; |
| 1716 | } |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | |
| 1721 | do { |
| 1722 | Token CurTypeTok = Tok; |
| 1723 | TypeResult typeArg = ParseTypeName(); |
| 1724 | |
| 1725 | |
| 1726 | SourceLocation ellipsisLoc; |
| 1727 | TryConsumeToken(tok::ellipsis, ellipsisLoc); |
| 1728 | if (typeArg.isUsable() && ellipsisLoc.isValid()) { |
| 1729 | typeArg = Actions.ActOnPackExpansion(typeArg.get(), ellipsisLoc); |
| 1730 | } |
| 1731 | |
| 1732 | if (typeArg.isUsable()) { |
| 1733 | typeArgs.push_back(typeArg.get()); |
| 1734 | if (!foundValidTypeId) { |
| 1735 | foundValidTypeId = CurTypeTok.getIdentifierInfo(); |
| 1736 | foundValidTypeSrcLoc = CurTypeTok.getLocation(); |
| 1737 | } |
| 1738 | } else { |
| 1739 | invalid = true; |
| 1740 | } |
| 1741 | } while (TryConsumeToken(tok::comma)); |
| 1742 | |
| 1743 | |
| 1744 | if (foundProtocolId && foundValidTypeId) |
| 1745 | Actions.DiagnoseTypeArgsAndProtocols(foundProtocolId, foundProtocolSrcLoc, |
| 1746 | foundValidTypeId, |
| 1747 | foundValidTypeSrcLoc); |
| 1748 | |
| 1749 | |
| 1750 | ParsedType T; |
| 1751 | if (unknownTypeArgs.size()) |
| 1752 | for (unsigned i = 0, e = unknownTypeArgsLoc.size(); i < e; ++i) |
| 1753 | Actions.DiagnoseUnknownTypeName(unknownTypeArgs[i], unknownTypeArgsLoc[i], |
| 1754 | getCurScope(), nullptr, T); |
| 1755 | |
| 1756 | |
| 1757 | SourceLocation rAngleLoc; |
| 1758 | (void)ParseGreaterThanInTemplateList(rAngleLoc, consumeLastToken, |
| 1759 | ); |
| 1760 | |
| 1761 | if (invalid) { |
| 1762 | typeArgs.clear(); |
| 1763 | return; |
| 1764 | } |
| 1765 | |
| 1766 | |
| 1767 | typeArgsLAngleLoc = lAngleLoc; |
| 1768 | typeArgsRAngleLoc = rAngleLoc; |
| 1769 | } |
| 1770 | |
| 1771 | void Parser::parseObjCTypeArgsAndProtocolQualifiers( |
| 1772 | ParsedType baseType, |
| 1773 | SourceLocation &typeArgsLAngleLoc, |
| 1774 | SmallVectorImpl<ParsedType> &typeArgs, |
| 1775 | SourceLocation &typeArgsRAngleLoc, |
| 1776 | SourceLocation &protocolLAngleLoc, |
| 1777 | SmallVectorImpl<Decl *> &protocols, |
| 1778 | SmallVectorImpl<SourceLocation> &protocolLocs, |
| 1779 | SourceLocation &protocolRAngleLoc, |
| 1780 | bool consumeLastToken) { |
| 1781 | assert(Tok.is(tok::less)); |
| 1782 | |
| 1783 | |
| 1784 | parseObjCTypeArgsOrProtocolQualifiers(baseType, |
| 1785 | typeArgsLAngleLoc, |
| 1786 | typeArgs, |
| 1787 | typeArgsRAngleLoc, |
| 1788 | protocolLAngleLoc, |
| 1789 | protocols, |
| 1790 | protocolLocs, |
| 1791 | protocolRAngleLoc, |
| 1792 | consumeLastToken, |
| 1793 | ); |
| 1794 | if (Tok.is(tok::eof)) |
| 1795 | return; |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | if ((consumeLastToken && Tok.is(tok::less)) || |
| 1801 | (!consumeLastToken && NextToken().is(tok::less))) { |
| 1802 | |
| 1803 | |
| 1804 | if (!consumeLastToken) |
| 1805 | ConsumeToken(); |
| 1806 | |
| 1807 | if (!protocols.empty()) { |
| 1808 | SkipUntilFlags skipFlags = SkipUntilFlags(); |
| 1809 | if (!consumeLastToken) |
| 1810 | skipFlags = skipFlags | StopBeforeMatch; |
| 1811 | Diag(Tok, diag::err_objc_type_args_after_protocols) |
| 1812 | << SourceRange(protocolLAngleLoc, protocolRAngleLoc); |
| 1813 | SkipUntil(tok::greater, tok::greatergreater, skipFlags); |
| 1814 | } else { |
| 1815 | ParseObjCProtocolReferences(protocols, protocolLocs, |
| 1816 | , |
| 1817 | , |
| 1818 | protocolLAngleLoc, protocolRAngleLoc, |
| 1819 | consumeLastToken); |
| 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | TypeResult Parser::parseObjCTypeArgsAndProtocolQualifiers( |
| 1825 | SourceLocation loc, |
| 1826 | ParsedType type, |
| 1827 | bool consumeLastToken, |
| 1828 | SourceLocation &endLoc) { |
| 1829 | assert(Tok.is(tok::less)); |
| 1830 | SourceLocation typeArgsLAngleLoc; |
| 1831 | SmallVector<ParsedType, 4> typeArgs; |
| 1832 | SourceLocation typeArgsRAngleLoc; |
| 1833 | SourceLocation protocolLAngleLoc; |
| 1834 | SmallVector<Decl *, 4> protocols; |
| 1835 | SmallVector<SourceLocation, 4> protocolLocs; |
| 1836 | SourceLocation protocolRAngleLoc; |
| 1837 | |
| 1838 | |
| 1839 | parseObjCTypeArgsAndProtocolQualifiers(type, typeArgsLAngleLoc, typeArgs, |
| 1840 | typeArgsRAngleLoc, protocolLAngleLoc, |
| 1841 | protocols, protocolLocs, |
| 1842 | protocolRAngleLoc, consumeLastToken); |
| 1843 | |
| 1844 | if (Tok.is(tok::eof)) |
| 1845 | return true; |
| 1846 | |
| 1847 | |
| 1848 | if (consumeLastToken) |
| 1849 | endLoc = PrevTokLocation; |
| 1850 | else |
| 1851 | endLoc = Tok.getLocation(); |
| 1852 | |
| 1853 | return Actions.actOnObjCTypeArgsAndProtocolQualifiers( |
| 1854 | getCurScope(), |
| 1855 | loc, |
| 1856 | type, |
| 1857 | typeArgsLAngleLoc, |
| 1858 | typeArgs, |
| 1859 | typeArgsRAngleLoc, |
| 1860 | protocolLAngleLoc, |
| 1861 | protocols, |
| 1862 | protocolLocs, |
| 1863 | protocolRAngleLoc); |
| 1864 | } |
| 1865 | |
| 1866 | void Parser::HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc, |
| 1867 | BalancedDelimiterTracker &T, |
| 1868 | SmallVectorImpl<Decl *> &AllIvarDecls, |
| 1869 | bool RBraceMissing) { |
| 1870 | if (!RBraceMissing) |
| 1871 | T.consumeClose(); |
| 1872 | |
| 1873 | Actions.ActOnObjCContainerStartDefinition(interfaceDecl); |
| 1874 | Actions.ActOnLastBitfield(T.getCloseLocation(), AllIvarDecls); |
| 1875 | Actions.ActOnObjCContainerFinishDefinition(); |
| 1876 | |
| 1877 | |
| 1878 | Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, AllIvarDecls, |
| 1879 | T.getOpenLocation(), T.getCloseLocation(), |
| 1880 | ParsedAttributesView()); |
| 1881 | } |
| 1882 | |
| 1883 | |
| 1884 | |
| 1885 | |
| 1886 | |
| 1887 | |
| 1888 | |
| 1889 | |
| 1890 | |
| 1891 | |
| 1892 | |
| 1893 | |
| 1894 | |
| 1895 | |
| 1896 | |
| 1897 | |
| 1898 | |
| 1899 | |
| 1900 | |
| 1901 | |
| 1902 | |
| 1903 | |
| 1904 | void Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, |
| 1905 | tok::ObjCKeywordKind visibility, |
| 1906 | SourceLocation atLoc) { |
| 1907 | (0) . __assert_fail ("Tok.is(tok..l_brace) && \"expected {\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 1907, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_brace) && "expected {"); |
| 1908 | SmallVector<Decl *, 32> AllIvarDecls; |
| 1909 | |
| 1910 | ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); |
| 1911 | ObjCDeclContextSwitch ObjCDC(*this); |
| 1912 | |
| 1913 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 1914 | T.consumeOpen(); |
| 1915 | |
| 1916 | while (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | if (Tok.is(tok::semi)) { |
| 1921 | ConsumeExtraSemi(InstanceVariableList); |
| 1922 | continue; |
| 1923 | } |
| 1924 | |
| 1925 | |
| 1926 | if (TryConsumeToken(tok::at)) { |
| 1927 | if (Tok.is(tok::code_completion)) { |
| 1928 | Actions.CodeCompleteObjCAtVisibility(getCurScope()); |
| 1929 | return cutOffParsing(); |
| 1930 | } |
| 1931 | |
| 1932 | switch (Tok.getObjCKeywordID()) { |
| 1933 | case tok::objc_private: |
| 1934 | case tok::objc_public: |
| 1935 | case tok::objc_protected: |
| 1936 | case tok::objc_package: |
| 1937 | visibility = Tok.getObjCKeywordID(); |
| 1938 | ConsumeToken(); |
| 1939 | continue; |
| 1940 | |
| 1941 | case tok::objc_end: |
| 1942 | Diag(Tok, diag::err_objc_unexpected_atend); |
| 1943 | Tok.setLocation(Tok.getLocation().getLocWithOffset(-1)); |
| 1944 | Tok.setKind(tok::at); |
| 1945 | Tok.setLength(1); |
| 1946 | PP.EnterToken(Tok); |
| 1947 | HelperActionsForIvarDeclarations(interfaceDecl, atLoc, |
| 1948 | T, AllIvarDecls, true); |
| 1949 | return; |
| 1950 | |
| 1951 | default: |
| 1952 | Diag(Tok, diag::err_objc_illegal_visibility_spec); |
| 1953 | continue; |
| 1954 | } |
| 1955 | } |
| 1956 | |
| 1957 | if (Tok.is(tok::code_completion)) { |
| 1958 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
| 1959 | Sema::PCC_ObjCInstanceVariableList); |
| 1960 | return cutOffParsing(); |
| 1961 | } |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | |
| 1966 | if (Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) { |
| 1967 | SourceLocation DeclEnd; |
| 1968 | ParseStaticAssertDeclaration(DeclEnd); |
| 1969 | continue; |
| 1970 | } |
| 1971 | |
| 1972 | auto ObjCIvarCallback = [&](ParsingFieldDeclarator &FD) { |
| 1973 | Actions.ActOnObjCContainerStartDefinition(interfaceDecl); |
| 1974 | |
| 1975 | FD.D.setObjCIvar(true); |
| 1976 | Decl *Field = Actions.ActOnIvar( |
| 1977 | getCurScope(), FD.D.getDeclSpec().getSourceRange().getBegin(), FD.D, |
| 1978 | FD.BitfieldSize, visibility); |
| 1979 | Actions.ActOnObjCContainerFinishDefinition(); |
| 1980 | if (Field) |
| 1981 | AllIvarDecls.push_back(Field); |
| 1982 | FD.complete(Field); |
| 1983 | }; |
| 1984 | |
| 1985 | |
| 1986 | ParsingDeclSpec DS(*this); |
| 1987 | ParseStructDeclaration(DS, ObjCIvarCallback); |
| 1988 | |
| 1989 | if (Tok.is(tok::semi)) { |
| 1990 | ConsumeToken(); |
| 1991 | } else { |
| 1992 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 1993 | |
| 1994 | SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); |
| 1995 | } |
| 1996 | } |
| 1997 | HelperActionsForIvarDeclarations(interfaceDecl, atLoc, |
| 1998 | T, AllIvarDecls, false); |
| 1999 | } |
| 2000 | |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | |
| 2006 | |
| 2007 | |
| 2008 | |
| 2009 | |
| 2010 | |
| 2011 | |
| 2012 | |
| 2013 | |
| 2014 | |
| 2015 | |
| 2016 | |
| 2017 | Parser::DeclGroupPtrTy |
| 2018 | Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, |
| 2019 | ParsedAttributes &attrs) { |
| 2020 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_protocol) && \"ParseObjCAtProtocolDeclaration(). Expected @protocol\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2021, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isObjCAtKeyword(tok::objc_protocol) && |
| 2021 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_protocol) && \"ParseObjCAtProtocolDeclaration(). Expected @protocol\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2021, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "ParseObjCAtProtocolDeclaration(): Expected @protocol"); |
| 2022 | ConsumeToken(); |
| 2023 | |
| 2024 | if (Tok.is(tok::code_completion)) { |
| 2025 | Actions.CodeCompleteObjCProtocolDecl(getCurScope()); |
| 2026 | cutOffParsing(); |
| 2027 | return nullptr; |
| 2028 | } |
| 2029 | |
| 2030 | MaybeSkipAttributes(tok::objc_protocol); |
| 2031 | |
| 2032 | if (expectIdentifier()) |
| 2033 | return nullptr; |
| 2034 | |
| 2035 | IdentifierInfo *protocolName = Tok.getIdentifierInfo(); |
| 2036 | SourceLocation nameLoc = ConsumeToken(); |
| 2037 | |
| 2038 | if (TryConsumeToken(tok::semi)) { |
| 2039 | IdentifierLocPair ProtoInfo(protocolName, nameLoc); |
| 2040 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, ProtoInfo, attrs); |
| 2041 | } |
| 2042 | |
| 2043 | CheckNestedObjCContexts(AtLoc); |
| 2044 | |
| 2045 | if (Tok.is(tok::comma)) { |
| 2046 | SmallVector<IdentifierLocPair, 8> ProtocolRefs; |
| 2047 | ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); |
| 2048 | |
| 2049 | |
| 2050 | while (1) { |
| 2051 | ConsumeToken(); |
| 2052 | if (expectIdentifier()) { |
| 2053 | SkipUntil(tok::semi); |
| 2054 | return nullptr; |
| 2055 | } |
| 2056 | ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), |
| 2057 | Tok.getLocation())); |
| 2058 | ConsumeToken(); |
| 2059 | |
| 2060 | if (Tok.isNot(tok::comma)) |
| 2061 | break; |
| 2062 | } |
| 2063 | |
| 2064 | if (ExpectAndConsume(tok::semi, diag::err_expected_after, "@protocol")) |
| 2065 | return nullptr; |
| 2066 | |
| 2067 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, ProtocolRefs, attrs); |
| 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | SourceLocation LAngleLoc, EndProtoLoc; |
| 2072 | |
| 2073 | SmallVector<Decl *, 8> ProtocolRefs; |
| 2074 | SmallVector<SourceLocation, 8> ProtocolLocs; |
| 2075 | if (Tok.is(tok::less) && |
| 2076 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, true, |
| 2077 | LAngleLoc, EndProtoLoc, |
| 2078 | )) |
| 2079 | return nullptr; |
| 2080 | |
| 2081 | Decl *ProtoType = Actions.ActOnStartProtocolInterface( |
| 2082 | AtLoc, protocolName, nameLoc, ProtocolRefs.data(), ProtocolRefs.size(), |
| 2083 | ProtocolLocs.data(), EndProtoLoc, attrs); |
| 2084 | |
| 2085 | ParseObjCInterfaceDeclList(tok::objc_protocol, ProtoType); |
| 2086 | return Actions.ConvertDeclToDeclGroup(ProtoType); |
| 2087 | } |
| 2088 | |
| 2089 | |
| 2090 | |
| 2091 | |
| 2092 | |
| 2093 | |
| 2094 | |
| 2095 | |
| 2096 | |
| 2097 | |
| 2098 | |
| 2099 | Parser::DeclGroupPtrTy |
| 2100 | Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { |
| 2101 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_implementation) && \"ParseObjCAtImplementationDeclaration(). Expected @implementation\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2102, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isObjCAtKeyword(tok::objc_implementation) && |
| 2102 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_implementation) && \"ParseObjCAtImplementationDeclaration(). Expected @implementation\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2102, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "ParseObjCAtImplementationDeclaration(): Expected @implementation"); |
| 2103 | CheckNestedObjCContexts(AtLoc); |
| 2104 | ConsumeToken(); |
| 2105 | |
| 2106 | |
| 2107 | if (Tok.is(tok::code_completion)) { |
| 2108 | Actions.CodeCompleteObjCImplementationDecl(getCurScope()); |
| 2109 | cutOffParsing(); |
| 2110 | return nullptr; |
| 2111 | } |
| 2112 | |
| 2113 | MaybeSkipAttributes(tok::objc_implementation); |
| 2114 | |
| 2115 | if (expectIdentifier()) |
| 2116 | return nullptr; |
| 2117 | |
| 2118 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
| 2119 | SourceLocation nameLoc = ConsumeToken(); |
| 2120 | Decl *ObjCImpDecl = nullptr; |
| 2121 | |
| 2122 | |
| 2123 | |
| 2124 | if (Tok.is(tok::less)) { |
| 2125 | SourceLocation lAngleLoc, rAngleLoc; |
| 2126 | SmallVector<IdentifierLocPair, 8> protocolIdents; |
| 2127 | SourceLocation diagLoc = Tok.getLocation(); |
| 2128 | ObjCTypeParamListScope typeParamScope(Actions, getCurScope()); |
| 2129 | if (parseObjCTypeParamListOrProtocolRefs(typeParamScope, lAngleLoc, |
| 2130 | protocolIdents, rAngleLoc)) { |
| 2131 | Diag(diagLoc, diag::err_objc_parameterized_implementation) |
| 2132 | << SourceRange(diagLoc, PrevTokLocation); |
| 2133 | } else if (lAngleLoc.isValid()) { |
| 2134 | Diag(lAngleLoc, diag::err_unexpected_protocol_qualifier) |
| 2135 | << FixItHint::CreateRemoval(SourceRange(lAngleLoc, rAngleLoc)); |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | if (Tok.is(tok::l_paren)) { |
| 2140 | |
| 2141 | ConsumeParen(); |
| 2142 | SourceLocation categoryLoc, rparenLoc; |
| 2143 | IdentifierInfo *categoryId = nullptr; |
| 2144 | |
| 2145 | if (Tok.is(tok::code_completion)) { |
| 2146 | Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); |
| 2147 | cutOffParsing(); |
| 2148 | return nullptr; |
| 2149 | } |
| 2150 | |
| 2151 | if (Tok.is(tok::identifier)) { |
| 2152 | categoryId = Tok.getIdentifierInfo(); |
| 2153 | categoryLoc = ConsumeToken(); |
| 2154 | } else { |
| 2155 | Diag(Tok, diag::err_expected) |
| 2156 | << tok::identifier; |
| 2157 | return nullptr; |
| 2158 | } |
| 2159 | if (Tok.isNot(tok::r_paren)) { |
| 2160 | Diag(Tok, diag::err_expected) << tok::r_paren; |
| 2161 | SkipUntil(tok::r_paren); |
| 2162 | return nullptr; |
| 2163 | } |
| 2164 | rparenLoc = ConsumeParen(); |
| 2165 | if (Tok.is(tok::less)) { |
| 2166 | Diag(Tok, diag::err_unexpected_protocol_qualifier); |
| 2167 | SourceLocation protocolLAngleLoc, protocolRAngleLoc; |
| 2168 | SmallVector<Decl *, 4> protocols; |
| 2169 | SmallVector<SourceLocation, 4> protocolLocs; |
| 2170 | (void)ParseObjCProtocolReferences(protocols, protocolLocs, |
| 2171 | , |
| 2172 | , |
| 2173 | protocolLAngleLoc, protocolRAngleLoc, |
| 2174 | ); |
| 2175 | } |
| 2176 | ObjCImpDecl = Actions.ActOnStartCategoryImplementation( |
| 2177 | AtLoc, nameId, nameLoc, categoryId, |
| 2178 | categoryLoc); |
| 2179 | |
| 2180 | } else { |
| 2181 | |
| 2182 | SourceLocation superClassLoc; |
| 2183 | IdentifierInfo *superClassId = nullptr; |
| 2184 | if (TryConsumeToken(tok::colon)) { |
| 2185 | |
| 2186 | if (expectIdentifier()) |
| 2187 | return nullptr; |
| 2188 | superClassId = Tok.getIdentifierInfo(); |
| 2189 | superClassLoc = ConsumeToken(); |
| 2190 | } |
| 2191 | ObjCImpDecl = Actions.ActOnStartClassImplementation( |
| 2192 | AtLoc, nameId, nameLoc, |
| 2193 | superClassId, superClassLoc); |
| 2194 | |
| 2195 | if (Tok.is(tok::l_brace)) |
| 2196 | ParseObjCClassInstanceVariables(ObjCImpDecl, tok::objc_private, AtLoc); |
| 2197 | else if (Tok.is(tok::less)) { |
| 2198 | Diag(Tok, diag::err_unexpected_protocol_qualifier); |
| 2199 | |
| 2200 | SourceLocation protocolLAngleLoc, protocolRAngleLoc; |
| 2201 | SmallVector<Decl *, 4> protocols; |
| 2202 | SmallVector<SourceLocation, 4> protocolLocs; |
| 2203 | (void)ParseObjCProtocolReferences(protocols, protocolLocs, |
| 2204 | , |
| 2205 | , |
| 2206 | protocolLAngleLoc, protocolRAngleLoc, |
| 2207 | ); |
| 2208 | } |
| 2209 | } |
| 2210 | assert(ObjCImpDecl); |
| 2211 | |
| 2212 | SmallVector<Decl *, 8> DeclsInGroup; |
| 2213 | |
| 2214 | { |
| 2215 | ObjCImplParsingDataRAII ObjCImplParsing(*this, ObjCImpDecl); |
| 2216 | while (!ObjCImplParsing.isFinished() && !isEofOrEom()) { |
| 2217 | ParsedAttributesWithRange attrs(AttrFactory); |
| 2218 | MaybeParseCXX11Attributes(attrs); |
| 2219 | if (DeclGroupPtrTy DGP = ParseExternalDeclaration(attrs)) { |
| 2220 | DeclGroupRef DG = DGP.get(); |
| 2221 | DeclsInGroup.append(DG.begin(), DG.end()); |
| 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | return Actions.ActOnFinishObjCImplementation(ObjCImpDecl, DeclsInGroup); |
| 2227 | } |
| 2228 | |
| 2229 | Parser::DeclGroupPtrTy |
| 2230 | Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { |
| 2231 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_end) && \"ParseObjCAtEndDeclaration(). Expected @end\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2232, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isObjCAtKeyword(tok::objc_end) && |
| 2232 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_end) && \"ParseObjCAtEndDeclaration(). Expected @end\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2232, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "ParseObjCAtEndDeclaration(): Expected @end"); |
| 2233 | ConsumeToken(); |
| 2234 | if (CurParsedObjCImpl) |
| 2235 | CurParsedObjCImpl->finish(atEnd); |
| 2236 | else |
| 2237 | |
| 2238 | Diag(atEnd.getBegin(), diag::err_expected_objc_container); |
| 2239 | return nullptr; |
| 2240 | } |
| 2241 | |
| 2242 | Parser::ObjCImplParsingDataRAII::~ObjCImplParsingDataRAII() { |
| 2243 | if (!Finished) { |
| 2244 | finish(P.Tok.getLocation()); |
| 2245 | if (P.isEofOrEom()) { |
| 2246 | P.Diag(P.Tok, diag::err_objc_missing_end) |
| 2247 | << FixItHint::CreateInsertion(P.Tok.getLocation(), "\n@end\n"); |
| 2248 | P.Diag(Dcl->getBeginLoc(), diag::note_objc_container_start) |
| 2249 | << Sema::OCK_Implementation; |
| 2250 | } |
| 2251 | } |
| 2252 | P.CurParsedObjCImpl = nullptr; |
| 2253 | assert(LateParsedObjCMethods.empty()); |
| 2254 | } |
| 2255 | |
| 2256 | void Parser::ObjCImplParsingDataRAII::finish(SourceRange AtEnd) { |
| 2257 | assert(!Finished); |
| 2258 | P.Actions.DefaultSynthesizeProperties(P.getCurScope(), Dcl, AtEnd.getBegin()); |
| 2259 | for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) |
| 2260 | P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i], |
| 2261 | true); |
| 2262 | |
| 2263 | P.Actions.ActOnAtEnd(P.getCurScope(), AtEnd); |
| 2264 | |
| 2265 | if (HasCFunction) |
| 2266 | for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) |
| 2267 | P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i], |
| 2268 | false); |
| 2269 | |
| 2270 | |
| 2271 | for (LateParsedObjCMethodContainer::iterator |
| 2272 | I = LateParsedObjCMethods.begin(), |
| 2273 | E = LateParsedObjCMethods.end(); I != E; ++I) |
| 2274 | delete *I; |
| 2275 | LateParsedObjCMethods.clear(); |
| 2276 | |
| 2277 | Finished = true; |
| 2278 | } |
| 2279 | |
| 2280 | |
| 2281 | |
| 2282 | |
| 2283 | Decl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { |
| 2284 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_compatibility_alias) && \"ParseObjCAtAliasDeclaration(). Expected @compatibility_alias\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2285, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && |
| 2285 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_compatibility_alias) && \"ParseObjCAtAliasDeclaration(). Expected @compatibility_alias\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2285, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); |
| 2286 | ConsumeToken(); |
| 2287 | if (expectIdentifier()) |
| 2288 | return nullptr; |
| 2289 | IdentifierInfo *aliasId = Tok.getIdentifierInfo(); |
| 2290 | SourceLocation aliasLoc = ConsumeToken(); |
| 2291 | if (expectIdentifier()) |
| 2292 | return nullptr; |
| 2293 | IdentifierInfo *classId = Tok.getIdentifierInfo(); |
| 2294 | SourceLocation classLoc = ConsumeToken(); |
| 2295 | ExpectAndConsume(tok::semi, diag::err_expected_after, "@compatibility_alias"); |
| 2296 | return Actions.ActOnCompatibilityAlias(atLoc, aliasId, aliasLoc, |
| 2297 | classId, classLoc); |
| 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | |
| 2302 | |
| 2303 | |
| 2304 | |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { |
| 2312 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_synthesize) && \"ParseObjCPropertySynthesize(). Expected '@synthesize'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2313, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && |
| 2313 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_synthesize) && \"ParseObjCPropertySynthesize(). Expected '@synthesize'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2313, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "ParseObjCPropertySynthesize(): Expected '@synthesize'"); |
| 2314 | ConsumeToken(); |
| 2315 | |
| 2316 | while (true) { |
| 2317 | if (Tok.is(tok::code_completion)) { |
| 2318 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); |
| 2319 | cutOffParsing(); |
| 2320 | return nullptr; |
| 2321 | } |
| 2322 | |
| 2323 | if (Tok.isNot(tok::identifier)) { |
| 2324 | Diag(Tok, diag::err_synthesized_property_name); |
| 2325 | SkipUntil(tok::semi); |
| 2326 | return nullptr; |
| 2327 | } |
| 2328 | |
| 2329 | IdentifierInfo *propertyIvar = nullptr; |
| 2330 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 2331 | SourceLocation propertyLoc = ConsumeToken(); |
| 2332 | SourceLocation propertyIvarLoc; |
| 2333 | if (TryConsumeToken(tok::equal)) { |
| 2334 | |
| 2335 | if (Tok.is(tok::code_completion)) { |
| 2336 | Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId); |
| 2337 | cutOffParsing(); |
| 2338 | return nullptr; |
| 2339 | } |
| 2340 | |
| 2341 | if (expectIdentifier()) |
| 2342 | break; |
| 2343 | propertyIvar = Tok.getIdentifierInfo(); |
| 2344 | propertyIvarLoc = ConsumeToken(); |
| 2345 | } |
| 2346 | Actions.ActOnPropertyImplDecl( |
| 2347 | getCurScope(), atLoc, propertyLoc, true, |
| 2348 | propertyId, propertyIvar, propertyIvarLoc, |
| 2349 | ObjCPropertyQueryKind::OBJC_PR_query_unknown); |
| 2350 | if (Tok.isNot(tok::comma)) |
| 2351 | break; |
| 2352 | ConsumeToken(); |
| 2353 | } |
| 2354 | ExpectAndConsume(tok::semi, diag::err_expected_after, "@synthesize"); |
| 2355 | return nullptr; |
| 2356 | } |
| 2357 | |
| 2358 | |
| 2359 | |
| 2360 | |
| 2361 | |
| 2362 | |
| 2363 | |
| 2364 | |
| 2365 | Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { |
| 2366 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_dynamic) && \"ParseObjCPropertyDynamic(). Expected '@dynamic'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2367, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && |
| 2367 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_dynamic) && \"ParseObjCPropertyDynamic(). Expected '@dynamic'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2367, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "ParseObjCPropertyDynamic(): Expected '@dynamic'"); |
| 2368 | ConsumeToken(); |
| 2369 | |
| 2370 | bool isClassProperty = false; |
| 2371 | if (Tok.is(tok::l_paren)) { |
| 2372 | ConsumeParen(); |
| 2373 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 2374 | |
| 2375 | if (!II) { |
| 2376 | Diag(Tok, diag::err_objc_expected_property_attr) << II; |
| 2377 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2378 | } else { |
| 2379 | SourceLocation AttrName = ConsumeToken(); |
| 2380 | if (II->isStr("class")) { |
| 2381 | isClassProperty = true; |
| 2382 | if (Tok.isNot(tok::r_paren)) { |
| 2383 | Diag(Tok, diag::err_expected) << tok::r_paren; |
| 2384 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2385 | } else |
| 2386 | ConsumeParen(); |
| 2387 | } else { |
| 2388 | Diag(AttrName, diag::err_objc_expected_property_attr) << II; |
| 2389 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2390 | } |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | while (true) { |
| 2395 | if (Tok.is(tok::code_completion)) { |
| 2396 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); |
| 2397 | cutOffParsing(); |
| 2398 | return nullptr; |
| 2399 | } |
| 2400 | |
| 2401 | if (expectIdentifier()) { |
| 2402 | SkipUntil(tok::semi); |
| 2403 | return nullptr; |
| 2404 | } |
| 2405 | |
| 2406 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 2407 | SourceLocation propertyLoc = ConsumeToken(); |
| 2408 | Actions.ActOnPropertyImplDecl( |
| 2409 | getCurScope(), atLoc, propertyLoc, false, |
| 2410 | propertyId, nullptr, SourceLocation(), |
| 2411 | isClassProperty ? ObjCPropertyQueryKind::OBJC_PR_query_class : |
| 2412 | ObjCPropertyQueryKind::OBJC_PR_query_unknown); |
| 2413 | |
| 2414 | if (Tok.isNot(tok::comma)) |
| 2415 | break; |
| 2416 | ConsumeToken(); |
| 2417 | } |
| 2418 | ExpectAndConsume(tok::semi, diag::err_expected_after, "@dynamic"); |
| 2419 | return nullptr; |
| 2420 | } |
| 2421 | |
| 2422 | |
| 2423 | |
| 2424 | |
| 2425 | StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { |
| 2426 | ExprResult Res; |
| 2427 | ConsumeToken(); |
| 2428 | if (Tok.isNot(tok::semi)) { |
| 2429 | Res = ParseExpression(); |
| 2430 | if (Res.isInvalid()) { |
| 2431 | SkipUntil(tok::semi); |
| 2432 | return StmtError(); |
| 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | ExpectAndConsume(tok::semi, diag::err_expected_after, "@throw"); |
| 2437 | return Actions.ActOnObjCAtThrowStmt(atLoc, Res.get(), getCurScope()); |
| 2438 | } |
| 2439 | |
| 2440 | |
| 2441 | |
| 2442 | |
| 2443 | StmtResult |
| 2444 | Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { |
| 2445 | ConsumeToken(); |
| 2446 | if (Tok.isNot(tok::l_paren)) { |
| 2447 | Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; |
| 2448 | return StmtError(); |
| 2449 | } |
| 2450 | |
| 2451 | |
| 2452 | ConsumeParen(); |
| 2453 | ExprResult operand(ParseExpression()); |
| 2454 | |
| 2455 | if (Tok.is(tok::r_paren)) { |
| 2456 | ConsumeParen(); |
| 2457 | } else { |
| 2458 | if (!operand.isInvalid()) |
| 2459 | Diag(Tok, diag::err_expected) << tok::r_paren; |
| 2460 | |
| 2461 | |
| 2462 | SkipUntil(tok::l_brace, StopAtSemi | StopBeforeMatch); |
| 2463 | } |
| 2464 | |
| 2465 | |
| 2466 | if (Tok.isNot(tok::l_brace)) { |
| 2467 | if (!operand.isInvalid()) |
| 2468 | Diag(Tok, diag::err_expected) << tok::l_brace; |
| 2469 | return StmtError(); |
| 2470 | } |
| 2471 | |
| 2472 | |
| 2473 | if (!operand.isInvalid()) |
| 2474 | operand = Actions.ActOnObjCAtSynchronizedOperand(atLoc, operand.get()); |
| 2475 | |
| 2476 | |
| 2477 | ParseScope bodyScope(this, Scope::DeclScope | Scope::CompoundStmtScope); |
| 2478 | StmtResult body(ParseCompoundStatementBody()); |
| 2479 | bodyScope.Exit(); |
| 2480 | |
| 2481 | |
| 2482 | |
| 2483 | if (operand.isInvalid()) |
| 2484 | return StmtError(); |
| 2485 | |
| 2486 | if (body.isInvalid()) |
| 2487 | body = Actions.ActOnNullStmt(Tok.getLocation()); |
| 2488 | |
| 2489 | return Actions.ActOnObjCAtSynchronizedStmt(atLoc, operand.get(), body.get()); |
| 2490 | } |
| 2491 | |
| 2492 | |
| 2493 | |
| 2494 | |
| 2495 | |
| 2496 | |
| 2497 | |
| 2498 | |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | |
| 2503 | StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { |
| 2504 | bool catch_or_finally_seen = false; |
| 2505 | |
| 2506 | ConsumeToken(); |
| 2507 | if (Tok.isNot(tok::l_brace)) { |
| 2508 | Diag(Tok, diag::err_expected) << tok::l_brace; |
| 2509 | return StmtError(); |
| 2510 | } |
| 2511 | StmtVector CatchStmts; |
| 2512 | StmtResult FinallyStmt; |
| 2513 | ParseScope TryScope(this, Scope::DeclScope | Scope::CompoundStmtScope); |
| 2514 | StmtResult TryBody(ParseCompoundStatementBody()); |
| 2515 | TryScope.Exit(); |
| 2516 | if (TryBody.isInvalid()) |
| 2517 | TryBody = Actions.ActOnNullStmt(Tok.getLocation()); |
| 2518 | |
| 2519 | while (Tok.is(tok::at)) { |
| 2520 | |
| 2521 | |
| 2522 | |
| 2523 | Token AfterAt = GetLookAheadToken(1); |
| 2524 | if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && |
| 2525 | !AfterAt.isObjCAtKeyword(tok::objc_finally)) |
| 2526 | break; |
| 2527 | |
| 2528 | SourceLocation AtCatchFinallyLoc = ConsumeToken(); |
| 2529 | if (Tok.isObjCAtKeyword(tok::objc_catch)) { |
| 2530 | Decl *FirstPart = nullptr; |
| 2531 | ConsumeToken(); |
| 2532 | if (Tok.is(tok::l_paren)) { |
| 2533 | ConsumeParen(); |
| 2534 | ParseScope CatchScope(this, Scope::DeclScope | |
| 2535 | Scope::CompoundStmtScope | |
| 2536 | Scope::AtCatchScope); |
| 2537 | if (Tok.isNot(tok::ellipsis)) { |
| 2538 | DeclSpec DS(AttrFactory); |
| 2539 | ParseDeclarationSpecifiers(DS); |
| 2540 | Declarator ParmDecl(DS, DeclaratorContext::ObjCCatchContext); |
| 2541 | ParseDeclarator(ParmDecl); |
| 2542 | |
| 2543 | |
| 2544 | |
| 2545 | FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); |
| 2546 | } else |
| 2547 | ConsumeToken(); |
| 2548 | |
| 2549 | SourceLocation RParenLoc; |
| 2550 | |
| 2551 | if (Tok.is(tok::r_paren)) |
| 2552 | RParenLoc = ConsumeParen(); |
| 2553 | else |
| 2554 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2555 | |
| 2556 | StmtResult CatchBody(true); |
| 2557 | if (Tok.is(tok::l_brace)) |
| 2558 | CatchBody = ParseCompoundStatementBody(); |
| 2559 | else |
| 2560 | Diag(Tok, diag::err_expected) << tok::l_brace; |
| 2561 | if (CatchBody.isInvalid()) |
| 2562 | CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
| 2563 | |
| 2564 | StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, |
| 2565 | RParenLoc, |
| 2566 | FirstPart, |
| 2567 | CatchBody.get()); |
| 2568 | if (!Catch.isInvalid()) |
| 2569 | CatchStmts.push_back(Catch.get()); |
| 2570 | |
| 2571 | } else { |
| 2572 | Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) |
| 2573 | << "@catch clause"; |
| 2574 | return StmtError(); |
| 2575 | } |
| 2576 | catch_or_finally_seen = true; |
| 2577 | } else { |
| 2578 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_finally) && \"Lookahead confused?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2578, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); |
| 2579 | ConsumeToken(); |
| 2580 | ParseScope FinallyScope(this, |
| 2581 | Scope::DeclScope | Scope::CompoundStmtScope); |
| 2582 | |
| 2583 | bool ShouldCapture = |
| 2584 | getTargetInfo().getTriple().isWindowsMSVCEnvironment(); |
| 2585 | if (ShouldCapture) |
| 2586 | Actions.ActOnCapturedRegionStart(Tok.getLocation(), getCurScope(), |
| 2587 | CR_ObjCAtFinally, 1); |
| 2588 | |
| 2589 | StmtResult FinallyBody(true); |
| 2590 | if (Tok.is(tok::l_brace)) |
| 2591 | FinallyBody = ParseCompoundStatementBody(); |
| 2592 | else |
| 2593 | Diag(Tok, diag::err_expected) << tok::l_brace; |
| 2594 | |
| 2595 | if (FinallyBody.isInvalid()) { |
| 2596 | FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); |
| 2597 | if (ShouldCapture) |
| 2598 | Actions.ActOnCapturedRegionError(); |
| 2599 | } else if (ShouldCapture) { |
| 2600 | FinallyBody = Actions.ActOnCapturedRegionEnd(FinallyBody.get()); |
| 2601 | } |
| 2602 | |
| 2603 | FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, |
| 2604 | FinallyBody.get()); |
| 2605 | catch_or_finally_seen = true; |
| 2606 | break; |
| 2607 | } |
| 2608 | } |
| 2609 | if (!catch_or_finally_seen) { |
| 2610 | Diag(atLoc, diag::err_missing_catch_finally); |
| 2611 | return StmtError(); |
| 2612 | } |
| 2613 | |
| 2614 | return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.get(), |
| 2615 | CatchStmts, |
| 2616 | FinallyStmt.get()); |
| 2617 | } |
| 2618 | |
| 2619 | |
| 2620 | |
| 2621 | |
| 2622 | StmtResult |
| 2623 | Parser::ParseObjCAutoreleasePoolStmt(SourceLocation atLoc) { |
| 2624 | ConsumeToken(); |
| 2625 | if (Tok.isNot(tok::l_brace)) { |
| 2626 | Diag(Tok, diag::err_expected) << tok::l_brace; |
| 2627 | return StmtError(); |
| 2628 | } |
| 2629 | |
| 2630 | |
| 2631 | ParseScope BodyScope(this, Scope::DeclScope | Scope::CompoundStmtScope); |
| 2632 | |
| 2633 | StmtResult AutoreleasePoolBody(ParseCompoundStatementBody()); |
| 2634 | |
| 2635 | BodyScope.Exit(); |
| 2636 | if (AutoreleasePoolBody.isInvalid()) |
| 2637 | AutoreleasePoolBody = Actions.ActOnNullStmt(Tok.getLocation()); |
| 2638 | return Actions.ActOnObjCAutoreleasePoolStmt(atLoc, |
| 2639 | AutoreleasePoolBody.get()); |
| 2640 | } |
| 2641 | |
| 2642 | |
| 2643 | |
| 2644 | void Parser::StashAwayMethodOrFunctionBodyTokens(Decl *MDecl) { |
| 2645 | if (SkipFunctionBodies && (!MDecl || Actions.canSkipFunctionBody(MDecl)) && |
| 2646 | trySkippingFunctionBody()) { |
| 2647 | Actions.ActOnSkippedFunctionBody(MDecl); |
| 2648 | return; |
| 2649 | } |
| 2650 | |
| 2651 | LexedMethod* LM = new LexedMethod(this, MDecl); |
| 2652 | CurParsedObjCImpl->LateParsedObjCMethods.push_back(LM); |
| 2653 | CachedTokens &Toks = LM->Toks; |
| 2654 | |
| 2655 | Toks.push_back(Tok); |
| 2656 | if (Tok.is(tok::kw_try)) { |
| 2657 | ConsumeToken(); |
| 2658 | if (Tok.is(tok::colon)) { |
| 2659 | Toks.push_back(Tok); |
| 2660 | ConsumeToken(); |
| 2661 | while (Tok.isNot(tok::l_brace)) { |
| 2662 | ConsumeAndStoreUntil(tok::l_paren, Toks, ); |
| 2663 | ConsumeAndStoreUntil(tok::r_paren, Toks, ); |
| 2664 | } |
| 2665 | } |
| 2666 | Toks.push_back(Tok); |
| 2667 | } |
| 2668 | else if (Tok.is(tok::colon)) { |
| 2669 | ConsumeToken(); |
| 2670 | |
| 2671 | while (Tok.isNot(tok::l_brace)) { |
| 2672 | ConsumeAndStoreUntil(tok::l_paren, Toks, ); |
| 2673 | ConsumeAndStoreUntil(tok::r_paren, Toks, ); |
| 2674 | } |
| 2675 | Toks.push_back(Tok); |
| 2676 | } |
| 2677 | ConsumeBrace(); |
| 2678 | |
| 2679 | ConsumeAndStoreUntil(tok::r_brace, Toks, ); |
| 2680 | while (Tok.is(tok::kw_catch)) { |
| 2681 | ConsumeAndStoreUntil(tok::l_brace, Toks, ); |
| 2682 | ConsumeAndStoreUntil(tok::r_brace, Toks, ); |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | |
| 2687 | |
| 2688 | Decl *Parser::ParseObjCMethodDefinition() { |
| 2689 | Decl *MDecl = ParseObjCMethodPrototype(); |
| 2690 | |
| 2691 | PrettyDeclStackTraceEntry CrashInfo(Actions.Context, MDecl, Tok.getLocation(), |
| 2692 | "parsing Objective-C method"); |
| 2693 | |
| 2694 | |
| 2695 | if (Tok.is(tok::semi)) { |
| 2696 | if (CurParsedObjCImpl) { |
| 2697 | Diag(Tok, diag::warn_semicolon_before_method_body) |
| 2698 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 2699 | } |
| 2700 | ConsumeToken(); |
| 2701 | } |
| 2702 | |
| 2703 | |
| 2704 | if (Tok.isNot(tok::l_brace)) { |
| 2705 | Diag(Tok, diag::err_expected_method_body); |
| 2706 | |
| 2707 | |
| 2708 | SkipUntil(tok::l_brace, StopAtSemi | StopBeforeMatch); |
| 2709 | |
| 2710 | |
| 2711 | if (Tok.isNot(tok::l_brace)) |
| 2712 | return nullptr; |
| 2713 | } |
| 2714 | |
| 2715 | if (!MDecl) { |
| 2716 | ConsumeBrace(); |
| 2717 | SkipUntil(tok::r_brace); |
| 2718 | return nullptr; |
| 2719 | } |
| 2720 | |
| 2721 | |
| 2722 | Actions.AddAnyMethodToGlobalPool(MDecl); |
| 2723 | (0) . __assert_fail ("CurParsedObjCImpl && \"ParseObjCMethodDefinition - Method out of @implementation\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2724, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert (CurParsedObjCImpl |
| 2724 | (0) . __assert_fail ("CurParsedObjCImpl && \"ParseObjCMethodDefinition - Method out of @implementation\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2724, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && "ParseObjCMethodDefinition - Method out of @implementation"); |
| 2725 | |
| 2726 | StashAwayMethodOrFunctionBodyTokens(MDecl); |
| 2727 | return MDecl; |
| 2728 | } |
| 2729 | |
| 2730 | StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc, |
| 2731 | ParsedStmtContext StmtCtx) { |
| 2732 | if (Tok.is(tok::code_completion)) { |
| 2733 | Actions.CodeCompleteObjCAtStatement(getCurScope()); |
| 2734 | cutOffParsing(); |
| 2735 | return StmtError(); |
| 2736 | } |
| 2737 | |
| 2738 | if (Tok.isObjCAtKeyword(tok::objc_try)) |
| 2739 | return ParseObjCTryStmt(AtLoc); |
| 2740 | |
| 2741 | if (Tok.isObjCAtKeyword(tok::objc_throw)) |
| 2742 | return ParseObjCThrowStmt(AtLoc); |
| 2743 | |
| 2744 | if (Tok.isObjCAtKeyword(tok::objc_synchronized)) |
| 2745 | return ParseObjCSynchronizedStmt(AtLoc); |
| 2746 | |
| 2747 | if (Tok.isObjCAtKeyword(tok::objc_autoreleasepool)) |
| 2748 | return ParseObjCAutoreleasePoolStmt(AtLoc); |
| 2749 | |
| 2750 | if (Tok.isObjCAtKeyword(tok::objc_import) && |
| 2751 | getLangOpts().DebuggerSupport) { |
| 2752 | SkipUntil(tok::semi); |
| 2753 | return Actions.ActOnNullStmt(Tok.getLocation()); |
| 2754 | } |
| 2755 | |
| 2756 | ExprStatementTokLoc = AtLoc; |
| 2757 | ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); |
| 2758 | if (Res.isInvalid()) { |
| 2759 | |
| 2760 | |
| 2761 | |
| 2762 | SkipUntil(tok::semi); |
| 2763 | return StmtError(); |
| 2764 | } |
| 2765 | |
| 2766 | |
| 2767 | ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); |
| 2768 | return handleExprStmt(Res, StmtCtx); |
| 2769 | } |
| 2770 | |
| 2771 | ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { |
| 2772 | switch (Tok.getKind()) { |
| 2773 | case tok::code_completion: |
| 2774 | Actions.CodeCompleteObjCAtExpression(getCurScope()); |
| 2775 | cutOffParsing(); |
| 2776 | return ExprError(); |
| 2777 | |
| 2778 | case tok::minus: |
| 2779 | case tok::plus: { |
| 2780 | tok::TokenKind Kind = Tok.getKind(); |
| 2781 | SourceLocation OpLoc = ConsumeToken(); |
| 2782 | |
| 2783 | if (!Tok.is(tok::numeric_constant)) { |
| 2784 | const char *Symbol = nullptr; |
| 2785 | switch (Kind) { |
| 2786 | case tok::minus: Symbol = "-"; break; |
| 2787 | case tok::plus: Symbol = "+"; break; |
| 2788 | default: llvm_unreachable("missing unary operator case"); |
| 2789 | } |
| 2790 | Diag(Tok, diag::err_nsnumber_nonliteral_unary) |
| 2791 | << Symbol; |
| 2792 | return ExprError(); |
| 2793 | } |
| 2794 | |
| 2795 | ExprResult Lit(Actions.ActOnNumericConstant(Tok)); |
| 2796 | if (Lit.isInvalid()) { |
| 2797 | return Lit; |
| 2798 | } |
| 2799 | ConsumeToken(); |
| 2800 | |
| 2801 | Lit = Actions.ActOnUnaryOp(getCurScope(), OpLoc, Kind, Lit.get()); |
| 2802 | if (Lit.isInvalid()) |
| 2803 | return Lit; |
| 2804 | |
| 2805 | return ParsePostfixExpressionSuffix( |
| 2806 | Actions.BuildObjCNumericLiteral(AtLoc, Lit.get())); |
| 2807 | } |
| 2808 | |
| 2809 | case tok::string_literal: |
| 2810 | case tok::wide_string_literal: |
| 2811 | return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); |
| 2812 | |
| 2813 | case tok::char_constant: |
| 2814 | return ParsePostfixExpressionSuffix(ParseObjCCharacterLiteral(AtLoc)); |
| 2815 | |
| 2816 | case tok::numeric_constant: |
| 2817 | return ParsePostfixExpressionSuffix(ParseObjCNumericLiteral(AtLoc)); |
| 2818 | |
| 2819 | case tok::kw_true: |
| 2820 | case tok::kw___objc_yes: |
| 2821 | return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc, true)); |
| 2822 | case tok::kw_false: |
| 2823 | case tok::kw___objc_no: |
| 2824 | return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc, false)); |
| 2825 | |
| 2826 | case tok::l_square: |
| 2827 | |
| 2828 | return ParsePostfixExpressionSuffix(ParseObjCArrayLiteral(AtLoc)); |
| 2829 | |
| 2830 | case tok::l_brace: |
| 2831 | |
| 2832 | return ParsePostfixExpressionSuffix(ParseObjCDictionaryLiteral(AtLoc)); |
| 2833 | |
| 2834 | case tok::l_paren: |
| 2835 | |
| 2836 | return ParsePostfixExpressionSuffix(ParseObjCBoxedExpr(AtLoc)); |
| 2837 | |
| 2838 | default: |
| 2839 | if (Tok.getIdentifierInfo() == nullptr) |
| 2840 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
| 2841 | |
| 2842 | switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { |
| 2843 | case tok::objc_encode: |
| 2844 | return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); |
| 2845 | case tok::objc_protocol: |
| 2846 | return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); |
| 2847 | case tok::objc_selector: |
| 2848 | return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); |
| 2849 | case tok::objc_available: |
| 2850 | return ParseAvailabilityCheckExpr(AtLoc); |
| 2851 | default: { |
| 2852 | const char *str = nullptr; |
| 2853 | |
| 2854 | |
| 2855 | |
| 2856 | if (GetLookAheadToken(1).is(tok::l_brace) && |
| 2857 | ExprStatementTokLoc == AtLoc) { |
| 2858 | char ch = Tok.getIdentifierInfo()->getNameStart()[0]; |
| 2859 | str = |
| 2860 | ch == 't' ? "try" |
| 2861 | : (ch == 'f' ? "finally" |
| 2862 | : (ch == 'a' ? "autoreleasepool" : nullptr)); |
| 2863 | } |
| 2864 | if (str) { |
| 2865 | SourceLocation kwLoc = Tok.getLocation(); |
| 2866 | return ExprError(Diag(AtLoc, diag::err_unexpected_at) << |
| 2867 | FixItHint::CreateReplacement(kwLoc, str)); |
| 2868 | } |
| 2869 | else |
| 2870 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
| 2871 | } |
| 2872 | } |
| 2873 | } |
| 2874 | } |
| 2875 | |
| 2876 | |
| 2877 | |
| 2878 | |
| 2879 | |
| 2880 | |
| 2881 | |
| 2882 | |
| 2883 | |
| 2884 | |
| 2885 | |
| 2886 | |
| 2887 | |
| 2888 | |
| 2889 | |
| 2890 | |
| 2891 | |
| 2892 | |
| 2893 | |
| 2894 | |
| 2895 | |
| 2896 | |
| 2897 | |
| 2898 | bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { |
| 2899 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 2900 | |
| 2901 | if (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_typename, |
| 2902 | tok::annot_cxxscope)) |
| 2903 | TryAnnotateTypeOrScopeToken(); |
| 2904 | |
| 2905 | if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) { |
| 2906 | |
| 2907 | |
| 2908 | |
| 2909 | |
| 2910 | |
| 2911 | ExprResult Receiver = Actions.CorrectDelayedTyposInExpr(ParseExpression()); |
| 2912 | if (Receiver.isInvalid()) |
| 2913 | return true; |
| 2914 | |
| 2915 | IsExpr = true; |
| 2916 | TypeOrExpr = Receiver.get(); |
| 2917 | return false; |
| 2918 | } |
| 2919 | |
| 2920 | |
| 2921 | |
| 2922 | |
| 2923 | |
| 2924 | DeclSpec DS(AttrFactory); |
| 2925 | ParseCXXSimpleTypeSpecifier(DS); |
| 2926 | |
| 2927 | if (Tok.is(tok::l_paren)) { |
| 2928 | |
| 2929 | |
| 2930 | |
| 2931 | |
| 2932 | |
| 2933 | |
| 2934 | |
| 2935 | |
| 2936 | |
| 2937 | |
| 2938 | |
| 2939 | |
| 2940 | ExprResult Receiver = ParseCXXTypeConstructExpression(DS); |
| 2941 | if (!Receiver.isInvalid()) |
| 2942 | Receiver = ParsePostfixExpressionSuffix(Receiver.get()); |
| 2943 | if (!Receiver.isInvalid()) |
| 2944 | Receiver = ParseRHSOfBinaryExpression(Receiver.get(), prec::Comma); |
| 2945 | if (Receiver.isInvalid()) |
| 2946 | return true; |
| 2947 | |
| 2948 | IsExpr = true; |
| 2949 | TypeOrExpr = Receiver.get(); |
| 2950 | return false; |
| 2951 | } |
| 2952 | |
| 2953 | |
| 2954 | |
| 2955 | |
| 2956 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); |
| 2957 | TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 2958 | if (Type.isInvalid()) |
| 2959 | return true; |
| 2960 | |
| 2961 | IsExpr = false; |
| 2962 | TypeOrExpr = Type.get().getAsOpaquePtr(); |
| 2963 | return false; |
| 2964 | } |
| 2965 | |
| 2966 | |
| 2967 | |
| 2968 | |
| 2969 | |
| 2970 | |
| 2971 | bool Parser::isSimpleObjCMessageExpression() { |
| 2972 | (0) . __assert_fail ("Tok.is(tok..l_square) && getLangOpts().ObjC && \"Incorrect start for isSimpleObjCMessageExpression\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2973, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_square) && getLangOpts().ObjC && |
| 2973 | (0) . __assert_fail ("Tok.is(tok..l_square) && getLangOpts().ObjC && \"Incorrect start for isSimpleObjCMessageExpression\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 2973, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Incorrect start for isSimpleObjCMessageExpression"); |
| 2974 | return GetLookAheadToken(1).is(tok::identifier) && |
| 2975 | GetLookAheadToken(2).is(tok::identifier); |
| 2976 | } |
| 2977 | |
| 2978 | bool Parser::isStartOfObjCClassMessageMissingOpenBracket() { |
| 2979 | if (!getLangOpts().ObjC || !NextToken().is(tok::identifier) || |
| 2980 | InMessageExpression) |
| 2981 | return false; |
| 2982 | |
| 2983 | ParsedType Type; |
| 2984 | |
| 2985 | if (Tok.is(tok::annot_typename)) |
| 2986 | Type = getTypeAnnotation(Tok); |
| 2987 | else if (Tok.is(tok::identifier)) |
| 2988 | Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(), |
| 2989 | getCurScope()); |
| 2990 | else |
| 2991 | return false; |
| 2992 | |
| 2993 | if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) { |
| 2994 | const Token &AfterNext = GetLookAheadToken(2); |
| 2995 | if (AfterNext.isOneOf(tok::colon, tok::r_square)) { |
| 2996 | if (Tok.is(tok::identifier)) |
| 2997 | TryAnnotateTypeOrScopeToken(); |
| 2998 | |
| 2999 | return Tok.is(tok::annot_typename); |
| 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | return false; |
| 3004 | } |
| 3005 | |
| 3006 | |
| 3007 | |
| 3008 | |
| 3009 | |
| 3010 | |
| 3011 | |
| 3012 | |
| 3013 | |
| 3014 | |
| 3015 | ExprResult Parser::ParseObjCMessageExpression() { |
| 3016 | (0) . __assert_fail ("Tok.is(tok..l_square) && \"'[' expected\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 3016, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_square) && "'[' expected"); |
| 3017 | SourceLocation LBracLoc = ConsumeBracket(); |
| 3018 | |
| 3019 | if (Tok.is(tok::code_completion)) { |
| 3020 | Actions.CodeCompleteObjCMessageReceiver(getCurScope()); |
| 3021 | cutOffParsing(); |
| 3022 | return ExprError(); |
| 3023 | } |
| 3024 | |
| 3025 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 3026 | |
| 3027 | if (getLangOpts().CPlusPlus) { |
| 3028 | |
| 3029 | |
| 3030 | |
| 3031 | |
| 3032 | |
| 3033 | |
| 3034 | if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && |
| 3035 | NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) |
| 3036 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), nullptr, |
| 3037 | nullptr); |
| 3038 | |
| 3039 | |
| 3040 | bool IsExpr; |
| 3041 | void *TypeOrExpr = nullptr; |
| 3042 | if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { |
| 3043 | SkipUntil(tok::r_square, StopAtSemi); |
| 3044 | return ExprError(); |
| 3045 | } |
| 3046 | |
| 3047 | if (IsExpr) |
| 3048 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), nullptr, |
| 3049 | static_cast<Expr *>(TypeOrExpr)); |
| 3050 | |
| 3051 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
| 3052 | ParsedType::getFromOpaquePtr(TypeOrExpr), |
| 3053 | nullptr); |
| 3054 | } |
| 3055 | |
| 3056 | if (Tok.is(tok::identifier)) { |
| 3057 | IdentifierInfo *Name = Tok.getIdentifierInfo(); |
| 3058 | SourceLocation NameLoc = Tok.getLocation(); |
| 3059 | ParsedType ReceiverType; |
| 3060 | switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, |
| 3061 | Name == Ident_super, |
| 3062 | NextToken().is(tok::period), |
| 3063 | ReceiverType)) { |
| 3064 | case Sema::ObjCSuperMessage: |
| 3065 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), nullptr, |
| 3066 | nullptr); |
| 3067 | |
| 3068 | case Sema::ObjCClassMessage: |
| 3069 | if (!ReceiverType) { |
| 3070 | SkipUntil(tok::r_square, StopAtSemi); |
| 3071 | return ExprError(); |
| 3072 | } |
| 3073 | |
| 3074 | ConsumeToken(); |
| 3075 | |
| 3076 | |
| 3077 | if (Tok.is(tok::less)) { |
| 3078 | SourceLocation NewEndLoc; |
| 3079 | TypeResult NewReceiverType |
| 3080 | = parseObjCTypeArgsAndProtocolQualifiers(NameLoc, ReceiverType, |
| 3081 | , |
| 3082 | NewEndLoc); |
| 3083 | if (!NewReceiverType.isUsable()) { |
| 3084 | SkipUntil(tok::r_square, StopAtSemi); |
| 3085 | return ExprError(); |
| 3086 | } |
| 3087 | |
| 3088 | ReceiverType = NewReceiverType.get(); |
| 3089 | } |
| 3090 | |
| 3091 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
| 3092 | ReceiverType, nullptr); |
| 3093 | |
| 3094 | case Sema::ObjCInstanceMessage: |
| 3095 | |
| 3096 | break; |
| 3097 | } |
| 3098 | } |
| 3099 | |
| 3100 | |
| 3101 | ExprResult Res = Actions.CorrectDelayedTyposInExpr(ParseExpression()); |
| 3102 | if (Res.isInvalid()) { |
| 3103 | SkipUntil(tok::r_square, StopAtSemi); |
| 3104 | return Res; |
| 3105 | } |
| 3106 | |
| 3107 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), nullptr, |
| 3108 | Res.get()); |
| 3109 | } |
| 3110 | |
| 3111 | |
| 3112 | |
| 3113 | |
| 3114 | |
| 3115 | |
| 3116 | |
| 3117 | |
| 3118 | |
| 3119 | |
| 3120 | |
| 3121 | |
| 3122 | |
| 3123 | |
| 3124 | |
| 3125 | |
| 3126 | |
| 3127 | |
| 3128 | |
| 3129 | |
| 3130 | |
| 3131 | |
| 3132 | |
| 3133 | |
| 3134 | |
| 3135 | |
| 3136 | |
| 3137 | |
| 3138 | |
| 3139 | |
| 3140 | |
| 3141 | |
| 3142 | |
| 3143 | |
| 3144 | |
| 3145 | |
| 3146 | |
| 3147 | |
| 3148 | |
| 3149 | ExprResult |
| 3150 | Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, |
| 3151 | SourceLocation SuperLoc, |
| 3152 | ParsedType ReceiverType, |
| 3153 | Expr *ReceiverExpr) { |
| 3154 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 3155 | |
| 3156 | if (Tok.is(tok::code_completion)) { |
| 3157 | if (SuperLoc.isValid()) |
| 3158 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, None, |
| 3159 | false); |
| 3160 | else if (ReceiverType) |
| 3161 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, None, |
| 3162 | false); |
| 3163 | else |
| 3164 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
| 3165 | None, false); |
| 3166 | cutOffParsing(); |
| 3167 | return ExprError(); |
| 3168 | } |
| 3169 | |
| 3170 | |
| 3171 | SourceLocation Loc; |
| 3172 | IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); |
| 3173 | |
| 3174 | SmallVector<IdentifierInfo *, 12> KeyIdents; |
| 3175 | SmallVector<SourceLocation, 12> KeyLocs; |
| 3176 | ExprVector KeyExprs; |
| 3177 | |
| 3178 | if (Tok.is(tok::colon)) { |
| 3179 | while (1) { |
| 3180 | |
| 3181 | KeyIdents.push_back(selIdent); |
| 3182 | KeyLocs.push_back(Loc); |
| 3183 | |
| 3184 | if (ExpectAndConsume(tok::colon)) { |
| 3185 | |
| 3186 | |
| 3187 | |
| 3188 | SkipUntil(tok::r_square, StopAtSemi); |
| 3189 | return ExprError(); |
| 3190 | } |
| 3191 | |
| 3192 | |
| 3193 | |
| 3194 | if (Tok.is(tok::code_completion)) { |
| 3195 | if (SuperLoc.isValid()) |
| 3196 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
| 3197 | KeyIdents, |
| 3198 | ); |
| 3199 | else if (ReceiverType) |
| 3200 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
| 3201 | KeyIdents, |
| 3202 | ); |
| 3203 | else |
| 3204 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
| 3205 | KeyIdents, |
| 3206 | ); |
| 3207 | |
| 3208 | cutOffParsing(); |
| 3209 | return ExprError(); |
| 3210 | } |
| 3211 | |
| 3212 | ExprResult Expr; |
| 3213 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 3214 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 3215 | Expr = ParseBraceInitializer(); |
| 3216 | } else |
| 3217 | Expr = ParseAssignmentExpression(); |
| 3218 | |
| 3219 | ExprResult Res(Expr); |
| 3220 | if (Res.isInvalid()) { |
| 3221 | |
| 3222 | |
| 3223 | |
| 3224 | SkipUntil(tok::r_square, StopAtSemi); |
| 3225 | return Res; |
| 3226 | } |
| 3227 | |
| 3228 | |
| 3229 | KeyExprs.push_back(Res.get()); |
| 3230 | |
| 3231 | |
| 3232 | if (Tok.is(tok::code_completion)) { |
| 3233 | if (SuperLoc.isValid()) |
| 3234 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
| 3235 | KeyIdents, |
| 3236 | ); |
| 3237 | else if (ReceiverType) |
| 3238 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
| 3239 | KeyIdents, |
| 3240 | ); |
| 3241 | else |
| 3242 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
| 3243 | KeyIdents, |
| 3244 | ); |
| 3245 | cutOffParsing(); |
| 3246 | return ExprError(); |
| 3247 | } |
| 3248 | |
| 3249 | |
| 3250 | selIdent = ParseObjCSelectorPiece(Loc); |
| 3251 | if (!selIdent && Tok.isNot(tok::colon)) |
| 3252 | break; |
| 3253 | |
| 3254 | } |
| 3255 | |
| 3256 | while (Tok.is(tok::comma)) { |
| 3257 | SourceLocation commaLoc = ConsumeToken(); |
| 3258 | |
| 3259 | ExprResult Res(ParseAssignmentExpression()); |
| 3260 | if (Tok.is(tok::colon)) |
| 3261 | Res = Actions.CorrectDelayedTyposInExpr(Res); |
| 3262 | if (Res.isInvalid()) { |
| 3263 | if (Tok.is(tok::colon)) { |
| 3264 | Diag(commaLoc, diag::note_extra_comma_message_arg) << |
| 3265 | FixItHint::CreateRemoval(commaLoc); |
| 3266 | } |
| 3267 | |
| 3268 | |
| 3269 | |
| 3270 | SkipUntil(tok::r_square, StopAtSemi); |
| 3271 | return Res; |
| 3272 | } |
| 3273 | |
| 3274 | |
| 3275 | KeyExprs.push_back(Res.get()); |
| 3276 | } |
| 3277 | } else if (!selIdent) { |
| 3278 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 3279 | |
| 3280 | |
| 3281 | |
| 3282 | |
| 3283 | SkipUntil(tok::r_square, StopAtSemi); |
| 3284 | return ExprError(); |
| 3285 | } |
| 3286 | |
| 3287 | if (Tok.isNot(tok::r_square)) { |
| 3288 | Diag(Tok, diag::err_expected) |
| 3289 | << (Tok.is(tok::identifier) ? tok::colon : tok::r_square); |
| 3290 | |
| 3291 | |
| 3292 | |
| 3293 | SkipUntil(tok::r_square, StopAtSemi); |
| 3294 | return ExprError(); |
| 3295 | } |
| 3296 | |
| 3297 | SourceLocation RBracLoc = ConsumeBracket(); |
| 3298 | |
| 3299 | unsigned nKeys = KeyIdents.size(); |
| 3300 | if (nKeys == 0) { |
| 3301 | KeyIdents.push_back(selIdent); |
| 3302 | KeyLocs.push_back(Loc); |
| 3303 | } |
| 3304 | Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); |
| 3305 | |
| 3306 | if (SuperLoc.isValid()) |
| 3307 | return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, |
| 3308 | LBracLoc, KeyLocs, RBracLoc, KeyExprs); |
| 3309 | else if (ReceiverType) |
| 3310 | return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, |
| 3311 | LBracLoc, KeyLocs, RBracLoc, KeyExprs); |
| 3312 | return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, |
| 3313 | LBracLoc, KeyLocs, RBracLoc, KeyExprs); |
| 3314 | } |
| 3315 | |
| 3316 | ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { |
| 3317 | ExprResult Res(ParseStringLiteralExpression()); |
| 3318 | if (Res.isInvalid()) return Res; |
| 3319 | |
| 3320 | |
| 3321 | |
| 3322 | |
| 3323 | SmallVector<SourceLocation, 4> AtLocs; |
| 3324 | ExprVector AtStrings; |
| 3325 | AtLocs.push_back(AtLoc); |
| 3326 | AtStrings.push_back(Res.get()); |
| 3327 | |
| 3328 | while (Tok.is(tok::at)) { |
| 3329 | AtLocs.push_back(ConsumeToken()); |
| 3330 | |
| 3331 | |
| 3332 | if (!isTokenStringLiteral()) |
| 3333 | return ExprError(Diag(Tok, diag::err_objc_concat_string)); |
| 3334 | |
| 3335 | ExprResult Lit(ParseStringLiteralExpression()); |
| 3336 | if (Lit.isInvalid()) |
| 3337 | return Lit; |
| 3338 | |
| 3339 | AtStrings.push_back(Lit.get()); |
| 3340 | } |
| 3341 | |
| 3342 | return Actions.ParseObjCStringLiteral(AtLocs.data(), AtStrings); |
| 3343 | } |
| 3344 | |
| 3345 | |
| 3346 | |
| 3347 | |
| 3348 | |
| 3349 | |
| 3350 | ExprResult Parser::ParseObjCBooleanLiteral(SourceLocation AtLoc, |
| 3351 | bool ArgValue) { |
| 3352 | SourceLocation EndLoc = ConsumeToken(); |
| 3353 | return Actions.ActOnObjCBoolLiteral(AtLoc, EndLoc, ArgValue); |
| 3354 | } |
| 3355 | |
| 3356 | |
| 3357 | |
| 3358 | |
| 3359 | ExprResult Parser::ParseObjCCharacterLiteral(SourceLocation AtLoc) { |
| 3360 | ExprResult Lit(Actions.ActOnCharacterConstant(Tok)); |
| 3361 | if (Lit.isInvalid()) { |
| 3362 | return Lit; |
| 3363 | } |
| 3364 | ConsumeToken(); |
| 3365 | return Actions.BuildObjCNumericLiteral(AtLoc, Lit.get()); |
| 3366 | } |
| 3367 | |
| 3368 | |
| 3369 | |
| 3370 | |
| 3371 | |
| 3372 | |
| 3373 | ExprResult Parser::ParseObjCNumericLiteral(SourceLocation AtLoc) { |
| 3374 | ExprResult Lit(Actions.ActOnNumericConstant(Tok)); |
| 3375 | if (Lit.isInvalid()) { |
| 3376 | return Lit; |
| 3377 | } |
| 3378 | ConsumeToken(); |
| 3379 | return Actions.BuildObjCNumericLiteral(AtLoc, Lit.get()); |
| 3380 | } |
| 3381 | |
| 3382 | |
| 3383 | |
| 3384 | |
| 3385 | ExprResult |
| 3386 | Parser::ParseObjCBoxedExpr(SourceLocation AtLoc) { |
| 3387 | if (Tok.isNot(tok::l_paren)) |
| 3388 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@"); |
| 3389 | |
| 3390 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3391 | T.consumeOpen(); |
| 3392 | ExprResult ValueExpr(ParseAssignmentExpression()); |
| 3393 | if (T.consumeClose()) |
| 3394 | return ExprError(); |
| 3395 | |
| 3396 | if (ValueExpr.isInvalid()) |
| 3397 | return ExprError(); |
| 3398 | |
| 3399 | |
| 3400 | |
| 3401 | SourceLocation LPLoc = T.getOpenLocation(), RPLoc = T.getCloseLocation(); |
| 3402 | ValueExpr = Actions.ActOnParenExpr(LPLoc, RPLoc, ValueExpr.get()); |
| 3403 | return Actions.BuildObjCBoxedExpr(SourceRange(AtLoc, RPLoc), |
| 3404 | ValueExpr.get()); |
| 3405 | } |
| 3406 | |
| 3407 | ExprResult Parser::ParseObjCArrayLiteral(SourceLocation AtLoc) { |
| 3408 | ExprVector ElementExprs; |
| 3409 | ConsumeBracket(); |
| 3410 | |
| 3411 | bool HasInvalidEltExpr = false; |
| 3412 | while (Tok.isNot(tok::r_square)) { |
| 3413 | |
| 3414 | ExprResult Res(ParseAssignmentExpression()); |
| 3415 | if (Res.isInvalid()) { |
| 3416 | |
| 3417 | |
| 3418 | |
| 3419 | SkipUntil(tok::r_square, StopAtSemi); |
| 3420 | return Res; |
| 3421 | } |
| 3422 | |
| 3423 | Res = Actions.CorrectDelayedTyposInExpr(Res.get()); |
| 3424 | if (Res.isInvalid()) |
| 3425 | HasInvalidEltExpr = true; |
| 3426 | |
| 3427 | |
| 3428 | if (Tok.is(tok::ellipsis)) |
| 3429 | Res = Actions.ActOnPackExpansion(Res.get(), ConsumeToken()); |
| 3430 | if (Res.isInvalid()) |
| 3431 | HasInvalidEltExpr = true; |
| 3432 | |
| 3433 | ElementExprs.push_back(Res.get()); |
| 3434 | |
| 3435 | if (Tok.is(tok::comma)) |
| 3436 | ConsumeToken(); |
| 3437 | else if (Tok.isNot(tok::r_square)) |
| 3438 | return ExprError(Diag(Tok, diag::err_expected_either) << tok::r_square |
| 3439 | << tok::comma); |
| 3440 | } |
| 3441 | SourceLocation EndLoc = ConsumeBracket(); |
| 3442 | |
| 3443 | if (HasInvalidEltExpr) |
| 3444 | return ExprError(); |
| 3445 | |
| 3446 | MultiExprArg Args(ElementExprs); |
| 3447 | return Actions.BuildObjCArrayLiteral(SourceRange(AtLoc, EndLoc), Args); |
| 3448 | } |
| 3449 | |
| 3450 | ExprResult Parser::ParseObjCDictionaryLiteral(SourceLocation AtLoc) { |
| 3451 | SmallVector<ObjCDictionaryElement, 4> Elements; |
| 3452 | ConsumeBrace(); |
| 3453 | bool HasInvalidEltExpr = false; |
| 3454 | while (Tok.isNot(tok::r_brace)) { |
| 3455 | |
| 3456 | ExprResult KeyExpr; |
| 3457 | { |
| 3458 | ColonProtectionRAIIObject X(*this); |
| 3459 | KeyExpr = ParseAssignmentExpression(); |
| 3460 | if (KeyExpr.isInvalid()) { |
| 3461 | |
| 3462 | |
| 3463 | |
| 3464 | SkipUntil(tok::r_brace, StopAtSemi); |
| 3465 | return KeyExpr; |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | if (ExpectAndConsume(tok::colon)) { |
| 3470 | SkipUntil(tok::r_brace, StopAtSemi); |
| 3471 | return ExprError(); |
| 3472 | } |
| 3473 | |
| 3474 | ExprResult ValueExpr(ParseAssignmentExpression()); |
| 3475 | if (ValueExpr.isInvalid()) { |
| 3476 | |
| 3477 | |
| 3478 | |
| 3479 | SkipUntil(tok::r_brace, StopAtSemi); |
| 3480 | return ValueExpr; |
| 3481 | } |
| 3482 | |
| 3483 | |
| 3484 | KeyExpr = Actions.CorrectDelayedTyposInExpr(KeyExpr.get()); |
| 3485 | ValueExpr = Actions.CorrectDelayedTyposInExpr(ValueExpr.get()); |
| 3486 | if (KeyExpr.isInvalid() || ValueExpr.isInvalid()) |
| 3487 | HasInvalidEltExpr = true; |
| 3488 | |
| 3489 | |
| 3490 | |
| 3491 | |
| 3492 | SourceLocation EllipsisLoc; |
| 3493 | if (getLangOpts().CPlusPlus) |
| 3494 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
| 3495 | |
| 3496 | |
| 3497 | |
| 3498 | ObjCDictionaryElement Element = { |
| 3499 | KeyExpr.get(), ValueExpr.get(), EllipsisLoc, None |
| 3500 | }; |
| 3501 | Elements.push_back(Element); |
| 3502 | |
| 3503 | if (!TryConsumeToken(tok::comma) && Tok.isNot(tok::r_brace)) |
| 3504 | return ExprError(Diag(Tok, diag::err_expected_either) << tok::r_brace |
| 3505 | << tok::comma); |
| 3506 | } |
| 3507 | SourceLocation EndLoc = ConsumeBrace(); |
| 3508 | |
| 3509 | if (HasInvalidEltExpr) |
| 3510 | return ExprError(); |
| 3511 | |
| 3512 | |
| 3513 | return Actions.BuildObjCDictionaryLiteral(SourceRange(AtLoc, EndLoc), |
| 3514 | Elements); |
| 3515 | } |
| 3516 | |
| 3517 | |
| 3518 | |
| 3519 | ExprResult |
| 3520 | Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { |
| 3521 | (0) . __assert_fail ("Tok.isObjCAtKeyword(tok..objc_encode) && \"Not an @encode expression!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 3521, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); |
| 3522 | |
| 3523 | SourceLocation EncLoc = ConsumeToken(); |
| 3524 | |
| 3525 | if (Tok.isNot(tok::l_paren)) |
| 3526 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); |
| 3527 | |
| 3528 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3529 | T.consumeOpen(); |
| 3530 | |
| 3531 | TypeResult Ty = ParseTypeName(); |
| 3532 | |
| 3533 | T.consumeClose(); |
| 3534 | |
| 3535 | if (Ty.isInvalid()) |
| 3536 | return ExprError(); |
| 3537 | |
| 3538 | return Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, T.getOpenLocation(), |
| 3539 | Ty.get(), T.getCloseLocation()); |
| 3540 | } |
| 3541 | |
| 3542 | |
| 3543 | |
| 3544 | ExprResult |
| 3545 | Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) { |
| 3546 | SourceLocation ProtoLoc = ConsumeToken(); |
| 3547 | |
| 3548 | if (Tok.isNot(tok::l_paren)) |
| 3549 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); |
| 3550 | |
| 3551 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3552 | T.consumeOpen(); |
| 3553 | |
| 3554 | if (expectIdentifier()) |
| 3555 | return ExprError(); |
| 3556 | |
| 3557 | IdentifierInfo *protocolId = Tok.getIdentifierInfo(); |
| 3558 | SourceLocation ProtoIdLoc = ConsumeToken(); |
| 3559 | |
| 3560 | T.consumeClose(); |
| 3561 | |
| 3562 | return Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, |
| 3563 | T.getOpenLocation(), ProtoIdLoc, |
| 3564 | T.getCloseLocation()); |
| 3565 | } |
| 3566 | |
| 3567 | |
| 3568 | |
| 3569 | ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { |
| 3570 | SourceLocation SelectorLoc = ConsumeToken(); |
| 3571 | |
| 3572 | if (Tok.isNot(tok::l_paren)) |
| 3573 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); |
| 3574 | |
| 3575 | SmallVector<IdentifierInfo *, 12> KeyIdents; |
| 3576 | SourceLocation sLoc; |
| 3577 | |
| 3578 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3579 | T.consumeOpen(); |
| 3580 | bool HasOptionalParen = Tok.is(tok::l_paren); |
| 3581 | if (HasOptionalParen) |
| 3582 | ConsumeParen(); |
| 3583 | |
| 3584 | if (Tok.is(tok::code_completion)) { |
| 3585 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents); |
| 3586 | cutOffParsing(); |
| 3587 | return ExprError(); |
| 3588 | } |
| 3589 | |
| 3590 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); |
| 3591 | if (!SelIdent && |
| 3592 | Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) |
| 3593 | return ExprError(Diag(Tok, diag::err_expected) << tok::identifier); |
| 3594 | |
| 3595 | KeyIdents.push_back(SelIdent); |
| 3596 | |
| 3597 | unsigned nColons = 0; |
| 3598 | if (Tok.isNot(tok::r_paren)) { |
| 3599 | while (1) { |
| 3600 | if (TryConsumeToken(tok::coloncolon)) { |
| 3601 | ++nColons; |
| 3602 | KeyIdents.push_back(nullptr); |
| 3603 | } else if (ExpectAndConsume(tok::colon)) |
| 3604 | return ExprError(); |
| 3605 | ++nColons; |
| 3606 | |
| 3607 | if (Tok.is(tok::r_paren)) |
| 3608 | break; |
| 3609 | |
| 3610 | if (Tok.is(tok::code_completion)) { |
| 3611 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents); |
| 3612 | cutOffParsing(); |
| 3613 | return ExprError(); |
| 3614 | } |
| 3615 | |
| 3616 | |
| 3617 | SourceLocation Loc; |
| 3618 | SelIdent = ParseObjCSelectorPiece(Loc); |
| 3619 | KeyIdents.push_back(SelIdent); |
| 3620 | if (!SelIdent && Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) |
| 3621 | break; |
| 3622 | } |
| 3623 | } |
| 3624 | if (HasOptionalParen && Tok.is(tok::r_paren)) |
| 3625 | ConsumeParen(); |
| 3626 | T.consumeClose(); |
| 3627 | Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); |
| 3628 | return Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, |
| 3629 | T.getOpenLocation(), |
| 3630 | T.getCloseLocation(), |
| 3631 | !HasOptionalParen); |
| 3632 | } |
| 3633 | |
| 3634 | void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) { |
| 3635 | |
| 3636 | Decl *MCDecl = LM.D; |
| 3637 | bool skip = MCDecl && |
| 3638 | ((parseMethod && !Actions.isObjCMethodDecl(MCDecl)) || |
| 3639 | (!parseMethod && Actions.isObjCMethodDecl(MCDecl))); |
| 3640 | if (skip) |
| 3641 | return; |
| 3642 | |
| 3643 | |
| 3644 | SourceLocation OrigLoc = Tok.getLocation(); |
| 3645 | |
| 3646 | (0) . __assert_fail ("!LM.Toks.empty() && \"ParseLexedObjCMethodDef - Empty body!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 3646, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!"); |
| 3647 | |
| 3648 | |
| 3649 | Token Eof; |
| 3650 | Eof.startToken(); |
| 3651 | Eof.setKind(tok::eof); |
| 3652 | Eof.setEofData(MCDecl); |
| 3653 | Eof.setLocation(OrigLoc); |
| 3654 | LM.Toks.push_back(Eof); |
| 3655 | |
| 3656 | |
| 3657 | LM.Toks.push_back(Tok); |
| 3658 | PP.EnterTokenStream(LM.Toks, true); |
| 3659 | |
| 3660 | |
| 3661 | ConsumeAnyToken(); |
| 3662 | |
| 3663 | (0) . __assert_fail ("Tok.isOneOf(tok..l_brace, tok..kw_try, tok..colon) && \"Inline objective-c method not starting with '{' or 'try' or '.'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 3664, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::l_brace, tok::kw_try, tok::colon) && |
| 3664 | (0) . __assert_fail ("Tok.isOneOf(tok..l_brace, tok..kw_try, tok..colon) && \"Inline objective-c method not starting with '{' or 'try' or '.'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseObjc.cpp", 3664, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Inline objective-c method not starting with '{' or 'try' or ':'"); |
| 3665 | |
| 3666 | ParseScope BodyScope(this, (parseMethod ? Scope::ObjCMethodScope : 0) | |
| 3667 | Scope::FnScope | Scope::DeclScope | |
| 3668 | Scope::CompoundStmtScope); |
| 3669 | |
| 3670 | |
| 3671 | |
| 3672 | if (parseMethod) |
| 3673 | Actions.ActOnStartOfObjCMethodDef(getCurScope(), MCDecl); |
| 3674 | else |
| 3675 | Actions.ActOnStartOfFunctionDef(getCurScope(), MCDecl); |
| 3676 | if (Tok.is(tok::kw_try)) |
| 3677 | ParseFunctionTryBlock(MCDecl, BodyScope); |
| 3678 | else { |
| 3679 | if (Tok.is(tok::colon)) |
| 3680 | ParseConstructorInitializer(MCDecl); |
| 3681 | else |
| 3682 | Actions.ActOnDefaultCtorInitializers(MCDecl); |
| 3683 | ParseFunctionStatementBody(MCDecl, BodyScope); |
| 3684 | } |
| 3685 | |
| 3686 | if (Tok.getLocation() != OrigLoc) { |
| 3687 | |
| 3688 | |
| 3689 | |
| 3690 | |
| 3691 | |
| 3692 | if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(), |
| 3693 | OrigLoc)) |
| 3694 | while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof)) |
| 3695 | ConsumeAnyToken(); |
| 3696 | } |
| 3697 | |
| 3698 | ConsumeAnyToken(); |
| 3699 | } |
| 3700 | |