context_footprint/domain/
node.rs1pub type NodeId = u32;
3
4pub type ScopeId = String;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct SourceSpan {
10 pub start_line: u32,
11 pub start_column: u32,
12 pub end_line: u32,
13 pub end_column: u32,
14}
15
16#[derive(Debug, Clone)]
18pub struct NodeCore {
19 pub id: NodeId,
20 pub name: String,
21 pub scope: Option<ScopeId>,
22 pub context_size: u32, pub span: SourceSpan,
24 pub doc_score: f32, pub is_external: bool,
26 pub file_path: String, }
28
29impl NodeCore {
30 #[allow(clippy::too_many_arguments)]
31 pub fn new(
32 id: NodeId,
33 name: String,
34 scope: Option<ScopeId>,
35 context_size: u32,
36 span: SourceSpan,
37 doc_score: f32,
38 is_external: bool,
39 file_path: String,
40 ) -> Self {
41 Self {
42 id,
43 name,
44 scope,
45 context_size,
46 span,
47 doc_score,
48 is_external,
49 file_path,
50 }
51 }
52}
53
54#[derive(Debug, Clone, PartialEq, Eq)]
56pub enum Visibility {
57 Public,
58 Private,
59 Protected,
60 Internal,
61}
62
63#[derive(Debug, Clone)]
65pub struct FunctionNode {
66 pub core: NodeCore,
67
68 pub param_count: u32,
70 pub typed_param_count: u32,
71 pub has_return_type: bool,
72
73 pub is_async: bool,
75 pub is_generator: bool,
76 pub visibility: Visibility,
77}
78
79#[derive(Debug, Clone, PartialEq, Eq)]
81pub enum Mutability {
82 Const, Immutable, Mutable, }
86
87#[derive(Debug, Clone, PartialEq, Eq)]
89pub enum VariableKind {
90 Global, ClassField, }
93
94#[derive(Debug, Clone)]
96pub struct VariableNode {
97 pub core: NodeCore,
98
99 pub has_type_annotation: bool,
101
102 pub mutability: Mutability,
104
105 pub variable_kind: VariableKind,
107}
108
109#[derive(Debug, Clone, PartialEq, Eq)]
111pub enum TypeKind {
112 Class,
113 Interface, Protocol, Struct,
116 Enum,
117 TypeAlias, FunctionType, Union, Intersection, }
122
123#[derive(Debug, Clone)]
125pub struct TypeNode {
126 pub core: NodeCore,
127
128 pub type_kind: TypeKind,
130
131 pub is_abstract: bool, pub type_param_count: u32, }
137
138#[derive(Debug, Clone)]
140pub enum Node {
141 Function(FunctionNode),
142 Variable(VariableNode),
143 Type(TypeNode),
144}
145
146impl Node {
147 pub fn core(&self) -> &NodeCore {
148 match self {
149 Node::Function(f) => &f.core,
150 Node::Variable(v) => &v.core,
151 Node::Type(t) => &t.core,
152 }
153 }
154
155 pub fn core_mut(&mut self) -> &mut NodeCore {
156 match self {
157 Node::Function(f) => &mut f.core,
158 Node::Variable(v) => &mut v.core,
159 Node::Type(t) => &mut t.core,
160 }
161 }
162}