diff options
-rw-r--r-- | src/dotty/tools/dotc/Compiler.scala | 9 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 41 |
2 files changed, 44 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index 26c01b039..8ed8b6dce 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -9,20 +9,21 @@ import Scopes._ import typer.{FrontEnd, Typer, Mode, ImportInfo} import reporting.ConsoleReporter import dotty.tools.dotc.core.Phases.Phase -import dotty.tools.dotc.transform.{UncurryTreeTransform, LazyValsCreateCompanionObjects, LazyValTranformContext} +import dotty.tools.dotc.transform._ import dotty.tools.dotc.transform.TreeTransforms.{TreeTransform, TreeTransformer} import dotty.tools.dotc.transform.PostTyperTransformers.PostTyperTransformer import dotty.tools.dotc.core.DenotTransformers.DenotTransformer import dotty.tools.dotc.core.Denotations.SingleDenotation -import dotty.tools.dotc.transform.TreeTransforms.Separator class Compiler { def phases: List[List[Phase]] = List( List(new FrontEnd), List(new LazyValsCreateCompanionObjects), //force separataion between lazyVals and LVCreateCO - List(new LazyValTranformContext().transformer, new UncurryTreeTransform) - ) + List(new LazyValTranformContext().transformer, new TypeTestsCasts), + // List(new Erasure), + List(new UncurryTreeTransform) + ) var runId = 1 def nextRunId = { diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 9d4ec21de..173f81894 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -5,7 +5,7 @@ package ast import core._ import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._ import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._ -import CheckTrees._, Denotations._ +import CheckTrees._, Denotations._, Decorators._ import config.Printers._ /** Some creators for typed trees */ @@ -27,6 +27,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def Select(qualifier: Tree, tp: NamedType)(implicit ctx: Context): Select = untpd.Select(qualifier, tp.name).withType(tp) + def Select(qualifier: Tree, sym: Symbol)(implicit ctx: Context): Select = + untpd.Select(qualifier, sym.name).withType(qualifier.tpe select sym) + def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit ctx: Context) = untpd.SelectWithSig(qualifier, name, sig) .withType(TermRef.withSig(qualifier.tpe, name.asTermName, sig)) @@ -46,6 +49,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = ta.assignType(untpd.Apply(fn, args), fn, args) + def ensureApplied(fn: Tree)(implicit ctx: Context): Tree = + if (fn.tpe.widen.isParameterless) fn else Apply(fn, Nil) + def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = ta.assignType(untpd.TypeApply(fn, args), fn, args) @@ -165,6 +171,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def ValDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): ValDef = ta.assignType(untpd.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs), sym) + def SyntheticValDef(name: TermName, rhs: Tree)(implicit ctx: Context): ValDef = + ValDef(ctx.newSymbol(ctx.owner, name, Synthetic, rhs.tpe, coord = rhs.pos), rhs) + def DefDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): DefDef = ta.assignType(DefDef(sym, Function.const(rhs) _), sym) @@ -234,9 +243,16 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { case pre => SelectFromTypeTree(TypeTree(pre), tp) } // no checks necessary - def ref(sym: Symbol)(implicit ctx: Context): tpd.NameTree = + def ref(sym: Symbol)(implicit ctx: Context): NameTree = ref(NamedType(sym.owner.thisType, sym.name, sym.denot)) + def singleton(tp: Type)(implicit ctx: Context): Tree = tp match { + case tp: TermRef => ref(tp) + case ThisType(cls) => This(cls) + case SuperType(qual, _) => singleton(qual) + case ConstantType(value) => Literal(value) + } + // ------ Creating typed equivalents of trees that exist only in untyped form ------- /** new C(args) */ @@ -383,6 +399,27 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { ownerMap andThen (from zip to).toMap) } + // convert a numeric with a toXXX method + def numericConversion(tree: Tree, numericCls: Symbol)(implicit ctx: Context): Tree = { + val mname = ("to" + numericCls.name).toTermName + val conversion = tree.tpe member mname + assert(conversion.symbol.exists, s"$tree => $numericCls") + ensureApplied(Select(tree, conversion.symbol.termRef)) + } + + def evalOnce(tree: Tree)(within: Tree => Tree)(implicit ctx: Context) = { + if (isIdempotentExpr(tree)) within(tree) + else { + val vdef = SyntheticValDef(ctx.freshName("ev$").toTermName, tree) + Block(vdef :: Nil, within(Ident(vdef.namedType))) + } + } + + def runtimeCall(name: TermName, args: List[Tree])(implicit ctx: Context): Tree = ??? + + def mkAnd(tree1: Tree, tree2: Tree)(implicit ctx: Context) = + Apply(Select(tree1, defn.Boolean_and), tree2 :: Nil) + // ensure that constructors are fully applied? // ensure that normal methods are fully applied? |