n.Right.exprfmt(s, nprec+1, mode)
case OADDSTR:
- i := 0
- for _, n1 := range n.List.Slice() {
+ for i, n1 := range n.List.Slice() {
if i != 0 {
fmt.Fprint(s, " + ")
}
n1.exprfmt(s, nprec, mode)
- i++
}
case OCMPSTR, OCMPIFACE:
)
func parseFiles(filenames []string) uint {
- var lines uint
var noders []*noder
// Limit the number of simultaneously open files.
sem := make(chan struct{}, runtime.GOMAXPROCS(0)+10)
}(filename)
}
+ var lines uint
for _, p := range noders {
for e := range p.err {
yyerrorpos(e.Pos, "%s", e.Msg)
// above the mark on the temporary stack, but it does not pop them
// from the stack.
func cleantempnopop(mark ordermarker, order *Order, out *[]*Node) {
- var kill *Node
-
for i := len(order.temp) - 1; i >= int(mark); i-- {
n := order.temp[i]
if n.Name.Keepalive() {
n.Name.SetKeepalive(false)
n.SetAddrtaken(true) // ensure SSA keeps the n variable
- kill = nod(OVARLIVE, n, nil)
+ kill := nod(OVARLIVE, n, nil)
kill = typecheck(kill, Etop)
*out = append(*out, kill)
}
- kill = nod(OVARKILL, n, nil)
+ kill := nod(OVARKILL, n, nil)
kill = typecheck(kill, Etop)
*out = append(*out, kill)
}
case OAS2, OAS2DOTTYPE, OAS2MAPR, OAS2FUNC:
var post []*Node
- var m *Node
- var a *Node
- for i1, n1 := range n.List.Slice() {
- if n1.Op == OINDEXMAP {
- m = n1
+ for i, m := range n.List.Slice() {
+ switch {
+ case m.Op == OINDEXMAP:
if !m.Left.IsAutoTmp() {
m.Left = ordercopyexpr(m.Left, m.Left.Type, order, 0)
}
if !m.Right.IsAutoTmp() {
m.Right = ordercopyexpr(m.Right, m.Right.Type, order, 0)
}
- n.List.SetIndex(i1, ordertemp(m.Type, order, false))
- a = nod(OAS, m, n.List.Index(i1))
- a = typecheck(a, Etop)
- post = append(post, a)
- } else if instrumenting && n.Op == OAS2FUNC && !isblank(n.List.Index(i1)) {
- m = n.List.Index(i1)
+ fallthrough
+ case instrumenting && n.Op == OAS2FUNC && !isblank(m):
t := ordertemp(m.Type, order, false)
- n.List.SetIndex(i1, t)
- a = nod(OAS, m, t)
+ n.List.SetIndex(i, t)
+ a := nod(OAS, m, t)
a = typecheck(a, Etop)
post = append(post, a)
}
// hiter contains pointers and needs to be zeroed.
prealloc[n] = ordertemp(hiter(n.Type), order, true)
}
- for i := range n.List.Slice() {
- n.List.SetIndex(i, orderexprinplace(n.List.Index(i), order))
+ for i, n1 := range n.List.Slice() {
+ n.List.SetIndex(i, orderexprinplace(n1, order))
}
orderblockNodes(&n.Nbody)
order.out = append(order.out, n)
case OSELECT:
t := marktemp(order)
- var tmp1 *Node
- var tmp2 *Node
- var r *Node
for _, n2 := range n.List.Slice() {
if n2.Op != OXCASE {
Fatalf("order select case %v", n2.Op)
}
- r = n2.Left
+ r := n2.Left
setlineno(n2)
// Append any new body prologue to ninit.
// use channel element type for temporary to avoid conversions,
// such as in case interfacevalue = <-intchan.
// the conversion happens in the OAS instead.
- tmp1 = r.Left
+ tmp1 := r.Left
if r.Colas() {
- tmp2 = nod(ODCL, tmp1, nil)
+ tmp2 := nod(ODCL, tmp1, nil)
tmp2 = typecheck(tmp2, Etop)
n2.Ninit.Append(tmp2)
}
r.Left = ordertemp(r.Right.Left.Type.Elem(), order, types.Haspointers(r.Right.Left.Type.Elem()))
- tmp2 = nod(OAS, tmp1, r.Left)
+ tmp2 := nod(OAS, tmp1, r.Left)
tmp2 = typecheck(tmp2, Etop)
n2.Ninit.Append(tmp2)
}
r.List.Set(nil)
}
if r.List.Len() != 0 {
- tmp1 = r.List.First()
+ tmp1 := r.List.First()
if r.Colas() {
- tmp2 = nod(ODCL, tmp1, nil)
+ tmp2 := nod(ODCL, tmp1, nil)
tmp2 = typecheck(tmp2, Etop)
n2.Ninit.Append(tmp2)
}
r.List.Set1(ordertemp(types.Types[TBOOL], order, false))
- tmp2 = okas(tmp1, r.List.First())
+ tmp2 := okas(tmp1, r.List.First())
tmp2 = typecheck(tmp2, Etop)
n2.Ninit.Append(tmp2)
}
// ../../../../runtime/type.go:/structType
// for security, only the exported fields.
case TSTRUCT:
- n := 0
-
- for _, t1 := range t.Fields().Slice() {
+ fields := t.Fields().Slice()
+ for _, t1 := range fields {
dtypesym(t1.Type)
- n++
}
// All non-exported struct field names within a struct
// struct type descriptor, we can omit that
// information from the field descriptors.
var spkg *types.Pkg
- for _, f := range t.Fields().Slice() {
+ for _, f := range fields {
if !exportname(f.Sym.Name) {
spkg = f.Sym.Pkg
break
ot = dcommontype(lsym, ot, t)
ot = dgopkgpath(lsym, ot, spkg)
ot = dsymptr(lsym, ot, lsym, ot+3*Widthptr+uncommonSize(t))
- ot = duintptr(lsym, ot, uint64(n))
- ot = duintptr(lsym, ot, uint64(n))
+ ot = duintptr(lsym, ot, uint64(len(fields)))
+ ot = duintptr(lsym, ot, uint64(len(fields)))
- dataAdd := n * structfieldSize()
+ dataAdd := len(fields) * structfieldSize()
ot = dextratype(lsym, ot, t, dataAdd)
- for _, f := range t.Fields().Slice() {
+ for _, f := range fields {
// ../../../../runtime/type.go:/structField
ot = dnameField(lsym, ot, spkg, f)
ot = dsymptr(lsym, ot, dtypesym(f.Type), 0)
}
func initreorder(l []*Node, out *[]*Node) {
- var n *Node
- for _, n = range l {
+ for _, n := range l {
switch n.Op {
case ODCLFUNC, ODCLCONST, ODCLTYPE:
continue
// put dynamics into array (5)
var index int64
- for _, r := range n.List.Slice() {
- value := r
- if r.Op == OKEY {
- index = nonnegintconst(r.Left)
- value = r.Right
+ for _, value := range n.List.Slice() {
+ if value.Op == OKEY {
+ index = nonnegintconst(value.Left)
+ value = value.Right
}
a := nod(OINDEX, vauto, nodintconst(index))
a.SetBounded(true)
// find all the exported symbols in package opkg
// and make them available in the current package
func importdot(opkg *types.Pkg, pack *Node) {
- var s1 *types.Sym
- var pkgerror string
-
n := 0
for _, s := range opkg.Syms {
if s.Def == nil {
if !exportname(s.Name) || strings.ContainsRune(s.Name, 0xb7) { // 0xb7 = center dot
continue
}
- s1 = lookup(s.Name)
+ s1 := lookup(s.Name)
if s1.Def != nil {
- pkgerror = fmt.Sprintf("during import %q", opkg.Path)
+ pkgerror := fmt.Sprintf("during import %q", opkg.Path)
redeclare(s1, pkgerror)
continue
}
for i3, l := range n.List.Slice() {
setlineno(l)
if l.Op != OKEY {
- n.List.SetIndex(i3, typecheck(n.List.Index(i3), Erv))
+ n.List.SetIndex(i3, typecheck(l, Erv))
yyerror("missing key in map literal")
continue
}
// Need valid field offsets for Xoffset below.
dowidth(t)
- bad := 0
+ errored := false
if n.List.Len() != 0 && nokeys(n.List) {
// simple list of variables
ls := n.List.Slice()
n1 = typecheck(n1, Erv)
ls[i] = n1
if i >= t.NumFields() {
- if bad == 0 {
+ if !errored {
yyerror("too many values in struct initializer")
+ errored = true
}
- bad++
continue
}
}
if l.Op != OSTRUCTKEY {
- if bad == 0 {
+ if !errored {
yyerror("mixture of field:value and value initializers")
+ errored = true
}
- bad++
ls[i] = typecheck(ls[i], Erv)
continue
}
// then it is done first. otherwise must
// make temp variables
func reorder1(all []*Node) []*Node {
- c := 0 // function calls
- t := 0 // total parameters
+ if len(all) == 1 {
+ return all
+ }
+ funcCalls := 0
for _, n := range all {
- t++
updateHasCall(n)
if n.HasCall() {
- c++
+ funcCalls++
}
}
-
- if c == 0 || t == 1 {
+ if funcCalls == 0 {
return all
}
}
d++
- if d == c {
+ if d == funcCalls {
f = n
continue
}
}
t := nod(OTFUNC, nil, nil)
- num := 0
var printargs []*Node
- for _, n1 := range n.List.Slice() {
- buf := fmt.Sprintf("a%d", num)
- num++
+ for i, n1 := range n.List.Slice() {
+ buf := fmt.Sprintf("a%d", i)
a := namedfield(buf, n1.Type)
t.List.Append(a)
printargs = append(printargs, a.Left)