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
use crate::linter::{Rule, RuleResult}; use sv_parser::{unwrap_locate, unwrap_node, AlwaysKeyword, RefNode, SyntaxTree}; pub struct CaseDefault; impl Rule for CaseDefault { fn check(&self, _syntax_tree: &SyntaxTree, node: &RefNode) -> RuleResult { match node { RefNode::AlwaysConstruct(x) => { let (ref a, _) = x.nodes; match a { AlwaysKeyword::AlwaysComb(_) => { if let Some(x) = unwrap_node!(x.clone(), CaseStatementNormal) { let loc = unwrap_locate!(x.clone()).unwrap(); let a = unwrap_node!(x.clone(), CaseItemDefault); if a.is_some() { RuleResult::Pass } else { RuleResult::FailLocate(loc.clone()) } } else { RuleResult::Pass } } _ => RuleResult::Pass, } } RefNode::FunctionDeclaration(x) => { if let Some(x) = unwrap_node!(x.clone(), CaseStatementNormal) { let loc = unwrap_locate!(x.clone()).unwrap(); let a = unwrap_node!(x.clone(), CaseItemDefault); if a.is_some() { RuleResult::Pass } else { RuleResult::FailLocate(loc.clone()) } } else { RuleResult::Pass } } _ => RuleResult::Pass, } } fn name(&self) -> String { String::from("case_default") } fn hint(&self) -> String { String::from("`case` must have `default` in `always_comb` or `function`") } fn reason(&self) -> String { String::from("'not full case' causes mismatch between simulation and synthesis") } }