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()