aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-04-16 18:00:52 -0400
committerBrian Anderson <[email protected]>2011-04-16 18:01:17 -0400
commitdcfdb02fabc3f640dac2873c365acdd9d979008e (patch)
tree45d6d60831b323f87eed216846d1eb4217bb8bf4 /src/comp/front
parentMore tests for #fmt (diff)
downloadrust-dcfdb02fabc3f640dac2873c365acdd9d979008e.tar.xz
rust-dcfdb02fabc3f640dac2873c365acdd9d979008e.zip
Make #fmt support explicit conversion widths
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/extfmt.rs40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/comp/front/extfmt.rs b/src/comp/front/extfmt.rs
index bd5fc433..65917ade 100644
--- a/src/comp/front/extfmt.rs
+++ b/src/comp/front/extfmt.rs
@@ -91,6 +91,11 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
ret make_new_lit(sp, lit);
}
+ fn make_new_int(common.span sp, int i) -> @ast.expr {
+ auto lit = ast.lit_int(i);
+ ret make_new_lit(sp, lit);
+ }
+
fn make_new_uint(common.span sp, uint u) -> @ast.expr {
auto lit = ast.lit_uint(u);
ret make_new_lit(sp, lit);
@@ -145,6 +150,26 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
}
fn make_rt_conv_expr(common.span sp, &conv cnv) -> @ast.expr {
+
+ fn make_count(common.span sp, &count cnt) -> @ast.expr {
+ alt (cnt) {
+ case (count_implied) {
+ auto idents = make_path_vec("count_implied");
+ ret make_path_expr(sp, idents);
+ }
+ case (count_is(?c)) {
+ auto count_lit = make_new_int(sp, c);
+ auto count_is_path = make_path_vec("count_is");
+ auto count_is_args = vec(count_lit);
+ ret make_call(sp, count_is_path, count_is_args);
+ }
+ case (_) {
+ log "not implemented";
+ fail;
+ }
+ }
+ }
+
fn make_ty(common.span sp, &ty t) -> @ast.expr {
auto rt_type;
alt (t) {
@@ -170,12 +195,17 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
ret make_path_expr(sp, idents);
}
- fn make_conv_rec(common.span sp, &@ast.expr ty_expr) -> @ast.expr {
- ret make_rec_expr(sp, vec(tup("ty", ty_expr)));
+ fn make_conv_rec(common.span sp, @ast.expr width_expr,
+ @ast.expr ty_expr) -> @ast.expr {
+ ret make_rec_expr(sp, vec(tup("width", width_expr),
+ tup("ty", ty_expr)));
}
+ auto rt_conv_width = make_count(sp, cnv.width);
auto rt_conv_ty = make_ty(sp, cnv.ty);
- ret make_conv_rec(sp, rt_conv_ty);
+ ret make_conv_rec(sp,
+ rt_conv_width,
+ rt_conv_ty);
}
fn make_conv_call(common.span sp, str conv_type,
@@ -208,6 +238,8 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
alt (cnv.width) {
case (count_implied) {
}
+ case (count_is(_)) {
+ }
case (_) {
log unsupported;
fail;
@@ -225,7 +257,7 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
alt (cnv.ty) {
case (ty_str) {
- ret arg;
+ ret make_conv_call(arg.span, "str", cnv, arg);
}
case (ty_int(?sign)) {
alt (sign) {