Сценарий: Инициализация переменной - тип auto

Этот коммит содержится в:
Softonik 2024-02-12 05:55:59 +03:00 коммит произвёл Nobody
родитель 1d39dfa762
коммит a62f3e06ad
2 изменённых файлов: 36 добавлений и 4 удалений

Просмотреть файл

@ -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");
}
```

Просмотреть файл

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