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
47
48
pub mod source_file;
use crate::Result;
use cubist_config::ContractsConfig;
use solang_parser::pt;
use source_file::SourceFile;
pub struct SourceFiles {
pub sources: Vec<SourceFile>,
}
impl SourceFiles {
pub fn new(config: &ContractsConfig) -> Result<Self> {
let sources = config
.targets
.iter()
.flat_map(|(target, target_config)| {
target_config.files().iter().map(|file| {
SourceFile::new(file, config.relative_to_root(file).unwrap(), *target)
})
})
.collect::<Result<Vec<_>>>()?;
Ok(SourceFiles { sources })
}
pub fn len(&self) -> usize {
self.sources.len()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
pub fn get_import_path(import: &pt::Import) -> &String {
match import {
pt::Import::Plain(s, ..) => &s.string,
pt::Import::GlobalSymbol(s, ..) => &s.string,
pt::Import::Rename(s, ..) => &s.string,
}
}