Refactoring. Delete repetitive code.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-18 15:58:57 +03:00
parent aa1b67d093
commit ec44c57c34
2 changed files with 77 additions and 94 deletions

View File

@ -1450,19 +1450,19 @@ void QmuParserBase::CreateRPN() const
case cmIF: case cmIF:
m_nIfElseCounter++; m_nIfElseCounter++;
// fallthrough intentional (no break!) // fallthrough intentional (no break!)
case cmLAND:
case cmLOR:
case cmLT:
case cmGT:
case cmLE: case cmLE:
case cmGE: case cmGE:
case cmNEQ: case cmNEQ:
case cmEQ: case cmEQ:
case cmLT:
case cmGT:
case cmADD: case cmADD:
case cmSUB: case cmSUB:
case cmMUL: case cmMUL:
case cmDIV: case cmDIV:
case cmPOW: case cmPOW:
case cmLAND:
case cmLOR:
case cmASSIGN: case cmASSIGN:
case cmOPRT_BIN: case cmOPRT_BIN:
// A binary operator (user defined or built in) has been found. // A binary operator (user defined or built in) has been found.

View File

@ -384,108 +384,91 @@ bool QmuParserTokenReader::IsBuiltIn ( token_type &a_Tok )
int len = pOprtDef.at ( i ).length(); int len = pOprtDef.at ( i ).length();
if ( pOprtDef.at ( i ) == m_strFormula.mid ( m_iPos, len ) ) if ( pOprtDef.at ( i ) == m_strFormula.mid ( m_iPos, len ) )
{ {
switch ( i ) if (i >= cmLE && i <= cmASSIGN)
{ {
//case cmAND: //if (len!=sTok.length())
//case cmOR: // continue;
//case cmXOR:
case cmLAND:
case cmLOR:
case cmLT:
case cmGT:
case cmLE:
case cmGE:
case cmNEQ:
case cmEQ:
case cmADD:
case cmSUB:
case cmMUL:
case cmDIV:
case cmPOW:
case cmASSIGN:
//if (len!=sTok.length())
// continue;
// The assignement operator need special treatment // The assignement operator need special treatment
if ( i == cmASSIGN && m_iSynFlags & noASSIGN ) if ( i == cmASSIGN && m_iSynFlags & noASSIGN )
{
Error ( ecUNEXPECTED_OPERATOR, m_iPos, pOprtDef.at ( i ) );
}
if ( m_pParser->HasBuiltInOprt() == false)
{
continue;
}
if ( m_iSynFlags & noOPT )
{
// Maybe its an infix operator not an operator
// Both operator types can share characters in
// their identifiers
if ( IsInfixOpTok ( a_Tok ) )
{ {
Error ( ecUNEXPECTED_OPERATOR, m_iPos, pOprtDef.at ( i ) ); return true;
} }
if ( m_pParser->HasBuiltInOprt() == false) Error ( ecUNEXPECTED_OPERATOR, m_iPos, pOprtDef.at ( i ) );
{ }
continue;
}
if ( m_iSynFlags & noOPT )
{
// Maybe its an infix operator not an operator
// Both operator types can share characters in
// their identifiers
if ( IsInfixOpTok ( a_Tok ) )
{
return true;
}
Error ( ecUNEXPECTED_OPERATOR, m_iPos, pOprtDef.at ( i ) ); m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE;
} m_iSynFlags |= ( ( i != cmEND ) && ( i != cmBC ) ) ? noEND : 0;
}
else if (i == cmBO)
{
if ( m_iSynFlags & noBO )
{
Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) );
}
m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE; if ( m_lastTok.GetCode() == cmFUNC )
m_iSynFlags |= ( ( i != cmEND ) && ( i != cmBC ) ) ? noEND : 0; {
break; m_iSynFlags = noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE;
}
else
{
m_iSynFlags = noBC | noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE;
}
case cmBO: ++m_iBrackets;
if ( m_iSynFlags & noBO ) }
{ else if (i == cmBC)
Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) ); {
} if ( m_iSynFlags & noBC )
{
Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) );
}
if ( m_lastTok.GetCode() == cmFUNC ) m_iSynFlags = noBO | noVAR | noVAL | noFUN | noINFIXOP | noSTR | noASSIGN;
{
m_iSynFlags = noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE;
}
else
{
m_iSynFlags = noBC | noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE;
}
++m_iBrackets; if ( --m_iBrackets < 0 )
break; {
Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) );
}
}
else if (i == cmELSE)
{
if ( m_iSynFlags & noELSE )
{
Error ( ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef.at ( i ) );
}
case cmBC: m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE;
if ( m_iSynFlags & noBC ) }
{ else if (i == cmIF)
Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) ); {
} if ( m_iSynFlags & noIF )
{
Error ( ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef.at ( i ) );
}
m_iSynFlags = noBO | noVAR | noVAL | noFUN | noINFIXOP | noSTR | noASSIGN; m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE;
}
if ( --m_iBrackets < 0 ) else // The operator is listed in c_DefaultOprt, but not here. This is a bad thing...
{ {
Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) ); Error ( ecINTERNAL_ERROR );
} }
break;
case cmELSE:
if ( m_iSynFlags & noELSE )
{
Error ( ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef.at ( i ) );
}
m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE;
break;
case cmIF:
if ( m_iSynFlags & noIF )
{
Error ( ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef.at ( i ) );
}
m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE;
break;
default: // The operator is listed in c_DefaultOprt, but not here. This is a bad thing...
Error ( ecINTERNAL_ERROR );
} // switch operator id
m_iPos += len; m_iPos += len;
a_Tok.Set ( static_cast<ECmdCode>(i), pOprtDef.at ( i ) ); a_Tok.Set ( static_cast<ECmdCode>(i), pOprtDef.at ( i ) );