diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-12-21 15:22:06 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-12-21 17:14:14 +0100 |
commit | 489bce598626390d9c0aa5e5b8514e26070add61 (patch) | |
tree | 170ec95dcb393dbe4f7178bc08e6d96b6b76954b /formula/source | |
parent | f19599c929ac6ae2708b19b9eff62ff70b44ee75 (diff) |
loplugin:flatten in filter..framework
Change-Id: I15a577b3c6da03001bbbf2c2b43b29b41c4007c1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127234
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'formula/source')
-rw-r--r-- | formula/source/core/api/token.cxx | 164 | ||||
-rw-r--r-- | formula/source/ui/dlg/structpg.cxx | 28 |
2 files changed, 96 insertions, 96 deletions
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index 89ae03162778..abda98f2f86d 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -942,68 +942,68 @@ void FormulaTokenArray::AddRecalcMode( ScRecalcMode nBits ) bool FormulaTokenArray::HasMatrixDoubleRefOps() const { - if ( pRPN && nRPN ) + if ( !pRPN || !nRPN ) + return false; + + // RPN-Interpreter simulation. + // Simply assumes a double as return value of each function. + std::unique_ptr<FormulaToken*[]> pStack(new FormulaToken* [nRPN]); + FormulaToken* pResult = new FormulaDoubleToken( 0.0 ); + short sp = 0; + for ( auto t: RPNTokens() ) { - // RPN-Interpreter simulation. - // Simply assumes a double as return value of each function. - std::unique_ptr<FormulaToken*[]> pStack(new FormulaToken* [nRPN]); - FormulaToken* pResult = new FormulaDoubleToken( 0.0 ); - short sp = 0; - for ( auto t: RPNTokens() ) + OpCode eOp = t->GetOpCode(); + sal_uInt8 nParams = t->GetParamCount(); + switch ( eOp ) { - OpCode eOp = t->GetOpCode(); - sal_uInt8 nParams = t->GetParamCount(); - switch ( eOp ) + case ocAdd : + case ocSub : + case ocMul : + case ocDiv : + case ocPow : + case ocPower : + case ocAmpersand : + case ocEqual : + case ocNotEqual : + case ocLess : + case ocGreater : + case ocLessEqual : + case ocGreaterEqual : { - case ocAdd : - case ocSub : - case ocMul : - case ocDiv : - case ocPow : - case ocPower : - case ocAmpersand : - case ocEqual : - case ocNotEqual : - case ocLess : - case ocGreater : - case ocLessEqual : - case ocGreaterEqual : + for ( sal_uInt8 k = nParams; k; k-- ) { - for ( sal_uInt8 k = nParams; k; k-- ) + if ( sp >= k && pStack[sp-k]->GetType() == svDoubleRef ) { - if ( sp >= k && pStack[sp-k]->GetType() == svDoubleRef ) - { - pResult->Delete(); - return true; - } + pResult->Delete(); + return true; } } - break; - default: - { - // added to avoid warnings - } } - if ( eOp == ocPush || lcl_IsReference( eOp, t->GetType() ) ) - pStack[sp++] = t; - else if (FormulaCompiler::IsOpCodeJumpCommand( eOp )) - { // ignore Jumps, pop previous Result (Condition) - if ( sp ) - --sp; + break; + default: + { + // added to avoid warnings } - else - { // pop parameters, push result - sp = sal::static_int_cast<short>( sp - nParams ); - if ( sp < 0 ) - { - SAL_WARN("formula.core", "FormulaTokenArray::HasMatrixDoubleRefOps: sp < 0" ); - sp = 0; - } - pStack[sp++] = pResult; + } + if ( eOp == ocPush || lcl_IsReference( eOp, t->GetType() ) ) + pStack[sp++] = t; + else if (FormulaCompiler::IsOpCodeJumpCommand( eOp )) + { // ignore Jumps, pop previous Result (Condition) + if ( sp ) + --sp; + } + else + { // pop parameters, push result + sp = sal::static_int_cast<short>( sp - nParams ); + if ( sp < 0 ) + { + SAL_WARN("formula.core", "FormulaTokenArray::HasMatrixDoubleRefOps: sp < 0" ); + sp = 0; } + pStack[sp++] = pResult; } - pResult->Delete(); } + pResult->Delete(); return false; } @@ -1530,23 +1530,23 @@ inline bool isWhitespace( OpCode eOp ) { return eOp == ocSpaces || eOp == ocWhit bool FormulaTokenArray::MayReferenceFollow() { - if ( pCode && nLen > 0 ) + if ( !pCode || nLen <= 0 ) + return false; + + // ignore trailing spaces + sal_uInt16 i = nLen - 1; + while (i > 0 && isWhitespace( pCode[i]->GetOpCode())) { - // ignore trailing spaces - sal_uInt16 i = nLen - 1; - while (i > 0 && isWhitespace( pCode[i]->GetOpCode())) - { - --i; - } - if (i > 0 || !isWhitespace( pCode[i]->GetOpCode())) + --i; + } + if (i > 0 || !isWhitespace( pCode[i]->GetOpCode())) + { + OpCode eOp = pCode[i]->GetOpCode(); + if ( (SC_OPCODE_START_BIN_OP <= eOp && eOp < SC_OPCODE_STOP_BIN_OP ) || + (SC_OPCODE_START_UN_OP <= eOp && eOp < SC_OPCODE_STOP_UN_OP ) || + eOp == SC_OPCODE_OPEN || eOp == SC_OPCODE_SEP ) { - OpCode eOp = pCode[i]->GetOpCode(); - if ( (SC_OPCODE_START_BIN_OP <= eOp && eOp < SC_OPCODE_STOP_BIN_OP ) || - (SC_OPCODE_START_UN_OP <= eOp && eOp < SC_OPCODE_STOP_UN_OP ) || - eOp == SC_OPCODE_OPEN || eOp == SC_OPCODE_SEP ) - { - return true; - } + return true; } } return false; @@ -1776,26 +1776,26 @@ FormulaToken* FormulaTokenArrayPlainIterator::GetNextReferenceRPN() FormulaToken* FormulaTokenArrayPlainIterator::GetNextReferenceOrName() { - if( mpFTA->GetArray() ) + if( !mpFTA->GetArray() ) + return nullptr; + + while ( mnIndex < mpFTA->GetLen() ) { - while ( mnIndex < mpFTA->GetLen() ) + FormulaToken* t = mpFTA->GetArray()[ mnIndex++ ]; + switch( t->GetType() ) { - FormulaToken* t = mpFTA->GetArray()[ mnIndex++ ]; - switch( t->GetType() ) + case svSingleRef: + case svDoubleRef: + case svIndex: + case svExternalSingleRef: + case svExternalDoubleRef: + case svExternalName: + return t; + default: { - case svSingleRef: - case svDoubleRef: - case svIndex: - case svExternalSingleRef: - case svExternalDoubleRef: - case svExternalName: - return t; - default: - { - // added to avoid warnings - } - } - } + // added to avoid warnings + } + } } return nullptr; } diff --git a/formula/source/ui/dlg/structpg.cxx b/formula/source/ui/dlg/structpg.cxx index 0eed0ff0dfaa..69a912206384 100644 --- a/formula/source/ui/dlg/structpg.cxx +++ b/formula/source/ui/dlg/structpg.cxx @@ -104,22 +104,22 @@ OUString StructPage::GetEntryText(const weld::TreeIter* pEntry) const const FormulaToken* StructPage::GetFunctionEntry(const weld::TreeIter* pEntry) { - if (pEntry) + if (!pEntry) + return nullptr; + + const FormulaToken * pToken = reinterpret_cast<const FormulaToken *>(m_xTlbStruct->get_id(*pEntry).toInt64()); + if (pToken) { - const FormulaToken * pToken = reinterpret_cast<const FormulaToken *>(m_xTlbStruct->get_id(*pEntry).toInt64()); - if (pToken) + if ( !(pToken->IsFunction() || pToken->GetParamCount() > 1 ) ) { - if ( !(pToken->IsFunction() || pToken->GetParamCount() > 1 ) ) - { - std::unique_ptr<weld::TreeIter> xParent(m_xTlbStruct->make_iterator(pEntry)); - if (!m_xTlbStruct->iter_parent(*xParent)) - return nullptr; - return GetFunctionEntry(xParent.get()); - } - else - { - return pToken; - } + std::unique_ptr<weld::TreeIter> xParent(m_xTlbStruct->make_iterator(pEntry)); + if (!m_xTlbStruct->iter_parent(*xParent)) + return nullptr; + return GetFunctionEntry(xParent.get()); + } + else + { + return pToken; } } return nullptr; |