Commit 3835c72
feat(semantic-gate): compare vars BY NAME, and tighten tolerances to 1.00
Counting has a ceiling, and it is lower than it looks: renaming or retyping a
variable keeps the count identical, so the check passes at ANY tolerance --
1.00 included. Measured on a real 27-POU project: renaming one variable left
the count at 62 -> 62 and every count-based check stayed green.
That is the "wrong identifier" class: a name that crosses a boundary and no
longer matches on the other side. It does not raise an error anywhere -- it
just silently returns nothing, which is indistinguishable from "not there yet".
What changed:
- count_st_vars() now returns _var_names, parsed from the declaration
(`name [, name2] [AT %addr] : type [:= init] ;`).
- count_xml_vars() now returns _var_names from the XML <variable name="...">.
- validate_semantic() emits VARS_MISSING_BY_NAME listing the names declared in
the ST that are absent from the XML. Identifiers are compared case-folded
(IEC 61131-3 is case-insensitive) and reported as written.
- Default tolerances 0.75/0.70 -> 1.00/1.00. That 25%/30% slack was never used:
on the same real project ST and XML match 1:1 on every POU, so 1.00 costs
zero red and removes room for a real loss to hide in.
Deliberate limit, to avoid false positives: the by-name comparison only runs
when the .st declares exactly ONE POU, because count_st_vars scans the whole
FILE while count_xml_vars scans a single POU. With 2+ POUs the sets are not
comparable, and a gate that cries wolf is a gate that gets skipped.
Proven by mutation, both directions:
- renaming a variable in a real .st: count 62 -> 62 (count-based check blind,
as predicted), by-name check FAILS naming the variable;
- disabling the by-name comparison in production code: exactly 1 of 19 tests
fails, and it is the one that asserts the rename -- surgical, not coupled.
Tests: 15 -> 19.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 588c5af commit 3835c72
2 files changed
Lines changed: 147 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
| |||
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| 85 | + | |
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
| |||
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
94 | 108 | | |
95 | 109 | | |
96 | 110 | | |
| 111 | + | |
97 | 112 | | |
98 | 113 | | |
99 | 114 | | |
| |||
118 | 133 | | |
119 | 134 | | |
120 | 135 | | |
| 136 | + | |
121 | 137 | | |
122 | 138 | | |
123 | 139 | | |
| |||
128 | 144 | | |
129 | 145 | | |
130 | 146 | | |
| 147 | + | |
| 148 | + | |
131 | 149 | | |
132 | 150 | | |
133 | 151 | | |
134 | 152 | | |
| 153 | + | |
135 | 154 | | |
136 | 155 | | |
137 | 156 | | |
| |||
207 | 226 | | |
208 | 227 | | |
209 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
210 | 252 | | |
211 | 253 | | |
212 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
0 commit comments