]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/ext/build.rs
syntax: fix fallout of merging ast::ViewItem into ast::Item.
[rust.git] / src / libsyntax / ext / build.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use abi;
12 use ast::{Ident, Generics, Expr};
13 use ast;
14 use ast_util;
15 use attr;
16 use codemap::{Span, respan, Spanned, DUMMY_SP, Pos};
17 use ext::base::ExtCtxt;
18 use owned_slice::OwnedSlice;
19 use parse::token::special_idents;
20 use parse::token::InternedString;
21 use parse::token;
22 use ptr::P;
23
24
25 // Transitional reexports so qquote can find the paths it is looking for
26 mod syntax {
27     pub use ext;
28     pub use parse;
29 }
30
31 pub trait AstBuilder {
32     // paths
33     fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path;
34     fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path;
35     fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path;
36     fn path_all(&self, sp: Span,
37                 global: bool,
38                 idents: Vec<ast::Ident> ,
39                 lifetimes: Vec<ast::Lifetime>,
40                 types: Vec<P<ast::Ty>>,
41                 bindings: Vec<P<ast::TypeBinding>> )
42         -> ast::Path;
43
44     // types
45     fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy;
46
47     fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty>;
48     fn ty_path(&self, ast::Path) -> P<ast::Ty>;
49     fn ty_sum(&self, ast::Path, OwnedSlice<ast::TyParamBound>) -> P<ast::Ty>;
50     fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>;
51
52     fn ty_rptr(&self, span: Span,
53                ty: P<ast::Ty>,
54                lifetime: Option<ast::Lifetime>,
55                mutbl: ast::Mutability) -> P<ast::Ty>;
56     fn ty_ptr(&self, span: Span,
57               ty: P<ast::Ty>,
58               mutbl: ast::Mutability) -> P<ast::Ty>;
59
60     fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
61     fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
62
63     fn ty_vars(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ;
64     fn ty_vars_global(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ;
65     fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField;
66
67     fn typaram(&self,
68                span: Span,
69                id: ast::Ident,
70                bounds: OwnedSlice<ast::TyParamBound>,
71                default: Option<P<ast::Ty>>) -> ast::TyParam;
72
73     fn trait_ref(&self, path: ast::Path) -> ast::TraitRef;
74     fn poly_trait_ref(&self, path: ast::Path) -> ast::PolyTraitRef;
75     fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
76     fn lifetime(&self, span: Span, ident: ast::Name) -> ast::Lifetime;
77     fn lifetime_def(&self,
78                     span: Span,
79                     name: ast::Name,
80                     bounds: Vec<ast::Lifetime>)
81                     -> ast::LifetimeDef;
82
83     // statements
84     fn stmt_expr(&self, expr: P<ast::Expr>) -> P<ast::Stmt>;
85     fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: P<ast::Expr>) -> P<ast::Stmt>;
86     fn stmt_let_typed(&self,
87                       sp: Span,
88                       mutbl: bool,
89                       ident: ast::Ident,
90                       typ: P<ast::Ty>,
91                       ex: P<ast::Expr>)
92                       -> P<ast::Stmt>;
93     fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt>;
94
95     // blocks
96     fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
97              expr: Option<P<ast::Expr>>) -> P<ast::Block>;
98     fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block>;
99     fn block_all(&self, span: Span,
100                  stmts: Vec<P<ast::Stmt>>,
101                  expr: Option<P<ast::Expr>>) -> P<ast::Block>;
102
103     // expressions
104     fn expr(&self, span: Span, node: ast::Expr_) -> P<ast::Expr>;
105     fn expr_path(&self, path: ast::Path) -> P<ast::Expr>;
106     fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr>;
107
108     fn expr_self(&self, span: Span) -> P<ast::Expr>;
109     fn expr_binary(&self, sp: Span, op: ast::BinOp,
110                    lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr>;
111     fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>;
112     fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>) -> P<ast::Expr>;
113
114     fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>;
115     fn expr_mut_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>;
116     fn expr_field_access(&self, span: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr>;
117     fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>,
118                              idx: uint) -> P<ast::Expr>;
119     fn expr_call(&self, span: Span, expr: P<ast::Expr>, args: Vec<P<ast::Expr>>) -> P<ast::Expr>;
120     fn expr_call_ident(&self, span: Span, id: ast::Ident, args: Vec<P<ast::Expr>>) -> P<ast::Expr>;
121     fn expr_call_global(&self, sp: Span, fn_path: Vec<ast::Ident>,
122                         args: Vec<P<ast::Expr>> ) -> P<ast::Expr>;
123     fn expr_method_call(&self, span: Span,
124                         expr: P<ast::Expr>, ident: ast::Ident,
125                         args: Vec<P<ast::Expr>> ) -> P<ast::Expr>;
126     fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr>;
127     fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>) -> P<ast::Expr>;
128
129     fn field_imm(&self, span: Span, name: Ident, e: P<ast::Expr>) -> ast::Field;
130     fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec<ast::Field>) -> P<ast::Expr>;
131     fn expr_struct_ident(&self, span: Span, id: ast::Ident,
132                          fields: Vec<ast::Field>) -> P<ast::Expr>;
133
134     fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P<ast::Expr>;
135
136     fn expr_uint(&self, span: Span, i: uint) -> P<ast::Expr>;
137     fn expr_int(&self, sp: Span, i: int) -> P<ast::Expr>;
138     fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr>;
139     fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr>;
140
141     fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>;
142     fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr>;
143     fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>;
144     fn expr_str(&self, sp: Span, s: InternedString) -> P<ast::Expr>;
145
146     fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr>;
147     fn expr_none(&self, sp: Span) -> P<ast::Expr>;
148
149     fn expr_break(&self, sp: Span) -> P<ast::Expr>;
150
151     fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>;
152
153     fn expr_fail(&self, span: Span, msg: InternedString) -> P<ast::Expr>;
154     fn expr_unreachable(&self, span: Span) -> P<ast::Expr>;
155
156     fn expr_ok(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Expr>;
157     fn expr_err(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Expr>;
158     fn expr_try(&self, span: Span, head: P<ast::Expr>) -> P<ast::Expr>;
159
160     fn pat(&self, span: Span, pat: ast::Pat_) -> P<ast::Pat>;
161     fn pat_wild(&self, span: Span) -> P<ast::Pat>;
162     fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat>;
163     fn pat_ident(&self, span: Span, ident: ast::Ident) -> P<ast::Pat>;
164
165     fn pat_ident_binding_mode(&self,
166                               span: Span,
167                               ident: ast::Ident,
168                               bm: ast::BindingMode) -> P<ast::Pat>;
169     fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec<P<ast::Pat>> ) -> P<ast::Pat>;
170     fn pat_struct(&self, span: Span,
171                   path: ast::Path, field_pats: Vec<Spanned<ast::FieldPat>> ) -> P<ast::Pat>;
172     fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat>;
173
174     fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat>;
175     fn pat_none(&self, span: Span) -> P<ast::Pat>;
176
177     fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat>;
178     fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat>;
179
180     fn arm(&self, span: Span, pats: Vec<P<ast::Pat>>, expr: P<ast::Expr>) -> ast::Arm;
181     fn arm_unreachable(&self, span: Span) -> ast::Arm;
182
183     fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: Vec<ast::Arm> ) -> P<ast::Expr>;
184     fn expr_if(&self, span: Span,
185                cond: P<ast::Expr>, then: P<ast::Expr>, els: Option<P<ast::Expr>>) -> P<ast::Expr>;
186     fn expr_loop(&self, span: Span, block: P<ast::Block>) -> P<ast::Expr>;
187
188     fn lambda_fn_decl(&self, span: Span,
189                       fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> P<ast::Expr>;
190
191     fn lambda(&self, span: Span, ids: Vec<ast::Ident> , blk: P<ast::Block>) -> P<ast::Expr>;
192     fn lambda0(&self, span: Span, blk: P<ast::Block>) -> P<ast::Expr>;
193     fn lambda1(&self, span: Span, blk: P<ast::Block>, ident: ast::Ident) -> P<ast::Expr>;
194
195     fn lambda_expr(&self, span: Span, ids: Vec<ast::Ident> , blk: P<ast::Expr>) -> P<ast::Expr>;
196     fn lambda_expr_0(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Expr>;
197     fn lambda_expr_1(&self, span: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr>;
198
199     fn lambda_stmts(&self, span: Span, ids: Vec<ast::Ident>,
200                     blk: Vec<P<ast::Stmt>>) -> P<ast::Expr>;
201     fn lambda_stmts_0(&self, span: Span, stmts: Vec<P<ast::Stmt>>) -> P<ast::Expr>;
202     fn lambda_stmts_1(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
203                       ident: ast::Ident) -> P<ast::Expr>;
204
205     // items
206     fn item(&self, span: Span,
207             name: Ident, attrs: Vec<ast::Attribute> , node: ast::Item_) -> P<ast::Item>;
208
209     fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::Arg;
210     // FIXME unused self
211     fn fn_decl(&self, inputs: Vec<ast::Arg> , output: P<ast::Ty>) -> P<ast::FnDecl>;
212
213     fn item_fn_poly(&self,
214                     span: Span,
215                     name: Ident,
216                     inputs: Vec<ast::Arg> ,
217                     output: P<ast::Ty>,
218                     generics: Generics,
219                     body: P<ast::Block>) -> P<ast::Item>;
220     fn item_fn(&self,
221                span: Span,
222                name: Ident,
223                inputs: Vec<ast::Arg> ,
224                output: P<ast::Ty>,
225                body: P<ast::Block>) -> P<ast::Item>;
226
227     fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>> ) -> ast::Variant;
228     fn item_enum_poly(&self,
229                       span: Span,
230                       name: Ident,
231                       enum_definition: ast::EnumDef,
232                       generics: Generics) -> P<ast::Item>;
233     fn item_enum(&self, span: Span, name: Ident, enum_def: ast::EnumDef) -> P<ast::Item>;
234
235     fn item_struct_poly(&self,
236                         span: Span,
237                         name: Ident,
238                         struct_def: ast::StructDef,
239                         generics: Generics) -> P<ast::Item>;
240     fn item_struct(&self, span: Span, name: Ident, struct_def: ast::StructDef) -> P<ast::Item>;
241
242     fn item_mod(&self, span: Span, inner_span: Span,
243                 name: Ident, attrs: Vec<ast::Attribute>,
244                 items: Vec<P<ast::Item>>) -> P<ast::Item>;
245
246     fn item_static(&self,
247                    span: Span,
248                    name: Ident,
249                    ty: P<ast::Ty>,
250                    mutbl: ast::Mutability,
251                    expr: P<ast::Expr>)
252                    -> P<ast::Item>;
253
254     fn item_const(&self,
255                    span: Span,
256                    name: Ident,
257                    ty: P<ast::Ty>,
258                    expr: P<ast::Expr>)
259                    -> P<ast::Item>;
260
261     fn item_ty_poly(&self,
262                     span: Span,
263                     name: Ident,
264                     ty: P<ast::Ty>,
265                     generics: Generics) -> P<ast::Item>;
266     fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> P<ast::Item>;
267
268     fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute;
269
270     fn meta_word(&self, sp: Span, w: InternedString) -> P<ast::MetaItem>;
271     fn meta_list(&self,
272                  sp: Span,
273                  name: InternedString,
274                  mis: Vec<P<ast::MetaItem>> )
275                  -> P<ast::MetaItem>;
276     fn meta_name_value(&self,
277                        sp: Span,
278                        name: InternedString,
279                        value: ast::Lit_)
280                        -> P<ast::MetaItem>;
281
282     fn item_use(&self, sp: Span,
283                 vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item>;
284     fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item>;
285     fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
286                         ident: ast::Ident, path: ast::Path) -> P<ast::Item>;
287     fn item_use_list(&self, sp: Span, vis: ast::Visibility,
288                      path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item>;
289     fn item_use_glob(&self, sp: Span,
290                      vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item>;
291 }
292
293 impl<'a> AstBuilder for ExtCtxt<'a> {
294     fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
295         self.path_all(span, false, strs, Vec::new(), Vec::new(), Vec::new())
296     }
297     fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
298         self.path(span, vec!(id))
299     }
300     fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
301         self.path_all(span, true, strs, Vec::new(), Vec::new(), Vec::new())
302     }
303     fn path_all(&self,
304                 sp: Span,
305                 global: bool,
306                 mut idents: Vec<ast::Ident> ,
307                 lifetimes: Vec<ast::Lifetime>,
308                 types: Vec<P<ast::Ty>>,
309                 bindings: Vec<P<ast::TypeBinding>> )
310                 -> ast::Path {
311         let last_identifier = idents.pop().unwrap();
312         let mut segments: Vec<ast::PathSegment> = idents.into_iter()
313                                                       .map(|ident| {
314             ast::PathSegment {
315                 identifier: ident,
316                 parameters: ast::PathParameters::none(),
317             }
318         }).collect();
319         segments.push(ast::PathSegment {
320             identifier: last_identifier,
321             parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
322                 lifetimes: lifetimes,
323                 types: OwnedSlice::from_vec(types),
324                 bindings: OwnedSlice::from_vec(bindings),
325             })
326         });
327         ast::Path {
328             span: sp,
329             global: global,
330             segments: segments,
331         }
332     }
333
334     fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
335         ast::MutTy {
336             ty: ty,
337             mutbl: mutbl
338         }
339     }
340
341     fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty> {
342         P(ast::Ty {
343             id: ast::DUMMY_NODE_ID,
344             span: span,
345             node: ty
346         })
347     }
348
349     fn ty_path(&self, path: ast::Path) -> P<ast::Ty> {
350         self.ty(path.span, ast::TyPath(path, ast::DUMMY_NODE_ID))
351     }
352
353     fn ty_sum(&self, path: ast::Path, bounds: OwnedSlice<ast::TyParamBound>) -> P<ast::Ty> {
354         self.ty(path.span,
355                 ast::TyObjectSum(self.ty_path(path),
356                                  bounds))
357     }
358
359     // Might need to take bounds as an argument in the future, if you ever want
360     // to generate a bounded existential trait type.
361     fn ty_ident(&self, span: Span, ident: ast::Ident)
362         -> P<ast::Ty> {
363         self.ty_path(self.path_ident(span, ident))
364     }
365
366     fn ty_rptr(&self,
367                span: Span,
368                ty: P<ast::Ty>,
369                lifetime: Option<ast::Lifetime>,
370                mutbl: ast::Mutability)
371         -> P<ast::Ty> {
372         self.ty(span,
373                 ast::TyRptr(lifetime, self.ty_mt(ty, mutbl)))
374     }
375
376     fn ty_ptr(&self,
377               span: Span,
378               ty: P<ast::Ty>,
379               mutbl: ast::Mutability)
380         -> P<ast::Ty> {
381         self.ty(span,
382                 ast::TyPtr(self.ty_mt(ty, mutbl)))
383     }
384
385     fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
386         self.ty_path(
387             self.path_all(DUMMY_SP,
388                           true,
389                           vec!(
390                               self.ident_of("std"),
391                               self.ident_of("option"),
392                               self.ident_of("Option")
393                           ),
394                           Vec::new(),
395                           vec!( ty ),
396                           Vec::new()))
397     }
398
399     fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField {
400         ast::TypeField {
401             ident: name,
402             mt: ast::MutTy { ty: ty, mutbl: ast::MutImmutable },
403             span: span,
404         }
405     }
406
407     fn ty_infer(&self, span: Span) -> P<ast::Ty> {
408         self.ty(span, ast::TyInfer)
409     }
410
411     fn typaram(&self,
412                span: Span,
413                id: ast::Ident,
414                bounds: OwnedSlice<ast::TyParamBound>,
415                default: Option<P<ast::Ty>>) -> ast::TyParam {
416         ast::TyParam {
417             ident: id,
418             id: ast::DUMMY_NODE_ID,
419             bounds: bounds,
420             default: default,
421             span: span
422         }
423     }
424
425     // these are strange, and probably shouldn't be used outside of
426     // pipes. Specifically, the global version possible generates
427     // incorrect code.
428     fn ty_vars(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> {
429         ty_params.iter().map(|p| self.ty_ident(DUMMY_SP, p.ident)).collect()
430     }
431
432     fn ty_vars_global(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> {
433         ty_params
434             .iter()
435             .map(|p| self.ty_path(self.path_global(DUMMY_SP, vec!(p.ident))))
436             .collect()
437     }
438
439     fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
440         ast::TraitRef {
441             path: path,
442             ref_id: ast::DUMMY_NODE_ID,
443         }
444     }
445
446     fn poly_trait_ref(&self, path: ast::Path) -> ast::PolyTraitRef {
447         ast::PolyTraitRef {
448             bound_lifetimes: Vec::new(),
449             trait_ref: self.trait_ref(path)
450         }
451     }
452
453     fn typarambound(&self, path: ast::Path) -> ast::TyParamBound {
454         ast::TraitTyParamBound(self.poly_trait_ref(path), ast::TraitBoundModifier::None)
455     }
456
457     fn lifetime(&self, span: Span, name: ast::Name) -> ast::Lifetime {
458         ast::Lifetime { id: ast::DUMMY_NODE_ID, span: span, name: name }
459     }
460
461     fn lifetime_def(&self,
462                     span: Span,
463                     name: ast::Name,
464                     bounds: Vec<ast::Lifetime>)
465                     -> ast::LifetimeDef {
466         ast::LifetimeDef {
467             lifetime: self.lifetime(span, name),
468             bounds: bounds
469         }
470     }
471
472     fn stmt_expr(&self, expr: P<ast::Expr>) -> P<ast::Stmt> {
473         P(respan(expr.span, ast::StmtSemi(expr, ast::DUMMY_NODE_ID)))
474     }
475
476     fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
477                 ex: P<ast::Expr>) -> P<ast::Stmt> {
478         let pat = if mutbl {
479             self.pat_ident_binding_mode(sp, ident, ast::BindByValue(ast::MutMutable))
480         } else {
481             self.pat_ident(sp, ident)
482         };
483         let local = P(ast::Local {
484             pat: pat,
485             ty: None,
486             init: Some(ex),
487             id: ast::DUMMY_NODE_ID,
488             span: sp,
489             source: ast::LocalLet,
490         });
491         let decl = respan(sp, ast::DeclLocal(local));
492         P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
493     }
494
495     fn stmt_let_typed(&self,
496                       sp: Span,
497                       mutbl: bool,
498                       ident: ast::Ident,
499                       typ: P<ast::Ty>,
500                       ex: P<ast::Expr>)
501                       -> P<ast::Stmt> {
502         let pat = if mutbl {
503             self.pat_ident_binding_mode(sp, ident, ast::BindByValue(ast::MutMutable))
504         } else {
505             self.pat_ident(sp, ident)
506         };
507         let local = P(ast::Local {
508             pat: pat,
509             ty: Some(typ),
510             init: Some(ex),
511             id: ast::DUMMY_NODE_ID,
512             span: sp,
513             source: ast::LocalLet,
514         });
515         let decl = respan(sp, ast::DeclLocal(local));
516         P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
517     }
518
519     fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
520              expr: Option<P<Expr>>) -> P<ast::Block> {
521         self.block_all(span, stmts, expr)
522     }
523
524     fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt> {
525         let decl = respan(sp, ast::DeclItem(item));
526         P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
527     }
528
529     fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {
530         self.block_all(expr.span, Vec::new(), Some(expr))
531     }
532     fn block_all(&self,
533                  span: Span,
534                  stmts: Vec<P<ast::Stmt>>,
535                  expr: Option<P<ast::Expr>>) -> P<ast::Block> {
536             P(ast::Block {
537                stmts: stmts,
538                expr: expr,
539                id: ast::DUMMY_NODE_ID,
540                rules: ast::DefaultBlock,
541                span: span,
542             })
543     }
544
545     fn expr(&self, span: Span, node: ast::Expr_) -> P<ast::Expr> {
546         P(ast::Expr {
547             id: ast::DUMMY_NODE_ID,
548             node: node,
549             span: span,
550         })
551     }
552
553     fn expr_path(&self, path: ast::Path) -> P<ast::Expr> {
554         self.expr(path.span, ast::ExprPath(path))
555     }
556
557     fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr> {
558         self.expr_path(self.path_ident(span, id))
559     }
560     fn expr_self(&self, span: Span) -> P<ast::Expr> {
561         self.expr_ident(span, special_idents::self_)
562     }
563
564     fn expr_binary(&self, sp: Span, op: ast::BinOp,
565                    lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr> {
566         self.expr(sp, ast::ExprBinary(op, lhs, rhs))
567     }
568
569     fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
570         self.expr_unary(sp, ast::UnDeref, e)
571     }
572     fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>) -> P<ast::Expr> {
573         self.expr(sp, ast::ExprUnary(op, e))
574     }
575
576     fn expr_field_access(&self, sp: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr> {
577         let field_name = token::get_ident(ident);
578         let field_span = Span {
579             lo: sp.lo - Pos::from_uint(field_name.get().len()),
580             hi: sp.hi,
581             expn_id: sp.expn_id,
582         };
583
584         let id = Spanned { node: ident, span: field_span };
585         self.expr(sp, ast::ExprField(expr, id))
586     }
587     fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>, idx: uint) -> P<ast::Expr> {
588         let field_span = Span {
589             lo: sp.lo - Pos::from_uint(idx.to_string().len()),
590             hi: sp.hi,
591             expn_id: sp.expn_id,
592         };
593
594         let id = Spanned { node: idx, span: field_span };
595         self.expr(sp, ast::ExprTupField(expr, id))
596     }
597     fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
598         self.expr(sp, ast::ExprAddrOf(ast::MutImmutable, e))
599     }
600     fn expr_mut_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
601         self.expr(sp, ast::ExprAddrOf(ast::MutMutable, e))
602     }
603
604     fn expr_call(&self, span: Span, expr: P<ast::Expr>, args: Vec<P<ast::Expr>>) -> P<ast::Expr> {
605         self.expr(span, ast::ExprCall(expr, args))
606     }
607     fn expr_call_ident(&self, span: Span, id: ast::Ident,
608                        args: Vec<P<ast::Expr>>) -> P<ast::Expr> {
609         self.expr(span, ast::ExprCall(self.expr_ident(span, id), args))
610     }
611     fn expr_call_global(&self, sp: Span, fn_path: Vec<ast::Ident> ,
612                       args: Vec<P<ast::Expr>> ) -> P<ast::Expr> {
613         let pathexpr = self.expr_path(self.path_global(sp, fn_path));
614         self.expr_call(sp, pathexpr, args)
615     }
616     fn expr_method_call(&self, span: Span,
617                         expr: P<ast::Expr>,
618                         ident: ast::Ident,
619                         mut args: Vec<P<ast::Expr>> ) -> P<ast::Expr> {
620         let id = Spanned { node: ident, span: span };
621         args.insert(0, expr);
622         self.expr(span, ast::ExprMethodCall(id, Vec::new(), args))
623     }
624     fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr> {
625         self.expr(b.span, ast::ExprBlock(b))
626     }
627     fn field_imm(&self, span: Span, name: Ident, e: P<ast::Expr>) -> ast::Field {
628         ast::Field { ident: respan(span, name), expr: e, span: span }
629     }
630     fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec<ast::Field>) -> P<ast::Expr> {
631         self.expr(span, ast::ExprStruct(path, fields, None))
632     }
633     fn expr_struct_ident(&self, span: Span,
634                          id: ast::Ident, fields: Vec<ast::Field>) -> P<ast::Expr> {
635         self.expr_struct(span, self.path_ident(span, id), fields)
636     }
637
638     fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P<ast::Expr> {
639         self.expr(sp, ast::ExprLit(P(respan(sp, lit))))
640     }
641     fn expr_uint(&self, span: Span, i: uint) -> P<ast::Expr> {
642         self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs(false))))
643     }
644     fn expr_int(&self, sp: Span, i: int) -> P<ast::Expr> {
645         self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs(false),
646                                                                   ast::Sign::new(i))))
647     }
648     fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
649         self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8)))
650     }
651     fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> {
652         self.expr_lit(sp, ast::LitBool(value))
653     }
654
655     fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
656         self.expr(sp, ast::ExprVec(exprs))
657     }
658     fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> {
659         self.expr_call_global(sp,
660                               vec!(self.ident_of("std"),
661                                    self.ident_of("vec"),
662                                    self.ident_of("Vec"),
663                                    self.ident_of("new")),
664                               Vec::new())
665     }
666     fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
667         self.expr_addr_of(sp, self.expr_vec(sp, exprs))
668     }
669     fn expr_str(&self, sp: Span, s: InternedString) -> P<ast::Expr> {
670         self.expr_lit(sp, ast::LitStr(s, ast::CookedStr))
671     }
672
673     fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>) -> P<ast::Expr> {
674         self.expr(sp, ast::ExprCast(expr, ty))
675     }
676
677
678     fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
679         let some = vec!(
680             self.ident_of("std"),
681             self.ident_of("option"),
682             self.ident_of("Option"),
683             self.ident_of("Some"));
684         self.expr_call_global(sp, some, vec!(expr))
685     }
686
687     fn expr_none(&self, sp: Span) -> P<ast::Expr> {
688         let none = self.path_global(sp, vec!(
689             self.ident_of("std"),
690             self.ident_of("option"),
691             self.ident_of("Option"),
692             self.ident_of("None")));
693         self.expr_path(none)
694     }
695
696
697     fn expr_break(&self, sp: Span) -> P<ast::Expr> {
698         self.expr(sp, ast::ExprBreak(None))
699     }
700
701
702     fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
703         self.expr(sp, ast::ExprTup(exprs))
704     }
705
706     fn expr_fail(&self, span: Span, msg: InternedString) -> P<ast::Expr> {
707         let loc = self.codemap().lookup_char_pos(span.lo);
708         let expr_file = self.expr_str(span,
709                                       token::intern_and_get_ident(&loc.file.name[]));
710         let expr_line = self.expr_uint(span, loc.line);
711         let expr_file_line_tuple = self.expr_tuple(span, vec!(expr_file, expr_line));
712         let expr_file_line_ptr = self.expr_addr_of(span, expr_file_line_tuple);
713         self.expr_call_global(
714             span,
715             vec!(
716                 self.ident_of("std"),
717                 self.ident_of("rt"),
718                 self.ident_of("begin_unwind")),
719             vec!(
720                 self.expr_str(span, msg),
721                 expr_file_line_ptr))
722     }
723
724     fn expr_unreachable(&self, span: Span) -> P<ast::Expr> {
725         self.expr_fail(span,
726                        InternedString::new(
727                            "internal error: entered unreachable code"))
728     }
729
730     fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
731         let ok = vec!(
732             self.ident_of("std"),
733             self.ident_of("result"),
734             self.ident_of("Result"),
735             self.ident_of("Ok"));
736         self.expr_call_global(sp, ok, vec!(expr))
737     }
738
739     fn expr_err(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
740         let err = vec!(
741             self.ident_of("std"),
742             self.ident_of("result"),
743             self.ident_of("Result"),
744             self.ident_of("Err"));
745         self.expr_call_global(sp, err, vec!(expr))
746     }
747
748     fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
749         let ok = self.ident_of("Ok");
750         let ok_path = self.path_ident(sp, ok);
751         let err = self.ident_of("Err");
752         let err_path = self.path_ident(sp, err);
753
754         let binding_variable = self.ident_of("__try_var");
755         let binding_pat = self.pat_ident(sp, binding_variable);
756         let binding_expr = self.expr_ident(sp, binding_variable);
757
758         // Ok(__try_var) pattern
759         let ok_pat = self.pat_enum(sp, ok_path, vec!(binding_pat.clone()));
760
761         // Err(__try_var)  (pattern and expression resp.)
762         let err_pat = self.pat_enum(sp, err_path, vec!(binding_pat));
763         let err_inner_expr = self.expr_call_ident(sp, err, vec!(binding_expr.clone()));
764         // return Err(__try_var)
765         let err_expr = self.expr(sp, ast::ExprRet(Some(err_inner_expr)));
766
767         // Ok(__try_var) => __try_var
768         let ok_arm = self.arm(sp, vec!(ok_pat), binding_expr);
769         // Err(__try_var) => return Err(__try_var)
770         let err_arm = self.arm(sp, vec!(err_pat), err_expr);
771
772         // match head { Ok() => ..., Err() => ... }
773         self.expr_match(sp, head, vec!(ok_arm, err_arm))
774     }
775
776
777     fn pat(&self, span: Span, pat: ast::Pat_) -> P<ast::Pat> {
778         P(ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span: span })
779     }
780     fn pat_wild(&self, span: Span) -> P<ast::Pat> {
781         self.pat(span, ast::PatWild(ast::PatWildSingle))
782     }
783     fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> {
784         self.pat(span, ast::PatLit(expr))
785     }
786     fn pat_ident(&self, span: Span, ident: ast::Ident) -> P<ast::Pat> {
787         self.pat_ident_binding_mode(span, ident, ast::BindByValue(ast::MutImmutable))
788     }
789
790     fn pat_ident_binding_mode(&self,
791                               span: Span,
792                               ident: ast::Ident,
793                               bm: ast::BindingMode) -> P<ast::Pat> {
794         let pat = ast::PatIdent(bm, Spanned{span: span, node: ident}, None);
795         self.pat(span, pat)
796     }
797     fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
798         let pat = ast::PatEnum(path, Some(subpats));
799         self.pat(span, pat)
800     }
801     fn pat_struct(&self, span: Span,
802                   path: ast::Path, field_pats: Vec<Spanned<ast::FieldPat>>) -> P<ast::Pat> {
803         let pat = ast::PatStruct(path, field_pats, false);
804         self.pat(span, pat)
805     }
806     fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
807         self.pat(span, ast::PatTup(pats))
808     }
809
810     fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
811         let some = vec!(
812             self.ident_of("std"),
813             self.ident_of("option"),
814             self.ident_of("Option"),
815             self.ident_of("Some"));
816         let path = self.path_global(span, some);
817         self.pat_enum(span, path, vec!(pat))
818     }
819
820     fn pat_none(&self, span: Span) -> P<ast::Pat> {
821         let some = vec!(
822             self.ident_of("std"),
823             self.ident_of("option"),
824             self.ident_of("Option"),
825             self.ident_of("None"));
826         let path = self.path_global(span, some);
827         self.pat_enum(span, path, vec!())
828     }
829
830     fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
831         let some = vec!(
832             self.ident_of("std"),
833             self.ident_of("result"),
834             self.ident_of("Result"),
835             self.ident_of("Ok"));
836         let path = self.path_global(span, some);
837         self.pat_enum(span, path, vec!(pat))
838     }
839
840     fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
841         let some = vec!(
842             self.ident_of("std"),
843             self.ident_of("result"),
844             self.ident_of("Result"),
845             self.ident_of("Err"));
846         let path = self.path_global(span, some);
847         self.pat_enum(span, path, vec!(pat))
848     }
849
850     fn arm(&self, _span: Span, pats: Vec<P<ast::Pat>>, expr: P<ast::Expr>) -> ast::Arm {
851         ast::Arm {
852             attrs: vec!(),
853             pats: pats,
854             guard: None,
855             body: expr
856         }
857     }
858
859     fn arm_unreachable(&self, span: Span) -> ast::Arm {
860         self.arm(span, vec!(self.pat_wild(span)), self.expr_unreachable(span))
861     }
862
863     fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: Vec<ast::Arm>) -> P<Expr> {
864         self.expr(span, ast::ExprMatch(arg, arms, ast::MatchSource::Normal))
865     }
866
867     fn expr_if(&self, span: Span, cond: P<ast::Expr>,
868                then: P<ast::Expr>, els: Option<P<ast::Expr>>) -> P<ast::Expr> {
869         let els = els.map(|x| self.expr_block(self.block_expr(x)));
870         self.expr(span, ast::ExprIf(cond, self.block_expr(then), els))
871     }
872
873     fn expr_loop(&self, span: Span, block: P<ast::Block>) -> P<ast::Expr> {
874         self.expr(span, ast::ExprLoop(block, None))
875     }
876
877     fn lambda_fn_decl(&self, span: Span,
878                       fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> P<ast::Expr> {
879         self.expr(span, ast::ExprClosure(ast::CaptureByRef, None, fn_decl, blk))
880     }
881     fn lambda(&self, span: Span, ids: Vec<ast::Ident>, blk: P<ast::Block>) -> P<ast::Expr> {
882         let fn_decl = self.fn_decl(
883             ids.iter().map(|id| self.arg(span, *id, self.ty_infer(span))).collect(),
884             self.ty_infer(span));
885
886         self.expr(span, ast::ExprClosure(ast::CaptureByRef, None, fn_decl, blk))
887     }
888     fn lambda0(&self, span: Span, blk: P<ast::Block>) -> P<ast::Expr> {
889         self.lambda(span, Vec::new(), blk)
890     }
891
892     fn lambda1(&self, span: Span, blk: P<ast::Block>, ident: ast::Ident) -> P<ast::Expr> {
893         self.lambda(span, vec!(ident), blk)
894     }
895
896     fn lambda_expr(&self, span: Span, ids: Vec<ast::Ident>,
897                    expr: P<ast::Expr>) -> P<ast::Expr> {
898         self.lambda(span, ids, self.block_expr(expr))
899     }
900     fn lambda_expr_0(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
901         self.lambda0(span, self.block_expr(expr))
902     }
903     fn lambda_expr_1(&self, span: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr> {
904         self.lambda1(span, self.block_expr(expr), ident)
905     }
906
907     fn lambda_stmts(&self,
908                     span: Span,
909                     ids: Vec<ast::Ident>,
910                     stmts: Vec<P<ast::Stmt>>)
911                     -> P<ast::Expr> {
912         self.lambda(span, ids, self.block(span, stmts, None))
913     }
914     fn lambda_stmts_0(&self, span: Span, stmts: Vec<P<ast::Stmt>>) -> P<ast::Expr> {
915         self.lambda0(span, self.block(span, stmts, None))
916     }
917     fn lambda_stmts_1(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
918                       ident: ast::Ident) -> P<ast::Expr> {
919         self.lambda1(span, self.block(span, stmts, None), ident)
920     }
921
922     fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Arg {
923         let arg_pat = self.pat_ident(span, ident);
924         ast::Arg {
925             ty: ty,
926             pat: arg_pat,
927             id: ast::DUMMY_NODE_ID
928         }
929     }
930
931     // FIXME unused self
932     fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>) -> P<ast::FnDecl> {
933         P(ast::FnDecl {
934             inputs: inputs,
935             output: ast::Return(output),
936             variadic: false
937         })
938     }
939
940     fn item(&self, span: Span, name: Ident,
941             attrs: Vec<ast::Attribute>, node: ast::Item_) -> P<ast::Item> {
942         // FIXME: Would be nice if our generated code didn't violate
943         // Rust coding conventions
944         P(ast::Item {
945             ident: name,
946             attrs: attrs,
947             id: ast::DUMMY_NODE_ID,
948             node: node,
949             vis: ast::Inherited,
950             span: span
951         })
952     }
953
954     fn item_fn_poly(&self,
955                     span: Span,
956                     name: Ident,
957                     inputs: Vec<ast::Arg> ,
958                     output: P<ast::Ty>,
959                     generics: Generics,
960                     body: P<ast::Block>) -> P<ast::Item> {
961         self.item(span,
962                   name,
963                   Vec::new(),
964                   ast::ItemFn(self.fn_decl(inputs, output),
965                               ast::Unsafety::Normal,
966                               abi::Rust,
967                               generics,
968                               body))
969     }
970
971     fn item_fn(&self,
972                span: Span,
973                name: Ident,
974                inputs: Vec<ast::Arg> ,
975                output: P<ast::Ty>,
976                body: P<ast::Block>
977               ) -> P<ast::Item> {
978         self.item_fn_poly(
979             span,
980             name,
981             inputs,
982             output,
983             ast_util::empty_generics(),
984             body)
985     }
986
987     fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>> ) -> ast::Variant {
988         let args = tys.into_iter().map(|ty| {
989             ast::VariantArg { ty: ty, id: ast::DUMMY_NODE_ID }
990         }).collect();
991
992         respan(span,
993                ast::Variant_ {
994                    name: name,
995                    attrs: Vec::new(),
996                    kind: ast::TupleVariantKind(args),
997                    id: ast::DUMMY_NODE_ID,
998                    disr_expr: None,
999                    vis: ast::Public
1000                })
1001     }
1002
1003     fn item_enum_poly(&self, span: Span, name: Ident,
1004                       enum_definition: ast::EnumDef,
1005                       generics: Generics) -> P<ast::Item> {
1006         self.item(span, name, Vec::new(), ast::ItemEnum(enum_definition, generics))
1007     }
1008
1009     fn item_enum(&self, span: Span, name: Ident,
1010                  enum_definition: ast::EnumDef) -> P<ast::Item> {
1011         self.item_enum_poly(span, name, enum_definition,
1012                             ast_util::empty_generics())
1013     }
1014
1015     fn item_struct(&self, span: Span, name: Ident,
1016                    struct_def: ast::StructDef) -> P<ast::Item> {
1017         self.item_struct_poly(
1018             span,
1019             name,
1020             struct_def,
1021             ast_util::empty_generics()
1022         )
1023     }
1024
1025     fn item_struct_poly(&self, span: Span, name: Ident,
1026         struct_def: ast::StructDef, generics: Generics) -> P<ast::Item> {
1027         self.item(span, name, Vec::new(), ast::ItemStruct(P(struct_def), generics))
1028     }
1029
1030     fn item_mod(&self, span: Span, inner_span: Span, name: Ident,
1031                 attrs: Vec<ast::Attribute>,
1032                 items: Vec<P<ast::Item>>) -> P<ast::Item> {
1033         self.item(
1034             span,
1035             name,
1036             attrs,
1037             ast::ItemMod(ast::Mod {
1038                 inner: inner_span,
1039                 items: items,
1040             })
1041         )
1042     }
1043
1044     fn item_static(&self,
1045                    span: Span,
1046                    name: Ident,
1047                    ty: P<ast::Ty>,
1048                    mutbl: ast::Mutability,
1049                    expr: P<ast::Expr>)
1050                    -> P<ast::Item> {
1051         self.item(span, name, Vec::new(), ast::ItemStatic(ty, mutbl, expr))
1052     }
1053
1054     fn item_const(&self,
1055                   span: Span,
1056                   name: Ident,
1057                   ty: P<ast::Ty>,
1058                   expr: P<ast::Expr>)
1059                   -> P<ast::Item> {
1060         self.item(span, name, Vec::new(), ast::ItemConst(ty, expr))
1061     }
1062
1063     fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
1064                     generics: Generics) -> P<ast::Item> {
1065         self.item(span, name, Vec::new(), ast::ItemTy(ty, generics))
1066     }
1067
1068     fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> P<ast::Item> {
1069         self.item_ty_poly(span, name, ty, ast_util::empty_generics())
1070     }
1071
1072     fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute {
1073         respan(sp, ast::Attribute_ {
1074             id: attr::mk_attr_id(),
1075             style: ast::AttrOuter,
1076             value: mi,
1077             is_sugared_doc: false,
1078         })
1079     }
1080
1081     fn meta_word(&self, sp: Span, w: InternedString) -> P<ast::MetaItem> {
1082         P(respan(sp, ast::MetaWord(w)))
1083     }
1084     fn meta_list(&self,
1085                  sp: Span,
1086                  name: InternedString,
1087                  mis: Vec<P<ast::MetaItem>> )
1088                  -> P<ast::MetaItem> {
1089         P(respan(sp, ast::MetaList(name, mis)))
1090     }
1091     fn meta_name_value(&self,
1092                        sp: Span,
1093                        name: InternedString,
1094                        value: ast::Lit_)
1095                        -> P<ast::MetaItem> {
1096         P(respan(sp, ast::MetaNameValue(name, respan(sp, value))))
1097     }
1098
1099     fn item_use(&self, sp: Span,
1100                 vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item> {
1101         P(ast::Item {
1102             id: ast::DUMMY_NODE_ID,
1103             ident: special_idents::invalid,
1104             attrs: vec![],
1105             node: ast::ItemUse(vp),
1106             vis: vis,
1107             span: sp
1108         })
1109     }
1110
1111     fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item> {
1112         let last = path.segments.last().unwrap().identifier;
1113         self.item_use_simple_(sp, vis, last, path)
1114     }
1115
1116     fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
1117                         ident: ast::Ident, path: ast::Path) -> P<ast::Item> {
1118         self.item_use(sp, vis,
1119                       P(respan(sp,
1120                                ast::ViewPathSimple(ident,
1121                                                    path))))
1122     }
1123
1124     fn item_use_list(&self, sp: Span, vis: ast::Visibility,
1125                      path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item> {
1126         let imports = imports.iter().map(|id| {
1127             respan(sp, ast::PathListIdent { name: *id, id: ast::DUMMY_NODE_ID })
1128         }).collect();
1129
1130         self.item_use(sp, vis,
1131                       P(respan(sp,
1132                                ast::ViewPathList(self.path(sp, path),
1133                                                  imports))))
1134     }
1135
1136     fn item_use_glob(&self, sp: Span,
1137                      vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item> {
1138         self.item_use(sp, vis,
1139                       P(respan(sp,
1140                                ast::ViewPathGlob(self.path(sp, path)))))
1141     }
1142 }