1
Fork 0

Convert uses of #fmt to #ifmt. Issue #855

This commit is contained in:
Brian Anderson 2011-08-28 00:24:28 -07:00
parent 959938e891
commit 498e38b705
51 changed files with 345 additions and 380 deletions

View file

@ -341,9 +341,7 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &istr,
fn crate_meta_extras_hash(sha: sha1, _crate: &ast::crate, fn crate_meta_extras_hash(sha: sha1, _crate: &ast::crate,
metas: &provided_metas) -> istr { metas: &provided_metas) -> istr {
fn len_and_str(s: &istr) -> istr { fn len_and_str(s: &istr) -> istr {
ret istr::from_estr(#fmt["%u_%s", ret #ifmt["%u_%s", istr::byte_len(s), s];
istr::byte_len(s),
istr::to_estr(s)]);
} }
fn len_and_str_lit(l: &ast::lit) -> istr { fn len_and_str_lit(l: &ast::lit) -> istr {
@ -374,9 +372,9 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &istr,
fn warn_missing(sess: &session::session, name: &istr, default: &istr) { fn warn_missing(sess: &session::session, name: &istr, default: &istr) {
if !sess.get_opts().library { ret; } if !sess.get_opts().library { ret; }
sess.warn(istr::from_estr( sess.warn(
#fmt["missing crate link meta '%s', using '%s' as default", #ifmt["missing crate link meta '%s', using '%s' as default",
istr::to_estr(name), istr::to_estr(default)])); name, default]);
} }
fn crate_meta_name(sess: &session::session, _crate: &ast::crate, fn crate_meta_name(sess: &session::session, _crate: &ast::crate,
@ -461,9 +459,7 @@ fn mangle(ss: &[istr]) -> istr {
let n = ~"_ZN"; // Begin name-sequence. let n = ~"_ZN"; // Begin name-sequence.
for s: istr in ss { for s: istr in ss {
n += istr::from_estr(#fmt["%u%s", n += #ifmt["%u%s", istr::byte_len(s), s];
istr::byte_len(s),
istr::to_estr(s)]);
} }
n += ~"E"; // End name-sequence. n += ~"E"; // End name-sequence.

View file

@ -122,8 +122,8 @@ fn time<@T>(do_it: bool, what: &istr, thunk: fn() -> T) -> T {
let start = std::time::precise_time_s(); let start = std::time::precise_time_s();
let rv = thunk(); let rv = thunk();
let end = std::time::precise_time_s(); let end = std::time::precise_time_s();
log_err #fmt["time: %s took %s s", istr::to_estr(what), log_err #ifmt["time: %s took %s s", what,
istr::to_estr(common::float_to_str(end - start, 3u))]; common::float_to_str(end - start, 3u)];
ret rv; ret rv;
} }
@ -255,21 +255,21 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg,
} }
fn version(argv0: &istr) { fn version(argv0: &istr) {
let vers = "unknown version"; let vers = ~"unknown version";
// FIXME: Restore after istr conversion // FIXME: Restore after istr conversion
//let env_vers = #env["CFG_VERSION"]; //let env_vers = #env["CFG_VERSION"];
let env_vers = "FIXME"; let env_vers = ~"FIXME";
if str::byte_len(env_vers) != 0u { vers = env_vers; } if istr::byte_len(env_vers) != 0u { vers = env_vers; }
io::stdout().write_str( io::stdout().write_str(
istr::from_estr(#fmt["%s %s\n", #ifmt["%s %s\n",
istr::to_estr(argv0), argv0,
vers])); vers]);
} }
fn usage(argv0: &istr) { fn usage(argv0: &istr) {
io::stdout().write_str(istr::from_estr( io::stdout().write_str(
#fmt["usage: %s [options] <input>\n", istr::to_estr(argv0)] + #ifmt["usage: %s [options] <input>\n", argv0] +
" ~"
options: options:
-h --help display this message -h --help display this message
@ -302,7 +302,7 @@ options:
--test build test harness --test build test harness
--gc garbage collect shared data (experimental/temporary) --gc garbage collect shared data (experimental/temporary)
")); ");
} }
fn get_os(triple: &istr) -> session::os { fn get_os(triple: &istr) -> session::os {
@ -473,7 +473,7 @@ fn main(args: [str]) {
alt getopts::getopts(args, opts()) { alt getopts::getopts(args, opts()) {
getopts::success(m) { m } getopts::success(m) { m }
getopts::failure(f) { getopts::failure(f) {
log_err #fmt["error: %s", istr::to_estr(getopts::fail_str(f))]; log_err #ifmt["error: %s", getopts::fail_str(f)];
fail fail
} }
}; };
@ -637,11 +637,11 @@ fn main(args: [str]) {
let err_code = run::run_program(prog, gcc_args); let err_code = run::run_program(prog, gcc_args);
if 0 != err_code { if 0 != err_code {
sess.err(istr::from_estr( sess.err(
#fmt["linking with gcc failed with code %d", err_code])); #ifmt["linking with gcc failed with code %d", err_code]);
sess.note(istr::from_estr( sess.note(
#fmt["gcc arguments: %s", #ifmt["gcc arguments: %s",
istr::to_estr(istr::connect(gcc_args, ~" "))])); istr::connect(gcc_args, ~" ")]);
sess.abort_if_errors(); sess.abort_if_errors();
} }
// Clean up on Darwin // Clean up on Darwin

View file

@ -95,13 +95,13 @@ obj session(targ_cfg: @config,
} }
fn span_bug(sp: span, msg: &istr) -> ! { fn span_bug(sp: span, msg: &istr) -> ! {
self.span_fatal(sp, self.span_fatal(sp,
istr::from_estr(#fmt["internal compiler error %s", #ifmt["internal compiler error %s",
istr::to_estr(msg)])); msg]);
} }
fn bug(msg: &istr) -> ! { fn bug(msg: &istr) -> ! {
self.fatal(istr::from_estr( self.fatal(
#fmt["internal compiler error %s", #ifmt["internal compiler error %s",
istr::to_estr(msg)])); msg]);
} }
fn span_unimpl(sp: span, msg: &istr) -> ! { fn span_unimpl(sp: span, msg: &istr) -> ! {
self.span_bug(sp, ~"unimplemented " + msg); self.span_bug(sp, ~"unimplemented " + msg);

View file

@ -124,13 +124,11 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
} }
fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool { fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool {
log #fmt["looking for %s", log #ifmt["looking for %s",
istr::to_estr( syntax::print::pprust::meta_item_to_str(*needle)];
syntax::print::pprust::meta_item_to_str(*needle))];
for item: @ast::meta_item in haystack { for item: @ast::meta_item in haystack {
log #fmt["looking in %s", log #ifmt["looking in %s",
istr::to_estr( syntax::print::pprust::meta_item_to_str(*item)];
syntax::print::pprust::meta_item_to_str(*item))];
if eq(item, needle) { log "found it!"; ret true; } if eq(item, needle) { log "found it!"; ret true; }
} }
log "found it not :("; log "found it not :(";
@ -185,9 +183,9 @@ fn require_unique_names(sess: &session::session, metas: &[@ast::meta_item]) {
for meta: @ast::meta_item in metas { for meta: @ast::meta_item in metas {
let name = get_meta_item_name(meta); let name = get_meta_item_name(meta);
if map.contains_key(name) { if map.contains_key(name) {
sess.span_fatal(meta.span, istr::from_estr( sess.span_fatal(meta.span,
#fmt["duplicate meta item `%s`", #ifmt["duplicate meta item `%s`",
istr::to_estr(name)])); name]);
} }
map.insert(name, ()); map.insert(name, ());
} }

View file

@ -92,14 +92,14 @@ fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) ->
@ast::item { @ast::item {
cx.path += [i.ident]; cx.path += [i.ident];
log #fmt["current path: %s", log #ifmt["current path: %s",
istr::to_estr(ast_util::path_name_i(cx.path))]; ast_util::path_name_i(cx.path)];
if is_test_fn(i) { if is_test_fn(i) {
log "this is a test function"; log "this is a test function";
let test = {path: cx.path, ignore: is_ignored(i)}; let test = {path: cx.path, ignore: is_ignored(i)};
cx.testfns += [test]; cx.testfns += [test];
log #fmt["have %u test functions", vec::len(cx.testfns)]; log #ifmt["have %u test functions", vec::len(cx.testfns)];
} }
let res = fold::noop_fold_item(i, fld); let res = fold::noop_fold_item(i, fld);
@ -168,8 +168,8 @@ fn mk_test_module(cx: &test_ctxt) -> @ast::item {
node: item_, node: item_,
span: dummy_sp()}; span: dummy_sp()};
log #fmt["Synthetic test module:\n%s\n", log #ifmt["Synthetic test module:\n%s\n",
istr::to_estr(pprust::item_to_str(@item))]; pprust::item_to_str(@item)];
ret @item; ret @item;
} }
@ -234,7 +234,7 @@ fn mk_test_desc_vec_ty(cx: &test_ctxt) -> @ast::ty {
} }
fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr { fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr {
log #fmt["building test vector from %u tests", vec::len(cx.testfns)]; log #ifmt["building test vector from %u tests", vec::len(cx.testfns)];
let descs = []; let descs = [];
for test: test in cx.testfns { for test: test in cx.testfns {
let test_ = test; // Satisfy alias analysis let test_ = test; // Satisfy alias analysis
@ -249,8 +249,8 @@ fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr {
fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr { fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
let path = test.path; let path = test.path;
log #fmt["encoding %s", log #ifmt["encoding %s",
istr::to_estr(ast_util::path_name_i(path))]; ast_util::path_name_i(path)];
let name_lit: ast::lit = let name_lit: ast::lit =
nospan(ast::lit_str(ast_util::path_name_i(path), ast::sk_rc)); nospan(ast::lit_str(ast_util::path_name_i(path), ast::sk_rc));

View file

@ -1040,7 +1040,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
} }
13 { ret ~"Vector"; } 13 { ret ~"Vector"; }
14 { ret ~"Metadata"; } 14 { ret ~"Metadata"; }
_ { log_err #fmt["unknown TypeKind %d", kind as int]; fail; } _ { log_err #ifmt["unknown TypeKind %d", kind as int]; fail; }
} }
} }

View file

