1414#![ allow( non_camel_case_types) ]
1515
1616use middle:: def;
17- use middle:: mem_categorization:: Typer ;
1817use middle:: resolve;
1918use middle:: ty;
2019use util:: nodemap:: { NodeMap , NodeSet } ;
@@ -24,27 +23,6 @@ use syntax::codemap::Span;
2423use syntax:: visit:: Visitor ;
2524use syntax:: visit;
2625
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-
4826struct CollectFreevarsVisitor < ' a , ' b : ' a > {
4927 node_id : ast:: NodeId ,
5028 seen : NodeSet ,
@@ -60,30 +38,22 @@ impl<'a, 'b, 'v> Visitor<'v> for CollectFreevarsVisitor<'a, 'b> {
6038 fn visit_expr ( & mut self , expr : & ast:: Expr ) {
6139 match expr. node {
6240 ast:: ExprProc ( ..) => {
63- self . cx . capture_mode_map . insert ( expr. id , CaptureByValue ) ;
41+ self . cx . capture_mode_map . insert ( expr. id , ast :: CaptureByValue ) ;
6442 self . depth += 1 ;
6543 visit:: walk_expr ( self , expr) ;
6644 self . depth -= 1 ;
6745 }
6846 ast:: ExprFnBlock ( _, _, _) => {
6947 // NOTE(stage0): After snapshot, change to:
7048 //
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 ) ;
7751 self . depth += 1 ;
7852 visit:: walk_expr ( self , expr) ;
7953 self . depth -= 1 ;
8054 }
8155 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) ;
8757 self . depth += 1 ;
8858 visit:: walk_expr ( self , expr) ;
8959 self . depth -= 1 ;
@@ -111,7 +81,7 @@ impl<'a, 'b, 'v> Visitor<'v> for CollectFreevarsVisitor<'a, 'b> {
11181 } ,
11282 _ => return
11383 } ;
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 {
11585 def : def,
11686 span : expr. span ,
11787 } ) ;
@@ -124,8 +94,8 @@ impl<'a, 'b, 'v> Visitor<'v> for CollectFreevarsVisitor<'a, 'b> {
12494
12595struct AnnotateFreevarsVisitor < ' a > {
12696 def_map : & ' a resolve:: DefMap ,
127- freevars : freevar_map ,
128- capture_mode_map : CaptureModeMap ,
97+ freevars : ty :: FreevarMap ,
98+ capture_mode_map : ty :: CaptureModeMap ,
12999}
130100
131101impl < ' a , ' v > Visitor < ' v > for AnnotateFreevarsVisitor < ' a > {
@@ -147,7 +117,7 @@ impl<'a, 'v> Visitor<'v> for AnnotateFreevarsVisitor<'a> {
147117// node of interest rather than building up the free variables in
148118// one pass. This could be improved upon if it turns out to matter.
149119pub fn annotate_freevars ( def_map : & resolve:: DefMap , krate : & ast:: Crate )
150- -> ( freevar_map , CaptureModeMap ) {
120+ -> ( ty :: FreevarMap , ty :: CaptureModeMap ) {
151121 let mut visitor = AnnotateFreevarsVisitor {
152122 def_map : def_map,
153123 freevars : NodeMap :: new ( ) ,
@@ -156,15 +126,3 @@ pub fn annotate_freevars(def_map: &resolve::DefMap, krate: &ast::Crate)
156126 visit:: walk_crate ( & mut visitor, krate) ;
157127 ( visitor. freevars , visitor. capture_mode_map )
158128}
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