sway_core/language/parsed/
module.rs

1use crate::{
2    language::{HasModule, HasSubmodules, ModName, Visibility},
3    transform,
4};
5
6use super::ParseTree;
7use sway_types::Span;
8
9pub type ModuleHash = u64;
10pub type ModuleEvaluationOrder = Vec<ModName>;
11
12/// A module and its submodules in the form of a tree.
13#[derive(Debug, Clone)]
14pub struct ParseModule {
15    /// The content of this module in the form of a `ParseTree`.
16    pub tree: ParseTree,
17    /// Submodules introduced within this module using the `dep` syntax in order of declaration.
18    pub submodules: Vec<(ModName, ParseSubmodule)>,
19    pub attributes: transform::AttributesMap,
20    /// The span of the module kind.
21    pub module_kind_span: Span,
22    /// Evaluation order for the submodules
23    pub module_eval_order: ModuleEvaluationOrder,
24    /// an empty span at the beginning of the file containing the module
25    pub span: Span,
26    /// an hash used for caching the module
27    pub hash: ModuleHash,
28}
29
30/// A library module that was declared as a `mod` of another module.
31///
32/// Only submodules are guaranteed to be a `library`.
33#[derive(Debug, Clone)]
34pub struct ParseSubmodule {
35    pub module: ParseModule,
36    pub mod_name_span: Span,
37    pub visibility: Visibility,
38}
39
40impl HasModule<ParseModule> for ParseSubmodule {
41    fn module(&self) -> &ParseModule {
42        &self.module
43    }
44}
45
46impl HasSubmodules<ParseSubmodule> for ParseModule {
47    fn submodules(&self) -> &[(ModName, ParseSubmodule)] {
48        &self.submodules
49    }
50}