simplify the ReplaceToken() offset logic to absolute offsets
Change-Id: I8d02fb63bc0c5cb48aabaf7a8800f5f9ac95cbf5
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
@@ -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 );
|
||||
|
@@ -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<ScTokenArray*>(pArr)->ReplaceToken( 1, pTableRefToken,
|
||||
FormulaTokenArray::ReplaceMode::BACKWARD_CODE_ONLY);
|
||||
static_cast<ScTokenArray*>(pArr)->ReplaceToken( nIdx, pTableRefToken,
|
||||
FormulaTokenArray::ReplaceMode::CODE_ONLY);
|
||||
}
|
||||
}
|
||||
switch (eOp)
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user