compiler: emit debug variable info for _deploy()

This commit is contained in:
Evgeniy Stratonikov 2021-05-12 16:03:47 +03:00
parent b72f6be9e9
commit 7b638d5489
3 changed files with 9 additions and 3 deletions

View file

@ -48,6 +48,8 @@ type codegen struct {
staticVariables []string
// initVariables contains variables local to `_initialize` method.
initVariables []string
// deployVariables contains variables local to `_initialize` method.
deployVariables []string
// A mapping from label's names to their ids.
labels map[labelWithType]uint16
@ -464,6 +466,8 @@ func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl, pkg *types.
if isInit {
c.initVariables = append(c.initVariables, f.variables...)
} else if isDeploy {
c.deployVariables = append(c.deployVariables, f.variables...)
}
f.rng.End = uint16(c.prog.Len() - 1)

View file

@ -169,6 +169,7 @@ func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
ReturnType: "Void",
ReturnTypeSC: smartcontract.VoidType,
SeqPoints: c.sequencePoints[manifest.MethodDeploy],
Variables: c.deployVariables,
})
}
for name, scope := range c.funcs {

View file

@ -63,7 +63,7 @@ func MethodParams(addr interop.Hash160, h interop.Hash256,
type MyStruct struct {}
func (ms MyStruct) MethodOnStruct() { }
func (ms *MyStruct) MethodOnPointerToStruct() { }
func _deploy(data interface{}, isUpdate bool) {}
func _deploy(data interface{}, isUpdate bool) { x := 1; _ = x }
`
info, err := getBuildInfo("foo.go", src)
@ -99,8 +99,9 @@ func _deploy(data interface{}, isUpdate bool) {}
t.Run("variables", func(t *testing.T) {
vars := map[string][]string{
"Main": {"s,ByteString", "res,Integer"},
manifest.MethodInit: {"a,Integer", "x,ByteString"},
"Main": {"s,ByteString", "res,Integer"},
manifest.MethodInit: {"a,Integer", "x,ByteString"},
manifest.MethodDeploy: {"x,Integer"},
}
for i := range d.Methods {
v, ok := vars[d.Methods[i].ID]