@ -100,13 +100,13 @@ fn metadata_matches(crate_data: &@[u8], metas: &[@ast::meta_item]) -> bool {
let attrs = decoder::get_crate_attributes(crate_data); let attrs = decoder::get_crate_attributes(crate_data);
let linkage_metas = attr::find_linkage_metas(attrs); let linkage_metas = attr::find_linkage_metas(attrs);
log #fmt["matching %u metadata requirements against %u items", log #ifmt["matching %u metadata requirements against %u items",
vec::len(metas), vec::len(linkage_metas)]; vec::len(metas), vec::len(linkage_metas)];
for needed: @ast::meta_item in metas { for needed: @ast::meta_item in metas {
if !attr::contains(linkage_metas, needed) { if !attr::contains(linkage_metas, needed) {
log #fmt["missing %s", log #ifmt["missing %s",
istr::to_estr(pprust::meta_item_to_str(*needed))]; pprust::meta_item_to_str(*needed)];
ret false; ret false;
} }
} }
@ -170,27 +170,27 @@ fn find_library_crate_aux(nn: &{prefix: istr, suffix: istr},
// manually filtering fs::list_dir here. // manually filtering fs::list_dir here.
for library_search_path: istr in library_search_paths { for library_search_path: istr in library_search_paths {
log #fmt["searching %s", istr::to_estr(library_search_path)]; log #ifmt["searching %s", library_search_path];
for path: istr in fs::list_dir(library_search_path) { for path: istr in fs::list_dir(library_search_path) {
log #fmt["searching %s", istr::to_estr(path)]; log #ifmt["searching %s", path];
let f: istr = fs::basename(path); let f: istr = fs::basename(path);
if !(istr::starts_with(f, prefix) && istr::ends_with(f, suffix)) if !(istr::starts_with(f, prefix) && istr::ends_with(f, suffix))
{ {
log #fmt["skipping %s, doesn't look like %s*%s", log #ifmt["skipping %s, doesn't look like %s*%s",
istr::to_estr(path), path,
istr::to_estr(prefix), prefix,
istr::to_estr(suffix)]; suffix];
cont; cont;
} }
alt get_metadata_section(path) { alt get_metadata_section(path) {
option::some(cvec) { option::some(cvec) {
if !metadata_matches(cvec, metas) { if !metadata_matches(cvec, metas) {
log #fmt["skipping %s, metadata doesn't match", log #ifmt["skipping %s, metadata doesn't match",
istr::to_estr(path)]; path];
cont; cont;
} }
log #fmt["found %s with matching metadata", log #ifmt["found %s with matching metadata",
istr::to_estr(path)]; path];
ret some({ident: path, data: cvec}); ret some({ident: path, data: cvec});
} }
_ { } _ { }
@ -230,9 +230,9 @@ fn load_library_crate(sess: &session::session, span: span, ident: &ast::ident,
alt find_library_crate(sess, ident, metas, library_search_paths) { alt find_library_crate(sess, ident, metas, library_search_paths) {
some(t) { ret t; } some(t) { ret t; }
none. { none. {
sess.span_fatal(span, istr::from_estr( sess.span_fatal(span,
#fmt["can't find crate for '%s'", #ifmt["can't find crate for '%s'",
istr::to_estr(ident)])); ident]);
} }
} }
} }
@ -275,7 +275,7 @@ fn resolve_crate_deps(e: env, cdata: &@[u8]) -> cstore::cnum_map {
for dep: decoder::crate_dep in decoder::get_crate_deps(cdata) { for dep: decoder::crate_dep in decoder::get_crate_deps(cdata) {
let extrn_cnum = dep.cnum; let extrn_cnum = dep.cnum;
let cname = dep.ident; let cname = dep.ident;
log #fmt["resolving dep %s", istr::to_estr(cname)]; log #ifmt["resolving dep %s", cname];
if e.crate_cache.contains_key(cname) { if e.crate_cache.contains_key(cname) {
log "already have it"; log "already have it";
// We've already seen this crate // We've already seen this crate

View file

@ -349,9 +349,8 @@ fn get_attributes(md: &ebml::doc) -> [ast::attribute] {
fn list_meta_items(meta_items: &ebml::doc, out: io::writer) { fn list_meta_items(meta_items: &ebml::doc, out: io::writer) {
for mi: @ast::meta_item in get_meta_items(meta_items) { for mi: @ast::meta_item in get_meta_items(meta_items) {
out.write_str( out.write_str(
istr::from_estr( #ifmt["%s\n",
#fmt["%s\n", pprust::meta_item_to_str(*mi)]);
istr::to_estr(pprust::meta_item_to_str(*mi))]));
} }
} }
@ -360,9 +359,8 @@ fn list_crate_attributes(md: &ebml::doc, out: io::writer) {
for attr: ast::attribute in get_attributes(md) { for attr: ast::attribute in get_attributes(md) {
out.write_str( out.write_str(
istr::from_estr( #ifmt["%s\n",
#fmt["%s\n", pprust::attribute_to_str(attr)]);
istr::to_estr(pprust::attribute_to_str(attr))]));
} }
out.write_str(~"\n\n"); out.write_str(~"\n\n");
@ -392,8 +390,8 @@ fn list_crate_deps(data: @[u8], out: io::writer) {
for dep: crate_dep in get_crate_deps(data) { for dep: crate_dep in get_crate_deps(data) {
out.write_str( out.write_str(
istr::from_estr(#fmt["%d %s\n", dep.cnum, #ifmt["%d %s\n", dep.cnum,
istr::to_estr(dep.ident)])); dep.ident]);
} }
out.write_str(~"\n"); out.write_str(~"\n");
@ -414,10 +412,9 @@ fn list_crate_items(bytes: &@[u8], md: &ebml::doc, out: io::writer) {
let did_doc = ebml::get_doc(def, tag_def_id); let did_doc = ebml::get_doc(def, tag_def_id);
let did = parse_def_id(ebml::doc_data(did_doc)); let did = parse_def_id(ebml::doc_data(did_doc));
out.write_str( out.write_str(
istr::from_estr( #ifmt["%s (%s)\n",
#fmt["%s (%s)\n", data.path,
istr::to_estr(data.path), describe_def(items, did)]);
istr::to_estr(describe_def(items, did))]));
} }
} }
out.write_str(~"\n"); out.write_str(~"\n");

View file

@ -178,7 +178,7 @@ fn encode_inlineness(ebml_w: &ebml::writer, c: u8) {
} }
fn def_to_str(did: &def_id) -> istr { fn def_to_str(did: &def_id) -> istr {
ret istr::from_estr(#fmt["%d:%d", did.crate, did.node]); ret #ifmt["%d:%d", did.crate, did.node];
} }
fn encode_type_param_kinds(ebml_w: &ebml::writer, tps: &[ty_param]) { fn encode_type_param_kinds(ebml_w: &ebml::writer, tps: &[ty_param]) {

View file

@ -257,10 +257,10 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope) ->
alt f.node { alt f.node {
ast::expr_path(_) { ast::expr_path(_) {
if def_is_local(cx.tcx.def_map.get(f.id), true) { if def_is_local(cx.tcx.def_map.get(f.id), true) {
cx.tcx.sess.span_err(f.span, istr::from_estr( cx.tcx.sess.span_err(f.span,
#fmt["function may alias with \ #ifmt["function may alias with \
argument %u, which is not immutably rooted", argument %u, which is not immutably rooted",
unsafe_t_offsets[0]])); unsafe_t_offsets[0]]);
} }
} }
_ { } _ { }
@ -275,10 +275,10 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope) ->
let mut_alias = arg_t.mode == ty::mo_alias(true); let mut_alias = arg_t.mode == ty::mo_alias(true);
if i != offset && if i != offset &&
ty_can_unsafely_include(cx, unsafe, arg_t.ty, mut_alias) { ty_can_unsafely_include(cx, unsafe, arg_t.ty, mut_alias) {
cx.tcx.sess.span_err(args[i].span, istr::from_estr( cx.tcx.sess.span_err(args[i].span,
#fmt["argument %u may alias with \ #ifmt["argument %u may alias with \
argument %u, which is not immutably rooted", argument %u, which is not immutably rooted",
i, offset])); i, offset]);
} }
i += 1u; i += 1u;
} }

View file

@ -96,11 +96,11 @@ fn lower_kind(a: kind, b: kind) -> kind {
if kind_lteq(a, b) { a } else { b } if kind_lteq(a, b) { a } else { b }
} }
fn kind_to_str(k: kind) -> str { fn kind_to_str(k: kind) -> istr {
alt k { alt k {
ast::kind_pinned. { "pinned" } ast::kind_pinned. { ~"pinned" }
ast::kind_unique. { "unique" } ast::kind_unique. { ~"unique" }
ast::kind_shared. { "shared" } ast::kind_shared. { ~"shared" }
} }
} }
@ -114,17 +114,17 @@ fn type_and_kind(tcx: &ty::ctxt, e: &@ast::expr) ->
fn need_expr_kind(tcx: &ty::ctxt, e: &@ast::expr, k_need: ast::kind, fn need_expr_kind(tcx: &ty::ctxt, e: &@ast::expr, k_need: ast::kind,
descr: &istr) { descr: &istr) {
let tk = type_and_kind(tcx, e); let tk = type_and_kind(tcx, e);
log #fmt["for %s: want %s type, got %s type %s", istr::to_estr(descr), log #ifmt["for %s: want %s type, got %s type %s", descr,
kind_to_str(k_need), kind_to_str(tk.kind), kind_to_str(k_need), kind_to_str(tk.kind),
istr::to_estr(util::ppaux::ty_to_str(tcx, tk.ty))]; util::ppaux::ty_to_str(tcx, tk.ty)];
if !kind_lteq(k_need, tk.kind) { if !kind_lteq(k_need, tk.kind) {
let s = let s =
#fmt["mismatched kinds for %s: needed %s type, got %s type %s", #ifmt["mismatched kinds for %s: needed %s type, got %s type %s",
istr::to_estr(descr), kind_to_str(k_need), descr, kind_to_str(k_need),
kind_to_str(tk.kind), kind_to_str(tk.kind),
istr::to_estr(util::ppaux::ty_to_str(tcx, tk.ty))]; util::ppaux::ty_to_str(tcx, tk.ty)];
tcx.sess.span_err(e.span, istr::from_estr(s)); tcx.sess.span_err(e.span, s);
} }
} }
@ -169,11 +169,11 @@ fn check_expr(tcx: &ty::ctxt, e: &@ast::expr) {
let k = ty::type_kind(tcx, t); let k = ty::type_kind(tcx, t);
if !kind_lteq(k_need, k) { if !kind_lteq(k_need, k) {
let s = let s =
#fmt["mismatched kinds for typaram %d: \ #ifmt["mismatched kinds for typaram %d: \
needed %s type, got %s type %s", needed %s type, got %s type %s",
i, kind_to_str(k_need), kind_to_str(k), i, kind_to_str(k_need), kind_to_str(k),
istr::to_estr(util::ppaux::ty_to_str(tcx, t))]; util::ppaux::ty_to_str(tcx, t)];
tcx.sess.span_err(e.span, istr::from_estr(s)); tcx.sess.span_err(e.span, s);
} }
i += 1; i += 1;
} }

View file

