use leo_span::Symbol;
use crate::{Composite, ConstDeclaration, Function, Indent, Interface, Module};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Library {
pub name: Symbol,
pub modules: IndexMap<Vec<Symbol>, Module>,
pub consts: Vec<(Symbol, ConstDeclaration)>,
pub structs: Vec<(Symbol, Composite)>,
pub functions: Vec<(Symbol, Function)>,
pub interfaces: Vec<(Symbol, Interface)>,
}
impl fmt::Display for Library {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "library {} {{", self.name)?;
for (_, interface) in self.interfaces.iter() {
writeln!(f, "{}", Indent(interface))?;
}
for (_, struct_def) in self.structs.iter() {
writeln!(f, "{}", Indent(struct_def))?;
}
for (_, const_decl) in self.consts.iter() {
writeln!(f, "{};", Indent(const_decl))?;
}
for (_, func) in self.functions.iter() {
writeln!(f, "{}", Indent(func))?;
}
for (_, module) in self.modules.iter() {
writeln!(f, "{}", module)?;
}
writeln!(f, "}}")
}
}