mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: add ir.ContainsClosure
And use it to unify all codes that need parent/closure checking. Change-Id: I0b0aa1b007598668dff2c4bee31e21f0fb3830ce Reviewed-on: https://go-review.googlesource.com/c/go/+/650315 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
34073a736a
commit
a08984bc8f
3 changed files with 21 additions and 28 deletions
|
|
@ -627,3 +627,18 @@ func (fn *Func) DeclareParams(setNname bool) {
|
|||
declareParams(params, PPARAM, "~p", 0)
|
||||
declareParams(results, PPARAMOUT, "~r", len(params))
|
||||
}
|
||||
|
||||
// ContainsClosure reports whether c is a closure contained within f.
|
||||
func ContainsClosure(f, c *Func) bool {
|
||||
// Common cases.
|
||||
if f == c || c.OClosure == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
for p := c.ClosureParent; p != nil; p = p.ClosureParent {
|
||||
if p == f {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue