diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-01-24 21:42:54 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-01-24 21:42:54 -0800 |
| commit | 9ecd5ee81d642fed89246924b240bf3d3b0b8e64 (patch) | |
| tree | c165baf881e05c443b37a1b965c8b54a8f9a3406 /src/comp/syntax/parse | |
| parent | 4d096a8c860b0f7ff0933a8606f6e39398aebaae (diff) | |
| download | rust-9ecd5ee81d642fed89246924b240bf3d3b0b8e64.tar.gz rust-9ecd5ee81d642fed89246924b240bf3d3b0b8e64.zip | |
rustc: Split diagnostics into "span diagnostics" and "diagnostics".
The former contain a codemap (which is per-crate), and the latter don't. This will be useful in order to allow more than one crate to be compiled in one run of the compiler.
Diffstat (limited to 'src/comp/syntax/parse')
| -rw-r--r-- | src/comp/syntax/parse/lexer.rs | 13 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 21 |
2 files changed, 18 insertions, 16 deletions
diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index 3dc1666b11e..f51838ef28e 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -10,7 +10,7 @@ import driver::diagnostic; type reader = @{ cm: codemap::codemap, - diagnostic: diagnostic::handler, + span_diagnostic: diagnostic::span_handler, src: str, len: uint, mutable col: uint, @@ -49,17 +49,18 @@ impl reader for reader { } else { self.curr = -1 as char; } } fn fatal(m: str) -> ! { - self.diagnostic.span_fatal( + self.span_diagnostic.span_fatal( ast_util::mk_sp(self.chpos, self.chpos), m) } } fn new_reader(cm: codemap::codemap, - diagnostic: diagnostic::handler, + span_diagnostic: diagnostic::span_handler, src: str, filemap: codemap::filemap, itr: @interner::interner<str>) -> reader { - let r = @{cm: cm, diagnostic: diagnostic, + let r = @{cm: cm, + span_diagnostic: span_diagnostic, src: src, len: str::byte_len(src), mutable col: 0u, mutable pos: 0u, mutable curr: -1 as char, mutable chpos: filemap.start_pos.ch, mutable strs: [], @@ -667,13 +668,13 @@ fn is_lit(t: token::token) -> bool { type lit = {lit: str, pos: uint}; fn gather_comments_and_literals(cm: codemap::codemap, - diagnostic: diagnostic::handler, + span_diagnostic: diagnostic::span_handler, path: str, srdr: io::reader) -> {cmnts: [cmnt], lits: [lit]} { let src = str::unsafe_from_bytes(srdr.read_whole_stream()); let itr = @interner::mk::<str>(str::hash, str::eq); - let rdr = new_reader(cm, diagnostic, src, + let rdr = new_reader(cm, span_diagnostic, src, codemap::new_filemap(path, 0u, 0u), itr); let comments: [cmnt] = []; let literals: [lit] = []; diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 1ae1cc2ecb9..504a37647b8 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -24,7 +24,7 @@ enum file_type { CRATE_FILE, SOURCE_FILE, } type parse_sess = @{ cm: codemap::codemap, mutable next_id: node_id, - diagnostic: diagnostic::handler, + span_diagnostic: diagnostic::span_handler, // these two must be kept up to date mutable chpos: uint, mutable byte_pos: uint @@ -78,13 +78,13 @@ impl parser for parser { ret self.buffer[distance - 1u].tok; } fn fatal(m: str) -> ! { - self.sess.diagnostic.span_fatal(self.span, m) + self.sess.span_diagnostic.span_fatal(self.span, m) } fn span_fatal(sp: span, m: str) -> ! { - self.sess.diagnostic.span_fatal(sp, m) + self.sess.span_diagnostic.span_fatal(sp, m) } fn warn(m: str) { - self.sess.diagnostic.span_warn(self.span, m) + self.sess.span_diagnostic.span_warn(self.span, m) } fn get_str(i: token::str_num) -> str { interner::get(*self.reader.interner, i) @@ -101,14 +101,14 @@ fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str, src } result::err(e) { - sess.diagnostic.fatal(e) + sess.span_diagnostic.handler().fatal(e) } }; let filemap = codemap::new_filemap(path, 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.diagnostic, - src, filemap, itr); + let rdr = lexer::new_reader(sess.cm, sess.span_diagnostic, src, filemap, + itr); ret new_parser(sess, cfg, rdr, ftype); } @@ -118,8 +118,8 @@ fn new_parser_from_source_str(sess: parse_sess, cfg: ast::crate_cfg, let filemap = codemap::new_filemap(name, 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.diagnostic, - source, filemap, itr); + let rdr = lexer::new_reader(sess.cm, sess.span_diagnostic, source, + filemap, itr); ret new_parser(sess, cfg, rdr, ftype); } @@ -2628,7 +2628,8 @@ fn parse_crate_from_file(input: str, cfg: ast::crate_cfg, sess: parse_sess) -> } else if str::ends_with(input, ".rs") { parse_crate_from_source_file(input, cfg, sess) } else { - sess.diagnostic.fatal("unknown input file type: " + input) + sess.span_diagnostic.handler().fatal("unknown input file type: " + + input) } } |
