Skip to content

Commit 1d6f492

Browse files
committed
Extract the finding the proper objc renamed Decl into getRenameDecl method
1 parent c0e887d commit 1d6f492

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -912,24 +912,18 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
912912
}
913913
return hasPrintedAnything;
914914
}
915-
916-
void printRenameForDecl(const AvailableAttr *AvAttr, const ValueDecl *D,
917-
bool includeQuotes) {
918-
assert(!AvAttr->Rename.empty());
919-
920-
auto renamedParsedDeclName = parseDeclName(AvAttr->Rename);
921-
auto renamedDeclName = renamedParsedDeclName.formDeclName(D->getASTContext());
922-
915+
916+
const ValueDecl *getRenameDecl(const ValueDecl *D, const ParsedDeclName renamedParsedDeclName) {
923917
auto declContext = D->getDeclContext();
924-
const ValueDecl *renamedDecl = nullptr;
918+
auto renamedDeclName = renamedParsedDeclName.formDeclName(D->getASTContext());
925919

926920
if (isa<ClassDecl>(D) || isa<ProtocolDecl>(D)) {
927921
UnqualifiedLookup lookup(renamedDeclName.getBaseIdentifier(),
928922
declContext->getModuleScopeContext(),
929923
nullptr,
930924
SourceLoc(),
931925
UnqualifiedLookup::Flags::TypeLookup);
932-
renamedDecl = lookup.getSingleTypeResult();
926+
return lookup.getSingleTypeResult();
933927
} else {
934928
TypeDecl *typeDecl = declContext->getSelfNominalTypeDecl();
935929

@@ -941,24 +935,23 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
941935
SourceLoc(),
942936
UnqualifiedLookup::Flags::TypeLookup);
943937
if (!specificTypeLookup.getSingleTypeResult()) {
944-
renamedDecl = nullptr;
945-
goto printing_rename_attribute;
938+
return nullptr;
946939
}
947940

948941
if (typeDecl->getDeclaredInterfaceType()->matches(specificTypeLookup.getSingleTypeResult()->getDeclaredInterfaceType(), TypeMatchFlags::AllowOverride)) {
949942
// If the Context Name contain the name of the subclass then we would find the renamed in the superclass instead
950943
typeDecl = specificTypeLookup.getSingleTypeResult();
951944
} else if (!specificTypeLookup.getSingleTypeResult()->getDeclaredInterfaceType()->matches(typeDecl->getDeclaredInterfaceType(), TypeMatchFlags::AllowOverride)) {
952945
// Failed and print the raw renamed attributed when there is no relationship between those 2 types
953-
renamedDecl = nullptr;
954-
goto printing_rename_attribute;
946+
return nullptr;
955947
}
956948
}
957949

950+
const ValueDecl *renamedDecl = nullptr;
958951
SmallVector<ValueDecl *, 4> lookupResults;
959952
declContext->lookupQualified(
960-
typeDecl,
961-
renamedDeclName, NL_QualifiedDefault, lookupResults);
953+
typeDecl,
954+
renamedDeclName, NL_QualifiedDefault, lookupResults);
962955
for (auto candidate : lookupResults) {
963956
if (!shouldInclude(candidate))
964957
continue;
@@ -986,7 +979,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
986979
break;
987980
}
988981
}
989-
982+
990983
if (!hasSameParameterTypes) {
991984
continue;
992985
}
@@ -999,9 +992,16 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
999992
}
1000993
renamedDecl = candidate;
1001994
}
995+
return renamedDecl;
1002996
}
997+
}
998+
999+
void printRenameForDecl(const AvailableAttr *AvAttr, const ValueDecl *D,
1000+
bool includeQuotes) {
1001+
assert(!AvAttr->Rename.empty());
1002+
1003+
const swift::ValueDecl * renamedDecl = getRenameDecl(D, parseDeclName(AvAttr->Rename));
10031004

1004-
printing_rename_attribute:
10051005
if (renamedDecl) {
10061006
SmallString<128> scratch;
10071007
auto renamedObjCRuntimeName = renamedDecl->getObjCRuntimeName()

0 commit comments

Comments
 (0)