Convert parser to istrs. Issue #855
This commit is contained in:
parent
427d42228f
commit
675073c266
8 changed files with 231 additions and 217 deletions
|
@ -95,7 +95,8 @@ fn input_is_stdin(filename: str) -> bool { filename == "-" }
|
|||
fn parse_input(sess: session::session, cfg: &ast::crate_cfg, input: str) ->
|
||||
@ast::crate {
|
||||
if !input_is_stdin(input) {
|
||||
parser::parse_crate_from_file(input, cfg, sess.get_parse_sess())
|
||||
parser::parse_crate_from_file(
|
||||
istr::from_estr(input), cfg, sess.get_parse_sess())
|
||||
} else { parse_input_src(sess, cfg, input).crate }
|
||||
}
|
||||
|
||||
|
@ -107,7 +108,9 @@ fn parse_input_src(sess: session::session, cfg: &ast::crate_cfg, infile: str)
|
|||
} else { io::stdin() }.read_whole_stream();
|
||||
let src = str::unsafe_from_bytes(srcbytes);
|
||||
let crate =
|
||||
parser::parse_crate_from_source_str(infile, src, cfg,
|
||||
parser::parse_crate_from_source_str(
|
||||
istr::from_estr(infile),
|
||||
istr::from_estr(src), cfg,
|
||||
sess.get_parse_sess());
|
||||
ret {crate: crate, src: src};
|
||||
}
|
||||
|
|
|
@ -4649,7 +4649,7 @@ fn trans_fail_value(cx: &@block_ctxt, sp_opt: &option::t<span>,
|
|||
alt sp_opt {
|
||||
some(sp) {
|
||||
let loc = bcx_ccx(cx).sess.lookup_pos(sp.lo);
|
||||
V_filename = C_cstr(bcx_ccx(cx), istr::from_estr(loc.filename));
|
||||
V_filename = C_cstr(bcx_ccx(cx), loc.filename);
|
||||
V_line = loc.line as int;
|
||||
}
|
||||
none. { V_filename = C_cstr(bcx_ccx(cx), ~"<runtime>"); V_line = 0; }
|
||||
|
|
|
@ -8,7 +8,7 @@ import std::option;
|
|||
import std::option::some;
|
||||
import std::option::none;
|
||||
|
||||
type filename = str;
|
||||
type filename = istr;
|
||||
|
||||
type file_pos = {ch: uint, byte: uint};
|
||||
|
||||
|
@ -84,7 +84,9 @@ fn span_to_str(sp: &span, cm: &codemap) -> str {
|
|||
#fmt["%s:%u:%u: %u:%u",
|
||||
if some(lo.filename) == prev_file {
|
||||
"-"
|
||||
} else { lo.filename }, lo.line, lo.col, hi.line, hi.col];
|
||||
} else {
|
||||
istr::to_estr(lo.filename)
|
||||
}, lo.line, lo.col, hi.line, hi.col];
|
||||
alt cur.expanded_from {
|
||||
os_none. { break; }
|
||||
os_some(new_sp) {
|
||||
|
@ -146,14 +148,16 @@ 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 ", fm.name, line + 1u]));
|
||||
istr::from_estr(#fmt["%s:%u ",
|
||||
istr::to_estr(fm.name), line + 1u]));
|
||||
let s = get_line(fm, line as int, file);
|
||||
if !str::ends_with(s, "\n") { s += "\n"; }
|
||||
io::stdout().write_str(istr::from_estr(s));
|
||||
}
|
||||
if elided {
|
||||
let last_line = display_lines[vec::len(display_lines) - 1u];
|
||||
let s = #fmt["%s:%u ", fm.name, last_line + 1u];
|
||||
let s = #fmt["%s:%u ",
|
||||
istr::to_estr(fm.name), last_line + 1u];
|
||||
let indent = str::char_len(s);
|
||||
let out = ~"";
|
||||
while indent > 0u { out += ~" "; indent -= 1u; }
|
||||
|
@ -172,7 +176,7 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap,
|
|||
while num > 0u { num /= 10u; digits += 1u; }
|
||||
|
||||
// indent past |name:## | and the 0-offset column location
|
||||
let left = str::char_len(fm.name) + digits + lo.col + 3u;
|
||||
let left = istr::char_len(fm.name) + digits + lo.col + 3u;
|
||||
let s = "";
|
||||
while left > 0u { str::push_char(s, ' '); left -= 1u; }
|
||||
|
||||
|
@ -209,7 +213,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
|
|||
for each i: uint in uint::range(lo.line - 1u, hi.line as uint) {
|
||||
lines += [i];
|
||||
}
|
||||
ret @{name: lo.filename, lines: lines};
|
||||
ret @{name: istr::to_estr(lo.filename), lines: lines};
|
||||
}
|
||||
|
||||
fn get_line(fm: filemap, line: int, file: &str) -> str {
|
||||
|
@ -230,7 +234,9 @@ fn get_line(fm: filemap, line: int, file: &str) -> str {
|
|||
}
|
||||
|
||||
fn get_filemap(cm: codemap, filename: str) -> filemap {
|
||||
for fm: filemap in cm.files { if fm.name == filename { ret fm; } }
|
||||
for fm: filemap in cm.files {
|
||||
if fm.name == istr::from_estr(filename) { ret fm; }
|
||||
}
|
||||
//XXjdm the following triggers a mismatched type bug
|
||||
// (or expected function, found _|_)
|
||||
fail; // ("asking for " + filename + " which we don't know about");
|
||||
|
|
|
@ -93,7 +93,8 @@ fn mk_ctxt(sess: &session) -> ext_ctxt {
|
|||
// super-ugly and needs a better solution.
|
||||
let crate_file_name_hack = sess.get_codemap().files[0].name;
|
||||
|
||||
ret ext_ctxt(@sess, crate_file_name_hack, codemap::os_none);
|
||||
ret ext_ctxt(@sess, istr::to_estr(crate_file_name_hack),
|
||||
codemap::os_none);
|
||||
}
|
||||
|
||||
fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: str) -> str {
|
||||
|
|
|
@ -51,7 +51,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &istr,
|
|||
let file_path = id + ~".rs";
|
||||
alt file_opt {
|
||||
some(f) {
|
||||
file_path = istr::from_estr(f);
|
||||
file_path = f;
|
||||
}
|
||||
none. { }
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &istr,
|
|||
if cx.mode == mode_depend { cx.deps += [full_path]; ret; }
|
||||
let p0 =
|
||||
new_parser_from_file(cx.sess, cx.cfg,
|
||||
istr::to_estr(full_path), cx.chpos,
|
||||
full_path, cx.chpos,
|
||||
cx.byte_pos, SOURCE_FILE);
|
||||
let inner_attrs = parse_inner_attrs_and_next(p0);
|
||||
let mod_attrs = attrs + inner_attrs.inner;
|
||||
|
@ -82,7 +82,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &istr,
|
|||
let path = id;
|
||||
alt dir_opt {
|
||||
some(d) {
|
||||
path = istr::from_estr(d);
|
||||
path = d;
|
||||
}
|
||||
none. { }
|
||||
}
|
||||
|
|
|
@ -728,7 +728,7 @@ fn gather_comments_and_literals(cm: &codemap::codemap, path: &istr,
|
|||
let itr = @interner::mk::<istr>(istr::hash, istr::eq);
|
||||
let rdr = new_reader(cm, src,
|
||||
codemap::new_filemap(
|
||||
istr::to_estr(path), 0u, 0u), itr);
|
||||
path, 0u, 0u), itr);
|
||||
let comments: [cmnt] = [];
|
||||
let literals: [lit] = [];
|
||||
let first_read: bool = true;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -252,7 +252,8 @@ fn parse_and_print(code: &str) -> str {
|
|||
let filename = "tmp.rs";
|
||||
let sess = @{cm: codemap::new_codemap(), mutable next_id: 0};
|
||||
//write_file(filename, code);
|
||||
let crate = parser::parse_crate_from_source_str(filename, code, [], sess);
|
||||
let crate = parser::parse_crate_from_source_str(
|
||||
istr::from_estr(filename), istr::from_estr(code), [], sess);
|
||||
ret as_str(bind pprust::print_crate(sess.cm, crate, filename,
|
||||
io::string_reader(istr::from_estr(code)), _,
|
||||
pprust::no_ann()));
|
||||
|
@ -360,7 +361,9 @@ fn check_variants(files: &[str]) {
|
|||
log_err "check_variants: " + file;
|
||||
let sess = @{cm: codemap::new_codemap(), mutable next_id: 0};
|
||||
let crate =
|
||||
parser::parse_crate_from_source_str(file, s, [], sess);
|
||||
parser::parse_crate_from_source_str(
|
||||
istr::from_estr(file),
|
||||
istr::from_estr(s), [], sess);
|
||||
log_err as_str(bind pprust::print_crate(sess.cm, crate, file,
|
||||
io::string_reader(istr::from_estr(s)), _,
|
||||
pprust::no_ann()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue