revive_solc_json_interface/standard_json/input/settings/selection/
mod.rs

1//! The `solc --standard-json` output selection.
2
3pub mod file;
4
5use std::collections::BTreeMap;
6
7use serde::Deserialize;
8use serde::Serialize;
9
10use self::file::flag::Flag;
11use self::file::File as FileSelection;
12
13/// The `solc --standard-json` output selection.
14#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq)]
15pub struct Selection {
16    /// Only the 'all' wildcard is available for robustness reasons.
17    #[serde(default, rename = "*", skip_serializing_if = "FileSelection::is_empty")]
18    all: FileSelection,
19
20    #[serde(skip_serializing_if = "BTreeMap::is_empty", flatten)]
21    pub files: BTreeMap<String, FileSelection>,
22}
23
24impl Selection {
25    /// Creates the selection with arbitrary flags.
26    pub fn new(flags: Vec<Flag>) -> Self {
27        Self {
28            all: FileSelection::new(flags),
29            files: Default::default(),
30        }
31    }
32
33    /// Creates the selection required by our compilation process.
34    pub fn new_required() -> Self {
35        Self {
36            all: FileSelection::new_required(),
37            files: BTreeMap::new(),
38        }
39    }
40
41    /// Creates the selection required for test compilation (includes EVM bytecode).
42    pub fn new_required_for_tests() -> Self {
43        Self {
44            all: FileSelection::new_required_for_tests(),
45            files: BTreeMap::new(),
46        }
47    }
48
49    /// Creates the selection required by Yul validation process.
50    pub fn new_yul_validation() -> Self {
51        Self::new(vec![Flag::EVM])
52    }
53
54    /// Extends the output selection with another one.
55    pub fn extend(&mut self, other: Self) -> &mut Self {
56        self.all.extend(other.all);
57        self
58    }
59
60    /// Returns flags that are going to be automatically added by the compiler,
61    /// but were not explicitly requested by the user.
62    ///
63    /// Afterwards, the flags are used to prune JSON output before returning it.
64    pub fn selection_to_prune(&self) -> Self {
65        Self {
66            all: self.all.selection_to_prune(),
67            files: Default::default(),
68        }
69    }
70
71    /// Whether the flag is requested.
72    pub fn contains(&self, flag: &Flag) -> bool {
73        self.all.contains(flag)
74    }
75}