File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
libsolidity/experimental/ast Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -287,9 +287,34 @@ std::vector<experimental::Type> TypeEnvironmentHelpers::typeVars(Type _type) con
287287 };
288288 typeVarsImpl (_type, typeVarsImpl);
289289 return typeVars;
290-
291290}
292291
292+ experimental::Type TypeEnvironmentHelpers::substitute (
293+ Type const & _type,
294+ Type const & _partToReplace,
295+ Type const & _replacement
296+ ) const
297+ {
298+ using ranges::views::transform;
299+ using ranges::to;
300+
301+ if (env.typeEquals (_type, _partToReplace))
302+ return _replacement;
303+
304+ auto recurse = [&](Type const & _t) { return substitute (_t, _partToReplace, _replacement); };
305+
306+ return visit (util::GenericVisitor{
307+ [&](TypeConstant const & _typeConstant) -> Type {
308+ return TypeConstant{
309+ _typeConstant.constructor ,
310+ _typeConstant.arguments | transform (recurse) | to<std::vector<Type>>,
311+ };
312+ },
313+ [&](auto const & _type) -> Type {
314+ return _type;
315+ },
316+ }, env.resolve (_type));
317+ }
293318
294319std::string TypeSystemHelpers::sortToString (Sort _sort) const
295320{
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ struct TypeEnvironmentHelpers
5555 std::string typeToString (Type const & _type) const ;
5656 std::string canonicalTypeName (Type _type) const ;
5757 std::vector<Type> typeVars (Type _type) const ;
58+
59+ Type substitute (Type const & _type, Type const & _partToReplace, Type const & _replacement) const ;
5860};
5961
6062}
You can’t perform that action at this time.
0 commit comments