@@ -137,7 +137,7 @@ namespace {
137
137
using DelayedMemberSet = llvm::SmallSetVector<const ValueDecl *, 32 >;
138
138
139
139
class ObjCPrinter : private DeclVisitor <ObjCPrinter>,
140
- private TypeVisitor<ObjCPrinter, void ,
140
+ private TypeVisitor<ObjCPrinter, void ,
141
141
Optional<OptionalTypeKind>>
142
142
{
143
143
friend ASTVisitor;
@@ -528,7 +528,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
528
528
return sel.getNumArgs () == 0 &&
529
529
sel.getSelectorPieces ().front ().str () == " init" ;
530
530
}
531
-
531
+
532
532
void printAbstractFunctionAsMethod (AbstractFunctionDecl *AFD,
533
533
bool isClassMethod,
534
534
bool isNSUIntegerSubscript = false ) {
@@ -553,7 +553,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
553
553
auto resultTy = getForeignResultType (AFD, methodTy, errorConvention);
554
554
555
555
// Constructors and methods returning DynamicSelf return
556
- // instancetype.
556
+ // instancetype.
557
557
if (isa<ConstructorDecl>(AFD) ||
558
558
(isa<FuncDecl>(AFD) && cast<FuncDecl>(AFD)->hasDynamicSelf ())) {
559
559
if (errorConvention && errorConvention->stripsResultOptionality ()) {
@@ -776,9 +776,8 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
776
776
};
777
777
778
778
// / Returns \c true if anything was printed.
779
- bool printAvailability (
780
- const Decl *D,
781
- PrintLeadingSpace printLeadingSpace = PrintLeadingSpace::Yes) {
779
+ bool printAvailability (const Decl *D, PrintLeadingSpace printLeadingSpace =
780
+ PrintLeadingSpace::Yes) {
782
781
bool hasPrintedAnything = false ;
783
782
auto maybePrintLeadingSpace = [&] {
784
783
if (printLeadingSpace == PrintLeadingSpace::Yes || hasPrintedAnything)
@@ -788,7 +787,8 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
788
787
789
788
for (auto AvAttr : D->getAttrs ().getAttributes <AvailableAttr>()) {
790
789
if (AvAttr->Platform == PlatformKind::none) {
791
- if (AvAttr->PlatformAgnostic == PlatformAgnosticAvailabilityKind::Unavailable) {
790
+ if (AvAttr->PlatformAgnostic ==
791
+ PlatformAgnosticAvailabilityKind::Unavailable) {
792
792
// Availability for *
793
793
if (!AvAttr->Rename .empty () && isa<ValueDecl>(D)) {
794
794
// rename
@@ -833,11 +833,10 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
833
833
}
834
834
835
835
// Availability for a specific platform
836
- if (!AvAttr->Introduced .hasValue ()
837
- && !AvAttr->Deprecated .hasValue ()
838
- && !AvAttr->Obsoleted .hasValue ()
839
- && !AvAttr->isUnconditionallyDeprecated ()
840
- && !AvAttr->isUnconditionallyUnavailable ()) {
836
+ if (!AvAttr->Introduced .hasValue () && !AvAttr->Deprecated .hasValue () &&
837
+ !AvAttr->Obsoleted .hasValue () &&
838
+ !AvAttr->isUnconditionallyDeprecated () &&
839
+ !AvAttr->isUnconditionallyUnavailable ()) {
841
840
continue ;
842
841
}
843
842
@@ -912,43 +911,75 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
912
911
}
913
912
return hasPrintedAnything;
914
913
}
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
-
914
+
915
+ const ValueDecl *getRenameDecl (const ValueDecl *D,
916
+ const ParsedDeclName renamedParsedDeclName) {
923
917
auto declContext = D->getDeclContext ();
924
- const ValueDecl *renamedDecl = nullptr ;
925
-
918
+ ASTContext &astContext = D->getASTContext ();
919
+ auto renamedDeclName = renamedParsedDeclName.formDeclName (astContext);
920
+
926
921
if (isa<ClassDecl>(D) || isa<ProtocolDecl>(D)) {
922
+ if (!renamedParsedDeclName.ContextName .empty ()) {
923
+ return nullptr ;
924
+ }
927
925
UnqualifiedLookup lookup (renamedDeclName.getBaseIdentifier (),
928
- declContext->getModuleScopeContext (),
929
- nullptr ,
926
+ declContext->getModuleScopeContext (), nullptr ,
930
927
SourceLoc (),
931
928
UnqualifiedLookup::Flags::TypeLookup);
932
- renamedDecl = lookup.getSingleTypeResult ();
929
+ return lookup.getSingleTypeResult ();
930
+ }
931
+
932
+ TypeDecl *typeDecl = declContext->getSelfNominalTypeDecl ();
933
+
934
+ const ValueDecl *renamedDecl = nullptr ;
935
+ SmallVector<ValueDecl *, 4 > lookupResults;
936
+ declContext->lookupQualified (typeDecl->getDeclaredInterfaceType (),
937
+ renamedDeclName, NL_QualifiedDefault, nullptr ,
938
+ lookupResults);
939
+
940
+ if (lookupResults.size () == 1 ) {
941
+ auto candidate = lookupResults[0 ];
942
+ if (!shouldInclude (candidate))
943
+ return nullptr ;
944
+ if (candidate->getKind () != D->getKind () ||
945
+ (candidate->isInstanceMember () !=
946
+ cast<ValueDecl>(D)->isInstanceMember ()))
947
+ return nullptr ;
948
+
949
+ renamedDecl = candidate;
933
950
} else {
934
- SmallVector<ValueDecl *, 4 > lookupResults;
935
- declContext->lookupQualified (
936
- declContext->getSelfNominalTypeDecl (),
937
- renamedDeclName, NL_QualifiedDefault, lookupResults);
938
951
for (auto candidate : lookupResults) {
939
952
if (!shouldInclude (candidate))
940
953
continue ;
941
-
954
+
942
955
if (candidate->getKind () != D->getKind () ||
943
956
(candidate->isInstanceMember () !=
944
957
cast<ValueDecl>(D)->isInstanceMember ()))
945
958
continue ;
946
-
947
- if (isa<FuncDecl>(candidate) &&
948
- (cast<FuncDecl>(candidate)->getParameters ()->size () !=
949
- cast<FuncDecl>(D)->getParameters ()->size ()))
950
- continue ;
951
-
959
+
960
+ if (isa<AbstractFunctionDecl>(candidate)) {
961
+ auto cParams = cast<AbstractFunctionDecl>(candidate)->getParameters ();
962
+ auto dParams = cast<AbstractFunctionDecl>(D)->getParameters ();
963
+
964
+ if (cParams->size () != dParams->size ())
965
+ continue ;
966
+
967
+ bool hasSameParameterTypes = true ;
968
+ for (auto index : indices (*cParams)) {
969
+ auto cParamsType = cParams->get (index)->getType ();
970
+ auto dParamsType = dParams->get (index)->getType ();
971
+ if (!cParamsType->matchesParameter (dParamsType,
972
+ TypeMatchOptions ())) {
973
+ hasSameParameterTypes = false ;
974
+ break ;
975
+ }
976
+ }
977
+
978
+ if (!hasSameParameterTypes) {
979
+ continue ;
980
+ }
981
+ }
982
+
952
983
if (renamedDecl) {
953
984
// If we found a duplicated candidate then we would silently fail.
954
985
renamedDecl = nullptr ;
@@ -957,11 +988,20 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
957
988
renamedDecl = candidate;
958
989
}
959
990
}
960
-
991
+ return renamedDecl;
992
+ }
993
+
994
+ void printRenameForDecl (const AvailableAttr *AvAttr, const ValueDecl *D,
995
+ bool includeQuotes) {
996
+ assert (!AvAttr->Rename .empty ());
997
+
998
+ const ValueDecl *renamedDecl =
999
+ getRenameDecl (D, parseDeclName (AvAttr->Rename ));
1000
+
961
1001
if (renamedDecl) {
962
1002
SmallString<128 > scratch;
963
- auto renamedObjCRuntimeName = renamedDecl-> getObjCRuntimeName ()
964
- ->getString (scratch);
1003
+ auto renamedObjCRuntimeName =
1004
+ renamedDecl-> getObjCRuntimeName () ->getString (scratch);
965
1005
printEncodedString (renamedObjCRuntimeName, includeQuotes);
966
1006
} else {
967
1007
printEncodedString (AvAttr->Rename , includeQuotes);
@@ -1476,9 +1516,9 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1476
1516
MAP (UnsafeMutableRawPointer, " void *" , true );
1477
1517
1478
1518
Identifier ID_ObjectiveC = ctx.Id_ObjectiveC ;
1479
- specialNames[{ID_ObjectiveC, ctx.getIdentifier (" ObjCBool" )}]
1519
+ specialNames[{ID_ObjectiveC, ctx.getIdentifier (" ObjCBool" )}]
1480
1520
= { " BOOL" , false };
1481
- specialNames[{ID_ObjectiveC, ctx.getIdentifier (" Selector" )}]
1521
+ specialNames[{ID_ObjectiveC, ctx.getIdentifier (" Selector" )}]
1482
1522
= { " SEL" , true };
1483
1523
specialNames[{ID_ObjectiveC,
1484
1524
ctx.getIdentifier (
@@ -1605,7 +1645,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1605
1645
os << clangDecl->getKindName () << " " ;
1606
1646
}
1607
1647
1608
- void visitStructType (StructType *ST,
1648
+ void visitStructType (StructType *ST,
1609
1649
Optional<OptionalTypeKind> optionalKind) {
1610
1650
const StructDecl *SD = ST->getStructOrBoundGenericStruct ();
1611
1651
@@ -1829,7 +1869,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1829
1869
visitExistentialType (PT, optionalKind, /* isMetatype=*/ false );
1830
1870
}
1831
1871
1832
- void visitProtocolCompositionType (ProtocolCompositionType *PCT,
1872
+ void visitProtocolCompositionType (ProtocolCompositionType *PCT,
1833
1873
Optional<OptionalTypeKind> optionalKind) {
1834
1874
visitExistentialType (PCT, optionalKind, /* isMetatype=*/ false );
1835
1875
}
@@ -1840,7 +1880,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1840
1880
visitExistentialType (instanceTy, optionalKind, /* isMetatype=*/ true );
1841
1881
}
1842
1882
1843
- void visitMetatypeType (MetatypeType *MT,
1883
+ void visitMetatypeType (MetatypeType *MT,
1844
1884
Optional<OptionalTypeKind> optionalKind) {
1845
1885
Type instanceTy = MT->getInstanceType ();
1846
1886
if (auto classTy = instanceTy->getAs <ClassType>()) {
@@ -1875,7 +1915,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1875
1915
os << cast<clang::ObjCTypeParamDecl>(decl->getClangDecl ())->getName ();
1876
1916
printNullability (optionalKind);
1877
1917
}
1878
-
1918
+
1879
1919
void printFunctionType (FunctionType *FT, char pointerSigil,
1880
1920
Optional<OptionalTypeKind> optionalKind) {
1881
1921
visitPart (FT->getResult (), OTK_None);
@@ -1884,7 +1924,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1884
1924
openFunctionTypes.push_back (FT);
1885
1925
}
1886
1926
1887
- void visitFunctionType (FunctionType *FT,
1927
+ void visitFunctionType (FunctionType *FT,
1888
1928
Optional<OptionalTypeKind> optionalKind) {
1889
1929
switch (FT->getRepresentation ()) {
1890
1930
case AnyFunctionType::Representation::Thin:
@@ -1928,18 +1968,18 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1928
1968
visitPart (PT->getSinglyDesugaredType (), optionalKind);
1929
1969
}
1930
1970
1931
- void visitSyntaxSugarType (SyntaxSugarType *SST,
1971
+ void visitSyntaxSugarType (SyntaxSugarType *SST,
1932
1972
Optional<OptionalTypeKind> optionalKind) {
1933
1973
visitPart (SST->getSinglyDesugaredType (), optionalKind);
1934
1974
}
1935
1975
1936
- void visitDynamicSelfType (DynamicSelfType *DST,
1976
+ void visitDynamicSelfType (DynamicSelfType *DST,
1937
1977
Optional<OptionalTypeKind> optionalKind) {
1938
1978
printNullability (optionalKind, NullabilityPrintKind::ContextSensitive);
1939
1979
os << " instancetype" ;
1940
1980
}
1941
1981
1942
- void visitReferenceStorageType (ReferenceStorageType *RST,
1982
+ void visitReferenceStorageType (ReferenceStorageType *RST,
1943
1983
Optional<OptionalTypeKind> optionalKind) {
1944
1984
visitPart (RST->getReferentType (), optionalKind);
1945
1985
}
@@ -1977,7 +2017,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1977
2017
// / finishFunctionType()). If only a part of a type is being printed, use
1978
2018
// / visitPart().
1979
2019
public:
1980
- void print (Type ty, Optional<OptionalTypeKind> optionalKind,
2020
+ void print (Type ty, Optional<OptionalTypeKind> optionalKind,
1981
2021
Identifier name = Identifier(),
1982
2022
IsFunctionParam_t isFuncParam = IsNotFunctionParam) {
1983
2023
PrettyStackTraceType trace (M.getASTContext (), " printing" , ty);
@@ -2829,9 +2869,9 @@ class ModuleWriter {
2829
2869
// FIXME: This will end up taking linear time.
2830
2870
auto lhsMembers = cast<ExtensionDecl>(*lhs)->getMembers ();
2831
2871
auto rhsMembers = cast<ExtensionDecl>(*rhs)->getMembers ();
2832
- unsigned numLHSMembers = std::distance (lhsMembers.begin (),
2872
+ unsigned numLHSMembers = std::distance (lhsMembers.begin (),
2833
2873
lhsMembers.end ());
2834
- unsigned numRHSMembers = std::distance (rhsMembers.begin (),
2874
+ unsigned numRHSMembers = std::distance (rhsMembers.begin (),
2835
2875
rhsMembers.end ());
2836
2876
if (numLHSMembers != numRHSMembers)
2837
2877
return numLHSMembers < numRHSMembers ? Descending : Ascending;
0 commit comments