neo_solidity/semantic/
types.rs1#[derive(Debug, Clone)]
3pub struct SemanticResult {
4 pub warnings: Vec<String>,
5 pub suggestions: Vec<String>,
6 pub errors: Vec<String>,
7 pub complexity_metrics: ComplexityMetrics,
8 pub security_issues: Vec<SecurityIssue>,
9 pub performance_metrics: PerformanceMetrics,
10}
11
12impl SemanticResult {
13 pub fn has_errors(&self) -> bool {
15 !self.errors.is_empty()
16 }
17
18 pub fn has_security_issues(&self) -> bool {
20 !self.security_issues.is_empty()
21 }
22
23 pub fn critical_issue_count(&self) -> usize {
25 self.security_issues
26 .iter()
27 .filter(|i| matches!(i.severity, Severity::High | Severity::Critical))
28 .count()
29 }
30
31 pub fn total_issues(&self) -> usize {
33 self.errors.len() + self.warnings.len() + self.security_issues.len()
34 }
35}
36
37#[derive(Debug, Clone, Default)]
39pub struct ComplexityMetrics {
40 pub cyclomatic: u32,
41 pub function_count: u32,
42 pub max_nesting_depth: u32,
43}
44
45impl ComplexityMetrics {
46 pub fn is_acceptable(&self) -> bool {
48 self.cyclomatic <= 15 && self.max_nesting_depth <= 5
49 }
50
51 pub fn rating(&self) -> &'static str {
53 match self.cyclomatic {
54 0..=5 => "Simple",
55 6..=10 => "Moderate",
56 11..=20 => "Complex",
57 _ => "Very Complex",
58 }
59 }
60}
61
62#[derive(Debug, Clone)]
64pub struct SecurityIssue {
65 pub message: String,
66 pub severity: Severity,
67}
68
69impl SecurityIssue {
70 pub fn new(message: impl Into<String>, severity: Severity) -> Self {
72 Self {
73 message: message.into(),
74 severity,
75 }
76 }
77}
78
79#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
81pub enum Severity {
82 Low,
83 Medium,
84 High,
85 Critical,
86}
87
88impl Severity {
89 pub fn as_str(&self) -> &'static str {
91 match self {
92 Self::Low => "low",
93 Self::Medium => "medium",
94 Self::High => "high",
95 Self::Critical => "critical",
96 }
97 }
98}
99
100#[derive(Debug, Clone, Default)]
102pub struct PerformanceMetrics {
103 pub estimated_gas: u64,
104 pub hot_paths: Vec<String>,
105 pub optimization_opportunities: Vec<String>,
106}
107
108impl PerformanceMetrics {
109 pub fn has_opportunities(&self) -> bool {
111 !self.optimization_opportunities.is_empty()
112 }
113}
114
115#[derive(Default)]
116pub struct SemanticAnalyzer;
117