summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
blob: d80a1c4f34833ec24e11cb0e2946904bfc0d4e52 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* NSC -- new Scala compiler
 * Copyright 2005-2011 LAMP/EPFL
 * @author  Paul Phillips
 */

package scala.tools.nsc
package backend

import io.AbstractFile
import util.{ClassPath,JavaClassPath}
import util.ClassPath.{ JavaContext, DefaultJavaContext }
import scala.tools.util.PathResolver

trait JavaPlatform extends Platform {
  import global._
  import definitions._

  type BinaryRepr = AbstractFile

  lazy val classPath  = new PathResolver(settings).result
  def rootLoader = new loaders.PackageLoader(classPath.asInstanceOf[ClassPath[platform.BinaryRepr]])
    // [Martin] Why do we need a cast here?
    // The problem is that we cannot specify at this point that global.platform should be of type JavaPlatform.
    // So we cannot infer that global.platform.BinaryRepr is AbstractFile.
    // Ideally, we should be able to write at the top of the JavaPlatform trait:
    //   val global: Global { val platform: JavaPlatform }
    //   import global._
    // Right now, this does nothing because the concrete definition of platform in Global
    // replaces the tighter abstract definition here. If we had DOT typing rules, the two
    // types would be conjoined and everything would work out. Yet another reason to push for DOT.

  private def depAnalysisPhase =
    if (settings.make.isDefault) Nil
    else List(dependencyAnalysis)

  def platformPhases = List(
    flatten,    // get rid of inner classes
    genJVM      // generate .class files
  ) ++ depAnalysisPhase

  lazy val externalEquals          = getMember(BoxesRunTimeClass, nme.equals_)
  lazy val externalEqualsNumNum    = getMember(BoxesRunTimeClass, "equalsNumNum")
  lazy val externalEqualsNumChar   = getMember(BoxesRunTimeClass, "equalsNumChar")
  lazy val externalEqualsNumObject = getMember(BoxesRunTimeClass, "equalsNumObject")

  /** We could get away with excluding BoxedBooleanClass for the
   *  purpose of equality testing since it need not compare equal
   *  to anything but other booleans, but it should be present in
   *  case this is put to other uses.
   */
  def isMaybeBoxed(sym: Symbol) = {
    (sym == ObjectClass) ||
    (sym == JavaSerializableClass) ||
    (sym == ComparableClass) ||
    (sym isNonBottomSubClass BoxedNumberClass) ||
    (sym isNonBottomSubClass BoxedCharacterClass) ||
    (sym isNonBottomSubClass BoxedBooleanClass)
  }

  def newClassLoader(bin: AbstractFile): loaders.SymbolLoader =
    new loaders.ClassfileLoader(bin)

  def doLoad(cls: ClassPath[BinaryRepr]#ClassRep): Boolean = true

  def needCompile(bin: AbstractFile, src: AbstractFile) =
    src.lastModified >= bin.lastModified
}