diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-12-12 15:01:02 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-12-12 17:49:02 +0100 |
commit | 40b0bd21e87480b659e7ed92854eee385a2a3c55 (patch) | |
tree | e71ba92b77eead12445c68c866d7ba71f74e19f5 | |
parent | 4781ba436f72b5b763833c3c036e7f1c0e4d9e3b (diff) |
sc: rowcol: tdf#50916 pass ScDocument to the token classes
needed to create a fake ScDocument for the external ref manager, since
it has no ScDocument at all
Change-Id: Ia786ac291133e3c438694e81ecfb2590729a853d
Reviewed-on: https://gerrit.libreoffice.org/85050
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
65 files changed, 323 insertions, 312 deletions
diff --git a/sc/inc/clipcontext.hxx b/sc/inc/clipcontext.hxx index e2b99ba5bf34..dd84c0e17501 100644 --- a/sc/inc/clipcontext.hxx +++ b/sc/inc/clipcontext.hxx @@ -95,6 +95,7 @@ public: ScDocument* getUndoDoc(); ScDocument* getClipDoc(); + ScDocument* getDestDoc() { return &mrDestDoc; } InsertDeleteFlags getInsertFlag() const; void setDeleteFlag( InsertDeleteFlags nFlag ); diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index 98a3aed7ee78..dce569c2b68a 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -167,7 +167,7 @@ public: */ bool IsValidReference(const ScDocument* pDoc) const; - formula::FormulaToken* CreateToken() const; // create typified token + formula::FormulaToken* CreateToken(const ScDocument* pDoc) const; // create typified token }; class SC_DLLPUBLIC ScCompiler : public formula::FormulaCompiler diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx index 7a6394ad71af..e698eada3362 100644 --- a/sc/inc/externalrefmgr.hxx +++ b/sc/inc/externalrefmgr.hxx @@ -298,6 +298,9 @@ public: */ void clearCacheTables(sal_uInt16 nFileId); + // Get the fake doc used to pass to methods that need an ScDocument in order to do row/col validation + const ScDocument* getFakeDoc() const { return mpFakeDoc; } + private: struct RangeHash { @@ -355,6 +358,7 @@ private: private: mutable osl::Mutex maMtxDocs; mutable DocDataType maDocs; + ScDocument* mpFakeDoc; // just to have something to pass to the methods that need to validate columns/rows }; class SC_DLLPUBLIC ScExternalRefManager final : public formula::ExternalReferenceHelper, public SfxListener diff --git a/sc/inc/reftokenhelper.hxx b/sc/inc/reftokenhelper.hxx index cf71b2309bad..759d69c5762e 100644 --- a/sc/inc/reftokenhelper.hxx +++ b/sc/inc/reftokenhelper.hxx @@ -47,9 +47,9 @@ namespace ScRefTokenHelper /** * Create a double reference token from a range object. */ - void getTokenFromRange(ScTokenRef& pToken, const ScRange& rRange); + void getTokenFromRange(const ScDocument* pDoc, ScTokenRef& pToken, const ScRange& rRange); - void getTokensFromRangeList(::std::vector<ScTokenRef>& pTokens, const ScRangeList& rRanges); + void getTokensFromRangeList(const ScDocument* pDoc, ::std::vector<ScTokenRef>& pTokens, const ScRangeList& rRanges); bool SC_DLLPUBLIC isRef(const ScTokenRef& pToken); bool SC_DLLPUBLIC isExternalRef(const ScTokenRef& pToken); @@ -57,12 +57,12 @@ namespace ScRefTokenHelper bool SC_DLLPUBLIC intersects( const ::std::vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos); - void SC_DLLPUBLIC join(::std::vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos); + void SC_DLLPUBLIC join(const ScDocument* pDoc, ::std::vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos); bool getDoubleRefDataFromToken(ScComplexRefData& rData, const ScTokenRef& pToken); - ScTokenRef createRefToken(const ScAddress& rAddr); - ScTokenRef createRefToken(const ScRange& rRange); + ScTokenRef createRefToken(const ScDocument* pDoc, const ScAddress& rAddr); + ScTokenRef createRefToken(const ScDocument* pDoc, const ScRange& rRange); }; #endif diff --git a/sc/inc/token.hxx b/sc/inc/token.hxx index 5be5ecda9b48..58adad226284 100644 --- a/sc/inc/token.hxx +++ b/sc/inc/token.hxx @@ -54,14 +54,14 @@ void DumpToken(formula::FormulaToken const & rToken); A reused or new'ed ScDoubleRefToken, or a NULL TokenRef if rTok1 or rTok2 are not of sv(Single|Double)Ref */ -formula::FormulaTokenRef extendRangeReference( formula::FormulaToken & rTok1, formula::FormulaToken & rTok2, const ScAddress & rPos, bool bReuseDoubleRef ); +formula::FormulaTokenRef extendRangeReference( const ScDocument* pDoc, formula::FormulaToken & rTok1, formula::FormulaToken & rTok2, const ScAddress & rPos, bool bReuseDoubleRef ); class ScSingleRefToken final : public formula::FormulaToken { private: - ScSingleRefData aSingleRef; + ScSingleRefData aSingleRef; public: - ScSingleRefToken( const ScSingleRefData& r, OpCode e = ocPush ) : + ScSingleRefToken( const ScDocument* /*pDoc*/, const ScSingleRefData& r, OpCode e = ocPush ) : FormulaToken( formula::svSingleRef, e ), aSingleRef( r ) {} virtual const ScSingleRefData* GetSingleRef() const override; virtual ScSingleRefData* GetSingleRef() override; @@ -73,9 +73,9 @@ public: class ScDoubleRefToken final : public formula::FormulaToken { private: - ScComplexRefData aDoubleRef; + ScComplexRefData aDoubleRef; public: - ScDoubleRefToken( const ScComplexRefData& r, OpCode e = ocPush ) : + ScDoubleRefToken( const ScDocument* /*pDoc*/, const ScComplexRefData& r, OpCode e = ocPush ) : FormulaToken( formula::svDoubleRef, e ), aDoubleRef( r ) {} virtual const ScSingleRefData* GetSingleRef() const override; virtual ScSingleRefData* GetSingleRef() override; diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 867e74df7a91..ae6eb22a593f 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -48,8 +48,9 @@ class SAL_WARN_UNUSED SC_DLLPUBLIC ScTokenArray final : public formula::FormulaT { friend class ScCompiler; - bool ImplGetReference( ScRange& rRange, const ScAddress& rPos, bool bValidOnly ) const; + bool ImplGetReference( const ScDocument* pDoc, ScRange& rRange, const ScAddress& rPos, bool bValidOnly ) const; + const ScDocument* mpDoc; size_t mnHashValue; ScFormulaVectorState meVectorState : 4; // Only 4 bits bool mbOpenCLEnabled : 1; @@ -58,7 +59,7 @@ class SAL_WARN_UNUSED SC_DLLPUBLIC ScTokenArray final : public formula::FormulaT void CheckForThreading( const formula::FormulaToken& r ); public: - ScTokenArray(); + ScTokenArray(const ScDocument* pDoc); /** Assignment with incrementing references of FormulaToken entries (not copied!) */ ScTokenArray( const ScTokenArray& ) = default; @@ -91,7 +92,6 @@ public: references. Only use with real functions, e.g. GetOuterFuncOpCode() == ocSum ! */ bool GetAdjacentExtendOfOuterFuncRefs( - const ScDocument* pDoc, SCCOLROW& nExtend, const ScAddress& rPos, ScDirection ); @@ -253,7 +253,7 @@ public: * Create a string representation of formula token array without modifying * the internal state of the token array. */ - OUString CreateString( const ScDocument* pDoc, sc::TokenStringContext& rCxt, const ScAddress& rPos ) const; + OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const; void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ); bool NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const; diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index d5607629dc70..1b85a34ce8c0 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -2792,7 +2792,7 @@ void ScExportTest::testSharedFormulaExportXLS() return false; } - OUString aFormula = pFC->GetCode()->CreateString(&rDoc, aCxt, aPos); + OUString aFormula = pFC->GetCode()->CreateString(aCxt, aPos); aExpected = "Coefficients!RC[-1]"; if (aFormula != aExpected) { diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index a8a98ce2fa44..b90db089d8ed 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -3690,7 +3690,7 @@ void Test::testFormulaRefUpdateNameDeleteRow() sc::TokenStringContext aCxt(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH); const ScTokenArray* pCode = pName->GetCode(); - OUString aExpr = pCode->CreateString(m_pDoc, aCxt, ScAddress(0,0,0)); + OUString aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr); // Insert a new name 'MyAddress' to reference $B$3. Note absolute row. @@ -3702,7 +3702,7 @@ void Test::testFormulaRefUpdateNameDeleteRow() sc::TokenStringContext aCxt2(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH); const ScTokenArray* pCode2 = pName2->GetCode(); - OUString aExpr2 = pCode2->CreateString(m_pDoc, aCxt2, ScAddress(0,0,0)); + OUString aExpr2 = pCode2->CreateString(aCxt2, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$3"), aExpr2); ScDocFunc& rFunc = getDocShell().GetDocFunc(); @@ -3713,16 +3713,16 @@ void Test::testFormulaRefUpdateNameDeleteRow() rFunc.DeleteCells(ScRange(0,2,0,m_pDoc->MaxCol(),2,0), &aMark, DelCellCmd::CellsUp, true); // The reference in the 'MyRange' name should get updated to B2:B3. - aExpr = pCode->CreateString(m_pDoc, aCxt, ScAddress(0,0,0)); + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$3"), aExpr); // The reference in the 'MyAddress' name should get updated to $B$#REF!. - aExpr2 = pCode2->CreateString(m_pDoc, aCxt2, ScAddress(0,0,0)); + aExpr2 = pCode2->CreateString(aCxt2, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$#REF!"), aExpr2); // Delete row 3 again. rFunc.DeleteCells(ScRange(0,2,0,m_pDoc->MaxCol(),2,0), &aMark, DelCellCmd::CellsUp, true); - aExpr = pCode->CreateString(m_pDoc, aCxt, ScAddress(0,0,0)); + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$2"), aExpr); // Undo and check. @@ -3735,7 +3735,7 @@ void Test::testFormulaRefUpdateNameDeleteRow() CPPUNIT_ASSERT(pName); pCode = pName->GetCode(); - aExpr = pCode->CreateString(m_pDoc, aCxt, ScAddress(0,0,0)); + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$3"), aExpr); // Undo again and check. @@ -3745,13 +3745,13 @@ void Test::testFormulaRefUpdateNameDeleteRow() CPPUNIT_ASSERT(pName); pCode = pName->GetCode(); - aExpr = pCode->CreateString(m_pDoc, aCxt, ScAddress(0,0,0)); + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr); // Delete row 2-3. rFunc.DeleteCells(ScRange(0,1,0,m_pDoc->MaxCol(),2,0), &aMark, DelCellCmd::CellsUp, true); - aExpr = pCode->CreateString(m_pDoc, aCxt, ScAddress(0,0,0)); + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$2"), aExpr); // Undo and check. @@ -3761,14 +3761,14 @@ void Test::testFormulaRefUpdateNameDeleteRow() CPPUNIT_ASSERT(pName); pCode = pName->GetCode(); - aExpr = pCode->CreateString(m_pDoc, aCxt, ScAddress(0,0,0)); + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr); pName2 = m_pDoc->GetRangeName()->findByUpperName("MYADDRESS"); CPPUNIT_ASSERT(pName2); pCode2 = pName2->GetCode(); - aExpr2 = pCode2->CreateString(m_pDoc, aCxt2, ScAddress(0,0,0)); + aExpr2 = pCode2->CreateString(aCxt2, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$3"), aExpr2); m_pDoc->InsertTab(1, "test2"); @@ -3781,7 +3781,7 @@ void Test::testFormulaRefUpdateNameDeleteRow() CPPUNIT_ASSERT(pName); pCode = pName->GetCode(); - aExpr = pCode->CreateString(m_pDoc, aCxt, ScAddress(0,0,0)); + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr); pName2 = m_pDoc->GetRangeName()->findByUpperName("MYADDRESS"); @@ -3794,7 +3794,7 @@ void Test::testFormulaRefUpdateNameDeleteRow() // relative to its base position on sheet 0 (same for the 'MyRange' range, // which is the reason why it is not updated either). // This is a tad confusing... - aExpr2 = pCode2->CreateString(m_pDoc, aCxt2, ScAddress(0,0,0)); + aExpr2 = pCode2->CreateString(aCxt2, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$B$3"), aExpr2); m_pDoc->DeleteTab(1); @@ -4022,7 +4022,7 @@ void Test::testFormulaRefUpdateNameDelete() m_pDoc->DeleteCol(1, 0, 3, 0, 0, 1); const ScTokenArray* pCode = pName->GetCode(); sc::TokenStringContext aCxt(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH); - OUString aExpr = pCode->CreateString(m_pDoc, aCxt, ScAddress(0,0,0)); + OUString aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(OUString("$Test.$B$1"), aExpr); m_pDoc->DeleteTab(0); @@ -4181,7 +4181,7 @@ void Test::testTokenArrayRefUpdateMove() ScCompiler aComp(m_pDoc, aPos, m_pDoc->GetGrammar()); std::unique_ptr<ScTokenArray> pArray(aComp.CompileString(aTest)); - OUString aStr = pArray->CreateString(m_pDoc, aCxt, aPos); + OUString aStr = pArray->CreateString(aCxt, aPos); CPPUNIT_ASSERT_EQUAL(aTest, aStr); @@ -4189,7 +4189,7 @@ void Test::testTokenArrayRefUpdateMove() // string should not change. pArray->AdjustReferenceOnMove(aRefCxt, aPos, aPos); - aStr = pArray->CreateString(m_pDoc, aCxt, aPos); + aStr = pArray->CreateString(aCxt, aPos); CPPUNIT_ASSERT_EQUAL(aTest, aStr); } @@ -8463,7 +8463,7 @@ void Test::testRefR1C1WholeCol() ScCompiler aComp(m_pDoc, aPos, FormulaGrammar::GRAM_ENGLISH_XL_R1C1); std::unique_ptr<ScTokenArray> pTokens(aComp.CompileString("=C[10]")); sc::TokenStringContext aCxt(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH); - OUString aFormula = pTokens->CreateString(m_pDoc, aCxt, aPos); + OUString aFormula = pTokens->CreateString(aCxt, aPos); CPPUNIT_ASSERT_EQUAL(OUString("L:L"), aFormula); @@ -8478,7 +8478,7 @@ void Test::testRefR1C1WholeRow() ScCompiler aComp(m_pDoc, aPos, FormulaGrammar::GRAM_ENGLISH_XL_R1C1); std::unique_ptr<ScTokenArray> pTokens(aComp.CompileString("=R[3]")); sc::TokenStringContext aCxt(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH); - OUString aFormula = pTokens->CreateString(m_pDoc, aCxt, aPos); + OUString aFormula = pTokens->CreateString(aCxt, aPos); CPPUNIT_ASSERT_EQUAL(OUString("5:5"), aFormula); diff --git a/sc/source/core/data/clipcontext.cxx b/sc/source/core/data/clipcontext.cxx index 3c5ac04bbe5d..1926d865669e 100644 --- a/sc/source/core/data/clipcontext.cxx +++ b/sc/source/core/data/clipcontext.cxx @@ -152,7 +152,7 @@ void CopyFromClipContext::setSingleCell( const ScAddress& rSrcPos, const ScColum aRef.InitAddress(rSrcPos); aRef.SetFlag3D(true); - ScTokenArray aArr; + ScTokenArray aArr(mpClipDoc); aArr.AddSingleReference(aRef); rSrcCell.set(new ScFormulaCell(mpClipDoc, rSrcPos, aArr)); return; diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index d1b10c128344..63080b5dfb7f 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -113,7 +113,7 @@ sc::MatrixEdge ScColumn::GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sc::Matr { using namespace sc; - if (!ValidRow(nRow1) || !ValidRow(nRow2) || nRow1 > nRow2) + if (!GetDoc()->ValidRow(nRow1) || !GetDoc()->ValidRow(nRow2) || nRow1 > nRow2) return MatrixEdge::Nothing; ScAddress aOrigin(ScAddress::INITIALIZE_INVALID); @@ -1280,7 +1280,7 @@ class CopyAsLinkHandler aRef.InitAddress(ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab())); // Absolute reference. aRef.SetFlag3D(true); - ScTokenArray aArr; + ScTokenArray aArr(mrDestCol.GetDoc()); aArr.AddSingleReference(aRef); return new ScFormulaCell(mrDestCol.GetDoc(), ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab()), aArr); } @@ -1986,7 +1986,7 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol) // Split the formula grouping at the top and bottom boundaries. sc::CellStoreType::position_type aPos = maCells.position(nStartRow); sc::SharedFormulaUtil::splitFormulaCellGroup(aPos, nullptr); - if (ValidRow(nEndRow+1)) + if (GetDoc()->ValidRow(nEndRow+1)) { aPos = maCells.position(aPos.first, nEndRow+1); sc::SharedFormulaUtil::splitFormulaCellGroup(aPos, nullptr); @@ -1995,7 +1995,7 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol) // Do the same with the destination column. aPos = rCol.maCells.position(nStartRow); sc::SharedFormulaUtil::splitFormulaCellGroup(aPos, nullptr); - if (ValidRow(nEndRow+1)) + if (GetDoc()->ValidRow(nEndRow+1)) { aPos = rCol.maCells.position(aPos.first, nEndRow+1); sc::SharedFormulaUtil::splitFormulaCellGroup(aPos, nullptr); @@ -2013,7 +2013,7 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol) // Re-group transferred formula cells. aPos = rCol.maCells.position(nStartRow); sc::SharedFormulaUtil::joinFormulaCellAbove(aPos); - if (ValidRow(nEndRow+1)) + if (GetDoc()->ValidRow(nEndRow+1)) { aPos = rCol.maCells.position(aPos.first, nEndRow+1); sc::SharedFormulaUtil::joinFormulaCellAbove(aPos); @@ -2474,15 +2474,15 @@ bool ScColumn::UpdateReference( sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc if (rCxt.mnRowDelta < 0) { nSplitPos = rCxt.maRange.aStart.Row() + rCxt.mnRowDelta; - if (ValidRow(nSplitPos)) + if (GetDoc()->ValidRow(nSplitPos)) aBounds.push_back(nSplitPos); } nSplitPos = rCxt.maRange.aStart.Row(); - if (ValidRow(nSplitPos)) + if (GetDoc()->ValidRow(nSplitPos)) { aBounds.push_back(nSplitPos); nSplitPos = rCxt.maRange.aEnd.Row() + 1; - if (ValidRow(nSplitPos)) + if (GetDoc()->ValidRow(nSplitPos)) aBounds.push_back(nSplitPos); } } @@ -3190,7 +3190,7 @@ void ScColumn::SetDirtyVar() bool ScColumn::IsFormulaDirty( SCROW nRow ) const { - if (!ValidRow(nRow)) + if (!GetDoc()->ValidRow(nRow)) return false; std::pair<sc::CellStoreType::const_iterator,size_t> aPos = maCells.position(nRow); diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index e64da24de5c1..545179eb2857 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -1688,7 +1688,7 @@ struct ColumnStorageDumper void printFormula(const ScFormulaCell* pCell) const { sc::TokenStringContext aCxt(mpDoc, mpDoc->GetGrammar()); - OUString aFormula = pCell->GetCode()->CreateString(mpDoc, aCxt, pCell->aPos); + OUString aFormula = pCell->GetCode()->CreateString(aCxt, pCell->aPos); cout << " * formula: " << aFormula << endl; } diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 99954e8a0574..f417b63d4b0a 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -108,7 +108,7 @@ struct DirtyCellInterpreter void ScColumn::InterpretDirtyCells( SCROW nRow1, SCROW nRow2 ) { - if (!ValidRow(nRow1) || !ValidRow(nRow2) || nRow1 > nRow2) + if (!GetDoc()->ValidRow(nRow1) || !GetDoc()->ValidRow(nRow2) || nRow1 > nRow2) return; DirtyCellInterpreter aFunc; @@ -425,7 +425,7 @@ void ScColumn::DetachFormulaCells( // Split formula grouping at the top and bottom boundaries. sc::SharedFormulaUtil::splitFormulaCellGroup(aPos, nullptr); - if (nLength > 0 && ValidRow(nNextTopRow)) + if (nLength > 0 && GetDoc()->ValidRow(nNextTopRow)) { if (pNewSharedRows && !bLowerSplitOff && !GetDoc()->IsClipOrUndo()) { @@ -462,7 +462,7 @@ void ScColumn::AttachFormulaCells( sc::StartListeningContext& rCxt, SCROW nRow1, sc::CellStoreType::iterator it = aPos.first; sc::SharedFormulaUtil::joinFormulaCellAbove(aPos); - if (ValidRow(nRow2+1)) + if (GetDoc()->ValidRow(nRow2+1)) { aPos = maCells.position(it, nRow2+1); sc::SharedFormulaUtil::joinFormulaCellAbove(aPos); @@ -508,7 +508,7 @@ void ScColumn::DetachFormulaCells( sc::EndListeningContext& rCxt, SCROW nRow1, S // Split formula grouping at the top and bottom boundaries. sc::SharedFormulaUtil::splitFormulaCellGroup(aPos, &rCxt); - if (ValidRow(nRow2+1)) + if (GetDoc()->ValidRow(nRow2+1)) { if (pNewSharedRows && !bLowerSplitOff && !GetDoc()->IsClipOrUndo()) { @@ -1087,7 +1087,7 @@ class CopyCellsFromClipHandler aRef.InitAddress(aSrcPos); aRef.SetFlag3D(true); - ScTokenArray aArr; + ScTokenArray aArr(mrCxt.getDestDoc()); aArr.AddSingleReference(aRef); mrDestCol.SetFormulaCell( @@ -1421,7 +1421,7 @@ void ScColumn::CopyFromClip( aRef.SetAbsRow(nDestRow - nDy); // Source row aDestPos.SetRow( nDestRow ); - ScTokenArray aArr; + ScTokenArray aArr(GetDoc()); aArr.AddSingleReference( aRef ); SetFormulaCell(nDestRow, new ScFormulaCell(pDocument, aDestPos, aArr)); } @@ -1577,7 +1577,7 @@ public: case sc::element_type_formula: { // Combination of value and at least one formula -> Create formula - ScTokenArray aArr; + ScTokenArray aArr(mrDestColumn.GetDoc()); // First row aArr.AddDouble(f); @@ -1635,7 +1635,7 @@ public: case sc::element_type_numeric: { // Source is formula, and dest is value. - ScTokenArray aArr; + ScTokenArray aArr(mrDestColumn.GetDoc()); // First row lcl_AddCode(aArr, p); @@ -1664,7 +1664,7 @@ public: case sc::element_type_formula: { // Both are formulas. - ScTokenArray aArr; + ScTokenArray aArr(mrDestColumn.GetDoc()); // First row lcl_AddCode(aArr, p); @@ -1744,7 +1744,7 @@ public: break; case sc::element_type_formula: { - ScTokenArray aArr; + ScTokenArray aArr(mrDestColumn.GetDoc()); // First row ScFormulaCell* pSrc = sc::formula_block::at(*aPos.first->data, aPos.second); @@ -1836,7 +1836,7 @@ public: // Merge with the next formula group (if any). size_t nNextRow = nDestRow + rNewCell.size; - if (ValidRow(nNextRow)) + if (mrDestColumn.GetDoc()->ValidRow(nNextRow)) { aPos = rDestCells.position(aPos.first, nNextRow); sc::SharedFormulaUtil::joinFormulaCellAbove(aPos); @@ -2182,7 +2182,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const OUString& rString, formula::FormulaGrammar::AddressConvention eConv, const ScSetStringParam* pParam ) { - if (!ValidRow(nRow)) + if (!GetDoc()->ValidRow(nRow)) return false; ScCellValue aNewCell; @@ -2336,11 +2336,11 @@ void ScColumn::SetFormulaCell( bool ScColumn::SetFormulaCells( SCROW nRow, std::vector<ScFormulaCell*>& rCells ) { - if (!ValidRow(nRow)) + if (!GetDoc()->ValidRow(nRow)) return false; SCROW nEndRow = nRow + rCells.size() - 1; - if (!ValidRow(nEndRow)) + if (!GetDoc()->ValidRow(nEndRow)) return false; sc::CellStoreType::position_type aPos = maCells.position(nRow); @@ -2538,7 +2538,7 @@ public: StrCellIterator(const sc::CellStoreType& rCells, SCROW nStart, const ScDocument* pDoc) : miBeg(rCells.begin()), miEnd(rCells.end()), mpDoc(pDoc) { - if (ValidRow(nStart)) + if (pDoc->ValidRow(nStart)) maPos = rCells.position(nStart); else // Make this iterator invalid. @@ -2799,7 +2799,7 @@ void ScColumn::RemoveProtected( SCROW nStartRow, SCROW nEndRow ) void ScColumn::SetError( SCROW nRow, const FormulaError nError) { - if (!ValidRow(nRow)) + if (!GetDoc()->ValidRow(nRow)) return; ScFormulaCell* pCell = new ScFormulaCell(GetDoc(), ScAddress(nCol, nRow, nTab)); @@ -2817,7 +2817,7 @@ void ScColumn::SetError( SCROW nRow, const FormulaError nError) void ScColumn::SetRawString( SCROW nRow, const OUString& rStr ) { - if (!ValidRow(nRow)) + if (!GetDoc()->ValidRow(nRow)) return; svl::SharedString aSS = GetDoc()->GetSharedStringPool().intern(rStr); @@ -2829,7 +2829,7 @@ void ScColumn::SetRawString( SCROW nRow, const OUString& rStr ) void ScColumn::SetRawString( SCROW nRow, const svl::SharedString& rStr ) { - if (!ValidRow(nRow)) + if (!GetDoc()->ValidRow(nRow)) return; std::vector<SCROW> aNewSharedRows; @@ -2847,7 +2847,7 @@ void ScColumn::SetRawString( SCROW nRow, const svl::SharedString& rStr ) void ScColumn::SetRawString( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, const svl::SharedString& rStr, bool bBroadcast ) { - if (!ValidRow(nRow)) + if (!GetDoc()->ValidRow(nRow)) return; std::vector<SCROW> aNewSharedRows; @@ -2866,7 +2866,7 @@ void ScColumn::SetRawString( void ScColumn::SetValue( SCROW nRow, double fVal ) { - if (!ValidRow(nRow)) + if (!GetDoc()->ValidRow(nRow)) return; std::vector<SCROW> aNewSharedRows; @@ -2884,7 +2884,7 @@ void ScColumn::SetValue( SCROW nRow, double fVal ) void ScColumn::SetValue( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, double fVal, bool bBroadcast ) { - if (!ValidRow(nRow)) + if (!GetDoc()->ValidRow(nRow)) return; std::vector<SCROW> aNewSharedRows; diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 14302b32e90f..72110495ba91 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -352,7 +352,7 @@ void ScConditionEntry::Compile( const OUString& rExpr1, const OUString& rExpr2, if ( mpDoc->IsImportingXML() && !bTextToReal ) { // temporary formula string as string tokens - pFormula1.reset( new ScTokenArray ); + pFormula1.reset( new ScTokenArray(mpDoc) ); pFormula1->AssignXMLString( rExpr1, rExprNmsp1 ); // bRelRef1 is set when the formula is compiled again (CompileXML) } @@ -371,7 +371,7 @@ void ScConditionEntry::Compile( const OUString& rExpr1, const OUString& rExpr2, if ( mpDoc->IsImportingXML() && !bTextToReal ) { // temporary formula string as string tokens - pFormula2.reset( new ScTokenArray ); + pFormula2.reset( new ScTokenArray(mpDoc) ); pFormula2->AssignXMLString( rExpr2, rExprNmsp2 ); // bRelRef2 is set when the formula is compiled again (CompileXML) } @@ -1289,7 +1289,7 @@ std::unique_ptr<ScTokenArray> ScConditionEntry::CreateFlatCopiedTokenArray( sal_ pRet.reset(new ScTokenArray( *pFormula1 )); else { - pRet.reset(new ScTokenArray()); + pRet.reset(new ScTokenArray(mpDoc)); if (bIsStr1) { svl::SharedStringPool& rSPool = mpDoc->GetSharedStringPool(); @@ -1305,7 +1305,7 @@ std::unique_ptr<ScTokenArray> ScConditionEntry::CreateFlatCopiedTokenArray( sal_ pRet.reset(new ScTokenArray( *pFormula2 )); else { - pRet.reset(new ScTokenArray()); + pRet.reset(new ScTokenArray(mpDoc)); if (bIsStr2) { svl::SharedStringPool& rSPool = mpDoc->GetSharedStringPool(); diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index 1c64afa18842..22c0ecfae717 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -313,8 +313,8 @@ void ScDocument::InsertMatrixFormula(SCCOL nCol1, SCROW nRow1, aRefData.SetTabRel( true ); aRefData.SetAddress(aBasePos, aBasePos); - ScTokenArray aArr; // consists only of one single reference token. - formula::FormulaToken* t = aArr.AddMatrixSingleReference( aRefData); + ScTokenArray aArr(this); // consists only of one single reference token. + formula::FormulaToken* t = aArr.AddMatrixSingleReference(aRefData); for (const SCTAB& nTab : rMark) { diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx index e5c0cfbef37e..e73a6c3831f1 100644 --- a/sc/source/core/data/documentimport.cxx +++ b/sc/source/core/data/documentimport.cxx @@ -409,7 +409,7 @@ void ScDocumentImport::setMatrixCells( aRefData.SetTabRel(true); aRefData.SetAddress(rBasePos, rBasePos); - ScTokenArray aArr; // consists only of one single reference token. + ScTokenArray aArr(&mpImpl->mrDoc); // consists only of one single reference token. formula::FormulaToken* t = aArr.AddMatrixSingleReference(aRefData); ScAddress aPos = rBasePos; diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index d07619e07fc4..adeb53d311ed 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -615,7 +615,7 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos ) : nSeenInIteration(0), nFormatType(SvNumFormatType::NUMBER), eTempGrammar(formula::FormulaGrammar::GRAM_DEFAULT), - pCode(new ScTokenArray), + pCode(new ScTokenArray(pDoc)), pDocument(pDoc), pPrevious(nullptr), pNext(nullptr), @@ -658,7 +658,7 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos, Compile( rFormula, true, eGrammar ); // bNoListening, Insert does that if (!pCode) // We need to have a non-NULL token array instance at all times. - pCode = new ScTokenArray; + pCode = new ScTokenArray(pDoc); } ScFormulaCell::ScFormulaCell( @@ -783,7 +783,7 @@ ScFormulaCell::ScFormulaCell( nSeenInIteration(0), nFormatType(xGroup->mnFormatType), eTempGrammar( eGrammar), - pCode(xGroup->mpCode ? xGroup->mpCode.get() : new ScTokenArray), + pCode(xGroup->mpCode ? xGroup->mpCode.get() : new ScTokenArray(pDoc)), pDocument( pDoc ), pPrevious(nullptr), pNext(nullptr), @@ -983,7 +983,7 @@ void ScFormulaCell::GetFormula( OUStringBuffer& rBuffer, ScFormulaCell* pCell = nullptr; ScSingleRefData& rRef = *p->GetSingleRef(); ScAddress aAbs = rRef.toAbs(aPos); - if (ValidAddress(aAbs)) + if (pDocument->ValidAddress(aAbs)) pCell = pDocument->GetFormulaCell(aAbs); if (pCell) @@ -1029,7 +1029,7 @@ OUString ScFormulaCell::GetFormula( sc::CompileFormulaContext& rCxt, const ScInt OUStringBuffer aBuf; if (pCode->GetCodeError() != FormulaError::NONE && !pCode->GetLen()) { - ScTokenArray aCode; + ScTokenArray aCode(pContext->mpDoc); aCode.AddToken( FormulaErrorToken( pCode->GetCodeError())); ScCompiler aComp(rCxt, aPos, aCode, false, false, pContext); aComp.CreateStringFromTokenArray(aBuf); @@ -1049,7 +1049,7 @@ OUString ScFormulaCell::GetFormula( sc::CompileFormulaContext& rCxt, const ScInt ScFormulaCell* pCell = nullptr; ScSingleRefData& rRef = *p->GetSingleRef(); ScAddress aAbs = rRef.toAbs(aPos); - if (ValidAddress(aAbs)) + if (pDocument->ValidAddress(aAbs)) pCell = pDocument->GetFormulaCell(aAbs); if (pCell) @@ -3214,7 +3214,7 @@ void setOldCodeToUndo( ScFormulaCell* pFCell = new ScFormulaCell( - pUndoDoc, aUndoPos, pOldCode ? *pOldCode : ScTokenArray(), eTempGrammar, cMatrixFlag); + pUndoDoc, aUndoPos, pOldCode ? *pOldCode : ScTokenArray(pUndoDoc), eTempGrammar, cMatrixFlag); pFCell->SetResultToken(nullptr); // to recognize it as changed later (Cut/Paste!) pUndoDoc->SetFormulaCell(aUndoPos, pFCell); @@ -3819,7 +3819,7 @@ void ScFormulaCell::UpdateTranspose( const ScRange& rSource, const ScAddress& rD if (pUndoDoc) { ScFormulaCell* pFCell = new ScFormulaCell( - pUndoDoc, aPos, pOld ? *pOld : ScTokenArray(), eTempGrammar, cMatrixFlag); + pUndoDoc, aPos, pOld ? *pOld : ScTokenArray(pUndoDoc), eTempGrammar, cMatrixFlag); pFCell->aResult.SetToken( nullptr); // to recognize it as changed later (Cut/Paste!) pUndoDoc->SetFormulaCell(aPos, pFCell); @@ -5031,7 +5031,7 @@ bool ScFormulaCell::InterpretFormulaGroupOpenCL(sc::FormulaLogger::GroupScope& a xGroup->mpCode = std::move(mxGroup->mpCode); // temporarily transfer } - ScTokenArray aCode; + ScTokenArray aCode(pDocument); ScGroupTokenConverter aConverter(aCode, *pDocument, *this, xGroup->mpTopCell->aPos); // TODO avoid this extra compilation ScCompiler aComp( pDocument, xGroup->mpTopCell->aPos, *pCode, formula::FormulaGrammar::GRAM_UNSPECIFIED, true, cMatrixFlag != ScMatrixMode::NONE ); @@ -5113,7 +5113,7 @@ bool ScFormulaCell::InterpretInvariantFormulaGroup() // An invariant group should only have absolute row references, and no // external references are allowed. - ScTokenArray aCode; + ScTokenArray aCode(pDocument); FormulaTokenArrayPlainIterator aIter(*pCode); for (const formula::FormulaToken* p = aIter.First(); p; p = aIter.Next()) { @@ -5490,7 +5490,7 @@ void ScFormulaCell::Dump() const } sc::TokenStringContext aCxt(pDocument, pDocument->GetGrammar()); - cout << " * code: " << pCode->CreateString(pDocument, aCxt, aPos) << endl; + cout << " * code: " << pCode->CreateString(aCxt, aPos) << endl; FormulaError nErrCode = pCode->GetCodeError(); cout << " * code error: "; diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 2c532b733562..0df049aba144 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -811,7 +811,7 @@ class TransClipHandler aRef.InitAddress(aSrcPos); // Absolute reference. aRef.SetFlag3D(true); - ScTokenArray aArr; + ScTokenArray aArr(&mrClipTab.GetDoc()); aArr.AddSingleReference(aRef); return new ScFormulaCell(&mrClipTab.GetDoc(), rDestPos, aArr); } @@ -910,7 +910,7 @@ void ScTable::TransposeClip( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScSingleRefData aRef; aRef.InitAddress(ScAddress(nCol,nRow,nTab)); aRef.SetFlag3D(true); - ScTokenArray aArr; + ScTokenArray aArr(pDestDoc); aArr.AddSingleReference( aRef ); pTransClip->SetFormulaCell( @@ -2378,7 +2378,7 @@ bool ScTable::IsBlockEditable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, { if ( !ValidColRow( nCol2, nRow2 ) ) { - OSL_FAIL("IsBlockEditable: invalid column or row"); + SAL_WARN("sc", "IsBlockEditable: invalid column or row " << nCol2 << " " << nRow2); if (pOnlyNotBecauseOfMatrix) *pOnlyNotBecauseOfMatrix = false; return false; @@ -3178,7 +3178,7 @@ sal_uInt16 ScTable::GetCommonWidth( SCCOL nEndCol ) const sal_uInt16 ScTable::GetRowHeight( SCROW nRow, SCROW* pStartRow, SCROW* pEndRow, bool bHiddenAsZero ) const { - OSL_ENSURE(ValidRow(nRow),"Invalid row number"); + SAL_WARN_IF(!ValidRow(nRow), "sc", "Invalid row number " << nRow); if (ValidRow(nRow) && mpRowHeights) { diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index c3d627d09eff..7f881167d3d4 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -2164,7 +2164,7 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam ) aRef.Ref2.SetAbsCol(nResCols[nResult]); aRef.Ref2.SetAbsRow(rRowEntry.nFuncEnd); - ScTokenArray aArr; + ScTokenArray aArr(pDocument); aArr.AddOpCode( ocSubTotal ); aArr.AddOpCode( ocOpen ); aArr.AddDouble( static_cast<double>(pResFunc[nResult]) ); diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx index 655588a5a841..056fd3eb6547 100644 --- a/sc/source/core/data/validat.cxx +++ b/sc/source/core/data/validat.cxx @@ -775,7 +775,7 @@ bool ScValidationData::GetSelectionFromFormula( { for( nCol = 0; nCol < nCols ; nCol++ ) { - ScTokenArray aCondTokArr; + ScTokenArray aCondTokArr(pDocument); std::unique_ptr<ScTypedStrData> pEntry; OUString aValStr; ScMatrixValue nMatVal = pValues->Get( nCol, nRow); @@ -930,7 +930,7 @@ bool ScValidationData::IsListValid( ScRefCellValue& rCell, const ScAddress& rPos if( !bIsValid ) { // create a formula containing a single string or number - ScTokenArray aCondTokArr; + ScTokenArray aCondTokArr(GetDocument()); double fValue; OUString aStr(pString); if (GetDocument()->GetFormatTable()->IsNumberFormat(aStr, nFormat, fValue)) diff --git a/sc/source/core/tool/chartlis.cxx b/sc/source/core/tool/chartlis.cxx index dd19b56985f1..fab194a2be5d 100644 --- a/sc/source/core/tool/chartlis.cxx +++ b/sc/source/core/tool/chartlis.cxx @@ -101,7 +101,7 @@ ScChartListener::ScChartListener( const OUString& rName, ScDocument* pDocP, bUsed( false ), bDirty( false ) { - ScRefTokenHelper::getTokensFromRangeList(*mpTokens, *rRangeList); + ScRefTokenHelper::getTokensFromRangeList(pDocP, *mpTokens, *rRangeList); } ScChartListener::ScChartListener( const OUString& rName, ScDocument* pDocP, std::unique_ptr<vector<ScTokenRef>> pTokens ) : @@ -193,7 +193,7 @@ ScRangeListRef ScChartListener::GetRangeList() const void ScChartListener::SetRangeList( const ScRangeListRef& rNew ) { vector<ScTokenRef> aTokens; - ScRefTokenHelper::getTokensFromRangeList(aTokens, *rNew); + ScRefTokenHelper::getTokensFromRangeList(mpDoc, aTokens, *rNew); mpTokens->swap(aTokens); } @@ -292,7 +292,7 @@ void ScChartListener::ChangeListening( const ScRangeListRef& rRangeListRef, void ScChartListener::UpdateChartIntersecting( const ScRange& rRange ) { ScTokenRef pToken; - ScRefTokenHelper::getTokenFromRange(pToken, rRange); + ScRefTokenHelper::getTokenFromRange(mpDoc, pToken, rRange); if (ScRefTokenHelper::intersects(*mpTokens, pToken, ScAddress())) { diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index b943edf34af1..3d4a2def3552 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -4458,7 +4458,7 @@ std::unique_ptr<ScTokenArray> ScCompiler::CompileString( const OUString& rFormul if( meGrammar == FormulaGrammar::GRAM_EXTERNAL ) SetGrammar( FormulaGrammar::GRAM_PODF ); - ScTokenArray aArr; + ScTokenArray aArr(pDoc); pArr = &aArr; maArrIterator = FormulaTokenArrayPlainIterator(*pArr); aFormula = comphelper::string::strip(rFormula, ' '); @@ -4658,7 +4658,7 @@ std::unique_ptr<ScTokenArray> ScCompiler::CompileString( const OUString& rFormul ++pFunctionStack[ nFunction ].nSep; } } - FormulaToken* pNewToken = static_cast<ScTokenArray*>(pArr)->Add( maRawToken.CreateToken()); + FormulaToken* pNewToken = static_cast<ScTokenArray*>(pArr)->Add( maRawToken.CreateToken(pDoc)); if (!pNewToken && eOp == ocArrayClose && pArr->OpCodeBefore( pArr->GetLen()) == ocArrayClose) { // Nested inline array or non-value/non-string in array. The @@ -4778,7 +4778,7 @@ std::unique_ptr<ScTokenArray> ScCompiler::CompileString( const OUString& rFormul table::CellAddress aReferencePos; ScUnoConversion::FillApiAddress( aReferencePos, aPos ); uno::Sequence< sheet::FormulaToken > aTokenSeq = xParser->parseFormula( rFormula, aReferencePos ); - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(pDoc); if( ScTokenConversion::ConvertToTokenArray( *pDoc, aTokenArray, aTokenSeq ) ) { // remember pArr, in case a subsequent CompileTokenArray() is executed. @@ -4827,7 +4827,7 @@ bool ScCompiler::HandleRange() bool bAddPair = !(bBorder1 && bBorder2); if ( bAddPair ) { - pNew = new ScTokenArray(); + pNew = new ScTokenArray(pDoc); pNew->AddOpCode( ocClose ); PushTokenArray( pNew, true ); } @@ -4850,7 +4850,7 @@ bool ScCompiler::HandleRange() maArrIterator.Reset(); if ( bAddPair ) { - pNew = new ScTokenArray(); + pNew = new ScTokenArray(pDoc); pNew->AddOpCode( ocOpen ); PushTokenArray( pNew, true ); } @@ -4861,7 +4861,7 @@ bool ScCompiler::HandleRange() { // No ScRangeData for an already compiled token can happen in BIFF .xls // import if the original range is not present in the document. - pNew = new ScTokenArray; + pNew = new ScTokenArray(pDoc); pNew->Add( new FormulaErrorToken( FormulaError::NoName)); PushTokenArray( pNew, true ); return GetToken(); @@ -5287,7 +5287,7 @@ sal_Unicode ScCompiler::GetNativeAddressSymbol( Convention::SpecialSymbolType eT FormulaTokenRef ScCompiler::ExtendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2 ) { - return extendRangeReference( rTok1, rTok2, aPos, true/*bReuseDoubleRef*/ ); + return extendRangeReference( pDoc, rTok1, rTok2, aPos, true/*bReuseDoubleRef*/ ); } void ScCompiler::fillAddInToken(::std::vector< css::sheet::FormulaOpCodeMapEntry >& _rVec,bool _bIsEnglish) const @@ -5488,7 +5488,7 @@ bool ScCompiler::HandleColRowName() SetError(FormulaError::NoRef); else if (mbJumpCommandReorder) { - ScTokenArray* pNew = new ScTokenArray(); + ScTokenArray* pNew = new ScTokenArray(pDoc); if ( bSingle ) { ScSingleRefData aRefData; @@ -5519,7 +5519,7 @@ bool ScCompiler::HandleColRowName() pNew->AddDoubleReference( aRefData ); else { // automagically - pNew->Add( new ScDoubleRefToken( aRefData, ocColRowNameAuto ) ); + pNew->Add( new ScDoubleRefToken( pDoc, aRefData, ocColRowNameAuto ) ); } } PushTokenArray( pNew, true ); @@ -5544,7 +5544,7 @@ bool ScCompiler::HandleDbData() pDBData->GetArea(aRange); aRange.aEnd.SetTab(aRange.aStart.Tab()); aRefData.SetRange(aRange, aPos); - ScTokenArray* pNew = new ScTokenArray(); + ScTokenArray* pNew = new ScTokenArray(pDoc); pNew->AddDoubleReference( aRefData ); PushTokenArray( pNew, true ); return GetToken(); @@ -5745,7 +5745,7 @@ bool ScCompiler::HandleTableRef() } } while (eState != sStop); } - ScTokenArray* pNew = new ScTokenArray(); + ScTokenArray* pNew = new ScTokenArray(pDoc); if (nError == FormulaError::NONE || nError == FormulaError::NoValue) { bool bCol2Rel = false; @@ -5808,7 +5808,7 @@ bool ScCompiler::HandleTableRef() if (nError != FormulaError::NONE) { aRefData.SetAddress( aRange.aStart, aRange.aStart); - pTR->SetAreaRefRPN( new ScSingleRefToken( aRefData)); // set reference at TableRef + pTR->SetAreaRefRPN( new ScSingleRefToken(pDoc, aRefData)); // set reference at TableRef pNew->Add( new FormulaErrorToken( nError)); // set error in RPN } else @@ -5837,7 +5837,7 @@ bool ScCompiler::HandleTableRef() if (nError != FormulaError::NONE) { aRefData.SetRange( aRange, aRange.aStart); - pTR->SetAreaRefRPN( new ScDoubleRefToken( aRefData)); // set reference at TableRef + pTR->SetAreaRefRPN( new ScDoubleRefToken(pDoc, aRefData)); // set reference at TableRef pNew->Add( new FormulaErrorToken( nError)); // set error in RPN } else @@ -6095,7 +6095,7 @@ void ScCompiler::ReplaceDoubleRefII(FormulaToken** ppDoubleRefTok) aSingleRef.SetAddress(aAddr, aPos); // Replace the original doubleref token with computed singleref token - FormulaToken* pNewSingleRefTok = new ScSingleRefToken(aSingleRef); + FormulaToken* pNewSingleRefTok = new ScSingleRefToken(pDoc, aSingleRef); (*ppDoubleRefTok)->DecRef(); *ppDoubleRefTok = pNewSingleRefTok; pNewSingleRefTok->IncRef(); @@ -6226,7 +6226,7 @@ void ScCompiler::CorrectSumRange(const ScComplexRefData& rBaseRange, return; // Replace sum-range token - FormulaToken* pNewSumRangeTok = new ScDoubleRefToken(rSumRange); + FormulaToken* pNewSumRangeTok = new ScDoubleRefToken(pDoc, rSumRange); (*ppSumRangeToken)->DecRef(); *ppSumRangeToken = pNewSumRangeTok; pNewSumRangeTok->IncRef(); diff --git a/sc/source/core/tool/consoli.cxx b/sc/source/core/tool/consoli.cxx index dae69f4b01f0..bb8647e5e401 100644 --- a/sc/source/core/tool/consoli.cxx +++ b/sc/source/core/tool/consoli.cxx @@ -476,7 +476,7 @@ void ScConsData::OutputToDocument( ScDocument* pDestDoc, SCCOL nCol, SCROW nRow, aSRef.SetAddress(ScAddress(aRef.nCol,aRef.nRow,aRef.nTab), ScAddress()); - ScTokenArray aRefArr; + ScTokenArray aRefArr(pDestDoc); aRefArr.AddSingleReference(aSRef); aRefArr.AddOpCode(ocStop); ScAddress aDest( sal::static_int_cast<SCCOL>(nCol+nArrX), @@ -495,7 +495,7 @@ void ScConsData::OutputToDocument( ScDocument* pDestDoc, SCCOL nCol, SCROW nRow, aRange.aEnd.SetRow(nRow+nArrY+nNeeded-1); aCRef.SetRange(aRange, aDest); - ScTokenArray aArr; + ScTokenArray aArr(pDestDoc); aArr.AddOpCode(eOpCode); // selected function aArr.AddOpCode(ocOpen); aArr.AddDoubleReference(aCRef); diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx index 91693af8ff40..8cf2f8a5fd33 100644 --- a/sc/source/core/tool/detfunc.cxx +++ b/sc/source/core/tool/detfunc.cxx @@ -1376,7 +1376,7 @@ void ScDetectiveFunc::GetAllPreds(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW n for (formula::FormulaToken* p = aRefIter.GetNextRefToken(); p; p = aRefIter.GetNextRefToken()) { ScTokenRef pRef(p->Clone()); - ScRefTokenHelper::join(rRefTokens, pRef, aIter.GetPos()); + ScRefTokenHelper::join(pDoc, rRefTokens, pRef, aIter.GetPos()); } } } @@ -1386,7 +1386,7 @@ void ScDetectiveFunc::GetAllSuccs(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW n { vector<ScTokenRef> aSrcRange; aSrcRange.push_back( - ScRefTokenHelper::createRefToken(ScRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab))); + ScRefTokenHelper::createRefToken(pDoc, ScRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab))); ScCellIterator aIter(pDoc, ScRange(0, 0, nTab, pDoc->MaxCol(), pDoc->MaxRow(), nTab)); for (bool bHas = aIter.first(); bHas; bHas = aIter.next()) @@ -1403,8 +1403,8 @@ void ScDetectiveFunc::GetAllSuccs(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW n if (ScRefTokenHelper::intersects(aSrcRange, pRef, aPos)) { // This address is absolute. - pRef = ScRefTokenHelper::createRefToken(aPos); - ScRefTokenHelper::join(rRefTokens, pRef, ScAddress()); + pRef = ScRefTokenHelper::createRefToken(pDoc, aPos); + ScRefTokenHelper::join(pDoc, rRefTokens, pRef, ScAddress()); } } } diff --git a/sc/source/core/tool/formulalogger.cxx b/sc/source/core/tool/formulalogger.cxx index 9cddc2a46b9e..3b172e26bb88 100644 --- a/sc/source/core/tool/formulalogger.cxx +++ b/sc/source/core/tool/formulalogger.cxx @@ -78,7 +78,7 @@ struct FormulaLogger::GroupScope::Impl if (mbOutputEnabled) { sc::TokenStringContext aCxt(&rDoc, rDoc.GetGrammar()); - OUString aFormula = rCell.GetCode()->CreateString(&rDoc, aCxt, rCell.aPos); + OUString aFormula = rCell.GetCode()->CreateString(aCxt, rCell.aPos); mrLogger.write(maPrefix); mrLogger.writeNestLevel(); diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index a62e6885c0eb..5340d622e9b4 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -2488,7 +2488,7 @@ void ScInterpreter::ScCellExternal() else if ( aInfoType == "ADDRESS" ) { // ODF 1.2 says we need to always display address using the ODF A1 grammar. - ScTokenArray aArray; + ScTokenArray aArray(pDok); aArray.AddExternalSingleReference(nFileId, svl::SharedString( aTabName), aRef); // string not interned ScCompiler aComp(pDok, aPos, aArray, formula::FormulaGrammar::GRAM_ODFF_A1); OUString aStr; @@ -4431,7 +4431,7 @@ void ScInterpreter::ScColumn() OUString aTabName; ScSingleRefData aRef; PopExternalSingleRef( nFileId, aTabName, aRef ); - ScAddress aAbsRef = aRef.toAbs( aPos ); + ScAddress aAbsRef = aRef.toAbs(aPos); nVal = static_cast<double>( aAbsRef.Col() + 1 ); } break; @@ -4455,7 +4455,7 @@ void ScInterpreter::ScColumn() OUString aTabName; ScComplexRefData aRef; PopExternalDoubleRef( nFileId, aTabName, aRef ); - ScRange aAbs = aRef.toAbs( aPos ); + ScRange aAbs = aRef.toAbs(aPos); nCol1 = aAbs.aStart.Col(); nCol2 = aAbs.aEnd.Col(); } @@ -4535,7 +4535,7 @@ void ScInterpreter::ScRow() OUString aTabName; ScSingleRefData aRef; PopExternalSingleRef( nFileId, aTabName, aRef ); - ScAddress aAbsRef = aRef.toAbs( aPos ); + ScAddress aAbsRef = aRef.toAbs(aPos); nVal = static_cast<double>( aAbsRef.Row() + 1 ); } break; @@ -4558,7 +4558,7 @@ void ScInterpreter::ScRow() OUString aTabName; ScComplexRefData aRef; PopExternalDoubleRef( nFileId, aTabName, aRef ); - ScRange aAbs = aRef.toAbs( aPos ); + ScRange aAbs = aRef.toAbs(aPos); nRow1 = aAbs.aStart.Row(); nRow2 = aAbs.aEnd.Row(); } @@ -7744,7 +7744,7 @@ std::unique_ptr<ScDBQueryParamBase> ScInterpreter::GetDBParams( bool& rMissingFi SetError(nErr); } - if (!ValidCol(nField)) + if (!pDok->ValidCol(nField)) return nullptr; unique_ptr<ScDBQueryParamBase> pParam( pDBRef->createQueryParam(pQueryRef.get()) ); @@ -8269,7 +8269,7 @@ void ScInterpreter::ScAddressFunc() --nCol; --nRow; - if (nGlobalError != FormulaError::NONE || !ValidCol( nCol) || !ValidRow( nRow)) + if (nGlobalError != FormulaError::NONE || !pDok->ValidCol( nCol) || !pDok->ValidRow( nRow)) { PushIllegalArgument(); return; @@ -8346,7 +8346,7 @@ void ScInterpreter::ScOffset() { nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1) + nColPlus); nRow1 = static_cast<SCROW>(static_cast<long>(nRow1) + nRowPlus); - if (!ValidCol(nCol1) || !ValidRow(nRow1)) + if (!pDok->ValidCol(nCol1) || !pDok->ValidRow(nRow1)) PushIllegalArgument(); else PushSingleRef(nCol1, nRow1, nTab1); @@ -8361,8 +8361,8 @@ void ScInterpreter::ScOffset() nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus); nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1); nRow2 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowNew-1); - if (!ValidCol(nCol1) || !ValidRow(nRow1) || - !ValidCol(nCol2) || !ValidRow(nRow2)) + if (!pDok->ValidCol(nCol1) || !pDok->ValidRow(nRow1) || + !pDok->ValidCol(nCol2) || !pDok->ValidRow(nRow2)) PushIllegalArgument(); else PushDoubleRef(nCol1, nRow1, nTab1, nCol2, nRow2, nTab1); @@ -8384,7 +8384,7 @@ void ScInterpreter::ScOffset() { nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1) + nColPlus); nRow1 = static_cast<SCROW>(static_cast<long>(nRow1) + nRowPlus); - if (!ValidCol(nCol1) || !ValidRow(nRow1)) + if (!pDok->ValidCol(nCol1) || !pDok->ValidRow(nRow1)) PushIllegalArgument(); else PushExternalSingleRef(nFileId, aTabName, nCol1, nRow1, nTab1); @@ -8400,8 +8400,8 @@ void ScInterpreter::ScOffset() nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1); nRow2 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowNew-1); nTab2 = nTab1; - if (!ValidCol(nCol1) || !ValidRow(nRow1) || - !ValidCol(nCol2) || !ValidRow(nRow2)) + if (!pDok->ValidCol(nCol1) || !pDok->ValidRow(nRow1) || + !pDok->ValidCol(nCol2) || !pDok->ValidRow(nRow2)) PushIllegalArgument(); else PushExternalDoubleRef(nFileId, aTabName, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2); @@ -8419,8 +8419,8 @@ void ScInterpreter::ScOffset() nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus); nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1); nRow2 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowNew-1); - if (!ValidCol(nCol1) || !ValidRow(nRow1) || - !ValidCol(nCol2) || !ValidRow(nRow2) || nTab1 != nTab2) + if (!pDok->ValidCol(nCol1) || !pDok->ValidRow(nRow1) || + !pDok->ValidCol(nCol2) || !pDok->ValidRow(nRow2) || nTab1 != nTab2) PushIllegalArgument(); else PushDoubleRef(nCol1, nRow1, nTab1, nCol2, nRow2, nTab1); @@ -8447,8 +8447,8 @@ void ScInterpreter::ScOffset() nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus); nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1); nRow2 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowNew-1); - if (!ValidCol(nCol1) || !ValidRow(nRow1) || - !ValidCol(nCol2) || !ValidRow(nRow2) || nTab1 != nTab2) + if (!pDok->ValidCol(nCol1) || !pDok->ValidRow(nRow1) || + !pDok->ValidCol(nCol2) || !pDok->ValidRow(nRow2) || nTab1 != nTab2) PushIllegalArgument(); else PushExternalDoubleRef(nFileId, aTabName, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2); diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index d6c76315b8fd..e20af82a4f4b 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -2494,9 +2494,9 @@ void ScInterpreter::ScIntersect() { const ScComplexRefData& rRef = (*pRefList)[0]; if (rRef.Ref1 == rRef.Ref2) - PushTempToken( new ScSingleRefToken( rRef.Ref1)); + PushTempToken( new ScSingleRefToken(pDok, rRef.Ref1)); else - PushTempToken( new ScDoubleRefToken( rRef)); + PushTempToken( new ScDoubleRefToken(pDok, rRef)); } else PushTokenRef( xRes); @@ -2568,7 +2568,7 @@ void ScInterpreter::ScRangeFunc() // We explicitly tell extendRangeReference() to not reuse the token, // casting const away spares two clones. FormulaTokenRef xRes = extendRangeReference( - const_cast<FormulaToken&>(*x1), const_cast<FormulaToken&>(*x2), aPos, false); + pDok, const_cast<FormulaToken&>(*x1), const_cast<FormulaToken&>(*x2), aPos, false); if (!xRes) PushIllegalArgument(); else diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 1e112c386043..55d6b715c2f4 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -1367,7 +1367,7 @@ void ScInterpreter::PopRefListPushMatrixOrRef() if (nEntries == 1) { --sp; - PushTempTokenWithoutError( new ScDoubleRefToken( (*pv)[0] )); + PushTempTokenWithoutError( new ScDoubleRefToken( pDok, (*pv)[0] )); } else if (bMatrixFormula) { @@ -1813,7 +1813,7 @@ void ScInterpreter::PushSingleRef(SCCOL nCol, SCROW nRow, SCTAB nTab) { ScSingleRefData aRef; aRef.InitAddress(ScAddress(nCol,nRow,nTab)); - PushTempTokenWithoutError( new ScSingleRefToken( aRef ) ); + PushTempTokenWithoutError( new ScSingleRefToken( pDok, aRef ) ); } } @@ -1824,7 +1824,7 @@ void ScInterpreter::PushDoubleRef(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, { ScComplexRefData aRef; aRef.InitRange(ScRange(nCol1,nRow1,nTab1,nCol2,nRow2,nTab2)); - PushTempTokenWithoutError( new ScDoubleRefToken( aRef ) ); + PushTempTokenWithoutError( new ScDoubleRefToken( pDok, aRef ) ); } } @@ -1859,7 +1859,7 @@ void ScInterpreter::PushSingleRef( const ScRefAddress& rRef ) { ScSingleRefData aRef; aRef.InitFromRefAddress( rRef, aPos); - PushTempTokenWithoutError( new ScSingleRefToken( aRef ) ); + PushTempTokenWithoutError( new ScSingleRefToken( pDok, aRef ) ); } } @@ -1869,7 +1869,7 @@ void ScInterpreter::PushDoubleRef( const ScRefAddress& rRef1, const ScRefAddress { ScComplexRefData aRef; aRef.InitFromRefAddresses( rRef1, rRef2, aPos); - PushTempTokenWithoutError( new ScDoubleRefToken( aRef ) ); + PushTempTokenWithoutError( new ScDoubleRefToken( pDok, aRef ) ); } } @@ -3666,7 +3666,7 @@ void ScInterpreter::ScDBArea() pDBData->GetArea(aRange); aRange.aEnd.SetTab(aRange.aStart.Tab()); aRefData.SetRange(aRange, aPos); - PushTempToken( new ScDoubleRefToken( aRefData ) ); + PushTempToken( new ScDoubleRefToken( pDok, aRefData ) ); } else PushError( FormulaError::NoName); @@ -3750,7 +3750,7 @@ void ScInterpreter::ScColRowNameAuto() } } aRefData.SetRange(aAbs, aPos); - PushTempToken( new ScDoubleRefToken( aRefData ) ); + PushTempToken( new ScDoubleRefToken( pDok, aRefData ) ); } // --- internals ------------------------------------------------------------ diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index 2ad06e46a8ba..6b8c2098a305 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -74,7 +74,7 @@ ScRangeData::ScRangeData( ScDocument* pDok, // Copy ctor default-constructs pCode if it was NULL, so it's initialized here, too, // to ensure same behavior if unnecessary copying is left out. - pCode.reset( new ScTokenArray ); + pCode.reset( new ScTokenArray(pDoc) ); pCode->SetFromRangeName(true); } } @@ -103,7 +103,7 @@ ScRangeData::ScRangeData( ScDocument* pDok, const ScAddress& rTarget ) : aName ( rName ), aUpperName ( ScGlobal::pCharClass->uppercase( rName ) ), - pCode ( new ScTokenArray() ), + pCode ( new ScTokenArray(pDok) ), aPos ( rTarget ), eType ( Type::Name ), pDoc ( pDok ), @@ -125,7 +125,7 @@ ScRangeData::ScRangeData( ScDocument* pDok, ScRangeData::ScRangeData(const ScRangeData& rScRangeData, ScDocument* pDocument, const ScAddress* pPos) : aName (rScRangeData.aName), aUpperName (rScRangeData.aUpperName), - pCode (rScRangeData.pCode ? rScRangeData.pCode->Clone().release() : new ScTokenArray()), // make real copy (not copy-ctor) + pCode (rScRangeData.pCode ? rScRangeData.pCode->Clone().release() : new ScTokenArray(pDocument)), // make real copy (not copy-ctor) aPos (pPos ? *pPos : rScRangeData.aPos), eType (rScRangeData.eType), pDoc (pDocument ? pDocument : rScRangeData.pDoc), diff --git a/sc/source/core/tool/reftokenhelper.cxx b/sc/source/core/tool/reftokenhelper.cxx index 7ed8db3e2f82..135b544fcdac 100644 --- a/sc/source/core/tool/reftokenhelper.cxx +++ b/sc/source/core/tool/reftokenhelper.cxx @@ -166,7 +166,7 @@ void ScRefTokenHelper::getRangeListFromTokens( } } -void ScRefTokenHelper::getTokenFromRange(ScTokenRef& pToken, const ScRange& rRange) +void ScRefTokenHelper::getTokenFromRange(const ScDocument* pDoc, ScTokenRef& pToken, const ScRange& rRange) { ScComplexRefData aData; aData.InitRange(rRange); @@ -176,10 +176,10 @@ void ScRefTokenHelper::getTokenFromRange(ScTokenRef& pToken, const ScRange& rRan // different sheets. aData.Ref2.SetFlag3D(rRange.aStart.Tab() != rRange.aEnd.Tab()); - pToken.reset(new ScDoubleRefToken(aData)); + pToken.reset(new ScDoubleRefToken(pDoc, aData)); } -void ScRefTokenHelper::getTokensFromRangeList(vector<ScTokenRef>& pTokens, const ScRangeList& rRanges) +void ScRefTokenHelper::getTokensFromRangeList(const ScDocument* pDoc, vector<ScTokenRef>& pTokens, const ScRangeList& rRanges) { vector<ScTokenRef> aTokens; size_t nCount = rRanges.size(); @@ -188,7 +188,7 @@ void ScRefTokenHelper::getTokensFromRangeList(vector<ScTokenRef>& pTokens, const { const ScRange & rRange = rRanges[i]; ScTokenRef pToken; - ScRefTokenHelper::getTokenFromRange(pToken, rRange); + ScRefTokenHelper::getTokenFromRange(pDoc, pToken, rRange); aTokens.push_back(pToken); } pTokens.swap(aTokens); @@ -267,9 +267,9 @@ public: * @param rTokens existing list of reference tokens * @param rToken new token */ - void operator() (vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos) + void operator() (const ScDocument* pDoc, vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos) { - join(rTokens, pToken, rPos); + join(pDoc, rTokens, pToken, rPos); } private: @@ -302,7 +302,7 @@ private: return true; } - void join(vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos) + void join(const ScDocument* pDoc, vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos) { // Normalize the token to a double reference. ScComplexRefData aData; @@ -389,7 +389,7 @@ private: if (bExternal) pOldToken.reset(new ScExternalDoubleRefToken(nFileId, aTabName, aNewData)); else - pOldToken.reset(new ScDoubleRefToken(aNewData)); + pOldToken.reset(new ScDoubleRefToken(pDoc, aNewData)); bJoined = true; break; @@ -405,7 +405,7 @@ private: // Pop the last token from the list, and keep joining recursively. ScTokenRef p = rTokens.back(); rTokens.pop_back(); - join(rTokens, p, rPos); + join(pDoc, rTokens, p, rPos); } else rTokens.push_back(pToken); @@ -414,10 +414,10 @@ private: } -void ScRefTokenHelper::join(vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos) +void ScRefTokenHelper::join(const ScDocument* pDoc, vector<ScTokenRef>& rTokens, const ScTokenRef& pToken, const ScAddress& rPos) { JoinRefTokenRanges join; - join(rTokens, pToken, rPos); + join(pDoc, rTokens, pToken, rPos); } bool ScRefTokenHelper::getDoubleRefDataFromToken(ScComplexRefData& rData, const ScTokenRef& pToken) @@ -445,19 +445,19 @@ bool ScRefTokenHelper::getDoubleRefDataFromToken(ScComplexRefData& rData, const return true; } -ScTokenRef ScRefTokenHelper::createRefToken(const ScAddress& rAddr) +ScTokenRef ScRefTokenHelper::createRefToken(const ScDocument* pDoc, const ScAddress& rAddr) { ScSingleRefData aRefData; aRefData.InitAddress(rAddr); - ScTokenRef pRef(new ScSingleRefToken(aRefData)); + ScTokenRef pRef(new ScSingleRefToken(pDoc, aRefData)); return pRef; } -ScTokenRef ScRefTokenHelper::createRefToken(const ScRange& rRange) +ScTokenRef ScRefTokenHelper::createRefToken(const ScDocument* pDoc, const ScRange& rRange) { ScComplexRefData aRefData; aRefData.InitRange(rRange); - ScTokenRef pRef(new ScDoubleRefToken(aRefData)); + ScTokenRef pRef(new ScDoubleRefToken(pDoc, aRefData)); return pRef; } diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index d305044afe3f..a70c68842273 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -350,7 +350,7 @@ bool ScRawToken::IsValidReference(const ScDocument* pDoc) const return false; } -FormulaToken* ScRawToken::CreateToken() const +FormulaToken* ScRawToken::CreateToken(const ScDocument* pDoc) const { #define IF_NOT_OPCODE_ERROR(o,c) SAL_WARN_IF((eOp!=o), "sc.core", #c "::ctor: OpCode " << static_cast<int>(eOp) << " lost, converted to " #o "; maybe inherit from FormulaToken instead!") switch ( GetType() ) @@ -370,14 +370,14 @@ FormulaToken* ScRawToken::CreateToken() const } case svSingleRef : if (eOp == ocPush) - return new ScSingleRefToken( aRef.Ref1 ); + return new ScSingleRefToken(pDoc, aRef.Ref1 ); else - return new ScSingleRefToken( aRef.Ref1, eOp ); + return new ScSingleRefToken(pDoc, aRef.Ref1, eOp ); case svDoubleRef : if (eOp == ocPush) - return new ScDoubleRefToken( aRef ); + return new ScDoubleRefToken(pDoc, aRef ); else - return new ScDoubleRefToken( aRef, eOp ); + return new ScDoubleRefToken(pDoc, aRef, eOp ); case svMatrix : IF_NOT_OPCODE_ERROR( ocPush, ScMatrixToken); return new ScMatrixToken( pMat ); @@ -499,7 +499,7 @@ void DumpToken(formula::FormulaToken const & rToken) } #endif -FormulaTokenRef extendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2, +FormulaTokenRef extendRangeReference( const ScDocument* pDoc, FormulaToken & rTok1, FormulaToken & rTok2, const ScAddress & rPos, bool bReuseDoubleRef ) { @@ -545,11 +545,11 @@ FormulaTokenRef extendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2 ScComplexRefData aRef; aRef.Ref1 = aRef.Ref2 = *rTok1.GetSingleRef(); aRef.Ref2.SetFlag3D( false); - aRef.Extend( rRef2, rPos); + aRef.Extend(rRef2, rPos); if (bExternal) xRes = new ScExternalDoubleRefToken( rTok1.GetIndex(), rTok1.GetString(), aRef); else - xRes = new ScDoubleRefToken( aRef); + xRes = new ScDoubleRefToken(pDoc, aRef); } else { @@ -575,7 +575,7 @@ FormulaTokenRef extendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2 return nullptr; if (bExternal) return nullptr; // external reference list not possible - xRes = new ScDoubleRefToken( (*pRefList)[0] ); + xRes = new ScDoubleRefToken(pDoc, (*pRefList)[0] ); } if (!xRes) return nullptr; // shouldn't happen... @@ -587,10 +587,10 @@ FormulaTokenRef extendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2 switch (sv[i]) { case svSingleRef: - rRef.Extend( *pt[i]->GetSingleRef(), rPos); + rRef.Extend(*pt[i]->GetSingleRef(), rPos); break; case svDoubleRef: - rRef.Extend( *pt[i]->GetDoubleRef(), rPos); + rRef.Extend(*pt[i]->GetDoubleRef(), rPos); break; case svRefList: { @@ -599,7 +599,7 @@ FormulaTokenRef extendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2 return nullptr; for (const auto& rRefData : *p) { - rRef.Extend( rRefData, rPos); + rRef.Extend(rRefData, rPos); } } break; @@ -607,13 +607,13 @@ FormulaTokenRef extendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2 if (rRef.Ref1.IsFlag3D() || rRef.Ref2.IsFlag3D()) return nullptr; // no other sheets with external refs else - rRef.Extend( *pt[i]->GetSingleRef(), rPos); + rRef.Extend(*pt[i]->GetSingleRef(), rPos); break; case svExternalDoubleRef: if (rRef.Ref1.IsFlag3D() || rRef.Ref2.IsFlag3D()) return nullptr; // no other sheets with external refs else - rRef.Extend( *pt[i]->GetDoubleRef(), rPos); + rRef.Extend(*pt[i]->GetDoubleRef(), rPos); break; default: ; // nothing, prevent compiler warning @@ -1678,7 +1678,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r ) } } -bool ScTokenArray::ImplGetReference( ScRange& rRange, const ScAddress& rPos, bool bValidOnly ) const +bool ScTokenArray::ImplGetReference( const ScDocument* pDoc, ScRange& rRange, const ScAddress& rPos, bool bValidOnly ) const { bool bIs = false; if ( pCode && nLen == 1 ) @@ -1690,7 +1690,7 @@ bool ScTokenArray::ImplGetReference( ScRange& rRange, const ScAddress& rPos, boo { const ScSingleRefData& rRef = *static_cast<const ScSingleRefToken*>(pToken)->GetSingleRef(); rRange.aStart = rRange.aEnd = rRef.toAbs(rPos); - bIs = !bValidOnly || ValidAddress(rRange.aStart); + bIs = !bValidOnly || pDoc->ValidAddress(rRange.aStart); } else if ( pToken->GetType() == svDoubleRef ) { @@ -1699,7 +1699,7 @@ bool ScTokenArray::ImplGetReference( ScRange& rRange, const ScAddress& rPos, boo const ScSingleRefData& rRef2 = rCompl.Ref2; rRange.aStart = rRef1.toAbs(rPos); rRange.aEnd = rRef2.toAbs(rPos); - bIs = !bValidOnly || ValidRange(rRange); + bIs = !bValidOnly || pDoc->ValidRange(rRange); } } } @@ -1852,16 +1852,17 @@ bool ScTokenArray::IsInvariant() const bool ScTokenArray::IsReference( ScRange& rRange, const ScAddress& rPos ) const { - return ImplGetReference(rRange, rPos, false); + return ImplGetReference(mpDoc, rRange, rPos, false); } bool ScTokenArray::IsValidReference( ScRange& rRange, const ScAddress& rPos ) const { - return ImplGetReference(rRange, rPos, true); + return ImplGetReference(mpDoc, rRange, rPos, true); } -ScTokenArray::ScTokenArray() : +ScTokenArray::ScTokenArray(const ScDocument* pDoc) : FormulaTokenArray(), + mpDoc(pDoc), mnHashValue(0) { ResetVectorState(); @@ -1908,7 +1909,7 @@ void ScTokenArray::Clear() std::unique_ptr<ScTokenArray> ScTokenArray::Clone() const { - std::unique_ptr<ScTokenArray> p(new ScTokenArray()); + std::unique_ptr<ScTokenArray> p(new ScTokenArray(mpDoc)); p->nLen = nLen; p->nRPN = nRPN; p->nMode = nMode; @@ -1966,7 +1967,7 @@ std::unique_ptr<ScTokenArray> ScTokenArray::Clone() const FormulaToken* ScTokenArray::AddRawToken( const ScRawToken& r ) { - return Add( r.CreateToken() ); + return Add( r.CreateToken(mpDoc) ); } // Utility function to ensure that there is strict alternation of values and @@ -2164,7 +2165,7 @@ void ScTokenArray::MergeRangeReference( const ScAddress & rPos ) (((p2 = PeekPrev(nIdx)) != nullptr) && p2->GetOpCode() == ocRange) && ((p1 = PeekPrev(nIdx)) != nullptr)) { - FormulaTokenRef p = extendRangeReference( *p1, *p3, rPos, true); + FormulaTokenRef p = extendRangeReference( mpDoc, *p1, *p3, rPos, true); if (p) { p->IncRef(); @@ -2186,17 +2187,17 @@ FormulaToken* ScTokenArray::AddOpCode( OpCode e ) FormulaToken* ScTokenArray::AddSingleReference( const ScSingleRefData& rRef ) { - return Add( new ScSingleRefToken( rRef ) ); + return Add( new ScSingleRefToken(mpDoc, rRef ) ); } FormulaToken* ScTokenArray::AddMatrixSingleReference( const ScSingleRefData& rRef ) { - return Add( new ScSingleRefToken( rRef, ocMatRef ) ); + return Add( new ScSingleRefToken(mpDoc, rRef, ocMatRef ) ); } FormulaToken* ScTokenArray::AddDoubleReference( const ScComplexRefData& rRef ) { - return Add( new ScDoubleRefToken( rRef ) ); + return Add( new ScDoubleRefToken(mpDoc, rRef ) ); } FormulaToken* ScTokenArray::AddMatrix( const ScMatrixRef& p ) @@ -2233,7 +2234,7 @@ FormulaToken* ScTokenArray::AddExternalDoubleReference( sal_uInt16 nFileId, cons FormulaToken* ScTokenArray::AddColRowName( const ScSingleRefData& rRef ) { - return Add( new ScSingleRefToken( rRef, ocColRowName ) ); + return Add( new ScSingleRefToken(mpDoc, rRef, ocColRowName ) ); } void ScTokenArray::AssignXMLString( const OUString &rText, const OUString &rFormulaNmsp ) @@ -2249,7 +2250,7 @@ void ScTokenArray::AssignXMLString( const OUString &rText, const OUString &rForm Assign( nTokens, aTokens ); } -bool ScTokenArray::GetAdjacentExtendOfOuterFuncRefs( const ScDocument* pDoc, SCCOLROW& nExtend, +bool ScTokenArray::GetAdjacentExtendOfOuterFuncRefs( SCCOLROW& nExtend, const ScAddress& rPos, ScDirection eDir ) { SCCOL nCol = 0; @@ -2257,13 +2258,13 @@ bool ScTokenArray::GetAdjacentExtendOfOuterFuncRefs( const ScDocument* pDoc, SCC switch ( eDir ) { case DIR_BOTTOM : - if ( rPos.Row() < pDoc->MaxRow() ) + if ( rPos.Row() < mpDoc->MaxRow() ) nRow = (nExtend = rPos.Row()) + 1; else return false; break; case DIR_RIGHT : - if ( rPos.Col() < pDoc->MaxCol() ) + if ( rPos.Col() < mpDoc->MaxCol() ) nCol = static_cast<SCCOL>(nExtend = rPos.Col()) + 1; else return false; @@ -4512,6 +4513,7 @@ void ScTokenArray::ClearTabDeleted( const ScAddress& rPos, SCTAB nStartTab, SCTA namespace { void checkBounds( + const ScDocument* pDoc, const ScAddress& rPos, SCROW nGroupLen, const ScRange& rCheckRange, const ScSingleRefData& rRef, std::vector<SCROW>& rBounds, const ScRange* pDeletedRange ) { @@ -4547,7 +4549,7 @@ void checkBounds( SCROW nOffset = pDeletedRange->aStart.Row() - aAbs.aStart.Row(); SCROW nRow = rPos.Row() + nOffset; // Unlike for rCheckRange, for pDeletedRange nRow can be anywhere>=0. - if (ValidRow(nRow)) + if (pDoc->ValidRow(nRow)) rBounds.push_back(nRow); } @@ -4572,7 +4574,7 @@ void checkBounds( SCROW nOffset = pDeletedRange->aEnd.Row() + 1 - aAbs.aStart.Row(); SCROW nRow = rPos.Row() + nOffset; // Unlike for rCheckRange, for pDeletedRange nRow can be ~anywhere. - if (ValidRow(nRow)) + if (pDoc->ValidRow(nRow)) rBounds.push_back(nRow); } } @@ -4610,7 +4612,7 @@ void checkBounds( pDeletedRange = &aDeletedRange; } - checkBounds(rPos, nGroupLen, aCheckRange, rRef, rBounds, pDeletedRange); + checkBounds(&rCxt.mrDoc, rPos, nGroupLen, aCheckRange, rRef, rBounds, pDeletedRange); } } @@ -4669,14 +4671,14 @@ void ScTokenArray::CheckRelativeReferenceBounds( case svSingleRef: { const ScSingleRefData& rRef = *p->GetSingleRef(); - checkBounds(rPos, nGroupLen, rRange, rRef, rBounds, nullptr); + checkBounds(mpDoc, rPos, nGroupLen, rRange, rRef, rBounds, nullptr); } break; case svDoubleRef: { const ScComplexRefData& rRef = *p->GetDoubleRef(); - checkBounds(rPos, nGroupLen, rRange, rRef.Ref1, rBounds, nullptr); - checkBounds(rPos, nGroupLen, rRange, rRef.Ref2, rBounds, nullptr); + checkBounds(mpDoc, rPos, nGroupLen, rRange, rRef.Ref1, rBounds, nullptr); + checkBounds(mpDoc, rPos, nGroupLen, rRange, rRef.Ref2, rBounds, nullptr); } break; default: @@ -5090,7 +5092,7 @@ void appendTokenByType( const ScDocument* pDoc, sc::TokenStringContext& rCxt, OU } -OUString ScTokenArray::CreateString( const ScDocument* pDoc, sc::TokenStringContext& rCxt, const ScAddress& rPos ) const +OUString ScTokenArray::CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const { if (!nLen) return OUString(); @@ -5113,7 +5115,7 @@ OUString ScTokenArray::CreateString( const ScDocument* pDoc, sc::TokenStringCont if (eOp < rCxt.mxOpCodeMap->getSymbolCount()) aBuf.append(rCxt.mxOpCodeMap->getSymbol(eOp)); - appendTokenByType(pDoc, rCxt, aBuf, *pToken, rPos, IsFromRangeName()); + appendTokenByType(mpDoc, rCxt, aBuf, *pToken, rPos, IsFromRangeName()); } return aBuf.makeStringAndClear(); diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx index a8397ee17607..6dbb629fc7c7 100644 --- a/sc/source/filter/excel/excform.cxx +++ b/sc/source/filter/excel/excform.cxx @@ -197,7 +197,7 @@ std::unique_ptr<ScTokenArray> ExcelToSc::GetDummy() { aPool.Store( "Dummy()" ); aPool >> aStack; - return aPool.GetTokenArray( aStack.Get()); + return aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); } // if bAllowArrays is false stream seeks to first byte after <nFormulaLen> @@ -223,7 +223,7 @@ ConvErr ExcelToSc::Convert( std::unique_ptr<ScTokenArray>& pResult, XclImpStream { aPool.Store( "-/-" ); aPool >> aStack; - pResult = aPool.GetTokenArray( aStack.Get()); + pResult = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); return ConvErr::OK; } @@ -860,14 +860,14 @@ ConvErr ExcelToSc::Convert( std::unique_ptr<ScTokenArray>& pResult, XclImpStream { aPool << ocBad; aPool >> aStack; - pResult = aPool.GetTokenArray( aStack.Get()); + pResult = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); eRet = ConvErr::Ni; } else if( aIn.GetRecPos() != nEndPos ) { aPool << ocBad; aPool >> aStack; - pResult = aPool.GetTokenArray( aStack.Get()); + pResult = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); eRet = ConvErr::Count; } else if( bArrayFormula ) @@ -877,7 +877,7 @@ ConvErr ExcelToSc::Convert( std::unique_ptr<ScTokenArray>& pResult, XclImpStream } else { - pResult = aPool.GetTokenArray( aStack.Get()); + pResult = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); eRet = ConvErr::OK; } @@ -1692,7 +1692,7 @@ std::unique_ptr<ScTokenArray> ExcelToSc::GetBoolErr( XclBoolError eType ) aPool >> aStack; - std::unique_ptr<ScTokenArray> pResult = aPool.GetTokenArray( aStack.Get()); + std::unique_ptr<ScTokenArray> pResult = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); if( nError != FormulaError::NONE ) pResult->SetCodeError( nError ); diff --git a/sc/source/filter/excel/excform8.cxx b/sc/source/filter/excel/excform8.cxx index 8c9d0f7191ec..beee318fcd0c 100644 --- a/sc/source/filter/excel/excform8.cxx +++ b/sc/source/filter/excel/excform8.cxx @@ -20,6 +20,7 @@ #include <excform.hxx> #include <document.hxx> +#include <documentimport.hxx> #include <xltracer.hxx> #include <xistream.hxx> #include <xihelper.hxx> @@ -151,7 +152,7 @@ ConvErr ExcelToSc8::Convert( std::unique_ptr<ScTokenArray>& rpTokArray, XclImpSt { aPool.Store( "-/-" ); aPool >> aStack; - rpTokArray = aPool.GetTokenArray( aStack.Get()); + rpTokArray = aPool.GetTokenArray(&GetDocImport().getDoc(), aStack.Get()); return ConvErr::OK; } @@ -914,14 +915,14 @@ ConvErr ExcelToSc8::Convert( std::unique_ptr<ScTokenArray>& rpTokArray, XclImpSt { aPool << ocBad; aPool >> aStack; - rpTokArray = aPool.GetTokenArray( aStack.Get()); + rpTokArray = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); eRet = ConvErr::Ni; } else if( aIn.GetRecPos() != nEndPos ) { aPool << ocBad; aPool >> aStack; - rpTokArray = aPool.GetTokenArray( aStack.Get()); + rpTokArray = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); eRet = ConvErr::Count; } else if( bArrayFormula ) @@ -931,7 +932,7 @@ ConvErr ExcelToSc8::Convert( std::unique_ptr<ScTokenArray>& rpTokArray, XclImpSt } else { - rpTokArray = aPool.GetTokenArray( aStack.Get()); + rpTokArray = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); eRet = ConvErr::OK; } @@ -1298,7 +1299,7 @@ void ExcelToSc8::ConvertExternName( std::unique_ptr<ScTokenArray>& rpArray, XclI { aPool.Store("-/-"); aPool >> aStack; - rpArray = aPool.GetTokenArray( aStack.Get()); + rpArray = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); return; } @@ -1414,17 +1415,17 @@ void ExcelToSc8::ConvertExternName( std::unique_ptr<ScTokenArray>& rpArray, XclI { aPool << ocBad; aPool >> aStack; - rpArray = aPool.GetTokenArray( aStack.Get()); + rpArray = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); } else if( rStrm.GetRecPos() != nEndPos ) { aPool << ocBad; aPool >> aStack; - rpArray = aPool.GetTokenArray( aStack.Get()); + rpArray = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); } else { - rpArray = aPool.GetTokenArray( aStack.Get()); + rpArray = aPool.GetTokenArray( &GetDocImport().getDoc(), aStack.Get()); } rStrm.Seek(nEndPos); diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx index eab70437bcef..f42e9f96b770 100644 --- a/sc/source/filter/excel/xechart.cxx +++ b/sc/source/filter/excel/xechart.cxx @@ -896,7 +896,7 @@ sal_uInt16 XclExpChSourceLink::ConvertDataSequence( Reference< XDataSequence > c if( !pArray ) return nDefCount; - ScTokenArray aArray; + ScTokenArray aArray(&GetRoot().GetDoc()); sal_uInt32 nValueCount = 0; FormulaTokenArrayPlainIterator aIter(*pArray); for( const FormulaToken* pToken = aIter.First(); pToken; pToken = aIter.Next() ) diff --git a/sc/source/filter/excel/xeformula.cxx b/sc/source/filter/excel/xeformula.cxx index 314794dcd426..2f24b1b2c723 100644 --- a/sc/source/filter/excel/xeformula.cxx +++ b/sc/source/filter/excel/xeformula.cxx @@ -2614,14 +2614,14 @@ XclTokenArrayRef XclExpFormulaCompiler::CreateFormula( XclTokenArrayRef XclExpFormulaCompiler::CreateFormula( XclFormulaType eType, const ScAddress& rScPos ) { - ScTokenArray aScTokArr; + ScTokenArray aScTokArr(&GetRoot().GetDoc()); lclPutCellToTokenArray( aScTokArr, rScPos, GetCurrScTab(), mxImpl->Is3DRefOnly( eType ) ); return mxImpl->CreateFormula( eType, aScTokArr ); } XclTokenArrayRef XclExpFormulaCompiler::CreateFormula( XclFormulaType eType, const ScRange& rScRange ) { - ScTokenArray aScTokArr; + ScTokenArray aScTokArr(&GetRoot().GetDoc()); lclPutRangeToTokenArray( aScTokArr, rScRange, GetCurrScTab(), mxImpl->Is3DRefOnly( eType ) ); return mxImpl->CreateFormula( eType, aScTokArr ); } @@ -2632,7 +2632,7 @@ XclTokenArrayRef XclExpFormulaCompiler::CreateFormula( XclFormulaType eType, con if( nCount == 0 ) return XclTokenArrayRef(); - ScTokenArray aScTokArr; + ScTokenArray aScTokArr(&GetRoot().GetDoc()); SCTAB nCurrScTab = GetCurrScTab(); bool b3DRefOnly = mxImpl->Is3DRefOnly( eType ); for( size_t nIdx = 0; nIdx < nCount; ++nIdx ) diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx index 4c4354233f51..4f78956a9d7f 100644 --- a/sc/source/filter/excel/xichart.cxx +++ b/sc/source/filter/excel/xichart.cxx @@ -904,7 +904,7 @@ void XclImpChSourceLink::FillSourceLink( ::std::vector< ScTokenRef >& rTokens ) ScTokenRef pToken(p->Clone()); if (ScRefTokenHelper::isRef(pToken)) // This is a reference token. Store it. - ScRefTokenHelper::join(rTokens, pToken, ScAddress()); + ScRefTokenHelper::join(&GetRoot().GetDoc(), rTokens, pToken, ScAddress()); } } diff --git a/sc/source/filter/html/htmlimp.cxx b/sc/source/filter/html/htmlimp.cxx index 00412301018e..7496530124cf 100644 --- a/sc/source/filter/html/htmlimp.cxx +++ b/sc/source/filter/html/htmlimp.cxx @@ -104,7 +104,7 @@ void ScHTMLImport::InsertRangeName( ScDocument* pDoc, const OUString& rName, con aRefData.InitRange( rRange ); aRefData.Ref1.SetFlag3D( true ); aRefData.Ref2.SetFlag3D( aRefData.Ref2.Tab() != aRefData.Ref1.Tab() ); - ScTokenArray aTokArray; + ScTokenArray aTokArray(pDoc); aTokArray.AddDoubleReference( aRefData ); ScRangeData* pRangeData = new ScRangeData( pDoc, rName, aTokArray ); pDoc->GetRangeName()->insert( pRangeData ); diff --git a/sc/source/filter/inc/lotrange.hxx b/sc/source/filter/inc/lotrange.hxx index ee0253dbffac..5dc145bb0429 100644 --- a/sc/source/filter/inc/lotrange.hxx +++ b/sc/source/filter/inc/lotrange.hxx @@ -97,7 +97,7 @@ public: inline LR_ID GetIndex( SCCOL nCol, SCROW nRow ); inline LR_ID GetIndex( SCCOL nColS, SCROW nRowS, SCCOL nColE, SCROW nRowE ); LR_ID GetIndex( const LotusRange& ); - void Append( std::unique_ptr<LotusRange> pLR ); + void Append( const ScDocument* pDoc, std::unique_ptr<LotusRange> pLR ); }; inline LR_ID LotusRangeList::GetIndex( SCCOL nCol, SCROW nRow ) diff --git a/sc/source/filter/inc/namebuff.hxx b/sc/source/filter/inc/namebuff.hxx index fea49820580f..2bf50c652946 100644 --- a/sc/source/filter/inc/namebuff.hxx +++ b/sc/source/filter/inc/namebuff.hxx @@ -97,7 +97,7 @@ private: std::vector<Entry> maEntries; public: - RangeNameBufferWK3(); + RangeNameBufferWK3(const ScDocument* pDoc); ~RangeNameBufferWK3(); void Add( const OUString& rName, const ScComplexRefData& rCRD ); inline void Add( const OUString& rName, const ScRange& aScRange ); diff --git a/sc/source/filter/inc/qproform.hxx b/sc/source/filter/inc/qproform.hxx index fa1f2c2075a3..ee0fe9cce378 100644 --- a/sc/source/filter/inc/qproform.hxx +++ b/sc/source/filter/inc/qproform.hxx @@ -58,7 +58,7 @@ private: public: static const size_t nBufSize = 256; QProToSc( SvStream &aStr, svl::SharedStringPool& rSPool, const ScAddress& rRefPos ); - ConvErr Convert( std::unique_ptr<ScTokenArray>& pArray ); + ConvErr Convert( const ScDocument* pDoc, std::unique_ptr<ScTokenArray>& pArray ); void DoFunc( DefTokenId eOc, sal_uInt16 nArgs, const sal_Char* pExtString ); void ReadSRD( ScSingleRefData& rR, sal_Int8 nPage, sal_Int8 nCol, sal_uInt16 rRel ); void IncToken( TokenId &aParam ); diff --git a/sc/source/filter/inc/tokstack.hxx b/sc/source/filter/inc/tokstack.hxx index 82a6a9552219..26283660b04d 100644 --- a/sc/source/filter/inc/tokstack.hxx +++ b/sc/source/filter/inc/tokstack.hxx @@ -251,7 +251,7 @@ public: TokenId StoreExtRef( sal_uInt16 nFileId, const OUString& rTabName, const ScSingleRefData& rRef ); TokenId StoreExtRef( sal_uInt16 nFileId, const OUString& rTabName, const ScComplexRefData& rRef ); - std::unique_ptr<ScTokenArray> GetTokenArray( const TokenId& rId ); + std::unique_ptr<ScTokenArray> GetTokenArray( const ScDocument* pDoc, const TokenId& rId ); void Reset(); bool IsSingleOp( const TokenId& rId, const DefTokenId eId ) const; const OUString* GetExternal( const TokenId& rId ) const; @@ -408,9 +408,9 @@ inline TokenId TokenPool::Store() return nId; } -inline std::unique_ptr<ScTokenArray> TokenPool::GetTokenArray( const TokenId& rId ) +inline std::unique_ptr<ScTokenArray> TokenPool::GetTokenArray( const ScDocument *pDoc, const TokenId& rId ) { - std::unique_ptr<ScTokenArray> pScToken( new ScTokenArray ); + std::unique_ptr<ScTokenArray> pScToken( new ScTokenArray(pDoc) ); if( rId ) {//...only if rId > 0! diff --git a/sc/source/filter/lotus/lotform.cxx b/sc/source/filter/lotus/lotform.cxx index a9e38c18b507..f0088500f5eb 100644 --- a/sc/source/filter/lotus/lotform.cxx +++ b/sc/source/filter/lotus/lotform.cxx @@ -435,7 +435,7 @@ void LotusToSc::Convert( std::unique_ptr<ScTokenArray>& rpErg, sal_Int32& rRest if( nBytesLeft < 0 ) { - rpErg = aPool.GetTokenArray( aStack.Get()); + rpErg = aPool.GetTokenArray(m_rContext.pDoc, aStack.Get()); return; } @@ -654,7 +654,7 @@ void LotusToSc::Convert( std::unique_ptr<ScTokenArray>& rpErg, sal_Int32& rRest } } - rpErg = aPool.GetTokenArray( aStack.Get()); + rpErg = aPool.GetTokenArray(m_rContext.pDoc, aStack.Get()); SAL_WARN_IF( nBytesLeft < 0, "sc.filter", "*LotusToSc::Convert(): processed too much!"); SAL_WARN_IF( nBytesLeft > 0, "sc.filter", "*LotusToSc::Convert(): what happens with the rest?" ); diff --git a/sc/source/filter/lotus/lotus.cxx b/sc/source/filter/lotus/lotus.cxx index a2f0482a31b1..b900c22a58b4 100644 --- a/sc/source/filter/lotus/lotus.cxx +++ b/sc/source/filter/lotus/lotus.cxx @@ -94,7 +94,7 @@ LotusContext::LotusContext(ScDocument* pDocP, rtl_TextEncoding eQ) , maRangeNames() , eFirstType( Lotus123Typ::X) , eActType( Lotus123Typ::X) - , pRngNmBffWK3( new RangeNameBufferWK3() ) + , pRngNmBffWK3( new RangeNameBufferWK3(pDocP) ) , maAttrTable( *this ) { } diff --git a/sc/source/filter/lotus/op.cxx b/sc/source/filter/lotus/op.cxx index 01f1a3616d34..6d99a18dea98 100644 --- a/sc/source/filter/lotus/op.cxx +++ b/sc/source/filter/lotus/op.cxx @@ -222,7 +222,7 @@ void OP_NamedRange(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/) aTmp = ScfTools::ConvertToScDefinedName( aTmp ); - rContext.maRangeNames.Append( std::move(pRange) ); + rContext.maRangeNames.Append( rContext.pDoc, std::move(pRange) ); } } @@ -260,7 +260,7 @@ void OP_SymphNamedRange(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/) OUString aTmp( cBuf, strlen(cBuf), rContext.eCharset ); aTmp = ScfTools::ConvertToScDefinedName( aTmp ); - rContext.maRangeNames.Append( std::move(pRange) ); + rContext.maRangeNames.Append( rContext.pDoc, std::move(pRange) ); } } diff --git a/sc/source/filter/lotus/tool.cxx b/sc/source/filter/lotus/tool.cxx index 5eeb6af4642f..908e7bacfabb 100644 --- a/sc/source/filter/lotus/tool.cxx +++ b/sc/source/filter/lotus/tool.cxx @@ -398,13 +398,13 @@ LR_ID LotusRangeList::GetIndex( const LotusRange &rRef ) return ID_FAIL; } -void LotusRangeList::Append( std::unique_ptr<LotusRange> pLR ) +void LotusRangeList::Append( const ScDocument* pDoc, std::unique_ptr<LotusRange> pLR ) { assert( pLR ); auto pLRTmp = pLR.get(); maRanges.push_back(std::move(pLR)); - ScTokenArray aTokArray; + ScTokenArray aTokArray(pDoc); ScSingleRefData* pSingRef = &aComplRef.Ref1; @@ -426,8 +426,8 @@ void LotusRangeList::Append( std::unique_ptr<LotusRange> pLR ) nIdCnt++; } -RangeNameBufferWK3::RangeNameBufferWK3() - : pScTokenArray( new ScTokenArray ) +RangeNameBufferWK3::RangeNameBufferWK3(const ScDocument* pDoc) + : pScTokenArray( new ScTokenArray(pDoc) ) { nIntCount = 1; } diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx index 748cdb91a342..aa10002ea957 100644 --- a/sc/source/filter/oox/condformatbuffer.cxx +++ b/sc/source/filter/oox/condformatbuffer.cxx @@ -854,7 +854,7 @@ void CondFormatRule::finalizeImport() eOperator == ScConditionMode::ContainsText || eOperator == ScConditionMode::NotContainsText ) { ScDocument& rDoc = getScDocument(); - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(&rDoc); svl::SharedStringPool& rSPool = rDoc.GetSharedStringPool(); aTokenArray.AddString(rSPool.intern(maModel.maText)); OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId ); @@ -867,12 +867,12 @@ void CondFormatRule::finalizeImport() std::unique_ptr<ScTokenArray> pTokenArray2; if( maModel.maFormulas.size() >= 2) { - pTokenArray2.reset(new ScTokenArray()); + pTokenArray2.reset(new ScTokenArray(&rDoc)); ScTokenConversion::ConvertToTokenArray(rDoc, *pTokenArray2, maModel.maFormulas[1]); rDoc.CheckLinkFormulaNeedingCheck(*pTokenArray2); } - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(&rDoc); OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId ); ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, maModel.maFormulas[ 0 ] ); rDoc.CheckLinkFormulaNeedingCheck( aTokenArray); @@ -884,7 +884,7 @@ void CondFormatRule::finalizeImport() eOperator == ScConditionMode::TopPercent || eOperator == ScConditionMode::BottomPercent ) { ScDocument& rDoc = getScDocument(); - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(&rDoc); aTokenArray.AddDouble( maModel.mnRank ); OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId ); ScCondFormatEntry* pNewEntry = new ScCondFormatEntry( eOperator, &aTokenArray, nullptr, &rDoc, aPos, aStyleName ); @@ -895,7 +895,7 @@ void CondFormatRule::finalizeImport() { ScDocument& rDoc = getScDocument(); // actually that is still unsupported - ScTokenArray aTokenArrayDev; + ScTokenArray aTokenArrayDev(&rDoc); aTokenArrayDev.AddDouble( maModel.mnStdDev ); OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId ); ScCondFormatEntry* pNewEntry = new ScCondFormatEntry( eOperator, &aTokenArrayDev, nullptr, &rDoc, aPos, aStyleName ); diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx index e8f9f5c6a2a6..3f8c8db4169a 100644 --- a/sc/source/filter/oox/formulabuffer.cxx +++ b/sc/source/filter/oox/formulabuffer.cxx @@ -54,7 +54,7 @@ public: }; explicit CachedTokenArray( ScDocument& rDoc ) : - maCxt(&rDoc, formula::FormulaGrammar::GRAM_OOXML), mpDoc(&rDoc) {} + maCxt(&rDoc, formula::FormulaGrammar::GRAM_OOXML) {} Item* get( const ScAddress& rPos, const OUString& rFormula ) { @@ -65,7 +65,7 @@ public: Item& rCached = *it->second; const ScTokenArray& rCode = *rCached.mpCell->GetCode(); - OUString aPredicted = rCode.CreateString(mpDoc, maCxt, rPos); + OUString aPredicted = rCode.CreateString(maCxt, rPos); if (rFormula == aPredicted) return &rCached; @@ -96,7 +96,6 @@ private: typedef std::unordered_map<SCCOL, std::unique_ptr<Item>> ColCacheType; ColCacheType maCache; sc::TokenStringContext maCxt; - const ScDocument* mpDoc; }; void applySharedFormulas( diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx index dd74d30523bc..89269da46260 100644 --- a/sc/source/filter/oox/workbookhelper.cxx +++ b/sc/source/filter/oox/workbookhelper.cxx @@ -360,7 +360,7 @@ ScRangeData* lcl_addNewByNameAndTokens( ScDocument& rDoc, ScRangeName* pNames, c if ( nUnoType & NamedRangeFlag::PRINT_AREA ) nNewType |= ScRangeData::Type::PrintArea; if ( nUnoType & NamedRangeFlag::COLUMN_HEADER ) nNewType |= ScRangeData::Type::ColHeader; if ( nUnoType & NamedRangeFlag::ROW_HEADER ) nNewType |= ScRangeData::Type::RowHeader; - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(&rDoc); (void)ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, rTokens ); ScRangeData* pNew = new ScRangeData( &rDoc, rName, aTokenArray, ScAddress(), nNewType ); pNew->GuessPosition(); diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx index 3fb3693b7e6a..7542e545b40f 100644 --- a/sc/source/filter/oox/worksheethelper.cxx +++ b/sc/source/filter/oox/worksheethelper.cxx @@ -1544,7 +1544,7 @@ void WorksheetHelper::putRichString( const ScAddress& rAddress, const RichString void WorksheetHelper::putFormulaTokens( const ScAddress& rAddress, const ApiTokenSequence& rTokens ) { ScDocumentImport& rDoc = getDocImport(); - std::unique_ptr<ScTokenArray> pTokenArray(new ScTokenArray); + std::unique_ptr<ScTokenArray> pTokenArray(new ScTokenArray(&rDoc.getDoc())); ScTokenConversion::ConvertToTokenArray(rDoc.getDoc(), *pTokenArray, rTokens); rDoc.setFormulaCell(rAddress, std::move(pTokenArray)); } diff --git a/sc/source/filter/qpro/qpro.cxx b/sc/source/filter/qpro/qpro.cxx index b2162cb3f26f..09ffa346a57b 100644 --- a/sc/source/filter/qpro/qpro.cxx +++ b/sc/source/filter/qpro/qpro.cxx @@ -109,7 +109,7 @@ ErrCode ScQProReader::readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pSty std::unique_ptr<ScTokenArray> pArray; QProToSc aConv(*mpStream, pDoc->GetSharedStringPool(), aAddr); - if (ConvErr::OK != aConv.Convert( pArray )) + if (ConvErr::OK != aConv.Convert( pDoc, pArray )) eRet = SCERR_IMPORT_FORMAT; else { diff --git a/sc/source/filter/qpro/qproform.cxx b/sc/source/filter/qpro/qproform.cxx index 175f098463eb..c56599d6c963 100644 --- a/sc/source/filter/qpro/qproform.cxx +++ b/sc/source/filter/qpro/qproform.cxx @@ -188,7 +188,7 @@ do { \ break; /* switch */ \ } -ConvErr QProToSc::Convert( std::unique_ptr<ScTokenArray>& pArray ) +ConvErr QProToSc::Convert( const ScDocument* pDoc, std::unique_ptr<ScTokenArray>& pArray ) { sal_uInt8 nFmla[ nBufSize ]; sal_uInt8 nArgArray[ nBufSize ] = {0}; @@ -391,7 +391,7 @@ ConvErr QProToSc::Convert( std::unique_ptr<ScTokenArray>& pArray ) } i++; } - pArray = aPool.GetTokenArray( aStack.Get()); + pArray = aPool.GetTokenArray(pDoc, aStack.Get()); return eRet; } diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index af23b64587f6..853578ea9ac5 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -1357,7 +1357,7 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos ) if ( !aText.isEmpty() ) { // temporary formula string as string tokens - std::unique_ptr<ScTokenArray> pCode(new ScTokenArray()); + std::unique_ptr<ScTokenArray> pCode(new ScTokenArray(pDoc)); // Check the special case of a single error constant without leading // '=' and create an error formula cell without tokens. diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx index 9d0e55bfbbe4..0402cc89a481 100644 --- a/sc/source/filter/xml/xmlsubti.cxx +++ b/sc/source/filter/xml/xmlsubti.cxx @@ -270,7 +270,7 @@ void ScMyTables::AddMatrixRange( maMatrixRangeList.push_back(aScRange); ScDocumentImport& rDoc = rImport.GetDoc(); - ScTokenArray aCode; + ScTokenArray aCode(&rDoc.getDoc()); aCode.AssignXMLString( rFormula, ((eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) ? rFormulaNmsp : OUString())); rDoc.setMatrixCells(aScRange, aCode, eGrammar); diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 330b5b45e481..880d33472e95 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -4319,7 +4319,7 @@ bool ScDocFunc::EnterMatrix( const ScRange& rRange, const ScMarkData* pTabMark, } else if ( rDoc.IsImportingXML() ) { - ScTokenArray aCode; + ScTokenArray aCode(&rDoc); aCode.AssignXMLString( rString, ((eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) ? rFormulaNmsp : OUString())); rDoc.InsertMatrixFormula( nStartCol, nStartRow, nEndCol, nEndRow, diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx index 96d159a42c1a..577823b3b0a2 100644 --- a/sc/source/ui/docshell/externalrefmgr.cxx +++ b/sc/source/ui/docshell/externalrefmgr.cxx @@ -456,7 +456,9 @@ ScExternalRefCache::CellFormat::CellFormat() : { } -ScExternalRefCache::ScExternalRefCache() {} +ScExternalRefCache::ScExternalRefCache() + : mpFakeDoc(new ScDocument()) +{} ScExternalRefCache::~ScExternalRefCache() {} @@ -685,7 +687,7 @@ ScExternalRefCache::TokenArrayRef ScExternalRefCache::getCellRangeData( ScMatrixToken aToken(xMat); if (!pArray) - pArray.reset(new ScTokenArray); + pArray.reset(new ScTokenArray(mpFakeDoc)); pArray->AddToken(aToken); bFirstTab = false; @@ -1534,7 +1536,7 @@ static std::unique_ptr<ScTokenArray> convertToTokenArray( std::unique_ptr<ScRange> pUsedRange; - unique_ptr<ScTokenArray> pArray(new ScTokenArray); + unique_ptr<ScTokenArray> pArray(new ScTokenArray(pSrcDoc)); bool bFirstTab = true; vector<ScExternalRefCache::SingleRangeData>::iterator itrCache = rCacheData.begin(), itrCacheEnd = rCacheData.end(); @@ -1609,14 +1611,14 @@ static std::unique_ptr<ScTokenArray> convertToTokenArray( return pArray; } -static std::unique_ptr<ScTokenArray> lcl_fillEmptyMatrix(const ScRange& rRange) +static std::unique_ptr<ScTokenArray> lcl_fillEmptyMatrix(const ScDocument* pDoc, const ScRange& rRange) { SCSIZE nC = static_cast<SCSIZE>(rRange.aEnd.Col()-rRange.aStart.Col()+1); SCSIZE nR = static_cast<SCSIZE>(rRange.aEnd.Row()-rRange.aStart.Row()+1); ScMatrixRef xMat = new ScMatrix(nC, nR); ScMatrixToken aToken(xMat); - unique_ptr<ScTokenArray> pArray(new ScTokenArray); + unique_ptr<ScTokenArray> pArray(new ScTokenArray(pDoc)); pArray->AddToken(aToken); return pArray; } @@ -1799,7 +1801,7 @@ void putRangeDataIntoCache( else { // Array is empty. Fill it with an empty matrix of the required size. - pArray = lcl_fillEmptyMatrix(rCacheRange); + pArray = lcl_fillEmptyMatrix(rRefCache.getFakeDoc(), rCacheRange); // Make sure to set this range 'cached', to prevent unnecessarily // accessing the src document time and time again. @@ -2002,7 +2004,7 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getDoubleRefTokens( if (!pSrcDoc) { // Source document is not reachable. Throw a reference error. - pArray.reset(new ScTokenArray); + pArray.reset(new ScTokenArray(pSrcDoc)); pArray->AddToken(FormulaErrorToken(FormulaError::NoRef)); return pArray; } @@ -2246,7 +2248,7 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getDoubleRefTokensFromSr if (!pSrcDoc->GetTable(rTabName, nTab1)) { // specified table name doesn't exist in the source document. - pArray.reset(new ScTokenArray); + pArray.reset(new ScTokenArray(pSrcDoc)); pArray->AddToken(FormulaErrorToken(FormulaError::NoRef)); return pArray; } @@ -2294,7 +2296,7 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getRangeNameTokensFromSr // register the source document with the link manager if it's a new // source. - ScExternalRefCache::TokenArrayRef pNew(new ScTokenArray); + ScExternalRefCache::TokenArrayRef pNew(new ScTokenArray(pSrcDoc)); ScTokenArray aCode(*pRangeData->GetCode()); FormulaTokenArrayPlainIterator aIter(aCode); diff --git a/sc/source/ui/docshell/tablink.cxx b/sc/source/ui/docshell/tablink.cxx index 80eb7cca743a..9956c7114a60 100644 --- a/sc/source/ui/docshell/tablink.cxx +++ b/sc/source/ui/docshell/tablink.cxx @@ -317,7 +317,7 @@ bool ScTableLink::Refresh(const OUString& rNewFile, const OUString& rNewFilter, size_t nRanges = aErrorCells.size(); if ( nRanges ) // found any? { - ScTokenArray aTokenArr; + ScTokenArray aTokenArr(&rDoc); aTokenArr.AddOpCode( ocNotAvail ); aTokenArr.AddOpCode( ocOpen ); aTokenArr.AddOpCode( ocClose ); diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx index 877a6a101974..dd9ef3559496 100644 --- a/sc/source/ui/formdlg/formula.cxx +++ b/sc/source/ui/formdlg/formula.cxx @@ -429,7 +429,7 @@ void ScFormulaDlg::SetReference( const ScRange& rRef, ScDocument& rRefDoc ) // We can't use ScRange::Format here because in R1C1 mode we need // to display the reference position relative to the cursor // position. - ScTokenArray aArray; + ScTokenArray aArray(&rRefDoc); ScComplexRefData aRefData; aRefData.InitRangeRel(rRef, m_CursorPos); bool bSingle = aRefData.Ref1 == aRefData.Ref2; @@ -665,7 +665,7 @@ table::CellAddress ScFormulaDlg::getReferencePosition() const ::std::unique_ptr<formula::FormulaTokenArray> ScFormulaDlg::convertToTokenArray(const uno::Sequence< sheet::FormulaToken >& _aTokenList) { - ::std::unique_ptr<formula::FormulaTokenArray> pArray(new ScTokenArray()); + ::std::unique_ptr<formula::FormulaTokenArray> pArray(new ScTokenArray(m_pDoc)); pArray->Fill(_aTokenList, m_pDoc->GetSharedStringPool(), m_pDoc->GetExternalRefManager()); return pArray; } diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index f65b7fcf6032..660ffffc657d 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -1190,7 +1190,7 @@ static bool lcl_PutDataArray( ScDocShell& rDocShell, const ScRange& rRange, uno::Sequence< sheet::FormulaToken > aTokens; if ( rElement >>= aTokens ) { - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(&rDoc); ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, aTokens ); rDoc.SetFormula(aPos, aTokenArray); } @@ -4949,7 +4949,7 @@ void SAL_CALL ScCellRangeObj::setArrayTokens( const uno::Sequence<sheet::Formula } ScDocument& rDoc = pDocSh->GetDocument(); - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(&rDoc); (void)ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, rTokens ); // Actually GRAM_API is a don't-care here because of the token @@ -6348,7 +6348,7 @@ void SAL_CALL ScCellObj::setTokens( const uno::Sequence<sheet::FormulaToken>& rT if ( pDocSh ) { ScDocument& rDoc = pDocSh->GetDocument(); - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(&rDoc); (void)ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, rTokens ); ScFormulaCell* pNewCell = new ScFormulaCell(&rDoc, aCellPos, aTokenArray); diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx index 0f404ba5d780..658ad00c7b91 100644 --- a/sc/source/ui/unoobj/chart2uno.cxx +++ b/sc/source/ui/unoobj/chart2uno.cxx @@ -176,12 +176,12 @@ struct TokenTable return nRet; } - vector<ScTokenRef> getColRanges(SCCOL nCol) const; - vector<ScTokenRef> getRowRanges(SCROW nRow) const; - vector<ScTokenRef> getAllRanges() const; + vector<ScTokenRef> getColRanges(const ScDocument* pDoc, SCCOL nCol) const; + vector<ScTokenRef> getRowRanges(const ScDocument* pDoc, SCROW nRow) const; + vector<ScTokenRef> getAllRanges(const ScDocument* pDoc) const; }; -vector<ScTokenRef> TokenTable::getColRanges(SCCOL nCol) const +vector<ScTokenRef> TokenTable::getColRanges(const ScDocument* pDoc, SCCOL nCol) const { if (nCol >= mnColCount) return vector<ScTokenRef>(); @@ -197,12 +197,12 @@ vector<ScTokenRef> TokenTable::getColRanges(SCCOL nCol) const continue; ScTokenRef pCopy(p->Clone()); - ScRefTokenHelper::join(aTokens, pCopy, ScAddress()); + ScRefTokenHelper::join(pDoc, aTokens, pCopy, ScAddress()); } return aTokens; } -vector<ScTokenRef> TokenTable::getRowRanges(SCROW nRow) const +vector<ScTokenRef> TokenTable::getRowRanges(const ScDocument* pDoc, SCROW nRow) const { if (nRow >= mnRowCount) return vector<ScTokenRef>(); @@ -218,12 +218,12 @@ vector<ScTokenRef> TokenTable::getRowRanges(SCROW nRow) const continue; ScTokenRef p2(p->Clone()); - ScRefTokenHelper::join(aTokens, p2, ScAddress()); + ScRefTokenHelper::join(pDoc, aTokens, p2, ScAddress()); } return aTokens; } -vector<ScTokenRef> TokenTable::getAllRanges() const +vector<ScTokenRef> TokenTable::getAllRanges(const ScDocument* pDoc) const { vector<ScTokenRef> aTokens; sal_uInt32 nStop = mnColCount*mnRowCount; @@ -234,7 +234,7 @@ vector<ScTokenRef> TokenTable::getAllRanges() const continue; ScTokenRef p2(p->Clone()); - ScRefTokenHelper::join(aTokens, p2, ScAddress()); + ScRefTokenHelper::join(pDoc, aTokens, p2, ScAddress()); } return aTokens; } @@ -264,6 +264,7 @@ public: vector<ScTokenRef> getDataRowRanges(SCROW nRow) const; private: + const ScDocument* mpDoc; SCCOL mnDataColCount; SCROW mnDataRowCount; @@ -276,6 +277,7 @@ private: Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount, SCROW nAllRowCount, bool bFillRowHeader, bool bFillColumnHeader, FormulaTokenMapMap& rCols, ScDocument* pDoc) { + mpDoc = pDoc; // if bFillRowHeader is true, at least the first column serves as a row header. // If more than one column is pure text all the first pure text columns are used as header. // Likewise, if bFillColumnHeader is true, at least the first row serves as a column header. @@ -403,33 +405,33 @@ Chart2PositionMap::~Chart2PositionMap() vector<ScTokenRef> Chart2PositionMap::getLeftUpperCornerRanges() const { - return maLeftUpperCorner.getAllRanges(); + return maLeftUpperCorner.getAllRanges(mpDoc); } vector<ScTokenRef> Chart2PositionMap::getAllColHeaderRanges() const { - return maColHeaders.getAllRanges(); + return maColHeaders.getAllRanges(mpDoc); } vector<ScTokenRef> Chart2PositionMap::getAllRowHeaderRanges() const { - return maRowHeaders.getAllRanges(); + return maRowHeaders.getAllRanges(mpDoc); } vector<ScTokenRef> Chart2PositionMap::getColHeaderRanges(SCCOL nCol) const { - return maColHeaders.getColRanges( nCol); + return maColHeaders.getColRanges(mpDoc, nCol); } vector<ScTokenRef> Chart2PositionMap::getRowHeaderRanges(SCROW nRow) const { - return maRowHeaders.getRowRanges( nRow); + return maRowHeaders.getRowRanges(mpDoc, nRow); } vector<ScTokenRef> Chart2PositionMap::getDataColRanges(SCCOL nCol) const { - return maData.getColRanges( nCol); + return maData.getColRanges(mpDoc, nCol); } vector<ScTokenRef> Chart2PositionMap::getDataRowRanges(SCROW nRow) const { - return maData.getRowRanges( nRow); + return maData.getRowRanges(mpDoc, nRow); } /** @@ -760,7 +762,7 @@ void Chart2Positioner::createPositionMap() if (bExternal) rCol[ nInsRow ].reset(new ScExternalSingleRefToken(nFileId, aTabName, aCellData)); else - rCol[ nInsRow ].reset(new ScSingleRefToken(aCellData)); + rCol[ nInsRow ].reset(new ScSingleRefToken(mpDoc, aCellData)); } } } @@ -871,7 +873,7 @@ public: mpRangeStr->append(mcRangeSep); ScTokenRef aStart, aEnd; - bool bValidToken = splitRangeToken(rToken, aStart, aEnd); + bool bValidToken = splitRangeToken(mpDoc, rToken, aStart, aEnd); OSL_ENSURE(bValidToken, "invalid token"); if (!bValidToken) return; @@ -895,7 +897,7 @@ public: } private: - static bool splitRangeToken(const ScTokenRef& pToken, ScTokenRef& rStart, ScTokenRef& rEnd) + static bool splitRangeToken(const ScDocument* pDoc, const ScTokenRef& pToken, ScTokenRef& rStart, ScTokenRef& rEnd) { ScComplexRefData aData; bool bIsRefToken = ScRefTokenHelper::getDoubleRefDataFromToken(aData, pToken); @@ -919,12 +921,12 @@ private: if (bExternal) rStart.reset(new ScExternalSingleRefToken(nFileId, aTabName, aData.Ref1)); else - rStart.reset(new ScSingleRefToken(aData.Ref1)); + rStart.reset(new ScSingleRefToken(pDoc, aData.Ref1)); if (bExternal) rEnd.reset(new ScExternalSingleRefToken(nFileId, aTabName, aData.Ref2)); else - rEnd.reset(new ScSingleRefToken(aData.Ref2)); + rEnd.reset(new ScSingleRefToken(pDoc, aData.Ref2)); return true; } @@ -1049,7 +1051,7 @@ uno::Reference< chart2::data::XLabeledDataSequence > lcl_createLabeledDataSequen * * @return true if the corner was added, false otherwise. */ -bool lcl_addUpperLeftCornerIfMissing(vector<ScTokenRef>& rRefTokens, +bool lcl_addUpperLeftCornerIfMissing(const ScDocument* pDoc, vector<ScTokenRef>& rRefTokens, SCROW nCornerRowCount, SCCOL nCornerColumnCount) { using ::std::max; @@ -1286,12 +1288,12 @@ bool lcl_addUpperLeftCornerIfMissing(vector<ScTokenRef>& rRefTokens, { ScTokenRef pCorner( new ScExternalSingleRefToken(nFileId, aExtTabName, aData)); - ScRefTokenHelper::join(rRefTokens, pCorner, ScAddress()); + ScRefTokenHelper::join(pDoc, rRefTokens, pCorner, ScAddress()); } else { - ScTokenRef pCorner(new ScSingleRefToken(aData)); - ScRefTokenHelper::join(rRefTokens, pCorner, ScAddress()); + ScTokenRef pCorner(new ScSingleRefToken(pDoc, aData)); + ScRefTokenHelper::join(pDoc, rRefTokens, pCorner, ScAddress()); } } else @@ -1306,12 +1308,12 @@ bool lcl_addUpperLeftCornerIfMissing(vector<ScTokenRef>& rRefTokens, { ScTokenRef pCorner( new ScExternalDoubleRefToken(nFileId, aExtTabName, r)); - ScRefTokenHelper::join(rRefTokens, pCorner, ScAddress()); + ScRefTokenHelper::join(pDoc, rRefTokens, pCorner, ScAddress()); } else { - ScTokenRef pCorner(new ScDoubleRefToken(r)); - ScRefTokenHelper::join(rRefTokens, pCorner, ScAddress()); + ScTokenRef pCorner(new ScDoubleRefToken(pDoc, r)); + ScRefTokenHelper::join(pDoc, rRefTokens, pCorner, ScAddress()); } } @@ -1461,7 +1463,7 @@ ScChart2DataProvider::createDataSource( shrinkToDataRange(m_pDocument, aRefTokens); if (bLabel) - lcl_addUpperLeftCornerIfMissing(aRefTokens, 1, 1); //#i90669# + lcl_addUpperLeftCornerIfMissing(m_pDocument, aRefTokens, 1, 1); //#i90669# bool bColHeaders = (bOrientCol ? bLabel : bCategories ); bool bRowHeaders = (bOrientCol ? bCategories : bLabel ); @@ -1776,9 +1778,9 @@ uno::Sequence< beans::PropertyValue > SAL_CALL ScChart2DataProvider::detectArgum aLabel.initRangeAnalyzer(aTokens); for (const auto& rxToken : aTokens) { - ScRefTokenHelper::join(aAllTokens, rxToken, ScAddress()); + ScRefTokenHelper::join(m_pDocument, aAllTokens, rxToken, ScAddress()); if(!bThisIsCategories) - ScRefTokenHelper::join(aAllSeriesLabelTokens, rxToken, ScAddress()); + ScRefTokenHelper::join(m_pDocument, aAllSeriesLabelTokens, rxToken, ScAddress()); } if(bThisIsCategories) bHasCategoriesLabels=true; @@ -1794,9 +1796,9 @@ uno::Sequence< beans::PropertyValue > SAL_CALL ScChart2DataProvider::detectArgum aValues.initRangeAnalyzer(aTokens); for (const auto& rxToken : aTokens) { - ScRefTokenHelper::join(aAllTokens, rxToken, ScAddress()); + ScRefTokenHelper::join(m_pDocument, aAllTokens, rxToken, ScAddress()); if(bThisIsCategories) - ScRefTokenHelper::join(aAllCategoriesValuesTokens, rxToken, ScAddress()); + ScRefTokenHelper::join(m_pDocument, aAllCategoriesValuesTokens, rxToken, ScAddress()); } } //detect row source @@ -1889,7 +1891,7 @@ uno::Sequence< beans::PropertyValue > SAL_CALL ScChart2DataProvider::detectArgum aTop.initRangeAnalyzer(aAllCategoriesValuesTokens); aLeft.initRangeAnalyzer(aAllSeriesLabelTokens); } - lcl_addUpperLeftCornerIfMissing(aAllTokens, aTop.getRowCount(), aLeft.getColumnCount());//e.g. #i91212# + lcl_addUpperLeftCornerIfMissing(m_pDocument, aAllTokens, aTop.getRowCount(), aLeft.getColumnCount());//e.g. #i91212# } // Get range string. @@ -2027,7 +2029,7 @@ sal_Bool SAL_CALL ScChart2DataProvider::createDataSequenceByFormulaTokensPossibl if (!aTokens.hasElements()) return false; - ScTokenArray aCode; + ScTokenArray aCode(m_pDocument); if (!ScTokenConversion::ConvertToTokenArray(*m_pDocument, aCode, aTokens)) return false; @@ -2085,7 +2087,7 @@ ScChart2DataProvider::createDataSequenceByFormulaTokens( if (!aTokens.hasElements()) return xResult; - ScTokenArray aCode; + ScTokenArray aCode(m_pDocument); if (!ScTokenConversion::ConvertToTokenArray(*m_pDocument, aCode, aTokens)) return xResult; @@ -2624,7 +2626,7 @@ void ScChart2DataSequence::UpdateTokensFromRanges(const ScRangeList& rRanges) ScTokenRef pToken; const ScRange & rRange = rRanges[i]; - ScRefTokenHelper::getTokenFromRange(pToken, rRange); + ScRefTokenHelper::getTokenFromRange(m_pDocument, pToken, rRange); sal_uInt32 nOrigPos = (*m_pRangeIndices)[i]; m_aTokens[nOrigPos] = pToken; } diff --git a/sc/source/ui/unoobj/fmtuno.cxx b/sc/source/ui/unoobj/fmtuno.cxx index 2d0dc66b29cd..040de3b19e99 100644 --- a/sc/source/ui/unoobj/fmtuno.cxx +++ b/sc/source/ui/unoobj/fmtuno.cxx @@ -215,14 +215,14 @@ void ScTableConditionalFormat::FillFormat( ScConditionalFormat& rFormat, if ( aData.maTokens1.hasElements() ) { - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(pDoc); if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aData.maTokens1) ) pCoreEntry->SetFormula1(aTokenArray); } if ( aData.maTokens2.hasElements() ) { - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(pDoc); if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aData.maTokens2) ) pCoreEntry->SetFormula2(aTokenArray); } @@ -601,14 +601,14 @@ ScValidationData* ScTableValidationObj::CreateValidationData( ScDocument* pDoc, if ( aTokens1.hasElements() ) { - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(pDoc); if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aTokens1) ) pRet->SetFormula1(aTokenArray); } if ( aTokens2.hasElements() ) { - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(pDoc); if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aTokens2) ) pRet->SetFormula2(aTokenArray); } diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx index b65b34d168e7..1152389b1883 100644 --- a/sc/source/ui/unoobj/funcuno.cxx +++ b/sc/source/ui/unoobj/funcuno.cxx @@ -471,7 +471,7 @@ uno::Any SAL_CALL ScFunctionAccess::callFunction( const OUString& aName, // find function - ScTokenArray aTokenArr; + ScTokenArray aTokenArr(pDoc); if ( !lcl_AddFunctionToken( aTokenArr, aName,aCompiler ) ) { // function not found diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx index 5359cb5eb03b..b3a3e65e57ed 100644 --- a/sc/source/ui/unoobj/nameuno.cxx +++ b/sc/source/ui/unoobj/nameuno.cxx @@ -331,7 +331,7 @@ void SAL_CALL ScNamedRangeObj::setTokens( const uno::Sequence<sheet::FormulaToke SolarMutexGuard aGuard; if( pDocShell ) { - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(&pDocShell->GetDocument()); (void)ScTokenConversion::ConvertToTokenArray( pDocShell->GetDocument(), aTokenArray, rTokens ); // GRAM_API for API compatibility. Modify_Impl( nullptr, &aTokenArray, nullptr, nullptr, nullptr, formula::FormulaGrammar::GRAM_API ); diff --git a/sc/source/ui/unoobj/tokenuno.cxx b/sc/source/ui/unoobj/tokenuno.cxx index d5e8e8b6b6cc..a71e8bb2e351 100644 --- a/sc/source/ui/unoobj/tokenuno.cxx +++ b/sc/source/ui/unoobj/tokenuno.cxx @@ -154,7 +154,7 @@ OUString SAL_CALL ScFormulaParserObj::printFormula( if (mpDocShell) { ScDocument& rDoc = mpDocShell->GetDocument(); - ScTokenArray aCode; + ScTokenArray aCode(&rDoc); (void)ScTokenConversion::ConvertToTokenArray( rDoc, aCode, aTokens ); ScAddress aRefPos( ScAddress::UNINITIALIZED ); ScUnoConversion::FillScAddress( aRefPos, rReferencePos ); diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 6233f5c5aaa0..df19cb0d8117 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -2005,7 +2005,7 @@ ScVbaRange::setFormulaArray(const uno::Any& rFormula) OUString sFormula; rFormula >>= sFormula; uno::Sequence<sheet::FormulaToken> aTokens = xParser->parseFormula( sFormula, aAddress ); - ScTokenArray aTokenArray; + ScTokenArray aTokenArray(&getScDocument()); (void)ScTokenConversion::ConvertToTokenArray( getScDocument(), aTokenArray, aTokens ); getScDocShell()->GetDocFunc().EnterMatrix( getScRangeList()[0], nullptr, &aTokenArray, OUString(), true, true, EMPTY_OUSTRING, formula::FormulaGrammar::GRAM_API ); diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index d530cc81cbcd..483f2e5f2d8c 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -3074,7 +3074,7 @@ void ScCellShell::ExecuteFillSingleEdit() aInit = "="; const ScTokenArray* pCode = aCell.mpFormula->GetCode(); sc::TokenStringContext aCxt(pDoc, pDoc->GetGrammar()); - aInit += pCode->CreateString(pDoc, aCxt, aCurPos); + aInit += pCode->CreateString(aCxt, aCurPos); } else aInit = aCell.getString(pDoc); diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index e31e2f006ceb..198a53495798 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -271,7 +271,7 @@ static ScAutoSum lcl_IsAutoSumData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, default : break; } - if ( pCode->GetAdjacentExtendOfOuterFuncRefs( pDoc, nExtend, + if ( pCode->GetAdjacentExtendOfOuterFuncRefs( nExtend, ScAddress( nCol, nRow, nTab ), eDir ) ) return val; } @@ -787,7 +787,7 @@ OUString ScViewFunc::GetAutoSumFormula( const ScRangeList& rRangeList, bool bSub { ScViewData& rViewData = GetViewData(); ScDocument* pDoc = rViewData.GetDocument(); - std::unique_ptr<ScTokenArray> pArray(new ScTokenArray); + std::unique_ptr<ScTokenArray> pArray(new ScTokenArray(pDoc)); pArray->AddOpCode(bSubTotal ? ocSubTotal : eCode); pArray->AddOpCode(ocOpen); |