From 5f5eca9ee9367c57da8138f2618759dfc86ffb71 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 13 Feb 2016 22:34:39 +0100 Subject: Utility method for phase replacement Allows to replace existing phase by sequence of new phases. --- src/dotty/tools/dotc/core/Phases.scala | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala index 970a9297a..83ac64d53 100644 --- a/src/dotty/tools/dotc/core/Phases.scala +++ b/src/dotty/tools/dotc/core/Phases.scala @@ -347,6 +347,13 @@ object Phases { override def toString = phaseName } + /** Replace all instances of `oldPhaseClass` in `current` phases + * by the result of `newPhases` applied to the old phase. + */ + def replace(oldPhaseClass: Class[_ <: Phase], newPhases: Phase => List[Phase], current: List[List[Phase]]): List[List[Phase]] = + current.map(_.flatMap(phase => + if (oldPhaseClass.isInstance(phase)) newPhases(phase) else phase :: Nil)) + /** Dotty deviation: getClass yields Class[_], instead of [Class <: ]. * We can get back the old behavior using this decorator. We should also use the same * trick for standard getClass. -- cgit v1.2.3