]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/ir: remove ConstExpr in favor of BasicLit
authorMatthew Dempsky <mdempsky@google.com>
Wed, 6 Sep 2023 22:52:55 +0000 (15:52 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 8 Sep 2023 18:51:02 +0000 (18:51 +0000)
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 <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/node_gen.go

index 7204451364f0b2e4c4ba5cef64609bddaa243216..573021a554bae142eaaa3268c8ec2e1b28a11949 100644 (file)
@@ -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 {
index 1274431b14a7e284376a8f36c4983df953e946f8..1fd8e89936699545837ff9cfc7ce9ec7cd692613 100644 (file)
@@ -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