feat: complete rule evidence and frozen review fixtures
This commit is contained in:
1 parent
1f4e120a53
commit
344ef28870
27 files changed
+1992
-356
No files matched your search
+28
-8
@@ -143,13 +143,25 @@ pub fn align_function(markdown: &MarkdownTree, analysis: &AnalysisFunction) -> R
|
||||
if candidates.len() != 1 {
|
||||
tree.issues.push(format!(
|
||||
"{:?} opener [{}, {}) 与 Analysis 关联数量为 {}",
|
||||
expected, control.opener.span.start, control.opener.span.end, candidates.len()
|
||||
expected,
|
||||
control.opener.span.start,
|
||||
control.opener.span.end,
|
||||
candidates.len()
|
||||
));
|
||||
continue;
|
||||
}
|
||||
let (index, node) = candidates[0];
|
||||
// The frozen core omits an explicitly empty else arm from Analysis.
|
||||
if node.arm_count.is_some_and(|count| match count {
|
||||
1 => false,
|
||||
2 => control.else_carrier.is_none(),
|
||||
_ => true,
|
||||
}) {
|
||||
tree.issues.push("分支臂数量与 Analysis 不一致".into());
|
||||
}
|
||||
if semantic_to_control[index].is_some() {
|
||||
tree.issues.push("多个载体复用了同一 Analysis 控制节点".into());
|
||||
tree.issues
|
||||
.push("多个载体复用了同一 Analysis 控制节点".into());
|
||||
continue;
|
||||
}
|
||||
semantic_to_control[index] = Some(control_index);
|
||||
@@ -166,7 +178,8 @@ pub fn align_function(markdown: &MarkdownTree, analysis: &AnalysisFunction) -> R
|
||||
.parent
|
||||
.and_then(|parent| semantic_to_control[parent]);
|
||||
if semantic_parent != tree.controls[*control_index].parent {
|
||||
tree.issues.push("源载体嵌套与 Analysis 控制嵌套不一致".into());
|
||||
tree.issues
|
||||
.push("源载体嵌套与 Analysis 控制嵌套不一致".into());
|
||||
}
|
||||
}
|
||||
tree.complete = tree.issues.is_empty();
|
||||
@@ -178,6 +191,7 @@ struct SemanticControl {
|
||||
kind: ControlKind,
|
||||
span: Span,
|
||||
condition_span: Option<Span>,
|
||||
arm_count: Option<usize>,
|
||||
parent: Option<usize>,
|
||||
}
|
||||
|
||||
@@ -192,7 +206,7 @@ fn semantic_controls(analysis: &AnalysisFunction) -> Vec<SemanticControl> {
|
||||
}
|
||||
let (Some(span), condition_span) = (
|
||||
node_span(node),
|
||||
node.get("condition_span").and_then(node_span),
|
||||
node.get("condition_span").and_then(span_value),
|
||||
) else {
|
||||
continue;
|
||||
};
|
||||
@@ -205,6 +219,7 @@ fn semantic_controls(analysis: &AnalysisFunction) -> Vec<SemanticControl> {
|
||||
},
|
||||
span,
|
||||
condition_span,
|
||||
arm_count: node.get("arms").and_then(Value::as_array).map(Vec::len),
|
||||
parent,
|
||||
});
|
||||
if kind == "branch" {
|
||||
@@ -230,7 +245,10 @@ fn semantic_controls(analysis: &AnalysisFunction) -> Vec<SemanticControl> {
|
||||
}
|
||||
|
||||
pub fn node_span(node: &Value) -> Option<Span> {
|
||||
let span = node.get("span")?;
|
||||
span_value(node.get("span")?)
|
||||
}
|
||||
|
||||
fn span_value(span: &Value) -> Option<Span> {
|
||||
Some(Span::new(
|
||||
span.get("start")?.as_u64()? as usize,
|
||||
span.get("end")?.as_u64()? as usize,
|
||||
@@ -267,9 +285,11 @@ impl Keyword {
|
||||
pub fn statement_count(analysis: &AnalysisFunction) -> usize {
|
||||
semantic_nodes(&analysis.body)
|
||||
.filter(|node| {
|
||||
node.get("kind").and_then(Value::as_str).is_some_and(|kind| {
|
||||
matches!(kind, "assign" | "expression" | "branch" | "loop" | "return")
|
||||
})
|
||||
node.get("kind")
|
||||
.and_then(Value::as_str)
|
||||
.is_some_and(|kind| {
|
||||
matches!(kind, "assign" | "expression" | "branch" | "loop" | "return")
|
||||
})
|
||||
})
|
||||
.count()
|
||||
}
|
||||
Reference in new issue
Block a user