1use crate::functions::FunctionData;
2use crate::interning::StringId;
3use crate::location::Location;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ModuleData {
8 pub name: StringId,
9 pub functions: Vec<FunctionData>,
10 pub dialects: Vec<StringId>,
11 pub location: Location,
12}
13
14impl ModuleData {
15 pub fn new(name: StringId) -> Self {
16 Self {
17 name,
18 functions: Vec::new(),
19 dialects: Vec::new(),
20 location: Location::unknown(),
21 }
22 }
23
24 pub fn add_function(&mut self, func: FunctionData) {
25 self.functions.push(func);
26 }
27
28 pub fn num_functions(&self) -> usize {
29 self.functions.len()
30 }
31
32 pub fn find_function(&self, name: StringId) -> Option<&FunctionData> {
33 self.functions.iter().find(|f| f.name == name)
34 }
35}