2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-05-17 08:51:25 -05:00
|
|
|
use abi::AbiSet;
|
2013-11-30 16:00:39 -06:00
|
|
|
use ast::{P, Ident};
|
2012-12-23 16:41:37 -06:00
|
|
|
use ast;
|
2013-05-17 08:51:25 -05:00
|
|
|
use ast_util;
|
2014-01-01 00:53:22 -06:00
|
|
|
use codemap::{Span, respan, DUMMY_SP};
|
2013-05-17 06:27:17 -05:00
|
|
|
use ext::base::ExtCtxt;
|
2013-05-17 08:51:25 -05:00
|
|
|
use ext::quote::rt::*;
|
2014-01-09 07:05:33 -06:00
|
|
|
use fold::Folder;
|
2013-05-17 08:51:25 -05:00
|
|
|
use opt_vec;
|
2013-02-14 23:50:03 -06:00
|
|
|
use opt_vec::OptVec;
|
2014-01-27 06:18:36 -06:00
|
|
|
use parse::token::special_idents;
|
2014-01-10 16:02:36 -06:00
|
|
|
use parse::token;
|
2013-02-14 23:50:03 -06:00
|
|
|
|
2013-02-21 02:16:31 -06:00
|
|
|
pub struct Field {
|
2013-09-01 19:50:59 -05:00
|
|
|
ident: ast::Ident,
|
2013-09-01 20:45:37 -05:00
|
|
|
ex: @ast::Expr
|
2013-02-21 02:16:31 -06:00
|
|
|
}
|
|
|
|
|
2013-05-15 17:55:57 -05:00
|
|
|
// Transitional reexports so qquote can find the paths it is looking for
|
|
|
|
mod syntax {
|
|
|
|
pub use ext;
|
|
|
|
pub use parse;
|
|
|
|
}
|
|
|
|
|
2013-05-17 08:51:25 -05:00
|
|
|
pub trait AstBuilder {
|
|
|
|
// paths
|
2013-09-01 19:50:59 -05:00
|
|
|
fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path;
|
|
|
|
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path;
|
|
|
|
fn path_global(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn path_all(&self, sp: Span,
|
2013-05-19 00:53:42 -05:00
|
|
|
global: bool,
|
2013-09-01 19:50:59 -05:00
|
|
|
idents: ~[ast::Ident],
|
2013-10-29 05:03:32 -05:00
|
|
|
lifetimes: OptVec<ast::Lifetime>,
|
2013-11-30 16:00:39 -06:00
|
|
|
types: ~[P<ast::Ty>])
|
2013-07-05 05:15:21 -05:00
|
|
|
-> ast::Path;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
// types
|
2014-01-09 07:05:33 -06:00
|
|
|
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty>;
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> P<ast::Ty>;
|
|
|
|
fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn ty_rptr(&self, span: Span,
|
2013-11-30 16:00:39 -06:00
|
|
|
ty: P<ast::Ty>,
|
2013-07-05 07:33:52 -05:00
|
|
|
lifetime: Option<ast::Lifetime>,
|
2013-11-30 16:00:39 -06:00
|
|
|
mutbl: ast::Mutability) -> P<ast::Ty>;
|
|
|
|
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty>;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
|
|
|
|
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
|
|
|
|
fn ty_nil(&self) -> P<ast::Ty>;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>];
|
|
|
|
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>];
|
|
|
|
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField;
|
2013-05-17 08:51:25 -05:00
|
|
|
fn strip_bounds(&self, bounds: &Generics) -> Generics;
|
|
|
|
|
2014-01-30 11:28:02 -06:00
|
|
|
fn typaram(&self,
|
|
|
|
id: ast::Ident,
|
|
|
|
bounds: OptVec<ast::TyParamBound>,
|
|
|
|
default: Option<P<ast::Ty>>) -> ast::TyParam;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn trait_ref(&self, path: ast::Path) -> ast::TraitRef;
|
2013-07-05 05:15:21 -05:00
|
|
|
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
|
2013-09-01 19:50:59 -05:00
|
|
|
fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
// statements
|
2013-09-01 20:45:37 -05:00
|
|
|
fn stmt_expr(&self, expr: @ast::Expr) -> @ast::Stmt;
|
|
|
|
fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: @ast::Expr) -> @ast::Stmt;
|
2013-08-08 13:38:10 -05:00
|
|
|
fn stmt_let_typed(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
sp: Span,
|
2013-08-08 13:38:10 -05:00
|
|
|
mutbl: bool,
|
2013-09-01 19:50:59 -05:00
|
|
|
ident: ast::Ident,
|
2013-11-30 16:00:39 -06:00
|
|
|
typ: P<ast::Ty>,
|
2013-09-01 20:45:37 -05:00
|
|
|
ex: @ast::Expr)
|
|
|
|
-> @ast::Stmt;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
// blocks
|
2013-11-30 16:00:39 -06:00
|
|
|
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> P<ast::Block>;
|
|
|
|
fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block>;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn block_all(&self, span: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
view_items: ~[ast::ViewItem],
|
2013-09-01 20:45:37 -05:00
|
|
|
stmts: ~[@ast::Stmt],
|
2013-11-30 16:00:39 -06:00
|
|
|
expr: Option<@ast::Expr>) -> P<ast::Block>;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
// expressions
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr(&self, span: Span, node: ast::Expr_) -> @ast::Expr;
|
|
|
|
fn expr_path(&self, path: ast::Path) -> @ast::Expr;
|
|
|
|
fn expr_ident(&self, span: Span, id: ast::Ident) -> @ast::Expr;
|
|
|
|
|
|
|
|
fn expr_self(&self, span: Span) -> @ast::Expr;
|
|
|
|
fn expr_binary(&self, sp: Span, op: ast::BinOp,
|
|
|
|
lhs: @ast::Expr, rhs: @ast::Expr) -> @ast::Expr;
|
|
|
|
fn expr_deref(&self, sp: Span, e: @ast::Expr) -> @ast::Expr;
|
|
|
|
fn expr_unary(&self, sp: Span, op: ast::UnOp, e: @ast::Expr) -> @ast::Expr;
|
|
|
|
|
|
|
|
fn expr_managed(&self, sp: Span, e: @ast::Expr) -> @ast::Expr;
|
|
|
|
fn expr_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr;
|
|
|
|
fn expr_mut_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr;
|
|
|
|
fn expr_field_access(&self, span: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr;
|
|
|
|
fn expr_call(&self, span: Span, expr: @ast::Expr, args: ~[@ast::Expr]) -> @ast::Expr;
|
|
|
|
fn expr_call_ident(&self, span: Span, id: ast::Ident, args: ~[@ast::Expr]) -> @ast::Expr;
|
2013-09-01 19:50:59 -05:00
|
|
|
fn expr_call_global(&self, sp: Span, fn_path: ~[ast::Ident],
|
2013-09-01 20:45:37 -05:00
|
|
|
args: ~[@ast::Expr]) -> @ast::Expr;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn expr_method_call(&self, span: Span,
|
2013-09-01 20:45:37 -05:00
|
|
|
expr: @ast::Expr, ident: ast::Ident,
|
|
|
|
args: ~[@ast::Expr]) -> @ast::Expr;
|
2013-11-30 16:00:39 -06:00
|
|
|
fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr;
|
|
|
|
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: P<ast::Ty>) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field;
|
|
|
|
fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr;
|
|
|
|
fn expr_struct_ident(&self, span: Span, id: ast::Ident, fields: ~[ast::Field]) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_uint(&self, span: Span, i: uint) -> @ast::Expr;
|
|
|
|
fn expr_int(&self, sp: Span, i: int) -> @ast::Expr;
|
|
|
|
fn expr_u8(&self, sp: Span, u: u8) -> @ast::Expr;
|
|
|
|
fn expr_bool(&self, sp: Span, value: bool) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_vstore(&self, sp: Span, expr: @ast::Expr, vst: ast::ExprVstore) -> @ast::Expr;
|
|
|
|
fn expr_vec(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr;
|
|
|
|
fn expr_vec_uniq(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr;
|
|
|
|
fn expr_vec_slice(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr;
|
2014-01-10 16:02:36 -06:00
|
|
|
fn expr_str(&self, sp: Span, s: InternedString) -> @ast::Expr;
|
|
|
|
fn expr_str_uniq(&self, sp: Span, s: InternedString) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-16 23:12:18 -05:00
|
|
|
fn expr_some(&self, sp: Span, expr: @ast::Expr) -> @ast::Expr;
|
|
|
|
fn expr_none(&self, sp: Span) -> @ast::Expr;
|
|
|
|
|
2014-01-10 16:02:36 -06:00
|
|
|
fn expr_fail(&self, span: Span, msg: InternedString) -> @ast::Expr;
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_unreachable(&self, span: Span) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn pat(&self, span: Span, pat: ast::Pat_) -> @ast::Pat;
|
|
|
|
fn pat_wild(&self, span: Span) -> @ast::Pat;
|
|
|
|
fn pat_lit(&self, span: Span, expr: @ast::Expr) -> @ast::Pat;
|
|
|
|
fn pat_ident(&self, span: Span, ident: ast::Ident) -> @ast::Pat;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
|
|
|
fn pat_ident_binding_mode(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
ident: ast::Ident,
|
2013-09-01 20:45:37 -05:00
|
|
|
bm: ast::BindingMode) -> @ast::Pat;
|
|
|
|
fn pat_enum(&self, span: Span, path: ast::Path, subpats: ~[@ast::Pat]) -> @ast::Pat;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn pat_struct(&self, span: Span,
|
2013-09-01 20:45:37 -05:00
|
|
|
path: ast::Path, field_pats: ~[ast::FieldPat]) -> @ast::Pat;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn arm(&self, span: Span, pats: ~[@ast::Pat], expr: @ast::Expr) -> ast::Arm;
|
|
|
|
fn arm_unreachable(&self, span: Span) -> ast::Arm;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_match(&self, span: Span, arg: @ast::Expr, arms: ~[ast::Arm]) -> @ast::Expr;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn expr_if(&self, span: Span,
|
2013-09-01 20:45:37 -05:00
|
|
|
cond: @ast::Expr, then: @ast::Expr, els: Option<@ast::Expr>) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn lambda_fn_decl(&self, span: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr;
|
|
|
|
fn lambda0(&self, span: Span, blk: P<ast::Block>) -> @ast::Expr;
|
|
|
|
fn lambda1(&self, span: Span, blk: P<ast::Block>, ident: ast::Ident) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda_expr(&self, span: Span, ids: ~[ast::Ident], blk: @ast::Expr) -> @ast::Expr;
|
|
|
|
fn lambda_expr_0(&self, span: Span, expr: @ast::Expr) -> @ast::Expr;
|
|
|
|
fn lambda_expr_1(&self, span: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda_stmts(&self, span: Span, ids: ~[ast::Ident], blk: ~[@ast::Stmt]) -> @ast::Expr;
|
|
|
|
fn lambda_stmts_0(&self, span: Span, stmts: ~[@ast::Stmt]) -> @ast::Expr;
|
|
|
|
fn lambda_stmts_1(&self, span: Span, stmts: ~[@ast::Stmt], ident: ast::Ident) -> @ast::Expr;
|
2013-05-15 17:55:57 -05:00
|
|
|
|
2013-05-17 08:51:25 -05:00
|
|
|
// items
|
2013-08-31 11:13:04 -05:00
|
|
|
fn item(&self, span: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
name: Ident, attrs: ~[ast::Attribute], node: ast::Item_) -> @ast::Item;
|
2013-05-15 17:55:57 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::Arg;
|
2014-01-26 02:43:42 -06:00
|
|
|
// FIXME unused self
|
2014-01-09 07:05:33 -06:00
|
|
|
fn fn_decl(&self, inputs: ~[ast::Arg], output: P<ast::Ty>) -> P<ast::FnDecl>;
|
2013-05-15 17:55:57 -05:00
|
|
|
|
2013-05-17 08:51:25 -05:00
|
|
|
fn item_fn_poly(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident,
|
2014-01-09 07:05:33 -06:00
|
|
|
inputs: ~[ast::Arg],
|
2013-11-30 16:00:39 -06:00
|
|
|
output: P<ast::Ty>,
|
2013-05-17 08:51:25 -05:00
|
|
|
generics: Generics,
|
2014-01-09 07:05:33 -06:00
|
|
|
body: P<ast::Block>) -> @ast::Item;
|
2013-05-17 08:51:25 -05:00
|
|
|
fn item_fn(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident,
|
2014-01-09 07:05:33 -06:00
|
|
|
inputs: ~[ast::Arg],
|
2013-11-30 16:00:39 -06:00
|
|
|
output: P<ast::Ty>,
|
2014-01-09 07:05:33 -06:00
|
|
|
body: P<ast::Block>) -> @ast::Item;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::Variant;
|
2013-05-17 08:51:25 -05:00
|
|
|
fn item_enum_poly(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident,
|
2014-01-09 07:05:33 -06:00
|
|
|
enum_definition: ast::EnumDef,
|
|
|
|
generics: Generics) -> @ast::Item;
|
|
|
|
fn item_enum(&self, span: Span, name: Ident, enum_def: ast::EnumDef) -> @ast::Item;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
fn item_struct_poly(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident,
|
2014-01-09 07:05:33 -06:00
|
|
|
struct_def: ast::StructDef,
|
|
|
|
generics: Generics) -> @ast::Item;
|
|
|
|
fn item_struct(&self, span: Span, name: Ident, struct_def: ast::StructDef) -> @ast::Item;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn item_mod(&self, span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident, attrs: ~[ast::Attribute],
|
2014-01-09 07:05:33 -06:00
|
|
|
vi: ~[ast::ViewItem], items: ~[@ast::Item]) -> @ast::Item;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
fn item_ty_poly(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident,
|
2013-11-30 16:00:39 -06:00
|
|
|
ty: P<ast::Ty>,
|
2014-01-09 07:05:33 -06:00
|
|
|
generics: Generics) -> @ast::Item;
|
|
|
|
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::Item;
|
2013-05-17 09:19:28 -05:00
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute;
|
2013-05-17 09:19:28 -05:00
|
|
|
|
2014-01-08 12:35:15 -06:00
|
|
|
fn meta_word(&self, sp: Span, w: InternedString) -> @ast::MetaItem;
|
|
|
|
fn meta_list(&self,
|
|
|
|
sp: Span,
|
|
|
|
name: InternedString,
|
|
|
|
mis: ~[@ast::MetaItem])
|
|
|
|
-> @ast::MetaItem;
|
|
|
|
fn meta_name_value(&self,
|
|
|
|
sp: Span,
|
|
|
|
name: InternedString,
|
|
|
|
value: ast::Lit_)
|
|
|
|
-> @ast::MetaItem;
|
2013-05-17 09:19:28 -05:00
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn view_use(&self, sp: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
vis: ast::Visibility, vp: ~[@ast::ViewPath]) -> ast::ViewItem;
|
|
|
|
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
|
|
|
|
path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::ViewItem;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn view_use_glob(&self, sp: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
vis: ast::Visibility, path: ~[ast::Ident]) -> ast::ViewItem;
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
|
2013-12-25 12:10:33 -06:00
|
|
|
impl<'a> AstBuilder for ExtCtxt<'a> {
|
2013-09-01 19:50:59 -05:00
|
|
|
fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
|
2013-10-29 05:03:32 -05:00
|
|
|
self.path_all(span, false, strs, opt_vec::Empty, ~[])
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 19:50:59 -05:00
|
|
|
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.path(span, ~[id])
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-09-01 19:50:59 -05:00
|
|
|
fn path_global(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
|
2013-10-29 05:03:32 -05:00
|
|
|
self.path_all(span, true, strs, opt_vec::Empty, ~[])
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-08-07 11:47:28 -05:00
|
|
|
fn path_all(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
sp: Span,
|
2013-05-19 00:53:42 -05:00
|
|
|
global: bool,
|
2013-09-01 19:50:59 -05:00
|
|
|
mut idents: ~[ast::Ident],
|
2013-10-29 05:03:32 -05:00
|
|
|
lifetimes: OptVec<ast::Lifetime>,
|
2013-11-30 16:00:39 -06:00
|
|
|
types: ~[P<ast::Ty>])
|
2013-08-07 11:47:28 -05:00
|
|
|
-> ast::Path {
|
2013-12-23 09:20:52 -06:00
|
|
|
let last_identifier = idents.pop().unwrap();
|
2013-08-08 13:38:10 -05:00
|
|
|
let mut segments: ~[ast::PathSegment] = idents.move_iter()
|
|
|
|
.map(|ident| {
|
2013-08-07 11:47:28 -05:00
|
|
|
ast::PathSegment {
|
|
|
|
identifier: ident,
|
2013-10-29 05:03:32 -05:00
|
|
|
lifetimes: opt_vec::Empty,
|
2013-08-07 11:47:28 -05:00
|
|
|
types: opt_vec::Empty,
|
|
|
|
}
|
|
|
|
}).collect();
|
|
|
|
segments.push(ast::PathSegment {
|
|
|
|
identifier: last_identifier,
|
2013-10-29 05:03:32 -05:00
|
|
|
lifetimes: lifetimes,
|
2013-08-07 11:47:28 -05:00
|
|
|
types: opt_vec::from(types),
|
|
|
|
});
|
2013-07-05 05:15:21 -05:00
|
|
|
ast::Path {
|
2013-05-19 00:53:42 -05:00
|
|
|
span: sp,
|
|
|
|
global: global,
|
2013-08-07 11:47:28 -05:00
|
|
|
segments: segments,
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
|
|
|
|
ast::MutTy {
|
2013-11-30 16:00:39 -06:00
|
|
|
ty: ty,
|
2013-05-19 00:53:42 -05:00
|
|
|
mutbl: mutbl
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty> {
|
2013-11-30 16:00:39 -06:00
|
|
|
P(ast::Ty {
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2013-05-15 17:55:57 -05:00
|
|
|
span: span,
|
2013-05-19 00:53:42 -05:00
|
|
|
node: ty
|
2013-11-30 16:00:39 -06:00
|
|
|
})
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-07-05 20:38:56 -05:00
|
|
|
fn ty_path(&self, path: ast::Path, bounds: Option<OptVec<ast::TyParamBound>>)
|
2013-11-30 16:00:39 -06:00
|
|
|
-> P<ast::Ty> {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.ty(path.span,
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::TyPath(path, bounds, ast::DUMMY_NODE_ID))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
|
2013-06-17 14:16:30 -05:00
|
|
|
// Might need to take bounds as an argument in the future, if you ever want
|
|
|
|
// to generate a bounded existential trait type.
|
2013-09-01 19:50:59 -05:00
|
|
|
fn ty_ident(&self, span: Span, ident: ast::Ident)
|
2013-11-30 16:00:39 -06:00
|
|
|
-> P<ast::Ty> {
|
2013-07-05 20:38:56 -05:00
|
|
|
self.ty_path(self.path_ident(span, ident), None)
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ty_rptr(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-11-30 16:00:39 -06:00
|
|
|
ty: P<ast::Ty>,
|
2013-07-05 07:33:52 -05:00
|
|
|
lifetime: Option<ast::Lifetime>,
|
2013-09-01 20:45:37 -05:00
|
|
|
mutbl: ast::Mutability)
|
2013-11-30 16:00:39 -06:00
|
|
|
-> P<ast::Ty> {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.ty(span,
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::TyRptr(lifetime, self.ty_mt(ty, mutbl)))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-12-31 14:55:39 -06:00
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> {
|
2014-01-09 07:05:33 -06:00
|
|
|
self.ty(span, ast::TyUniq(ty))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-12-31 14:55:39 -06:00
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
|
2013-05-17 08:51:25 -05:00
|
|
|
self.ty_path(
|
2014-01-01 00:53:22 -06:00
|
|
|
self.path_all(DUMMY_SP,
|
2013-05-19 00:53:42 -05:00
|
|
|
true,
|
|
|
|
~[
|
2013-05-22 13:02:40 -05:00
|
|
|
self.ident_of("std"),
|
2013-05-19 00:53:42 -05:00
|
|
|
self.ident_of("option"),
|
|
|
|
self.ident_of("Option")
|
|
|
|
],
|
2013-10-29 05:03:32 -05:00
|
|
|
opt_vec::Empty,
|
2013-07-05 20:38:56 -05:00
|
|
|
~[ ty ]), None)
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField {
|
2013-07-27 03:25:59 -05:00
|
|
|
ast::TypeField {
|
|
|
|
ident: name,
|
2014-01-09 07:05:33 -06:00
|
|
|
mt: ast::MutTy { ty: ty, mutbl: ast::MutImmutable },
|
2013-07-27 03:25:59 -05:00
|
|
|
span: span,
|
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_infer(&self, span: Span) -> P<ast::Ty> {
|
2014-01-09 07:05:33 -06:00
|
|
|
self.ty(span, ast::TyInfer)
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_nil(&self) -> P<ast::Ty> {
|
|
|
|
P(ast::Ty {
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2014-01-09 07:05:33 -06:00
|
|
|
node: ast::TyNil,
|
2014-01-01 00:53:22 -06:00
|
|
|
span: DUMMY_SP,
|
2013-11-30 16:00:39 -06:00
|
|
|
})
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2014-01-30 11:28:02 -06:00
|
|
|
fn typaram(&self,
|
|
|
|
id: ast::Ident,
|
|
|
|
bounds: OptVec<ast::TyParamBound>,
|
|
|
|
default: Option<P<ast::Ty>>) -> ast::TyParam {
|
|
|
|
ast::TyParam {
|
|
|
|
ident: id,
|
|
|
|
id: ast::DUMMY_NODE_ID,
|
|
|
|
bounds: bounds,
|
|
|
|
default: default
|
|
|
|
}
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// these are strange, and probably shouldn't be used outside of
|
|
|
|
// pipes. Specifically, the global version possible generates
|
|
|
|
// incorrect code.
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>] {
|
2013-05-17 08:51:25 -05:00
|
|
|
opt_vec::take_vec(
|
2014-01-01 00:53:22 -06:00
|
|
|
ty_params.map(|p| self.ty_ident(DUMMY_SP, p.ident)))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>] {
|
2013-05-17 08:51:25 -05:00
|
|
|
opt_vec::take_vec(
|
|
|
|
ty_params.map(|p| self.ty_path(
|
2014-01-01 00:53:22 -06:00
|
|
|
self.path_global(DUMMY_SP, ~[p.ident]), None)))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn strip_bounds(&self, generics: &Generics) -> Generics {
|
2013-11-20 18:23:04 -06:00
|
|
|
let new_params = generics.ty_params.map(|ty_param| {
|
2013-06-27 19:41:35 -05:00
|
|
|
ast::TyParam { bounds: opt_vec::Empty, ..*ty_param }
|
2013-11-20 18:23:04 -06:00
|
|
|
});
|
2013-05-17 08:51:25 -05:00
|
|
|
Generics {
|
|
|
|
ty_params: new_params,
|
2013-07-02 14:47:32 -05:00
|
|
|
.. (*generics).clone()
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
|
|
|
|
ast::TraitRef {
|
2013-05-19 00:53:42 -05:00
|
|
|
path: path,
|
2013-09-06 21:11:55 -05:00
|
|
|
ref_id: ast::DUMMY_NODE_ID
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
}
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-07-05 05:15:21 -05:00
|
|
|
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound {
|
2013-05-19 00:53:42 -05:00
|
|
|
ast::TraitTyParamBound(self.trait_ref(path))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime {
|
2013-09-06 21:11:55 -05:00
|
|
|
ast::Lifetime { id: ast::DUMMY_NODE_ID, span: span, ident: ident }
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn stmt_expr(&self, expr: @ast::Expr) -> @ast::Stmt {
|
2013-09-06 21:11:55 -05:00
|
|
|
@respan(expr.span, ast::StmtSemi(expr, ast::DUMMY_NODE_ID))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: @ast::Expr) -> @ast::Stmt {
|
2013-10-20 07:31:23 -05:00
|
|
|
let pat = if mutbl {
|
|
|
|
self.pat_ident_binding_mode(sp, ident, ast::BindByValue(ast::MutMutable))
|
|
|
|
} else {
|
|
|
|
self.pat_ident(sp, ident)
|
|
|
|
};
|
2013-07-19 00:38:55 -05:00
|
|
|
let local = @ast::Local {
|
|
|
|
ty: self.ty_infer(sp),
|
|
|
|
pat: pat,
|
|
|
|
init: Some(ex),
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2013-07-19 00:38:55 -05:00
|
|
|
span: sp,
|
|
|
|
};
|
2013-09-01 20:45:37 -05:00
|
|
|
let decl = respan(sp, ast::DeclLocal(local));
|
2013-09-06 21:11:55 -05:00
|
|
|
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-08-08 13:38:10 -05:00
|
|
|
fn stmt_let_typed(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
sp: Span,
|
2013-08-08 13:38:10 -05:00
|
|
|
mutbl: bool,
|
2013-09-01 19:50:59 -05:00
|
|
|
ident: ast::Ident,
|
2013-11-30 16:00:39 -06:00
|
|
|
typ: P<ast::Ty>,
|
2013-09-01 20:45:37 -05:00
|
|
|
ex: @ast::Expr)
|
|
|
|
-> @ast::Stmt {
|
2013-10-20 07:31:23 -05:00
|
|
|
let pat = if mutbl {
|
|
|
|
self.pat_ident_binding_mode(sp, ident, ast::BindByValue(ast::MutMutable))
|
|
|
|
} else {
|
|
|
|
self.pat_ident(sp, ident)
|
|
|
|
};
|
2013-08-08 13:38:10 -05:00
|
|
|
let local = @ast::Local {
|
|
|
|
ty: typ,
|
|
|
|
pat: pat,
|
|
|
|
init: Some(ex),
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2013-08-08 13:38:10 -05:00
|
|
|
span: sp,
|
|
|
|
};
|
2013-09-01 20:45:37 -05:00
|
|
|
let decl = respan(sp, ast::DeclLocal(local));
|
2013-09-06 21:11:55 -05:00
|
|
|
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
|
2013-08-08 13:38:10 -05:00
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@Expr>) -> P<ast::Block> {
|
2013-08-01 10:34:59 -05:00
|
|
|
self.block_all(span, ~[], stmts, expr)
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block> {
|
2013-08-01 10:34:59 -05:00
|
|
|
self.block_all(expr.span, ~[], ~[], Some(expr))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-08-01 10:34:59 -05:00
|
|
|
fn block_all(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
view_items: ~[ast::ViewItem],
|
2013-09-01 20:45:37 -05:00
|
|
|
stmts: ~[@ast::Stmt],
|
2013-11-30 16:00:39 -06:00
|
|
|
expr: Option<@ast::Expr>) -> P<ast::Block> {
|
|
|
|
P(ast::Block {
|
2013-07-16 13:08:35 -05:00
|
|
|
view_items: view_items,
|
|
|
|
stmts: stmts,
|
|
|
|
expr: expr,
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2013-07-27 03:25:59 -05:00
|
|
|
rules: ast::DefaultBlock,
|
2013-07-16 13:08:35 -05:00
|
|
|
span: span,
|
2013-11-30 16:00:39 -06:00
|
|
|
})
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr(&self, span: Span, node: ast::Expr_) -> @ast::Expr {
|
|
|
|
@ast::Expr {
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2013-05-17 08:51:25 -05:00
|
|
|
node: node,
|
|
|
|
span: span,
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_path(&self, path: ast::Path) -> @ast::Expr {
|
|
|
|
self.expr(path.span, ast::ExprPath(path))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_ident(&self, span: Span, id: ast::Ident) -> @ast::Expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr_path(self.path_ident(span, id))
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_self(&self, span: Span) -> @ast::Expr {
|
2014-01-27 06:18:36 -06:00
|
|
|
self.expr_ident(span, special_idents::self_)
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_binary(&self, sp: Span, op: ast::BinOp,
|
|
|
|
lhs: @ast::Expr, rhs: @ast::Expr) -> @ast::Expr {
|
2013-09-06 21:11:55 -05:00
|
|
|
self.expr(sp, ast::ExprBinary(ast::DUMMY_NODE_ID, op, lhs, rhs))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_deref(&self, sp: Span, e: @ast::Expr) -> @ast::Expr {
|
|
|
|
self.expr_unary(sp, ast::UnDeref, e)
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_unary(&self, sp: Span, op: ast::UnOp, e: @ast::Expr)
|
|
|
|
-> @ast::Expr {
|
2013-09-06 21:11:55 -05:00
|
|
|
self.expr(sp, ast::ExprUnary(ast::DUMMY_NODE_ID, op, e))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_managed(&self, sp: Span, e: @ast::Expr) -> @ast::Expr {
|
2013-12-31 14:55:39 -06:00
|
|
|
self.expr_unary(sp, ast::UnBox, e)
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_field_access(&self, sp: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr {
|
|
|
|
self.expr(sp, ast::ExprField(expr, ident, ~[]))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr {
|
|
|
|
self.expr(sp, ast::ExprAddrOf(ast::MutImmutable, e))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_mut_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr {
|
|
|
|
self.expr(sp, ast::ExprAddrOf(ast::MutMutable, e))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_call(&self, span: Span, expr: @ast::Expr, args: ~[@ast::Expr]) -> @ast::Expr {
|
|
|
|
self.expr(span, ast::ExprCall(expr, args, ast::NoSugar))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_call_ident(&self, span: Span, id: ast::Ident, args: ~[@ast::Expr]) -> @ast::Expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr(span,
|
2013-09-01 20:45:37 -05:00
|
|
|
ast::ExprCall(self.expr_ident(span, id), args, ast::NoSugar))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 19:50:59 -05:00
|
|
|
fn expr_call_global(&self, sp: Span, fn_path: ~[ast::Ident],
|
2013-09-01 20:45:37 -05:00
|
|
|
args: ~[@ast::Expr]) -> @ast::Expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
let pathexpr = self.expr_path(self.path_global(sp, fn_path));
|
|
|
|
self.expr_call(sp, pathexpr, args)
|
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn expr_method_call(&self, span: Span,
|
2013-09-01 20:45:37 -05:00
|
|
|
expr: @ast::Expr,
|
2013-09-01 19:50:59 -05:00
|
|
|
ident: ast::Ident,
|
2014-01-27 06:18:36 -06:00
|
|
|
mut args: ~[@ast::Expr]) -> @ast::Expr {
|
|
|
|
args.unshift(expr);
|
|
|
|
self.expr(span, ast::ExprMethodCall(ast::DUMMY_NODE_ID, ident, ~[], args, ast::NoSugar))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr {
|
2013-09-01 20:45:37 -05:00
|
|
|
self.expr(b.span, ast::ExprBlock(b))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field {
|
2013-10-28 21:22:42 -05:00
|
|
|
ast::Field { ident: respan(span, name), expr: e, span: span }
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr {
|
|
|
|
self.expr(span, ast::ExprStruct(path, fields, None))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn expr_struct_ident(&self, span: Span,
|
2013-09-01 20:45:37 -05:00
|
|
|
id: ast::Ident, fields: ~[ast::Field]) -> @ast::Expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr_struct(span, self.path_ident(span, id), fields)
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> @ast::Expr {
|
2013-09-01 20:45:37 -05:00
|
|
|
self.expr(sp, ast::ExprLit(@respan(sp, lit)))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_uint(&self, span: Span, i: uint) -> @ast::Expr {
|
2014-01-09 07:05:33 -06:00
|
|
|
self.expr_lit(span, ast::LitUint(i as u64, ast::TyU))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_int(&self, sp: Span, i: int) -> @ast::Expr {
|
2014-01-09 07:05:33 -06:00
|
|
|
self.expr_lit(sp, ast::LitInt(i as i64, ast::TyI))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_u8(&self, sp: Span, u: u8) -> @ast::Expr {
|
2014-01-09 07:05:33 -06:00
|
|
|
self.expr_lit(sp, ast::LitUint(u as u64, ast::TyU8))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_bool(&self, sp: Span, value: bool) -> @ast::Expr {
|
2014-01-09 07:05:33 -06:00
|
|
|
self.expr_lit(sp, ast::LitBool(value))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_vstore(&self, sp: Span, expr: @ast::Expr, vst: ast::ExprVstore) -> @ast::Expr {
|
|
|
|
self.expr(sp, ast::ExprVstore(expr, vst))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_vec(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr {
|
|
|
|
self.expr(sp, ast::ExprVec(exprs, ast::MutImmutable))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_vec_uniq(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr {
|
|
|
|
self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::ExprVstoreUniq)
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_vec_slice(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr {
|
|
|
|
self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::ExprVstoreSlice)
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2014-01-10 16:02:36 -06:00
|
|
|
fn expr_str(&self, sp: Span, s: InternedString) -> @ast::Expr {
|
2014-01-09 07:05:33 -06:00
|
|
|
self.expr_lit(sp, ast::LitStr(s, ast::CookedStr))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2014-01-10 16:02:36 -06:00
|
|
|
fn expr_str_uniq(&self, sp: Span, s: InternedString) -> @ast::Expr {
|
2013-09-01 20:45:37 -05:00
|
|
|
self.expr_vstore(sp, self.expr_str(sp, s), ast::ExprVstoreUniq)
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: P<ast::Ty>) -> @ast::Expr {
|
2013-09-16 23:12:18 -05:00
|
|
|
self.expr(sp, ast::ExprCast(expr, ty))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn expr_some(&self, sp: Span, expr: @ast::Expr) -> @ast::Expr {
|
|
|
|
let some = ~[
|
|
|
|
self.ident_of("std"),
|
|
|
|
self.ident_of("option"),
|
|
|
|
self.ident_of("Some"),
|
|
|
|
];
|
|
|
|
self.expr_call_global(sp, some, ~[expr])
|
|
|
|
}
|
|
|
|
|
|
|
|
fn expr_none(&self, sp: Span) -> @ast::Expr {
|
|
|
|
let none = self.path_global(sp, ~[
|
|
|
|
self.ident_of("std"),
|
|
|
|
self.ident_of("option"),
|
|
|
|
self.ident_of("None"),
|
|
|
|
]);
|
|
|
|
self.expr_path(none)
|
|
|
|
}
|
|
|
|
|
2014-01-10 16:02:36 -06:00
|
|
|
fn expr_fail(&self, span: Span, msg: InternedString) -> @ast::Expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
let loc = self.codemap().lookup_char_pos(span.lo);
|
|
|
|
self.expr_call_global(
|
|
|
|
span,
|
|
|
|
~[
|
2013-05-22 13:02:40 -05:00
|
|
|
self.ident_of("std"),
|
2013-10-27 14:12:40 -05:00
|
|
|
self.ident_of("rt"),
|
|
|
|
self.ident_of("begin_unwind"),
|
2013-05-19 00:53:42 -05:00
|
|
|
],
|
|
|
|
~[
|
2013-09-17 09:45:49 -05:00
|
|
|
self.expr_str(span, msg),
|
2014-01-10 16:02:36 -06:00
|
|
|
self.expr_str(span,
|
|
|
|
token::intern_and_get_ident(loc.file.name)),
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr_uint(span, loc.line),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2013-09-17 09:45:49 -05:00
|
|
|
fn expr_unreachable(&self, span: Span) -> @ast::Expr {
|
2014-01-10 16:02:36 -06:00
|
|
|
self.expr_fail(span,
|
|
|
|
InternedString::new(
|
|
|
|
"internal error: entered unreachable code"))
|
2013-09-17 09:45:49 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn pat(&self, span: Span, pat: ast::Pat_) -> @ast::Pat {
|
2013-09-06 21:11:55 -05:00
|
|
|
@ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span: span }
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn pat_wild(&self, span: Span) -> @ast::Pat {
|
|
|
|
self.pat(span, ast::PatWild)
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn pat_lit(&self, span: Span, expr: @ast::Expr) -> @ast::Pat {
|
|
|
|
self.pat(span, ast::PatLit(expr))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn pat_ident(&self, span: Span, ident: ast::Ident) -> @ast::Pat {
|
2013-10-20 07:31:23 -05:00
|
|
|
self.pat_ident_binding_mode(span, ident, ast::BindByValue(ast::MutImmutable))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn pat_ident_binding_mode(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
ident: ast::Ident,
|
2013-09-01 20:45:37 -05:00
|
|
|
bm: ast::BindingMode) -> @ast::Pat {
|
2013-05-19 00:53:42 -05:00
|
|
|
let path = self.path_ident(span, ident);
|
2013-09-01 20:45:37 -05:00
|
|
|
let pat = ast::PatIdent(bm, path, None);
|
2013-05-19 00:53:42 -05:00
|
|
|
self.pat(span, pat)
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn pat_enum(&self, span: Span, path: ast::Path, subpats: ~[@ast::Pat]) -> @ast::Pat {
|
|
|
|
let pat = ast::PatEnum(path, Some(subpats));
|
2013-05-19 00:53:42 -05:00
|
|
|
self.pat(span, pat)
|
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn pat_struct(&self, span: Span,
|
2013-09-01 20:45:37 -05:00
|
|
|
path: ast::Path, field_pats: ~[ast::FieldPat]) -> @ast::Pat {
|
|
|
|
let pat = ast::PatStruct(path, field_pats, false);
|
2013-05-19 00:53:42 -05:00
|
|
|
self.pat(span, pat)
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn arm(&self, _span: Span, pats: ~[@ast::Pat], expr: @ast::Expr) -> ast::Arm {
|
|
|
|
ast::Arm {
|
2013-05-19 00:53:42 -05:00
|
|
|
pats: pats,
|
|
|
|
guard: None,
|
2013-08-01 10:34:59 -05:00
|
|
|
body: self.block_expr(expr)
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn arm_unreachable(&self, span: Span) -> ast::Arm {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.arm(span, ~[self.pat_wild(span)], self.expr_unreachable(span))
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_match(&self, span: Span, arg: @ast::Expr, arms: ~[ast::Arm]) -> @Expr {
|
|
|
|
self.expr(span, ast::ExprMatch(arg, arms))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn expr_if(&self, span: Span,
|
2013-09-01 20:45:37 -05:00
|
|
|
cond: @ast::Expr, then: @ast::Expr, els: Option<@ast::Expr>) -> @ast::Expr {
|
2013-09-20 01:08:47 -05:00
|
|
|
let els = els.map(|x| self.expr_block(self.block_expr(x)));
|
2013-09-01 20:45:37 -05:00
|
|
|
self.expr(span, ast::ExprIf(cond, self.block_expr(then), els))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn lambda_fn_decl(&self, span: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> @ast::Expr {
|
2013-09-01 20:45:37 -05:00
|
|
|
self.expr(span, ast::ExprFnBlock(fn_decl, blk))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
let fn_decl = self.fn_decl(
|
|
|
|
ids.map(|id| self.arg(span, *id, self.ty_infer(span))),
|
|
|
|
self.ty_infer(span));
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
self.expr(span, ast::ExprFnBlock(fn_decl, blk))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-11-30 16:00:39 -06:00
|
|
|
fn lambda0(&self, _span: Span, blk: P<ast::Block>) -> @ast::Expr {
|
|
|
|
let blk_e = self.expr(blk.span, ast::ExprBlock(blk));
|
2013-12-28 23:06:22 -06:00
|
|
|
quote_expr!(self, || $blk_e )
|
2013-08-15 01:06:33 -05:00
|
|
|
}
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn lambda1(&self, _span: Span, blk: P<ast::Block>, ident: ast::Ident) -> @ast::Expr {
|
|
|
|
let blk_e = self.expr(blk.span, ast::ExprBlock(blk));
|
2013-12-28 23:06:22 -06:00
|
|
|
quote_expr!(self, |$ident| $blk_e )
|
2013-08-15 01:06:33 -05:00
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda_expr(&self, span: Span, ids: ~[ast::Ident], expr: @ast::Expr) -> @ast::Expr {
|
2013-08-01 10:34:59 -05:00
|
|
|
self.lambda(span, ids, self.block_expr(expr))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda_expr_0(&self, span: Span, expr: @ast::Expr) -> @ast::Expr {
|
2013-08-01 10:34:59 -05:00
|
|
|
self.lambda0(span, self.block_expr(expr))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda_expr_1(&self, span: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr {
|
2013-08-01 10:34:59 -05:00
|
|
|
self.lambda1(span, self.block_expr(expr), ident)
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda_stmts(&self, span: Span, ids: ~[ast::Ident], stmts: ~[@ast::Stmt]) -> @ast::Expr {
|
2013-08-01 10:34:59 -05:00
|
|
|
self.lambda(span, ids, self.block(span, stmts, None))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda_stmts_0(&self, span: Span, stmts: ~[@ast::Stmt]) -> @ast::Expr {
|
2013-08-01 10:34:59 -05:00
|
|
|
self.lambda0(span, self.block(span, stmts, None))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda_stmts_1(&self, span: Span, stmts: ~[@ast::Stmt], ident: ast::Ident) -> @ast::Expr {
|
2013-08-01 10:34:59 -05:00
|
|
|
self.lambda1(span, self.block(span, stmts, None), ident)
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Arg {
|
2013-05-19 00:53:42 -05:00
|
|
|
let arg_pat = self.pat_ident(span, ident);
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::Arg {
|
2013-05-17 08:51:25 -05:00
|
|
|
ty: ty,
|
2013-05-19 00:53:42 -05:00
|
|
|
pat: arg_pat,
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2014-01-26 02:43:42 -06:00
|
|
|
// FIXME unused self
|
2014-01-09 07:05:33 -06:00
|
|
|
fn fn_decl(&self, inputs: ~[ast::Arg], output: P<ast::Ty>) -> P<ast::FnDecl> {
|
|
|
|
P(ast::FnDecl {
|
2013-05-17 08:51:25 -05:00
|
|
|
inputs: inputs,
|
|
|
|
output: output,
|
2014-01-09 07:05:33 -06:00
|
|
|
cf: ast::Return,
|
2013-10-25 00:56:34 -05:00
|
|
|
variadic: false
|
2013-11-30 16:00:39 -06:00
|
|
|
})
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn item(&self, span: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
name: Ident, attrs: ~[ast::Attribute], node: ast::Item_) -> @ast::Item {
|
2014-01-26 02:43:42 -06:00
|
|
|
// FIXME: Would be nice if our generated code didn't violate
|
2013-05-17 08:51:25 -05:00
|
|
|
// Rust coding conventions
|
2014-01-09 07:05:33 -06:00
|
|
|
@ast::Item { ident: name,
|
2013-05-19 00:53:42 -05:00
|
|
|
attrs: attrs,
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2013-05-17 09:19:28 -05:00
|
|
|
node: node,
|
2014-01-09 07:05:33 -06:00
|
|
|
vis: ast::Inherited,
|
2013-05-17 09:19:28 -05:00
|
|
|
span: span }
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn item_fn_poly(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident,
|
2014-01-09 07:05:33 -06:00
|
|
|
inputs: ~[ast::Arg],
|
2013-11-30 16:00:39 -06:00
|
|
|
output: P<ast::Ty>,
|
2013-05-17 08:51:25 -05:00
|
|
|
generics: Generics,
|
2014-01-09 07:05:33 -06:00
|
|
|
body: P<ast::Block>) -> @ast::Item {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.item(span,
|
|
|
|
name,
|
|
|
|
~[],
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::ItemFn(self.fn_decl(inputs, output),
|
|
|
|
ast::ImpureFn,
|
|
|
|
AbiSet::Rust(),
|
|
|
|
generics,
|
|
|
|
body))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn item_fn(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident,
|
2014-01-09 07:05:33 -06:00
|
|
|
inputs: ~[ast::Arg],
|
2013-11-30 16:00:39 -06:00
|
|
|
output: P<ast::Ty>,
|
|
|
|
body: P<ast::Block>
|
2014-01-09 07:05:33 -06:00
|
|
|
) -> @ast::Item {
|
2013-05-17 08:51:25 -05:00
|
|
|
self.item_fn_poly(
|
2013-05-19 00:53:42 -05:00
|
|
|
span,
|
2013-05-17 08:51:25 -05:00
|
|
|
name,
|
|
|
|
inputs,
|
|
|
|
output,
|
|
|
|
ast_util::empty_generics(),
|
2013-05-19 00:53:42 -05:00
|
|
|
body)
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::Variant {
|
2013-08-09 22:09:47 -05:00
|
|
|
let args = tys.move_iter().map(|ty| {
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::VariantArg { ty: ty, id: ast::DUMMY_NODE_ID }
|
2013-07-05 23:57:11 -05:00
|
|
|
}).collect();
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
respan(span,
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::Variant_ {
|
2013-05-19 00:53:42 -05:00
|
|
|
name: name,
|
|
|
|
attrs: ~[],
|
2014-01-09 07:05:33 -06:00
|
|
|
kind: ast::TupleVariantKind(args),
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2013-05-19 00:53:42 -05:00
|
|
|
disr_expr: None,
|
2014-01-09 07:05:33 -06:00
|
|
|
vis: ast::Public
|
2013-05-19 00:53:42 -05:00
|
|
|
})
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn item_enum_poly(&self, span: Span, name: Ident,
|
2014-01-09 07:05:33 -06:00
|
|
|
enum_definition: ast::EnumDef,
|
|
|
|
generics: Generics) -> @ast::Item {
|
|
|
|
self.item(span, name, ~[], ast::ItemEnum(enum_definition, generics))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn item_enum(&self, span: Span, name: Ident,
|
2014-01-09 07:05:33 -06:00
|
|
|
enum_definition: ast::EnumDef) -> @ast::Item {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.item_enum_poly(span, name, enum_definition,
|
2013-05-17 08:51:25 -05:00
|
|
|
ast_util::empty_generics())
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn item_struct(&self, span: Span, name: Ident,
|
|
|
|
struct_def: ast::StructDef) -> @ast::Item {
|
2013-05-17 08:51:25 -05:00
|
|
|
self.item_struct_poly(
|
|
|
|
span,
|
2013-05-19 00:53:42 -05:00
|
|
|
name,
|
2013-05-17 08:51:25 -05:00
|
|
|
struct_def,
|
|
|
|
ast_util::empty_generics()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn item_struct_poly(&self, span: Span, name: Ident,
|
|
|
|
struct_def: ast::StructDef, generics: Generics) -> @ast::Item {
|
|
|
|
self.item(span, name, ~[], ast::ItemStruct(@struct_def, generics))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn item_mod(&self, span: Span, name: Ident,
|
2013-07-19 06:51:37 -05:00
|
|
|
attrs: ~[ast::Attribute],
|
2014-01-09 07:05:33 -06:00
|
|
|
vi: ~[ast::ViewItem],
|
|
|
|
items: ~[@ast::Item]) -> @ast::Item {
|
2013-05-17 08:51:25 -05:00
|
|
|
self.item(
|
|
|
|
span,
|
2013-05-19 00:53:42 -05:00
|
|
|
name,
|
|
|
|
attrs,
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::ItemMod(ast::Mod {
|
2013-05-19 00:53:42 -05:00
|
|
|
view_items: vi,
|
2013-05-17 08:51:25 -05:00
|
|
|
items: items,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
|
2014-01-09 07:05:33 -06:00
|
|
|
generics: Generics) -> @ast::Item {
|
|
|
|
self.item(span, name, ~[], ast::ItemTy(ty, generics))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::Item {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.item_ty_poly(span, name, ty, ast_util::empty_generics())
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute {
|
2013-07-19 06:51:37 -05:00
|
|
|
respan(sp, ast::Attribute_ {
|
|
|
|
style: ast::AttrOuter,
|
|
|
|
value: mi,
|
|
|
|
is_sugared_doc: false,
|
|
|
|
})
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
|
|
|
|
2014-01-08 12:35:15 -06:00
|
|
|
fn meta_word(&self, sp: Span, w: InternedString) -> @ast::MetaItem {
|
2013-07-19 06:51:37 -05:00
|
|
|
@respan(sp, ast::MetaWord(w))
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
2014-01-08 12:35:15 -06:00
|
|
|
fn meta_list(&self,
|
|
|
|
sp: Span,
|
|
|
|
name: InternedString,
|
|
|
|
mis: ~[@ast::MetaItem])
|
|
|
|
-> @ast::MetaItem {
|
2013-07-19 06:51:37 -05:00
|
|
|
@respan(sp, ast::MetaList(name, mis))
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
2014-01-08 12:35:15 -06:00
|
|
|
fn meta_name_value(&self,
|
|
|
|
sp: Span,
|
|
|
|
name: InternedString,
|
|
|
|
value: ast::Lit_)
|
|
|
|
-> @ast::MetaItem {
|
2013-07-19 06:51:37 -05:00
|
|
|
@respan(sp, ast::MetaNameValue(name, respan(sp, value)))
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn view_use(&self, sp: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
vis: ast::Visibility, vp: ~[@ast::ViewPath]) -> ast::ViewItem {
|
|
|
|
ast::ViewItem {
|
|
|
|
node: ast::ViewItemUse(vp),
|
2013-05-19 00:53:42 -05:00
|
|
|
attrs: ~[],
|
|
|
|
vis: vis,
|
|
|
|
span: sp
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
|
|
|
|
path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::ViewItem {
|
2013-11-20 18:23:04 -06:00
|
|
|
let imports = imports.map(|id| {
|
2014-01-09 07:05:33 -06:00
|
|
|
respan(sp, ast::PathListIdent_ { name: *id, id: ast::DUMMY_NODE_ID })
|
2013-11-20 18:23:04 -06:00
|
|
|
});
|
2013-05-17 09:19:28 -05:00
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
self.view_use(sp, vis,
|
|
|
|
~[@respan(sp,
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::ViewPathList(self.path(sp, path),
|
|
|
|
imports,
|
|
|
|
ast::DUMMY_NODE_ID))])
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn view_use_glob(&self, sp: Span,
|
2014-01-09 07:05:33 -06:00
|
|
|
vis: ast::Visibility, path: ~[ast::Ident]) -> ast::ViewItem {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.view_use(sp, vis,
|
|
|
|
~[@respan(sp,
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID))])
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-08-29 14:10:02 -05:00
|
|
|
|
2013-12-27 18:17:36 -06:00
|
|
|
struct Duplicator<'a> {
|
2013-12-25 12:10:33 -06:00
|
|
|
cx: &'a ExtCtxt<'a>,
|
2013-08-29 14:10:02 -05:00
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
impl<'a> Folder for Duplicator<'a> {
|
2013-12-27 21:34:51 -06:00
|
|
|
fn new_id(&mut self, _: NodeId) -> NodeId {
|
2013-08-29 14:10:02 -05:00
|
|
|
ast::DUMMY_NODE_ID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Duplicate {
|
|
|
|
//
|
|
|
|
// Duplication functions
|
|
|
|
//
|
|
|
|
// These functions just duplicate AST nodes.
|
|
|
|
//
|
|
|
|
|
2013-12-27 18:17:36 -06:00
|
|
|
fn duplicate(&self, cx: &ExtCtxt) -> Self;
|
2013-08-29 14:10:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Duplicate for @ast::Expr {
|
2013-12-27 18:17:36 -06:00
|
|
|
fn duplicate(&self, cx: &ExtCtxt) -> @ast::Expr {
|
2013-12-27 21:34:51 -06:00
|
|
|
let mut folder = Duplicator {
|
2013-08-29 14:10:02 -05:00
|
|
|
cx: cx,
|
2013-12-27 18:17:36 -06:00
|
|
|
};
|
2013-08-29 14:10:02 -05:00
|
|
|
folder.fold_expr(*self)
|
|
|
|
}
|
|
|
|
}
|