From f0c171a1dd2698f5bec14f5cf00136477032c202 Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Tue, 6 Feb 2018 17:47:59 +0900 Subject: starmath: Make SmParser::DoLine() etc. return std::unique_ptr Change-Id: Ia85f66d3490471d7e0c2ce8a1947051be129acf9 Reviewed-on: https://gerrit.libreoffice.org/49276 Tested-by: Jenkins Reviewed-by: Takeshi Abe --- starmath/inc/parse.hxx | 16 +++++----- starmath/source/parse.cxx | 78 +++++++++++++++++++++++------------------------ 2 files changed, 47 insertions(+), 47 deletions(-) (limited to 'starmath') diff --git a/starmath/inc/parse.hxx b/starmath/inc/parse.hxx index e3ec707d8bf4..ef51bcc61bdc 100644 --- a/starmath/inc/parse.hxx +++ b/starmath/inc/parse.hxx @@ -79,19 +79,19 @@ class SmParser // grammar std::unique_ptr DoTable(); - SmLineNode *DoLine(); + std::unique_ptr DoLine(); std::unique_ptr DoExpression(bool bUseExtraSpaces = true); - SmNode *DoRelation(); - SmNode *DoSum(); - SmNode *DoProduct(); - SmNode *DoSubSup(TG nActiveGroup, SmNode *pGivenNode); - SmNode *DoOpSubSup(); - SmNode *DoPower(); + std::unique_ptr DoRelation(); + std::unique_ptr DoSum(); + std::unique_ptr DoProduct(); + std::unique_ptr DoSubSup(TG nActiveGroup, SmNode *pGivenNode); + std::unique_ptr DoOpSubSup(); + std::unique_ptr DoPower(); SmBlankNode *DoBlank(); SmNode *DoTerm(bool bGroupNumberIdent); SmNode *DoEscape(); SmOperNode *DoOperator(); - SmNode *DoOper(); + std::unique_ptr DoOper(); SmStructureNode *DoUnOper(); std::unique_ptr DoAlign(bool bUseExtraSpaces = true); SmStructureNode *DoFontAttribut(); diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index e097e87e1b8e..a7c1a8a0d6d2 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -957,11 +957,11 @@ std::unique_ptr SmParser::DoTable() throw std::range_error("parser depth limit"); std::vector> aLineArray; - aLineArray.emplace_back(std::unique_ptr(DoLine())); + aLineArray.push_back(DoLine()); while (m_aCurToken.eType == TNEWLINE) { NextToken(); - aLineArray.emplace_back(std::unique_ptr(DoLine())); + aLineArray.push_back(DoLine()); } assert(m_aCurToken.eType == TEND); std::unique_ptr xSNode(new SmTableNode(m_aCurToken)); @@ -1000,7 +1000,7 @@ std::unique_ptr SmParser::DoAlign(bool bUseExtraSpaces) } // Postcondition: m_aCurToken.eType == TEND || m_aCurToken.eType == TNEWLINE -SmLineNode *SmParser::DoLine() +std::unique_ptr SmParser::DoLine() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -1029,7 +1029,7 @@ SmLineNode *SmParser::DoLine() auto xSNode = o3tl::make_unique(m_aCurToken); xSNode->SetSubNodes(buildNodeArray(ExpressionArray)); - return xSNode.release(); + return std::move(xSNode); // this explicit move can be omitted since C++14 } std::unique_ptr SmParser::DoExpression(bool bUseExtraSpaces) @@ -1039,9 +1039,9 @@ std::unique_ptr SmParser::DoExpression(bool bUseExtraSpaces) throw std::range_error("parser depth limit"); std::vector> RelationArray; - RelationArray.emplace_back(std::unique_ptr(DoRelation())); + RelationArray.push_back(DoRelation()); while (m_aCurToken.nLevel >= 4) - RelationArray.emplace_back(std::unique_ptr(DoRelation())); + RelationArray.push_back(DoRelation()); if (RelationArray.size() > 1) { @@ -1059,49 +1059,49 @@ std::unique_ptr SmParser::DoExpression(bool bUseExtraSpaces) } } -SmNode *SmParser::DoRelation() +std::unique_ptr SmParser::DoRelation() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) throw std::range_error("parser depth limit"); - std::unique_ptr xFirst(DoSum()); + auto xFirst = DoSum(); while (TokenInGroup(TG::Relation)) { std::unique_ptr xSNode(new SmBinHorNode(m_aCurToken)); - std::unique_ptr xSecond(DoOpSubSup()); - std::unique_ptr xThird(DoSum()); + auto xSecond = DoOpSubSup(); + auto xThird = DoSum(); xSNode->SetSubNodes(xFirst.release(), xSecond.release(), xThird.release()); xFirst = std::move(xSNode); } - return xFirst.release(); + return xFirst; } -SmNode *SmParser::DoSum() +std::unique_ptr SmParser::DoSum() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) throw std::range_error("parser depth limit"); - std::unique_ptr xFirst(DoProduct()); + auto xFirst = DoProduct(); while (TokenInGroup(TG::Sum)) { std::unique_ptr xSNode(new SmBinHorNode(m_aCurToken)); - std::unique_ptr xSecond(DoOpSubSup()); - std::unique_ptr xThird(DoProduct()); + auto xSecond = DoOpSubSup(); + auto xThird = DoProduct(); xSNode->SetSubNodes(xFirst.release(), xSecond.release(), xThird.release()); xFirst = std::move(xSNode); } - return xFirst.release(); + return xFirst; } -SmNode *SmParser::DoProduct() +std::unique_ptr SmParser::DoProduct() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) throw std::range_error("parser depth limit"); - std::unique_ptr xFirst(DoPower()); + auto xFirst = DoPower(); while (TokenInGroup(TG::Product)) { @@ -1154,10 +1154,10 @@ SmNode *SmParser::DoProduct() default: xSNode.reset(new SmBinHorNode(m_aCurToken)); - xOper.reset(DoOpSubSup()); + xOper = DoOpSubSup(); } - std::unique_ptr xArg(DoPower()); + auto xArg = DoPower(); if (bSwitchArgs) { @@ -1170,10 +1170,10 @@ SmNode *SmParser::DoProduct() } xFirst = std::move(xSNode); } - return xFirst.release(); + return xFirst; } -SmNode *SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode) +std::unique_ptr SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode) { std::unique_ptr xGivenNode(pGivenNode); DepthProtect aDepthGuard(m_nParseDepth); @@ -1237,7 +1237,7 @@ SmNode *SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode) if (eType == TFROM || eType == TTO) { // parse limits in old 4.0 and 5.0 style - xSNode.reset(DoRelation()); + xSNode = DoRelation(); } else xSNode.reset(DoTerm(true)); @@ -1246,10 +1246,10 @@ SmNode *SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode) } pNode->SetSubNodes(buildNodeArray(aSubNodes)); - return pNode.release(); + return std::move(pNode); // this explicit move can be omitted since C++14 } -SmNode *SmParser::DoOpSubSup() +std::unique_ptr SmParser::DoOpSubSup() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -1262,10 +1262,10 @@ SmNode *SmParser::DoOpSubSup() // get sub- supscripts if any if (m_aCurToken.nGroup == TG::Power) return DoSubSup(TG::Power, pNode.release()); - return pNode.release(); + return std::move(pNode); // this explicit move can be omitted since C++14 } -SmNode *SmParser::DoPower() +std::unique_ptr SmParser::DoPower() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -1276,7 +1276,7 @@ SmNode *SmParser::DoPower() if (m_aCurToken.nGroup == TG::Power) return DoSubSup(TG::Power, xNode.release()); - return xNode.release(); + return xNode; } SmBlankNode *SmParser::DoBlank() @@ -1502,7 +1502,7 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent) || TokenInGroup(TG::FontAttr)) aStack.push(std::unique_ptr(bIsAttr ? DoAttribut() : DoFontAttribut())); - std::unique_ptr xFirstNode(DoPower()); + auto xFirstNode = DoPower(); while (!aStack.empty()) { std::unique_ptr xNode = std::move(aStack.top()); @@ -1569,19 +1569,19 @@ SmOperNode *SmParser::DoOperator() auto xSNode = o3tl::make_unique(m_aCurToken); // get operator - std::unique_ptr xOperator(DoOper()); + auto xOperator = DoOper(); if (m_aCurToken.nGroup == TG::Limit || m_aCurToken.nGroup == TG::Power) - xOperator.reset(DoSubSup(m_aCurToken.nGroup, xOperator.release())); + xOperator = DoSubSup(m_aCurToken.nGroup, xOperator.release()); // get argument - std::unique_ptr xArg(DoPower()); + auto xArg = DoPower(); xSNode->SetSubNodes(xOperator.release(), xArg.release()); return xSNode.release(); } -SmNode *SmParser::DoOper() +std::unique_ptr SmParser::DoOper() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -1636,7 +1636,7 @@ SmNode *SmParser::DoOper() } NextToken(); - return pNode.release(); + return pNode; } SmStructureNode *SmParser::DoUnOper() @@ -1665,7 +1665,7 @@ SmStructureNode *SmParser::DoUnOper() case TNROOT : NextToken(); - xExtra.reset(DoPower()); + xExtra = DoPower(); break; case TUOPER : @@ -1682,7 +1682,7 @@ SmStructureNode *SmParser::DoUnOper() case TMINUSPLUS : case TNEG : case TFACT : - xOper.reset(DoOpSubSup()); + xOper = DoOpSubSup(); break; default : @@ -1690,7 +1690,7 @@ SmStructureNode *SmParser::DoUnOper() } // get argument - xArg.reset(DoPower()); + xArg = DoPower(); if (eType == TABS) { @@ -2133,8 +2133,8 @@ SmTableNode *SmParser::DoBinom() NextToken(); - std::unique_ptr xFirst(DoSum()); - std::unique_ptr xSecond(DoSum()); + auto xFirst = DoSum(); + auto xSecond = DoSum(); xSNode->SetSubNodes(xFirst.release(), xSecond.release()); return xSNode.release(); } -- cgit v1.2.3