diff --git a/src/Func.cc b/src/Func.cc index 7a120e0538..5233074630 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -503,6 +503,21 @@ void ScriptFunc::AddBody(StmtPtr new_body, sort(bodies.begin(), bodies.end()); } +void ScriptFunc::ReplaceBody(const StmtPtr& old_body, StmtPtr new_body) + { + bool found_it = false; + + for ( auto& body : bodies ) + if ( body.stmts.get() == old_body.get() ) + { + body.stmts = new_body; + found_it = true; + } + + ASSERT(found_it); + current_body = new_body; + } + void ScriptFunc::AddClosure(IDPList ids, Frame* f) { if ( ! f ) diff --git a/src/Func.h b/src/Func.h index 191a766218..7d9a9686ff 100644 --- a/src/Func.h +++ b/src/Func.h @@ -196,6 +196,11 @@ public: const std::vector& new_inits, size_t new_frame_size, int priority) override; + // Replace the given current instance of a function body with + // a new one. + void ReplaceBody(const detail::StmtPtr& old_body, + detail::StmtPtr new_body); + StmtPtr CurrentBody() const { return current_body; } /**