Skip to content

Commit 44e9031

Browse files
committed
cmd/internal/gc: more Node cleanups
More Node cleanups, these ones touch go.y. - convert Node.Implicit to bool - convert Node.Used to bool Change-Id: I85c7ff9e66cee7122b560adedc995166c874f2f2 Reviewed-on: https://go-review.googlesource.com/7124 Reviewed-by: Keith Randall <[email protected]>
1 parent 42c8be4 commit 44e9031

15 files changed

+77
-77
lines changed

src/cmd/internal/gc/closure.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func transformclosure(xfunc *Node) {
402402
addr = newname(Lookup(namebuf))
403403
addr.Ntype = Nod(OIND, typenod(v.Type), nil)
404404
addr.Class = PAUTO
405-
addr.Used = 1
405+
addr.Used = true
406406
addr.Curfn = xfunc
407407
xfunc.Dcl = list(xfunc.Dcl, addr)
408408
v.Heapaddr = addr
@@ -461,7 +461,7 @@ func walkclosure(func_ *Node, init **NodeList) *Node {
461461

462462
clos := Nod(OCOMPLIT, nil, Nod(OIND, typ, nil))
463463
clos.Esc = func_.Esc
464-
clos.Right.Implicit = 1
464+
clos.Right.Implicit = true
465465
clos.List = concat(list1(Nod(OCFUNC, func_.Closure.Nname, nil)), func_.Enter)
466466

467467
// Force type conversion from *struct to the func type.
@@ -609,7 +609,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
609609
ptr.Class = PAUTO
610610
ptr.Addable = 1
611611
ptr.Ullman = 1
612-
ptr.Used = 1
612+
ptr.Used = true
613613
ptr.Curfn = xfunc
614614
xfunc.Dcl = list(xfunc.Dcl, ptr)
615615
var body *NodeList
@@ -667,7 +667,7 @@ func walkpartialcall(n *Node, init **NodeList) *Node {
667667

668668
clos := Nod(OCOMPLIT, nil, Nod(OIND, typ, nil))
669669
clos.Esc = n.Esc
670-
clos.Right.Implicit = 1
670+
clos.Right.Implicit = true
671671
clos.List = list1(Nod(OCFUNC, n.Nname.Nname, nil))
672672
clos.List = list(clos.List, n.Left)
673673

src/cmd/internal/gc/esc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ func esccall(e *EscState, n *Node, up *Node) {
10951095
src.Class = PAUTO
10961096
src.Curfn = Curfn
10971097
src.Escloopdepth = e.loopdepth
1098-
src.Used = 1
1098+
src.Used = true
10991099
src.Lineno = n.Lineno
11001100
n.Escretval = list(n.Escretval, src)
11011101
}

src/cmd/internal/gc/fmt.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ func Jconv(n *Node, flag int) string {
273273
fp += fmt.Sprintf(" isddd(%d)", n.Isddd)
274274
}
275275

276-
if n.Implicit != 0 {
277-
fp += fmt.Sprintf(" implicit(%d)", n.Implicit)
276+
if n.Implicit {
277+
fp += fmt.Sprintf(" implicit(%v)", n.Implicit)
278278
}
279279

280280
if n.Embedded != 0 {
@@ -289,8 +289,8 @@ func Jconv(n *Node, flag int) string {
289289
fp += " assigned"
290290
}
291291

292-
if c == 0 && n.Used != 0 {
293-
fp += fmt.Sprintf(" used(%d)", n.Used)
292+
if c == 0 && n.Used {
293+
fp += fmt.Sprintf(" used(%v)", n.Used)
294294
}
295295
return fp
296296
}
@@ -859,7 +859,7 @@ func stmtfmt(n *Node) string {
859859
}
860860

861861
case OASOP:
862-
if n.Implicit != 0 {
862+
if n.Implicit {
863863
if n.Etype == OADD {
864864
f += fmt.Sprintf("%v++", Nconv(n.Left, 0))
865865
} else {
@@ -1109,7 +1109,7 @@ var opprec = []int{
11091109
}
11101110

11111111
func exprfmt(n *Node, prec int) string {
1112-
for n != nil && n.Implicit != 0 && (n.Op == OIND || n.Op == OADDR) {
1112+
for n != nil && n.Implicit && (n.Op == OIND || n.Op == OADDR) {
11131113
n = n.Left
11141114
}
11151115

@@ -1266,9 +1266,9 @@ func exprfmt(n *Node, prec int) string {
12661266
return f
12671267

12681268
case OCOMPLIT:
1269-
ptrlit := n.Right != nil && n.Right.Implicit != 0 && n.Right.Type != nil && Isptr[n.Right.Type.Etype]
1269+
ptrlit := n.Right != nil && n.Right.Implicit && n.Right.Type != nil && Isptr[n.Right.Type.Etype]
12701270
if fmtmode == FErr {
1271-
if n.Right != nil && n.Right.Type != nil && n.Implicit == 0 {
1271+
if n.Right != nil && n.Right.Type != nil && !n.Implicit {
12721272
if ptrlit {
12731273
return fmt.Sprintf("&%v literal", Tconv(n.Right.Type.Type, 0))
12741274
} else {
@@ -1289,7 +1289,7 @@ func exprfmt(n *Node, prec int) string {
12891289
return f
12901290

12911291
case OPTRLIT:
1292-
if fmtmode == FExp && n.Left.Implicit != 0 {
1292+
if fmtmode == FExp && n.Left.Implicit {
12931293
return fmt.Sprintf("%v", Nconv(n.Left, 0))
12941294
}
12951295
var f string
@@ -1299,7 +1299,7 @@ func exprfmt(n *Node, prec int) string {
12991299
case OSTRUCTLIT:
13001300
if fmtmode == FExp { // requires special handling of field names
13011301
var f string
1302-
if n.Implicit != 0 {
1302+
if n.Implicit {
13031303
f += "{"
13041304
} else {
13051305
f += fmt.Sprintf("(%v{", Tconv(n.Type, 0))
@@ -1314,7 +1314,7 @@ func exprfmt(n *Node, prec int) string {
13141314
}
13151315
}
13161316

1317-
if n.Implicit == 0 {
1317+
if !n.Implicit {
13181318
f += "})"
13191319
return f
13201320
}
@@ -1330,7 +1330,7 @@ func exprfmt(n *Node, prec int) string {
13301330
if fmtmode == FErr {
13311331
return fmt.Sprintf("%v literal", Tconv(n.Type, 0))
13321332
}
1333-
if fmtmode == FExp && n.Implicit != 0 {
1333+
if fmtmode == FExp && n.Implicit {
13341334
return fmt.Sprintf("{ %v }", Hconv(n.List, obj.FmtComma))
13351335
}
13361336
var f string

src/cmd/internal/gc/gen.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ func Tempname(nn *Node, t *Type) {
613613
func temp(t *Type) *Node {
614614
n := Nod(OXXX, nil, nil)
615615
Tempname(n, t)
616-
n.Sym.Def.Used = 1
616+
n.Sym.Def.Used = true
617617
return n.Orig
618618
}
619619

src/cmd/internal/gc/go.y

+10-10
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ simple_stmt:
418418
switch($$.Op) {
419419
case ONAME, ONONAME, OTYPE, OPACK, OLITERAL:
420420
$$ = Nod(OPAREN, $$, nil);
421-
$$.Implicit = 1;
421+
$$.Implicit = true;
422422
break;
423423
}
424424
}
@@ -460,13 +460,13 @@ simple_stmt:
460460
| expr LINC
461461
{
462462
$$ = Nod(OASOP, $1, Nodintconst(1));
463-
$$.Implicit = 1;
463+
$$.Implicit = true;
464464
$$.Etype = OADD;
465465
}
466466
| expr LDEC
467467
{
468468
$$ = Nod(OASOP, $1, Nodintconst(1));
469-
$$.Implicit = 1;
469+
$$.Implicit = true;
470470
$$.Etype = OSUB;
471471
}
472472

@@ -886,7 +886,7 @@ uexpr:
886886
// Special case for &T{...}: turn into (*T){...}.
887887
$$ = $2;
888888
$$.Right = Nod(OIND, $$.Right, nil);
889-
$$.Right.Implicit = 1;
889+
$$.Right.Implicit = true;
890890
} else {
891891
$$ = Nod(OADDR, $2, nil);
892892
}
@@ -949,7 +949,7 @@ pexpr_no_paren:
949949
if $1.Op == OPACK {
950950
var s *Sym
951951
s = restrictlookup($3.Name, $1.Pkg);
952-
$1.Used = 1;
952+
$1.Used = true;
953953
$$ = oldname(s);
954954
break;
955955
}
@@ -1034,7 +1034,7 @@ bare_complitexpr:
10341034
switch($$.Op) {
10351035
case ONAME, ONONAME, OTYPE, OPACK, OLITERAL:
10361036
$$ = Nod(OPAREN, $$, nil);
1037-
$$.Implicit = 1;
1037+
$$.Implicit = true;
10381038
}
10391039
}
10401040
| '{' start_complit braced_keyval_list '}'
@@ -1160,7 +1160,7 @@ name:
11601160
{
11611161
$$ = oldname($1);
11621162
if $$.Pack != nil {
1163-
$$.Pack.Used = 1;
1163+
$$.Pack.Used = true;
11641164
}
11651165
}
11661166

@@ -1238,7 +1238,7 @@ dotname:
12381238
if $1.Op == OPACK {
12391239
var s *Sym
12401240
s = restrictlookup($3.Name, $1.Pkg);
1241-
$1.Used = 1;
1241+
$1.Used = true;
12421242
$$ = oldname(s);
12431243
break;
12441244
}
@@ -1626,7 +1626,7 @@ packname:
16261626
$$ = $1;
16271627
n = oldname($1);
16281628
if n.Pack != nil {
1629-
n.Pack.Used = 1;
1629+
n.Pack.Used = true;
16301630
}
16311631
}
16321632
| LNAME '.' sym
@@ -1637,7 +1637,7 @@ packname:
16371637
Yyerror("%v is not a package", Sconv($1, 0));
16381638
pkg = localpkg;
16391639
} else {
1640-
$1.Def.Used = 1;
1640+
$1.Def.Used = true;
16411641
pkg = $1.Def.Pkg;
16421642
}
16431643
$$ = restrictlookup($3.Name, pkg);

src/cmd/internal/gc/gsubr.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ func fixautoused(p *obj.Prog) {
174174
if p == nil {
175175
break
176176
}
177-
if p.As == obj.ATYPE && p.From.Node != nil && p.From.Name == obj.NAME_AUTO && ((p.From.Node).(*Node)).Used == 0 {
177+
if p.As == obj.ATYPE && p.From.Node != nil && p.From.Name == obj.NAME_AUTO && !((p.From.Node).(*Node)).Used {
178178
*lp = p.Link
179179
continue
180180
}
181181

182-
if (p.As == obj.AVARDEF || p.As == obj.AVARKILL) && p.To.Node != nil && ((p.To.Node).(*Node)).Used == 0 {
182+
if (p.As == obj.AVARDEF || p.As == obj.AVARKILL) && p.To.Node != nil && !((p.To.Node).(*Node)).Used {
183183
// Cannot remove VARDEF instruction, because - unlike TYPE handled above -
184184
// VARDEFs are interspersed with other code, and a jump might be using the
185185
// VARDEF as a target. Replace with a no-op instead. A later pass will remove
@@ -267,11 +267,11 @@ func markautoused(p *obj.Prog) {
267267
}
268268

269269
if p.From.Node != nil {
270-
((p.From.Node).(*Node)).Used = 1
270+
((p.From.Node).(*Node)).Used = true
271271
}
272272

273273
if p.To.Node != nil {
274-
((p.To.Node).(*Node)).Used = 1
274+
((p.To.Node).(*Node)).Used = true
275275
}
276276
}
277277
}

src/cmd/internal/gc/inl.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ func inlvar(var_ *Node) *Node {
840840
n := newname(var_.Sym)
841841
n.Type = var_.Type
842842
n.Class = PAUTO
843-
n.Used = 1
843+
n.Used = true
844844
n.Curfn = Curfn // the calling function, not the called one
845845
n.Addrtaken = var_.Addrtaken
846846

@@ -863,7 +863,7 @@ func retvar(t *Type, i int) *Node {
863863
n := newname(Lookup(namebuf))
864864
n.Type = t.Type
865865
n.Class = PAUTO
866-
n.Used = 1
866+
n.Used = true
867867
n.Curfn = Curfn // the calling function, not the called one
868868
Curfn.Dcl = list(Curfn.Dcl, n)
869869
return n
@@ -876,7 +876,7 @@ func argvar(t *Type, i int) *Node {
876876
n := newname(Lookup(namebuf))
877877
n.Type = t.Type
878878
n.Class = PAUTO
879-
n.Used = 1
879+
n.Used = true
880880
n.Curfn = Curfn // the calling function, not the called one
881881
Curfn.Dcl = list(Curfn.Dcl, n)
882882
return n

src/cmd/internal/gc/lex.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3131,7 +3131,7 @@ func mkpackage(pkgname string) {
31313131
// leave s->block set to cause redeclaration
31323132
// errors if a conflicting top-level name is
31333133
// introduced by a different file.
3134-
if s.Def.Used == 0 && nsyntaxerrors == 0 {
3134+
if !s.Def.Used && nsyntaxerrors == 0 {
31353135
pkgnotused(int(s.Def.Lineno), s.Def.Pkg.Path, s.Name)
31363136
}
31373137
s.Def = nil
@@ -3141,9 +3141,9 @@ func mkpackage(pkgname string) {
31413141
if s.Def.Sym != s {
31423142
// throw away top-level name left over
31433143
// from previous import . "x"
3144-
if s.Def.Pack != nil && s.Def.Pack.Used == 0 && nsyntaxerrors == 0 {
3144+
if s.Def.Pack != nil && !s.Def.Pack.Used && nsyntaxerrors == 0 {
31453145
pkgnotused(int(s.Def.Pack.Lineno), s.Def.Pack.Pkg.Path, "")
3146-
s.Def.Pack.Used = 1
3146+
s.Def.Pack.Used = true
31473147
}
31483148

31493149
s.Def = nil

src/cmd/internal/gc/pgen.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ func cmpstackvar(a *Node, b *Node) int {
197197
return 0
198198
}
199199

200-
if (a.Used == 0) != (b.Used == 0) {
201-
return int(b.Used) - int(a.Used)
200+
if a.Used != b.Used {
201+
return bool2int(b.Used) - bool2int(a.Used)
202202
}
203203

204204
ap := bool2int(haspointers(a.Type))
@@ -235,7 +235,7 @@ func allocauto(ptxt *obj.Prog) {
235235
// Mark the PAUTO's unused.
236236
for ll := Curfn.Dcl; ll != nil; ll = ll.Next {
237237
if ll.N.Class == PAUTO {
238-
ll.N.Used = 0
238+
ll.N.Used = false
239239
}
240240
}
241241

@@ -247,7 +247,7 @@ func allocauto(ptxt *obj.Prog) {
247247
ll := Curfn.Dcl
248248

249249
n := ll.N
250-
if n.Class == PAUTO && n.Op == ONAME && n.Used == 0 {
250+
if n.Class == PAUTO && n.Op == ONAME && !n.Used {
251251
// No locals used at all
252252
Curfn.Dcl = nil
253253

@@ -257,7 +257,7 @@ func allocauto(ptxt *obj.Prog) {
257257

258258
for ll := Curfn.Dcl; ll.Next != nil; ll = ll.Next {
259259
n = ll.Next.N
260-
if n.Class == PAUTO && n.Op == ONAME && n.Used == 0 {
260+
if n.Class == PAUTO && n.Op == ONAME && !n.Used {
261261
ll.Next = nil
262262
Curfn.Dcl.End = ll
263263
break

src/cmd/internal/gc/select.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func typecheckselect(sel *Node) {
4545
// remove implicit conversions; the eventual assignment
4646
// will reintroduce them.
4747
case OAS:
48-
if (n.Right.Op == OCONVNOP || n.Right.Op == OCONVIFACE) && n.Right.Implicit != 0 {
48+
if (n.Right.Op == OCONVNOP || n.Right.Op == OCONVIFACE) && n.Right.Implicit {
4949
n.Right = n.Right.Left
5050
}
5151

src/cmd/internal/gc/subr.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ func assignconv(n *Node, t *Type, context string) *Node {
13411341
r := Nod(OCONVNOP, n, nil)
13421342
r.Type = Types[TBOOL]
13431343
r.Typecheck = 1
1344-
r.Implicit = 1
1344+
r.Implicit = true
13451345
n = r
13461346
}
13471347
}
@@ -1360,7 +1360,7 @@ func assignconv(n *Node, t *Type, context string) *Node {
13601360
r := Nod(op, n, nil)
13611361
r.Type = t
13621362
r.Typecheck = 1
1363-
r.Implicit = 1
1363+
r.Implicit = true
13641364
r.Orig = n.Orig
13651365
return r
13661366
}
@@ -2146,7 +2146,7 @@ func adddot(n *Node) *Node {
21462146
// rebuild elided dots
21472147
for c := d - 1; c >= 0; c-- {
21482148
if n.Left.Type != nil && Isptr[n.Left.Type.Etype] {
2149-
n.Left.Implicit = 1
2149+
n.Left.Implicit = true
21502150
}
21512151
n.Left = Nod(ODOT, n.Left, newname(dotlist[c].field.Sym))
21522152
}

src/cmd/internal/gc/syntax.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ type Node struct {
4343
Local uint8
4444
Dodata uint8
4545
Initorder uint8
46-
Used uint8
46+
Used bool
4747
Isddd uint8
4848
Readonly bool
49-
Implicit uint8
49+
Implicit bool
5050
Addrtaken bool // address taken, even if not moved to heap
5151
Assigned bool // is the variable ever assigned to
5252
Captured bool // is the variable captured by a closure

0 commit comments

Comments
 (0)