diff --git a/pkg/service/expr.go b/pkg/service/expr.go index 193a8a8..e103084 100644 --- a/pkg/service/expr.go +++ b/pkg/service/expr.go @@ -7,6 +7,7 @@ import ( ) func handleExpr(expr ast.Expr) string { + // spew.Dump(expr) code := "" switch e := expr.(type) { case *ast.BasicLit: diff --git a/pkg/service/features/app.feature b/pkg/service/features/app.feature index c3c67fb..301b7d0 100644 --- a/pkg/service/features/app.feature +++ b/pkg/service/features/app.feature @@ -48,6 +48,37 @@ public: virtual void Add(int) = 0; virtual void Add2(int,double) = 0; }; +``` + + Сценарий: Класс: свойство типа интерфейс - указатель + * Исходник: +``` +package test + +type Device interface { +} +type DeviceClass struct { +} +type system struct { + d Device + dc DeviceClass + dcp *DeviceClass +} +``` + * Результат: +``` +class Device { +public: +}; +class DeviceClass { +public: +}; +class system { +public: + Device* d; + DeviceClass* dc; + DeviceClass* dcp; +}; ``` Сценарий: Структура с полем diff --git a/pkg/service/type.go b/pkg/service/type.go index 3670efe..e439051 100644 --- a/pkg/service/type.go +++ b/pkg/service/type.go @@ -58,17 +58,24 @@ func handleFieldList(l *ast.FieldList) string { } func handleField(f *ast.Field) (code string) { + // spew.Dump(f) code += " " switch t := f.Type.(type) { case *ast.Ident: code += handleIdentExpr(t) + case *ast.StarExpr: + code += handleStarExpr(t) case *ast.FuncType: code += handleFuncDeclType(t) case *ast.ArrayType: code += handleArray(t) } + if isClassByExpr(f.Type) { + code += "*" + } + code += " " nado_zapyatuyu := false for _, n := range f.Names { @@ -87,3 +94,27 @@ func handleField(f *ast.Field) (code string) { code += ";\n" return } + +func isClassByExpr(e ast.Expr) (found bool) { + name := getExprTypeName(e) + for _, c := range classDeclarations { + if c.Name() == name { + found = true + break + } + } + return +} +func getExprTypeName(te ast.Expr) string { + switch t := te.(type) { + case *ast.Ident: + return t.Name + case *ast.StarExpr: + ident, ok := t.X.(*ast.Ident) + if ok { + return ident.Name + } + } + + return "" +}