From 94ea4afaf4f2d2b58e56689e888d7d1c7fa53096 Mon Sep 17 00:00:00 2001 From: Softonik Date: Mon, 12 Feb 2024 06:30:07 +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=9A=D0=BB=D0=B0=D1=81=D1=81:=20=D1=81=D0=B2=D0=BE?= =?UTF-8?q?=D0=B9=D1=81=D1=82=D0=B2=D0=BE=20=D1=82=D0=B8=D0=BF=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D0=B8=D0=BB=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=20-=20=D1=83?= =?UTF-8?q?=D0=BA=D0=B0=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/expr.go | 1 + pkg/service/features/app.feature | 31 +++++++++++++++++++++++++++++++ pkg/service/type.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) 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 "" +}