2018-09-28 15:26:53 +00:00
|
|
|
use crate::compiler;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2019-01-25 15:25:17 +00:00
|
|
|
#[salsa::query_group(ClassTable)]
|
2019-01-12 10:11:59 +00:00
|
|
|
pub trait ClassTableDatabase: compiler::CompilerDatabase {
|
|
|
|
/// Get the fields.
|
|
|
|
fn fields(&self, class: DefId) -> Arc<Vec<DefId>>;
|
2018-09-28 15:26:53 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
/// Get the list of all classes
|
|
|
|
fn all_classes(&self) -> Arc<Vec<DefId>>;
|
2018-09-28 15:26:53 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
/// Get the list of all fields
|
|
|
|
fn all_fields(&self) -> Arc<Vec<DefId>>;
|
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
|
|
|
|
2018-10-19 01:26:48 +00:00
|
|
|
fn all_classes(_: &impl ClassTableDatabase) -> Arc<Vec<DefId>> {
|
2018-10-05 14:30:17 +00:00
|
|
|
Arc::new(vec![DefId(0), DefId(10)]) // dummy impl
|
2018-09-28 15:26:53 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 14:30:17 +00:00
|
|
|
fn fields(_: &impl ClassTableDatabase, 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
|
|
|
}
|
|
|
|
|
2018-10-19 01:26:48 +00:00
|
|
|
fn all_fields(db: &impl ClassTableDatabase) -> Arc<Vec<DefId>> {
|
2018-10-05 14:30:17 +00:00
|
|
|
Arc::new(
|
2018-10-19 01:26:48 +00:00
|
|
|
db.all_classes()
|
2018-10-05 14:30:17 +00:00
|
|
|
.iter()
|
|
|
|
.cloned()
|
|
|
|
.flat_map(|def_id| {
|
|
|
|
let fields = db.fields(def_id);
|
|
|
|
(0..fields.len()).map(move |i| fields[i])
|
2018-10-19 01:26:48 +00:00
|
|
|
})
|
|
|
|
.collect(),
|
2018-10-05 14:30:17 +00:00
|
|
|
)
|
2018-09-28 15:26:53 +00:00
|
|
|
}
|