aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-04-22 13:34:35 +0200
committerMartin Odersky <odersky@gmail.com>2015-04-22 17:19:35 +0200
commit3a158c0a047d2842c0604faf75251c0828408bc9 (patch)
treede0a4aef01c6722f9ed648d686c1b27fafd57ecb /src/dotty/tools
parent7e60221120015be2607947f2de55ca4984db7077 (diff)
downloaddotty-3a158c0a047d2842c0604faf75251c0828408bc9.tar.gz
dotty-3a158c0a047d2842c0604faf75251c0828408bc9.tar.bz2
dotty-3a158c0a047d2842c0604faf75251c0828408bc9.zip
Roll SyntheticMethods into PostTyper
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/dotc/Compiler.scala7
-rw-r--r--src/dotty/tools/dotc/transform/PostTyper.scala14
-rw-r--r--src/dotty/tools/dotc/transform/SyntheticMethods.scala28
3 files changed, 26 insertions, 23 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala
index 73040ca9c..e1146330f 100644
--- a/src/dotty/tools/dotc/Compiler.scala
+++ b/src/dotty/tools/dotc/Compiler.scala
@@ -6,7 +6,7 @@ import Contexts._
import Periods._
import Symbols._
import Scopes._
-import typer.{FrontEnd, Typer, Mode, ImportInfo, RefChecks, InstChecks}
+import typer.{FrontEnd, Typer, Mode, ImportInfo, RefChecks}
import reporting.ConsoleReporter
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.transform._
@@ -39,9 +39,8 @@ class Compiler {
List(
List(new FrontEnd),
List(new PostTyper),
- List(new FirstTransform,
- new SyntheticMethods),
- List(new Pickler), // Pickler needs to come last in a group since it should not pickle trees generated later
+ List(new FirstTransform),
+ List(new Pickler),
List(new RefChecks,
new ElimRepeated,
new NormalizeFlags,
diff --git a/src/dotty/tools/dotc/transform/PostTyper.scala b/src/dotty/tools/dotc/transform/PostTyper.scala
index 98c110e11..1b42a2501 100644
--- a/src/dotty/tools/dotc/transform/PostTyper.scala
+++ b/src/dotty/tools/dotc/transform/PostTyper.scala
@@ -23,7 +23,9 @@ import Symbols._, TypeUtils._
* field (corresponding = super class field is initialized with subclass field)
* (@see ForwardParamAccessors)
*
- * (3) Check that `New` nodes can be instantiated, and that annotations are valid
+ * (3) Add synthetic methods (@see SyntheticMethods)
+ *
+ * (4) Check that `New` nodes can be instantiated, and that annotations are valid
*
* The reason for making this a macro transform is that some functions (in particular
* super and protected accessors and instantiation checks) are naturally top-down and
@@ -46,7 +48,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
val superAcc = new SuperAccessors(thisTransformer)
val paramFwd = new ParamForwarding(thisTransformer)
-
+ val synthMth = new SyntheticMethods(thisTransformer)
+
/** Check that `tp` refers to a nonAbstract class
* and that the instance conforms to the self type of the created class.
*/
@@ -99,9 +102,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
val saved = parentNews
parentNews ++= impl.parents.flatMap(newPart)
try
- paramFwd.forwardParamAccessors(
- superAcc.wrapTemplate(impl)(
- super.transform(_).asInstanceOf[Template]))
+ synthMth.addSyntheticMethods(
+ paramFwd.forwardParamAccessors(
+ superAcc.wrapTemplate(impl)(
+ super.transform(_).asInstanceOf[Template])))
finally parentNews = saved
case tree @ TypeApply(sel: Select, args) =>
val args1 = transform(args)
diff --git a/src/dotty/tools/dotc/transform/SyntheticMethods.scala b/src/dotty/tools/dotc/transform/SyntheticMethods.scala
index 4726105c6..222b64575 100644
--- a/src/dotty/tools/dotc/transform/SyntheticMethods.scala
+++ b/src/dotty/tools/dotc/transform/SyntheticMethods.scala
@@ -31,19 +31,20 @@ import scala.language.postfixOps
* def equals(other: Any): Boolean
* def hashCode(): Int
*/
-class SyntheticMethods extends MiniPhaseTransform with IdentityDenotTransformer { thisTransformer =>
+class SyntheticMethods(thisTransformer: DenotTransformer) {
import ast.tpd._
- override def phaseName = "synthetics"
-
- private var valueSymbols: List[Symbol] = _
- private var caseSymbols: List[Symbol] = _
-
- override def prepareForUnit(tree: Tree)(implicit ctx: Context) = {
- valueSymbols = List(defn.Any_hashCode, defn.Any_equals)
- caseSymbols = valueSymbols ++ List(defn.Any_toString, defn.Product_canEqual, defn.Product_productArity)
- this
- }
+ private var myValueSymbols: List[Symbol] = Nil
+ private var myCaseSymbols: List[Symbol] = Nil
+
+ private def initSymbols(implicit ctx: Context) =
+ if (myValueSymbols.isEmpty) {
+ myValueSymbols = List(defn.Any_hashCode, defn.Any_equals)
+ myCaseSymbols = myValueSymbols ++ List(defn.Any_toString, defn.Product_canEqual, defn.Product_productArity)
+ }
+
+ def valueSymbols(implicit ctx: Context) = { initSymbols; myValueSymbols }
+ def caseSymbols(implicit ctx: Context) = { initSymbols; myCaseSymbols }
/** The synthetic methods of the case or value class `clazz`.
*/
@@ -185,10 +186,9 @@ class SyntheticMethods extends MiniPhaseTransform with IdentityDenotTransformer
symbolsToSynthesize flatMap syntheticDefIfMissing
}
- override def transformTemplate(impl: Template)(implicit ctx: Context, info: TransformerInfo) =
+ def addSyntheticMethods(impl: Template)(implicit ctx: Context) =
if (ctx.owner.is(Case) || isDerivedValueClass(ctx.owner))
- cpy.Template(impl)(
- body = impl.body ++ syntheticMethods(ctx.owner.asClass))
+ cpy.Template(impl)(body = impl.body ++ syntheticMethods(ctx.owner.asClass))
else
impl
}