@@ -656,18 +656,17 @@ static void reportRelated(ASTContext &Ctx, const Decl *D,
656
656
}
657
657
}
658
658
659
- static ArrayRef<const DeclAttribute* >
660
- getDeclAttributes (const Decl *D, std::vector<const DeclAttribute* > &Scratch) {
661
- for (auto Attr : D->getAttrs ()) {
659
+ static ArrayRef<SemanticAvailableAttr >
660
+ getAvailableAttrs (const Decl *D, std::vector<SemanticAvailableAttr > &Scratch) {
661
+ for (auto Attr : D->getSemanticAvailableAttrs ()) {
662
662
Scratch.push_back (Attr);
663
663
}
664
+ // FIXME: [availability] Special-casing enums and deprecation here is weird.
664
665
// For enum elements, inherit their parent enum decls' deprecated attributes.
665
666
if (auto *DE = dyn_cast<EnumElementDecl>(D)) {
666
- for (auto Attr : DE->getParentEnum ()->getAttrs ()) {
667
- if (auto Avail = dyn_cast<AvailableAttr>(Attr)) {
668
- if (Avail->Deprecated || Avail->isUnconditionallyDeprecated ()) {
669
- Scratch.push_back (Attr);
670
- }
667
+ for (auto Attr : DE->getParentEnum ()->getSemanticAvailableAttrs ()) {
668
+ if (Attr.getDeprecated () || Attr.isUnconditionallyDeprecated ()) {
669
+ Scratch.push_back (Attr);
671
670
}
672
671
}
673
672
}
@@ -676,10 +675,8 @@ getDeclAttributes(const Decl *D, std::vector<const DeclAttribute*> &Scratch) {
676
675
}
677
676
678
677
// Only reports @available.
679
- // FIXME: Handle all attributes.
680
- static void reportAttributes (ASTContext &Ctx,
681
- const Decl *D,
682
- DocInfoConsumer &Consumer) {
678
+ static void reportAvailabilityAttributes (ASTContext &Ctx, const Decl *D,
679
+ DocInfoConsumer &Consumer) {
683
680
static UIdent AvailableAttrKind (" source.lang.swift.attribute.availability" );
684
681
static UIdent PlatformIOS (" source.availability.platform.ios" );
685
682
static UIdent PlatformMacCatalyst (" source.availability.platform.maccatalyst" );
@@ -693,61 +690,75 @@ static void reportAttributes(ASTContext &Ctx,
693
690
static UIdent PlatformWatchOSAppExt (" source.availability.platform.watchos_app_extension" );
694
691
static UIdent PlatformOpenBSD (" source.availability.platform.openbsd" );
695
692
static UIdent PlatformWindows (" source.availability.platform.windows" );
696
- std::vector<const DeclAttribute*> Scratch;
697
-
698
- for (auto Attr : getDeclAttributes (D, Scratch)) {
699
- if (auto Av = dyn_cast<AvailableAttr>(Attr)) {
700
- UIdent PlatformUID;
701
- switch (Av->getPlatform ()) {
702
- case PlatformKind::none:
703
- PlatformUID = UIdent (); break ;
704
- case PlatformKind::iOS:
705
- PlatformUID = PlatformIOS; break ;
706
- case PlatformKind::macCatalyst:
707
- PlatformUID = PlatformMacCatalyst; break ;
708
- case PlatformKind::macOS:
709
- PlatformUID = PlatformOSX; break ;
710
- case PlatformKind::tvOS:
711
- PlatformUID = PlatformtvOS; break ;
712
- case PlatformKind::watchOS:
713
- PlatformUID = PlatformWatchOS; break ;
714
- case PlatformKind::iOSApplicationExtension:
715
- PlatformUID = PlatformIOSAppExt; break ;
716
- case PlatformKind::visionOS:
717
- // FIXME: Formal platform support in SourceKit is needed.
718
- PlatformUID = UIdent (); break ;
719
- case PlatformKind::macCatalystApplicationExtension:
720
- PlatformUID = PlatformMacCatalystAppExt; break ;
721
- case PlatformKind::macOSApplicationExtension:
722
- PlatformUID = PlatformOSXAppExt; break ;
723
- case PlatformKind::tvOSApplicationExtension:
724
- PlatformUID = PlatformtvOSAppExt; break ;
725
- case PlatformKind::watchOSApplicationExtension:
726
- PlatformUID = PlatformWatchOSAppExt; break ;
727
- case PlatformKind::visionOSApplicationExtension:
728
- // FIXME: Formal platform support in SourceKit is needed.
729
- PlatformUID = UIdent (); break ;
730
- case PlatformKind::OpenBSD:
731
- PlatformUID = PlatformOpenBSD; break ;
732
- case PlatformKind::Windows:
733
- PlatformUID = PlatformWindows; break ;
734
- }
693
+ std::vector<SemanticAvailableAttr> Scratch;
735
694
736
- AvailableAttrInfo Info;
737
- Info.AttrKind = AvailableAttrKind;
738
- Info.IsUnavailable = Av->isUnconditionallyUnavailable ();
739
- Info.IsDeprecated = Av->isUnconditionallyDeprecated ();
740
- Info.Platform = PlatformUID;
741
- Info.Message = Av->Message ;
742
- if (Av->Introduced )
743
- Info.Introduced = *Av->Introduced ;
744
- if (Av->Deprecated )
745
- Info.Deprecated = *Av->Deprecated ;
746
- if (Av->Obsoleted )
747
- Info.Obsoleted = *Av->Obsoleted ;
748
-
749
- Consumer.handleAvailableAttribute (Info);
695
+ for (auto Attr : getAvailableAttrs (D, Scratch)) {
696
+ UIdent PlatformUID;
697
+ switch (Attr.getPlatform ()) {
698
+ case PlatformKind::none:
699
+ PlatformUID = UIdent ();
700
+ break ;
701
+ case PlatformKind::iOS:
702
+ PlatformUID = PlatformIOS;
703
+ break ;
704
+ case PlatformKind::macCatalyst:
705
+ PlatformUID = PlatformMacCatalyst;
706
+ break ;
707
+ case PlatformKind::macOS:
708
+ PlatformUID = PlatformOSX;
709
+ break ;
710
+ case PlatformKind::tvOS:
711
+ PlatformUID = PlatformtvOS;
712
+ break ;
713
+ case PlatformKind::watchOS:
714
+ PlatformUID = PlatformWatchOS;
715
+ break ;
716
+ case PlatformKind::iOSApplicationExtension:
717
+ PlatformUID = PlatformIOSAppExt;
718
+ break ;
719
+ case PlatformKind::visionOS:
720
+ // FIXME: Formal platform support in SourceKit is needed.
721
+ PlatformUID = UIdent ();
722
+ break ;
723
+ case PlatformKind::macCatalystApplicationExtension:
724
+ PlatformUID = PlatformMacCatalystAppExt;
725
+ break ;
726
+ case PlatformKind::macOSApplicationExtension:
727
+ PlatformUID = PlatformOSXAppExt;
728
+ break ;
729
+ case PlatformKind::tvOSApplicationExtension:
730
+ PlatformUID = PlatformtvOSAppExt;
731
+ break ;
732
+ case PlatformKind::watchOSApplicationExtension:
733
+ PlatformUID = PlatformWatchOSAppExt;
734
+ break ;
735
+ case PlatformKind::visionOSApplicationExtension:
736
+ // FIXME: Formal platform support in SourceKit is needed.
737
+ PlatformUID = UIdent ();
738
+ break ;
739
+ case PlatformKind::OpenBSD:
740
+ PlatformUID = PlatformOpenBSD;
741
+ break ;
742
+ case PlatformKind::Windows:
743
+ PlatformUID = PlatformWindows;
744
+ break ;
750
745
}
746
+ // FIXME: [availability] Handle other availability domains?
747
+
748
+ AvailableAttrInfo Info;
749
+ Info.AttrKind = AvailableAttrKind;
750
+ Info.IsUnavailable = Attr.isUnconditionallyUnavailable ();
751
+ Info.IsDeprecated = Attr.isUnconditionallyDeprecated ();
752
+ Info.Platform = PlatformUID;
753
+ Info.Message = Attr.getMessage ();
754
+ if (Attr.getIntroduced ())
755
+ Info.Introduced = Attr.getIntroduced ().value ();
756
+ if (Attr.getDeprecated ())
757
+ Info.Deprecated = Attr.getDeprecated ().value ();
758
+ if (Attr.getObsoleted ())
759
+ Info.Obsoleted = Attr.getObsoleted ().value ();
760
+
761
+ Consumer.handleAvailableAttribute (Info);
751
762
}
752
763
}
753
764
@@ -764,7 +775,7 @@ static void reportDocEntities(ASTContext &Ctx,
764
775
: TypeOrExtensionDecl (),
765
776
Consumer);
766
777
reportDocEntities (Ctx, Entity.SubEntities , Consumer);
767
- reportAttributes (Ctx, Entity.Dcl , Consumer);
778
+ reportAvailabilityAttributes (Ctx, Entity.Dcl , Consumer);
768
779
Consumer.finishSourceEntity (EntInfo.Kind );
769
780
}
770
781
}
0 commit comments