1#[macro_use]
7extern crate bitflags;
8
9#[macro_use]
10pub mod arenas;
11pub mod errors;
12pub mod grind;
13pub mod id;
14pub mod lexer;
15pub mod name;
16pub mod score;
17pub mod source;
18pub mod util;
19
20pub use self::id::NodeId;
21use crate::errors::{DiagBuilder2, DiagEmitter, Severity};
22use std::cell::Cell;
23
24pub struct Session {
25 pub opts: SessionOptions,
26 pub failed: Cell<bool>,
28}
29
30impl Session {
31 pub fn new() -> Session {
33 Session {
34 opts: Default::default(),
35 failed: Cell::new(false),
36 }
37 }
38
39 pub fn failed(&self) -> bool {
40 self.failed.get()
41 }
42}
43
44impl DiagEmitter for Session {
45 fn emit(&self, diag: DiagBuilder2) {
46 if diag.severity >= Severity::Error {
47 self.failed.set(true);
48 }
49 eprintln!("{}", diag);
50 }
51}
52
53impl SessionContext for Session {
54 fn has_verbosity(&self, verb: Verbosity) -> bool {
55 self.opts.verbosity.contains(verb)
56 }
57}
58
59pub trait SessionContext: DiagEmitter {
61 fn has_verbosity(&self, verb: Verbosity) -> bool;
63}
64
65#[derive(Debug, Default)]
70pub struct SessionOptions {
71 pub ignore_duplicate_defs: bool,
72 pub trace_scoreboard: bool,
74 pub verbosity: Verbosity,
76 pub opt_level: usize,
78}
79
80bitflags! {
81 #[derive(Default)]
85 pub struct Verbosity: u16 {
86 const TYPES = 1 << 0;
87 const EXPR_TYPES = 1 << 1;
88 const TYPE_CONTEXTS = 1 << 2;
89 const TYPECK = 1 << 3;
90 const NAMES = 1 << 4;
91 const CASTS = 1 << 5;
92 const PORTS = 1 << 6;
93 const CONSTS = 1 << 7;
94 const INSTS = 1 << 8;
95 const FUNC_ARGS = 1 << 9;
96 const CALL_ARGS = 1 << 10;
97 }
98}