@ -575,8 +575,7 @@ fn unresolved_fatal(e: &env, sp: &span, id: &ident, kind: &istr) -> ! {
} }
fn mk_unresolved_msg(id: &ident, kind: &istr) -> istr { fn mk_unresolved_msg(id: &ident, kind: &istr) -> istr {
ret istr::from_estr( ret #ifmt["unresolved %s: %s", kind, id];
#fmt["unresolved %s: %s", istr::to_estr(kind), istr::to_estr(id)]);
} }
// Lookup helpers // Lookup helpers
@ -1011,8 +1010,7 @@ fn lookup_glob_in_mod(e: &env, info: @indexed_mod, sp: &span, id: &ident,
for match: glob_imp_def in matches { for match: glob_imp_def in matches {
let sp = match.item.span; let sp = match.item.span;
e.sess.span_note( e.sess.span_note(
sp, istr::from_estr(#fmt["'%s' is imported here", sp, #ifmt["'%s' is imported here", id]);
istr::to_estr(id)]));
} }
e.sess.span_fatal(sp, e.sess.span_fatal(sp,
~"'" + id ~"'" + id

View file

@ -1893,8 +1893,8 @@ fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int,
alt { ti.take_glue } { alt { ti.take_glue } {
some(_) { } some(_) { }
none. { none. {
log #fmt["+++ lazily_emit_tydesc_glue TAKE %s", log #ifmt["+++ lazily_emit_tydesc_glue TAKE %s",
istr::to_estr(ty_to_str(bcx_tcx(cx), ti.ty))]; ty_to_str(bcx_tcx(cx), ti.ty)];
let lcx = cx.fcx.lcx; let lcx = cx.fcx.lcx;
let glue_fn = let glue_fn =
declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx), declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx),
@ -1903,16 +1903,16 @@ fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int,
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn, make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
default_helper(make_take_glue), default_helper(make_take_glue),
ti.ty_params, ~"take"); ti.ty_params, ~"take");
log #fmt["--- lazily_emit_tydesc_glue TAKE %s", log #ifmt["--- lazily_emit_tydesc_glue TAKE %s",
istr::to_estr(ty_to_str(bcx_tcx(cx), ti.ty))]; ty_to_str(bcx_tcx(cx), ti.ty)];
} }
} }
} else if field == abi::tydesc_field_drop_glue { } else if field == abi::tydesc_field_drop_glue {
alt { ti.drop_glue } { alt { ti.drop_glue } {
some(_) { } some(_) { }
none. { none. {
log #fmt["+++ lazily_emit_tydesc_glue DROP %s", log #ifmt["+++ lazily_emit_tydesc_glue DROP %s",
istr::to_estr(ty_to_str(bcx_tcx(cx), ti.ty))]; ty_to_str(bcx_tcx(cx), ti.ty)];
let lcx = cx.fcx.lcx; let lcx = cx.fcx.lcx;
let glue_fn = let glue_fn =
declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx), declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx),
@ -1921,16 +1921,16 @@ fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int,
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn, make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
default_helper(make_drop_glue), default_helper(make_drop_glue),
ti.ty_params, ~"drop"); ti.ty_params, ~"drop");
log #fmt["--- lazily_emit_tydesc_glue DROP %s", log #ifmt["--- lazily_emit_tydesc_glue DROP %s",
istr::to_estr(ty_to_str(bcx_tcx(cx), ti.ty))]; ty_to_str(bcx_tcx(cx), ti.ty)];
} }
} }
} else if field == abi::tydesc_field_free_glue { } else if field == abi::tydesc_field_free_glue {
alt { ti.free_glue } { alt { ti.free_glue } {
some(_) { } some(_) { }
none. { none. {
log #fmt["+++ lazily_emit_tydesc_glue FREE %s", log #ifmt["+++ lazily_emit_tydesc_glue FREE %s",
istr::to_estr(ty_to_str(bcx_tcx(cx), ti.ty))]; ty_to_str(bcx_tcx(cx), ti.ty)];
let lcx = cx.fcx.lcx; let lcx = cx.fcx.lcx;
let glue_fn = let glue_fn =
declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx), declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx),
@ -1939,19 +1939,19 @@ fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int,
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn, make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
default_helper(make_free_glue), default_helper(make_free_glue),
ti.ty_params, ~"free"); ti.ty_params, ~"free");
log #fmt["--- lazily_emit_tydesc_glue FREE %s", log #ifmt["--- lazily_emit_tydesc_glue FREE %s",
istr::to_estr(ty_to_str(bcx_tcx(cx), ti.ty))]; ty_to_str(bcx_tcx(cx), ti.ty)];
} }
} }
} else if field == abi::tydesc_field_cmp_glue { } else if field == abi::tydesc_field_cmp_glue {
alt { ti.cmp_glue } { alt { ti.cmp_glue } {
some(_) { } some(_) { }
none. { none. {
log #fmt["+++ lazily_emit_tydesc_glue CMP %s", log #ifmt["+++ lazily_emit_tydesc_glue CMP %s",
istr::to_estr(ty_to_str(bcx_tcx(cx), ti.ty))]; ty_to_str(bcx_tcx(cx), ti.ty)];
ti.cmp_glue = some(bcx_ccx(cx).upcalls.cmp_type); ti.cmp_glue = some(bcx_ccx(cx).upcalls.cmp_type);
log #fmt["--- lazily_emit_tydesc_glue CMP %s", log #ifmt["--- lazily_emit_tydesc_glue CMP %s",
istr::to_estr(ty_to_str(bcx_tcx(cx), ti.ty))]; ty_to_str(bcx_tcx(cx), ti.ty)];
} }
} }
} else if field == abi::tydesc_field_copy_glue { } else if field == abi::tydesc_field_copy_glue {
@ -6323,16 +6323,16 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
write_metadata(cx.ccx, crate); write_metadata(cx.ccx, crate);
if ccx.sess.get_opts().stats { if ccx.sess.get_opts().stats {
log_err "--- trans stats ---"; log_err "--- trans stats ---";
log_err #fmt["n_static_tydescs: %u", ccx.stats.n_static_tydescs]; log_err #ifmt["n_static_tydescs: %u", ccx.stats.n_static_tydescs];
log_err #fmt["n_derived_tydescs: %u", ccx.stats.n_derived_tydescs]; log_err #ifmt["n_derived_tydescs: %u", ccx.stats.n_derived_tydescs];
log_err #fmt["n_glues_created: %u", ccx.stats.n_glues_created]; log_err #ifmt["n_glues_created: %u", ccx.stats.n_glues_created];
log_err #fmt["n_null_glues: %u", ccx.stats.n_null_glues]; log_err #ifmt["n_null_glues: %u", ccx.stats.n_null_glues];
log_err #fmt["n_real_glues: %u", ccx.stats.n_real_glues]; log_err #ifmt["n_real_glues: %u", ccx.stats.n_real_glues];
for timing: {ident: istr, time: int} in *ccx.stats.fn_times { for timing: {ident: istr, time: int} in *ccx.stats.fn_times {
log_err #fmt["time: %s took %d ms", log_err #ifmt["time: %s took %d ms",
istr::to_estr(timing.ident), timing.time]; timing.ident, timing.time];
} }
} }
ret llmod; ret llmod;

View file

@ -170,10 +170,10 @@ fn find_pre_post_state_call(fcx: &fn_ctxt, pres: &prestate, a: &@expr,
let changed = find_pre_post_state_expr(fcx, pres, a); let changed = find_pre_post_state_expr(fcx, pres, a);
// FIXME: This could be a typestate constraint // FIXME: This could be a typestate constraint
if vec::len(bs) != vec::len(ops) { if vec::len(bs) != vec::len(ops) {
fcx.ccx.tcx.sess.span_bug(a.span, istr::from_estr( fcx.ccx.tcx.sess.span_bug(a.span,
#fmt["mismatched arg lengths: \ #ifmt["mismatched arg lengths: \
%u exprs vs. %u ops", %u exprs vs. %u ops",
vec::len(bs), vec::len(ops)])); vec::len(bs), vec::len(ops)]);
} }
ret find_pre_post_state_exprs(fcx, expr_poststate(fcx.ccx, a), id, ops, ret find_pre_post_state_exprs(fcx, expr_poststate(fcx.ccx, a), id, ops,
bs, cf) || changed; bs, cf) || changed;

View file

