Skip to main content

sentri_core/
analysis_context.rs

1//! Analysis context tracking.
2
3use crate::model::ProgramModel;
4
5/// Represents a warning with source location.
6#[derive(Debug, Clone)]
7pub struct AnalysisWarning {
8    /// The warning message.
9    pub message: String,
10    /// The file where the issue was found.
11    pub file: String,
12    /// The line number of the issue.
13    pub line: usize,
14    /// The column position (optional).
15    pub column: Option<usize>,
16    /// The exact source line content.
17    pub source_line: Option<String>,
18}
19
20/// Context information from analysis phase.
21#[derive(Debug, Clone)]
22pub struct AnalysisContext {
23    /// The analyzed program model.
24    pub program: ProgramModel,
25    /// Whether the analysis found no critical issues.
26    pub is_valid: bool,
27    /// All warnings encountered during analysis.
28    pub warnings: Vec<AnalysisWarning>,
29}
30
31impl AnalysisContext {
32    /// Create a new analysis context for a program.
33    pub fn new(program: ProgramModel) -> Self {
34        Self {
35            program,
36            is_valid: true,
37            warnings: Vec::new(),
38        }
39    }
40
41    /// Add a warning with source location.
42    pub fn add_warning(
43        &mut self,
44        message: String,
45        file: String,
46        line: usize,
47        column: Option<usize>,
48        source_line: Option<String>,
49    ) {
50        self.warnings.push(AnalysisWarning {
51            message,
52            file,
53            line,
54            column,
55            source_line,
56        });
57    }
58
59    /// Mark the context as invalid due to critical issues.
60    pub fn mark_invalid(&mut self) {
61        self.is_valid = false;
62    }
63
64    /// Get the number of warnings.
65    pub fn warning_count(&self) -> usize {
66        self.warnings.len()
67    }
68
69    /// Check if there are any warnings.
70    pub fn has_warnings(&self) -> bool {
71        !self.warnings.is_empty()
72    }
73}