diff --git a/pkg/service/expr.go b/pkg/service/expr.go index 72f0bee..8445a25 100644 --- a/pkg/service/expr.go +++ b/pkg/service/expr.go @@ -22,6 +22,8 @@ func handleExpr(expr ast.Expr) string { code += handleParenExpr(e) case *ast.SelectorExpr: code += handleSelectorExpr(e) + case *ast.StructType: + code += handleStructType(e) } return code } diff --git a/pkg/service/features/app.feature b/pkg/service/features/app.feature index 75b6122..53a8860 100644 --- a/pkg/service/features/app.feature +++ b/pkg/service/features/app.feature @@ -22,5 +22,24 @@ type device struct {} ``` * Результат: ``` -class device {} +class device { +public: +}; +``` + + Сценарий: Структура с полем + * Исходник: +``` +package test + +type device struct { + a int +} +``` + * Результат: +``` +class device { +public: + int a; +}; ``` diff --git a/pkg/service/type.go b/pkg/service/type.go index 8fea284..f9f551c 100644 --- a/pkg/service/type.go +++ b/pkg/service/type.go @@ -10,6 +10,43 @@ func handleTypeSpec(spec ast.Spec) string { code += " " code += s.Name.String() code += " " - code += "{}" + code += "{\n" + code += handleClass(s.Type) + // spew.Dump(s.TypeParams) + code += "};\n" + return code +} + +func handleClass(e ast.Expr) string { + code := "" + code += "public:\n" + code += handleExpr(e) + // spew.Dump(e) + return code +} + +func handleStructType(s *ast.StructType) string { + code := "" + code += handleFieldList(s.Fields) + return code +} + +func handleFieldList(l *ast.FieldList) string { + code := "" + for _, f := range l.List { + code += handleField(f) + } + return code +} + +func handleField(f *ast.Field) string { + code := "" + code += " " + code += handleIdentExpr(f.Type) + code += " " + for _, n := range f.Names { + code += handleIdentExpr(n) + } + code += ";\n" return code }