From 108890c3bf538e121cc6146ac3bfb86de767ba57 Mon Sep 17 00:00:00 2001 From: Softonik Date: Fri, 26 Jan 2024 04:17:06 +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=BE=D0=B1=D1=8A=D1=8F=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85-=D1=83=D0=BA=D0=B0=D0=B7=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=B9=20=D0=B8=20=D0=B8=D1=85=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/expr.go | 15 +++++++++++---- pkg/service/features/app.feature | 12 ++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pkg/service/expr.go b/pkg/service/expr.go index 4c1aa23..dee0b64 100644 --- a/pkg/service/expr.go +++ b/pkg/service/expr.go @@ -32,10 +32,17 @@ func handleBasicLit(bl *ast.BasicLit) string { return bl.Value } -func handleUnaryExpr(expr *ast.UnaryExpr) string { - code := expr.Op.String() - code += handleExpr(expr.X) - return code +func handleUnaryExpr(expr *ast.UnaryExpr) (code string) { + cl, ok := expr.X.(*ast.CompositeLit) + if ok { + code += "new " + code += handleIdentExpr(cl.Type) + code += "()" + } else { + code += expr.Op.String() + code += handleExpr(expr.X) + } + return } func handleBinaryExpr(expr ast.Expr) string { diff --git a/pkg/service/features/app.feature b/pkg/service/features/app.feature index 2f9cbc5..02c61ce 100644 --- a/pkg/service/features/app.feature +++ b/pkg/service/features/app.feature @@ -196,7 +196,7 @@ this->x=dev2->x; } ``` - Сценарий: Структура с объявлением переменных-указателей + Сценарий: Структура с объявлением переменных-указателей и их созданием * Исходник: ``` package test @@ -206,11 +206,19 @@ var ( ) type device struct {} + +func main() { + dev1 = &device{} +} ``` * Результат: ``` class device { public: }; +void main(); device *dev1,*dev2; -``` \ No newline at end of file +void main() { +dev1=new device(); +} +```