@@ -12,6 +12,8 @@ use syntax::fold::Folder;
1212use syntax:: { ast, fold, attr} ;
1313use syntax:: codemap;
1414
15+ use std:: gc:: Gc ;
16+
1517struct Context < ' a > {
1618 in_cfg: |attrs : & [ ast:: Attribute ] |: ' a -> bool ,
1719}
@@ -36,7 +38,7 @@ impl<'a> fold::Folder for Context<'a> {
3638 fn fold_item_underscore ( & mut self , item : & ast:: Item_ ) -> ast:: Item_ {
3739 fold_item_underscore ( self , item)
3840 }
39- fn fold_expr ( & mut self , expr : @ ast:: Expr ) -> @ ast:: Expr {
41+ fn fold_expr ( & mut self , expr : Gc < ast:: Expr > ) -> Gc < ast:: Expr > {
4042 fold_expr ( self , expr)
4143 }
4244}
@@ -60,8 +62,8 @@ fn filter_view_item<'r>(cx: &mut Context, view_item: &'r ast::ViewItem)
6062}
6163
6264fn fold_mod ( cx : & mut Context , m : & ast:: Mod ) -> ast:: Mod {
63- let filtered_items: Vec < & @ ast:: Item > = m. items . iter ( )
64- . filter ( |& a| item_in_cfg ( cx, * a) )
65+ let filtered_items: Vec < & Gc < ast:: Item > > = m. items . iter ( )
66+ . filter ( |a| item_in_cfg ( cx, & * * * a) )
6567 . collect ( ) ;
6668 let flattened_items = filtered_items. move_iter ( )
6769 . flat_map ( |& x| cx. fold_item ( x) . move_iter ( ) )
@@ -76,9 +78,9 @@ fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
7678 }
7779}
7880
79- fn filter_foreign_item ( cx : & mut Context , item : @ ast:: ForeignItem )
80- -> Option < @ ast:: ForeignItem > {
81- if foreign_item_in_cfg ( cx, item) {
81+ fn filter_foreign_item ( cx : & mut Context , item : Gc < ast:: ForeignItem > )
82+ -> Option < Gc < ast:: ForeignItem > > {
83+ if foreign_item_in_cfg ( cx, & * item) {
8284 Some ( item)
8385 } else {
8486 None
@@ -103,7 +105,7 @@ fn fold_foreign_mod(cx: &mut Context, nm: &ast::ForeignMod) -> ast::ForeignMod {
103105fn fold_item_underscore ( cx : & mut Context , item : & ast:: Item_ ) -> ast:: Item_ {
104106 let item = match * item {
105107 ast:: ItemImpl ( ref a, ref b, c, ref methods) => {
106- let methods = methods. iter ( ) . filter ( |m| method_in_cfg ( cx, * * m) )
108+ let methods = methods. iter ( ) . filter ( |m| method_in_cfg ( cx, & * * * m) )
107109 . map ( |x| * x) . collect ( ) ;
108110 ast:: ItemImpl ( ( * a) . clone ( ) , ( * b) . clone ( ) , c, methods)
109111 }
@@ -114,8 +116,8 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
114116 . collect ( ) ;
115117 ast:: ItemTrait ( ( * a) . clone ( ) , b, ( * c) . clone ( ) , methods)
116118 }
117- ast:: ItemStruct ( def, ref generics) => {
118- ast:: ItemStruct ( fold_struct ( cx, def) , generics. clone ( ) )
119+ ast:: ItemStruct ( ref def, ref generics) => {
120+ ast:: ItemStruct ( fold_struct ( cx, & * * def) , generics. clone ( ) )
119121 }
120122 ast:: ItemEnum ( ref def, ref generics) => {
121123 let mut variants = def. variants . iter ( ) . map ( |c| c. clone ( ) ) .
@@ -125,11 +127,11 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
125127 } else {
126128 Some ( match v. node . kind {
127129 ast:: TupleVariantKind ( ..) => v,
128- ast:: StructVariantKind ( def) => {
129- let def = fold_struct ( cx, def) ;
130- @ codemap:: Spanned {
130+ ast:: StructVariantKind ( ref def) => {
131+ let def = fold_struct ( cx, & * * def) ;
132+ box ( GC ) codemap:: Spanned {
131133 node : ast:: Variant_ {
132- kind : ast:: StructVariantKind ( def) ,
134+ kind : ast:: StructVariantKind ( def. clone ( ) ) ,
133135 ..v. node . clone ( )
134136 } ,
135137 ..* v
@@ -148,24 +150,24 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
148150 fold:: noop_fold_item_underscore ( & item, cx)
149151}
150152
151- fn fold_struct ( cx : & mut Context , def : & ast:: StructDef ) -> @ ast:: StructDef {
153+ fn fold_struct ( cx : & mut Context , def : & ast:: StructDef ) -> Gc < ast:: StructDef > {
152154 let mut fields = def. fields . iter ( ) . map ( |c| c. clone ( ) ) . filter ( |m| {
153155 ( cx. in_cfg ) ( m. node . attrs . as_slice ( ) )
154156 } ) ;
155- @ ast:: StructDef {
157+ box ( GC ) ast:: StructDef {
156158 fields : fields. collect ( ) ,
157159 ctor_id : def. ctor_id ,
158160 super_struct : def. super_struct . clone ( ) ,
159161 is_virtual : def. is_virtual ,
160162 }
161163}
162164
163- fn retain_stmt ( cx : & mut Context , stmt : @ ast:: Stmt ) -> bool {
165+ fn retain_stmt ( cx : & mut Context , stmt : Gc < ast:: Stmt > ) -> bool {
164166 match stmt. node {
165167 ast:: StmtDecl ( decl, _) => {
166168 match decl. node {
167- ast:: DeclItem ( item) => {
168- item_in_cfg ( cx, item)
169+ ast:: DeclItem ( ref item) => {
170+ item_in_cfg ( cx, & * * item)
169171 }
170172 _ => true
171173 }
@@ -175,10 +177,10 @@ fn retain_stmt(cx: &mut Context, stmt: @ast::Stmt) -> bool {
175177}
176178
177179fn fold_block ( cx : & mut Context , b : ast:: P < ast:: Block > ) -> ast:: P < ast:: Block > {
178- let resulting_stmts: Vec < & @ ast:: Stmt > =
180+ let resulting_stmts: Vec < & Gc < ast:: Stmt > > =
179181 b. stmts . iter ( ) . filter ( |& a| retain_stmt ( cx, * a) ) . collect ( ) ;
180182 let resulting_stmts = resulting_stmts. move_iter ( )
181- . flat_map ( |& stmt| cx. fold_stmt ( stmt) . move_iter ( ) )
183+ . flat_map ( |stmt| cx. fold_stmt ( & * * stmt) . move_iter ( ) )
182184 . collect ( ) ;
183185 let filtered_view_items = b. view_items . iter ( ) . filter_map ( |a| {
184186 filter_view_item ( cx, a) . map ( |x| cx. fold_view_item ( x) )
@@ -193,14 +195,14 @@ fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
193195 } )
194196}
195197
196- fn fold_expr ( cx : & mut Context , expr : @ ast:: Expr ) -> @ ast:: Expr {
198+ fn fold_expr ( cx : & mut Context , expr : Gc < ast:: Expr > ) -> Gc < ast:: Expr > {
197199 let expr = match expr. node {
198200 ast:: ExprMatch ( ref m, ref arms) => {
199201 let arms = arms. iter ( )
200202 . filter ( |a| ( cx. in_cfg ) ( a. attrs . as_slice ( ) ) )
201203 . map ( |a| a. clone ( ) )
202204 . collect ( ) ;
203- @ ast:: Expr {
205+ box ( GC ) ast:: Expr {
204206 id : expr. id ,
205207 span : expr. span . clone ( ) ,
206208 node : ast:: ExprMatch ( m. clone ( ) , arms) ,
@@ -236,7 +238,7 @@ fn trait_method_in_cfg(cx: &mut Context, meth: &ast::TraitMethod) -> bool {
236238
237239// Determine if an item should be translated in the current crate
238240// configuration based on the item's attributes
239- fn in_cfg ( cfg : & [ @ ast:: MetaItem ] , attrs : & [ ast:: Attribute ] ) -> bool {
241+ fn in_cfg ( cfg : & [ Gc < ast:: MetaItem > ] , attrs : & [ ast:: Attribute ] ) -> bool {
240242 attr:: test_cfg ( cfg, attrs. iter ( ) . map ( |x| * x) )
241243}
242244
0 commit comments