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
68
69
70
71
72
73
74
|
package dotty.tools
package dotc
package core
package tasty
import TastyFormat._
import collection.mutable
import TastyBuffer._
import java.util.UUID
import core.Symbols.Symbol
import ast.tpd
class TastyPickler {
private val sections = new mutable.ArrayBuffer[(TastyName.NameRef, TastyBuffer)]
val uuid = UUID.randomUUID()
private val headerBuffer = {
val buf = new TastyBuffer(24)
for (ch <- header) buf.writeByte(ch.toByte)
buf.writeNat(MajorVersion)
buf.writeNat(MinorVersion)
buf.writeUncompressedLong(uuid.getMostSignificantBits)
buf.writeUncompressedLong(uuid.getLeastSignificantBits)
buf
}
val nameBuffer = new NameBuffer
def newSection(name: String, buf: TastyBuffer) =
sections += ((nameBuffer.nameIndex(name), buf))
def assembleParts(): Array[Byte] = {
def lengthWithLength(buf: TastyBuffer) = {
buf.assemble()
buf.length + natSize(buf.length)
}
val totalSize =
headerBuffer.length +
lengthWithLength(nameBuffer) + {
for ((nameRef, buf) <- sections) yield
natSize(nameRef.index) + lengthWithLength(buf)
}.sum
val all = new TastyBuffer(totalSize)
all.writeBytes(headerBuffer.bytes, headerBuffer.length)
all.writeNat(nameBuffer.length)
all.writeBytes(nameBuffer.bytes, nameBuffer.length)
for ((nameRef, buf) <- sections) {
all.writeNat(nameRef.index)
all.writeNat(buf.length)
all.writeBytes(buf.bytes, buf.length)
}
assert(all.length == totalSize && all.bytes.length == totalSize, s"totalSize = $totalSize, all.length = ${all.length}, all.bytes.length = ${all.bytes.length}")
all.bytes
}
/**
* Addresses in TASTY file of trees, stored by pickling.
* Note that trees are checked for reference equality,
* so one can reliably use this function only directly after `pickler`.
* Note that a tree can have several addresses, if it is shared,
* i.e. accessible from different paths. Any such sharing is undone by pickling.
*/
var addrsOfTree: tpd.Tree => List[Addr] = (_ => Nil)
/**
* Addresses in TASTY file of symbols, stored by pickling.
* Note that trees are checked for reference equality,
* so one can reliably use this function only dirrectly after `pickler`
*/
var addrOfSym: Symbol => Option[Addr] = (_ => None)
val treePkl = new TreePickler(this)
}
|