2012-01-25 14:47:56 -07:00
|
|
|
import codemap::span;
|
2012-03-29 13:48:05 -07:00
|
|
|
import base::ext_ctxt;
|
2012-01-25 14:47:56 -07:00
|
|
|
|
2012-06-29 14:38:33 -07:00
|
|
|
fn mk_expr(cx: ext_ctxt, sp: codemap::span, expr: ast::expr_) ->
|
|
|
|
@ast::expr {
|
2012-08-01 17:30:05 -07:00
|
|
|
return @{id: cx.next_id(), callee_id: cx.next_id(),
|
2012-07-11 14:31:35 -07:00
|
|
|
node: expr, span: sp};
|
2012-06-29 14:38:33 -07:00
|
|
|
}
|
|
|
|
|
2012-01-26 16:34:05 -07:00
|
|
|
fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
|
2012-01-25 14:47:56 -07:00
|
|
|
let sp_lit = @{node: lit, span: sp};
|
2012-07-11 14:31:35 -07:00
|
|
|
mk_expr(cx, sp, ast::expr_lit(sp_lit))
|
2012-01-25 14:47:56 -07:00
|
|
|
}
|
2012-01-26 16:34:05 -07:00
|
|
|
fn mk_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
|
2012-01-25 14:47:56 -07:00
|
|
|
let lit = ast::lit_int(i as i64, ast::ty_i);
|
2012-08-01 17:30:05 -07:00
|
|
|
return mk_lit(cx, sp, lit);
|
2012-01-25 14:47:56 -07:00
|
|
|
}
|
2012-01-26 16:34:05 -07:00
|
|
|
fn mk_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr {
|
2012-01-25 14:47:56 -07:00
|
|
|
let lit = ast::lit_uint(u as u64, ast::ty_u);
|
2012-08-01 17:30:05 -07:00
|
|
|
return mk_lit(cx, sp, lit);
|
2012-01-25 14:47:56 -07:00
|
|
|
}
|
2012-07-13 15:54:39 -07:00
|
|
|
fn mk_u8(cx: ext_ctxt, sp: span, u: u8) -> @ast::expr {
|
|
|
|
let lit = ast::lit_uint(u as u64, ast::ty_u8);
|
2012-08-01 17:30:05 -07:00
|
|
|
return mk_lit(cx, sp, lit);
|
2012-07-13 15:54:39 -07:00
|
|
|
}
|
2012-01-26 16:34:05 -07:00
|
|
|
fn mk_binary(cx: ext_ctxt, sp: span, op: ast::binop,
|
|
|
|
lhs: @ast::expr, rhs: @ast::expr)
|
2012-01-25 14:47:56 -07:00
|
|
|
-> @ast::expr {
|
2012-06-27 16:06:58 -07:00
|
|
|
cx.next_id(); // see ast_util::op_expr_callee_id
|
2012-06-29 14:38:33 -07:00
|
|
|
mk_expr(cx, sp, ast::expr_binary(op, lhs, rhs))
|
2012-01-25 14:47:56 -07:00
|
|
|
}
|
2012-01-26 16:34:05 -07:00
|
|
|
fn mk_unary(cx: ext_ctxt, sp: span, op: ast::unop, e: @ast::expr)
|
|
|
|
-> @ast::expr {
|
2012-06-27 16:06:58 -07:00
|
|
|
cx.next_id(); // see ast_util::op_expr_callee_id
|
2012-06-29 14:38:33 -07:00
|
|
|
mk_expr(cx, sp, ast::expr_unary(op, e))
|
2012-01-26 16:34:05 -07:00
|
|
|
}
|
2012-06-29 16:26:56 -07:00
|
|
|
fn mk_path(cx: ext_ctxt, sp: span, idents: ~[ast::ident]) ->
|
2012-01-26 16:34:05 -07:00
|
|
|
@ast::expr {
|
2012-04-24 15:52:52 -07:00
|
|
|
let path = @{span: sp, global: false, idents: idents,
|
2012-06-29 16:26:56 -07:00
|
|
|
rp: none, types: ~[]};
|
2012-04-23 13:04:46 +02:00
|
|
|
let pathexpr = ast::expr_path(path);
|
2012-06-29 14:38:33 -07:00
|
|
|
mk_expr(cx, sp, pathexpr)
|
2012-01-25 14:47:56 -07:00
|
|
|
}
|
2012-01-26 16:34:05 -07:00
|
|
|
fn mk_access_(cx: ext_ctxt, sp: span, p: @ast::expr, m: ast::ident)
|
|
|
|
-> @ast::expr {
|
2012-06-29 16:26:56 -07:00
|
|
|
mk_expr(cx, sp, ast::expr_field(p, m, ~[]))
|
2012-01-26 16:34:05 -07:00
|
|
|
}
|
2012-06-29 16:26:56 -07:00
|
|
|
fn mk_access(cx: ext_ctxt, sp: span, p: ~[ast::ident], m: ast::ident)
|
2012-01-26 16:34:05 -07:00
|
|
|
-> @ast::expr {
|
|
|
|
let pathexpr = mk_path(cx, sp, p);
|
2012-08-01 17:30:05 -07:00
|
|
|
return mk_access_(cx, sp, pathexpr, m);
|
2012-01-26 16:34:05 -07:00
|
|
|
}
|
|
|
|
fn mk_call_(cx: ext_ctxt, sp: span, fn_expr: @ast::expr,
|
2012-06-29 16:26:56 -07:00
|
|
|
args: ~[@ast::expr]) -> @ast::expr {
|
2012-06-29 14:38:33 -07:00
|
|
|
mk_expr(cx, sp, ast::expr_call(fn_expr, args, false))
|
2012-01-26 16:34:05 -07:00
|
|
|
}
|
2012-06-29 16:26:56 -07:00
|
|
|
fn mk_call(cx: ext_ctxt, sp: span, fn_path: ~[ast::ident],
|
|
|
|
args: ~[@ast::expr]) -> @ast::expr {
|
2012-01-26 16:34:05 -07:00
|
|
|
let pathexpr = mk_path(cx, sp, fn_path);
|
2012-08-01 17:30:05 -07:00
|
|
|
return mk_call_(cx, sp, pathexpr, args);
|
2012-01-26 16:34:05 -07:00
|
|
|
}
|
|
|
|
// e = expr, t = type
|
2012-06-29 16:26:56 -07:00
|
|
|
fn mk_base_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
|
2012-01-25 14:47:56 -07:00
|
|
|
@ast::expr {
|
2012-02-15 11:25:39 -08:00
|
|
|
let vecexpr = ast::expr_vec(exprs, ast::m_imm);
|
2012-07-11 14:31:35 -07:00
|
|
|
mk_expr(cx, sp, vecexpr)
|
2012-01-25 14:47:56 -07:00
|
|
|
}
|
2012-06-25 20:00:39 -07:00
|
|
|
fn mk_vstore_e(cx: ext_ctxt, sp: span, expr: @ast::expr, vst: ast::vstore) ->
|
|
|
|
@ast::expr {
|
2012-06-29 14:38:33 -07:00
|
|
|
mk_expr(cx, sp, ast::expr_vstore(expr, vst))
|
2012-06-25 20:00:39 -07:00
|
|
|
}
|
2012-06-29 16:26:56 -07:00
|
|
|
fn mk_uniq_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
|
2012-06-25 20:00:39 -07:00
|
|
|
@ast::expr {
|
2012-06-29 14:38:33 -07:00
|
|
|
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::vstore_uniq)
|
2012-06-25 20:00:39 -07:00
|
|
|
}
|
2012-06-29 16:26:56 -07:00
|
|
|
fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
|
2012-06-28 16:23:12 -07:00
|
|
|
@ast::expr {
|
2012-06-29 14:38:33 -07:00
|
|
|
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::vstore_fixed(none))
|
2012-06-28 16:23:12 -07:00
|
|
|
}
|
2012-07-13 22:57:48 -07:00
|
|
|
fn mk_base_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
|
2012-07-13 15:54:39 -07:00
|
|
|
let lit = ast::lit_str(@s);
|
2012-08-01 17:30:05 -07:00
|
|
|
return mk_lit(cx, sp, lit);
|
2012-07-13 15:54:39 -07:00
|
|
|
}
|
2012-07-13 22:57:48 -07:00
|
|
|
fn mk_uniq_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
|
2012-07-13 15:54:39 -07:00
|
|
|
mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::vstore_uniq)
|
|
|
|
}
|
2012-06-25 20:00:39 -07:00
|
|
|
|
2012-01-26 16:34:05 -07:00
|
|
|
fn mk_rec_e(cx: ext_ctxt, sp: span,
|
2012-06-29 16:26:56 -07:00
|
|
|
fields: ~[{ident: ast::ident, ex: @ast::expr}]) ->
|
2012-01-26 16:34:05 -07:00
|
|
|
@ast::expr {
|
2012-06-29 16:26:56 -07:00
|
|
|
let mut astfields: ~[ast::field] = ~[];
|
2012-06-30 16:19:07 -07:00
|
|
|
for fields.each |field| {
|
2012-01-26 16:34:05 -07:00
|
|
|
let ident = field.ident;
|
|
|
|
let val = field.ex;
|
|
|
|
let astfield =
|
2012-02-15 11:25:39 -08:00
|
|
|
{node: {mutbl: ast::m_imm, ident: ident, expr: val}, span: sp};
|
2012-06-27 23:09:51 -07:00
|
|
|
vec::push(astfields, astfield);
|
2012-01-26 16:34:05 -07:00
|
|
|
}
|
|
|
|
let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>);
|
2012-06-29 14:38:33 -07:00
|
|
|
mk_expr(cx, sp, recexpr)
|
2012-01-25 14:47:56 -07:00
|
|
|
}
|
2012-01-26 16:34:05 -07:00
|
|
|
|