use std::{cell::Cell, default::Default};
use crate::{Code, CodeId, Config, InputFiles};
#[derive(Debug, Eq, PartialEq, Copy, Clone, Ord, PartialOrd, Hash)]
pub struct CompilationId(pub u32);
#[derive(Debug)]
pub struct CompileContext {
pub compilation_id: CompilationId,
pub config: Config,
pub input_files: InputFiles,
current_uid: Cell<usize>,
}
impl CompileContext {
pub fn new(compilation_id: CompilationId) -> Self {
CompileContext {
compilation_id,
config: Default::default(),
input_files: Default::default(),
current_uid: Default::default(),
}
}
pub fn add_input_file(&mut self, code: Code) -> CodeId {
self.input_files.add_input(code)
}
pub fn get_input_file(&self, id: CodeId) -> &Code {
self.input_files.get_input(id)
}
pub fn get_unique_id(&self) -> usize {
let old = self.current_uid.get();
self.current_uid.set(old + 1);
old
}
}