@@ -2426,42 +2426,60 @@ class stmt_group_t : public stmt_impl_t {
2426
2426
: stmt_impl_t (_type_info()), label(label), body(body) {}
2427
2427
};
2428
2428
2429
- // Statement sequence, allows combining two statements.
2429
+ // Statement sequence, allows combining multiple statements.
2430
2430
// C++ equivalent:
2431
2431
// {
2432
- // head;
2433
- // tail;
2432
+ // vec[0];
2433
+ // vec[1];
2434
+ // ...
2434
2435
// }
2435
2436
class stmt_seq_t : public stmt_impl_t {
2436
2437
public:
2437
2438
IR_DECL_STMT_TYPE_ID (stmt_seq_t )
2438
2439
2440
+ static stmt_t make (const std::vector<stmt_t > &vec) {
2441
+ return stmt_t (new stmt_seq_t (vec));
2442
+ }
2443
+
2439
2444
static stmt_t make (const stmt_t &head, const stmt_t &tail) {
2440
- return stmt_t ( new stmt_seq_t ( head, tail) );
2445
+ return head. append ( tail);
2441
2446
}
2442
2447
2443
2448
bool is_equal (const object_impl_t &obj) const override {
2444
2449
if (!obj.is <self_type>()) return false ;
2445
2450
auto &other = obj.as <self_type>();
2446
2451
2447
- return head. is_equal (other. head ) && tail. is_equal ( other.tail );
2452
+ return ir_utils:: is_equal (vec, other.vec );
2448
2453
}
2449
2454
2450
- size_t get_hash () const override { return ir_utils::get_hash (head, tail ); }
2455
+ size_t get_hash () const override { return ir_utils::get_hash (vec ); }
2451
2456
2452
2457
IR_DECLARE_TRAVERSERS ()
2453
2458
2454
- stmt_t head;
2455
- stmt_t tail;
2459
+ std::vector<stmt_t > vec;
2456
2460
2457
2461
private:
2458
- stmt_seq_t (const stmt_t &head, const stmt_t &tail )
2459
- : stmt_impl_t (_type_info()), head(head), tail(tail ) {}
2462
+ stmt_seq_t (const std::vector< stmt_t > &vec )
2463
+ : stmt_impl_t (_type_info()), vec(vec ) {}
2460
2464
};
2461
2465
2462
2466
inline stmt_t stmt_t::append (const stmt_t &s) const {
2463
2467
if (is_empty ()) return s;
2464
- return stmt_seq_t::make (*this , s);
2468
+ if (s.is_empty ()) return *this ;
2469
+ auto *seq1 = this ->as_ptr <stmt_seq_t >();
2470
+ auto *seq2 = s.as_ptr <stmt_seq_t >();
2471
+ std::vector<stmt_t > vec;
2472
+ if (seq1) {
2473
+ vec.insert (vec.end (), seq1->vec .begin (), seq1->vec .end ());
2474
+ } else {
2475
+ vec.push_back (*this );
2476
+ }
2477
+ if (seq2) {
2478
+ vec.insert (vec.end (), seq2->vec .begin (), seq2->vec .end ());
2479
+ } else {
2480
+ vec.push_back (s);
2481
+ }
2482
+ return stmt_seq_t::make (vec);
2465
2483
}
2466
2484
2467
2485
// Function call attribute.
0 commit comments