2018-09-28 15:26:53 +00:00
|
|
|
use crate::compiler;
|
|
|
|
use salsa::{query_definition, query_prototype};
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
pub trait ClassTableQueryContext: compiler::CompilerQueryContext {
|
2018-09-29 08:32:41 +00:00
|
|
|
query_prototype! {
|
2018-09-28 15:26:53 +00:00
|
|
|
/// Get the fields.
|
2018-09-29 08:32:41 +00:00
|
|
|
fn fields() for Fields;
|
2018-09-28 15:26:53 +00:00
|
|
|
|
|
|
|
/// Get the list of all classes
|
2018-09-29 08:32:41 +00:00
|
|
|
fn all_classes() for AllClasses;
|
2018-09-28 15:26:53 +00:00
|
|
|
|
|
|
|
/// Get the list of all fields
|
2018-09-29 08:32:41 +00:00
|
|
|
fn all_fields() for AllFields;
|
|
|
|
}
|
2018-09-28 15:26:53 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 15:40:20 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
|
|
|
pub struct DefId(usize);
|
2018-09-28 15:26:53 +00:00
|
|
|
|
|
|
|
query_definition! {
|
|
|
|
pub AllClasses(_: &impl ClassTableQueryContext, (): ()) -> Arc<Vec<DefId>> {
|
2018-09-28 15:40:20 +00:00
|
|
|
Arc::new(vec![DefId(0), DefId(10)]) // dummy impl
|
2018-09-28 15:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
query_definition! {
|
2018-09-28 15:40:20 +00:00
|
|
|
pub Fields(_: &impl ClassTableQueryContext, class: DefId) -> Arc<Vec<DefId>> {
|
|
|
|
Arc::new(vec![DefId(class.0 + 1), DefId(class.0 + 2)]) // dummy impl
|
2018-09-28 15:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
query_definition! {
|
2018-09-28 15:40:20 +00:00
|
|
|
pub AllFields(query: &impl ClassTableQueryContext, (): ()) -> Arc<Vec<DefId>> {
|
2018-09-28 15:26:53 +00:00
|
|
|
Arc::new(
|
|
|
|
query.all_classes()
|
|
|
|
.of(())
|
|
|
|
.iter()
|
|
|
|
.cloned()
|
|
|
|
.flat_map(|def_id| {
|
|
|
|
let fields = query.fields().of(def_id);
|
2018-09-28 15:40:20 +00:00
|
|
|
(0..fields.len()).map(move |i| fields[i])
|
2018-09-28 15:26:53 +00:00
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|