From d165db69093fb28ad3eb07b4073b1e0a433012ea Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sun, 30 May 2021 17:46:09 -0700 Subject: [PATCH] fixes for treating WhileStmt's "loop_cond_pred_stmt" as a first-class citizen --- src/Stmt.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Stmt.cc b/src/Stmt.cc index 0bac3c9c72..ee441ba213 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1109,7 +1109,10 @@ WhileStmt::~WhileStmt() = default; bool WhileStmt::IsPure() const { - return loop_condition->IsPure() && body->IsPure(); + if ( loop_condition->IsPure() && body->IsPure() ) + return ! loop_cond_pred_stmt || loop_cond_pred_stmt->IsPure(); + else + return false; } void WhileStmt::StmtDescribe(ODesc* d) const @@ -1119,6 +1122,13 @@ void WhileStmt::StmtDescribe(ODesc* d) const if ( d->IsReadable() ) d->Add("("); + if ( loop_cond_pred_stmt ) + { + d->Add(" {"); + loop_cond_pred_stmt->Describe(d); + d->Add("} "); + } + loop_condition->Describe(d); if ( d->IsReadable() ) @@ -1136,6 +1146,12 @@ TraversalCode WhileStmt::Traverse(TraversalCallback* cb) const TraversalCode tc = cb->PreStmt(this); HANDLE_TC_STMT_PRE(tc); + if ( loop_cond_pred_stmt ) + { + tc = loop_cond_pred_stmt->Traverse(cb); + HANDLE_TC_STMT_PRE(tc); + } + tc = loop_condition->Traverse(cb); HANDLE_TC_STMT_PRE(tc);