1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/// Unique identifier for AST nodes
pub type NodeKey = u32;
/// Invalid node key constant
pub const INVALID_NODE_KEY: NodeKey = u32::MAX;
/// Language identifier
/// Apply Kaizen - Add support for additional project file types
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[repr(u8)]
pub enum Language {
Rust = 0,
TypeScript = 1,
JavaScript = 2,
Python = 3,
// Kaizen improvement - Add project documentation and configuration languages
Markdown = 4,
Makefile = 5,
Toml = 6,
Yaml = 7,
Json = 8,
Shell = 9,
C = 10,
Cpp = 11,
Cython = 12,
Kotlin = 13,
AssemblyScript = 14,
WebAssembly = 15,
}
/// Node flags for quick filtering and AST node categorization
///
/// Provides efficient bitwise operations for marking AST nodes with language-specific
/// attributes like async/await, visibility modifiers, and semantic properties.
///
/// # Examples
///
/// Basic flag manipulation:
/// ```rust,no_run
/// use pmat::models::unified_ast::NodeFlags;
///
/// let mut flags = NodeFlags::new();
/// assert!(!flags.has(NodeFlags::ASYNC));
///
/// flags.set(NodeFlags::ASYNC);
/// assert!(flags.has(NodeFlags::ASYNC));
///
/// flags.unset(NodeFlags::ASYNC);
/// assert!(!flags.has(NodeFlags::ASYNC));
/// ```
///
/// Combining multiple flags:
/// ```rust,no_run
/// use pmat::models::unified_ast::NodeFlags;
///
/// let mut flags = NodeFlags::new();
/// flags.set(NodeFlags::ASYNC | NodeFlags::EXPORTED);
///
/// assert!(flags.has(NodeFlags::ASYNC));
/// assert!(flags.has(NodeFlags::EXPORTED));
/// assert!(!flags.has(NodeFlags::PRIVATE));
/// ```
#[derive(Debug, Clone, Copy, Default)]
#[repr(transparent)]
pub struct NodeFlags(u8);
impl NodeFlags {
pub const ASYNC: u8 = 0b0000_0001;
pub const GENERATOR: u8 = 0b0000_0010;
pub const ABSTRACT: u8 = 0b0000_0100;
pub const STATIC: u8 = 0b0000_1000;
pub const CONST: u8 = 0b0001_0000;
pub const EXPORTED: u8 = 0b0010_0000;
pub const PRIVATE: u8 = 0b0100_0000;
pub const DEPRECATED: u8 = 0b1000_0000;
// C-specific flags (using a second byte in future if needed)
pub const INLINE: u8 = 0b00000001; // inline function
pub const VOLATILE: u8 = 0b00000010; // volatile variable
pub const RESTRICT: u8 = 0b00000100; // restrict pointer
pub const EXTERN: u8 = 0b00001000; // extern linkage
// C++-specific flags (can overlap with C flags as they're language-specific)
pub const VIRTUAL: u8 = 0b00000001; // virtual function
pub const OVERRIDE: u8 = 0b00000010; // override specifier
pub const FINAL: u8 = 0b00000100; // final specifier
pub const MUTABLE: u8 = 0b00001000; // mutable member
pub const CONSTEXPR: u8 = 0b00010000; // constexpr
pub const NOEXCEPT: u8 = 0b00100000; // noexcept
/// Creates a new `NodeFlags` instance with no flags set
///
/// # Examples
/// ```rust
/// use pmat::models::unified_ast::NodeFlags;
///
/// let flags = NodeFlags::new();
/// assert!(!flags.has(NodeFlags::ASYNC));
/// assert!(!flags.has(NodeFlags::EXPORTED));
/// ```
#[must_use]
pub fn new() -> Self {
Self(0)
}
/// Sets the specified flag(s) using bitwise OR
///
/// # Examples
/// ```rust
/// use pmat::models::unified_ast::NodeFlags;
///
/// let mut flags = NodeFlags::new();
/// flags.set(NodeFlags::ASYNC);
/// assert!(flags.has(NodeFlags::ASYNC));
///
/// // Set multiple flags at once
/// flags.set(NodeFlags::EXPORTED | NodeFlags::CONST);
/// assert!(flags.has(NodeFlags::EXPORTED));
/// assert!(flags.has(NodeFlags::CONST));
/// ```
pub fn set(&mut self, flag: u8) {
self.0 |= flag;
}
/// Unsets the specified flag(s) using bitwise AND NOT
///
/// # Examples
/// ```rust
/// use pmat::models::unified_ast::NodeFlags;
///
/// let mut flags = NodeFlags::new();
/// flags.set(NodeFlags::ASYNC | NodeFlags::EXPORTED);
/// assert!(flags.has(NodeFlags::ASYNC));
/// assert!(flags.has(NodeFlags::EXPORTED));
///
/// flags.unset(NodeFlags::ASYNC);
/// assert!(!flags.has(NodeFlags::ASYNC));
/// assert!(flags.has(NodeFlags::EXPORTED)); // Other flags preserved
/// ```
pub fn unset(&mut self, flag: u8) {
self.0 &= !flag;
}
/// Checks if any of the specified flag(s) are set
///
/// # Examples
/// ```rust
/// use pmat::models::unified_ast::NodeFlags;
///
/// let mut flags = NodeFlags::new();
/// flags.set(NodeFlags::ASYNC);
///
/// assert!(flags.has(NodeFlags::ASYNC));
/// assert!(!flags.has(NodeFlags::EXPORTED));
///
/// // Check multiple flags (returns true if ANY are set)
/// assert!(flags.has(NodeFlags::ASYNC | NodeFlags::EXPORTED));
/// ```
#[must_use]
pub fn has(&self, flag: u8) -> bool {
self.0 & flag != 0
}
}
/// Language-agnostic AST node kinds
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[repr(u16)]
pub enum AstKind {
// Universal constructs
Function(FunctionKind),
Class(ClassKind),
Variable(VarKind),
Import(ImportKind),
Expression(ExprKind),
Statement(StmtKind),
Type(TypeKind),
Module(ModuleKind),
Macro(MacroKind), // C-specific preprocessor macros
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum FunctionKind {
Regular,
Method,
Constructor,
Getter,
Setter,
Lambda,
Closure,
Destructor, // C++ destructor
Operator, // C++ operator overload
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ClassKind {
Regular,
Abstract,
Interface,
Trait,
Enum,
Struct,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum VarKind {
Let,
Const,
Static,
Field,
Parameter,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ImportKind {
Module,
Named,
Default,
Namespace,
Dynamic,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ExprKind {
Call,
Member,
Binary,
Unary,
Literal,
Identifier,
Array,
Object,
New, // C++ new expression
Delete, // C++ delete expression
Lambda, // C++ lambda expression
Conditional, // TypeScript conditional expression (?:)
This, // TypeScript this expression
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum StmtKind {
Block,
If,
For,
While,
Return,
Throw,
Try,
Switch,
Goto, // C-specific
Label, // C-specific
DoWhile, // C-specific
ForEach, // C++ range-based for
Catch, // C++ catch clause
Break, // break statement
Continue, // continue statement
Case, // case statement in switch
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum TypeKind {
Primitive,
Array,
Tuple,
Union,
Intersection,
Generic,
Function,
Object,
Pointer, // C-specific
Struct, // C-specific (distinct from Object)
Enum, // C-specific enum (distinct from Rust enum)
Typedef, // C-specific
Class, // C++ class
Template, // C++ template
Namespace, // C++ namespace
Alias, // C++ using alias
Interface, // TypeScript interface
Module, // TypeScript module
Annotation, // TypeScript type annotation
Mapped, // TypeScript mapped type
Conditional, // TypeScript conditional type
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ModuleKind {
File,
Namespace,
Package,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum MacroKind {
ObjectLike, // #define PI 3.14
FunctionLike, // #define MAX(a,b) ((a)>(b)?(a):(b))
Variadic, // #define DEBUG(...) fprintf(stderr, __VA_ARGS__)
Include, // #include <stdio.h>
Conditional, // #ifdef, #ifndef, #if, #elif, #else, #endif
Export, // TypeScript export macro
Decorator, // TypeScript decorator
}