aboutsummaryrefslogtreecommitdiff
path: root/go/pointer/util.go
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-16 14:15:45 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-16 14:15:45 +0000
commitcd3c7908c2ca750b27d330b4d257edc6818c4a5d (patch)
tree194d7b0e539d014393564a256bec571e18d6533a /go/pointer/util.go
parent3225eca48f7ce16eb31b2dd5a170806c1214a49e (diff)
parent09c5a32afc5b66f28f166a68afe1fc71afbf9b73 (diff)
downloadgolang-x-tools-cd3c7908c2ca750b27d330b4d257edc6818c4a5d.tar.gz
Snap for 9757917 from 09c5a32afc5b66f28f166a68afe1fc71afbf9b73 to build-tools-releasebuild-tools-release
Change-Id: If48e809642d94de846f47e34b88e446095e21aa5
Diffstat (limited to 'go/pointer/util.go')
-rw-r--r--go/pointer/util.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/go/pointer/util.go b/go/pointer/util.go
index 5bdd623c0..17728aa06 100644
--- a/go/pointer/util.go
+++ b/go/pointer/util.go
@@ -8,12 +8,13 @@ import (
"bytes"
"fmt"
"go/types"
- exec "golang.org/x/sys/execabs"
"log"
"os"
"runtime"
"time"
+ exec "golang.org/x/sys/execabs"
+
"golang.org/x/tools/container/intsets"
)
@@ -35,7 +36,6 @@ func CanPoint(T types.Type) bool {
// CanHaveDynamicTypes reports whether the type T can "hold" dynamic types,
// i.e. is an interface (incl. reflect.Type) or a reflect.Value.
-//
func CanHaveDynamicTypes(T types.Type) bool {
switch T := T.(type) {
case *types.Named:
@@ -69,17 +69,21 @@ func deref(typ types.Type) types.Type {
// of a type T: the subelement's type and its path from the root of T.
//
// For example, for this type:
-// type line struct{ points []struct{x, y int} }
+//
+// type line struct{ points []struct{x, y int} }
+//
// flatten() of the inner struct yields the following []fieldInfo:
-// struct{ x, y int } ""
-// int ".x"
-// int ".y"
+//
+// struct{ x, y int } ""
+// int ".x"
+// int ".y"
+//
// and flatten(line) yields:
-// struct{ points []struct{x, y int} } ""
-// struct{ x, y int } ".points[*]"
-// int ".points[*].x
-// int ".points[*].y"
//
+// struct{ points []struct{x, y int} } ""
+// struct{ x, y int } ".points[*]"
+// int ".points[*].x
+// int ".points[*].y"
type fieldInfo struct {
typ types.Type
@@ -89,7 +93,6 @@ type fieldInfo struct {
}
// path returns a user-friendly string describing the subelement path.
-//
func (fi *fieldInfo) path() string {
var buf bytes.Buffer
for p := fi; p != nil; p = p.tail {
@@ -113,7 +116,6 @@ func (fi *fieldInfo) path() string {
// reflect.Value is considered pointerlike, similar to interface{}.
//
// Callers must not mutate the result.
-//
func (a *analysis) flatten(t types.Type) []*fieldInfo {
fl, ok := a.flattenMemo[t]
if !ok {
@@ -124,7 +126,7 @@ func (a *analysis) flatten(t types.Type) []*fieldInfo {
// Debuggability hack: don't remove
// the named type from interfaces as
// they're very verbose.
- fl = append(fl, &fieldInfo{typ: t})
+ fl = append(fl, &fieldInfo{typ: t}) // t may be a type param
} else {
fl = a.flatten(u)
}