93 lines
2.0 KiB
Plaintext
93 lines
2.0 KiB
Plaintext
|
|
// Phase 74-SSA: Enhanced reproduction - closer to ParserBox pattern
|
||
|
|
// Goal: Reproduce ValueId undef with more realistic conditions
|
||
|
|
//
|
||
|
|
// Added features:
|
||
|
|
// 1. State fields (like ParserBox.gpos, usings_json)
|
||
|
|
// 2. using statement (like ParserBox uses sh_core)
|
||
|
|
// 3. Multiple methods (not just one delegation)
|
||
|
|
// 4. Method with loop (like ParserBox.trim)
|
||
|
|
|
||
|
|
static box TargetBox {
|
||
|
|
is_digit(ch) {
|
||
|
|
if ch >= "0" && ch <= "9" { return 1 }
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
|
||
|
|
skip_ws(str, i) {
|
||
|
|
local n = str.length()
|
||
|
|
loop(i < n) {
|
||
|
|
local ch = str.substring(i, i + 1)
|
||
|
|
if ch == " " || ch == "\t" || ch == "\n" { i = i + 1 } else { break }
|
||
|
|
}
|
||
|
|
return i
|
||
|
|
}
|
||
|
|
|
||
|
|
trim(s) {
|
||
|
|
if s == null { return "" }
|
||
|
|
local str = "" + s
|
||
|
|
local n = str.length()
|
||
|
|
local b = TargetBox.skip_ws(str, 0)
|
||
|
|
if b >= n { return "" }
|
||
|
|
local e = n
|
||
|
|
loop(e > b) {
|
||
|
|
local ch = str.substring(e - 1, e)
|
||
|
|
if ch == " " || ch == "\t" { e = e - 1 } else { break }
|
||
|
|
}
|
||
|
|
if e > b { return str.substring(b, e) }
|
||
|
|
return ""
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
box DelegateBox {
|
||
|
|
// State fields (like ParserBox)
|
||
|
|
gpos
|
||
|
|
data
|
||
|
|
|
||
|
|
birth() {
|
||
|
|
me.gpos = 0
|
||
|
|
me.data = ""
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
|
||
|
|
// Method with loop + delegation (like ParserBox.trim)
|
||
|
|
trim(s) {
|
||
|
|
// Phase 74-SSA: This delegation pattern should cause SSA undef
|
||
|
|
return TargetBox.trim(s)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Simple delegation (like ParserBox.is_digit)
|
||
|
|
is_digit(ch) {
|
||
|
|
return TargetBox.is_digit(ch)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Method that uses state + delegation
|
||
|
|
process(text) {
|
||
|
|
local t = me.trim(text)
|
||
|
|
me.data = t
|
||
|
|
return t
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
box Main {
|
||
|
|
main() {
|
||
|
|
local delegate = new DelegateBox()
|
||
|
|
|
||
|
|
// Test delegation through instance
|
||
|
|
local text = " hello "
|
||
|
|
local trimmed = delegate.trim(text)
|
||
|
|
|
||
|
|
// Test is_digit delegation
|
||
|
|
local ch = "7"
|
||
|
|
local d = delegate.is_digit(ch)
|
||
|
|
|
||
|
|
// Test combined (state + delegation)
|
||
|
|
local result = delegate.process(" world ")
|
||
|
|
|
||
|
|
// Use results to avoid dead code elimination
|
||
|
|
if trimmed.length() > 0 && d == 1 && result.length() > 0 {
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
return 1
|
||
|
|
}
|
||
|
|
}
|