formula/source/core/api/token.cxx | 26 ++++++++++++++++++++++---- include/formula/tokenarray.hxx | 23 +++++++++++++++++++++-- sc/source/core/tool/compiler.cxx | 3 ++- sc/source/core/tool/token.cxx | 13 ++++--------- 4 files changed, 49 insertions(+), 16 deletions(-)
New commits: commit d53ad9250d77f89a2a7d260a98090a8504c12108 Author: Eike Rathke <[email protected]> Date: Mon Jun 15 17:50:10 2015 +0200 use ReplaceToken() in ReadjustAbsolute3DReferences() Actually the RPN token needs to be replaced as well if it was referenced. Change-Id: Ie548568dceadaf315ae5596c480916730bed2dca diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 4479488..71bc28c 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -2360,10 +2360,8 @@ void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, cons OUString aTabName; sal_uInt16 nFileId; GetExternalTableData(pOldDoc, pNewDoc, rRef1.Tab(), aTabName, nFileId); - ScExternalDoubleRefToken* pToken = new ScExternalDoubleRefToken(nFileId, aTabName, rRef); - pToken->IncRef(); - pCode[j]->DecRef(); // ATTENTION: rRef can't be used after this point - pCode[j] = pToken; + ReplaceToken( j, new ScExternalDoubleRefToken(nFileId, aTabName, rRef), FORWARD_CODE_AND_RPN); + // ATTENTION: rRef can't be used after this point } } break; @@ -2379,11 +2377,8 @@ void ScTokenArray::ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, cons OUString aTabName; sal_uInt16 nFileId; GetExternalTableData(pOldDoc, pNewDoc, rRef.Tab(), aTabName, nFileId); - //replace with ScExternalSingleRefToken and adjust references - ScExternalSingleRefToken* pToken = new ScExternalSingleRefToken(nFileId, aTabName, rRef); - pToken->IncRef(); - pCode[j]->DecRef(); // ATTENTION: rRef can't be used after this point - pCode[j] = pToken; + ReplaceToken( j, new ScExternalSingleRefToken(nFileId, aTabName, rRef), FORWARD_CODE_AND_RPN); + // ATTENTION: rRef can't be used after this point } } break; commit 1d463600f4db2993838c7660da2cb87aa19218fd Author: Eike Rathke <[email protected]> Date: Mon Jun 15 14:51:52 2015 +0200 prepare ReplaceToken() to replace also in RPN Change-Id: I98fbcb9849f2c2b1f26109a54ecbf5347cdd8b4e diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index a5e9392..0d272fb 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -848,15 +848,33 @@ FormulaToken* FormulaTokenArray::MergeArray( ) return NULL; } -FormulaToken* FormulaTokenArray::ReplaceToken( sal_uInt16 nOffset, FormulaToken* t ) +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); - sal_uInt16 nPos = nLen - nOffset - 1; t->IncRef(); - pCode[nPos]->DecRef(); - pCode[nPos] = t; + FormulaToken* p = pCode[nOffset]; + pCode[nOffset] = t; + if (eMode == FORWARD_CODE_AND_RPN && p->GetRef() > 1) + { + for (sal_uInt16 i=0; i < nRPN; ++i) + { + if (pRPN[i] == p) + { + t->IncRef(); + pRPN[i] = t; + p->DecRef(); + if (p->GetRef() == 1) + break; // for + } + } + } + p->DecRef(); // may be dead now return t; } else diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx index 8aebb4b..d06d3e1a 100644 --- a/include/formula/tokenarray.hxx +++ b/include/formula/tokenarray.hxx @@ -122,10 +122,29 @@ protected: /// Also used by the compiler. The token MUST had been allocated with new! FormulaToken* Add( FormulaToken* ); + + enum ReplaceMode + { + BACKWARD_CODE_ONLY, ///< offset goes backward, replacement only in pCode + FORWARD_CODE_AND_RPN ///< offset goes forward, replacement in pCode and RPN + }; + /** Also used by the compiler. The token MUST had been allocated with new! - @param nOffset negative offset of token, 0==last, 1==previous, ... + @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, ... + @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 + token as well. */ - FormulaToken* ReplaceToken( sal_uInt16 nOffset, FormulaToken* ); + FormulaToken* ReplaceToken( sal_uInt16 nOffset, FormulaToken*, ReplaceMode eMode ); + inline void SetCombinedBitsRecalcMode( ScRecalcMode nBits ) { nMode |= (nBits & ~RECALCMODE_EMASK); } inline ScRecalcMode GetCombinedBitsRecalcMode() const diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index ca4bf4a..e4a7293 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -4143,7 +4143,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<ScTokenArray*>(pArr)->ReplaceToken( 1, pTableRefToken); + static_cast<ScTokenArray*>(pArr)->ReplaceToken( 1, pTableRefToken, + FormulaTokenArray::ReplaceMode::BACKWARD_CODE_ONLY); } } switch (eOp) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
