From 6e5051553050974eb9362e1465cc2d40e2c9a610 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 18 May 2013 00:19:28 +1000 Subject: [PATCH] syntax/ext: migrate build.rs functions to AstBuilder methods. --- src/libsyntax/ext/build.rs | 1330 ++++++++++++-------- src/libsyntax/ext/bytes.rs | 12 +- src/libsyntax/ext/deriving/clone.rs | 9 +- src/libsyntax/ext/deriving/cmp/eq.rs | 6 +- src/libsyntax/ext/deriving/cmp/ord.rs | 24 +- src/libsyntax/ext/deriving/cmp/totaleq.rs | 4 +- src/libsyntax/ext/deriving/cmp/totalord.rs | 6 +- src/libsyntax/ext/deriving/decodable.rs | 168 ++- src/libsyntax/ext/deriving/encodable.rs | 131 +- src/libsyntax/ext/deriving/generic.rs | 34 +- src/libsyntax/ext/deriving/iter_bytes.rs | 8 +- src/libsyntax/ext/deriving/mod.rs | 52 +- src/libsyntax/ext/deriving/rand.rs | 40 +- src/libsyntax/ext/deriving/to_str.rs | 6 +- src/libsyntax/ext/deriving/ty.rs | 36 +- src/libsyntax/ext/env.rs | 6 +- src/libsyntax/ext/fmt.rs | 41 +- src/libsyntax/ext/quote.rs | 120 +- src/libsyntax/ext/source_util.rs | 18 +- 19 files changed, 1126 insertions(+), 925 deletions(-) diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index a2d88c1f23a..eb48ed58375 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -25,525 +25,6 @@ pub struct Field { ex: @ast::expr } -pub fn mk_expr(cx: @ExtCtxt, - sp: codemap::span, - expr: ast::expr_) - -> @ast::expr { - @ast::expr { - id: cx.next_id(), - callee_id: cx.next_id(), - node: expr, - span: sp, - } -} - -pub fn mk_lit(cx: @ExtCtxt, sp: span, lit: ast::lit_) -> @ast::expr { - let sp_lit = @codemap::spanned { node: lit, span: sp }; - mk_expr(cx, sp, ast::expr_lit(sp_lit)) -} -pub fn mk_int(cx: @ExtCtxt, sp: span, i: int) -> @ast::expr { - let lit = ast::lit_int(i as i64, ast::ty_i); - return mk_lit(cx, sp, lit); -} -pub fn mk_uint(cx: @ExtCtxt, sp: span, u: uint) -> @ast::expr { - let lit = ast::lit_uint(u as u64, ast::ty_u); - return mk_lit(cx, sp, lit); -} -pub fn mk_u8(cx: @ExtCtxt, sp: span, u: u8) -> @ast::expr { - let lit = ast::lit_uint(u as u64, ast::ty_u8); - return mk_lit(cx, sp, lit); -} -pub fn mk_binary(cx: @ExtCtxt, sp: span, op: ast::binop, - lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr { - cx.next_id(); // see ast_util::op_expr_callee_id - mk_expr(cx, sp, ast::expr_binary(op, lhs, rhs)) -} - -pub fn mk_deref(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - mk_unary(cx, sp, ast::deref, e) -} -pub fn mk_unary(cx: @ExtCtxt, sp: span, op: ast::unop, e: @ast::expr) - -> @ast::expr { - cx.next_id(); // see ast_util::op_expr_callee_id - mk_expr(cx, sp, ast::expr_unary(op, e)) -} -pub fn mk_raw_path(sp: span, idents: ~[ast::ident]) -> @ast::Path { - mk_raw_path_(sp, idents, None, ~[]) -} -pub fn mk_raw_path_(sp: span, - idents: ~[ast::ident], - rp: Option<@ast::Lifetime>, - types: ~[@ast::Ty]) - -> @ast::Path { - @ast::Path { span: sp, - global: false, - idents: idents, - rp: rp, - types: types } -} -pub fn mk_raw_path_global(sp: span, idents: ~[ast::ident]) -> @ast::Path { - mk_raw_path_global_(sp, idents, None, ~[]) -} -pub fn mk_raw_path_global_(sp: span, - idents: ~[ast::ident], - rp: Option<@ast::Lifetime>, - types: ~[@ast::Ty]) -> @ast::Path { - @ast::Path { span: sp, - global: true, - idents: idents, - rp: rp, - types: types } -} -pub fn mk_path_raw(cx: @ExtCtxt, sp: span, path: @ast::Path)-> @ast::expr { - mk_expr(cx, sp, ast::expr_path(path)) -} -pub fn mk_path(cx: @ExtCtxt, sp: span, idents: ~[ast::ident]) - -> @ast::expr { - mk_path_raw(cx, sp, mk_raw_path(sp, idents)) -} -pub fn mk_path_global(cx: @ExtCtxt, sp: span, idents: ~[ast::ident]) - -> @ast::expr { - mk_path_raw(cx, sp, mk_raw_path_global(sp, idents)) -} -pub fn mk_access_(cx: @ExtCtxt, sp: span, p: @ast::expr, m: ast::ident) - -> @ast::expr { - mk_expr(cx, sp, ast::expr_field(p, m, ~[])) -} -pub fn mk_access(cx: @ExtCtxt, sp: span, p: ~[ast::ident], m: ast::ident) - -> @ast::expr { - let pathexpr = mk_path(cx, sp, p); - return mk_access_(cx, sp, pathexpr, m); -} -pub fn mk_addr_of(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - return mk_expr(cx, sp, ast::expr_addr_of(ast::m_imm, e)); -} -pub fn mk_mut_addr_of(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - return mk_expr(cx, sp, ast::expr_addr_of(ast::m_mutbl, e)); -} -pub fn mk_method_call(cx: @ExtCtxt, - sp: span, - rcvr_expr: @ast::expr, - method_ident: ast::ident, - args: ~[@ast::expr]) -> @ast::expr { - mk_expr(cx, sp, ast::expr_method_call(rcvr_expr, method_ident, ~[], args, ast::NoSugar)) -} -pub fn mk_call_(cx: @ExtCtxt, sp: span, fn_expr: @ast::expr, - args: ~[@ast::expr]) -> @ast::expr { - mk_expr(cx, sp, ast::expr_call(fn_expr, args, ast::NoSugar)) -} -pub fn mk_call(cx: @ExtCtxt, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr { - let pathexpr = mk_path(cx, sp, fn_path); - return mk_call_(cx, sp, pathexpr, args); -} -pub fn mk_call_global(cx: @ExtCtxt, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr { - let pathexpr = mk_path_global(cx, sp, fn_path); - return mk_call_(cx, sp, pathexpr, args); -} -// e = expr, t = type -pub fn mk_base_vec_e(cx: @ExtCtxt, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr { - let vecexpr = ast::expr_vec(exprs, ast::m_imm); - mk_expr(cx, sp, vecexpr) -} -pub fn mk_vstore_e(cx: @ExtCtxt, sp: span, expr: @ast::expr, - vst: ast::expr_vstore) -> - @ast::expr { - mk_expr(cx, sp, ast::expr_vstore(expr, vst)) -} -pub fn mk_uniq_vec_e(cx: @ExtCtxt, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr { - mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_uniq) -} -pub fn mk_slice_vec_e(cx: @ExtCtxt, sp: span, exprs: ~[@ast::expr]) - -> @ast::expr { - mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), - ast::expr_vstore_slice) -} -pub fn mk_base_str(cx: @ExtCtxt, sp: span, s: ~str) -> @ast::expr { - let lit = ast::lit_str(@s); - return mk_lit(cx, sp, lit); -} -pub fn mk_uniq_str(cx: @ExtCtxt, sp: span, s: ~str) -> @ast::expr { - mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::expr_vstore_uniq) -} -pub fn mk_field(sp: span, f: &Field) -> ast::field { - codemap::spanned { - node: ast::field_ { mutbl: ast::m_imm, ident: f.ident, expr: f.ex }, - span: sp, - } -} -pub fn mk_fields(sp: span, fields: ~[Field]) -> ~[ast::field] { - fields.map(|f| mk_field(sp, f)) -} -pub fn mk_struct_e(cx: @ExtCtxt, - sp: span, - ctor_path: ~[ast::ident], - fields: ~[Field]) - -> @ast::expr { - mk_expr(cx, sp, - ast::expr_struct(mk_raw_path(sp, ctor_path), - mk_fields(sp, fields), - option::None::<@ast::expr>)) -} -pub fn mk_global_struct_e(cx: @ExtCtxt, - sp: span, - ctor_path: ~[ast::ident], - fields: ~[Field]) - -> @ast::expr { - mk_expr(cx, sp, - ast::expr_struct(mk_raw_path_global(sp, ctor_path), - mk_fields(sp, fields), - option::None::<@ast::expr>)) -} -pub fn mk_glob_use(cx: @ExtCtxt, - sp: span, - vis: ast::visibility, - path: ~[ast::ident]) -> @ast::view_item { - let glob = @codemap::spanned { - node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()), - span: sp, - }; - @ast::view_item { node: ast::view_item_use(~[glob]), - attrs: ~[], - vis: vis, - span: sp } -} -pub fn mk_local(cx: @ExtCtxt, sp: span, mutbl: bool, - ident: ast::ident, ex: @ast::expr) -> @ast::stmt { - - let pat = @ast::pat { - id: cx.next_id(), - node: ast::pat_ident( - ast::bind_by_copy, - mk_raw_path(sp, ~[ident]), - None), - span: sp, - }; - let ty = @ast::Ty { id: cx.next_id(), node: ast::ty_infer, span: sp }; - let local = @codemap::spanned { - node: ast::local_ { - is_mutbl: mutbl, - ty: ty, - pat: pat, - init: Some(ex), - id: cx.next_id(), - }, - span: sp, - }; - let decl = codemap::spanned {node: ast::decl_local(~[local]), span: sp}; - @codemap::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp } -} -pub fn mk_block(cx: @ExtCtxt, span: span, - view_items: ~[@ast::view_item], - stmts: ~[@ast::stmt], - expr: Option<@ast::expr>) -> @ast::expr { - let blk = codemap::spanned { - node: ast::blk_ { - view_items: view_items, - stmts: stmts, - expr: expr, - id: cx.next_id(), - rules: ast::default_blk, - }, - span: span, - }; - mk_expr(cx, span, ast::expr_block(blk)) -} -pub fn mk_block_(cx: @ExtCtxt, - span: span, - stmts: ~[@ast::stmt]) - -> ast::blk { - codemap::spanned { - node: ast::blk_ { - view_items: ~[], - stmts: stmts, - expr: None, - id: cx.next_id(), - rules: ast::default_blk, - }, - span: span, - } -} -pub fn mk_simple_block(cx: @ExtCtxt, - span: span, - expr: @ast::expr) - -> ast::blk { - codemap::spanned { - node: ast::blk_ { - view_items: ~[], - stmts: ~[], - expr: Some(expr), - id: cx.next_id(), - rules: ast::default_blk, - }, - span: span, - } -} -pub fn mk_lambda_(cx: @ExtCtxt, - span: span, - fn_decl: ast::fn_decl, - blk: ast::blk) - -> @ast::expr { - mk_expr(cx, span, ast::expr_fn_block(fn_decl, blk)) -} -pub fn mk_lambda(cx: @ExtCtxt, - span: span, - fn_decl: ast::fn_decl, - expr: @ast::expr) - -> @ast::expr { - let blk = mk_simple_block(cx, span, expr); - mk_lambda_(cx, span, fn_decl, blk) -} -pub fn mk_lambda_stmts(cx: @ExtCtxt, - span: span, - fn_decl: ast::fn_decl, - stmts: ~[@ast::stmt]) - -> @ast::expr { - let blk = mk_block(cx, span, ~[], stmts, None); - mk_lambda(cx, span, fn_decl, blk) -} -pub fn mk_lambda_no_args(cx: @ExtCtxt, - span: span, - expr: @ast::expr) - -> @ast::expr { - let fn_decl = mk_fn_decl(~[], mk_ty_infer(cx, span)); - mk_lambda(cx, span, fn_decl, expr) -} -pub fn mk_copy(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - mk_expr(cx, sp, ast::expr_copy(e)) -} -pub fn mk_managed(cx: @ExtCtxt, sp: span, e: @ast::expr) -> @ast::expr { - mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e)) -} -pub fn mk_pat(cx: @ExtCtxt, span: span, pat: ast::pat_) -> @ast::pat { - @ast::pat { id: cx.next_id(), node: pat, span: span } -} -pub fn mk_pat_wild(cx: @ExtCtxt, span: span) -> @ast::pat { - mk_pat(cx, span, ast::pat_wild) -} -pub fn mk_pat_lit(cx: @ExtCtxt, - span: span, - expr: @ast::expr) -> @ast::pat { - mk_pat(cx, span, ast::pat_lit(expr)) -} -pub fn mk_pat_ident(cx: @ExtCtxt, - span: span, - ident: ast::ident) -> @ast::pat { - mk_pat_ident_with_binding_mode(cx, span, ident, ast::bind_by_copy) -} - -pub fn mk_pat_ident_with_binding_mode(cx: @ExtCtxt, - span: span, - ident: ast::ident, - bm: ast::binding_mode) -> @ast::pat { - let path = mk_raw_path(span, ~[ ident ]); - let pat = ast::pat_ident(bm, path, None); - mk_pat(cx, span, pat) -} -pub fn mk_pat_enum(cx: @ExtCtxt, - span: span, - path: @ast::Path, - subpats: ~[@ast::pat]) - -> @ast::pat { - let pat = ast::pat_enum(path, Some(subpats)); - mk_pat(cx, span, pat) -} -pub fn mk_pat_struct(cx: @ExtCtxt, - span: span, - path: @ast::Path, - field_pats: ~[ast::field_pat]) - -> @ast::pat { - let pat = ast::pat_struct(path, field_pats, false); - mk_pat(cx, span, pat) -} -pub fn mk_bool(cx: @ExtCtxt, span: span, value: bool) -> @ast::expr { - let lit_expr = ast::expr_lit(@codemap::spanned { - node: ast::lit_bool(value), - span: span }); - build::mk_expr(cx, span, lit_expr) -} -pub fn mk_stmt(cx: @ExtCtxt, span: span, expr: @ast::expr) -> @ast::stmt { - let stmt_ = ast::stmt_semi(expr, cx.next_id()); - @codemap::spanned { node: stmt_, span: span } -} - -pub fn mk_ty_mt(ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt { - ast::mt { - ty: ty, - mutbl: mutbl - } -} - -pub fn mk_ty(cx: @ExtCtxt, - span: span, - ty: ast::ty_) -> @ast::Ty { - @ast::Ty { - id: cx.next_id(), - span: span, - node: ty - } -} - -pub fn mk_ty_path(cx: @ExtCtxt, - span: span, - idents: ~[ ast::ident ]) - -> @ast::Ty { - let ty = build::mk_raw_path(span, idents); - mk_ty_path_path(cx, span, ty) -} - -pub fn mk_ty_path_global(cx: @ExtCtxt, - span: span, - idents: ~[ ast::ident ]) - -> @ast::Ty { - let ty = build::mk_raw_path_global(span, idents); - mk_ty_path_path(cx, span, ty) -} - -pub fn mk_ty_path_path(cx: @ExtCtxt, - span: span, - path: @ast::Path) - -> @ast::Ty { - let ty = ast::ty_path(path, cx.next_id()); - mk_ty(cx, span, ty) -} - -pub fn mk_ty_rptr(cx: @ExtCtxt, - span: span, - ty: @ast::Ty, - lifetime: Option<@ast::Lifetime>, - mutbl: ast::mutability) - -> @ast::Ty { - mk_ty(cx, span, - ast::ty_rptr(lifetime, mk_ty_mt(ty, mutbl))) -} -pub fn mk_ty_uniq(cx: @ExtCtxt, span: span, ty: @ast::Ty) -> @ast::Ty { - mk_ty(cx, span, ast::ty_uniq(mk_ty_mt(ty, ast::m_imm))) -} -pub fn mk_ty_box(cx: @ExtCtxt, span: span, - ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty { - mk_ty(cx, span, ast::ty_box(mk_ty_mt(ty, mutbl))) -} - - - -pub fn mk_ty_infer(cx: @ExtCtxt, span: span) -> @ast::Ty { - mk_ty(cx, span, ast::ty_infer) -} -pub fn mk_trait_ref_global(cx: @ExtCtxt, - span: span, - idents: ~[ ast::ident ]) - -> @ast::trait_ref -{ - mk_trait_ref_(cx, build::mk_raw_path_global(span, idents)) -} -pub fn mk_trait_ref_(cx: @ExtCtxt, path: @ast::Path) -> @ast::trait_ref { - @ast::trait_ref { - path: path, - ref_id: cx.next_id() - } -} -pub fn mk_simple_ty_path(cx: @ExtCtxt, - span: span, - ident: ast::ident) - -> @ast::Ty { - mk_ty_path(cx, span, ~[ ident ]) -} -pub fn mk_arg(cx: @ExtCtxt, - span: span, - ident: ast::ident, - ty: @ast::Ty) - -> ast::arg { - let arg_pat = mk_pat_ident(cx, span, ident); - ast::arg { - is_mutbl: false, - ty: ty, - pat: arg_pat, - id: cx.next_id() - } -} -pub fn mk_fn_decl(inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl { - ast::fn_decl { inputs: inputs, output: output, cf: ast::return_val } -} -pub fn mk_trait_ty_param_bound_global(cx: @ExtCtxt, - span: span, - idents: ~[ast::ident]) - -> ast::TyParamBound { - ast::TraitTyParamBound(mk_trait_ref_global(cx, span, idents)) -} -pub fn mk_trait_ty_param_bound_(cx: @ExtCtxt, - path: @ast::Path) -> ast::TyParamBound { - ast::TraitTyParamBound(mk_trait_ref_(cx, path)) -} -pub fn mk_ty_param(cx: @ExtCtxt, - ident: ast::ident, - bounds: @OptVec) - -> ast::TyParam { - ast::TyParam { ident: ident, id: cx.next_id(), bounds: bounds } -} -pub fn mk_lifetime(cx: @ExtCtxt, - span: span, - ident: ast::ident) - -> ast::Lifetime { - ast::Lifetime { id: cx.next_id(), span: span, ident: ident } -} -pub fn mk_arm(cx: @ExtCtxt, - span: span, - pats: ~[@ast::pat], - expr: @ast::expr) - -> ast::arm { - ast::arm { - pats: pats, - guard: None, - body: mk_simple_block(cx, span, expr) - } -} -pub fn mk_unreachable(cx: @ExtCtxt, span: span) -> @ast::expr { - let loc = cx.codemap().lookup_char_pos(span.lo); - mk_call_global( - cx, - span, - ~[ - cx.ident_of("core"), - cx.ident_of("sys"), - cx.ident_of("FailWithCause"), - cx.ident_of("fail_with"), - ], - ~[ - mk_base_str(cx, span, ~"internal error: entered unreachable code"), - mk_base_str(cx, span, copy loc.file.name), - mk_uint(cx, span, loc.line), - ] - ) -} -pub fn mk_unreachable_arm(cx: @ExtCtxt, span: span) -> ast::arm { - mk_arm(cx, span, ~[mk_pat_wild(cx, span)], mk_unreachable(cx, span)) -} - -pub fn make_self(cx: @ExtCtxt, span: span) -> @ast::expr { - build::mk_expr(cx, span, ast::expr_self) -} - -// -// Duplication functions -// -// These functions just duplicate AST nodes. -// - -pub fn duplicate_expr(cx: @ExtCtxt, expr: @ast::expr) -> @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(expr) -} - - - // Transitional reexports so qquote can find the paths it is looking for mod syntax { pub use ext; @@ -555,12 +36,12 @@ pub trait AstBuilder { fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; fn path_tps(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) - -> @ast::Path; + -> @ast::Path; fn path_tps_global(&self, span: span, strs: ~[ast::ident], tps: ~[@ast::Ty]) - -> @ast::Path; + -> @ast::Path; // types fn ty_path(&self, @ast::Path) -> @ast::Ty; @@ -595,15 +76,15 @@ pub trait AstBuilder { fn expr_var(&self, span: span, var: &str) -> @ast::expr; fn expr_self(&self, span: span) -> @ast::expr; fn expr_field(&self, span: span, expr: @ast::expr, ident: ast::ident) - -> @ast::expr; + -> @ast::expr; fn expr_call(&self, span: span, expr: @ast::expr, args: ~[@ast::expr]) - -> @ast::expr; + -> @ast::expr; fn expr_method_call(&self, span: span, expr: @ast::expr, ident: ast::ident, args: ~[@ast::expr]) - -> @ast::expr; + -> @ast::expr; fn expr_blk(&self, b: ast::blk) -> @ast::expr; fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field; fn expr_struct(&self, @@ -613,13 +94,13 @@ pub trait AstBuilder { fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr; fn lambda_expr_0(&self, expr: @ast::expr) -> @ast::expr; fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident) - -> @ast::expr; + -> @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; + -> @ast::expr; // items fn item(&self, name: ident, span: span, node: ast::item_) -> @ast::item; @@ -675,6 +156,226 @@ pub trait AstBuilder { generics: Generics) -> @ast::item; fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item; + + + + fn mk_expr(&self, + sp: codemap::span, + expr: ast::expr_) + -> @ast::expr; + + fn mk_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr; + fn mk_int(&self, sp: span, i: int) -> @ast::expr; + fn mk_uint(&self, sp: span, u: uint) -> @ast::expr; + fn mk_u8(&self, sp: span, u: u8) -> @ast::expr; + fn mk_binary(&self, sp: span, op: ast::binop, + lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr; + + fn mk_deref(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_unary(&self, sp: span, op: ast::unop, e: @ast::expr) + -> @ast::expr; + // XXX: unused self + fn mk_raw_path(&self, sp: span, idents: ~[ast::ident]) -> @ast::Path; + // XXX: unused self + fn mk_raw_path_(&self, sp: span, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) + -> @ast::Path; + // XXX: unused self + fn mk_raw_path_global(&self, sp: span,idents: ~[ast::ident]) -> @ast::Path; + // XXX: unused self + fn mk_raw_path_global_(&self, sp: span, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) -> @ast::Path; + fn mk_path_raw(&self, sp: span, path: @ast::Path)-> @ast::expr; + fn mk_path(&self, sp: span, idents: ~[ast::ident]) + -> @ast::expr; + fn mk_path_global(&self, sp: span, idents: ~[ast::ident]) + -> @ast::expr; + fn mk_access_(&self, sp: span, p: @ast::expr, m: ast::ident) + -> @ast::expr; + fn mk_access(&self, sp: span, p: ~[ast::ident], m: ast::ident) + -> @ast::expr; + fn mk_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_method_call(&self, + sp: span, + rcvr_expr: @ast::expr, + method_ident: ast::ident, + args: ~[@ast::expr]) -> @ast::expr; + fn mk_call_(&self, sp: span, fn_expr: @ast::expr, + args: ~[@ast::expr]) -> @ast::expr; + fn mk_call(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr; + fn mk_call_global(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr; + // e = expr, t = type + fn mk_base_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr; + fn mk_vstore_e(&self, sp: span, expr: @ast::expr, + vst: ast::expr_vstore) -> + @ast::expr; + fn mk_uniq_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr; + fn mk_slice_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr; + fn mk_base_str(&self, sp: span, s: ~str) -> @ast::expr; + fn mk_uniq_str(&self, sp: span, s: ~str) -> @ast::expr; + // XXX: unused self + fn mk_field(&self, sp: span, f: &Field) -> ast::field; + // XXX: unused self + fn mk_fields(&self, sp: span, fields: ~[Field]) -> ~[ast::field]; + fn mk_struct_e(&self, + sp: span, + ctor_path: ~[ast::ident], + fields: ~[Field]) + -> @ast::expr; + fn mk_global_struct_e(&self, + sp: span, + ctor_path: ~[ast::ident], + fields: ~[Field]) + -> @ast::expr; + fn mk_glob_use(&self, + sp: span, + vis: ast::visibility, + path: ~[ast::ident]) -> @ast::view_item; + fn mk_local(&self, sp: span, mutbl: bool, + ident: ast::ident, ex: @ast::expr) -> @ast::stmt; + fn mk_block(&self, span: span, + view_items: ~[@ast::view_item], + stmts: ~[@ast::stmt], + expr: Option<@ast::expr>) -> @ast::expr; + fn mk_block_(&self, + span: span, + stmts: ~[@ast::stmt]) + -> ast::blk; + fn mk_simple_block(&self, + span: span, + expr: @ast::expr) + -> ast::blk; + fn mk_lambda_(&self, + span: span, + fn_decl: ast::fn_decl, + blk: ast::blk) + -> @ast::expr; + fn mk_lambda(&self, + span: span, + fn_decl: ast::fn_decl, + expr: @ast::expr) + -> @ast::expr; + fn mk_lambda_stmts(&self, + span: span, + fn_decl: ast::fn_decl, + stmts: ~[@ast::stmt]) + -> @ast::expr ; + fn mk_lambda_no_args(&self, + span: span, + expr: @ast::expr) + -> @ast::expr; + fn mk_copy(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_managed(&self, sp: span, e: @ast::expr) -> @ast::expr; + fn mk_pat(&self, span: span, pat: ast::pat_) -> @ast::pat; + fn mk_pat_wild(&self, span: span) -> @ast::pat; + fn mk_pat_lit(&self, + span: span, + expr: @ast::expr) -> @ast::pat; + fn mk_pat_ident(&self, + span: span, + ident: ast::ident) -> @ast::pat; + + fn mk_pat_ident_with_binding_mode(&self, + span: span, + ident: ast::ident, + bm: ast::binding_mode) -> @ast::pat; + fn mk_pat_enum(&self, + span: span, + path: @ast::Path, + subpats: ~[@ast::pat]) + -> @ast::pat; + fn mk_pat_struct(&self, + span: span, + path: @ast::Path, + field_pats: ~[ast::field_pat]) + -> @ast::pat; + fn mk_bool(&self, span: span, value: bool) -> @ast::expr; + fn mk_stmt(&self, span: span, expr: @ast::expr) -> @ast::stmt; + + // XXX: unused self + fn mk_ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt; + + fn mk_ty(&self, + span: span, + ty: ast::ty_) -> @ast::Ty; + + fn mk_ty_path(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::Ty; + + fn mk_ty_path_global(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::Ty; + + fn mk_ty_path_path(&self, + span: span, + path: @ast::Path) + -> @ast::Ty; + + fn mk_ty_rptr(&self, + span: span, + ty: @ast::Ty, + lifetime: Option<@ast::Lifetime>, + mutbl: ast::mutability) + -> @ast::Ty; + fn mk_ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty; + fn mk_ty_box(&self, span: span, + ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty; + + + + fn mk_ty_infer(&self, span: span) -> @ast::Ty; + fn mk_trait_ref_global(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::trait_ref; + fn mk_trait_ref_(&self, path: @ast::Path) -> @ast::trait_ref; + fn mk_simple_ty_path(&self, + span: span, + ident: ast::ident) + -> @ast::Ty; + fn mk_arg(&self, + span: span, + ident: ast::ident, + ty: @ast::Ty) + -> ast::arg; + // XXX unused self + fn mk_fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl; + fn mk_trait_ty_param_bound_global(&self, + span: span, + idents: ~[ast::ident]) + -> ast::TyParamBound; + fn mk_trait_ty_param_bound_(&self, + path: @ast::Path) -> ast::TyParamBound; + fn mk_ty_param(&self, + ident: ast::ident, + bounds: @OptVec) + -> ast::TyParam; + fn mk_lifetime(&self, + span: span, + ident: ast::ident) + -> ast::Lifetime; + fn mk_arm(&self, + span: span, + pats: ~[@ast::pat], + expr: @ast::expr) + -> ast::arm; + fn mk_unreachable(&self, span: span) -> @ast::expr; + fn mk_unreachable_arm(&self, span: span) -> ast::arm; + + fn make_self(&self, span: span) -> @ast::expr; } impl AstBuilder for @ExtCtxt { @@ -729,8 +430,8 @@ impl AstBuilder for @ExtCtxt { } fn ty_path(&self, path: @ast::Path) -> @ast::Ty { - build::mk_ty(*self, path.span, - ast::ty_path(path, self.next_id())) + self.mk_ty(path.span, + ast::ty_path(path, self.next_id())) } fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty { @@ -779,14 +480,14 @@ impl AstBuilder for @ExtCtxt { fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty] { opt_vec::take_vec( ty_params.map(|p| self.ty_path( - mk_raw_path(dummy_sp(), ~[p.ident])))) + self.mk_raw_path(dummy_sp(), ~[p.ident])))) } fn ty_vars_global(&self, ty_params: &OptVec) -> ~[@ast::Ty] { opt_vec::take_vec( ty_params.map(|p| self.ty_path( - mk_raw_path(dummy_sp(), ~[p.ident])))) + self.mk_raw_path(dummy_sp(), ~[p.ident])))) } fn strip_bounds(&self, generics: &Generics) -> Generics { @@ -803,7 +504,7 @@ impl AstBuilder for @ExtCtxt { fn stmt_expr(&self, expr: @ast::expr) -> @ast::stmt { @codemap::spanned { node: ast::stmt_semi(expr, self.next_id()), - span: expr.span } + span: expr.span } } fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt { @@ -819,7 +520,7 @@ impl AstBuilder for @ExtCtxt { span, ast::expr_lit( @codemap::spanned { node: ast::lit_str(s), - span: span})), + span: span})), ast::expr_vstore_uniq)) } @@ -828,7 +529,7 @@ impl AstBuilder for @ExtCtxt { span, ast::expr_lit( @codemap::spanned { node: ast::lit_uint(i as u64, ast::ty_u), - span: span})) + span: span})) } fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@expr>) -> ast::blk { @@ -942,7 +643,7 @@ impl AstBuilder for @ExtCtxt { } fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident) - -> @ast::expr { + -> @ast::expr { self.lambda1(self.blk_expr(expr), ident) } @@ -954,7 +655,7 @@ impl AstBuilder for @ExtCtxt { span: span, stmts: ~[@ast::stmt], ident: ast::ident) - -> @ast::expr { + -> @ast::expr { self.lambda1(self.blk(span, stmts, None), ident) } @@ -992,20 +693,20 @@ impl AstBuilder for @ExtCtxt { let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ { style: ast::attr_outer, value: @respan(dummy_sp(), - ast::meta_list(@~"allow", ~[ - @respan(dummy_sp(), - ast::meta_word( - @~"non_camel_case_types")) - ])), + ast::meta_list(@~"allow", ~[ + @respan(dummy_sp(), + ast::meta_word( + @~"non_camel_case_types")) + ])), is_sugared_doc: false }); @ast::item { ident: name, - attrs: ~[non_camel_case_attribute], - id: self.next_id(), - node: node, - vis: ast::public, - span: span } + attrs: ~[non_camel_case_attribute], + id: self.next_id(), + node: node, + vis: ast::public, + span: span } } fn item_fn_poly(&self, name: ident, @@ -1027,7 +728,7 @@ impl AstBuilder for @ExtCtxt { inputs: ~[ast::arg], output: @ast::Ty, body: ast::blk - ) -> @ast::item { + ) -> @ast::item { self.item_fn_poly( name, inputs, @@ -1100,7 +801,7 @@ impl AstBuilder for @ExtCtxt { @codemap::spanned { node: ast::view_path_simple( self.ident_of("Owned"), - mk_raw_path( + self.mk_raw_path( codemap::dummy_sp(), ~[ self.ident_of("core"), @@ -1140,4 +841,539 @@ impl AstBuilder for @ExtCtxt { } + + + + + + fn mk_expr(&self, + sp: codemap::span, + expr: ast::expr_) + -> @ast::expr { + @ast::expr { + id: self.next_id(), + callee_id: self.next_id(), + node: expr, + span: sp, + } + } + + fn mk_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr { + let sp_lit = @codemap::spanned { node: lit, span: sp }; + self.mk_expr( sp, ast::expr_lit(sp_lit)) + } + fn mk_int(&self, sp: span, i: int) -> @ast::expr { + let lit = ast::lit_int(i as i64, ast::ty_i); + return self.mk_lit( sp, lit); + } + fn mk_uint(&self, sp: span, u: uint) -> @ast::expr { + let lit = ast::lit_uint(u as u64, ast::ty_u); + return self.mk_lit( sp, lit); + } + fn mk_u8(&self, sp: span, u: u8) -> @ast::expr { + let lit = ast::lit_uint(u as u64, ast::ty_u8); + return self.mk_lit( sp, lit); + } + fn mk_binary(&self, sp: span, op: ast::binop, + lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr { + self.next_id(); // see ast_util::op_expr_callee_id + self.mk_expr( sp, ast::expr_binary(op, lhs, rhs)) + } + + fn mk_deref(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.mk_unary( sp, ast::deref, e) + } + fn mk_unary(&self, sp: span, op: ast::unop, e: @ast::expr) + -> @ast::expr { + self.next_id(); // see ast_util::op_expr_callee_id + self.mk_expr( sp, ast::expr_unary(op, e)) + } + // XXX: unused self + fn mk_raw_path(&self, sp: span, idents: ~[ast::ident]) -> @ast::Path { + self.mk_raw_path_(sp, idents, None, ~[]) + } + // XXX: unused self + fn mk_raw_path_(&self, sp: span, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) + -> @ast::Path { + @ast::Path { span: sp, + global: false, + idents: idents, + rp: rp, + types: types } + } + // XXX: unused self + fn mk_raw_path_global(&self, sp: span, idents: ~[ast::ident]) -> @ast::Path { + self.mk_raw_path_global_(sp, idents, None, ~[]) + } + // XXX: unused self + fn mk_raw_path_global_(&self, sp: span, + idents: ~[ast::ident], + rp: Option<@ast::Lifetime>, + types: ~[@ast::Ty]) -> @ast::Path { + @ast::Path { span: sp, + global: true, + idents: idents, + rp: rp, + types: types } + } + fn mk_path_raw(&self, sp: span, path: @ast::Path)-> @ast::expr { + self.mk_expr( sp, ast::expr_path(path)) + } + fn mk_path(&self, sp: span, idents: ~[ast::ident]) + -> @ast::expr { + self.mk_path_raw( sp, self.mk_raw_path(sp, idents)) + } + fn mk_path_global(&self, sp: span, idents: ~[ast::ident]) + -> @ast::expr { + self.mk_path_raw( sp, self.mk_raw_path_global(sp, idents)) + } + fn mk_access_(&self, sp: span, p: @ast::expr, m: ast::ident) + -> @ast::expr { + self.mk_expr( sp, ast::expr_field(p, m, ~[])) + } + fn mk_access(&self, sp: span, p: ~[ast::ident], m: ast::ident) + -> @ast::expr { + let pathexpr = self.mk_path( sp, p); + return self.mk_access_( sp, pathexpr, m); + } + fn mk_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr { + return self.mk_expr( sp, ast::expr_addr_of(ast::m_imm, e)); + } + fn mk_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr { + return self.mk_expr( sp, ast::expr_addr_of(ast::m_mutbl, e)); + } + fn mk_method_call(&self, + sp: span, + rcvr_expr: @ast::expr, + method_ident: ast::ident, + args: ~[@ast::expr]) -> @ast::expr { + self.mk_expr( sp, ast::expr_method_call(rcvr_expr, method_ident, ~[], args, ast::NoSugar)) + } + fn mk_call_(&self, sp: span, fn_expr: @ast::expr, + args: ~[@ast::expr]) -> @ast::expr { + self.mk_expr( sp, ast::expr_call(fn_expr, args, ast::NoSugar)) + } + fn mk_call(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr { + let pathexpr = self.mk_path( sp, fn_path); + return self.mk_call_( sp, pathexpr, args); + } + fn mk_call_global(&self, sp: span, fn_path: ~[ast::ident], + args: ~[@ast::expr]) -> @ast::expr { + let pathexpr = self.mk_path_global( sp, fn_path); + return self.mk_call_( sp, pathexpr, args); + } + // e = expr, t = type + fn mk_base_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr { + let vecexpr = ast::expr_vec(exprs, ast::m_imm); + self.mk_expr( sp, vecexpr) + } + fn mk_vstore_e(&self, sp: span, expr: @ast::expr, + vst: ast::expr_vstore) -> + @ast::expr { + self.mk_expr( sp, ast::expr_vstore(expr, vst)) + } + fn mk_uniq_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr { + self.mk_vstore_e( sp, self.mk_base_vec_e( sp, exprs), ast::expr_vstore_uniq) + } + fn mk_slice_vec_e(&self, sp: span, exprs: ~[@ast::expr]) + -> @ast::expr { + self.mk_vstore_e( sp, self.mk_base_vec_e( sp, exprs), + ast::expr_vstore_slice) + } + fn mk_base_str(&self, sp: span, s: ~str) -> @ast::expr { + let lit = ast::lit_str(@s); + return self.mk_lit( sp, lit); + } + fn mk_uniq_str(&self, sp: span, s: ~str) -> @ast::expr { + self.mk_vstore_e( sp, self.mk_base_str( sp, s), ast::expr_vstore_uniq) + } + // XXX: unused self + fn mk_field(&self, sp: span, f: &Field) -> ast::field { + codemap::spanned { + node: ast::field_ { mutbl: ast::m_imm, ident: f.ident, expr: f.ex }, + span: sp, + } + } + // XXX: unused self + fn mk_fields(&self, sp: span, fields: ~[Field]) -> ~[ast::field] { + fields.map(|f| self.mk_field(sp, f)) + } + fn mk_struct_e(&self, + sp: span, + ctor_path: ~[ast::ident], + fields: ~[Field]) + -> @ast::expr { + self.mk_expr( sp, + ast::expr_struct(self.mk_raw_path(sp, ctor_path), + self.mk_fields(sp, fields), + option::None::<@ast::expr>)) + } + fn mk_global_struct_e(&self, + sp: span, + ctor_path: ~[ast::ident], + fields: ~[Field]) + -> @ast::expr { + self.mk_expr( sp, + ast::expr_struct(self.mk_raw_path_global(sp, ctor_path), + self.mk_fields(sp, fields), + option::None::<@ast::expr>)) + } + fn mk_glob_use(&self, + sp: span, + vis: ast::visibility, + path: ~[ast::ident]) -> @ast::view_item { + let glob = @codemap::spanned { + node: ast::view_path_glob(self.mk_raw_path(sp, path), self.next_id()), + span: sp, + }; + @ast::view_item { node: ast::view_item_use(~[glob]), + attrs: ~[], + vis: vis, + span: sp } + } + fn mk_local(&self, sp: span, mutbl: bool, + ident: ast::ident, ex: @ast::expr) -> @ast::stmt { + + let pat = @ast::pat { + id: self.next_id(), + node: ast::pat_ident( + ast::bind_by_copy, + self.mk_raw_path(sp, ~[ident]), + None), + span: sp, + }; + let ty = @ast::Ty { id: self.next_id(), node: ast::ty_infer, span: sp }; + let local = @codemap::spanned { + node: ast::local_ { + is_mutbl: mutbl, + ty: ty, + pat: pat, + init: Some(ex), + id: self.next_id(), + }, + span: sp, + }; + let decl = codemap::spanned {node: ast::decl_local(~[local]), span: sp}; + @codemap::spanned { node: ast::stmt_decl(@decl, self.next_id()), span: sp } + } + fn mk_block(&self, span: span, + view_items: ~[@ast::view_item], + stmts: ~[@ast::stmt], + expr: Option<@ast::expr>) -> @ast::expr { + let blk = codemap::spanned { + node: ast::blk_ { + view_items: view_items, + stmts: stmts, + expr: expr, + id: self.next_id(), + rules: ast::default_blk, + }, + span: span, + }; + self.mk_expr( span, ast::expr_block(blk)) + } + fn mk_block_(&self, + span: span, + stmts: ~[@ast::stmt]) + -> ast::blk { + codemap::spanned { + node: ast::blk_ { + view_items: ~[], + stmts: stmts, + expr: None, + id: self.next_id(), + rules: ast::default_blk, + }, + span: span, + } + } + fn mk_simple_block(&self, + span: span, + expr: @ast::expr) + -> ast::blk { + codemap::spanned { + node: ast::blk_ { + view_items: ~[], + stmts: ~[], + expr: Some(expr), + id: self.next_id(), + rules: ast::default_blk, + }, + span: span, + } + } + fn mk_lambda_(&self, + span: span, + fn_decl: ast::fn_decl, + blk: ast::blk) + -> @ast::expr { + self.mk_expr( span, ast::expr_fn_block(fn_decl, blk)) + } + fn mk_lambda(&self, + span: span, + fn_decl: ast::fn_decl, + expr: @ast::expr) + -> @ast::expr { + let blk = self.mk_simple_block( span, expr); + self.mk_lambda_( span, fn_decl, blk) + } + fn mk_lambda_stmts(&self, + span: span, + fn_decl: ast::fn_decl, + stmts: ~[@ast::stmt]) + -> @ast::expr { + let blk = self.mk_block( span, ~[], stmts, None); + self.mk_lambda( span, fn_decl, blk) + } + fn mk_lambda_no_args(&self, + span: span, + expr: @ast::expr) + -> @ast::expr { + let fn_decl = self.mk_fn_decl(~[], self.mk_ty_infer( span)); + self.mk_lambda( span, fn_decl, expr) + } + fn mk_copy(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.mk_expr( sp, ast::expr_copy(e)) + } + fn mk_managed(&self, sp: span, e: @ast::expr) -> @ast::expr { + self.mk_expr( sp, ast::expr_unary(ast::box(ast::m_imm), e)) + } + fn mk_pat(&self, span: span, pat: ast::pat_) -> @ast::pat { + @ast::pat { id: self.next_id(), node: pat, span: span } + } + fn mk_pat_wild(&self, span: span) -> @ast::pat { + self.mk_pat( span, ast::pat_wild) + } + fn mk_pat_lit(&self, + span: span, + expr: @ast::expr) -> @ast::pat { + self.mk_pat( span, ast::pat_lit(expr)) + } + fn mk_pat_ident(&self, + span: span, + ident: ast::ident) -> @ast::pat { + self.mk_pat_ident_with_binding_mode( span, ident, ast::bind_by_copy) + } + + fn mk_pat_ident_with_binding_mode(&self, + span: span, + ident: ast::ident, + bm: ast::binding_mode) -> @ast::pat { + let path = self.mk_raw_path(span, ~[ ident ]); + let pat = ast::pat_ident(bm, path, None); + self.mk_pat( span, pat) + } + fn mk_pat_enum(&self, + span: span, + path: @ast::Path, + subpats: ~[@ast::pat]) + -> @ast::pat { + let pat = ast::pat_enum(path, Some(subpats)); + self.mk_pat( span, pat) + } + fn mk_pat_struct(&self, + span: span, + path: @ast::Path, + field_pats: ~[ast::field_pat]) + -> @ast::pat { + let pat = ast::pat_struct(path, field_pats, false); + self.mk_pat( span, pat) + } + fn mk_bool(&self, span: span, value: bool) -> @ast::expr { + let lit_expr = ast::expr_lit(@codemap::spanned { + node: ast::lit_bool(value), + span: span }); + self.mk_expr( span, lit_expr) + } + fn mk_stmt(&self, span: span, expr: @ast::expr) -> @ast::stmt { + let stmt_ = ast::stmt_semi(expr, self.next_id()); + @codemap::spanned { node: stmt_, span: span } + } + + // XXX: unused self + fn mk_ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt { + ast::mt { + ty: ty, + mutbl: mutbl + } + } + + fn mk_ty(&self, + span: span, + ty: ast::ty_) -> @ast::Ty { + @ast::Ty { + id: self.next_id(), + span: span, + node: ty + } + } + + fn mk_ty_path(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::Ty { + let ty = self.mk_raw_path(span, idents); + self.mk_ty_path_path( span, ty) + } + + fn mk_ty_path_global(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::Ty { + let ty = self.mk_raw_path_global(span, idents); + self.mk_ty_path_path( span, ty) + } + + fn mk_ty_path_path(&self, + span: span, + path: @ast::Path) + -> @ast::Ty { + let ty = ast::ty_path(path, self.next_id()); + self.mk_ty( span, ty) + } + + fn mk_ty_rptr(&self, + span: span, + ty: @ast::Ty, + lifetime: Option<@ast::Lifetime>, + mutbl: ast::mutability) + -> @ast::Ty { + self.mk_ty( span, + ast::ty_rptr(lifetime, self.mk_ty_mt(ty, mutbl))) + } + fn mk_ty_uniq(&self, span: span, ty: @ast::Ty) -> @ast::Ty { + self.mk_ty( span, ast::ty_uniq(self.mk_ty_mt(ty, ast::m_imm))) + } + fn mk_ty_box(&self, span: span, + ty: @ast::Ty, mutbl: ast::mutability) -> @ast::Ty { + self.mk_ty( span, ast::ty_box(self.mk_ty_mt(ty, mutbl))) + } + + + + fn mk_ty_infer(&self, span: span) -> @ast::Ty { + self.mk_ty( span, ast::ty_infer) + } + fn mk_trait_ref_global(&self, + span: span, + idents: ~[ ast::ident ]) + -> @ast::trait_ref + { + self.mk_trait_ref_( self.mk_raw_path_global(span, idents)) + } + fn mk_trait_ref_(&self, path: @ast::Path) -> @ast::trait_ref { + @ast::trait_ref { + path: path, + ref_id: self.next_id() + } + } + fn mk_simple_ty_path(&self, + span: span, + ident: ast::ident) + -> @ast::Ty { + self.mk_ty_path( span, ~[ ident ]) + } + fn mk_arg(&self, + span: span, + ident: ast::ident, + ty: @ast::Ty) + -> ast::arg { + let arg_pat = self.mk_pat_ident( span, ident); + ast::arg { + is_mutbl: false, + ty: ty, + pat: arg_pat, + id: self.next_id() + } + } + // XXX unused self + fn mk_fn_decl(&self, inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl { + ast::fn_decl { inputs: inputs, output: output, cf: ast::return_val } + } + fn mk_trait_ty_param_bound_global(&self, + span: span, + idents: ~[ast::ident]) + -> ast::TyParamBound { + ast::TraitTyParamBound(self.mk_trait_ref_global( span, idents)) + } + fn mk_trait_ty_param_bound_(&self, + path: @ast::Path) -> ast::TyParamBound { + ast::TraitTyParamBound(self.mk_trait_ref_( path)) + } + fn mk_ty_param(&self, + ident: ast::ident, + bounds: @OptVec) + -> ast::TyParam { + ast::TyParam { ident: ident, id: self.next_id(), bounds: bounds } + } + fn mk_lifetime(&self, + span: span, + ident: ast::ident) + -> ast::Lifetime { + ast::Lifetime { id: self.next_id(), span: span, ident: ident } + } + fn mk_arm(&self, + span: span, + pats: ~[@ast::pat], + expr: @ast::expr) + -> ast::arm { + ast::arm { + pats: pats, + guard: None, + body: self.mk_simple_block( span, expr) + } + } + fn mk_unreachable(&self, span: span) -> @ast::expr { + let loc = self.codemap().lookup_char_pos(span.lo); + self.mk_call_global( + span, + ~[ + self.ident_of("core"), + self.ident_of("sys"), + self.ident_of("FailWithCause"), + self.ident_of("fail_with"), + ], + ~[ + self.mk_base_str( span, ~"internal error: entered unreachable code"), + self.mk_base_str( span, copy loc.file.name), + self.mk_uint( span, loc.line), + ] + ) + } + fn mk_unreachable_arm(&self, span: span) -> ast::arm { + self.mk_arm( span, ~[self.mk_pat_wild( span)], self.mk_unreachable( span)) + } + + fn make_self(&self, span: span) -> @ast::expr { + self.mk_expr( span, ast::expr_self) + } +} + + +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) + } } diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index da13c9bfa28..cdc6e267ccc 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -14,7 +14,7 @@ use ast; use codemap::span; use ext::base::*; use ext::base; -use ext::build::{mk_u8, mk_slice_vec_e}; +use ext::build::AstBuilder; pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { // Gather all argument expressions @@ -28,7 +28,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas // string literal, push each byte to vector expression ast::lit_str(s) => { for s.each |byte| { - bytes.push(mk_u8(cx, sp, byte)); + bytes.push(cx.mk_u8(sp, byte)); } } @@ -37,7 +37,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas if v > 0xFF { cx.span_err(sp, "Too large u8 literal in bytes!") } else { - bytes.push(mk_u8(cx, sp, v as u8)); + bytes.push(cx.mk_u8(sp, v as u8)); } } @@ -48,14 +48,14 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas } else if v < 0 { cx.span_err(sp, "Negative integer literal in bytes!") } else { - bytes.push(mk_u8(cx, sp, v as u8)); + bytes.push(cx.mk_u8(sp, v as u8)); } } // char literal, push to vector expression ast::lit_int(v, ast::ty_char) => { if (v as char).is_ascii() { - bytes.push(mk_u8(cx, sp, v as u8)); + bytes.push(cx.mk_u8(sp, v as u8)); } else { cx.span_err(sp, "Non-ascii char literal in bytes!") } @@ -68,6 +68,6 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas } } - let e = mk_slice_vec_e(cx, sp, bytes); + let e = cx.mk_slice_vec_e(sp, bytes); MRExpr(e) } diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index c08b478e8ed..07aead9588a 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -12,6 +12,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; @@ -79,7 +80,7 @@ fn cs_clone( let ctor_ident; let all_fields; let subcall = |field| - build::mk_method_call(cx, span, field, clone_ident, ~[]); + cx.mk_method_call(span, field, clone_ident, ~[]); match *substr.fields { Struct(ref af) => { @@ -102,7 +103,7 @@ fn cs_clone( [(None, _, _), .. _] => { // enum-like let subcalls = all_fields.map(|&(_, self_f, _)| subcall(self_f)); - build::mk_call(cx, span, ctor_ident, subcalls) + cx.mk_call(span, ctor_ident, subcalls) }, _ => { // struct-like @@ -118,9 +119,9 @@ fn cs_clone( if fields.is_empty() { // no fields, so construct like `None` - build::mk_path(cx, span, ctor_ident) + cx.mk_path(span, ctor_ident) } else { - build::mk_struct_e(cx, span, + cx.mk_struct_e(span, ctor_ident, fields) } diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 197366b09ae..1af66404489 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -11,7 +11,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_eq(cx: @ExtCtxt, @@ -21,11 +21,11 @@ pub fn expand_deriving_eq(cx: @ExtCtxt, // structures are equal if all fields are equal, and non equal, if // any fields are not equal or if the enum variants are different fn cs_eq(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - cs_and(|cx, span, _, _| build::mk_bool(cx, span, false), + cs_and(|cx, span, _, _| cx.mk_bool(span, false), cx, span, substr) } fn cs_ne(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - cs_or(|cx, span, _, _| build::mk_bool(cx, span, true), + cs_or(|cx, span, _, _| cx.mk_bool(span, true), cx, span, substr) } diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index 29fc2c7271c..41b5bf63aca 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -12,7 +12,7 @@ use ast::{meta_item, item, expr_if, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_ord(cx: @ExtCtxt, @@ -62,10 +62,10 @@ fn cs_ord(less: bool, equal: bool, } else { cx.ident_of("gt") }; - let false_blk_expr = build::mk_block(cx, span, + let false_blk_expr = cx.mk_block(span, ~[], ~[], - Some(build::mk_bool(cx, span, false))); - let base = build::mk_bool(cx, span, equal); + Some(cx.mk_bool(span, false))); + let base = cx.mk_bool(span, equal); cs_fold( false, // need foldr, @@ -98,19 +98,19 @@ fn cs_ord(less: bool, equal: bool, cx.span_bug(span, "Not exactly 2 arguments in `deriving(Ord)`"); } - let cmp = build::mk_method_call(cx, span, + let cmp = cx.mk_method_call(span, self_f, cx.ident_of("eq"), other_fs.to_owned()); - let subexpr = build::mk_simple_block(cx, span, subexpr); + let subexpr = cx.mk_simple_block(span, subexpr); let elseif = expr_if(cmp, subexpr, Some(false_blk_expr)); - let elseif = build::mk_expr(cx, span, elseif); + let elseif = cx.mk_expr(span, elseif); - let cmp = build::mk_method_call(cx, span, + let cmp = cx.mk_method_call(span, self_f, binop, other_fs.to_owned()); - let true_blk = build::mk_simple_block(cx, span, - build::mk_bool(cx, span, true)); + let true_blk = cx.mk_simple_block(span, + cx.mk_bool(span, true)); let if_ = expr_if(cmp, true_blk, Some(elseif)); - build::mk_expr(cx, span, if_) + cx.mk_expr(span, if_) }, base, |cx, span, args, _| { @@ -119,7 +119,7 @@ fn cs_ord(less: bool, equal: bool, match args { [(self_var, _, _), (other_var, _, _)] => - build::mk_bool(cx, span, + cx.mk_bool(span, if less { self_var < other_var } else { diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 0ab99430d10..48393efce64 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -12,7 +12,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_totaleq(cx: @ExtCtxt, @@ -21,7 +21,7 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt, in_items: ~[@item]) -> ~[@item] { fn cs_equals(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - cs_and(|cx, span, _, _| build::mk_bool(cx, span, false), + cs_and(|cx, span, _, _| cx.mk_bool(span, false), cx, span, substr) } diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 2b4d8a28fbd..3404a21edd0 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -11,7 +11,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; use core::cmp::{Ordering, Equal, Less, Greater}; @@ -47,7 +47,7 @@ pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> @expr { Equal => "Equal", Greater => "Greater" }; - build::mk_path_global(cx, span, + cx.mk_path_global(span, ~[cx.ident_of("core"), cx.ident_of("cmp"), cx.ident_of(cnst)]) @@ -60,7 +60,7 @@ pub fn cs_cmp(cx: @ExtCtxt, span: span, // foldr (possibly) nests the matches in lexical_ordering better false, |cx, span, old, new| { - build::mk_call_global(cx, span, + cx.mk_call_global(span, ~[cx.ident_of("core"), cx.ident_of("cmp"), cx.ident_of("lexical_ordering")], diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 24f9b6acf85..781ac9814ec 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -16,7 +16,8 @@ encodable.rs for more. use ast; use ast::*; use ext::base::ExtCtxt; -use ext::build; +use ext::build::Field; +use ext::build::AstBuilder; use ext::deriving::*; use codemap::{span, spanned}; use ast_util; @@ -44,12 +45,10 @@ fn create_derived_decodable_impl( generics: &Generics, method: @method ) -> @item { - let decoder_ty_param = build::mk_ty_param( - cx, + let decoder_ty_param = cx.mk_ty_param( cx.ident_of("__D"), @opt_vec::with( - build::mk_trait_ty_param_bound_global( - cx, + cx.mk_trait_ty_param_bound_global( span, ~[ cx.ident_of("std"), @@ -64,7 +63,7 @@ fn create_derived_decodable_impl( let generic_ty_params = opt_vec::with(decoder_ty_param); let methods = [method]; - let trait_path = build::mk_raw_path_global_( + let trait_path = cx.mk_raw_path_global_( span, ~[ cx.ident_of("std"), @@ -73,7 +72,7 @@ fn create_derived_decodable_impl( ], None, ~[ - build::mk_simple_ty_path(cx, span, cx.ident_of("__D")) + cx.mk_simple_ty_path(span, cx.ident_of("__D")) ] ); create_derived_impl( @@ -98,15 +97,14 @@ fn create_decode_method( expr: @ast::expr ) -> @method { // Create the `e` parameter. - let d_arg_type = build::mk_ty_rptr( - cx, + let d_arg_type = cx.mk_ty_rptr( span, - build::mk_simple_ty_path(cx, span, cx.ident_of("__D")), + cx.mk_simple_ty_path(span, cx.ident_of("__D")), None, ast::m_mutbl ); let d_ident = cx.ident_of("__d"); - let d_arg = build::mk_arg(cx, span, d_ident, d_arg_type); + let d_arg = cx.mk_arg(span, d_ident, d_arg_type); // Create the type of the return value. let output_type = create_self_type_with_params( @@ -118,10 +116,10 @@ fn create_decode_method( // Create the function declaration. let inputs = ~[d_arg]; - let fn_decl = build::mk_fn_decl(inputs, output_type); + let fn_decl = cx.mk_fn_decl(inputs, output_type); // Create the body block. - let body_block = build::mk_simple_block(cx, span, expr); + let body_block = cx.mk_simple_block(span, expr); // Create the method. let explicit_self = spanned { node: sty_static, span: span }; @@ -146,11 +144,9 @@ fn call_substructure_decode_method( span: span ) -> @ast::expr { // Call the substructure method. - build::mk_call_( - cx, + cx.mk_call_( span, - build::mk_path_global( - cx, + cx.mk_path_global( span, ~[ cx.ident_of("std"), @@ -160,7 +156,7 @@ fn call_substructure_decode_method( ] ), ~[ - build::mk_path(cx, span, ~[cx.ident_of("__d")]) + cx.mk_path(span, ~[cx.ident_of("__d")]) ] ) } @@ -222,32 +218,31 @@ fn create_read_struct_field( span: span, idx: uint, ident: ident -) -> build::Field { +) -> Field { // Call the substructure method. let decode_expr = call_substructure_decode_method(cx, span); - let d_arg = build::mk_arg(cx, + let d_arg = cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_struct_field"), ~[ - build::mk_base_str(cx, span, cx.str_of(ident)), - build::mk_uint(cx, span, idx), - build::mk_lambda(cx, + cx.mk_base_str(span, cx.str_of(ident)), + cx.mk_uint(span, idx), + cx.mk_lambda( span, - build::mk_fn_decl(~[d_arg], - build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[d_arg], + cx.mk_ty_infer(span)), decode_expr), ] ); - build::Field { ident: ident, ex: call_expr } + Field { ident: ident, ex: call_expr } } fn create_read_struct_arg( @@ -255,22 +250,21 @@ fn create_read_struct_arg( span: span, idx: uint, ident: ident -) -> build::Field { +) -> Field { // Call the substructure method. let decode_expr = call_substructure_decode_method(cx, span); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_struct_arg"), ~[ - build::mk_uint(cx, span, idx), - build::mk_lambda_no_args(cx, span, decode_expr), + cx.mk_uint(span, idx), + cx.mk_lambda_no_args(span, decode_expr), ] ); - build::Field { ident: ident, ex: call_expr } + Field { ident: ident, ex: call_expr } } fn expand_deriving_decodable_struct_method( @@ -298,29 +292,25 @@ fn expand_deriving_decodable_struct_method( i += 1; } - let d_arg = build::mk_arg(cx, + let d_arg = cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let read_struct_expr = build::mk_method_call( - cx, + let read_struct_expr = cx.mk_method_call( span, - build::mk_path( - cx, + cx.mk_path( span, ~[cx.ident_of("__d")] ), cx.ident_of("read_struct"), ~[ - build::mk_base_str(cx, span, cx.str_of(type_ident)), - build::mk_uint(cx, span, fields.len()), - build::mk_lambda( - cx, + cx.mk_base_str(span, cx.str_of(type_ident)), + cx.mk_uint(span, fields.len()), + cx.mk_lambda( span, - build::mk_fn_decl(~[d_arg], build::mk_ty_infer(cx, span)), - build::mk_struct_e( - cx, + cx.mk_fn_decl(~[d_arg], cx.mk_ty_infer(span)), + cx.mk_struct_e( span, ~[type_ident], fields @@ -340,14 +330,14 @@ fn create_read_variant_arg( variant: &ast::variant ) -> ast::arm { // Create the matching pattern. - let pat = build::mk_pat_lit(cx, span, build::mk_uint(cx, span, idx)); + let pat = cx.mk_pat_lit(span, cx.mk_uint(span, idx)); // Feed each argument in this variant to the decode function // as well. let variant_arg_len = variant_arg_count(cx, span, variant); let expr = if variant_arg_len == 0 { - build::mk_path(cx, span, ~[variant.node.name]) + cx.mk_path(span, ~[variant.node.name]) } else { // Feed the discriminant to the decode function. let mut args = ~[]; @@ -356,22 +346,21 @@ fn create_read_variant_arg( // Call the substructure method. let expr = call_substructure_decode_method(cx, span); - let d_arg = build::mk_arg(cx, + let d_arg = cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span)); - let t_infer = build::mk_ty_infer(cx, span); + cx.mk_ty_infer(span)); + let t_infer = cx.mk_ty_infer(span); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_enum_variant_arg"), ~[ - build::mk_uint(cx, span, j), - build::mk_lambda(cx, + cx.mk_uint(span, j), + cx.mk_lambda( span, - build::mk_fn_decl(~[d_arg], t_infer), + cx.mk_fn_decl(~[d_arg], t_infer), expr), ] ); @@ -379,8 +368,7 @@ fn create_read_variant_arg( args.push(call_expr); } - build::mk_call( - cx, + cx.mk_call( span, ~[variant.node.name], args @@ -388,7 +376,7 @@ fn create_read_variant_arg( }; // Create the arm. - build::mk_arm(cx, span, ~[pat], expr) + cx.mk_arm(span, ~[pat], expr) } fn create_read_enum_variant( @@ -397,12 +385,10 @@ fn create_read_enum_variant( enum_definition: &enum_def ) -> @expr { // Create a vector that contains all the variant names. - let expr_arm_names = build::mk_base_vec_e( - cx, + let expr_arm_names = cx.mk_base_vec_e( span, do enum_definition.variants.map |variant| { - build::mk_base_str( - cx, + cx.mk_base_str( span, cx.str_of(variant.node.name) ) @@ -415,41 +401,36 @@ fn create_read_enum_variant( }; // Add the impossible case arm. - arms.push(build::mk_unreachable_arm(cx, span)); + arms.push(cx.mk_unreachable_arm(span)); // Create the read_enum_variant expression. - build::mk_method_call( - cx, + cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_enum_variant"), ~[ expr_arm_names, - build::mk_lambda( - cx, + cx.mk_lambda( span, - build::mk_fn_decl( + cx.mk_fn_decl( ~[ - build::mk_arg( - cx, + cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span) + cx.mk_ty_infer(span) ), - build::mk_arg( - cx, + cx.mk_arg( span, cx.ident_of("__i"), - build::mk_ty_infer(cx, span) + cx.mk_ty_infer(span) ) ], - build::mk_ty_infer(cx, span) + cx.mk_ty_infer(span) ), - build::mk_expr( - cx, + cx.mk_expr( span, ast::expr_match( - build::mk_path(cx, span, ~[cx.ident_of("__i")]), + cx.mk_path(span, ~[cx.ident_of("__i")]), arms ) ) @@ -471,23 +452,22 @@ fn expand_deriving_decodable_enum_method( enum_definition ); - let d_arg = build::mk_arg(cx, + let d_arg = cx.mk_arg( span, cx.ident_of("__d"), - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); // Create the read_enum expression - let read_enum_expr = build::mk_method_call( - cx, + let read_enum_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__d")]), + cx.mk_path(span, ~[cx.ident_of("__d")]), cx.ident_of("read_enum"), ~[ - build::mk_base_str(cx, span, cx.str_of(type_ident)), - build::mk_lambda(cx, + cx.mk_base_str(span, cx.str_of(type_ident)), + cx.mk_lambda( span, - build::mk_fn_decl(~[d_arg], - build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[d_arg], + cx.mk_ty_infer(span)), read_enum_variant_expr), ] ); diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 128bbf39b16..eda1909aed4 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -79,7 +79,7 @@ would yield functions like: use ast; use ast::*; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::*; use codemap::{span, spanned}; use ast_util; @@ -107,12 +107,10 @@ fn create_derived_encodable_impl( generics: &Generics, method: @method ) -> @item { - let encoder_ty_param = build::mk_ty_param( - cx, + let encoder_ty_param = cx.mk_ty_param( cx.ident_of("__E"), @opt_vec::with( - build::mk_trait_ty_param_bound_global( - cx, + cx.mk_trait_ty_param_bound_global( span, ~[ cx.ident_of("std"), @@ -127,7 +125,7 @@ fn create_derived_encodable_impl( let generic_ty_params = opt_vec::with(encoder_ty_param); let methods = [method]; - let trait_path = build::mk_raw_path_global_( + let trait_path = cx.mk_raw_path_global_( span, ~[ cx.ident_of("std"), @@ -136,7 +134,7 @@ fn create_derived_encodable_impl( ], None, ~[ - build::mk_simple_ty_path(cx, span, cx.ident_of("__E")) + cx.mk_simple_ty_path(span, cx.ident_of("__E")) ] ); create_derived_impl( @@ -159,24 +157,23 @@ fn create_encode_method( statements: ~[@stmt] ) -> @method { // Create the `e` parameter. - let e_arg_type = build::mk_ty_rptr( - cx, + let e_arg_type = cx.mk_ty_rptr( span, - build::mk_simple_ty_path(cx, span, cx.ident_of("__E")), + cx.mk_simple_ty_path(span, cx.ident_of("__E")), None, ast::m_mutbl ); - let e_arg = build::mk_arg(cx, span, cx.ident_of("__e"), e_arg_type); + let e_arg = cx.mk_arg(span, cx.ident_of("__e"), e_arg_type); // Create the type of the return value. let output_type = @ast::Ty { id: cx.next_id(), node: ty_nil, span: span }; // Create the function declaration. let inputs = ~[e_arg]; - let fn_decl = build::mk_fn_decl(inputs, output_type); + let fn_decl = cx.mk_fn_decl(inputs, output_type); // Create the body block. - let body_block = build::mk_block_(cx, span, statements); + let body_block = cx.mk_block_(span, statements); // Create the method. let explicit_self = spanned { node: sty_region(None, m_imm), span: span }; @@ -203,12 +200,11 @@ fn call_substructure_encode_method( ) -> @ast::expr { // Gather up the parameters we want to chain along. let e_ident = cx.ident_of("__e"); - let e_expr = build::mk_path(cx, span, ~[e_ident]); + let e_expr = cx.mk_path(span, ~[e_ident]); // Call the substructure method. let encode_ident = cx.ident_of("encode"); - build::mk_method_call( - cx, + cx.mk_method_call( span, self_field, encode_ident, @@ -279,9 +275,9 @@ fn expand_deriving_encodable_struct_method( match struct_field.node.kind { named_field(ident, _) => { // Create the accessor for this field. - let self_field = build::mk_access_(cx, + let self_field = cx.mk_access_( span, - build::make_self(cx, span), + cx.make_self(span), ident); // Call the substructure method. @@ -292,31 +288,29 @@ fn expand_deriving_encodable_struct_method( ); let e_ident = cx.ident_of("__e"); - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, e_ident, - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let blk_expr = build::mk_lambda( - cx, + let blk_expr = cx.mk_lambda( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), encode_expr ); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__e")]), + cx.mk_path(span, ~[cx.ident_of("__e")]), cx.ident_of("emit_struct_field"), ~[ - build::mk_base_str(cx, span, cx.str_of(ident)), - build::mk_uint(cx, span, idx), + cx.mk_base_str(span, cx.str_of(ident)), + cx.mk_uint(span, idx), blk_expr ] ); - statements.push(build::mk_stmt(cx, span, call_expr)); + statements.push(cx.mk_stmt(span, call_expr)); } unnamed_field => { cx.span_unimpl( @@ -328,33 +322,30 @@ fn expand_deriving_encodable_struct_method( idx += 1; } - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, cx.ident_of("__e"), - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let emit_struct_stmt = build::mk_method_call( - cx, + let emit_struct_stmt = cx.mk_method_call( span, - build::mk_path( - cx, + cx.mk_path( span, ~[cx.ident_of("__e")] ), cx.ident_of("emit_struct"), ~[ - build::mk_base_str(cx, span, cx.str_of(type_ident)), - build::mk_uint(cx, span, statements.len()), - build::mk_lambda_stmts( - cx, + cx.mk_base_str(span, cx.str_of(type_ident)), + cx.mk_uint(span, statements.len()), + cx.mk_lambda_stmts( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), statements ), ] ); - let statements = ~[build::mk_stmt(cx, span, emit_struct_stmt)]; + let statements = ~[cx.mk_stmt(span, emit_struct_stmt)]; // Create the method itself. return create_encode_method(cx, span, statements); @@ -382,56 +373,52 @@ fn expand_deriving_encodable_enum_method( let expr = call_substructure_encode_method(cx, span, field); let e_ident = cx.ident_of("__e"); - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, e_ident, - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); - let blk_expr = build::mk_lambda( - cx, + let blk_expr = cx.mk_lambda( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), expr ); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__e")]), + cx.mk_path(span, ~[cx.ident_of("__e")]), cx.ident_of("emit_enum_variant_arg"), ~[ - build::mk_uint(cx, span, j), + cx.mk_uint(span, j), blk_expr, ] ); - stmts.push(build::mk_stmt(cx, span, call_expr)); + stmts.push(cx.mk_stmt(span, call_expr)); } // Create the pattern body. - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, cx.ident_of("__e"), - build::mk_ty_infer(cx, span)); - let call_expr = build::mk_method_call( - cx, + cx.mk_ty_infer(span)); + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__e")]), + cx.mk_path(span, ~[cx.ident_of("__e")]), cx.ident_of("emit_enum_variant"), ~[ - build::mk_base_str(cx, span, cx.str_of(variant.node.name)), - build::mk_uint(cx, span, i), - build::mk_uint(cx, span, variant_arg_len), - build::mk_lambda_stmts( - cx, + cx.mk_base_str(span, cx.str_of(variant.node.name)), + cx.mk_uint(span, i), + cx.mk_uint(span, variant_arg_len), + cx.mk_lambda_stmts( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), stmts ) ] ); - let match_body_block = build::mk_simple_block(cx, span, call_expr); + let match_body_block = cx.mk_simple_block(span, call_expr); // Create the arm. ast::arm { @@ -442,31 +429,29 @@ fn expand_deriving_encodable_enum_method( }; let e_ident = cx.ident_of("__e"); - let e_arg = build::mk_arg(cx, + let e_arg = cx.mk_arg( span, e_ident, - build::mk_ty_infer(cx, span)); + cx.mk_ty_infer(span)); // Create the method body. - let lambda_expr = build::mk_lambda( - cx, + let lambda_expr = cx.mk_lambda( span, - build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)), + cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)), expand_enum_or_struct_match(cx, span, arms) ); - let call_expr = build::mk_method_call( - cx, + let call_expr = cx.mk_method_call( span, - build::mk_path(cx, span, ~[cx.ident_of("__e")]), + cx.mk_path(span, ~[cx.ident_of("__e")]), cx.ident_of("emit_enum"), ~[ - build::mk_base_str(cx, span, cx.str_of(type_ident)), + cx.mk_base_str(span, cx.str_of(type_ident)), lambda_expr, ] ); - let stmt = build::mk_stmt(cx, span, call_expr); + let stmt = cx.mk_stmt(span, call_expr); // Create the method. create_encode_method(cx, span, ~[stmt]) diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 0bb97ec3122..4859fec2e44 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -166,7 +166,7 @@ use ast; use ast::{enum_def, expr, ident, Generics, struct_def}; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::*; use codemap::{span,respan}; use opt_vec; @@ -431,7 +431,7 @@ impl<'self> MethodDef<'self> { let ident = cx.ident_of(fmt!("__arg_%u", i)); arg_tys.push((ident, ast_ty)); - let arg_expr = build::mk_path(cx, span, ~[ident]); + let arg_expr = cx.mk_path(span, ~[ident]); match *ty { // for static methods, just treat any Self @@ -440,7 +440,7 @@ impl<'self> MethodDef<'self> { self_args.push(arg_expr); } Ptr(~Self, _) if nonstatic => { - self_args.push(build::mk_deref(cx, span, arg_expr)) + self_args.push(cx.mk_deref(span, arg_expr)) } _ => { nonself_args.push(arg_expr); @@ -461,14 +461,14 @@ impl<'self> MethodDef<'self> { let fn_generics = self.generics.to_generics(cx, span, type_ident, generics); let args = do arg_types.map |&(id, ty)| { - build::mk_arg(cx, span, id, ty) + cx.mk_arg(span, id, ty) }; let ret_type = self.get_ret_ty(cx, span, generics, type_ident); let method_ident = cx.ident_of(self.name); - let fn_decl = build::mk_fn_decl(args, ret_type); - let body_block = build::mk_simple_block(cx, span, body); + let fn_decl = cx.mk_fn_decl(args, ret_type); + let body_block = cx.mk_simple_block(span, body); // Create the method. @@ -558,10 +558,10 @@ impl<'self> MethodDef<'self> { let match_arm = ast::arm { pats: ~[ pat ], guard: None, - body: build::mk_simple_block(cx, span, body) + body: cx.mk_simple_block(span, body) }; - body = build::mk_expr(cx, span, ast::expr_match(arg_expr, ~[match_arm])) + body = cx.mk_expr(span, ast::expr_match(arg_expr, ~[match_arm])) } body } @@ -738,15 +738,15 @@ impl<'self> MethodDef<'self> { matches_so_far, match_count + 1); matches_so_far.pop(); - arms.push(build::mk_arm(cx, span, ~[ pattern ], arm_expr)); + arms.push(cx.mk_arm(span, ~[ pattern ], arm_expr)); if enum_def.variants.len() > 1 { let e = &EnumNonMatching(&[]); let wild_expr = self.call_substructure_method(cx, span, type_ident, self_args, nonself_args, e); - let wild_arm = build::mk_arm(cx, span, - ~[ build::mk_pat_wild(cx, span) ], + let wild_arm = cx.mk_arm(span, + ~[ cx.mk_pat_wild(span) ], wild_expr); arms.push(wild_arm); } @@ -774,13 +774,13 @@ impl<'self> MethodDef<'self> { match_count + 1); matches_so_far.pop(); - let arm = build::mk_arm(cx, span, ~[ pattern ], arm_expr); + let arm = cx.mk_arm(span, ~[ pattern ], arm_expr); arms.push(arm); } } // match foo { arm, arm, arm, ... } - build::mk_expr(cx, span, + cx.mk_expr(span, ast::expr_match(self_args[match_count], arms)) } } @@ -887,7 +887,7 @@ pub fn cs_same_method(f: &fn(@ExtCtxt, span, ~[@expr]) -> @expr, EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { // call self_n.method(other_1_n, other_2_n, ...) let called = do all_fields.map |&(_, self_field, other_fields)| { - build::mk_method_call(cx, span, + cx.mk_method_call(span, self_field, substructure.method_ident, other_fields) @@ -945,7 +945,7 @@ pub fn cs_binop(binop: ast::binop, base: @expr, cs_same_method_fold( true, // foldl is good enough |cx, span, old, new| { - build::mk_binary(cx, span, + cx.mk_binary(span, binop, old, new) @@ -960,7 +960,7 @@ pub fn cs_binop(binop: ast::binop, base: @expr, pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { - cs_binop(ast::or, build::mk_bool(cx, span, false), + cs_binop(ast::or, cx.mk_bool(span, false), enum_nonmatch_f, cx, span, substructure) } @@ -969,7 +969,7 @@ pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc, cx: @ExtCtxt, span: span, substructure: &Substructure) -> @expr { - cs_binop(ast::and, build::mk_bool(cx, span, true), + cs_binop(ast::and, cx.mk_bool(span, true), enum_nonmatch_f, cx, span, substructure) } diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index c655eef34d1..cc89bae37b7 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -11,7 +11,7 @@ use ast::{meta_item, item, expr, and}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_iter_bytes(cx: @ExtCtxt, @@ -48,7 +48,7 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @ }; let iter_bytes_ident = substr.method_ident; let call_iterbytes = |thing_expr| { - build::mk_method_call(cx, span, + cx.mk_method_call(span, thing_expr, iter_bytes_ident, copy lsb0_f) }; @@ -63,7 +63,7 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @ // iteration function. let discriminant = match variant.node.disr_expr { Some(copy d)=> d, - None => build::mk_uint(cx, span, index) + None => cx.mk_uint(span, index) }; exprs.push(call_iterbytes(discriminant)); @@ -82,6 +82,6 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @ } do vec::foldl(exprs[0], exprs.slice(1, exprs.len())) |prev, me| { - build::mk_binary(cx, span, and, prev, *me) + cx.mk_binary(span, and, prev, *me) } } diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 4a6c7803838..a7f70236251 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -21,7 +21,7 @@ library. use ast; use ast::{Ty, enum_def, expr, ident, item, Generics, meta_item, struct_def}; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use codemap::{span, respan}; use parse::token::special_idents::clownshoes_extensions; use opt_vec; @@ -172,7 +172,7 @@ pub fn create_self_type_with_params(cx: @ExtCtxt, // Create the type parameters on the `self` path. let mut self_ty_params = ~[]; for generics.ty_params.each |ty_param| { - let self_ty_param = build::mk_simple_ty_path(cx, + let self_ty_param = cx.mk_simple_ty_path( span, ty_param.ident); self_ty_params.push(self_ty_param); @@ -186,11 +186,11 @@ pub fn create_self_type_with_params(cx: @ExtCtxt, // Create the type of `self`. - let self_type = build::mk_raw_path_(span, - ~[ type_ident ], + let self_type = cx.mk_raw_path_(span, + ~[ type_ident ], lifetime, self_ty_params); - build::mk_ty_path_path(cx, span, self_type) + cx.mk_ty_path_path(span, self_type) } pub fn create_derived_impl(cx: @ExtCtxt, @@ -222,18 +222,18 @@ pub fn create_derived_impl(cx: @ExtCtxt, for generics.ty_params.each |ty_param| { // extra restrictions on the generics parameters to the type being derived upon let mut bounds = do bounds_paths.map |&bound_path| { - build::mk_trait_ty_param_bound_(cx, bound_path) + cx.mk_trait_ty_param_bound_(bound_path) }; let this_trait_bound = - build::mk_trait_ty_param_bound_(cx, trait_path); + cx.mk_trait_ty_param_bound_(trait_path); bounds.push(this_trait_bound); - impl_generics.ty_params.push(build::mk_ty_param(cx, ty_param.ident, @bounds)); + impl_generics.ty_params.push(cx.mk_ty_param(ty_param.ident, @bounds)); } // Create the reference to the trait. - let trait_ref = build::mk_trait_ref_(cx, trait_path); + let trait_ref = cx.mk_trait_ref_(trait_path); // Create the type of `self`. let self_type = create_self_type_with_params(cx, @@ -255,7 +255,7 @@ pub fn create_subpatterns(cx: @ExtCtxt, mutbl: ast::mutability) -> ~[@ast::pat] { do field_paths.map |&path| { - build::mk_pat(cx, span, + cx.mk_pat(span, ast::pat_ident(ast::bind_by_ref(mutbl), path, None)) } } @@ -274,12 +274,12 @@ pub fn create_struct_pattern(cx: @ExtCtxt, -> (@ast::pat, ~[(Option, @expr)]) { if struct_def.fields.is_empty() { return ( - build::mk_pat_ident_with_binding_mode( - cx, span, struct_ident, ast::bind_infer), + cx.mk_pat_ident_with_binding_mode( + span, struct_ident, ast::bind_infer), ~[]); } - let matching_path = build::mk_raw_path(span, ~[ struct_ident ]); + let matching_path = cx.mk_raw_path(span, ~[ struct_ident ]); let mut paths = ~[], ident_expr = ~[]; @@ -301,10 +301,10 @@ pub fn create_struct_pattern(cx: @ExtCtxt, cx.span_bug(span, "A struct with named and unnamed fields in `deriving`"); } }; - let path = build::mk_raw_path(span, + let path = cx.mk_raw_path(span, ~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]); paths.push(path); - ident_expr.push((opt_id, build::mk_path_raw(cx, span, path))); + ident_expr.push((opt_id, cx.mk_path_raw(span, path))); } let subpats = create_subpatterns(cx, span, paths, mutbl); @@ -318,9 +318,9 @@ pub fn create_struct_pattern(cx: @ExtCtxt, push(ast::field_pat { ident: id.get(), pat: pat }) } }; - build::mk_pat_struct(cx, span, matching_path, field_pats) + cx.mk_pat_struct(span, matching_path, field_pats) } else { - build::mk_pat_enum(cx, span, matching_path, subpats) + cx.mk_pat_enum(span, matching_path, subpats) }; (pattern, ident_expr) @@ -337,24 +337,24 @@ pub fn create_enum_variant_pattern(cx: @ExtCtxt, match variant.node.kind { ast::tuple_variant_kind(ref variant_args) => { if variant_args.is_empty() { - return (build::mk_pat_ident_with_binding_mode( - cx, span, variant_ident, ast::bind_infer), ~[]); + return (cx.mk_pat_ident_with_binding_mode( + span, variant_ident, ast::bind_infer), ~[]); } - let matching_path = build::mk_raw_path(span, ~[ variant_ident ]); + let matching_path = cx.mk_raw_path(span, ~[ variant_ident ]); let mut paths = ~[], ident_expr = ~[]; for uint::range(0, variant_args.len()) |i| { - let path = build::mk_raw_path(span, + let path = cx.mk_raw_path(span, ~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]); paths.push(path); - ident_expr.push((None, build::mk_path_raw(cx, span, path))); + ident_expr.push((None, cx.mk_path_raw(span, path))); } let subpats = create_subpatterns(cx, span, paths, mutbl); - (build::mk_pat_enum(cx, span, matching_path, subpats), + (cx.mk_pat_enum(span, matching_path, subpats), ident_expr) } ast::struct_variant_kind(struct_def) => { @@ -377,8 +377,8 @@ pub fn expand_enum_or_struct_match(cx: @ExtCtxt, span: span, arms: ~[ ast::arm ]) -> @expr { - let self_expr = build::make_self(cx, span); - let self_expr = build::mk_unary(cx, span, ast::deref, self_expr); + let self_expr = cx.make_self(span); + let self_expr = cx.mk_unary(span, ast::deref, self_expr); let self_match_expr = ast::expr_match(self_expr, arms); - build::mk_expr(cx, span, self_match_expr) + cx.mk_expr(span, self_match_expr) } diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 64cf7e93b92..b8e9de22fb0 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -12,7 +12,7 @@ use ast; use ast::{meta_item, item, expr, ident}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::{AstBuilder, Duplicate, Field}; use ext::deriving::generic::*; pub fn expand_deriving_rand(cx: @ExtCtxt, @@ -59,10 +59,10 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cx.ident_of("rand") ]; let rand_call = || { - build::mk_call_global(cx, + cx.mk_call_global( span, copy rand_ident, - ~[ build::duplicate_expr(cx, rng[0]) ]) + ~[ rng[0].duplicate(cx) ]) }; return match *substr.fields { @@ -74,30 +74,30 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { cx.span_fatal(span, "`Rand` cannot be derived for enums with no variants"); } - let variant_count = build::mk_uint(cx, span, variants.len()); + let variant_count = cx.mk_uint(span, variants.len()); // need to specify the uint-ness of the random number - let u32_ty = build::mk_ty_path(cx, span, ~[cx.ident_of("uint")]); - let r_ty = build::mk_ty_path(cx, span, ~[cx.ident_of("R")]); - let rand_name = build::mk_raw_path_(span, copy rand_ident, None, ~[ u32_ty, r_ty ]); - let rand_name = build::mk_path_raw(cx, span, rand_name); + let u32_ty = cx.mk_ty_path(span, ~[cx.ident_of("uint")]); + let r_ty = cx.mk_ty_path(span, ~[cx.ident_of("R")]); + let rand_name = cx.mk_raw_path_(span, copy rand_ident, None, ~[ u32_ty, r_ty ]); + let rand_name = cx.mk_path_raw(span, rand_name); - let rv_call = build::mk_call_(cx, + let rv_call = cx.mk_call_( span, rand_name, - ~[ build::duplicate_expr(cx, rng[0]) ]); + ~[ rng[0].duplicate(cx) ]); // rand() % variants.len() - let rand_variant = build::mk_binary(cx, span, ast::rem, + let rand_variant = cx.mk_binary(span, ast::rem, rv_call, variant_count); let mut arms = do variants.mapi |i, id_sum| { - let i_expr = build::mk_uint(cx, span, i); - let pat = build::mk_pat_lit(cx, span, i_expr); + let i_expr = cx.mk_uint(span, i); + let pat = cx.mk_pat_lit(span, i_expr); match *id_sum { (ident, ref summary) => { - build::mk_arm(cx, span, + cx.mk_arm(span, ~[ pat ], rand_thing(cx, span, ident, summary, rand_call)) } @@ -105,9 +105,9 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { }; // _ => {} at the end. Should never occur - arms.push(build::mk_unreachable_arm(cx, span)); + arms.push(cx.mk_unreachable_arm(span)); - build::mk_expr(cx, span, + cx.mk_expr(span, ast::expr_match(rand_variant, arms)) } _ => cx.bug("Non-static method in `deriving(Rand)`") @@ -121,20 +121,20 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { match *summary { Left(copy count) => { if count == 0 { - build::mk_path(cx, span, ctor_ident) + cx.mk_path(span, ctor_ident) } else { let exprs = vec::from_fn(count, |_| rand_call()); - build::mk_call(cx, span, ctor_ident, exprs) + cx.mk_call(span, ctor_ident, exprs) } } Right(ref fields) => { let rand_fields = do fields.map |ident| { - build::Field { + Field { ident: *ident, ex: rand_call() } }; - build::mk_struct_e(cx, span, ctor_ident, rand_fields) + cx.mk_struct_e(span, ctor_ident, rand_fields) } } } diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index 19fd601186b..9198c67177e 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -11,7 +11,7 @@ use ast::{meta_item, item, expr}; use codemap::span; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use ext::deriving::generic::*; pub fn expand_deriving_to_str(cx: @ExtCtxt, @@ -42,8 +42,8 @@ pub fn expand_deriving_to_str(cx: @ExtCtxt, fn to_str_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { match substr.self_args { [self_obj] => { - let self_addr = build::mk_addr_of(cx, span, self_obj); - build::mk_call_global(cx, span, + let self_addr = cx.mk_addr_of(span, self_obj); + cx.mk_call_global(span, ~[cx.ident_of("core"), cx.ident_of("sys"), cx.ident_of("log_str")], diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 154e7647bb5..a9d13bfe79c 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -16,7 +16,7 @@ explicit `Self` type to use when specifying impls to be derived. use ast; use ast::{expr,Generics,ident}; use ext::base::ExtCtxt; -use ext::build; +use ext::build::AstBuilder; use codemap::{span,respan}; use opt_vec; @@ -55,7 +55,7 @@ pub impl<'self> Path<'self> { fn to_ty(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> @ast::Ty { - build::mk_ty_path_path(cx, span, + cx.mk_ty_path_path(span, self.to_path(cx, span, self_ty, self_generics)) } @@ -66,9 +66,9 @@ pub impl<'self> Path<'self> { let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics)); if self.global { - build::mk_raw_path_global_(span, idents, lt, tys) + cx.mk_raw_path_global_(span, idents, lt, tys) } else { - build::mk_raw_path_(span, idents, lt, tys) + cx.mk_raw_path_(span, idents, lt, tys) } } } @@ -106,7 +106,7 @@ pub fn nil_ty() -> Ty<'static> { fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<@ast::Lifetime> { match *lt { - Some(ref s) => Some(@build::mk_lifetime(cx, span, cx.ident_of(*s))), + Some(ref s) => Some(@cx.mk_lifetime(span, cx.ident_of(*s))), None => None } } @@ -119,20 +119,20 @@ pub impl<'self> Ty<'self> { let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); match *ptr { Owned => { - build::mk_ty_uniq(cx, span, raw_ty) + cx.mk_ty_uniq(span, raw_ty) } Managed(mutbl) => { - build::mk_ty_box(cx, span, raw_ty, mutbl) + cx.mk_ty_box(span, raw_ty, mutbl) } Borrowed(ref lt, mutbl) => { let lt = mk_lifetime(cx, span, lt); - build::mk_ty_rptr(cx, span, raw_ty, lt, mutbl) + cx.mk_ty_rptr(span, raw_ty, lt, mutbl) } } } Literal(ref p) => { p.to_ty(cx, span, self_ty, self_generics) } Self => { - build::mk_ty_path_path(cx, span, self.to_path(cx, span, self_ty, self_generics)) + cx.mk_ty_path_path(span, self.to_path(cx, span, self_ty, self_generics)) } Tuple(ref fields) => { let ty = if fields.is_empty() { @@ -141,7 +141,7 @@ pub impl<'self> Ty<'self> { ast::ty_tup(fields.map(|f| f.to_ty(cx, span, self_ty, self_generics))) }; - build::mk_ty(cx, span, ty) + cx.mk_ty(span, ty) } } } @@ -151,7 +151,7 @@ pub impl<'self> Ty<'self> { match *self { Self => { let self_params = do self_generics.ty_params.map |ty_param| { - build::mk_ty_path(cx, span, ~[ ty_param.ident ]) + cx.mk_ty_path(span, ~[ ty_param.ident ]) }; let lifetime = if self_generics.lifetimes.is_empty() { None @@ -159,7 +159,7 @@ pub impl<'self> Ty<'self> { Some(@*self_generics.lifetimes.get(0)) }; - build::mk_raw_path_(span, ~[self_ty], lifetime, + cx.mk_raw_path_(span, ~[self_ty], lifetime, opt_vec::take_vec(self_params)) } Literal(ref p) => { @@ -177,9 +177,9 @@ fn mk_ty_param(cx: @ExtCtxt, span: span, name: &str, bounds: &[Path], let bounds = opt_vec::from( do bounds.map |b| { let path = b.to_path(cx, span, self_ident, self_generics); - build::mk_trait_ty_param_bound_(cx, path) + cx.mk_trait_ty_param_bound_(path) }); - build::mk_ty_param(cx, cx.ident_of(name), @bounds) + cx.mk_ty_param(cx.ident_of(name), @bounds) } fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Generics { @@ -204,7 +204,7 @@ pub impl<'self> LifetimeBounds<'self> { fn to_generics(&self, cx: @ExtCtxt, span: span, self_ty: ident, self_generics: &Generics) -> Generics { let lifetimes = do self.lifetimes.map |lt| { - build::mk_lifetime(cx, span, cx.ident_of(*lt)) + cx.mk_lifetime(span, cx.ident_of(*lt)) }; let ty_params = do self.bounds.map |t| { match t { @@ -220,7 +220,7 @@ pub impl<'self> LifetimeBounds<'self> { pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option) -> (@expr, ast::explicit_self) { - let self_path = build::make_self(cx, span); + let self_path = cx.make_self(span); match *self_ptr { None => { (self_path, respan(span, ast::sty_value)) @@ -232,12 +232,12 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option) Owned => ast::sty_uniq(ast::m_imm), Managed(mutbl) => ast::sty_box(mutbl), Borrowed(ref lt, mutbl) => { - let lt = lt.map(|s| @build::mk_lifetime(cx, span, + let lt = lt.map(|s| @cx.mk_lifetime(span, cx.ident_of(*s))); ast::sty_region(lt, mutbl) } }); - let self_expr = build::mk_deref(cx, span, self_path); + let self_expr = cx.mk_deref(span, self_path); (self_expr, self_ty) } } diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 3d74595e645..fb7367b47ba 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -18,7 +18,7 @@ use ast; use codemap::span; use ext::base::*; use ext::base; -use ext::build::mk_base_str; +use ext::build::AstBuilder; pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { @@ -29,8 +29,8 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) // Option rather than just an maybe-empty string. let e = match os::getenv(var) { - None => mk_base_str(cx, sp, ~""), - Some(ref s) => mk_base_str(cx, sp, copy *s) + None => cx.mk_base_str(sp, ~""), + Some(ref s) => cx.mk_base_str(sp, copy *s) }; MRExpr(e) } diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index ca281a22e39..1e4ff03b610 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -19,7 +19,7 @@ use codemap::span; use ext::base::*; use ext::base; use ext::build; -use ext::build::*; +use ext::build::AstBuilder; use core::unstable::extfmt::ct::*; @@ -56,7 +56,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, } fn make_rt_path_expr(cx: @ExtCtxt, sp: span, nm: &str) -> @ast::expr { let path = make_path_vec(cx, nm); - return mk_path_global(cx, sp, path); + cx.mk_path_global(sp, path) } // Produces an AST expression that represents a RT::conv record, // which tells the RT::conv* functions how to perform the conversion @@ -72,7 +72,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, FlagSignAlways => "flag_sign_always", FlagAlternate => "flag_alternate" }; - tmp_expr = mk_binary(cx, sp, ast::bitor, tmp_expr, + tmp_expr = cx.mk_binary(sp, ast::bitor, tmp_expr, make_rt_path_expr(cx, sp, fstr)); } return tmp_expr; @@ -83,10 +83,10 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, return make_rt_path_expr(cx, sp, "CountImplied"); } CountIs(c) => { - let count_lit = mk_uint(cx, sp, c as uint); + let count_lit = cx.mk_uint(sp, c as uint); let count_is_path = make_path_vec(cx, "CountIs"); let count_is_args = ~[count_lit]; - return mk_call_global(cx, sp, count_is_path, count_is_args); + return cx.mk_call_global(sp, count_is_path, count_is_args); } _ => cx.span_unimpl(sp, "unimplemented fmt! conversion") } @@ -107,8 +107,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { let intr = cx.parse_sess().interner; - mk_global_struct_e( - cx, + cx.mk_global_struct_e( sp, make_path_vec(cx, "Conv"), ~[ @@ -140,7 +139,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, let path = make_path_vec(cx, fname); let cnv_expr = make_rt_conv_expr(cx, sp, cnv); let args = ~[cnv_expr, arg, buf]; - return mk_call_global(cx, arg.span, path, args); + cx.mk_call_global(arg.span, path, args) } fn make_new_conv(cx: @ExtCtxt, sp: span, cnv: &Conv, @@ -198,10 +197,10 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, TyChar => ("char", arg), TyBits | TyOctal | TyHex(_) | TyInt(Unsigned) => ("uint", arg), TyFloat => ("float", arg), - TyPoly => ("poly", mk_addr_of(cx, sp, arg)) + TyPoly => ("poly", cx.mk_addr_of(sp, arg)) }; return make_conv_call(cx, arg.span, name, cnv, actual_arg, - mk_mut_addr_of(cx, arg.span, buf)); + cx.mk_mut_addr_of(arg.span, buf)); } fn log_conv(c: &Conv) { debug!("Building conversion:"); @@ -259,7 +258,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, /* 'ident' is the local buffer building up the result of fmt! */ let ident = cx.parse_sess().interner.intern("__fmtbuf"); - let buf = || mk_path(cx, fmt_sp, ~[ident]); + let buf = || cx.mk_path(fmt_sp, ~[ident]); let str_ident = cx.parse_sess().interner.intern("str"); let push_ident = cx.parse_sess().interner.intern("push_str"); let mut stms = ~[]; @@ -276,14 +275,14 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, buffer with it directly. If it's actually the only piece, then there's no need for it to be mutable */ if i == 0 { - stms.push(mk_local(cx, fmt_sp, npieces > 1, ident, mk_uniq_str(cx, fmt_sp, s))); + stms.push(cx.mk_local(fmt_sp, npieces > 1, ident, cx.mk_uniq_str(fmt_sp, s))); } else { - let args = ~[mk_mut_addr_of(cx, fmt_sp, buf()), mk_base_str(cx, fmt_sp, s)]; - let call = mk_call_global(cx, + let args = ~[cx.mk_mut_addr_of(fmt_sp, buf()), cx.mk_base_str(fmt_sp, s)]; + let call = cx.mk_call_global( fmt_sp, ~[str_ident, push_ident], args); - stms.push(mk_stmt(cx, fmt_sp, call)); + stms.push(cx.mk_stmt(fmt_sp, call)); } } @@ -300,12 +299,12 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, /* If the first portion is a conversion, then the local buffer must be initialized as an empty string */ if i == 0 { - stms.push(mk_local(cx, fmt_sp, true, ident, - mk_uniq_str(cx, fmt_sp, ~""))); + stms.push(cx.mk_local(fmt_sp, true, ident, + cx.mk_uniq_str(fmt_sp, ~""))); } - stms.push(mk_stmt(cx, fmt_sp, - make_new_conv(cx, fmt_sp, conv, - args[n], buf()))); + stms.push(cx.mk_stmt(fmt_sp, + make_new_conv(cx, fmt_sp, conv, + args[n], buf()))); } } } @@ -317,5 +316,5 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, nargs, expected_nargs)); } - return mk_block(cx, fmt_sp, ~[], stms, Some(buf())); + cx.mk_block(fmt_sp, ~[], stms, Some(buf())) } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 2ccceeec294..5ab28b50e84 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -12,7 +12,7 @@ use ast; use codemap::{BytePos, Pos, span}; use ext::base::ExtCtxt; use ext::base; -use ext::build; +use ext::build::AstBuilder; use parse::token::*; use parse::token; use parse; @@ -382,7 +382,7 @@ pub fn expand_quote_expr(cx: @ExtCtxt, pub fn expand_quote_item(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); + let e_attrs = cx.mk_uniq_vec_e(sp, ~[]); base::MRExpr(expand_parse_call(cx, sp, "parse_item", ~[e_attrs], tts)) } @@ -390,7 +390,7 @@ pub fn expand_quote_item(cx: @ExtCtxt, pub fn expand_quote_pat(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_refutable = build::mk_lit(cx, sp, ast::lit_bool(true)); + let e_refutable = cx.mk_lit(sp, ast::lit_bool(true)); base::MRExpr(expand_parse_call(cx, sp, "parse_pat", ~[e_refutable], tts)) } @@ -398,7 +398,7 @@ pub fn expand_quote_pat(cx: @ExtCtxt, pub fn expand_quote_ty(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_param_colons = build::mk_lit(cx, sp, ast::lit_bool(false)); + let e_param_colons = cx.mk_lit(sp, ast::lit_bool(false)); base::MRExpr(expand_parse_call(cx, sp, "parse_ty", ~[e_param_colons], tts)) } @@ -406,7 +406,7 @@ pub fn expand_quote_ty(cx: @ExtCtxt, pub fn expand_quote_stmt(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); + let e_attrs = cx.mk_uniq_vec_e(sp, ~[]); base::MRExpr(expand_parse_call(cx, sp, "parse_stmt", ~[e_attrs], tts)) } @@ -421,17 +421,17 @@ fn id_ext(cx: @ExtCtxt, str: &str) -> ast::ident { // Lift an ident to the expr that evaluates to that ident. fn mk_ident(cx: @ExtCtxt, sp: span, ident: ast::ident) -> @ast::expr { - let e_str = build::mk_base_str(cx, sp, cx.str_of(ident)); - build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), - id_ext(cx, "ident_of"), - ~[e_str]) + let e_str = cx.mk_base_str(sp, cx.str_of(ident)); + cx.mk_method_call(sp, + cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), + id_ext(cx, "ident_of"), + ~[e_str]) } fn mk_bytepos(cx: @ExtCtxt, sp: span, bpos: BytePos) -> @ast::expr { let path = ids_ext(cx, ~[~"BytePos"]); - let arg = build::mk_uint(cx, sp, bpos.to_uint()); - build::mk_call(cx, sp, path, ~[arg]) + let arg = cx.mk_uint(sp, bpos.to_uint()); + cx.mk_call(sp, path, ~[arg]) } fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr { @@ -447,7 +447,7 @@ fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr { SHL => "SHL", SHR => "SHR" }; - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[name.to_owned()])) } @@ -455,12 +455,12 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { match *tok { BINOP(binop) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"BINOP"]), ~[mk_binop(cx, sp, binop)]); } BINOPEQ(binop) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"BINOPEQ"]), ~[mk_binop(cx, sp, binop)]); } @@ -475,12 +475,12 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { ast::ty_i64 => ~"ty_i64" }; let e_ity = - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[s_ity])); - let e_i64 = build::mk_lit(cx, sp, ast::lit_int(i, ast::ty_i64)); + let e_i64 = cx.mk_lit(sp, ast::lit_int(i, ast::ty_i64)); - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_INT"]), ~[e_i64, e_ity]); } @@ -494,21 +494,21 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { ast::ty_u64 => ~"ty_u64" }; let e_uty = - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[s_uty])); - let e_u64 = build::mk_lit(cx, sp, ast::lit_uint(u, ast::ty_u64)); + let e_u64 = cx.mk_lit(sp, ast::lit_uint(u, ast::ty_u64)); - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_UINT"]), ~[e_u64, e_uty]); } LIT_INT_UNSUFFIXED(i) => { - let e_i64 = build::mk_lit(cx, sp, + let e_i64 = cx.mk_lit(sp, ast::lit_int(i, ast::ty_i64)); - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_INT_UNSUFFIXED"]), ~[e_i64]); } @@ -520,37 +520,37 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { ast::ty_f64 => ~"ty_f64" }; let e_fty = - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[s_fty])); let e_fident = mk_ident(cx, sp, fident); - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_FLOAT"]), ~[e_fident, e_fty]); } LIT_STR(ident) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIT_STR"]), ~[mk_ident(cx, sp, ident)]); } IDENT(ident, b) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"IDENT"]), ~[mk_ident(cx, sp, ident), - build::mk_lit(cx, sp, ast::lit_bool(b))]); + cx.mk_lit(sp, ast::lit_bool(b))]); } LIFETIME(ident) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"LIFETIME"]), ~[mk_ident(cx, sp, ident)]); } DOC_COMMENT(ident) => { - return build::mk_call(cx, sp, + return cx.mk_call(sp, ids_ext(cx, ~[~"DOC_COMMENT"]), ~[mk_ident(cx, sp, ident)]); } @@ -595,7 +595,7 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr { EOF => "EOF", _ => fail!() }; - build::mk_path(cx, sp, + cx.mk_path(sp, ids_ext(cx, ~[name.to_owned()])) } @@ -606,18 +606,18 @@ fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree) match *tt { ast::tt_tok(sp, ref tok) => { - let e_sp = build::mk_path(cx, sp, + let e_sp = cx.mk_path(sp, ids_ext(cx, ~[~"sp"])); let e_tok = - build::mk_call(cx, sp, + cx.mk_call(sp, ids_ext(cx, ~[~"tt_tok"]), ~[e_sp, mk_token(cx, sp, tok)]); let e_push = - build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ids_ext(cx, ~[~"tt"])), + cx.mk_method_call(sp, + cx.mk_path(sp, ids_ext(cx, ~[~"tt"])), id_ext(cx, "push"), ~[e_tok]); - ~[build::mk_stmt(cx, sp, e_push)] + ~[cx.mk_stmt(sp, e_push)] } @@ -629,19 +629,19 @@ fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree) // tt.push_all_move($ident.to_tokens(ext_cx)) let e_to_toks = - build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ~[ident]), + cx.mk_method_call(sp, + cx.mk_path(sp, ~[ident]), id_ext(cx, "to_tokens"), - ~[build::mk_path(cx, sp, + ~[cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"]))]); let e_push = - build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ids_ext(cx, ~[~"tt"])), + cx.mk_method_call(sp, + cx.mk_path(sp, ids_ext(cx, ~[~"tt"])), id_ext(cx, "push_all_move"), ~[e_to_toks]); - ~[build::mk_stmt(cx, sp, e_push)] + ~[cx.mk_stmt(sp, e_push)] } } } @@ -677,11 +677,11 @@ fn expand_tts(cx: @ExtCtxt, // We want to emit a block expression that does a sequence of 'use's to // import the runtime module, followed by a tt-building expression. - let uses = ~[ build::mk_glob_use(cx, sp, ast::public, - ids_ext(cx, ~[~"syntax", - ~"ext", - ~"quote", - ~"rt"])) ]; + let uses = ~[ cx.mk_glob_use(sp, ast::public, + ids_ext(cx, ~[~"syntax", + ~"ext", + ~"quote", + ~"rt"])) ]; // We also bind a single value, sp, to ext_cx.call_site() // @@ -709,23 +709,23 @@ fn expand_tts(cx: @ExtCtxt, // of quotes, for example) but at this point it seems not likely to be // worth the hassle. - let e_sp = build::mk_method_call(cx, sp, - build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), + let e_sp = cx.mk_method_call(sp, + cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), id_ext(cx, "call_site"), ~[]); - let stmt_let_sp = build::mk_local(cx, sp, false, + let stmt_let_sp = cx.mk_local(sp, false, id_ext(cx, "sp"), e_sp); - let stmt_let_tt = build::mk_local(cx, sp, true, + let stmt_let_tt = cx.mk_local(sp, true, id_ext(cx, "tt"), - build::mk_uniq_vec_e(cx, sp, ~[])); + cx.mk_uniq_vec_e(sp, ~[])); - build::mk_block(cx, sp, uses, + cx.mk_block(sp, uses, ~[stmt_let_sp, stmt_let_tt] + mk_tts(cx, sp, tts), - Some(build::mk_path(cx, sp, + Some(cx.mk_path(sp, ids_ext(cx, ~[~"tt"])))) } @@ -736,16 +736,16 @@ fn expand_parse_call(cx: @ExtCtxt, tts: &[ast::token_tree]) -> @ast::expr { let tts_expr = expand_tts(cx, sp, tts); - let cfg_call = || build::mk_method_call( - cx, sp, build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), + let cfg_call = || cx.mk_method_call( + sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), id_ext(cx, "cfg"), ~[]); - let parse_sess_call = || build::mk_method_call( - cx, sp, build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), + let parse_sess_call = || cx.mk_method_call( + sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])), id_ext(cx, "parse_sess"), ~[]); let new_parser_call = - build::mk_call_global(cx, sp, + cx.mk_call_global(sp, ids_ext(cx, ~[~"syntax", ~"ext", ~"quote", @@ -755,7 +755,7 @@ fn expand_parse_call(cx: @ExtCtxt, cfg_call(), tts_expr]); - build::mk_method_call(cx, sp, + cx.mk_method_call(sp, new_parser_call, id_ext(cx, parse_method), arg_exprs) diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index d78c06bec07..40dc44ca993 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -14,7 +14,7 @@ use codemap::{FileMap, Loc, Pos, ExpandedFrom, span}; use codemap::{CallInfo, NameAndSpan}; use ext::base::*; use ext::base; -use ext::build::{mk_base_vec_e, mk_uint, mk_u8, mk_base_str}; +use ext::build::AstBuilder; use parse; use print::pprust; @@ -30,7 +30,7 @@ pub fn expand_line(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); - base::MRExpr(mk_uint(cx, topmost.call_site, loc.line)) + base::MRExpr(cx.mk_uint(topmost.call_site, loc.line)) } /* col!(): expands to the current column number */ @@ -40,7 +40,7 @@ pub fn expand_col(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); - base::MRExpr(mk_uint(cx, topmost.call_site, loc.col.to_uint())) + base::MRExpr(cx.mk_uint(topmost.call_site, loc.col.to_uint())) } /* file!(): expands to the current filename */ @@ -53,19 +53,19 @@ pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let Loc { file: @FileMap { name: filename, _ }, _ } = cx.codemap().lookup_char_pos(topmost.call_site.lo); - base::MRExpr(mk_base_str(cx, topmost.call_site, filename)) + base::MRExpr(cx.mk_base_str(topmost.call_site, filename)) } pub fn expand_stringify(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let s = pprust::tts_to_str(tts, cx.parse_sess().interner); - base::MRExpr(mk_base_str(cx, sp, s)) + base::MRExpr(cx.mk_base_str(sp, s)) } pub fn expand_mod(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "module_path!"); - base::MRExpr(mk_base_str(cx, sp, + base::MRExpr(cx.mk_base_str(sp, str::connect(cx.mod_path().map( |x| cx.str_of(*x)), "::"))) } @@ -94,7 +94,7 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) } } - base::MRExpr(mk_base_str(cx, sp, result::unwrap(res))) + base::MRExpr(cx.mk_base_str(sp, result::unwrap(res))) } pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) @@ -103,9 +103,9 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) { result::Ok(src) => { let u8_exprs = vec::map(src, |char| { - mk_u8(cx, sp, *char) + cx.mk_u8(sp, *char) }); - base::MRExpr(mk_base_vec_e(cx, sp, u8_exprs)) + base::MRExpr(cx.mk_base_vec_e(sp, u8_exprs)) } result::Err(ref e) => { cx.parse_sess().span_diagnostic.handler().fatal((*e))