Skip to content

Commit

Permalink
Fixed bug with if statments and replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
meamy committed Nov 6, 2023
1 parent 21c57cd commit 1d18942
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions include/qasmtools/ast/replacer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,29 @@ class Replacer : public Visitor {
void visit(IfStmt& stmt) override {
stmt.then().accept(*this);
if (replacement_stmts_) {
std::list<ptr<Stmt>> ret;
std::optional<std::list<ptr<Stmt>>> ret = std::nullopt;
for (auto& rep : *replacement_stmts_) {
auto tmp = object::clone(stmt);
tmp->set_then(std::move(rep));
ret.emplace_back(std::move(tmp));
auto stmts = replace(*tmp);
if (!ret) {
ret = std::move(stmts);
} else if (stmts) {
ret->splice(ret->end(), *stmts);
}
}
replacement_stmts_ = std::move(ret);
} else if (replacement_gates_) {
std::list<ptr<Stmt>> ret;
std::optional<std::list<ptr<Stmt>>> ret = std::nullopt;
for (auto& rep : *replacement_gates_) {
auto tmp = object::clone(stmt);
tmp->set_then(std::move(rep));
ret.emplace_back(std::move(tmp));
auto stmts = replace(*tmp);
if (!ret) {
ret = std::move(stmts);
} else if (stmts) {
ret->splice(ret->end(), *stmts);
}
}
replacement_gates_ = std::nullopt;
replacement_stmts_ = std::move(ret);
Expand Down

0 comments on commit 1d18942

Please sign in to comment.