syntax/ext: convert all AstBuilder methods to a uniform syntax.

This commit is contained in:
Huon Wilson 2013-05-19 15:53:42 +10:00
parent 6e50515530
commit a59bec43e3
21 changed files with 1121 additions and 1809 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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(cx.mk_u8(sp, byte));
bytes.push(cx.expr_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(cx.mk_u8(sp, v as u8));
bytes.push(cx.expr_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(cx.mk_u8(sp, v as u8));
bytes.push(cx.expr_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(cx.mk_u8(sp, v as u8));
bytes.push(cx.expr_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 = cx.mk_slice_vec_e(sp, bytes);
let e = cx.expr_vec_slice(sp, bytes);
MRExpr(e)
}

View File

@ -11,7 +11,6 @@
use ast::{meta_item, item, expr};
use codemap::span;
use ext::base::ExtCtxt;
use ext::build;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
@ -80,15 +79,15 @@ fn cs_clone(
let ctor_ident;
let all_fields;
let subcall = |field|
cx.mk_method_call(span, field, clone_ident, ~[]);
cx.expr_method_call(span, field, clone_ident, ~[]);
match *substr.fields {
Struct(ref af) => {
ctor_ident = ~[ substr.type_ident ];
ctor_ident = substr.type_ident;
all_fields = af;
}
EnumMatching(_, variant, ref af) => {
ctor_ident = ~[ variant.node.name ];
ctor_ident = variant.node.name;
all_fields = af;
},
EnumNonMatching(*) => cx.span_bug(span,
@ -103,7 +102,7 @@ fn cs_clone(
[(None, _, _), .. _] => {
// enum-like
let subcalls = all_fields.map(|&(_, self_f, _)| subcall(self_f));
cx.mk_call(span, ctor_ident, subcalls)
cx.expr_call_ident(span, ctor_ident, subcalls)
},
_ => {
// struct-like
@ -114,16 +113,14 @@ fn cs_clone(
fmt!("unnamed field in normal struct in `deriving(%s)`",
name))
};
build::Field { ident: ident, ex: subcall(self_f) }
cx.field_imm(span, ident, subcall(self_f))
};
if fields.is_empty() {
// no fields, so construct like `None`
cx.mk_path(span, ctor_ident)
cx.expr_ident(span, ctor_ident)
} else {
cx.mk_struct_e(span,
ctor_ident,
fields)
cx.expr_struct_ident(span, ctor_ident, fields)
}
}
}

View File

@ -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, _, _| cx.mk_bool(span, false),
cs_and(|cx, span, _, _| cx.expr_bool(span, false),
cx, span, substr)
}
fn cs_ne(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
cs_or(|cx, span, _, _| cx.mk_bool(span, true),
cs_or(|cx, span, _, _| cx.expr_bool(span, true),
cx, span, substr)
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
use ast::{meta_item, item, expr_if, expr};
use ast::{meta_item, item, expr};
use codemap::span;
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
@ -62,10 +62,7 @@ fn cs_ord(less: bool, equal: bool,
} else {
cx.ident_of("gt")
};
let false_blk_expr = cx.mk_block(span,
~[], ~[],
Some(cx.mk_bool(span, false)));
let base = cx.mk_bool(span, equal);
let base = cx.expr_bool(span, equal);
cs_fold(
false, // need foldr,
@ -98,19 +95,15 @@ fn cs_ord(less: bool, equal: bool,
cx.span_bug(span, "Not exactly 2 arguments in `deriving(Ord)`");
}
let cmp = cx.mk_method_call(span,
self_f, cx.ident_of("eq"), other_fs.to_owned());
let subexpr = cx.mk_simple_block(span, subexpr);
let elseif = expr_if(cmp, subexpr, Some(false_blk_expr));
let elseif = cx.mk_expr(span, elseif);
let cmp = cx.expr_method_call(span,
self_f, cx.ident_of("eq"), other_fs.to_owned());
let elseif = cx.expr_if(span, cmp,
subexpr, Some(cx.expr_bool(span, false)));
let cmp = cx.mk_method_call(span,
self_f, binop, other_fs.to_owned());
let true_blk = cx.mk_simple_block(span,
cx.mk_bool(span, true));
let if_ = expr_if(cmp, true_blk, Some(elseif));
cx.mk_expr(span, if_)
let cmp = cx.expr_method_call(span,
self_f, binop, other_fs.to_owned());
cx.expr_if(span, cmp,
cx.expr_bool(span, true), Some(elseif))
},
base,
|cx, span, args, _| {
@ -119,7 +112,7 @@ fn cs_ord(less: bool, equal: bool,
match args {
[(self_var, _, _),
(other_var, _, _)] =>
cx.mk_bool(span,
cx.expr_bool(span,
if less {
self_var < other_var
} else {

View File

@ -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, _, _| cx.mk_bool(span, false),
cs_and(|cx, span, _, _| cx.expr_bool(span, false),
cx, span, substr)
}

View File

@ -47,10 +47,11 @@ pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> @expr {
Equal => "Equal",
Greater => "Greater"
};
cx.mk_path_global(span,
~[cx.ident_of("core"),
cx.ident_of("cmp"),
cx.ident_of(cnst)])
cx.expr_path(
cx.path_global(span,
~[cx.ident_of("core"),
cx.ident_of("cmp"),
cx.ident_of(cnst)]))
}
pub fn cs_cmp(cx: @ExtCtxt, span: span,
@ -60,11 +61,11 @@ pub fn cs_cmp(cx: @ExtCtxt, span: span,
// foldr (possibly) nests the matches in lexical_ordering better
false,
|cx, span, old, new| {
cx.mk_call_global(span,
~[cx.ident_of("core"),
cx.ident_of("cmp"),
cx.ident_of("lexical_ordering")],
~[old, new])
cx.expr_call_global(span,
~[cx.ident_of("core"),
cx.ident_of("cmp"),
cx.ident_of("lexical_ordering")],
~[old, new])
},
ordering_const(cx, span, Equal),
|cx, span, list, _| {

View File

@ -16,7 +16,6 @@
use ast;
use ast::*;
use ext::base::ExtCtxt;
use ext::build::Field;
use ext::build::AstBuilder;
use ext::deriving::*;
use codemap::{span, spanned};
@ -45,26 +44,25 @@ fn create_derived_decodable_impl(
generics: &Generics,
method: @method
) -> @item {
let decoder_ty_param = cx.mk_ty_param(
let decoder_ty_param = cx.typaram(
cx.ident_of("__D"),
@opt_vec::with(
cx.mk_trait_ty_param_bound_global(
span,
~[
cx.ident_of("std"),
cx.ident_of("serialize"),
cx.ident_of("Decoder"),
]
)
)
);
cx.typarambound(
cx.path_global(
span,
~[
cx.ident_of("std"),
cx.ident_of("serialize"),
cx.ident_of("Decoder"),
]))));
// All the type parameters need to bound to the trait.
let generic_ty_params = opt_vec::with(decoder_ty_param);
let methods = [method];
let trait_path = cx.mk_raw_path_global_(
let trait_path = cx.path_all(
span,
true,
~[
cx.ident_of("std"),
cx.ident_of("serialize"),
@ -72,7 +70,7 @@ fn create_derived_decodable_impl(
],
None,
~[
cx.mk_simple_ty_path(span, cx.ident_of("__D"))
cx.ty_ident(span, cx.ident_of("__D"))
]
);
create_derived_impl(
@ -97,14 +95,14 @@ fn create_decode_method(
expr: @ast::expr
) -> @method {
// Create the `e` parameter.
let d_arg_type = cx.mk_ty_rptr(
let d_arg_type = cx.ty_rptr(
span,
cx.mk_simple_ty_path(span, cx.ident_of("__D")),
cx.ty_ident(span, cx.ident_of("__D")),
None,
ast::m_mutbl
);
let d_ident = cx.ident_of("__d");
let d_arg = cx.mk_arg(span, d_ident, d_arg_type);
let d_arg = cx.arg(span, d_ident, d_arg_type);
// Create the type of the return value.
let output_type = create_self_type_with_params(
@ -116,10 +114,10 @@ fn create_decode_method(
// Create the function declaration.
let inputs = ~[d_arg];
let fn_decl = cx.mk_fn_decl(inputs, output_type);
let fn_decl = cx.fn_decl(inputs, output_type);
// Create the body block.
let body_block = cx.mk_simple_block(span, expr);
let body_block = cx.blk_expr(expr);
// Create the method.
let explicit_self = spanned { node: sty_static, span: span };
@ -144,19 +142,21 @@ fn call_substructure_decode_method(
span: span
) -> @ast::expr {
// Call the substructure method.
cx.mk_call_(
cx.expr_call(
span,
cx.mk_path_global(
span,
~[
cx.ident_of("std"),
cx.ident_of("serialize"),
cx.ident_of("Decodable"),
cx.ident_of("decode"),
]
cx.expr_path(
cx.path_global(
span,
~[
cx.ident_of("std"),
cx.ident_of("serialize"),
cx.ident_of("Decodable"),
cx.ident_of("decode"),
]
)
),
~[
cx.mk_path(span, ~[cx.ident_of("__d")])
cx.expr_ident(span, cx.ident_of("__d"))
]
)
}
@ -218,31 +218,24 @@ fn create_read_struct_field(
span: span,
idx: uint,
ident: ident
) -> Field {
) -> ast::field {
// Call the substructure method.
let decode_expr = call_substructure_decode_method(cx, span);
let d_arg = cx.mk_arg(
span,
cx.ident_of("__d"),
cx.mk_ty_infer(span));
let d_id = cx.ident_of("__d");
let call_expr = cx.mk_method_call(
let call_expr = cx.expr_method_call(
span,
cx.mk_path(span, ~[cx.ident_of("__d")]),
cx.expr_ident(span, d_id),
cx.ident_of("read_struct_field"),
~[
cx.mk_base_str(span, cx.str_of(ident)),
cx.mk_uint(span, idx),
cx.mk_lambda(
span,
cx.mk_fn_decl(~[d_arg],
cx.mk_ty_infer(span)),
decode_expr),
cx.expr_str(span, cx.str_of(ident)),
cx.expr_uint(span, idx),
cx.lambda_expr_1(span, decode_expr, d_id)
]
);
Field { ident: ident, ex: call_expr }
cx.field_imm(span, ident, call_expr)
}
fn create_read_struct_arg(
@ -250,21 +243,21 @@ fn create_read_struct_arg(
span: span,
idx: uint,
ident: ident
) -> Field {
) -> ast::field {
// Call the substructure method.
let decode_expr = call_substructure_decode_method(cx, span);
let call_expr = cx.mk_method_call(
let call_expr = cx.expr_method_call(
span,
cx.mk_path(span, ~[cx.ident_of("__d")]),
cx.expr_ident(span, cx.ident_of("__d")),
cx.ident_of("read_struct_arg"),
~[
cx.mk_uint(span, idx),
cx.mk_lambda_no_args(span, decode_expr),
cx.expr_uint(span, idx),
cx.lambda_expr_0(span, decode_expr),
]
);
Field { ident: ident, ex: call_expr }
cx.field_imm(span, ident, call_expr)
}
fn expand_deriving_decodable_struct_method(
@ -292,30 +285,19 @@ fn expand_deriving_decodable_struct_method(
i += 1;
}
let d_arg = cx.mk_arg(
span,
cx.ident_of("__d"),
cx.mk_ty_infer(span));
let d_id = cx.ident_of("__d");
let read_struct_expr = cx.mk_method_call(
let read_struct_expr = cx.expr_method_call(
span,
cx.mk_path(
span,
~[cx.ident_of("__d")]
),
cx.expr_ident(span, d_id),
cx.ident_of("read_struct"),
~[
cx.mk_base_str(span, cx.str_of(type_ident)),
cx.mk_uint(span, fields.len()),
cx.mk_lambda(
cx.expr_str(span, cx.str_of(type_ident)),
cx.expr_uint(span, fields.len()),
cx.lambda_expr_1(
span,
cx.mk_fn_decl(~[d_arg], cx.mk_ty_infer(span)),
cx.mk_struct_e(
span,
~[type_ident],
fields
)
),
cx.expr_struct_ident(span, type_ident, fields),
d_id)
]
);
@ -330,14 +312,14 @@ fn create_read_variant_arg(
variant: &ast::variant
) -> ast::arm {
// Create the matching pattern.
let pat = cx.mk_pat_lit(span, cx.mk_uint(span, idx));
let pat = cx.pat_lit(span, cx.expr_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 {
cx.mk_path(span, ~[variant.node.name])
cx.expr_ident(span, variant.node.name)
} else {
// Feed the discriminant to the decode function.
let mut args = ~[];
@ -346,37 +328,26 @@ fn create_read_variant_arg(
// Call the substructure method.
let expr = call_substructure_decode_method(cx, span);
let d_arg = cx.mk_arg(
span,
cx.ident_of("__d"),
cx.mk_ty_infer(span));
let t_infer = cx.mk_ty_infer(span);
let d_id = cx.ident_of("__d");
let call_expr = cx.mk_method_call(
let call_expr = cx.expr_method_call(
span,
cx.mk_path(span, ~[cx.ident_of("__d")]),
cx.expr_ident(span, d_id),
cx.ident_of("read_enum_variant_arg"),
~[
cx.mk_uint(span, j),
cx.mk_lambda(
span,
cx.mk_fn_decl(~[d_arg], t_infer),
expr),
cx.expr_uint(span, j),
cx.lambda_expr_1(span, expr, d_id),
]
);
args.push(call_expr);
}
cx.mk_call(
span,
~[variant.node.name],
args
)
cx.expr_call_ident(span, variant.node.name, args)
};
// Create the arm.
cx.mk_arm(span, ~[pat], expr)
cx.arm(span, ~[pat], expr)
}
fn create_read_enum_variant(
@ -385,10 +356,10 @@ fn create_read_enum_variant(
enum_definition: &enum_def
) -> @expr {
// Create a vector that contains all the variant names.
let expr_arm_names = cx.mk_base_vec_e(
let expr_arm_names = cx.expr_vec(
span,
do enum_definition.variants.map |variant| {
cx.mk_base_str(
cx.expr_str(
span,
cx.str_of(variant.node.name)
)
@ -401,40 +372,18 @@ fn create_read_enum_variant(
};
// Add the impossible case arm.
arms.push(cx.mk_unreachable_arm(span));
arms.push(cx.arm_unreachable(span));
// Create the read_enum_variant expression.
cx.mk_method_call(
cx.expr_method_call(
span,
cx.mk_path(span, ~[cx.ident_of("__d")]),
cx.expr_ident(span, cx.ident_of("__d")),
cx.ident_of("read_enum_variant"),
~[
expr_arm_names,
cx.mk_lambda(
span,
cx.mk_fn_decl(
~[
cx.mk_arg(
span,
cx.ident_of("__d"),
cx.mk_ty_infer(span)
),
cx.mk_arg(
span,
cx.ident_of("__i"),
cx.mk_ty_infer(span)
)
],
cx.mk_ty_infer(span)
),
cx.mk_expr(
span,
ast::expr_match(
cx.mk_path(span, ~[cx.ident_of("__i")]),
arms
)
)
)
cx.lambda_expr(span,
~[cx.ident_of("__d"), cx.ident_of("__i")],
cx.expr_match(span, cx.expr_ident(span, cx.ident_of("__i")), arms))
]
)
}
@ -452,23 +401,16 @@ fn expand_deriving_decodable_enum_method(
enum_definition
);
let d_arg = cx.mk_arg(
span,
cx.ident_of("__d"),
cx.mk_ty_infer(span));
let d_id = cx.ident_of("__d");
// Create the read_enum expression
let read_enum_expr = cx.mk_method_call(
let read_enum_expr = cx.expr_method_call(
span,
cx.mk_path(span, ~[cx.ident_of("__d")]),
cx.expr_ident(span, d_id),
cx.ident_of("read_enum"),
~[
cx.mk_base_str(span, cx.str_of(type_ident)),
cx.mk_lambda(
span,
cx.mk_fn_decl(~[d_arg],
cx.mk_ty_infer(span)),
read_enum_variant_expr),
cx.expr_str(span, cx.str_of(type_ident)),
cx.lambda_expr_1(span, read_enum_variant_expr, d_id)
]
);

View File

@ -107,26 +107,25 @@ fn create_derived_encodable_impl(
generics: &Generics,
method: @method
) -> @item {
let encoder_ty_param = cx.mk_ty_param(
let encoder_ty_param = cx.typaram(
cx.ident_of("__E"),
@opt_vec::with(
cx.mk_trait_ty_param_bound_global(
span,
~[
cx.ident_of("std"),
cx.ident_of("serialize"),
cx.ident_of("Encoder"),
]
)
)
);
cx.typarambound(
cx.path_global(
span,
~[
cx.ident_of("std"),
cx.ident_of("serialize"),
cx.ident_of("Encoder"),
]))));
// All the type parameters need to bound to the trait.
let generic_ty_params = opt_vec::with(encoder_ty_param);
let methods = [method];
let trait_path = cx.mk_raw_path_global_(
let trait_path = cx.path_all(
span,
true,
~[
cx.ident_of("std"),
cx.ident_of("serialize"),
@ -134,7 +133,7 @@ fn create_derived_encodable_impl(
],
None,
~[
cx.mk_simple_ty_path(span, cx.ident_of("__E"))
cx.ty_ident(span, cx.ident_of("__E"))
]
);
create_derived_impl(
@ -157,23 +156,23 @@ fn create_encode_method(
statements: ~[@stmt]
) -> @method {
// Create the `e` parameter.
let e_arg_type = cx.mk_ty_rptr(
let e_arg_type = cx.ty_rptr(
span,
cx.mk_simple_ty_path(span, cx.ident_of("__E")),
cx.ty_ident(span, cx.ident_of("__E")),
None,
ast::m_mutbl
);
let e_arg = cx.mk_arg(span, cx.ident_of("__e"), e_arg_type);
let e_arg = cx.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 };
let output_type = cx.ty_nil();
// Create the function declaration.
let inputs = ~[e_arg];
let fn_decl = cx.mk_fn_decl(inputs, output_type);
let fn_decl = cx.fn_decl(inputs, output_type);
// Create the body block.
let body_block = cx.mk_block_(span, statements);
let body_block = cx.blk(span, statements, None);
// Create the method.
let explicit_self = spanned { node: sty_region(None, m_imm), span: span };
@ -200,11 +199,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 = cx.mk_path(span, ~[e_ident]);
let e_expr = cx.expr_ident(span, e_ident);
// Call the substructure method.
let encode_ident = cx.ident_of("encode");
cx.mk_method_call(
cx.expr_method_call(
span,
self_field,
encode_ident,
@ -275,10 +274,9 @@ fn expand_deriving_encodable_struct_method(
match struct_field.node.kind {
named_field(ident, _) => {
// Create the accessor for this field.
let self_field = cx.mk_access_(
span,
cx.make_self(span),
ident);
let self_field = cx.expr_field_access(span,
cx.expr_self(span),
ident);
// Call the substructure method.
let encode_expr = call_substructure_encode_method(
@ -288,29 +286,19 @@ fn expand_deriving_encodable_struct_method(
);
let e_ident = cx.ident_of("__e");
let e_arg = cx.mk_arg(
span,
e_ident,
cx.mk_ty_infer(span));
let blk_expr = cx.mk_lambda(
let call_expr = cx.expr_method_call(
span,
cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)),
encode_expr
);
let call_expr = cx.mk_method_call(
span,
cx.mk_path(span, ~[cx.ident_of("__e")]),
cx.expr_ident(span, e_ident),
cx.ident_of("emit_struct_field"),
~[
cx.mk_base_str(span, cx.str_of(ident)),
cx.mk_uint(span, idx),
blk_expr
cx.expr_str(span, cx.str_of(ident)),
cx.expr_uint(span, idx),
cx.lambda_expr_1(span, encode_expr, e_ident)
]
);
statements.push(cx.mk_stmt(span, call_expr));
statements.push(cx.stmt_expr(call_expr));
}
unnamed_field => {
cx.span_unimpl(
@ -322,30 +310,19 @@ fn expand_deriving_encodable_struct_method(
idx += 1;
}
let e_arg = cx.mk_arg(
span,
cx.ident_of("__e"),
cx.mk_ty_infer(span));
let emit_struct_stmt = cx.mk_method_call(
let e_id = cx.ident_of("__e");
let emit_struct_stmt = cx.expr_method_call(
span,
cx.mk_path(
span,
~[cx.ident_of("__e")]
),
cx.expr_ident(span, e_id),
cx.ident_of("emit_struct"),
~[
cx.mk_base_str(span, cx.str_of(type_ident)),
cx.mk_uint(span, statements.len()),
cx.mk_lambda_stmts(
span,
cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)),
statements
),
cx.expr_str(span, cx.str_of(type_ident)),
cx.expr_uint(span, statements.len()),
cx.lambda_stmts_1(span, statements, e_id),
]
);
let statements = ~[cx.mk_stmt(span, emit_struct_stmt)];
let statements = ~[cx.stmt_expr(emit_struct_stmt)];
// Create the method itself.
return create_encode_method(cx, span, statements);
@ -373,85 +350,59 @@ 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 = cx.mk_arg(
span,
e_ident,
cx.mk_ty_infer(span));
let blk_expr = cx.mk_lambda(
let call_expr = cx.expr_method_call(
span,
cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)),
expr
);
let call_expr = cx.mk_method_call(
span,
cx.mk_path(span, ~[cx.ident_of("__e")]),
cx.expr_ident(span, e_ident),
cx.ident_of("emit_enum_variant_arg"),
~[
cx.mk_uint(span, j),
blk_expr,
cx.expr_uint(span, j),
cx.lambda_expr_1(span, expr, e_ident),
]
);
stmts.push(cx.mk_stmt(span, call_expr));
stmts.push(cx.stmt_expr(call_expr));
}
// Create the pattern body.
let e_arg = cx.mk_arg(
span,
cx.ident_of("__e"),
cx.mk_ty_infer(span));
let call_expr = cx.mk_method_call(
let e_id = cx.ident_of("__e");
let call_expr = cx.expr_method_call(
span,
cx.mk_path(span, ~[cx.ident_of("__e")]),
cx.expr_ident(span, e_id),
cx.ident_of("emit_enum_variant"),
~[
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,
cx.mk_fn_decl(~[e_arg], cx.mk_ty_infer(span)),
stmts
)
cx.expr_str(span, cx.str_of(variant.node.name)),
cx.expr_uint(span, i),
cx.expr_uint(span, variant_arg_len),
cx.lambda_stmts_1(span, stmts, e_id)
]
);
let match_body_block = cx.mk_simple_block(span, call_expr);
//let match_body_block = cx.blk_expr(call_expr);
// Create the arm.
ast::arm {
pats: ~[pat],
guard: None,
body: match_body_block,
}
cx.arm(span, ~[pat], call_expr) //match_body_block)
};
let e_ident = cx.ident_of("__e");
let e_arg = cx.mk_arg(
span,
e_ident,
cx.mk_ty_infer(span));
// Create the method body.
let lambda_expr = cx.mk_lambda(
let lambda_expr = cx.lambda_expr_1(
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),
e_ident);
let call_expr = cx.mk_method_call(
let call_expr = cx.expr_method_call(
span,
cx.mk_path(span, ~[cx.ident_of("__e")]),
cx.expr_ident(span, e_ident),
cx.ident_of("emit_enum"),
~[
cx.mk_base_str(span, cx.str_of(type_ident)),
cx.expr_str(span, cx.str_of(type_ident)),
lambda_expr,
]
);
let stmt = cx.mk_stmt(span, call_expr);
let stmt = cx.stmt_expr(call_expr);
// Create the method.
create_encode_method(cx, span, ~[stmt])

View File

@ -431,7 +431,7 @@ fn split_self_nonself_args(&self, cx: @ExtCtxt, span: span,
let ident = cx.ident_of(fmt!("__arg_%u", i));
arg_tys.push((ident, ast_ty));
let arg_expr = cx.mk_path(span, ~[ident]);
let arg_expr = cx.expr_ident(span, ident);
match *ty {
// for static methods, just treat any Self
@ -440,7 +440,7 @@ fn split_self_nonself_args(&self, cx: @ExtCtxt, span: span,
self_args.push(arg_expr);
}
Ptr(~Self, _) if nonstatic => {
self_args.push(cx.mk_deref(span, arg_expr))
self_args.push(cx.expr_deref(span, arg_expr))
}
_ => {
nonself_args.push(arg_expr);
@ -461,14 +461,14 @@ fn create_method(&self, cx: @ExtCtxt, span: span,
let fn_generics = self.generics.to_generics(cx, span, type_ident, generics);
let args = do arg_types.map |&(id, ty)| {
cx.mk_arg(span, id, ty)
cx.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 = cx.mk_fn_decl(args, ret_type);
let body_block = cx.mk_simple_block(span, body);
let fn_decl = cx.fn_decl(args, ret_type);
let body_block = cx.blk_expr(body);
// Create the method.
@ -555,13 +555,8 @@ fn expand_struct_method_body(&self,
// structs. This is actually right-to-left, but it shoudn't
// matter.
for vec::each2(self_args, patterns) |&arg_expr, &pat| {
let match_arm = ast::arm {
pats: ~[ pat ],
guard: None,
body: cx.mk_simple_block(span, body)
};
body = cx.mk_expr(span, ast::expr_match(arg_expr, ~[match_arm]))
body = cx.expr_match(span, arg_expr,
~[ cx.arm(span, ~[pat], body) ])
}
body
}
@ -690,7 +685,7 @@ fn build_enum_match(&self,
}
let field_tuples =
do vec::map_zip(*self_vec,
enum_matching_fields) |&(id, self_f), &other| {
enum_matching_fields) |&(id, self_f), &other| {
(id, self_f, other)
};
substructure = EnumMatching(variant_index, variant, field_tuples);
@ -738,16 +733,16 @@ fn build_enum_match(&self,
matches_so_far,
match_count + 1);
matches_so_far.pop();
arms.push(cx.mk_arm(span, ~[ pattern ], arm_expr));
arms.push(cx.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 = cx.mk_arm(span,
~[ cx.mk_pat_wild(span) ],
wild_expr);
let wild_arm = cx.arm(span,
~[ cx.pat_wild(span) ],
wild_expr);
arms.push(wild_arm);
}
} else {
@ -774,14 +769,13 @@ fn build_enum_match(&self,
match_count + 1);
matches_so_far.pop();
let arm = cx.mk_arm(span, ~[ pattern ], arm_expr);
let arm = cx.arm(span, ~[ pattern ], arm_expr);
arms.push(arm);
}
}
// match foo { arm, arm, arm, ... }
cx.mk_expr(span,
ast::expr_match(self_args[match_count], arms))
cx.expr_match(span, self_args[match_count], arms)
}
}
@ -887,10 +881,10 @@ 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)| {
cx.mk_method_call(span,
self_field,
substructure.method_ident,
other_fields)
cx.expr_method_call(span,
self_field,
substructure.method_ident,
other_fields)
};
f(cx, span, called)
@ -945,9 +939,9 @@ pub fn cs_binop(binop: ast::binop, base: @expr,
cs_same_method_fold(
true, // foldl is good enough
|cx, span, old, new| {
cx.mk_binary(span,
binop,
old, new)
cx.expr_binary(span,
binop,
old, new)
},
base,
@ -960,7 +954,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, cx.mk_bool(span, false),
cs_binop(ast::or, cx.expr_bool(span, false),
enum_nonmatch_f,
cx, span, substructure)
}
@ -969,7 +963,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, cx.mk_bool(span, true),
cs_binop(ast::and, cx.expr_bool(span, true),
enum_nonmatch_f,
cx, span, substructure)
}

View File

@ -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| {
cx.mk_method_call(span,
cx.expr_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 => cx.mk_uint(span, index)
None => cx.expr_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| {
cx.mk_binary(span, and, prev, *me)
cx.expr_binary(span, and, prev, *me)
}
}

View File

@ -22,7 +22,7 @@
use ast::{Ty, enum_def, expr, ident, item, Generics, meta_item, struct_def};
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use codemap::{span, respan};
use codemap::span;
use parse::token::special_idents::clownshoes_extensions;
use opt_vec;
@ -143,38 +143,15 @@ pub fn expand_deriving(cx: @ExtCtxt,
result
}
fn create_impl_item(cx: @ExtCtxt, span: span, item: ast::item_) -> @item {
let doc_attr = respan(span,
ast::lit_str(@~"Automatically derived."));
let doc_attr = respan(span, ast::meta_name_value(@~"doc", doc_attr));
let doc_attr = ast::attribute_ {
style: ast::attr_outer,
value: @doc_attr,
is_sugared_doc: false
};
let doc_attr = respan(span, doc_attr);
@ast::item {
ident: clownshoes_extensions,
attrs: ~[doc_attr],
id: cx.next_id(),
node: item,
vis: ast::public,
span: span,
}
}
pub fn create_self_type_with_params(cx: @ExtCtxt,
span: span,
type_ident: ident,
generics: &Generics)
-> @Ty {
span: span,
type_ident: ident,
generics: &Generics)
-> @Ty {
// Create the type parameters on the `self` path.
let mut self_ty_params = ~[];
for generics.ty_params.each |ty_param| {
let self_ty_param = cx.mk_simple_ty_path(
span,
ty_param.ident);
let self_ty_param = cx.ty_ident(span, ty_param.ident);
self_ty_params.push(self_ty_param);
}
@ -186,11 +163,7 @@ pub fn create_self_type_with_params(cx: @ExtCtxt,
// Create the type of `self`.
let self_type = cx.mk_raw_path_(span,
~[ type_ident ],
lifetime,
self_ty_params);
cx.mk_ty_path_path(span, self_type)
cx.ty_path(cx.path_all(span, false, ~[ type_ident ], lifetime, self_ty_params))
}
pub fn create_derived_impl(cx: @ExtCtxt,
@ -222,18 +195,17 @@ 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| {
cx.mk_trait_ty_param_bound_(bound_path)
cx.typarambound(bound_path)
};
let this_trait_bound =
cx.mk_trait_ty_param_bound_(trait_path);
let this_trait_bound = cx.typarambound(trait_path);
bounds.push(this_trait_bound);
impl_generics.ty_params.push(cx.mk_ty_param(ty_param.ident, @bounds));
impl_generics.ty_params.push(cx.typaram(ty_param.ident, @bounds));
}
// Create the reference to the trait.
let trait_ref = cx.mk_trait_ref_(trait_path);
let trait_ref = cx.trait_ref(trait_path);
// Create the type of `self`.
let self_type = create_self_type_with_params(cx,
@ -241,12 +213,18 @@ pub fn create_derived_impl(cx: @ExtCtxt,
type_ident,
generics);
// Create the impl item.
let impl_item = ast::item_impl(impl_generics,
Some(trait_ref),
self_type,
methods.map(|x| *x));
return create_impl_item(cx, span, impl_item);
let doc_attr = cx.attribute(
span,
cx.meta_name_value(span,
~"doc", ast::lit_str(@~"Automatically derived.")));
cx.item(
span,
clownshoes_extensions,
~[doc_attr],
ast::item_impl(impl_generics,
Some(trait_ref),
self_type,
methods.map(|x| *x)))
}
pub fn create_subpatterns(cx: @ExtCtxt,
@ -255,7 +233,7 @@ pub fn create_subpatterns(cx: @ExtCtxt,
mutbl: ast::mutability)
-> ~[@ast::pat] {
do field_paths.map |&path| {
cx.mk_pat(span,
cx.pat(span,
ast::pat_ident(ast::bind_by_ref(mutbl), path, None))
}
}
@ -274,12 +252,12 @@ pub fn create_struct_pattern(cx: @ExtCtxt,
-> (@ast::pat, ~[(Option<ident>, @expr)]) {
if struct_def.fields.is_empty() {
return (
cx.mk_pat_ident_with_binding_mode(
cx.pat_ident_binding_mode(
span, struct_ident, ast::bind_infer),
~[]);
}
let matching_path = cx.mk_raw_path(span, ~[ struct_ident ]);
let matching_path = cx.path(span, ~[ struct_ident ]);
let mut paths = ~[], ident_expr = ~[];
@ -301,10 +279,10 @@ pub fn create_struct_pattern(cx: @ExtCtxt,
cx.span_bug(span, "A struct with named and unnamed fields in `deriving`");
}
};
let path = cx.mk_raw_path(span,
~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]);
let path = cx.path_ident(span,
cx.ident_of(fmt!("%s_%u", prefix, i)));
paths.push(path);
ident_expr.push((opt_id, cx.mk_path_raw(span, path)));
ident_expr.push((opt_id, cx.expr_path(path)));
}
let subpats = create_subpatterns(cx, span, paths, mutbl);
@ -318,9 +296,9 @@ pub fn create_struct_pattern(cx: @ExtCtxt,
push(ast::field_pat { ident: id.get(), pat: pat })
}
};
cx.mk_pat_struct(span, matching_path, field_pats)
cx.pat_struct(span, matching_path, field_pats)
} else {
cx.mk_pat_enum(span, matching_path, subpats)
cx.pat_enum(span, matching_path, subpats)
};
(pattern, ident_expr)
@ -337,24 +315,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 (cx.mk_pat_ident_with_binding_mode(
return (cx.pat_ident_binding_mode(
span, variant_ident, ast::bind_infer), ~[]);
}
let matching_path = cx.mk_raw_path(span, ~[ variant_ident ]);
let matching_path = cx.path_ident(span, variant_ident);
let mut paths = ~[], ident_expr = ~[];
for uint::range(0, variant_args.len()) |i| {
let path = cx.mk_raw_path(span,
~[ cx.ident_of(fmt!("%s_%u", prefix, i)) ]);
let path = cx.path_ident(span,
cx.ident_of(fmt!("%s_%u", prefix, i)));
paths.push(path);
ident_expr.push((None, cx.mk_path_raw(span, path)));
ident_expr.push((None, cx.expr_path(path)));
}
let subpats = create_subpatterns(cx, span, paths, mutbl);
(cx.mk_pat_enum(span, matching_path, subpats),
(cx.pat_enum(span, matching_path, subpats),
ident_expr)
}
ast::struct_variant_kind(struct_def) => {
@ -377,8 +355,6 @@ pub fn expand_enum_or_struct_match(cx: @ExtCtxt,
span: span,
arms: ~[ ast::arm ])
-> @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);
cx.mk_expr(span, self_match_expr)
let self_expr = cx.expr_deref(span, cx.expr_self(span));
cx.expr_match(span, self_expr, arms)
}

View File

@ -12,7 +12,7 @@
use ast::{meta_item, item, expr, ident};
use codemap::span;
use ext::base::ExtCtxt;
use ext::build::{AstBuilder, Duplicate, Field};
use ext::build::{AstBuilder, Duplicate};
use ext::deriving::generic::*;
pub fn expand_deriving_rand(cx: @ExtCtxt,
@ -59,10 +59,9 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
cx.ident_of("rand")
];
let rand_call = || {
cx.mk_call_global(
span,
copy rand_ident,
~[ rng[0].duplicate(cx) ])
cx.expr_call_global(span,
copy rand_ident,
~[ rng[0].duplicate(cx) ])
};
return match *substr.fields {
@ -74,41 +73,39 @@ 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 = cx.mk_uint(span, variants.len());
let variant_count = cx.expr_uint(span, variants.len());
// need to specify the uint-ness of the random number
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 u32_ty = cx.ty_ident(span, cx.ident_of("uint"));
let r_ty = cx.ty_ident(span, cx.ident_of("R"));
let rand_name = cx.path_all(span, false, copy rand_ident, None, ~[ u32_ty, r_ty ]);
let rand_name = cx.expr_path(rand_name);
let rv_call = cx.mk_call_(
span,
rand_name,
~[ rng[0].duplicate(cx) ]);
let rv_call = cx.expr_call(span,
rand_name,
~[ rng[0].duplicate(cx) ]);
// rand() % variants.len()
let rand_variant = cx.mk_binary(span, ast::rem,
let rand_variant = cx.expr_binary(span, ast::rem,
rv_call, variant_count);
let mut arms = do variants.mapi |i, id_sum| {
let i_expr = cx.mk_uint(span, i);
let pat = cx.mk_pat_lit(span, i_expr);
let i_expr = cx.expr_uint(span, i);
let pat = cx.pat_lit(span, i_expr);
match *id_sum {
(ident, ref summary) => {
cx.mk_arm(span,
~[ pat ],
rand_thing(cx, span, ident, summary, rand_call))
cx.arm(span,
~[ pat ],
rand_thing(cx, span, ident, summary, rand_call))
}
}
};
// _ => {} at the end. Should never occur
arms.push(cx.mk_unreachable_arm(span));
arms.push(cx.arm_unreachable(span));
cx.mk_expr(span,
ast::expr_match(rand_variant, arms))
cx.expr_match(span, rand_variant, arms)
}
_ => cx.bug("Non-static method in `deriving(Rand)`")
};
@ -117,24 +114,20 @@ fn rand_thing(cx: @ExtCtxt, span: span,
ctor_ident: ident,
summary: &Either<uint, ~[ident]>,
rand_call: &fn() -> @expr) -> @expr {
let ctor_ident = ~[ ctor_ident ];
match *summary {
Left(copy count) => {
if count == 0 {
cx.mk_path(span, ctor_ident)
cx.expr_ident(span, ctor_ident)
} else {
let exprs = vec::from_fn(count, |_| rand_call());
cx.mk_call(span, ctor_ident, exprs)
cx.expr_call_ident(span, ctor_ident, exprs)
}
}
Right(ref fields) => {
let rand_fields = do fields.map |ident| {
Field {
ident: *ident,
ex: rand_call()
}
cx.field_imm(span, *ident, rand_call())
};
cx.mk_struct_e(span, ctor_ident, rand_fields)
cx.expr_struct_ident(span, ctor_ident, rand_fields)
}
}
}

View File

@ -42,12 +42,12 @@ 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 = 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")],
~[self_addr])
let self_addr = cx.expr_addr_of(span, self_obj);
cx.expr_call_global(span,
~[cx.ident_of("core"),
cx.ident_of("sys"),
cx.ident_of("log_str")],
~[self_addr])
}
_ => cx.span_bug(span, "Invalid number of arguments in `deriving(ToStr)`")
}

View File

@ -55,9 +55,8 @@ fn new_<'r>(path: ~[&'r str], lifetime: Option<&'r str>, params: ~[~Ty<'r>], glo
fn to_ty(&self, cx: @ExtCtxt, span: span,
self_ty: ident, self_generics: &Generics) -> @ast::Ty {
cx.mk_ty_path_path(span,
self.to_path(cx, span,
self_ty, self_generics))
cx.ty_path(self.to_path(cx, span,
self_ty, self_generics))
}
fn to_path(&self, cx: @ExtCtxt, span: span,
self_ty: ident, self_generics: &Generics) -> @ast::Path {
@ -65,11 +64,7 @@ fn to_path(&self, cx: @ExtCtxt, span: span,
let lt = mk_lifetime(cx, span, &self.lifetime);
let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics));
if self.global {
cx.mk_raw_path_global_(span, idents, lt, tys)
} else {
cx.mk_raw_path_(span, idents, lt, tys)
}
cx.path_all(span, self.global, idents, lt, tys)
}
}
@ -106,7 +101,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(@cx.mk_lifetime(span, cx.ident_of(*s))),
Some(ref s) => Some(@cx.lifetime(span, cx.ident_of(*s))),
None => None
}
}
@ -119,20 +114,20 @@ fn to_ty(&self, cx: @ExtCtxt, span: span,
let raw_ty = ty.to_ty(cx, span, self_ty, self_generics);
match *ptr {
Owned => {
cx.mk_ty_uniq(span, raw_ty)
cx.ty_uniq(span, raw_ty)
}
Managed(mutbl) => {
cx.mk_ty_box(span, raw_ty, mutbl)
cx.ty_box(span, raw_ty, mutbl)
}
Borrowed(ref lt, mutbl) => {
let lt = mk_lifetime(cx, span, lt);
cx.mk_ty_rptr(span, raw_ty, lt, mutbl)
cx.ty_rptr(span, raw_ty, lt, mutbl)
}
}
}
Literal(ref p) => { p.to_ty(cx, span, self_ty, self_generics) }
Self => {
cx.mk_ty_path_path(span, self.to_path(cx, span, self_ty, self_generics))
cx.ty_path(self.to_path(cx, span, self_ty, self_generics))
}
Tuple(ref fields) => {
let ty = if fields.is_empty() {
@ -141,7 +136,7 @@ fn to_ty(&self, cx: @ExtCtxt, span: span,
ast::ty_tup(fields.map(|f| f.to_ty(cx, span, self_ty, self_generics)))
};
cx.mk_ty(span, ty)
cx.ty(span, ty)
}
}
}
@ -151,7 +146,7 @@ fn to_path(&self, cx: @ExtCtxt, span: span,
match *self {
Self => {
let self_params = do self_generics.ty_params.map |ty_param| {
cx.mk_ty_path(span, ~[ ty_param.ident ])
cx.ty_ident(span, ty_param.ident)
};
let lifetime = if self_generics.lifetimes.is_empty() {
None
@ -159,8 +154,8 @@ fn to_path(&self, cx: @ExtCtxt, span: span,
Some(@*self_generics.lifetimes.get(0))
};
cx.mk_raw_path_(span, ~[self_ty], lifetime,
opt_vec::take_vec(self_params))
cx.path_all(span, false, ~[self_ty], lifetime,
opt_vec::take_vec(self_params))
}
Literal(ref p) => {
p.to_path(cx, span, self_ty, self_generics)
@ -177,9 +172,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);
cx.mk_trait_ty_param_bound_(path)
cx.typarambound(path)
});
cx.mk_ty_param(cx.ident_of(name), @bounds)
cx.typaram(cx.ident_of(name), @bounds)
}
fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Generics {
@ -204,7 +199,7 @@ fn empty() -> LifetimeBounds<'static> {
fn to_generics(&self, cx: @ExtCtxt, span: span,
self_ty: ident, self_generics: &Generics) -> Generics {
let lifetimes = do self.lifetimes.map |lt| {
cx.mk_lifetime(span, cx.ident_of(*lt))
cx.lifetime(span, cx.ident_of(*lt))
};
let ty_params = do self.bounds.map |t| {
match t {
@ -220,7 +215,7 @@ fn to_generics(&self, cx: @ExtCtxt, span: span,
pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option<PtrTy>)
-> (@expr, ast::explicit_self) {
let self_path = cx.make_self(span);
let self_path = cx.expr_self(span);
match *self_ptr {
None => {
(self_path, respan(span, ast::sty_value))
@ -232,12 +227,12 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option<PtrTy>)
Owned => ast::sty_uniq(ast::m_imm),
Managed(mutbl) => ast::sty_box(mutbl),
Borrowed(ref lt, mutbl) => {
let lt = lt.map(|s| @cx.mk_lifetime(span,
cx.ident_of(*s)));
let lt = lt.map(|s| @cx.lifetime(span,
cx.ident_of(*s)));
ast::sty_region(lt, mutbl)
}
});
let self_expr = cx.mk_deref(span, self_path);
let self_expr = cx.expr_deref(span, self_path);
(self_expr, self_ty)
}
}

View File

@ -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.
let e = match os::getenv(var) {
None => cx.mk_base_str(sp, ~""),
Some(ref s) => cx.mk_base_str(sp, copy *s)
None => cx.expr_str(sp, ~""),
Some(ref s) => cx.expr_str(sp, copy *s)
};
MRExpr(e)
}

View File

@ -18,7 +18,6 @@
use codemap::span;
use ext::base::*;
use ext::base;
use ext::build;
use ext::build::AstBuilder;
use core::unstable::extfmt::ct::*;
@ -56,7 +55,7 @@ fn make_path_vec(cx: @ExtCtxt, ident: &str) -> ~[ast::ident] {
}
fn make_rt_path_expr(cx: @ExtCtxt, sp: span, nm: &str) -> @ast::expr {
let path = make_path_vec(cx, nm);
cx.mk_path_global(sp, path)
cx.expr_path(cx.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,8 +71,8 @@ fn make_flags(cx: @ExtCtxt, sp: span, flags: &[Flag]) -> @ast::expr {
FlagSignAlways => "flag_sign_always",
FlagAlternate => "flag_alternate"
};
tmp_expr = cx.mk_binary(sp, ast::bitor, tmp_expr,
make_rt_path_expr(cx, sp, fstr));
tmp_expr = cx.expr_binary(sp, ast::bitor, tmp_expr,
make_rt_path_expr(cx, sp, fstr));
}
return tmp_expr;
}
@ -83,10 +82,10 @@ fn make_count(cx: @ExtCtxt, sp: span, cnt: Count) -> @ast::expr {
return make_rt_path_expr(cx, sp, "CountImplied");
}
CountIs(c) => {
let count_lit = cx.mk_uint(sp, c as uint);
let count_lit = cx.expr_uint(sp, c as uint);
let count_is_path = make_path_vec(cx, "CountIs");
let count_is_args = ~[count_lit];
return cx.mk_call_global(sp, count_is_path, count_is_args);
return cx.expr_call_global(sp, count_is_path, count_is_args);
}
_ => cx.span_unimpl(sp, "unimplemented fmt! conversion")
}
@ -107,22 +106,14 @@ fn make_conv_struct(cx: @ExtCtxt, sp: span, flags_expr: @ast::expr,
width_expr: @ast::expr, precision_expr: @ast::expr,
ty_expr: @ast::expr) -> @ast::expr {
let intr = cx.parse_sess().interner;
cx.mk_global_struct_e(
cx.expr_struct(
sp,
make_path_vec(cx, "Conv"),
cx.path_global(sp, make_path_vec(cx, "Conv")),
~[
build::Field {
ident: intr.intern("flags"), ex: flags_expr
},
build::Field {
ident: intr.intern("width"), ex: width_expr
},
build::Field {
ident: intr.intern("precision"), ex: precision_expr
},
build::Field {
ident: intr.intern("ty"), ex: ty_expr
},
cx.field_imm(sp, intr.intern("flags"), flags_expr),
cx.field_imm(sp, intr.intern("width"), width_expr),
cx.field_imm(sp, intr.intern("precision"), precision_expr),
cx.field_imm(sp, intr.intern("ty"), ty_expr)
]
)
}
@ -139,7 +130,7 @@ fn make_conv_call(cx: @ExtCtxt, sp: span, conv_type: &str, cnv: &Conv,
let path = make_path_vec(cx, fname);
let cnv_expr = make_rt_conv_expr(cx, sp, cnv);
let args = ~[cnv_expr, arg, buf];
cx.mk_call_global(arg.span, path, args)
cx.expr_call_global(arg.span, path, args)
}
fn make_new_conv(cx: @ExtCtxt, sp: span, cnv: &Conv,
@ -197,10 +188,10 @@ fn is_signed_type(cnv: &Conv) -> bool {
TyChar => ("char", arg),
TyBits | TyOctal | TyHex(_) | TyInt(Unsigned) => ("uint", arg),
TyFloat => ("float", arg),
TyPoly => ("poly", cx.mk_addr_of(sp, arg))
TyPoly => ("poly", cx.expr_addr_of(sp, arg))
};
return make_conv_call(cx, arg.span, name, cnv, actual_arg,
cx.mk_mut_addr_of(arg.span, buf));
cx.expr_mut_addr_of(arg.span, buf));
}
fn log_conv(c: &Conv) {
debug!("Building conversion:");
@ -258,7 +249,7 @@ fn log_conv(c: &Conv) {
/* 'ident' is the local buffer building up the result of fmt! */
let ident = cx.parse_sess().interner.intern("__fmtbuf");
let buf = || cx.mk_path(fmt_sp, ~[ident]);
let buf = || cx.expr_ident(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 = ~[];
@ -275,14 +266,14 @@ fn log_conv(c: &Conv) {
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(cx.mk_local(fmt_sp, npieces > 1, ident, cx.mk_uniq_str(fmt_sp, s)));
stms.push(cx.stmt_let(fmt_sp, npieces > 1,
ident, cx.expr_str_uniq(fmt_sp, s)));
} else {
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(cx.mk_stmt(fmt_sp, call));
let args = ~[cx.expr_mut_addr_of(fmt_sp, buf()), cx.expr_str(fmt_sp, s)];
let call = cx.expr_call_global(fmt_sp,
~[str_ident, push_ident],
args);
stms.push(cx.stmt_expr(call));
}
}
@ -299,12 +290,11 @@ fn log_conv(c: &Conv) {
/* If the first portion is a conversion, then the local buffer
must be initialized as an empty string */
if i == 0 {
stms.push(cx.mk_local(fmt_sp, true, ident,
cx.mk_uniq_str(fmt_sp, ~"")));
stms.push(cx.stmt_let(fmt_sp, true, ident,
cx.expr_str_uniq(fmt_sp, ~"")));
}
stms.push(cx.mk_stmt(fmt_sp,
make_new_conv(cx, fmt_sp, conv,
args[n], buf())));
stms.push(cx.stmt_expr(make_new_conv(cx, fmt_sp, conv,
args[n], buf())));
}
}
}
@ -316,5 +306,5 @@ fn log_conv(c: &Conv) {
nargs, expected_nargs));
}
cx.mk_block(fmt_sp, ~[], stms, Some(buf()))
cx.expr_blk(cx.blk(fmt_sp, stms, Some(buf())))
}

View File

@ -16,7 +16,7 @@
use ast::ident;
use ast;
use codemap::span;
use ext::quote::rt::*;
// use ext::quote::rt::*;
// Transitional reexports so qquote can find the paths it is looking for
mod syntax {

View File

@ -53,14 +53,13 @@ fn gen_send(&mut self, cx: @ExtCtxt, try: bool) -> @ast::item {
assert!(next_state.tys.len() ==
next.generics.ty_params.len());
let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str()));
let args_ast = vec::map_zip(arg_names, *tys, |n, t| cx.arg(*n, *t));
let args_ast = vec::map_zip(arg_names, *tys, |n, t| cx.arg(span, *n, *t));
let pipe_ty = cx.ty_path(
path(~[this.data_name()], span)
.add_tys(cx.ty_vars_global(&this.generics.ty_params)));
.add_tys(cx.ty_vars(&this.generics.ty_params)));
let args_ast = vec::append(
~[cx.arg(cx.ident_of("pipe"),
pipe_ty)],
~[cx.arg(span, cx.ident_of("pipe"), pipe_ty)],
args_ast);
let mut body = ~"{\n";
@ -113,15 +112,16 @@ fn gen_send(&mut self, cx: @ExtCtxt, try: bool) -> @ast::item {
let body = cx.parse_expr(body);
let mut rty = cx.ty_path(path(~[next.data_name()],
span)
.add_tys(copy next_state.tys));
span)
.add_tys(copy next_state.tys));
if try {
rty = cx.ty_option(rty);
}
let name = cx.ident_of(if try { ~"try_" + name } else { name } );
cx.item_fn_poly(name,
cx.item_fn_poly(dummy_sp(),
name,
args_ast,
rty,
self.get_generics(),
@ -133,14 +133,15 @@ fn gen_send(&mut self, cx: @ExtCtxt, try: bool) -> @ast::item {
let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str()));
let args_ast = do vec::map_zip(arg_names, *tys) |n, t| {
cx.arg(cx.ident_of(*n), *t)
cx.arg(span, cx.ident_of(*n), *t)
};
let args_ast = vec::append(
~[cx.arg(cx.ident_of("pipe"),
~[cx.arg(span,
cx.ident_of("pipe"),
cx.ty_path(
path(~[this.data_name()], span)
.add_tys(cx.ty_vars_global(
.add_tys(cx.ty_vars(
&this.generics.ty_params))))],
args_ast);
@ -172,12 +173,13 @@ fn gen_send(&mut self, cx: @ExtCtxt, try: bool) -> @ast::item {
let name = if try { ~"try_" + name } else { name };
cx.item_fn_poly(cx.ident_of(name),
cx.item_fn_poly(dummy_sp(),
cx.ident_of(name),
args_ast,
if try {
cx.ty_option(cx.ty_nil_ast_builder())
cx.ty_option(cx.ty_nil())
} else {
cx.ty_nil_ast_builder()
cx.ty_nil()
},
self.get_generics(),
cx.blk_expr(body))
@ -187,7 +189,7 @@ fn gen_send(&mut self, cx: @ExtCtxt, try: bool) -> @ast::item {
fn to_ty(&mut self, cx: @ExtCtxt) -> @ast::Ty {
cx.ty_path(path(~[cx.ident_of(self.name())], self.span())
.add_tys(cx.ty_vars_global(&self.get_generics().ty_params)))
.add_tys(cx.ty_vars(&self.get_generics().ty_params)))
}
}
@ -226,15 +228,15 @@ fn to_type_decls(&self, cx: @ExtCtxt) -> ~[@ast::item] {
None => tys
};
let v = cx.variant(cx.ident_of(name), span, tys);
let v = cx.variant(span, cx.ident_of(name), tys);
items_msg.push(v);
}
~[
cx.item_enum_poly(
name,
self.span,
name,
ast::enum_def { variants: items_msg },
cx.strip_bounds(&self.generics)
)
@ -263,8 +265,8 @@ fn to_endpoint_decls(&self, cx: @ExtCtxt,
if !self.proto.is_bounded() {
items.push(
cx.item_ty_poly(
self.data_name(),
self.span,
self.data_name(),
cx.ty_path(
path_global(~[cx.ident_of("core"),
cx.ident_of("pipes"),
@ -274,15 +276,15 @@ fn to_endpoint_decls(&self, cx: @ExtCtxt,
path(~[cx.ident_of("super"),
self.data_name()],
dummy_sp())
.add_tys(cx.ty_vars_global(
.add_tys(cx.ty_vars(
&self.generics.ty_params))))),
cx.strip_bounds(&self.generics)));
}
else {
items.push(
cx.item_ty_poly(
self.data_name(),
self.span,
self.data_name(),
cx.ty_path(
path_global(~[cx.ident_of("core"),
cx.ident_of("pipes"),
@ -342,15 +344,18 @@ fn gen_init(&self, cx: @ExtCtxt) -> @ast::item {
}
fn gen_buffer_init(&self, ext_cx: @ExtCtxt) -> @ast::expr {
ext_cx.expr_struct(path(~[ext_cx.ident_of("__Buffer")],
dummy_sp()),
self.states.map_to_vec(|s| {
let fty = s.to_ty(ext_cx);
ext_cx.field_imm(ext_cx.ident_of(s.name),
quote_expr!(
::core::pipes::mk_packet::<$fty>()
))
}))
ext_cx.expr_struct(
dummy_sp(),
path(~[ext_cx.ident_of("__Buffer")],
dummy_sp()),
self.states.map_to_vec(|s| {
let fty = s.to_ty(ext_cx);
ext_cx.field_imm(dummy_sp(),
ext_cx.ident_of(s.name),
quote_expr!(
::core::pipes::mk_packet::<$fty>()
))
}))
}
fn gen_init_bounded(&self, ext_cx: @ExtCtxt) -> @ast::expr {
@ -392,9 +397,9 @@ fn buffer_ty_path(&self, cx: @ExtCtxt) -> @ast::Ty {
}
cx.ty_path(path(~[cx.ident_of("super"),
cx.ident_of("__Buffer")],
copy self.span)
.add_tys(cx.ty_vars_global(&params)))
cx.ident_of("__Buffer")],
copy self.span)
.add_tys(cx.ty_vars_global(&params)))
}
fn gen_buffer_type(&self, cx: @ExtCtxt) -> @ast::item {
@ -429,8 +434,8 @@ fn gen_buffer_type(&self, cx: @ExtCtxt) -> @ast::item {
};
cx.item_struct_poly(
cx.ident_of("__Buffer"),
dummy_sp(),
cx.ident_of("__Buffer"),
ast::struct_def {
fields: fields,
ctor_id: None
@ -454,13 +459,24 @@ fn compile(&self, cx: @ExtCtxt) -> @ast::item {
items.push(self.gen_buffer_type(cx))
}
items.push(cx.item_mod(cx.ident_of("client"),
copy self.span,
items.push(cx.item_mod(copy self.span,
cx.ident_of("client"),
~[], ~[],
client_states));
items.push(cx.item_mod(cx.ident_of("server"),
copy self.span,
items.push(cx.item_mod(copy self.span,
cx.ident_of("server"),
~[], ~[],
server_states));
cx.item_mod(cx.ident_of(copy self.name), copy self.span, items)
// XXX: Would be nice if our generated code didn't violate
// Rust coding conventions
let allows = cx.attribute(
copy self.span,
cx.meta_list(copy self.span,
~"allow",
~[cx.meta_word(copy self.span, ~"non_camel_case_types"),
cx.meta_word(copy self.span, ~"unused_mut")]));
cx.item_mod(copy self.span, cx.ident_of(copy self.name),
~[allows], ~[], items)
}
}

View File

@ -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 = cx.mk_uniq_vec_e(sp, ~[]);
let e_attrs = cx.expr_vec_uniq(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 = cx.mk_lit(sp, ast::lit_bool(true));
let e_refutable = cx.expr_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 = cx.mk_lit(sp, ast::lit_bool(false));
let e_param_colons = cx.expr_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 = cx.mk_uniq_vec_e(sp, ~[]);
let e_attrs = cx.expr_vec_uniq(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 = 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])
let e_str = cx.expr_str(sp, cx.str_of(ident));
cx.expr_method_call(sp,
cx.expr_ident(sp, id_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 = cx.mk_uint(sp, bpos.to_uint());
cx.mk_call(sp, path, ~[arg])
let path = id_ext(cx, "BytePos");
let arg = cx.expr_uint(sp, bpos.to_uint());
cx.expr_call_ident(sp, path, ~[arg])
}
fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr {
@ -447,22 +447,21 @@ fn mk_binop(cx: @ExtCtxt, sp: span, bop: token::binop) -> @ast::expr {
SHL => "SHL",
SHR => "SHR"
};
cx.mk_path(sp,
ids_ext(cx, ~[name.to_owned()]))
cx.expr_ident(sp, id_ext(cx, name))
}
fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr {
match *tok {
BINOP(binop) => {
return cx.mk_call(sp,
ids_ext(cx, ~[~"BINOP"]),
~[mk_binop(cx, sp, binop)]);
return cx.expr_call_ident(sp,
id_ext(cx, "BINOP"),
~[mk_binop(cx, sp, binop)]);
}
BINOPEQ(binop) => {
return cx.mk_call(sp,
ids_ext(cx, ~[~"BINOPEQ"]),
~[mk_binop(cx, sp, binop)]);
return cx.expr_call_ident(sp,
id_ext(cx, "BINOPEQ"),
~[mk_binop(cx, sp, binop)]);
}
LIT_INT(i, ity) => {
@ -474,15 +473,13 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr {
ast::ty_i32 => ~"ty_i32",
ast::ty_i64 => ~"ty_i64"
};
let e_ity =
cx.mk_path(sp,
ids_ext(cx, ~[s_ity]));
let e_ity = cx.expr_ident(sp, id_ext(cx, s_ity));
let e_i64 = cx.mk_lit(sp, ast::lit_int(i, ast::ty_i64));
let e_i64 = cx.expr_lit(sp, ast::lit_int(i, ast::ty_i64));
return cx.mk_call(sp,
ids_ext(cx, ~[~"LIT_INT"]),
~[e_i64, e_ity]);
return cx.expr_call_ident(sp,
id_ext(cx, "LIT_INT"),
~[e_i64, e_ity]);
}
LIT_UINT(u, uty) => {
@ -493,24 +490,21 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr {
ast::ty_u32 => ~"ty_u32",
ast::ty_u64 => ~"ty_u64"
};
let e_uty =
cx.mk_path(sp,
ids_ext(cx, ~[s_uty]));
let e_uty = cx.expr_ident(sp, id_ext(cx, s_uty));
let e_u64 = cx.mk_lit(sp, ast::lit_uint(u, ast::ty_u64));
let e_u64 = cx.expr_lit(sp, ast::lit_uint(u, ast::ty_u64));
return cx.mk_call(sp,
ids_ext(cx, ~[~"LIT_UINT"]),
~[e_u64, e_uty]);
return cx.expr_call_ident(sp,
id_ext(cx, "LIT_UINT"),
~[e_u64, e_uty]);
}
LIT_INT_UNSUFFIXED(i) => {
let e_i64 = cx.mk_lit(sp,
ast::lit_int(i, ast::ty_i64));
let e_i64 = cx.expr_lit(sp, ast::lit_int(i, ast::ty_i64));
return cx.mk_call(sp,
ids_ext(cx, ~[~"LIT_INT_UNSUFFIXED"]),
~[e_i64]);
return cx.expr_call_ident(sp,
id_ext(cx, "LIT_INT_UNSUFFIXED"),
~[e_i64]);
}
LIT_FLOAT(fident, fty) => {
@ -519,40 +513,38 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr {
ast::ty_f32 => ~"ty_f32",
ast::ty_f64 => ~"ty_f64"
};
let e_fty =
cx.mk_path(sp,
ids_ext(cx, ~[s_fty]));
let e_fty = cx.expr_ident(sp, id_ext(cx, s_fty));
let e_fident = mk_ident(cx, sp, fident);
return cx.mk_call(sp,
ids_ext(cx, ~[~"LIT_FLOAT"]),
~[e_fident, e_fty]);
return cx.expr_call_ident(sp,
id_ext(cx, "LIT_FLOAT"),
~[e_fident, e_fty]);
}
LIT_STR(ident) => {
return cx.mk_call(sp,
ids_ext(cx, ~[~"LIT_STR"]),
~[mk_ident(cx, sp, ident)]);
return cx.expr_call_ident(sp,
id_ext(cx, "LIT_STR"),
~[mk_ident(cx, sp, ident)]);
}
IDENT(ident, b) => {
return cx.mk_call(sp,
ids_ext(cx, ~[~"IDENT"]),
~[mk_ident(cx, sp, ident),
cx.mk_lit(sp, ast::lit_bool(b))]);
return cx.expr_call_ident(sp,
id_ext(cx, "IDENT"),
~[mk_ident(cx, sp, ident),
cx.expr_bool(sp, b)]);
}
LIFETIME(ident) => {
return cx.mk_call(sp,
ids_ext(cx, ~[~"LIFETIME"]),
~[mk_ident(cx, sp, ident)]);
return cx.expr_call_ident(sp,
id_ext(cx, "LIFETIME"),
~[mk_ident(cx, sp, ident)]);
}
DOC_COMMENT(ident) => {
return cx.mk_call(sp,
ids_ext(cx, ~[~"DOC_COMMENT"]),
~[mk_ident(cx, sp, ident)]);
return cx.expr_call_ident(sp,
id_ext(cx, "DOC_COMMENT"),
~[mk_ident(cx, sp, ident)]);
}
INTERPOLATED(_) => fail!("quote! with interpolated token"),
@ -595,8 +587,7 @@ fn mk_token(cx: @ExtCtxt, sp: span, tok: &token::Token) -> @ast::expr {
EOF => "EOF",
_ => fail!()
};
cx.mk_path(sp,
ids_ext(cx, ~[name.to_owned()]))
cx.expr_ident(sp, id_ext(cx, name))
}
@ -606,19 +597,16 @@ fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree)
match *tt {
ast::tt_tok(sp, ref tok) => {
let e_sp = cx.mk_path(sp,
ids_ext(cx, ~[~"sp"]));
let e_tok =
cx.mk_call(sp,
ids_ext(cx, ~[~"tt_tok"]),
~[e_sp, mk_token(cx, sp, tok)]);
let e_sp = cx.expr_ident(sp, id_ext(cx, "sp"));
let e_tok = cx.expr_call_ident(sp,
id_ext(cx, "tt_tok"),
~[e_sp, mk_token(cx, sp, tok)]);
let e_push =
cx.mk_method_call(sp,
cx.mk_path(sp, ids_ext(cx, ~[~"tt"])),
id_ext(cx, "push"),
~[e_tok]);
~[cx.mk_stmt(sp, e_push)]
cx.expr_method_call(sp,
cx.expr_ident(sp, id_ext(cx, "tt")),
id_ext(cx, "push"),
~[e_tok]);
~[cx.stmt_expr(e_push)]
}
ast::tt_delim(ref tts) => mk_tts(cx, sp, *tts),
@ -629,19 +617,18 @@ fn mk_tt(cx: @ExtCtxt, sp: span, tt: &ast::token_tree)
// tt.push_all_move($ident.to_tokens(ext_cx))
let e_to_toks =
cx.mk_method_call(sp,
cx.mk_path(sp, ~[ident]),
id_ext(cx, "to_tokens"),
~[cx.mk_path(sp,
ids_ext(cx, ~[~"ext_cx"]))]);
cx.expr_method_call(sp,
cx.expr_ident(sp, ident),
id_ext(cx, "to_tokens"),
~[cx.expr_ident(sp, id_ext(cx, "ext_cx"))]);
let e_push =
cx.mk_method_call(sp,
cx.mk_path(sp, ids_ext(cx, ~[~"tt"])),
id_ext(cx, "push_all_move"),
~[e_to_toks]);
cx.expr_method_call(sp,
cx.expr_ident(sp, id_ext(cx, "tt")),
id_ext(cx, "push_all_move"),
~[e_to_toks]);
~[cx.mk_stmt(sp, e_push)]
~[cx.stmt_expr(e_push)]
}
}
}
@ -677,11 +664,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 = ~[ cx.mk_glob_use(sp, ast::public,
ids_ext(cx, ~[~"syntax",
~"ext",
~"quote",
~"rt"])) ];
let uses = ~[ cx.view_use_glob(sp, ast::public,
ids_ext(cx, ~[~"syntax",
~"ext",
~"quote",
~"rt"])) ];
// We also bind a single value, sp, to ext_cx.call_site()
//
@ -709,24 +696,24 @@ 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 = cx.mk_method_call(sp,
cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])),
id_ext(cx, "call_site"),
~[]);
let e_sp = cx.expr_method_call(sp,
cx.expr_ident(sp, id_ext(cx, "ext_cx")),
id_ext(cx, "call_site"),
~[]);
let stmt_let_sp = cx.mk_local(sp, false,
id_ext(cx, "sp"),
e_sp);
let stmt_let_sp = cx.stmt_let(sp, false,
id_ext(cx, "sp"),
e_sp);
let stmt_let_tt = cx.mk_local(sp, true,
id_ext(cx, "tt"),
cx.mk_uniq_vec_e(sp, ~[]));
let stmt_let_tt = cx.stmt_let(sp, true,
id_ext(cx, "tt"),
cx.expr_vec_uniq(sp, ~[]));
cx.mk_block(sp, uses,
~[stmt_let_sp,
stmt_let_tt] + mk_tts(cx, sp, tts),
Some(cx.mk_path(sp,
ids_ext(cx, ~[~"tt"]))))
cx.expr_blk(
cx.blk_all(sp, uses,
~[stmt_let_sp,
stmt_let_tt] + mk_tts(cx, sp, tts),
Some(cx.expr_ident(sp, id_ext(cx, "tt")))))
}
fn expand_parse_call(cx: @ExtCtxt,
@ -736,27 +723,26 @@ fn expand_parse_call(cx: @ExtCtxt,
tts: &[ast::token_tree]) -> @ast::expr {
let tts_expr = expand_tts(cx, sp, tts);
let cfg_call = || cx.mk_method_call(
sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])),
let cfg_call = || cx.expr_method_call(
sp, cx.expr_ident(sp, id_ext(cx, "ext_cx")),
id_ext(cx, "cfg"), ~[]);
let parse_sess_call = || cx.mk_method_call(
sp, cx.mk_path(sp, ids_ext(cx, ~[~"ext_cx"])),
let parse_sess_call = || cx.expr_method_call(
sp, cx.expr_ident(sp, id_ext(cx, "ext_cx")),
id_ext(cx, "parse_sess"), ~[]);
let new_parser_call =
cx.mk_call_global(sp,
ids_ext(cx, ~[~"syntax",
~"ext",
~"quote",
~"rt",
~"new_parser_from_tts"]),
~[parse_sess_call(),
cfg_call(),
tts_expr]);
cx.expr_call_global(sp,
ids_ext(cx, ~[~"syntax",
~"ext",
~"quote",
~"rt",
~"new_parser_from_tts"]),
~[parse_sess_call(),
cfg_call(),
tts_expr]);
cx.mk_method_call(sp,
new_parser_call,
id_ext(cx, parse_method),
arg_exprs)
cx.expr_method_call(sp, new_parser_call,
id_ext(cx, parse_method),
arg_exprs)
}

View File

@ -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(cx.mk_uint(topmost.call_site, loc.line))
base::MRExpr(cx.expr_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(cx.mk_uint(topmost.call_site, loc.col.to_uint()))
base::MRExpr(cx.expr_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(cx.mk_base_str(topmost.call_site, filename))
base::MRExpr(cx.expr_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(cx.mk_base_str(sp, s))
base::MRExpr(cx.expr_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(cx.mk_base_str(sp,
base::MRExpr(cx.expr_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(cx.mk_base_str(sp, result::unwrap(res)))
base::MRExpr(cx.expr_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| {
cx.mk_u8(sp, *char)
cx.expr_u8(sp, *char)
});
base::MRExpr(cx.mk_base_vec_e(sp, u8_exprs))
base::MRExpr(cx.expr_vec(sp, u8_exprs))
}
result::Err(ref e) => {
cx.parse_sess().span_diagnostic.handler().fatal((*e))