diff options
author | Miguel Garcia <miguelalfredo.garcia@epfl.ch> | 2012-05-08 11:25:18 +0200 |
---|---|---|
committer | Miguel Garcia <miguelalfredo.garcia@epfl.ch> | 2012-05-08 11:25:18 +0200 |
commit | 73fb63f1159de0ed877125a3fc48002726dcb416 (patch) | |
tree | 31155faa19884a4cf6cbe1958c14a77dc3bbaed1 /src | |
parent | aa555debf77eeec3a72a1d700f06347d2e489299 (diff) | |
download | scala-73fb63f1159de0ed877125a3fc48002726dcb416.tar.gz scala-73fb63f1159de0ed877125a3fc48002726dcb416.tar.bz2 scala-73fb63f1159de0ed877125a3fc48002726dcb416.zip |
overriding rather than pattern matching in icode.Opcodes
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala b/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala index ec6c631bd1..169c805a0f 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala @@ -593,48 +593,49 @@ trait Opcodes { self: ICodes => /** This class represents a method invocation style. */ sealed abstract class InvokeStyle { /** Is this a dynamic method call? */ - def isDynamic: Boolean = this match { - case Dynamic => true - case _ => false - } + def isDynamic: Boolean = false /** Is this a static method call? */ - def isStatic: Boolean = this match { - case Static(_) => true - case _ => false - } + def isStatic: Boolean = false - def isSuper: Boolean = this match { - case SuperCall(_) => true - case _ => false - } + def isSuper: Boolean = false /** Is this an instance method call? */ - def hasInstance: Boolean = this match { - case Static(false) => false - case _ => true - } + def hasInstance: Boolean = true /** Returns a string representation of this style. */ - override def toString(): String = this match { - case Dynamic => "dynamic" - case Static(false) => "static-class" - case Static(true) => "static-instance" - case SuperCall(mix) => "super(" + mix + ")" - } + override def toString(): String } - /** Virtual calls */ - case object Dynamic extends InvokeStyle + /** Virtual calls. + * On JVM, translated to either `invokeinterface` or `invokevirtual`. + */ + case object Dynamic extends InvokeStyle { + override def isDynamic = true + override def toString(): String = "dynamic" + } /** - * Special invoke. Static(true) is used for calls to private - * members. + * Special invoke: + * Static(true) is used for calls to private members, ie `invokespecial` on JVM. + * Static(false) is used for calls to class-level instance-less static methods, ie `invokestatic` on JVM. */ - case class Static(onInstance: Boolean) extends InvokeStyle + case class Static(onInstance: Boolean) extends InvokeStyle { + override def isStatic = true + override def hasInstance = onInstance + override def toString(): String = { + if(onInstance) "static-instance" + else "static-class" + } + } - /** Call through super[mix]. */ - case class SuperCall(mix: Name) extends InvokeStyle + /** Call through super[mix]. + * On JVM, translated to `invokespecial`. + */ + case class SuperCall(mix: Name) extends InvokeStyle { + override def isSuper = true + override def toString(): String = { "super(" + mix + ")" } + } // CLR backend |