@@ -165,6 +165,8 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
165
165
bool enable_fall_through;
166
166
std::map<ASR::symbol_t *, std::map<std::string, ASR::expr_t *>> struct2member_inits;
167
167
std::map<SymbolTable*, std::vector<ASR::symbol_t *>> scope2enums;
168
+ clang::ForStmt* for_loop;
169
+ bool inside_loop;
168
170
169
171
explicit ClangASTtoASRVisitor (clang::ASTContext *Context_,
170
172
Allocator& al_, ASR::asr_t *& tu_):
@@ -173,7 +175,8 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
173
175
assignment_target{nullptr }, print_args{nullptr },
174
176
is_all_called{false }, is_range_called{false },
175
177
current_switch_case{nullptr }, default_stmt{nullptr },
176
- interpret_init_list_expr_as_list{false }, enable_fall_through{false } {}
178
+ interpret_init_list_expr_as_list{false }, enable_fall_through{false },
179
+ for_loop{nullptr }, inside_loop{false } {}
177
180
178
181
template <typename T>
179
182
Location Lloc (T *x) {
@@ -2290,10 +2293,26 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
2290
2293
2291
2294
bool TraverseBreakStmt (clang::BreakStmt* x) {
2292
2295
clang::RecursiveASTVisitor<ClangASTtoASRVisitor>::TraverseBreakStmt (x);
2296
+ if ( inside_loop ) {
2297
+ tmp = ASR::make_Exit_t (al, Lloc (x), nullptr );
2298
+ is_stmt_created = true ;
2299
+ }
2293
2300
is_break_stmt_present.set (true );
2294
2301
return true ;
2295
2302
}
2296
2303
2304
+ bool TraverseContinueStmt (clang::ContinueStmt* x) {
2305
+ if ( for_loop != nullptr ) {
2306
+ clang::Stmt* inc_stmt = for_loop->getInc ();
2307
+ TraverseStmt (inc_stmt);
2308
+ LCOMPILERS_ASSERT (tmp != nullptr && is_stmt_created);
2309
+ current_body->push_back (al, ASRUtils::STMT (tmp.get ()));
2310
+ }
2311
+ tmp = ASR::make_Cycle_t (al, Lloc (x), nullptr );
2312
+ is_stmt_created = true ;
2313
+ return true ;
2314
+ }
2315
+
2297
2316
bool TraverseCaseStmt (clang::CaseStmt* x) {
2298
2317
if ( x->caseStmtIsGNURange () ) {
2299
2318
throw std::runtime_error (" Ranges not supported in case." );
@@ -2437,6 +2456,16 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
2437
2456
is_stmt_created = true ;
2438
2457
break ;
2439
2458
}
2459
+ case clang::UnaryOperatorKind::UO_PostDec: {
2460
+ ASR::expr_t * decbyone = ASRUtils::EXPR (ASR::make_IntegerBinOp_t (
2461
+ al, Lloc (x), var, ASR::binopType::Sub,
2462
+ ASRUtils::EXPR (ASR::make_IntegerConstant_t (
2463
+ al, Lloc (x), 1 , ASRUtils::expr_type (var))),
2464
+ ASRUtils::expr_type (var), nullptr ));
2465
+ tmp = ASR::make_Assignment_t (al, Lloc (x), var, decbyone, nullptr );
2466
+ is_stmt_created = true ;
2467
+ break ;
2468
+ }
2440
2469
case clang::UnaryOperatorKind::UO_Minus: {
2441
2470
CreateUnaryMinus (var, Lloc (x));
2442
2471
break ;
@@ -2452,7 +2481,35 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
2452
2481
return true ;
2453
2482
}
2454
2483
2484
+ bool TraverseWhileStmt (clang::WhileStmt* x) {
2485
+ bool inside_loop_copy = inside_loop;
2486
+ inside_loop = true ;
2487
+ std::map<std::string, std::string> alias;
2488
+ scopes.push_back (alias);
2489
+
2490
+ clang::Expr* loop_cond = x->getCond ();
2491
+ TraverseStmt (loop_cond);
2492
+ ASR::expr_t * test = ASRUtils::EXPR (tmp.get ());
2493
+
2494
+ Vec<ASR::stmt_t *> body; body.reserve (al, 1 );
2495
+ Vec<ASR::stmt_t *>*current_body_copy = current_body;
2496
+ current_body = &body;
2497
+ clang::Stmt* loop_body = x->getBody ();
2498
+ TraverseStmt (loop_body);
2499
+ current_body = current_body_copy;
2500
+
2501
+ tmp = ASR::make_WhileLoop_t (al, Lloc (x), nullptr , test, body.p , body.size ());
2502
+ is_stmt_created = true ;
2503
+ scopes.pop_back ();
2504
+ inside_loop = inside_loop_copy;
2505
+ return true ;
2506
+ }
2507
+
2455
2508
bool TraverseForStmt (clang::ForStmt* x) {
2509
+ bool inside_loop_copy = inside_loop;
2510
+ inside_loop = true ;
2511
+ clang::ForStmt* for_loop_copy = for_loop;
2512
+ for_loop = x;
2456
2513
std::map<std::string, std::string> alias;
2457
2514
scopes.push_back (alias);
2458
2515
clang::Stmt* init_stmt = x->getInit ();
@@ -2478,6 +2535,8 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
2478
2535
tmp = ASR::make_WhileLoop_t (al, Lloc (x), nullptr , test, body.p , body.size ());
2479
2536
is_stmt_created = true ;
2480
2537
scopes.pop_back ();
2538
+ for_loop = for_loop_copy;
2539
+ inside_loop = inside_loop_copy;
2481
2540
return true ;
2482
2541
}
2483
2542
0 commit comments