use super::macros::Macro;
use super::stdlib::{BuiltinFunction, Template};
use quantrs2_anneal::qubo::Variable;
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct ImportResolver {
pub paths: Vec<String>,
pub modules: HashMap<String, Module>,
pub symbols: HashMap<String, ImportedSymbol>,
}
#[derive(Debug, Clone)]
pub struct Module {
pub name: String,
pub exports: HashMap<String, ExportedItem>,
}
#[derive(Debug, Clone)]
pub enum ExportedItem {
Variable(Variable),
Function(BuiltinFunction),
Template(Template),
Macro(Macro),
}
#[derive(Debug, Clone)]
pub struct ImportedSymbol {
pub module: String,
pub original_name: String,
pub local_name: String,
}
impl ImportResolver {
pub fn new() -> Self {
Self {
paths: Vec::new(),
modules: HashMap::new(),
symbols: HashMap::new(),
}
}
pub fn add_path(&mut self, path: String) {
self.paths.push(path);
}
pub const fn load_module(&mut self, _name: &str) -> Result<(), String> {
Ok(())
}
pub fn import_symbol(
&mut self,
module: &str,
symbol: &str,
alias: Option<&str>,
) -> Result<(), String> {
let local_name = alias.unwrap_or(symbol).to_string();
self.symbols.insert(
local_name.clone(),
ImportedSymbol {
module: module.to_string(),
original_name: symbol.to_string(),
local_name,
},
);
Ok(())
}
}
impl Default for ImportResolver {
fn default() -> Self {
Self::new()
}
}