Better don't touch stack.
--HG-- branch : develop
This commit is contained in:
parent
84f1c4e10f
commit
ba89a2856d
|
@ -841,13 +841,13 @@ void QmuParserBase::ApplyIfElse(QStack<token_type> &a_stOpt, QStack<token_type>
|
||||||
while (a_stOpt.size() && a_stOpt.top().GetCode()==cmELSE)
|
while (a_stOpt.size() && a_stOpt.top().GetCode()==cmELSE)
|
||||||
{
|
{
|
||||||
token_type opElse = a_stOpt.pop();
|
token_type opElse = a_stOpt.pop();
|
||||||
Q_ASSERT(a_stOpt.size()>0); //-V654
|
Q_ASSERT(a_stOpt.size()>0);
|
||||||
|
|
||||||
// Take the value associated with the else branch from the value stack
|
// Take the value associated with the else branch from the value stack
|
||||||
token_type vVal2 = a_stVal.pop();
|
token_type vVal2 = a_stVal.pop();
|
||||||
|
|
||||||
Q_ASSERT(a_stOpt.size()>0); //-V654
|
Q_ASSERT(a_stOpt.size()>0);
|
||||||
Q_ASSERT(a_stVal.size()>=2); //-V654
|
Q_ASSERT(a_stVal.size()>=2);
|
||||||
|
|
||||||
// it then else is a ternary operator Pop all three values from the value s
|
// it then else is a ternary operator Pop all three values from the value s
|
||||||
// tack and just return the right value
|
// tack and just return the right value
|
||||||
|
@ -857,8 +857,8 @@ void QmuParserBase::ApplyIfElse(QStack<token_type> &a_stOpt, QStack<token_type>
|
||||||
a_stVal.push( (qFuzzyCompare(vExpr.GetVal()+1, 1+0)==false) ? vVal1 : vVal2);
|
a_stVal.push( (qFuzzyCompare(vExpr.GetVal()+1, 1+0)==false) ? vVal1 : vVal2);
|
||||||
|
|
||||||
token_type opIf = a_stOpt.pop();
|
token_type opIf = a_stOpt.pop();
|
||||||
Q_ASSERT(opElse.GetCode()==cmELSE); //-V654
|
Q_ASSERT(opElse.GetCode()==cmELSE);
|
||||||
Q_ASSERT(opIf.GetCode()==cmIF); //-V654
|
Q_ASSERT(opIf.GetCode()==cmIF);
|
||||||
|
|
||||||
m_vRPN.AddIfElse(cmENDIF);
|
m_vRPN.AddIfElse(cmENDIF);
|
||||||
} // while pending if-else-clause found
|
} // while pending if-else-clause found
|
||||||
|
@ -877,7 +877,7 @@ void QmuParserBase::ApplyBinOprt(QStack<token_type> &a_stOpt, QStack<token_type>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Q_ASSERT(a_stVal.size()>=2); //-V654
|
Q_ASSERT(a_stVal.size()>=2);
|
||||||
token_type valTok1 = a_stVal.pop(),
|
token_type valTok1 = a_stVal.pop(),
|
||||||
valTok2 = a_stVal.pop(),
|
valTok2 = a_stVal.pop(),
|
||||||
optTok = a_stOpt.pop(),
|
optTok = a_stOpt.pop(),
|
||||||
|
@ -913,9 +913,10 @@ void QmuParserBase::ApplyBinOprt(QStack<token_type> &a_stOpt, QStack<token_type>
|
||||||
*/
|
*/
|
||||||
void QmuParserBase::ApplyRemainingOprt(QStack<token_type> &stOpt, QStack<token_type> &stVal) const
|
void QmuParserBase::ApplyRemainingOprt(QStack<token_type> &stOpt, QStack<token_type> &stVal) const
|
||||||
{
|
{
|
||||||
const ECmdCode code = stOpt.top().GetCode();
|
while (stOpt.size() && stOpt.top().GetCode() != cmBO && stOpt.top().GetCode() != cmIF)
|
||||||
while (stOpt.size() && code != cmBO && code != cmIF)
|
|
||||||
{
|
{
|
||||||
|
const ECmdCode code = stOpt.top().GetCode();
|
||||||
|
|
||||||
if ((code >= cmLE && code <= cmASSIGN) || code == cmOPRT_INFIX || code == cmOPRT_BIN)
|
if ((code >= cmLE && code <= cmASSIGN) || code == cmOPRT_INFIX || code == cmOPRT_BIN)
|
||||||
{
|
{
|
||||||
if (code==cmOPRT_INFIX)
|
if (code==cmOPRT_INFIX)
|
||||||
|
@ -1175,7 +1176,7 @@ qreal QmuParserBase::ParseCmdCodeBulk(int nOffset, int nThreadID) const
|
||||||
|
|
||||||
// The index of the string argument in the string table
|
// The index of the string argument in the string table
|
||||||
int iIdxStack = pTok->Fun.idx;
|
int iIdxStack = pTok->Fun.idx;
|
||||||
Q_ASSERT( iIdxStack>=0 && iIdxStack<m_vStringBuf.size() ); //-V654
|
Q_ASSERT( iIdxStack>=0 && iIdxStack<m_vStringBuf.size() );
|
||||||
|
|
||||||
switch (pTok->Fun.argc) // switch according to argument count
|
switch (pTok->Fun.argc) // switch according to argument count
|
||||||
{
|
{
|
||||||
|
@ -1395,8 +1396,7 @@ void QmuParserBase::CreateRPN() const
|
||||||
ApplyRemainingOprt(stOpt, stVal);
|
ApplyRemainingOprt(stOpt, stVal);
|
||||||
|
|
||||||
// Check if the bracket content has been evaluated completely
|
// Check if the bracket content has been evaluated completely
|
||||||
token_type &topToken = stOpt.top();
|
if (stOpt.size() && stOpt.top().GetCode()==cmBO)
|
||||||
if (stOpt.size() && topToken.GetCode()==cmBO)
|
|
||||||
{
|
{
|
||||||
// if opt is ")" and opta is "(" the bracket has been evaluated, now its time to check
|
// if opt is ")" and opta is "(" the bracket has been evaluated, now its time to check
|
||||||
// if there is either a function or a sign pending
|
// if there is either a function or a sign pending
|
||||||
|
@ -1409,17 +1409,17 @@ void QmuParserBase::CreateRPN() const
|
||||||
|
|
||||||
stOpt.pop(); // Take opening bracket from stack
|
stOpt.pop(); // Take opening bracket from stack
|
||||||
|
|
||||||
if (iArgCount>1 && ( stOpt.size()==0 || (topToken.GetCode()!=cmFUNC &&
|
if (iArgCount>1 && ( stOpt.size()==0 || (stOpt.top().GetCode()!=cmFUNC &&
|
||||||
topToken.GetCode()!=cmFUNC_BULK &&
|
stOpt.top().GetCode()!=cmFUNC_BULK &&
|
||||||
topToken.GetCode()!=cmFUNC_STR) ) )
|
stOpt.top().GetCode()!=cmFUNC_STR) ) )
|
||||||
{
|
{
|
||||||
Error(ecUNEXPECTED_ARG, m_pTokenReader->GetPos());
|
Error(ecUNEXPECTED_ARG, m_pTokenReader->GetPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
// The opening bracket was popped from the stack now check if there
|
// The opening bracket was popped from the stack now check if there
|
||||||
// was a function before this bracket
|
// was a function before this bracket
|
||||||
if (stOpt.size() && topToken.GetCode()!=cmOPRT_INFIX && topToken.GetCode()!=cmOPRT_BIN &&
|
if (stOpt.size() && stOpt.top().GetCode()!=cmOPRT_INFIX && stOpt.top().GetCode()!=cmOPRT_BIN &&
|
||||||
topToken.GetFuncAddr()!=0)
|
stOpt.top().GetFuncAddr()!=0)
|
||||||
{
|
{
|
||||||
ApplyFunc(stOpt, stVal, iArgCount);
|
ApplyFunc(stOpt, stVal, iArgCount);
|
||||||
}
|
}
|
||||||
|
@ -1453,16 +1453,16 @@ void QmuParserBase::CreateRPN() const
|
||||||
case cmLOR:
|
case cmLOR:
|
||||||
case cmASSIGN:
|
case cmASSIGN:
|
||||||
case cmOPRT_BIN:
|
case cmOPRT_BIN:
|
||||||
|
// A binary operator (user defined or built in) has been found.
|
||||||
|
while ( stOpt.size() && stOpt.top().GetCode() != cmBO && stOpt.top().GetCode() != cmELSE &&
|
||||||
|
stOpt.top().GetCode() != cmIF)
|
||||||
{
|
{
|
||||||
const token_type &topToken = stOpt.top();
|
const token_type &topToken = stOpt.top();
|
||||||
// A binary operator (user defined or built in) has been found.
|
|
||||||
while ( stOpt.size() && topToken.GetCode() != cmBO && topToken.GetCode() != cmELSE &&
|
|
||||||
topToken.GetCode() != cmIF)
|
|
||||||
{
|
|
||||||
int nPrec1 = GetOprtPrecedence(topToken),
|
int nPrec1 = GetOprtPrecedence(topToken),
|
||||||
nPrec2 = GetOprtPrecedence(opt);
|
nPrec2 = GetOprtPrecedence(opt);
|
||||||
|
|
||||||
if (topToken.GetCode()==opt.GetCode())
|
const ECmdCode code = topToken.GetCode();
|
||||||
|
if (code==opt.GetCode())
|
||||||
{
|
{
|
||||||
// Deal with operator associativity
|
// Deal with operator associativity
|
||||||
EOprtAssociativity eOprtAsct = GetOprtAssociativity(opt);
|
EOprtAssociativity eOprtAsct = GetOprtAssociativity(opt);
|
||||||
|
@ -1477,7 +1477,7 @@ void QmuParserBase::CreateRPN() const
|
||||||
// In case the operators are not equal the precedence decides alone...
|
// In case the operators are not equal the precedence decides alone...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (topToken.GetCode()==cmOPRT_INFIX)
|
if (code==cmOPRT_INFIX)
|
||||||
{
|
{
|
||||||
ApplyFunc(stOpt, stVal, 1);
|
ApplyFunc(stOpt, stVal, 1);
|
||||||
}
|
}
|
||||||
|
@ -1495,7 +1495,6 @@ void QmuParserBase::CreateRPN() const
|
||||||
// The operator can't be evaluated right now, push back to the operator stack
|
// The operator can't be evaluated right now, push back to the operator stack
|
||||||
stOpt.push(opt);
|
stOpt.push(opt);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// Last section contains functions and operators implicitely mapped to functions
|
// Last section contains functions and operators implicitely mapped to functions
|
||||||
//
|
//
|
||||||
|
@ -1552,7 +1551,7 @@ void QmuParserBase::CreateRPN() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the last value (= final result) from the stack
|
// get the last value (= final result) from the stack
|
||||||
Q_ASSERT(stArgCount.size()==1); //-V654
|
Q_ASSERT(stArgCount.size()==1);
|
||||||
m_nFinalResultIdx = stArgCount.top();
|
m_nFinalResultIdx = stArgCount.top();
|
||||||
if (m_nFinalResultIdx==0)
|
if (m_nFinalResultIdx==0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user