1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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: (),
}