Добавлено переводов строк для наглядности результата

Этот коммит содержится в:
Softonik 2024-02-12 13:37:10 +03:00 коммит произвёл Nobody
родитель ca4c4a0fd6
коммит ba57ec17b1
3 изменённых файлов: 8 добавлений и 9 удалений

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

@ -120,7 +120,7 @@ func (c *class) methodImplementationToString(m *ast.FuncDecl) (code string) {
code += c.name + "::"
code += m.Name.String() + "("
code += handleFuncDeclParams(m.Type)
code += ") {"
code += ") {\n"
if len(m.Recv.List) > 0 {
n := m.Recv.List[0].Names
if len(n) > 0 {
@ -130,9 +130,7 @@ func (c *class) methodImplementationToString(m *ast.FuncDecl) (code string) {
}
code += handleBlockStmt(m.Body)
isInMethod = false
code += "}"
code += "\n"
code += "}\n"
return
}

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

@ -53,9 +53,9 @@ func handleFunctionDeclaration(fd *ast.FuncDecl) string {
addFunctionDeclaration(ft + " " + name + "(" + fp + ");")
code += ") {"
code += ") {\n"
code += handleBlockStmt(fd.Body)
code += "}"
code += "}\n"
return code
}
func shouldSkipFunction(t *ast.FuncType) (res bool) {

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

@ -16,6 +16,7 @@ func handleBlockStmt(body *ast.BlockStmt) string {
}
for _, stmt := range body.List {
code += handleStmt(stmt, false)
code += "\n"
}
return code
}
@ -174,7 +175,7 @@ func handleForStmt(stmt *ast.ForStmt) string {
code += ";"
code += handleStmt(stmt.Post, true)
}
code += ") {"
code += ") {\n"
code += handleBlockStmt(stmt.Body)
code += "}"
return code
@ -183,10 +184,10 @@ func handleForStmt(stmt *ast.ForStmt) string {
func handleIfStmt(stmt *ast.IfStmt) string {
cond := handleExpr(stmt.Cond)
body := handleBlockStmt(stmt.Body)
code := fmt.Sprintf(`if (%s) { %s }`, cond, body)
code := fmt.Sprintf("if (%s) {\n %s }\n", cond, body)
if stmt.Else != nil {
tail := handleBlockStmt(stmt.Else.(*ast.BlockStmt))
code += fmt.Sprintf(" else { %s }", tail)
code += fmt.Sprintf(" else {\n %s }\n", tail)
}
return code
}