formula/source/core/api/token.cxx | 26 ++++++++++++++++++++++---- include/formula/tokenarray.hxx | 25 +++++++++++++++++++++++-- sc/source/core/tool/compiler.cxx | 3 ++- sc/source/core/tool/token.cxx | 13 ++++--------- 4 files changed, 51 insertions(+), 16 deletions(-)
New commits: commit 06ed48f0895bf86f915421ecad23ca2a23116f25 Author: Stephan Bergmann <[email protected]> Date: Mon Jun 15 18:30:52 2015 +0200 Make ReplaceMode accessible from ScCompiler::CompileString (cherry picked from commit dbd093176ee8d2185205e7d29fcd0949c074dc85) Fix previous commit (cherry picked from commit f96313d16163ce66c2fa04c99fa25b7c6da1c5b1) 56b5212595f7750965a7620498fb063422f2eae0 Change-Id: If25443f27ff09aca8b38d00ab80ecfdc00ab2642 diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx index d06d3e1a..1050047 100644 --- a/include/formula/tokenarray.hxx +++ b/include/formula/tokenarray.hxx @@ -123,12 +123,14 @@ protected: /// Also used by the compiler. The token MUST had been allocated with new! FormulaToken* Add( FormulaToken* ); +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 }; +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, commit 90c595d054f396d3caa2a868a9b2193f5ac30e8d 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 (cherry picked from commit d53ad9250d77f89a2a7d260a98090a8504c12108) diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 360804f..f9e0cc0 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 3d388bf4d7b3e609f135a362bcc6a972bee187d7 Author: Eike Rathke <[email protected]> Date: Mon Jun 15 14:51:52 2015 +0200 prepare ReplaceToken() to replace also in RPN Change-Id: I98fbcb9849f2c2b1f26109a54ecbf5347cdd8b4e (cherry picked from commit 1d463600f4db2993838c7660da2cb87aa19218fd) diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index ba1be28..cc88919 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 5a74997..82fd38e 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -4144,7 +4144,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
