diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-08-28 00:24:28 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-31 11:44:06 -0700 |
| commit | 498e38b705348333df9ab02059d07f114baccc45 (patch) | |
| tree | 23a43b5b13b21ed2510d6dc52799e3e6d672b467 /src/comp/syntax | |
| parent | 959938e89144435c3a2fb1752527cfb17dd071a4 (diff) | |
| download | rust-498e38b705348333df9ab02059d07f114baccc45.tar.gz rust-498e38b705348333df9ab02059d07f114baccc45.zip | |
Convert uses of #fmt to #ifmt. Issue #855
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/codemap.rs | 23 | ||||
| -rw-r--r-- | src/comp/syntax/ext/expand.rs | 6 | ||||
| -rw-r--r-- | src/comp/syntax/ext/fmt.rs | 25 | ||||
| -rw-r--r-- | src/comp/syntax/ext/ifmt.rs | 25 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 10 | ||||
| -rw-r--r-- | src/comp/syntax/parse/lexer.rs | 15 | ||||
| -rw-r--r-- | src/comp/syntax/print/pp.rs | 42 | ||||
| -rw-r--r-- | src/comp/syntax/untyped_ast.rs | 2 |
8 files changed, 72 insertions, 76 deletions
diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index 21ba2a98a77..508aa1da700 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -80,13 +80,13 @@ fn span_to_str(sp: &span, cm: &codemap) -> istr { while true { let lo = lookup_char_pos(cm, cur.lo); let hi = lookup_char_pos(cm, cur.hi); - res += istr::from_estr( - #fmt["%s:%u:%u: %u:%u", + res += + #ifmt["%s:%u:%u: %u:%u", if some(lo.filename) == prev_file { - "-" + ~"-" } else { - istr::to_estr(lo.filename) - }, lo.line, lo.col, hi.line, hi.col]); + lo.filename + }, lo.line, lo.col, hi.line, hi.col]; alt cur.expanded_from { os_none. { break; } os_some(new_sp) { @@ -115,10 +115,9 @@ fn emit_diagnostic(sp: &option::t<span>, msg: &istr, kind: &istr, color: u8, if term::color_supported() { term::fg(io::stdout().get_buf_writer(), color); } - io::stdout().write_str(istr::from_estr(#fmt["%s:", istr::to_estr(kind)])); + io::stdout().write_str(#ifmt[~"%s:", kind]); if term::color_supported() { term::reset(io::stdout().get_buf_writer()); } - io::stdout().write_str(istr::from_estr(#fmt[" %s\n", - istr::to_estr(msg)])); + io::stdout().write_str(#ifmt[~" %s\n", msg]); maybe_highlight_lines(sp, cm, maybe_lines); } @@ -148,17 +147,15 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap, // Print the offending lines for line: uint in display_lines { io::stdout().write_str( - istr::from_estr(#fmt["%s:%u ", - istr::to_estr(fm.name), line + 1u])); + #ifmt[~"%s:%u ", fm.name, line + 1u]); let s = get_line(fm, line as int, file); if !istr::ends_with(s, ~"\n") { s += ~"\n"; } io::stdout().write_str(s); } if elided { let last_line = display_lines[vec::len(display_lines) - 1u]; - let s = #fmt["%s:%u ", - istr::to_estr(fm.name), last_line + 1u]; - let indent = str::char_len(s); + let s = #ifmt[~"%s:%u ", fm.name, last_line + 1u]; + let indent = istr::char_len(s); let out = ~""; while indent > 0u { out += ~" "; indent -= 1u; } out += ~"...\n"; diff --git a/src/comp/syntax/ext/expand.rs b/src/comp/syntax/ext/expand.rs index c8bf5cfa495..ce787c2bc6e 100644 --- a/src/comp/syntax/ext/expand.rs +++ b/src/comp/syntax/ext/expand.rs @@ -26,9 +26,9 @@ fn expand_expr(exts: &hashmap<istr, syntax_extension>, cx: &ext_ctxt, let extname = pth.node.idents[0]; alt exts.find(extname) { none. { - cx.span_fatal(pth.span, istr::from_estr( - #fmt["macro undefined: '%s'", - istr::to_estr(extname)])) + cx.span_fatal(pth.span, + #ifmt["macro undefined: '%s'", + extname]) } some(normal(ext)) { let expanded = ext(cx, pth.span, args, body); diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index 30879dc8a0a..59bc277c741 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -1,7 +1,7 @@ /* - * The compiler code necessary to support the #fmt extension. Eventually this + * The compiler code necessary to support the #ifmt extension. Eventually this * should all get sucked into either the standard library extfmt module or the * compiler syntax extension plugin interface. */ @@ -22,15 +22,16 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, alt arg.node { ast::expr_vec(elts, _) { elts } _ { - cx.span_fatal(sp, ~"#fmt requires arguments of the form `[...]`.") + cx.span_fatal( + sp, ~"#ifmt requires arguments of the form `[...]`.") } }; if vec::len::<@ast::expr>(args) == 0u { - cx.span_fatal(sp, ~"#fmt requires a format string"); + cx.span_fatal(sp, ~"#ifmt requires a format string"); } let fmt = expr_to_str(cx, args[0], - ~"first argument to #fmt must be a " + ~"first argument to #ifmt must be a " + ~"string literal."); let fmtspan = args[0].span; log "Format string:"; @@ -151,7 +152,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let count_is_args = [count_lit]; ret make_call(cx, sp, count_is_path, count_is_args); } - _ { cx.span_unimpl(sp, ~"unimplemented #fmt conversion"); } + _ { cx.span_unimpl(sp, ~"unimplemented #ifmt conversion"); } } } fn make_ty(cx: &ext_ctxt, sp: span, t: &ty) -> @ast::expr { @@ -205,7 +206,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], _ { ret false; } } } - let unsupported = ~"conversion not supported in #fmt string"; + let unsupported = ~"conversion not supported in #ifmt string"; alt cnv.param { option::none. { } _ { cx.span_unimpl(sp, unsupported); } @@ -217,14 +218,14 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], if !is_signed_type(cnv) { cx.span_fatal(sp, ~"+ flag only valid in " + - ~"signed #fmt conversion"); + ~"signed #ifmt conversion"); } } flag_space_for_sign. { if !is_signed_type(cnv) { cx.span_fatal(sp, ~"space flag only valid in " + - ~"signed #fmt conversions"); + ~"signed #ifmt conversions"); } } flag_left_zero_pad. { } @@ -330,7 +331,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], n += 1u; if n >= nargs { cx.span_fatal(sp, - ~"not enough arguments to #fmt " + + ~"not enough arguments to #ifmt " + ~"for the given format string"); } log "Building conversion:"; @@ -345,9 +346,9 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], if expected_nargs < nargs { cx.span_fatal( - sp, istr::from_estr( - #fmt["too many arguments to #fmt. found %u, expected %u", - nargs, expected_nargs])); + sp, + #ifmt["too many arguments to #fmt. found %u, expected %u", + nargs, expected_nargs]); } ret tmp_expr; } diff --git a/src/comp/syntax/ext/ifmt.rs b/src/comp/syntax/ext/ifmt.rs index c1bd13ac01e..f96b24676cb 100644 --- a/src/comp/syntax/ext/ifmt.rs +++ b/src/comp/syntax/ext/ifmt.rs @@ -1,7 +1,7 @@ /* - * The compiler code necessary to support the #fmt extension. Eventually this + * The compiler code necessary to support the #ifmt extension. Eventually this * should all get sucked into either the standard library extfmt module or the * compiler syntax extension plugin interface. */ @@ -22,15 +22,16 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, alt arg.node { ast::expr_vec(elts, _) { elts } _ { - cx.span_fatal(sp, ~"#fmt requires arguments of the form `[...]`.") + cx.span_fatal( + sp, ~"#ifmt requires arguments of the form `[...]`.") } }; if vec::len::<@ast::expr>(args) == 0u { - cx.span_fatal(sp, ~"#fmt requires a format string"); + cx.span_fatal(sp, ~"#ifmt requires a format string"); } let fmt = expr_to_str(cx, args[0], - ~"first argument to #fmt must be a " + ~"first argument to #ifmt must be a " + ~"string literal."); let fmtspan = args[0].span; log "Format string:"; @@ -151,7 +152,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let count_is_args = [count_lit]; ret make_call(cx, sp, count_is_path, count_is_args); } - _ { cx.span_unimpl(sp, ~"unimplemented #fmt conversion"); } + _ { cx.span_unimpl(sp, ~"unimplemented #ifmt conversion"); } } } fn make_ty(cx: &ext_ctxt, sp: span, t: &ty) -> @ast::expr { @@ -205,7 +206,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], _ { ret false; } } } - let unsupported = ~"conversion not supported in #fmt string"; + let unsupported = ~"conversion not supported in #ifmt string"; alt cnv.param { option::none. { } _ { cx.span_unimpl(sp, unsupported); } @@ -217,14 +218,14 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], if !is_signed_type(cnv) { cx.span_fatal(sp, ~"+ flag only valid in " + - ~"signed #fmt conversion"); + ~"signed #ifmt conversion"); } } flag_space_for_sign. { if !is_signed_type(cnv) { cx.span_fatal(sp, ~"space flag only valid in " + - ~"signed #fmt conversions"); + ~"signed #ifmt conversions"); } } flag_left_zero_pad. { } @@ -330,7 +331,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], n += 1u; if n >= nargs { cx.span_fatal(sp, - ~"not enough arguments to #fmt " + + ~"not enough arguments to #ifmt " + ~"for the given format string"); } log "Building conversion:"; @@ -345,9 +346,9 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], if expected_nargs < nargs { cx.span_fatal( - sp, istr::from_estr( - #fmt["too many arguments to #fmt. found %u, expected %u", - nargs, expected_nargs])); + sp, + #ifmt["too many arguments to #fmt. found %u, expected %u", + nargs, expected_nargs]); } ret tmp_expr; } diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index ccd792d78f5..2ab61e12244 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -309,13 +309,13 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], let len = vec::len(*ms); if old_len != len { let msg = - #fmt["'%s' occurs %u times, but ", - istr::to_estr(fv), len] + - #fmt["'%s' occurs %u times", - istr::to_estr(old_name), + #ifmt["'%s' occurs %u times, but ", + fv, len] + + #ifmt["'%s' occurs %u times", + old_name, old_len]; cx.span_fatal( - repeat_me.span, istr::from_estr(msg)); + repeat_me.span, msg); } } } diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index 988c46b6b88..fa147faa1cc 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -326,8 +326,7 @@ fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char { rdr.bump(); if !is_hex_digit(n) { rdr.err( - istr::from_estr( - #fmt["illegal numeric character escape: %d", n as int])); + #ifmt["illegal numeric character escape: %d", n as int]); fail; } accum_int *= 16; @@ -471,8 +470,8 @@ fn next_token_inner(rdr: &reader) -> token::token { 'U' { c2 = scan_numeric_escape(rdr, 8u); } c2 { rdr.err( - istr::from_estr(#fmt["unknown character escape: %d", - c2 as int])); + #ifmt["unknown character escape: %d", + c2 as int]); fail; } } @@ -512,8 +511,8 @@ fn next_token_inner(rdr: &reader) -> token::token { } c2 { rdr.err( - istr::from_estr(#fmt["unknown string escape: %d", - c2 as int])); + #ifmt["unknown string escape: %d", + c2 as int]); fail; } } @@ -553,7 +552,7 @@ fn next_token_inner(rdr: &reader) -> token::token { '%' { ret binop(rdr, token::PERCENT); } c { rdr.err( - istr::from_estr(#fmt["unkown start of token: %d", c as int])); + #ifmt["unkown start of token: %d", c as int]); fail; } } @@ -654,7 +653,7 @@ fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt { let curr_line = ~"/*"; let level: int = 1; while level > 0 { - log #fmt["=== block comment level %d", level]; + log #ifmt["=== block comment level %d", level]; if rdr.is_eof() { rdr.err(~"unterminated block comment"); fail; } if rdr.curr() == '\n' { trim_whitespace_prefix_and_push_line(lines, curr_line, col); diff --git a/src/comp/syntax/print/pp.rs b/src/comp/syntax/print/pp.rs index d5d7a7125ff..59460a07e06 100644 --- a/src/comp/syntax/print/pp.rs +++ b/src/comp/syntax/print/pp.rs @@ -67,8 +67,7 @@ tag token { STRING(istr, int); BREAK(break_t); BEGIN(begin_t); END; EOF; } fn tok_str(t: token) -> istr { alt t { STRING(s, len) { - ret istr::from_estr( - #fmt["STR(%s,%d)", istr::to_estr(s), len]); + ret #ifmt[~"STR(%s,%d)", s, len]; } BREAK(_) { ret ~"BREAK"; } BEGIN(_) { ret ~"BEGIN"; } @@ -87,8 +86,7 @@ fn buf_str(toks: &[mutable token], szs: &[mutable int], left: uint, while i != right && L != 0u { L -= 1u; if i != left { s += ~", "; } - s += istr::from_estr( - #fmt["%d=%s", szs[i], istr::to_estr(tok_str(toks[i]))]); + s += #ifmt[~"%d=%s", szs[i], tok_str(toks[i])]; i += 1u; i %= n; } @@ -107,7 +105,7 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer { // fall behind. let n: uint = 3u * linewidth; - log #fmt["mk_printer %u", linewidth]; + log #ifmt[~"mk_printer %u", linewidth]; let token: [mutable token] = vec::init_elt_mut(EOF, n); let size: [mutable int] = vec::init_elt_mut(0, n); let scan_stack: [mutable uint] = vec::init_elt_mut(0u, n); @@ -247,7 +245,7 @@ obj printer(out: io::writer, fn replace_last_token(t: token) { token[right] = t; } fn pretty_print(t: token) { - log #fmt["pp [%u,%u]", left, right]; + log #ifmt[~"pp [%u,%u]", left, right]; alt t { EOF. { if !scan_stack_empty { @@ -263,17 +261,17 @@ obj printer(out: io::writer, left = 0u; right = 0u; } else { self.advance_right(); } - log #fmt["pp BEGIN/buffer [%u,%u]", left, right]; + log #ifmt[~"pp BEGIN/buffer [%u,%u]", left, right]; token[right] = t; size[right] = -right_total; self.scan_push(right); } END. { if scan_stack_empty { - log #fmt["pp END/print [%u,%u]", left, right]; + log #ifmt[~"pp END/print [%u,%u]", left, right]; self.print(t, 0); } else { - log #fmt["pp END/buffer [%u,%u]", left, right]; + log #ifmt[~"pp END/buffer [%u,%u]", left, right]; self.advance_right(); token[right] = t; size[right] = -1; @@ -287,7 +285,7 @@ obj printer(out: io::writer, left = 0u; right = 0u; } else { self.advance_right(); } - log #fmt["pp BREAK/buffer [%u,%u]", left, right]; + log #ifmt[~"pp BREAK/buffer [%u,%u]", left, right]; self.check_stack(0); self.scan_push(right); token[right] = t; @@ -296,10 +294,10 @@ obj printer(out: io::writer, } STRING(s, len) { if scan_stack_empty { - log #fmt["pp STRING/print [%u,%u]", left, right]; + log #ifmt[~"pp STRING/print [%u,%u]", left, right]; self.print(t, len); } else { - log #fmt["pp STRING/buffer [%u,%u]", left, right]; + log #ifmt[~"pp STRING/buffer [%u,%u]", left, right]; self.advance_right(); token[right] = t; size[right] = len; @@ -310,14 +308,14 @@ obj printer(out: io::writer, } } fn check_stream() { - log #fmt["check_stream [%u, %u] with left_total=%d, right_total=%d", + log #ifmt[~"check_stream [%u, %u] with left_total=%d, right_total=%d", left, right, left_total, right_total]; if right_total - left_total > space { - log #fmt["scan window is %d, longer than space on line (%d)", + log #ifmt[~"scan window is %d, longer than space on line (%d)", right_total - left_total, space]; if !scan_stack_empty { if left == scan_stack[bottom] { - log #fmt["setting %u to infinity and popping", left]; + log #ifmt["setting %u to infinity and popping", left]; size[self.scan_pop_bottom()] = size_infinity; } } @@ -326,7 +324,7 @@ obj printer(out: io::writer, } } fn scan_push(x: uint) { - log #fmt["scan_push %u", x]; + log #ifmt["scan_push %u", x]; if scan_stack_empty { scan_stack_empty = false; } else { top += 1u; top %= buf_len; assert (top != bottom); } @@ -355,7 +353,7 @@ obj printer(out: io::writer, assert (right != left); } fn advance_left(x: token, L: int) { - log #fmt["advnce_left [%u,%u], sizeof(%u)=%d", left, right, left, L]; + log #ifmt["advnce_left [%u,%u], sizeof(%u)=%d", left, right, left, L]; if L >= 0 { self.print(x, L); alt x { @@ -394,13 +392,13 @@ obj printer(out: io::writer, } } fn print_newline(amount: int) { - log #fmt["NEWLINE %d", amount]; + log #ifmt["NEWLINE %d", amount]; out.write_str(~"\n"); pending_indentation = 0; self.indent(amount); } fn indent(amount: int) { - log #fmt["INDENT %d", amount]; + log #ifmt["INDENT %d", amount]; pending_indentation += amount; } fn top() -> print_stack_elt { @@ -417,15 +415,15 @@ obj printer(out: io::writer, out.write_str(s); } fn print(x: token, L: int) { - log #fmt["print %s %d (remaining line space=%d)", - istr::to_estr(tok_str(x)), L, + log #ifmt["print %s %d (remaining line space=%d)", + tok_str(x), L, space]; log buf_str(token, size, left, right, 6u); alt x { BEGIN(b) { if L > space { let col = margin - space + b.offset; - log #fmt["print BEGIN -> push broken block at col %d", col]; + log #ifmt["print BEGIN -> push broken block at col %d", col]; print_stack += [{offset: col, pbreak: broken(b.breaks)}]; } else { log "print BEGIN -> push fitting block"; diff --git a/src/comp/syntax/untyped_ast.rs b/src/comp/syntax/untyped_ast.rs index 124a1e947f1..c1db95b2aaf 100644 --- a/src/comp/syntax/untyped_ast.rs +++ b/src/comp/syntax/untyped_ast.rs @@ -362,7 +362,7 @@ fn dummy() { alt *elts.(idx) { leaf_destructure(x) { x } _ { - ctx.ff(sp, #fmt["expected %s in position %u", + ctx.ff(sp, #ifmt["expected %s in position %u", #ident_to_str[leaf_destructure], idx]) } }], |
