From b09e560a4de8bdff9da45ba6f67c8cc3a4c0245b Mon Sep 17 00:00:00 2001 From: Softonik Date: Mon, 22 Jan 2024 03:07:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B8=D1=81=D1=82=D0=BA=D0=B0:=20Spec=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=87=D0=B8=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/service.go | 32 -------------------------------- pkg/service/spec.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 pkg/service/spec.go diff --git a/pkg/service/service.go b/pkg/service/service.go index ca647d4..fc715a4 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -472,23 +472,6 @@ func handleIfStmt(stmt *ast.IfStmt) string { return code } -func handleImportSpec(spec ast.Spec) string { - s := spec.(*ast.ImportSpec) - code := "" - if s.Name != nil { - name := handleIdent(s.Name) - if val, ok := mapping[name]; ok { - name = val - } - if name != "" { - if name != "controller" { - code = "#include <" + name + ".h>\n" - } - } - } - return code -} - func handleSelectorExpr(expr ast.Expr) string { s := expr.(*ast.SelectorExpr) code := "" @@ -504,21 +487,6 @@ func handleSelectorExpr(expr ast.Expr) string { return code } -func handleSpecs(specs []ast.Spec) string { - code := "" - for _, spec := range specs { - switch spec.(type) { - case *ast.ImportSpec: - code += handleImportSpec(spec) - case *ast.ValueSpec: - code += handleValueSpec(spec) + ";" - case *ast.TypeSpec: - code += handleTypeSpec(spec) - } - } - return code -} - func handleStmt(stmt ast.Stmt, standaloneAssignment bool) string { code := "" switch s := stmt.(type) { diff --git a/pkg/service/spec.go b/pkg/service/spec.go new file mode 100644 index 0000000..c69edc3 --- /dev/null +++ b/pkg/service/spec.go @@ -0,0 +1,37 @@ +package service + +import ( + "go/ast" +) + +func handleSpecs(specs []ast.Spec) string { + code := "" + for _, spec := range specs { + switch spec.(type) { + case *ast.ImportSpec: + code += handleImportSpec(spec) + case *ast.ValueSpec: + code += handleValueSpec(spec) + ";" + case *ast.TypeSpec: + code += handleTypeSpec(spec) + } + } + return code +} + +func handleImportSpec(spec ast.Spec) string { + s := spec.(*ast.ImportSpec) + code := "" + if s.Name != nil { + name := handleIdent(s.Name) + if val, ok := mapping[name]; ok { + name = val + } + if name != "" { + if name != "controller" { + code = "#include <" + name + ".h>\n" + } + } + } + return code +}