800321db06
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.
29 lines
751 B
Go
29 lines
751 B
Go
package nested1
|
|
|
|
import (
|
|
"github.com/nspcc-dev/neo-go/pkg/compiler/testdata/globalvar/nested2"
|
|
alias "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/globalvar/nested3"
|
|
)
|
|
|
|
// Unused shouldn't produce any code if unused.
|
|
var Unused = 11
|
|
|
|
// A should produce call to f and should not be DROPped if C is used. It uses
|
|
// aliased package var as an argument to check analizator.
|
|
var A = f(alias.Argument)
|
|
|
|
// B should produce call to f and be DROPped if unused. It uses foreign package var as an argument
|
|
// to check analizator.
|
|
var B = f(nested2.Argument)
|
|
|
|
// C shouldn't produce any code if unused. It uses
|
|
var C = A + nested2.A + nested2.Unique
|
|
|
|
func f(i int) int {
|
|
return i
|
|
}
|
|
|
|
// F is used for nested calls check.
|
|
func F(i int) int {
|
|
return i
|
|
}
|