summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2018-02-06 17:47:59 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2018-02-07 01:36:57 +0100
commitf0c171a1dd2698f5bec14f5cf00136477032c202 (patch)
tree0c93f240ad27dce5dd0d6b6b83792be34a660517 /starmath
parentb1069ea6f25daa268eb4358d5ea20094b46ef347 (diff)
starmath: Make SmParser::DoLine() etc. return std::unique_ptr
Change-Id: Ia85f66d3490471d7e0c2ce8a1947051be129acf9 Reviewed-on: https://gerrit.libreoffice.org/49276 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/inc/parse.hxx16
-rw-r--r--starmath/source/parse.cxx78
2 files changed, 47 insertions, 47 deletions
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<SmTableNode> DoTable();
- SmLineNode *DoLine();
+ std::unique_ptr<SmNode> DoLine();
std::unique_ptr<SmNode> DoExpression(bool bUseExtraSpaces = true);
- SmNode *DoRelation();
- SmNode *DoSum();
- SmNode *DoProduct();
- SmNode *DoSubSup(TG nActiveGroup, SmNode *pGivenNode);
- SmNode *DoOpSubSup();
- SmNode *DoPower();
+ std::unique_ptr<SmNode> DoRelation();
+ std::unique_ptr<SmNode> DoSum();
+ std::unique_ptr<SmNode> DoProduct();
+ 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();
- SmNode *DoOper();
+ std::unique_ptr<SmNode> DoOper();
SmStructureNode *DoUnOper();
std::unique_ptr<SmNode> 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<SmTableNode> SmParser::DoTable()
throw std::range_error("parser depth limit");
std::vector<std::unique_ptr<SmNode>> aLineArray;
- aLineArray.emplace_back(std::unique_ptr<SmNode>(DoLine()));
+ aLineArray.push_back(DoLine());
while (m_aCurToken.eType == TNEWLINE)
{
NextToken();
- aLineArray.emplace_back(std::unique_ptr<SmNode>(DoLine()));
+ aLineArray.push_back(DoLine());
}
assert(m_aCurToken.eType == TEND);
std::unique_ptr<SmTableNode> xSNode(new SmTableNode(m_aCurToken));
@@ -1000,7 +1000,7 @@ std::unique_ptr<SmNode> SmParser::DoAlign(bool bUseExtraSpaces)
}
// Postcondition: m_aCurToken.eType == TEND || m_aCurToken.eType == TNEWLINE
-SmLineNode *SmParser::DoLine()
+std::unique_ptr<SmNode> SmParser::DoLine()
{
DepthProtect aDepthGuard(m_nParseDepth);
if (aDepthGuard.TooDeep())
@@ -1029,7 +1029,7 @@ SmLineNode *SmParser::DoLine()
auto xSNode = o3tl::make_unique<SmLineNode>(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<SmNode> SmParser::DoExpression(bool bUseExtraSpaces)
@@ -1039,9 +1039,9 @@ std::unique_ptr<SmNode> SmParser::DoExpression(bool bUseExtraSpaces)
throw std::range_error("parser depth limit");
std::vector<std::unique_ptr<SmNode>> RelationArray;
- RelationArray.emplace_back(std::unique_ptr<SmNode>(DoRelation()));
+ RelationArray.push_back(DoRelation());
while (m_aCurToken.nLevel >= 4)
- RelationArray.emplace_back(std::unique_ptr<SmNode>(DoRelation()));
+ RelationArray.push_back(DoRelation());
if (RelationArray.size() > 1)
{
@@ -1059,49 +1059,49 @@ std::unique_ptr<SmNode> SmParser::DoExpression(bool bUseExtraSpaces)
}
}
-SmNode *SmParser::DoRelation()
+std::unique_ptr<SmNode> SmParser::DoRelation()
{
DepthProtect aDepthGuard(m_nParseDepth);
if (aDepthGuard.TooDeep())
throw std::range_error("parser depth limit");
- std::unique_ptr<SmNode> xFirst(DoSum());
+ auto xFirst = DoSum();
while (TokenInGroup(TG::Relation))
{
std::unique_ptr<SmStructureNode> xSNode(new SmBinHorNode(m_aCurToken));
- std::unique_ptr<SmNode> xSecond(DoOpSubSup());
- std::unique_ptr<SmNode> 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<SmNode> SmParser::DoSum()
{
DepthProtect aDepthGuard(m_nParseDepth);
if (aDepthGuard.TooDeep())
throw std::range_error("parser depth limit");
- std::unique_ptr<SmNode> xFirst(DoProduct());
+ auto xFirst = DoProduct();
while (TokenInGroup(TG::Sum))
{
std::unique_ptr<SmStructureNode> xSNode(new SmBinHorNode(m_aCurToken));
- std::unique_ptr<SmNode> xSecond(DoOpSubSup());
- std::unique_ptr<SmNode> 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<SmNode> SmParser::DoProduct()
{
DepthProtect aDepthGuard(m_nParseDepth);
if (aDepthGuard.TooDeep())
throw std::range_error("parser depth limit");
- std::unique_ptr<SmNode> 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<SmNode> 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<SmNode> SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode)
{
std::unique_ptr<SmNode> 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<SmNode> 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<SmNode> 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<SmStructureNode>(bIsAttr ? DoAttribut() : DoFontAttribut()));
- std::unique_ptr<SmNode> xFirstNode(DoPower());
+ auto xFirstNode = DoPower();
while (!aStack.empty())
{
std::unique_ptr<SmStructureNode> xNode = std::move(aStack.top());
@@ -1569,19 +1569,19 @@ SmOperNode *SmParser::DoOperator()
auto xSNode = o3tl::make_unique<SmOperNode>(m_aCurToken);
// get operator
- std::unique_ptr<SmNode> 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<SmNode> xArg(DoPower());
+ auto xArg = DoPower();
xSNode->SetSubNodes(xOperator.release(), xArg.release());
return xSNode.release();
}
-SmNode *SmParser::DoOper()
+std::unique_ptr<SmNode> 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<SmNode> xFirst(DoSum());
- std::unique_ptr<SmNode> xSecond(DoSum());
+ auto xFirst = DoSum();
+ auto xSecond = DoSum();
xSNode->SetSubNodes(xFirst.release(), xSecond.release());
return xSNode.release();
}