Merge pull request #1315 from nspcc-dev/debugger-compatibility-fixes

Debugger compatibility fixes, part 2
This commit is contained in:
Roman Khimov 2020-08-13 18:23:38 +03:00 committed by GitHub
commit bf090a436b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 10 deletions

View file

@ -194,8 +194,10 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
} }
} }
di.Events[i] = EventDebugInfo{ di.Events[i] = EventDebugInfo{
ID: e.Name, ID: e.Name,
Name: e.Name, // DebugInfo event name should be at the format {namespace},{name}
// but we don't provide namespace via .yml config
Name: "," + e.Name,
Parameters: params, Parameters: params,
} }
} }

View file

@ -32,7 +32,7 @@ func TestCompiler(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
m := map[string]bool{} m := map[string]bool{}
for i := range di.Methods { for i := range di.Methods {
m[di.Methods[i].Name.Name] = true m[di.Methods[i].ID] = true
} }
require.Contains(t, m, "Func1") require.Contains(t, m, "Func1")
require.Contains(t, m, "Func2") require.Contains(t, m, "Func2")

View file

@ -8,6 +8,8 @@ import (
"go/types" "go/types"
"strconv" "strconv"
"strings" "strings"
"unicode"
"unicode/utf8"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
@ -26,8 +28,11 @@ type DebugInfo struct {
// MethodDebugInfo represents smart-contract's method debug information. // MethodDebugInfo represents smart-contract's method debug information.
type MethodDebugInfo struct { type MethodDebugInfo struct {
// ID is the actual name of the method.
ID string `json:"id"` ID string `json:"id"`
// Name is the name of the method together with the namespace it belongs to. // Name is the name of the method with the first letter in a lowercase
// together with the namespace it belongs to. We need to keep the first letter
// lowercased to match manifest standards.
Name DebugMethodName `json:"name"` Name DebugMethodName `json:"name"`
// IsExported defines whether method is exported. // IsExported defines whether method is exported.
IsExported bool `json:"-"` IsExported bool `json:"-"`
@ -51,7 +56,7 @@ type DebugMethodName struct {
// EventDebugInfo represents smart-contract's event debug information. // EventDebugInfo represents smart-contract's event debug information.
type EventDebugInfo struct { type EventDebugInfo struct {
ID string `json:"id"` ID string `json:"id"`
// Name is a human-readable event name in a format "{namespace}-{name}". // Name is a human-readable event name in a format "{namespace},{name}".
Name string `json:"name"` Name string `json:"name"`
Parameters []DebugParam `json:"params"` Parameters []DebugParam `json:"params"`
} }
@ -158,10 +163,11 @@ func (c *codegen) methodInfoFromScope(name string, scope *funcScope) *MethodDebu
} }
ss := strings.Split(name, ".") ss := strings.Split(name, ".")
name = ss[len(ss)-1] name = ss[len(ss)-1]
r, n := utf8.DecodeRuneInString(name)
return &MethodDebugInfo{ return &MethodDebugInfo{
ID: name, ID: name,
Name: DebugMethodName{ Name: DebugMethodName{
Name: name, Name: string(unicode.ToLower(r)) + name[n:],
Namespace: scope.pkg.Name(), Namespace: scope.pkg.Name(),
}, },
IsExported: scope.decl.Name.IsExported(), IsExported: scope.decl.Name.IsExported(),
@ -292,7 +298,7 @@ func (m *MethodDebugInfo) ToManifestMethod() (manifest.Method, error) {
if err != nil { if err != nil {
return result, err return result, err
} }
result.Name = strings.ToLower(string(m.Name.Name[0])) + m.Name.Name[1:] result.Name = m.Name.Name
result.Offset = int(m.Range.Start) result.Offset = int(m.Range.Start)
result.Parameters = parameters result.Parameters = parameters
result.ReturnType = returnType result.ReturnType = returnType

View file

@ -69,7 +69,7 @@ func unexportedMethod() int { return 1 }
"unexportedMethod": "Integer", "unexportedMethod": "Integer",
} }
for i := range d.Methods { for i := range d.Methods {
name := d.Methods[i].Name.Name name := d.Methods[i].ID
assert.Equal(t, returnTypes[name], d.Methods[i].ReturnType) assert.Equal(t, returnTypes[name], d.Methods[i].ReturnType)
} }
}) })
@ -79,7 +79,7 @@ func unexportedMethod() int { return 1 }
"Main": {"s,String", "res,Integer"}, "Main": {"s,String", "res,Integer"},
} }
for i := range d.Methods { for i := range d.Methods {
v, ok := vars[d.Methods[i].Name.Name] v, ok := vars[d.Methods[i].ID]
if ok { if ok {
require.Equal(t, v, d.Methods[i].Variables) require.Equal(t, v, d.Methods[i].Variables)
} }
@ -112,7 +112,7 @@ func unexportedMethod() int { return 1 }
}}, }},
} }
for i := range d.Methods { for i := range d.Methods {
v, ok := paramTypes[d.Methods[i].Name.Name] v, ok := paramTypes[d.Methods[i].ID]
if ok { if ok {
require.Equal(t, v, d.Methods[i].Parameters) require.Equal(t, v, d.Methods[i].Parameters)
} }