Convert extfmt::rt::Conv into a struct
This commit is contained in:
parent
79a9b23f4a
commit
90734a0d33
@ -376,13 +376,23 @@ fn test(s: &str, flags: &[Flag], next: uint) {
|
||||
fn test_parse_fmt_string() {
|
||||
assert parse_fmt_string("foo %s bar", die) == ~[
|
||||
PieceString(~"foo "),
|
||||
PieceConv(Conv {param: None, flags: ~[], width: CountImplied,
|
||||
precision: CountImplied, ty: TyStr}),
|
||||
PieceConv(Conv {
|
||||
param: None,
|
||||
flags: ~[],
|
||||
width: CountImplied,
|
||||
precision: CountImplied,
|
||||
ty: TyStr,
|
||||
}),
|
||||
PieceString(~" bar")];
|
||||
|
||||
assert parse_fmt_string("%s", die) == ~[
|
||||
PieceConv(Conv {param: None, flags: ~[], width: CountImplied,
|
||||
precision: CountImplied, ty: TyStr })];
|
||||
PieceConv(Conv {
|
||||
param: None,
|
||||
flags: ~[],
|
||||
width: CountImplied,
|
||||
precision: CountImplied,
|
||||
ty: TyStr,
|
||||
})];
|
||||
|
||||
assert parse_fmt_string("%%%%", die) == ~[
|
||||
PieceString(~"%"), PieceString(~"%")];
|
||||
@ -486,8 +496,19 @@ pub enum Count { CountIs(uint), CountImplied, }
|
||||
|
||||
pub enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub struct Conv {
|
||||
flags: u32,
|
||||
width: Count,
|
||||
precision: Count,
|
||||
ty: Ty,
|
||||
}
|
||||
|
||||
pub pure fn conv_int(cv: Conv, i: int) -> ~str {
|
||||
let radix = 10;
|
||||
let prec = get_int_precision(cv);
|
||||
|
@ -172,6 +172,15 @@ fn mk_struct_e(cx: ext_ctxt, sp: span,
|
||||
mk_fields(sp, fields),
|
||||
option::None::<@ast::expr>))
|
||||
}
|
||||
fn mk_global_struct_e(cx: ext_ctxt, sp: span,
|
||||
ctor_path: ~[ast::ident],
|
||||
fields: ~[{ident: ast::ident, ex: @ast::expr}]) ->
|
||||
@ast::expr {
|
||||
mk_expr(cx, sp,
|
||||
ast::expr_struct(mk_raw_path_global(sp, ctor_path),
|
||||
mk_fields(sp, fields),
|
||||
option::None::<@ast::expr>))
|
||||
}
|
||||
fn mk_glob_use(cx: ext_ctxt, sp: span,
|
||||
path: ~[ast::ident]) -> @ast::view_item {
|
||||
let glob = @ast::spanned {
|
||||
|
@ -56,8 +56,8 @@ fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: &str) -> ! {
|
||||
fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
pieces: ~[Piece], args: ~[@ast::expr])
|
||||
-> @ast::expr {
|
||||
fn make_path_vec(_cx: ext_ctxt, ident: @~str) -> ~[ast::ident] {
|
||||
let intr = _cx.parse_sess().interner;
|
||||
fn make_path_vec(cx: ext_ctxt, ident: @~str) -> ~[ast::ident] {
|
||||
let intr = cx.parse_sess().interner;
|
||||
return ~[intr.intern(@~"extfmt"), intr.intern(@~"rt"),
|
||||
intr.intern(ident)];
|
||||
}
|
||||
@ -111,23 +111,28 @@ fn make_ty(cx: ext_ctxt, sp: span, t: Ty) -> @ast::expr {
|
||||
}
|
||||
return make_rt_path_expr(cx, sp, @rt_type);
|
||||
}
|
||||
fn make_conv_rec(cx: ext_ctxt, sp: span, flags_expr: @ast::expr,
|
||||
fn make_conv_struct(cx: ext_ctxt, 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;
|
||||
return mk_rec_e(cx, sp,
|
||||
~[{ident: intr.intern(@~"flags"), ex: flags_expr},
|
||||
{ident: intr.intern(@~"width"), ex: width_expr},
|
||||
{ident: intr.intern(@~"precision"),
|
||||
ex: precision_expr},
|
||||
{ident: intr.intern(@~"ty"), ex: ty_expr}]);
|
||||
mk_global_struct_e(
|
||||
cx,
|
||||
sp,
|
||||
make_path_vec(cx, @~"Conv"),
|
||||
~[
|
||||
{ident: intr.intern(@~"flags"), ex: flags_expr},
|
||||
{ident: intr.intern(@~"width"), ex: width_expr},
|
||||
{ident: intr.intern(@~"precision"), ex: precision_expr},
|
||||
{ident: intr.intern(@~"ty"), ex: ty_expr},
|
||||
]
|
||||
)
|
||||
}
|
||||
let rt_conv_flags = make_flags(cx, sp, cnv.flags);
|
||||
let rt_conv_width = make_count(cx, sp, cnv.width);
|
||||
let rt_conv_precision = make_count(cx, sp, cnv.precision);
|
||||
let rt_conv_ty = make_ty(cx, sp, cnv.ty);
|
||||
return make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width,
|
||||
rt_conv_precision, rt_conv_ty);
|
||||
make_conv_struct(cx, sp, rt_conv_flags, rt_conv_width,
|
||||
rt_conv_precision, rt_conv_ty)
|
||||
}
|
||||
fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: ~str, cnv: Conv,
|
||||
arg: @ast::expr) -> @ast::expr {
|
||||
|
Loading…
Reference in New Issue
Block a user