From f2206eb2b1bde7c9dcc8d20dd729e9b814bcdece Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 6 Aug 2024 14:24:46 +0300 Subject: [PATCH] fix for_bare --- ast.v | 6 ++++++ stmt.v | 12 ++++++++++++ {untested => tests}/for_bare/for_bare.go | 0 {untested => tests}/for_bare/for_bare.go.json | 0 {untested => tests}/for_bare/for_bare.vv | 0 5 files changed, 18 insertions(+) rename {untested => tests}/for_bare/for_bare.go (100%) rename {untested => tests}/for_bare/for_bare.go.json (100%) rename {untested => tests}/for_bare/for_bare.vv (100%) diff --git a/ast.v b/ast.v index fa22efe..720d457 100644 --- a/ast.v +++ b/ast.v @@ -21,6 +21,7 @@ type Expr = ArrayType type Stmt = AssignStmt | BlockStmt + | BranchStmt | CaseClause | DeclStmt | DeferStmt @@ -262,6 +263,11 @@ struct ReturnStmt { results []Expr @[json: 'Results'] } +struct BranchStmt { + node_type_str string @[json: '_type'] + tok string @[json: 'Tok'] +} + struct FuncLit { node_type_str string @[json: '_type'] typ FuncType @[json: 'Type'] diff --git a/stmt.v b/stmt.v index bc471d6..552ee1b 100644 --- a/stmt.v +++ b/stmt.v @@ -20,6 +20,9 @@ fn (mut app App) stmt(stmt Stmt) { BlockStmt { app.block_stmt(stmt) } + BranchStmt { + app.branch_stmt(stmt) + } ExprStmt { // app.genln('expr stmt') app.expr_stmt(stmt) @@ -92,6 +95,10 @@ fn (mut app App) if_stmt(node IfStmt) { fn (mut app App) for_stmt(f ForStmt) { app.gen('for ') + if f.init.node_type_str == '' { // == unsafe { nil } { + app.block_stmt(f.body) + return + } app.assign_stmt(f.init, true) app.gen('; ') app.expr(f.cond) @@ -168,3 +175,8 @@ fn (mut app App) return_stmt(node ReturnStmt) { } } } + +// continue break etc +fn (mut app App) branch_stmt(node BranchStmt) { + app.genln(node.tok) +} diff --git a/untested/for_bare/for_bare.go b/tests/for_bare/for_bare.go similarity index 100% rename from untested/for_bare/for_bare.go rename to tests/for_bare/for_bare.go diff --git a/untested/for_bare/for_bare.go.json b/tests/for_bare/for_bare.go.json similarity index 100% rename from untested/for_bare/for_bare.go.json rename to tests/for_bare/for_bare.go.json diff --git a/untested/for_bare/for_bare.vv b/tests/for_bare/for_bare.vv similarity index 100% rename from untested/for_bare/for_bare.vv rename to tests/for_bare/for_bare.vv