@ -2440,20 +2440,20 @@ mod unify {
fn dump_var_bindings(tcx: ty_ctxt, vb: @var_bindings) { fn dump_var_bindings(tcx: ty_ctxt, vb: @var_bindings) {
let i = 0u; let i = 0u;
while i < vec::len::<ufind::node>(vb.sets.nodes) { while i < vec::len::<ufind::node>(vb.sets.nodes) {
let sets = ""; let sets = ~"";
let j = 0u; let j = 0u;
while j < vec::len::<option::t<uint>>(vb.sets.nodes) { while j < vec::len::<option::t<uint>>(vb.sets.nodes) {
if ufind::find(vb.sets, j) == i { sets += #fmt[" %u", j]; } if ufind::find(vb.sets, j) == i { sets += #ifmt[" %u", j]; }
j += 1u; j += 1u;
} }
let typespec; let typespec;
alt smallintmap::find::<t>(vb.types, i) { alt smallintmap::find::<t>(vb.types, i) {
none. { typespec = ""; } none. { typespec = ~""; }
some(typ) { some(typ) {
typespec = " =" + istr::to_estr(ty_to_str(tcx, typ)); typespec = ~" =" + ty_to_str(tcx, typ);
} }
} }
log_err #fmt["set %u:%s%s", i, typespec, sets]; log_err #ifmt["set %u:%s%s", i, typespec, sets];
i += 1u; i += 1u;
} }
} }

View file

@ -1368,16 +1368,16 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat,
let arg_len = vec::len::<ty::t>(arg_types); let arg_len = vec::len::<ty::t>(arg_types);
if arg_len != subpats_len { if arg_len != subpats_len {
// TODO: note definition of tag variant // TODO: note definition of tag variant
// TODO (issue #448): Wrap a #fmt string over multiple // TODO (issue #448): Wrap a #ifmt string over multiple
// lines... // lines...
let s = let s =
#fmt["this pattern has %u field%s, but the \ #ifmt["this pattern has %u field%s, but the \
corresponding variant has %u field%s", corresponding variant has %u field%s",
subpats_len, subpats_len,
if subpats_len == 1u { "" } else { "s" }, if subpats_len == 1u { ~"" } else { ~"s" },
arg_len, if arg_len == 1u { "" } else { "s" }]; arg_len, if arg_len == 1u { ~"" } else { ~"s" }];
fcx.ccx.tcx.sess.span_fatal( fcx.ccx.tcx.sess.span_fatal(
pat.span, istr::from_estr(s)); pat.span, s);
} }
// TODO: vec::iter2 // TODO: vec::iter2
@ -1390,14 +1390,14 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat,
} else if subpats_len > 0u { } else if subpats_len > 0u {
// TODO: note definition of tag variant // TODO: note definition of tag variant
fcx.ccx.tcx.sess.span_fatal( fcx.ccx.tcx.sess.span_fatal(
pat.span, istr::from_estr( pat.span,
#fmt["this pattern has %u field%s, \ #ifmt["this pattern has %u field%s, \
but the corresponding \ but the corresponding \
variant has no fields", variant has no fields",
subpats_len, subpats_len,
if subpats_len == 1u { if subpats_len == 1u {
"" ~""
} else { "s" }])); } else { ~"s" }]);
} }
write::ty_fixup(fcx, pat.id, path_tpot); write::ty_fixup(fcx, pat.id, path_tpot);
} }
@ -1405,9 +1405,9 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat,
// FIXME: Switch expected and actual in this message? I // FIXME: Switch expected and actual in this message? I
// can never tell. // can never tell.
fcx.ccx.tcx.sess.span_fatal( fcx.ccx.tcx.sess.span_fatal(
pat.span, istr::from_estr( pat.span,
#fmt["mismatched types: expected %s, found tag", #ifmt["mismatched types: expected %s, found tag",
istr::to_estr(ty_to_str(fcx.ccx.tcx, expected))])); ty_to_str(fcx.ccx.tcx, expected)]);
} }
} }
write::ty_fixup(fcx, pat.id, path_tpot); write::ty_fixup(fcx, pat.id, path_tpot);
@ -1418,20 +1418,20 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat,
ty::ty_rec(fields) { ex_fields = fields; } ty::ty_rec(fields) { ex_fields = fields; }
_ { _ {
fcx.ccx.tcx.sess.span_fatal( fcx.ccx.tcx.sess.span_fatal(
pat.span, istr::from_estr( pat.span,
#fmt["mismatched types: expected %s, found record", #ifmt["mismatched types: expected %s, found record",
istr::to_estr(ty_to_str(fcx.ccx.tcx, expected))])); ty_to_str(fcx.ccx.tcx, expected)]);
} }
} }
let f_count = vec::len(fields); let f_count = vec::len(fields);
let ex_f_count = vec::len(ex_fields); let ex_f_count = vec::len(ex_fields);
if ex_f_count < f_count || !etc && ex_f_count > f_count { if ex_f_count < f_count || !etc && ex_f_count > f_count {
fcx.ccx.tcx.sess.span_fatal( fcx.ccx.tcx.sess.span_fatal(
pat.span, istr::from_estr( pat.span,
#fmt["mismatched types: expected a record \ #ifmt["mismatched types: expected a record \
with %u fields, found one with %u \ with %u fields, found one with %u \
fields", fields",
ex_f_count, f_count])); ex_f_count, f_count]);
} }
fn matches(name: &istr, f: &ty::field) -> bool { fn matches(name: &istr, f: &ty::field) -> bool {
ret istr::eq(name, f.ident); ret istr::eq(name, f.ident);
@ -1440,10 +1440,10 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat,
alt vec::find(bind matches(f.ident, _), ex_fields) { alt vec::find(bind matches(f.ident, _), ex_fields) {
some(field) { check_pat(fcx, map, f.pat, field.mt.ty); } some(field) { check_pat(fcx, map, f.pat, field.mt.ty); }
none. { none. {
fcx.ccx.tcx.sess.span_fatal(pat.span, istr::from_estr( fcx.ccx.tcx.sess.span_fatal(pat.span,
#fmt["mismatched types: did not \ #ifmt["mismatched types: did not \
expect a record with a field %s", expect a record with a field %s",
istr::to_estr(f.ident)])); f.ident]);
} }
} }
} }
@ -1455,19 +1455,19 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat,
ty::ty_tup(elts) { ex_elts = elts; } ty::ty_tup(elts) { ex_elts = elts; }
_ { _ {
fcx.ccx.tcx.sess.span_fatal( fcx.ccx.tcx.sess.span_fatal(
pat.span, istr::from_estr( pat.span,
#fmt["mismatched types: expected %s, found tuple", #ifmt["mismatched types: expected %s, found tuple",
istr::to_estr(ty_to_str(fcx.ccx.tcx, expected))])); ty_to_str(fcx.ccx.tcx, expected)]);
} }
} }
let e_count = vec::len(elts); let e_count = vec::len(elts);
if e_count != vec::len(ex_elts) { if e_count != vec::len(ex_elts) {
fcx.ccx.tcx.sess.span_fatal( fcx.ccx.tcx.sess.span_fatal(
pat.span, istr::from_estr( pat.span,
#fmt["mismatched types: expected a tuple \ #ifmt["mismatched types: expected a tuple \
with %u fields, found one with %u \ with %u fields, found one with %u \
fields", fields",
vec::len(ex_elts), e_count])); vec::len(ex_elts), e_count]);
} }
let i = 0u; let i = 0u;
for elt in elts { check_pat(fcx, map, elt, ex_elts[i]); i += 1u; } for elt in elts { check_pat(fcx, map, elt, ex_elts[i]); i += 1u; }
@ -1595,16 +1595,17 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
let expected_arg_count = vec::len(arg_tys); let expected_arg_count = vec::len(arg_tys);
let supplied_arg_count = vec::len(args); let supplied_arg_count = vec::len(args);
if expected_arg_count != supplied_arg_count { if expected_arg_count != supplied_arg_count {
fcx.ccx.tcx.sess.span_err(sp, istr::from_estr( fcx.ccx.tcx.sess.span_err(
#fmt["this function takes %u \ sp,
#ifmt["this function takes %u \
parameter%s but %u parameter%s supplied", parameter%s but %u parameter%s supplied",
expected_arg_count, expected_arg_count,
if expected_arg_count == 1u { if expected_arg_count == 1u {
"" ~""
} else { "s" }, supplied_arg_count, } else { ~"s" }, supplied_arg_count,
if supplied_arg_count == 1u { if supplied_arg_count == 1u {
" was" ~" was"
} else { "s were" }])); } else { ~"s were" }]);
// HACK: extend the arguments list with dummy arguments to // HACK: extend the arguments list with dummy arguments to
// check against // check against
let dummy = {mode: ty::mo_val, ty: ty::mk_nil(fcx.ccx.tcx)}; let dummy = {mode: ty::mo_val, ty: ty::mk_nil(fcx.ccx.tcx)};
@ -1819,10 +1820,10 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
if !type_is_integral(fcx, oper.span, oper_t) && if !type_is_integral(fcx, oper.span, oper_t) &&
structure_of(fcx, oper.span, oper_t) != ty::ty_bool { structure_of(fcx, oper.span, oper_t) != ty::ty_bool {
tcx.sess.span_err( tcx.sess.span_err(
expr.span, istr::from_estr( expr.span,
#fmt["mismatched types: expected bool \ #ifmt["mismatched types: expected bool \
or integer but found %s", or integer but found %s",
istr::to_estr(ty_to_str(tcx, oper_t))])); ty_to_str(tcx, oper_t)]);
} }
} }
ast::neg. { ast::neg. {
@ -2266,9 +2267,9 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
_ { _ {
let t_err = resolve_type_vars_if_possible(fcx, base_t); let t_err = resolve_type_vars_if_possible(fcx, base_t);
let msg = let msg =
#fmt["attempted field access on type %s", #ifmt["attempted field access on type %s",
istr::to_estr(ty_to_str(tcx, t_err))]; ty_to_str(tcx, t_err)];
tcx.sess.span_fatal(expr.span, istr::from_estr(msg)); tcx.sess.span_fatal(expr.span, msg);
} }
} }
} }

View file

