1use std::rc::Weak;
2
3use kodept_core::ConvertibleToRef;
4use kodept_core::structure::span::CodeHolder;
5
6use crate::graph::{AnyNode, NodeId};
7use crate::graph::{SyntaxTree, SyntaxTreeBuilder};
8use crate::rlt_accessor::{RLTFamily};
9
10pub trait Identifiable: Sized {
11 fn get_id(&self) -> NodeId<Self>;
12}
13
14impl<T: crate::graph::Identifiable> Identifiable for T {
15 fn get_id(&self) -> NodeId<Self> {
16 <Self as crate::graph::Identifiable>::get_id(self)
17 }
18}
19
20#[allow(clippy::wrong_self_convention)]
21pub trait AsEnum {
22 type Enum;
23
24 fn as_enum(self) -> Self::Enum;
25}
26
27pub trait Linker {
28 fn link<A, B>(&mut self, ast: &A, with: &B)
29 where
30 A: Identifiable + Into<AnyNode>,
31 B: Into<RLTFamily> + Clone;
32
33 fn link_existing<A, B>(&mut self, a: A, b: &B) -> A
34 where
35 A: Identifiable + Into<AnyNode>,
36 B: Identifiable + Into<AnyNode>;
37
38 fn link_by_id<A, B>(&mut self, ast_id: NodeId<A>, with: &B)
39 where
40 B: Into<RLTFamily> + Clone,
41 A: Into<AnyNode>;
42}
43
44pub trait Accessor {
45 fn access<A, B>(&self, ast: &A) -> Option<&B>
46 where
47 A: Identifiable + Into<AnyNode>,
48 RLTFamily: ConvertibleToRef<B>;
49
50 fn access_unknown<A>(&self, ast: &A) -> Option<RLTFamily>
51 where
52 A: Identifiable + Into<AnyNode>;
53
54 fn tree(&self) -> Weak<SyntaxTree>;
55}
56
57pub(crate) trait PopulateTree {
58 type Output: Into<AnyNode>;
59
60 fn convert(
61 &self,
62 builder: &mut SyntaxTreeBuilder,
63 context: &mut (impl Linker + CodeHolder),
64 ) -> NodeId<Self::Output>;
65}