本文整理匯總了Golang中golang.org/x/tools/go/ssa.Value.Referrers方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.Referrers方法的具體用法?Golang Value.Referrers怎麽用?Golang Value.Referrers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類golang.org/x/tools/go/ssa.Value
的用法示例。
在下文中一共展示了Value.Referrers方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: isAlive
func (f *Function) isAlive(loc ssa.Instruction, val ssa.Value) bool {
block := loc.Block()
instrIdx := f.instrIdxInBlock(loc)
if val.Referrers() == nil {
return false
}
for _, ref := range *val.Referrers() {
bk := ref.Block()
if bk.Index != block.Index {
continue
}
for i, _ := range bk.Instrs {
if i > instrIdx {
return true
}
}
}
return false
}
示例2: escapes
func escapes(val ssa.Value, bb *ssa.BasicBlock, pending []ssa.Value) bool {
for _, p := range pending {
if val == p {
return false
}
}
for _, ref := range *val.Referrers() {
switch ref := ref.(type) {
case *ssa.Phi:
// We must consider the variable to have escaped if it is
// possible for the program to see more than one "version"
// of the variable at once, as this requires the program
// to use heap allocation for the multiple versions.
//
// I (pcc) think that this is only possible (without stores)
// in the case where a phi node that (directly or indirectly)
// refers to the allocation dominates the allocation.
if ref.Block().Dominates(bb) {
return true
}
if escapes(ref, bb, append(pending, val)) {
return true
}
case *ssa.BinOp, *ssa.ChangeType, *ssa.Convert, *ssa.ChangeInterface, *ssa.MakeInterface, *ssa.Slice, *ssa.FieldAddr, *ssa.IndexAddr, *ssa.TypeAssert, *ssa.Extract:
if escapes(ref.(ssa.Value), bb, append(pending, val)) {
return true
}
case *ssa.Range, *ssa.DebugRef:
continue
case *ssa.UnOp:
if ref.Op == token.MUL || ref.Op == token.ARROW {
continue
}
if escapes(ref, bb, append(pending, val)) {
return true
}
case *ssa.Store:
if val == ref.Val {
return true
}
case *ssa.Call:
if builtin, ok := ref.Call.Value.(*ssa.Builtin); ok {
switch builtin.Name() {
case "cap", "len", "copy", "ssa:wrapnilchk":
continue
case "append":
if ref.Call.Args[0] == val && escapes(ref, bb, append(pending, val)) {
return true
}
default:
return true
}
} else {
return true
}
default:
return true
}
}
return false
}