pub mod lean;
pub mod rust;
use std::collections::HashMap;
use crate::{
ast::{Item, Metadata, Module, span::Span},
printer::{Print, Printer},
};
use camino::Utf8PathBuf;
use hax_types::engine_api::File;
pub trait Backend {
type Printer: Printer;
fn printer(&self) -> Self::Printer {
Self::Printer::default()
}
const NAME: &'static str = Self::Printer::NAME;
fn phases(&self) -> Vec<Box<dyn crate::phase::Phase>> {
vec![]
}
fn items_to_module(&self, items: Vec<Item>) -> Vec<Module> {
let mut modules: HashMap<_, Vec<_>> = HashMap::new();
for item in items {
let module_ident = item.ident.mod_only_closest_parent();
modules.entry(module_ident).or_default().push(item);
}
modules
.into_iter()
.map(|(ident, items)| Module {
ident,
items,
meta: Metadata {
span: Span::dummy(),
attributes: vec![],
},
})
.collect()
}
fn module_path(&self, module: &Module) -> Utf8PathBuf;
}
pub fn apply_backend<B: Backend + 'static>(backend: B, mut items: Vec<Item>) -> Vec<File> {
for phase in backend.phases() {
phase.apply(&mut items);
}
let modules = backend.items_to_module(items);
modules
.into_iter()
.map(|module: Module| {
let path = backend.module_path(&module).into_string();
let (contents, _) = backend.printer().print(module);
File {
path,
contents,
sourcemap: None,
}
})
.collect()
}
#[allow(unused)]
mod prelude {
pub use super::Backend;
pub use crate::ast::identifiers::global_id::view::AnyKind;
pub use crate::ast::identifiers::*;
pub use crate::ast::literals::*;
pub use crate::ast::resugared::*;
pub use crate::ast::*;
pub use crate::printer::render_view::*;
pub use crate::printer::*;
pub use crate::symbol::Symbol;
pub use hax_rust_engine_macros::prepend_associated_functions_with;
pub use pretty::DocAllocator;
pub use pretty::DocBuilder;
pub use pretty::Pretty;
pub use pretty_ast::install_pretty_helpers;
}