From 3e15dd2915f6f0ebb485781e837f1d9c94268b68 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 4 Oct 2018 15:34:38 +0200 Subject: use more unique_ptr in SmParser Change-Id: I132598f5829e02664040dff745011a59c6a19c1d Reviewed-on: https://gerrit.libreoffice.org/61401 Tested-by: Jenkins Reviewed-by: Noel Grandin --- starmath/inc/parse.hxx | 28 ++++++------ starmath/source/parse.cxx | 110 +++++++++++++++++++++++----------------------- 2 files changed, 68 insertions(+), 70 deletions(-) diff --git a/starmath/inc/parse.hxx b/starmath/inc/parse.hxx index 17e20b4cdaea..851512030c5b 100644 --- a/starmath/inc/parse.hxx +++ b/starmath/inc/parse.hxx @@ -89,27 +89,27 @@ class SmParser 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(); + std::unique_ptr DoBlank(); + std::unique_ptr DoTerm(bool bGroupNumberIdent); + std::unique_ptr DoEscape(); + std::unique_ptr DoOperator(); std::unique_ptr DoOper(); - SmStructureNode *DoUnOper(); + std::unique_ptr DoUnOper(); std::unique_ptr DoAlign(bool bUseExtraSpaces = true); std::unique_ptr DoFontAttribut(); std::unique_ptr DoAttribut(); std::unique_ptr DoFont(); std::unique_ptr DoFontSize(); std::unique_ptr DoColor(); - SmStructureNode *DoBrace(); - SmBracebodyNode *DoBracebody(bool bIsLeftRight); - SmTextNode *DoFunction(); - SmTableNode *DoBinom(); - SmStructureNode *DoStack(); - SmStructureNode *DoMatrix(); - SmSpecialNode *DoSpecial(); - SmGlyphSpecialNode *DoGlyphSpecial(); - SmExpressionNode *DoError(SmParseError Error); + std::unique_ptr DoBrace(); + std::unique_ptr DoBracebody(bool bIsLeftRight); + std::unique_ptr DoFunction(); + std::unique_ptr DoBinom(); + std::unique_ptr DoStack(); + std::unique_ptr DoMatrix(); + std::unique_ptr DoSpecial(); + std::unique_ptr DoGlyphSpecial(); + std::unique_ptr DoError(SmParseError Error); // end of grammar public: diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index 56d778f9b44c..71f9a3a4dce6 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -988,7 +988,7 @@ std::unique_ptr SmParser::DoAlign(bool bUseExtraSpaces) // allow for just one align statement in 5.0 if (TokenInGroup(TG::Align)) - return std::unique_ptr(DoError(SmParseError::DoubleAlign)); + return DoError(SmParseError::DoubleAlign); } auto pNode = DoExpression(bUseExtraSpaces); @@ -1146,7 +1146,7 @@ std::unique_ptr SmParser::DoProduct() //Let the glyph node know it's a binary operation m_aCurToken.eType = TBOPER; m_aCurToken.nGroup = TG::Product; - xOper.reset(DoGlyphSpecial()); + xOper = DoGlyphSpecial(); break; case TOVERBRACE : @@ -1243,7 +1243,7 @@ std::unique_ptr SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode) { // forget the earlier one, remember an error instead aSubNodes[nIndex].reset(); - xENode.reset(DoError(SmParseError::DoubleSubsupscript)); // this also skips current token. + xENode = DoError(SmParseError::DoubleSubsupscript); // this also skips current token. } else { @@ -1261,7 +1261,7 @@ std::unique_ptr SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode) xSNode = DoRelation(); } else - xSNode.reset(DoTerm(true)); + xSNode = DoTerm(true); aSubNodes[nIndex] = std::move(xENode ? xENode : xSNode); } @@ -1308,7 +1308,7 @@ std::unique_ptr SmParser::DoPower() return xNode; } -SmBlankNode *SmParser::DoBlank() +std::unique_ptr SmParser::DoBlank() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -1330,10 +1330,10 @@ SmBlankNode *SmParser::DoBlank() { pBlankNode->Clear(); } - return pBlankNode.release(); + return pBlankNode; } -SmNode *SmParser::DoTerm(bool bGroupNumberIdent) +std::unique_ptr SmParser::DoTerm(bool bGroupNumberIdent) { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -1362,18 +1362,18 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent) xSNode->SetSubNodes(nullptr, nullptr); NextToken(); - return xSNode.release(); + return std::unique_ptr(xSNode.release()); } auto pNode = DoAlign(!bNoSpace); if (m_aCurToken.eType == TRGROUP) { NextToken(); - return pNode.release(); + return pNode; } auto xSNode = o3tl::make_unique(m_aCurToken); std::unique_ptr xError(DoError(SmParseError::RgroupExpected)); xSNode->SetSubNodes(pNode.release(), xError.release()); - return xSNode.release(); + return std::unique_ptr(xSNode.release()); } case TLEFT : @@ -1387,13 +1387,13 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent) { auto pNode = o3tl::make_unique(m_aCurToken, FNT_TEXT); NextToken(); - return pNode.release(); + return std::unique_ptr(pNode.release()); } case TCHARACTER : { auto pNode = o3tl::make_unique(m_aCurToken, FNT_VARIABLE); NextToken(); - return pNode.release(); + return std::unique_ptr(pNode.release()); } case TIDENT : case TNUMBER : @@ -1405,7 +1405,7 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent) if (!bGroupNumberIdent) { NextToken(); - return pTextNode.release(); + return std::unique_ptr(pTextNode.release()); } std::vector> aNodes; // Some people want to be able to write "x_2n" for "x_{2n}" @@ -1442,13 +1442,13 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent) if (moveToNextToken) NextToken(); if (aNodes.empty()) - return pTextNode.release(); + return std::unique_ptr(pTextNode.release()); // We have several concatenated identifiers and numbers. // Let's group them into one SmExpressionNode. aNodes.insert(aNodes.begin(), std::move(pTextNode)); std::unique_ptr xNode(new SmExpressionNode(SmToken())); xNode->SetSubNodes(buildNodeArray(aNodes)); - return xNode.release(); + return std::unique_ptr(xNode.release()); } case TLEFTARROW : case TRIGHTARROW : @@ -1473,7 +1473,7 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent) { auto pNode = o3tl::make_unique(m_aCurToken); NextToken(); - return pNode.release(); + return std::unique_ptr(pNode.release()); } case TSETN : @@ -1493,14 +1493,14 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent) { auto pNode = o3tl::make_unique(m_aCurToken); NextToken(); - return pNode.release(); + return std::unique_ptr(pNode.release()); } case TPLACE: { auto pNode = o3tl::make_unique(m_aCurToken); NextToken(); - return pNode.release(); + return std::unique_ptr(pNode.release()); } case TSPECIAL: @@ -1539,7 +1539,7 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent) xNode->SetSubNodes(nullptr, xFirstNode.release()); xFirstNode = std::move(xNode); } - return xFirstNode.release(); + return xFirstNode; } if (TokenInGroup(TG::Function)) return DoFunction(); @@ -1547,7 +1547,7 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent) } } -SmNode *SmParser::DoEscape() +std::unique_ptr SmParser::DoEscape() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -1580,14 +1580,14 @@ SmNode *SmParser::DoEscape() { auto pNode = o3tl::make_unique(m_aCurToken); NextToken(); - return pNode.release(); + return std::unique_ptr(pNode.release()); } default: return DoError(SmParseError::UnexpectedToken); } } -SmOperNode *SmParser::DoOperator() +std::unique_ptr SmParser::DoOperator() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -1607,7 +1607,7 @@ SmOperNode *SmParser::DoOperator() auto xArg = DoPower(); xSNode->SetSubNodes(xOperator.release(), xArg.release()); - return xSNode.release(); + return xSNode; } std::unique_ptr SmParser::DoOper() @@ -1668,7 +1668,7 @@ std::unique_ptr SmParser::DoOper() return pNode; } -SmStructureNode *SmParser::DoUnOper() +std::unique_ptr SmParser::DoUnOper() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -1702,7 +1702,7 @@ SmStructureNode *SmParser::DoUnOper() //Let the glyph know what it is... m_aCurToken.eType = TUOPER; m_aCurToken.nGroup = TG::UnOper; - xOper.reset(DoGlyphSpecial()); + xOper = DoGlyphSpecial(); break; case TPLUS : @@ -1756,7 +1756,7 @@ SmStructureNode *SmParser::DoUnOper() xSNode->SetSubNodes(xOper.release(), xArg.release()); } } - return xSNode.release(); + return xSNode; } std::unique_ptr SmParser::DoAttribut() @@ -1862,8 +1862,7 @@ std::unique_ptr SmParser::DoColor() } else { - xNode.reset(DoError(SmParseError::ColorExpected)); - return xNode; + return DoError(SmParseError::ColorExpected); } } while (m_aCurToken.eType == TCOLOR); @@ -1891,8 +1890,7 @@ std::unique_ptr SmParser::DoFont() } else { - xNode.reset(DoError(SmParseError::FontExpected)); - return xNode; + return DoError(SmParseError::FontExpected); } } while (m_aCurToken.eType == TFONT); @@ -1945,14 +1943,14 @@ std::unique_ptr SmParser::DoFontSize() case TDIVIDEBY: Type = FontSizeType::DIVIDE; break; default: - return std::unique_ptr(DoError(SmParseError::SizeExpected)); + return DoError(SmParseError::SizeExpected); } if (Type != FontSizeType::ABSOLUT) { NextToken(); if (m_aCurToken.eType != TNUMBER) - return std::unique_ptr(DoError(SmParseError::SizeExpected)); + return DoError(SmParseError::SizeExpected); } // get number argument @@ -1993,7 +1991,7 @@ std::unique_ptr SmParser::DoFontSize() #endif } -SmStructureNode *SmParser::DoBrace() +std::unique_ptr SmParser::DoBrace() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -2017,7 +2015,7 @@ SmStructureNode *SmParser::DoBrace() pLeft.reset(new SmMathSymbolNode(m_aCurToken)); NextToken(); - pBody.reset(DoBracebody(true)); + pBody = DoBracebody(true); if (m_aCurToken.eType == TRIGHT) { NextToken(); @@ -2044,7 +2042,7 @@ SmStructureNode *SmParser::DoBrace() pLeft.reset(new SmMathSymbolNode(m_aCurToken)); NextToken(); - pBody.reset(DoBracebody(false)); + pBody = DoBracebody(false); SmTokenType eExpectedType = TUNKNOWN; switch (pLeft->GetToken().eType) @@ -2076,12 +2074,12 @@ SmStructureNode *SmParser::DoBrace() assert(pRight); xSNode->SetSubNodes(pLeft.release(), pBody.release(), pRight.release()); xSNode->SetScaleMode(eScaleMode); - return xSNode.release(); + return xSNode; } return DoError(eError); } -SmBracebodyNode *SmParser::DoBracebody(bool bIsLeftRight) +std::unique_ptr SmParser::DoBracebody(bool bIsLeftRight) { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -2104,7 +2102,7 @@ SmBracebodyNode *SmParser::DoBracebody(bool bIsLeftRight) { aNodes.push_back(DoAlign()); if (m_aCurToken.eType != TMLINE && m_aCurToken.eType != TRIGHT) - aNodes.emplace_back(std::unique_ptr(DoError(SmParseError::RightExpected))); + aNodes.emplace_back(DoError(SmParseError::RightExpected)); } } while (m_aCurToken.eType != TEND && m_aCurToken.eType != TRIGHT); } @@ -2121,17 +2119,17 @@ SmBracebodyNode *SmParser::DoBracebody(bool bIsLeftRight) { aNodes.push_back(DoAlign()); if (m_aCurToken.eType != TMLINE && !TokenInGroup(TG::RBrace)) - aNodes.emplace_back(std::unique_ptr(DoError(SmParseError::RbraceExpected))); + aNodes.emplace_back(DoError(SmParseError::RbraceExpected)); } } while (m_aCurToken.eType != TEND && !TokenInGroup(TG::RBrace)); } pBody->SetSubNodes(buildNodeArray(aNodes)); pBody->SetScaleMode(bIsLeftRight ? SmScaleMode::Height : SmScaleMode::None); - return pBody.release(); + return pBody; } -SmTextNode *SmParser::DoFunction() +std::unique_ptr SmParser::DoFunction() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -2165,7 +2163,7 @@ SmTextNode *SmParser::DoFunction() { auto pNode = o3tl::make_unique(m_aCurToken, FNT_FUNCTION); NextToken(); - return pNode.release(); + return pNode; } default: @@ -2174,7 +2172,7 @@ SmTextNode *SmParser::DoFunction() } } -SmTableNode *SmParser::DoBinom() +std::unique_ptr SmParser::DoBinom() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -2187,10 +2185,10 @@ SmTableNode *SmParser::DoBinom() auto xFirst = DoSum(); auto xSecond = DoSum(); xSNode->SetSubNodes(xFirst.release(), xSecond.release()); - return xSNode.release(); + return xSNode; } -SmStructureNode *SmParser::DoStack() +std::unique_ptr SmParser::DoStack() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -2211,13 +2209,13 @@ SmStructureNode *SmParser::DoStack() if (m_aCurToken.eType == TRGROUP) NextToken(); else - aExprArr.emplace_back(std::unique_ptr(DoError(SmParseError::RgroupExpected))); + aExprArr.emplace_back(DoError(SmParseError::RgroupExpected)); xSNode->SetSubNodes(buildNodeArray(aExprArr)); - return xSNode.release(); + return xSNode; } -SmStructureNode *SmParser::DoMatrix() +std::unique_ptr SmParser::DoMatrix() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -2249,7 +2247,7 @@ SmStructureNode *SmParser::DoMatrix() if (m_aCurToken.eType == TPOUND) NextToken(); else - xNode.reset(DoError(SmParseError::PoundExpected)); + xNode = DoError(SmParseError::PoundExpected); } aExprArr.emplace_back(std::move(xNode)); } @@ -2271,10 +2269,10 @@ SmStructureNode *SmParser::DoMatrix() xMNode->SetSubNodes(buildNodeArray(aExprArr)); xMNode->SetRowCol(static_cast(nRow), static_cast(nCol)); - return xMNode.release(); + return std::unique_ptr(xMNode.release()); } -SmSpecialNode *SmParser::DoSpecial() +std::unique_ptr SmParser::DoSpecial() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -2317,10 +2315,10 @@ SmSpecialNode *SmParser::DoSpecial() auto pNode = o3tl::make_unique(m_aCurToken); NextToken(); - return pNode.release(); + return pNode; } -SmGlyphSpecialNode *SmParser::DoGlyphSpecial() +std::unique_ptr SmParser::DoGlyphSpecial() { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -2328,10 +2326,10 @@ SmGlyphSpecialNode *SmParser::DoGlyphSpecial() auto pNode = o3tl::make_unique(m_aCurToken); NextToken(); - return pNode.release(); + return pNode; } -SmExpressionNode *SmParser::DoError(SmParseError eError) +std::unique_ptr SmParser::DoError(SmParseError eError) { DepthProtect aDepthGuard(m_nParseDepth); if (aDepthGuard.TooDeep()) @@ -2345,7 +2343,7 @@ SmExpressionNode *SmParser::DoError(SmParseError eError) NextToken(); - return xSNode.release(); + return xSNode; } // end grammar -- cgit