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 }