]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: add ir.TypeNodeAt
authorMatthew Dempsky <mdempsky@google.com>
Fri, 11 Jun 2021 08:10:10 +0000 (01:10 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 11 Jun 2021 14:46:12 +0000 (14:46 +0000)
This CL adds a variant of ir.TypeNode that allows specifying position
information. This shouldn't normally be needed/used, but it's
occasionally helpful for writing code that passes toolstash -cmp.

Change-Id: I2be5da0339fd1ec2bee01d6c5310bd2ef58c46b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/327049
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/ir/type.go

index a903ea8cd45543faebe7c9bce30c428f318b6a1b..431468375a1122159b90c581419b9b8cfd03345e 100644 (file)
@@ -300,11 +300,22 @@ func (n *typeNode) CanBeNtype()       {}
 
 // TypeNode returns the Node representing the type t.
 func TypeNode(t *types.Type) Ntype {
+       return TypeNodeAt(src.NoXPos, t)
+}
+
+// TypeNodeAt is like TypeNode, but allows specifying the position
+// information if a new OTYPE needs to be constructed.
+//
+// Deprecated: Use TypeNode instead. For typical use, the position for
+// an anonymous OTYPE node should not matter. However, TypeNodeAt is
+// available for use with toolstash -cmp to refactor existing code
+// that is sensitive to OTYPE position.
+func TypeNodeAt(pos src.XPos, t *types.Type) Ntype {
        if n := t.Obj(); n != nil {
                if n.Type() != t {
                        base.Fatalf("type skew: %v has type %v, but expected %v", n, n.Type(), t)
                }
                return n.(Ntype)
        }
-       return newTypeNode(src.NoXPos, t)
+       return newTypeNode(pos, t)
 }