Debian Codegraph @

go/types/typeutil/callee.go

raw symbols SCIP
1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package typeutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/types/typeutil`/
6
7 import (
8 "go/astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/"
9 "go/typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/"
10 _ "unsafescip-go gomod github.com/golang/go/src go1.25.0 unsafe/" // for linkname
11 )
12
13 // Callee returns the named target of a function call, if any:
14 // a function, method, builtin, or variable.
15 // It returns nil for a T(x) conversion.
16 //
17 // Functions and methods may potentially have type parameters.
18 //
19 // Note: for calls of instantiated functions and methods, Callee returns
20 // the corresponding generic function or method on the generic type.
21 func Calleescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/types/typeutil`/Callee().(info *typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Infoscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#, call *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.CallExprscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/CallExpr#) typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Objectscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Object# {
22 obj := info.Usesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Uses.[usedIdentscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/types/typeutil`/usedIdent().(info, call.Funscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/CallExpr#Fun.)]
23 if obj == nil {
24 return nil
25 }
26 if _, ok := obj.(*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.TypeNamescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/TypeName#); ok {
27 return nil
28 }
29 return obj
30 }
31
32 // StaticCallee returns the target (function or method) of a static function
33 // call, if any. It returns nil for calls to builtins.
34 //
35 // Note: for calls of instantiated functions and methods, StaticCallee returns
36 // the corresponding generic function or method on the generic type.
37 func StaticCalleescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/types/typeutil`/StaticCallee().(info *typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Infoscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#, call *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.CallExprscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/CallExpr#) *typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Funcscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func# {
38 obj := info.Usesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Uses.[usedIdentscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/types/typeutil`/usedIdent().(info, call.Funscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/CallExpr#Fun.)]
39 fn, _ := obj.(*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Funcscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func#)
40 if fn == nil || interfaceMethodscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/types/typeutil`/interfaceMethod().(fn) {
41 return nil
42 }
43 return fn
44 }
45
46 // usedIdent is the implementation of [internal/typesinternal.UsedIdent].
47 // It returns the identifier associated with e.
48 // See typesinternal.UsedIdent for a fuller description.
49 // This function should live in typesinternal, but cannot because it would
50 // create an import cycle.
51 //
52 //go:linkname usedIdent golang.org/x/tools/go/types/typeutil.usedIdent
53 func usedIdentscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/types/typeutil`/usedIdent().(info *typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Infoscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#, e astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Exprscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Expr#) *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Identscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Ident# {
54 if info.Typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Types. == nil || info.Usesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Uses. == nil {
55 panic("one of info.Types or info.Uses is nil; both must be populated")
56 }
57 // Look through type instantiation if necessary.
58 switch d := astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Unparenscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Unparen().(e).(type) {
59 case *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.IndexExprscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IndexExpr#:
60 if info.Typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Info#Types.[d.Indexscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IndexExpr#Index.].IsTypescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/TypeAndValue#IsType().() {
61 e = d.Xscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IndexExpr#X.
62 }
63 case *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.IndexListExprscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IndexListExpr#:
64 e = d.Xscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/IndexListExpr#X.
65 }
66
67 switch e := astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Unparenscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Unparen().(e).(type) {
68 // info.Uses always has the object we want, even for selector expressions.
69 // We don't need info.Selections.
70 // See go/types/recording.go:recordSelection.
71 case *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Identscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Ident#:
72 return e
73 case *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.SelectorExprscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/SelectorExpr#:
74 return e.Selscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/SelectorExpr#Sel.
75 }
76 return nil
77 }
78
79 // interfaceMethod reports whether its argument is a method of an interface.
80 // This function should live in typesinternal, but cannot because it would create an import cycle.
81 //
82 //go:linkname interfaceMethod golang.org/x/tools/go/types/typeutil.interfaceMethod
83 func interfaceMethodscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/types/typeutil`/interfaceMethod().(f *typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Funcscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func#) bool {
84 recv := f.Signaturescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func#Signature().().Recvscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Signature#Recv().()
85 return recv != nil && typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.IsInterfacescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/IsInterface().(recv.Typescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/object#Type().())
86 }