@@ -301,8 +301,10 @@ class InheritedProtocolCollector {
301
301
static const StringLiteral DummyProtocolName;
302
302
303
303
using AvailableAttrList = TinyPtrVector<const AvailableAttr *>;
304
+ using OtherAttrList = TinyPtrVector<const DeclAttribute*>;
304
305
using ProtocolAndAvailability =
305
- std::tuple<ProtocolDecl *, AvailableAttrList, bool /* isUnchecked*/ >;
306
+ std::tuple<ProtocolDecl *, AvailableAttrList, bool /* isUnchecked*/ ,
307
+ OtherAttrList>;
306
308
307
309
// / Protocols that will be included by the ASTPrinter without any extra work.
308
310
SmallVector<ProtocolDecl *, 8 > IncludedProtocols;
@@ -338,6 +340,17 @@ class InheritedProtocolCollector {
338
340
return cache.getValue ();
339
341
}
340
342
343
+ static OtherAttrList getOtherAttrList (const Decl *D) {
344
+ OtherAttrList results;
345
+ while (D) {
346
+ for (auto *result: D->getAttrs ().getAttributes <OriginallyDefinedInAttr>()) {
347
+ results.push_back (result);
348
+ }
349
+ D = D->getDeclContext ()->getAsDecl ();
350
+ }
351
+ return results;
352
+ }
353
+
341
354
static bool canPrintProtocolTypeNormally (Type type, const Decl *D) {
342
355
return isPublicOrUsableFromInline (type);
343
356
}
@@ -369,7 +382,8 @@ class InheritedProtocolCollector {
369
382
ExtraProtocols.push_back (
370
383
ProtocolAndAvailability (protoTy->getDecl (),
371
384
getAvailabilityAttrs (D, availableAttrs),
372
- inherited.isUnchecked ));
385
+ inherited.isUnchecked ,
386
+ getOtherAttrList (D)));
373
387
}
374
388
// FIXME: This ignores layout constraints, but currently we don't support
375
389
// any of those besides 'AnyObject'.
@@ -389,7 +403,8 @@ class InheritedProtocolCollector {
389
403
ExtraProtocols.push_back (
390
404
ProtocolAndAvailability (conf->getProtocol (),
391
405
getAvailabilityAttrs (D, availableAttrs),
392
- isUncheckedConformance (conf)));
406
+ isUncheckedConformance (conf),
407
+ getOtherAttrList (D)));
393
408
}
394
409
}
395
410
}
@@ -550,6 +565,7 @@ class InheritedProtocolCollector {
550
565
auto proto = std::get<0 >(protoAndAvailability);
551
566
auto availability = std::get<1 >(protoAndAvailability);
552
567
auto isUnchecked = std::get<2 >(protoAndAvailability);
568
+ auto otherAttrs = std::get<3 >(protoAndAvailability);
553
569
proto->walkInheritedProtocols (
554
570
[&](ProtocolDecl *inherited) -> TypeWalker::Action {
555
571
if (!handledProtocols.insert (inherited).second )
@@ -571,7 +587,8 @@ class InheritedProtocolCollector {
571
587
conformanceDeclaredInModule (M, nominal, inherited) &&
572
588
!M->isImportedImplementationOnly (inherited->getParentModule ())) {
573
589
protocolsToPrint.push_back (
574
- ProtocolAndAvailability (inherited, availability, isUnchecked));
590
+ ProtocolAndAvailability (inherited, availability, isUnchecked,
591
+ otherAttrs));
575
592
return TypeWalker::Action::SkipChildren;
576
593
}
577
594
@@ -586,6 +603,7 @@ class InheritedProtocolCollector {
586
603
auto proto = std::get<0 >(protoAndAvailability);
587
604
auto availability = std::get<1 >(protoAndAvailability);
588
605
auto isUnchecked = std::get<2 >(protoAndAvailability);
606
+ auto otherAttrs = std::get<3 >(protoAndAvailability);
589
607
590
608
bool haveFeatureChecks = printOptions.PrintCompatibilityFeatureChecks &&
591
609
printCompatibilityFeatureChecksPre (printer, proto);
@@ -595,6 +613,7 @@ class InheritedProtocolCollector {
595
613
attrs.insert (attrs.end (), availability.begin (), availability.end ());
596
614
auto spiAttributes = proto->getAttrs ().getAttributes <SPIAccessControlAttr>();
597
615
attrs.insert (attrs.end (), spiAttributes.begin (), spiAttributes.end ());
616
+ attrs.insert (attrs.end (), otherAttrs.begin (), otherAttrs.end ());
598
617
DeclAttributes::print (printer, printOptions, attrs);
599
618
600
619
printer << " extension " ;
0 commit comments