Skip to content

Commit 21d7810

Browse files
committed
cmd/compile: use one format for exporting calls of builtin functions
Minor cleanup. Each of these cases appears both during export and import when running all.bash and thus is tested by all.bash. Change-Id: Iaa4a5a5b163cefe33e43d08d396e02a02e5c22a5 Reviewed-on: https://go-review.googlesource.com/23060 Reviewed-by: Matthew Dempsky <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent eb9062b commit 21d7810

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/cmd/compile/internal/gc/bexport.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -1256,26 +1256,35 @@ func (p *exporter) expr(n *Node) {
12561256
p.expr(max)
12571257

12581258
case OCOPY, OCOMPLEX:
1259+
// treated like other builtin calls (see e.g., OREAL)
12591260
p.op(op)
12601261
p.expr(n.Left)
12611262
p.expr(n.Right)
1263+
p.op(OEND)
12621264

12631265
case OCONV, OCONVIFACE, OCONVNOP, OARRAYBYTESTR, OARRAYRUNESTR, OSTRARRAYBYTE, OSTRARRAYRUNE, ORUNESTR:
12641266
p.op(OCONV)
12651267
p.typ(n.Type)
1266-
if p.bool(n.Left != nil) {
1268+
if n.Left != nil {
12671269
p.expr(n.Left)
1270+
p.op(OEND)
12681271
} else {
1269-
p.exprList(n.List)
1272+
p.exprList(n.List) // emits terminating OEND
12701273
}
12711274

12721275
case OREAL, OIMAG, OAPPEND, OCAP, OCLOSE, ODELETE, OLEN, OMAKE, ONEW, OPANIC, ORECOVER, OPRINT, OPRINTN:
12731276
p.op(op)
1274-
if p.bool(n.Left != nil) {
1277+
if n.Left != nil {
12751278
p.expr(n.Left)
1279+
p.op(OEND)
12761280
} else {
1277-
p.exprList(n.List)
1281+
p.exprList(n.List) // emits terminating OEND
1282+
}
1283+
// only append() calls may contain '...' arguments
1284+
if op == OAPPEND {
12781285
p.bool(n.Isddd)
1286+
} else if n.Isddd {
1287+
Fatalf("exporter: unexpected '...' with %s call", opnames[op])
12791288
}
12801289

12811290
case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER, OGETG:

src/cmd/compile/internal/gc/bimport.go

+4-15
Original file line numberDiff line numberDiff line change
@@ -884,29 +884,18 @@ func (p *importer) node() *Node {
884884
n.SetSliceBounds(low, high, max)
885885
return n
886886

887-
case OCOPY, OCOMPLEX:
888-
n := builtinCall(op)
889-
n.List.Set([]*Node{p.expr(), p.expr()})
890-
return n
891-
892887
// case OCONV, OCONVIFACE, OCONVNOP, OARRAYBYTESTR, OARRAYRUNESTR, OSTRARRAYBYTE, OSTRARRAYRUNE, ORUNESTR:
893888
// unreachable - mapped to OCONV case below by exporter
894889

895890
case OCONV:
896891
n := Nod(OCALL, typenod(p.typ()), nil)
897-
if p.bool() {
898-
n.List.Set1(p.expr())
899-
} else {
900-
n.List.Set(p.exprList())
901-
}
892+
n.List.Set(p.exprList())
902893
return n
903894

904-
case OREAL, OIMAG, OAPPEND, OCAP, OCLOSE, ODELETE, OLEN, OMAKE, ONEW, OPANIC, ORECOVER, OPRINT, OPRINTN:
895+
case OCOPY, OCOMPLEX, OREAL, OIMAG, OAPPEND, OCAP, OCLOSE, ODELETE, OLEN, OMAKE, ONEW, OPANIC, ORECOVER, OPRINT, OPRINTN:
905896
n := builtinCall(op)
906-
if p.bool() {
907-
n.List.Set1(p.expr())
908-
} else {
909-
n.List.Set(p.exprList())
897+
n.List.Set(p.exprList())
898+
if op == OAPPEND {
910899
n.Isddd = p.bool()
911900
}
912901
return n

0 commit comments

Comments
 (0)