1
0
mirror of https://github.com/golang/go synced 2024-11-16 20:04:52 -07:00

internal/bisect: copy parser changes from CL 494177

x/tools/cmd/bisect is changing to emit hex skips for robustness.
Update this copy of internal/bisect to understand them.

Change-Id: Ie9445714e8e9fb594e656db2f94dcde9b6ce82d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/494178
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Russ Cox 2023-05-10 15:51:46 -04:00
parent 1d92e0e3fa
commit 48f8c5c037
2 changed files with 44 additions and 23 deletions

View File

@ -191,30 +191,32 @@ func TestLoopVarHashes(t *testing.T) {
return string(b)
}
m := f("v001100110110110010100100")
t.Logf(m)
for _, arg := range []string{"v001100110110110010100100", "vx336ca4"} {
m := f(arg)
t.Logf(m)
mCount := strings.Count(m, "loopvarhash triggered cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 001100110110110010100100")
otherCount := strings.Count(m, "loopvarhash")
if mCount < 1 {
t.Errorf("did not see triggered main.go:27:6")
}
if mCount != otherCount {
t.Errorf("too many matches")
}
mCount := strings.Count(m, "loopvarhash triggered cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 001100110110110010100100")
otherCount := strings.Count(m, "loopvarhash")
if mCount < 1 {
t.Errorf("%s: did not see triggered main.go:27:6", arg)
}
if mCount != otherCount {
t.Errorf("%s: too many matches", arg)
}
mCount = strings.Count(m, "cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 [bisect-match 0x7802e115b9336ca4]")
otherCount = strings.Count(m, "[bisect-match ")
if mCount < 1 {
t.Errorf("did not see bisect-match for main.go:27:6")
}
if mCount != otherCount {
t.Errorf("too many matches")
}
mCount = strings.Count(m, "cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 [bisect-match 0x7802e115b9336ca4]")
otherCount = strings.Count(m, "[bisect-match ")
if mCount < 1 {
t.Errorf("%s: did not see bisect-match for main.go:27:6", arg)
}
if mCount != otherCount {
t.Errorf("%s: too many matches", arg)
}
// This next test carefully dodges a bug-to-be-fixed with inlined locations for ir.Names.
if !strings.Contains(m, ", 100, 100, 100, 100") {
t.Errorf("Did not see expected value of m run")
// This next test carefully dodges a bug-to-be-fixed with inlined locations for ir.Names.
if !strings.Contains(m, ", 100, 100, 100, 100") {
t.Errorf("%s: did not see expected value of m run", arg)
}
}
}

View File

@ -229,17 +229,35 @@ func New(pattern string) (*Matcher, error) {
result := true
bits := uint64(0)
start := 0
wid := 1 // 1-bit (binary); sometimes 4-bit (hex)
for i := 0; i <= len(p); i++ {
// Imagine a trailing - at the end of the pattern to flush final suffix
c := byte('-')
if i < len(p) {
c = p[i]
}
if i == start && wid == 1 && c == 'x' { // leading x for hex
start = i + 1
wid = 4
continue
}
switch c {
default:
return nil, &parseError{"invalid pattern syntax: " + pattern}
case '2', '3', '4', '5', '6', '7', '8', '9':
if wid != 4 {
return nil, &parseError{"invalid pattern syntax: " + pattern}
}
fallthrough
case '0', '1':
bits = bits<<1 | uint64(c-'0')
bits <<= wid
bits |= uint64(c - '0')
case 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F':
if wid != 4 {
return nil, &parseError{"invalid pattern syntax: " + pattern}
}
bits <<= 4
bits |= uint64(c&^0x20 - 'A' + 10)
case 'y':
if i+1 < len(p) && (p[i+1] == '0' || p[i+1] == '1') {
return nil, &parseError{"invalid pattern syntax: " + pattern}
@ -251,7 +269,7 @@ func New(pattern string) (*Matcher, error) {
return nil, &parseError{"invalid pattern syntax (+ after -): " + pattern}
}
if i > 0 {
n := i - start
n := (i - start) * wid
if n > 64 {
return nil, &parseError{"pattern bits too long: " + pattern}
}
@ -270,6 +288,7 @@ func New(pattern string) (*Matcher, error) {
bits = 0
result = c == '+'
start = i + 1
wid = 1
}
}
return m, nil