summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-06-15 14:51:52 +0200
committerEike Rathke <erack@redhat.com>2015-06-15 17:52:16 +0200
commit1d463600f4db2993838c7660da2cb87aa19218fd (patch)
tree9679701e0ab6da444e912abf48f02e59c8cafbd8
parent09c5a9d41e03b3137ce47b9f9419290525458337 (diff)
prepare ReplaceToken() to replace also in RPN
Change-Id: I98fbcb9849f2c2b1f26109a54ecbf5347cdd8b4e
-rw-r--r--formula/source/core/api/token.cxx26
-rw-r--r--include/formula/tokenarray.hxx23
-rw-r--r--sc/source/core/tool/compiler.cxx3
3 files changed, 45 insertions, 7 deletions
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index a5e93923e971..0d272fb1baf2 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 8aebb4b1b45f..d06d3e1a0f25 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 ca4bf4a49601..e4a7293906d7 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)