compiler: use fully-qualified names for tracking functions

Function name now consists of 3 parts:
1) full package path
2) method receiver type (if any)
3) function name itself .

Fix #1150.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-07-29 17:20:00 +03:00
parent 528c184f00
commit a781d299e0
8 changed files with 87 additions and 15 deletions

View file

@ -45,7 +45,7 @@ type funcScope struct {
i int
}
func newFuncScope(decl *ast.FuncDecl, label uint16) *funcScope {
func (c *codegen) newFuncScope(decl *ast.FuncDecl, label uint16) *funcScope {
var name string
if decl.Name != nil {
name = decl.Name.Name
@ -54,6 +54,7 @@ func newFuncScope(decl *ast.FuncDecl, label uint16) *funcScope {
name: name,
decl: decl,
label: label,
pkg: c.currPkg,
vars: newVarScope(),
voidCalls: map[*ast.CallExpr]bool{},
variables: []string{},
@ -61,6 +62,14 @@ func newFuncScope(decl *ast.FuncDecl, label uint16) *funcScope {
}
}
func (c *codegen) getFuncNameFromDecl(pkgPath string, decl *ast.FuncDecl) string {
name := decl.Name.Name
if decl.Recv != nil {
name = decl.Recv.List[0].Type.(*ast.Ident).Name + "." + name
}
return c.getIdentName(pkgPath, name)
}
// analyzeVoidCalls checks for functions that are not assigned
// and therefore we need to cleanup the return value from the stack.
func (c *funcScope) analyzeVoidCalls(node ast.Node) bool {