提升: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:
+52
-8
@@ -32,33 +32,77 @@ def _split_at_operator(text, operator):
|
||||
|
||||
|
||||
def parse_single_condition(text, fields=None):
|
||||
"""Parse 'AMOUNT > 1000' into ('AMOUNT', '>', '1000').
|
||||
Also handles subscripted fields: 'WS-ITEM(SUB) = 'A''.
|
||||
Also resolves 88-level condition names (e.g. STATUS-APPROVED → WS-TRAN-STATUS = 'A').
|
||||
Returns None if the condition contains AND/OR (compound).
|
||||
"""Parse a COBOL condition into (field, operator, value) 3-tuple.
|
||||
|
||||
Handles:
|
||||
- Basic: AMOUNT > 1000 → (AMOUNT, '>', '1000')
|
||||
- 88-lev: STATUS-APPROVED → (parent, '=', value)
|
||||
- NOT =: X NOT = 5 → (X, '<>', '5') (NOT = means <>)
|
||||
- NOT >: X NOT > 5 → (X, '<=', '5')
|
||||
- NOT <: X NOT < 5 → (X, '>=', '5')
|
||||
- NOT 88: NOT WS-EOF-Y → (parent, '<>', value)
|
||||
- Bare: WS-EOF → (WS-EOF, '=', 'Y')
|
||||
- NOT bare: NOT WS-EOF → (WS-EOF, '<>', 'Y')
|
||||
- NOT arith: A+B NOT = C → ('A+B', '<>', 'C')
|
||||
|
||||
Returns None for compound (AND/OR) conditions.
|
||||
"""
|
||||
if ' AND ' in text or ' OR ' in text:
|
||||
return None
|
||||
# Check if text is an 88-level condition name
|
||||
text = text.strip()
|
||||
|
||||
# Resolve 88-level condition names
|
||||
if fields:
|
||||
for f in fields:
|
||||
if f.get('is_88') and f['name'] == text.upper():
|
||||
return (f.get('parent', ''), '=', f.get('value', ''))
|
||||
# NOT 88-level → invert operator
|
||||
if f.get('is_88') and text.upper().startswith('NOT ') and f['name'] == text[4:].strip().upper():
|
||||
return (f.get('parent', ''), '<>', f.get('value', ''))
|
||||
|
||||
# Bare NOT field reference (no operator): NOT WS-EOF → WS-EOF <> 'Y'
|
||||
if text.upper().startswith('NOT ') and not re.search(r'(>=|<=|<>|>|<|=)', text):
|
||||
field_name = text[4:].strip()
|
||||
if re.match(r'^[A-Z][A-Z0-9-]*(?:\([^)]*\))?$', field_name, re.IGNORECASE):
|
||||
return (field_name, '<>', 'Y')
|
||||
|
||||
# Normalize COBOL NOT-operators: X NOT = Y → X <> Y
|
||||
normalized = text
|
||||
not_map = [
|
||||
(r'\bNOT\s+>=', '<'), (r'\bNOT\s+<=', '>'),
|
||||
(r'\bNOT\s+<>', '='), (r'\bNOT\s+=', '<>'),
|
||||
(r'\bNOT\s+>', '<='), (r'\bNOT\s+<', '>='),
|
||||
]
|
||||
for pat, repl in not_map:
|
||||
if re.search(pat, text, re.IGNORECASE):
|
||||
normalized = re.sub(pat, repl, text, flags=re.IGNORECASE)
|
||||
break
|
||||
|
||||
# Standard regex: FIELD OP VALUE
|
||||
m = re.match(
|
||||
r"^(\w[\w-]*(?:\s*\([^)]*\))?)\s*(>=|<=|<>|>|<|=)\s*(.+)$",
|
||||
text
|
||||
normalized
|
||||
)
|
||||
if m:
|
||||
field = re.sub(r'\s*([(),])\s*', r'\1', m.group(1))
|
||||
return (field, m.group(2), m.group(3).strip().strip("'").strip('"'))
|
||||
# Try arithmetic expression: e.g. A + B > C
|
||||
|
||||
# Arithmetic expression regex (lazy match allows spaces in field expr)
|
||||
m = re.match(
|
||||
r"^(\w[\w\s+\-*/().-]+?)\s*(>=|<=|<>|>|<|=)\s*(.+)$",
|
||||
text
|
||||
normalized
|
||||
)
|
||||
if m:
|
||||
field = re.sub(r'\s*([(),])\s*', r'\1', m.group(1)).strip()
|
||||
# Clean trailing ' NOT' that got swallowed by lazy match
|
||||
if field.upper().endswith(' NOT'):
|
||||
field = field[:-4].strip()
|
||||
return (field, m.group(2), m.group(3).strip().strip("'").strip('"'))
|
||||
|
||||
# Bare field: WS-EOF (no operator) → treat as WS-EOF = 'Y'
|
||||
if re.match(r'^[A-Z][A-Z0-9-]*(?:\([^)]*\))?$', text, re.IGNORECASE):
|
||||
return (text, '=', 'Y')
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user