mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
new method for Stmt nodes to report whether they could execute a "return"
This commit is contained in:
parent
3d69b0551a
commit
087eb1ca4e
3 changed files with 40 additions and 1 deletions
|
@ -273,6 +273,10 @@ bool IfStmt::NoFlowAfter(bool ignore_break) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool IfStmt::CouldReturn(bool ignore_break) const {
|
||||
return (s1 && s1->CouldReturn(ignore_break)) || (s2 && s2->CouldReturn(ignore_break));
|
||||
}
|
||||
|
||||
IntrusivePtr<Case> Case::Duplicate() {
|
||||
if ( expr_cases ) {
|
||||
auto new_exprs = expr_cases->Duplicate()->AsListExprPtr();
|
||||
|
@ -404,6 +408,14 @@ bool SwitchStmt::NoFlowAfter(bool ignore_break) const {
|
|||
return default_seen_with_no_flow_after;
|
||||
}
|
||||
|
||||
bool SwitchStmt::CouldReturn(bool ignore_break) const {
|
||||
for ( const auto& c : *Cases() )
|
||||
if ( c->Body()->CouldReturn(true) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AddDelStmt::IsReduced(Reducer* c) const { return e->HasReducedOps(c); }
|
||||
|
||||
StmtPtr AddDelStmt::DoReduce(Reducer* c) {
|
||||
|
@ -499,6 +511,8 @@ StmtPtr WhileStmt::DoReduce(Reducer* c) {
|
|||
return ThisPtr();
|
||||
}
|
||||
|
||||
bool WhileStmt::CouldReturn(bool ignore_break) const { return body->CouldReturn(false); }
|
||||
|
||||
StmtPtr ForStmt::Duplicate() {
|
||||
auto expr_copy = e->Duplicate();
|
||||
|
||||
|
@ -568,6 +582,8 @@ StmtPtr ForStmt::DoReduce(Reducer* c) {
|
|||
return ThisPtr();
|
||||
}
|
||||
|
||||
bool ForStmt::CouldReturn(bool ignore_break) const { return body->CouldReturn(false); }
|
||||
|
||||
StmtPtr ReturnStmt::Duplicate() { return SetSucc(new ReturnStmt(e ? e->Duplicate() : nullptr, true)); }
|
||||
|
||||
ReturnStmt::ReturnStmt(ExprPtr arg_e, bool ignored) : ExprStmt(STMT_RETURN, std::move(arg_e)) {}
|
||||
|
@ -784,6 +800,14 @@ bool StmtList::NoFlowAfter(bool ignore_break) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool StmtList::CouldReturn(bool ignore_break) const {
|
||||
for ( auto& s : stmts )
|
||||
if ( s->CouldReturn(ignore_break) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
StmtPtr InitStmt::Duplicate() {
|
||||
// Need to duplicate the initializer list since later reductions
|
||||
// can modify it in place.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue