From 56fe611154df5ee796e3cc8c22eddb7b8a031a2f Mon Sep 17 00:00:00 2001 From: Softonik Date: Fri, 26 Jan 2024 03:28:42 +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=B8=20=D1=81=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=D1=81=D1=82=D0=B2=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 | 9 ++++++-- pkg/service/features/app.feature | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/pkg/service/expr.go b/pkg/service/expr.go index 0371eb5..2d93910 100644 --- a/pkg/service/expr.go +++ b/pkg/service/expr.go @@ -87,8 +87,13 @@ func handleSelectorExpr(expr ast.Expr) string { code := "" switch x := s.X.(type) { case *ast.Ident: - if isInMethod && x.Name == currentReceiverName { - code += "this->" + if isInMethod { + if x.Name == currentReceiverName { + code += "this" + } else { + code += handleIdentExpr(x) + } + code += "->" } else { code += handleIdentExpr(x) code += "." diff --git a/pkg/service/features/app.feature b/pkg/service/features/app.feature index 2b60f65..3643f42 100644 --- a/pkg/service/features/app.feature +++ b/pkg/service/features/app.feature @@ -161,3 +161,38 @@ this->x=1; this->x=this->y; } ``` + + Сценарий: Структура с вызовом метода и свойства другого объекта + * Исходник: +``` +package test + +type device struct { + x int +} + +func (d *device) doSomething() { + dev2.doSomethingElse() +} +func (d *device) doSomethingElse() { + dev2.x = 1 + d.x = dev2.x +} +``` + * Результат: +``` +class device { +public: + int x; + void doSomething(); + void doSomethingElse(); +}; +void device::doSomething() { +dev2->doSomethingElse(); +} +void device::doSomethingElse() { +dev2->x=1; +this->x=dev2->x; +} +``` +