Skip to content

Commit 7252fd6

Browse files
committed
---
yaml --- r: 348501 b: refs/heads/master c: 9bf6d86 h: refs/heads/master i: 348499: 5dbcf9a
1 parent fb5d803 commit 7252fd6

File tree

7 files changed

+31
-84
lines changed

7 files changed

+31
-84
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: fa36ac31f390e98945d5bbe848554f629b7c3262
2+
refs/heads/master: 9bf6d8689d806471169058a8bb745e8fa863b822
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ class ClangImporter final : public ClangModuleLoader {
217217
StringRef relatedEntityKind,
218218
llvm::function_ref<void(TypeDecl *)> receiver) override;
219219

220-
/// Look up the nested 'Code' enum for an error wrapper struct.
221-
EnumDecl *lookupErrorCodeEnum(const StructDecl *errorWrapper) const;
220+
/// Just like Decl::getClangNode() except we look through to the 'Code'
221+
/// enum of an error wrapper struct.
222+
ClangNode getEffectiveClangNode(const Decl *decl) const;
222223

223224
/// Look for textually included declarations from the bridging header.
224225
///

trunk/lib/ClangImporter/ClangImporter.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,26 +2173,9 @@ static bool isVisibleFromModule(const ClangModuleUnit *ModuleFilter,
21732173
if (!Wrapper)
21742174
return false;
21752175

2176-
auto ClangNode = VD->getClangNode();
2177-
if (!ClangNode) {
2178-
// If we synthesized a ValueDecl, it won't have a Clang node. Find the
2179-
// associated declaration that /does/ have a Clang node, and use that.
2180-
auto *SynthesizedTypeAttr =
2181-
VD->getAttrs().getAttribute<ClangImporterSynthesizedTypeAttr>();
2182-
assert(SynthesizedTypeAttr);
2183-
2184-
switch (SynthesizedTypeAttr->getKind()) {
2185-
case ClangImporterSynthesizedTypeAttr::Kind::NSErrorWrapper:
2186-
case ClangImporterSynthesizedTypeAttr::Kind::NSErrorWrapperAnon: {
2187-
ASTContext &Ctx = ContainingUnit->getASTContext();
2188-
auto *Importer = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
2189-
auto WrapperStruct = cast<StructDecl>(VD);
2190-
auto *CodeEnum = Importer->lookupErrorCodeEnum(WrapperStruct);
2191-
ClangNode = CodeEnum->getClangNode();
2192-
break;
2193-
}
2194-
}
2195-
}
2176+
ASTContext &Ctx = ContainingUnit->getASTContext();
2177+
auto *Importer = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
2178+
auto ClangNode = Importer->getEffectiveClangNode(VD);
21962179

21972180
// Macros can be "redeclared" by putting an equivalent definition in two
21982181
// different modules. (We don't actually check the equivalence.)
@@ -2498,8 +2481,19 @@ void ClangImporter::lookupValue(DeclName name, VisibleDeclConsumer &consumer) {
24982481
});
24992482
}
25002483

2501-
EnumDecl *ClangImporter::lookupErrorCodeEnum(const StructDecl *errorWrapper) const {
2502-
return Impl.lookupErrorCodeEnum(errorWrapper);
2484+
ClangNode ClangImporter::getEffectiveClangNode(const Decl *decl) const {
2485+
// Directly...
2486+
if (auto clangNode = decl->getClangNode())
2487+
return clangNode;
2488+
2489+
// Or via the nested "Code" enum.
2490+
if (auto *errorWrapper = dyn_cast<StructDecl>(decl)) {
2491+
if (auto *code = Impl.lookupErrorCodeEnum(errorWrapper))
2492+
if (auto clangNode = code->getClangNode())
2493+
return clangNode;
2494+
}
2495+
2496+
return ClangNode();
25032497
}
25042498

25052499
void ClangImporter::lookupTypeDecl(

trunk/lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,7 @@ namespace {
29412941
AccessLevel::Public, loc, SourceLoc(),
29422942
C.Id_ErrorType, loc,
29432943
/*genericparams=*/nullptr, enumDecl);
2944-
alias->setUnderlyingType(Impl.getSugaredTypeReference(errorWrapper));
2944+
alias->setUnderlyingType(errorWrapper->getDeclaredInterfaceType());
29452945
enumDecl->addMember(alias);
29462946

29472947
// Add the 'Code' enum to the error wrapper.
@@ -5160,7 +5160,7 @@ namespace {
51605160
typealias->setGenericParams(GTD->getGenericParams()->clone(typealias));
51615161
}
51625162

5163-
typealias->setUnderlyingType(Impl.getSugaredTypeReference(typeDecl));
5163+
typealias->setUnderlyingType(typeDecl->getDeclaredInterfaceType());
51645164
return typealias;
51655165
}
51665166

@@ -5392,7 +5392,7 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
53925392
alias->setGenericParams(GTD->getGenericParams()->clone(alias));
53935393
}
53945394

