starmath: Return SmStructureNode from DoAttribut()/DoFontAttribut()

This spares a pair of push and pop of the stack.

Change-Id: Ic5f1ee0ee158779f2f231dab9f7059ce6618bdcb
Reviewed-on: https://gerrit.libreoffice.org/35245
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
This commit is contained in:
Takeshi Abe
2017-03-16 12:27:05 +09:00
parent 6742500ccb
commit 51cf59ca9e
2 changed files with 29 additions and 48 deletions

View File

@@ -77,11 +77,11 @@ class SmParser
void DoOper(); void DoOper();
void DoUnOper(); void DoUnOper();
void DoAlign(); void DoAlign();
void DoFontAttribut(); SmStructureNode *DoFontAttribut();
void DoAttribut(); SmAttributNode *DoAttribut();
void DoFont(); SmStructureNode *DoFont();
void DoFontSize(); SmStructureNode *DoFontSize();
void DoColor(); SmStructureNode *DoColor();
void DoBrace(); void DoBrace();
SmBracebodyNode *DoBracebody(bool bIsLeftRight); SmBracebodyNode *DoBracebody(bool bIsLeftRight);
void DoFunction(); void DoFunction();

View File

@@ -1487,16 +1487,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
bool bIsAttr; bool bIsAttr;
while ( (bIsAttr = TokenInGroup(TG::Attribute)) while ( (bIsAttr = TokenInGroup(TG::Attribute))
|| TokenInGroup(TG::FontAttr)) || TokenInGroup(TG::FontAttr))
{ aStack.push((bIsAttr) ? DoAttribut() : DoFontAttribut());
if (bIsAttr)
DoAttribut();
else
DoFontAttribut();
SmNode* pTmp = popOrZero(m_aNodeStack);
assert(pTmp && !pTmp->IsVisible());
aStack.push(static_cast<SmStructureNode *>(pTmp));
}
DoPower(); DoPower();
@@ -1716,11 +1707,11 @@ void SmParser::DoUnOper()
m_aNodeStack.push_front(std::move(pSNode)); m_aNodeStack.push_front(std::move(pSNode));
} }
void SmParser::DoAttribut() SmAttributNode *SmParser::DoAttribut()
{ {
assert(TokenInGroup(TG::Attribute)); assert(TokenInGroup(TG::Attribute));
std::unique_ptr<SmStructureNode> pSNode(new SmAttributNode(m_aCurToken)); auto pSNode = o3tl::make_unique<SmAttributNode>(m_aCurToken);
SmNode *pAttr; SmNode *pAttr;
SmScaleMode eScaleMode = SCALE_NONE; SmScaleMode eScaleMode = SCALE_NONE;
@@ -1748,11 +1739,11 @@ void SmParser::DoAttribut()
pSNode->SetSubNodes(pAttr, nullptr); // the body will be filled later pSNode->SetSubNodes(pAttr, nullptr); // the body will be filled later
pSNode->SetScaleMode(eScaleMode); pSNode->SetScaleMode(eScaleMode);
m_aNodeStack.push_front(std::move(pSNode)); return pSNode.release();
} }
void SmParser::DoFontAttribut() SmStructureNode *SmParser::DoFontAttribut()
{ {
assert(TokenInGroup(TG::FontAttr)); assert(TokenInGroup(TG::FontAttr));
@@ -1763,28 +1754,28 @@ void SmParser::DoFontAttribut()
case TBOLD : case TBOLD :
case TNBOLD : case TNBOLD :
case TPHANTOM : case TPHANTOM :
m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(m_aCurToken)); {
NextToken(); auto pNode = o3tl::make_unique<SmFontNode>(m_aCurToken);
break; NextToken();
return pNode.release();
}
case TSIZE : case TSIZE :
DoFontSize(); return DoFontSize();
break;
case TFONT : case TFONT :
DoFont(); return DoFont();
break;
case TCOLOR : case TCOLOR :
DoColor(); return DoColor();
break;
default : default :
assert(false); assert(false);
return nullptr;
} }
} }
void SmParser::DoColor() SmStructureNode *SmParser::DoColor()
{ {
assert(m_aCurToken.eType == TCOLOR); assert(m_aCurToken.eType == TCOLOR);
@@ -1798,16 +1789,13 @@ void SmParser::DoColor()
NextToken(); NextToken();
} }
else else
{ return DoError(SmParseError::ColorExpected);
Error(SmParseError::ColorExpected);
return;
}
} while (m_aCurToken.eType == TCOLOR); } while (m_aCurToken.eType == TCOLOR);
m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(aToken)); return new SmFontNode(aToken);
} }
void SmParser::DoFont() SmStructureNode *SmParser::DoFont()
{ {
assert(m_aCurToken.eType == TFONT); assert(m_aCurToken.eType == TFONT);
@@ -1821,13 +1809,10 @@ void SmParser::DoFont()
NextToken(); NextToken();
} }
else else
{ return DoError(SmParseError::FontExpected);
Error(SmParseError::FontExpected);
return;
}
} while (m_aCurToken.eType == TFONT); } while (m_aCurToken.eType == TFONT);
m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(aToken)); return new SmFontNode(aToken);
} }
@@ -1853,7 +1838,7 @@ static bool lcl_IsNumber(const OUString& rText)
return true; return true;
} }
void SmParser::DoFontSize() SmStructureNode *SmParser::DoFontSize()
{ {
assert(m_aCurToken.eType == TSIZE); assert(m_aCurToken.eType == TSIZE);
@@ -1871,18 +1856,14 @@ void SmParser::DoFontSize()
case TDIVIDEBY: Type = FontSizeType::DIVIDE; break; case TDIVIDEBY: Type = FontSizeType::DIVIDE; break;
default: default:
Error(SmParseError::SizeExpected); return DoError(SmParseError::SizeExpected);
return;
} }
if (Type != FontSizeType::ABSOLUT) if (Type != FontSizeType::ABSOLUT)
{ {
NextToken(); NextToken();
if (m_aCurToken.eType != TNUMBER) if (m_aCurToken.eType != TNUMBER)
{ return DoError(SmParseError::SizeExpected);
Error(SmParseError::SizeExpected);
return;
}
} }
// get number argument // get number argument
@@ -1916,7 +1897,7 @@ void SmParser::DoFontSize()
NextToken(); NextToken();
pFontNode->SetSizeParameter(aValue, Type); pFontNode->SetSizeParameter(aValue, Type);
m_aNodeStack.push_front(std::move(pFontNode)); return pFontNode.release();
} }
void SmParser::DoBrace() void SmParser::DoBrace()