fn.Nbody.Append(r)
if Debug['r'] != 0 {
- dumpslice("genhash body", fn.Nbody.Slice())
+ dumplist("genhash body", fn.Nbody)
}
funcbody(fn)
}
if Debug['r'] != 0 {
- dumpslice("geneq body", fn.Nbody.Slice())
+ dumplist("geneq body", fn.Nbody)
}
funcbody(fn)
}
for _, f := range p.inlined {
if p.trace {
- p.tracef("{ %s }\n", Hconvslice(f.Inl.Slice(), obj.FmtSharp))
+ p.tracef("{ %s }\n", Hconv(f.Inl, obj.FmtSharp))
}
p.nodeList(f.Inl)
if p.trace {
}
p.int(it.Len())
if p.trace {
- if it.Len() == 0 {
+ if it.Len() <= 1 {
p.tracef("] {}")
} else {
p.tracef("] {>")
}
// Look for anything we need for the inline body
-func reexportdeplist(ll *NodeList) {
- for ; ll != nil; ll = ll.Next {
- reexportdep(ll.N)
- }
-}
-
-func reexportdepslice(ll []*Node) {
- for _, n := range ll {
- reexportdep(n)
+func reexportdeplist(ll nodesOrNodeList) {
+ for it := nodeSeqIterate(ll); !it.Done(); it.Next() {
+ reexportdep(it.N())
}
}
reexportdeplist(n.List)
reexportdeplist(n.Rlist)
reexportdeplist(n.Ninit)
- reexportdepslice(n.Nbody.Slice())
+ reexportdeplist(n.Nbody)
}
func dumpexportconst(s *Sym) {
}
// NOTE: The space after %#S here is necessary for ld's export data parser.
- exportf("\tfunc %v %v { %v }\n", Sconv(s, obj.FmtSharp), Tconv(t, obj.FmtShort|obj.FmtSharp), Hconvslice(n.Func.Inl.Slice(), obj.FmtSharp|obj.FmtBody))
+ exportf("\tfunc %v %v { %v }\n", Sconv(s, obj.FmtSharp), Tconv(t, obj.FmtShort|obj.FmtSharp), Hconv(n.Func.Inl, obj.FmtSharp|obj.FmtBody))
- reexportdepslice(n.Func.Inl.Slice())
+ reexportdeplist(n.Func.Inl)
} else {
exportf("\tfunc %v %v\n", Sconv(s, obj.FmtSharp), Tconv(t, obj.FmtShort|obj.FmtSharp))
}
if Debug['l'] < 2 {
typecheckinl(f.Type.Nname)
}
- exportf("\tfunc (%v) %v %v { %v }\n", Tconv(getthisx(f.Type).Type, obj.FmtSharp), Sconv(f.Sym, obj.FmtShort|obj.FmtByte|obj.FmtSharp), Tconv(f.Type, obj.FmtShort|obj.FmtSharp), Hconvslice(f.Type.Nname.Func.Inl.Slice(), obj.FmtSharp))
- reexportdepslice(f.Type.Nname.Func.Inl.Slice())
+ exportf("\tfunc (%v) %v %v { %v }\n", Tconv(getthisx(f.Type).Type, obj.FmtSharp), Sconv(f.Sym, obj.FmtShort|obj.FmtByte|obj.FmtSharp), Tconv(f.Type, obj.FmtShort|obj.FmtSharp), Hconv(f.Type.Nname.Func.Inl, obj.FmtSharp))
+ reexportdeplist(f.Type.Nname.Func.Inl)
} else {
exportf("\tfunc (%v) %v %v\n", Tconv(getthisx(f.Type).Type, obj.FmtSharp), Sconv(f.Sym, obj.FmtShort|obj.FmtByte|obj.FmtSharp), Tconv(f.Type, obj.FmtShort|obj.FmtSharp))
}
// block starting with the init statements.
// if we can just say "for" n->ninit; ... then do so
- simpleinit := n.Ninit != nil && n.Ninit.Next == nil && n.Ninit.N.Ninit == nil && stmtwithinit(n.Op)
+ simpleinit := nodeSeqLen(n.Ninit) == 1 && nodeSeqLen(nodeSeqFirst(n.Ninit).Ninit) == 0 && stmtwithinit(n.Op)
// otherwise, print the inits as separate statements
- complexinit := n.Ninit != nil && !simpleinit && (fmtmode != FErr)
+ complexinit := nodeSeqLen(n.Ninit) != 0 && !simpleinit && (fmtmode != FErr)
// but if it was for if/for/switch, put in an extra surrounding block to limit the scope
extrablock := complexinit && stmtwithinit(n.Op)
} else {
f += fmt.Sprintf("if %v { %v }", n.Left, n.Nbody)
}
- if n.Rlist != nil {
+ if nodeSeqLen(n.Rlist) != 0 {
f += fmt.Sprintf(" else { %v }", n.Rlist)
}
f += "for"
if simpleinit {
- f += fmt.Sprintf(" %v;", n.Ninit.N)
+ f += fmt.Sprintf(" %v;", nodeSeqFirst(n.Ninit))
} else if n.Right != nil {
f += " ;"
}
break
}
- if n.List == nil {
+ if nodeSeqLen(n.List) == 0 {
f += fmt.Sprintf("for range %v { %v }", n.Right, n.Nbody)
break
}
f += Oconv(int(n.Op), obj.FmtSharp)
if simpleinit {
- f += fmt.Sprintf(" %v;", n.Ninit.N)
+ f += fmt.Sprintf(" %v;", nodeSeqFirst(n.Ninit))
}
if n.Left != nil {
f += Nconv(n.Left, 0)
f += fmt.Sprintf(" { %v }", n.List)
case OCASE, OXCASE:
- if n.List != nil {
+ if nodeSeqLen(n.List) != 0 {
f += fmt.Sprintf("case %v: %v", Hconv(n.List, obj.FmtComma), n.Nbody)
} else {
f += fmt.Sprintf("default: %v", n.Nbody)
} else {
f += fmt.Sprintf("(%v{", n.Type)
}
- for l := n.List; l != nil; l = l.Next {
- f += fmt.Sprintf(" %v:%v", Sconv(l.N.Left.Sym, obj.FmtShort|obj.FmtByte), l.N.Right)
+ for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
+ f += fmt.Sprintf(" %v:%v", Sconv(it.N().Left.Sym, obj.FmtShort|obj.FmtByte), it.N().Right)
- if l.Next != nil {
+ if it.Len() > 1 {
f += ","
} else {
f += " "
return f
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
- if n.List != nil { // pre-typecheck
+ if nodeSeqLen(n.List) != 0 { // pre-typecheck
return fmt.Sprintf("make(%v, %v)", n.Type, Hconv(n.List, obj.FmtComma))
}
if n.Right != nil {
case OADDSTR:
var f string
- for l := n.List; l != nil; l = l.Next {
- if l != n.List {
+ i := 0
+ for it := nodeSeqIterate(n.List); !it.Done(); it.Next() {
+ if i != 0 {
f += " + "
}
- f += exprfmt(l.N, nprec)
+ f += exprfmt(it.N(), nprec)
+ i++
}
return f
return buf.String()
}
- if n.Ninit != nil {
+ if nodeSeqLen(n.Ninit) != 0 {
fmt.Fprintf(&buf, "%v-init%v", Oconv(int(n.Op), 0), n.Ninit)
indent(&buf)
}
if n.Right != nil {
buf.WriteString(Nconv(n.Right, 0))
}
- if n.List != nil {
+ if nodeSeqLen(n.List) != 0 {
indent(&buf)
fmt.Fprintf(&buf, "%v-list%v", Oconv(int(n.Op), 0), n.List)
}
- if n.Rlist != nil {
+ if nodeSeqLen(n.Rlist) != 0 {
indent(&buf)
fmt.Fprintf(&buf, "%v-rlist%v", Oconv(int(n.Op), 0), n.Rlist)
}
}
func (n Nodes) String() string {
- return Hconvslice(n.Slice(), 0)
+ return Hconv(n, 0)
}
// Fmt '%H': NodeList.
// Flags: all those of %N plus ',': separate with comma's instead of semicolons.
-func Hconv(l *NodeList, flag int) string {
- if l == nil && fmtmode == FDbg {
+func Hconv(l nodesOrNodeList, flag int) string {
+ if nodeSeqLen(l) == 0 && fmtmode == FDbg {
return "<nil>"
}
}
var buf bytes.Buffer
- for ; l != nil; l = l.Next {
- buf.WriteString(Nconv(l.N, 0))
- if l.Next != nil {
+ for it := nodeSeqIterate(l); !it.Done(); it.Next() {
+ buf.WriteString(Nconv(it.N(), 0))
+ if it.Len() > 1 {
buf.WriteString(sep)
}
}
return buf.String()
}
-func Hconvslice(l []*Node, flag int) string {
- if len(l) == 0 && fmtmode == FDbg {
- return "<nil>"
- }
-
- sf := flag
- sm, sb := setfmode(&flag)
- sep := "; "
- if fmtmode == FDbg {
- sep = "\n"
- } else if flag&obj.FmtComma != 0 {
- sep = ", "
- }
-
- var buf bytes.Buffer
- for i, n := range l {
- buf.WriteString(Nconv(n, 0))
- if i+1 < len(l) {
- buf.WriteString(sep)
- }
- }
-
- flag = sf
- fmtbody = sb
- fmtmode = sm
- return buf.String()
-}
-
-func dumplist(s string, l *NodeList) {
+func dumplist(s string, l nodesOrNodeList) {
fmt.Printf("%s%v\n", s, Hconv(l, obj.FmtSign))
}
-func dumpslice(s string, l []*Node) {
- fmt.Printf("%s%v\n", s, Hconvslice(l, obj.FmtSign))
-}
-
func Dump(s string, n *Node) {
fmt.Printf("%s [%p]%v\n", s, n, Nconv(n, obj.FmtSign))
}
}
if Debug['m'] > 2 {
- fmt.Printf("typecheck import [%v] %v { %v }\n", fn.Sym, Nconv(fn, obj.FmtLong), Hconvslice(fn.Func.Inl.Slice(), obj.FmtSharp))
+ fmt.Printf("typecheck import [%v] %v { %v }\n", fn.Sym, Nconv(fn, obj.FmtLong), Hconv(fn.Func.Inl, obj.FmtSharp))
}
save_safemode := safemode
fn.Type.Nname = fn.Func.Nname
if Debug['m'] > 1 {
- fmt.Printf("%v: can inline %v as: %v { %v }\n", fn.Line(), Nconv(fn.Func.Nname, obj.FmtSharp), Tconv(fn.Type, obj.FmtSharp), Hconvslice(fn.Func.Nname.Func.Inl.Slice(), obj.FmtSharp))
+ fmt.Printf("%v: can inline %v as: %v { %v }\n", fn.Line(), Nconv(fn.Func.Nname, obj.FmtSharp), Tconv(fn.Type, obj.FmtSharp), Hconv(fn.Func.Nname.Func.Inl, obj.FmtSharp))
} else if Debug['m'] != 0 {
fmt.Printf("%v: can inline %v\n", fn.Line(), fn.Func.Nname)
}
// Bingo, we have a function node, and it has an inlineable body
if Debug['m'] > 1 {
- fmt.Printf("%v: inlining call to %v %v { %v }\n", n.Line(), fn.Sym, Tconv(fn.Type, obj.FmtSharp), Hconvslice(fn.Func.Inl.Slice(), obj.FmtSharp))
+ fmt.Printf("%v: inlining call to %v %v { %v }\n", n.Line(), fn.Sym, Tconv(fn.Type, obj.FmtSharp), Hconv(fn.Func.Inl, obj.FmtSharp))
} else if Debug['m'] != 0 {
fmt.Printf("%v: inlining call to %v\n", n.Line(), fn)
}
func order(fn *Node) {
if Debug['W'] > 1 {
s := fmt.Sprintf("\nbefore order %v", fn.Func.Nname.Sym)
- dumpslice(s, fn.Nbody.Slice())
+ dumplist(s, fn.Nbody)
}
orderblockNodes(&fn.Nbody)
if Debug['W'] != 0 {
s := fmt.Sprintf("after instrument %v", fn.Func.Nname.Sym)
- dumpslice(s, fn.Nbody.Slice())
+ dumplist(s, fn.Nbody)
s = fmt.Sprintf("enter %v", fn.Func.Nname.Sym)
- dumpslice(s, fn.Func.Enter.Slice())
+ dumplist(s, fn.Func.Enter)
s = fmt.Sprintf("exit %v", fn.Func.Nname.Sym)
- dumpslice(s, fn.Func.Exit.Slice())
+ dumplist(s, fn.Func.Exit)
}
}
printssa := name == os.Getenv("GOSSAFUNC")
if printssa {
fmt.Println("generating SSA for", name)
- dumpslice("buildssa-enter", fn.Func.Enter.Slice())
- dumpslice("buildssa-body", fn.Nbody.Slice())
- dumpslice("buildssa-exit", fn.Func.Exit.Slice())
+ dumplist("buildssa-enter", fn.Func.Enter)
+ dumplist("buildssa-body", fn.Nbody)
+ dumplist("buildssa-exit", fn.Func.Exit)
}
var s state
}
if false && Debug['r'] != 0 {
- dumpslice("genwrapper body", fn.Nbody.Slice())
+ dumplist("genwrapper body", fn.Nbody)
}
funcbody(fn)
}
func (ni *nodesIterator) Len() int {
- return len(ni.n.Slice())
+ return len(ni.n.Slice()[ni.i:])
}
func (ni *nodesIterator) Seq() nodesOrNodeList {
if Debug['W'] != 0 {
s := fmt.Sprintf("\nbefore %v", Curfn.Func.Nname.Sym)
- dumpslice(s, Curfn.Nbody.Slice())
+ dumplist(s, Curfn.Nbody)
}
lno := lineno
walkstmtlist(Curfn.Nbody)
if Debug['W'] != 0 {
s := fmt.Sprintf("after walk %v", Curfn.Func.Nname.Sym)
- dumpslice(s, Curfn.Nbody.Slice())
+ dumplist(s, Curfn.Nbody)
}
heapmoves()
if Debug['W'] != 0 && len(Curfn.Func.Enter.Slice()) > 0 {
s := fmt.Sprintf("enter %v", Curfn.Func.Nname.Sym)
- dumpslice(s, Curfn.Func.Enter.Slice())
+ dumplist(s, Curfn.Func.Enter)
}
}
nx = Nod(OINDEX, ns, nn) // s[n] ...
nx.Bounded = true
l = append(l, Nod(OAS, nx, it.N())) // s[n] = arg
- if it.Len() != 0 {
+ if it.Len() > 1 {
l = append(l, Nod(OAS, nn, Nod(OADD, nn, Nodintconst(1)))) // n = n + 1
}
}