compiler: rename named unused global vars to "_"
So that (*codegen).Visit is able to omit code generation for these unused global vars. The most tricky part is to detect unused global variables, it is done in several steps: 1. Collect the set of named used/unused global vars. 2. Collect the set of globally declared expressions that contain function calls. 3. Pick up global vars from the set made at step 2. 4. Traverse used functions and puck up those global vars that are used from these functions. 5. Rename all globals that are presented in the set made at step 1 but are not presented in the set made on step 3 or step 4.
This commit is contained in:
parent
1e6b70d570
commit
800321db06
10 changed files with 903 additions and 22 deletions
18
pkg/compiler/testdata/globalvar/funccall/main.go
vendored
Normal file
18
pkg/compiler/testdata/globalvar/funccall/main.go
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
package funccall
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/compiler/testdata/globalvar/nested1"
|
||||
"github.com/nspcc-dev/neo-go/pkg/compiler/testdata/globalvar/nested2"
|
||||
alias "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/globalvar/nested3"
|
||||
)
|
||||
|
||||
// F should be called from the main package to check usage analyzer against
|
||||
// nested constructions handling.
|
||||
func F() int {
|
||||
return nested1.F(nested2.Argument + alias.Argument)
|
||||
}
|
||||
|
||||
// GetAge calls method on the global struct.
|
||||
func GetAge() int {
|
||||
return alias.Anna.GetAge()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue