use crate::{error::CompileError, warning::CompileWarning};
use core::cell::RefCell;
#[derive(Default)]
pub struct Handler {
inner: RefCell<HandlerInner>,
}
#[derive(Default)]
struct HandlerInner {
errors: Vec<CompileError>,
warnings: Vec<CompileWarning>,
}
impl Handler {
pub fn emit_err(&self, err: CompileError) -> ErrorEmitted {
self.inner.borrow_mut().errors.push(err);
ErrorEmitted { _priv: () }
}
pub fn emit_warn(&self, warn: CompileWarning) {
self.inner.borrow_mut().warnings.push(warn);
}
pub fn consume(self) -> (Vec<CompileError>, Vec<CompileWarning>) {
let inner = self.inner.into_inner();
(inner.errors, inner.warnings)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ErrorEmitted {
_priv: (),
}