|
1 | | -use std::cmp::Ord; |
2 | | -use std::ops; |
3 | | -use std::path::PathBuf; |
| 1 | +mod types; |
| 2 | +pub use crate::types::*; |
4 | 3 |
|
5 | | -use num_derive::FromPrimitive; |
6 | | -use serde::{Deserialize, Serialize}; |
7 | | -use serde_repr::*; |
8 | | - |
9 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
10 | | -pub enum TraceLowLevelEvent { |
11 | | - Step(StepRecord), |
12 | | - Path(PathBuf), // should be always generated before usage, so we can stop stream at random n |
13 | | - Variable(String), // interning new name for it |
14 | | - Type(TypeRecord), // should be always generated before Value referencing it |
15 | | - Value(FullValueRecord), // full values: simpler case working even without modification support |
16 | | - Function(FunctionRecord), // should be always generated before CallRecord referencing it |
17 | | - Call(CallRecord), |
18 | | - Return(ReturnRecord), |
19 | | - Event(RecordEvent), |
20 | | -} |
21 | | - |
22 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
23 | | -pub struct FullValueRecord { |
24 | | - pub variable_id: VariableId, |
25 | | - pub value: ValueRecord, |
26 | | -} |
27 | | - |
28 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
29 | | -pub struct TraceMetadata { |
30 | | - pub workdir: PathBuf, |
31 | | - pub program: String, |
32 | | - pub args: Vec<String>, |
33 | | -} |
34 | | - |
35 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
36 | | -pub struct TraceLowLevelRecord { |
37 | | - pub events: Vec<TraceLowLevelEvent>, |
38 | | -} |
39 | | - |
40 | | -// call keys: |
41 | | - |
42 | | -#[derive(Debug, Default, Copy, Clone, PartialEq, Serialize, Deserialize)] |
43 | | -#[serde(transparent)] |
44 | | -pub struct CallKey(pub i64); |
45 | | - |
46 | | -impl CallKey { |
47 | | - pub fn to_usize(self) -> usize { |
48 | | - self.0 as usize |
49 | | - } |
50 | | -} |
51 | | - |
52 | | -impl ops::Add<usize> for CallKey { |
53 | | - type Output = CallKey; |
54 | | - |
55 | | - fn add(self, arg: usize) -> Self::Output { |
56 | | - CallKey(self.0 + arg as i64) |
57 | | - } |
58 | | -} |
59 | | - |
60 | | -impl ops::AddAssign<usize> for CallKey { |
61 | | - fn add_assign(&mut self, arg: usize) { |
62 | | - self.0 += arg as i64; |
63 | | - } |
64 | | -} |
65 | | - |
66 | | -pub const NO_KEY: CallKey = CallKey(-1); |
67 | | - |
68 | | -// end of call keys code |
69 | | - |
70 | | -#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize)] |
71 | | -#[serde(transparent)] |
72 | | -pub struct Line(pub i64); |
73 | | - |
74 | | -impl Line { |
75 | | - pub fn to_usize(self) -> usize { |
76 | | - self.0 as usize |
77 | | - } |
78 | | - |
79 | | - pub fn as_i64(&self) -> i64 { |
80 | | - self.0 |
81 | | - } |
82 | | -} |
83 | | - |
84 | | -#[derive( |
85 | | - Hash, Debug, Default, Copy, Clone, Serialize, Deserialize, Ord, PartialOrd, Eq, PartialEq, |
86 | | -)] |
87 | | -#[serde(transparent)] |
88 | | -pub struct PathId(pub usize); |
89 | | - |
90 | | -#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize, Ord, PartialOrd, Eq, PartialEq)] |
91 | | -#[serde(transparent)] |
92 | | -pub struct StepId(pub i64); |
93 | | - |
94 | | -impl StepId { |
95 | | - pub fn to_usize(self) -> usize { |
96 | | - self.0 as usize |
97 | | - } |
98 | | -} |
99 | | - |
100 | | -impl ops::Add<usize> for StepId { |
101 | | - type Output = StepId; |
102 | | - |
103 | | - fn add(self, arg: usize) -> Self::Output { |
104 | | - StepId(self.0 + arg as i64) |
105 | | - } |
106 | | -} |
107 | | - |
108 | | -impl ops::Sub<usize> for StepId { |
109 | | - type Output = StepId; |
110 | | - |
111 | | - fn sub(self, arg: usize) -> Self::Output { |
112 | | - StepId(self.0 - arg as i64) |
113 | | - } |
114 | | -} |
115 | | - |
116 | | -#[derive(Debug, Copy, Clone, Serialize, Deserialize)] |
117 | | -pub struct VariableId(pub usize); |
118 | | - |
119 | | -#[derive(Debug, Copy, Clone, Serialize, Deserialize)] |
120 | | -pub struct FunctionId(pub usize); |
121 | | - |
122 | | - |
123 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
124 | | -pub struct CallRecord { |
125 | | - // pub key: CallKey, |
126 | | - pub function_id: FunctionId, |
127 | | - pub args: Vec<ArgRecord>, |
128 | | -} |
129 | | - |
130 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
131 | | -pub struct ReturnRecord { |
132 | | - // implicit by order or explicit in some cases? pub call_key: CallKey |
133 | | - pub return_value: ValueRecord, |
134 | | -} |
135 | | - |
136 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
137 | | -pub struct FunctionRecord { |
138 | | - pub path_id: PathId, |
139 | | - pub line: Line, |
140 | | - pub name: String, |
141 | | -} |
142 | | - |
143 | | - |
144 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
145 | | -pub struct ArgRecord { |
146 | | - pub name: String, |
147 | | - pub value: ValueRecord, |
148 | | -} |
149 | | - |
150 | | -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] |
151 | | -pub struct StepRecord { |
152 | | - pub path_id: PathId, |
153 | | - pub line: Line, |
154 | | -} |
155 | | - |
156 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
157 | | -pub struct VariableRecord { |
158 | | - pub name: String, |
159 | | - pub value: ValueRecord, |
160 | | -} |
161 | | - |
162 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
163 | | -pub struct TypeRecord { |
164 | | - pub kind: TypeKind, |
165 | | - pub lang_type: String, |
166 | | - pub specific_info: TypeSpecificInfo, |
167 | | -} |
168 | | - |
169 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
170 | | -pub struct FieldTypeRecord { |
171 | | - pub name: String, |
172 | | - pub typ: TypeRecord, |
173 | | -} |
174 | | - |
175 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
176 | | -#[serde(tag = "kind")] |
177 | | -pub enum TypeSpecificInfo { |
178 | | - None, |
179 | | - Struct { fields: Vec<FieldTypeRecord> }, |
180 | | -} |
181 | | - |
182 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
183 | | -pub struct RecordEvent { |
184 | | - pub kind: EventLogKind, |
185 | | - pub content: String, |
186 | | -} |
187 | | - |
188 | | -#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize, PartialEq)] |
189 | | -#[serde(transparent)] |
190 | | -pub struct TypeId(pub usize); |
191 | | - |
192 | | -// use ValueRecord for recording custom languages |
193 | | -// use value::Value for interaction with existing frontend |
194 | | -// TODO: convert between them or |
195 | | -// serialize ValueRecord in a compatible way? |
196 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
197 | | -#[serde(tag = "kind")] |
198 | | -pub enum ValueRecord { |
199 | | - Int { |
200 | | - i: i64, |
201 | | - type_id: TypeId, |
202 | | - }, |
203 | | - Float { |
204 | | - f: f64, |
205 | | - type_id: TypeId, |
206 | | - }, |
207 | | - Bool { |
208 | | - b: bool, |
209 | | - type_id: TypeId, |
210 | | - }, |
211 | | - String { |
212 | | - text: String, |
213 | | - type_id: TypeId, |
214 | | - }, |
215 | | - Sequence { |
216 | | - elements: Vec<ValueRecord>, |
217 | | - type_id: TypeId, |
218 | | - }, |
219 | | - Struct { |
220 | | - field_values: Vec<ValueRecord>, |
221 | | - type_id: TypeId, // must point to Type with STRUCT kind and TypeSpecificInfo::Struct |
222 | | - }, |
223 | | - Raw { |
224 | | - r: String, |
225 | | - type_id: TypeId, |
226 | | - }, |
227 | | - Error { |
228 | | - msg: String, |
229 | | - type_id: TypeId, |
230 | | - }, |
231 | | - None { |
232 | | - type_id: TypeId, |
233 | | - }, |
234 | | -} |
235 | | - |
236 | | - |
237 | | - |
238 | | -#[derive( |
239 | | - Debug, Default, Copy, Clone, FromPrimitive, Serialize_repr, Deserialize_repr, PartialEq, |
240 | | -)] |
241 | | -#[repr(u8)] |
242 | | -pub enum TypeKind { |
243 | | - #[default] |
244 | | - Seq, |
245 | | - Set, |
246 | | - HashSet, |
247 | | - OrderedSet, |
248 | | - Array, |
249 | | - Varargs, |
250 | | - |
251 | | - Struct, |
252 | | - |
253 | | - Int, |
254 | | - Float, |
255 | | - String, |
256 | | - CString, |
257 | | - Char, |
258 | | - Bool, |
259 | | - |
260 | | - Literal, |
261 | | - |
262 | | - Ref, |
263 | | - |
264 | | - Recursion, |
265 | | - |
266 | | - Raw, |
267 | | - |
268 | | - Enum, |
269 | | - Enum16, |
270 | | - Enum32, |
271 | | - |
272 | | - C, |
273 | | - |
274 | | - TableKind, |
275 | | - |
276 | | - Union, |
277 | | - |
278 | | - Pointer, |
279 | | - |
280 | | - Error, |
281 | | - |
282 | | - FunctionKind, |
283 | | - |
284 | | - TypeValue, |
285 | | - |
286 | | - Tuple, |
287 | | - |
288 | | - Variant, |
289 | | - |
290 | | - Html, |
291 | | - |
292 | | - None, |
293 | | - NonExpanded, |
294 | | - Any, |
295 | | - Slice, |
296 | | -} |
297 | | - |
298 | | -#[derive( |
299 | | - Debug, Default, Copy, Clone, FromPrimitive, Serialize_repr, Deserialize_repr, PartialEq, |
300 | | -)] |
301 | | -#[repr(u8)] |
302 | | -pub enum EventLogKind { |
303 | | - #[default] |
304 | | - Write, |
305 | | - WriteFile, |
306 | | - Read, |
307 | | - ReadFile, |
308 | | - // not used for now |
309 | | - ReadDir, |
310 | | - OpenDir, |
311 | | - CloseDir, |
312 | | - Socket, |
313 | | - Open, |
314 | | - // used for trace events |
315 | | - TraceLogEvent, |
316 | | -} |
0 commit comments