1
Fork 0

syntax/ext: migrate build.rs functions to AstBuilder methods.

This commit is contained in:
Huon Wilson 2013-05-18 00:19:28 +10:00
parent 8c15a0ec4c
commit 6e50515530
19 changed files with 1126 additions and 925 deletions

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@ use ast;
use codemap::span; use codemap::span;
use ext::base::*; use ext::base::*;
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 { pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult {
// Gather all argument expressions // 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 // string literal, push each byte to vector expression
ast::lit_str(s) => { ast::lit_str(s) => {
for s.each |byte| { 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 { if v > 0xFF {
cx.span_err(sp, "Too large u8 literal in bytes!") cx.span_err(sp, "Too large u8 literal in bytes!")
} else { } 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 { } else if v < 0 {
cx.span_err(sp, "Negative integer literal in bytes!") cx.span_err(sp, "Negative integer literal in bytes!")
} else { } 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 // char literal, push to vector expression
ast::lit_int(v, ast::ty_char) => { ast::lit_int(v, ast::ty_char) => {
if (v as char).is_ascii() { 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 { } else {
cx.span_err(sp, "Non-ascii char literal in bytes!") 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) MRExpr(e)
} }

View file

@ -12,6 +12,7 @@ use ast::{meta_item, item, expr};
use codemap::span; use codemap::span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build;
use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
@ -79,7 +80,7 @@ fn cs_clone(
let ctor_ident; let ctor_ident;
let all_fields; let all_fields;
let subcall = |field| let subcall = |field|
build::mk_method_call(cx, span, field, clone_ident, ~[]); cx.mk_method_call(span, field, clone_ident, ~[]);
match *substr.fields { match *substr.fields {
Struct(ref af) => { Struct(ref af) => {
@ -102,7 +103,7 @@ fn cs_clone(
[(None, _, _), .. _] => { [(None, _, _), .. _] => {
// enum-like // enum-like
let subcalls = all_fields.map(|&(_, self_f, _)| subcall(self_f)); 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 // struct-like
@ -118,9 +119,9 @@ fn cs_clone(
if fields.is_empty() { if fields.is_empty() {
// no fields, so construct like `None` // no fields, so construct like `None`
build::mk_path(cx, span, ctor_ident) cx.mk_path(span, ctor_ident)
} else { } else {
build::mk_struct_e(cx, span, cx.mk_struct_e(span,
ctor_ident, ctor_ident,
fields) fields)
} }

View file

@ -11,7 +11,7 @@
use ast::{meta_item, item, expr}; use ast::{meta_item, item, expr};
use codemap::span; use codemap::span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_eq(cx: @ExtCtxt, 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 // structures are equal if all fields are equal, and non equal, if
// any fields are not equal or if the enum variants are different // any fields are not equal or if the enum variants are different
fn cs_eq(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { 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) cx, span, substr)
} }
fn cs_ne(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { 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) cx, span, substr)
} }

View file

@ -12,7 +12,7 @@
use ast::{meta_item, item, expr_if, expr}; use ast::{meta_item, item, expr_if, expr};
use codemap::span; use codemap::span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_ord(cx: @ExtCtxt, pub fn expand_deriving_ord(cx: @ExtCtxt,
@ -62,10 +62,10 @@ fn cs_ord(less: bool, equal: bool,
} else { } else {
cx.ident_of("gt") 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))); Some(cx.mk_bool(span, false)));
let base = build::mk_bool(cx, span, equal); let base = cx.mk_bool(span, equal);
cs_fold( cs_fold(
false, // need foldr, 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)`"); 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()); 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 = 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()); self_f, binop, other_fs.to_owned());
let true_blk = build::mk_simple_block(cx, span, let true_blk = cx.mk_simple_block(span,
build::mk_bool(cx, span, true)); cx.mk_bool(span, true));
let if_ = expr_if(cmp, true_blk, Some(elseif)); let if_ = expr_if(cmp, true_blk, Some(elseif));
build::mk_expr(cx, span, if_) cx.mk_expr(span, if_)
}, },
base, base,
|cx, span, args, _| { |cx, span, args, _| {
@ -119,7 +119,7 @@ fn cs_ord(less: bool, equal: bool,
match args { match args {
[(self_var, _, _), [(self_var, _, _),
(other_var, _, _)] => (other_var, _, _)] =>
build::mk_bool(cx, span, cx.mk_bool(span,
if less { if less {
self_var < other_var self_var < other_var
} else { } else {

View file

@ -12,7 +12,7 @@
use ast::{meta_item, item, expr}; use ast::{meta_item, item, expr};
use codemap::span; use codemap::span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_totaleq(cx: @ExtCtxt, pub fn expand_deriving_totaleq(cx: @ExtCtxt,
@ -21,7 +21,7 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt,
in_items: ~[@item]) -> ~[@item] { in_items: ~[@item]) -> ~[@item] {
fn cs_equals(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { 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) cx, span, substr)
} }

View file

@ -11,7 +11,7 @@
use ast::{meta_item, item, expr}; use ast::{meta_item, item, expr};
use codemap::span; use codemap::span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
use core::cmp::{Ordering, Equal, Less, Greater}; use core::cmp::{Ordering, Equal, Less, Greater};
@ -47,7 +47,7 @@ pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> @expr {
Equal => "Equal", Equal => "Equal",
Greater => "Greater" Greater => "Greater"
}; };
build::mk_path_global(cx, span, cx.mk_path_global(span,
~[cx.ident_of("core"), ~[cx.ident_of("core"),
cx.ident_of("cmp"), cx.ident_of("cmp"),
cx.ident_of(cnst)]) 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 // foldr (possibly) nests the matches in lexical_ordering better
false, false,
|cx, span, old, new| { |cx, span, old, new| {
build::mk_call_global(cx, span, cx.mk_call_global(span,
~[cx.ident_of("core"), ~[cx.ident_of("core"),
cx.ident_of("cmp"), cx.ident_of("cmp"),
cx.ident_of("lexical_ordering")], cx.ident_of("lexical_ordering")],

View file

@ -16,7 +16,8 @@ encodable.rs for more.
use ast; use ast;
use ast::*; use ast::*;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::Field;
use ext::build::AstBuilder;
use ext::deriving::*; use ext::deriving::*;
use codemap::{span, spanned}; use codemap::{span, spanned};
use ast_util; use ast_util;
@ -44,12 +45,10 @@ fn create_derived_decodable_impl(
generics: &Generics, generics: &Generics,
method: @method method: @method
) -> @item { ) -> @item {
let decoder_ty_param = build::mk_ty_param( let decoder_ty_param = cx.mk_ty_param(
cx,
cx.ident_of("__D"), cx.ident_of("__D"),
@opt_vec::with( @opt_vec::with(
build::mk_trait_ty_param_bound_global( cx.mk_trait_ty_param_bound_global(
cx,
span, span,
~[ ~[
cx.ident_of("std"), cx.ident_of("std"),
@ -64,7 +63,7 @@ fn create_derived_decodable_impl(
let generic_ty_params = opt_vec::with(decoder_ty_param); let generic_ty_params = opt_vec::with(decoder_ty_param);
let methods = [method]; let methods = [method];
let trait_path = build::mk_raw_path_global_( let trait_path = cx.mk_raw_path_global_(
span, span,
~[ ~[
cx.ident_of("std"), cx.ident_of("std"),
@ -73,7 +72,7 @@ fn create_derived_decodable_impl(
], ],
None, 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( create_derived_impl(
@ -98,15 +97,14 @@ fn create_decode_method(
expr: @ast::expr expr: @ast::expr
) -> @method { ) -> @method {
// Create the `e` parameter. // Create the `e` parameter.
let d_arg_type = build::mk_ty_rptr( let d_arg_type = cx.mk_ty_rptr(
cx,
span, span,
build::mk_simple_ty_path(cx, span, cx.ident_of("__D")), cx.mk_simple_ty_path(span, cx.ident_of("__D")),
None, None,
ast::m_mutbl ast::m_mutbl
); );
let d_ident = cx.ident_of("__d"); 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. // Create the type of the return value.
let output_type = create_self_type_with_params( let output_type = create_self_type_with_params(
@ -118,10 +116,10 @@ fn create_decode_method(
// Create the function declaration. // Create the function declaration.
let inputs = ~[d_arg]; 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. // 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. // Create the method.
let explicit_self = spanned { node: sty_static, span: span }; let explicit_self = spanned { node: sty_static, span: span };
@ -146,11 +144,9 @@ fn call_substructure_decode_method(
span: span span: span
) -> @ast::expr { ) -> @ast::expr {
// Call the substructure method. // Call the substructure method.
build::mk_call_( cx.mk_call_(
cx,
span, span,
build::mk_path_global( cx.mk_path_global(
cx,
span, span,
~[ ~[
cx.ident_of("std"), 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, span: span,
idx: uint, idx: uint,
ident: ident ident: ident
) -> build::Field { ) -> Field {
// Call the substructure method. // Call the substructure method.
let decode_expr = call_substructure_decode_method(cx, span); let decode_expr = call_substructure_decode_method(cx, span);
let d_arg = build::mk_arg(cx, let d_arg = cx.mk_arg(
span, span,
cx.ident_of("__d"), cx.ident_of("__d"),
build::mk_ty_infer(cx, span)); cx.mk_ty_infer(span));
let call_expr = build::mk_method_call( let call_expr = cx.mk_method_call(
cx,
span, span,
build::mk_path(cx, span, ~[cx.ident_of("__d")]), cx.mk_path(span, ~[cx.ident_of("__d")]),
cx.ident_of("read_struct_field"), cx.ident_of("read_struct_field"),
~[ ~[
build::mk_base_str(cx, span, cx.str_of(ident)), cx.mk_base_str(span, cx.str_of(ident)),
build::mk_uint(cx, span, idx), cx.mk_uint(span, idx),
build::mk_lambda(cx, cx.mk_lambda(
span, span,
build::mk_fn_decl(~[d_arg], cx.mk_fn_decl(~[d_arg],
build::mk_ty_infer(cx, span)), cx.mk_ty_infer(span)),
decode_expr), decode_expr),
] ]
); );
build::Field { ident: ident, ex: call_expr } Field { ident: ident, ex: call_expr }
} }
fn create_read_struct_arg( fn create_read_struct_arg(
@ -255,22 +250,21 @@ fn create_read_struct_arg(
span: span, span: span,
idx: uint, idx: uint,
ident: ident ident: ident
) -> build::Field { ) -> Field {
// Call the substructure method. // Call the substructure method.
let decode_expr = call_substructure_decode_method(cx, span); let decode_expr = call_substructure_decode_method(cx, span);
let call_expr = build::mk_method_call( let call_expr = cx.mk_method_call(
cx,
span, span,
build::mk_path(cx, span, ~[cx.ident_of("__d")]), cx.mk_path(span, ~[cx.ident_of("__d")]),
cx.ident_of("read_struct_arg"), cx.ident_of("read_struct_arg"),
~[ ~[
build::mk_uint(cx, span, idx), cx.mk_uint(span, idx),
build::mk_lambda_no_args(cx, span, decode_expr), 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( fn expand_deriving_decodable_struct_method(
@ -298,29 +292,25 @@ fn expand_deriving_decodable_struct_method(
i += 1; i += 1;
} }
let d_arg = build::mk_arg(cx, let d_arg = cx.mk_arg(
span, span,
cx.ident_of("__d"), cx.ident_of("__d"),
build::mk_ty_infer(cx, span)); cx.mk_ty_infer(span));
let read_struct_expr = build::mk_method_call( let read_struct_expr = cx.mk_method_call(
cx,
span, span,
build::mk_path( cx.mk_path(
cx,
span, span,
~[cx.ident_of("__d")] ~[cx.ident_of("__d")]
), ),
cx.ident_of("read_struct"), cx.ident_of("read_struct"),
~[ ~[
build::mk_base_str(cx, span, cx.str_of(type_ident)), cx.mk_base_str(span, cx.str_of(type_ident)),
build::mk_uint(cx, span, fields.len()), cx.mk_uint(span, fields.len()),
build::mk_lambda( cx.mk_lambda(
cx,
span, span,
build::mk_fn_decl(~[d_arg], build::mk_ty_infer(cx, span)), cx.mk_fn_decl(~[d_arg], cx.mk_ty_infer(span)),
build::mk_struct_e( cx.mk_struct_e(
cx,
span, span,
~[type_ident], ~[type_ident],
fields fields
@ -340,14 +330,14 @@ fn create_read_variant_arg(
variant: &ast::variant variant: &ast::variant
) -> ast::arm { ) -> ast::arm {
// Create the matching pattern. // 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 // Feed each argument in this variant to the decode function
// as well. // as well.
let variant_arg_len = variant_arg_count(cx, span, variant); let variant_arg_len = variant_arg_count(cx, span, variant);
let expr = if variant_arg_len == 0 { let expr = if variant_arg_len == 0 {
build::mk_path(cx, span, ~[variant.node.name]) cx.mk_path(span, ~[variant.node.name])
} else { } else {
// Feed the discriminant to the decode function. // Feed the discriminant to the decode function.
let mut args = ~[]; let mut args = ~[];
@ -356,22 +346,21 @@ fn create_read_variant_arg(
// Call the substructure method. // Call the substructure method.
let expr = call_substructure_decode_method(cx, span); let expr = call_substructure_decode_method(cx, span);
let d_arg = build::mk_arg(cx, let d_arg = cx.mk_arg(
span, span,
cx.ident_of("__d"), cx.ident_of("__d"),
build::mk_ty_infer(cx, span)); cx.mk_ty_infer(span));
let t_infer = build::mk_ty_infer(cx, span); let t_infer = cx.mk_ty_infer(span);
let call_expr = build::mk_method_call( let call_expr = cx.mk_method_call(
cx,
span, 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"), cx.ident_of("read_enum_variant_arg"),
~[ ~[
build::mk_uint(cx, span, j), cx.mk_uint(span, j),
build::mk_lambda(cx, cx.mk_lambda(
span, span,
build::mk_fn_decl(~[d_arg], t_infer), cx.mk_fn_decl(~[d_arg], t_infer),
expr), expr),
] ]
); );
@ -379,8 +368,7 @@ fn create_read_variant_arg(
args.push(call_expr); args.push(call_expr);
} }
build::mk_call( cx.mk_call(
cx,
span, span,
~[variant.node.name], ~[variant.node.name],
args args
@ -388,7 +376,7 @@ fn create_read_variant_arg(
}; };
// Create the arm. // Create the arm.
build::mk_arm(cx, span, ~[pat], expr) cx.mk_arm(span, ~[pat], expr)
} }
fn create_read_enum_variant( fn create_read_enum_variant(
@ -397,12 +385,10 @@ fn create_read_enum_variant(
enum_definition: &enum_def enum_definition: &enum_def
) -> @expr { ) -> @expr {
// Create a vector that contains all the variant names. // Create a vector that contains all the variant names.
let expr_arm_names = build::mk_base_vec_e( let expr_arm_names = cx.mk_base_vec_e(
cx,
span, span,
do enum_definition.variants.map |variant| { do enum_definition.variants.map |variant| {
build::mk_base_str( cx.mk_base_str(
cx,
span, span,
cx.str_of(variant.node.name) cx.str_of(variant.node.name)
) )
@ -415,41 +401,36 @@ fn create_read_enum_variant(
}; };
// Add the impossible case arm. // 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. // Create the read_enum_variant expression.
build::mk_method_call( cx.mk_method_call(
cx,
span, span,
build::mk_path(cx, span, ~[cx.ident_of("__d")]), cx.mk_path(span, ~[cx.ident_of("__d")]),
cx.ident_of("read_enum_variant"), cx.ident_of("read_enum_variant"),
~[ ~[
expr_arm_names, expr_arm_names,
build::mk_lambda( cx.mk_lambda(
cx,
span, span,
build::mk_fn_decl( cx.mk_fn_decl(
~[ ~[
build::mk_arg( cx.mk_arg(
cx,
span, span,
cx.ident_of("__d"), cx.ident_of("__d"),
build::mk_ty_infer(cx, span) cx.mk_ty_infer(span)
), ),
build::mk_arg( cx.mk_arg(
cx,
span, span,
cx.ident_of("__i"), 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.mk_expr(
cx,
span, span,
ast::expr_match( ast::expr_match(
build::mk_path(cx, span, ~[cx.ident_of("__i")]), cx.mk_path(span, ~[cx.ident_of("__i")]),
arms arms
) )
) )
@ -471,23 +452,22 @@ fn expand_deriving_decodable_enum_method(
enum_definition enum_definition
); );
let d_arg = build::mk_arg(cx, let d_arg = cx.mk_arg(
span, span,
cx.ident_of("__d"), cx.ident_of("__d"),
build::mk_ty_infer(cx, span)); cx.mk_ty_infer(span));
// Create the read_enum expression // Create the read_enum expression
let read_enum_expr = build::mk_method_call( let read_enum_expr = cx.mk_method_call(
cx,
span, span,
build::mk_path(cx, span, ~[cx.ident_of("__d")]), cx.mk_path(span, ~[cx.ident_of("__d")]),
cx.ident_of("read_enum"), cx.ident_of("read_enum"),
~[ ~[
build::mk_base_str(cx, span, cx.str_of(type_ident)), cx.mk_base_str(span, cx.str_of(type_ident)),
build::mk_lambda(cx, cx.mk_lambda(
span, span,
build::mk_fn_decl(~[d_arg], cx.mk_fn_decl(~[d_arg],
build::mk_ty_infer(cx, span)), cx.mk_ty_infer(span)),
read_enum_variant_expr), read_enum_variant_expr),
] ]
); );

View file

@ -79,7 +79,7 @@ would yield functions like:
use ast; use ast;
use ast::*; use ast::*;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use ext::deriving::*; use ext::deriving::*;
use codemap::{span, spanned}; use codemap::{span, spanned};
use ast_util; use ast_util;
@ -107,12 +107,10 @@ fn create_derived_encodable_impl(
generics: &Generics, generics: &Generics,
method: @method method: @method
) -> @item { ) -> @item {
let encoder_ty_param = build::mk_ty_param( let encoder_ty_param = cx.mk_ty_param(
cx,
cx.ident_of("__E"), cx.ident_of("__E"),
@opt_vec::with( @opt_vec::with(
build::mk_trait_ty_param_bound_global( cx.mk_trait_ty_param_bound_global(
cx,
span, span,
~[ ~[
cx.ident_of("std"), cx.ident_of("std"),
@ -127,7 +125,7 @@ fn create_derived_encodable_impl(
let generic_ty_params = opt_vec::with(encoder_ty_param); let generic_ty_params = opt_vec::with(encoder_ty_param);
let methods = [method]; let methods = [method];
let trait_path = build::mk_raw_path_global_( let trait_path = cx.mk_raw_path_global_(
span, span,
~[ ~[
cx.ident_of("std"), cx.ident_of("std"),
@ -136,7 +134,7 @@ fn create_derived_encodable_impl(
], ],
None, 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( create_derived_impl(
@ -159,24 +157,23 @@ fn create_encode_method(
statements: ~[@stmt] statements: ~[@stmt]
) -> @method { ) -> @method {
// Create the `e` parameter. // Create the `e` parameter.
let e_arg_type = build::mk_ty_rptr( let e_arg_type = cx.mk_ty_rptr(
cx,
span, span,
build::mk_simple_ty_path(cx, span, cx.ident_of("__E")), cx.mk_simple_ty_path(span, cx.ident_of("__E")),
None, None,
ast::m_mutbl 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. // Create the type of the return value.
let output_type = @ast::Ty { id: cx.next_id(), node: ty_nil, span: span }; let output_type = @ast::Ty { id: cx.next_id(), node: ty_nil, span: span };
// Create the function declaration. // Create the function declaration.
let inputs = ~[e_arg]; 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. // Create the body block.
let body_block = build::mk_block_(cx, span, statements); let body_block = cx.mk_block_(span, statements);
// Create the method. // Create the method.
let explicit_self = spanned { node: sty_region(None, m_imm), span: span }; let explicit_self = spanned { node: sty_region(None, m_imm), span: span };
@ -203,12 +200,11 @@ fn call_substructure_encode_method(
) -> @ast::expr { ) -> @ast::expr {
// Gather up the parameters we want to chain along. // Gather up the parameters we want to chain along.
let e_ident = cx.ident_of("__e"); 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. // Call the substructure method.
let encode_ident = cx.ident_of("encode"); let encode_ident = cx.ident_of("encode");
build::mk_method_call( cx.mk_method_call(
cx,
span, span,
self_field, self_field,
encode_ident, encode_ident,
@ -279,9 +275,9 @@ fn expand_deriving_encodable_struct_method(
match struct_field.node.kind { match struct_field.node.kind {
named_field(ident, _) => { named_field(ident, _) => {
// Create the accessor for this field. // Create the accessor for this field.
let self_field = build::mk_access_(cx, let self_field = cx.mk_access_(
span, span,
build::make_self(cx, span), cx.make_self(span),
ident); ident);
// Call the substructure method. // Call the substructure method.
@ -292,31 +288,29 @@ fn expand_deriving_encodable_struct_method(
); );
let e_ident = cx.ident_of("__e"); let e_ident = cx.ident_of("__e");
let e_arg = build::mk_arg(cx, let e_arg = cx.mk_arg(
span, span,
e_ident, e_ident,
build::mk_ty_infer(cx, span)); cx.mk_ty_infer(span));
let blk_expr = build::mk_lambda( let blk_expr = cx.mk_lambda(
cx,
span, 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 encode_expr
); );
let call_expr = build::mk_method_call( let call_expr = cx.mk_method_call(
cx,
span, span,
build::mk_path(cx, span, ~[cx.ident_of("__e")]), cx.mk_path(span, ~[cx.ident_of("__e")]),
cx.ident_of("emit_struct_field"), cx.ident_of("emit_struct_field"),
~[ ~[
build::mk_base_str(cx, span, cx.str_of(ident)), cx.mk_base_str(span, cx.str_of(ident)),
build::mk_uint(cx, span, idx), cx.mk_uint(span, idx),
blk_expr blk_expr
] ]
); );
statements.push(build::mk_stmt(cx, span, call_expr)); statements.push(cx.mk_stmt(span, call_expr));
} }
unnamed_field => { unnamed_field => {
cx.span_unimpl( cx.span_unimpl(
@ -328,33 +322,30 @@ fn expand_deriving_encodable_struct_method(
idx += 1; idx += 1;
} }
let e_arg = build::mk_arg(cx, let e_arg = cx.mk_arg(
span, span,
cx.ident_of("__e"), cx.ident_of("__e"),
build::mk_ty_infer(cx, span)); cx.mk_ty_infer(span));
let emit_struct_stmt = build::mk_method_call( let emit_struct_stmt = cx.mk_method_call(
cx,
span, span,
build::mk_path( cx.mk_path(
cx,
span, span,
~[cx.ident_of("__e")] ~[cx.ident_of("__e")]
), ),
cx.ident_of("emit_struct"), cx.ident_of("emit_struct"),
~[ ~[
build::mk_base_str(cx, span, cx.str_of(type_ident)), cx.mk_base_str(span, cx.str_of(type_ident)),
build::mk_uint(cx, span, statements.len()), cx.mk_uint(span, statements.len()),
build::mk_lambda_stmts( cx.mk_lambda_stmts(
cx,
span, 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 statements
), ),
] ]
); );
let statements = ~[build::mk_stmt(cx, span, emit_struct_stmt)]; let statements = ~[cx.mk_stmt(span, emit_struct_stmt)];
// Create the method itself. // Create the method itself.
return create_encode_method(cx, span, statements); 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 expr = call_substructure_encode_method(cx, span, field);
let e_ident = cx.ident_of("__e"); let e_ident = cx.ident_of("__e");
let e_arg = build::mk_arg(cx, let e_arg = cx.mk_arg(
span, span,
e_ident, e_ident,
build::mk_ty_infer(cx, span)); cx.mk_ty_infer(span));
let blk_expr = build::mk_lambda( let blk_expr = cx.mk_lambda(
cx,
span, 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 expr
); );
let call_expr = build::mk_method_call( let call_expr = cx.mk_method_call(
cx,
span, 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"), cx.ident_of("emit_enum_variant_arg"),
~[ ~[
build::mk_uint(cx, span, j), cx.mk_uint(span, j),
blk_expr, blk_expr,
] ]
); );
stmts.push(build::mk_stmt(cx, span, call_expr)); stmts.push(cx.mk_stmt(span, call_expr));
} }
// Create the pattern body. // Create the pattern body.
let e_arg = build::mk_arg(cx, let e_arg = cx.mk_arg(
span, span,
cx.ident_of("__e"), cx.ident_of("__e"),
build::mk_ty_infer(cx, span)); cx.mk_ty_infer(span));
let call_expr = build::mk_method_call( let call_expr = cx.mk_method_call(
cx,
span, span,
build::mk_path(cx, span, ~[cx.ident_of("__e")]), cx.mk_path(span, ~[cx.ident_of("__e")]),
cx.ident_of("emit_enum_variant"), cx.ident_of("emit_enum_variant"),
~[ ~[
build::mk_base_str(cx, span, cx.str_of(variant.node.name)), cx.mk_base_str(span, cx.str_of(variant.node.name)),
build::mk_uint(cx, span, i), cx.mk_uint(span, i),
build::mk_uint(cx, span, variant_arg_len), cx.mk_uint(span, variant_arg_len),
build::mk_lambda_stmts( cx.mk_lambda_stmts(
cx,
span, 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 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. // Create the arm.
ast::arm { ast::arm {
@ -442,31 +429,29 @@ fn expand_deriving_encodable_enum_method(
}; };
let e_ident = cx.ident_of("__e"); let e_ident = cx.ident_of("__e");
let e_arg = build::mk_arg(cx, let e_arg = cx.mk_arg(
span, span,
e_ident, e_ident,
build::mk_ty_infer(cx, span)); cx.mk_ty_infer(span));
// Create the method body. // Create the method body.
let lambda_expr = build::mk_lambda( let lambda_expr = cx.mk_lambda(
cx,
span, 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) expand_enum_or_struct_match(cx, span, arms)
); );
let call_expr = build::mk_method_call( let call_expr = cx.mk_method_call(
cx,
span, span,
build::mk_path(cx, span, ~[cx.ident_of("__e")]), cx.mk_path(span, ~[cx.ident_of("__e")]),
cx.ident_of("emit_enum"), 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, lambda_expr,
] ]
); );
let stmt = build::mk_stmt(cx, span, call_expr); let stmt = cx.mk_stmt(span, call_expr);
// Create the method. // Create the method.
create_encode_method(cx, span, ~[stmt]) create_encode_method(cx, span, ~[stmt])

View file

@ -166,7 +166,7 @@ use ast;
use ast::{enum_def, expr, ident, Generics, struct_def}; use ast::{enum_def, expr, ident, Generics, struct_def};
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use ext::deriving::*; use ext::deriving::*;
use codemap::{span,respan}; use codemap::{span,respan};
use opt_vec; use opt_vec;
@ -431,7 +431,7 @@ impl<'self> MethodDef<'self> {
let ident = cx.ident_of(fmt!("__arg_%u", i)); let ident = cx.ident_of(fmt!("__arg_%u", i));
arg_tys.push((ident, ast_ty)); 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 { match *ty {
// for static methods, just treat any Self // for static methods, just treat any Self
@ -440,7 +440,7 @@ impl<'self> MethodDef<'self> {
self_args.push(arg_expr); self_args.push(arg_expr);
} }
Ptr(~Self, _) if nonstatic => { 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); 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 fn_generics = self.generics.to_generics(cx, span, type_ident, generics);
let args = do arg_types.map |&(id, ty)| { 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 ret_type = self.get_ret_ty(cx, span, generics, type_ident);
let method_ident = cx.ident_of(self.name); let method_ident = cx.ident_of(self.name);
let fn_decl = build::mk_fn_decl(args, ret_type); let fn_decl = cx.mk_fn_decl(args, ret_type);
let body_block = build::mk_simple_block(cx, span, body); let body_block = cx.mk_simple_block(span, body);
// Create the method. // Create the method.
@ -558,10 +558,10 @@ impl<'self> MethodDef<'self> {
let match_arm = ast::arm { let match_arm = ast::arm {
pats: ~[ pat ], pats: ~[ pat ],
guard: None, 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 body
} }
@ -738,15 +738,15 @@ impl<'self> MethodDef<'self> {
matches_so_far, matches_so_far,
match_count + 1); match_count + 1);
matches_so_far.pop(); 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 { if enum_def.variants.len() > 1 {
let e = &EnumNonMatching(&[]); let e = &EnumNonMatching(&[]);
let wild_expr = self.call_substructure_method(cx, span, type_ident, let wild_expr = self.call_substructure_method(cx, span, type_ident,
self_args, nonself_args, self_args, nonself_args,
e); e);
let wild_arm = build::mk_arm(cx, span, let wild_arm = cx.mk_arm(span,
~[ build::mk_pat_wild(cx, span) ], ~[ cx.mk_pat_wild(span) ],
wild_expr); wild_expr);
arms.push(wild_arm); arms.push(wild_arm);
} }
@ -774,13 +774,13 @@ impl<'self> MethodDef<'self> {
match_count + 1); match_count + 1);
matches_so_far.pop(); 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); arms.push(arm);
} }
} }
// match foo { arm, arm, arm, ... } // match foo { arm, arm, arm, ... }
build::mk_expr(cx, span, cx.mk_expr(span,
ast::expr_match(self_args[match_count], arms)) 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) => { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
// call self_n.method(other_1_n, other_2_n, ...) // call self_n.method(other_1_n, other_2_n, ...)
let called = do all_fields.map |&(_, self_field, other_fields)| { let called = do all_fields.map |&(_, self_field, other_fields)| {
build::mk_method_call(cx, span, cx.mk_method_call(span,
self_field, self_field,
substructure.method_ident, substructure.method_ident,
other_fields) other_fields)
@ -945,7 +945,7 @@ pub fn cs_binop(binop: ast::binop, base: @expr,
cs_same_method_fold( cs_same_method_fold(
true, // foldl is good enough true, // foldl is good enough
|cx, span, old, new| { |cx, span, old, new| {
build::mk_binary(cx, span, cx.mk_binary(span,
binop, binop,
old, new) old, new)
@ -960,7 +960,7 @@ pub fn cs_binop(binop: ast::binop, base: @expr,
pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc,
cx: @ExtCtxt, span: span, cx: @ExtCtxt, span: span,
substructure: &Substructure) -> @expr { 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, enum_nonmatch_f,
cx, span, substructure) cx, span, substructure)
} }
@ -969,7 +969,7 @@ pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc,
pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc, pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc,
cx: @ExtCtxt, span: span, cx: @ExtCtxt, span: span,
substructure: &Substructure) -> @expr { 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, enum_nonmatch_f,
cx, span, substructure) cx, span, substructure)
} }

View file

@ -11,7 +11,7 @@
use ast::{meta_item, item, expr, and}; use ast::{meta_item, item, expr, and};
use codemap::span; use codemap::span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_iter_bytes(cx: @ExtCtxt, 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 iter_bytes_ident = substr.method_ident;
let call_iterbytes = |thing_expr| { let call_iterbytes = |thing_expr| {
build::mk_method_call(cx, span, cx.mk_method_call(span,
thing_expr, iter_bytes_ident, thing_expr, iter_bytes_ident,
copy lsb0_f) copy lsb0_f)
}; };
@ -63,7 +63,7 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @
// iteration function. // iteration function.
let discriminant = match variant.node.disr_expr { let discriminant = match variant.node.disr_expr {
Some(copy d)=> d, Some(copy d)=> d,
None => build::mk_uint(cx, span, index) None => cx.mk_uint(span, index)
}; };
exprs.push(call_iterbytes(discriminant)); 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| { 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)
} }
} }

View file

@ -21,7 +21,7 @@ library.
use ast; use ast;
use ast::{Ty, enum_def, expr, ident, item, Generics, meta_item, struct_def}; use ast::{Ty, enum_def, expr, ident, item, Generics, meta_item, struct_def};
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use codemap::{span, respan}; use codemap::{span, respan};
use parse::token::special_idents::clownshoes_extensions; use parse::token::special_idents::clownshoes_extensions;
use opt_vec; use opt_vec;
@ -172,7 +172,7 @@ pub fn create_self_type_with_params(cx: @ExtCtxt,
// Create the type parameters on the `self` path. // Create the type parameters on the `self` path.
let mut self_ty_params = ~[]; let mut self_ty_params = ~[];
for generics.ty_params.each |ty_param| { 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, span,
ty_param.ident); ty_param.ident);
self_ty_params.push(self_ty_param); 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`. // Create the type of `self`.
let self_type = build::mk_raw_path_(span, let self_type = cx.mk_raw_path_(span,
~[ type_ident ], ~[ type_ident ],
lifetime, lifetime,
self_ty_params); 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, 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| { for generics.ty_params.each |ty_param| {
// extra restrictions on the generics parameters to the type being derived upon // extra restrictions on the generics parameters to the type being derived upon
let mut bounds = do bounds_paths.map |&bound_path| { 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 = 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); 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. // 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`. // Create the type of `self`.
let self_type = create_self_type_with_params(cx, let self_type = create_self_type_with_params(cx,
@ -255,7 +255,7 @@ pub fn create_subpatterns(cx: @ExtCtxt,
mutbl: ast::mutability) mutbl: ast::mutability)
-> ~[@ast::pat] { -> ~[@ast::pat] {
do field_paths.map |&path| { do field_paths.map |&path| {
build::mk_pat(cx, span, cx.mk_pat(span,
ast::pat_ident(ast::bind_by_ref(mutbl), path, None)) ast::pat_ident(ast::bind_by_ref(mutbl), path, None))
} }
} }
@ -274,12 +274,12 @@ pub fn create_struct_pattern(cx: @ExtCtxt,
-> (@ast::pat, ~[(Option<ident>, @expr)]) { -> (@ast::pat, ~[(Option<ident>, @expr)]) {
if struct_def.fields.is_empty() { if struct_def.fields.is_empty() {
return ( return (
build::mk_pat_ident_with_binding_mode( cx.mk_pat_ident_with_binding_mode(
cx, span, struct_ident, ast::bind_infer), 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 = ~[]; 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`"); 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)) ]); ~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]);
paths.push(path); 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); 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 }) 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 { } else {
build::mk_pat_enum(cx, span, matching_path, subpats) cx.mk_pat_enum(span, matching_path, subpats)
}; };
(pattern, ident_expr) (pattern, ident_expr)
@ -337,24 +337,24 @@ pub fn create_enum_variant_pattern(cx: @ExtCtxt,
match variant.node.kind { match variant.node.kind {
ast::tuple_variant_kind(ref variant_args) => { ast::tuple_variant_kind(ref variant_args) => {
if variant_args.is_empty() { if variant_args.is_empty() {
return (build::mk_pat_ident_with_binding_mode( return (cx.mk_pat_ident_with_binding_mode(
cx, span, variant_ident, ast::bind_infer), ~[]); 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 = ~[]; let mut paths = ~[], ident_expr = ~[];
for uint::range(0, variant_args.len()) |i| { 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)) ]); ~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]);
paths.push(path); 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); 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) ident_expr)
} }
ast::struct_variant_kind(struct_def) => { ast::struct_variant_kind(struct_def) => {
@ -377,8 +377,8 @@ pub fn expand_enum_or_struct_match(cx: @ExtCtxt,
span: span, span: span,
arms: ~[ ast::arm ]) arms: ~[ ast::arm ])
-> @expr { -> @expr {
let self_expr = build::make_self(cx, span); let self_expr = cx.make_self(span);
let self_expr = build::mk_unary(cx, span, ast::deref, self_expr); let self_expr = cx.mk_unary(span, ast::deref, self_expr);
let self_match_expr = ast::expr_match(self_expr, arms); 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)
} }

View file

@ -12,7 +12,7 @@ use ast;
use ast::{meta_item, item, expr, ident}; use ast::{meta_item, item, expr, ident};
use codemap::span; use codemap::span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::{AstBuilder, Duplicate, Field};
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_rand(cx: @ExtCtxt, 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") cx.ident_of("rand")
]; ];
let rand_call = || { let rand_call = || {
build::mk_call_global(cx, cx.mk_call_global(
span, span,
copy rand_ident, copy rand_ident,
~[ build::duplicate_expr(cx, rng[0]) ]) ~[ rng[0].duplicate(cx) ])
}; };
return match *substr.fields { 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"); 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 // need to specify the uint-ness of the random number
let u32_ty = build::mk_ty_path(cx, span, ~[cx.ident_of("uint")]); let u32_ty = cx.mk_ty_path(span, ~[cx.ident_of("uint")]);
let r_ty = build::mk_ty_path(cx, span, ~[cx.ident_of("R")]); let r_ty = cx.mk_ty_path(span, ~[cx.ident_of("R")]);
let rand_name = build::mk_raw_path_(span, copy rand_ident, None, ~[ u32_ty, r_ty ]); let rand_name = cx.mk_raw_path_(span, copy rand_ident, None, ~[ u32_ty, r_ty ]);
let rand_name = build::mk_path_raw(cx, span, rand_name); let rand_name = cx.mk_path_raw(span, rand_name);
let rv_call = build::mk_call_(cx, let rv_call = cx.mk_call_(
span, span,
rand_name, rand_name,
~[ build::duplicate_expr(cx, rng[0]) ]); ~[ rng[0].duplicate(cx) ]);
// rand() % variants.len() // 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); rv_call, variant_count);
let mut arms = do variants.mapi |i, id_sum| { let mut arms = do variants.mapi |i, id_sum| {
let i_expr = build::mk_uint(cx, span, i); let i_expr = cx.mk_uint(span, i);
let pat = build::mk_pat_lit(cx, span, i_expr); let pat = cx.mk_pat_lit(span, i_expr);
match *id_sum { match *id_sum {
(ident, ref summary) => { (ident, ref summary) => {
build::mk_arm(cx, span, cx.mk_arm(span,
~[ pat ], ~[ pat ],
rand_thing(cx, span, ident, summary, rand_call)) 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 // _ => {} 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)) ast::expr_match(rand_variant, arms))
} }
_ => cx.bug("Non-static method in `deriving(Rand)`") _ => cx.bug("Non-static method in `deriving(Rand)`")
@ -121,20 +121,20 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
match *summary { match *summary {
Left(copy count) => { Left(copy count) => {
if count == 0 { if count == 0 {
build::mk_path(cx, span, ctor_ident) cx.mk_path(span, ctor_ident)
} else { } else {
let exprs = vec::from_fn(count, |_| rand_call()); 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) => { Right(ref fields) => {
let rand_fields = do fields.map |ident| { let rand_fields = do fields.map |ident| {
build::Field { Field {
ident: *ident, ident: *ident,
ex: rand_call() ex: rand_call()
} }
}; };
build::mk_struct_e(cx, span, ctor_ident, rand_fields) cx.mk_struct_e(span, ctor_ident, rand_fields)
} }
} }
} }

View file

@ -11,7 +11,7 @@
use ast::{meta_item, item, expr}; use ast::{meta_item, item, expr};
use codemap::span; use codemap::span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_to_str(cx: @ExtCtxt, 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 { fn to_str_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
match substr.self_args { match substr.self_args {
[self_obj] => { [self_obj] => {
let self_addr = build::mk_addr_of(cx, span, self_obj); let self_addr = cx.mk_addr_of(span, self_obj);
build::mk_call_global(cx, span, cx.mk_call_global(span,
~[cx.ident_of("core"), ~[cx.ident_of("core"),
cx.ident_of("sys"), cx.ident_of("sys"),
cx.ident_of("log_str")], cx.ident_of("log_str")],

View file

@ -16,7 +16,7 @@ explicit `Self` type to use when specifying impls to be derived.
use ast; use ast;
use ast::{expr,Generics,ident}; use ast::{expr,Generics,ident};
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build; use ext::build::AstBuilder;
use codemap::{span,respan}; use codemap::{span,respan};
use opt_vec; use opt_vec;
@ -55,7 +55,7 @@ pub impl<'self> Path<'self> {
fn to_ty(&self, cx: @ExtCtxt, span: span, fn to_ty(&self, cx: @ExtCtxt, span: span,
self_ty: ident, self_generics: &Generics) -> @ast::Ty { 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.to_path(cx, span,
self_ty, self_generics)) 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)); let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics));
if self.global { if self.global {
build::mk_raw_path_global_(span, idents, lt, tys) cx.mk_raw_path_global_(span, idents, lt, tys)
} else { } 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> { fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<@ast::Lifetime> {
match *lt { 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 None => None
} }
} }
@ -119,20 +119,20 @@ pub impl<'self> Ty<'self> {
let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); let raw_ty = ty.to_ty(cx, span, self_ty, self_generics);
match *ptr { match *ptr {
Owned => { Owned => {
build::mk_ty_uniq(cx, span, raw_ty) cx.mk_ty_uniq(span, raw_ty)
} }
Managed(mutbl) => { Managed(mutbl) => {
build::mk_ty_box(cx, span, raw_ty, mutbl) cx.mk_ty_box(span, raw_ty, mutbl)
} }
Borrowed(ref lt, mutbl) => { Borrowed(ref lt, mutbl) => {
let lt = mk_lifetime(cx, span, lt); 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) } Literal(ref p) => { p.to_ty(cx, span, self_ty, self_generics) }
Self => { 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) => { Tuple(ref fields) => {
let ty = if fields.is_empty() { 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))) 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 { match *self {
Self => { Self => {
let self_params = do self_generics.ty_params.map |ty_param| { 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() { let lifetime = if self_generics.lifetimes.is_empty() {
None None
@ -159,7 +159,7 @@ pub impl<'self> Ty<'self> {
Some(@*self_generics.lifetimes.get(0)) 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)) opt_vec::take_vec(self_params))
} }
Literal(ref p) => { Literal(ref p) => {
@ -177,9 +177,9 @@ fn mk_ty_param(cx: @ExtCtxt, span: span, name: &str, bounds: &[Path],
let bounds = opt_vec::from( let bounds = opt_vec::from(
do bounds.map |b| { do bounds.map |b| {
let path = b.to_path(cx, span, self_ident, self_generics); 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 { 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, fn to_generics(&self, cx: @ExtCtxt, span: span,
self_ty: ident, self_generics: &Generics) -> Generics { self_ty: ident, self_generics: &Generics) -> Generics {
let lifetimes = do self.lifetimes.map |lt| { 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| { let ty_params = do self.bounds.map |t| {
match t { match t {
@ -220,7 +220,7 @@ pub impl<'self> LifetimeBounds<'self> {
pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option<PtrTy>) pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option<PtrTy>)
-> (@expr, ast::explicit_self) { -> (@expr, ast::explicit_self) {
let self_path = build::make_self(cx, span); let self_path = cx.make_self(span);
match *self_ptr { match *self_ptr {
None => { None => {
(self_path, respan(span, ast::sty_value)) (self_path, respan(span, ast::sty_value))
@ -232,12 +232,12 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option<PtrTy>)
Owned => ast::sty_uniq(ast::m_imm), Owned => ast::sty_uniq(ast::m_imm),
Managed(mutbl) => ast::sty_box(mutbl), Managed(mutbl) => ast::sty_box(mutbl),
Borrowed(ref lt, 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))); cx.ident_of(*s)));
ast::sty_region(lt, mutbl) 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) (self_expr, self_ty)
} }
} }

View file

@ -18,7 +18,7 @@ use ast;
use codemap::span; use codemap::span;
use ext::base::*; use ext::base::*;
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]) pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult { -> base::MacResult {
@ -29,8 +29,8 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
// Option<str> rather than just an maybe-empty string. // Option<str> rather than just an maybe-empty string.
let e = match os::getenv(var) { let e = match os::getenv(var) {
None => mk_base_str(cx, sp, ~""), None => cx.mk_base_str(sp, ~""),
Some(ref s) => mk_base_str(cx, sp, copy *s) Some(ref s) => cx.mk_base_str(sp, copy *s)
}; };
MRExpr(e) MRExpr(e)
} }

View file

@ -19,7 +19,7 @@ use codemap::span;
use ext::base::*; use ext::base::*;
use ext::base; use ext::base;
use ext::build; use ext::build;
use ext::build::*; use ext::build::AstBuilder;
use core::unstable::extfmt::ct::*; 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 { fn make_rt_path_expr(cx: @ExtCtxt, sp: span, nm: &str) -> @ast::expr {
let path = make_path_vec(cx, nm); 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, // Produces an AST expression that represents a RT::conv record,
// which tells the RT::conv* functions how to perform the conversion // 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", FlagSignAlways => "flag_sign_always",
FlagAlternate => "flag_alternate" 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)); make_rt_path_expr(cx, sp, fstr));
} }
return tmp_expr; return tmp_expr;
@ -83,10 +83,10 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span,
return make_rt_path_expr(cx, sp, "CountImplied"); return make_rt_path_expr(cx, sp, "CountImplied");
} }
CountIs(c) => { 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_path = make_path_vec(cx, "CountIs");
let count_is_args = ~[count_lit]; 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") _ => 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, width_expr: @ast::expr, precision_expr: @ast::expr,
ty_expr: @ast::expr) -> @ast::expr { ty_expr: @ast::expr) -> @ast::expr {
let intr = cx.parse_sess().interner; let intr = cx.parse_sess().interner;
mk_global_struct_e( cx.mk_global_struct_e(
cx,
sp, sp,
make_path_vec(cx, "Conv"), 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 path = make_path_vec(cx, fname);
let cnv_expr = make_rt_conv_expr(cx, sp, cnv); let cnv_expr = make_rt_conv_expr(cx, sp, cnv);
let args = ~[cnv_expr, arg, buf]; 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, 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), TyChar => ("char", arg),
TyBits | TyOctal | TyHex(_) | TyInt(Unsigned) => ("uint", arg), TyBits | TyOctal | TyHex(_) | TyInt(Unsigned) => ("uint", arg),
TyFloat => ("float", 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, 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) { fn log_conv(c: &Conv) {
debug!("Building conversion:"); 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! */ /* 'ident' is the local buffer building up the result of fmt! */
let ident = cx.parse_sess().interner.intern("__fmtbuf"); 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 str_ident = cx.parse_sess().interner.intern("str");
let push_ident = cx.parse_sess().interner.intern("push_str"); let push_ident = cx.parse_sess().interner.intern("push_str");
let mut stms = ~[]; 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, buffer with it directly. If it's actually the only piece,
then there's no need for it to be mutable */ then there's no need for it to be mutable */
if i == 0 { 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 { } else {
let args = ~[mk_mut_addr_of(cx, fmt_sp, buf()), mk_base_str(cx, fmt_sp, s)]; let args = ~[cx.mk_mut_addr_of(fmt_sp, buf()), cx.mk_base_str(fmt_sp, s)];
let call = mk_call_global(cx, let call = cx.mk_call_global(
fmt_sp, fmt_sp,
~[str_ident, push_ident], ~[str_ident, push_ident],
args); 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 /* If the first portion is a conversion, then the local buffer
must be initialized as an empty string */ must be initialized as an empty string */
if i == 0 { if i == 0 {
stms.push(mk_local(cx, fmt_sp, true, ident, stms.push(cx.mk_local(fmt_sp, true, ident,
mk_uniq_str(cx, fmt_sp, ~""))); cx.mk_uniq_str(fmt_sp, ~"")));
} }
stms.push(mk_stmt(cx, fmt_sp, stms.push(cx.mk_stmt(fmt_sp,
make_new_conv(cx, fmt_sp, conv, make_new_conv(cx, fmt_sp, conv,
args[n], buf()))); args[n], buf())));
} }
} }
} }
@ -317,5 +316,5 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span,
nargs, expected_nargs)); nargs, expected_nargs));
} }
return mk_block(cx, fmt_sp, ~[], stms, Some(buf())); cx.mk_block(fmt_sp, ~[], stms, Some(buf()))
} }

View file

@ -12,7 +12,7 @@ use ast;
use codemap::{BytePos, Pos, span}; use codemap::{BytePos, Pos, span};
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::base; use ext::base;
use ext::build; use ext::build::AstBuilder;
use parse::token::*; use parse::token::*;
use parse::token; use parse::token;
use parse; use parse;
@ -382,7 +382,7 @@ pub fn expand_quote_expr(cx: @ExtCtxt,
pub fn expand_quote_item(cx: @ExtCtxt, pub fn expand_quote_item(cx: @ExtCtxt,
sp: span, sp: span,
tts: &[ast::token_tree]) -> base::MacResult { 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", base::MRExpr(expand_parse_call(cx, sp, "parse_item",
~[e_attrs], tts)) ~[e_attrs], tts))
} }
@ -390,7 +390,7 @@ pub fn expand_quote_item(cx: @ExtCtxt,
pub fn expand_quote_pat(cx: @ExtCtxt, pub fn expand_quote_pat(cx: @ExtCtxt,
sp: span, sp: span,
tts: &[ast::token_tree]) -> base::MacResult { 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", base::MRExpr(expand_parse_call(cx, sp, "parse_pat",
~[e_refutable], tts)) ~[e_refutable], tts))
} }
@ -398,7 +398,7 @@ pub fn expand_quote_pat(cx: @ExtCtxt,
pub fn expand_quote_ty(cx: @ExtCtxt, pub fn expand_quote_ty(cx: @ExtCtxt,
sp: span, sp: span,
tts: &[ast::token_tree]) -> base::MacResult { 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", base::MRExpr(expand_parse_call(cx, sp, "parse_ty",
~[e_param_colons], tts)) ~[e_param_colons], tts))
} }
@ -406,7 +406,7 @@ pub fn expand_quote_ty(cx: @ExtCtxt,
pub fn expand_quote_stmt(cx: @ExtCtxt, pub fn expand_quote_stmt(cx: @ExtCtxt,
sp: span, sp: span,
tts: &[ast::token_tree]) -> base::MacResult { 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", base::MRExpr(expand_parse_call(cx, sp, "parse_stmt",
~[e_attrs], tts)) ~[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. // Lift an ident to the expr that evaluates to that ident.
fn mk_ident(cx: @ExtCtxt, sp: span, ident: ast::ident) -> @ast::expr { 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)); let e_str = cx.mk_base_str(sp, cx.str_of(ident));
build::mk_method_call(cx, sp, cx.mk_method_call(sp,
build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])),
id_ext(cx, "ident_of"), id_ext(cx, "ident_of"),
~[e_str]) ~[e_str])
} }
fn mk_bytepos(cx: @ExtCtxt, sp: span, bpos: BytePos) -> @ast::expr { fn mk_bytepos(cx: @ExtCtxt, sp: span, bpos: BytePos) -> @ast::expr {
let path = ids_ext(cx, ~[~"BytePos"]); let path = ids_ext(cx, ~[~"BytePos"]);
let arg = build::mk_uint(cx, sp, bpos.to_uint()); let arg = cx.mk_uint(sp, bpos.to_uint());
build::mk_call(cx, sp, path, ~[arg]) cx.mk_call(sp, path, ~[arg])
} }
fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr { 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", SHL => "SHL",
SHR => "SHR" SHR => "SHR"
}; };
build::mk_path(cx, sp, cx.mk_path(sp,
ids_ext(cx, ~[name.to_owned()])) ids_ext(cx, ~[name.to_owned()]))
} }
@ -455,12 +455,12 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr {
match *tok { match *tok {
BINOP(binop) => { BINOP(binop) => {
return build::mk_call(cx, sp, return cx.mk_call(sp,
ids_ext(cx, ~[~"BINOP"]), ids_ext(cx, ~[~"BINOP"]),
~[mk_binop(cx, sp, binop)]); ~[mk_binop(cx, sp, binop)]);
} }
BINOPEQ(binop) => { BINOPEQ(binop) => {
return build::mk_call(cx, sp, return cx.mk_call(sp,
ids_ext(cx, ~[~"BINOPEQ"]), ids_ext(cx, ~[~"BINOPEQ"]),
~[mk_binop(cx, sp, binop)]); ~[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" ast::ty_i64 => ~"ty_i64"
}; };
let e_ity = let e_ity =
build::mk_path(cx, sp, cx.mk_path(sp,
ids_ext(cx, ~[s_ity])); 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"]), ids_ext(cx, ~[~"LIT_INT"]),
~[e_i64, e_ity]); ~[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" ast::ty_u64 => ~"ty_u64"
}; };
let e_uty = let e_uty =
build::mk_path(cx, sp, cx.mk_path(sp,
ids_ext(cx, ~[s_uty])); 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"]), ids_ext(cx, ~[~"LIT_UINT"]),
~[e_u64, e_uty]); ~[e_u64, e_uty]);
} }
LIT_INT_UNSUFFIXED(i) => { 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)); ast::lit_int(i, ast::ty_i64));
return build::mk_call(cx, sp, return cx.mk_call(sp,
ids_ext(cx, ~[~"LIT_INT_UNSUFFIXED"]), ids_ext(cx, ~[~"LIT_INT_UNSUFFIXED"]),
~[e_i64]); ~[e_i64]);
} }
@ -520,37 +520,37 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr {
ast::ty_f64 => ~"ty_f64" ast::ty_f64 => ~"ty_f64"
}; };
let e_fty = let e_fty =
build::mk_path(cx, sp, cx.mk_path(sp,
ids_ext(cx, ~[s_fty])); ids_ext(cx, ~[s_fty]));
let e_fident = mk_ident(cx, sp, fident); let e_fident = mk_ident(cx, sp, fident);
return build::mk_call(cx, sp, return cx.mk_call(sp,
ids_ext(cx, ~[~"LIT_FLOAT"]), ids_ext(cx, ~[~"LIT_FLOAT"]),
~[e_fident, e_fty]); ~[e_fident, e_fty]);
} }
LIT_STR(ident) => { LIT_STR(ident) => {
return build::mk_call(cx, sp, return cx.mk_call(sp,
ids_ext(cx, ~[~"LIT_STR"]), ids_ext(cx, ~[~"LIT_STR"]),
~[mk_ident(cx, sp, ident)]); ~[mk_ident(cx, sp, ident)]);
} }
IDENT(ident, b) => { IDENT(ident, b) => {
return build::mk_call(cx, sp, return cx.mk_call(sp,
ids_ext(cx, ~[~"IDENT"]), ids_ext(cx, ~[~"IDENT"]),
~[mk_ident(cx, sp, 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) => { LIFETIME(ident) => {
return build::mk_call(cx, sp, return cx.mk_call(sp,
ids_ext(cx, ~[~"LIFETIME"]), ids_ext(cx, ~[~"LIFETIME"]),
~[mk_ident(cx, sp, ident)]); ~[mk_ident(cx, sp, ident)]);
} }
DOC_COMMENT(ident) => { DOC_COMMENT(ident) => {
return build::mk_call(cx, sp, return cx.mk_call(sp,
ids_ext(cx, ~[~"DOC_COMMENT"]), ids_ext(cx, ~[~"DOC_COMMENT"]),
~[mk_ident(cx, sp, ident)]); ~[mk_ident(cx, sp, ident)]);
} }
@ -595,7 +595,7 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr {
EOF => "EOF", EOF => "EOF",
_ => fail!() _ => fail!()
}; };
build::mk_path(cx, sp, cx.mk_path(sp,
ids_ext(cx, ~[name.to_owned()])) ids_ext(cx, ~[name.to_owned()]))
} }
@ -606,18 +606,18 @@ fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree)
match *tt { match *tt {
ast::tt_tok(sp, ref tok) => { 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"])); ids_ext(cx, ~[~"sp"]));
let e_tok = let e_tok =
build::mk_call(cx, sp, cx.mk_call(sp,
ids_ext(cx, ~[~"tt_tok"]), ids_ext(cx, ~[~"tt_tok"]),
~[e_sp, mk_token(cx, sp, tok)]); ~[e_sp, mk_token(cx, sp, tok)]);
let e_push = let e_push =
build::mk_method_call(cx, sp, cx.mk_method_call(sp,
build::mk_path(cx, sp, ids_ext(cx, ~[~"tt"])), cx.mk_path(sp, ids_ext(cx, ~[~"tt"])),
id_ext(cx, "push"), id_ext(cx, "push"),
~[e_tok]); ~[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)) // tt.push_all_move($ident.to_tokens(ext_cx))
let e_to_toks = let e_to_toks =
build::mk_method_call(cx, sp, cx.mk_method_call(sp,
build::mk_path(cx, sp, ~[ident]), cx.mk_path(sp, ~[ident]),
id_ext(cx, "to_tokens"), id_ext(cx, "to_tokens"),
~[build::mk_path(cx, sp, ~[cx.mk_path(sp,
ids_ext(cx, ~[~"ext_cx"]))]); ids_ext(cx, ~[~"ext_cx"]))]);
let e_push = let e_push =
build::mk_method_call(cx, sp, cx.mk_method_call(sp,
build::mk_path(cx, sp, ids_ext(cx, ~[~"tt"])), cx.mk_path(sp, ids_ext(cx, ~[~"tt"])),
id_ext(cx, "push_all_move"), id_ext(cx, "push_all_move"),
~[e_to_toks]); ~[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 // 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. // import the runtime module, followed by a tt-building expression.
let uses = ~[ build::mk_glob_use(cx, sp, ast::public, let uses = ~[ cx.mk_glob_use(sp, ast::public,
ids_ext(cx, ~[~"syntax", ids_ext(cx, ~[~"syntax",
~"ext", ~"ext",
~"quote", ~"quote",
~"rt"])) ]; ~"rt"])) ];
// We also bind a single value, sp, to ext_cx.call_site() // 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 // of quotes, for example) but at this point it seems not likely to be
// worth the hassle. // worth the hassle.
let e_sp = build::mk_method_call(cx, sp, let e_sp = cx.mk_method_call(sp,
build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])),
id_ext(cx, "call_site"), 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"), id_ext(cx, "sp"),
e_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"), 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_sp,
stmt_let_tt] + mk_tts(cx, sp, tts), stmt_let_tt] + mk_tts(cx, sp, tts),
Some(build::mk_path(cx, sp, Some(cx.mk_path(sp,
ids_ext(cx, ~[~"tt"])))) ids_ext(cx, ~[~"tt"]))))
} }
@ -736,16 +736,16 @@ fn expand_parse_call(cx: @ExtCtxt,
tts: &[ast::token_tree]) -> @ast::expr { tts: &[ast::token_tree]) -> @ast::expr {
let tts_expr = expand_tts(cx, sp, tts); let tts_expr = expand_tts(cx, sp, tts);
let cfg_call = || build::mk_method_call( let cfg_call = || cx.mk_method_call(
cx, sp, build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])),
id_ext(cx, "cfg"), ~[]); id_ext(cx, "cfg"), ~[]);
let parse_sess_call = || build::mk_method_call( let parse_sess_call = || cx.mk_method_call(
cx, sp, build::mk_path(cx, sp, ids_ext(cx, ~[~"ext_cx"])), sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])),
id_ext(cx, "parse_sess"), ~[]); id_ext(cx, "parse_sess"), ~[]);
let new_parser_call = let new_parser_call =
build::mk_call_global(cx, sp, cx.mk_call_global(sp,
ids_ext(cx, ~[~"syntax", ids_ext(cx, ~[~"syntax",
~"ext", ~"ext",
~"quote", ~"quote",
@ -755,7 +755,7 @@ fn expand_parse_call(cx: @ExtCtxt,
cfg_call(), cfg_call(),
tts_expr]); tts_expr]);
build::mk_method_call(cx, sp, cx.mk_method_call(sp,
new_parser_call, new_parser_call,
id_ext(cx, parse_method), id_ext(cx, parse_method),
arg_exprs) arg_exprs)

View file

@ -14,7 +14,7 @@ use codemap::{FileMap, Loc, Pos, ExpandedFrom, span};
use codemap::{CallInfo, NameAndSpan}; use codemap::{CallInfo, NameAndSpan};
use ext::base::*; use ext::base::*;
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 parse;
use print::pprust; 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 topmost = topmost_expn_info(cx.backtrace().get());
let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); 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 */ /* 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 topmost = topmost_expn_info(cx.backtrace().get());
let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); 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 */ /* 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 topmost = topmost_expn_info(cx.backtrace().get());
let Loc { file: @FileMap { name: filename, _ }, _ } = let Loc { file: @FileMap { name: filename, _ }, _ } =
cx.codemap().lookup_char_pos(topmost.call_site.lo); 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]) pub fn expand_stringify(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult { -> base::MacResult {
let s = pprust::tts_to_str(tts, cx.parse_sess().interner); 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]) pub fn expand_mod(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult { -> base::MacResult {
base::check_zero_tts(cx, sp, tts, "module_path!"); 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( str::connect(cx.mod_path().map(
|x| cx.str_of(*x)), "::"))) |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]) 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))) { match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) {
result::Ok(src) => { result::Ok(src) => {
let u8_exprs = vec::map(src, |char| { 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) => { result::Err(ref e) => {
cx.parse_sess().span_diagnostic.handler().fatal((*e)) cx.parse_sess().span_diagnostic.handler().fatal((*e))