blob: 77909d9157a7cb25430f8fa4974eb518b0dfdd2a (
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
|
package scala.reflect
package internal
import Flags._
trait CapturedVariables { self: SymbolTable =>
import definitions._
/** Mark a variable as captured; i.e. force boxing in a *Ref type.
*/
def captureVariable(vble: Symbol): Unit = vble setFlag CAPTURED
/** Mark given identifier as a reference to a captured variable itself
* suppressing dereferencing with the `elem` field.
*/
def referenceCapturedVariable(vble: Symbol): Tree = ReferenceToBoxed(Ident(vble))
/** Convert type of a captured variable to *Ref type.
*/
def capturedVariableType(vble: Symbol): Type =
capturedVariableType(vble, NoType, false)
/** Convert type of a captured variable to *Ref type.
*/
def capturedVariableType(vble: Symbol, tpe: Type = NoType, erasedTypes: Boolean = false): Type = {
val tpe1 = if (tpe == NoType) vble.tpe else tpe
val symClass = tpe1.typeSymbol
def refType(valueRef: Map[Symbol, Symbol], objectRefClass: Symbol) =
if (isPrimitiveValueClass(symClass) && symClass != UnitClass) valueRef(symClass).tpe
else if (erasedTypes) objectRefClass.tpe
else appliedType(objectRefClass, tpe)
if (vble.hasAnnotation(VolatileAttr)) refType(volatileRefClass, VolatileObjectRefClass)
else refType(refClass, ObjectRefClass)
}
}
|