From 7143b214f24c196d873caeea4dbb11d2139d9b68 Mon Sep 17 00:00:00 2001 From: Matthew Ballance Date: Fri, 22 Dec 2023 16:50:30 -0800 Subject: [PATCH] Progress on support for scoped local variables Signed-off-by: Matthew Ballance --- src/EvalTypeProcStmt.cpp | 60 ++++++++++++++++++++++++++++------------ src/EvalTypeProcStmt.h | 1 + 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/EvalTypeProcStmt.cpp b/src/EvalTypeProcStmt.cpp index aa1def1..f3be4fb 100644 --- a/src/EvalTypeProcStmt.cpp +++ b/src/EvalTypeProcStmt.cpp @@ -189,38 +189,64 @@ void EvalTypeProcStmt::visitTypeProcStmtIfElse(dm::ITypeProcStmtIfElse *s) { case 0: { // Evaluate condition m_idx = 1; + m_sub_idx = 0; - if (EvalTypeExpr(m_ctxt, m_thread, m_vp_id, s->getCond()).eval()) { - clrFlags(EvalFlags::Complete); - break; - } } case 1: { - m_idx = 2; - // Have the condition result - vsc::dm::ValRefBool cond(getResult()); - if (!cond.valid()) { - ERROR("if-condition value is not valid"); + // Step through if-else clauses until we find cond==true or + // reach the end of the list + if (m_sub_idx > 0 && hasFlags(EvalFlags::Complete) && getResult().vp()) { + // Move on to the 'execute' stage + m_idx = 2; + // The condition was for the *previous* entry, so adjust + m_sub_idx--; + } else { + while (m_sub_idx < s->getIfClauses().size()) { + + if (EvalTypeExpr(m_ctxt, m_thread, m_vp_id, + s->getIfClauses().at(m_sub_idx)->getCond()).eval()) { + clrFlags(EvalFlags::Complete); + m_sub_idx++; + break; + } else if (getResult().vp()) { + // Roll + m_idx = 2; + break; + } else { + m_sub_idx++; + } + } + + if (!hasFlags(EvalFlags::Complete)) { + break; + } } + } + case 2: { + m_idx = 3; - if (cond.valid() && cond.get_val()) { - DEBUG("True branch"); - if (EvalTypeProcStmt(m_ctxt, m_thread, m_vp_id, s->getTrue()).eval()) { + vsc::dm::ValRefBool cond(getResult()); + // Evaluate the selected branch (if cond==true) + if (m_sub_idx < s->getIfClauses().size() && cond.valid() && cond.get_val()) { + // + if (EvalTypeProcStmt(m_ctxt, m_thread, m_vp_id, + s->getIfClauses().at(m_sub_idx).get()).eval()) { clrFlags(EvalFlags::Complete); break; } - } else if (s->getFalse()) { - DEBUG("False branch"); - if (EvalTypeProcStmt(m_ctxt, m_thread, m_vp_id, s->getFalse()).eval()) { + } else if (s->getElseClause()) { + if (EvalTypeProcStmt(m_ctxt, m_thread, m_vp_id, + s->getElseClause()).eval()) { clrFlags(EvalFlags::Complete); break; } } } - case 2: { - // + + case 3: { + } } DEBUG_LEAVE("visitTypeProcStmtIfElse"); diff --git a/src/EvalTypeProcStmt.h b/src/EvalTypeProcStmt.h index 598d544..16758ff 100644 --- a/src/EvalTypeProcStmt.h +++ b/src/EvalTypeProcStmt.h @@ -62,6 +62,7 @@ class EvalTypeProcStmt : static dmgr::IDebug *m_dbg; dm::ITypeProcStmt *m_stmt; uint32_t m_idx; + int32_t m_sub_idx; };