From: Matthew Dempsky Date: Wed, 6 Sep 2023 22:52:55 +0000 (-0700) Subject: cmd/internal/ir: remove ConstExpr in favor of BasicLit X-Git-Tag: go1.22rc1~939 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7f1f4a193662f18393ee7a189bccba4f3d1c3a64;p=gostls13.git cmd/internal/ir: remove ConstExpr in favor of BasicLit OrigNode will be going away soon, which is the only reason for ConstExpr to exist. Otherwise, it's identical to BasicLit. To keep existing code working, change NewConstExpr to construct and return a BasicLit instead. Change-Id: I68b43ec1fcaa57e6723f289ce9f953996aeefb14 Reviewed-on: https://go-review.googlesource.com/c/go/+/526395 Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Cuong Manh Le Auto-Submit: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/ir/expr.go b/src/cmd/compile/internal/ir/expr.go index 7204451364..573021a554 100644 --- a/src/cmd/compile/internal/ir/expr.go +++ b/src/cmd/compile/internal/ir/expr.go @@ -148,6 +148,15 @@ func NewBasicLit(pos src.XPos, val constant.Value) Node { func (n *BasicLit) Val() constant.Value { return n.val } func (n *BasicLit) SetVal(val constant.Value) { n.val = val } +// NewConstExpr returns an OLITERAL representing val, copying the +// position and type from orig. +func NewConstExpr(val constant.Value, orig Node) Node { + n := NewBasicLit(orig.Pos(), val) + n.SetType(orig.Type()) + n.SetTypecheck(orig.Typecheck()) + return n +} + // A BinaryExpr is a binary expression X Op Y, // or Op(X, Y) for builtin functions that do not become calls. type BinaryExpr struct { @@ -258,25 +267,6 @@ func (n *CompLitExpr) SetOp(op Op) { } } -type ConstExpr struct { - miniExpr - origNode - val constant.Value -} - -func NewConstExpr(val constant.Value, orig Node) Node { - n := &ConstExpr{val: val} - n.op = OLITERAL - n.pos = orig.Pos() - n.orig = orig - n.SetType(orig.Type()) - n.SetTypecheck(orig.Typecheck()) - return n -} - -func (n *ConstExpr) Sym() *types.Sym { return n.orig.Sym() } -func (n *ConstExpr) Val() constant.Value { return n.val } - // A ConvExpr is a conversion Type(X). // It may end up being a value or a type. type ConvExpr struct { diff --git a/src/cmd/compile/internal/ir/node_gen.go b/src/cmd/compile/internal/ir/node_gen.go index 1274431b14..1fd8e89936 100644 --- a/src/cmd/compile/internal/ir/node_gen.go +++ b/src/cmd/compile/internal/ir/node_gen.go @@ -471,25 +471,6 @@ func (n *CompLitExpr) editChildrenWithHidden(edit func(Node) Node) { } } -func (n *ConstExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) } -func (n *ConstExpr) copy() Node { - c := *n - c.init = copyNodes(c.init) - return &c -} -func (n *ConstExpr) doChildren(do func(Node) bool) bool { - if doNodes(n.init, do) { - return true - } - return false -} -func (n *ConstExpr) editChildren(edit func(Node) Node) { - editNodes(n.init, edit) -} -func (n *ConstExpr) editChildrenWithHidden(edit func(Node) Node) { - editNodes(n.init, edit) -} - func (n *ConvExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) } func (n *ConvExpr) copy() Node { c := *n