feat: DB管线补全 + 新增orchestrator_db/program_schema/to_sql + 清理临时脚本

This commit is contained in:
hangshuo652
2026-07-11 14:55:52 +08:00
parent 40e8a50ab4
commit af37e33b98
32 changed files with 3232 additions and 255 deletions
+61 -8
View File
@@ -82,15 +82,49 @@ def _wsl_path(windows_path: str) -> str:
return f'/mnt/{drive}/{rest}'
def _find_if_body_lines(source_lines: list[str], if_lineno_1: int):
"""在源码中定位 IF 语句的 THEN/ELSE 体行范围(行号 1-indexed)。
Returns (then_lines, else_lines):
then_lines: list[int] — THEN 体的行号(1-indexed
else_lines: list[int] — ELSE 体的行号(1-indexed),无 ELSE 则为空
"""
start = if_lineno_1 # 0-indexed, start AFTER the IF line
depth = 1
else_start_0 = None
end_if_0 = None
n = len(source_lines)
for i in range(start, n):
line = source_lines[i].upper().strip()
if re.match(r'\bIF\b', line) and not re.match(r'ELSE\s+IF', line, re.IGNORECASE):
depth += 1
if re.match(r'END-IF', line):
depth -= 1
if depth == 0:
end_if_0 = i
break
if depth == 1 and re.match(r'ELSE\b', line):
else_start_0 = i
then_start_1 = if_lineno_1 + 1
if else_start_0 is not None:
then_1 = list(range(then_start_1, else_start_0 + 1))
else_1 = list(range(else_start_0 + 2, (end_if_0 or start) + 2))
else:
then_1 = list(range(then_start_1, (end_if_0 or start) + 2))
else_1 = []
return then_1, else_1
def mark_from_gcov(decision_points: list, gcov_data: dict[int, int],
branch_tree) -> None:
branch_tree, source_text: str | None = None) -> None:
"""用 gcov 行执行计数推断决策点分支覆盖,直接修改 decision_points 的 active_branches。
推断规则(简化版,先覆盖主要场景):
当 source_text 提供时(预处理源码),IF 分支使用体行计数精确判断 T/F。
IF (条件行 L):
- 条件行 L 在 gcov 中 count == 0 → 不可到达,不标记
- 条件行 L 在 gcov 中 count > 0 → 标记 T 和 F 都覆盖
- 体行计数 > 0 → 对应分支覆盖(T=THEN体,F=ELSE体)
- 无体行数据时回退:count==0 跳过,count>0 标记 T/F
EVALUATE:
- subject 行 count > 0 → 标记所有 WHEN 为已覆盖
@@ -100,6 +134,8 @@ def mark_from_gcov(decision_points: list, gcov_data: dict[int, int],
- count > 1 → 循环体至少进入一次 → Enter 覆盖
- Skip 总视为覆盖(无论进入与否,最终都会跳出)
"""
source_lines = source_text.splitlines() if source_text else None
for dp in decision_points:
ln = dp.source_line
if ln <= 0 or ln not in gcov_data:
@@ -110,10 +146,27 @@ def mark_from_gcov(decision_points: list, gcov_data: dict[int, int],
continue
if dp.kind == 'IF':
if count == 0:
continue
dp.active_branches.add('T')
dp.active_branches.add('F')
# 清除静态分析的 IF 标记,用 gcov 运行时数据重新判断
dp.active_branches.discard('T')
dp.active_branches.discard('F')
if source_lines and ln <= len(source_lines):
then_lines, else_lines = _find_if_body_lines(source_lines, ln)
then_cov = any(gcov_data.get(tl, 0) > 0 for tl in then_lines)
else_cov = any(gcov_data.get(el, 0) > 0 for el in else_lines)
if then_cov:
dp.active_branches.add('T')
if else_cov:
dp.active_branches.add('F')
# 如果体行范围为空或无法判断,回退到基于 IF 行计数
if not then_lines and not else_lines:
if count > 0:
dp.active_branches.add('T')
dp.active_branches.add('F')
else:
# 无源码文本回退到原逻辑
if count > 0:
dp.active_branches.add('T')
dp.active_branches.add('F')
elif dp.kind == 'EVALUATE':
if count == 0: