@@ -104,7 +104,7 @@ getDefaultMakeStructRawValuedOptions() {
104
104
return opts;
105
105
}
106
106
107
- static bool isInSystemModule (DeclContext *D) {
107
+ static bool isInSystemModule (const DeclContext *D) {
108
108
return cast<ClangModuleUnit>(D->getModuleScopeContext ())->isSystemModule ();
109
109
}
110
110
@@ -4091,7 +4091,7 @@ namespace {
4091
4091
// / Check whether we have already imported a method with the given
4092
4092
// / selector in the given context.
4093
4093
bool isMethodAlreadyImported (ObjCSelector selector, bool isInstance,
4094
- DeclContext *dc,
4094
+ const DeclContext *dc,
4095
4095
llvm::function_ref<bool (AbstractFunctionDecl *fn)> filter) {
4096
4096
// We only need to perform this check for classes.
4097
4097
auto classDecl
@@ -4425,7 +4425,7 @@ namespace {
4425
4425
// / NSArray(capacity: 1024)
4426
4426
// / \endcode
4427
4427
ConstructorDecl *importConstructor (const clang::ObjCMethodDecl *objcMethod,
4428
- DeclContext *dc,
4428
+ const DeclContext *dc,
4429
4429
bool implicit,
4430
4430
Optional<CtorInitializerKind> kind,
4431
4431
bool required);
@@ -4454,7 +4454,7 @@ namespace {
4454
4454
// / This variant of the function is responsible for actually binding the
4455
4455
// / constructor declaration appropriately.
4456
4456
ConstructorDecl *importConstructor (const clang::ObjCMethodDecl *objcMethod,
4457
- DeclContext *dc,
4457
+ const DeclContext *dc,
4458
4458
bool implicit,
4459
4459
CtorInitializerKind kind,
4460
4460
bool required,
@@ -4518,16 +4518,15 @@ namespace {
4518
4518
void importMirroredProtocolMembers (const clang::ObjCContainerDecl *decl,
4519
4519
DeclContext *dc,
4520
4520
ArrayRef<ProtocolDecl *> protocols,
4521
- SmallVectorImpl<Decl *> &members,
4522
- ASTContext &Ctx);
4521
+ SmallVectorImpl<Decl *> &members);
4523
4522
4524
4523
void importNonOverriddenMirroredMethods (DeclContext *dc,
4525
4524
MutableArrayRef<MirroredMethodEntry> entries,
4526
4525
SmallVectorImpl<Decl *> &newMembers);
4527
4526
4528
4527
// / Import constructors from our superclasses (and their
4529
4528
// / categories/extensions), effectively "inheriting" constructors.
4530
- void importInheritedConstructors (ClassDecl *classDecl,
4529
+ void importInheritedConstructors (const ClassDecl *classDecl,
4531
4530
SmallVectorImpl<Decl *> &newMembers);
4532
4531
4533
4532
Decl *VisitObjCCategoryDecl (const clang::ObjCCategoryDecl *decl) {
@@ -6083,7 +6082,7 @@ SwiftDeclConverter::getImplicitProperty(ImportedName importedName,
6083
6082
}
6084
6083
6085
6084
ConstructorDecl *SwiftDeclConverter::importConstructor (
6086
- const clang::ObjCMethodDecl *objcMethod, DeclContext *dc, bool implicit,
6085
+ const clang::ObjCMethodDecl *objcMethod, const DeclContext *dc, bool implicit,
6087
6086
Optional<CtorInitializerKind> kind, bool required) {
6088
6087
// Only methods in the 'init' family can become constructors.
6089
6088
assert (isInitMethod (objcMethod) && " Not a real init method" );
@@ -6234,7 +6233,7 @@ bool SwiftDeclConverter::existingConstructorIsWorse(
6234
6233
// / This variant of the function is responsible for actually binding the
6235
6234
// / constructor declaration appropriately.
6236
6235
ConstructorDecl *SwiftDeclConverter::importConstructor (
6237
- const clang::ObjCMethodDecl *objcMethod, DeclContext *dc, bool implicit,
6236
+ const clang::ObjCMethodDecl *objcMethod, const DeclContext *dc, bool implicit,
6238
6237
CtorInitializerKind kind, bool required, ObjCSelector selector,
6239
6238
ImportedName importedName, ArrayRef<const clang::ParmVarDecl *> args,
6240
6239
bool variadic, bool &redundant) {
@@ -6354,7 +6353,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
6354
6353
/* NameLoc=*/ SourceLoc (), failability, /* FailabilityLoc=*/ SourceLoc (),
6355
6354
/* Throws=*/ importedName.getErrorInfo ().hasValue (),
6356
6355
/* ThrowsLoc=*/ SourceLoc (), bodyParams,
6357
- /* GenericParams=*/ nullptr , dc );
6356
+ /* GenericParams=*/ nullptr , const_cast <DeclContext *>(dc) );
6358
6357
6359
6358
addObjCAttribute (result, selector);
6360
6359
@@ -6941,8 +6940,7 @@ Optional<GenericParamList *> SwiftDeclConverter::importObjCGenericParams(
6941
6940
6942
6941
void SwiftDeclConverter::importMirroredProtocolMembers (
6943
6942
const clang::ObjCContainerDecl *decl, DeclContext *dc,
6944
- ArrayRef<ProtocolDecl *> protocols, SmallVectorImpl<Decl *> &members,
6945
- ASTContext &Ctx) {
6943
+ ArrayRef<ProtocolDecl *> protocols, SmallVectorImpl<Decl *> &members) {
6946
6944
assert (dc);
6947
6945
const clang::ObjCInterfaceDecl *interfaceDecl = nullptr ;
6948
6946
const ClangModuleUnit *declModule;
@@ -7189,7 +7187,7 @@ void SwiftDeclConverter::importNonOverriddenMirroredMethods(DeclContext *dc,
7189
7187
}
7190
7188
7191
7189
void SwiftDeclConverter::importInheritedConstructors (
7192
- ClassDecl *classDecl, SmallVectorImpl<Decl *> &newMembers) {
7190
+ const ClassDecl *classDecl, SmallVectorImpl<Decl *> &newMembers) {
7193
7191
if (!classDecl->hasSuperclass ())
7194
7192
return ;
7195
7193
@@ -8673,6 +8671,15 @@ void ClangImporter::Implementation::insertMembersAndAlternates(
8673
8671
});
8674
8672
}
8675
8673
8674
+ void ClangImporter::Implementation::importInheritedConstructors (
8675
+ const clang::ObjCInterfaceDecl *curObjCClass,
8676
+ const ClassDecl *classDecl, SmallVectorImpl<Decl *> &newMembers) {
8677
+ if (curObjCClass->getName () != " Protocol" ) {
8678
+ SwiftDeclConverter converter (*this , CurrentVersion);
8679
+ converter.importInheritedConstructors (classDecl, newMembers);
8680
+ }
8681
+ }
8682
+
8676
8683
void ClangImporter::Implementation::collectMembersToAdd (
8677
8684
const clang::ObjCContainerDecl *objcContainer, Decl *D, DeclContext *DC,
8678
8685
SmallVectorImpl<Decl *> &members) {
@@ -8687,24 +8694,16 @@ void ClangImporter::Implementation::collectMembersToAdd(
8687
8694
8688
8695
auto protos = getImportedProtocols (D);
8689
8696
if (auto clangClass = dyn_cast<clang::ObjCInterfaceDecl>(objcContainer)) {
8690
- auto swiftClass = cast<ClassDecl>(D);
8691
8697
objcContainer = clangClass = clangClass->getDefinition ();
8692
-
8693
- // Imported inherited initializers.
8694
- if (clangClass->getName () != " Protocol" ) {
8695
- converter.importInheritedConstructors (const_cast <ClassDecl *>(swiftClass),
8696
- members);
8697
- }
8698
-
8698
+ importInheritedConstructors (clangClass, cast<ClassDecl>(D), members);
8699
8699
} else if (auto clangProto
8700
8700
= dyn_cast<clang::ObjCProtocolDecl>(objcContainer)) {
8701
8701
objcContainer = clangProto->getDefinition ();
8702
8702
}
8703
8703
// Import mirrored declarations for protocols to which this category
8704
8704
// or extension conforms.
8705
8705
// FIXME: This is supposed to be a short-term hack.
8706
- converter.importMirroredProtocolMembers (objcContainer, DC,
8707
- protos, members, SwiftContext);
8706
+ converter.importMirroredProtocolMembers (objcContainer, DC, protos, members);
8708
8707
}
8709
8708
8710
8709
void ClangImporter::Implementation::loadAllConformances (
0 commit comments