mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-04 09:02:28 +00:00
compiler: allow to use inlined functions to init globals
This commit is contained in:
parent
ac91de80e7
commit
0a4ff9d3e4
5 changed files with 111 additions and 35 deletions
|
@ -46,13 +46,24 @@ func (c *codegen) traverseGlobals() (int, int, int) {
|
|||
var n, nConst int
|
||||
initLocals := -1
|
||||
deployLocals := -1
|
||||
c.ForEachFile(func(f *ast.File, _ *types.Package) {
|
||||
c.ForEachFile(func(f *ast.File, pkg *types.Package) {
|
||||
nv, nc := countGlobals(f)
|
||||
n += nv
|
||||
nConst += nc
|
||||
if initLocals == -1 || deployLocals == -1 || !hasDefer {
|
||||
ast.Inspect(f, func(node ast.Node) bool {
|
||||
switch n := node.(type) {
|
||||
case *ast.GenDecl:
|
||||
if n.Tok == token.VAR {
|
||||
for i := range n.Specs {
|
||||
for _, v := range n.Specs[i].(*ast.ValueSpec).Values {
|
||||
num := c.countLocalsCall(v, pkg)
|
||||
if num > initLocals {
|
||||
initLocals = num
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case *ast.FuncDecl:
|
||||
if isInitFunc(n) {
|
||||
num, _ := c.countLocals(n)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue