@@ -459,36 +459,6 @@ static bool shouldSerializeAsLocalContext(const DeclContext *DC) {
459
459
!isa<SubscriptDecl>(DC);
460
460
}
461
461
462
- static const Decl *getDeclForContext (const DeclContext *DC) {
463
- switch (DC->getContextKind ()) {
464
- case DeclContextKind::Module:
465
- // Use a null decl to represent the module.
466
- return nullptr ;
467
- case DeclContextKind::FileUnit:
468
- return getDeclForContext (DC->getParent ());
469
- case DeclContextKind::SerializedLocal:
470
- llvm_unreachable (" Serialized local contexts should only come from deserialization" );
471
- case DeclContextKind::Initializer:
472
- case DeclContextKind::AbstractClosureExpr:
473
- // FIXME: What about default functions?
474
- llvm_unreachable (" shouldn't serialize decls from anonymous closures" );
475
- case DeclContextKind::GenericTypeDecl:
476
- return cast<GenericTypeDecl>(DC);
477
- case DeclContextKind::ExtensionDecl:
478
- return cast<ExtensionDecl>(DC);
479
- case DeclContextKind::TopLevelCodeDecl:
480
- llvm_unreachable (" shouldn't serialize the main module" );
481
- case DeclContextKind::AbstractFunctionDecl:
482
- return cast<AbstractFunctionDecl>(DC);
483
- case DeclContextKind::SubscriptDecl:
484
- return cast<SubscriptDecl>(DC);
485
- case DeclContextKind::EnumElementDecl:
486
- return cast<EnumElementDecl>(DC);
487
- }
488
-
489
- llvm_unreachable (" Unhandled DeclContextKind in switch." );
490
- }
491
-
492
462
namespace {
493
463
struct Accessors {
494
464
uint8_t OpaqueReadOwnership;
@@ -634,7 +604,7 @@ DeclContextID Serializer::addDeclContextRef(const DeclContext *DC) {
634
604
if (shouldSerializeAsLocalContext (DC))
635
605
addLocalDeclContextRef (DC);
636
606
else
637
- addDeclRef (getDeclForContext (DC ));
607
+ addDeclRef (DC-> getAsDecl ( ));
638
608
639
609
auto &id = DeclContextIDs[DC];
640
610
if (id)
@@ -1538,7 +1508,7 @@ Serializer::writeConformance(ProtocolConformanceRef conformanceRef,
1538
1508
switch (conformance->getKind ()) {
1539
1509
case ProtocolConformanceKind::Normal: {
1540
1510
auto normal = cast<NormalProtocolConformance>(conformance);
1541
- if (!isDeclXRef (getDeclForContext ( normal->getDeclContext ()))
1511
+ if (!isDeclXRef (normal->getDeclContext ()-> getAsDecl ( ))
1542
1512
&& !isa<ClangModuleUnit>(normal->getDeclContext ()
1543
1513
->getModuleScopeContext ())) {
1544
1514
// A normal conformance in this module file.
@@ -2046,7 +2016,7 @@ void Serializer::writeDeclContext(const DeclContext *DC) {
2046
2016
case DeclContextKind::GenericTypeDecl:
2047
2017
case DeclContextKind::ExtensionDecl:
2048
2018
case DeclContextKind::EnumElementDecl:
2049
- declOrDeclContextID = addDeclRef (getDeclForContext (DC ));
2019
+ declOrDeclContextID = addDeclRef (DC-> getAsDecl ( ));
2050
2020
isDecl = true ;
2051
2021
break ;
2052
2022
0 commit comments