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;
|
|
|
|
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-05-19 00:53:42 -05:00
|
|
|
use codemap::{span, respan, dummy_sp};
|
2013-05-08 14:26:34 -05:00
|
|
|
use fold;
|
2013-05-17 06:27:17 -05:00
|
|
|
use ext::base::ExtCtxt;
|
2013-05-17 08:51:25 -05:00
|
|
|
use ext::quote::rt::*;
|
|
|
|
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 {
|
|
|
|
ident: ast::ident,
|
|
|
|
ex: @ast::expr
|
|
|
|
}
|
|
|
|
|
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-07-05 05:15:21 -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-05-19 00:53:42 -05:00
|
|
|
fn path_all(&self, sp: span,
|
|
|
|
global: bool,
|
|
|
|
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-07-05 23:57:11 -05:00
|
|
|
fn ty_mt(&self, ty: ast::Ty, mutbl: ast::mutability) -> ast::mt;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
2013-07-05 23:57:11 -05:00
|
|
|
fn ty(&self, span: span, ty: ast::ty_) -> ast::Ty;
|
|
|
|
fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> ast::Ty;
|
|
|
|
fn ty_ident(&self, span: span, idents: ast::ident) -> ast::Ty;
|
2013-05-19 00:53:42 -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-07-05 23:57:11 -05:00
|
|
|
mutbl: ast::mutability) -> ast::Ty;
|
|
|
|
fn ty_uniq(&self, span: span, ty: ast::Ty) -> ast::Ty;
|
|
|
|
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;
|
|
|
|
fn ty_infer(&self, sp: span) -> ast::Ty;
|
|
|
|
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];
|
|
|
|
fn ty_field_imm(&self, span: span, name: ident, ty: ast::Ty) -> ast::ty_field;
|
2013-05-17 08:51:25 -05:00
|
|
|
fn strip_bounds(&self, bounds: &Generics) -> Generics;
|
|
|
|
|
2013-07-05 20:38:56 -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-05-19 00:53:42 -05:00
|
|
|
fn lifetime(&self, span: span, ident: ast::ident) -> ast::Lifetime;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
// statements
|
|
|
|
fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt;
|
2013-05-19 00:53:42 -05:00
|
|
|
fn stmt_let(&self, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
// blocks
|
|
|
|
fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> ast::blk;
|
|
|
|
fn blk_expr(&self, expr: @ast::expr) -> ast::blk;
|
2013-05-19 00:53:42 -05:00
|
|
|
fn blk_all(&self, span: span,
|
2013-07-05 03:28:53 -05:00
|
|
|
view_items: ~[ast::view_item],
|
2013-05-19 00:53:42 -05:00
|
|
|
stmts: ~[@ast::stmt],
|
|
|
|
expr: Option<@ast::expr>) -> ast::blk;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
|
|
|
// expressions
|
|
|
|
fn expr(&self, span: span, node: ast::expr_) -> @ast::expr;
|
2013-07-05 05:15:21 -05:00
|
|
|
fn expr_path(&self, path: ast::Path) -> @ast::expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
fn expr_ident(&self, span: span, id: ast::ident) -> @ast::expr;
|
|
|
|
|
2013-05-15 17:55:57 -05:00
|
|
|
fn expr_self(&self, span: span) -> @ast::expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
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;
|
|
|
|
fn expr_call_global(&self, sp: span, fn_path: ~[ast::ident],
|
|
|
|
args: ~[@ast::expr]) -> @ast::expr;
|
|
|
|
fn expr_method_call(&self, span: span,
|
|
|
|
expr: @ast::expr, ident: ast::ident,
|
|
|
|
args: ~[@ast::expr]) -> @ast::expr;
|
2013-05-17 08:51:25 -05:00
|
|
|
fn expr_blk(&self, b: ast::blk) -> @ast::expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
|
|
|
fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field;
|
2013-07-05 05:15:21 -05:00
|
|
|
fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::field]) -> @ast::expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
fn expr_struct_ident(&self, span: span, id: ast::ident, fields: ~[ast::field]) -> @ast::expr;
|
|
|
|
|
|
|
|
fn expr_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
fn expr_vstore(&self, sp: span, expr: @ast::expr, vst: ast::expr_vstore) -> @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;
|
2013-06-12 12:02:55 -05:00
|
|
|
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
|
|
|
|
|
|
|
fn expr_unreachable(&self, span: span) -> @ast::expr;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
fn pat_ident_binding_mode(&self,
|
|
|
|
span: span,
|
|
|
|
ident: ast::ident,
|
|
|
|
bm: ast::binding_mode) -> @ast::pat;
|
2013-07-05 05:15:21 -05:00
|
|
|
fn pat_enum(&self, span: span, path: ast::Path, subpats: ~[@ast::pat]) -> @ast::pat;
|
2013-05-19 00:53:42 -05:00
|
|
|
fn pat_struct(&self, span: span,
|
2013-07-05 05:15:21 -05:00
|
|
|
path: ast::Path, field_pats: ~[ast::field_pat]) -> @ast::pat;
|
2013-05-19 00:53:42 -05:00
|
|
|
|
|
|
|
fn arm(&self, span: span, pats: ~[@ast::pat], expr: @ast::expr) -> ast::arm;
|
|
|
|
fn arm_unreachable(&self, span: span) -> ast::arm;
|
|
|
|
|
|
|
|
fn expr_match(&self, span: span, arg: @ast::expr, arms: ~[ast::arm]) -> @ast::expr;
|
|
|
|
fn expr_if(&self, span: span,
|
|
|
|
cond: @ast::expr, then: @ast::expr, els: Option<@ast::expr>) -> @ast::expr;
|
|
|
|
|
|
|
|
fn lambda_fn_decl(&self, span: span, fn_decl: ast::fn_decl, blk: ast::blk) -> @ast::expr;
|
|
|
|
|
|
|
|
fn lambda(&self, span: span, ids: ~[ast::ident], blk: ast::blk) -> @ast::expr;
|
|
|
|
fn lambda0(&self, span: span, blk: ast::blk) -> @ast::expr;
|
|
|
|
fn lambda1(&self, span: span, blk: ast::blk, ident: ast::ident) -> @ast::expr;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
fn lambda_stmts(&self, span: span, ids: ~[ast::ident], blk: ~[@ast::stmt]) -> @ast::expr;
|
2013-05-15 17:55:57 -05:00
|
|
|
fn lambda_stmts_0(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr;
|
2013-05-19 00:53:42 -05:00
|
|
|
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-05-19 00:53:42 -05:00
|
|
|
fn item(&self, span: span,
|
2013-07-19 06:51:37 -05:00
|
|
|
name: ident, attrs: ~[ast::Attribute], node: ast::item_) -> @ast::item;
|
2013-05-15 17:55:57 -05:00
|
|
|
|
2013-07-05 23:57:11 -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-05-19 00:53:42 -05:00
|
|
|
span: span,
|
|
|
|
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,
|
|
|
|
body: ast::blk) -> @ast::item;
|
|
|
|
fn item_fn(&self,
|
2013-05-19 00:53:42 -05:00
|
|
|
span: span,
|
2013-05-17 08:51:25 -05:00
|
|
|
name: ident,
|
|
|
|
inputs: ~[ast::arg],
|
2013-07-05 23:57:11 -05:00
|
|
|
output: ast::Ty,
|
2013-05-17 08:51:25 -05:00
|
|
|
body: ast::blk) -> @ast::item;
|
|
|
|
|
2013-07-05 23:57:11 -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,
|
|
|
|
span: span,
|
2013-05-19 00:53:42 -05:00
|
|
|
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
|
|
|
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,
|
|
|
|
span: span,
|
2013-05-19 00:53:42 -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
|
|
|
fn item_struct(&self, span: span, name: ident, struct_def: ast::struct_def) -> @ast::item;
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn item_mod(&self, span: span,
|
2013-07-19 06:51:37 -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,
|
|
|
|
span: span,
|
2013-05-19 00:53:42 -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-07-05 23:57:11 -05:00
|
|
|
fn item_ty(&self, span: span, name: ident, ty: ast::Ty) -> @ast::item;
|
2013-05-17 09:19:28 -05:00
|
|
|
|
2013-07-19 06:51:37 -05:00
|
|
|
fn attribute(&self, sp: span, mi: @ast::MetaItem) -> ast::Attribute;
|
2013-05-17 09:19:28 -05:00
|
|
|
|
2013-07-19 06:51:37 -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-05-19 00:53:42 -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-05-19 00:53:42 -05:00
|
|
|
fn view_use_list(&self, sp: span, vis: ast::visibility,
|
2013-07-05 03:28:53 -05:00
|
|
|
path: ~[ast::ident], imports: &[ast::ident]) -> ast::view_item;
|
2013-05-19 00:53:42 -05:00
|
|
|
fn view_use_glob(&self, sp: span,
|
2013-07-05 03:28:53 -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-07-05 05:15:21 -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-07-05 05:15:21 -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-07-05 05:15:21 -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, ~[])
|
|
|
|
}
|
|
|
|
fn path_all(&self, sp: span,
|
|
|
|
global: bool,
|
|
|
|
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 {
|
|
|
|
ast::Path {
|
2013-05-19 00:53:42 -05:00
|
|
|
span: sp,
|
|
|
|
global: global,
|
|
|
|
idents: idents,
|
|
|
|
rp: rp,
|
|
|
|
types: types
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 23:57:11 -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-07-05 23:57:11 -05:00
|
|
|
fn ty(&self, span: span, ty: ast::ty_) -> ast::Ty {
|
|
|
|
ast::Ty {
|
2013-05-19 00:53:42 -05:00
|
|
|
id: self.next_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-06-17 14:16:30 -05:00
|
|
|
ast::ty_path(path, bounds, self.next_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-05-19 00:53:42 -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,
|
|
|
|
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-05-19 00:53:42 -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-07-05 23:57:11 -05:00
|
|
|
fn ty_uniq(&self, span: span, ty: ast::Ty) -> ast::Ty {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.ty(span, ast::ty_uniq(self.ty_mt(ty, ast::m_imm)))
|
|
|
|
}
|
|
|
|
fn ty_box(&self, span: span,
|
2013-07-05 23:57:11 -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-07-05 23:57:11 -05:00
|
|
|
fn ty_field_imm(&self, span: span, name: ident, ty: ast::Ty) -> ast::ty_field {
|
2013-05-19 00:53:42 -05:00
|
|
|
respan(span,
|
|
|
|
ast::ty_field_ {
|
|
|
|
ident: name,
|
2013-07-05 23:57:11 -05:00
|
|
|
mt: ast::mt { ty: ~ty, mutbl: ast::m_imm },
|
2013-05-19 00:53:42 -05:00
|
|
|
})
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-07-05 23:57:11 -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-05-15 17:55:57 -05:00
|
|
|
id: self.next_id(),
|
2013-05-17 08:51:25 -05:00
|
|
|
node: ast::ty_nil,
|
|
|
|
span: dummy_sp(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 20:38:56 -05:00
|
|
|
fn typaram(&self, id: ast::ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam {
|
2013-05-19 00:53:42 -05:00
|
|
|
ast::TyParam { ident: id, id: self.next_id(), bounds: bounds }
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
ref_id: self.next_id()
|
|
|
|
}
|
|
|
|
}
|
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-05-19 00:53:42 -05:00
|
|
|
fn lifetime(&self, span: span, ident: ast::ident) -> ast::Lifetime {
|
|
|
|
ast::Lifetime { id: self.next_id(), span: span, ident: ident }
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt {
|
|
|
|
@respan(expr.span, ast::stmt_semi(expr, self.next_id()))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn stmt_let(&self, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt {
|
|
|
|
let pat = self.pat_ident(sp, ident);
|
|
|
|
let local = @respan(sp,
|
|
|
|
ast::local_ {
|
|
|
|
is_mutbl: mutbl,
|
|
|
|
ty: self.ty_infer(sp),
|
|
|
|
pat: pat,
|
|
|
|
init: Some(ex),
|
|
|
|
id: self.next_id(),
|
|
|
|
});
|
2013-06-04 23:43:41 -05:00
|
|
|
let decl = respan(sp, ast::decl_local(local));
|
2013-05-19 00:53:42 -05:00
|
|
|
@respan(sp, ast::stmt_decl(@decl, self.next_id()))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-17 08:51:25 -05:00
|
|
|
fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@expr>) -> ast::blk {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.blk_all(span, ~[], stmts, expr)
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-17 08:51:25 -05:00
|
|
|
fn blk_expr(&self, expr: @ast::expr) -> ast::blk {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.blk_all(expr.span, ~[], ~[], Some(expr))
|
|
|
|
}
|
|
|
|
fn blk_all(&self,
|
|
|
|
span: span,
|
2013-07-05 03:28:53 -05:00
|
|
|
view_items: ~[ast::view_item],
|
2013-05-19 00:53:42 -05:00
|
|
|
stmts: ~[@ast::stmt],
|
|
|
|
expr: Option<@ast::expr>) -> ast::blk {
|
2013-07-16 13:08:35 -05:00
|
|
|
ast::blk {
|
|
|
|
view_items: view_items,
|
|
|
|
stmts: stmts,
|
|
|
|
expr: expr,
|
|
|
|
id: self.next_id(),
|
|
|
|
rules: ast::default_blk,
|
|
|
|
span: span,
|
|
|
|
}
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn expr(&self, span: span, node: ast::expr_) -> @ast::expr {
|
|
|
|
@ast::expr {
|
|
|
|
id: self.next_id(),
|
|
|
|
node: node,
|
|
|
|
span: span,
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 05:15:21 -05:00
|
|
|
fn expr_path(&self, path: ast::Path) -> @ast::expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr(path.span, ast::expr_path(path))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn expr_ident(&self, span: span, id: ast::ident) -> @ast::expr {
|
|
|
|
self.expr_path(self.path_ident(span, id))
|
|
|
|
}
|
|
|
|
fn expr_self(&self, span: span) -> @ast::expr {
|
|
|
|
self.expr(span, ast::expr_self)
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn expr_binary(&self, sp: span, op: ast::binop,
|
|
|
|
lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr {
|
2013-06-01 17:31:56 -05:00
|
|
|
self.expr(sp, ast::expr_binary(self.next_id(), op, lhs, rhs))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn expr_deref(&self, sp: span, e: @ast::expr) -> @ast::expr {
|
|
|
|
self.expr_unary(sp, ast::deref, e)
|
|
|
|
}
|
|
|
|
fn expr_unary(&self, sp: span, op: ast::unop, e: @ast::expr)
|
|
|
|
-> @ast::expr {
|
2013-06-01 17:31:56 -05:00
|
|
|
self.expr(sp, ast::expr_unary(self.next_id(), op, e))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn expr_managed(&self, sp: span, e: @ast::expr) -> @ast::expr {
|
|
|
|
self.expr_unary(sp, ast::box(ast::m_imm), e)
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn expr_field_access(&self, sp: span, expr: @ast::expr, ident: ast::ident) -> @ast::expr {
|
|
|
|
self.expr(sp, ast::expr_field(expr, ident, ~[]))
|
|
|
|
}
|
|
|
|
fn expr_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr {
|
|
|
|
self.expr(sp, ast::expr_addr_of(ast::m_imm, e))
|
|
|
|
}
|
|
|
|
fn expr_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr {
|
|
|
|
self.expr(sp, ast::expr_addr_of(ast::m_mutbl, e))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn expr_call(&self, span: span, expr: @ast::expr, args: ~[@ast::expr]) -> @ast::expr {
|
|
|
|
self.expr(span, ast::expr_call(expr, args, ast::NoSugar))
|
|
|
|
}
|
|
|
|
fn expr_call_ident(&self, span: span, id: ast::ident, args: ~[@ast::expr]) -> @ast::expr {
|
|
|
|
self.expr(span,
|
|
|
|
ast::expr_call(self.expr_ident(span, id), args, ast::NoSugar))
|
|
|
|
}
|
|
|
|
fn expr_call_global(&self, sp: span, fn_path: ~[ast::ident],
|
|
|
|
args: ~[@ast::expr]) -> @ast::expr {
|
|
|
|
let pathexpr = self.expr_path(self.path_global(sp, fn_path));
|
|
|
|
self.expr_call(sp, pathexpr, args)
|
|
|
|
}
|
|
|
|
fn expr_method_call(&self, span: span,
|
|
|
|
expr: @ast::expr,
|
|
|
|
ident: ast::ident,
|
|
|
|
args: ~[@ast::expr]) -> @ast::expr {
|
2013-05-15 17:55:57 -05:00
|
|
|
self.expr(span,
|
2013-06-01 17:31:56 -05:00
|
|
|
ast::expr_method_call(self.next_id(), expr, ident, ~[], args, ast::NoSugar))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-05-17 08:51:25 -05:00
|
|
|
fn expr_blk(&self, b: ast::blk) -> @ast::expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr(b.span, ast::expr_block(b))
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
2013-05-19 00:53:42 -05:00
|
|
|
fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field {
|
2013-05-23 21:47:38 -05:00
|
|
|
respan(span, ast::field_ { ident: name, expr: e })
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
2013-07-05 05:15:21 -05:00
|
|
|
fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::field]) -> @ast::expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr(span, ast::expr_struct(path, fields, None))
|
|
|
|
}
|
|
|
|
fn expr_struct_ident(&self, span: span,
|
|
|
|
id: ast::ident, fields: ~[ast::field]) -> @ast::expr {
|
|
|
|
self.expr_struct(span, self.path_ident(span, id), fields)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn expr_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr {
|
|
|
|
self.expr(sp, ast::expr_lit(@respan(sp, lit)))
|
|
|
|
}
|
|
|
|
fn expr_uint(&self, span: span, i: uint) -> @ast::expr {
|
|
|
|
self.expr_lit(span, ast::lit_uint(i as u64, ast::ty_u))
|
|
|
|
}
|
|
|
|
fn expr_int(&self, sp: span, i: int) -> @ast::expr {
|
|
|
|
self.expr_lit(sp, ast::lit_int(i as i64, ast::ty_i))
|
|
|
|
}
|
|
|
|
fn expr_u8(&self, sp: span, u: u8) -> @ast::expr {
|
|
|
|
self.expr_lit(sp, ast::lit_uint(u as u64, ast::ty_u8))
|
|
|
|
}
|
|
|
|
fn expr_bool(&self, sp: span, value: bool) -> @ast::expr {
|
|
|
|
self.expr_lit(sp, ast::lit_bool(value))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn expr_vstore(&self, sp: span, expr: @ast::expr, vst: ast::expr_vstore) -> @ast::expr {
|
|
|
|
self.expr(sp, ast::expr_vstore(expr, vst))
|
|
|
|
}
|
|
|
|
fn expr_vec(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr {
|
|
|
|
self.expr(sp, ast::expr_vec(exprs, ast::m_imm))
|
|
|
|
}
|
|
|
|
fn expr_vec_uniq(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr {
|
|
|
|
self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::expr_vstore_uniq)
|
|
|
|
}
|
|
|
|
fn expr_vec_slice(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr {
|
|
|
|
self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::expr_vstore_slice)
|
|
|
|
}
|
2013-06-12 12:02:55 -05:00
|
|
|
fn expr_str(&self, sp: span, s: @str) -> @ast::expr {
|
|
|
|
self.expr_lit(sp, ast::lit_str(s))
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
2013-06-12 12:02:55 -05:00
|
|
|
fn expr_str_uniq(&self, sp: span, s: @str) -> @ast::expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr_vstore(sp, self.expr_str(sp, s), ast::expr_vstore_uniq)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn expr_unreachable(&self, span: span) -> @ast::expr {
|
|
|
|
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-06-12 12:02:55 -05:00
|
|
|
self.expr_str(span, @"internal error: entered unreachable code"),
|
|
|
|
self.expr_str(span, loc.file.name),
|
2013-05-19 00:53:42 -05:00
|
|
|
self.expr_uint(span, loc.line),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn pat(&self, span: span, pat: ast::pat_) -> @ast::pat {
|
|
|
|
@ast::pat { id: self.next_id(), node: pat, span: span }
|
|
|
|
}
|
|
|
|
fn pat_wild(&self, span: span) -> @ast::pat {
|
|
|
|
self.pat(span, ast::pat_wild)
|
|
|
|
}
|
|
|
|
fn pat_lit(&self, span: span, expr: @ast::expr) -> @ast::pat {
|
|
|
|
self.pat(span, ast::pat_lit(expr))
|
|
|
|
}
|
|
|
|
fn pat_ident(&self, span: span, ident: ast::ident) -> @ast::pat {
|
2013-05-29 18:59:33 -05:00
|
|
|
self.pat_ident_binding_mode(span, ident, ast::bind_infer)
|
2013-05-19 00:53:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn pat_ident_binding_mode(&self,
|
|
|
|
span: span,
|
|
|
|
ident: ast::ident,
|
|
|
|
bm: ast::binding_mode) -> @ast::pat {
|
|
|
|
let path = self.path_ident(span, ident);
|
|
|
|
let pat = ast::pat_ident(bm, path, None);
|
|
|
|
self.pat(span, pat)
|
|
|
|
}
|
2013-07-05 05:15:21 -05:00
|
|
|
fn pat_enum(&self, span: span, path: ast::Path, subpats: ~[@ast::pat]) -> @ast::pat {
|
2013-05-19 00:53:42 -05:00
|
|
|
let pat = ast::pat_enum(path, Some(subpats));
|
|
|
|
self.pat(span, pat)
|
|
|
|
}
|
|
|
|
fn pat_struct(&self, span: span,
|
2013-07-05 05:15:21 -05:00
|
|
|
path: ast::Path, field_pats: ~[ast::field_pat]) -> @ast::pat {
|
2013-05-19 00:53:42 -05:00
|
|
|
let pat = ast::pat_struct(path, field_pats, false);
|
|
|
|
self.pat(span, pat)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn arm(&self, _span: span, pats: ~[@ast::pat], expr: @ast::expr) -> ast::arm {
|
|
|
|
ast::arm {
|
|
|
|
pats: pats,
|
|
|
|
guard: None,
|
|
|
|
body: self.blk_expr(expr)
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn arm_unreachable(&self, span: span) -> ast::arm {
|
|
|
|
self.arm(span, ~[self.pat_wild(span)], self.expr_unreachable(span))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn expr_match(&self, span: span, arg: @ast::expr, arms: ~[ast::arm]) -> @expr {
|
|
|
|
self.expr(span, ast::expr_match(arg, arms))
|
|
|
|
}
|
2013-05-17 08:51:25 -05:00
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn expr_if(&self, span: span,
|
|
|
|
cond: @ast::expr, then: @ast::expr, els: Option<@ast::expr>) -> @ast::expr {
|
|
|
|
let els = els.map(|x| self.expr_blk(self.blk_expr(*x)));
|
|
|
|
self.expr(span, ast::expr_if(cond, self.blk_expr(then), els))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lambda_fn_decl(&self, span: span, fn_decl: ast::fn_decl, blk: ast::blk) -> @ast::expr {
|
|
|
|
self.expr(span, ast::expr_fn_block(fn_decl, blk))
|
|
|
|
}
|
|
|
|
fn lambda(&self, span: span, ids: ~[ast::ident], blk: ast::blk) -> @ast::expr {
|
|
|
|
let fn_decl = self.fn_decl(
|
|
|
|
ids.map(|id| self.arg(span, *id, self.ty_infer(span))),
|
|
|
|
self.ty_infer(span));
|
|
|
|
|
|
|
|
self.expr(span, ast::expr_fn_block(fn_decl, blk))
|
|
|
|
}
|
|
|
|
fn lambda0(&self, _span: span, blk: ast::blk) -> @ast::expr {
|
2013-05-17 08:51:25 -05:00
|
|
|
let ext_cx = *self;
|
2013-07-02 14:47:32 -05:00
|
|
|
let blk_e = self.expr(blk.span, ast::expr_block(blk.clone()));
|
2013-05-19 00:53:42 -05:00
|
|
|
quote_expr!(|| $blk_e )
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn lambda1(&self, _span: span, blk: ast::blk, ident: ast::ident) -> @ast::expr {
|
2013-05-17 08:51:25 -05:00
|
|
|
let ext_cx = *self;
|
2013-07-02 14:47:32 -05:00
|
|
|
let blk_e = self.expr(blk.span, ast::expr_block(blk.clone()));
|
2013-05-19 00:53:42 -05:00
|
|
|
quote_expr!(|$ident| $blk_e )
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn lambda_expr(&self, span: span, ids: ~[ast::ident], expr: @ast::expr) -> @ast::expr {
|
|
|
|
self.lambda(span, ids, self.blk_expr(expr))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-05-19 00:53:42 -05:00
|
|
|
fn lambda_expr_0(&self, span: span, expr: @ast::expr) -> @ast::expr {
|
|
|
|
self.lambda0(span, self.blk_expr(expr))
|
|
|
|
}
|
|
|
|
fn lambda_expr_1(&self, span: span, expr: @ast::expr, ident: ast::ident) -> @ast::expr {
|
|
|
|
self.lambda1(span, self.blk_expr(expr), ident)
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn lambda_stmts(&self, span: span, ids: ~[ast::ident], stmts: ~[@ast::stmt]) -> @ast::expr {
|
|
|
|
self.lambda(span, ids, self.blk(span, stmts, None))
|
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
fn lambda_stmts_0(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr {
|
2013-05-19 00:53:42 -05:00
|
|
|
self.lambda0(span, self.blk(span, stmts, None))
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|
2013-05-19 00:53:42 -05:00
|
|
|
fn lambda_stmts_1(&self, span: span, stmts: ~[@ast::stmt], ident: ast::ident) -> @ast::expr {
|
|
|
|
self.lambda1(span, self.blk(span, stmts, None), ident)
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-07-05 23:57:11 -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,
|
|
|
|
id: self.next_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-05-19 00:53:42 -05:00
|
|
|
fn item(&self, span: span,
|
2013-07-19 06:51:37 -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-05-17 09:19:28 -05:00
|
|
|
id: self.next_id(),
|
|
|
|
node: node,
|
|
|
|
vis: ast::public,
|
|
|
|
span: span }
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn item_fn_poly(&self,
|
|
|
|
span: span,
|
|
|
|
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,
|
|
|
|
body: ast::blk) -> @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-05-19 00:53:42 -05:00
|
|
|
span: span,
|
2013-05-17 08:51:25 -05:00
|
|
|
name: ident,
|
|
|
|
inputs: ~[ast::arg],
|
2013-07-05 23:57:11 -05:00
|
|
|
output: ast::Ty,
|
2013-05-17 08:51:25 -05:00
|
|
|
body: ast::blk
|
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-07-05 23:57:11 -05:00
|
|
|
fn variant(&self, span: span, name: ident, tys: ~[ast::Ty]) -> ast::variant {
|
|
|
|
let args = tys.consume_iter().transform(|ty| {
|
|
|
|
ast::variant_arg { ty: ty, id: self.next_id() }
|
|
|
|
}).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),
|
|
|
|
id: self.next_id(),
|
|
|
|
disr_expr: None,
|
|
|
|
vis: ast::public
|
|
|
|
})
|
2013-05-17 08:51:25 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -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-05-19 00:53:42 -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-05-17 08:51:25 -05:00
|
|
|
span: span,
|
2013-05-19 00:53:42 -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,
|
|
|
|
span: span,
|
2013-05-19 00:53:42 -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-05-19 00:53:42 -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-07-05 23:57:11 -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-07-05 23:57:11 -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-07-19 06:51:37 -05:00
|
|
|
fn attribute(&self, sp: span, mi: @ast::MetaItem) -> ast::Attribute {
|
|
|
|
respan(sp, ast::Attribute_ {
|
|
|
|
style: ast::AttrOuter,
|
|
|
|
value: mi,
|
|
|
|
is_sugared_doc: false,
|
|
|
|
})
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
|
|
|
|
2013-07-19 06:51:37 -05:00
|
|
|
fn meta_word(&self, sp: span, w: @str) -> @ast::MetaItem {
|
|
|
|
@respan(sp, ast::MetaWord(w))
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
2013-07-19 06:51:37 -05:00
|
|
|
fn meta_list(&self, sp: span, name: @str, mis: ~[@ast::MetaItem]) -> @ast::MetaItem {
|
|
|
|
@respan(sp, ast::MetaList(name, mis))
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
2013-07-19 06:51:37 -05:00
|
|
|
fn meta_name_value(&self, sp: span, name: @str, value: ast::lit_) -> @ast::MetaItem {
|
|
|
|
@respan(sp, ast::MetaNameValue(name, respan(sp, value)))
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -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-05-19 00:53:42 -05:00
|
|
|
fn view_use_list(&self, sp: span, vis: ast::visibility,
|
2013-07-05 03:28:53 -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| {
|
|
|
|
respan(sp, ast::path_list_ident_ { name: *id, id: self.next_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,
|
|
|
|
self.next_id()))])
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
|
|
|
|
2013-05-19 00:53:42 -05:00
|
|
|
fn view_use_glob(&self, sp: span,
|
2013-07-05 03:28:53 -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,
|
|
|
|
ast::view_path_glob(self.path(sp, path), self.next_id()))])
|
2013-05-17 09:19:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 = fold::default_ast_fold();
|
|
|
|
let folder = @fold::AstFoldFns {
|
|
|
|
new_id: |_| cx.next_id(),
|
|
|
|
..*folder
|
|
|
|
};
|
|
|
|
let folder = fold::make_fold(folder);
|
|
|
|
folder.fold_expr(*self)
|
|
|
|
}
|
2013-05-15 17:55:57 -05:00
|
|
|
}
|