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-09-01 19:50:59 -05:00
|
|
|
use ast::Ident;
|
2012-12-23 16:41:37 -06:00
|
|
|
use ast;
|
2013-05-17 08:51:25 -05:00
|
|
|
use ast_util;
|
2013-08-31 11:13:04 -05: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::*;
|
2013-08-29 14:10:02 -05:00
|
|
|
use fold;
|
2013-05-17 08:51:25 -05:00
|
|
|
use opt_vec;
|
2013-02-14 23:50:03 -06:00
|
|
|
use opt_vec::OptVec;
|
|
|
|
|
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-07-05 07:33:52 -05:00
|
|
|
rp: Option<ast::Lifetime>,
|
2013-07-05 23:57:11 -05:00
|
|
|
types: ~[ast::Ty])
|
2013-07-05 05:15:21 -05:00
|
|
|
-> ast::Path;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
// types
|
2013-09-01 20:45:37 -05:00
|
|
|
fn ty_mt(&self, ty: ast::Ty, mutbl: ast::Mutability) -> ast::mt;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn ty(&self, span: Span, ty: ast::ty_) -> ast::Ty;
|
2013-07-05 23:57:11 -05:00
|
|
|
fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> ast::Ty;
|
2013-09-01 19:50:59 -05:00
|
|
|
fn ty_ident(&self, span: Span, idents: ast::Ident) -> 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-07-05 23:57:11 -05:00
|
|
|
ty: 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) -> ast::Ty;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn ty_uniq(&self, span: Span, ty: ast::Ty) -> ast::Ty;
|
2013-09-01 20:45:37 -05:00
|
|
|
fn ty_box(&self, span: Span, ty: ast::Ty, mutbl: ast::Mutability) -> ast::Ty;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-07-05 23:57:11 -05:00
|
|
|
fn ty_option(&self, ty: ast::Ty) -> ast::Ty;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn ty_infer(&self, sp: Span) -> ast::Ty;
|
2013-07-05 23:57:11 -05:00
|
|
|
fn ty_nil(&self) -> ast::Ty;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-07-05 23:57:11 -05:00
|
|
|
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[ast::Ty];
|
|
|
|
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[ast::Ty];
|
2013-09-01 19:50:59 -05:00
|
|
|
fn ty_field_imm(&self, span: Span, name: Ident, ty: ast::Ty) -> ast::TypeField;
|
2013-05-17 08:51:25 -05:00
|
|
|
fn strip_bounds(&self, bounds: &Generics) -> Generics;
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn typaram(&self, id: ast::Ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-07-05 19:47:42 -05:00
|
|
|
fn trait_ref(&self, path: ast::Path) -> ast::trait_ref;
|
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-08-08 13:38:10 -05:00
|
|
|
typ: 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-09-01 20:45:37 -05:00
|
|
|
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> ast::Block;
|
|
|
|
fn block_expr(&self, expr: @ast::Expr) -> ast::Block;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn block_all(&self, span: Span,
|
2013-08-01 10:34:59 -05:00
|
|
|
view_items: ~[ast::view_item],
|
2013-09-01 20:45:37 -05:00
|
|
|
stmts: ~[@ast::Stmt],
|
|
|
|
expr: Option<@ast::Expr>) -> 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;
|
|
|
|
fn expr_block(&self, b: ast::Block) -> @ast::Expr;
|
2013-09-16 23:12:18 -05:00
|
|
|
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: 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
|
|
|
|
2013-09-01 20:45:37 -05: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;
|
|
|
|
fn expr_str(&self, sp: Span, s: @str) -> @ast::Expr;
|
|
|
|
fn expr_str_uniq(&self, sp: Span, s: @str) -> @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;
|
|
|
|
|
2013-09-17 09:45:49 -05:00
|
|
|
fn expr_fail(&self, span: Span, msg: @str) -> @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-09-01 20:45:37 -05:00
|
|
|
fn lambda_fn_decl(&self, span: Span, fn_decl: ast::fn_decl, blk: ast::Block) -> @ast::Expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: ast::Block) -> @ast::Expr;
|
|
|
|
fn lambda0(&self, span: Span, blk: ast::Block) -> @ast::Expr;
|
|
|
|
fn lambda1(&self, span: Span, blk: 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,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident, attrs: ~[ast::Attribute], node: ast::item_) -> @ast::item;
|
2013-05-15 17:55:57 -05:00
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn arg(&self, span: Span, name: Ident, ty: ast::Ty) -> ast::arg;
|
2013-05-19 00:53:42 -05:00
|
|
|
// XXX unused self
|
2013-07-05 23:57:11 -05:00
|
|
|
fn fn_decl(&self, inputs: ~[ast::arg], output: ast::Ty) -> ast::fn_decl;
|
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,
|
2013-05-17 08:51:25 -05:00
|
|
|
inputs: ~[ast::arg],
|
2013-07-05 23:57:11 -05:00
|
|
|
output: ast::Ty,
|
2013-05-17 08:51:25 -05:00
|
|
|
generics: Generics,
|
2013-07-19 00:38:55 -05:00
|
|
|
body: 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,
|
2013-05-17 08:51:25 -05:00
|
|
|
inputs: ~[ast::arg],
|
2013-07-05 23:57:11 -05:00
|
|
|
output: ast::Ty,
|
2013-07-19 00:38:55 -05:00
|
|
|
body: ast::Block) -> @ast::item;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn variant(&self, span: Span, name: Ident, tys: ~[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,
|
2013-05-17 08:51:25 -05:00
|
|
|
enum_definition: ast::enum_def,
|
|
|
|
generics: Generics) -> @ast::item;
|
2013-09-01 19:50:59 -05:00
|
|
|
fn item_enum(&self, span: Span, name: Ident, enum_def: ast::enum_def) -> @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,
|
2013-05-17 08:51:25 -05:00
|
|
|
struct_def: ast::struct_def,
|
|
|
|
generics: Generics) -> @ast::item;
|
2013-09-01 19:50:59 -05:00
|
|
|
fn item_struct(&self, span: Span, name: Ident, struct_def: ast::struct_def) -> @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],
|
2013-07-05 03:28:53 -05:00
|
|
|
vi: ~[ast::view_item], 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-07-05 23:57:11 -05:00
|
|
|
ty: ast::Ty,
|
2013-05-17 08:51:25 -05:00
|
|
|
generics: Generics) -> @ast::item;
|
2013-09-01 19:50:59 -05:00
|
|
|
fn item_ty(&self, span: Span, name: Ident, ty: 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
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn meta_word(&self, sp: Span, w: @str) -> @ast::MetaItem;
|
|
|
|
fn meta_list(&self, sp: Span, name: @str, mis: ~[@ast::MetaItem]) -> @ast::MetaItem;
|
|
|
|
fn meta_name_value(&self, sp: Span, name: @str, 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,
|
2013-07-05 03:28:53 -05:00
|
|
|
vis: ast::visibility, vp: ~[@ast::view_path]) -> ast::view_item;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn view_use_list(&self, sp: Span, vis: ast::visibility,
|
2013-09-01 19:50:59 -05:00
|
|
|
path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::view_item;
|
2013-08-31 11:13:04 -05:00
|
|
|
fn view_use_glob(&self, sp: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item;
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
|
2013-05-17 08:51:25 -05:00
|
|
|
impl AstBuilder for @ExtCtxt {
|
2013-09-01 19:50:59 -05:00
|
|
|
fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.path_all(span, false, strs, None, ~[])
|
|
|
|
}
|
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-05-19 00:53:42 -05:00
|
|
|
self.path_all(span, true, strs, None, ~[])
|
|
|
|
}
|
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-07-05 07:33:52 -05:00
|
|
|
rp: Option<ast::Lifetime>,
|
2013-07-05 23:57:11 -05:00
|
|
|
types: ~[ast::Ty])
|
2013-08-07 11:47:28 -05:00
|
|
|
-> ast::Path {
|
|
|
|
let last_identifier = idents.pop();
|
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,
|
|
|
|
lifetime: None,
|
|
|
|
types: opt_vec::Empty,
|
|
|
|
}
|
|
|
|
}).collect();
|
|
|
|
segments.push(ast::PathSegment {
|
|
|
|
identifier: last_identifier,
|
|
|
|
lifetime: rp,
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn ty_mt(&self, ty: ast::Ty, mutbl: ast::Mutability) -> ast::mt {
|
2013-05-19 00:53:42 -05:00
|
|
|
ast::mt {
|
2013-07-05 23:57:11 -05:00
|
|
|
ty: ~ty,
|
2013-05-19 00:53:42 -05:00
|
|
|
mutbl: mutbl
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn ty(&self, span: Span, ty: ast::ty_) -> ast::Ty {
|
2013-07-05 23:57:11 -05:00
|
|
|
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-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-07-05 23:57:11 -05:00
|
|
|
-> ast::Ty {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.ty(path.span,
|
2013-09-06 21:11:55 -05:00
|
|
|
ast::ty_path(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-07-05 23:57:11 -05:00
|
|
|
-> 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-07-05 23:57:11 -05:00
|
|
|
ty: 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-07-05 23:57:11 -05:00
|
|
|
-> ast::Ty {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.ty(span,
|
|
|
|
ast::ty_rptr(lifetime, self.ty_mt(ty, mutbl)))
|
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn ty_uniq(&self, span: Span, ty: ast::Ty) -> ast::Ty {
|
2013-09-01 20:45:37 -05:00
|
|
|
self.ty(span, ast::ty_uniq(self.ty_mt(ty, ast::MutImmutable)))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn ty_box(&self, span: Span,
|
2013-09-01 20:45:37 -05:00
|
|
|
ty: ast::Ty, mutbl: ast::Mutability) -> ast::Ty {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.ty(span, ast::ty_box(self.ty_mt(ty, mutbl)))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-07-05 23:57:11 -05:00
|
|
|
fn ty_option(&self, ty: ast::Ty) -> ast::Ty {
|
2013-05-17 08:51:25 -05:00
|
|
|
self.ty_path(
|
2013-05-19 00:53:42 -05:00
|
|
|
self.path_all(dummy_sp(),
|
|
|
|
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")
|
|
|
|
],
|
|
|
|
None,
|
2013-07-05 20:38:56 -05:00
|
|
|
~[ ty ]), None)
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn ty_field_imm(&self, span: Span, name: Ident, ty: ast::Ty) -> ast::TypeField {
|
2013-07-27 03:25:59 -05:00
|
|
|
ast::TypeField {
|
|
|
|
ident: name,
|
2013-09-01 20:45:37 -05:00
|
|
|
mt: ast::mt { ty: ~ty, mutbl: ast::MutImmutable },
|
2013-07-27 03:25:59 -05:00
|
|
|
span: span,
|
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn ty_infer(&self, span: Span) -> ast::Ty {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.ty(span, ast::ty_infer)
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-07-05 23:57:11 -05:00
|
|
|
fn ty_nil(&self) -> ast::Ty {
|
|
|
|
ast::Ty {
|
2013-09-06 21:11:55 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2013-05-17 08:51:25 -05:00
|
|
|
node: ast::ty_nil,
|
|
|
|
span: dummy_sp(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn typaram(&self, id: ast::Ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam {
|
2013-09-06 21:11:55 -05:00
|
|
|
ast::TyParam { ident: id, id: ast::DUMMY_NODE_ID, bounds: bounds }
|
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-07-05 23:57:11 -05:00
|
|
|
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[ast::Ty] {
|
2013-05-17 08:51:25 -05:00
|
|
|
opt_vec::take_vec(
|
2013-05-19 00:53:42 -05:00
|
|
|
ty_params.map(|p| self.ty_ident(dummy_sp(), p.ident)))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-07-05 23:57:11 -05:00
|
|
|
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[ast::Ty] {
|
2013-05-17 08:51:25 -05:00
|
|
|
opt_vec::take_vec(
|
|
|
|
ty_params.map(|p| self.ty_path(
|
2013-07-05 20:38:56 -05:00
|
|
|
self.path_global(dummy_sp(), ~[p.ident]), None)))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn strip_bounds(&self, generics: &Generics) -> Generics {
|
|
|
|
let new_params = do generics.ty_params.map |ty_param| {
|
2013-06-27 19:41:35 -05:00
|
|
|
ast::TyParam { bounds: opt_vec::Empty, ..*ty_param }
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 19:47:42 -05:00
|
|
|
fn trait_ref(&self, path: ast::Path) -> ast::trait_ref {
|
|
|
|
ast::trait_ref {
|
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-05-19 00:53:42 -05:00
|
|
|
let pat = self.pat_ident(sp, ident);
|
2013-07-19 00:38:55 -05:00
|
|
|
let local = @ast::Local {
|
|
|
|
is_mutbl: mutbl,
|
|
|
|
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-08-08 13:38:10 -05:00
|
|
|
typ: ast::Ty,
|
2013-09-01 20:45:37 -05:00
|
|
|
ex: @ast::Expr)
|
|
|
|
-> @ast::Stmt {
|
2013-08-08 13:38:10 -05:00
|
|
|
let pat = self.pat_ident(sp, ident);
|
|
|
|
let local = @ast::Local {
|
|
|
|
is_mutbl: mutbl,
|
|
|
|
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-09-01 20:45:37 -05:00
|
|
|
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@Expr>) -> 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-09-01 20:45:37 -05:00
|
|
|
fn block_expr(&self, expr: @ast::Expr) -> 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,
|
2013-08-01 10:34:59 -05:00
|
|
|
view_items: ~[ast::view_item],
|
2013-09-01 20:45:37 -05:00
|
|
|
stmts: ~[@ast::Stmt],
|
|
|
|
expr: Option<@ast::Expr>) -> ast::Block {
|
2013-07-19 00:38:55 -05:00
|
|
|
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-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 {
|
|
|
|
self.expr(span, ast::ExprSelf)
|
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 {
|
|
|
|
self.expr_unary(sp, ast::UnBox(ast::MutImmutable), 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,
|
2013-09-01 20:45:37 -05:00
|
|
|
args: ~[@ast::Expr]) -> @ast::Expr {
|
2013-05-15 17:55:57 -05:00
|
|
|
self.expr(span,
|
2013-09-06 21:11:55 -05:00
|
|
|
ast::ExprMethodCall(ast::DUMMY_NODE_ID, expr, ident, ~[], args, ast::NoSugar))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_block(&self, b: ast::Block) -> @ast::Expr {
|
|
|
|
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-07-19 09:24:22 -05:00
|
|
|
ast::Field { ident: 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)
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_lit(&self, sp: Span, lit: ast::lit_) -> @ast::Expr {
|
|
|
|
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 {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr_lit(span, ast::lit_uint(i as u64, ast::ty_u))
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_int(&self, sp: Span, i: int) -> @ast::Expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr_lit(sp, ast::lit_int(i as i64, ast::ty_i))
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_u8(&self, sp: Span, u: u8) -> @ast::Expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr_lit(sp, ast::lit_uint(u as u64, ast::ty_u8))
|
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_bool(&self, sp: Span, value: bool) -> @ast::Expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr_lit(sp, ast::lit_bool(value))
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_str(&self, sp: Span, s: @str) -> @ast::Expr {
|
2013-10-07 19:49:10 -05:00
|
|
|
self.expr_lit(sp, ast::lit_str(s, ast::CookedStr))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn expr_str_uniq(&self, sp: Span, s: @str) -> @ast::Expr {
|
|
|
|
self.expr_vstore(sp, self.expr_str(sp, s), ast::ExprVstoreUniq)
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-16 23:12:18 -05:00
|
|
|
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: ast::Ty) -> @ast::Expr {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2013-09-17 09:45:49 -05:00
|
|
|
fn expr_fail(&self, span: Span, msg: @str) -> @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-05-19 00:53:42 -05:00
|
|
|
self.ident_of("sys"),
|
|
|
|
self.ident_of("FailWithCause"),
|
|
|
|
self.ident_of("fail_with"),
|
|
|
|
],
|
|
|
|
~[
|
2013-09-17 09:45:49 -05:00
|
|
|
self.expr_str(span, msg),
|
2013-06-12 12:02:55 -05:00
|
|
|
self.expr_str(span, 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 {
|
|
|
|
self.expr_fail(span, @"internal error: entered unreachable code")
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
self.pat_ident_binding_mode(span, ident, ast::BindInfer)
|
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-08-04 16:59:36 -05:00
|
|
|
let els = els.map_move(|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-09-01 20:45:37 -05:00
|
|
|
fn lambda_fn_decl(&self, span: Span, fn_decl: ast::fn_decl, blk: ast::Block) -> @ast::Expr {
|
|
|
|
self.expr(span, ast::ExprFnBlock(fn_decl, blk))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: 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-09-01 20:45:37 -05:00
|
|
|
fn lambda0(&self, _span: Span, blk: ast::Block) -> @ast::Expr {
|
|
|
|
let blk_e = self.expr(blk.span, ast::ExprBlock(blk.clone()));
|
2013-08-15 01:06:33 -05:00
|
|
|
quote_expr!(*self, || $blk_e )
|
|
|
|
}
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
fn lambda1(&self, _span: Span, blk: ast::Block, ident: ast::Ident) -> @ast::Expr {
|
|
|
|
let blk_e = self.expr(blk.span, ast::ExprBlock(blk.clone()));
|
2013-08-15 01:06:33 -05:00
|
|
|
quote_expr!(*self, |$ident| $blk_e )
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn arg(&self, span: Span, ident: ast::Ident, ty: ast::Ty) -> ast::arg {
|
2013-05-19 00:53:42 -05:00
|
|
|
let arg_pat = self.pat_ident(span, ident);
|
2013-05-17 08:51:25 -05:00
|
|
|
ast::arg {
|
|
|
|
is_mutbl: false,
|
|
|
|
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
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
// XXX unused self
|
2013-07-05 23:57:11 -05:00
|
|
|
fn fn_decl(&self, inputs: ~[ast::arg], output: ast::Ty) -> ast::fn_decl {
|
2013-05-17 08:51:25 -05:00
|
|
|
ast::fn_decl {
|
|
|
|
inputs: inputs,
|
|
|
|
output: output,
|
|
|
|
cf: ast::return_val,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn item(&self, span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident, attrs: ~[ast::Attribute], node: ast::item_) -> @ast::item {
|
2013-05-17 08:51:25 -05:00
|
|
|
// XXX: Would be nice if our generated code didn't violate
|
|
|
|
// Rust coding conventions
|
|
|
|
@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,
|
2013-08-07 02:11:34 -05: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,
|
2013-05-17 08:51:25 -05:00
|
|
|
inputs: ~[ast::arg],
|
2013-07-05 23:57:11 -05:00
|
|
|
output: ast::Ty,
|
2013-05-17 08:51:25 -05:00
|
|
|
generics: Generics,
|
2013-07-19 00:38:55 -05:00
|
|
|
body: ast::Block) -> @ast::item {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.item(span,
|
|
|
|
name,
|
|
|
|
~[],
|
2013-05-17 08:51:25 -05:00
|
|
|
ast::item_fn(self.fn_decl(inputs, output),
|
|
|
|
ast::impure_fn,
|
|
|
|
AbiSet::Rust(),
|
|
|
|
generics,
|
|
|
|
body))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn item_fn(&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident,
|
2013-05-17 08:51:25 -05:00
|
|
|
inputs: ~[ast::arg],
|
2013-07-05 23:57:11 -05:00
|
|
|
output: ast::Ty,
|
2013-07-19 00:38:55 -05:00
|
|
|
body: ast::Block
|
2013-05-17 09:19:28 -05: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
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn variant(&self, span: Span, name: Ident, tys: ~[ast::Ty]) -> ast::variant {
|
2013-08-09 22:09:47 -05:00
|
|
|
let args = tys.move_iter().map(|ty| {
|
2013-09-06 21:11:55 -05:00
|
|
|
ast::variant_arg { 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,
|
|
|
|
ast::variant_ {
|
|
|
|
name: name,
|
|
|
|
attrs: ~[],
|
|
|
|
kind: ast::tuple_variant_kind(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,
|
|
|
|
vis: ast::public
|
|
|
|
})
|
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,
|
2013-05-17 08:51:25 -05:00
|
|
|
enum_definition: ast::enum_def,
|
|
|
|
generics: Generics) -> @ast::item {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.item(span, name, ~[], ast::item_enum(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,
|
2013-05-17 08:51:25 -05:00
|
|
|
enum_definition: ast::enum_def) -> @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())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn item_struct(
|
2013-05-19 00:53:42 -05:00
|
|
|
&self,
|
2013-08-31 11:13:04 -05:00
|
|
|
span: Span,
|
2013-09-01 19:50:59 -05:00
|
|
|
name: Ident,
|
2013-05-17 08:51:25 -05:00
|
|
|
struct_def: ast::struct_def
|
|
|
|
) -> @ast::item {
|
|
|
|
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()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2013-05-17 08:51:25 -05:00
|
|
|
struct_def: ast::struct_def,
|
|
|
|
generics: Generics
|
|
|
|
) -> @ast::item {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.item(span, name, ~[], ast::item_struct(@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],
|
2013-07-05 03:28:53 -05:00
|
|
|
vi: ~[ast::view_item],
|
2013-05-17 08:51:25 -05:00
|
|
|
items: ~[@ast::item]) -> @ast::item {
|
|
|
|
self.item(
|
|
|
|
span,
|
2013-05-19 00:53:42 -05:00
|
|
|
name,
|
|
|
|
attrs,
|
2013-05-17 08:51:25 -05:00
|
|
|
ast::item_mod(ast::_mod {
|
2013-05-19 00:53:42 -05:00
|
|
|
view_items: vi,
|
2013-05-17 08:51:25 -05:00
|
|
|
items: items,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn item_ty_poly(&self, span: Span, name: Ident, ty: ast::Ty,
|
2013-05-17 08:51:25 -05:00
|
|
|
generics: Generics) -> @ast::item {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.item(span, name, ~[], ast::item_ty(ty, generics))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
fn item_ty(&self, span: Span, name: Ident, ty: 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
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn meta_word(&self, sp: Span, w: @str) -> @ast::MetaItem {
|
2013-07-19 06:51:37 -05:00
|
|
|
@respan(sp, ast::MetaWord(w))
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn meta_list(&self, sp: Span, name: @str, 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
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn meta_name_value(&self, sp: Span, name: @str, 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,
|
2013-07-05 03:28:53 -05:00
|
|
|
vis: ast::visibility, vp: ~[@ast::view_path]) -> ast::view_item {
|
|
|
|
ast::view_item {
|
2013-05-19 00:53:42 -05:00
|
|
|
node: ast::view_item_use(vp),
|
|
|
|
attrs: ~[],
|
|
|
|
vis: vis,
|
|
|
|
span: sp
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn view_use_list(&self, sp: Span, vis: ast::visibility,
|
2013-09-01 19:50:59 -05:00
|
|
|
path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::view_item {
|
2013-05-19 00:53:42 -05:00
|
|
|
let imports = do imports.map |id| {
|
2013-09-06 21:11:55 -05:00
|
|
|
respan(sp, ast::path_list_ident_ { name: *id, id: ast::DUMMY_NODE_ID })
|
2013-05-17 09:19:28 -05:00
|
|
|
};
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
self.view_use(sp, vis,
|
|
|
|
~[@respan(sp,
|
|
|
|
ast::view_path_list(self.path(sp, path),
|
|
|
|
imports,
|
2013-09-06 21:11:55 -05:00
|
|
|
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,
|
2013-09-01 19:50:59 -05:00
|
|
|
vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.view_use(sp, vis,
|
|
|
|
~[@respan(sp,
|
2013-09-06 21:11:55 -05:00
|
|
|
ast::view_path_glob(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
|
|
|
|
|
|
|
struct Duplicator {
|
|
|
|
cx: @ExtCtxt,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fold::ast_fold for Duplicator {
|
2013-09-18 20:18:45 -05:00
|
|
|
fn new_id(&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.
|
|
|
|
//
|
|
|
|
|
|
|
|
fn duplicate(&self, cx: @ExtCtxt) -> Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Duplicate for @ast::Expr {
|
|
|
|
fn duplicate(&self, cx: @ExtCtxt) -> @ast::Expr {
|
|
|
|
let folder = @Duplicator {
|
|
|
|
cx: cx,
|
|
|
|
} as @fold::ast_fold;
|
|
|
|
folder.fold_expr(*self)
|
|
|
|
}
|
|
|
|
}
|