#[path = "types/expr_lookup.rs"]
mod expr_lookup;
pub use expr_lookup::ExprIdLookup;
use crate::GqlType;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct ExprId(u32);
impl ExprId {
pub(crate) const fn new(raw: u32) -> Self {
Self(raw)
}
#[must_use]
pub const fn get(self) -> u32 {
self.0
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum AnalyzedType {
Resolved(GqlType),
Dynamic,
}
impl AnalyzedType {
pub const DYNAMIC: Self = Self::Dynamic;
#[must_use]
pub const fn is_dynamic(&self) -> bool {
matches!(self, Self::Dynamic)
}
#[must_use]
pub const fn is_resolved(&self) -> bool {
matches!(self, Self::Resolved(_))
}
}
#[derive(Clone, Debug, Default)]
pub struct ExprTypeTable {
cells: Vec<AnalyzedType>,
}
impl ExprTypeTable {
pub(crate) fn push(&mut self, ty: AnalyzedType) -> ExprId {
let id = ExprId::new(self.cells.len() as u32);
self.cells.push(ty);
id
}
#[must_use]
pub fn get(&self, id: ExprId) -> &AnalyzedType {
&self.cells[id.0 as usize]
}
#[must_use]
pub fn try_get(&self, id: ExprId) -> Option<&AnalyzedType> {
self.cells.get(id.0 as usize)
}
#[must_use]
pub fn len(&self) -> usize {
self.cells.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.cells.is_empty()
}
pub fn iter(&self) -> impl Iterator<Item = (ExprId, &AnalyzedType)> {
self.cells
.iter()
.enumerate()
.map(|(index, ty)| (ExprId::new(index as u32), ty))
}
}