@@ -64,23 +64,28 @@ class Type {
64
64
65
65
// / Provide type casting support.
66
66
template <typename U>
67
+ [[deprecated(" Use mlir::isa<U>() instead" )]]
67
68
bool isa () const {
68
69
assert (impl && " isa<> used on a null type." );
69
70
return U::classof (*this );
70
71
}
71
72
template <typename U, typename V, typename ... Others>
73
+ [[deprecated(" Use mlir::isa<U>() instead" )]]
72
74
bool isa () const {
73
75
return isa<U>() || isa<V, Others...>();
74
76
}
75
77
template <typename U>
78
+ [[deprecated(" Use mlir::dyn_cast<U>() instead" )]]
76
79
U dyn_cast () const {
77
80
return isa<U>() ? U (impl) : U (nullptr );
78
81
}
79
82
template <typename U>
83
+ [[deprecated(" Use mlir::dyn_cast_or_null<U>() instead" )]]
80
84
U dyn_cast_or_null () const {
81
85
return (impl && isa<U>()) ? U (impl) : U (nullptr );
82
86
}
83
87
template <typename U>
88
+ [[deprecated(" Use mlir::cast<U>() instead" )]]
84
89
U cast () const {
85
90
assert (isa<U>());
86
91
return U (impl);
@@ -323,6 +328,29 @@ struct DenseMapInfo<mlir::pdll::ast::Type> {
323
328
return lhs == rhs;
324
329
}
325
330
};
331
+
332
+ // / Add support for llvm style casts.
333
+ // / We provide a cast between To and From if From is mlir::pdll::ast::Type or
334
+ // / derives from it
335
+ template <typename To, typename From>
336
+ struct CastInfo <
337
+ To, From,
338
+ std::enable_if_t <
339
+ std::is_same_v<mlir::pdll::ast::Type, std::remove_const_t <From>> ||
340
+ std::is_base_of_v<mlir::pdll::ast::Type, From>>>
341
+ : NullableValueCastFailed<To>,
342
+ DefaultDoCastIfPossible<To, From, CastInfo<To, From>> {
343
+ static inline bool isPossible (mlir::pdll::ast::Type ty) {
344
+ // / Return a constant true instead of a dynamic true when casting to self or
345
+ // / up the hierarchy.
346
+ if constexpr (std::is_base_of_v<To, From>) {
347
+ return true ;
348
+ } else {
349
+ return To::classof (ty);
350
+ };
351
+ }
352
+ static inline To doCast (mlir::pdll::ast::Type ty) { return To (ty.getImpl ()); }
353
+ };
326
354
} // namespace llvm
327
355
328
356
#endif // MLIR_TOOLS_PDLL_AST_TYPES_H_
0 commit comments