about summary refs log tree commit diff
path: root/src/comp/driver
diff options
context:
space:
mode:
authorKevin Atkinson <kevina@cs.utah.edu>2012-01-25 15:53:45 -0700
committerKevin Atkinson <kevina@cs.utah.edu>2012-01-25 16:00:47 -0700
commitc5e03e0e599e49f74303bbafc6d559f3138b5f72 (patch)
treee2c87afbd28be1b40dcff23875465b7d61fed83d /src/comp/driver
parent746fa279889b3ce2ed671aa06d34f15c4f34e902 (diff)
downloadrust-c5e03e0e599e49f74303bbafc6d559f3138b5f72.tar.gz
rust-c5e03e0e599e49f74303bbafc6d559f3138b5f72.zip
Keep source file around after parsing.
Specifically box the string (to avoid unnecessary copies) and store it
in codemap::filemap.

Remove the hack in driver::diagnostic that rereads the source from the
file and instead just get the source from the filemap.

(This commit is also a prerequisite for issue #1612)
Diffstat (limited to 'src/comp/driver')
-rw-r--r--src/comp/driver/diagnostic.rs11
-rw-r--r--src/comp/driver/driver.rs10
2 files changed, 6 insertions, 15 deletions
diff --git a/src/comp/driver/diagnostic.rs b/src/comp/driver/diagnostic.rs
index 19301a91971..986087bf4d0 100644
--- a/src/comp/driver/diagnostic.rs
+++ b/src/comp/driver/diagnostic.rs
@@ -193,15 +193,6 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
     // pull out the lines
     if lines.name == "-" { ret; }
 
-    // FIXME: reading in the entire file is the worst possible way to
-    //        get access to the necessary lines.
-    let file = alt io::read_whole_file_str(lines.name) {
-      result::ok(file) { file }
-      result::err(e) {
-        // Hard to report errors while reporting an error
-        ret;
-      }
-    };
     let fm = codemap::get_filemap(cm, lines.name);
 
     // arbitrarily only print up to six lines of the error
@@ -215,7 +206,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
     // Print the offending lines
     for line: uint in display_lines {
         io::stdout().write_str(#fmt["%s:%u ", fm.name, line + 1u]);
-        let s = codemap::get_line(fm, line as int, file);
+        let s = codemap::get_line(fm, line as int);
         if !str::ends_with(s, "\n") { s += "\n"; }
         io::stdout().write_str(s);
     }
diff --git a/src/comp/driver/driver.rs b/src/comp/driver/driver.rs
index f500936aa73..8840a7a59f8 100644
--- a/src/comp/driver/driver.rs
+++ b/src/comp/driver/driver.rs
@@ -77,7 +77,7 @@ fn parse_cfgspecs(cfgspecs: [str]) -> ast::crate_cfg {
 fn input_is_stdin(filename: str) -> bool { filename == "-" }
 
 fn parse_input(sess: session, cfg: ast::crate_cfg, input: str)
-    -> {crate: @ast::crate, src: str} {
+    -> {crate: @ast::crate, src: @str} {
     let src = get_input_str(sess, input);
     let crate = if !input_is_stdin(input) {
         parser::parse_crate_from_file(input, cfg, sess.parse_sess)
@@ -87,7 +87,7 @@ fn parse_input(sess: session, cfg: ast::crate_cfg, input: str)
     {crate: crate, src: src}
 }
 
-fn get_input_str(sess: session, infile: str) -> str {
+fn get_input_str(sess: session, infile: str) -> @str {
     let stream = if !input_is_stdin(infile) {
         alt io::file_reader(infile) {
           result::ok(reader) { reader }
@@ -96,7 +96,7 @@ fn get_input_str(sess: session, infile: str) -> str {
           }
         }
     } else { io::stdin() };
-    str::unsafe_from_bytes(stream.read_whole_stream())
+    @str::unsafe_from_bytes(stream.read_whole_stream())
 }
 
 fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
@@ -141,7 +141,7 @@ enum compile_upto {
 fn compile_upto(sess: session, cfg: ast::crate_cfg,
                 input: str, upto: compile_upto,
                 outputs: option::t<output_filenames>)
-    -> {crate: @ast::crate, tcx: option::t<ty::ctxt>, src: str} {
+    -> {crate: @ast::crate, tcx: option::t<ty::ctxt>, src: @str} {
     let time_passes = sess.opts.time_passes;
     let {crate, src} =
         time(time_passes, "parsing", bind parse_input(sess, cfg, input));
@@ -300,7 +300,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
       ppm_expanded | ppm_normal {}
     }
     pprust::print_crate(sess.codemap, sess.span_diagnostic, crate, input,
-                        io::string_reader(src), io::stdout(), ann);
+                        io::string_reader(*src), io::stdout(), ann);
 }
 
 fn get_os(triple: str) -> option<session::os> {