From 11825a08c406cd9cb27b1209cabff440e950c651 Mon Sep 17 00:00:00 2001 From: Softonik Date: Fri, 26 Jan 2024 03:57:38 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/class.go | 8 +++----- pkg/service/expr.go | 8 ++++++++ pkg/service/features/app.feature | 18 ++++++++++++++++++ pkg/service/type.go | 4 ++++ pkg/service/value.go | 22 +++++++++++++++++++--- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/pkg/service/class.go b/pkg/service/class.go index 6086eb4..634370c 100644 --- a/pkg/service/class.go +++ b/pkg/service/class.go @@ -6,6 +6,9 @@ import ( var ( classDeclarations []*Class + + isInMethod = false + currentReceiverName = "" ) type Class struct { @@ -63,11 +66,6 @@ func (c *Class) methodImplementationsToString() (code string) { return } -var ( - isInMethod = false - currentReceiverName = "" -) - func (c *Class) methodImplementationToString(m *ast.FuncDecl) (code string) { code += "void " code += c.Name + "::" diff --git a/pkg/service/expr.go b/pkg/service/expr.go index 2d93910..4c1aa23 100644 --- a/pkg/service/expr.go +++ b/pkg/service/expr.go @@ -105,3 +105,11 @@ func handleSelectorExpr(expr ast.Expr) string { } return code } + +func handleStarExpr(s *ast.StarExpr) (code string) { + switch x := s.X.(type) { + case *ast.Ident: + code += handleIdentExpr(x) + } + return +} diff --git a/pkg/service/features/app.feature b/pkg/service/features/app.feature index 3643f42..2f9cbc5 100644 --- a/pkg/service/features/app.feature +++ b/pkg/service/features/app.feature @@ -196,3 +196,21 @@ this->x=dev2->x; } ``` + Сценарий: Структура с объявлением переменных-указателей + * Исходник: +``` +package test + +var ( + dev1, dev2 *device +) + +type device struct {} +``` + * Результат: +``` +class device { +public: +}; +device *dev1,*dev2; +``` \ No newline at end of file diff --git a/pkg/service/type.go b/pkg/service/type.go index 7cb0b17..48b28f2 100644 --- a/pkg/service/type.go +++ b/pkg/service/type.go @@ -4,6 +4,10 @@ import ( "go/ast" ) +var ( + isPointerType = false +) + func handleTypeSpec(spec ast.Spec) (code string) { s := spec.(*ast.TypeSpec) handleClass(s) diff --git a/pkg/service/value.go b/pkg/service/value.go index c5c87bf..da64ab8 100644 --- a/pkg/service/value.go +++ b/pkg/service/value.go @@ -9,7 +9,14 @@ func handleValueSpec(spec ast.Spec) string { code := "" code += handleValueSpecType(s.Type) code += " " + + _, ok := s.Type.(*ast.StarExpr) + if ok { + isPointerType = true + } code += handleValueSpecNames(s.Names) + isPointerType = false + if s.Values != nil { code += " = " code += handleValueSpecValues(s.Values) @@ -17,12 +24,19 @@ func handleValueSpec(spec ast.Spec) string { return code } -func handleValueSpecNames(names []*ast.Ident) string { - code := "" +func handleValueSpecNames(names []*ast.Ident) (code string) { + nado_zapyatuyu := false for _, name := range names { + if nado_zapyatuyu { + code += "," + } + if isPointerType { + code += "*" + } code += handleIdentExpr(name) + nado_zapyatuyu = true } - return code + return } func handleValueSpecType(expr ast.Expr) string { @@ -32,6 +46,8 @@ func handleValueSpecType(expr ast.Expr) string { code += handleSelectorExpr(t) case *ast.Ident: code += handleIdentExpr(t) + case *ast.StarExpr: + code += handleStarExpr(t) } return code }