GoPLS Viewer

Home|gopls/go/pointer/callgraph.go
1// Copyright 2013 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
5package pointer
6
7// This file defines the internal (context-sensitive) call graph.
8
9import (
10    "fmt"
11    "go/token"
12
13    "golang.org/x/tools/go/ssa"
14)
15
16type cgnode struct {
17    fn         *ssa.Function
18    obj        nodeid      // start of this contour's object block
19    sites      []*callsite // ordered list of callsites within this function
20    callersite *callsite   // where called from, if known; nil for shared contours
21}
22
23// contour returns a description of this node's contour.
24func (n *cgnodecontour() string {
25    if n.callersite == nil {
26        return "shared contour"
27    }
28    if n.callersite.instr != nil {
29        return fmt.Sprintf("as called from %s"n.callersite.instr.Parent())
30    }
31    return fmt.Sprintf("as called from intrinsic (targets=n%d)"n.callersite.targets)
32}
33
34func (n *cgnodeString() string {
35    return fmt.Sprintf("cg%d:%s"n.objn.fn)
36}
37
38// A callsite represents a single call site within a cgnode;
39// it is implicitly context-sensitive.
40// callsites never represent calls to built-ins;
41// they are handled as intrinsics.
42type callsite struct {
43    targets nodeid              // pts(ยท) contains objects for dynamically called functions
44    instr   ssa.CallInstruction // the call instruction; nil for synthetic/intrinsic
45}
46
47func (c *callsiteString() string {
48    if c.instr != nil {
49        return c.instr.Common().Description()
50    }
51    return "synthetic function call"
52}
53
54// pos returns the source position of this callsite, or token.NoPos if implicit.
55func (c *callsitepos() token.Pos {
56    if c.instr != nil {
57        return c.instr.Pos()
58    }
59    return token.NoPos
60}
61
MembersX
cgnode
cgnode.String
callsite.instr
cgnode.sites
callsite
callsite.String
callsite.pos.c
callsite.pos
cgnode.contour
callsite.String.c
cgnode.fn
cgnode.obj
cgnode.callersite
cgnode.contour.n
cgnode.String.n
callsite.targets
Members
X