@ -80,13 +80,13 @@ fn span_to_str(sp: &span, cm: &codemap) -> istr {
while true { while true {
let lo = lookup_char_pos(cm, cur.lo); let lo = lookup_char_pos(cm, cur.lo);
let hi = lookup_char_pos(cm, cur.hi); let hi = lookup_char_pos(cm, cur.hi);
res += istr::from_estr( res +=
#fmt["%s:%u:%u: %u:%u", #ifmt["%s:%u:%u: %u:%u",
if some(lo.filename) == prev_file { if some(lo.filename) == prev_file {
"-" ~"-"
} else { } else {
istr::to_estr(lo.filename) lo.filename
}, lo.line, lo.col, hi.line, hi.col]); }, lo.line, lo.col, hi.line, hi.col];
alt cur.expanded_from { alt cur.expanded_from {
os_none. { break; } os_none. { break; }
os_some(new_sp) { 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() { if term::color_supported() {
term::fg(io::stdout().get_buf_writer(), color); 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()); } if term::color_supported() { term::reset(io::stdout().get_buf_writer()); }
io::stdout().write_str(istr::from_estr(#fmt[" %s\n", io::stdout().write_str(#ifmt[~" %s\n", msg]);
istr::to_estr(msg)]));
maybe_highlight_lines(sp, cm, maybe_lines); 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 // Print the offending lines
for line: uint in display_lines { for line: uint in display_lines {
io::stdout().write_str( io::stdout().write_str(
istr::from_estr(#fmt["%s:%u ", #ifmt[~"%s:%u ", fm.name, line + 1u]);
istr::to_estr(fm.name), line + 1u]));
let s = get_line(fm, line as int, file); let s = get_line(fm, line as int, file);
if !istr::ends_with(s, ~"\n") { s += ~"\n"; } if !istr::ends_with(s, ~"\n") { s += ~"\n"; }
io::stdout().write_str(s); io::stdout().write_str(s);
} }
if elided { if elided {
let last_line = display_lines[vec::len(display_lines) - 1u]; let last_line = display_lines[vec::len(display_lines) - 1u];
let s = #fmt["%s:%u ", let s = #ifmt[~"%s:%u ", fm.name, last_line + 1u];
istr::to_estr(fm.name), last_line + 1u]; let indent = istr::char_len(s);
let indent = str::char_len(s);
let out = ~""; let out = ~"";
while indent > 0u { out += ~" "; indent -= 1u; } while indent > 0u { out += ~" "; indent -= 1u; }
out += ~"...\n"; out += ~"...\n";

View file

@ -26,9 +26,9 @@ fn expand_expr(exts: &hashmap<istr, syntax_extension>, cx: &ext_ctxt,
let extname = pth.node.idents[0]; let extname = pth.node.idents[0];
alt exts.find(extname) { alt exts.find(extname) {
none. { none. {
cx.span_fatal(pth.span, istr::from_estr( cx.span_fatal(pth.span,
#fmt["macro undefined: '%s'", #ifmt["macro undefined: '%s'",
istr::to_estr(extname)])) extname])
} }
some(normal(ext)) { some(normal(ext)) {
let expanded = ext(cx, pth.span, args, body); let expanded = ext(cx, pth.span, args, body);

View file

@ -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 * should all get sucked into either the standard library extfmt module or the
* compiler syntax extension plugin interface. * compiler syntax extension plugin interface.
*/ */
@ -22,15 +22,16 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr,
alt arg.node { alt arg.node {
ast::expr_vec(elts, _) { elts } 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 { 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 = let fmt =
expr_to_str(cx, args[0], expr_to_str(cx, args[0],
~"first argument to #fmt must be a " ~"first argument to #ifmt must be a "
+ ~"string literal."); + ~"string literal.");
let fmtspan = args[0].span; let fmtspan = args[0].span;
log "Format string:"; log "Format string:";
@ -151,7 +152,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
let count_is_args = [count_lit]; let count_is_args = [count_lit];
ret make_call(cx, sp, count_is_path, count_is_args); 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 { 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; } _ { ret false; }
} }
} }
let unsupported = ~"conversion not supported in #fmt string"; let unsupported = ~"conversion not supported in #ifmt string";
alt cnv.param { alt cnv.param {
option::none. { } option::none. { }
_ { cx.span_unimpl(sp, unsupported); } _ { 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) { if !is_signed_type(cnv) {
cx.span_fatal(sp, cx.span_fatal(sp,
~"+ flag only valid in " + ~"+ flag only valid in " +
~"signed #fmt conversion"); ~"signed #ifmt conversion");
} }
} }
flag_space_for_sign. { flag_space_for_sign. {
if !is_signed_type(cnv) { if !is_signed_type(cnv) {
cx.span_fatal(sp, cx.span_fatal(sp,
~"space flag only valid in " + ~"space flag only valid in " +
~"signed #fmt conversions"); ~"signed #ifmt conversions");
} }
} }
flag_left_zero_pad. { } flag_left_zero_pad. { }
@ -330,7 +331,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
n += 1u; n += 1u;
if n >= nargs { if n >= nargs {
cx.span_fatal(sp, cx.span_fatal(sp,
~"not enough arguments to #fmt " + ~"not enough arguments to #ifmt " +
~"for the given format string"); ~"for the given format string");
} }
log "Building conversion:"; log "Building conversion:";
@ -345,9 +346,9 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
if expected_nargs < nargs { if expected_nargs < nargs {
cx.span_fatal( cx.span_fatal(
sp, istr::from_estr( sp,
#fmt["too many arguments to #fmt. found %u, expected %u", #ifmt["too many arguments to #fmt. found %u, expected %u",
nargs, expected_nargs])); nargs, expected_nargs]);
} }
ret tmp_expr; ret tmp_expr;
} }

View file

@ -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 * should all get sucked into either the standard library extfmt module or the
* compiler syntax extension plugin interface. * compiler syntax extension plugin interface.
*/ */
@ -22,15 +22,16 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr,
alt arg.node { alt arg.node {
ast::expr_vec(elts, _) { elts } 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 { 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 = let fmt =
expr_to_str(cx, args[0], expr_to_str(cx, args[0],
~"first argument to #fmt must be a " ~"first argument to #ifmt must be a "
+ ~"string literal."); + ~"string literal.");
let fmtspan = args[0].span; let fmtspan = args[0].span;
log "Format string:"; log "Format string:";
@ -151,7 +152,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
let count_is_args = [count_lit]; let count_is_args = [count_lit];
ret make_call(cx, sp, count_is_path, count_is_args); 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 { 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; } _ { ret false; }
} }
} }
let unsupported = ~"conversion not supported in #fmt string"; let unsupported = ~"conversion not supported in #ifmt string";
alt cnv.param { alt cnv.param {
option::none. { } option::none. { }
_ { cx.span_unimpl(sp, unsupported); } _ { 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) { if !is_signed_type(cnv) {
cx.span_fatal(sp, cx.span_fatal(sp,
~"+ flag only valid in " + ~"+ flag only valid in " +
~"signed #fmt conversion"); ~"signed #ifmt conversion");
} }
} }
flag_space_for_sign. { flag_space_for_sign. {
if !is_signed_type(cnv) { if !is_signed_type(cnv) {
cx.span_fatal(sp, cx.span_fatal(sp,
~"space flag only valid in " + ~"space flag only valid in " +
~"signed #fmt conversions"); ~"signed #ifmt conversions");
} }
} }
flag_left_zero_pad. { } flag_left_zero_pad. { }
@ -330,7 +331,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
n += 1u; n += 1u;
if n >= nargs { if n >= nargs {
cx.span_fatal(sp, cx.span_fatal(sp,
~"not enough arguments to #fmt " + ~"not enough arguments to #ifmt " +
~"for the given format string"); ~"for the given format string");
} }
log "Building conversion:"; log "Building conversion:";
@ -345,9 +346,9 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
if expected_nargs < nargs { if expected_nargs < nargs {
cx.span_fatal( cx.span_fatal(
sp, istr::from_estr( sp,
#fmt["too many arguments to #fmt. found %u, expected %u", #ifmt["too many arguments to #fmt. found %u, expected %u",
nargs, expected_nargs])); nargs, expected_nargs]);
} }
ret tmp_expr; ret tmp_expr;
} }

View file

@ -309,13 +309,13 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
let len = vec::len(*ms); let len = vec::len(*ms);
if old_len != len { if old_len != len {
let msg = let msg =
#fmt["'%s' occurs %u times, but ", #ifmt["'%s' occurs %u times, but ",
istr::to_estr(fv), len] + fv, len] +
#fmt["'%s' occurs %u times", #ifmt["'%s' occurs %u times",
istr::to_estr(old_name), old_name,
old_len]; old_len];
cx.span_fatal( cx.span_fatal(
repeat_me.span, istr::from_estr(msg)); repeat_me.span, msg);
} }
} }
} }

View file

