diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index 7009d94e4756..ac5e33954ff0 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -867,16 +867,13 @@ FormulaToken* FormulaTokenArray::MergeArray( ) FormulaToken* FormulaTokenArray::ReplaceToken( sal_uInt16 nOffset, FormulaToken* t, FormulaTokenArray::ReplaceMode eMode ) { - if (eMode == BACKWARD_CODE_ONLY) - nOffset = nLen - nOffset - 1; - if (nOffset < nLen) { CheckToken(*t); t->IncRef(); FormulaToken* p = pCode[nOffset]; pCode[nOffset] = t; - if (eMode == FORWARD_CODE_AND_RPN && p->GetRef() > 1) + if (eMode == CODE_AND_RPN && p->GetRef() > 1) { for (sal_uInt16 i=0; i < nRPN; ++i) { diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx index e890c3aae2a1..cd0f430f365c 100644 --- a/include/formula/tokenarray.hxx +++ b/include/formula/tokenarray.hxx @@ -127,23 +127,19 @@ protected: public: enum ReplaceMode { - BACKWARD_CODE_ONLY, ///< offset goes backward, replacement only in pCode - FORWARD_CODE_AND_RPN ///< offset goes forward, replacement in pCode and RPN + CODE_ONLY, ///< replacement only in pCode + CODE_AND_RPN ///< replacement in pCode and pRPN }; protected: /** Also used by the compiler. The token MUST had been allocated with new! @param nOffset - If eMode==BACKWARD_CODE_ONLY negative offset of token, 0==last, - 1==previous, ... - If eMode==FORWARD_CODE_AND_RPN positive offset of token, 0==first, - 1==second, ... + Absolute offset in pCode of the token to be replaced. @param eMode - If BACKWARD_CODE_ONLY only the token in pCode at nLen-nOffset-1 - is replaced. - If FORWARD_CODE_AND_RPN the token in pCode at nOffset is - replaced; if the original token was also referenced in the RPN - array then that reference is replaced with a reference to the new + If CODE_ONLY only the token in pCode at nOffset is replaced. + If CODE_AND_RPN the token in pCode at nOffset is replaced; + if the original token was also referenced in the pRPN array + then that reference is replaced with a reference to the new token as well. */ FormulaToken* ReplaceToken( sal_uInt16 nOffset, FormulaToken*, ReplaceMode eMode ); diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index e16446a8606a..f6472867b291 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -4325,8 +4325,8 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula ) FormulaToken* pTableRefToken = new ScTableRefToken( pPrev->GetIndex(), ScTableRefToken::TABLE); maTableRefs.push_back( TableRefEntry( pTableRefToken)); // pPrev may be dead hereafter. - static_cast(pArr)->ReplaceToken( 1, pTableRefToken, - FormulaTokenArray::ReplaceMode::BACKWARD_CODE_ONLY); + static_cast(pArr)->ReplaceToken( nIdx, pTableRefToken, + FormulaTokenArray::ReplaceMode::CODE_ONLY); } } switch (eOp) diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 154868ed24be..00203e05cdf8 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -2397,7 +2397,7 @@ void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, cons OUString aTabName; sal_uInt16 nFileId; GetExternalTableData(pOldDoc, pNewDoc, rRef1.Tab(), aTabName, nFileId); - ReplaceToken( j, new ScExternalDoubleRefToken(nFileId, aTabName, rRef), FORWARD_CODE_AND_RPN); + ReplaceToken( j, new ScExternalDoubleRefToken(nFileId, aTabName, rRef), CODE_AND_RPN); // ATTENTION: rRef can't be used after this point } } @@ -2414,7 +2414,7 @@ void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, cons OUString aTabName; sal_uInt16 nFileId; GetExternalTableData(pOldDoc, pNewDoc, rRef.Tab(), aTabName, nFileId); - ReplaceToken( j, new ScExternalSingleRefToken(nFileId, aTabName, rRef), FORWARD_CODE_AND_RPN); + ReplaceToken( j, new ScExternalSingleRefToken(nFileId, aTabName, rRef), CODE_AND_RPN); // ATTENTION: rRef can't be used after this point } }