From a62f3e06add361fa8a0c1a2e9435f842874e06ad Mon Sep 17 00:00:00 2001 From: Softonik Date: Mon, 12 Feb 2024 05:55:59 +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=98=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D0=BE=D0=B9=20-=20=D1=82=D0=B8=D0=BF=20auto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/features/variables.feature | 16 ++++++++++++++++ pkg/service/stmt.go | 24 ++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/pkg/service/features/variables.feature b/pkg/service/features/variables.feature index 98fd5e4..f115083 100644 --- a/pkg/service/features/variables.feature +++ b/pkg/service/features/variables.feature @@ -87,4 +87,20 @@ void foo(); void foo() { std::string foo = "bar"; } +``` + + Сценарий: Инициализация переменной - тип auto + * Исходник: +``` +package test +func foo() { + a := NewDevice(1,b,"stroka") +} +``` + * Результат: +``` +void foo(); +void foo() { +auto a=NewDevice(1,b,"stroka"); +} ``` diff --git a/pkg/service/stmt.go b/pkg/service/stmt.go index 59b2d69..037faf3 100644 --- a/pkg/service/stmt.go +++ b/pkg/service/stmt.go @@ -3,6 +3,7 @@ package service import ( "fmt" "go/ast" + "go/token" "strings" "github.com/davecgh/go-spew/spew" @@ -57,12 +58,18 @@ func handleStmt(stmt ast.Stmt, standaloneAssignment bool) string { return code } -func handleAssignStmt(as *ast.AssignStmt) string { - code := handleAssignStmtExpr(as.Lhs) - code += as.Tok.String() +func handleAssignStmt(as *ast.AssignStmt) (code string) { + tkn, new := handleToken(as.Tok) + if new { + code += "auto " + } + + code += handleAssignStmtExpr(as.Lhs) + code += tkn code += handleAssignStmtExpr(as.Rhs) - return code + return } + func handleAssignStmtExpr(e []ast.Expr) string { ops := make([]string, 0) code := "" @@ -73,6 +80,15 @@ func handleAssignStmtExpr(e []ast.Expr) string { return code } +func handleToken(t token.Token) (code string, new bool) { + st := t.String() + switch st { + case ":=": + return "=", true + } + return st, false +} + func handleIncDecStmt(as *ast.IncDecStmt) string { code := handleExpr(as.X) code += as.Tok.String()