use rayon::iter::{IndexedParallelIterator, ParallelIterator};
use crate::{
metadata::{
diagnostics::DiagnosticCategory,
loader::{LoaderContext, MetadataLoader},
tables::NestedClassRaw,
},
prelude::TableId,
Result,
};
pub(crate) struct NestedClassLoader;
impl MetadataLoader for NestedClassLoader {
fn load(&self, context: &LoaderContext) -> Result<()> {
let Some(header) = context.meta else {
return Ok(());
};
let Some(table) = header.table::<NestedClassRaw>() else {
return Ok(());
};
table
.par_iter()
.enumerate()
.try_for_each(|(index, row)| -> Result<()> {
let Some(row) = context.handle_row(row, index)? else {
return Ok(());
};
let token_msg = || format!("nested class 0x{:08x}", row.token.value());
let Some(owned) = context.handle_result(
row.to_owned(context.types),
DiagnosticCategory::Type,
token_msg,
)?
else {
return Ok(());
};
context.handle_error(owned.apply(), DiagnosticCategory::Type, token_msg)?;
context.nested_class.insert(row.token, owned);
Ok(())
})?;
context.types.build_fullnames();
Ok(())
}
fn table_id(&self) -> Option<TableId> {
Some(TableId::NestedClass)
}
fn dependencies(&self) -> &'static [TableId] {
&[TableId::TypeDef]
}
}