14
14
#![ allow( non_camel_case_types) ]
15
15
16
16
use middle:: def;
17
- use middle:: mem_categorization:: Typer ;
18
17
use middle:: resolve;
19
18
use middle:: ty;
20
19
use util:: nodemap:: { NodeMap , NodeSet } ;
@@ -24,27 +23,6 @@ use syntax::codemap::Span;
24
23
use syntax:: visit:: Visitor ;
25
24
use syntax:: visit;
26
25
27
- #[ deriving( Clone , Decodable , Encodable , Show ) ]
28
- pub enum CaptureMode {
29
- /// Copy/move the value into the environment.
30
- CaptureByValue ,
31
-
32
- /// Access by reference (used for stack closures).
33
- CaptureByRef
34
- }
35
-
36
- // A vector of defs representing the free variables referred to in a function.
37
- // (The def_upvar will already have been stripped).
38
- #[ deriving( Encodable , Decodable ) ]
39
- pub struct freevar_entry {
40
- pub def : def:: Def , //< The variable being accessed free.
41
- pub span : Span //< First span where it is accessed (there can be multiple)
42
- }
43
-
44
- pub type freevar_map = NodeMap < Vec < freevar_entry > > ;
45
-
46
- pub type CaptureModeMap = NodeMap < CaptureMode > ;
47
-
48
26
struct CollectFreevarsVisitor < ' a , ' b : ' a > {
49
27
node_id : ast:: NodeId ,
50
28
seen : NodeSet ,
@@ -60,30 +38,22 @@ impl<'a, 'b, 'v> Visitor<'v> for CollectFreevarsVisitor<'a, 'b> {
60
38
fn visit_expr ( & mut self , expr : & ast:: Expr ) {
61
39
match expr. node {
62
40
ast:: ExprProc ( ..) => {
63
- self . cx . capture_mode_map . insert ( expr. id , CaptureByValue ) ;
41
+ self . cx . capture_mode_map . insert ( expr. id , ast :: CaptureByValue ) ;
64
42
self . depth += 1 ;
65
43
visit:: walk_expr ( self , expr) ;
66
44
self . depth -= 1 ;
67
45
}
68
46
ast:: ExprFnBlock ( _, _, _) => {
69
47
// NOTE(stage0): After snapshot, change to:
70
48
//
71
- //let capture_mode = match capture_clause {
72
- // ast::CaptureByValue => CaptureByValue,
73
- // ast::CaptureByRef => CaptureByRef,
74
- //};
75
- let capture_mode = CaptureByRef ;
76
- self . cx . capture_mode_map . insert ( expr. id , capture_mode) ;
49
+ //self.cx.capture_mode_map.insert(expr.id, capture_clause);
50
+ self . cx . capture_mode_map . insert ( expr. id , ast:: CaptureByRef ) ;
77
51
self . depth += 1 ;
78
52
visit:: walk_expr ( self , expr) ;
79
53
self . depth -= 1 ;
80
54
}
81
55
ast:: ExprUnboxedFn ( capture_clause, _, _, _) => {
82
- let capture_mode = match capture_clause {
83
- ast:: CaptureByValue => CaptureByValue ,
84
- ast:: CaptureByRef => CaptureByRef ,
85
- } ;
86
- self . cx . capture_mode_map . insert ( expr. id , capture_mode) ;
56
+ self . cx . capture_mode_map . insert ( expr. id , capture_clause) ;
87
57
self . depth += 1 ;
88
58
visit:: walk_expr ( self , expr) ;
89
59
self . depth -= 1 ;
@@ -111,7 +81,7 @@ impl<'a, 'b, 'v> Visitor<'v> for CollectFreevarsVisitor<'a, 'b> {
111
81
} ,
112
82
_ => return
113
83
} ;
114
- self . cx . freevars . find_or_insert ( self . node_id , vec ! [ ] ) . push ( freevar_entry {
84
+ self . cx . freevars . find_or_insert ( self . node_id , vec ! [ ] ) . push ( ty :: Freevar {
115
85
def : def,
116
86
span : expr. span ,
117
87
} ) ;
@@ -124,8 +94,8 @@ impl<'a, 'b, 'v> Visitor<'v> for CollectFreevarsVisitor<'a, 'b> {
124
94
125
95
struct AnnotateFreevarsVisitor < ' a > {
126
96
def_map : & ' a resolve:: DefMap ,
127
- freevars : freevar_map ,
128
- capture_mode_map : CaptureModeMap ,
97
+ freevars : ty :: FreevarMap ,
98
+ capture_mode_map : ty :: CaptureModeMap ,
129
99
}
130
100
131
101
impl < ' a , ' v > Visitor < ' v > for AnnotateFreevarsVisitor < ' a > {
@@ -147,7 +117,7 @@ impl<'a, 'v> Visitor<'v> for AnnotateFreevarsVisitor<'a> {
147
117
// node of interest rather than building up the free variables in
148
118
// one pass. This could be improved upon if it turns out to matter.
149
119
pub fn annotate_freevars ( def_map : & resolve:: DefMap , krate : & ast:: Crate )
150
- -> ( freevar_map , CaptureModeMap ) {
120
+ -> ( ty :: FreevarMap , ty :: CaptureModeMap ) {
151
121
let mut visitor = AnnotateFreevarsVisitor {
152
122
def_map : def_map,
153
123
freevars : NodeMap :: new ( ) ,
@@ -156,15 +126,3 @@ pub fn annotate_freevars(def_map: &resolve::DefMap, krate: &ast::Crate)
156
126
visit:: walk_crate ( & mut visitor, krate) ;
157
127
( visitor. freevars , visitor. capture_mode_map )
158
128
}
159
-
160
- pub fn with_freevars < T > ( tcx : & ty:: ctxt , fid : ast:: NodeId , f: |& [ freevar_entry] | -> T ) -> T {
161
- match tcx. freevars . borrow ( ) . find ( & fid) {
162
- None => fail ! ( "with_freevars: {} has no freevars" , fid) ,
163
- Some ( d) => f ( d. as_slice ( ) )
164
- }
165
- }
166
-
167
- pub fn get_capture_mode < ' tcx , T : Typer < ' tcx > > ( tcx : & T , closure_expr_id : ast:: NodeId )
168
- -> CaptureMode {
169
- tcx. capture_mode ( closure_expr_id)
170
- }
0 commit comments