2024-01-08 13:26:33 -08:00
|
|
|
use super::*;
|
|
|
|
|
2024-05-19 02:29:13 -07:00
|
|
|
#[derive(Debug)]
|
2024-01-08 13:26:33 -08:00
|
|
|
pub(crate) struct Source<'src> {
|
2024-05-18 23:38:57 -07:00
|
|
|
pub(crate) file_depth: u32,
|
2024-05-20 01:04:03 -07:00
|
|
|
pub(crate) file_path: Vec<PathBuf>,
|
2024-05-25 18:10:06 -07:00
|
|
|
pub(crate) import_offsets: Vec<usize>,
|
2024-01-08 13:26:33 -08:00
|
|
|
pub(crate) namepath: Namepath<'src>,
|
2024-05-18 23:38:57 -07:00
|
|
|
pub(crate) path: PathBuf,
|
|
|
|
pub(crate) submodule_depth: u32,
|
2024-01-11 19:00:38 -08:00
|
|
|
pub(crate) working_directory: PathBuf,
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'src> Source<'src> {
|
|
|
|
pub(crate) fn root(path: &Path) -> Self {
|
|
|
|
Self {
|
2024-05-18 23:38:57 -07:00
|
|
|
file_depth: 0,
|
2024-05-20 01:04:03 -07:00
|
|
|
file_path: vec![path.into()],
|
2024-05-25 18:10:06 -07:00
|
|
|
import_offsets: Vec::new(),
|
2024-01-08 13:26:33 -08:00
|
|
|
namepath: Namepath::default(),
|
2024-05-18 23:38:57 -07:00
|
|
|
path: path.into(),
|
|
|
|
submodule_depth: 0,
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: path.parent().unwrap().into(),
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-25 18:10:06 -07:00
|
|
|
pub(crate) fn import(&self, path: PathBuf, import_offset: usize) -> Self {
|
2024-01-08 13:26:33 -08:00
|
|
|
Self {
|
2024-05-18 23:38:57 -07:00
|
|
|
file_depth: self.file_depth + 1,
|
2024-05-20 01:04:03 -07:00
|
|
|
file_path: self
|
|
|
|
.file_path
|
|
|
|
.clone()
|
|
|
|
.into_iter()
|
|
|
|
.chain(iter::once(path.clone()))
|
|
|
|
.collect(),
|
2024-05-25 18:10:06 -07:00
|
|
|
import_offsets: self
|
|
|
|
.import_offsets
|
|
|
|
.iter()
|
|
|
|
.copied()
|
|
|
|
.chain(iter::once(import_offset))
|
|
|
|
.collect(),
|
2024-01-08 13:26:33 -08:00
|
|
|
namepath: self.namepath.clone(),
|
2024-05-18 23:38:57 -07:00
|
|
|
path,
|
|
|
|
submodule_depth: self.submodule_depth,
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: self.working_directory.clone(),
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn module(&self, name: Name<'src>, path: PathBuf) -> Self {
|
|
|
|
Self {
|
2024-05-18 23:38:57 -07:00
|
|
|
file_depth: self.file_depth + 1,
|
2024-05-20 01:04:03 -07:00
|
|
|
file_path: self
|
|
|
|
.file_path
|
|
|
|
.clone()
|
|
|
|
.into_iter()
|
|
|
|
.chain(iter::once(path.clone()))
|
|
|
|
.collect(),
|
2024-05-25 18:10:06 -07:00
|
|
|
import_offsets: Vec::new(),
|
2024-05-18 23:38:57 -07:00
|
|
|
namepath: self.namepath.join(name),
|
2024-05-20 01:04:03 -07:00
|
|
|
path: path.clone(),
|
2024-05-18 23:38:57 -07:00
|
|
|
submodule_depth: self.submodule_depth + 1,
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: path.parent().unwrap().into(),
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|