@ -326,8 +326,7 @@ fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char {
rdr.bump(); rdr.bump();
if !is_hex_digit(n) { if !is_hex_digit(n) {
rdr.err( rdr.err(
istr::from_estr( #ifmt["illegal numeric character escape: %d", n as int]);
#fmt["illegal numeric character escape: %d", n as int]));
fail; fail;
} }
accum_int *= 16; accum_int *= 16;
@ -471,8 +470,8 @@ fn next_token_inner(rdr: &reader) -> token::token {
'U' { c2 = scan_numeric_escape(rdr, 8u); } 'U' { c2 = scan_numeric_escape(rdr, 8u); }
c2 { c2 {
rdr.err( rdr.err(
istr::from_estr(#fmt["unknown character escape: %d", #ifmt["unknown character escape: %d",
c2 as int])); c2 as int]);
fail; fail;
} }
} }
@ -512,8 +511,8 @@ fn next_token_inner(rdr: &reader) -> token::token {
} }
c2 { c2 {
rdr.err( rdr.err(
istr::from_estr(#fmt["unknown string escape: %d", #ifmt["unknown string escape: %d",
c2 as int])); c2 as int]);
fail; fail;
} }
} }
@ -553,7 +552,7 @@ fn next_token_inner(rdr: &reader) -> token::token {
'%' { ret binop(rdr, token::PERCENT); } '%' { ret binop(rdr, token::PERCENT); }
c { c {
rdr.err( rdr.err(
istr::from_estr(#fmt["unkown start of token: %d", c as int])); #ifmt["unkown start of token: %d", c as int]);
fail; fail;
} }
} }
@ -654,7 +653,7 @@ fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt {
let curr_line = ~"/*"; let curr_line = ~"/*";
let level: int = 1; let level: int = 1;
while level > 0 { 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.is_eof() { rdr.err(~"unterminated block comment"); fail; }
if rdr.curr() == '\n' { if rdr.curr() == '\n' {
trim_whitespace_prefix_and_push_line(lines, curr_line, col); trim_whitespace_prefix_and_push_line(lines, curr_line, col);

View file

@ -67,8 +67,7 @@ tag token { STRING(istr, int); BREAK(break_t); BEGIN(begin_t); END; EOF; }
fn tok_str(t: token) -> istr { fn tok_str(t: token) -> istr {
alt t { alt t {
STRING(s, len) { STRING(s, len) {
ret istr::from_estr( ret #ifmt[~"STR(%s,%d)", s, len];
#fmt["STR(%s,%d)", istr::to_estr(s), len]);
} }
BREAK(_) { ret ~"BREAK"; } BREAK(_) { ret ~"BREAK"; }
BEGIN(_) { ret ~"BEGIN"; } BEGIN(_) { ret ~"BEGIN"; }
@ -87,8 +86,7 @@ fn buf_str(toks: &[mutable token], szs: &[mutable int], left: uint,
while i != right && L != 0u { while i != right && L != 0u {
L -= 1u; L -= 1u;
if i != left { s += ~", "; } if i != left { s += ~", "; }
s += istr::from_estr( s += #ifmt[~"%d=%s", szs[i], tok_str(toks[i])];
#fmt["%d=%s", szs[i], istr::to_estr(tok_str(toks[i]))]);
i += 1u; i += 1u;
i %= n; i %= n;
} }
@ -107,7 +105,7 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer {
// fall behind. // fall behind.
let n: uint = 3u * linewidth; 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 token: [mutable token] = vec::init_elt_mut(EOF, n);
let size: [mutable int] = vec::init_elt_mut(0, n); let size: [mutable int] = vec::init_elt_mut(0, n);
let scan_stack: [mutable uint] = vec::init_elt_mut(0u, 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 replace_last_token(t: token) { token[right] = t; }
fn pretty_print(t: token) { fn pretty_print(t: token) {
log #fmt["pp [%u,%u]", left, right]; log #ifmt[~"pp [%u,%u]", left, right];
alt t { alt t {
EOF. { EOF. {
if !scan_stack_empty { if !scan_stack_empty {
@ -263,17 +261,17 @@ obj printer(out: io::writer,
left = 0u; left = 0u;
right = 0u; right = 0u;
} else { self.advance_right(); } } 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; token[right] = t;
size[right] = -right_total; size[right] = -right_total;
self.scan_push(right); self.scan_push(right);
} }
END. { END. {
if scan_stack_empty { 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); self.print(t, 0);
} else { } else {
log #fmt["pp END/buffer [%u,%u]", left, right]; log #ifmt[~"pp END/buffer [%u,%u]", left, right];
self.advance_right(); self.advance_right();
token[right] = t; token[right] = t;
size[right] = -1; size[right] = -1;
@ -287,7 +285,7 @@ obj printer(out: io::writer,
left = 0u; left = 0u;
right = 0u; right = 0u;
} else { self.advance_right(); } } 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.check_stack(0);
self.scan_push(right); self.scan_push(right);
token[right] = t; token[right] = t;
@ -296,10 +294,10 @@ obj printer(out: io::writer,
} }
STRING(s, len) { STRING(s, len) {
if scan_stack_empty { 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); self.print(t, len);
} else { } else {
log #fmt["pp STRING/buffer [%u,%u]", left, right]; log #ifmt[~"pp STRING/buffer [%u,%u]", left, right];
self.advance_right(); self.advance_right();
token[right] = t; token[right] = t;
size[right] = len; size[right] = len;
@ -310,14 +308,14 @@ obj printer(out: io::writer,
} }
} }
fn check_stream() { 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]; left, right, left_total, right_total];
if right_total - left_total > space { 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]; right_total - left_total, space];
if !scan_stack_empty { if !scan_stack_empty {
if left == scan_stack[bottom] { 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; size[self.scan_pop_bottom()] = size_infinity;
} }
} }
@ -326,7 +324,7 @@ obj printer(out: io::writer,
} }
} }
fn scan_push(x: uint) { fn scan_push(x: uint) {
log #fmt["scan_push %u", x]; log #ifmt["scan_push %u", x];
if scan_stack_empty { if scan_stack_empty {
scan_stack_empty = false; scan_stack_empty = false;
} else { top += 1u; top %= buf_len; assert (top != bottom); } } else { top += 1u; top %= buf_len; assert (top != bottom); }
@ -355,7 +353,7 @@ obj printer(out: io::writer,
assert (right != left); assert (right != left);
} }
fn advance_left(x: token, L: int) { 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 { if L >= 0 {
self.print(x, L); self.print(x, L);
alt x { alt x {
@ -394,13 +392,13 @@ obj printer(out: io::writer,
} }
} }
fn print_newline(amount: int) { fn print_newline(amount: int) {
log #fmt["NEWLINE %d", amount]; log #ifmt["NEWLINE %d", amount];
out.write_str(~"\n"); out.write_str(~"\n");
pending_indentation = 0; pending_indentation = 0;
self.indent(amount); self.indent(amount);
} }
fn indent(amount: int) { fn indent(amount: int) {
log #fmt["INDENT %d", amount]; log #ifmt["INDENT %d", amount];
pending_indentation += amount; pending_indentation += amount;
} }
fn top() -> print_stack_elt { fn top() -> print_stack_elt {
@ -417,15 +415,15 @@ obj printer(out: io::writer,
out.write_str(s); out.write_str(s);
} }
fn print(x: token, L: int) { fn print(x: token, L: int) {
log #fmt["print %s %d (remaining line space=%d)", log #ifmt["print %s %d (remaining line space=%d)",
istr::to_estr(tok_str(x)), L, tok_str(x), L,
space]; space];
log buf_str(token, size, left, right, 6u); log buf_str(token, size, left, right, 6u);
alt x { alt x {
BEGIN(b) { BEGIN(b) {
if L > space { if L > space {
let col = margin - space + b.offset; 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)}]; print_stack += [{offset: col, pbreak: broken(b.breaks)}];
} else { } else {
log "print BEGIN -> push fitting block"; log "print BEGIN -> push fitting block";

View file

@ -362,7 +362,7 @@ fn dummy() {
alt *elts.(idx) { alt *elts.(idx) {
leaf_destructure(x) { x } 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]) #ident_to_str[leaf_destructure], idx])
} }
}], }],

View file

@ -195,7 +195,7 @@ fn check_whole_compiler(code: &str) {
~"/Users/jruderman/code/rust/build/stage1/rustc", ~"/Users/jruderman/code/rust/build/stage1/rustc",
[~"-c", istr::from_estr(filename)]); [~"-c", istr::from_estr(filename)]);
//log_err #fmt("Status: %d", p.status); //log_err #ifmt("Status: %d", p.status);
//log_err "Output: " + p.out; //log_err "Output: " + p.out;
if p.err != "" { if p.err != "" {
if contains(p.err, "argument of incompatible type") { if contains(p.err, "argument of incompatible type") {
@ -265,7 +265,7 @@ fn content_is_dangerous_to_modify(code: &str) -> bool {
let dangerous_patterns = let dangerous_patterns =
["obj", // not safe to steal; https://github.com/graydon/rust/issues/761 ["obj", // not safe to steal; https://github.com/graydon/rust/issues/761
"#macro", // not safe to steal things inside of it, because they have a special syntax "#macro", // not safe to steal things inside of it, because they have a special syntax
"#", // strange representation of the arguments to #fmt, for example "#", // strange representation of the arguments to #ifmt, for example
" be ", // don't want to replace its child with a non-call: "Non-call expression in tail call" " be ", // don't want to replace its child with a non-call: "Non-call expression in tail call"
"@"]; // hangs when compiling: https://github.com/graydon/rust/issues/768 "@"]; // hangs when compiling: https://github.com/graydon/rust/issues/768
@ -327,9 +327,9 @@ fn check_roundtrip_convergence(code: &str, maxIters: uint) {
} }
if old == new { if old == new {
log_err #fmt["Converged after %u iterations", i]; log_err #ifmt["Converged after %u iterations", i];
} else { } else {
log_err #fmt["Did not converge after %u iterations!", i]; log_err #ifmt["Did not converge after %u iterations!", i];
write_file("round-trip-a.rs", old); write_file("round-trip-a.rs", old);
write_file("round-trip-b.rs", new); write_file("round-trip-b.rs", new);
std::run::run_program(~"diff", std::run::run_program(~"diff",
@ -340,12 +340,12 @@ fn check_roundtrip_convergence(code: &str, maxIters: uint) {
} }
fn check_convergence(files: &[str]) { fn check_convergence(files: &[str]) {
log_err #fmt["pp convergence tests: %u files", vec::len(files)]; log_err #ifmt["pp convergence tests: %u files", vec::len(files)];
for file in files { for file in files {
if !file_is_confusing(file) { if !file_is_confusing(file) {
let s = istr::to_estr(io::read_whole_file_str(istr::from_estr(file))); let s = istr::to_estr(io::read_whole_file_str(istr::from_estr(file)));
if !content_is_confusing(s) { if !content_is_confusing(s) {
log_err #fmt["pp converge: %s", file]; log_err #ifmt["pp converge: %s", istr::from_estr(file)];
// Change from 7u to 2u when https://github.com/graydon/rust/issues/759 is fixed // Change from 7u to 2u when https://github.com/graydon/rust/issues/759 is fixed
check_roundtrip_convergence(s, 7u); check_roundtrip_convergence(s, 7u);
} }
@ -377,7 +377,7 @@ fn check_variants(files: &[str]) {
fn main(args: [str]) { fn main(args: [str]) {
if vec::len(args) != 2u { if vec::len(args) != 2u {
log_err #fmt["usage: %s <testdir>", args[0]]; log_err #ifmt["usage: %s <testdir>", istr::from_estr(args[0])];
ret; ret;
} }
let files = []; let files = [];

View file

@ -7,8 +7,7 @@ tag ip_addr { ipv4(u8, u8, u8, u8); }
fn format_addr(ip: ip_addr) -> istr { fn format_addr(ip: ip_addr) -> istr {
alt ip { alt ip {
ipv4(a, b, c, d) { ipv4(a, b, c, d) {
istr::from_estr( #ifmt["%u.%u.%u.%u", a as uint, b as uint, c as uint, d as uint]
#fmt["%u.%u.%u.%u", a as uint, b as uint, c as uint, d as uint])
} }
_ { fail "Unsupported address type"; } _ { fail "Unsupported address type"; }
} }

View file

@ -81,7 +81,7 @@ fn join(task_port: (task_id, comm::port<task_notification>)) -> task_result {
exit(_id, res) { exit(_id, res) {
if _id == id { if _id == id {
ret res ret res
} else { fail #fmt["join received id %d, expected %d", _id, id] } } else { fail #ifmt["join received id %d, expected %d", _id, id] }
} }
} }
} }

View file

@ -120,11 +120,11 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
te_filtered(filtered_tests) { te_filtered(filtered_tests) {
st.total = vec::len(filtered_tests); st.total = vec::len(filtered_tests);
st.out.write_line( st.out.write_line(
istr::from_estr(#fmt["\nrunning %u tests", st.total])); #ifmt["\nrunning %u tests", st.total]);
} }
te_wait(test) { te_wait(test) {
st.out.write_str( st.out.write_str(
istr::from_estr(#fmt["test %s ... ", test.name])); #ifmt["test %s ... ", istr::from_estr(test.name)]);
} }
te_result(test, result) { te_result(test, result) {
alt result { alt result {
@ -167,19 +167,18 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
st.out.write_line(~"\nfailures:"); st.out.write_line(~"\nfailures:");
for test: test_desc in st.failures { for test: test_desc in st.failures {
let testname = test.name; // Satisfy alias analysis let testname = test.name; // Satisfy alias analysis
st.out.write_line(istr::from_estr(#fmt[" %s", testname])); st.out.write_line(#ifmt[" %s", istr::from_estr(testname)]);
} }
} }
st.out.write_str(istr::from_estr(#fmt["\nresult: "])); st.out.write_str(#ifmt["\nresult: "]);
if success { if success {
// There's no parallelism at this point so it's safe to use color // There's no parallelism at this point so it's safe to use color
write_ok(st.out, true); write_ok(st.out, true);
} else { write_failed(st.out, true); } } else { write_failed(st.out, true); }
st.out.write_str( st.out.write_str(
istr::from_estr( #ifmt[". %u passed; %u failed; %u ignored\n\n", st.passed,
#fmt[". %u passed; %u failed; %u ignored\n\n", st.passed, st.failed, st.ignored]);
st.failed, st.ignored]));
ret success; ret success;
@ -226,7 +225,7 @@ fn run_tests(opts: &test_opts, tests: &[test_desc], to_task: &test_to_task,
// provide a great user experience because you might sit waiting for the // provide a great user experience because you might sit waiting for the
// result of a particular test for an unusually long amount of time. // result of a particular test for an unusually long amount of time.
let concurrency = get_concurrency(); let concurrency = get_concurrency();
log #fmt["using %u test tasks", concurrency]; log #ifmt["using %u test tasks", concurrency];
let total = vec::len(filtered_tests); let total = vec::len(filtered_tests);
let run_idx = 0u; let run_idx = 0u;
let wait_idx = 0u; let wait_idx = 0u;

View file

@ -28,7 +28,7 @@ fn main() {
} else { max_depth = n; } } else { max_depth = n; }
let stretch_depth = max_depth + 1; let stretch_depth = max_depth + 1;
let stretch_tree = bottom_up_tree(0, stretch_depth); let stretch_tree = bottom_up_tree(0, stretch_depth);
log #fmt["stretch tree of depth %d\t check: %d", stretch_depth, log #ifmt["stretch tree of depth %d\t check: %d", stretch_depth,
item_check(stretch_tree)]; item_check(stretch_tree)];
let long_lived_tree = bottom_up_tree(0, max_depth); let long_lived_tree = bottom_up_tree(0, max_depth);
let depth = min_depth; let depth = min_depth;
@ -43,10 +43,10 @@ fn main() {
chk += item_check(temp_tree); chk += item_check(temp_tree);
i += 1; i += 1;
} }
log #fmt["%d\t trees of depth %d\t check: %d", iterations * 2, depth, log #ifmt["%d\t trees of depth %d\t check: %d", iterations * 2, depth,
chk]; chk];
depth += 2; depth += 2;
} }
log #fmt["long lived trees of depth %d\t check: %d", max_depth, log #ifmt["long lived trees of depth %d\t check: %d", max_depth,
item_check(long_lived_tree)]; item_check(long_lived_tree)];
} }

View file

@ -58,5 +58,5 @@ fn fannkuch(n: int) -> int {
fn main(args: [str]) { fn main(args: [str]) {
let n = 7; let n = 7;
log #fmt["Pfannkuchen(%d) = %d", n, fannkuch(n)]; log #ifmt["Pfannkuchen(%d) = %d", n, fannkuch(n)];
} }

View file

@ -69,7 +69,7 @@ fn stress_task(id: int) {
let n = 15; let n = 15;
assert (fib(n) == fib(n)); assert (fib(n) == fib(n));
i += 1; i += 1;
log_err #fmt["%d: Completed %d iterations", id, i]; log_err #ifmt["%d: Completed %d iterations", id, i];
} }
} }
@ -108,9 +108,8 @@ fn main(argv: [str]) {
let elapsed = stop - start; let elapsed = stop - start;
out.write_line( out.write_line(
istr::from_estr( #ifmt["%d\t%d\t%s", n, fibn,
#fmt["%d\t%d\t%s", n, fibn, u64::str(elapsed)]);
istr::to_estr(u64::str(elapsed))]));
} }
} }
} }

View file

@ -128,7 +128,7 @@ mod map_reduce {
while !is_done || ref_count > 0 { while !is_done || ref_count > 0 {
alt recv(p) { alt recv(p) {
emit_val(v) { emit_val(v) {
// log_err #fmt("received %d", v); // log_err #ifmt("received %d", v);
ret some(v); ret some(v);
} }
done. { done. {
@ -203,7 +203,7 @@ fn main(argv: [str]) {
let out = io::stdout(); let out = io::stdout();
out.write_line( out.write_line(
istr::from_estr(#fmt["Usage: %s <filename> ...", argv[0]])); #ifmt["Usage: %s <filename> ...", istr::from_estr(argv[0])]);
// TODO: run something just to make sure the code hasn't // TODO: run something just to make sure the code hasn't
// broken yet. This is the unit test mode of this program. // broken yet. This is the unit test mode of this program.

View file

@ -124,7 +124,7 @@ mod map_reduce {
while !is_done || ref_count > 0 { while !is_done || ref_count > 0 {
alt recv(p) { alt recv(p) {
emit_val(v) { emit_val(v) {
// log_err #fmt("received %d", v); // log_err #ifmt("received %d", v);
ret some(v); ret some(v);
} }
done. { done. {
@ -198,8 +198,8 @@ fn main(argv: [str]) {
if vec::len(argv) < 2u { if vec::len(argv) < 2u {
let out = io::stdout(); let out = io::stdout();
out.write_line(istr::from_estr( out.write_line(
#fmt["Usage: %s <filename> ...", argv[0]])); #ifmt["Usage: %s <filename> ...", istr::from_estr(argv[0])]);
// TODO: run something just to make sure the code hasn't // TODO: run something just to make sure the code hasn't
// broken yet. This is the unit test mode of this program. // broken yet. This is the unit test mode of this program.

View file

@ -1,7 +1,7 @@
// error-pattern:expecting [, found fmt // error-pattern:expecting [, found ifmt
// Don't know how to deal with a syntax extension appearing after an // Don't know how to deal with a syntax extension appearing after an
// item attribute. Probably could use a better error message. // item attribute. Probably could use a better error message.
#[foo = "bar"] #[foo = "bar"]
#fmt("baz") #ifmt("baz")
fn main() { } fn main() { }

View file

@ -1,3 +1,3 @@
// error-pattern:missing type // error-pattern:missing type
fn main() { #fmt["%+"]; } fn main() { #ifmt["%+"]; }

View file

@ -1,3 +1,3 @@
// error-pattern:format string // error-pattern:format string
fn main() { #fmt[]; } fn main() { #ifmt[]; }

View file

@ -1,8 +1,8 @@
// error-pattern: literal // error-pattern: literal
fn main() { fn main() {
// #fmt's first argument must be a literal. Hopefully this // #ifmt's first argument must be a literal. Hopefully this
// restriction can be eased eventually to just require a // restriction can be eased eventually to just require a
// compile-time constant. // compile-time constant.
let x = #fmt["a" + "b"]; let x = #ifmt["a" + "b"];
} }

View file

@ -1,8 +1,8 @@
// error-pattern: literal // error-pattern: literal
fn main() { fn main() {
// #fmt's first argument must be a literal. Hopefully this // #ifmt's first argument must be a literal. Hopefully this
// restriction can be eased eventually to just require a // restriction can be eased eventually to just require a
// compile-time constant. // compile-time constant.
let x = #fmt[20]; let x = #ifmt[20];
} }

View file

@ -2,4 +2,4 @@
use std; use std;
fn main() { let s = #fmt["%s%s%s", "test", "test"]; } fn main() { let s = #ifmt["%s%s%s", "test", "test"]; }

View file

@ -2,4 +2,4 @@
use std; use std;
fn main() { let s = #fmt["%s", "test", "test"]; } fn main() { let s = #ifmt["%s", "test", "test"]; }

View file

@ -1,3 +1,3 @@
// error-pattern:unknown type // error-pattern:unknown type
fn main() { #fmt["%w"]; } fn main() { #ifmt["%w"]; }

View file

@ -1,6 +1,6 @@
// error-pattern:only valid in signed #fmt conversion // error-pattern:only valid in signed #ifmt conversion
fn main() { fn main() {
// Can't use a sign on unsigned conversions // Can't use a sign on unsigned conversions
#fmt["%+u", 10u]; #ifmt["%+u", 10u];
} }

View file

@ -1,6 +1,6 @@
// error-pattern:only valid in signed #fmt conversion // error-pattern:only valid in signed #ifmt conversion
fn main() { fn main() {
// Can't use a space on unsigned conversions // Can't use a space on unsigned conversions
#fmt["% u", 10u]; #ifmt["% u", 10u];
} }

View file

@ -1,3 +1,3 @@
// error-pattern:unterminated conversion // error-pattern:unterminated conversion
fn main() { #fmt["%"]; } fn main() { #ifmt["%"]; }

View file

@ -72,34 +72,21 @@ fn parse_config(args: &[istr]) -> config {
fn log_config(config: &config) { fn log_config(config: &config) {
let c = config; let c = config;
logv(c, istr::from_estr( logv(c, #ifmt["configuration:"]);
#fmt["configuration:"])); logv(c, #ifmt["compile_lib_path: %s",
logv(c, istr::from_estr( config.compile_lib_path]);
#fmt["compile_lib_path: %s", logv(c, #ifmt["run_lib_path: %s", config.run_lib_path]);
istr::to_estr(config.compile_lib_path)])); logv(c, #ifmt["rustc_path: %s", config.rustc_path]);
logv(c, istr::from_estr( logv(c, #ifmt["src_base: %s", config.src_base]);
#fmt["run_lib_path: %s", istr::to_estr(config.run_lib_path)])); logv(c, #ifmt["build_base: %s", config.build_base]);
logv(c, istr::from_estr( logv(c, #ifmt["stage_id: %s", config.stage_id]);
#fmt["rustc_path: %s", istr::to_estr(config.rustc_path)])); logv(c, #ifmt["mode: %s", mode_str(config.mode)]);
logv(c, istr::from_estr( logv(c, #ifmt["run_ignored: %b", config.run_ignored]);
#fmt["src_base: %s", istr::to_estr(config.src_base)])); logv(c, #ifmt["filter: %s", opt_str(config.filter)]);
logv(c, istr::from_estr( logv(c, #ifmt["runtool: %s", opt_str(config.runtool)]);
#fmt["build_base: %s", istr::to_estr(config.build_base)])); logv(c, #ifmt["rustcflags: %s", opt_str(config.rustcflags)]);
logv(c, istr::from_estr( logv(c, #ifmt["verbose: %b", config.verbose]);
#fmt["stage_id: %s", istr::to_estr(config.stage_id)])); logv(c, #ifmt["\n"]);
logv(c, istr::from_estr(
#fmt["mode: %s", istr::to_estr(mode_str(config.mode))]));
logv(c, istr::from_estr(
#fmt["run_ignored: %b", config.run_ignored]));
logv(c, istr::from_estr(
#fmt["filter: %s", istr::to_estr(opt_str(config.filter))]));
logv(c, istr::from_estr(
#fmt["runtool: %s", istr::to_estr(opt_str(config.runtool))]));
logv(c, istr::from_estr(
#fmt["rustcflags: %s", istr::to_estr(opt_str(config.rustcflags))]));
logv(c, istr::from_estr(
#fmt["verbose: %b", config.verbose]));
logv(c, istr::from_estr(#fmt["\n"]));
} }
fn opt_str(maybestr: option::t<istr>) -> istr { fn opt_str(maybestr: option::t<istr>) -> istr {
@ -154,11 +141,12 @@ type tests_and_conv_fn =
{tests: [test::test_desc], to_task: fn(&fn()) -> test::joinable}; {tests: [test::test_desc], to_task: fn(&fn()) -> test::joinable};
fn make_tests(cx: &cx) -> tests_and_conv_fn { fn make_tests(cx: &cx) -> tests_and_conv_fn {
log #fmt["making tests from %s", istr::to_estr(cx.config.src_base)]; log #ifmt["making tests from %s", cx.config.src_base];
let configport = port::<[u8]>(); let configport = port::<[u8]>();
let tests = []; let tests = [];
for file: istr in fs::list_dir(cx.config.src_base) { for file: istr in fs::list_dir(cx.config.src_base) {
log #fmt["inspecting file %s", istr::to_estr(file)]; let file = file;
log #ifmt["inspecting file %s", file];
if is_test(cx.config, file) { if is_test(cx.config, file) {
tests += [make_test(cx, file, configport)]; tests += [make_test(cx, file, configport)];
} }
@ -196,9 +184,9 @@ fn make_test(cx: &cx, testfile: &istr, configport: &port<[u8]>) ->
} }
fn make_test_name(config: &config, testfile: &istr) -> str { fn make_test_name(config: &config, testfile: &istr) -> str {
#fmt["[%s] %s", istr::to_estr(
istr::to_estr(mode_str(config.mode)), #ifmt["[%s] %s", mode_str(config.mode),
istr::to_estr(testfile)] testfile])
} }
/* /*

View file

@ -115,9 +115,8 @@ fn parse_name_value_directive(line: &istr,
let value = let value =
istr::slice(line, colon + istr::byte_len(keycolon), istr::slice(line, colon + istr::byte_len(keycolon),
istr::byte_len(line)); istr::byte_len(line));
log #fmt("%s: %s", log #ifmt("%s: %s", directive,
istr::to_estr(directive), value);
istr::to_estr(value));
option::some(value) option::some(value)
} else { option::none } } else { option::none }
} }

View file

@ -25,7 +25,7 @@ fn run(cx: &cx, _testfile: -[u8]) {
// We're going to be dumping a lot of info. Start on a new line. // We're going to be dumping a lot of info. Start on a new line.
io::stdout().write_str(~"\n\n"); io::stdout().write_str(~"\n\n");
} }
log #fmt["running %s", istr::to_estr(testfile)]; log #ifmt["running %s", testfile];
let props = load_props(testfile); let props = load_props(testfile);
alt cx.config.mode { alt cx.config.mode {
mode_compile_fail. { run_cfail_test(cx, props, testfile); } mode_compile_fail. { run_cfail_test(cx, props, testfile); }
@ -91,14 +91,12 @@ fn run_pretty_test(cx: &cx, props: &test_props, testfile: &istr) {
let round = 0; let round = 0;
while round < rounds { while round < rounds {
logv(cx.config, logv(cx.config, #ifmt["pretty-printing round %d", round]);
istr::from_estr(#fmt["pretty-printing round %d", round]));
let procres = print_source(cx, testfile, srcs[round]); let procres = print_source(cx, testfile, srcs[round]);
if procres.status != 0 { if procres.status != 0 {
fatal_procres( fatal_procres(
istr::from_estr(#fmt["pretty-printing failed in round %d", #ifmt["pretty-printing failed in round %d", round],
round]),
procres); procres);
} }
@ -150,7 +148,7 @@ fn run_pretty_test(cx: &cx, props: &test_props, testfile: &istr) {
if expected != actual { if expected != actual {
error(~"pretty-printed source does match expected source"); error(~"pretty-printed source does match expected source");
let msg = let msg =
#fmt["\n\ #ifmt["\n\
expected:\n\ expected:\n\
------------------------------------------\n\ ------------------------------------------\n\
%s\n\ %s\n\
@ -160,8 +158,9 @@ actual:\n\
%s\n\ %s\n\
------------------------------------------\n\ ------------------------------------------\n\
\n", \n",
istr::to_estr(expected), istr::to_estr(actual)]; expected,
io::stdout().write_str(istr::from_estr(msg)); actual];
io::stdout().write_str(msg);
fail; fail;
} }
} }
@ -192,7 +191,8 @@ fn check_error_patterns(props: &test_props, testfile: &istr,
let next_err_pat = props.error_patterns[next_err_idx]; let next_err_pat = props.error_patterns[next_err_idx];
for line: istr in istr::split(procres.stdout, '\n' as u8) { for line: istr in istr::split(procres.stdout, '\n' as u8) {
if istr::find(line, next_err_pat) > 0 { if istr::find(line, next_err_pat) > 0 {
log #fmt["found error pattern %s", istr::to_estr(next_err_pat)]; log #ifmt["found error pattern %s",
next_err_pat];
next_err_idx += 1u; next_err_idx += 1u;
if next_err_idx == vec::len(props.error_patterns) { if next_err_idx == vec::len(props.error_patterns) {
log "found all error patterns"; log "found all error patterns";
@ -206,14 +206,13 @@ fn check_error_patterns(props: &test_props, testfile: &istr,
vec::slice(props.error_patterns, next_err_idx, vec::slice(props.error_patterns, next_err_idx,
vec::len(props.error_patterns)); vec::len(props.error_patterns));
if vec::len(missing_patterns) == 1u { if vec::len(missing_patterns) == 1u {
fatal_procres(istr::from_estr( fatal_procres(
#fmt["error pattern '%s' not found!", #ifmt["error pattern '%s' not found!",
istr::to_estr(missing_patterns[0])]), procres); missing_patterns[0]], procres);
} else { } else {
for pattern: istr in missing_patterns { for pattern: istr in missing_patterns {
error(istr::from_estr( error(#ifmt["error pattern '%s' not found!",
#fmt["error pattern '%s' not found!", pattern]);
istr::to_estr(pattern)]));
} }
fatal_procres(~"multiple error patterns not found", procres); fatal_procres(~"multiple error patterns not found", procres);
} }
@ -301,9 +300,8 @@ fn program_output(cx: &cx, testfile: &istr, lib_path: &istr, prog: &istr,
let cmdline = let cmdline =
{ {
let cmdline = make_cmdline(lib_path, prog, args); let cmdline = make_cmdline(lib_path, prog, args);
logv(cx.config, logv(cx.config, #ifmt["executing %s",
istr::from_estr(#fmt["executing %s", cmdline]);
istr::to_estr(cmdline)]));
cmdline cmdline
}; };
let res = procsrv::run(cx.procsrv, lib_path, prog, args, input); let res = procsrv::run(cx.procsrv, lib_path, prog, args, input);
@ -315,18 +313,18 @@ fn program_output(cx: &cx, testfile: &istr, lib_path: &istr, prog: &istr,
} }
fn make_cmdline(libpath: &istr, prog: &istr, args: &[istr]) -> istr { fn make_cmdline(libpath: &istr, prog: &istr, args: &[istr]) -> istr {
istr::from_estr(#fmt["%s %s %s", #ifmt["%s %s %s",
istr::to_estr(lib_path_cmd_prefix(libpath)), lib_path_cmd_prefix(libpath),
istr::to_estr(prog), prog,
istr::to_estr(istr::connect(args, ~" "))]) istr::connect(args, ~" ")]
} }
// Build the LD_LIBRARY_PATH variable as it would be seen on the command line // Build the LD_LIBRARY_PATH variable as it would be seen on the command line
// for diagnostic purposes // for diagnostic purposes
fn lib_path_cmd_prefix(path: &istr) -> istr { fn lib_path_cmd_prefix(path: &istr) -> istr {
istr::from_estr(#fmt["%s=\"%s\"", #ifmt["%s=\"%s\"",
istr::to_estr(util::lib_path_env_var()), util::lib_path_env_var(),
istr::to_estr(util::make_new_path(path))]) util::make_new_path(path)]
} }
fn dump_output(config: &config, testfile: &istr, out: &istr, err: &istr) { fn dump_output(config: &config, testfile: &istr, out: &istr, err: &istr) {
@ -365,34 +363,32 @@ fn output_base_name(config: &config, testfile: &istr) -> istr {
parts = vec::slice(parts, 0u, vec::len(parts) - 1u); parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
istr::connect(parts, ~".") istr::connect(parts, ~".")
}; };
istr::from_estr(#fmt["%s%s.%s", istr::to_estr(base), #ifmt["%s%s.%s", base, filename,
istr::to_estr(filename), config.stage_id]
istr::to_estr(config.stage_id)])
} }
fn maybe_dump_to_stdout(config: &config, out: &istr, err: &istr) { fn maybe_dump_to_stdout(config: &config, out: &istr, err: &istr) {
if config.verbose { if config.verbose {
let sep1 = #fmt["------%s------------------------------", "stdout"]; let sep1 = #ifmt["------%s------------------------------", ~"stdout"];
let sep2 = #fmt["------%s------------------------------", "stderr"]; let sep2 = #ifmt["------%s------------------------------", ~"stderr"];
let sep3 = ~"------------------------------------------"; let sep3 = ~"------------------------------------------";
io::stdout().write_line(istr::from_estr(sep1)); io::stdout().write_line(sep1);
io::stdout().write_line(out); io::stdout().write_line(out);
io::stdout().write_line(istr::from_estr(sep2)); io::stdout().write_line(sep2);
io::stdout().write_line(err); io::stdout().write_line(err);
io::stdout().write_line(sep3); io::stdout().write_line(sep3);
} }
} }
fn error(err: &istr) { fn error(err: &istr) {
io::stdout().write_line(istr::from_estr(#fmt["\nerror: %s", io::stdout().write_line(#ifmt["\nerror: %s", err]);
istr::to_estr(err)]));
} }
fn fatal(err: &istr) -> ! { error(err); fail; } fn fatal(err: &istr) -> ! { error(err); fail; }
fn fatal_procres(err: &istr, procres: procres) -> ! { fn fatal_procres(err: &istr, procres: procres) -> ! {
let msg = let msg =
istr::from_estr(#fmt["\n\ #ifmt["\n\
error: %s\n\ error: %s\n\
command: %s\n\ command: %s\n\
stdout:\n\ stdout:\n\
@ -404,10 +400,10 @@ stderr:\n\
%s\n\ %s\n\
------------------------------------------\n\ ------------------------------------------\n\
\n", \n",
istr::to_estr(err), err,
istr::to_estr(procres.cmdline), procres.cmdline,
istr::to_estr(procres.stdout), procres.stdout,
istr::to_estr(procres.stderr)]); procres.stderr];
io::stdout().write_str(msg); io::stdout().write_str(msg);
fail; fail;
} }

View file

@ -11,8 +11,7 @@ fn make_new_path(path: &istr) -> istr {
// maintain the current value while adding our own // maintain the current value while adding our own
alt getenv(lib_path_env_var()) { alt getenv(lib_path_env_var()) {
option::some(curr) { option::some(curr) {
istr::from_estr(#fmt["%s:%s", #ifmt["%s:%s", path, curr] }
istr::to_estr(path), istr::to_estr(curr)]) }
option::none. { path } option::none. { path }
} }
} }

View file

@ -3,4 +3,4 @@
use std; use std;
import std::str; import std::str;
fn main() { let str_var: str = "meh"; fail #fmt["%s", str_var]; } fn main() { let str_var: istr = ~"meh"; fail #ifmt["%s", str_var]; }

View file

@ -167,7 +167,7 @@ mod test_distinguish_syntax_ext {
use std; use std;
fn f() { fn f() {
#fmt["test%s", "s"]; #ifmt["test%s", ~"s"];
#[attr = "val"] #[attr = "val"]
fn g() { } fn g() { }
} }

View file

@ -54,7 +54,7 @@ fn test_simple() {
// Silly, but what else can we do? // Silly, but what else can we do?
check vec::same_length(expected, immut_names); check vec::same_length(expected, immut_names);
let pairs = vec::zip(expected, immut_names); let pairs = vec::zip(expected, immut_names);
for (a, b) in pairs { log #fmt["%d %d", a, b]; assert (a == b); } for (a, b) in pairs { log #ifmt["%d %d", a, b]; assert (a == b); }
} }
// Local Variables: // Local Variables: