From 9bf422f9953cb87e3b34d458df35600457198d73 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 22 Oct 2024 14:41:34 +1300 Subject: [PATCH] Analyser: account for the case where a piecewise statement doesn't have any children. --- src/analyser.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/analyser.cpp b/src/analyser.cpp index c3a68d105..1ebf42d13 100644 --- a/src/analyser.cpp +++ b/src/analyser.cpp @@ -688,30 +688,32 @@ void Analyser::AnalyserImpl::analyseNode(const XmlNodePtr &node, ast->mPimpl->populate(AnalyserEquationAst::Type::PIECEWISE, astParent); - analyseNode(mathmlChildNode(node, 0), ast->mPimpl->mOwnedLeftChild, ast, component, equation); + if (childCount >= 1) { + analyseNode(mathmlChildNode(node, 0), ast->mPimpl->mOwnedLeftChild, ast, component, equation); - if (childCount >= 2) { - AnalyserEquationAstPtr astRight; - AnalyserEquationAstPtr tempAst; + if (childCount >= 2) { + AnalyserEquationAstPtr astRight; + AnalyserEquationAstPtr tempAst; - analyseNode(mathmlChildNode(node, childCount - 1), astRight, nullptr, component, equation); + analyseNode(mathmlChildNode(node, childCount - 1), astRight, nullptr, component, equation); - for (auto i = childCount - 2; i > 0; --i) { - tempAst = AnalyserEquationAst::create(); + for (auto i = childCount - 2; i > 0; --i) { + tempAst = AnalyserEquationAst::create(); - tempAst->mPimpl->populate(AnalyserEquationAst::Type::PIECEWISE, astParent); + tempAst->mPimpl->populate(AnalyserEquationAst::Type::PIECEWISE, astParent); - analyseNode(mathmlChildNode(node, i), tempAst->mPimpl->mOwnedLeftChild, tempAst, component, equation); + analyseNode(mathmlChildNode(node, i), tempAst->mPimpl->mOwnedLeftChild, tempAst, component, equation); - astRight->mPimpl->mParent = tempAst; + astRight->mPimpl->mParent = tempAst; - tempAst->mPimpl->mOwnedRightChild = astRight; - astRight = tempAst; - } + tempAst->mPimpl->mOwnedRightChild = astRight; + astRight = tempAst; + } - astRight->mPimpl->mParent = ast; + astRight->mPimpl->mParent = ast; - ast->mPimpl->mOwnedRightChild = astRight; + ast->mPimpl->mOwnedRightChild = astRight; + } } } else if (node->isMathmlElement("piece")) { ast->mPimpl->populate(AnalyserEquationAst::Type::PIECE, astParent);