From 04c61b67a1fa4bf08564bcc7b79254bace396c77 Mon Sep 17 00:00:00 2001 From: Softonik Date: Sun, 11 Feb 2024 22:25:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=86=D0=B5=D0=BD=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B9:=20=D0=A1=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80?= =?UTF-8?q?=D0=B0=20=D1=81=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=D0=BE=D0=BC=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D0=B4=D1=80=D1=83=D0=B3?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/expr.go | 11 +++++++---- pkg/service/features/app.feature | 25 +++++++++++++++++++++++++ pkg/service/value.go | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) 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) }