Skip to content

Commit 3196ea9

Browse files
committed
Refactor and format
1 parent e7fe6f0 commit 3196ea9

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4122,32 +4122,15 @@ bool ClangImporter::Implementation::lookupValue(SwiftLookupTable &table,
41224122
bool declFound = false;
41234123

41244124
if (name.isOperator()) {
4125-
for (auto entry : table.lookupMemberOperators(name.getBaseName())) {
4126-
if (isVisibleClangEntry(entry)) {
4127-
if (auto decl = dyn_cast_or_null<ValueDecl>(
4128-
importDeclReal(entry->getMostRecentDecl(), CurrentVersion))) {
4129-
consumer.foundDecl(decl, DeclVisibilityKind::VisibleAtTopLevel);
4130-
declFound = true;
4131-
for (auto alternate : getAlternateDecls(decl)) {
4132-
if (alternate->getName().matchesRef(name)) {
4133-
consumer.foundDecl(alternate, DeclVisibilityKind::DynamicLookup,
4134-
DynamicLookupInfo::AnyObject);
4135-
}
4136-
}
4137-
}
4138-
}
4139-
}
41404125

4141-
// If CXXInterop is enabled we need to check the modified operator name as well
4142-
if(SwiftContext.LangOpts.EnableCXXInterop) {
4143-
auto declBaseName = DeclBaseName(SwiftContext.getIdentifier("__operator" + getOperatorNameForToken(name.getBaseName().getIdentifier().str().str())));
4126+
auto findAndConsumeBaseNameFromTable = [this, &table, &consumer, &declFound, &name](DeclBaseName declBaseName) {
41444127
for (auto entry : table.lookupMemberOperators(declBaseName)) {
41454128
if (isVisibleClangEntry(entry)) {
41464129
if (auto decl = dyn_cast_or_null<ValueDecl>(
41474130
importDeclReal(entry->getMostRecentDecl(), CurrentVersion))) {
41484131
consumer.foundDecl(decl, DeclVisibilityKind::VisibleAtTopLevel);
41494132
declFound = true;
4150-
for (auto alternate: getAlternateDecls(decl)) {
4133+
for (auto alternate : getAlternateDecls(decl)) {
41514134
if (alternate->getName().matchesRef(name)) {
41524135
consumer.foundDecl(alternate, DeclVisibilityKind::DynamicLookup,
41534136
DynamicLookupInfo::AnyObject);
@@ -4156,6 +4139,15 @@ bool ClangImporter::Implementation::lookupValue(SwiftLookupTable &table,
41564139
}
41574140
}
41584141
}
4142+
};
4143+
4144+
findAndConsumeBaseNameFromTable(name.getBaseName());
4145+
4146+
// If CXXInterop is enabled we need to check the modified operator name as well
4147+
if(SwiftContext.LangOpts.EnableCXXInterop) {
4148+
auto declBaseName = DeclBaseName(SwiftContext.getIdentifier(
4149+
"__operator" + getOperatorNameForToken(name.getBaseName().getIdentifier().str().str())));
4150+
findAndConsumeBaseNameFromTable(declBaseName);
41594151
}
41604152
}
41614153

lib/ClangImporter/ImportDecl.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4298,11 +4298,6 @@ namespace {
42984298
templateParams);
42994299

43004300
if (auto *mdecl = dyn_cast<clang::CXXMethodDecl>(decl)) {
4301-
// Subscripts and call operators are imported as normal methods.
4302-
// bool staticOperator = mdecl->isOverloadedOperator();
4303-
bool requiresStaticTopLevel =
4304-
mdecl->getOverloadedOperator() != clang::OO_Call &&
4305-
mdecl->getOverloadedOperator() != clang::OO_Subscript;
43064301
if (mdecl->isStatic()) {
43074302
selfIdx = None;
43084303
} else {
@@ -8154,7 +8149,6 @@ synthesizeOperatorMethodBody(AbstractFunctionDecl *afd, void *context) {
81548149
FuncDecl *SwiftDeclConverter::makeOperator(FuncDecl *operatorMethod, clang::CXXMethodDecl *clangOperator) {
81558150
auto &ctx = Impl.SwiftContext;
81568151
auto opName = clang::getOperatorSpelling(clangOperator->getOverloadedOperator());
8157-
auto loc = operatorMethod->getLoc();
81588152
auto paramList = operatorMethod->getParameters();
81598153
auto genericParamList = operatorMethod->getGenericParams();
81608154

@@ -8182,8 +8176,6 @@ FuncDecl *SwiftDeclConverter::makeOperator(FuncDecl *operatorMethod, clang::CXXM
81828176
newParams.push_back(param);
81838177
}
81848178

8185-
auto newParamList = ParameterList::create(ctx, newParams);
8186-
81878179
auto oldArgNames = operatorMethod->getName().getArgumentNames();
81888180
SmallVector<Identifier, 4> newArgNames;
81898181
newArgNames.push_back(Identifier());

0 commit comments

Comments
 (0)