pub fn build_session_(sopts: @session::options,
cm: @codemap::CodeMap,
demitter: @diagnostic::Emitter,
- span_diagnostic_handler: @mut diagnostic::span_handler)
+ span_diagnostic_handler: @mut diagnostic::SpanHandler)
-> Session {
let target_cfg = build_target_config(sopts, demitter);
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler,
// For a library crate, this is always none
entry_fn: RefCell<Option<(NodeId, codemap::Span)>>,
entry_type: Cell<Option<EntryFnType>>,
- span_diagnostic: @mut diagnostic::span_handler,
+ span_diagnostic: @mut diagnostic::SpanHandler,
filesearch: @filesearch::FileSearch,
building_library: Cell<bool>,
working_dir: Path,
v
}
- pub fn diagnostic(&self) -> @mut diagnostic::span_handler {
+ pub fn diagnostic(&self) -> @mut diagnostic::SpanHandler {
self.span_diagnostic
}
pub fn debugging_opt(&self, opt: uint) -> bool {
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{Span, dummy_sp};
-use syntax::diagnostic::span_handler;
+use syntax::diagnostic::SpanHandler;
use syntax::parse::token;
use syntax::parse::token::ident_interner;
use syntax::crateid::CrateId;
}
fn warn_if_multiple_versions(e: &mut Env,
- diag: @mut span_handler,
+ diag: @mut SpanHandler,
crate_cache: &[cache_entry]) {
if crate_cache.len() != 0u {
let name = crate_cache[crate_cache.len() - 1].crateid.name.clone();
use syntax::ast_util::*;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
-use syntax::diagnostic::span_handler;
+use syntax::diagnostic::SpanHandler;
use syntax::parse::token::special_idents;
use syntax::ast_util;
use syntax::visit::Visitor;
ii: ast::inlined_item|;
pub struct EncodeParams<'a> {
- diag: @mut span_handler,
+ diag: @mut SpanHandler,
tcx: ty::ctxt,
reexports2: middle::resolve::ExportMap2,
item_symbols: &'a RefCell<HashMap<ast::NodeId, ~str>>,
}
pub struct EncodeContext<'a> {
- diag: @mut span_handler,
+ diag: @mut SpanHandler,
tcx: ty::ctxt,
stats: @Stats,
reexports2: middle::resolve::ExportMap2,
use metadata::filesearch::{FileMatches, FileDoesntMatch};
use metadata::filesearch;
use syntax::codemap::Span;
-use syntax::diagnostic::span_handler;
+use syntax::diagnostic::SpanHandler;
use syntax::parse::token::ident_interner;
use syntax::crateid::CrateId;
use syntax::attr;
}
}
-pub fn note_crateid_attr(diag: @mut span_handler,
- crateid: &CrateId) {
+pub fn note_crateid_attr(diag: @mut SpanHandler,
+ crateid: &CrateId) {
diag.handler().note(format!("crate_id: {}", crateid.to_str()));
}
use syntax::abi::AbiSet;
use syntax::ast;
use syntax::ast::*;
-use syntax::diagnostic::span_handler;
+use syntax::diagnostic::SpanHandler;
use syntax::print::pprust::*;
macro_rules! mywrite( ($wr:expr, $($arg:tt)*) => (
) )
pub struct ctxt {
- diag: @mut span_handler,
+ diag: @mut SpanHandler,
// Def -> str Callback:
ds: extern "Rust" fn(DefId) -> ~str,
// The type context.
/// generates so that so that it can be reused and doesn't have to be redone
/// later on.
struct ctxt_ {
- diag: @mut syntax::diagnostic::span_handler,
+ diag: @mut syntax::diagnostic::SpanHandler,
interner: RefCell<HashMap<intern_key, ~t_box_>>,
next_id: Cell<uint>,
cstore: @metadata::cstore::CStore,
use ast_util;
use codemap::Span;
use codemap;
-use diagnostic::span_handler;
+use diagnostic::SpanHandler;
use parse::token::get_ident_interner;
use parse::token::ident_interner;
use parse::token::special_idents;
pub struct Ctx {
map: map,
path: path,
- diag: @mut span_handler,
+ diag: @mut SpanHandler,
}
impl Ctx {
}
}
-pub fn map_crate(diag: @mut span_handler, c: &Crate) -> map {
+pub fn map_crate(diag: @mut SpanHandler, c: &Crate) -> map {
let cx = @mut Ctx {
map: @mut HashMap::new(),
path: ~[],
// Used for items loaded from external crate that are being inlined into this
// crate. The `path` should be the path to the item but should not include
// the item itself.
-pub fn map_decoded_item(diag: @mut span_handler,
+pub fn map_decoded_item(diag: @mut SpanHandler,
map: map,
path: path,
ii: &inlined_item) {
use ast::{Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList};
use codemap::{Span, Spanned, spanned, dummy_spanned};
use codemap::BytePos;
-use diagnostic::span_handler;
+use diagnostic::SpanHandler;
use parse::comments::{doc_comment_style, strip_doc_comment_decoration};
use crateid::CrateId;
None
}
-pub fn require_unique_names(diagnostic: @mut span_handler,
+pub fn require_unique_names(diagnostic: @mut SpanHandler,
metas: &[@MetaItem]) {
let mut set = HashSet::new();
for meta in metas.iter() {
* present (before fields, if any) with that type; reprensentation
* optimizations which would remove it will not be done.
*/
-pub fn find_repr_attr(diagnostic: @mut span_handler, attr: @ast::MetaItem, acc: ReprAttr)
+pub fn find_repr_attr(diagnostic: @mut SpanHandler, attr: @ast::MetaItem, acc: ReprAttr)
-> ReprAttr {
let mut acc = acc;
match attr.node {
lvl: level);
}
-// a handler deals with errors; certain errors
-// (fatal, bug, unimpl) may cause immediate exit,
-// others log errors for later reporting.
-pub trait handler {
- fn fatal(@mut self, msg: &str) -> !;
- fn err(@mut self, msg: &str);
- fn bump_err_count(@mut self);
- fn err_count(@mut self) -> uint;
- fn has_errors(@mut self) -> bool;
- fn abort_if_errors(@mut self);
- fn warn(@mut self, msg: &str);
- fn note(@mut self, msg: &str);
- // used to indicate a bug in the compiler:
- fn bug(@mut self, msg: &str) -> !;
- fn unimpl(@mut self, msg: &str) -> !;
- fn emit(@mut self,
- cmsp: Option<(@codemap::CodeMap, Span)>,
- msg: &str,
- lvl: level);
-}
-
// a span-handler is like a handler but also
// accepts span information for source-location
// reporting.
-pub trait span_handler {
- fn span_fatal(@mut self, sp: Span, msg: &str) -> !;
- fn span_err(@mut self, sp: Span, msg: &str);
- fn span_warn(@mut self, sp: Span, msg: &str);
- fn span_note(@mut self, sp: Span, msg: &str);
- fn span_bug(@mut self, sp: Span, msg: &str) -> !;
- fn span_unimpl(@mut self, sp: Span, msg: &str) -> !;
- fn handler(@mut self) -> @mut handler;
-}
-
-struct HandlerT {
- err_count: uint,
- emit: @Emitter,
-}
-
-struct CodemapT {
- handler: @mut handler,
+pub struct SpanHandler {
+ handler: @mut Handler,
cm: @codemap::CodeMap,
}
-impl span_handler for CodemapT {
- fn span_fatal(@mut self, sp: Span, msg: &str) -> ! {
+impl SpanHandler {
+ pub fn span_fatal(@mut self, sp: Span, msg: &str) -> ! {
self.handler.emit(Some((self.cm, sp)), msg, fatal);
fail!();
}
- fn span_err(@mut self, sp: Span, msg: &str) {
+ pub fn span_err(@mut self, sp: Span, msg: &str) {
self.handler.emit(Some((self.cm, sp)), msg, error);
self.handler.bump_err_count();
}
- fn span_warn(@mut self, sp: Span, msg: &str) {
+ pub fn span_warn(@mut self, sp: Span, msg: &str) {
self.handler.emit(Some((self.cm, sp)), msg, warning);
}
- fn span_note(@mut self, sp: Span, msg: &str) {
+ pub fn span_note(@mut self, sp: Span, msg: &str) {
self.handler.emit(Some((self.cm, sp)), msg, note);
}
- fn span_bug(@mut self, sp: Span, msg: &str) -> ! {
+ pub fn span_bug(@mut self, sp: Span, msg: &str) -> ! {
self.span_fatal(sp, ice_msg(msg));
}
- fn span_unimpl(@mut self, sp: Span, msg: &str) -> ! {
+ pub fn span_unimpl(@mut self, sp: Span, msg: &str) -> ! {
self.span_bug(sp, ~"unimplemented " + msg);
}
- fn handler(@mut self) -> @mut handler {
+ pub fn handler(@mut self) -> @mut Handler {
self.handler
}
}
-impl handler for HandlerT {
- fn fatal(@mut self, msg: &str) -> ! {
+// a handler deals with errors; certain errors
+// (fatal, bug, unimpl) may cause immediate exit,
+// others log errors for later reporting.
+pub struct Handler {
+ err_count: uint,
+ emit: @Emitter,
+}
+
+impl Handler {
+ pub fn fatal(@mut self, msg: &str) -> ! {
self.emit.emit(None, msg, fatal);
fail!();
}
- fn err(@mut self, msg: &str) {
+ pub fn err(@mut self, msg: &str) {
self.emit.emit(None, msg, error);
self.bump_err_count();
}
- fn bump_err_count(@mut self) {
+ pub fn bump_err_count(@mut self) {
self.err_count += 1u;
}
- fn err_count(@mut self) -> uint {
+ pub fn err_count(@mut self) -> uint {
self.err_count
}
- fn has_errors(@mut self) -> bool {
+ pub fn has_errors(@mut self) -> bool {
self.err_count > 0u
}
- fn abort_if_errors(@mut self) {
+ pub fn abort_if_errors(@mut self) {
let s;
match self.err_count {
0u => return,
}
self.fatal(s);
}
- fn warn(@mut self, msg: &str) {
+ pub fn warn(@mut self, msg: &str) {
self.emit.emit(None, msg, warning);
}
- fn note(@mut self, msg: &str) {
+ pub fn note(@mut self, msg: &str) {
self.emit.emit(None, msg, note);
}
- fn bug(@mut self, msg: &str) -> ! {
+ pub fn bug(@mut self, msg: &str) -> ! {
self.fatal(ice_msg(msg));
}
- fn unimpl(@mut self, msg: &str) -> ! {
+ pub fn unimpl(@mut self, msg: &str) -> ! {
self.bug(~"unimplemented " + msg);
}
- fn emit(@mut self,
+ pub fn emit(@mut self,
cmsp: Option<(@codemap::CodeMap, Span)>,
msg: &str,
lvl: level) {
\nWe would appreciate a bug report: {}", msg, BUG_REPORT_URL)
}
-pub fn mk_span_handler(handler: @mut handler, cm: @codemap::CodeMap)
- -> @mut span_handler {
- @mut CodemapT {
+pub fn mk_span_handler(handler: @mut Handler, cm: @codemap::CodeMap)
+ -> @mut SpanHandler {
+ @mut SpanHandler {
handler: handler,
cm: cm,
- } as @mut span_handler
+ }
}
-pub fn mk_handler(emitter: Option<@Emitter>) -> @mut handler {
+pub fn mk_handler(emitter: Option<@Emitter>) -> @mut Handler {
let emit: @Emitter = match emitter {
Some(e) => e,
None => @DefaultEmitter as @Emitter
};
- @mut HandlerT {
+ @mut Handler {
err_count: 0,
emit: emit,
- } as @mut handler
+ }
}
#[deriving(Eq)]
}
pub fn expect<T:Clone>(
- diag: @mut span_handler,
+ diag: @mut SpanHandler,
opt: Option<T>,
msg: || -> ~str)
-> T {
use ast::Name;
use codemap;
use codemap::{CodeMap, Span, ExpnInfo};
-use diagnostic::span_handler;
use ext;
use ext::expand;
use parse;
use ast;
use ast::{token_tree, tt_delim, tt_tok, tt_seq, tt_nonterminal,Ident};
use codemap::{Span, dummy_sp};
-use diagnostic::span_handler;
+use diagnostic::SpanHandler;
use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal};
use parse::token::{EOF, INTERPOLATED, IDENT, Token, nt_ident};
use parse::token::{ident_to_str};
}
pub struct TtReader {
- sp_diag: @mut span_handler,
+ sp_diag: @mut SpanHandler,
// the unzipped tree:
stack: @mut TtFrame,
/* for MBE-style macro transcription */
/** This can do Macro-By-Example transcription. On the other hand, if
* `src` contains no `tt_seq`s and `tt_nonterminal`s, `interp` can (and
* should) be none. */
-pub fn new_tt_reader(sp_diag: @mut span_handler,
+pub fn new_tt_reader(sp_diag: @mut SpanHandler,
interp: Option<HashMap<Ident,@named_match>>,
src: ~[ast::token_tree])
-> @mut TtReader {
// it appears this function is called only from pprust... that's
// probably not a good thing.
pub fn gather_comments_and_literals(span_diagnostic:
- @mut diagnostic::span_handler,
+ @mut diagnostic::SpanHandler,
path: @str,
srdr: &mut io::Reader)
-> (~[cmnt], ~[lit]) {
use ast;
use codemap::{BytePos, CharPos, CodeMap, Pos, Span};
use codemap;
-use diagnostic::span_handler;
+use diagnostic::SpanHandler;
use ext::tt::transcribe::{tt_next_token};
use ext::tt::transcribe::{dup_tt_reader};
use parse::token;
fn is_eof(@mut self) -> bool;
fn next_token(@mut self) -> TokenAndSpan;
fn fatal(@mut self, ~str) -> !;
- fn span_diag(@mut self) -> @mut span_handler;
+ fn span_diag(@mut self) -> @mut SpanHandler;
fn peek(@mut self) -> TokenAndSpan;
fn dup(@mut self) -> @mut reader;
}
}
pub struct StringReader {
- span_diagnostic: @mut span_handler,
+ span_diagnostic: @mut SpanHandler,
src: @str,
// The absolute offset within the codemap of the next character to read
pos: BytePos,
peek_span: Span
}
-pub fn new_string_reader(span_diagnostic: @mut span_handler,
+pub fn new_string_reader(span_diagnostic: @mut SpanHandler,
filemap: @codemap::FileMap)
-> @mut StringReader {
let r = new_low_level_string_reader(span_diagnostic, filemap);
}
/* For comments.rs, which hackily pokes into 'pos' and 'curr' */
-pub fn new_low_level_string_reader(span_diagnostic: @mut span_handler,
+pub fn new_low_level_string_reader(span_diagnostic: @mut SpanHandler,
filemap: @codemap::FileMap)
-> @mut StringReader {
// Force the initial reader bump to start on a fresh line
fn fatal(@mut self, m: ~str) -> ! {
self.span_diagnostic.span_fatal(self.peek_span, m)
}
- fn span_diag(@mut self) -> @mut span_handler { self.span_diagnostic }
+ fn span_diag(@mut self) -> @mut SpanHandler { self.span_diagnostic }
fn peek(@mut self) -> TokenAndSpan {
// XXX(pcwalton): Bad copy!
TokenAndSpan {
fn fatal(@mut self, m: ~str) -> ! {
self.sp_diag.span_fatal(self.cur_span, m);
}
- fn span_diag(@mut self) -> @mut span_handler { self.sp_diag }
+ fn span_diag(@mut self) -> @mut SpanHandler { self.sp_diag }
fn peek(@mut self) -> TokenAndSpan {
TokenAndSpan {
tok: self.cur_tok.clone(),
use ast;
use codemap::{Span, CodeMap, FileMap, FileSubstr};
use codemap;
-use diagnostic::{span_handler, mk_span_handler, mk_handler, Emitter};
+use diagnostic::{SpanHandler, mk_span_handler, mk_handler, Emitter};
use parse::attr::parser_attr;
use parse::lexer::reader;
use parse::parser::Parser;
// info about a parsing session.
pub struct ParseSess {
cm: @codemap::CodeMap, // better be the same as the one in the reader!
- span_diagnostic: @mut span_handler, // better be the same as the one in the reader!
+ span_diagnostic: @mut SpanHandler, // better be the same as the one in the reader!
/// Used to determine and report recursive mod inclusions
included_mod_stack: ~[Path],
}
}
}
-pub fn new_parse_sess_special_handler(sh: @mut span_handler,
+pub fn new_parse_sess_special_handler(sh: @mut SpanHandler,
cm: @codemap::CodeMap)
-> @mut ParseSess {
@mut ParseSess {
// copy forward.
pub fn print_crate(cm: @CodeMap,
intr: @ident_interner,
- span_diagnostic: @mut diagnostic::span_handler,
+ span_diagnostic: @mut diagnostic::SpanHandler,
crate: &ast::Crate,
filename: @str,
input: @mut io::Reader,