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.
This commit is contained in:
Anna Shaleva 2020-08-13 10:29:08 +03:00
parent 3c170271c4
commit 9456f729be
3 changed files with 13 additions and 7 deletions

View file

@ -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