@@ -2582,44 +2582,53 @@ class DeclAttributes {
2582
2582
SourceLoc getStartLoc (bool forModifiers = false ) const ;
2583
2583
};
2584
2584
2585
+ // / Predicate used to filter attributes to only the original attributes.
2586
+ class OrigDeclAttrFilter {
2587
+ ModuleDecl *mod;
2588
+
2589
+ public:
2590
+ OrigDeclAttrFilter () : mod(nullptr ) {}
2591
+
2592
+ OrigDeclAttrFilter (ModuleDecl *mod) : mod(mod) {}
2593
+
2594
+ Optional<const DeclAttribute *>
2595
+ operator ()(const DeclAttribute *Attr) const ;
2596
+ };
2597
+
2585
2598
// / Attributes applied directly to the declaration.
2586
2599
// /
2587
2600
// / We should really just have \c DeclAttributes and \c SemanticDeclAttributes,
2588
2601
// / but currently almost all callers expect the latter. Instead of changing all
2589
- // / callers of \c getAttrs, instead provide a way to retrieive the original
2602
+ // / callers of \c getAttrs, instead provide a way to retrieve the original
2590
2603
// / attributes.
2591
2604
class OrigDeclAttributes {
2592
- SmallVector<DeclAttribute *> attributes;
2593
- using AttrListTy = SmallVectorImpl<DeclAttribute *>;
2594
-
2595
2605
public:
2596
- OrigDeclAttributes () = default ;
2606
+ using OrigFilteredRange = OptionalTransformRange<iterator_range<DeclAttributes::const_iterator>, OrigDeclAttrFilter> ;
2597
2607
2598
- OrigDeclAttributes (DeclAttributes semanticAttrs, ModuleDecl *mod);
2608
+ private:
2609
+ OrigFilteredRange origRange;
2599
2610
2611
+ public:
2612
+ OrigDeclAttributes () : origRange(make_range(DeclAttributes::const_iterator(nullptr ), DeclAttributes::const_iterator(nullptr )), OrigDeclAttrFilter()) {}
2600
2613
2601
- using iterator = AttrListTy::iterator;
2602
- using const_iterator = AttrListTy::const_iterator;
2614
+ OrigDeclAttributes (const DeclAttributes &allAttrs, ModuleDecl *mod) : origRange(make_range(allAttrs.begin(), allAttrs.end()), OrigDeclAttrFilter(mod)) {}
2603
2615
2604
- iterator begin () { return attributes.begin (); }
2605
- iterator end () { return attributes.end (); }
2606
- const_iterator begin () const { return attributes.begin (); }
2607
- const_iterator end () const { return attributes.end (); }
2616
+ OrigFilteredRange::iterator begin () const { return origRange.begin (); }
2617
+ OrigFilteredRange::iterator end () const { return origRange.end (); }
2608
2618
2609
2619
template <typename AttrType, bool AllowInvalid>
2610
2620
using AttributeKindRange =
2611
- OptionalTransformRange<iterator_range<const_iterator>,
2612
- ToAttributeKind<AttrType, AllowInvalid>, const_iterator>;
2621
+ OptionalTransformRange<OrigFilteredRange, ToAttributeKind<AttrType, AllowInvalid>>;
2613
2622
2614
2623
template <typename AttrType, bool AllowInvalid = false >
2615
2624
AttributeKindRange<AttrType, AllowInvalid> getAttributes () const {
2616
- return AttributeKindRange<AttrType, AllowInvalid>(make_range ( begin (), end ()) , ToAttributeKind<AttrType, AllowInvalid>());
2625
+ return AttributeKindRange<AttrType, AllowInvalid>(origRange , ToAttributeKind<AttrType, AllowInvalid>());
2617
2626
}
2618
2627
2619
2628
// / Retrieve the first attribute of the given attribute class.
2620
2629
template <typename AttrType>
2621
2630
const AttrType *getAttribute (bool allowInvalid = false ) const {
2622
- for (auto *attr : attributes ) {
2631
+ for (auto *attr : origRange ) {
2623
2632
if (auto *specificAttr = dyn_cast<AttrType>(attr)) {
2624
2633
if (specificAttr->isValid () || allowInvalid)
2625
2634
return specificAttr;
0 commit comments