blob: 5d08b4055762463d2d09aacdc1cc8ae9697b9624 (
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
|
/* NSC -- new Scala compiler
* Copyright 2005-2010 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
package scala.tools.nsc
package backend
package icode
import scala.collection._
/**
* @author Iulian Dragos
*/
trait Repository {
val global: Global
import global._
import icodes._
val loaded: mutable.Map[Symbol, IClass] = new mutable.HashMap
/** Is the given class available as icode? */
def available(sym: Symbol) = classes.contains(sym) || loaded.contains(sym)
/** The icode of the given class, if available */
def icode(sym: Symbol): Option[IClass] =
if (classes.contains(sym)) Some(classes(sym))
else if (loaded.contains(sym)) Some(loaded(sym))
else None
/** The icode of the given class. If not available, it loads
* its bytecode.
*/
def icode(sym: Symbol, force: Boolean): IClass =
if (available(sym)) icode(sym).get
else {
log("loading " + sym)
load(sym)
assert(available(sym))
loaded(sym)
}
/** Load bytecode for given symbol. */
private def load(sym: Symbol) {
val (c1, c2) = icodeReader.readClass(sym)
assert(c1.symbol == sym || c2.symbol == sym)
loaded += (c1.symbol -> c1)
loaded += (c2.symbol -> c2)
}
}
|