diff options
author | Teddy Wing | 2023-05-16 01:09:40 +0200 |
---|---|---|
committer | Teddy Wing | 2023-05-16 01:09:40 +0200 |
commit | 3442d134b4a66ecc198da08151fdd2cfea3aad4e (patch) | |
tree | b30b6171d624086261323367beb84c8a8ed32d33 | |
parent | 7308a5c8da0a11fb74b138ebcd5f980135f88eb5 (diff) | |
download | gocapturedrefrace-3442d134b4a66ecc198da08151fdd2cfea3aad4e.tar.bz2 |
Use `pass.TypesInfo.Defs[ident]` to differentiate DEFINE/ASSIGN
Got this idea from a question by zhizhixiong
(https://stackoverflow.com/users/12073516/zhizhixiong) on Stack
Overflow:
https://stackoverflow.com/questions/66544145/how-to-find-the-declaration-of-an-ident-using-go-analysis
This seems to correctly print defines and assigns. It doesn't print the
`decl` variable though.
-rw-r--r-- | gocapturedrefrace.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 0ca4af7..d88989e 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -160,6 +160,12 @@ func assignmentsInFunc( fmt.Printf("assignment: %v\n", assignment.Tok) } + if pass.TypesInfo.Defs[ident] != nil { + fmt.Println("DEFINE:", ident) + } else { + fmt.Println("ASSIGN:", ident) + } + assignments = append(assignments, ident.Name) return true |