Skip to content

Commit

Permalink
Analyser: account for the case where a piecewise statement doesn't ha…
Browse files Browse the repository at this point in the history
…ve any children.
  • Loading branch information
agarny committed Oct 22, 2024
1 parent 1f1b8c0 commit 9bf422f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9bf422f

Please sign in to comment.