[Libreoffice-commits] core.git: sc/inc sc/qa sc/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Sat Sep 12 15:33:54 UTC 2020


 sc/inc/simpleformulacalc.hxx              |    4 ++--
 sc/qa/unit/ucalc.cxx                      |    4 ++--
 sc/source/core/data/simpleformulacalc.cxx |   12 ++++++------
 sc/source/ui/app/inputhdl.cxx             |    4 ++--
 sc/source/ui/formdlg/formula.cxx          |    4 ++--
 5 files changed, 14 insertions(+), 14 deletions(-)

New commits:
commit fa2499a6e9c0c4f25b0a59cd89489d7051c57ee3
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Sat Sep 12 14:27:27 2020 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Sat Sep 12 17:33:06 2020 +0200

    establish that ScSimpleFormulaCalculator mpDoc is never null
    
    Change-Id: Ic3f404c266e9f91b47ba408036df37142a4fd91c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102519
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/inc/simpleformulacalc.hxx b/sc/inc/simpleformulacalc.hxx
index 39a26d02cbed..9bdc8c60d928 100644
--- a/sc/inc/simpleformulacalc.hxx
+++ b/sc/inc/simpleformulacalc.hxx
@@ -27,7 +27,7 @@ private:
     bool mbCalculated;
     std::unique_ptr<ScTokenArray> mpCode;
     ScAddress maAddr;
-    ScDocument* mpDoc;
+    ScDocument& mrDoc;
     ScFormulaResult maResult;
     formula::FormulaGrammar::Grammar maGram;
     bool mbMatrixResult;
@@ -36,7 +36,7 @@ private:
     bool mbMatrixFormula;
 
 public:
-    ScSimpleFormulaCalculator(ScDocument* pDoc, const ScAddress& rAddr,
+    ScSimpleFormulaCalculator(ScDocument& rDoc, const ScAddress& rAddr,
             const OUString& rFormula, bool bMatrixFormula,
             formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_DEFAULT);
     ~ScSimpleFormulaCalculator();
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 41bc846640cb..f29d1ab33f54 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -6370,7 +6370,7 @@ void Test::testFormulaWizardSubformula()
     m_pDoc->SetString(ScAddress(1,1,0), "=1/0");        // B2
     m_pDoc->SetString(ScAddress(1,2,0), "=gibberish");  // B3
 
-    ScSimpleFormulaCalculator aFCell1( m_pDoc, ScAddress(0,0,0), "=B1:B3", true );
+    ScSimpleFormulaCalculator aFCell1( *m_pDoc, ScAddress(0,0,0), "=B1:B3", true );
     FormulaError nErrCode = aFCell1.GetErrCode();
     CPPUNIT_ASSERT( nErrCode == FormulaError::NONE || aFCell1.IsMatrix() );
     CPPUNIT_ASSERT_EQUAL( OUString("{1;#DIV/0!;#NAME?}"), aFCell1.GetString().getString() );
@@ -6378,7 +6378,7 @@ void Test::testFormulaWizardSubformula()
     m_pDoc->SetString(ScAddress(1,0,0), "=NA()");       // B1
     m_pDoc->SetString(ScAddress(1,1,0), "2");           // B2
     m_pDoc->SetString(ScAddress(1,2,0), "=1+2");        // B3
-    ScSimpleFormulaCalculator aFCell2( m_pDoc, ScAddress(0,0,0), "=B1:B3", true );
+    ScSimpleFormulaCalculator aFCell2( *m_pDoc, ScAddress(0,0,0), "=B1:B3", true );
     nErrCode = aFCell2.GetErrCode();
     CPPUNIT_ASSERT( nErrCode == FormulaError::NONE || aFCell2.IsMatrix() );
     CPPUNIT_ASSERT_EQUAL( OUString("{#N/A;2;3}"), aFCell2.GetString().getString() );
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
index 50fcfceb5927..caeef59e7e61 100644
--- a/sc/source/core/data/simpleformulacalc.cxx
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -17,19 +17,19 @@
 
 #define DISPLAY_LEN 15
 
-ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument* pDoc, const ScAddress& rAddr,
+ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument& rDoc, const ScAddress& rAddr,
         const OUString& rFormula, bool bMatrixFormula, formula::FormulaGrammar::Grammar eGram )
     : mnFormatType(SvNumFormatType::ALL)
     , mbCalculated(false)
     , maAddr(rAddr)
