2021-07-03 12:18:13 -04:00
|
|
|
use std::fmt::{self, Debug};
|
|
|
|
|
use std::hash::Hash;
|
|
|
|
|
|
|
|
|
|
pub(crate) mod tree;
|
|
|
|
|
pub(crate) use tree::Tree;
|
|
|
|
|
|
|
|
|
|
pub(crate) mod nfa;
|
|
|
|
|
pub(crate) use nfa::Nfa;
|
|
|
|
|
|
|
|
|
|
pub(crate) mod dfa;
|
|
|
|
|
pub(crate) use dfa::Dfa;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub(crate) struct Uninhabited;
|
|
|
|
|
|
|
|
|
|
/// An instance of a byte is either initialized to a particular value, or uninitialized.
|
|
|
|
|
#[derive(Hash, Eq, PartialEq, Clone, Copy)]
|
|
|
|
|
pub(crate) enum Byte {
|
|
|
|
|
Uninit,
|
|
|
|
|
Init(u8),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Debug for Byte {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
match &self {
|
|
|
|
|
Self::Uninit => f.write_str("??u8"),
|
2022-12-19 10:31:55 +01:00
|
|
|
Self::Init(b) => write!(f, "{b:#04x}u8"),
|
2021-07-03 12:18:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) trait Def: Debug + Hash + Eq + PartialEq + Copy + Clone {}
|
2023-04-21 16:49:36 -07:00
|
|
|
pub trait Ref: Debug + Hash + Eq + PartialEq + Copy + Clone {
|
|
|
|
|
fn min_align(&self) -> usize {
|
|
|
|
|
1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_mutable(&self) -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-03 12:18:13 -04:00
|
|
|
|
|
|
|
|
impl Def for ! {}
|
|
|
|
|
impl Ref for ! {}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "rustc")]
|
2023-04-21 16:49:36 -07:00
|
|
|
pub mod rustc {
|
2021-07-03 12:18:13 -04:00
|
|
|
use rustc_middle::mir::Mutability;
|
2023-04-21 16:49:36 -07:00
|
|
|
use rustc_middle::ty::{self, Ty};
|
2021-07-03 12:18:13 -04:00
|
|
|
|
2022-08-02 14:44:23 +00:00
|
|
|
/// A reference in the layout.
|
2021-07-03 12:18:13 -04:00
|
|
|
#[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Clone, Copy)]
|
|
|
|
|
pub struct Ref<'tcx> {
|
2023-04-21 16:49:36 -07:00
|
|
|
pub lifetime: ty::Region<'tcx>,
|
|
|
|
|
pub ty: Ty<'tcx>,
|
|
|
|
|
pub mutability: Mutability,
|
|
|
|
|
pub align: usize,
|
2021-07-03 12:18:13 -04:00
|
|
|
}
|
|
|
|
|
|
2023-04-21 16:49:36 -07:00
|
|
|
impl<'tcx> super::Ref for Ref<'tcx> {
|
|
|
|
|
fn min_align(&self) -> usize {
|
|
|
|
|
self.align
|
|
|
|
|
}
|
2021-07-03 12:18:13 -04:00
|
|
|
|
2023-04-21 16:49:36 -07:00
|
|
|
fn is_mutable(&self) -> bool {
|
|
|
|
|
match self.mutability {
|
|
|
|
|
Mutability::Mut => true,
|
|
|
|
|
Mutability::Not => false,
|
|
|
|
|
}
|
2021-07-03 12:18:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
2023-04-21 16:49:36 -07:00
|
|
|
impl<'tcx> Ref<'tcx> {}
|
2021-07-03 12:18:13 -04:00
|
|
|
|
2022-08-02 14:44:23 +00:00
|
|
|
/// A visibility node in the layout.
|
2021-07-03 12:18:13 -04:00
|
|
|
#[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)]
|
|
|
|
|
pub enum Def<'tcx> {
|
|
|
|
|
Adt(ty::AdtDef<'tcx>),
|
|
|
|
|
Variant(&'tcx ty::VariantDef),
|
|
|
|
|
Field(&'tcx ty::FieldDef),
|
|
|
|
|
Primitive,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'tcx> super::Def for Def<'tcx> {}
|
|
|
|
|
}
|