diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-09-09 15:12:36 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-09-17 18:07:15 +0200 |
commit | 0ceaff7add2da68f69727bc7ee19492f7d84183c (patch) | |
tree | 15d6b217c721ece401ef8906bf20c71990d139c7 /src/dotty/tools/dotc/ast/tpd.scala | |
parent | d78c9d360182d87ba78d55fa255859cc89e2d95d (diff) | |
download | dotty-0ceaff7add2da68f69727bc7ee19492f7d84183c.tar.gz dotty-0ceaff7add2da68f69727bc7ee19492f7d84183c.tar.bz2 dotty-0ceaff7add2da68f69727bc7ee19492f7d84183c.zip |
initValue helper method
Diffstat (limited to 'src/dotty/tools/dotc/ast/tpd.scala')
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 9a8ef16eb..7cb697c46 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -345,6 +345,20 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { Thicket(valdef, clsdef) } + def initValue(tpe: Types.Type)(implicit ctx: Context) = { + val tpw = tpe.widen + + if (tpw =:= defn.IntType) Literal(Constant(0)) + else if (tpw =:= defn.LongType) Literal(Constant(0L)) + else if (tpw =:= defn.BooleanType) Literal(Constant(false)) + else if (tpw =:= defn.CharType) Literal(Constant('\u0000')) + else if (tpw =:= defn.FloatType) Literal(Constant(0f)) + else if (tpw =:= defn.DoubleType) Literal(Constant(0d)) + else if (tpw =:= defn.ByteType) Literal(Constant(0.toByte)) + else if (tpw =:= defn.ShortType) Literal(Constant(0.toShort)) + else Literal(Constant(null)).select(defn.Any_asInstanceOf).appliedToType(tpe) + } + private class FindLocalDummyAccumulator(cls: ClassSymbol)(implicit ctx: Context) extends TreeAccumulator[Symbol] { def apply(sym: Symbol, tree: Tree) = if (sym.exists) sym @@ -618,7 +632,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { } } - def runtimeCall(name: TermName, args: List[Tree])(implicit ctx: Context): Tree = ??? + def runtimeCall(name: TermName, args: List[Tree])(implicit ctx: Context): Tree = { + Ident(defn.ScalaRuntimeModule.requiredMethod(name).termRef).appliedToArgs(args) + } // ensure that constructors are fully applied? // ensure that normal methods are fully applied? |