Add generated file
This PR adds generated files under pkg/client and vendor folder.
This commit is contained in:
35
vendor/golang.org/x/tools/go/callgraph/static/static.go
generated
vendored
Normal file
35
vendor/golang.org/x/tools/go/callgraph/static/static.go
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// Package static computes the call graph of a Go program containing
|
||||
// only static call edges.
|
||||
package static // import "golang.org/x/tools/go/callgraph/static"
|
||||
|
||||
import (
|
||||
"golang.org/x/tools/go/callgraph"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
"golang.org/x/tools/go/ssa/ssautil"
|
||||
)
|
||||
|
||||
// CallGraph computes the call graph of the specified program
|
||||
// considering only static calls.
|
||||
//
|
||||
func CallGraph(prog *ssa.Program) *callgraph.Graph {
|
||||
cg := callgraph.New(nil) // TODO(adonovan) eliminate concept of rooted callgraph
|
||||
|
||||
// TODO(adonovan): opt: use only a single pass over the ssa.Program.
|
||||
// TODO(adonovan): opt: this is slower than RTA (perhaps because
|
||||
// the lower precision means so many edges are allocated)!
|
||||
for f := range ssautil.AllFunctions(prog) {
|
||||
fnode := cg.CreateNode(f)
|
||||
for _, b := range f.Blocks {
|
||||
for _, instr := range b.Instrs {
|
||||
if site, ok := instr.(ssa.CallInstruction); ok {
|
||||
if g := site.Common().StaticCallee(); g != nil {
|
||||
gnode := cg.CreateNode(g)
|
||||
callgraph.AddEdge(fnode, site, gnode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cg
|
||||
}
|
88
vendor/golang.org/x/tools/go/callgraph/static/static_test.go
generated
vendored
Normal file
88
vendor/golang.org/x/tools/go/callgraph/static/static_test.go
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package static_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/parser"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/go/callgraph"
|
||||
"golang.org/x/tools/go/callgraph/static"
|
||||
"golang.org/x/tools/go/loader"
|
||||
"golang.org/x/tools/go/ssa/ssautil"
|
||||
)
|
||||
|
||||
const input = `package P
|
||||
|
||||
type C int
|
||||
func (C) f()
|
||||
|
||||
type I interface{f()}
|
||||
|
||||
func f() {
|
||||
p := func() {}
|
||||
g()
|
||||
p() // SSA constant propagation => static
|
||||
|
||||
if unknown {
|
||||
p = h
|
||||
}
|
||||
p() // dynamic
|
||||
|
||||
C(0).f()
|
||||
}
|
||||
|
||||
func g() {
|
||||
var i I = C(0)
|
||||
i.f()
|
||||
}
|
||||
|
||||
func h()
|
||||
|
||||
var unknown bool
|
||||
`
|
||||
|
||||
func TestStatic(t *testing.T) {
|
||||
conf := loader.Config{ParserMode: parser.ParseComments}
|
||||
f, err := conf.ParseFile("P.go", input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
conf.CreateFromFiles("P", f)
|
||||
iprog, err := conf.Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
P := iprog.Created[0].Pkg
|
||||
|
||||
prog := ssautil.CreateProgram(iprog, 0)
|
||||
prog.Build()
|
||||
|
||||
cg := static.CallGraph(prog)
|
||||
|
||||
var edges []string
|
||||
callgraph.GraphVisitEdges(cg, func(e *callgraph.Edge) error {
|
||||
edges = append(edges, fmt.Sprintf("%s -> %s",
|
||||
e.Caller.Func.RelString(P),
|
||||
e.Callee.Func.RelString(P)))
|
||||
return nil
|
||||
})
|
||||
sort.Strings(edges)
|
||||
|
||||
want := []string{
|
||||
"(*C).f -> (C).f",
|
||||
"f -> (C).f",
|
||||
"f -> f$1",
|
||||
"f -> g",
|
||||
}
|
||||
if !reflect.DeepEqual(edges, want) {
|
||||
t.Errorf("Got edges %v, want %v", edges, want)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user