compiler: emit debug variable info for init()

This commit is contained in:
Evgeniy Stratonikov 2021-05-12 15:08:22 +03:00
parent 7afca7f8e5
commit b72f6be9e9
3 changed files with 18 additions and 1 deletions

View file

@ -46,6 +46,8 @@ type codegen struct {
globals map[string]int
// staticVariables contains global (static in NDX-DN11) variable names and types.
staticVariables []string
// initVariables contains variables local to `_initialize` method.
initVariables []string
// A mapping from label's names to their ids.
labels map[labelWithType]uint16
@ -460,6 +462,10 @@ func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl, pkg *types.
emit.Opcodes(c.prog.BinWriter, opcode.RET)
}
if isInit {
c.initVariables = append(c.initVariables, f.variables...)
}
f.rng.End = uint16(c.prog.Len() - 1)
if !isLambda {

View file

@ -138,6 +138,7 @@ func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
ReturnType: "Void",
ReturnTypeSC: smartcontract.VoidType,
SeqPoints: c.sequencePoints["init"],
Variables: c.initVariables,
})
}
if c.deployEndOffset >= 0 {

View file

@ -18,6 +18,15 @@ func TestCodeGen_DebugInfo(t *testing.T) {
import "github.com/nspcc-dev/neo-go/pkg/interop/storage"
import "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
var staticVar int
func init() {
a := 1
_ = a
}
func init() {
x := ""
_ = x
staticVar = 1
}
func Main(op string) bool {
var s string
_ = s
@ -90,7 +99,8 @@ func _deploy(data interface{}, isUpdate bool) {}
t.Run("variables", func(t *testing.T) {
vars := map[string][]string{
"Main": {"s,ByteString", "res,Integer"},
"Main": {"s,ByteString", "res,Integer"},
manifest.MethodInit: {"a,Integer", "x,ByteString"},
}
for i := range d.Methods {
v, ok := vars[d.Methods[i].ID]