@@ -70,6 +70,70 @@ class CanTypeVisitor {
70
70
#include " swift/AST/TypeNodes.def"
71
71
};
72
72
73
+ // / This is a convenience refinement of CanTypeVisitor which forwards the
74
+ // / paired nominal type methods to a common implementation.
75
+ // /
76
+ // / The delegation flow is:
77
+ // / {ClassType, BoundGenericClassType} -> AnyClassType -> AnyNominalType -> Type
78
+ // / {EnumType, BoundGenericEnumType} -> AnyEnumType -> AnyNominalType -> Type
79
+ // / {StructType, BoundGenericStructType} -> AnyStructType -> AnyNominalType -> Type
80
+ // / ProtocolType -> AnyNominalType -> Type
81
+ // /
82
+ // / The new visitAny*Type methods take the appropriate Decl* as their second
83
+ // / argument.
84
+ template <typename ImplClass, typename RetTy = void , typename ... Args>
85
+ class CanTypeVisitor_AnyNominal : public CanTypeVisitor <ImplClass, RetTy, Args...> {
86
+ public:
87
+ RetTy visitClassType (CanClassType T, Args... args) {
88
+ return static_cast <ImplClass*>(this )
89
+ ->visitAnyClassType (T, T->getDecl (), ::std::forward<Args>(args)...);
90
+ }
91
+ RetTy visitBoundGenericClassType (CanBoundGenericClassType T, Args... args) {
92
+ return static_cast <ImplClass*>(this )
93
+ ->visitAnyClassType (T, T->getDecl (), ::std::forward<Args>(args)...);
94
+ }
95
+ RetTy visitAnyClassType (CanType T, ClassDecl *D, Args... args) {
96
+ return static_cast <ImplClass*>(this )
97
+ ->visitAnyNominalType (T, D, ::std::forward<Args>(args)...);
98
+ }
99
+
100
+ RetTy visitStructType (CanStructType T, Args... args) {
101
+ return static_cast <ImplClass*>(this )
102
+ ->visitAnyStructType (T, T->getDecl (), ::std::forward<Args>(args)...);
103
+ }
104
+ RetTy visitBoundGenericStructType (CanBoundGenericStructType T, Args... args) {
105
+ return static_cast <ImplClass*>(this )
106
+ ->visitAnyStructType (T, T->getDecl (), ::std::forward<Args>(args)...);
107
+ }
108
+ RetTy visitAnyStructType (CanType T, StructDecl *D, Args... args) {
109
+ return static_cast <ImplClass*>(this )
110
+ ->visitAnyNominalType (T, D, ::std::forward<Args>(args)...);
111
+ }
112
+
113
+ RetTy visitEnumType (CanEnumType T, Args... args) {
114
+ return static_cast <ImplClass*>(this )
115
+ ->visitAnyEnumType (T, T->getDecl (), ::std::forward<Args>(args)...);
116
+ }
117
+ RetTy visitBoundGenericEnumType (CanBoundGenericEnumType T, Args... args) {
118
+ return static_cast <ImplClass*>(this )
119
+ ->visitAnyEnumType (T, T->getDecl (), ::std::forward<Args>(args)...);
120
+ }
121
+ RetTy visitAnyEnumType (CanType T, EnumDecl *D, Args... args) {
122
+ return static_cast <ImplClass*>(this )
123
+ ->visitAnyNominalType (T, D, ::std::forward<Args>(args)...);
124
+ }
125
+
126
+ RetTy visitProtocolType (CanProtocolType T, Args... args) {
127
+ return static_cast <ImplClass*>(this )
128
+ ->visitAnyNominalType (T, T->getDecl (), ::std::forward<Args>(args)...);
129
+ }
130
+
131
+ RetTy visitAnyNominalType (CanType T, NominalTypeDecl *D, Args... args) {
132
+ return static_cast <ImplClass*>(this )
133
+ ->visitType (T, ::std::forward<Args>(args)...);
134
+ }
135
+ };
136
+
73
137
} // end namespace swift
74
138
75
139
#endif
0 commit comments