1use std::fmt;
2
3use crate::node_map::HirNodeKind;
4
5#[derive(Clone, Copy, Hash, Eq, PartialEq)]
6pub struct HirId(pub(crate) usize);
7
8impl HirId {
9 pub const DUMMY: Self = HirId(usize::MAX);
10}
11
12impl fmt::Debug for HirId {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) }
14}
15
16impl fmt::Display for HirId {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) }
18}
19
20pub trait HirNode<'hir> {
21 fn get_hir_id(&self) -> HirId;
22 fn set_hir_id(&mut self, id: HirId);
23 fn get_hir_node_kind(&'hir self) -> HirNodeKind<'hir>;
24}
25
26#[macro_export]
27macro_rules! impl_hir_node {
28 ($s:ty, $var:ident) => {
29 impl<'hir> HirNode<'hir> for $s {
30 fn get_hir_id(&self) -> HirId { self.id }
31
32 fn get_hir_node_kind(&'hir self) -> HirNodeKind<'hir> { HirNodeKind::$var(self) }
33
34 fn set_hir_id(&mut self, id: HirId) { self.id = id; }
35 }
36 };
37}