forked from TrueCloudLab/neoneo-go
compiler: emit debug variable info for init()
This commit is contained in:
parent
7afca7f8e5
commit
b72f6be9e9
3 changed files with 18 additions and 1 deletions
|
@ -46,6 +46,8 @@ type codegen struct {
|
||||||
globals map[string]int
|
globals map[string]int
|
||||||
// staticVariables contains global (static in NDX-DN11) variable names and types.
|
// staticVariables contains global (static in NDX-DN11) variable names and types.
|
||||||
staticVariables []string
|
staticVariables []string
|
||||||
|
// initVariables contains variables local to `_initialize` method.
|
||||||
|
initVariables []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
|
||||||
|
@ -460,6 +462,10 @@ func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl, pkg *types.
|
||||||
emit.Opcodes(c.prog.BinWriter, opcode.RET)
|
emit.Opcodes(c.prog.BinWriter, opcode.RET)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isInit {
|
||||||
|
c.initVariables = append(c.initVariables, f.variables...)
|
||||||
|
}
|
||||||
|
|
||||||
f.rng.End = uint16(c.prog.Len() - 1)
|
f.rng.End = uint16(c.prog.Len() - 1)
|
||||||
|
|
||||||
if !isLambda {
|
if !isLambda {
|
||||||
|
|
|
@ -138,6 +138,7 @@ func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
|
||||||
ReturnType: "Void",
|
ReturnType: "Void",
|
||||||
ReturnTypeSC: smartcontract.VoidType,
|
ReturnTypeSC: smartcontract.VoidType,
|
||||||
SeqPoints: c.sequencePoints["init"],
|
SeqPoints: c.sequencePoints["init"],
|
||||||
|
Variables: c.initVariables,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if c.deployEndOffset >= 0 {
|
if c.deployEndOffset >= 0 {
|
||||||
|
|
|
@ -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/storage"
|
||||||
import "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
|
import "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
|
||||||
var staticVar int
|
var staticVar int
|
||||||
|
func init() {
|
||||||
|
a := 1
|
||||||
|
_ = a
|
||||||
|
}
|
||||||
|
func init() {
|
||||||
|
x := ""
|
||||||
|
_ = x
|
||||||
|
staticVar = 1
|
||||||
|
}
|
||||||
func Main(op string) bool {
|
func Main(op string) bool {
|
||||||
var s string
|
var s string
|
||||||
_ = s
|
_ = s
|
||||||
|
@ -90,7 +99,8 @@ func _deploy(data interface{}, isUpdate bool) {}
|
||||||
|
|
||||||
t.Run("variables", func(t *testing.T) {
|
t.Run("variables", func(t *testing.T) {
|
||||||
vars := map[string][]string{
|
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 {
|
for i := range d.Methods {
|
||||||
v, ok := vars[d.Methods[i].ID]
|
v, ok := vars[d.Methods[i].ID]
|
||||||
|
|
Loading…
Reference in a new issue