Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/swift/Basic/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,24 @@ inline OutputIterator transform(const Container &C, OutputIterator result,
return std::transform(C.begin(), C.end(), result, op);
}

/// Provides default implementations of !=, <=, >, and >= based on == and <.
template <typename T>
class RelationalOperationsBase {
public:
friend bool operator>(const T &left, const T &right) {
return right < left;
}
friend bool operator>=(const T &left, const T &right) {
return !(left < right);
}
friend bool operator<=(const T &left, const T &right) {
return !(right < left);
}
friend bool operator!=(const T &left, const T &right) {
return !(left == right);
}
};

} // end namespace swift

#endif // SWIFT_BASIC_INTERLEAVE_H
4 changes: 2 additions & 2 deletions lib/ClangImporter/ClangAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ clang::SwiftNewtypeAttr *
importer::getSwiftNewtypeAttr(const clang::TypedefNameDecl *decl,
ImportNameVersion version) {
// Newtype was introduced in Swift 3
if (version < ImportNameVersion::Swift3 )
if (version <= ImportNameVersion::swift2())
return nullptr;
return retrieveNewTypeAttr(decl);
}
Expand All @@ -448,7 +448,7 @@ clang::TypedefNameDecl *importer::findSwiftNewtype(const clang::NamedDecl *decl,
clang::Sema &clangSema,
ImportNameVersion version) {
// Newtype was introduced in Swift 3
if (version < ImportNameVersion::Swift3 )
if (version <= ImportNameVersion::swift2())
return nullptr;

auto varDecl = dyn_cast<clang::VarDecl>(decl);
Expand Down
29 changes: 15 additions & 14 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ ClangImporter::Implementation::Implementation(ASTContext &ctx,
BridgingHeaderExplicitlyRequested(!opts.BridgingHeader.empty()),
DisableAdapterModules(opts.DisableAdapterModules),
IsReadingBridgingPCH(false),
CurrentVersion(nameVersionFromOptions(ctx.LangOpts)),
CurrentVersion(ImportNameVersion::fromOptions(ctx.LangOpts)),
BridgingHeaderLookupTable(new SwiftLookupTable(nullptr)),
platformAvailability(ctx.LangOpts),
nameImporter() {}
Expand Down Expand Up @@ -2508,32 +2508,34 @@ ClangModuleUnit::lookupNestedType(Identifier name,

bool anyMatching = false;
TypeDecl *originalDecl = nullptr;
owner.forEachDistinctName(clangTypeDecl, [&](ImportedName newName,
ImportNameVersion nameVersion){
owner.forEachDistinctName(clangTypeDecl,
[&](ImportedName newName,
ImportNameVersion nameVersion) -> bool {
if (anyMatching)
return;
return true;
if (!newName.getDeclName().isSimpleName(name))
return;
return true;

auto decl = dyn_cast_or_null<TypeDecl>(
owner.importDeclReal(clangTypeDecl, nameVersion));
if (!decl)
return;
return false;

if (!originalDecl)
originalDecl = decl;
else if (originalDecl == decl)
return;
return true;

auto *importedContext = decl->getDeclContext()->
getAsNominalTypeOrNominalTypeExtensionContext();
if (importedContext != baseType)
return;
return true;

assert(decl->getFullName().matchesRef(name) &&
"importFullName behaved differently from importDecl");
results.push_back(decl);
anyMatching = true;
return true;
});
}

Expand Down Expand Up @@ -3150,10 +3152,8 @@ void ClangImporter::Implementation::lookupValue(
const clang::NamedDecl *recentClangDecl =
clangDecl->getMostRecentDecl();

forEachImportNameVersionFromCurrent(CurrentVersion,
[&](ImportNameVersion nameVersion) {
if (nameVersion == CurrentVersion)
return;
CurrentVersion.forEachOtherImportNameVersion(
[&](ImportNameVersion nameVersion) {
if (anyMatching)
return;

Expand Down Expand Up @@ -3211,12 +3211,12 @@ void ClangImporter::Implementation::lookupObjCMembers(

forEachDistinctName(clangDecl,
[&](ImportedName importedName,
ImportNameVersion nameVersion) {
ImportNameVersion nameVersion) -> bool {
// Import the declaration.
auto decl =
cast_or_null<ValueDecl>(importDeclReal(clangDecl, nameVersion));
if (!decl)
return;
return false;

// If the name we found matches, report the declaration.
// FIXME: If we didn't need to check alternate decls here, we could avoid
Expand All @@ -3232,6 +3232,7 @@ void ClangImporter::Implementation::lookupObjCMembers(
consumer.foundDecl(alternate, DeclVisibilityKind::DynamicLookup);
}
}
return true;
});
}
}
Expand Down
Loading