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
//! Analysis context tracking.
use crate::model::ProgramModel;
/// Represents a warning with source location.
#[derive(Debug, Clone)]
pub struct AnalysisWarning {
/// The warning message.
pub message: String,
/// The file where the issue was found.
pub file: String,
/// The line number of the issue.
pub line: usize,
/// The column position (optional).
pub column: Option<usize>,
/// The exact source line content.
pub source_line: Option<String>,
}
/// Context information from analysis phase.
#[derive(Debug, Clone)]
pub struct AnalysisContext {
/// The analyzed program model.
pub program: ProgramModel,
/// Whether the analysis found no critical issues.
pub is_valid: bool,
/// All warnings encountered during analysis.
pub warnings: Vec<AnalysisWarning>,
}
impl AnalysisContext {
/// Create a new analysis context for a program.
pub fn new(program: ProgramModel) -> Self {
Self {
program,
is_valid: true,
warnings: Vec::new(),
}
}
/// Add a warning with source location.
pub fn add_warning(
&mut self,
message: String,
file: String,
line: usize,
column: Option<usize>,
source_line: Option<String>,
) {
self.warnings.push(AnalysisWarning {
message,
file,
line,
column,
source_line,
});
}
/// Mark the context as invalid due to critical issues.
pub fn mark_invalid(&mut self) {
self.is_valid = false;
}
/// Get the number of warnings.
pub fn warning_count(&self) -> usize {
self.warnings.len()
}
/// Check if there are any warnings.
pub fn has_warnings(&self) -> bool {
!self.warnings.is_empty()
}
}