libgo: Update to go1.6rc1.
Reviewed-on: https://go-review.googlesource.com/19200 From-SVN: r233110
This commit is contained in:
parent
b081ed4efc
commit
f98dd1a338
728 changed files with 43810 additions and 11912 deletions
|
@ -59,7 +59,12 @@ func onePassPrefix(p *syntax.Prog) (prefix string, complete bool, pc uint32) {
|
|||
buf.WriteRune(i.Rune[0])
|
||||
pc, i = i.Out, &p.Inst[i.Out]
|
||||
}
|
||||
return buf.String(), i.Op == syntax.InstEmptyWidth && (syntax.EmptyOp(i.Arg))&syntax.EmptyBeginText != 0, pc
|
||||
if i.Op == syntax.InstEmptyWidth &&
|
||||
syntax.EmptyOp(i.Arg)&syntax.EmptyEndText != 0 &&
|
||||
p.Inst[i.Out].Op == syntax.InstMatch {
|
||||
complete = true
|
||||
}
|
||||
return buf.String(), complete, pc
|
||||
}
|
||||
|
||||
// OnePassNext selects the next actionable state of the prog, based on the input character.
|
||||
|
@ -108,10 +113,6 @@ func (q *queueOnePass) clear() {
|
|||
q.nextIndex = 0
|
||||
}
|
||||
|
||||
func (q *queueOnePass) reset() {
|
||||
q.nextIndex = 0
|
||||
}
|
||||
|
||||
func (q *queueOnePass) contains(u uint32) bool {
|
||||
if u >= uint32(len(q.sparse)) {
|
||||
return false
|
||||
|
@ -308,25 +309,9 @@ func makeOnePass(p *onePassProg) *onePassProg {
|
|||
var (
|
||||
instQueue = newQueue(len(p.Inst))
|
||||
visitQueue = newQueue(len(p.Inst))
|
||||
build func(uint32, *queueOnePass)
|
||||
check func(uint32, map[uint32]bool) bool
|
||||
onePassRunes = make([][]rune, len(p.Inst))
|
||||
)
|
||||
build = func(pc uint32, q *queueOnePass) {
|
||||
if q.contains(pc) {
|
||||
return
|
||||
}
|
||||
inst := p.Inst[pc]
|
||||
switch inst.Op {
|
||||
case syntax.InstAlt, syntax.InstAltMatch:
|
||||
q.insert(inst.Out)
|
||||
build(inst.Out, q)
|
||||
q.insert(inst.Arg)
|
||||
case syntax.InstMatch, syntax.InstFail:
|
||||
default:
|
||||
q.insert(inst.Out)
|
||||
}
|
||||
}
|
||||
|
||||
// check that paths from Alt instructions are unambiguous, and rebuild the new
|
||||
// program as a onepass program
|
||||
|
@ -385,11 +370,11 @@ func makeOnePass(p *onePassProg) *onePassProg {
|
|||
m[pc] = inst.Op == syntax.InstMatch
|
||||
break
|
||||
case syntax.InstRune:
|
||||
ok = check(inst.Out, m)
|
||||
m[pc] = false
|
||||
if len(inst.Next) > 0 {
|
||||
break
|
||||
}
|
||||
instQueue.insert(inst.Out)
|
||||
if len(inst.Rune) == 0 {
|
||||
onePassRunes[pc] = []rune{}
|
||||
inst.Next = []uint32{inst.Out}
|
||||
|
@ -413,11 +398,11 @@ func makeOnePass(p *onePassProg) *onePassProg {
|
|||
}
|
||||
inst.Op = syntax.InstRune
|
||||
case syntax.InstRune1:
|
||||
ok = check(inst.Out, m)
|
||||
m[pc] = false
|
||||
if len(inst.Next) > 0 {
|
||||
break
|
||||
}
|
||||
instQueue.insert(inst.Out)
|
||||
runes := []rune{}
|
||||
// expand case-folded runes
|
||||
if syntax.Flags(inst.Arg)&syntax.FoldCase != 0 {
|
||||
|
@ -437,19 +422,19 @@ func makeOnePass(p *onePassProg) *onePassProg {
|
|||
}
|
||||
inst.Op = syntax.InstRune
|
||||
case syntax.InstRuneAny:
|
||||
ok = check(inst.Out, m)
|
||||
m[pc] = false
|
||||
if len(inst.Next) > 0 {
|
||||
break
|
||||
}
|
||||
instQueue.insert(inst.Out)
|
||||
onePassRunes[pc] = append([]rune{}, anyRune...)
|
||||
inst.Next = []uint32{inst.Out}
|
||||
case syntax.InstRuneAnyNotNL:
|
||||
ok = check(inst.Out, m)
|
||||
m[pc] = false
|
||||
if len(inst.Next) > 0 {
|
||||
break
|
||||
}
|
||||
instQueue.insert(inst.Out)
|
||||
onePassRunes[pc] = append([]rune{}, anyRuneNotNL...)
|
||||
inst.Next = []uint32{}
|
||||
for i := len(onePassRunes[pc]) / 2; i >= 0; i-- {
|
||||
|
@ -463,24 +448,12 @@ func makeOnePass(p *onePassProg) *onePassProg {
|
|||
instQueue.insert(uint32(p.Start))
|
||||
m := make(map[uint32]bool, len(p.Inst))
|
||||
for !instQueue.empty() {
|
||||
pc := instQueue.next()
|
||||
inst := p.Inst[pc]
|
||||
visitQueue.clear()
|
||||
pc := instQueue.next()
|
||||
if !check(uint32(pc), m) {
|
||||
p = notOnePass
|
||||
break
|
||||
}
|
||||
switch inst.Op {
|
||||
case syntax.InstAlt, syntax.InstAltMatch:
|
||||
instQueue.insert(inst.Out)
|
||||
instQueue.insert(inst.Arg)
|
||||
case syntax.InstCapture, syntax.InstEmptyWidth, syntax.InstNop:
|
||||
instQueue.insert(inst.Out)
|
||||
case syntax.InstMatch:
|
||||
case syntax.InstFail:
|
||||
case syntax.InstRune, syntax.InstRune1, syntax.InstRuneAny, syntax.InstRuneAnyNotNL:
|
||||
default:
|
||||
}
|
||||
}
|
||||
if p != notOnePass {
|
||||
for i := range p.Inst {
|
||||
|
@ -490,47 +463,6 @@ func makeOnePass(p *onePassProg) *onePassProg {
|
|||
return p
|
||||
}
|
||||
|
||||
// walk visits each Inst in the prog once, and applies the argument
|
||||
// function(ip, next), in pre-order.
|
||||
func walk(prog *syntax.Prog, funcs ...func(ip, next uint32)) {
|
||||
var walk1 func(uint32)
|
||||
progQueue := newQueue(len(prog.Inst))
|
||||
walk1 = func(ip uint32) {
|
||||
if progQueue.contains(ip) {
|
||||
return
|
||||
}
|
||||
progQueue.insert(ip)
|
||||
inst := prog.Inst[ip]
|
||||
switch inst.Op {
|
||||
case syntax.InstAlt, syntax.InstAltMatch:
|
||||
for _, f := range funcs {
|
||||
f(ip, inst.Out)
|
||||
f(ip, inst.Arg)
|
||||
}
|
||||
walk1(inst.Out)
|
||||
walk1(inst.Arg)
|
||||
default:
|
||||
for _, f := range funcs {
|
||||
f(ip, inst.Out)
|
||||
}
|
||||
walk1(inst.Out)
|
||||
}
|
||||
}
|
||||
walk1(uint32(prog.Start))
|
||||
}
|
||||
|
||||
// find returns the Insts that match the argument predicate function
|
||||
func find(prog *syntax.Prog, f func(*syntax.Prog, int) bool) (matches []uint32) {
|
||||
matches = []uint32{}
|
||||
|
||||
for ip := range prog.Inst {
|
||||
if f(prog, ip) {
|
||||
matches = append(matches, uint32(ip))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var notOnePass *onePassProg = nil
|
||||
|
||||
// compileOnePass returns a new *syntax.Prog suitable for onePass execution if the original Prog
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue