common: add session context
Add a `SessionContext` trait that encapsulates diagnostic emission and
checking if certain options are set in the session. This should simplify
contexts further down the line in the compiler.
//! This crate contains the fundamental utilities used to by the rest of the
//! moore compiler.
-extern crate rustc_serialize;
-extern crate memmap;
#[macro_use]
extern crate bitflags;
+extern crate memmap;
+extern crate rustc_serialize;
pub mod errors;
pub mod lexer;
@@ -46,6 +46,18 @@ impl DiagEmitter for Session {
}
}
+impl SessionContext for Session {
+ fn has_verbosity(&self, verb: Verbosity) -> bool {
+ self.opts.verbosity.contains(verb)
+ }
+}
+
+/// Access session options and emit diagnostics.
+pub trait SessionContext: DiagEmitter {
+ /// Check if a verbosity option is set.
+ fn has_verbosity(&self, verb: Verbosity) -> bool;
+}
+
/// A set of options for a session.
///
/// The arguments passed on the command line are intended to modify these values