-    , mpDoc(pDoc)
+    , mrDoc(rDoc)
     , maGram(eGram)
     , mbMatrixResult(false)
     , mbLimitString(false)
     , mbMatrixFormula(bMatrixFormula)
 {
     // compile already here
-    ScCompiler aComp(mpDoc, maAddr, eGram, true, bMatrixFormula);
+    ScCompiler aComp(&mrDoc, maAddr, eGram, true, bMatrixFormula);
     mpCode = aComp.CompileString(rFormula);
     if(mpCode->GetCodeError() == FormulaError::NONE && mpCode->GetLen())
         aComp.CompileTokenArray();
@@ -46,17 +46,17 @@ void ScSimpleFormulaCalculator::Calculate()
 
     mbCalculated = true;
 
-    ScInterpreter aInt(mpDoc->GetFormulaCell( maAddr ), mpDoc, mpDoc->GetNonThreadedContext(), maAddr, *mpCode);
+    ScInterpreter aInt(mrDoc.GetFormulaCell( maAddr ), &mrDoc, mrDoc.GetNonThreadedContext(), maAddr, *mpCode);
     if (mbMatrixFormula)
         aInt.AssertFormulaMatrix();
 
-    std::unique_ptr<sfx2::LinkManager> pNewLinkMgr( new sfx2::LinkManager(mpDoc->GetDocumentShell()) );
+    std::unique_ptr<sfx2::LinkManager> pNewLinkMgr( new sfx2::LinkManager(mrDoc.GetDocumentShell()) );
     aInt.SetLinkManager( pNewLinkMgr.get() );
 
     formula::StackVar aIntType = aInt.Interpret();
     if ( aIntType == formula::svMatrixCell )
     {
-        ScCompiler aComp(mpDoc, maAddr, maGram);
+        ScCompiler aComp(&mrDoc, maAddr, maGram);
         OUStringBuffer aStr;
         aComp.CreateStringFromToken(aStr, aInt.GetResultToken().get());
 
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 0a41aa329a5c..525b09723332 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -1708,7 +1708,7 @@ static OUString lcl_Calculate( const OUString& rFormula, ScDocument& rDoc, const
     if(rFormula.isEmpty())
         return OUString();
 
-    std::unique_ptr<ScSimpleFormulaCalculator> pCalc( new ScSimpleFormulaCalculator( &rDoc, rPos, rFormula, false ) );
+    std::unique_ptr<ScSimpleFormulaCalculator> pCalc( new ScSimpleFormulaCalculator( rDoc, rPos, rFormula, false ) );
 
     // FIXME: HACK! In order to not get a #REF! for ColRowNames, if a name is actually inserted as a Range
     // into the whole Formula, but is interpreted as a single cell reference when displaying it on its own
@@ -1720,7 +1720,7 @@ static OUString lcl_Calculate( const OUString& rFormula, ScDocument& rDoc, const
         {   // ==1: Single one is as a Parameter always a Range
             // ==0: It might be one, if ...
             OUString aBraced = "(" + rFormula + ")";
-            pCalc.reset( new ScSimpleFormulaCalculator( &rDoc, rPos, aBraced, false ) );
+            pCalc.reset( new ScSimpleFormulaCalculator( rDoc, rPos, aBraced, false ) );
         }
         else
             bColRowName = false;
diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx
index 977ea5e827f6..28fb1250a034 100644
--- a/sc/source/ui/formdlg/formula.cxx
+++ b/sc/source/ui/formdlg/formula.cxx
@@ -298,7 +298,7 @@ void ScFormulaDlg::Close()
 bool ScFormulaDlg::calculateValue( const OUString& rStrExp, OUString& rStrResult, bool bMatrixFormula )
 {
     std::unique_ptr<ScSimpleFormulaCalculator> pFCell( new ScSimpleFormulaCalculator(
-                m_pDoc, m_CursorPos, rStrExp, bMatrixFormula));
+                *m_pDoc, m_CursorPos, rStrExp, bMatrixFormula));
     pFCell->SetLimitString(true);
 
     // HACK! to avoid neither #REF! from ColRowNames
@@ -313,7 +313,7 @@ bool ScFormulaDlg::calculateValue( const OUString& rStrExp, OUString& rStrResult
             // ==0: would be an area if...
             OUString aBraced = "(" + rStrExp + ")";
             pFCell.reset( new ScSimpleFormulaCalculator(
-                        m_pDoc, m_CursorPos, aBraced, bMatrixFormula));
+                        *m_pDoc, m_CursorPos, aBraced, bMatrixFormula));
             pFCell->SetLimitString(true);
         }
         else


More information about the Libreoffice-commits mailing list