diff --git a/pkg/service/expr.go b/pkg/service/expr.go index 52ac982..6db9db7 100644 --- a/pkg/service/expr.go +++ b/pkg/service/expr.go @@ -109,9 +109,7 @@ func handleParenExpr(stmt *ast.ParenExpr) string { return code } -func handleSelectorExpr(expr ast.Expr) string { - s := expr.(*ast.SelectorExpr) - code := "" +func handleSelectorExpr(s *ast.SelectorExpr) (code string) { switch x := s.X.(type) { case *ast.Ident: if isInMethod { @@ -125,12 +123,17 @@ func handleSelectorExpr(expr ast.Expr) string { code += handleIdentExpr(x) code += "." } + case *ast.SelectorExpr: + code += "this" + code += "->" + code += handleIdentExpr(x.Sel) + code += "->" } code += handleIdentExpr(s.Sel) if val, ok := mapping[code]; ok { code = val } - return code + return } func handleStarExpr(s *ast.StarExpr) (code string) { diff --git a/pkg/service/features/app.feature b/pkg/service/features/app.feature index 266e920..c70f7df 100644 --- a/pkg/service/features/app.feature +++ b/pkg/service/features/app.feature @@ -131,6 +131,31 @@ this->doSomethingElse(); } void device::doSomethingElse() { } +``` + + Сценарий: Структура с вызовом метода другого объекта + * Исходник: +``` +package test + +type device struct { + remote Other +} + +func (d *device) doSomething() { + d.remote.doSomethingElse() +} +``` + * Результат: +``` +class device { +public: + Other remote; + void doSomething(); +}; +void device::doSomething() { +this->remote->doSomethingElse(); +} ``` Сценарий: Структура с вызовом методов со входящими и выходящими параметрами diff --git a/pkg/service/value.go b/pkg/service/value.go index 09e5669..84a7b12 100644 --- a/pkg/service/value.go +++ b/pkg/service/value.go @@ -87,7 +87,7 @@ func handleValueSpecValues(values []ast.Expr) string { case *ast.BinaryExpr: code += handleBinaryExpr(v) case *ast.SelectorExpr: - code += handleSelectorExpr(value) + code += handleSelectorExpr(v) case *ast.CallExpr: code += handleCallExpr(v) }