mirror of
https://github.com/salsa-rs/salsa.git
synced 2024-12-26 14:00:52 +00:00
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
use crate::compiler;
|
|
use salsa::{query_definition, query_prototype};
|
|
use std::sync::Arc;
|
|
|
|
pub trait ClassTableQueryContext: compiler::CompilerQueryContext {
|
|
query_prototype! {
|
|
/// Get the fields.
|
|
fn fields() for Fields;
|
|
|
|
/// Get the list of all classes
|
|
fn all_classes() for AllClasses;
|
|
|
|
/// Get the list of all fields
|
|
fn all_fields() for AllFields;
|
|
}
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
|
pub struct DefId(usize);
|
|
|
|
query_definition! {
|
|
pub AllClasses(_: &impl ClassTableQueryContext, (): ()) -> Arc<Vec<DefId>> {
|
|
Arc::new(vec![DefId(0), DefId(10)]) // dummy impl
|
|
}
|
|
}
|
|
|
|
query_definition! {
|
|
pub Fields(_: &impl ClassTableQueryContext, class: DefId) -> Arc<Vec<DefId>> {
|
|
Arc::new(vec![DefId(class.0 + 1), DefId(class.0 + 2)]) // dummy impl
|
|
}
|
|
}
|
|
|
|
query_definition! {
|
|
pub AllFields(query: &impl ClassTableQueryContext, (): ()) -> Arc<Vec<DefId>> {
|
|
Arc::new(
|
|
query.all_classes()
|
|
.of(())
|
|
.iter()
|
|
.cloned()
|
|
.flat_map(|def_id| {
|
|
let fields = query.fields().of(def_id);
|
|
(0..fields.len()).map(move |i| fields[i])
|
|
})
|
|
.collect()
|
|
)
|
|
}
|
|
}
|