本文整理汇总了Golang中golang.org/x/tools/go/callgraph.Graph.CreateNode方法的典型用法代码示例。如果您正苦于以下问题:Golang Graph.CreateNode方法的具体用法?Golang Graph.CreateNode怎么用?Golang Graph.CreateNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/tools/go/callgraph.Graph
的用法示例。
在下文中一共展示了Graph.CreateNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FindNonConstCalls
// FindNonConstCalls returns the set of callsites of the given set of methods
// for which the "query" parameter is not a compile-time constant.
func FindNonConstCalls(cg *callgraph.Graph, qms []*QueryMethod) []ssa.CallInstruction {
cg.DeleteSyntheticNodes()
// package database/sql has a couple helper functions which are thin
// wrappers around other sensitive functions. Instead of handling the
// general case by tracing down callsites of wrapper functions
// recursively, let's just whitelist the functions we're already
// tracking, since it happens to be good enough for our use case.
okFuncs := make(map[*ssa.Function]struct{}, len(qms))
for _, m := range qms {
okFuncs[m.SSA] = struct{}{}
}
bad := make([]ssa.CallInstruction, 0)
for _, m := range qms {
node := cg.CreateNode(m.SSA)
for _, edge := range node.In {
if _, ok := okFuncs[edge.Site.Parent()]; ok {
continue
}
cc := edge.Site.Common()
args := cc.Args
// The first parameter is occasionally the receiver.
if len(args) == m.ArgCount+1 {
args = args[1:]
} else if len(args) != m.ArgCount {
panic("arg count mismatch")
}
v := args[m.Param]
if _, ok := v.(*ssa.Const); !ok {
bad = append(bad, edge.Site)
}
}
}
return bad
}