aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Phases.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-02-13 22:34:39 +0100
committerMartin Odersky <odersky@gmail.com>2016-02-17 18:38:51 +0100
commit5f5eca9ee9367c57da8138f2618759dfc86ffb71 (patch)
tree0827622bdaf9327db3662bd09d7c86f3c3f7166e /src/dotty/tools/dotc/core/Phases.scala
parentd1877e1ff89b318d16ad0637bcd923e540080140 (diff)
downloaddotty-5f5eca9ee9367c57da8138f2618759dfc86ffb71.tar.gz
dotty-5f5eca9ee9367c57da8138f2618759dfc86ffb71.tar.bz2
dotty-5f5eca9ee9367c57da8138f2618759dfc86ffb71.zip
Utility method for phase replacement
Allows to replace existing phase by sequence of new phases.
Diffstat (limited to 'src/dotty/tools/dotc/core/Phases.scala')
-rw-r--r--src/dotty/tools/dotc/core/Phases.scala7
1 files changed, 7 insertions, 0 deletions
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 <: <type of receiver>].
* We can get back the old behavior using this decorator. We should also use the same
* trick for standard getClass.