summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-01-14 20:52:28 -0800
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-01-14 20:52:28 -0800
commit4bcd19f6be51d7fb26b0930c8a3354b9222143ff (patch)
tree6ba0d0ef21b56fdb6a4e800c01f17d91f6972006 /src/libsyntax/ext
parent3ea3136e84659773fea9e6f89cb7ddf76cee2324 (diff)
downloadrust-4bcd19f6be51d7fb26b0930c8a3354b9222143ff.tar.gz
rust-4bcd19f6be51d7fb26b0930c8a3354b9222143ff.zip
Convert ast::{pat,field_pat,local_,arm} into structs
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/auto_encode.rs72
-rw-r--r--src/libsyntax/ext/build.rs31
-rw-r--r--src/libsyntax/ext/deriving.rs46
-rw-r--r--src/libsyntax/ext/pipes/ast_builder.rs14
4 files changed, 89 insertions, 74 deletions
diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs
index cd2cafb3699..fcb11f42647 100644
--- a/src/libsyntax/ext/auto_encode.rs
+++ b/src/libsyntax/ext/auto_encode.rs
@@ -317,11 +317,14 @@ priv impl ext_ctxt {
     }
 
     fn binder_pat(span: span, nm: ast::ident) -> @ast::pat {
-        @{id: self.next_id(),
-          node: ast::pat_ident(ast::bind_by_ref(ast::m_imm),
-                               self.path(span, ~[nm]),
-                               None),
-          span: span}
+        @ast::pat {
+            id: self.next_id(),
+            node: ast::pat_ident(
+                ast::bind_by_ref(ast::m_imm),
+                self.path(span, ~[nm]),
+                None),
+            span: span,
+        }
     }
 
     fn stmt(expr: @ast::expr) -> @ast::stmt {
@@ -579,12 +582,14 @@ fn mk_ser_method(
     let ser_inputs = ~[{
         mode: ast::infer(cx.next_id()),
         ty: ty_s,
-        pat: @{id: cx.next_id(),
-               node: ast::pat_ident(
-                    ast::bind_by_value,
-                    ast_util::ident_to_path(span, cx.ident_of(~"__s")),
-                    None),
-               span: span},
+        pat: @ast::pat {
+            id: cx.next_id(),
+            node: ast::pat_ident(
+                ast::bind_by_value,
+                ast_util::ident_to_path(span, cx.ident_of(~"__s")),
+                None),
+            span: span,
+        },
         id: cx.next_id(),
     }];
 
@@ -640,12 +645,14 @@ fn mk_deser_method(
     let deser_inputs = ~[{
         mode: ast::infer(cx.next_id()),
         ty: ty_d,
-        pat: @{id: cx.next_id(),
-               node: ast::pat_ident(
-                    ast::bind_by_value,
-                    ast_util::ident_to_path(span, cx.ident_of(~"__d")),
-                    None),
-               span: span},
+        pat: @ast::pat {
+            id: cx.next_id(),
+            node: ast::pat_ident(
+                ast::bind_by_value,
+                ast_util::ident_to_path(span, cx.ident_of(~"__d")),
+                None),
+            span: span,
+        },
         id: cx.next_id(),
     }];
 
@@ -967,7 +974,7 @@ fn ser_variant(
         )
     };
 
-    let pat = @{
+    let pat = @ast::pat {
         id: cx.next_id(),
         node: pat_node,
         span: span,
@@ -1020,7 +1027,7 @@ fn ser_variant(
         ]
     );
 
-    { pats: ~[pat], guard: None, body: cx.expr_blk(body) }
+    ast::arm { pats: ~[pat], guard: None, body: cx.expr_blk(body) }
 }
 
 fn mk_enum_ser_body(
@@ -1132,21 +1139,25 @@ fn mk_enum_deser_body(
                 fail ~"enum variants unimplemented",
         };
 
-        let pat = @{
+        let pat = @ast::pat {
             id: cx.next_id(),
             node: ast::pat_lit(cx.lit_uint(span, v_idx)),
             span: span,
         };
 
-        {
+        ast::arm {
             pats: ~[pat],
             guard: None,
             body: cx.expr_blk(body),
         }
     };
 
-    let impossible_case = {
-        pats: ~[@{ id: cx.next_id(), node: ast::pat_wild, span: span}],
+    let impossible_case = ast::arm {
+        pats: ~[@ast::pat {
+            id: cx.next_id(),
+            node: ast::pat_wild,
+            span: span,
+        }],
         guard: None,
 
         // FIXME(#3198): proper error message
@@ -1167,13 +1178,14 @@ fn mk_enum_deser_body(
                         node: ast::ty_infer,
                         span: span
                     },
-                    pat: @{id: cx.next_id(),
-                           node: ast::pat_ident(
-                                ast::bind_by_value,
-                                ast_util::ident_to_path(span,
-                                                        cx.ident_of(~"i")),
-                                None),
-                           span: span},
+                    pat: @ast::pat {
+                        id: cx.next_id(),
+                        node: ast::pat_ident(
+                            ast::bind_by_value,
+                            ast_util::ident_to_path(span, cx.ident_of(~"i")),
+                            None),
+                        span: span,
+                    },
                     id: cx.next_id(),
                 }],
                 output: @{
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index df40dc1ed29..72c13747bf1 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -181,18 +181,25 @@ fn mk_glob_use(cx: ext_ctxt, sp: span,
 fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
             ident: ast::ident, ex: @ast::expr) -> @ast::stmt {
 
-    let pat : @ast::pat = @{id: cx.next_id(),
-                            node: ast::pat_ident(ast::bind_by_value,
-                                                 mk_raw_path(sp, ~[ident]),
-                                                 None),
-                           span: sp};
+    let pat = @ast::pat {
+        id: cx.next_id(),
+        node: ast::pat_ident(
+            ast::bind_by_value,
+            mk_raw_path(sp, ~[ident]),
+            None),
+        span: sp,
+    };
     let ty : @ast::Ty = @{ id: cx.next_id(), node: ast::ty_infer, span: sp };
-    let local : @ast::local = @ast::spanned { node: { is_mutbl: mutbl,
-                                                      ty: ty,
-                                                      pat: pat,
-                                                      init: Some(ex),
-                                                      id: cx.next_id()},
-                                              span: sp};
+    let local = @ast::spanned {
+        node: ast::local_ {
+            is_mutbl: mutbl,
+            ty: ty,
+            pat: pat,
+            init: Some(ex),
+            id: cx.next_id(),
+        },
+        span: sp,
+    };
     let decl = ast::spanned {node: ast::decl_local(~[local]), span: sp};
     @ast::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp }
 }
@@ -243,7 +250,7 @@ fn mk_managed(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
     mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e))
 }
 fn mk_pat(cx: ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat {
-    @{ id: cx.next_id(), node: move pat, span: span }
+    @ast::pat { id: cx.next_id(), node: pat, span: span }
 }
 fn mk_pat_ident(cx: ext_ctxt, span: span, ident: ast::ident) -> @ast::pat {
     let path = mk_raw_path(span, ~[ ident ]);
diff --git a/src/libsyntax/ext/deriving.rs b/src/libsyntax/ext/deriving.rs
index 5b98868cd04..2148ad0cdb6 100644
--- a/src/libsyntax/ext/deriving.rs
+++ b/src/libsyntax/ext/deriving.rs
@@ -374,22 +374,17 @@ fn create_enum_variant_pattern(cx: ext_ctxt,
                                              prefix,
                                              struct_def.fields.len());
 
-            let field_pats = dvec::DVec();
-            for struct_def.fields.eachi |i, struct_field| {
+            let field_pats = do struct_def.fields.mapi |i, struct_field| {
                 let ident = match struct_field.node.kind {
                     named_field(ident, _, _) => ident,
                     unnamed_field => {
                         cx.span_bug(span, ~"unexpected unnamed field");
                     }
                 };
-                field_pats.push({ ident: ident, pat: subpats[i] });
-            }
-            let field_pats = dvec::unwrap(move field_pats);
+                ast::field_pat { ident: ident, pat: subpats[i] }
+            };
 
-            return build::mk_pat_struct(cx,
-                                        span,
-                                        matching_path,
-                                        move field_pats);
+            build::mk_pat_struct(cx, span, matching_path, field_pats)
         }
         enum_variant_kind(*) => {
             cx.span_unimpl(span, ~"enum variants for `deriving`");
@@ -732,7 +727,7 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
                                                          matching_body_expr);
 
         // Create the matching arm.
-        let matching_arm = {
+        let matching_arm = ast::arm {
             pats: ~[ matching_pat ],
             guard: None,
             body: move matching_body_block
@@ -743,7 +738,7 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
         // variant then there will always be a match.
         if enum_definition.variants.len() > 1 {
             // Create the nonmatching pattern.
-            let nonmatching_pat = @{
+            let nonmatching_pat = @ast::pat {
                 id: cx.next_id(),
                 node: pat_wild,
                 span: span
@@ -757,12 +752,12 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
                                        nonmatching_expr);
 
             // Create the nonmatching arm.
-            let nonmatching_arm = {
+            let nonmatching_arm = ast::arm {
                 pats: ~[ nonmatching_pat ],
                 guard: None,
-                body: move nonmatching_body_block
+                body: nonmatching_body_block,
             };
-            other_arms.push(move nonmatching_arm);
+            other_arms.push(nonmatching_arm);
         }
 
         // Create the self pattern.
@@ -784,10 +779,10 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
                                                             other_match_expr);
 
         // Create the self arm.
-        let self_arm = {
+        let self_arm = ast::arm {
             pats: ~[ self_pat ],
             guard: None,
-            body: move other_match_body_block
+            body: other_match_body_block,
         };
         self_arms.push(move self_arm);
     }
@@ -813,8 +808,7 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt,
                                           enum_definition: &enum_def)
                                        -> @method {
     // Create the arms of the match in the method body.
-    let arms = dvec::DVec();
-    for enum_definition.variants.eachi |i, variant| {
+    let arms = do enum_definition.variants.mapi |i, variant| {
         // Create the matching pattern.
         let pat = create_enum_variant_pattern(cx, span, variant, ~"__self");
 
@@ -850,24 +844,22 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt,
         let match_body_block = build::mk_block_(cx, span, move stmts);
 
         // Create the arm.
-        let arm = {
+        ast::arm {
             pats: ~[ pat ],
             guard: None,
-            body: move match_body_block
-        };
-        arms.push(move arm);
-    }
+            body: match_body_block,
+        }
+    };
 
     // Create the method body.
     let self_ident = cx.ident_of(~"self");
     let self_expr = build::mk_path(cx, span, ~[ self_ident ]);
     let self_expr = build::mk_unary(cx, span, deref, self_expr);
-    let arms = dvec::unwrap(move arms);
-    let self_match_expr = expr_match(self_expr, move arms);
-    let self_match_expr = build::mk_expr(cx, span, move self_match_expr);
+    let self_match_expr = expr_match(self_expr, arms);
+    let self_match_expr = build::mk_expr(cx, span, self_match_expr);
     let self_match_stmt = build::mk_stmt(cx, span, self_match_expr);
 
     // Create the method.
-    return create_iter_bytes_method(cx, span, ~[ self_match_stmt ]);
+    create_iter_bytes_method(cx, span, ~[ self_match_stmt ])
 }
 
diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs
index f5b6ca953b3..29d27e53d68 100644
--- a/src/libsyntax/ext/pipes/ast_builder.rs
+++ b/src/libsyntax/ext/pipes/ast_builder.rs
@@ -181,15 +181,19 @@ impl ext_ctxt: ext_ctxt_ast_builder {
     }
 
     fn arg(name: ident, ty: @ast::Ty) -> ast::arg {
-        {mode: ast::infer(self.next_id()),
-         ty: ty,
-         pat: @{id: self.next_id(),
+        {
+            mode: ast::infer(self.next_id()),
+            ty: ty,
+            pat: @ast::pat {
+                id: self.next_id(),
                 node: ast::pat_ident(
                     ast::bind_by_value,
                     ast_util::ident_to_path(dummy_sp(), name),
                     None),
-                span: dummy_sp()},
-         id: self.next_id()}
+                span: dummy_sp(),
+            },
+            id: self.next_id(),
+        }
     }
 
     fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {