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