summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-10-04 15:34:38 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-10-07 18:08:51 +0200
commit3e15dd2915f6f0ebb485781e837f1d9c94268b68 (patch)
treed7d864b7e19f939856db2755437f7b7da1622f88 /starmath
parent10510c002229c63ebf04b3b2a78b3f48fd95311c (diff)
use more unique_ptr in SmParser
Change-Id: I132598f5829e02664040dff745011a59c6a19c1d Reviewed-on: https://gerrit.libreoffice.org/61401 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/inc/parse.hxx28
-rw-r--r--starmath/source/parse.cxx110
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<SmNode> DoSubSup(TG nActiveGroup, SmNode *pGivenNode);
std::unique_ptr<SmNode> DoOpSubSup();
std::unique_ptr<SmNode> DoPower();
- SmBlankNode *DoBlank();
- SmNode *DoTerm(bool bGroupNumberIdent);
- SmNode *DoEscape();
- SmOperNode *DoOperator();
+ std::unique_ptr<SmBlankNode> DoBlank();
+ std::unique_ptr<SmNode> DoTerm(bool bGroupNumberIdent);
+ std::unique_ptr<SmNode> DoEscape();
+ std::unique_ptr<SmOperNode> DoOperator();
std::unique_ptr<SmNode> DoOper();
- SmStructureNode *DoUnOper();
+ std::unique_ptr<SmStructureNode> DoUnOper();
std::unique_ptr<SmNode> DoAlign(bool bUseExtraSpaces = true);
std::unique_ptr<SmStructureNode> DoFontAttribut();
std::unique_ptr<SmStructureNode> DoAttribut();
std::unique_ptr<SmStructureNode> DoFont();
std::unique_ptr<SmStructureNode> DoFontSize();
std::unique_ptr<SmStructureNode> 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<SmStructureNode> DoBrace();
+ std::unique_ptr<SmBracebodyNode> DoBracebody(bool bIsLeftRight);
+ std::unique_ptr<SmTextNode> DoFunction();
+ std::unique_ptr<SmTableNode> DoBinom();
+ std::unique_ptr<SmStructureNode> DoStack();
+ std::unique_ptr<SmStructureNode> DoMatrix();
+ std::unique_ptr<SmSpecialNode> DoSpecial();
+ std::unique_ptr<SmGlyphSpecialNode> DoGlyphSpecial();
+ std::unique_ptr<SmExpressionNode> 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<SmNode> SmParser::DoAlign(bool bUseExtraSpaces)
// allow for just one align statement in 5.0
if (TokenInGroup(TG::Align))
- return std::unique_ptr<SmNode>(DoError(SmParseError::DoubleAlign));
+ return DoError(SmParseError::DoubleAlign);
}
auto pNode = DoExpression(bUseExtraSpaces);
@@ -1146,7 +1146,7 @@ std::unique_ptr<SmNode> 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<SmNode> 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<SmNode> 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<SmNode> SmParser::DoPower()
return xNode;
}
-SmBlankNode *SmParser::DoBlank()
+std::unique_ptr<SmBlankNode> 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<SmNode> 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<SmNode>(xSNode.release());
}
auto pNode = DoAlign(!bNoSpace);
if (m_aCurToken.eType == TRGROUP) {
NextToken();
- return pNode.release();
+ return pNode;
}
auto xSNode = o3tl::make_unique<SmExpressionNode>(m_aCurToken);
std::unique_ptr<SmNode> xError(DoError(SmParseError::RgroupExpected));
xSNode->SetSubNodes(pNode.release(), xError.release());
- return xSNode.release();
+ return std::unique_ptr<SmNode>(xSNode.release());
}
case TLEFT :
@@ -1387,13 +1387,13 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent)
{
auto pNode = o3tl::make_unique<SmTextNode>(m_aCurToken, FNT_TEXT);
NextToken();
- return pNode.release();
+ return std::unique_ptr<SmNode>(pNode.release());
}
case TCHARACTER :
{
auto pNode = o3tl::make_unique<SmTextNode>(m_aCurToken, FNT_VARIABLE);
NextToken();
- return pNode.release();
+ return std::unique_ptr<SmNode>(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<SmNode>(pTextNode.release());
}
std::vector<std::unique_ptr<SmNode>> 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<SmNode>(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<SmExpressionNode> xNode(new SmExpressionNode(SmToken()));
xNode->SetSubNodes(buildNodeArray(aNodes));
- return xNode.release();
+ return std::unique_ptr<SmNode>(xNode.release());
}
case TLEFTARROW :
case TRIGHTARROW :
@@ -1473,7 +1473,7 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent)
{
auto pNode = o3tl::make_unique<SmMathSymbolNode>(m_aCurToken);
NextToken();
- return pNode.release();
+ return std::unique_ptr<SmNode>(pNode.release());
}
case TSETN :
@@ -1493,14 +1493,14 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent)
{
auto pNode = o3tl::make_unique<SmMathIdentifierNode>(m_aCurToken);
NextToken();
- return pNode.release();
+ return std::unique_ptr<SmNode>(pNode.release());
}
case TPLACE:
{
auto pNode = o3tl::make_unique<SmPlaceNode>(m_aCurToken);
NextToken();
- return pNode.release();
+ return std::unique_ptr<SmNode>(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<SmNode> SmParser::DoEscape()
{
DepthProtect aDepthGuard(m_nParseDepth);
if (aDepthGuard.TooDeep())
@@ -1580,14 +1580,14 @@ SmNode *SmParser::DoEscape()
{
auto pNode = o3tl::make_unique<SmMathSymbolNode>(m_aCurToken);
NextToken();
- return pNode.release();
+ return std::unique_ptr<SmNode>(pNode.release());
}
default:
return DoError(SmParseError::UnexpectedToken);
}
}
-SmOperNode *SmParser::DoOperator()
+std::unique_ptr<SmOperNode> 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<SmNode> SmParser::DoOper()
@@ -1668,7 +1668,7 @@ std::unique_ptr<SmNode> SmParser::DoOper()
return pNode;
}
-SmStructureNode *SmParser::DoUnOper()
+std::unique_ptr<SmStructureNode> 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<SmStructureNode> SmParser::DoAttribut()
@@ -1862,8 +1862,7 @@ std::unique_ptr<SmStructureNode> 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<SmStructureNode> 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<SmStructureNode> SmParser::DoFontSize()
case TDIVIDEBY: Type = FontSizeType::DIVIDE; break;
default:
- return std::unique_ptr<SmStructureNode>(DoError(SmParseError::SizeExpected));
+ return DoError(SmParseError::SizeExpected);
}
if (Type != FontSizeType::ABSOLUT)
{
NextToken();
if (m_aCurToken.eType != TNUMBER)
- return std::unique_ptr<SmStructureNode>(DoError(SmParseError::SizeExpected));
+ return DoError(SmParseError::SizeExpected);
}
// get number argument
@@ -1993,7 +1991,7 @@ std::unique_ptr<SmStructureNode> SmParser::DoFontSize()
#endif
}
-SmStructureNode *SmParser::DoBrace()
+std::unique_ptr<SmStructureNode> 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<SmBracebodyNode> 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<SmNode>(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<SmNode>(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<SmTextNode> SmParser::DoFunction()
{
DepthProtect aDepthGuard(m_nParseDepth);
if (aDepthGuard.TooDeep())
@@ -2165,7 +2163,7 @@ SmTextNode *SmParser::DoFunction()
{
auto pNode = o3tl::make_unique<SmTextNode>(m_aCurToken, FNT_FUNCTION);
NextToken();
- return pNode.release();
+ return pNode;
}
default:
@@ -2174,7 +2172,7 @@ SmTextNode *SmParser::DoFunction()
}
}
-SmTableNode *SmParser::DoBinom()
+std::unique_ptr<SmTableNode> 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<SmStructureNode> 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<SmNode>(DoError(SmParseError::RgroupExpected)));
+ aExprArr.emplace_back(DoError(SmParseError::RgroupExpected));
xSNode->SetSubNodes(buildNodeArray(aExprArr));
- return xSNode.release();
+ return xSNode;
}
-SmStructureNode *SmParser::DoMatrix()
+std::unique_ptr<SmStructureNode> 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<sal_uInt16>(nRow),
static_cast<sal_uInt16>(nCol));
- return xMNode.release();
+ return std::unique_ptr<SmStructureNode>(xMNode.release());
}
-SmSpecialNode *SmParser::DoSpecial()
+std::unique_ptr<SmSpecialNode> SmParser::DoSpecial()
{
DepthProtect aDepthGuard(m_nParseDepth);
if (aDepthGuard.TooDeep())
@@ -2317,10 +2315,10 @@ SmSpecialNode *SmParser::DoSpecial()
auto pNode = o3tl::make_unique<SmSpecialNode>(m_aCurToken);
NextToken();
- return pNode.release();
+ return pNode;
}
-SmGlyphSpecialNode *SmParser::DoGlyphSpecial()
+std::unique_ptr<SmGlyphSpecialNode> SmParser::DoGlyphSpecial()
{
DepthProtect aDepthGuard(m_nParseDepth);
if (aDepthGuard.TooDeep())
@@ -2328,10 +2326,10 @@ SmGlyphSpecialNode *SmParser::DoGlyphSpecial()
auto pNode = o3tl::make_unique<SmGlyphSpecialNode>(m_aCurToken);
NextToken();
- return pNode.release();
+ return pNode;
}
-SmExpressionNode *SmParser::DoError(SmParseError eError)
+std::unique_ptr<SmExpressionNode> 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