summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend/jvm/BCodeICodeCommon.scala
blob: 50d20921d50c4d15ab14782079fb1ee7dd7d56eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* NSC -- new Scala compiler
 * Copyright 2005-2014 LAMP/EPFL
 * @author  Martin Odersky
 */

package scala.tools.nsc.backend.jvm

import scala.tools.nsc.Global
import PartialFunction._

/**
 * This trait contains code shared between GenBCode and GenICode that depends on types defined in
 * the compiler cake (Global).
 */
final class BCodeICodeCommon[G <: Global](val global: G) {
  import global._

  /** Some useful equality helpers. */
  def isNull(t: Tree) = cond(t) { case Literal(Constant(null)) => true }
  def isLiteral(t: Tree) = cond(t) { case Literal(_) => true }
  def isNonNullExpr(t: Tree) = isLiteral(t) || ((t.symbol ne null) && t.symbol.isModule)

  /** If l or r is constant null, returns the other ; otherwise null */
  def ifOneIsNull(l: Tree, r: Tree) = if (isNull(l)) r else if (isNull(r)) l else null
}