Kaydet (Commit) 1d463600 authored tarafından Eike Rathke's avatar Eike Rathke

prepare ReplaceToken() to replace also in RPN

Change-Id: I98fbcb9849f2c2b1f26109a54ecbf5347cdd8b4e
üst 09c5a9d4
...@@ -848,15 +848,33 @@ FormulaToken* FormulaTokenArray::MergeArray( ) ...@@ -848,15 +848,33 @@ FormulaToken* FormulaTokenArray::MergeArray( )
return NULL; 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) if (nOffset < nLen)
{ {
CheckToken(*t); CheckToken(*t);
sal_uInt16 nPos = nLen - nOffset - 1;
t->IncRef(); t->IncRef();
pCode[nPos]->DecRef(); FormulaToken* p = pCode[nOffset];
pCode[nPos] = t; 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; return t;
} }
else else
......
...@@ -122,10 +122,29 @@ protected: ...@@ -122,10 +122,29 @@ protected:
/// Also used by the compiler. The token MUST had been allocated with new! /// Also used by the compiler. The token MUST had been allocated with new!
FormulaToken* Add( FormulaToken* ); 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! /** 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 ) inline void SetCombinedBitsRecalcMode( ScRecalcMode nBits )
{ nMode |= (nBits & ~RECALCMODE_EMASK); } { nMode |= (nBits & ~RECALCMODE_EMASK); }
inline ScRecalcMode GetCombinedBitsRecalcMode() const inline ScRecalcMode GetCombinedBitsRecalcMode() const
......
...@@ -4143,7 +4143,8 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula ) ...@@ -4143,7 +4143,8 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
FormulaToken* pTableRefToken = new ScTableRefToken( pPrev->GetIndex(), ScTableRefToken::TABLE); FormulaToken* pTableRefToken = new ScTableRefToken( pPrev->GetIndex(), ScTableRefToken::TABLE);
maTableRefs.push_back( TableRefEntry( pTableRefToken)); maTableRefs.push_back( TableRefEntry( pTableRefToken));
// pPrev may be dead hereafter. // 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) switch (eOp)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment