From 43604f262fda59ed20fa26438caed2ff1b78b243 Mon Sep 17 00:00:00 2001 From: Softonik Date: Sat, 19 Nov 2022 22:39:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B1=D0=B5=D1=81=D0=BA=D0=BE=D0=BD=D0=B5=D1=87=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D1=86=D0=B8=D0=BA=D0=BB=D0=B0=20for=20{}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile/service.go | 10 ++++++++-- transpile/service_test.go | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/transpile/service.go b/transpile/service.go index 548774f..ccfee17 100644 --- a/transpile/service.go +++ b/transpile/service.go @@ -545,13 +545,19 @@ func handleForStmt(stmt *ast.ForStmt) string { code += handleStmt(stmt.Init, true) code += ";" } - code += handleBinaryExpr(stmt.Cond) // stmt.Cond + + if stmt.Cond != nil { + code += handleBinaryExpr(stmt.Cond) + } else { + code += "1" + } + if !is_while { code += ";" code += handleStmt(stmt.Post, true) } code += ") {" - code += handleBlockStmt(stmt.Body) // stmt.Body + code += handleBlockStmt(stmt.Body) code += "}" return code } diff --git a/transpile/service_test.go b/transpile/service_test.go index 322f8d4..601ceea 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -790,6 +790,27 @@ var _ = Describe("Go Translator", func() { }) Describe("Циклы", func() { + It("for {}", func() { + source := `package test + func Loop() { + var i int + for { + i = i + } + } + ` + expected := ` + void loop(); + + void loop() { + int i; + while (1) { + i = i; + } + } + ` + Compare(source, expected) + }) It("for i=0; i<10; i+=1", func() { source := `package test func Setup() {}