summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-09-13 15:06:18 +0100
committerCaolán McNamara <caolanm@redhat.com>2020-09-13 21:17:36 +0200
commit862bd0d7f7a13f41f3489d2b926c3a229253c6b9 (patch)
tree819e3192902dfa46e971e0c103ee7f18c0bfd7b7
parentb4983e9607134bcf803a895a632412526c2cfe41 (diff)
CompileFormulaContext never constructed with a null ScDocument
Change-Id: I0c88a9383e52a7406b466a82cda8f54a0a7722c8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102585 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sc/inc/tokenstringcontext.hxx8
-rw-r--r--sc/qa/unit/subsequent_filters-test.cxx2
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx2
-rw-r--r--sc/source/core/data/documen2.cxx2
-rw-r--r--sc/source/core/data/documen4.cxx4
-rw-r--r--sc/source/core/data/document.cxx8
-rw-r--r--sc/source/core/data/document10.cxx8
-rw-r--r--sc/source/core/data/formulacell.cxx2
-rw-r--r--sc/source/core/tool/compiler.cxx4
-rw-r--r--sc/source/core/tool/rangenam.cxx2
-rw-r--r--sc/source/core/tool/tokenstringcontext.cxx10
-rw-r--r--sc/source/filter/excel/xestream.cxx2
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx2
13 files changed, 28 insertions, 28 deletions
diff --git a/sc/inc/tokenstringcontext.hxx b/sc/inc/tokenstringcontext.hxx
index c33f6daf6b97..a29f26fc2515 100644
--- a/sc/inc/tokenstringcontext.hxx
+++ b/sc/inc/tokenstringcontext.hxx
@@ -48,22 +48,22 @@ struct SC_DLLPUBLIC TokenStringContext
class SC_DLLPUBLIC CompileFormulaContext
{
- ScDocument* mpDoc;
+ ScDocument& mrDoc;
formula::FormulaGrammar::Grammar meGram;
std::vector<OUString> maTabNames;
void updateTabNames();
public:
- CompileFormulaContext( ScDocument* pDoc );
- CompileFormulaContext( ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram );
+ CompileFormulaContext( ScDocument& rDoc );
+ CompileFormulaContext( ScDocument& rDoc, formula::FormulaGrammar::Grammar eGram );
formula::FormulaGrammar::Grammar getGrammar() const { return meGram;}
void setGrammar( formula::FormulaGrammar::Grammar eGram );
const std::vector<OUString>& getTabNames() const { return maTabNames;}
- ScDocument* getDoc() { return mpDoc;}
+ ScDocument& getDoc() { return mrDoc;}
};
}
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index bc8c36a9bf9c..459f72ea95f6 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -3434,7 +3434,7 @@ void ScFiltersTest::testVBAUserFunctionXLSM()
ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0,0,0));
CPPUNIT_ASSERT(pFC);
- sc::CompileFormulaContext aCxt(&rDoc);
+ sc::CompileFormulaContext aCxt(rDoc);
OUString aFormula = pFC->GetFormula(aCxt);
CPPUNIT_ASSERT_EQUAL(OUString("=MYFUNC()"), aFormula);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index 88d1fbae110a..e1dc8b71867e 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -1051,7 +1051,7 @@ void Test::testSharedFormulasDeleteColumns()
CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pSRef->toAbs(*m_pDoc, ScAddress(1,0,0)).Row());
// The formula string should show #REF! in lieu of the column position (only for Calc A1 syntax).
- sc::CompileFormulaContext aCFCxt(m_pDoc, FormulaGrammar::GRAM_ENGLISH);
+ sc::CompileFormulaContext aCFCxt(*m_pDoc, FormulaGrammar::GRAM_ENGLISH);
CPPUNIT_ASSERT_EQUAL(OUString("=#REF!1"), pFC->GetFormula(aCFCxt));
SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager();
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 9d8ed27a82ce..34af43060d15 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -991,7 +991,7 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
// Readjust self-contained absolute references to this sheet
maTabs[nDestPos]->TestTabRefAbs(nSrcPos);
- sc::CompileFormulaContext aFormulaCxt(this);
+ sc::CompileFormulaContext aFormulaCxt(*this);
maTabs[nDestPos]->CompileAll(aFormulaCxt);
}
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 5f0d2fd64cb6..570f90e24cdf 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -555,7 +555,7 @@ void ScDocument::ReplaceStyle(const SvxSearchItem& rSearchItem,
void ScDocument::CompileDBFormula()
{
- sc::CompileFormulaContext aCxt(this);
+ sc::CompileFormulaContext aCxt(*this);
for (auto& rxTab : maTabs)
{
if (rxTab)
@@ -565,7 +565,7 @@ void ScDocument::CompileDBFormula()
void ScDocument::CompileColRowNameFormula()
{
- sc::CompileFormulaContext aCxt(this);
+ sc::CompileFormulaContext aCxt(*this);
for (auto& rxTab : maTabs)
{
if (rxTab)
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index f77f14ce9317..6ccd0dfa9b66 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3959,7 +3959,7 @@ void ScDocument::CalcAll()
void ScDocument::CompileAll()
{
- sc::CompileFormulaContext aCxt(this);
+ sc::CompileFormulaContext aCxt(*this);
for (const auto& a : maTabs)
{
if (a)
@@ -3977,7 +3977,7 @@ void ScDocument::CompileXML()
ScProgress aProgress( GetDocumentShell(), ScResId(
STR_PROGRESS_CALCULATING ), GetXMLImportedFormulaCount(), true );
- sc::CompileFormulaContext aCxt(this);
+ sc::CompileFormulaContext aCxt(*this);
// set AutoNameCache to speed up automatic name lookup
OSL_ENSURE( !pAutoNameCache, "AutoNameCache already set" );
@@ -4013,7 +4013,7 @@ void ScDocument::CompileXML()
bool ScDocument::CompileErrorCells(FormulaError nErrCode)
{
bool bCompiled = false;
- sc::CompileFormulaContext aCxt(this);
+ sc::CompileFormulaContext aCxt(*this);
for (const auto& a : maTabs)
{
if (!a)
@@ -4032,7 +4032,7 @@ void ScDocument::CalcAfterLoad( bool bStartListening )
return; // the calculation is then only performed when inserting into the real document
bCalcingAfterLoad = true;
- sc::CompileFormulaContext aCxt(this);
+ sc::CompileFormulaContext aCxt(*this);
{
for (const auto& a : maTabs)
{
diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx
index d722d89b090c..c0b909b349d0 100644
--- a/sc/source/core/data/document10.cxx
+++ b/sc/source/core/data/document10.cxx
@@ -280,7 +280,7 @@ void ScDocument::PreprocessAllRangeNamesUpdate( const std::map<OUString, std::un
}
sc::EndListeningContext aEndListenCxt(*this);
- sc::CompileFormulaContext aCompileCxt(this);
+ sc::CompileFormulaContext aCompileCxt(*this);
for (const auto& rxTab : maTabs)
{
@@ -292,7 +292,7 @@ void ScDocument::PreprocessAllRangeNamesUpdate( const std::map<OUString, std::un
void ScDocument::PreprocessRangeNameUpdate()
{
sc::EndListeningContext aEndListenCxt(*this);
- sc::CompileFormulaContext aCompileCxt(this);
+ sc::CompileFormulaContext aCompileCxt(*this);
for (const auto& rxTab : maTabs)
{
@@ -304,7 +304,7 @@ void ScDocument::PreprocessRangeNameUpdate()
void ScDocument::PreprocessDBDataUpdate()
{
sc::EndListeningContext aEndListenCxt(*this);
- sc::CompileFormulaContext aCompileCxt(this);
+ sc::CompileFormulaContext aCompileCxt(*this);
for (const auto& rxTab : maTabs)
{
@@ -316,7 +316,7 @@ void ScDocument::PreprocessDBDataUpdate()
void ScDocument::CompileHybridFormula()
{
sc::StartListeningContext aStartListenCxt(*this);
- sc::CompileFormulaContext aCompileCxt(this);
+ sc::CompileFormulaContext aCompileCxt(*this);
for (const auto& rxTab : maTabs)
{
ScTable* p = rxTab.get();
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 2081439e4eb9..81279a1e4936 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -1038,7 +1038,7 @@ OUString ScFormulaCell::GetFormula( sc::CompileFormulaContext& rCxt, const ScInt
OUStringBuffer aBuf;
if (pCode->GetCodeError() != FormulaError::NONE && !pCode->GetLen())
{
- ScTokenArray aCode(rCxt.getDoc());
+ ScTokenArray aCode(&rCxt.getDoc());
aCode.AddToken( FormulaErrorToken( pCode->GetCodeError()));
ScCompiler aComp(rCxt, aPos, aCode, false, false, pContext);
aComp.CreateStringFromTokenArray(aBuf);
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 93df9f18cf98..333806049b3c 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -1810,7 +1810,7 @@ struct ConventionXL_R1C1 : public ScCompiler::Convention, public ConventionXL
ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos, ScTokenArray& rArr,
bool bComputeII, bool bMatrixFlag, const ScInterpreterContext* pContext )
: FormulaCompiler(rArr, bComputeII, bMatrixFlag),
- pDoc(rCxt.getDoc()),
+ pDoc(&rCxt.getDoc()),
aPos(rPos),
mpFormatter(pContext? pContext->GetFormatTable() : pDoc->GetFormatTable()),
mpInterpreterContext(pContext),
@@ -1855,7 +1855,7 @@ ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos, ScTokenArr
ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos,
bool bComputeII, bool bMatrixFlag, const ScInterpreterContext* pContext )
: FormulaCompiler(bComputeII, bMatrixFlag),
- pDoc(rCxt.getDoc()),
+ pDoc(&rCxt.getDoc()),
aPos(rPos),
mpFormatter(pContext ? pContext->GetFormatTable() : pDoc ? pDoc->GetFormatTable() : nullptr),
mpInterpreterContext(pContext),
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index 956f9439f902..615daddf3568 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -189,7 +189,7 @@ void ScRangeData::CompileUnresolvedXML( sc::CompileFormulaContext& rCxt )
// Don't let the compiler set an error for unknown names on final
// compile, errors are handled by the interpreter thereafter.
CompileRangeData( aSymbol, false);
- rCxt.getDoc()->CheckLinkFormulaNeedingCheck( *pCode);
+ rCxt.getDoc().CheckLinkFormulaNeedingCheck( *pCode);
}
}
diff --git a/sc/source/core/tool/tokenstringcontext.cxx b/sc/source/core/tool/tokenstringcontext.cxx
index 8a326d081a79..8e15db4ee592 100644
--- a/sc/source/core/tool/tokenstringcontext.cxx
+++ b/sc/source/core/tool/tokenstringcontext.cxx
@@ -104,14 +104,14 @@ TokenStringContext::TokenStringContext( const ScDocument* pDoc, formula::Formula
}
}
-CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc ) :
- mpDoc(pDoc), meGram(pDoc->GetGrammar())
+CompileFormulaContext::CompileFormulaContext( ScDocument& rDoc ) :
+ mrDoc(rDoc), meGram(rDoc.GetGrammar())
{
updateTabNames();
}
-CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) :
- mpDoc(pDoc), meGram(eGram)
+CompileFormulaContext::CompileFormulaContext( ScDocument& rDoc, formula::FormulaGrammar::Grammar eGram ) :
+ mrDoc(rDoc), meGram(eGram)
{
updateTabNames();
}
@@ -119,7 +119,7 @@ CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc, formula::Formula
void CompileFormulaContext::updateTabNames()
{
// Fetch all sheet names.
- maTabNames = mpDoc->GetAllTableNames();
+ maTabNames = mrDoc.GetAllTableNames();
{
for (auto& rTabName : maTabNames)
ScCompiler::CheckTabQuotes(rTabName, formula::FormulaGrammar::extractRefConvention(meGram));
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index 5d636767de1d..78f03e2176a6 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -1031,7 +1031,7 @@ bool XclExpXmlStream::exportDocument()
aData.maMaxPos.SetCol( ::std::min( aData.maScMaxPos.Col(), aData.maXclMaxPos.Col() ) );
aData.maMaxPos.SetRow( ::std::min( aData.maScMaxPos.Row(), aData.maXclMaxPos.Row() ) );
aData.maMaxPos.SetTab( ::std::min( aData.maScMaxPos.Tab(), aData.maXclMaxPos.Tab() ) );
- aData.mpCompileFormulaCxt = std::make_shared<sc::CompileFormulaContext>(&rDoc);
+ aData.mpCompileFormulaCxt = std::make_shared<sc::CompileFormulaContext>(rDoc);
// set target path to get correct relative links to target document, not source
INetURLObject aPath(getFileUrl());
aData.maBasePath = aPath.GetPath() + "\\";
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index de07a3f7f347..b2c06583719d 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3166,7 +3166,7 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
if (!mpCompileFormulaCxt)
{
const formula::FormulaGrammar::Grammar eGrammar = pDoc->GetStorageGrammar();
- mpCompileFormulaCxt.reset(new sc::CompileFormulaContext(pDoc, eGrammar));
+ mpCompileFormulaCxt.reset(new sc::CompileFormulaContext(*pDoc, eGrammar));
}
OUString aFormula = pFormulaCell->GetFormula(*mpCompileFormulaCxt);