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

View file

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

View file

@ -63,7 +63,7 @@ func MethodParams(addr interop.Hash160, h interop.Hash256,
type MyStruct struct {} type MyStruct struct {}
func (ms MyStruct) MethodOnStruct() { } func (ms MyStruct) MethodOnStruct() { }
func (ms *MyStruct) MethodOnPointerToStruct() { } 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) info, err := getBuildInfo("foo.go", src)
@ -101,6 +101,7 @@ func _deploy(data interface{}, isUpdate bool) {}
vars := map[string][]string{ vars := map[string][]string{
"Main": {"s,ByteString", "res,Integer"}, "Main": {"s,ByteString", "res,Integer"},
manifest.MethodInit: {"a,Integer", "x,ByteString"}, manifest.MethodInit: {"a,Integer", "x,ByteString"},
manifest.MethodDeploy: {"x,Integer"},
} }
for i := range d.Methods { for i := range d.Methods {
v, ok := vars[d.Methods[i].ID] v, ok := vars[d.Methods[i].ID]