diff --git a/pkg/service/features/variables.feature b/pkg/service/features/variables.feature index f115083..743dca3 100644 --- a/pkg/service/features/variables.feature +++ b/pkg/service/features/variables.feature @@ -103,4 +103,20 @@ void foo(); void foo() { auto a=NewDevice(1,b,"stroka"); } +``` + + Сценарий: Инициализация переменной - тип string + * Исходник: +``` +package test +func foo() { + a := "stroka" +} +``` + * Результат: +``` +void foo(); +void foo() { +std::string a="stroka"; +} ``` diff --git a/pkg/service/stmt.go b/pkg/service/stmt.go index e8f9ea7..0701221 100644 --- a/pkg/service/stmt.go +++ b/pkg/service/stmt.go @@ -61,18 +61,41 @@ func handleStmt(stmt ast.Stmt, standaloneAssignment bool) string { return code } -func handleAssignStmt(as *ast.AssignStmt) (code string) { - tkn, new := handleToken(as.Tok) +func handleAssignStmt(a *ast.AssignStmt) (code string) { + // println() + // spew.Dump(a) + + tkn, new := handleToken(a.Tok) if new { - code += "auto " + t := "auto" + + if isExpr0String(a.Rhs) { + t = "std::string" + } + + code += t + " " } - code += handleAssignStmtExpr(as.Lhs) + code += handleAssignStmtExpr(a.Lhs) code += tkn - code += handleAssignStmtExpr(as.Rhs) + code += handleAssignStmtExpr(a.Rhs) return } +func isExpr0String(ee []ast.Expr) bool { + if len(ee) == 0 { + return false + } + e0 := ee[0] + + switch e := e0.(type) { + case *ast.BasicLit: + return e.Kind == token.STRING + } + + return false +} + func handleAssignStmtExpr(e []ast.Expr) string { ops := make([]string, 0) code := ""