| ... | ... | @@ -2119,9 +2119,6 @@ static AstNode *trans_unary_expr_or_type_trait_expr(Context *c, AstNode *block, |
| 2119 | 2119 | } |
| 2120 | 2120 | |
| 2121 | 2121 | static AstNode *trans_do_loop(Context *c, AstNode *block, DoStmt *stmt) { |
| 2122 | | stmt->getBody(); |
| 2123 | | stmt->getCond(); |
| 2124 | | |
| 2125 | 2122 | AstNode *while_node = trans_create_node(c, NodeTypeWhileExpr); |
| 2126 | 2123 | |
| 2127 | 2124 | AstNode *true_node = trans_create_node(c, NodeTypeBoolLiteral); |
| ... | ... | @@ -2171,6 +2168,51 @@ static AstNode *trans_do_loop(Context *c, AstNode *block, DoStmt *stmt) { |
| 2171 | 2168 | return while_node; |
| 2172 | 2169 | } |
| 2173 | 2170 | |
| 2171 | static AstNode *trans_for_loop(Context *c, AstNode *block, ForStmt *stmt) { |
| 2172 | AstNode *loop_block_node; |
| 2173 | AstNode *while_node = trans_create_node(c, NodeTypeWhileExpr); |
| 2174 | Stmt *init_stmt = stmt->getInit(); |
| 2175 | if (init_stmt == nullptr) { |
| 2176 | loop_block_node = while_node; |
| 2177 | } else { |
| 2178 | loop_block_node = trans_create_node(c, NodeTypeBlock); |
| 2179 | |
| 2180 | AstNode *vars_node = trans_stmt(c, false, loop_block_node, init_stmt, TransRValue); |
| 2181 | if (vars_node == nullptr) |
| 2182 | return nullptr; |
| 2183 | if (vars_node != skip_add_to_block_node) |
| 2184 | loop_block_node->data.block.statements.append(vars_node); |
| 2185 | |
| 2186 | loop_block_node->data.block.statements.append(while_node); |
| 2187 | } |
| 2188 | |
| 2189 | Stmt *cond_stmt = stmt->getCond(); |
| 2190 | if (cond_stmt == nullptr) { |
| 2191 | AstNode *true_node = trans_create_node(c, NodeTypeBoolLiteral); |
| 2192 | true_node->data.bool_literal.value = true; |
| 2193 | while_node->data.while_expr.condition = true_node; |
| 2194 | } else { |
| 2195 | while_node->data.while_expr.condition = trans_stmt(c, false, loop_block_node, cond_stmt, TransRValue); |
| 2196 | if (while_node->data.while_expr.condition == nullptr) |
| 2197 | return nullptr; |
| 2198 | } |
| 2199 | |
| 2200 | Stmt *inc_stmt = stmt->getInc(); |
| 2201 | if (inc_stmt != nullptr) { |
| 2202 | AstNode *inc_node = trans_stmt(c, false, loop_block_node, inc_stmt, TransRValue); |
| 2203 | if (inc_node == nullptr) |
| 2204 | return nullptr; |
| 2205 | while_node->data.while_expr.continue_expr = inc_node; |
| 2206 | } |
| 2207 | |
| 2208 | AstNode *child_statement = trans_stmt(c, false, loop_block_node, stmt->getBody(), TransRValue); |
| 2209 | if (child_statement == nullptr) |
| 2210 | return nullptr; |
| 2211 | while_node->data.while_expr.body = child_statement; |
| 2212 | |
| 2213 | return loop_block_node; |
| 2214 | } |
| 2215 | |
| 2174 | 2216 | static AstNode *trans_string_literal(Context *c, AstNode *block, StringLiteral *stmt) { |
| 2175 | 2217 | switch (stmt->getKind()) { |
| 2176 | 2218 | case StringLiteral::Ascii: |
| ... | ... | @@ -2230,6 +2272,8 @@ static AstNode *trans_stmt(Context *c, bool result_used, AstNode *block, Stmt *s |
| 2230 | 2272 | return trans_unary_expr_or_type_trait_expr(c, block, (UnaryExprOrTypeTraitExpr *)stmt); |
| 2231 | 2273 | case Stmt::DoStmtClass: |
| 2232 | 2274 | return trans_do_loop(c, block, (DoStmt *)stmt); |
| 2275 | case Stmt::ForStmtClass: |
| 2276 | return trans_for_loop(c, block, (ForStmt *)stmt); |
| 2233 | 2277 | case Stmt::StringLiteralClass: |
| 2234 | 2278 | return trans_string_literal(c, block, (StringLiteral *)stmt); |
| 2235 | 2279 | case Stmt::CaseStmtClass: |
| ... | ... | @@ -2568,9 +2612,6 @@ static AstNode *trans_stmt(Context *c, bool result_used, AstNode *block, Stmt *s |
| 2568 | 2612 | case Stmt::VAArgExprClass: |
| 2569 | 2613 | emit_warning(c, stmt->getLocStart(), "TODO handle C VAArgExprClass"); |
| 2570 | 2614 | return nullptr; |
| 2571 | | case Stmt::ForStmtClass: |
| 2572 | | emit_warning(c, stmt->getLocStart(), "TODO handle C ForStmtClass"); |
| 2573 | | return nullptr; |
| 2574 | 2615 | case Stmt::GotoStmtClass: |
| 2575 | 2616 | emit_warning(c, stmt->getLocStart(), "TODO handle C GotoStmtClass"); |
| 2576 | 2617 | return nullptr; |