| 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/DeclTemplate.h" |
| 16 | #include "clang/AST/PrettyDeclStackTrace.h" |
| 17 | #include "clang/Basic/Attributes.h" |
| 18 | #include "clang/Basic/CharInfo.h" |
| 19 | #include "clang/Basic/OperatorKinds.h" |
| 20 | #include "clang/Basic/TargetInfo.h" |
| 21 | #include "clang/Parse/ParseDiagnostic.h" |
| 22 | #include "clang/Parse/RAIIObjectsForParser.h" |
| 23 | #include "clang/Sema/DeclSpec.h" |
| 24 | #include "clang/Sema/ParsedTemplate.h" |
| 25 | #include "clang/Sema/Scope.h" |
| 26 | #include "llvm/ADT/SmallString.h" |
| 27 | |
| 28 | using namespace clang; |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | Parser::DeclGroupPtrTy Parser::ParseNamespace(DeclaratorContext Context, |
| 58 | SourceLocation &DeclEnd, |
| 59 | SourceLocation InlineLoc) { |
| 60 | (0) . __assert_fail ("Tok.is(tok..kw_namespace) && \"Not a namespace!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 60, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_namespace) && "Not a namespace!"); |
| 61 | SourceLocation NamespaceLoc = ConsumeToken(); |
| 62 | ObjCDeclContextSwitch ObjCDC(*this); |
| 63 | |
| 64 | if (Tok.is(tok::code_completion)) { |
| 65 | Actions.CodeCompleteNamespaceDecl(getCurScope()); |
| 66 | cutOffParsing(); |
| 67 | return nullptr; |
| 68 | } |
| 69 | |
| 70 | SourceLocation IdentLoc; |
| 71 | IdentifierInfo *Ident = nullptr; |
| 72 | InnerNamespaceInfoList ; |
| 73 | SourceLocation FirstNestedInlineLoc; |
| 74 | |
| 75 | ParsedAttributesWithRange attrs(AttrFactory); |
| 76 | SourceLocation attrLoc; |
| 77 | if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { |
| 78 | Diag(Tok.getLocation(), getLangOpts().CPlusPlus17 |
| 79 | ? diag::warn_cxx14_compat_ns_enum_attribute |
| 80 | : diag::ext_ns_enum_attribute) |
| 81 | << 0 ; |
| 82 | attrLoc = Tok.getLocation(); |
| 83 | ParseCXX11Attributes(attrs); |
| 84 | } |
| 85 | |
| 86 | if (Tok.is(tok::identifier)) { |
| 87 | Ident = Tok.getIdentifierInfo(); |
| 88 | IdentLoc = ConsumeToken(); |
| 89 | while (Tok.is(tok::coloncolon) && |
| 90 | (NextToken().is(tok::identifier) || |
| 91 | (NextToken().is(tok::kw_inline) && |
| 92 | GetLookAheadToken(2).is(tok::identifier)))) { |
| 93 | |
| 94 | InnerNamespaceInfo Info; |
| 95 | Info.NamespaceLoc = ConsumeToken(); |
| 96 | |
| 97 | if (Tok.is(tok::kw_inline)) { |
| 98 | Info.InlineLoc = ConsumeToken(); |
| 99 | if (FirstNestedInlineLoc.isInvalid()) |
| 100 | FirstNestedInlineLoc = Info.InlineLoc; |
| 101 | } |
| 102 | |
| 103 | Info.Ident = Tok.getIdentifierInfo(); |
| 104 | Info.IdentLoc = ConsumeToken(); |
| 105 | |
| 106 | ExtraNSs.push_back(Info); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | |
| 111 | if (!ExtraNSs.empty() && attrLoc.isValid()) |
| 112 | Diag(attrLoc, diag::err_unexpected_nested_namespace_attribute); |
| 113 | |
| 114 | |
| 115 | if (Tok.is(tok::kw___attribute)) { |
| 116 | attrLoc = Tok.getLocation(); |
| 117 | ParseGNUAttributes(attrs); |
| 118 | } |
| 119 | |
| 120 | if (Tok.is(tok::equal)) { |
| 121 | if (!Ident) { |
| 122 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 123 | |
| 124 | SkipUntil(tok::semi); |
| 125 | return nullptr; |
| 126 | } |
| 127 | if (attrLoc.isValid()) |
| 128 | Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias); |
| 129 | if (InlineLoc.isValid()) |
| 130 | Diag(InlineLoc, diag::err_inline_namespace_alias) |
| 131 | << FixItHint::CreateRemoval(InlineLoc); |
| 132 | Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); |
| 133 | return Actions.ConvertDeclToDeclGroup(NSAlias); |
| 134 | } |
| 135 | |
| 136 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 137 | if (T.consumeOpen()) { |
| 138 | if (Ident) |
| 139 | Diag(Tok, diag::err_expected) << tok::l_brace; |
| 140 | else |
| 141 | Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace; |
| 142 | return nullptr; |
| 143 | } |
| 144 | |
| 145 | if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() || |
| 146 | getCurScope()->isInObjcMethodScope() || getCurScope()->getBlockParent() || |
| 147 | getCurScope()->getFnParent()) { |
| 148 | Diag(T.getOpenLocation(), diag::err_namespace_nonnamespace_scope); |
| 149 | SkipUntil(tok::r_brace); |
| 150 | return nullptr; |
| 151 | } |
| 152 | |
| 153 | if (ExtraNSs.empty()) { |
| 154 | |
| 155 | } else if (InlineLoc.isValid()) { |
| 156 | Diag(InlineLoc, diag::err_inline_nested_namespace_definition); |
| 157 | } else if (getLangOpts().CPlusPlus2a) { |
| 158 | Diag(ExtraNSs[0].NamespaceLoc, |
| 159 | diag::warn_cxx14_compat_nested_namespace_definition); |
| 160 | if (FirstNestedInlineLoc.isValid()) |
| 161 | Diag(FirstNestedInlineLoc, |
| 162 | diag::warn_cxx17_compat_inline_nested_namespace_definition); |
| 163 | } else if (getLangOpts().CPlusPlus17) { |
| 164 | Diag(ExtraNSs[0].NamespaceLoc, |
| 165 | diag::warn_cxx14_compat_nested_namespace_definition); |
| 166 | if (FirstNestedInlineLoc.isValid()) |
| 167 | Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition); |
| 168 | } else { |
| 169 | TentativeParsingAction TPA(*this); |
| 170 | SkipUntil(tok::r_brace, StopBeforeMatch); |
| 171 | Token rBraceToken = Tok; |
| 172 | TPA.Revert(); |
| 173 | |
| 174 | if (!rBraceToken.is(tok::r_brace)) { |
| 175 | Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition) |
| 176 | << SourceRange(ExtraNSs.front().NamespaceLoc, |
| 177 | ExtraNSs.back().IdentLoc); |
| 178 | } else { |
| 179 | std::string NamespaceFix; |
| 180 | for (const auto &ExtraNS : ExtraNSs) { |
| 181 | NamespaceFix += " { "; |
| 182 | if (ExtraNS.InlineLoc.isValid()) |
| 183 | NamespaceFix += "inline "; |
| 184 | NamespaceFix += "namespace "; |
| 185 | NamespaceFix += ExtraNS.Ident->getName(); |
| 186 | } |
| 187 | |
| 188 | std::string RBraces; |
| 189 | for (unsigned i = 0, e = ExtraNSs.size(); i != e; ++i) |
| 190 | RBraces += "} "; |
| 191 | |
| 192 | Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition) |
| 193 | << FixItHint::CreateReplacement( |
| 194 | SourceRange(ExtraNSs.front().NamespaceLoc, |
| 195 | ExtraNSs.back().IdentLoc), |
| 196 | NamespaceFix) |
| 197 | << FixItHint::CreateInsertion(rBraceToken.getLocation(), RBraces); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | if (FirstNestedInlineLoc.isValid()) |
| 202 | Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | if (InlineLoc.isValid()) |
| 207 | Diag(InlineLoc, getLangOpts().CPlusPlus11 ? |
| 208 | diag::warn_cxx98_compat_inline_namespace : diag::ext_inline_namespace); |
| 209 | |
| 210 | |
| 211 | ParseScope NamespaceScope(this, Scope::DeclScope); |
| 212 | |
| 213 | UsingDirectiveDecl *ImplicitUsingDirectiveDecl = nullptr; |
| 214 | Decl *NamespcDecl = Actions.ActOnStartNamespaceDef( |
| 215 | getCurScope(), InlineLoc, NamespaceLoc, IdentLoc, Ident, |
| 216 | T.getOpenLocation(), attrs, ImplicitUsingDirectiveDecl); |
| 217 | |
| 218 | PrettyDeclStackTraceEntry CrashInfo(Actions.Context, NamespcDecl, |
| 219 | NamespaceLoc, "parsing namespace"); |
| 220 | |
| 221 | |
| 222 | |
| 223 | ParseInnerNamespace(ExtraNSs, 0, InlineLoc, attrs, T); |
| 224 | |
| 225 | |
| 226 | NamespaceScope.Exit(); |
| 227 | |
| 228 | DeclEnd = T.getCloseLocation(); |
| 229 | Actions.ActOnFinishNamespaceDef(NamespcDecl, DeclEnd); |
| 230 | |
| 231 | return Actions.ConvertDeclToDeclGroup(NamespcDecl, |
| 232 | ImplicitUsingDirectiveDecl); |
| 233 | } |
| 234 | |
| 235 | |
| 236 | void Parser::ParseInnerNamespace(const InnerNamespaceInfoList &InnerNSs, |
| 237 | unsigned int index, SourceLocation &InlineLoc, |
| 238 | ParsedAttributes &attrs, |
| 239 | BalancedDelimiterTracker &Tracker) { |
| 240 | if (index == InnerNSs.size()) { |
| 241 | while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) && |
| 242 | Tok.isNot(tok::eof)) { |
| 243 | ParsedAttributesWithRange attrs(AttrFactory); |
| 244 | MaybeParseCXX11Attributes(attrs); |
| 245 | ParseExternalDeclaration(attrs); |
| 246 | } |
| 247 | |
| 248 | |
| 249 | |
| 250 | Tracker.consumeClose(); |
| 251 | |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | ParseScope NamespaceScope(this, Scope::DeclScope); |
| 259 | UsingDirectiveDecl *ImplicitUsingDirectiveDecl = nullptr; |
| 260 | Decl *NamespcDecl = Actions.ActOnStartNamespaceDef( |
| 261 | getCurScope(), InnerNSs[index].InlineLoc, InnerNSs[index].NamespaceLoc, |
| 262 | InnerNSs[index].IdentLoc, InnerNSs[index].Ident, |
| 263 | Tracker.getOpenLocation(), attrs, ImplicitUsingDirectiveDecl); |
| 264 | (0) . __assert_fail ("!ImplicitUsingDirectiveDecl && \"nested namespace definition cannot define anonymous namespace\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 265, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!ImplicitUsingDirectiveDecl && |
| 265 | (0) . __assert_fail ("!ImplicitUsingDirectiveDecl && \"nested namespace definition cannot define anonymous namespace\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 265, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "nested namespace definition cannot define anonymous namespace"); |
| 266 | |
| 267 | ParseInnerNamespace(InnerNSs, ++index, InlineLoc, attrs, Tracker); |
| 268 | |
| 269 | NamespaceScope.Exit(); |
| 270 | Actions.ActOnFinishNamespaceDef(NamespcDecl, Tracker.getCloseLocation()); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | Decl *Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, |
| 277 | SourceLocation AliasLoc, |
| 278 | IdentifierInfo *Alias, |
| 279 | SourceLocation &DeclEnd) { |
| 280 | (0) . __assert_fail ("Tok.is(tok..equal) && \"Not equal token\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 280, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::equal) && "Not equal token"); |
| 281 | |
| 282 | ConsumeToken(); |
| 283 | |
| 284 | if (Tok.is(tok::code_completion)) { |
| 285 | Actions.CodeCompleteNamespaceAliasDecl(getCurScope()); |
| 286 | cutOffParsing(); |
| 287 | return nullptr; |
| 288 | } |
| 289 | |
| 290 | CXXScopeSpec SS; |
| 291 | |
| 292 | ParseOptionalCXXScopeSpecifier(SS, nullptr, , |
| 293 | , |
| 294 | , |
| 295 | , |
| 296 | ); |
| 297 | |
| 298 | if (Tok.isNot(tok::identifier)) { |
| 299 | Diag(Tok, diag::err_expected_namespace_name); |
| 300 | |
| 301 | SkipUntil(tok::semi); |
| 302 | return nullptr; |
| 303 | } |
| 304 | |
| 305 | if (SS.isInvalid()) { |
| 306 | |
| 307 | |
| 308 | SkipUntil(tok::semi); |
| 309 | return nullptr; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | IdentifierInfo *Ident = Tok.getIdentifierInfo(); |
| 314 | SourceLocation IdentLoc = ConsumeToken(); |
| 315 | |
| 316 | |
| 317 | DeclEnd = Tok.getLocation(); |
| 318 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name)) |
| 319 | SkipUntil(tok::semi); |
| 320 | |
| 321 | return Actions.ActOnNamespaceAliasDef(getCurScope(), NamespaceLoc, AliasLoc, |
| 322 | Alias, SS, IdentLoc, Ident); |
| 323 | } |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { |
| 333 | (0) . __assert_fail ("isTokenStringLiteral() && \"Not a string literal!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 333, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isTokenStringLiteral() && "Not a string literal!"); |
| 334 | ExprResult Lang = ParseStringLiteralExpression(false); |
| 335 | |
| 336 | ParseScope LinkageScope(this, Scope::DeclScope); |
| 337 | Decl *LinkageSpec = |
| 338 | Lang.isInvalid() |
| 339 | ? nullptr |
| 340 | : Actions.ActOnStartLinkageSpecification( |
| 341 | getCurScope(), DS.getSourceRange().getBegin(), Lang.get(), |
| 342 | Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation()); |
| 343 | |
| 344 | ParsedAttributesWithRange attrs(AttrFactory); |
| 345 | MaybeParseCXX11Attributes(attrs); |
| 346 | |
| 347 | if (Tok.isNot(tok::l_brace)) { |
| 348 | |
| 349 | |
| 350 | DS.SetRangeStart(SourceLocation()); |
| 351 | DS.SetRangeEnd(SourceLocation()); |
| 352 | |
| 353 | DS.setExternInLinkageSpec(true); |
| 354 | ParseExternalDeclaration(attrs, &DS); |
| 355 | return LinkageSpec ? Actions.ActOnFinishLinkageSpecification( |
| 356 | getCurScope(), LinkageSpec, SourceLocation()) |
| 357 | : nullptr; |
| 358 | } |
| 359 | |
| 360 | DS.abort(); |
| 361 | |
| 362 | ProhibitAttributes(attrs); |
| 363 | |
| 364 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 365 | T.consumeOpen(); |
| 366 | |
| 367 | unsigned NestedModules = 0; |
| 368 | while (true) { |
| 369 | switch (Tok.getKind()) { |
| 370 | case tok::annot_module_begin: |
| 371 | ++NestedModules; |
| 372 | ParseTopLevelDecl(); |
| 373 | continue; |
| 374 | |
| 375 | case tok::annot_module_end: |
| 376 | if (!NestedModules) |
| 377 | break; |
| 378 | --NestedModules; |
| 379 | ParseTopLevelDecl(); |
| 380 | continue; |
| 381 | |
| 382 | case tok::annot_module_include: |
| 383 | ParseTopLevelDecl(); |
| 384 | continue; |
| 385 | |
| 386 | case tok::eof: |
| 387 | break; |
| 388 | |
| 389 | case tok::r_brace: |
| 390 | if (!NestedModules) |
| 391 | break; |
| 392 | LLVM_FALLTHROUGH; |
| 393 | default: |
| 394 | ParsedAttributesWithRange attrs(AttrFactory); |
| 395 | MaybeParseCXX11Attributes(attrs); |
| 396 | ParseExternalDeclaration(attrs); |
| 397 | continue; |
| 398 | } |
| 399 | |
| 400 | break; |
| 401 | } |
| 402 | |
| 403 | T.consumeClose(); |
| 404 | return LinkageSpec ? Actions.ActOnFinishLinkageSpecification( |
| 405 | getCurScope(), LinkageSpec, T.getCloseLocation()) |
| 406 | : nullptr; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | Decl *Parser::ParseExportDeclaration() { |
| 416 | assert(Tok.is(tok::kw_export)); |
| 417 | SourceLocation ExportLoc = ConsumeToken(); |
| 418 | |
| 419 | ParseScope ExportScope(this, Scope::DeclScope); |
| 420 | Decl *ExportDecl = Actions.ActOnStartExportDecl( |
| 421 | getCurScope(), ExportLoc, |
| 422 | Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation()); |
| 423 | |
| 424 | if (Tok.isNot(tok::l_brace)) { |
| 425 | |
| 426 | ParsedAttributesWithRange Attrs(AttrFactory); |
| 427 | MaybeParseCXX11Attributes(Attrs); |
| 428 | MaybeParseMicrosoftAttributes(Attrs); |
| 429 | ParseExternalDeclaration(Attrs); |
| 430 | return Actions.ActOnFinishExportDecl(getCurScope(), ExportDecl, |
| 431 | SourceLocation()); |
| 432 | } |
| 433 | |
| 434 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 435 | T.consumeOpen(); |
| 436 | |
| 437 | |
| 438 | |
| 439 | if (Tok.is(tok::r_brace)) |
| 440 | Diag(ExportLoc, diag::err_export_empty) |
| 441 | << SourceRange(ExportLoc, Tok.getLocation()); |
| 442 | |
| 443 | while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) && |
| 444 | Tok.isNot(tok::eof)) { |
| 445 | ParsedAttributesWithRange Attrs(AttrFactory); |
| 446 | MaybeParseCXX11Attributes(Attrs); |
| 447 | MaybeParseMicrosoftAttributes(Attrs); |
| 448 | ParseExternalDeclaration(Attrs); |
| 449 | } |
| 450 | |
| 451 | T.consumeClose(); |
| 452 | return Actions.ActOnFinishExportDecl(getCurScope(), ExportDecl, |
| 453 | T.getCloseLocation()); |
| 454 | } |
| 455 | |
| 456 | |
| 457 | |
| 458 | Parser::DeclGroupPtrTy |
| 459 | Parser::ParseUsingDirectiveOrDeclaration(DeclaratorContext Context, |
| 460 | const ParsedTemplateInfo &TemplateInfo, |
| 461 | SourceLocation &DeclEnd, |
| 462 | ParsedAttributesWithRange &attrs) { |
| 463 | (0) . __assert_fail ("Tok.is(tok..kw_using) && \"Not using token\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 463, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_using) && "Not using token"); |
| 464 | ObjCDeclContextSwitch ObjCDC(*this); |
| 465 | |
| 466 | |
| 467 | SourceLocation UsingLoc = ConsumeToken(); |
| 468 | |
| 469 | if (Tok.is(tok::code_completion)) { |
| 470 | Actions.CodeCompleteUsing(getCurScope()); |
| 471 | cutOffParsing(); |
| 472 | return nullptr; |
| 473 | } |
| 474 | |
| 475 | |
| 476 | if (Tok.is(tok::kw_namespace)) { |
| 477 | |
| 478 | if (TemplateInfo.Kind) { |
| 479 | SourceRange R = TemplateInfo.getSourceRange(); |
| 480 | Diag(UsingLoc, diag::err_templated_using_directive_declaration) |
| 481 | << 0 << R << FixItHint::CreateRemoval(R); |
| 482 | } |
| 483 | |
| 484 | Decl *UsingDir = ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs); |
| 485 | return Actions.ConvertDeclToDeclGroup(UsingDir); |
| 486 | } |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | ProhibitAttributes(attrs); |
| 492 | |
| 493 | return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd, |
| 494 | AS_none); |
| 495 | } |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | Decl *Parser::ParseUsingDirective(DeclaratorContext Context, |
| 508 | SourceLocation UsingLoc, |
| 509 | SourceLocation &DeclEnd, |
| 510 | ParsedAttributes &attrs) { |
| 511 | (0) . __assert_fail ("Tok.is(tok..kw_namespace) && \"Not 'namespace' token\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 511, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); |
| 512 | |
| 513 | |
| 514 | SourceLocation NamespcLoc = ConsumeToken(); |
| 515 | |
| 516 | if (Tok.is(tok::code_completion)) { |
| 517 | Actions.CodeCompleteUsingDirective(getCurScope()); |
| 518 | cutOffParsing(); |
| 519 | return nullptr; |
| 520 | } |
| 521 | |
| 522 | CXXScopeSpec SS; |
| 523 | |
| 524 | ParseOptionalCXXScopeSpecifier(SS, nullptr, , |
| 525 | , |
| 526 | , |
| 527 | , |
| 528 | ); |
| 529 | |
| 530 | IdentifierInfo *NamespcName = nullptr; |
| 531 | SourceLocation IdentLoc = SourceLocation(); |
| 532 | |
| 533 | |
| 534 | if (Tok.isNot(tok::identifier)) { |
| 535 | Diag(Tok, diag::err_expected_namespace_name); |
| 536 | |
| 537 | SkipUntil(tok::semi); |
| 538 | |
| 539 | return nullptr; |
| 540 | } |
| 541 | |
| 542 | if (SS.isInvalid()) { |
| 543 | |
| 544 | |
| 545 | SkipUntil(tok::semi); |
| 546 | return nullptr; |
| 547 | } |
| 548 | |
| 549 | |
| 550 | NamespcName = Tok.getIdentifierInfo(); |
| 551 | IdentLoc = ConsumeToken(); |
| 552 | |
| 553 | |
| 554 | bool GNUAttr = false; |
| 555 | if (Tok.is(tok::kw___attribute)) { |
| 556 | GNUAttr = true; |
| 557 | ParseGNUAttributes(attrs); |
| 558 | } |
| 559 | |
| 560 | |
| 561 | DeclEnd = Tok.getLocation(); |
| 562 | if (ExpectAndConsume(tok::semi, |
| 563 | GNUAttr ? diag::err_expected_semi_after_attribute_list |
| 564 | : diag::err_expected_semi_after_namespace_name)) |
| 565 | SkipUntil(tok::semi); |
| 566 | |
| 567 | return Actions.ActOnUsingDirective(getCurScope(), UsingLoc, NamespcLoc, SS, |
| 568 | IdentLoc, NamespcName, attrs); |
| 569 | } |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | bool Parser::ParseUsingDeclarator(DeclaratorContext Context, |
| 577 | UsingDeclarator &D) { |
| 578 | D.clear(); |
| 579 | |
| 580 | |
| 581 | |
| 582 | TryConsumeToken(tok::kw_typename, D.TypenameLoc); |
| 583 | |
| 584 | if (Tok.is(tok::kw___super)) { |
| 585 | Diag(Tok.getLocation(), diag::err_super_in_using_declaration); |
| 586 | return true; |
| 587 | } |
| 588 | |
| 589 | |
| 590 | IdentifierInfo *LastII = nullptr; |
| 591 | ParseOptionalCXXScopeSpecifier(D.SS, nullptr, , |
| 592 | , |
| 593 | , |
| 594 | &LastII); |
| 595 | if (D.SS.isInvalid()) |
| 596 | return true; |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | if (getLangOpts().CPlusPlus11 && |
| 609 | Context == DeclaratorContext::MemberContext && |
| 610 | Tok.is(tok::identifier) && |
| 611 | (NextToken().is(tok::semi) || NextToken().is(tok::comma) || |
| 612 | NextToken().is(tok::ellipsis)) && |
| 613 | D.SS.isNotEmpty() && LastII == Tok.getIdentifierInfo() && |
| 614 | !D.SS.getScopeRep()->getAsNamespace() && |
| 615 | !D.SS.getScopeRep()->getAsNamespaceAlias()) { |
| 616 | SourceLocation IdLoc = ConsumeToken(); |
| 617 | ParsedType Type = |
| 618 | Actions.getInheritingConstructorName(D.SS, IdLoc, *LastII); |
| 619 | D.Name.setConstructorName(Type, IdLoc, IdLoc); |
| 620 | } else { |
| 621 | if (ParseUnqualifiedId( |
| 622 | D.SS, , |
| 623 | , |
| 624 | !(Tok.is(tok::identifier) && |
| 625 | NextToken().is(tok::equal)), |
| 626 | , |
| 627 | nullptr, nullptr, D.Name)) |
| 628 | return true; |
| 629 | } |
| 630 | |
| 631 | if (TryConsumeToken(tok::ellipsis, D.EllipsisLoc)) |
| 632 | Diag(Tok.getLocation(), getLangOpts().CPlusPlus17 ? |
| 633 | diag::warn_cxx17_compat_using_declaration_pack : |
| 634 | diag::ext_using_declaration_pack); |
| 635 | |
| 636 | return false; |
| 637 | } |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | Parser::DeclGroupPtrTy |
| 656 | Parser::ParseUsingDeclaration(DeclaratorContext Context, |
| 657 | const ParsedTemplateInfo &TemplateInfo, |
| 658 | SourceLocation UsingLoc, SourceLocation &DeclEnd, |
| 659 | AccessSpecifier AS) { |
| 660 | |
| 661 | |
| 662 | ParsedAttributesWithRange MisplacedAttrs(AttrFactory); |
| 663 | MaybeParseCXX11Attributes(MisplacedAttrs); |
| 664 | |
| 665 | UsingDeclarator D; |
| 666 | bool InvalidDeclarator = ParseUsingDeclarator(Context, D); |
| 667 | |
| 668 | ParsedAttributesWithRange Attrs(AttrFactory); |
| 669 | MaybeParseGNUAttributes(Attrs); |
| 670 | MaybeParseCXX11Attributes(Attrs); |
| 671 | |
| 672 | |
| 673 | if (Tok.is(tok::equal)) { |
| 674 | if (InvalidDeclarator) { |
| 675 | SkipUntil(tok::semi); |
| 676 | return nullptr; |
| 677 | } |
| 678 | |
| 679 | |
| 680 | |
| 681 | if (MisplacedAttrs.Range.isValid()) { |
| 682 | Diag(MisplacedAttrs.Range.getBegin(), diag::err_attributes_not_allowed) |
| 683 | << FixItHint::CreateInsertionFromRange( |
| 684 | Tok.getLocation(), |
| 685 | CharSourceRange::getTokenRange(MisplacedAttrs.Range)) |
| 686 | << FixItHint::CreateRemoval(MisplacedAttrs.Range); |
| 687 | Attrs.takeAllFrom(MisplacedAttrs); |
| 688 | } |
| 689 | |
| 690 | Decl *DeclFromDeclSpec = nullptr; |
| 691 | Decl *AD = ParseAliasDeclarationAfterDeclarator( |
| 692 | TemplateInfo, UsingLoc, D, DeclEnd, AS, Attrs, &DeclFromDeclSpec); |
| 693 | return Actions.ConvertDeclToDeclGroup(AD, DeclFromDeclSpec); |
| 694 | } |
| 695 | |
| 696 | |
| 697 | |
| 698 | ProhibitAttributes(MisplacedAttrs); |
| 699 | ProhibitAttributes(Attrs); |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | if (TemplateInfo.Kind) { |
| 705 | SourceRange R = TemplateInfo.getSourceRange(); |
| 706 | Diag(UsingLoc, diag::err_templated_using_directive_declaration) |
| 707 | << 1 << R << FixItHint::CreateRemoval(R); |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | return nullptr; |
| 713 | } |
| 714 | |
| 715 | SmallVector<Decl *, 8> DeclsInGroup; |
| 716 | while (true) { |
| 717 | |
| 718 | MaybeParseGNUAttributes(Attrs); |
| 719 | |
| 720 | if (InvalidDeclarator) |
| 721 | SkipUntil(tok::comma, tok::semi, StopBeforeMatch); |
| 722 | else { |
| 723 | |
| 724 | |
| 725 | if (D.TypenameLoc.isValid() && |
| 726 | D.Name.getKind() != UnqualifiedIdKind::IK_Identifier) { |
| 727 | Diag(D.Name.getSourceRange().getBegin(), |
| 728 | diag::err_typename_identifiers_only) |
| 729 | << FixItHint::CreateRemoval(SourceRange(D.TypenameLoc)); |
| 730 | |
| 731 | D.TypenameLoc = SourceLocation(); |
| 732 | } |
| 733 | |
| 734 | Decl *UD = Actions.ActOnUsingDeclaration(getCurScope(), AS, UsingLoc, |
| 735 | D.TypenameLoc, D.SS, D.Name, |
| 736 | D.EllipsisLoc, Attrs); |
| 737 | if (UD) |
| 738 | DeclsInGroup.push_back(UD); |
| 739 | } |
| 740 | |
| 741 | if (!TryConsumeToken(tok::comma)) |
| 742 | break; |
| 743 | |
| 744 | |
| 745 | Attrs.clear(); |
| 746 | InvalidDeclarator = ParseUsingDeclarator(Context, D); |
| 747 | } |
| 748 | |
| 749 | if (DeclsInGroup.size() > 1) |
| 750 | Diag(Tok.getLocation(), getLangOpts().CPlusPlus17 ? |
| 751 | diag::warn_cxx17_compat_multi_using_declaration : |
| 752 | diag::ext_multi_using_declaration); |
| 753 | |
| 754 | |
| 755 | DeclEnd = Tok.getLocation(); |
| 756 | if (ExpectAndConsume(tok::semi, diag::err_expected_after, |
| 757 | !Attrs.empty() ? "attributes list" |
| 758 | : "using declaration")) |
| 759 | SkipUntil(tok::semi); |
| 760 | |
| 761 | return Actions.BuildDeclaratorGroup(DeclsInGroup); |
| 762 | } |
| 763 | |
| 764 | Decl *Parser::ParseAliasDeclarationAfterDeclarator( |
| 765 | const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc, |
| 766 | UsingDeclarator &D, SourceLocation &DeclEnd, AccessSpecifier AS, |
| 767 | ParsedAttributes &Attrs, Decl **OwnedType) { |
| 768 | if (ExpectAndConsume(tok::equal)) { |
| 769 | SkipUntil(tok::semi); |
| 770 | return nullptr; |
| 771 | } |
| 772 | |
| 773 | Diag(Tok.getLocation(), getLangOpts().CPlusPlus11 ? |
| 774 | diag::warn_cxx98_compat_alias_declaration : |
| 775 | diag::ext_alias_declaration); |
| 776 | |
| 777 | |
| 778 | int SpecKind = -1; |
| 779 | if (TemplateInfo.Kind == ParsedTemplateInfo::Template && |
| 780 | D.Name.getKind() == UnqualifiedIdKind::IK_TemplateId) |
| 781 | SpecKind = 0; |
| 782 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) |
| 783 | SpecKind = 1; |
| 784 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) |
| 785 | SpecKind = 2; |
| 786 | if (SpecKind != -1) { |
| 787 | SourceRange Range; |
| 788 | if (SpecKind == 0) |
| 789 | Range = SourceRange(D.Name.TemplateId->LAngleLoc, |
| 790 | D.Name.TemplateId->RAngleLoc); |
| 791 | else |
| 792 | Range = TemplateInfo.getSourceRange(); |
| 793 | Diag(Range.getBegin(), diag::err_alias_declaration_specialization) |
| 794 | << SpecKind << Range; |
| 795 | SkipUntil(tok::semi); |
| 796 | return nullptr; |
| 797 | } |
| 798 | |
| 799 | |
| 800 | if (D.Name.getKind() != UnqualifiedIdKind::IK_Identifier) { |
| 801 | Diag(D.Name.StartLocation, diag::err_alias_declaration_not_identifier); |
| 802 | |
| 803 | SkipUntil(tok::semi); |
| 804 | return nullptr; |
| 805 | } else if (D.TypenameLoc.isValid()) |
| 806 | Diag(D.TypenameLoc, diag::err_alias_declaration_not_identifier) |
| 807 | << FixItHint::CreateRemoval(SourceRange( |
| 808 | D.TypenameLoc, |
| 809 | D.SS.isNotEmpty() ? D.SS.getEndLoc() : D.TypenameLoc)); |
| 810 | else if (D.SS.isNotEmpty()) |
| 811 | Diag(D.SS.getBeginLoc(), diag::err_alias_declaration_not_identifier) |
| 812 | << FixItHint::CreateRemoval(D.SS.getRange()); |
| 813 | if (D.EllipsisLoc.isValid()) |
| 814 | Diag(D.EllipsisLoc, diag::err_alias_declaration_pack_expansion) |
| 815 | << FixItHint::CreateRemoval(SourceRange(D.EllipsisLoc)); |
| 816 | |
| 817 | Decl *DeclFromDeclSpec = nullptr; |
| 818 | TypeResult TypeAlias = ParseTypeName( |
| 819 | nullptr, |
| 820 | TemplateInfo.Kind ? DeclaratorContext::AliasTemplateContext |
| 821 | : DeclaratorContext::AliasDeclContext, |
| 822 | AS, &DeclFromDeclSpec, &Attrs); |
| 823 | if (OwnedType) |
| 824 | *OwnedType = DeclFromDeclSpec; |
| 825 | |
| 826 | |
| 827 | DeclEnd = Tok.getLocation(); |
| 828 | if (ExpectAndConsume(tok::semi, diag::err_expected_after, |
| 829 | !Attrs.empty() ? "attributes list" |
| 830 | : "alias declaration")) |
| 831 | SkipUntil(tok::semi); |
| 832 | |
| 833 | TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; |
| 834 | MultiTemplateParamsArg TemplateParamsArg( |
| 835 | TemplateParams ? TemplateParams->data() : nullptr, |
| 836 | TemplateParams ? TemplateParams->size() : 0); |
| 837 | return Actions.ActOnAliasDeclaration(getCurScope(), AS, TemplateParamsArg, |
| 838 | UsingLoc, D.Name, Attrs, TypeAlias, |
| 839 | DeclFromDeclSpec); |
| 840 | } |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ |
| 851 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_static_assert, tok..kw__Static_assert) && \"Not a static_assert declaration\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 852, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert) && |
| 852 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_static_assert, tok..kw__Static_assert) && \"Not a static_assert declaration\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 852, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Not a static_assert declaration"); |
| 853 | |
| 854 | if (Tok.is(tok::kw__Static_assert) && !getLangOpts().C11) |
| 855 | Diag(Tok, diag::ext_c11_static_assert); |
| 856 | if (Tok.is(tok::kw_static_assert)) |
| 857 | Diag(Tok, diag::warn_cxx98_compat_static_assert); |
| 858 | |
| 859 | SourceLocation StaticAssertLoc = ConsumeToken(); |
| 860 | |
| 861 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 862 | if (T.consumeOpen()) { |
| 863 | Diag(Tok, diag::err_expected) << tok::l_paren; |
| 864 | SkipMalformedDecl(); |
| 865 | return nullptr; |
| 866 | } |
| 867 | |
| 868 | EnterExpressionEvaluationContext ConstantEvaluated( |
| 869 | Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 870 | ExprResult AssertExpr(ParseConstantExpressionInExprEvalContext()); |
| 871 | if (AssertExpr.isInvalid()) { |
| 872 | SkipMalformedDecl(); |
| 873 | return nullptr; |
| 874 | } |
| 875 | |
| 876 | ExprResult AssertMessage; |
| 877 | if (Tok.is(tok::r_paren)) { |
| 878 | Diag(Tok, getLangOpts().CPlusPlus17 |
| 879 | ? diag::warn_cxx14_compat_static_assert_no_message |
| 880 | : diag::ext_static_assert_no_message) |
| 881 | << (getLangOpts().CPlusPlus17 |
| 882 | ? FixItHint() |
| 883 | : FixItHint::CreateInsertion(Tok.getLocation(), ", \"\"")); |
| 884 | } else { |
| 885 | if (ExpectAndConsume(tok::comma)) { |
| 886 | SkipUntil(tok::semi); |
| 887 | return nullptr; |
| 888 | } |
| 889 | |
| 890 | if (!isTokenStringLiteral()) { |
| 891 | Diag(Tok, diag::err_expected_string_literal) |
| 892 | << ; |
| 893 | SkipMalformedDecl(); |
| 894 | return nullptr; |
| 895 | } |
| 896 | |
| 897 | AssertMessage = ParseStringLiteralExpression(); |
| 898 | if (AssertMessage.isInvalid()) { |
| 899 | SkipMalformedDecl(); |
| 900 | return nullptr; |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | T.consumeClose(); |
| 905 | |
| 906 | DeclEnd = Tok.getLocation(); |
| 907 | ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert); |
| 908 | |
| 909 | return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, |
| 910 | AssertExpr.get(), |
| 911 | AssertMessage.get(), |
| 912 | T.getCloseLocation()); |
| 913 | } |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | SourceLocation Parser::ParseDecltypeSpecifier(DeclSpec &DS) { |
| 921 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_decltype, tok..annot_decltype) && \"Not a decltype specifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 922, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::kw_decltype, tok::annot_decltype) |
| 922 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_decltype, tok..annot_decltype) && \"Not a decltype specifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 922, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && "Not a decltype specifier"); |
| 923 | |
| 924 | ExprResult Result; |
| 925 | SourceLocation StartLoc = Tok.getLocation(); |
| 926 | SourceLocation EndLoc; |
| 927 | |
| 928 | if (Tok.is(tok::annot_decltype)) { |
| 929 | Result = getExprAnnotation(Tok); |
| 930 | EndLoc = Tok.getAnnotationEndLoc(); |
| 931 | ConsumeAnnotationToken(); |
| 932 | if (Result.isInvalid()) { |
| 933 | DS.SetTypeSpecError(); |
| 934 | return EndLoc; |
| 935 | } |
| 936 | } else { |
| 937 | if (Tok.getIdentifierInfo()->isStr("decltype")) |
| 938 | Diag(Tok, diag::warn_cxx98_compat_decltype); |
| 939 | |
| 940 | ConsumeToken(); |
| 941 | |
| 942 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 943 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 944 | "decltype", tok::r_paren)) { |
| 945 | DS.SetTypeSpecError(); |
| 946 | return T.getOpenLocation() == Tok.getLocation() ? |
| 947 | StartLoc : T.getOpenLocation(); |
| 948 | } |
| 949 | |
| 950 | |
| 951 | if (Tok.is(tok::kw_auto)) { |
| 952 | |
| 953 | |
| 954 | |
| 955 | Diag(Tok.getLocation(), |
| 956 | getLangOpts().CPlusPlus14 |
| 957 | ? diag::warn_cxx11_compat_decltype_auto_type_specifier |
| 958 | : diag::ext_decltype_auto_type_specifier); |
| 959 | ConsumeToken(); |
| 960 | } else { |
| 961 | |
| 962 | |
| 963 | |
| 964 | |
| 965 | EnterExpressionEvaluationContext Unevaluated( |
| 966 | Actions, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, |
| 967 | Sema::ExpressionEvaluationContextRecord::EK_Decltype); |
| 968 | Result = |
| 969 | Actions.CorrectDelayedTyposInExpr(ParseExpression(), [](Expr *E) { |
| 970 | return E->hasPlaceholderType() ? ExprError() : E; |
| 971 | }); |
| 972 | if (Result.isInvalid()) { |
| 973 | DS.SetTypeSpecError(); |
| 974 | if (SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch)) { |
| 975 | EndLoc = ConsumeParen(); |
| 976 | } else { |
| 977 | if (PP.isBacktrackEnabled() && Tok.is(tok::semi)) { |
| 978 | |
| 979 | PP.RevertCachedTokens(2); |
| 980 | ConsumeToken(); |
| 981 | EndLoc = ConsumeAnyToken(); |
| 982 | assert(Tok.is(tok::semi)); |
| 983 | } else { |
| 984 | EndLoc = Tok.getLocation(); |
| 985 | } |
| 986 | } |
| 987 | return EndLoc; |
| 988 | } |
| 989 | |
| 990 | Result = Actions.ActOnDecltypeExpression(Result.get()); |
| 991 | } |
| 992 | |
| 993 | |
| 994 | T.consumeClose(); |
| 995 | if (T.getCloseLocation().isInvalid()) { |
| 996 | DS.SetTypeSpecError(); |
| 997 | |
| 998 | |
| 999 | return T.getCloseLocation(); |
| 1000 | } |
| 1001 | |
| 1002 | if (Result.isInvalid()) { |
| 1003 | DS.SetTypeSpecError(); |
| 1004 | return T.getCloseLocation(); |
| 1005 | } |
| 1006 | |
| 1007 | EndLoc = T.getCloseLocation(); |
| 1008 | } |
| 1009 | assert(!Result.isInvalid()); |
| 1010 | |
| 1011 | const char *PrevSpec = nullptr; |
| 1012 | unsigned DiagID; |
| 1013 | const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy(); |
| 1014 | |
| 1015 | if (Result.get() |
| 1016 | ? DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, |
| 1017 | DiagID, Result.get(), Policy) |
| 1018 | : DS.SetTypeSpecType(DeclSpec::TST_decltype_auto, StartLoc, PrevSpec, |
| 1019 | DiagID, Policy)) { |
| 1020 | Diag(StartLoc, DiagID) << PrevSpec; |
| 1021 | DS.SetTypeSpecError(); |
| 1022 | } |
| 1023 | return EndLoc; |
| 1024 | } |
| 1025 | |
| 1026 | void Parser::AnnotateExistingDecltypeSpecifier(const DeclSpec& DS, |
| 1027 | SourceLocation StartLoc, |
| 1028 | SourceLocation EndLoc) { |
| 1029 | |
| 1030 | if (PP.isBacktrackEnabled()) |
| 1031 | PP.RevertCachedTokens(1); |
| 1032 | else |
| 1033 | PP.EnterToken(Tok); |
| 1034 | |
| 1035 | Tok.setKind(tok::annot_decltype); |
| 1036 | setExprAnnotation(Tok, |
| 1037 | DS.getTypeSpecType() == TST_decltype ? DS.getRepAsExpr() : |
| 1038 | DS.getTypeSpecType() == TST_decltype_auto ? ExprResult() : |
| 1039 | ExprError()); |
| 1040 | Tok.setAnnotationEndLoc(EndLoc); |
| 1041 | Tok.setLocation(StartLoc); |
| 1042 | PP.AnnotateCachedTokens(Tok); |
| 1043 | } |
| 1044 | |
| 1045 | void Parser::ParseUnderlyingTypeSpecifier(DeclSpec &DS) { |
| 1046 | (0) . __assert_fail ("Tok.is(tok..kw___underlying_type) && \"Not an underlying type specifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 1047, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw___underlying_type) && |
| 1047 | (0) . __assert_fail ("Tok.is(tok..kw___underlying_type) && \"Not an underlying type specifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 1047, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Not an underlying type specifier"); |
| 1048 | |
| 1049 | SourceLocation StartLoc = ConsumeToken(); |
| 1050 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1051 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1052 | "__underlying_type", tok::r_paren)) { |
| 1053 | return; |
| 1054 | } |
| 1055 | |
| 1056 | TypeResult Result = ParseTypeName(); |
| 1057 | if (Result.isInvalid()) { |
| 1058 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | T.consumeClose(); |
| 1064 | if (T.getCloseLocation().isInvalid()) |
| 1065 | return; |
| 1066 | |
| 1067 | const char *PrevSpec = nullptr; |
| 1068 | unsigned DiagID; |
| 1069 | if (DS.SetTypeSpecType(DeclSpec::TST_underlyingType, StartLoc, PrevSpec, |
| 1070 | DiagID, Result.get(), |
| 1071 | Actions.getASTContext().getPrintingPolicy())) |
| 1072 | Diag(StartLoc, DiagID) << PrevSpec; |
| 1073 | DS.setTypeofParensRange(T.getRange()); |
| 1074 | } |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &BaseLoc, |
| 1095 | SourceLocation &EndLocation) { |
| 1096 | |
| 1097 | if (Tok.is(tok::kw_typename)) { |
| 1098 | Diag(Tok, diag::err_expected_class_name_not_template) |
| 1099 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 1100 | ConsumeToken(); |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | CXXScopeSpec SS; |
| 1105 | ParseOptionalCXXScopeSpecifier(SS, nullptr, ); |
| 1106 | |
| 1107 | BaseLoc = Tok.getLocation(); |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | if (Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) { |
| 1113 | if (SS.isNotEmpty()) |
| 1114 | Diag(SS.getBeginLoc(), diag::err_unexpected_scope_on_base_decltype) |
| 1115 | << FixItHint::CreateRemoval(SS.getRange()); |
| 1116 | |
| 1117 | DeclSpec DS(AttrFactory); |
| 1118 | |
| 1119 | EndLocation = ParseDecltypeSpecifier(DS); |
| 1120 | |
| 1121 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); |
| 1122 | return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 1123 | } |
| 1124 | |
| 1125 | |
| 1126 | if (Tok.is(tok::annot_template_id)) { |
| 1127 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
| 1128 | if (TemplateId->Kind == TNK_Type_template || |
| 1129 | TemplateId->Kind == TNK_Dependent_template_name) { |
| 1130 | AnnotateTemplateIdTokenAsType(); |
| 1131 | |
| 1132 | type failed") ? static_cast (0) . __assert_fail ("Tok.is(tok..annot_typename) && \"template-id -> type failed\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 1132, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
| 1133 | ParsedType Type = getTypeAnnotation(Tok); |
| 1134 | EndLocation = Tok.getAnnotationEndLoc(); |
| 1135 | ConsumeAnnotationToken(); |
| 1136 | |
| 1137 | if (Type) |
| 1138 | return Type; |
| 1139 | return true; |
| 1140 | } |
| 1141 | |
| 1142 | |
| 1143 | } |
| 1144 | |
| 1145 | if (Tok.isNot(tok::identifier)) { |
| 1146 | Diag(Tok, diag::err_expected_class_name); |
| 1147 | return true; |
| 1148 | } |
| 1149 | |
| 1150 | IdentifierInfo *Id = Tok.getIdentifierInfo(); |
| 1151 | SourceLocation IdLoc = ConsumeToken(); |
| 1152 | |
| 1153 | if (Tok.is(tok::less)) { |
| 1154 | |
| 1155 | |
| 1156 | TemplateNameKind TNK = TNK_Type_template; |
| 1157 | TemplateTy Template; |
| 1158 | if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc, getCurScope(), |
| 1159 | &SS, Template, TNK)) { |
| 1160 | Diag(IdLoc, diag::err_unknown_template_name) |
| 1161 | << Id; |
| 1162 | } |
| 1163 | |
| 1164 | if (!Template) { |
| 1165 | TemplateArgList TemplateArgs; |
| 1166 | SourceLocation LAngleLoc, RAngleLoc; |
| 1167 | ParseTemplateIdAfterTemplateName(true, LAngleLoc, TemplateArgs, |
| 1168 | RAngleLoc); |
| 1169 | return true; |
| 1170 | } |
| 1171 | |
| 1172 | |
| 1173 | UnqualifiedId TemplateName; |
| 1174 | TemplateName.setIdentifier(Id, IdLoc); |
| 1175 | |
| 1176 | |
| 1177 | if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), |
| 1178 | TemplateName)) |
| 1179 | return true; |
| 1180 | if (TNK == TNK_Type_template || TNK == TNK_Dependent_template_name) |
| 1181 | AnnotateTemplateIdTokenAsType(); |
| 1182 | |
| 1183 | |
| 1184 | |
| 1185 | if (Tok.isNot(tok::annot_typename)) |
| 1186 | return true; |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | EndLocation = Tok.getAnnotationEndLoc(); |
| 1191 | ParsedType Type = getTypeAnnotation(Tok); |
| 1192 | ConsumeAnnotationToken(); |
| 1193 | return Type; |
| 1194 | } |
| 1195 | |
| 1196 | |
| 1197 | IdentifierInfo *CorrectedII = nullptr; |
| 1198 | ParsedType Type = Actions.getTypeName( |
| 1199 | *Id, IdLoc, getCurScope(), &SS, , false, nullptr, |
| 1200 | , |
| 1201 | , |
| 1202 | false, &CorrectedII); |
| 1203 | if (!Type) { |
| 1204 | Diag(IdLoc, diag::err_expected_class_name); |
| 1205 | return true; |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | EndLocation = IdLoc; |
| 1210 | |
| 1211 | |
| 1212 | DeclSpec DS(AttrFactory); |
| 1213 | DS.SetRangeStart(IdLoc); |
| 1214 | DS.SetRangeEnd(EndLocation); |
| 1215 | DS.getTypeSpecScope() = SS; |
| 1216 | |
| 1217 | const char *PrevSpec = nullptr; |
| 1218 | unsigned DiagID; |
| 1219 | DS.SetTypeSpecType(TST_typename, IdLoc, PrevSpec, DiagID, Type, |
| 1220 | Actions.getASTContext().getPrintingPolicy()); |
| 1221 | |
| 1222 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); |
| 1223 | return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 1224 | } |
| 1225 | |
| 1226 | void Parser::ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs) { |
| 1227 | while (Tok.isOneOf(tok::kw___single_inheritance, |
| 1228 | tok::kw___multiple_inheritance, |
| 1229 | tok::kw___virtual_inheritance)) { |
| 1230 | IdentifierInfo *AttrName = Tok.getIdentifierInfo(); |
| 1231 | SourceLocation AttrNameLoc = ConsumeToken(); |
| 1232 | attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, |
| 1233 | ParsedAttr::AS_Keyword); |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | bool Parser::isValidAfterTypeSpecifier(bool CouldBeBitfield) { |
| 1241 | |
| 1242 | switch (Tok.getKind()) { |
| 1243 | default: break; |
| 1244 | case tok::semi: |
| 1245 | case tok::star: |
| 1246 | case tok::amp: |
| 1247 | case tok::ampamp: |
| 1248 | case tok::identifier: |
| 1249 | case tok::r_paren: |
| 1250 | case tok::annot_cxxscope: |
| 1251 | case tok::annot_typename: |
| 1252 | case tok::annot_template_id: |
| 1253 | case tok::l_paren: |
| 1254 | case tok::comma: |
| 1255 | case tok::kw_operator: |
| 1256 | case tok::kw___declspec: |
| 1257 | case tok::l_square: |
| 1258 | case tok::ellipsis: |
| 1259 | |
| 1260 | |
| 1261 | case tok::kw___attribute: |
| 1262 | case tok::annot_pragma_pack: |
| 1263 | |
| 1264 | case tok::annot_pragma_ms_pragma: |
| 1265 | |
| 1266 | case tok::annot_pragma_ms_vtordisp: |
| 1267 | |
| 1268 | case tok::annot_pragma_ms_pointers_to_members: |
| 1269 | return true; |
| 1270 | case tok::colon: |
| 1271 | return CouldBeBitfield; |
| 1272 | |
| 1273 | case tok::kw___cdecl: |
| 1274 | case tok::kw___fastcall: |
| 1275 | case tok::kw___stdcall: |
| 1276 | case tok::kw___thiscall: |
| 1277 | case tok::kw___vectorcall: |
| 1278 | |
| 1279 | |
| 1280 | return getLangOpts().MicrosoftExt; |
| 1281 | |
| 1282 | case tok::kw_const: |
| 1283 | case tok::kw_volatile: |
| 1284 | case tok::kw_restrict: |
| 1285 | case tok::kw__Atomic: |
| 1286 | case tok::kw___unaligned: |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | case tok::kw_inline: |
| 1291 | case tok::kw_virtual: |
| 1292 | case tok::kw_friend: |
| 1293 | |
| 1294 | case tok::kw_static: |
| 1295 | case tok::kw_extern: |
| 1296 | case tok::kw_typedef: |
| 1297 | case tok::kw_register: |
| 1298 | case tok::kw_auto: |
| 1299 | case tok::kw_mutable: |
| 1300 | case tok::kw_thread_local: |
| 1301 | case tok::kw_constexpr: |
| 1302 | |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | if (!isKnownToBeTypeSpecifier(NextToken())) |
| 1318 | return true; |
| 1319 | break; |
| 1320 | case tok::r_brace: |
| 1321 | |
| 1322 | if (!getLangOpts().CPlusPlus) |
| 1323 | return true; |
| 1324 | break; |
| 1325 | case tok::greater: |
| 1326 | |
| 1327 | return getLangOpts().CPlusPlus; |
| 1328 | } |
| 1329 | return false; |
| 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | |
| 1366 | |
| 1367 | |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | |
| 1372 | void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, |
| 1373 | SourceLocation StartLoc, DeclSpec &DS, |
| 1374 | const ParsedTemplateInfo &TemplateInfo, |
| 1375 | AccessSpecifier AS, |
| 1376 | bool EnteringContext, DeclSpecContext DSC, |
| 1377 | ParsedAttributesWithRange &Attributes) { |
| 1378 | DeclSpec::TST TagType; |
| 1379 | if (TagTokKind == tok::kw_struct) |
| 1380 | TagType = DeclSpec::TST_struct; |
| 1381 | else if (TagTokKind == tok::kw___interface) |
| 1382 | TagType = DeclSpec::TST_interface; |
| 1383 | else if (TagTokKind == tok::kw_class) |
| 1384 | TagType = DeclSpec::TST_class; |
| 1385 | else { |
| 1386 | (0) . __assert_fail ("TagTokKind == tok..kw_union && \"Not a class specifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 1386, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(TagTokKind == tok::kw_union && "Not a class specifier"); |
| 1387 | TagType = DeclSpec::TST_union; |
| 1388 | } |
| 1389 | |
| 1390 | if (Tok.is(tok::code_completion)) { |
| 1391 | |
| 1392 | Actions.CodeCompleteTag(getCurScope(), TagType); |
| 1393 | return cutOffParsing(); |
| 1394 | } |
| 1395 | |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | bool shouldDelayDiagsInTag = |
| 1407 | (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation || |
| 1408 | TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization); |
| 1409 | SuppressAccessChecks diagsFromTag(*this, shouldDelayDiagsInTag); |
| 1410 | |
| 1411 | ParsedAttributesWithRange attrs(AttrFactory); |
| 1412 | |
| 1413 | MaybeParseGNUAttributes(attrs); |
| 1414 | MaybeParseMicrosoftDeclSpecs(attrs); |
| 1415 | |
| 1416 | |
| 1417 | if (Tok.isOneOf(tok::kw___single_inheritance, |
| 1418 | tok::kw___multiple_inheritance, |
| 1419 | tok::kw___virtual_inheritance)) |
| 1420 | ParseMicrosoftInheritanceClassAttributes(attrs); |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | |
| 1425 | MaybeParseCXX11Attributes(attrs); |
| 1426 | |
| 1427 | |
| 1428 | |
| 1429 | SourceLocation AttrFixitLoc = Tok.getLocation(); |
| 1430 | |
| 1431 | if (TagType == DeclSpec::TST_struct && |
| 1432 | Tok.isNot(tok::identifier) && |
| 1433 | !Tok.isAnnotation() && |
| 1434 | Tok.getIdentifierInfo() && |
| 1435 | Tok.isOneOf(tok::kw___is_abstract, |
| 1436 | tok::kw___is_aggregate, |
| 1437 | tok::kw___is_arithmetic, |
| 1438 | tok::kw___is_array, |
| 1439 | tok::kw___is_assignable, |
| 1440 | tok::kw___is_base_of, |
| 1441 | tok::kw___is_class, |
| 1442 | tok::kw___is_complete_type, |
| 1443 | tok::kw___is_compound, |
| 1444 | tok::kw___is_const, |
| 1445 | tok::kw___is_constructible, |
| 1446 | tok::kw___is_convertible, |
| 1447 | tok::kw___is_convertible_to, |
| 1448 | tok::kw___is_destructible, |
| 1449 | tok::kw___is_empty, |
| 1450 | tok::kw___is_enum, |
| 1451 | tok::kw___is_floating_point, |
| 1452 | tok::kw___is_final, |
| 1453 | tok::kw___is_function, |
| 1454 | tok::kw___is_fundamental, |
| 1455 | tok::kw___is_integral, |
| 1456 | tok::kw___is_interface_class, |
| 1457 | tok::kw___is_literal, |
| 1458 | tok::kw___is_lvalue_expr, |
| 1459 | tok::kw___is_lvalue_reference, |
| 1460 | tok::kw___is_member_function_pointer, |
| 1461 | tok::kw___is_member_object_pointer, |
| 1462 | tok::kw___is_member_pointer, |
| 1463 | tok::kw___is_nothrow_assignable, |
| 1464 | tok::kw___is_nothrow_constructible, |
| 1465 | tok::kw___is_nothrow_destructible, |
| 1466 | tok::kw___is_object, |
| 1467 | tok::kw___is_pod, |
| 1468 | tok::kw___is_pointer, |
| 1469 | tok::kw___is_polymorphic, |
| 1470 | tok::kw___is_reference, |
| 1471 | tok::kw___is_rvalue_expr, |
| 1472 | tok::kw___is_rvalue_reference, |
| 1473 | tok::kw___is_same, |
| 1474 | tok::kw___is_scalar, |
| 1475 | tok::kw___is_sealed, |
| 1476 | tok::kw___is_signed, |
| 1477 | tok::kw___is_standard_layout, |
| 1478 | tok::kw___is_trivial, |
| 1479 | tok::kw___is_trivially_assignable, |
| 1480 | tok::kw___is_trivially_constructible, |
| 1481 | tok::kw___is_trivially_copyable, |
| 1482 | tok::kw___is_union, |
| 1483 | tok::kw___is_unsigned, |
| 1484 | tok::kw___is_void, |
| 1485 | tok::kw___is_volatile)) |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | TryKeywordIdentFallback(true); |
| 1492 | |
| 1493 | struct PreserveAtomicIdentifierInfoRAII { |
| 1494 | PreserveAtomicIdentifierInfoRAII(Token &Tok, bool Enabled) |
| 1495 | : AtomicII(nullptr) { |
| 1496 | if (!Enabled) |
| 1497 | return; |
| 1498 | assert(Tok.is(tok::kw__Atomic)); |
| 1499 | AtomicII = Tok.getIdentifierInfo(); |
| 1500 | AtomicII->revertTokenIDToIdentifier(); |
| 1501 | Tok.setKind(tok::identifier); |
| 1502 | } |
| 1503 | ~PreserveAtomicIdentifierInfoRAII() { |
| 1504 | if (!AtomicII) |
| 1505 | return; |
| 1506 | AtomicII->revertIdentifierToTokenID(tok::kw__Atomic); |
| 1507 | } |
| 1508 | IdentifierInfo *AtomicII; |
| 1509 | }; |
| 1510 | |
| 1511 | |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | |
| 1516 | bool ShouldChangeAtomicToIdentifier = getLangOpts().MSVCCompat && |
| 1517 | Tok.is(tok::kw__Atomic) && |
| 1518 | TagType == DeclSpec::TST_struct; |
| 1519 | PreserveAtomicIdentifierInfoRAII AtomicTokenGuard( |
| 1520 | Tok, ShouldChangeAtomicToIdentifier); |
| 1521 | |
| 1522 | |
| 1523 | CXXScopeSpec &SS = DS.getTypeSpecScope(); |
| 1524 | if (getLangOpts().CPlusPlus) { |
| 1525 | |
| 1526 | |
| 1527 | ColonProtectionRAIIObject X(*this); |
| 1528 | |
| 1529 | CXXScopeSpec Spec; |
| 1530 | bool HasValidSpec = true; |
| 1531 | if (ParseOptionalCXXScopeSpecifier(Spec, nullptr, EnteringContext)) { |
| 1532 | DS.SetTypeSpecError(); |
| 1533 | HasValidSpec = false; |
| 1534 | } |
| 1535 | if (Spec.isSet()) |
| 1536 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) { |
| 1537 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 1538 | HasValidSpec = false; |
| 1539 | } |
| 1540 | if (HasValidSpec) |
| 1541 | SS = Spec; |
| 1542 | } |
| 1543 | |
| 1544 | TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; |
| 1545 | |
| 1546 | |
| 1547 | IdentifierInfo *Name = nullptr; |
| 1548 | SourceLocation NameLoc; |
| 1549 | TemplateIdAnnotation *TemplateId = nullptr; |
| 1550 | if (Tok.is(tok::identifier)) { |
| 1551 | Name = Tok.getIdentifierInfo(); |
| 1552 | NameLoc = ConsumeToken(); |
| 1553 | |
| 1554 | if (Tok.is(tok::less) && getLangOpts().CPlusPlus) { |
| 1555 | |
| 1556 | |
| 1557 | |
| 1558 | TemplateArgList TemplateArgs; |
| 1559 | SourceLocation LAngleLoc, RAngleLoc; |
| 1560 | if (ParseTemplateIdAfterTemplateName(true, LAngleLoc, TemplateArgs, |
| 1561 | RAngleLoc)) { |
| 1562 | |
| 1563 | |
| 1564 | LAngleLoc = RAngleLoc = SourceLocation(); |
| 1565 | } |
| 1566 | |
| 1567 | Diag(NameLoc, diag::err_explicit_spec_non_template) |
| 1568 | << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) |
| 1569 | << TagTokKind << Name << SourceRange(LAngleLoc, RAngleLoc); |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) { |
| 1574 | if (TemplateParams->size() > 1) { |
| 1575 | TemplateParams->pop_back(); |
| 1576 | } else { |
| 1577 | TemplateParams = nullptr; |
| 1578 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
| 1579 | = ParsedTemplateInfo::NonTemplate; |
| 1580 | } |
| 1581 | } else if (TemplateInfo.Kind |
| 1582 | == ParsedTemplateInfo::ExplicitInstantiation) { |
| 1583 | |
| 1584 | TemplateParams = nullptr; |
| 1585 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
| 1586 | = ParsedTemplateInfo::NonTemplate; |
| 1587 | const_cast<ParsedTemplateInfo&>(TemplateInfo).TemplateLoc |
| 1588 | = SourceLocation(); |
| 1589 | const_cast<ParsedTemplateInfo&>(TemplateInfo).ExternLoc |
| 1590 | = SourceLocation(); |
| 1591 | } |
| 1592 | } |
| 1593 | } else if (Tok.is(tok::annot_template_id)) { |
| 1594 | TemplateId = takeTemplateIdAnnotation(Tok); |
| 1595 | NameLoc = ConsumeAnnotationToken(); |
| 1596 | |
| 1597 | if (TemplateId->Kind != TNK_Type_template && |
| 1598 | TemplateId->Kind != TNK_Dependent_template_name) { |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | SourceRange Range(NameLoc); |
| 1603 | if (SS.isNotEmpty()) |
| 1604 | Range.setBegin(SS.getBeginLoc()); |
| 1605 | |
| 1606 | |
| 1607 | Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template) |
| 1608 | << TemplateId->Name << static_cast<int>(TemplateId->Kind) << Range; |
| 1609 | |
| 1610 | DS.SetTypeSpecError(); |
| 1611 | SkipUntil(tok::semi, StopBeforeMatch); |
| 1612 | return; |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | |
| 1617 | |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | |
| 1627 | |
| 1628 | |
| 1629 | |
| 1630 | |
| 1631 | |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | |
| 1643 | MaybeParseCXX11Attributes(Attributes); |
| 1644 | |
| 1645 | const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy(); |
| 1646 | Sema::TagUseKind TUK; |
| 1647 | if (DSC == DeclSpecContext::DSC_trailing) |
| 1648 | TUK = Sema::TUK_Reference; |
| 1649 | else if (Tok.is(tok::l_brace) || |
| 1650 | (getLangOpts().CPlusPlus && Tok.is(tok::colon)) || |
| 1651 | (isCXX11FinalKeyword() && |
| 1652 | (NextToken().is(tok::l_brace) || NextToken().is(tok::colon)))) { |
| 1653 | if (DS.isFriendSpecified()) { |
| 1654 | |
| 1655 | |
| 1656 | Diag(Tok.getLocation(), diag::err_friend_decl_defines_type) |
| 1657 | << SourceRange(DS.getFriendSpecLoc()); |
| 1658 | |
| 1659 | |
| 1660 | |
| 1661 | SkipUntil(tok::semi, StopBeforeMatch); |
| 1662 | TUK = Sema::TUK_Friend; |
| 1663 | } else { |
| 1664 | |
| 1665 | TUK = Sema::TUK_Definition; |
| 1666 | } |
| 1667 | } else if (isCXX11FinalKeyword() && (NextToken().is(tok::l_square) || |
| 1668 | NextToken().is(tok::kw_alignas))) { |
| 1669 | |
| 1670 | |
| 1671 | TentativeParsingAction PA(*this); |
| 1672 | |
| 1673 | |
| 1674 | ConsumeToken(); |
| 1675 | |
| 1676 | |
| 1677 | while (true) { |
| 1678 | if (Tok.is(tok::l_square) && NextToken().is(tok::l_square)) { |
| 1679 | ConsumeBracket(); |
| 1680 | if (!SkipUntil(tok::r_square, StopAtSemi)) |
| 1681 | break; |
| 1682 | } else if (Tok.is(tok::kw_alignas) && NextToken().is(tok::l_paren)) { |
| 1683 | ConsumeToken(); |
| 1684 | ConsumeParen(); |
| 1685 | if (!SkipUntil(tok::r_paren, StopAtSemi)) |
| 1686 | break; |
| 1687 | } else { |
| 1688 | break; |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | if (Tok.isOneOf(tok::l_brace, tok::colon)) |
| 1693 | TUK = Sema::TUK_Definition; |
| 1694 | else |
| 1695 | TUK = Sema::TUK_Reference; |
| 1696 | |
| 1697 | PA.Revert(); |
| 1698 | } else if (!isTypeSpecifier(DSC) && |
| 1699 | (Tok.is(tok::semi) || |
| 1700 | (Tok.isAtStartOfLine() && !isValidAfterTypeSpecifier(false)))) { |
| 1701 | TUK = DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration; |
| 1702 | if (Tok.isNot(tok::semi)) { |
| 1703 | const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy(); |
| 1704 | |
| 1705 | ExpectAndConsume(tok::semi, diag::err_expected_after, |
| 1706 | DeclSpec::getSpecifierName(TagType, PPol)); |
| 1707 | PP.EnterToken(Tok); |
| 1708 | Tok.setKind(tok::semi); |
| 1709 | } |
| 1710 | } else |
| 1711 | TUK = Sema::TUK_Reference; |
| 1712 | |
| 1713 | |
| 1714 | |
| 1715 | if (TUK != Sema::TUK_Reference) { |
| 1716 | |
| 1717 | |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | SourceRange AttrRange = Attributes.Range; |
| 1722 | if (AttrRange.isValid()) { |
| 1723 | Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) |
| 1724 | << AttrRange |
| 1725 | << FixItHint::CreateInsertionFromRange(AttrFixitLoc, |
| 1726 | CharSourceRange(AttrRange, true)) |
| 1727 | << FixItHint::CreateRemoval(AttrRange); |
| 1728 | |
| 1729 | |
| 1730 | |
| 1731 | attrs.takeAllFrom(Attributes); |
| 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | |
| 1736 | |
| 1737 | if (shouldDelayDiagsInTag) { |
| 1738 | diagsFromTag.done(); |
| 1739 | if (TUK == Sema::TUK_Reference) |
| 1740 | diagsFromTag.redelay(); |
| 1741 | } |
| 1742 | |
| 1743 | if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error || |
| 1744 | TUK != Sema::TUK_Definition)) { |
| 1745 | if (DS.getTypeSpecType() != DeclSpec::TST_error) { |
| 1746 | |
| 1747 | Diag(StartLoc, diag::err_anon_type_definition) |
| 1748 | << DeclSpec::getSpecifierName(TagType, Policy); |
| 1749 | } |
| 1750 | |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | if (TUK == Sema::TUK_Definition && Tok.is(tok::colon)) |
| 1755 | SkipUntil(tok::semi, StopBeforeMatch); |
| 1756 | else |
| 1757 | SkipUntil(tok::comma, StopAtSemi); |
| 1758 | return; |
| 1759 | } |
| 1760 | |
| 1761 | |
| 1762 | DeclResult TagOrTempResult = true; |
| 1763 | TypeResult TypeResult = true; |
| 1764 | |
| 1765 | bool Owned = false; |
| 1766 | Sema::SkipBodyInfo SkipBody; |
| 1767 | if (TemplateId) { |
| 1768 | |
| 1769 | |
| 1770 | ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(), |
| 1771 | TemplateId->NumArgs); |
| 1772 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
| 1773 | TUK == Sema::TUK_Declaration) { |
| 1774 | |
| 1775 | ProhibitAttributes(attrs); |
| 1776 | |
| 1777 | TagOrTempResult = Actions.ActOnExplicitInstantiation( |
| 1778 | getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, |
| 1779 | TagType, StartLoc, SS, TemplateId->Template, |
| 1780 | TemplateId->TemplateNameLoc, TemplateId->LAngleLoc, TemplateArgsPtr, |
| 1781 | TemplateId->RAngleLoc, attrs); |
| 1782 | |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | } else if (TUK == Sema::TUK_Reference || |
| 1788 | (TUK == Sema::TUK_Friend && |
| 1789 | TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) { |
| 1790 | ProhibitAttributes(attrs); |
| 1791 | TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, StartLoc, |
| 1792 | TemplateId->SS, |
| 1793 | TemplateId->TemplateKWLoc, |
| 1794 | TemplateId->Template, |
| 1795 | TemplateId->TemplateNameLoc, |
| 1796 | TemplateId->LAngleLoc, |
| 1797 | TemplateArgsPtr, |
| 1798 | TemplateId->RAngleLoc); |
| 1799 | } else { |
| 1800 | |
| 1801 | |
| 1802 | TemplateParameterLists FakedParamLists; |
| 1803 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | |
| 1808 | |
| 1809 | |
| 1810 | |
| 1811 | |
| 1812 | |
| 1813 | |
| 1814 | |
| 1815 | (0) . __assert_fail ("(TUK == Sema..TUK_Definition || TUK == Sema..TUK_Friend) && \"Expected a definition here\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 1816, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((TUK == Sema::TUK_Definition || TUK == Sema::TUK_Friend) && |
| 1816 | (0) . __assert_fail ("(TUK == Sema..TUK_Definition || TUK == Sema..TUK_Friend) && \"Expected a definition here\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 1816, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Expected a definition here"); |
| 1817 | |
| 1818 | if (TUK == Sema::TUK_Friend) { |
| 1819 | Diag(DS.getFriendSpecLoc(), diag::err_friend_explicit_instantiation); |
| 1820 | TemplateParams = nullptr; |
| 1821 | } else { |
| 1822 | SourceLocation LAngleLoc = |
| 1823 | PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); |
| 1824 | Diag(TemplateId->TemplateNameLoc, |
| 1825 | diag::err_explicit_instantiation_with_definition) |
| 1826 | << SourceRange(TemplateInfo.TemplateLoc) |
| 1827 | << FixItHint::CreateInsertion(LAngleLoc, "<>"); |
| 1828 | |
| 1829 | |
| 1830 | |
| 1831 | |
| 1832 | FakedParamLists.push_back(Actions.ActOnTemplateParameterList( |
| 1833 | 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, None, |
| 1834 | LAngleLoc, nullptr)); |
| 1835 | TemplateParams = &FakedParamLists; |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | |
| 1840 | TagOrTempResult = Actions.ActOnClassTemplateSpecialization( |
| 1841 | getCurScope(), TagType, TUK, StartLoc, DS.getModulePrivateSpecLoc(), |
| 1842 | *TemplateId, attrs, |
| 1843 | MultiTemplateParamsArg(TemplateParams ? &(*TemplateParams)[0] |
| 1844 | : nullptr, |
| 1845 | TemplateParams ? TemplateParams->size() : 0), |
| 1846 | &SkipBody); |
| 1847 | } |
| 1848 | } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
| 1849 | TUK == Sema::TUK_Declaration) { |
| 1850 | |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | |
| 1855 | ProhibitAttributes(attrs); |
| 1856 | |
| 1857 | TagOrTempResult = Actions.ActOnExplicitInstantiation( |
| 1858 | getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, |
| 1859 | TagType, StartLoc, SS, Name, NameLoc, attrs); |
| 1860 | } else if (TUK == Sema::TUK_Friend && |
| 1861 | TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) { |
| 1862 | ProhibitAttributes(attrs); |
| 1863 | |
| 1864 | TagOrTempResult = Actions.ActOnTemplatedFriendTag( |
| 1865 | getCurScope(), DS.getFriendSpecLoc(), TagType, StartLoc, SS, Name, |
| 1866 | NameLoc, attrs, |
| 1867 | MultiTemplateParamsArg(TemplateParams ? &(*TemplateParams)[0] : nullptr, |
| 1868 | TemplateParams ? TemplateParams->size() : 0)); |
| 1869 | } else { |
| 1870 | if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition) |
| 1871 | ProhibitAttributes(attrs); |
| 1872 | |
| 1873 | if (TUK == Sema::TUK_Definition && |
| 1874 | TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { |
| 1875 | |
| 1876 | |
| 1877 | Diag(Tok, diag::err_template_defn_explicit_instantiation) |
| 1878 | << 1 << FixItHint::CreateRemoval(TemplateInfo.TemplateLoc); |
| 1879 | TemplateParams = nullptr; |
| 1880 | } |
| 1881 | |
| 1882 | bool IsDependent = false; |
| 1883 | |
| 1884 | |
| 1885 | |
| 1886 | |
| 1887 | MultiTemplateParamsArg TParams; |
| 1888 | if (TUK != Sema::TUK_Reference && TemplateParams) |
| 1889 | TParams = |
| 1890 | MultiTemplateParamsArg(&(*TemplateParams)[0], TemplateParams->size()); |
| 1891 | |
| 1892 | stripTypeAttributesOffDeclSpec(attrs, DS, TUK); |
| 1893 | |
| 1894 | |
| 1895 | TagOrTempResult = Actions.ActOnTag( |
| 1896 | getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS, |
| 1897 | DS.getModulePrivateSpecLoc(), TParams, Owned, IsDependent, |
| 1898 | SourceLocation(), false, clang::TypeResult(), |
| 1899 | DSC == DeclSpecContext::DSC_type_specifier, |
| 1900 | DSC == DeclSpecContext::DSC_template_param || |
| 1901 | DSC == DeclSpecContext::DSC_template_type_arg, |
| 1902 | &SkipBody); |
| 1903 | |
| 1904 | |
| 1905 | |
| 1906 | if (IsDependent) { |
| 1907 | assert(TUK == Sema::TUK_Reference || TUK == Sema::TUK_Friend); |
| 1908 | TypeResult = Actions.ActOnDependentTag(getCurScope(), TagType, TUK, |
| 1909 | SS, Name, StartLoc, NameLoc); |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | |
| 1914 | if (TUK == Sema::TUK_Definition) { |
| 1915 | assert(Tok.is(tok::l_brace) || |
| 1916 | (getLangOpts().CPlusPlus && Tok.is(tok::colon)) || |
| 1917 | isCXX11FinalKeyword()); |
| 1918 | if (SkipBody.ShouldSkip) |
| 1919 | SkipCXXMemberSpecification(StartLoc, AttrFixitLoc, TagType, |
| 1920 | TagOrTempResult.get()); |
| 1921 | else if (getLangOpts().CPlusPlus) |
| 1922 | ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType, |
| 1923 | TagOrTempResult.get()); |
| 1924 | else { |
| 1925 | Decl *D = |
| 1926 | SkipBody.CheckSameAsPrevious ? SkipBody.New : TagOrTempResult.get(); |
| 1927 | |
| 1928 | ParseStructUnionBody(StartLoc, TagType, D); |
| 1929 | if (SkipBody.CheckSameAsPrevious && |
| 1930 | !Actions.ActOnDuplicateDefinition(DS, TagOrTempResult.get(), |
| 1931 | SkipBody)) { |
| 1932 | DS.SetTypeSpecError(); |
| 1933 | return; |
| 1934 | } |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | if (!TagOrTempResult.isInvalid()) |
| 1939 | |
| 1940 | Actions.ProcessDeclAttributeDelayed(TagOrTempResult.get(), attrs); |
| 1941 | |
| 1942 | const char *PrevSpec = nullptr; |
| 1943 | unsigned DiagID; |
| 1944 | bool Result; |
| 1945 | if (!TypeResult.isInvalid()) { |
| 1946 | Result = DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, |
| 1947 | NameLoc.isValid() ? NameLoc : StartLoc, |
| 1948 | PrevSpec, DiagID, TypeResult.get(), Policy); |
| 1949 | } else if (!TagOrTempResult.isInvalid()) { |
| 1950 | Result = DS.SetTypeSpecType(TagType, StartLoc, |
| 1951 | NameLoc.isValid() ? NameLoc : StartLoc, |
| 1952 | PrevSpec, DiagID, TagOrTempResult.get(), Owned, |
| 1953 | Policy); |
| 1954 | } else { |
| 1955 | DS.SetTypeSpecError(); |
| 1956 | return; |
| 1957 | } |
| 1958 | |
| 1959 | if (Result) |
| 1960 | Diag(StartLoc, DiagID) << PrevSpec; |
| 1961 | |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | |
| 1966 | |
| 1967 | |
| 1968 | |
| 1969 | |
| 1970 | |
| 1971 | |
| 1972 | |
| 1973 | |
| 1974 | if (TUK == Sema::TUK_Definition && |
| 1975 | (getLangOpts().CPlusPlus || !isTypeSpecifier(DSC)) && |
| 1976 | (TemplateInfo.Kind || !isValidAfterTypeSpecifier(false))) { |
| 1977 | if (Tok.isNot(tok::semi)) { |
| 1978 | const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy(); |
| 1979 | ExpectAndConsume(tok::semi, diag::err_expected_after, |
| 1980 | DeclSpec::getSpecifierName(TagType, PPol)); |
| 1981 | |
| 1982 | |
| 1983 | |
| 1984 | PP.EnterToken(Tok); |
| 1985 | Tok.setKind(tok::semi); |
| 1986 | } |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | |
| 1991 | |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | |
| 1996 | |
| 1997 | void Parser::ParseBaseClause(Decl *ClassDecl) { |
| 1998 | (0) . __assert_fail ("Tok.is(tok..colon) && \"Not a base clause\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 1998, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::colon) && "Not a base clause"); |
| 1999 | ConsumeToken(); |
| 2000 | |
| 2001 | |
| 2002 | SmallVector<CXXBaseSpecifier *, 8> BaseInfo; |
| 2003 | |
| 2004 | while (true) { |
| 2005 | |
| 2006 | BaseResult Result = ParseBaseSpecifier(ClassDecl); |
| 2007 | if (Result.isInvalid()) { |
| 2008 | |
| 2009 | |
| 2010 | SkipUntil(tok::comma, tok::l_brace, StopAtSemi | StopBeforeMatch); |
| 2011 | } else { |
| 2012 | |
| 2013 | BaseInfo.push_back(Result.get()); |
| 2014 | } |
| 2015 | |
| 2016 | |
| 2017 | |
| 2018 | if (!TryConsumeToken(tok::comma)) |
| 2019 | break; |
| 2020 | } |
| 2021 | |
| 2022 | |
| 2023 | Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo); |
| 2024 | } |
| 2025 | |
| 2026 | |
| 2027 | |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | |
| 2032 | |
| 2033 | |
| 2034 | |
| 2035 | |
| 2036 | |
| 2037 | BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) { |
| 2038 | bool IsVirtual = false; |
| 2039 | SourceLocation StartLoc = Tok.getLocation(); |
| 2040 | |
| 2041 | ParsedAttributesWithRange Attributes(AttrFactory); |
| 2042 | MaybeParseCXX11Attributes(Attributes); |
| 2043 | |
| 2044 | |
| 2045 | if (TryConsumeToken(tok::kw_virtual)) |
| 2046 | IsVirtual = true; |
| 2047 | |
| 2048 | CheckMisplacedCXX11Attribute(Attributes, StartLoc); |
| 2049 | |
| 2050 | |
| 2051 | AccessSpecifier Access = getAccessSpecifierIfPresent(); |
| 2052 | if (Access != AS_none) |
| 2053 | ConsumeToken(); |
| 2054 | |
| 2055 | CheckMisplacedCXX11Attribute(Attributes, StartLoc); |
| 2056 | |
| 2057 | |
| 2058 | |
| 2059 | if (Tok.is(tok::kw_virtual)) { |
| 2060 | SourceLocation VirtualLoc = ConsumeToken(); |
| 2061 | if (IsVirtual) { |
| 2062 | |
| 2063 | Diag(VirtualLoc, diag::err_dup_virtual) |
| 2064 | << FixItHint::CreateRemoval(VirtualLoc); |
| 2065 | } |
| 2066 | |
| 2067 | IsVirtual = true; |
| 2068 | } |
| 2069 | |
| 2070 | CheckMisplacedCXX11Attribute(Attributes, StartLoc); |
| 2071 | |
| 2072 | |
| 2073 | |
| 2074 | |
| 2075 | |
| 2076 | |
| 2077 | |
| 2078 | if (getLangOpts().MSVCCompat && Tok.is(tok::kw__Atomic) && |
| 2079 | NextToken().is(tok::less)) |
| 2080 | Tok.setKind(tok::identifier); |
| 2081 | |
| 2082 | SourceLocation EndLocation; |
| 2083 | SourceLocation BaseLoc; |
| 2084 | TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation); |
| 2085 | if (BaseType.isInvalid()) |
| 2086 | return true; |
| 2087 | |
| 2088 | |
| 2089 | |
| 2090 | |
| 2091 | SourceLocation EllipsisLoc; |
| 2092 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
| 2093 | |
| 2094 | |
| 2095 | SourceRange Range(StartLoc, EndLocation); |
| 2096 | |
| 2097 | |
| 2098 | |
| 2099 | return Actions.ActOnBaseSpecifier(ClassDecl, Range, Attributes, IsVirtual, |
| 2100 | Access, BaseType.get(), BaseLoc, |
| 2101 | EllipsisLoc); |
| 2102 | } |
| 2103 | |
| 2104 | |
| 2105 | |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | |
| 2110 | |
| 2111 | AccessSpecifier Parser::getAccessSpecifierIfPresent() const { |
| 2112 | switch (Tok.getKind()) { |
| 2113 | default: return AS_none; |
| 2114 | case tok::kw_private: return AS_private; |
| 2115 | case tok::kw_protected: return AS_protected; |
| 2116 | case tok::kw_public: return AS_public; |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | |
| 2121 | |
| 2122 | |
| 2123 | |
| 2124 | void Parser::HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo, |
| 2125 | Decl *ThisDecl) { |
| 2126 | DeclaratorChunk::FunctionTypeInfo &FTI |
| 2127 | = DeclaratorInfo.getFunctionTypeInfo(); |
| 2128 | |
| 2129 | |
| 2130 | bool NeedLateParse = FTI.getExceptionSpecType() == EST_Unparsed; |
| 2131 | |
| 2132 | if (!NeedLateParse) { |
| 2133 | |
| 2134 | for (unsigned ParamIdx = 0; ParamIdx < FTI.NumParams; ++ParamIdx) { |
| 2135 | auto Param = cast<ParmVarDecl>(FTI.Params[ParamIdx].Param); |
| 2136 | if (Param->hasUnparsedDefaultArg()) { |
| 2137 | NeedLateParse = true; |
| 2138 | break; |
| 2139 | } |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | if (NeedLateParse) { |
| 2144 | |
| 2145 | |
| 2146 | auto LateMethod = new LateParsedMethodDeclaration(this, ThisDecl); |
| 2147 | getCurrentClass().LateParsedDeclarations.push_back(LateMethod); |
| 2148 | LateMethod->TemplateScope = getCurScope()->isTemplateParamScope(); |
| 2149 | |
| 2150 | |
| 2151 | LateMethod->ExceptionSpecTokens = FTI.ExceptionSpecTokens; |
| 2152 | FTI.ExceptionSpecTokens = nullptr; |
| 2153 | |
| 2154 | |
| 2155 | |
| 2156 | LateMethod->DefaultArgs.reserve(FTI.NumParams); |
| 2157 | for (unsigned ParamIdx = 0; ParamIdx < FTI.NumParams; ++ParamIdx) |
| 2158 | LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument( |
| 2159 | FTI.Params[ParamIdx].Param, |
| 2160 | std::move(FTI.Params[ParamIdx].DefaultArgTokens))); |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | |
| 2167 | |
| 2168 | |
| 2169 | |
| 2170 | |
| 2171 | VirtSpecifiers::Specifier Parser::isCXX11VirtSpecifier(const Token &Tok) const { |
| 2172 | if (!getLangOpts().CPlusPlus || Tok.isNot(tok::identifier)) |
| 2173 | return VirtSpecifiers::VS_None; |
| 2174 | |
| 2175 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 2176 | |
| 2177 | |
| 2178 | if (!Ident_final) { |
| 2179 | Ident_final = &PP.getIdentifierTable().get("final"); |
| 2180 | if (getLangOpts().GNUKeywords) |
| 2181 | Ident_GNU_final = &PP.getIdentifierTable().get("__final"); |
| 2182 | if (getLangOpts().MicrosoftExt) |
| 2183 | Ident_sealed = &PP.getIdentifierTable().get("sealed"); |
| 2184 | Ident_override = &PP.getIdentifierTable().get("override"); |
| 2185 | } |
| 2186 | |
| 2187 | if (II == Ident_override) |
| 2188 | return VirtSpecifiers::VS_Override; |
| 2189 | |
| 2190 | if (II == Ident_sealed) |
| 2191 | return VirtSpecifiers::VS_Sealed; |
| 2192 | |
| 2193 | if (II == Ident_final) |
| 2194 | return VirtSpecifiers::VS_Final; |
| 2195 | |
| 2196 | if (II == Ident_GNU_final) |
| 2197 | return VirtSpecifiers::VS_GNU_Final; |
| 2198 | |
| 2199 | return VirtSpecifiers::VS_None; |
| 2200 | } |
| 2201 | |
| 2202 | |
| 2203 | |
| 2204 | |
| 2205 | |
| 2206 | |
| 2207 | void Parser::ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, |
| 2208 | bool IsInterface, |
| 2209 | SourceLocation FriendLoc) { |
| 2210 | while (true) { |
| 2211 | VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(); |
| 2212 | if (Specifier == VirtSpecifiers::VS_None) |
| 2213 | return; |
| 2214 | |
| 2215 | if (FriendLoc.isValid()) { |
| 2216 | Diag(Tok.getLocation(), diag::err_friend_decl_spec) |
| 2217 | << VirtSpecifiers::getSpecifierName(Specifier) |
| 2218 | << FixItHint::CreateRemoval(Tok.getLocation()) |
| 2219 | << SourceRange(FriendLoc, FriendLoc); |
| 2220 | ConsumeToken(); |
| 2221 | continue; |
| 2222 | } |
| 2223 | |
| 2224 | |
| 2225 | |
| 2226 | const char *PrevSpec = nullptr; |
| 2227 | if (VS.SetSpecifier(Specifier, Tok.getLocation(), PrevSpec)) |
| 2228 | Diag(Tok.getLocation(), diag::err_duplicate_virt_specifier) |
| 2229 | << PrevSpec |
| 2230 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 2231 | |
| 2232 | if (IsInterface && (Specifier == VirtSpecifiers::VS_Final || |
| 2233 | Specifier == VirtSpecifiers::VS_Sealed)) { |
| 2234 | Diag(Tok.getLocation(), diag::err_override_control_interface) |
| 2235 | << VirtSpecifiers::getSpecifierName(Specifier); |
| 2236 | } else if (Specifier == VirtSpecifiers::VS_Sealed) { |
| 2237 | Diag(Tok.getLocation(), diag::ext_ms_sealed_keyword); |
| 2238 | } else if (Specifier == VirtSpecifiers::VS_GNU_Final) { |
| 2239 | Diag(Tok.getLocation(), diag::ext_warn_gnu_final); |
| 2240 | } else { |
| 2241 | Diag(Tok.getLocation(), |
| 2242 | getLangOpts().CPlusPlus11 |
| 2243 | ? diag::warn_cxx98_compat_override_control_keyword |
| 2244 | : diag::ext_override_control_keyword) |
| 2245 | << VirtSpecifiers::getSpecifierName(Specifier); |
| 2246 | } |
| 2247 | ConsumeToken(); |
| 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | |
| 2252 | |
| 2253 | bool Parser::isCXX11FinalKeyword() const { |
| 2254 | VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(); |
| 2255 | return Specifier == VirtSpecifiers::VS_Final || |
| 2256 | Specifier == VirtSpecifiers::VS_GNU_Final || |
| 2257 | Specifier == VirtSpecifiers::VS_Sealed; |
| 2258 | } |
| 2259 | |
| 2260 | |
| 2261 | |
| 2262 | bool Parser::ParseCXXMemberDeclaratorBeforeInitializer( |
| 2263 | Declarator &DeclaratorInfo, VirtSpecifiers &VS, ExprResult &BitfieldSize, |
| 2264 | LateParsedAttrList &LateParsedAttrs) { |
| 2265 | |
| 2266 | |
| 2267 | |
| 2268 | |
| 2269 | if (Tok.isNot(tok::colon)) |
| 2270 | ParseDeclarator(DeclaratorInfo); |
| 2271 | else |
| 2272 | DeclaratorInfo.SetIdentifier(nullptr, Tok.getLocation()); |
| 2273 | |
| 2274 | if (!DeclaratorInfo.isFunctionDeclarator() && TryConsumeToken(tok::colon)) { |
| 2275 | (0) . __assert_fail ("DeclaratorInfo.isPastIdentifier() && \"don't know where identifier would go yet?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 2276, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DeclaratorInfo.isPastIdentifier() && |
| 2276 | (0) . __assert_fail ("DeclaratorInfo.isPastIdentifier() && \"don't know where identifier would go yet?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 2276, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "don't know where identifier would go yet?"); |
| 2277 | BitfieldSize = ParseConstantExpression(); |
| 2278 | if (BitfieldSize.isInvalid()) |
| 2279 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
| 2280 | } else { |
| 2281 | ParseOptionalCXX11VirtSpecifierSeq( |
| 2282 | VS, getCurrentClass().IsInterface, |
| 2283 | DeclaratorInfo.getDeclSpec().getFriendSpecLoc()); |
| 2284 | if (!VS.isUnset()) |
| 2285 | MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS); |
| 2286 | } |
| 2287 | |
| 2288 | |
| 2289 | if (Tok.is(tok::kw_asm)) { |
| 2290 | SourceLocation Loc; |
| 2291 | ExprResult AsmLabel(ParseSimpleAsm(&Loc)); |
| 2292 | if (AsmLabel.isInvalid()) |
| 2293 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
| 2294 | |
| 2295 | DeclaratorInfo.setAsmLabel(AsmLabel.get()); |
| 2296 | DeclaratorInfo.SetRangeEnd(Loc); |
| 2297 | } |
| 2298 | |
| 2299 | |
| 2300 | MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs); |
| 2301 | |
| 2302 | |
| 2303 | |
| 2304 | if (BitfieldSize.isUnset() && VS.isUnset()) { |
| 2305 | ParseOptionalCXX11VirtSpecifierSeq( |
| 2306 | VS, getCurrentClass().IsInterface, |
| 2307 | DeclaratorInfo.getDeclSpec().getFriendSpecLoc()); |
| 2308 | if (!VS.isUnset()) { |
| 2309 | |
| 2310 | |
| 2311 | for (const ParsedAttr &AL : DeclaratorInfo.getAttributes()) |
| 2312 | if (AL.isKnownToGCC() && !AL.isCXX11Attribute()) |
| 2313 | Diag(AL.getLoc(), diag::warn_gcc_attribute_location); |
| 2314 | |
| 2315 | MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS); |
| 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | |
| 2320 | |
| 2321 | if (!DeclaratorInfo.hasName() && BitfieldSize.isUnset()) { |
| 2322 | |
| 2323 | SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); |
| 2324 | return true; |
| 2325 | } |
| 2326 | return false; |
| 2327 | } |
| 2328 | |
| 2329 | |
| 2330 | |
| 2331 | void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq( |
| 2332 | Declarator &D, |
| 2333 | VirtSpecifiers &VS) { |
| 2334 | DeclSpec DS(AttrFactory); |
| 2335 | |
| 2336 | |
| 2337 | |
| 2338 | ParseTypeQualifierListOpt( |
| 2339 | DS, AR_NoAttributesParsed, false, |
| 2340 | , llvm::function_ref<void()>([&]() { |
| 2341 | Actions.CodeCompleteFunctionQualifiers(DS, D, &VS); |
| 2342 | })); |
| 2343 | D.ExtendWithDeclSpec(DS); |
| 2344 | |
| 2345 | if (D.isFunctionDeclarator()) { |
| 2346 | auto &Function = D.getFunctionTypeInfo(); |
| 2347 | if (DS.getTypeQualifiers() != DeclSpec::TQ_unspecified) { |
| 2348 | auto DeclSpecCheck = [&](DeclSpec::TQ TypeQual, StringRef FixItName, |
| 2349 | SourceLocation SpecLoc) { |
| 2350 | FixItHint Insertion; |
| 2351 | auto &MQ = Function.getOrCreateMethodQualifiers(); |
| 2352 | if (!(MQ.getTypeQualifiers() & TypeQual)) { |
| 2353 | std::string Name(FixItName.data()); |
| 2354 | Name += " "; |
| 2355 | Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name); |
| 2356 | MQ.SetTypeQual(TypeQual, SpecLoc); |
| 2357 | } |
| 2358 | Diag(SpecLoc, diag::err_declspec_after_virtspec) |
| 2359 | << FixItName |
| 2360 | << VirtSpecifiers::getSpecifierName(VS.getLastSpecifier()) |
| 2361 | << FixItHint::CreateRemoval(SpecLoc) << Insertion; |
| 2362 | }; |
| 2363 | DS.forEachQualifier(DeclSpecCheck); |
| 2364 | } |
| 2365 | |
| 2366 | |
| 2367 | bool RefQualifierIsLValueRef = true; |
| 2368 | SourceLocation RefQualifierLoc; |
| 2369 | if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) { |
| 2370 | const char *Name = (RefQualifierIsLValueRef ? "& " : "&& "); |
| 2371 | FixItHint Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name); |
| 2372 | Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef; |
| 2373 | Function.RefQualifierLoc = RefQualifierLoc.getRawEncoding(); |
| 2374 | |
| 2375 | Diag(RefQualifierLoc, diag::err_declspec_after_virtspec) |
| 2376 | << (RefQualifierIsLValueRef ? "&" : "&&") |
| 2377 | << VirtSpecifiers::getSpecifierName(VS.getLastSpecifier()) |
| 2378 | << FixItHint::CreateRemoval(RefQualifierLoc) |
| 2379 | << Insertion; |
| 2380 | D.SetRangeEnd(RefQualifierLoc); |
| 2381 | } |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | |
| 2386 | |
| 2387 | |
| 2388 | |
| 2389 | |
| 2390 | |
| 2391 | |
| 2392 | |
| 2393 | |
| 2394 | |
| 2395 | |
| 2396 | |
| 2397 | |
| 2398 | |
| 2399 | |
| 2400 | |
| 2401 | |
| 2402 | |
| 2403 | |
| 2404 | |
| 2405 | |
| 2406 | |
| 2407 | |
| 2408 | |
| 2409 | |
| 2410 | |
| 2411 | |
| 2412 | |
| 2413 | |
| 2414 | |
| 2415 | |
| 2416 | |
| 2417 | |
| 2418 | |
| 2419 | |
| 2420 | |
| 2421 | Parser::DeclGroupPtrTy |
| 2422 | Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, |
| 2423 | ParsedAttributes &AccessAttrs, |
| 2424 | const ParsedTemplateInfo &TemplateInfo, |
| 2425 | ParsingDeclRAIIObject *TemplateDiags) { |
| 2426 | if (Tok.is(tok::at)) { |
| 2427 | if (getLangOpts().ObjC && NextToken().isObjCAtKeyword(tok::objc_defs)) |
| 2428 | Diag(Tok, diag::err_at_defs_cxx); |
| 2429 | else |
| 2430 | Diag(Tok, diag::err_at_in_class); |
| 2431 | |
| 2432 | ConsumeToken(); |
| 2433 | SkipUntil(tok::r_brace, StopAtSemi); |
| 2434 | return nullptr; |
| 2435 | } |
| 2436 | |
| 2437 | |
| 2438 | |
| 2439 | |
| 2440 | |
| 2441 | |
| 2442 | |
| 2443 | ColonProtectionRAIIObject X(*this); |
| 2444 | |
| 2445 | |
| 2446 | bool MalformedTypeSpec = false; |
| 2447 | if (!TemplateInfo.Kind && |
| 2448 | Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) { |
| 2449 | if (TryAnnotateCXXScopeToken()) |
| 2450 | MalformedTypeSpec = true; |
| 2451 | |
| 2452 | bool isAccessDecl; |
| 2453 | if (Tok.isNot(tok::annot_cxxscope)) |
| 2454 | isAccessDecl = false; |
| 2455 | else if (NextToken().is(tok::identifier)) |
| 2456 | isAccessDecl = GetLookAheadToken(2).is(tok::semi); |
| 2457 | else |
| 2458 | isAccessDecl = NextToken().is(tok::kw_operator); |
| 2459 | |
| 2460 | if (isAccessDecl) { |
| 2461 | |
| 2462 | CXXScopeSpec SS; |
| 2463 | ParseOptionalCXXScopeSpecifier(SS, nullptr, |
| 2464 | ); |
| 2465 | |
| 2466 | if (SS.isInvalid()) { |
| 2467 | SkipUntil(tok::semi); |
| 2468 | return nullptr; |
| 2469 | } |
| 2470 | |
| 2471 | |
| 2472 | SourceLocation TemplateKWLoc; |
| 2473 | UnqualifiedId Name; |
| 2474 | if (ParseUnqualifiedId(SS, false, true, true, false, nullptr, |
| 2475 | &TemplateKWLoc, Name)) { |
| 2476 | SkipUntil(tok::semi); |
| 2477 | return nullptr; |
| 2478 | } |
| 2479 | |
| 2480 | |
| 2481 | if (ExpectAndConsume(tok::semi, diag::err_expected_after, |
| 2482 | "access declaration")) { |
| 2483 | SkipUntil(tok::semi); |
| 2484 | return nullptr; |
| 2485 | } |
| 2486 | |
| 2487 | |
| 2488 | return DeclGroupPtrTy::make(DeclGroupRef(Actions.ActOnUsingDeclaration( |
| 2489 | getCurScope(), AS, SourceLocation(), |
| 2490 | SourceLocation(), SS, Name, |
| 2491 | SourceLocation(), |
| 2492 | ParsedAttributesView()))); |
| 2493 | } |
| 2494 | } |
| 2495 | |
| 2496 | |
| 2497 | |
| 2498 | if (!TemplateInfo.Kind && |
| 2499 | Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) { |
| 2500 | SourceLocation DeclEnd; |
| 2501 | return DeclGroupPtrTy::make( |
| 2502 | DeclGroupRef(ParseStaticAssertDeclaration(DeclEnd))); |
| 2503 | } |
| 2504 | |
| 2505 | if (Tok.is(tok::kw_template)) { |
| 2506 | (0) . __assert_fail ("!TemplateInfo.TemplateParams && \"Nested template improperly parsed?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 2507, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!TemplateInfo.TemplateParams && |
| 2507 | (0) . __assert_fail ("!TemplateInfo.TemplateParams && \"Nested template improperly parsed?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 2507, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Nested template improperly parsed?"); |
| 2508 | ObjCDeclContextSwitch ObjCDC(*this); |
| 2509 | SourceLocation DeclEnd; |
| 2510 | return DeclGroupPtrTy::make( |
| 2511 | DeclGroupRef(ParseTemplateDeclarationOrSpecialization( |
| 2512 | DeclaratorContext::MemberContext, DeclEnd, AccessAttrs, AS))); |
| 2513 | } |
| 2514 | |
| 2515 | |
| 2516 | if (Tok.is(tok::kw___extension__)) { |
| 2517 | |
| 2518 | ExtensionRAIIObject O(Diags); |
| 2519 | ConsumeToken(); |
| 2520 | return ParseCXXClassMemberDeclaration(AS, AccessAttrs, |
| 2521 | TemplateInfo, TemplateDiags); |
| 2522 | } |
| 2523 | |
| 2524 | ParsedAttributesWithRange attrs(AttrFactory); |
| 2525 | ParsedAttributesViewWithRange FnAttrs; |
| 2526 | |
| 2527 | MaybeParseCXX11Attributes(attrs); |
| 2528 | |
| 2529 | |
| 2530 | FnAttrs.addAll(attrs.begin(), attrs.end()); |
| 2531 | FnAttrs.Range = attrs.Range; |
| 2532 | |
| 2533 | MaybeParseMicrosoftAttributes(attrs); |
| 2534 | |
| 2535 | if (Tok.is(tok::kw_using)) { |
| 2536 | ProhibitAttributes(attrs); |
| 2537 | |
| 2538 | |
| 2539 | SourceLocation UsingLoc = ConsumeToken(); |
| 2540 | |
| 2541 | if (Tok.is(tok::kw_namespace)) { |
| 2542 | Diag(UsingLoc, diag::err_using_namespace_in_class); |
| 2543 | SkipUntil(tok::semi, StopBeforeMatch); |
| 2544 | return nullptr; |
| 2545 | } |
| 2546 | SourceLocation DeclEnd; |
| 2547 | |
| 2548 | return ParseUsingDeclaration(DeclaratorContext::MemberContext, TemplateInfo, |
| 2549 | UsingLoc, DeclEnd, AS); |
| 2550 | } |
| 2551 | |
| 2552 | |
| 2553 | LateParsedAttrList CommonLateParsedAttrs; |
| 2554 | |
| 2555 | |
| 2556 | |
| 2557 | ParsingDeclSpec DS(*this, TemplateDiags); |
| 2558 | DS.takeAttributesFrom(attrs); |
| 2559 | if (MalformedTypeSpec) |
| 2560 | DS.SetTypeSpecError(); |
| 2561 | |
| 2562 | ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DeclSpecContext::DSC_class, |
| 2563 | &CommonLateParsedAttrs); |
| 2564 | |
| 2565 | |
| 2566 | X.restore(); |
| 2567 | |
| 2568 | |
| 2569 | |
| 2570 | if (DS.hasTagDefinition() && |
| 2571 | TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate && |
| 2572 | DiagnoseMissingSemiAfterTagDefinition(DS, AS, DeclSpecContext::DSC_class, |
| 2573 | &CommonLateParsedAttrs)) |
| 2574 | return nullptr; |
| 2575 | |
| 2576 | MultiTemplateParamsArg TemplateParams( |
| 2577 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() |
| 2578 | : nullptr, |
| 2579 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0); |
| 2580 | |
| 2581 | if (TryConsumeToken(tok::semi)) { |
| 2582 | if (DS.isFriendSpecified()) |
| 2583 | ProhibitAttributes(FnAttrs); |
| 2584 | |
| 2585 | RecordDecl *AnonRecord = nullptr; |
| 2586 | Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec( |
| 2587 | getCurScope(), AS, DS, TemplateParams, false, AnonRecord); |
| 2588 | DS.complete(TheDecl); |
| 2589 | if (AnonRecord) { |
| 2590 | Decl* decls[] = {AnonRecord, TheDecl}; |
| 2591 | return Actions.BuildDeclaratorGroup(decls); |
| 2592 | } |
| 2593 | return Actions.ConvertDeclToDeclGroup(TheDecl); |
| 2594 | } |
| 2595 | |
| 2596 | ParsingDeclarator DeclaratorInfo(*this, DS, DeclaratorContext::MemberContext); |
| 2597 | VirtSpecifiers VS; |
| 2598 | |
| 2599 | |
| 2600 | LateParsedAttrList LateParsedAttrs; |
| 2601 | |
| 2602 | SourceLocation EqualLoc; |
| 2603 | SourceLocation PureSpecLoc; |
| 2604 | |
| 2605 | auto TryConsumePureSpecifier = [&] (bool AllowDefinition) { |
| 2606 | if (Tok.isNot(tok::equal)) |
| 2607 | return false; |
| 2608 | |
| 2609 | auto &Zero = NextToken(); |
| 2610 | SmallString<8> Buffer; |
| 2611 | if (Zero.isNot(tok::numeric_constant) || Zero.getLength() != 1 || |
| 2612 | PP.getSpelling(Zero, Buffer) != "0") |
| 2613 | return false; |
| 2614 | |
| 2615 | auto &After = GetLookAheadToken(2); |
| 2616 | if (!After.isOneOf(tok::semi, tok::comma) && |
| 2617 | !(AllowDefinition && |
| 2618 | After.isOneOf(tok::l_brace, tok::colon, tok::kw_try))) |
| 2619 | return false; |
| 2620 | |
| 2621 | EqualLoc = ConsumeToken(); |
| 2622 | PureSpecLoc = ConsumeToken(); |
| 2623 | return true; |
| 2624 | }; |
| 2625 | |
| 2626 | SmallVector<Decl *, 8> DeclsInGroup; |
| 2627 | ExprResult BitfieldSize; |
| 2628 | bool ExpectSemi = true; |
| 2629 | |
| 2630 | |
| 2631 | if (ParseCXXMemberDeclaratorBeforeInitializer( |
| 2632 | DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) { |
| 2633 | TryConsumeToken(tok::semi); |
| 2634 | return nullptr; |
| 2635 | } |
| 2636 | |
| 2637 | |
| 2638 | if (BitfieldSize.isUnset()) { |
| 2639 | |
| 2640 | |
| 2641 | if (getLangOpts().MicrosoftExt && DeclaratorInfo.isDeclarationOfFunction()) |
| 2642 | TryConsumePureSpecifier( true); |
| 2643 | |
| 2644 | FunctionDefinitionKind DefinitionKind = FDK_Declaration; |
| 2645 | |
| 2646 | |
| 2647 | |
| 2648 | |
| 2649 | |
| 2650 | if (Tok.is(tok::l_brace) && !getLangOpts().CPlusPlus11) { |
| 2651 | DefinitionKind = FDK_Definition; |
| 2652 | } else if (DeclaratorInfo.isFunctionDeclarator()) { |
| 2653 | if (Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try)) { |
| 2654 | DefinitionKind = FDK_Definition; |
| 2655 | } else if (Tok.is(tok::equal)) { |
| 2656 | const Token &KW = NextToken(); |
| 2657 | if (KW.is(tok::kw_default)) |
| 2658 | DefinitionKind = FDK_Defaulted; |
| 2659 | else if (KW.is(tok::kw_delete)) |
| 2660 | DefinitionKind = FDK_Deleted; |
| 2661 | } |
| 2662 | } |
| 2663 | DeclaratorInfo.setFunctionDefinitionKind(DefinitionKind); |
| 2664 | |
| 2665 | |
| 2666 | |
| 2667 | if (DeclaratorInfo.isFunctionDeclarator() && |
| 2668 | DefinitionKind != FDK_Definition && DS.isFriendSpecified()) { |
| 2669 | |
| 2670 | |
| 2671 | ProhibitAttributes(FnAttrs); |
| 2672 | } |
| 2673 | |
| 2674 | if (DefinitionKind != FDK_Declaration) { |
| 2675 | if (!DeclaratorInfo.isFunctionDeclarator()) { |
| 2676 | Diag(DeclaratorInfo.getIdentifierLoc(), diag::err_func_def_no_params); |
| 2677 | ConsumeBrace(); |
| 2678 | SkipUntil(tok::r_brace); |
| 2679 | |
| 2680 | |
| 2681 | TryConsumeToken(tok::semi); |
| 2682 | |
| 2683 | return nullptr; |
| 2684 | } |
| 2685 | |
| 2686 | if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { |
| 2687 | Diag(DeclaratorInfo.getIdentifierLoc(), |
| 2688 | diag::err_function_declared_typedef); |
| 2689 | |
| 2690 | |
| 2691 | DS.ClearStorageClassSpecs(); |
| 2692 | } |
| 2693 | |
| 2694 | Decl *FunDecl = |
| 2695 | ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo, TemplateInfo, |
| 2696 | VS, PureSpecLoc); |
| 2697 | |
| 2698 | if (FunDecl) { |
| 2699 | for (unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) { |
| 2700 | CommonLateParsedAttrs[i]->addDecl(FunDecl); |
| 2701 | } |
| 2702 | for (unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) { |
| 2703 | LateParsedAttrs[i]->addDecl(FunDecl); |
| 2704 | } |
| 2705 | } |
| 2706 | LateParsedAttrs.clear(); |
| 2707 | |
| 2708 | |
| 2709 | if (Tok.is(tok::semi)) |
| 2710 | ConsumeExtraSemi(AfterMemberFunctionDefinition); |
| 2711 | |
| 2712 | return DeclGroupPtrTy::make(DeclGroupRef(FunDecl)); |
| 2713 | } |
| 2714 | } |
| 2715 | |
| 2716 | |
| 2717 | |
| 2718 | |
| 2719 | |
| 2720 | while (1) { |
| 2721 | InClassInitStyle HasInClassInit = ICIS_NoInit; |
| 2722 | bool HasStaticInitializer = false; |
| 2723 | if (Tok.isOneOf(tok::equal, tok::l_brace) && PureSpecLoc.isInvalid()) { |
| 2724 | if (DeclaratorInfo.isDeclarationOfFunction()) { |
| 2725 | |
| 2726 | if (!TryConsumePureSpecifier( false)) |
| 2727 | |
| 2728 | HasStaticInitializer = true; |
| 2729 | } else if (DeclaratorInfo.getDeclSpec().getStorageClassSpec() != |
| 2730 | DeclSpec::SCS_static && |
| 2731 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() != |
| 2732 | DeclSpec::SCS_typedef && |
| 2733 | !DS.isFriendSpecified()) { |
| 2734 | |
| 2735 | if (BitfieldSize.get()) |
| 2736 | Diag(Tok, getLangOpts().CPlusPlus2a |
| 2737 | ? diag::warn_cxx17_compat_bitfield_member_init |
| 2738 | : diag::ext_bitfield_member_init); |
| 2739 | HasInClassInit = Tok.is(tok::equal) ? ICIS_CopyInit : ICIS_ListInit; |
| 2740 | } else { |
| 2741 | HasStaticInitializer = true; |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | |
| 2746 | |
| 2747 | |
| 2748 | |
| 2749 | NamedDecl *ThisDecl = nullptr; |
| 2750 | if (DS.isFriendSpecified()) { |
| 2751 | |
| 2752 | |
| 2753 | |
| 2754 | |
| 2755 | |
| 2756 | SmallVector<SourceRange, 4> Ranges; |
| 2757 | DeclaratorInfo.getCXX11AttributeRanges(Ranges); |
| 2758 | for (SmallVectorImpl<SourceRange>::iterator I = Ranges.begin(), |
| 2759 | E = Ranges.end(); I != E; ++I) |
| 2760 | Diag((*I).getBegin(), diag::err_attributes_not_allowed) << *I; |
| 2761 | |
| 2762 | ThisDecl = Actions.ActOnFriendFunctionDecl(getCurScope(), DeclaratorInfo, |
| 2763 | TemplateParams); |
| 2764 | } else { |
| 2765 | ThisDecl = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, |
| 2766 | DeclaratorInfo, |
| 2767 | TemplateParams, |
| 2768 | BitfieldSize.get(), |
| 2769 | VS, HasInClassInit); |
| 2770 | |
| 2771 | if (VarTemplateDecl *VT = |
| 2772 | ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) : nullptr) |
| 2773 | |
| 2774 | |
| 2775 | ThisDecl = VT->getTemplatedDecl(); |
| 2776 | |
| 2777 | if (ThisDecl) |
| 2778 | Actions.ProcessDeclAttributeList(getCurScope(), ThisDecl, AccessAttrs); |
| 2779 | } |
| 2780 | |
| 2781 | |
| 2782 | |
| 2783 | if (HasInClassInit != ICIS_NoInit && |
| 2784 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() == |
| 2785 | DeclSpec::SCS_static) { |
| 2786 | HasInClassInit = ICIS_NoInit; |
| 2787 | HasStaticInitializer = true; |
| 2788 | } |
| 2789 | |
| 2790 | if (ThisDecl && PureSpecLoc.isValid()) |
| 2791 | Actions.ActOnPureSpecifier(ThisDecl, PureSpecLoc); |
| 2792 | |
| 2793 | |
| 2794 | if (HasInClassInit != ICIS_NoInit) { |
| 2795 | |
| 2796 | Diag(Tok, getLangOpts().CPlusPlus11 |
| 2797 | ? diag::warn_cxx98_compat_nonstatic_member_init |
| 2798 | : diag::ext_nonstatic_member_init); |
| 2799 | |
| 2800 | if (DeclaratorInfo.isArrayOfUnknownBound()) { |
| 2801 | |
| 2802 | |
| 2803 | |
| 2804 | |
| 2805 | |
| 2806 | Diag(Tok, diag::err_incomplete_array_member_init); |
| 2807 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
| 2808 | |
| 2809 | |
| 2810 | if (ThisDecl) |
| 2811 | ThisDecl->setInvalidDecl(); |
| 2812 | } else |
| 2813 | ParseCXXNonStaticMemberInitializer(ThisDecl); |
| 2814 | } else if (HasStaticInitializer) { |
| 2815 | |
| 2816 | ExprResult Init = ParseCXXMemberInitializer( |
| 2817 | ThisDecl, DeclaratorInfo.isDeclarationOfFunction(), EqualLoc); |
| 2818 | |
| 2819 | if (Init.isInvalid()) |
| 2820 | SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); |
| 2821 | else if (ThisDecl) |
| 2822 | Actions.AddInitializerToDecl(ThisDecl, Init.get(), EqualLoc.isInvalid()); |
| 2823 | } else if (ThisDecl && DS.getStorageClassSpec() == DeclSpec::SCS_static) |
| 2824 | |
| 2825 | Actions.ActOnUninitializedDecl(ThisDecl); |
| 2826 | |
| 2827 | if (ThisDecl) { |
| 2828 | if (!ThisDecl->isInvalidDecl()) { |
| 2829 | |
| 2830 | for (unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) |
| 2831 | CommonLateParsedAttrs[i]->addDecl(ThisDecl); |
| 2832 | |
| 2833 | for (unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) |
| 2834 | LateParsedAttrs[i]->addDecl(ThisDecl); |
| 2835 | } |
| 2836 | Actions.FinalizeDeclaration(ThisDecl); |
| 2837 | DeclsInGroup.push_back(ThisDecl); |
| 2838 | |
| 2839 | if (DeclaratorInfo.isFunctionDeclarator() && |
| 2840 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() != |
| 2841 | DeclSpec::SCS_typedef) |
| 2842 | HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl); |
| 2843 | } |
| 2844 | LateParsedAttrs.clear(); |
| 2845 | |
| 2846 | DeclaratorInfo.complete(ThisDecl); |
| 2847 | |
| 2848 | |
| 2849 | |
| 2850 | SourceLocation CommaLoc; |
| 2851 | if (!TryConsumeToken(tok::comma, CommaLoc)) |
| 2852 | break; |
| 2853 | |
| 2854 | if (Tok.isAtStartOfLine() && |
| 2855 | !MightBeDeclarator(DeclaratorContext::MemberContext)) { |
| 2856 | |
| 2857 | |
| 2858 | |
| 2859 | Diag(CommaLoc, diag::err_expected_semi_declaration) |
| 2860 | << FixItHint::CreateReplacement(CommaLoc, ";"); |
| 2861 | ExpectSemi = false; |
| 2862 | break; |
| 2863 | } |
| 2864 | |
| 2865 | |
| 2866 | DeclaratorInfo.clear(); |
| 2867 | VS.clear(); |
| 2868 | BitfieldSize = ExprResult(); |
| 2869 | EqualLoc = PureSpecLoc = SourceLocation(); |
| 2870 | DeclaratorInfo.setCommaLoc(CommaLoc); |
| 2871 | |
| 2872 | |
| 2873 | MaybeParseGNUAttributes(DeclaratorInfo); |
| 2874 | |
| 2875 | if (ParseCXXMemberDeclaratorBeforeInitializer( |
| 2876 | DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) |
| 2877 | break; |
| 2878 | } |
| 2879 | |
| 2880 | if (ExpectSemi && |
| 2881 | ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) { |
| 2882 | |
| 2883 | SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); |
| 2884 | |
| 2885 | TryConsumeToken(tok::semi); |
| 2886 | return nullptr; |
| 2887 | } |
| 2888 | |
| 2889 | return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup); |
| 2890 | } |
| 2891 | |
| 2892 | |
| 2893 | |
| 2894 | |
| 2895 | |
| 2896 | |
| 2897 | |
| 2898 | |
| 2899 | |
| 2900 | |
| 2901 | |
| 2902 | |
| 2903 | |
| 2904 | |
| 2905 | |
| 2906 | |
| 2907 | |
| 2908 | |
| 2909 | |
| 2910 | |
| 2911 | |
| 2912 | ExprResult Parser::ParseCXXMemberInitializer(Decl *D, bool IsFunction, |
| 2913 | SourceLocation &EqualLoc) { |
| 2914 | (0) . __assert_fail ("Tok.isOneOf(tok..equal, tok..l_brace) && \"Data member initializer not starting with '=' or '{'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 2915, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::equal, tok::l_brace) |
| 2915 | (0) . __assert_fail ("Tok.isOneOf(tok..equal, tok..l_brace) && \"Data member initializer not starting with '=' or '{'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 2915, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && "Data member initializer not starting with '=' or '{'"); |
| 2916 | |
| 2917 | EnterExpressionEvaluationContext Context( |
| 2918 | Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated, D); |
| 2919 | if (TryConsumeToken(tok::equal, EqualLoc)) { |
| 2920 | if (Tok.is(tok::kw_delete)) { |
| 2921 | |
| 2922 | |
| 2923 | |
| 2924 | |
| 2925 | |
| 2926 | const Token &Next = NextToken(); |
| 2927 | if (IsFunction || Next.isOneOf(tok::semi, tok::comma, tok::eof)) { |
| 2928 | if (IsFunction) |
| 2929 | Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) |
| 2930 | << 1 ; |
| 2931 | else |
| 2932 | Diag(ConsumeToken(), diag::err_deleted_non_function); |
| 2933 | return ExprError(); |
| 2934 | } |
| 2935 | } else if (Tok.is(tok::kw_default)) { |
| 2936 | if (IsFunction) |
| 2937 | Diag(Tok, diag::err_default_delete_in_multiple_declaration) |
| 2938 | << 0 ; |
| 2939 | else |
| 2940 | Diag(ConsumeToken(), diag::err_default_special_members); |
| 2941 | return ExprError(); |
| 2942 | } |
| 2943 | } |
| 2944 | if (const auto *PD = dyn_cast_or_null<MSPropertyDecl>(D)) { |
| 2945 | Diag(Tok, diag::err_ms_property_initializer) << PD; |
| 2946 | return ExprError(); |
| 2947 | } |
| 2948 | return ParseInitializer(); |
| 2949 | } |
| 2950 | |
| 2951 | void Parser::SkipCXXMemberSpecification(SourceLocation RecordLoc, |
| 2952 | SourceLocation AttrFixitLoc, |
| 2953 | unsigned TagType, Decl *TagDecl) { |
| 2954 | |
| 2955 | if (getLangOpts().CPlusPlus && Tok.is(tok::identifier)) { |
| 2956 | (0) . __assert_fail ("isCXX11FinalKeyword() && \"not a class definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 2956, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isCXX11FinalKeyword() && "not a class definition"); |
| 2957 | ConsumeToken(); |
| 2958 | |
| 2959 | |
| 2960 | |
| 2961 | ParsedAttributesWithRange Attrs(AttrFactory); |
| 2962 | CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc); |
| 2963 | |
| 2964 | |
| 2965 | |
| 2966 | |
| 2967 | if (Tok.isNot(tok::colon) && Tok.isNot(tok::l_brace)) |
| 2968 | return; |
| 2969 | } |
| 2970 | |
| 2971 | |
| 2972 | |
| 2973 | |
| 2974 | if (Tok.is(tok::colon)) { |
| 2975 | |
| 2976 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); |
| 2977 | ParsingClassDefinition ParsingDef(*this, TagDecl, true, |
| 2978 | TagType == DeclSpec::TST_interface); |
| 2979 | auto OldContext = |
| 2980 | Actions.ActOnTagStartSkippedDefinition(getCurScope(), TagDecl); |
| 2981 | |
| 2982 | |
| 2983 | ParseBaseClause(nullptr); |
| 2984 | |
| 2985 | Actions.ActOnTagFinishSkippedDefinition(OldContext); |
| 2986 | |
| 2987 | if (!Tok.is(tok::l_brace)) { |
| 2988 | Diag(PP.getLocForEndOfToken(PrevTokLocation), |
| 2989 | diag::err_expected_lbrace_after_base_specifiers); |
| 2990 | return; |
| 2991 | } |
| 2992 | } |
| 2993 | |
| 2994 | |
| 2995 | assert(Tok.is(tok::l_brace)); |
| 2996 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 2997 | T.consumeOpen(); |
| 2998 | T.skipToEnd(); |
| 2999 | |
| 3000 | |
| 3001 | ParsedAttributes Attrs(AttrFactory); |
| 3002 | if (Tok.is(tok::kw___attribute)) |
| 3003 | MaybeParseGNUAttributes(Attrs); |
| 3004 | } |
| 3005 | |
| 3006 | Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclarationWithPragmas( |
| 3007 | AccessSpecifier &AS, ParsedAttributesWithRange &AccessAttrs, |
| 3008 | DeclSpec::TST TagType, Decl *TagDecl) { |
| 3009 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
| 3010 | |
| 3011 | switch (Tok.getKind()) { |
| 3012 | case tok::kw___if_exists: |
| 3013 | case tok::kw___if_not_exists: |
| 3014 | ParseMicrosoftIfExistsClassDeclaration(TagType, AccessAttrs, AS); |
| 3015 | return nullptr; |
| 3016 | |
| 3017 | case tok::semi: |
| 3018 | |
| 3019 | ConsumeExtraSemi(InsideStruct, TagType); |
| 3020 | return nullptr; |
| 3021 | |
| 3022 | |
| 3023 | case tok::annot_pragma_vis: |
| 3024 | HandlePragmaVisibility(); |
| 3025 | return nullptr; |
| 3026 | case tok::annot_pragma_pack: |
| 3027 | HandlePragmaPack(); |
| 3028 | return nullptr; |
| 3029 | case tok::annot_pragma_align: |
| 3030 | HandlePragmaAlign(); |
| 3031 | return nullptr; |
| 3032 | case tok::annot_pragma_ms_pointers_to_members: |
| 3033 | HandlePragmaMSPointersToMembers(); |
| 3034 | return nullptr; |
| 3035 | case tok::annot_pragma_ms_pragma: |
| 3036 | HandlePragmaMSPragma(); |
| 3037 | return nullptr; |
| 3038 | case tok::annot_pragma_ms_vtordisp: |
| 3039 | HandlePragmaMSVtorDisp(); |
| 3040 | return nullptr; |
| 3041 | case tok::annot_pragma_dump: |
| 3042 | HandlePragmaDump(); |
| 3043 | return nullptr; |
| 3044 | |
| 3045 | case tok::kw_namespace: |
| 3046 | |
| 3047 | DiagnoseUnexpectedNamespace(cast<NamedDecl>(TagDecl)); |
| 3048 | return nullptr; |
| 3049 | |
| 3050 | case tok::kw_private: |
| 3051 | |
| 3052 | |
| 3053 | if (getLangOpts().OpenCL && !NextToken().is(tok::colon)) |
| 3054 | return ParseCXXClassMemberDeclaration(AS, AccessAttrs); |
| 3055 | LLVM_FALLTHROUGH; |
| 3056 | case tok::kw_public: |
| 3057 | case tok::kw_protected: { |
| 3058 | AccessSpecifier NewAS = getAccessSpecifierIfPresent(); |
| 3059 | assert(NewAS != AS_none); |
| 3060 | |
| 3061 | AS = NewAS; |
| 3062 | SourceLocation ASLoc = Tok.getLocation(); |
| 3063 | unsigned TokLength = Tok.getLength(); |
| 3064 | ConsumeToken(); |
| 3065 | AccessAttrs.clear(); |
| 3066 | MaybeParseGNUAttributes(AccessAttrs); |
| 3067 | |
| 3068 | SourceLocation EndLoc; |
| 3069 | if (TryConsumeToken(tok::colon, EndLoc)) { |
| 3070 | } else if (TryConsumeToken(tok::semi, EndLoc)) { |
| 3071 | Diag(EndLoc, diag::err_expected) |
| 3072 | << tok::colon << FixItHint::CreateReplacement(EndLoc, ":"); |
| 3073 | } else { |
| 3074 | EndLoc = ASLoc.getLocWithOffset(TokLength); |
| 3075 | Diag(EndLoc, diag::err_expected) |
| 3076 | << tok::colon << FixItHint::CreateInsertion(EndLoc, ":"); |
| 3077 | } |
| 3078 | |
| 3079 | |
| 3080 | |
| 3081 | if (TagType == DeclSpec::TST_interface && AS != AS_public) { |
| 3082 | Diag(ASLoc, diag::err_access_specifier_interface) << (AS == AS_protected); |
| 3083 | } |
| 3084 | |
| 3085 | if (Actions.ActOnAccessSpecifier(NewAS, ASLoc, EndLoc, AccessAttrs)) { |
| 3086 | |
| 3087 | AccessAttrs.clear(); |
| 3088 | } |
| 3089 | |
| 3090 | return nullptr; |
| 3091 | } |
| 3092 | |
| 3093 | case tok::annot_pragma_openmp: |
| 3094 | return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, AccessAttrs, TagType, |
| 3095 | TagDecl); |
| 3096 | |
| 3097 | default: |
| 3098 | return ParseCXXClassMemberDeclaration(AS, AccessAttrs); |
| 3099 | } |
| 3100 | } |
| 3101 | |
| 3102 | |
| 3103 | |
| 3104 | |
| 3105 | |
| 3106 | |
| 3107 | |
| 3108 | void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, |
| 3109 | SourceLocation AttrFixitLoc, |
| 3110 | ParsedAttributesWithRange &Attrs, |
| 3111 | unsigned TagType, Decl *TagDecl) { |
| 3112 | (0) . __assert_fail ("(TagType == DeclSpec..TST_struct || TagType == DeclSpec..TST_interface || TagType == DeclSpec..TST_union || TagType == DeclSpec..TST_class) && \"Invalid TagType!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3115, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((TagType == DeclSpec::TST_struct || |
| 3113 | (0) . __assert_fail ("(TagType == DeclSpec..TST_struct || TagType == DeclSpec..TST_interface || TagType == DeclSpec..TST_union || TagType == DeclSpec..TST_class) && \"Invalid TagType!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3115, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> TagType == DeclSpec::TST_interface || |
| 3114 | (0) . __assert_fail ("(TagType == DeclSpec..TST_struct || TagType == DeclSpec..TST_interface || TagType == DeclSpec..TST_union || TagType == DeclSpec..TST_class) && \"Invalid TagType!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3115, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> TagType == DeclSpec::TST_union || |
| 3115 | (0) . __assert_fail ("(TagType == DeclSpec..TST_struct || TagType == DeclSpec..TST_interface || TagType == DeclSpec..TST_union || TagType == DeclSpec..TST_class) && \"Invalid TagType!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3115, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> TagType == DeclSpec::TST_class) && "Invalid TagType!"); |
| 3116 | |
| 3117 | PrettyDeclStackTraceEntry CrashInfo(Actions.Context, TagDecl, RecordLoc, |
| 3118 | "parsing struct/union/class body"); |
| 3119 | |
| 3120 | |
| 3121 | |
| 3122 | bool NonNestedClass = true; |
| 3123 | if (!ClassStack.empty()) { |
| 3124 | for (const Scope *S = getCurScope(); S; S = S->getParent()) { |
| 3125 | if (S->isClassScope()) { |
| 3126 | |
| 3127 | NonNestedClass = false; |
| 3128 | |
| 3129 | |
| 3130 | if (getCurrentClass().IsInterface) { |
| 3131 | Diag(RecordLoc, diag::err_invalid_member_in_interface) |
| 3132 | << |
| 3133 | << (isa<NamedDecl>(TagDecl) |
| 3134 | ? cast<NamedDecl>(TagDecl)->getQualifiedNameAsString() |
| 3135 | : "(anonymous)"); |
| 3136 | } |
| 3137 | break; |
| 3138 | } |
| 3139 | |
| 3140 | if ((S->getFlags() & Scope::FnScope)) |
| 3141 | |
| 3142 | |
| 3143 | break; |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | |
| 3148 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); |
| 3149 | |
| 3150 | |
| 3151 | ParsingClassDefinition ParsingDef(*this, TagDecl, NonNestedClass, |
| 3152 | TagType == DeclSpec::TST_interface); |
| 3153 | |
| 3154 | if (TagDecl) |
| 3155 | Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); |
| 3156 | |
| 3157 | SourceLocation FinalLoc; |
| 3158 | bool IsFinalSpelledSealed = false; |
| 3159 | |
| 3160 | |
| 3161 | if (getLangOpts().CPlusPlus && Tok.is(tok::identifier)) { |
| 3162 | VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(Tok); |
| 3163 | (0) . __assert_fail ("(Specifier == VirtSpecifiers..VS_Final || Specifier == VirtSpecifiers..VS_GNU_Final || Specifier == VirtSpecifiers..VS_Sealed) && \"not a class definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3166, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((Specifier == VirtSpecifiers::VS_Final || |
| 3164 | (0) . __assert_fail ("(Specifier == VirtSpecifiers..VS_Final || Specifier == VirtSpecifiers..VS_GNU_Final || Specifier == VirtSpecifiers..VS_Sealed) && \"not a class definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3166, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Specifier == VirtSpecifiers::VS_GNU_Final || |
| 3165 | (0) . __assert_fail ("(Specifier == VirtSpecifiers..VS_Final || Specifier == VirtSpecifiers..VS_GNU_Final || Specifier == VirtSpecifiers..VS_Sealed) && \"not a class definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3166, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Specifier == VirtSpecifiers::VS_Sealed) && |
| 3166 | (0) . __assert_fail ("(Specifier == VirtSpecifiers..VS_Final || Specifier == VirtSpecifiers..VS_GNU_Final || Specifier == VirtSpecifiers..VS_Sealed) && \"not a class definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3166, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "not a class definition"); |
| 3167 | FinalLoc = ConsumeToken(); |
| 3168 | IsFinalSpelledSealed = Specifier == VirtSpecifiers::VS_Sealed; |
| 3169 | |
| 3170 | if (TagType == DeclSpec::TST_interface) |
| 3171 | Diag(FinalLoc, diag::err_override_control_interface) |
| 3172 | << VirtSpecifiers::getSpecifierName(Specifier); |
| 3173 | else if (Specifier == VirtSpecifiers::VS_Final) |
| 3174 | Diag(FinalLoc, getLangOpts().CPlusPlus11 |
| 3175 | ? diag::warn_cxx98_compat_override_control_keyword |
| 3176 | : diag::ext_override_control_keyword) |
| 3177 | << VirtSpecifiers::getSpecifierName(Specifier); |
| 3178 | else if (Specifier == VirtSpecifiers::VS_Sealed) |
| 3179 | Diag(FinalLoc, diag::ext_ms_sealed_keyword); |
| 3180 | else if (Specifier == VirtSpecifiers::VS_GNU_Final) |
| 3181 | Diag(FinalLoc, diag::ext_warn_gnu_final); |
| 3182 | |
| 3183 | |
| 3184 | |
| 3185 | |
| 3186 | |
| 3187 | CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc); |
| 3188 | |
| 3189 | |
| 3190 | |
| 3191 | |
| 3192 | |
| 3193 | |
| 3194 | |
| 3195 | |
| 3196 | if (!Tok.is(tok::colon) && !Tok.is(tok::l_brace)) { |
| 3197 | if (TagDecl) |
| 3198 | Actions.ActOnTagDefinitionError(getCurScope(), TagDecl); |
| 3199 | return; |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | if (Tok.is(tok::colon)) { |
| 3204 | ParseScope InheritanceScope(this, getCurScope()->getFlags() | |
| 3205 | Scope::ClassInheritanceScope); |
| 3206 | |
| 3207 | ParseBaseClause(TagDecl); |
| 3208 | if (!Tok.is(tok::l_brace)) { |
| 3209 | bool SuggestFixIt = false; |
| 3210 | SourceLocation BraceLoc = PP.getLocForEndOfToken(PrevTokLocation); |
| 3211 | if (Tok.isAtStartOfLine()) { |
| 3212 | switch (Tok.getKind()) { |
| 3213 | case tok::kw_private: |
| 3214 | case tok::kw_protected: |
| 3215 | case tok::kw_public: |
| 3216 | SuggestFixIt = NextToken().getKind() == tok::colon; |
| 3217 | break; |
| 3218 | case tok::kw_static_assert: |
| 3219 | case tok::r_brace: |
| 3220 | case tok::kw_using: |
| 3221 | |
| 3222 | case tok::kw_template: |
| 3223 | SuggestFixIt = true; |
| 3224 | break; |
| 3225 | case tok::identifier: |
| 3226 | SuggestFixIt = isConstructorDeclarator(true); |
| 3227 | break; |
| 3228 | default: |
| 3229 | SuggestFixIt = isCXXSimpleDeclaration(); |
| 3230 | break; |
| 3231 | } |
| 3232 | } |
| 3233 | DiagnosticBuilder LBraceDiag = |
| 3234 | Diag(BraceLoc, diag::err_expected_lbrace_after_base_specifiers); |
| 3235 | if (SuggestFixIt) { |
| 3236 | LBraceDiag << FixItHint::CreateInsertion(BraceLoc, " {"); |
| 3237 | |
| 3238 | PP.EnterToken(Tok); |
| 3239 | Tok.setKind(tok::l_brace); |
| 3240 | } else { |
| 3241 | if (TagDecl) |
| 3242 | Actions.ActOnTagDefinitionError(getCurScope(), TagDecl); |
| 3243 | return; |
| 3244 | } |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | assert(Tok.is(tok::l_brace)); |
| 3249 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 3250 | T.consumeOpen(); |
| 3251 | |
| 3252 | if (TagDecl) |
| 3253 | Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, FinalLoc, |
| 3254 | IsFinalSpelledSealed, |
| 3255 | T.getOpenLocation()); |
| 3256 | |
| 3257 | |
| 3258 | |
| 3259 | |
| 3260 | AccessSpecifier CurAS; |
| 3261 | if (TagType == DeclSpec::TST_class) |
| 3262 | CurAS = AS_private; |
| 3263 | else |
| 3264 | CurAS = AS_public; |
| 3265 | ParsedAttributesWithRange AccessAttrs(AttrFactory); |
| 3266 | |
| 3267 | if (TagDecl) { |
| 3268 | |
| 3269 | while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) && |
| 3270 | Tok.isNot(tok::eof)) { |
| 3271 | |
| 3272 | ParseCXXClassMemberDeclarationWithPragmas( |
| 3273 | CurAS, AccessAttrs, static_cast<DeclSpec::TST>(TagType), TagDecl); |
| 3274 | } |
| 3275 | T.consumeClose(); |
| 3276 | } else { |
| 3277 | SkipUntil(tok::r_brace); |
| 3278 | } |
| 3279 | |
| 3280 | |
| 3281 | ParsedAttributes attrs(AttrFactory); |
| 3282 | MaybeParseGNUAttributes(attrs); |
| 3283 | |
| 3284 | if (TagDecl) |
| 3285 | Actions.ActOnFinishCXXMemberSpecification(getCurScope(), RecordLoc, TagDecl, |
| 3286 | T.getOpenLocation(), |
| 3287 | T.getCloseLocation(), attrs); |
| 3288 | |
| 3289 | |
| 3290 | |
| 3291 | |
| 3292 | |
| 3293 | |
| 3294 | if (TagDecl && NonNestedClass) { |
| 3295 | |
| 3296 | |
| 3297 | |
| 3298 | |
| 3299 | SourceLocation SavedPrevTokLocation = PrevTokLocation; |
| 3300 | ParseLexedAttributes(getCurrentClass()); |
| 3301 | ParseLexedMethodDeclarations(getCurrentClass()); |
| 3302 | |
| 3303 | |
| 3304 | Actions.ActOnFinishCXXMemberDecls(); |
| 3305 | |
| 3306 | ParseLexedMemberInitializers(getCurrentClass()); |
| 3307 | ParseLexedMethodDefs(getCurrentClass()); |
| 3308 | PrevTokLocation = SavedPrevTokLocation; |
| 3309 | |
| 3310 | |
| 3311 | |
| 3312 | Actions.ActOnFinishCXXNonNestedClass(TagDecl); |
| 3313 | } |
| 3314 | |
| 3315 | if (TagDecl) |
| 3316 | Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, T.getRange()); |
| 3317 | |
| 3318 | |
| 3319 | ParsingDef.Pop(); |
| 3320 | ClassScope.Exit(); |
| 3321 | } |
| 3322 | |
| 3323 | void Parser::DiagnoseUnexpectedNamespace(NamedDecl *D) { |
| 3324 | assert(Tok.is(tok::kw_namespace)); |
| 3325 | |
| 3326 | |
| 3327 | |
| 3328 | Diag(D->getLocation(), |
| 3329 | diag::err_missing_end_of_definition) << D; |
| 3330 | Diag(Tok.getLocation(), |
| 3331 | diag::note_missing_end_of_definition_before) << D; |
| 3332 | |
| 3333 | |
| 3334 | PP.EnterToken(Tok); |
| 3335 | |
| 3336 | Tok.startToken(); |
| 3337 | Tok.setLocation(PP.getLocForEndOfToken(PrevTokLocation)); |
| 3338 | Tok.setKind(tok::semi); |
| 3339 | PP.EnterToken(Tok); |
| 3340 | |
| 3341 | Tok.setKind(tok::r_brace); |
| 3342 | } |
| 3343 | |
| 3344 | |
| 3345 | |
| 3346 | |
| 3347 | |
| 3348 | |
| 3349 | |
| 3350 | |
| 3351 | |
| 3352 | |
| 3353 | |
| 3354 | |
| 3355 | |
| 3356 | |
| 3357 | |
| 3358 | |
| 3359 | |
| 3360 | |
| 3361 | |
| 3362 | |
| 3363 | |
| 3364 | |
| 3365 | void Parser::ParseConstructorInitializer(Decl *ConstructorDecl) { |
| 3366 | (0) . __assert_fail ("Tok.is(tok..colon) && \"Constructor initializer always starts with '.'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3367, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::colon) && |
| 3367 | (0) . __assert_fail ("Tok.is(tok..colon) && \"Constructor initializer always starts with '.'\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3367, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Constructor initializer always starts with ':'"); |
| 3368 | |
| 3369 | |
| 3370 | |
| 3371 | PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); |
| 3372 | SourceLocation ColonLoc = ConsumeToken(); |
| 3373 | |
| 3374 | SmallVector<CXXCtorInitializer*, 4> MemInitializers; |
| 3375 | bool AnyErrors = false; |
| 3376 | |
| 3377 | do { |
| 3378 | if (Tok.is(tok::code_completion)) { |
| 3379 | Actions.CodeCompleteConstructorInitializer(ConstructorDecl, |
| 3380 | MemInitializers); |
| 3381 | return cutOffParsing(); |
| 3382 | } |
| 3383 | |
| 3384 | MemInitResult MemInit = ParseMemInitializer(ConstructorDecl); |
| 3385 | if (!MemInit.isInvalid()) |
| 3386 | MemInitializers.push_back(MemInit.get()); |
| 3387 | else |
| 3388 | AnyErrors = true; |
| 3389 | |
| 3390 | if (Tok.is(tok::comma)) |
| 3391 | ConsumeToken(); |
| 3392 | else if (Tok.is(tok::l_brace)) |
| 3393 | break; |
| 3394 | |
| 3395 | |
| 3396 | else if (!MemInit.isInvalid() && |
| 3397 | Tok.isOneOf(tok::identifier, tok::coloncolon)) { |
| 3398 | SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation); |
| 3399 | Diag(Loc, diag::err_ctor_init_missing_comma) |
| 3400 | << FixItHint::CreateInsertion(Loc, ", "); |
| 3401 | } else { |
| 3402 | |
| 3403 | if (!MemInit.isInvalid()) |
| 3404 | Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace |
| 3405 | << tok::comma; |
| 3406 | SkipUntil(tok::l_brace, StopAtSemi | StopBeforeMatch); |
| 3407 | break; |
| 3408 | } |
| 3409 | } while (true); |
| 3410 | |
| 3411 | Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, MemInitializers, |
| 3412 | AnyErrors); |
| 3413 | } |
| 3414 | |
| 3415 | |
| 3416 | |
| 3417 | |
| 3418 | |
| 3419 | |
| 3420 | |
| 3421 | |
| 3422 | |
| 3423 | |
| 3424 | |
| 3425 | |
| 3426 | |
| 3427 | MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) { |
| 3428 | |
| 3429 | CXXScopeSpec SS; |
| 3430 | ParseOptionalCXXScopeSpecifier(SS, nullptr, ); |
| 3431 | |
| 3432 | |
| 3433 | IdentifierInfo *II = nullptr; |
| 3434 | SourceLocation IdLoc = Tok.getLocation(); |
| 3435 | |
| 3436 | DeclSpec DS(AttrFactory); |
| 3437 | |
| 3438 | ParsedType TemplateTypeTy; |
| 3439 | |
| 3440 | if (Tok.is(tok::identifier)) { |
| 3441 | |
| 3442 | |
| 3443 | II = Tok.getIdentifierInfo(); |
| 3444 | ConsumeToken(); |
| 3445 | } else if (Tok.is(tok::annot_decltype)) { |
| 3446 | |
| 3447 | |
| 3448 | |
| 3449 | |
| 3450 | ParseDecltypeSpecifier(DS); |
| 3451 | } else { |
| 3452 | TemplateIdAnnotation *TemplateId = Tok.is(tok::annot_template_id) |
| 3453 | ? takeTemplateIdAnnotation(Tok) |
| 3454 | : nullptr; |
| 3455 | if (TemplateId && (TemplateId->Kind == TNK_Type_template || |
| 3456 | TemplateId->Kind == TNK_Dependent_template_name)) { |
| 3457 | AnnotateTemplateIdTokenAsType(); |
| 3458 | type failed") ? static_cast (0) . __assert_fail ("Tok.is(tok..annot_typename) && \"template-id -> type failed\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3458, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
| 3459 | TemplateTypeTy = getTypeAnnotation(Tok); |
| 3460 | ConsumeAnnotationToken(); |
| 3461 | } else { |
| 3462 | Diag(Tok, diag::err_expected_member_or_base_name); |
| 3463 | return true; |
| 3464 | } |
| 3465 | } |
| 3466 | |
| 3467 | |
| 3468 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 3469 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 3470 | |
| 3471 | |
| 3472 | ExprResult InitList = ParseBraceInitializer(); |
| 3473 | if (InitList.isInvalid()) |
| 3474 | return true; |
| 3475 | |
| 3476 | SourceLocation EllipsisLoc; |
| 3477 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
| 3478 | |
| 3479 | return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, |
| 3480 | TemplateTypeTy, DS, IdLoc, |
| 3481 | InitList.get(), EllipsisLoc); |
| 3482 | } else if(Tok.is(tok::l_paren)) { |
| 3483 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3484 | T.consumeOpen(); |
| 3485 | |
| 3486 | |
| 3487 | ExprVector ArgExprs; |
| 3488 | CommaLocsTy CommaLocs; |
| 3489 | auto RunSignatureHelp = [&] { |
| 3490 | QualType PreferredType = Actions.ProduceCtorInitMemberSignatureHelp( |
| 3491 | getCurScope(), ConstructorDecl, SS, TemplateTypeTy, ArgExprs, II, |
| 3492 | T.getOpenLocation()); |
| 3493 | CalledSignatureHelp = true; |
| 3494 | return PreferredType; |
| 3495 | }; |
| 3496 | if (Tok.isNot(tok::r_paren) && |
| 3497 | ParseExpressionList(ArgExprs, CommaLocs, [&] { |
| 3498 | PreferredType.enterFunctionArgument(Tok.getLocation(), |
| 3499 | RunSignatureHelp); |
| 3500 | })) { |
| 3501 | if (PP.isCodeCompletionReached() && !CalledSignatureHelp) |
| 3502 | RunSignatureHelp(); |
| 3503 | SkipUntil(tok::r_paren, StopAtSemi); |
| 3504 | return true; |
| 3505 | } |
| 3506 | |
| 3507 | T.consumeClose(); |
| 3508 | |
| 3509 | SourceLocation EllipsisLoc; |
| 3510 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
| 3511 | |
| 3512 | return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, |
| 3513 | TemplateTypeTy, DS, IdLoc, |
| 3514 | T.getOpenLocation(), ArgExprs, |
| 3515 | T.getCloseLocation(), EllipsisLoc); |
| 3516 | } |
| 3517 | |
| 3518 | if (getLangOpts().CPlusPlus11) |
| 3519 | return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace; |
| 3520 | else |
| 3521 | return Diag(Tok, diag::err_expected) << tok::l_paren; |
| 3522 | } |
| 3523 | |
| 3524 | |
| 3525 | |
| 3526 | |
| 3527 | |
| 3528 | |
| 3529 | |
| 3530 | |
| 3531 | |
| 3532 | |
| 3533 | ExceptionSpecificationType |
| 3534 | Parser::tryParseExceptionSpecification(bool Delayed, |
| 3535 | SourceRange &SpecificationRange, |
| 3536 | SmallVectorImpl<ParsedType> &DynamicExceptions, |
| 3537 | SmallVectorImpl<SourceRange> &DynamicExceptionRanges, |
| 3538 | ExprResult &NoexceptExpr, |
| 3539 | CachedTokens *&ExceptionSpecTokens) { |
| 3540 | ExceptionSpecificationType Result = EST_None; |
| 3541 | ExceptionSpecTokens = nullptr; |
| 3542 | |
| 3543 | |
| 3544 | if (Delayed) { |
| 3545 | if (Tok.isNot(tok::kw_throw) && Tok.isNot(tok::kw_noexcept)) |
| 3546 | return EST_None; |
| 3547 | |
| 3548 | |
| 3549 | bool IsNoexcept = Tok.is(tok::kw_noexcept); |
| 3550 | Token StartTok = Tok; |
| 3551 | SpecificationRange = SourceRange(ConsumeToken()); |
| 3552 | |
| 3553 | |
| 3554 | if (!Tok.is(tok::l_paren)) { |
| 3555 | |
| 3556 | if (IsNoexcept) { |
| 3557 | Diag(Tok, diag::warn_cxx98_compat_noexcept_decl); |
| 3558 | NoexceptExpr = nullptr; |
| 3559 | return EST_BasicNoexcept; |
| 3560 | } |
| 3561 | |
| 3562 | Diag(Tok, diag::err_expected_lparen_after) << "throw"; |
| 3563 | return EST_DynamicNone; |
| 3564 | } |
| 3565 | |
| 3566 | |
| 3567 | ExceptionSpecTokens = new CachedTokens; |
| 3568 | ExceptionSpecTokens->push_back(StartTok); |
| 3569 | ExceptionSpecTokens->push_back(Tok); |
| 3570 | SpecificationRange.setEnd(ConsumeParen()); |
| 3571 | |
| 3572 | ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens, |
| 3573 | , |
| 3574 | ); |
| 3575 | SpecificationRange.setEnd(ExceptionSpecTokens->back().getLocation()); |
| 3576 | |
| 3577 | return EST_Unparsed; |
| 3578 | } |
| 3579 | |
| 3580 | |
| 3581 | if (Tok.is(tok::kw_throw)) { |
| 3582 | Result = ParseDynamicExceptionSpecification(SpecificationRange, |
| 3583 | DynamicExceptions, |
| 3584 | DynamicExceptionRanges); |
| 3585 | (0) . __assert_fail ("DynamicExceptions.size() == DynamicExceptionRanges.size() && \"Produced different number of exception types and ranges.\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3586, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DynamicExceptions.size() == DynamicExceptionRanges.size() && |
| 3586 | (0) . __assert_fail ("DynamicExceptions.size() == DynamicExceptionRanges.size() && \"Produced different number of exception types and ranges.\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3586, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Produced different number of exception types and ranges."); |
| 3587 | } |
| 3588 | |
| 3589 | |
| 3590 | if (Tok.isNot(tok::kw_noexcept)) |
| 3591 | return Result; |
| 3592 | |
| 3593 | Diag(Tok, diag::warn_cxx98_compat_noexcept_decl); |
| 3594 | |
| 3595 | |
| 3596 | |
| 3597 | SourceRange NoexceptRange; |
| 3598 | ExceptionSpecificationType NoexceptType = EST_None; |
| 3599 | |
| 3600 | SourceLocation KeywordLoc = ConsumeToken(); |
| 3601 | if (Tok.is(tok::l_paren)) { |
| 3602 | |
| 3603 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3604 | T.consumeOpen(); |
| 3605 | NoexceptExpr = ParseConstantExpression(); |
| 3606 | T.consumeClose(); |
| 3607 | if (!NoexceptExpr.isInvalid()) { |
| 3608 | NoexceptExpr = Actions.ActOnNoexceptSpec(KeywordLoc, NoexceptExpr.get(), |
| 3609 | NoexceptType); |
| 3610 | NoexceptRange = SourceRange(KeywordLoc, T.getCloseLocation()); |
| 3611 | } else { |
| 3612 | NoexceptType = EST_BasicNoexcept; |
| 3613 | } |
| 3614 | } else { |
| 3615 | |
| 3616 | NoexceptType = EST_BasicNoexcept; |
| 3617 | NoexceptRange = SourceRange(KeywordLoc, KeywordLoc); |
| 3618 | } |
| 3619 | |
| 3620 | if (Result == EST_None) { |
| 3621 | SpecificationRange = NoexceptRange; |
| 3622 | Result = NoexceptType; |
| 3623 | |
| 3624 | |
| 3625 | |
| 3626 | if (Tok.is(tok::kw_throw)) { |
| 3627 | Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); |
| 3628 | ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions, |
| 3629 | DynamicExceptionRanges); |
| 3630 | } |
| 3631 | } else { |
| 3632 | Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); |
| 3633 | } |
| 3634 | |
| 3635 | return Result; |
| 3636 | } |
| 3637 | |
| 3638 | static void diagnoseDynamicExceptionSpecification( |
| 3639 | Parser &P, SourceRange Range, bool IsNoexcept) { |
| 3640 | if (P.getLangOpts().CPlusPlus11) { |
| 3641 | const char *Replacement = IsNoexcept ? "noexcept" : "noexcept(false)"; |
| 3642 | P.Diag(Range.getBegin(), |
| 3643 | P.getLangOpts().CPlusPlus17 && !IsNoexcept |
| 3644 | ? diag::ext_dynamic_exception_spec |
| 3645 | : diag::warn_exception_spec_deprecated) |
| 3646 | << Range; |
| 3647 | P.Diag(Range.getBegin(), diag::note_exception_spec_deprecated) |
| 3648 | << Replacement << FixItHint::CreateReplacement(Range, Replacement); |
| 3649 | } |
| 3650 | } |
| 3651 | |
| 3652 | |
| 3653 | |
| 3654 | |
| 3655 | |
| 3656 | |
| 3657 | |
| 3658 | |
| 3659 | |
| 3660 | |
| 3661 | |
| 3662 | |
| 3663 | ExceptionSpecificationType Parser::ParseDynamicExceptionSpecification( |
| 3664 | SourceRange &SpecificationRange, |
| 3665 | SmallVectorImpl<ParsedType> &Exceptions, |
| 3666 | SmallVectorImpl<SourceRange> &Ranges) { |
| 3667 | (0) . __assert_fail ("Tok.is(tok..kw_throw) && \"expected throw\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3667, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_throw) && "expected throw"); |
| 3668 | |
| 3669 | SpecificationRange.setBegin(ConsumeToken()); |
| 3670 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3671 | if (T.consumeOpen()) { |
| 3672 | Diag(Tok, diag::err_expected_lparen_after) << "throw"; |
| 3673 | SpecificationRange.setEnd(SpecificationRange.getBegin()); |
| 3674 | return EST_DynamicNone; |
| 3675 | } |
| 3676 | |
| 3677 | |
| 3678 | |
| 3679 | if (Tok.is(tok::ellipsis)) { |
| 3680 | SourceLocation EllipsisLoc = ConsumeToken(); |
| 3681 | if (!getLangOpts().MicrosoftExt) |
| 3682 | Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec); |
| 3683 | T.consumeClose(); |
| 3684 | SpecificationRange.setEnd(T.getCloseLocation()); |
| 3685 | diagnoseDynamicExceptionSpecification(*this, SpecificationRange, false); |
| 3686 | return EST_MSAny; |
| 3687 | } |
| 3688 | |
| 3689 | |
| 3690 | SourceRange Range; |
| 3691 | while (Tok.isNot(tok::r_paren)) { |
| 3692 | TypeResult Res(ParseTypeName(&Range)); |
| 3693 | |
| 3694 | if (Tok.is(tok::ellipsis)) { |
| 3695 | |
| 3696 | |
| 3697 | |
| 3698 | SourceLocation Ellipsis = ConsumeToken(); |
| 3699 | Range.setEnd(Ellipsis); |
| 3700 | if (!Res.isInvalid()) |
| 3701 | Res = Actions.ActOnPackExpansion(Res.get(), Ellipsis); |
| 3702 | } |
| 3703 | |
| 3704 | if (!Res.isInvalid()) { |
| 3705 | Exceptions.push_back(Res.get()); |
| 3706 | Ranges.push_back(Range); |
| 3707 | } |
| 3708 | |
| 3709 | if (!TryConsumeToken(tok::comma)) |
| 3710 | break; |
| 3711 | } |
| 3712 | |
| 3713 | T.consumeClose(); |
| 3714 | SpecificationRange.setEnd(T.getCloseLocation()); |
| 3715 | diagnoseDynamicExceptionSpecification(*this, SpecificationRange, |
| 3716 | Exceptions.empty()); |
| 3717 | return Exceptions.empty() ? EST_DynamicNone : EST_Dynamic; |
| 3718 | } |
| 3719 | |
| 3720 | |
| 3721 | |
| 3722 | TypeResult Parser::ParseTrailingReturnType(SourceRange &Range, |
| 3723 | bool MayBeFollowedByDirectInit) { |
| 3724 | (0) . __assert_fail ("Tok.is(tok..arrow) && \"expected arrow\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3724, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::arrow) && "expected arrow"); |
| 3725 | |
| 3726 | ConsumeToken(); |
| 3727 | |
| 3728 | return ParseTypeName(&Range, MayBeFollowedByDirectInit |
| 3729 | ? DeclaratorContext::TrailingReturnVarContext |
| 3730 | : DeclaratorContext::TrailingReturnContext); |
| 3731 | } |
| 3732 | |
| 3733 | |
| 3734 | |
| 3735 | |
| 3736 | Sema::ParsingClassState |
| 3737 | Parser::PushParsingClass(Decl *ClassDecl, bool NonNestedClass, |
| 3738 | bool IsInterface) { |
| 3739 | (0) . __assert_fail ("(NonNestedClass || !ClassStack.empty()) && \"Nested class without outer class\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3740, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((NonNestedClass || !ClassStack.empty()) && |
| 3740 | (0) . __assert_fail ("(NonNestedClass || !ClassStack.empty()) && \"Nested class without outer class\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3740, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Nested class without outer class"); |
| 3741 | ClassStack.push(new ParsingClass(ClassDecl, NonNestedClass, IsInterface)); |
| 3742 | return Actions.PushParsingClass(); |
| 3743 | } |
| 3744 | |
| 3745 | |
| 3746 | |
| 3747 | void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) { |
| 3748 | for (unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I) |
| 3749 | delete Class->LateParsedDeclarations[I]; |
| 3750 | delete Class; |
| 3751 | } |
| 3752 | |
| 3753 | |
| 3754 | |
| 3755 | |
| 3756 | |
| 3757 | |
| 3758 | |
| 3759 | void Parser::PopParsingClass(Sema::ParsingClassState state) { |
| 3760 | (0) . __assert_fail ("!ClassStack.empty() && \"Mismatched push/pop for class parsing\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3760, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!ClassStack.empty() && "Mismatched push/pop for class parsing"); |
| 3761 | |
| 3762 | Actions.PopParsingClass(state); |
| 3763 | |
| 3764 | ParsingClass *Victim = ClassStack.top(); |
| 3765 | ClassStack.pop(); |
| 3766 | if (Victim->TopLevelClass) { |
| 3767 | |
| 3768 | |
| 3769 | DeallocateParsedClasses(Victim); |
| 3770 | return; |
| 3771 | } |
| 3772 | (0) . __assert_fail ("!ClassStack.empty() && \"Missing top-level class?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3772, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!ClassStack.empty() && "Missing top-level class?"); |
| 3773 | |
| 3774 | if (Victim->LateParsedDeclarations.empty()) { |
| 3775 | |
| 3776 | |
| 3777 | |
| 3778 | |
| 3779 | DeallocateParsedClasses(Victim); |
| 3780 | return; |
| 3781 | } |
| 3782 | |
| 3783 | |
| 3784 | |
| 3785 | |
| 3786 | (0) . __assert_fail ("getCurScope()->isClassScope() && \"Nested class outside of class scope?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3786, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getCurScope()->isClassScope() && "Nested class outside of class scope?"); |
| 3787 | ClassStack.top()->LateParsedDeclarations.push_back(new LateParsedClass(this, Victim)); |
| 3788 | Victim->TemplateScope = getCurScope()->getParent()->isTemplateParamScope(); |
| 3789 | } |
| 3790 | |
| 3791 | |
| 3792 | |
| 3793 | |
| 3794 | |
| 3795 | |
| 3796 | |
| 3797 | |
| 3798 | |
| 3799 | |
| 3800 | IdentifierInfo *Parser::TryParseCXX11AttributeIdentifier(SourceLocation &Loc) { |
| 3801 | switch (Tok.getKind()) { |
| 3802 | default: |
| 3803 | |
| 3804 | if (!Tok.isAnnotation()) { |
| 3805 | if (IdentifierInfo *II = Tok.getIdentifierInfo()) { |
| 3806 | Loc = ConsumeToken(); |
| 3807 | return II; |
| 3808 | } |
| 3809 | } |
| 3810 | return nullptr; |
| 3811 | |
| 3812 | case tok::numeric_constant: { |
| 3813 | |
| 3814 | |
| 3815 | |
| 3816 | if (Tok.getLocation().isMacroID()) { |
| 3817 | SmallString<8> ExpansionBuf; |
| 3818 | SourceLocation ExpansionLoc = |
| 3819 | PP.getSourceManager().getExpansionLoc(Tok.getLocation()); |
| 3820 | StringRef Spelling = PP.getSpelling(ExpansionLoc, ExpansionBuf); |
| 3821 | if (Spelling == "__clang__") { |
| 3822 | SourceRange TokRange( |
| 3823 | ExpansionLoc, |
| 3824 | PP.getSourceManager().getExpansionLoc(Tok.getEndLoc())); |
| 3825 | Diag(Tok, diag::warn_wrong_clang_attr_namespace) |
| 3826 | << FixItHint::CreateReplacement(TokRange, "_Clang"); |
| 3827 | Loc = ConsumeToken(); |
| 3828 | return &PP.getIdentifierTable().get("_Clang"); |
| 3829 | } |
| 3830 | } |
| 3831 | return nullptr; |
| 3832 | } |
| 3833 | |
| 3834 | case tok::ampamp: |
| 3835 | case tok::pipe: |
| 3836 | case tok::pipepipe: |
| 3837 | case tok::caret: |
| 3838 | case tok::tilde: |
| 3839 | case tok::amp: |
| 3840 | case tok::ampequal: |
| 3841 | case tok::pipeequal: |
| 3842 | case tok::caretequal: |
| 3843 | case tok::exclaim: |
| 3844 | case tok::exclaimequal: |
| 3845 | |
| 3846 | |
| 3847 | SmallString<8> SpellingBuf; |
| 3848 | SourceLocation SpellingLoc = |
| 3849 | PP.getSourceManager().getSpellingLoc(Tok.getLocation()); |
| 3850 | StringRef Spelling = PP.getSpelling(SpellingLoc, SpellingBuf); |
| 3851 | if (isLetter(Spelling[0])) { |
| 3852 | Loc = ConsumeToken(); |
| 3853 | return &PP.getIdentifierTable().get(Spelling); |
| 3854 | } |
| 3855 | return nullptr; |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName, |
| 3860 | IdentifierInfo *ScopeName) { |
| 3861 | switch (ParsedAttr::getKind(AttrName, ScopeName, ParsedAttr::AS_CXX11)) { |
| 3862 | case ParsedAttr::AT_CarriesDependency: |
| 3863 | case ParsedAttr::AT_Deprecated: |
| 3864 | case ParsedAttr::AT_FallThrough: |
| 3865 | case ParsedAttr::AT_CXX11NoReturn: |
| 3866 | return true; |
| 3867 | case ParsedAttr::AT_WarnUnusedResult: |
| 3868 | return !ScopeName && AttrName->getName().equals("nodiscard"); |
| 3869 | case ParsedAttr::AT_Unused: |
| 3870 | return !ScopeName && AttrName->getName().equals("maybe_unused"); |
| 3871 | default: |
| 3872 | return false; |
| 3873 | } |
| 3874 | } |
| 3875 | |
| 3876 | |
| 3877 | |
| 3878 | |
| 3879 | |
| 3880 | |
| 3881 | |
| 3882 | |
| 3883 | |
| 3884 | |
| 3885 | |
| 3886 | |
| 3887 | |
| 3888 | |
| 3889 | |
| 3890 | bool Parser::ParseCXX11AttributeArgs(IdentifierInfo *AttrName, |
| 3891 | SourceLocation AttrNameLoc, |
| 3892 | ParsedAttributes &Attrs, |
| 3893 | SourceLocation *EndLoc, |
| 3894 | IdentifierInfo *ScopeName, |
| 3895 | SourceLocation ScopeLoc) { |
| 3896 | (0) . __assert_fail ("Tok.is(tok..l_paren) && \"Not a C++11 attribute argument list\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3896, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_paren) && "Not a C++11 attribute argument list"); |
| 3897 | SourceLocation LParenLoc = Tok.getLocation(); |
| 3898 | const LangOptions &LO = getLangOpts(); |
| 3899 | ParsedAttr::Syntax Syntax = |
| 3900 | LO.CPlusPlus ? ParsedAttr::AS_CXX11 : ParsedAttr::AS_C2x; |
| 3901 | |
| 3902 | |
| 3903 | |
| 3904 | if (!hasAttribute(LO.CPlusPlus ? AttrSyntax::CXX : AttrSyntax::C, ScopeName, |
| 3905 | AttrName, getTargetInfo(), getLangOpts())) { |
| 3906 | |
| 3907 | ConsumeParen(); |
| 3908 | SkipUntil(tok::r_paren); |
| 3909 | return false; |
| 3910 | } |
| 3911 | |
| 3912 | if (ScopeName && (ScopeName->isStr("gnu") || ScopeName->isStr("__gnu__"))) { |
| 3913 | |
| 3914 | |
| 3915 | ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, |
| 3916 | ScopeLoc, Syntax, nullptr); |
| 3917 | return true; |
| 3918 | } |
| 3919 | |
| 3920 | unsigned NumArgs; |
| 3921 | |
| 3922 | if (ScopeName && (ScopeName->isStr("clang") || ScopeName->isStr("_Clang"))) |
| 3923 | NumArgs = ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, |
| 3924 | ScopeName, ScopeLoc, Syntax); |
| 3925 | else |
| 3926 | NumArgs = |
| 3927 | ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, |
| 3928 | ScopeName, ScopeLoc, Syntax); |
| 3929 | |
| 3930 | if (!Attrs.empty() && |
| 3931 | IsBuiltInOrStandardCXX11Attribute(AttrName, ScopeName)) { |
| 3932 | ParsedAttr &Attr = Attrs.back(); |
| 3933 | |
| 3934 | |
| 3935 | |
| 3936 | |
| 3937 | if (Attr.getMaxArgs() && !NumArgs) { |
| 3938 | |
| 3939 | |
| 3940 | Diag(LParenLoc, diag::err_attribute_requires_arguments) << AttrName; |
| 3941 | Attr.setInvalid(true); |
| 3942 | } else if (!Attr.getMaxArgs()) { |
| 3943 | |
| 3944 | |
| 3945 | |
| 3946 | Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments) |
| 3947 | << AttrName |
| 3948 | << FixItHint::CreateRemoval(SourceRange(LParenLoc, *EndLoc)); |
| 3949 | Attr.setInvalid(true); |
| 3950 | } |
| 3951 | } |
| 3952 | return true; |
| 3953 | } |
| 3954 | |
| 3955 | |
| 3956 | |
| 3957 | |
| 3958 | |
| 3959 | |
| 3960 | |
| 3961 | |
| 3962 | |
| 3963 | |
| 3964 | |
| 3965 | |
| 3966 | |
| 3967 | |
| 3968 | |
| 3969 | |
| 3970 | |
| 3971 | |
| 3972 | |
| 3973 | |
| 3974 | |
| 3975 | |
| 3976 | |
| 3977 | |
| 3978 | |
| 3979 | void Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs, |
| 3980 | SourceLocation *endLoc) { |
| 3981 | if (Tok.is(tok::kw_alignas)) { |
| 3982 | Diag(Tok.getLocation(), diag::warn_cxx98_compat_alignas); |
| 3983 | ParseAlignmentSpecifier(attrs, endLoc); |
| 3984 | return; |
| 3985 | } |
| 3986 | |
| 3987 | (0) . __assert_fail ("Tok.is(tok..l_square) && NextToken().is(tok..l_square) && \"Not a double square bracket attribute list\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3988, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square) && |
| 3988 | (0) . __assert_fail ("Tok.is(tok..l_square) && NextToken().is(tok..l_square) && \"Not a double square bracket attribute list\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 3988, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Not a double square bracket attribute list"); |
| 3989 | |
| 3990 | Diag(Tok.getLocation(), diag::warn_cxx98_compat_attribute); |
| 3991 | |
| 3992 | ConsumeBracket(); |
| 3993 | ConsumeBracket(); |
| 3994 | |
| 3995 | SourceLocation CommonScopeLoc; |
| 3996 | IdentifierInfo *CommonScopeName = nullptr; |
| 3997 | if (Tok.is(tok::kw_using)) { |
| 3998 | Diag(Tok.getLocation(), getLangOpts().CPlusPlus17 |
| 3999 | ? diag::warn_cxx14_compat_using_attribute_ns |
| 4000 | : diag::ext_using_attribute_ns); |
| 4001 | ConsumeToken(); |
| 4002 | |
| 4003 | CommonScopeName = TryParseCXX11AttributeIdentifier(CommonScopeLoc); |
| 4004 | if (!CommonScopeName) { |
| 4005 | Diag(Tok.getLocation(), diag::err_expected) << tok::identifier; |
| 4006 | SkipUntil(tok::r_square, tok::colon, StopBeforeMatch); |
| 4007 | } |
| 4008 | if (!TryConsumeToken(tok::colon) && CommonScopeName) |
| 4009 | Diag(Tok.getLocation(), diag::err_expected) << tok::colon; |
| 4010 | } |
| 4011 | |
| 4012 | llvm::SmallDenseMap<IdentifierInfo*, SourceLocation, 4> SeenAttrs; |
| 4013 | |
| 4014 | while (Tok.isNot(tok::r_square)) { |
| 4015 | |
| 4016 | if (TryConsumeToken(tok::comma)) |
| 4017 | continue; |
| 4018 | |
| 4019 | SourceLocation ScopeLoc, AttrLoc; |
| 4020 | IdentifierInfo *ScopeName = nullptr, *AttrName = nullptr; |
| 4021 | |
| 4022 | AttrName = TryParseCXX11AttributeIdentifier(AttrLoc); |
| 4023 | if (!AttrName) |
| 4024 | |
| 4025 | break; |
| 4026 | |
| 4027 | |
| 4028 | if (TryConsumeToken(tok::coloncolon)) { |
| 4029 | ScopeName = AttrName; |
| 4030 | ScopeLoc = AttrLoc; |
| 4031 | |
| 4032 | AttrName = TryParseCXX11AttributeIdentifier(AttrLoc); |
| 4033 | if (!AttrName) { |
| 4034 | Diag(Tok.getLocation(), diag::err_expected) << tok::identifier; |
| 4035 | SkipUntil(tok::r_square, tok::comma, StopAtSemi | StopBeforeMatch); |
| 4036 | continue; |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | if (CommonScopeName) { |
| 4041 | if (ScopeName) { |
| 4042 | Diag(ScopeLoc, diag::err_using_attribute_ns_conflict) |
| 4043 | << SourceRange(CommonScopeLoc); |
| 4044 | } else { |
| 4045 | ScopeName = CommonScopeName; |
| 4046 | ScopeLoc = CommonScopeLoc; |
| 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | bool StandardAttr = IsBuiltInOrStandardCXX11Attribute(AttrName, ScopeName); |
| 4051 | bool AttrParsed = false; |
| 4052 | |
| 4053 | if (StandardAttr && |
| 4054 | !SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second) |
| 4055 | Diag(AttrLoc, diag::err_cxx11_attribute_repeated) |
| 4056 | << AttrName << SourceRange(SeenAttrs[AttrName]); |
| 4057 | |
| 4058 | |
| 4059 | if (Tok.is(tok::l_paren)) |
| 4060 | AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, attrs, endLoc, |
| 4061 | ScopeName, ScopeLoc); |
| 4062 | |
| 4063 | if (!AttrParsed) |
| 4064 | attrs.addNew( |
| 4065 | AttrName, |
| 4066 | SourceRange(ScopeLoc.isValid() ? ScopeLoc : AttrLoc, AttrLoc), |
| 4067 | ScopeName, ScopeLoc, nullptr, 0, |
| 4068 | getLangOpts().CPlusPlus ? ParsedAttr::AS_CXX11 : ParsedAttr::AS_C2x); |
| 4069 | |
| 4070 | if (TryConsumeToken(tok::ellipsis)) |
| 4071 | Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis) |
| 4072 | << AttrName; |
| 4073 | } |
| 4074 | |
| 4075 | if (ExpectAndConsume(tok::r_square)) |
| 4076 | SkipUntil(tok::r_square); |
| 4077 | if (endLoc) |
| 4078 | *endLoc = Tok.getLocation(); |
| 4079 | if (ExpectAndConsume(tok::r_square)) |
| 4080 | SkipUntil(tok::r_square); |
| 4081 | } |
| 4082 | |
| 4083 | |
| 4084 | |
| 4085 | |
| 4086 | |
| 4087 | void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs, |
| 4088 | SourceLocation *endLoc) { |
| 4089 | assert(standardAttributesAllowed()); |
| 4090 | |
| 4091 | SourceLocation StartLoc = Tok.getLocation(), Loc; |
| 4092 | if (!endLoc) |
| 4093 | endLoc = &Loc; |
| 4094 | |
| 4095 | do { |
| 4096 | ParseCXX11AttributeSpecifier(attrs, endLoc); |
| 4097 | } while (isCXX11AttributeSpecifier()); |
| 4098 | |
| 4099 | attrs.Range = SourceRange(StartLoc, *endLoc); |
| 4100 | } |
| 4101 | |
| 4102 | void Parser::DiagnoseAndSkipCXX11Attributes() { |
| 4103 | |
| 4104 | SourceLocation StartLoc = Tok.getLocation(); |
| 4105 | SourceLocation EndLoc = SkipCXX11Attributes(); |
| 4106 | |
| 4107 | if (EndLoc.isValid()) { |
| 4108 | SourceRange Range(StartLoc, EndLoc); |
| 4109 | Diag(StartLoc, diag::err_attributes_not_allowed) |
| 4110 | << Range; |
| 4111 | } |
| 4112 | } |
| 4113 | |
| 4114 | SourceLocation Parser::SkipCXX11Attributes() { |
| 4115 | SourceLocation EndLoc; |
| 4116 | |
| 4117 | if (!isCXX11AttributeSpecifier()) |
| 4118 | return EndLoc; |
| 4119 | |
| 4120 | do { |
| 4121 | if (Tok.is(tok::l_square)) { |
| 4122 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 4123 | T.consumeOpen(); |
| 4124 | T.skipToEnd(); |
| 4125 | EndLoc = T.getCloseLocation(); |
| 4126 | } else { |
| 4127 | (0) . __assert_fail ("Tok.is(tok..kw_alignas) && \"not an attribute specifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 4127, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_alignas) && "not an attribute specifier"); |
| 4128 | ConsumeToken(); |
| 4129 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 4130 | if (!T.consumeOpen()) |
| 4131 | T.skipToEnd(); |
| 4132 | EndLoc = T.getCloseLocation(); |
| 4133 | } |
| 4134 | } while (isCXX11AttributeSpecifier()); |
| 4135 | |
| 4136 | return EndLoc; |
| 4137 | } |
| 4138 | |
| 4139 | |
| 4140 | void Parser::ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs) { |
| 4141 | (0) . __assert_fail ("Tok.is(tok..identifier) && \"Not a Microsoft attribute list\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 4141, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::identifier) && "Not a Microsoft attribute list"); |
| 4142 | IdentifierInfo *UuidIdent = Tok.getIdentifierInfo(); |
| 4143 | (0) . __assert_fail ("UuidIdent->getName() == \"uuid\" && \"Not a Microsoft attribute list\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 4143, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(UuidIdent->getName() == "uuid" && "Not a Microsoft attribute list"); |
| 4144 | |
| 4145 | SourceLocation UuidLoc = Tok.getLocation(); |
| 4146 | ConsumeToken(); |
| 4147 | |
| 4148 | |
| 4149 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 4150 | if (T.consumeOpen()) { |
| 4151 | Diag(Tok, diag::err_expected) << tok::l_paren; |
| 4152 | return; |
| 4153 | } |
| 4154 | |
| 4155 | ArgsVector ArgExprs; |
| 4156 | if (Tok.is(tok::string_literal)) { |
| 4157 | |
| 4158 | ExprResult StringResult = ParseStringLiteralExpression(); |
| 4159 | if (StringResult.isInvalid()) |
| 4160 | return; |
| 4161 | ArgExprs.push_back(StringResult.get()); |
| 4162 | } else { |
| 4163 | |
| 4164 | |
| 4165 | |
| 4166 | |
| 4167 | SmallString<42> StrBuffer; |
| 4168 | StrBuffer += "\""; |
| 4169 | |
| 4170 | |
| 4171 | |
| 4172 | |
| 4173 | |
| 4174 | |
| 4175 | |
| 4176 | |
| 4177 | SourceLocation StartLoc = Tok.getLocation(); |
| 4178 | while (Tok.isNot(tok::r_paren)) { |
| 4179 | if (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()) { |
| 4180 | Diag(Tok, diag::err_attribute_uuid_malformed_guid); |
| 4181 | SkipUntil(tok::r_paren, StopAtSemi); |
| 4182 | return; |
| 4183 | } |
| 4184 | SmallString<16> SpellingBuffer; |
| 4185 | SpellingBuffer.resize(Tok.getLength() + 1); |
| 4186 | bool Invalid = false; |
| 4187 | StringRef TokSpelling = PP.getSpelling(Tok, SpellingBuffer, &Invalid); |
| 4188 | if (Invalid) { |
| 4189 | SkipUntil(tok::r_paren, StopAtSemi); |
| 4190 | return; |
| 4191 | } |
| 4192 | StrBuffer += TokSpelling; |
| 4193 | ConsumeAnyToken(); |
| 4194 | } |
| 4195 | StrBuffer += "\""; |
| 4196 | |
| 4197 | if (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()) { |
| 4198 | Diag(Tok, diag::err_attribute_uuid_malformed_guid); |
| 4199 | ConsumeParen(); |
| 4200 | return; |
| 4201 | } |
| 4202 | |
| 4203 | |
| 4204 | |
| 4205 | |
| 4206 | Token Toks[1]; |
| 4207 | Toks[0].startToken(); |
| 4208 | Toks[0].setKind(tok::string_literal); |
| 4209 | Toks[0].setLocation(StartLoc); |
| 4210 | Toks[0].setLiteralData(StrBuffer.data()); |
| 4211 | Toks[0].setLength(StrBuffer.size()); |
| 4212 | StringLiteral *UuidString = |
| 4213 | cast<StringLiteral>(Actions.ActOnStringLiteral(Toks, nullptr).get()); |
| 4214 | ArgExprs.push_back(UuidString); |
| 4215 | } |
| 4216 | |
| 4217 | if (!T.consumeClose()) { |
| 4218 | Attrs.addNew(UuidIdent, SourceRange(UuidLoc, T.getCloseLocation()), nullptr, |
| 4219 | SourceLocation(), ArgExprs.data(), ArgExprs.size(), |
| 4220 | ParsedAttr::AS_Microsoft); |
| 4221 | } |
| 4222 | } |
| 4223 | |
| 4224 | |
| 4225 | |
| 4226 | |
| 4227 | |
| 4228 | |
| 4229 | |
| 4230 | |
| 4231 | |
| 4232 | void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs, |
| 4233 | SourceLocation *endLoc) { |
| 4234 | (0) . __assert_fail ("Tok.is(tok..l_square) && \"Not a Microsoft attribute list\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDeclCXX.cpp", 4234, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list"); |
| 4235 | |
| 4236 | do { |
| 4237 | |
| 4238 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 4239 | T.consumeOpen(); |
| 4240 | |
| 4241 | |
| 4242 | while (true) { |
| 4243 | SkipUntil(tok::r_square, tok::identifier, StopAtSemi | StopBeforeMatch); |
| 4244 | if (Tok.isNot(tok::identifier)) |
| 4245 | break; |
| 4246 | if (Tok.getIdentifierInfo()->getName() == "uuid") |
| 4247 | ParseMicrosoftUuidAttributeArgs(attrs); |
| 4248 | else |
| 4249 | ConsumeToken(); |
| 4250 | } |
| 4251 | |
| 4252 | T.consumeClose(); |
| 4253 | if (endLoc) |
| 4254 | *endLoc = T.getCloseLocation(); |
| 4255 | } while (Tok.is(tok::l_square)); |
| 4256 | } |
| 4257 | |
| 4258 | void Parser::ParseMicrosoftIfExistsClassDeclaration( |
| 4259 | DeclSpec::TST TagType, ParsedAttributes &AccessAttrs, |
| 4260 | AccessSpecifier &CurAS) { |
| 4261 | IfExistsCondition Result; |
| 4262 | if (ParseMicrosoftIfExistsCondition(Result)) |
| 4263 | return; |
| 4264 | |
| 4265 | BalancedDelimiterTracker Braces(*this, tok::l_brace); |
| 4266 | if (Braces.consumeOpen()) { |
| 4267 | Diag(Tok, diag::err_expected) << tok::l_brace; |
| 4268 | return; |
| 4269 | } |
| 4270 | |
| 4271 | switch (Result.Behavior) { |
| 4272 | case IEB_Parse: |
| 4273 | |
| 4274 | break; |
| 4275 | |
| 4276 | case IEB_Dependent: |
| 4277 | Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists) |
| 4278 | << Result.IsIfExists; |
| 4279 | |
| 4280 | LLVM_FALLTHROUGH; |
| 4281 | |
| 4282 | case IEB_Skip: |
| 4283 | Braces.skipToEnd(); |
| 4284 | return; |
| 4285 | } |
| 4286 | |
| 4287 | while (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
| 4288 | |
| 4289 | if (Tok.isOneOf(tok::kw___if_exists, tok::kw___if_not_exists)) { |
| 4290 | ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, |
| 4291 | AccessAttrs, CurAS); |
| 4292 | continue; |
| 4293 | } |
| 4294 | |
| 4295 | |
| 4296 | if (Tok.is(tok::semi)) { |
| 4297 | ConsumeExtraSemi(InsideStruct, TagType); |
| 4298 | continue; |
| 4299 | } |
| 4300 | |
| 4301 | AccessSpecifier AS = getAccessSpecifierIfPresent(); |
| 4302 | if (AS != AS_none) { |
| 4303 | |
| 4304 | CurAS = AS; |
| 4305 | SourceLocation ASLoc = Tok.getLocation(); |
| 4306 | ConsumeToken(); |
| 4307 | if (Tok.is(tok::colon)) |
| 4308 | Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation(), |
| 4309 | ParsedAttributesView{}); |
| 4310 | else |
| 4311 | Diag(Tok, diag::err_expected) << tok::colon; |
| 4312 | ConsumeToken(); |
| 4313 | continue; |
| 4314 | } |
| 4315 | |
| 4316 | |
| 4317 | ParseCXXClassMemberDeclaration(CurAS, AccessAttrs); |
| 4318 | } |
| 4319 | |
| 4320 | Braces.consumeClose(); |
| 4321 | } |
| 4322 | |