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,25 +384,8 @@ 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:
//case cmOR:
//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()) //if (len!=sTok.length())
// continue; // continue;
@ -431,9 +414,9 @@ bool QmuParserTokenReader::IsBuiltIn ( token_type &a_Tok )
m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE; m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE;
m_iSynFlags |= ( ( i != cmEND ) && ( i != cmBC ) ) ? noEND : 0; m_iSynFlags |= ( ( i != cmEND ) && ( i != cmBC ) ) ? noEND : 0;
break; }
else if (i == cmBO)
case cmBO: {
if ( m_iSynFlags & noBO ) if ( m_iSynFlags & noBO )
{ {
Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) ); Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) );
@ -449,9 +432,9 @@ bool QmuParserTokenReader::IsBuiltIn ( token_type &a_Tok )
} }
++m_iBrackets; ++m_iBrackets;
break; }
else if (i == cmBC)
case cmBC: {
if ( m_iSynFlags & noBC ) if ( m_iSynFlags & noBC )
{ {
Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) ); Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) );
@ -463,29 +446,29 @@ bool QmuParserTokenReader::IsBuiltIn ( token_type &a_Tok )
{ {
Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) ); Error ( ecUNEXPECTED_PARENS, m_iPos, pOprtDef.at ( i ) );
} }
break; }
else if (i == cmELSE)
case cmELSE: {
if ( m_iSynFlags & noELSE ) if ( m_iSynFlags & noELSE )
{ {
Error ( ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef.at ( i ) ); Error ( ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef.at ( i ) );
} }
m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE; m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE;
break; }
else if (i == cmIF)
case cmIF: {
if ( m_iSynFlags & noIF ) if ( m_iSynFlags & noIF )
{ {
Error ( ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef.at ( i ) ); Error ( ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef.at ( i ) );
} }
m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE; m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE;
break; }
else // The operator is listed in c_DefaultOprt, but not here. This is a bad thing...
default: // The operator is listed in c_DefaultOprt, but not here. This is a bad thing... {
Error ( ecINTERNAL_ERROR ); 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 ) );