1use crate::{block::Block, locale::LocaleFile, scope::Scope, stage::Stage, statement::Statement};
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct Symbol {
5 pub scope: Scope,
6 pub statement: Statement,
7}
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct ModuleImport {
11 pub module: String,
12 pub local: String,
13 pub items: Vec<ImportedItem>,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct ImportedItem {
18 pub name: String,
19 pub local: String,
20}
21
22#[derive(Debug, Clone, PartialEq)]
23pub struct Module {
24 pub name: String,
25 pub stage: Stage,
26 pub body: Block,
27 pub symbols: Vec<Symbol>,
28 pub imports: Vec<ModuleImport>,
29 pub submodules: Vec<String>,
30 pub locales: Vec<LocaleFile>,
32}
33
34impl Module {
35 #[must_use]
36 pub fn imported_item_local(&self, type_name: &str) -> Option<&str> {
37 self.imports
38 .iter()
39 .flat_map(|import| import.items.iter())
40 .find_map(|item| {
41 if item.name == type_name {
42 Some(item.local.as_str())
43 } else {
44 None
45 }
46 })
47 }
48
49 #[must_use]
50 pub fn is_imported_type_extension(&self, struct_decl: &crate::structure::Struct) -> bool {
51 struct_decl.fields.is_empty() && self.imported_item_local(&struct_decl.name).is_some()
52 }
53}