@@ -774,17 +774,17 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
774
774
No = false ,
775
775
Yes = true
776
776
};
777
-
778
- // / Returns \c true if anything was printed.
777
+
778
+ // / Returns \c true if anything was printed.
779
779
bool printAvailability (const Decl *D, PrintLeadingSpace printLeadingSpace =
780
- PrintLeadingSpace::Yes) {
780
+ PrintLeadingSpace::Yes) {
781
781
bool hasPrintedAnything = false ;
782
782
auto maybePrintLeadingSpace = [&] {
783
783
if (printLeadingSpace == PrintLeadingSpace::Yes || hasPrintedAnything)
784
784
os << " " ;
785
785
hasPrintedAnything = true ;
786
786
};
787
-
787
+
788
788
for (auto AvAttr : D->getAttrs ().getAttributes <AvailableAttr>()) {
789
789
if (AvAttr->Platform == PlatformKind::none) {
790
790
if (AvAttr->PlatformAgnostic ==
@@ -794,8 +794,8 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
794
794
// rename
795
795
maybePrintLeadingSpace ();
796
796
os << " SWIFT_UNAVAILABLE_MSG(\" '"
797
- << cast<ValueDecl>(D)->getBaseName ()
798
- << " ' has been renamed to '" ;
797
+ << cast<ValueDecl>(D)->getBaseName ()
798
+ << " ' has been renamed to '" ;
799
799
printRenameForDecl (AvAttr, cast<ValueDecl>(D), false );
800
800
os << ' \' ' ;
801
801
if (!AvAttr->Message .empty ()) {
@@ -831,45 +831,45 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
831
831
}
832
832
continue ;
833
833
}
834
-
834
+
835
835
// Availability for a specific platform
836
836
if (!AvAttr->Introduced .hasValue () && !AvAttr->Deprecated .hasValue () &&
837
837
!AvAttr->Obsoleted .hasValue () &&
838
838
!AvAttr->isUnconditionallyDeprecated () &&
839
839
!AvAttr->isUnconditionallyUnavailable ()) {
840
840
continue ;
841
841
}
842
-
842
+
843
843
const char *plat;
844
844
switch (AvAttr->Platform ) {
845
- case PlatformKind::OSX:
846
- plat = " macos" ;
847
- break ;
848
- case PlatformKind::iOS:
849
- plat = " ios" ;
850
- break ;
851
- case PlatformKind::tvOS:
852
- plat = " tvos" ;
853
- break ;
854
- case PlatformKind::watchOS:
855
- plat = " watchos" ;
856
- break ;
857
- case PlatformKind::OSXApplicationExtension:
858
- plat = " macos_app_extension" ;
859
- break ;
860
- case PlatformKind::iOSApplicationExtension:
861
- plat = " ios_app_extension" ;
862
- break ;
863
- case PlatformKind::tvOSApplicationExtension:
864
- plat = " tvos_app_extension" ;
865
- break ;
866
- case PlatformKind::watchOSApplicationExtension:
867
- plat = " watchos_app_extension" ;
868
- break ;
869
- case PlatformKind::none:
870
- llvm_unreachable (" handled above" );
845
+ case PlatformKind::OSX:
846
+ plat = " macos" ;
847
+ break ;
848
+ case PlatformKind::iOS:
849
+ plat = " ios" ;
850
+ break ;
851
+ case PlatformKind::tvOS:
852
+ plat = " tvos" ;
853
+ break ;
854
+ case PlatformKind::watchOS:
855
+ plat = " watchos" ;
856
+ break ;
857
+ case PlatformKind::OSXApplicationExtension:
858
+ plat = " macos_app_extension" ;
859
+ break ;
860
+ case PlatformKind::iOSApplicationExtension:
861
+ plat = " ios_app_extension" ;
862
+ break ;
863
+ case PlatformKind::tvOSApplicationExtension:
864
+ plat = " tvos_app_extension" ;
865
+ break ;
866
+ case PlatformKind::watchOSApplicationExtension:
867
+ plat = " watchos_app_extension" ;
868
+ break ;
869
+ case PlatformKind::none:
870
+ llvm_unreachable (" handled above" );
871
871
}
872
-
872
+
873
873
maybePrintLeadingSpace ();
874
874
os << " SWIFT_AVAILABILITY(" << plat;
875
875
if (AvAttr->isUnconditionallyUnavailable ()) {
@@ -895,7 +895,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
895
895
}
896
896
if (!AvAttr->Rename .empty () && isa<ValueDecl>(D)) {
897
897
os << " ,message=\" '" << cast<ValueDecl>(D)->getBaseName ()
898
- << " ' has been renamed to '" ;
898
+ << " ' has been renamed to '" ;
899
899
printRenameForDecl (AvAttr, cast<ValueDecl>(D), false );
900
900
os << ' \' ' ;
901
901
if (!AvAttr->Message .empty ()) {
@@ -911,13 +911,13 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
911
911
}
912
912
return hasPrintedAnything;
913
913
}
914
-
914
+
915
915
const ValueDecl *getRenameDecl (const ValueDecl *D,
916
916
const ParsedDeclName renamedParsedDeclName) {
917
917
auto declContext = D->getDeclContext ();
918
918
ASTContext &astContext = D->getASTContext ();
919
919
auto renamedDeclName = renamedParsedDeclName.formDeclName (astContext);
920
-
920
+
921
921
if (isa<ClassDecl>(D) || isa<ProtocolDecl>(D)) {
922
922
UnqualifiedLookup lookup (renamedDeclName.getBaseIdentifier (),
923
923
declContext->getModuleScopeContext (), nullptr ,
@@ -926,54 +926,54 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
926
926
return lookup.getSingleTypeResult ();
927
927
} else {
928
928
TypeDecl *typeDecl = declContext->getSelfNominalTypeDecl ();
929
-
929
+
930
930
if (!renamedParsedDeclName.ContextName .empty ()) {
931
931
auto contextIdentifier =
932
- astContext.getIdentifier (renamedParsedDeclName.ContextName );
932
+ astContext.getIdentifier (renamedParsedDeclName.ContextName );
933
933
UnqualifiedLookup specificTypeLookup (
934
- contextIdentifier, declContext->getModuleScopeContext (), nullptr ,
935
- SourceLoc (), UnqualifiedLookup::Flags::TypeLookup);
934
+ contextIdentifier, declContext->getModuleScopeContext (), nullptr ,
935
+ SourceLoc (), UnqualifiedLookup::Flags::TypeLookup);
936
936
if (!specificTypeLookup.getSingleTypeResult ()) {
937
937
return nullptr ;
938
938
}
939
-
939
+
940
940
if (typeDecl->getDeclaredInterfaceType ()->matches (
941
- specificTypeLookup.getSingleTypeResult ()
942
- ->getDeclaredInterfaceType (),
943
- TypeMatchFlags::AllowOverride)) {
941
+ specificTypeLookup.getSingleTypeResult ()
942
+ ->getDeclaredInterfaceType (),
943
+ TypeMatchFlags::AllowOverride)) {
944
944
// If the Context Name contain the name of the subclass then we would
945
945
// find the renamed in the superclass instead
946
946
typeDecl = specificTypeLookup.getSingleTypeResult ();
947
947
} else if (!specificTypeLookup.getSingleTypeResult ()
948
- ->getDeclaredInterfaceType ()
949
- ->matches (typeDecl->getDeclaredInterfaceType (),
950
- TypeMatchFlags::AllowOverride)) {
951
- // Failed and print the raw renamed attributed when there is no
952
- // relationship between those 2 types
953
- return nullptr ;
954
- }
948
+ ->getDeclaredInterfaceType ()
949
+ ->matches (typeDecl->getDeclaredInterfaceType (),
950
+ TypeMatchFlags::AllowOverride)) {
951
+ // Failed and print the raw renamed attributed when there is no
952
+ // relationship between those 2 types
953
+ return nullptr ;
954
+ }
955
955
}
956
-
956
+
957
957
const ValueDecl *renamedDecl = nullptr ;
958
958
SmallVector<ValueDecl *, 4 > lookupResults;
959
959
declContext->lookupQualified (typeDecl, renamedDeclName,
960
960
NL_QualifiedDefault, lookupResults);
961
961
for (auto candidate : lookupResults) {
962
962
if (!shouldInclude (candidate))
963
963
continue ;
964
-
964
+
965
965
if (candidate->getKind () != D->getKind () ||
966
966
(candidate->isInstanceMember () !=
967
967
cast<ValueDecl>(D)->isInstanceMember ()))
968
968
continue ;
969
-
969
+
970
970
if (isa<FuncDecl>(candidate)) {
971
971
auto cParams = cast<FuncDecl>(candidate)->getParameters ();
972
972
auto dParams = cast<FuncDecl>(D)->getParameters ();
973
-
973
+
974
974
if (cParams->size () != dParams->size ())
975
975
continue ;
976
-
976
+
977
977
bool hasSameParameterTypes = true ;
978
978
for (auto index : indices (*cParams)) {
979
979
auto cParamsType = cParams->get (index)->getType ();
@@ -984,12 +984,12 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
984
984
break ;
985
985
}
986
986
}
987
-
987
+
988
988
if (!hasSameParameterTypes) {
989
989
continue ;
990
990
}
991
991
}
992
-
992
+
993
993
if (renamedDecl) {
994
994
// If we found a duplicated candidate then we would silently fail.
995
995
renamedDecl = nullptr ;
@@ -1000,24 +1000,24 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1000
1000
return renamedDecl;
1001
1001
}
1002
1002
}
1003
-
1003
+
1004
1004
void printRenameForDecl (const AvailableAttr *AvAttr, const ValueDecl *D,
1005
1005
bool includeQuotes) {
1006
1006
assert (!AvAttr->Rename .empty ());
1007
-
1007
+
1008
1008
const swift::ValueDecl *renamedDecl =
1009
- getRenameDecl (D, parseDeclName (AvAttr->Rename ));
1010
-
1009
+ getRenameDecl (D, parseDeclName (AvAttr->Rename ));
1010
+
1011
1011
if (renamedDecl) {
1012
1012
SmallString<128 > scratch;
1013
1013
auto renamedObjCRuntimeName =
1014
- renamedDecl->getObjCRuntimeName ()->getString (scratch);
1014
+ renamedDecl->getObjCRuntimeName ()->getString (scratch);
1015
1015
printEncodedString (renamedObjCRuntimeName, includeQuotes);
1016
1016
} else {
1017
1017
printEncodedString (AvAttr->Rename , includeQuotes);
1018
1018
}
1019
1019
}
1020
-
1020
+
1021
1021
void printSwift3ObjCDeprecatedInference (ValueDecl *VD) {
1022
1022
const LangOptions &langOpts = M.getASTContext ().LangOpts ;
1023
1023
if (!langOpts.EnableSwift3ObjCInference ||
0 commit comments