Add debugging interface.

This commit is contained in:
Stephen Chung
2022-01-24 17:04:40 +08:00
parent 182870c9ed
commit fc87dec128
24 changed files with 1255 additions and 414 deletions

View File

@@ -811,7 +811,7 @@ impl AsRef<crate::Shared<crate::Module>> for AST {
/// _(internals)_ An [`AST`] node, consisting of either an [`Expr`] or a [`Stmt`].
/// Exported under the `internals` feature only.
#[derive(Debug, Clone, Hash)]
#[derive(Debug, Clone, Copy, Hash)]
pub enum ASTNode<'a> {
/// A statement ([`Stmt`]).
Stmt(&'a Stmt),
@@ -831,6 +831,19 @@ impl<'a> From<&'a Expr> for ASTNode<'a> {
}
}
impl PartialEq for ASTNode<'_> {
#[inline(always)]
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Stmt(x), Self::Stmt(y)) => std::ptr::eq(*x, *y),
(Self::Expr(x), Self::Expr(y)) => std::ptr::eq(*x, *y),
_ => false,
}
}
}
impl Eq for ASTNode<'_> {}
impl ASTNode<'_> {
/// Get the [`Position`] of this [`ASTNode`].
pub const fn position(&self) -> Position {