From 3c170271c419e55193f2624ccb6d3ce7e2c75d11 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 12 Aug 2020 17:39:41 +0300 Subject: [PATCH 1/2] compiler: provide namespace for events names For proper NEO3 debugger work we should provide namespaces for events names in .debug.json files. But we don't have namespaces in .yml configuration files and don't need this information for .manifest.json generation, so let's just keep namespaces empty. This do not prevents debugger from accepting our .debug.json files. --- pkg/compiler/compiler.go | 6 ++++-- pkg/compiler/debug.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 5df26aea2..16c28d146 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -194,8 +194,10 @@ func CompileAndSave(src string, o *Options) ([]byte, error) { } } di.Events[i] = EventDebugInfo{ - ID: e.Name, - Name: e.Name, + ID: 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, } } diff --git a/pkg/compiler/debug.go b/pkg/compiler/debug.go index 71e8f4adb..df99aca3d 100644 --- a/pkg/compiler/debug.go +++ b/pkg/compiler/debug.go @@ -51,7 +51,7 @@ type DebugMethodName struct { // EventDebugInfo represents smart-contract's event debug information. type EventDebugInfo struct { 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"` Parameters []DebugParam `json:"params"` } From 9456f729bea2b38d66ea2a87930db6971719626d Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 13 Aug 2020 10:29:08 +0300 Subject: [PATCH 2/2] compiler: generate methods names with lowercased first letter Methods names from debuginfo should match methods names from manifest. Original method names are stored in ID field. --- pkg/compiler/compiler_test.go | 2 +- pkg/compiler/debug.go | 12 +++++++++--- pkg/compiler/debug_test.go | 6 +++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index 797e0a16a..3341fb799 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -32,7 +32,7 @@ func TestCompiler(t *testing.T) { require.NoError(t, err) m := map[string]bool{} 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, "Func2") diff --git a/pkg/compiler/debug.go b/pkg/compiler/debug.go index df99aca3d..6aeca7e9f 100644 --- a/pkg/compiler/debug.go +++ b/pkg/compiler/debug.go @@ -8,6 +8,8 @@ import ( "go/types" "strconv" "strings" + "unicode" + "unicode/utf8" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/smartcontract" @@ -26,8 +28,11 @@ type DebugInfo struct { // MethodDebugInfo represents smart-contract's method debug information. type MethodDebugInfo struct { + // ID is the actual name of the method. 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"` // IsExported defines whether method is exported. IsExported bool `json:"-"` @@ -158,10 +163,11 @@ func (c *codegen) methodInfoFromScope(name string, scope *funcScope) *MethodDebu } ss := strings.Split(name, ".") name = ss[len(ss)-1] + r, n := utf8.DecodeRuneInString(name) return &MethodDebugInfo{ ID: name, Name: DebugMethodName{ - Name: name, + Name: string(unicode.ToLower(r)) + name[n:], Namespace: scope.pkg.Name(), }, IsExported: scope.decl.Name.IsExported(), @@ -292,7 +298,7 @@ func (m *MethodDebugInfo) ToManifestMethod() (manifest.Method, error) { if err != nil { 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.Parameters = parameters result.ReturnType = returnType diff --git a/pkg/compiler/debug_test.go b/pkg/compiler/debug_test.go index 69305f10d..95c778e8c 100644 --- a/pkg/compiler/debug_test.go +++ b/pkg/compiler/debug_test.go @@ -69,7 +69,7 @@ func unexportedMethod() int { return 1 } "unexportedMethod": "Integer", } 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) } }) @@ -79,7 +79,7 @@ func unexportedMethod() int { return 1 } "Main": {"s,String", "res,Integer"}, } for i := range d.Methods { - v, ok := vars[d.Methods[i].Name.Name] + v, ok := vars[d.Methods[i].ID] if ok { require.Equal(t, v, d.Methods[i].Variables) } @@ -112,7 +112,7 @@ func unexportedMethod() int { return 1 } }}, } for i := range d.Methods { - v, ok := paramTypes[d.Methods[i].Name.Name] + v, ok := paramTypes[d.Methods[i].ID] if ok { require.Equal(t, v, d.Methods[i].Parameters) }