diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-12-12 15:10:37 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-12-16 13:15:04 +0100 |
commit | 92dceb1694a4160e6e29ff8eb0b09ced96e4fa46 (patch) | |
tree | fd84e60e170ad1af04a6a72d30a5d369f37d7bc8 /src/dotty/tools/backend/jvm | |
parent | 81d56b0b2814faf70110e936852f53b43a7e56d3 (diff) | |
download | dotty-92dceb1694a4160e6e29ff8eb0b09ced96e4fa46.tar.gz dotty-92dceb1694a4160e6e29ff8eb0b09ced96e4fa46.tar.bz2 dotty-92dceb1694a4160e6e29ff8eb0b09ced96e4fa46.zip |
Handle Array.clone
Diffstat (limited to 'src/dotty/tools/backend/jvm')
-rw-r--r-- | src/dotty/tools/backend/jvm/DottyBackendInterface.scala | 12 | ||||
-rwxr-xr-x | src/dotty/tools/backend/jvm/scalaPrimitives.scala | 17 |
2 files changed, 20 insertions, 9 deletions
diff --git a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 575599034..672e00a5c 100644 --- a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -121,7 +121,11 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{ val LongClass: Symbol = defn.LongClass val FloatClass: Symbol = defn.FloatClass val DoubleClass: Symbol = defn.DoubleClass - val Array_clone: Symbol = defn.Array_clone + def isArrayClone(tree: Tree) = tree match { + case Select(qual, StdNames.nme.clone_) if qual.tpe.widen.isInstanceOf[JavaArrayType] => true + case _ => false + } + val hashMethodSym: Symbol = NoSymbol // used to dispatch ## on primitives to ScalaRuntime.hash. Should be implemented by a miniphase val externalEqualsNumNum: Symbol = ctx.requiredMethod(BoxesRunTimeClass, nme.equalsNumNum) lazy val externalEqualsNumChar: Symbol = ??? // ctx.requiredMethod(BoxesRunTimeClass, nme.equalsNumChar) // this method is private @@ -152,7 +156,7 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{ def getPrimitive(sym: Symbol): Int = primitives.getPrimitive(sym) - def isPrimitive(sym: Symbol): Boolean = primitives.isPrimitive(sym) + def isPrimitive(fun: Tree): Boolean = primitives.isPrimitive(fun) } implicit val TypeDefTag: ClassTag[TypeDef] = ClassTag[TypeDef](classOf[TypeDef]) implicit val ApplyTag: ClassTag[Apply] = ClassTag[Apply](classOf[Apply]) @@ -434,7 +438,9 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{ isPrivate //|| (sym.isPrimaryConstructor && sym.owner.isTopLevelModuleClass) def isFinal: Boolean = sym is Flags.Final - def isStaticMember: Boolean = (sym is Flags.JavaStatic) || (owner is Flags.ImplClass) + def isStaticMember: Boolean = (sym ne NoSymbol) && ((sym is Flags.JavaStatic) || (owner is Flags.ImplClass)) + // guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone + def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass) def isBridge: Boolean = sym is Flags.Bridge def isArtifact: Boolean = sym is Flags.Artifact diff --git a/src/dotty/tools/backend/jvm/scalaPrimitives.scala b/src/dotty/tools/backend/jvm/scalaPrimitives.scala index feb74faf5..857a92d21 100755 --- a/src/dotty/tools/backend/jvm/scalaPrimitives.scala +++ b/src/dotty/tools/backend/jvm/scalaPrimitives.scala @@ -7,9 +7,10 @@ package dotty.tools.dotc package backend.jvm import dotty.tools.backend.jvm.GenBCodePipeline -import dotty.tools.dotc.ast.Trees.{Select, Apply} -import dotty.tools.dotc.ast.tpd +import dotty.tools.dotc.ast.Trees.Select +import dotty.tools.dotc.ast.tpd._ import dotty.tools.dotc.core.Names.TermName +import dotty.tools.dotc.core.StdNames import dotty.tools.dotc.core.StdNames._ import dotty.tools.dotc.core.Types.{JavaArrayType, ErrorType, Type} @@ -42,7 +43,6 @@ class DottyPrimitives(ctx: Context) { /** Return the code for the given symbol. */ def getPrimitive(sym: Symbol): Int = { - assert(isPrimitive(sym), "Unknown primitive " + sym) primitives(sym) } @@ -55,7 +55,7 @@ class DottyPrimitives(ctx: Context) { * @param tpe The type of the receiver object. It is used only for array * operations */ - def getPrimitive(app: tpd.Apply, tpe: Type)(implicit ctx: Context): Int = { + def getPrimitive(app: Apply, tpe: Type)(implicit ctx: Context): Int = { val fun = app.fun.symbol val defn = ctx.definitions val code = app.fun match { @@ -404,8 +404,13 @@ class DottyPrimitives(ctx: Context) { primitives.toMap } - def isPrimitive(sym: Symbol): Boolean = { - (primitives contains sym) || sym == NoSymbol // the only trees that do not have a symbol assigned are array.{update,select,length} + def isPrimitive(fun: Tree): Boolean = { + (primitives contains fun.symbol(ctx)) || + (fun.symbol(ctx) == NoSymbol // the only trees that do not have a symbol assigned are array.{update,select,length,clone}} + && (fun match { + case Select(_, StdNames.nme.clone_) => false // but array.clone is NOT a primitive op. + case _ => true + })) } } |