提升:37/37基准程序全量解析+O(N)路径枚举+运行时gcov验证

## 核心变更

### 1. 新PROCEDURE DIVISION解析器(procedure_parser.py)
- 行级状态机替换旧的BrParser regex解析器
- 覆盖:IF/ELSE/END-IF(嵌套)、EVALUATE/WHEN/ALSO、
  PERFORM UNTIL/VARYING、READ/AT END/NOT AT END、
  SORT/MERGE、GO TO DEPENDING ON
- 之前:3/37程序有分支检测  →  现在:37/37全部有分支
- 速度:~20ms/程序,纯规则引擎

### 2. 桥接层(pipeline_bridge.py)
- 新解析器为主,旧解析器3秒超时兜底
- 自动选取分支数更多的结果

### 3. 线性路径枚举(design_mcdc.py)
- 替换旧的Cartesian积路径枚举(O(2^N))为每决策点独立枚举(O(N))
- 28-sysin: 162分支仅163条路径(之前需截断到60DP)
- 消除了500路径硬上限和60DP截断

### 4. 条件解析修复(cond.py)
- NOT运算符规范化:X NOT = 5 → X <> 5
- 88-level反向:NOT WS-EOF-Y → parent <> value
- 裸字段引用:NOT WS-EOF → WS-EOF <> 'Y'
- 验证:1182个IF条件中0个NOT污染

### 5. 约束字段过滤(__init__.py)
- OF限定词剥离:STD-KEY OF MASTER-REC → STD-KEY
- 下标字段解析:WS-ITEM(SUB) → WS-ITEM
- 跳过不在fields_dict中的字段(group item/伪影)

### 6. 预处理器增强(read.py)
- VALUE ALL剥离(VALUE ALL '*' → VALUE '*')
- &续行合并(COBOL多行字符串拼接)
- PIC小数点点→V转换(Z(9)9.99. → Z(9)9V99.)
- 缺少点号补全

### 7. Grammar修复(grammar.lark)
- OCCURS 1 TIME支持(原只认TIMES)
- USAGE IS COMP支持(可选IS)
- $符号在PICTURE_STRING中
- 无NAME条款支持(clause+)

### 8. Flatfile写入(flatfile.py)
- 多记录FD支持(选字段最多的记录)
- Path类型强制转换
- 回退零值记录

### 9. Bug修复
- trace_to_root空列表保护(core.py)

### 10. 测试套件(S16-S21)
- S16: 全量基准程序端到端
- S17: gcov运行时对比
- S18/S19: 桥接器验证
- S20: DISPLAY插桩运行时验证+gcov分支覆盖率
- S21: 条件解析修复验证
- 全部17/17回归测试通过

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
NB-076
2026-06-22 23:41:22 +08:00
parent 097f5449da
commit e5ab3baa46
18 changed files with 2313 additions and 38 deletions
+54
View File
@@ -0,0 +1,54 @@
"""S19: Final bridge test — extract_structure with new procedure parser"""
import sys, os, re, time
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
ROOT = "D:/cobol-java/cobol-test-programs/"
COPYBOOKS = os.path.join(ROOT, "common", "copybooks")
from cobol_testgen import extract_structure, generate_data
from cobol_testgen.read import preprocess, resolve_copybooks
from cobol_testgen.flatfile import analyze_fd_layout, write_all_files
def find_main(d):
cbls = [f for f in os.listdir(d) if f.endswith('.cbl')]
ws = [f for f in cbls if re.match(r'main-\d{2}-', f, re.IGNORECASE)]
if ws: return max(ws, key=lambda f: os.path.getsize(os.path.join(d, f)))
return max(cbls, key=lambda f: os.path.getsize(os.path.join(d, f))) if cbls else None
fmt = "{:<28} {:>4} {:>7} {:>5} {:>5} {}"
print(fmt.format("Program", "Br", "Time", "Recs", "Flats", "Parser"))
print("-"*78)
with_br = 0; gen_ok = 0; old_cnt = 0; new_cnt = 0; total_t = 0
for d in sorted(os.listdir(ROOT)):
dp = os.path.join(ROOT, d)
if not os.path.isdir(dp) or d in ('common','docs','cross-cutting'): continue
fn = find_main(dp)
if not fn: continue
t0 = time.time()
try:
src = open(os.path.join(dp, fn), encoding='utf-8').read()
st = extract_structure(src)
branches = st.get('total_branches', 0)
t = (time.time()-t0)*1000
total_t += t
# Also generate data + flat files
pp = resolve_copybooks(src, dp, extra_search_paths=[COPYBOOKS])
pp = preprocess(pp)
recs = generate_data(pp, st)
layouts = analyze_fd_layout(pp)
flats = write_all_files(recs, pp, dp) if layouts else []
parser = st.get("parser", "old")
if branches > 0: with_br += 1
gen_ok += 1
if parser == "new": new_cnt += 1
else: old_cnt += 1
print(fmt.format(d, branches, f"{t:.0f}ms", len(recs), len(flats), parser))
except Exception as e:
print(fmt.format(d, "ERR", f"{(time.time()-t0)*1000:.0f}ms", "", "", str(e)[:40]))
print(f"\nWith branches: {with_br}/{gen_ok}")
print(f"Parser: new={new_cnt} old={old_cnt}")
print(f"Total time: {total_t/1000:.1f}s")