5395-
alias->setUnderlyingType(Impl.getSugaredTypeReference(typeDecl));
5395+
alias->setUnderlyingType(typeDecl->getDeclaredInterfaceType());
53965396

53975397
// Record that this is the official version of this declaration.
53985398
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = alias;

trunk/lib/ClangImporter/ImportType.cpp

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -840,33 +840,17 @@ namespace {
840840
return getAdjustedTypeDeclReferenceType(decl);
841841
}
842842

843-
/// Retrieve the 'Code' type for a bridged NSError, or nullptr if
844-
/// this is not a bridged NSError type.
845-
TypeDecl *getBridgedNSErrorCode(TypeDecl *decl) {
846-
auto errorWrapper = dyn_cast<StructDecl>(decl);
847-
if (!errorWrapper) return nullptr;
848-
849-
const DeclAttributes &allAttrs = errorWrapper->getAttrs();
850-
for (auto attr : allAttrs.getAttributes<SynthesizedProtocolAttr>()) {
851-
if (attr->getProtocolKind() ==
852-
KnownProtocolKind::BridgedStoredNSError) {
853-
return Impl.lookupErrorCodeEnum(errorWrapper);
854-
}
855-
}
856-
857-
return nullptr;
858-
}
859-
860843
/// Retrieve the adjusted type of a reference to the given type declaration.
861-
Type getAdjustedTypeDeclReferenceType(TypeDecl *type) {
844+
Type getAdjustedTypeDeclReferenceType(TypeDecl *decl) {
862845
// If the imported declaration is a bridged NSError, dig out
863846
// the Code nested type. References to the enum type from C
864847
// code need to map to the code type (which is ABI compatible with C),
865848
// and the bridged error type is used elsewhere.
866-
if (auto codeDecl = getBridgedNSErrorCode(type))
867-
return Impl.getSugaredTypeReference(codeDecl);
849+
if (auto *structDecl = dyn_cast<StructDecl>(decl))
850+
if (auto *codeEnum = Impl.lookupErrorCodeEnum(structDecl))
851+
return codeEnum->getDeclaredInterfaceType();
868852

869-
return Impl.getSugaredTypeReference(type);
853+
return decl->getDeclaredInterfaceType();
870854
}
871855

872856
ImportResult VisitEnumType(const clang::EnumType *type) {
@@ -2535,23 +2519,6 @@ static Type getNamedProtocolType(ClangImporter::Implementation &impl,
25352519
return Type();
25362520
}
25372521

2538-
Type ClangImporter::Implementation::getSugaredTypeReference(TypeDecl *type) {
2539-
// For typealiases, build a sugared type.
2540-
if (auto typealias = dyn_cast<TypeAliasDecl>(type)) {
2541-
// If this typealias is nested, retrieve the parent type.
2542-
Type parentType;
2543-
if (auto nominal = typealias->getDeclContext()->getSelfNominalTypeDecl()) {
2544-
if (!nominal->getGenericSignature())
2545-
parentType = nominal->getDeclaredInterfaceType();
2546-
}
2547-
2548-
return TypeAliasType::get(typealias, parentType, SubstitutionMap(),
2549-
typealias->getUnderlyingTypeLoc().getType());
2550-
}
2551-
2552-
return type->getDeclaredInterfaceType();
2553-
}
2554-
25552522
Type ClangImporter::Implementation::getNSCopyingType() {
25562523
return getNamedProtocolType(*this, "NSCopying");
25572524
}

trunk/lib/ClangImporter/ImporterImpl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
950950
/// Retrieve the NSCopying protocol type.
951951
Type getNSCopyingType();
952952

953-
/// Retrieve a sugared referenece to the given (imported) type.
954-
Type getSugaredTypeReference(TypeDecl *type);
955-
956953
/// Determines whether the given type matches an implicit type
957954
/// bound of "Hashable", which is used to validate NSDictionary/NSSet.
958955
bool matchesHashableBound(Type type);

trunk/lib/IDE/Utils.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -954,21 +954,9 @@ bool swift::ide::isFromClang(const Decl *D) {
954954
}
955955

956956
ClangNode swift::ide::getEffectiveClangNode(const Decl *decl) {
957-
// Directly...
958-
if (auto clangNode = decl->getClangNode())
959-
return clangNode;
960-
961-
// Or via the nested "Code" enum.
962-
if (auto *errorWrapper = dyn_cast<StructDecl>(decl)) {
963-
auto &ctx = errorWrapper->getASTContext();
964-
auto *importer = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
965-
if (importer)
966-
if (auto *code = importer->lookupErrorCodeEnum(errorWrapper))
967-
if (auto clangDecl = code->getClangDecl())
968-
return clangDecl;
969-
}
970-
971-
return ClangNode();
957+
auto &ctx = decl->getASTContext();
958+
auto *importer = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
959+
return importer->getEffectiveClangNode(decl);
972960
}
973961

974962
/// Retrieve the Clang node for the given extension, if it has one.

0 commit comments

Comments
 (0)