diff options
| author | Kevin Atkinson <kevina@cs.utah.edu> | 2012-01-25 15:53:45 -0700 |
|---|---|---|
| committer | Kevin Atkinson <kevina@cs.utah.edu> | 2012-01-25 16:00:47 -0700 |
| commit | c5e03e0e599e49f74303bbafc6d559f3138b5f72 (patch) | |
| tree | e2c87afbd28be1b40dcff23875465b7d61fed83d /src/comp/syntax/parse/parser.rs | |
| parent | 746fa279889b3ce2ed671aa06d34f15c4f34e902 (diff) | |
| download | rust-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/syntax/parse/parser.rs')
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index eca22f38adf..eef02b5e4b7 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -98,27 +98,28 @@ fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str, let src = alt io::read_whole_file_str(path) { result::ok(src) { // FIXME: This copy is unfortunate - src + @src } result::err(e) { sess.span_diagnostic.handler().fatal(e) } }; - let filemap = codemap::new_filemap(path, sess.chpos, sess.byte_pos); + let filemap = codemap::new_filemap(path, src, + sess.chpos, sess.byte_pos); sess.cm.files += [filemap]; let itr = @interner::mk(str::hash, str::eq); - let rdr = lexer::new_reader(sess.cm, sess.span_diagnostic, src, filemap, - itr); + let rdr = lexer::new_reader(sess.cm, sess.span_diagnostic, filemap, itr); ret new_parser(sess, cfg, rdr, ftype); } fn new_parser_from_source_str(sess: parse_sess, cfg: ast::crate_cfg, - name: str, source: str) -> parser { + name: str, source: @str) -> parser { let ftype = SOURCE_FILE; - let filemap = codemap::new_filemap(name, sess.chpos, sess.byte_pos); + let filemap = codemap::new_filemap(name, source, + sess.chpos, sess.byte_pos); sess.cm.files += [filemap]; let itr = @interner::mk(str::hash, str::eq); - let rdr = lexer::new_reader(sess.cm, sess.span_diagnostic, source, + let rdr = lexer::new_reader(sess.cm, sess.span_diagnostic, filemap, itr); ret new_parser(sess, cfg, rdr, ftype); } @@ -2462,7 +2463,7 @@ fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg, } -fn parse_expr_from_source_str(name: str, source: str, cfg: ast::crate_cfg, +fn parse_expr_from_source_str(name: str, source: @str, cfg: ast::crate_cfg, sess: parse_sess) -> @ast::expr { let p = new_parser_from_source_str(sess, cfg, name, source); let r = parse_expr(p); @@ -2471,7 +2472,7 @@ fn parse_expr_from_source_str(name: str, source: str, cfg: ast::crate_cfg, ret r; } -fn parse_crate_from_source_str(name: str, source: str, cfg: ast::crate_cfg, +fn parse_crate_from_source_str(name: str, source: @str, cfg: ast::crate_cfg, sess: parse_sess) -> @ast::crate { let p = new_parser_from_source_str(sess, cfg, name, source); let r = parse_crate_mod(p, cfg); |
