@@ -64,23 +64,28 @@ class Type {
6464
6565 // / Provide type casting support.
6666 template <typename U>
67+ [[deprecated(" Use mlir::isa<U>() instead" )]]
6768 bool isa () const {
6869 assert (impl && " isa<> used on a null type." );
6970 return U::classof (*this );
7071 }
7172 template <typename U, typename V, typename ... Others>
73+ [[deprecated(" Use mlir::isa<U>() instead" )]]
7274 bool isa () const {
7375 return isa<U>() || isa<V, Others...>();
7476 }
7577 template <typename U>
78+ [[deprecated(" Use mlir::dyn_cast<U>() instead" )]]
7679 U dyn_cast () const {
7780 return isa<U>() ? U (impl) : U (nullptr );
7881 }
7982 template <typename U>
83+ [[deprecated(" Use mlir::dyn_cast_or_null<U>() instead" )]]
8084 U dyn_cast_or_null () const {
8185 return (impl && isa<U>()) ? U (impl) : U (nullptr );
8286 }
8387 template <typename U>
88+ [[deprecated(" Use mlir::cast<U>() instead" )]]
8489 U cast () const {
8590 assert (isa<U>());
8691 return U (impl);
@@ -323,6 +328,29 @@ struct DenseMapInfo<mlir::pdll::ast::Type> {
323328 return lhs == rhs;
324329 }
325330};
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+ };
326354} // namespace llvm
327355
328356#endif // MLIR_TOOLS_PDLL_AST_TYPES_H_
0 commit comments