]> Cypherpunks repositories - gostls13.git/commit
[dev.regabi] cmd/compile: add SameSource, Uses, and DeclaredBy helpers
authorMatthew Dempsky <mdempsky@google.com>
Fri, 4 Dec 2020 00:52:45 +0000 (16:52 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 4 Dec 2020 20:25:07 +0000 (20:25 +0000)
commitd9cb84c84bb0edc1afb782f99de4cc424ac0d23f
treef9d13fe0b2a6417e2c25906951c4c903e8493c0e
parent5dbd2e8e44d823bfbc3df883c544e23f4a872de1
[dev.regabi] cmd/compile: add SameSource, Uses, and DeclaredBy helpers

Currently, because we use the same *Name to represent both declaration
and uses of an object, it's ambiguous what "n1 == n2" means when
comparing two Node values. It can mean any of: Are these the same
syntactic element? Is n1 a use of declared variable n2? Are n1 and n2
both uses of the same declared variable?

We'd like to introduce a new IdentExpr node to replace use of Name
within the AST, but that means those three cases need to be handled
differently. The first case needs to stay "n1 == n2", but the other
cases need to become "n1.Name() == n2" and "n1.Name() == n2.Name()",
respectively. ("n1.Name() == n2.Name()" also currently works for the
second case, but eventually we'll want to get rid of the Name.Name
method.)

This CL introduces helper functions SameSource and Uses to handle
these cases. It also introduces DeclaredBy, which is another somewhat
common case that the next CL introduces uses of.

Passes buildall w/ toolstash -cmp.

Updates #42990.

Change-Id: Ia816c124446e9067645d5820a8163f295968794f
Reviewed-on: https://go-review.googlesource.com/c/go/+/275305
Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/ir/name.go