cairo_lang_sierra_generator/debug_info/
mod.rs1use cairo_lang_defs::diagnostic_utils::StableLocation;
2use cairo_lang_filesystem::ids::FileLongId;
3use salsa::Database;
4use serde::{Deserialize, Serialize};
5
6mod function_debug_info;
7mod statements_locations;
8mod type_names;
9
10pub use function_debug_info::serializable::{
11 SerializableAllFunctionsDebugInfo, SerializableFunctionDebugInfo,
12};
13pub use function_debug_info::{AllFunctionsDebugInfo, FunctionDebugInfo};
14pub use statements_locations::StatementsLocations;
15pub use statements_locations::statements_code_locations::StatementsSourceCodeLocations;
16pub use statements_locations::statements_functions::StatementsFunctions;
17pub use type_names::{EnumInfo, SerializableTypeNamesDebugInfo, SierraTypeId, StructInfo};
18
19#[derive(Clone, Debug, Eq, PartialEq)]
20pub struct SierraProgramDebugInfo<'db> {
21 pub statements_locations: StatementsLocations<'db>,
22 pub functions_info: AllFunctionsDebugInfo<'db>,
23}
24
25#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
27pub struct SourceFileFullPath(pub String);
28
29#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
31pub struct SourceCodeLocation {
32 pub line: usize,
34 pub col: usize,
36}
37
38#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
40pub struct SourceCodeSpan {
41 pub start: SourceCodeLocation,
43 pub end: SourceCodeLocation,
45}
46
47impl SourceCodeSpan {
48 pub fn contains(&self, other: &Self) -> bool {
49 self.start <= other.start && self.end >= other.end
50 }
51}
52
53fn maybe_code_location<'db>(
57 db: &'db dyn Database,
58 location: StableLocation<'db>,
59) -> Option<(SourceFileFullPath, SourceCodeSpan, bool)> {
60 let is_macro =
61 matches!(location.file_id(db).long(db), FileLongId::Virtual(_) | FileLongId::External(_));
62 let location = location.span_in_file(db).user_location(db);
63 let file_full_path = location.file_id.full_path(db);
64 let position = location.span.position_in_file(db, location.file_id)?;
65 let source_location = SourceCodeSpan {
66 start: SourceCodeLocation { col: position.start.col, line: position.start.line },
67 end: SourceCodeLocation { col: position.end.col, line: position.end.line },
68 };
69
70 Some((SourceFileFullPath(file_full_path), source_location, is_macro))
71}