Skip to content

Commit b0ce340

Browse files
committed
Ignore the Context Name in the rename declaration on most of the cases
1 parent 25d74fe commit b0ce340

File tree

1 file changed

+48
-56
lines changed

1 file changed

+48
-56
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -919,82 +919,74 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
919919
auto renamedDeclName = renamedParsedDeclName.formDeclName(astContext);
920920

921921
if (isa<ClassDecl>(D) || isa<ProtocolDecl>(D)) {
922+
if (!renamedParsedDeclName.ContextName.empty()) {
923+
return nullptr;
924+
}
922925
UnqualifiedLookup lookup(renamedDeclName.getBaseIdentifier(),
923926
declContext->getModuleScopeContext(), nullptr,
924927
SourceLoc(),
925928
UnqualifiedLookup::Flags::TypeLookup);
926929
return lookup.getSingleTypeResult();
927-
} else {
928-
TypeDecl *typeDecl = declContext->getSelfNominalTypeDecl();
929-
930-
if (!renamedParsedDeclName.ContextName.empty()) {
931-
auto contextIdentifier =
932-
astContext.getIdentifier(renamedParsedDeclName.ContextName);
933-
UnqualifiedLookup specificTypeLookup(
934-
contextIdentifier, declContext->getModuleScopeContext(), nullptr,
935-
SourceLoc(), UnqualifiedLookup::Flags::TypeLookup);
936-
if (!specificTypeLookup.getSingleTypeResult()) {
937-
return nullptr;
938-
}
939-
}
940-
941-
const ValueDecl *renamedDecl = nullptr;
942-
SmallVector<ValueDecl *, 4> lookupResults;
943-
declContext->lookupQualified(typeDecl, renamedDeclName,
944-
NL_QualifiedDefault, lookupResults);
930+
}
931+
932+
TypeDecl *typeDecl = declContext->getSelfNominalTypeDecl();
933+
934+
const ValueDecl *renamedDecl = nullptr;
935+
SmallVector<ValueDecl *, 4> lookupResults;
936+
declContext->lookupQualified(typeDecl, renamedDeclName,
937+
NL_QualifiedDefault, lookupResults);
938+
939+
if (lookupResults.size() == 1) {
940+
auto candidate = lookupResults[0];
941+
if (!shouldInclude(candidate))
942+
return nullptr;
943+
if (candidate->getKind() != D->getKind() ||
944+
(candidate->isInstanceMember() !=
945+
cast<ValueDecl>(D)->isInstanceMember()))
946+
return nullptr;
945947

946-
if (lookupResults.size() == 1) {
947-
auto candidate = lookupResults[0];
948+
renamedDecl = candidate;
949+
} else {
950+
for (auto candidate : lookupResults) {
948951
if (!shouldInclude(candidate))
949-
return nullptr;
952+
continue;
953+
950954
if (candidate->getKind() != D->getKind() ||
951955
(candidate->isInstanceMember() !=
952956
cast<ValueDecl>(D)->isInstanceMember()))
953-
return nullptr;
954-
955-
renamedDecl = candidate;
956-
} else {
957-
for (auto candidate : lookupResults) {
958-
if (!shouldInclude(candidate))
959-
continue;
957+
continue;
958+
959+
if (isa<FuncDecl>(candidate)) {
960+
auto cParams = cast<FuncDecl>(candidate)->getParameters();
961+
auto dParams = cast<FuncDecl>(D)->getParameters();
960962

961-
if (candidate->getKind() != D->getKind() ||
962-
(candidate->isInstanceMember() !=
963-
cast<ValueDecl>(D)->isInstanceMember()))
963+
if (cParams->size() != dParams->size())
964964
continue;
965965

966-
if (isa<FuncDecl>(candidate)) {
967-
auto cParams = cast<FuncDecl>(candidate)->getParameters();
968-
auto dParams = cast<FuncDecl>(D)->getParameters();
969-
970-
if (cParams->size() != dParams->size())
971-
continue;
972-
973-
bool hasSameParameterTypes = true;
974-
for (auto index : indices(*cParams)) {
975-
auto cParamsType = cParams->get(index)->getType();
976-
auto dParamsType = dParams->get(index)->getType();
977-
if (!cParamsType->matchesParameter(dParamsType, TypeMatchOptions())) {
978-
hasSameParameterTypes = false;
979-
break;
980-
}
981-
}
982-
983-
if (!hasSameParameterTypes) {
984-
continue;
966+
bool hasSameParameterTypes = true;
967+
for (auto index : indices(*cParams)) {
968+
auto cParamsType = cParams->get(index)->getType();
969+
auto dParamsType = dParams->get(index)->getType();
970+
if (!cParamsType->matchesParameter(dParamsType, TypeMatchOptions())) {
971+
hasSameParameterTypes = false;
972+
break;
985973
}
986974
}
987975

988-
if (renamedDecl) {
989-
// If we found a duplicated candidate then we would silently fail.
990-
renamedDecl = nullptr;
991-
break;
976+
if (!hasSameParameterTypes) {
977+
continue;
992978
}
993-
renamedDecl = candidate;
994979
}
980+
981+
if (renamedDecl) {
982+
// If we found a duplicated candidate then we would silently fail.
983+
renamedDecl = nullptr;
984+
break;
985+
}
986+
renamedDecl = candidate;
995987
}
996-
return renamedDecl;
997988
}
989+
return renamedDecl;
998990
}
999991

1000992
void printRenameForDecl(const AvailableAttr *AvAttr, const ValueDecl *D,

0 commit comments

Comments
 (0)