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

Eike Rathke erack at redhat.com
Tue May 23 08:41:30 UTC 2017


 sc/source/core/inc/interpre.hxx  |    2 
 sc/source/core/tool/interpr1.cxx |   87 +++++++++++++++++++++++++++++----------
 2 files changed, 66 insertions(+), 23 deletions(-)

New commits:
commit 6a6aa56b45f19c250e9c4111b478203ddb75478b
Author: Eike Rathke <erack at redhat.com>
Date:   Tue May 23 10:39:25 2017 +0200

    Handle SUMIF and AVERAGEIF with array of references, tdf#58874
    
    Change-Id: I37bad7b85ee61631399f1b49d0bc9be3b8d00423

diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 51ddade6e1e8..e5ba5ede6b0c 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -5115,6 +5115,10 @@ void ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
     double fCount = 0.0;
     bool bNull = true;
     short nParam = 1;
+    const SCSIZE nMatRows = GetRefListArrayMaxSize( nParam);
+    // There's either one RefList and nothing else, or none.
+    ScMatrixRef xResMat = (nMatRows ? GetNewMat( 1, nMatRows) : nullptr);
+    SCSIZE nRefListArrayPos = 0;
     size_t nRefInList = 0;
     while (nParam-- > 0)
     {
@@ -5130,10 +5134,12 @@ void ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
             case svRefList :
                 if (bSumExtraRange)
                 {
+                    /* TODO: this could resolve if all refs are of the same size */
                     SetError( FormulaError::IllegalParameter);
                 }
                 else
                 {
+                    nRefListArrayPos = nRefInList;
                     ScRange aRange;
                     PopDoubleRef( aRange, nParam, nRefInList);
                     aRange.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2);
@@ -5370,14 +5376,28 @@ void ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
             PushError( FormulaError::IllegalParameter);
             return;
         }
-    }
 
-    switch( eFunc )
-    {
-        case ifSUMIF:     fRes = ::rtl::math::approxAdd( fSum, fMem ); break;
-        case ifAVERAGEIF: fRes = div( ::rtl::math::approxAdd( fSum, fMem ), fCount); break;
+        switch( eFunc )
+        {
+            case ifSUMIF:     fRes = ::rtl::math::approxAdd( fSum, fMem ); break;
+            case ifAVERAGEIF: fRes = div( ::rtl::math::approxAdd( fSum, fMem ), fCount); break;
+        }
+        if (xResMat)
+        {
+            if (nGlobalError == FormulaError::NONE)
+                xResMat->PutDouble( fRes, 0, nRefListArrayPos);
+            else
+            {
+                xResMat->PutError( nGlobalError, 0, nRefListArrayPos);
+                nGlobalError = FormulaError::NONE;
+            }
+            fRes = fSum = fMem = fCount = 0.0;
+        }
     }
-    PushDouble( fRes);
+    if (xResMat)
+        PushMatrix( xResMat);
+    else
+        PushDouble( fRes);
 }
 
 void ScInterpreter::ScSumIf()
commit 44a1f0c17d3c5b212ff60b2f24f50693b3da9eab
Author: Eike Rathke <erack at redhat.com>
Date:   Tue May 23 01:28:13 2017 +0200

    Move pushing result token into IterateParametersIf(), tdf#58874
    
    Change-Id: I98c52784992f5734480736ce4f8290490ca752f1

diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 9e5de664d0dc..8e6d89206c3a 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -596,7 +596,7 @@ void ScColumn();
 void ScRow();
 void ScSheet();
 void ScMatch();
-double IterateParametersIf( ScIterFuncIf );
+void IterateParametersIf( ScIterFuncIf );
 void ScCountIf();
 void ScSumIf();
 void ScAverageIf();
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 12aa11b97bbf..51ddade6e1e8 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -4967,11 +4967,14 @@ void ScInterpreter::ScCountEmptyCells()
     }
 }
 
-double ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
+void ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
 {
     sal_uInt8 nParamCount = GetByte();
     if ( !MustHaveParamCount( nParamCount, 2, 3 ) )
-        return 0;
+    {
+        PushError( nGlobalError);
+        return;
+    }
 
     SCCOL nCol3 = 0;
     SCROW nRow3 = 0;
@@ -4994,8 +4997,8 @@ double ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
                     PopDoubleRef( nCol3, nRow3, nTab3, nColJunk, nRowJunk, nTabJunk );
                     if ( nTabJunk != nTab3 )
                     {
-                        SetError( FormulaError::IllegalParameter);
-                        return 0;
+                        PushError( FormulaError::IllegalParameter);
+                        return;
                     }
                 }
                 break;
@@ -5012,7 +5015,10 @@ double ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
                     ScExternalRefCache::TokenRef pToken;
                     PopExternalSingleRef(pToken);
                     if (nGlobalError != FormulaError::NONE)
-                        return 0;
+                    {
+                        PushError( nGlobalError);
+                        return;
+                    }
 
                     if (pToken->GetType() == svDouble)
                         pSumExtraMatrix->PutDouble(pToken->GetDouble(), 0, 0);
@@ -5024,8 +5030,8 @@ double ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
                 PopExternalDoubleRef(pSumExtraMatrix);
                 break;
             default:
-                SetError( FormulaError::IllegalParameter);
-                return 0;
+                PushError( FormulaError::IllegalParameter);
+                return;
         }
     }
 
@@ -5039,7 +5045,10 @@ double ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
             {
                 ScAddress aAdr;
                 if ( !PopDoubleRefOrSingleRef( aAdr ) )
-                    return 0;
+                {
+                    PushError( nGlobalError);
+                    return;
+                }
 
                 ScRefCellValue aCell(*pDok, aAdr);
                 switch (aCell.meType)
@@ -5146,8 +5155,8 @@ double ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
                     pQueryMatrix = GetMatrix();
                     if (!pQueryMatrix)
                     {
-                        SetError( FormulaError::IllegalParameter);
-                        return 0;
+                        PushError( FormulaError::IllegalParameter);
+                        return;
                     }
                     nCol1 = 0;
                     nRow1 = 0;
@@ -5358,8 +5367,8 @@ double ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
         }
         else
         {
-            SetError( FormulaError::IllegalParameter);
-            return 0;
+            PushError( FormulaError::IllegalParameter);
+            return;
         }
     }
 
@@ -5368,17 +5377,17 @@ double ScInterpreter::IterateParametersIf( ScIterFuncIf eFunc )
         case ifSUMIF:     fRes = ::rtl::math::approxAdd( fSum, fMem ); break;
         case ifAVERAGEIF: fRes = div( ::rtl::math::approxAdd( fSum, fMem ), fCount); break;
     }
-    return fRes;
+    PushDouble( fRes);
 }
 
 void ScInterpreter::ScSumIf()
 {
-    PushDouble( IterateParametersIf( ifSUMIF));
+    IterateParametersIf( ifSUMIF);
 }
 
 void ScInterpreter::ScAverageIf()
 {
-    PushDouble( IterateParametersIf( ifAVERAGEIF));
+    IterateParametersIf( ifAVERAGEIF);
 }
 
 void ScInterpreter::ScCountIf()
commit b9ecc28533ed366bc6544303df763b6be29c2963
Author: Eike Rathke <erack at redhat.com>
Date:   Tue May 23 00:45:21 2017 +0200

    Handle COUNTIF with array of references, tdf#58874
    
    Change-Id: Id0325fba37cbf2cfea4a33e3e8110c5d85cf16a6

diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index f80f49557d82..12aa11b97bbf 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -5444,6 +5444,10 @@ void ScInterpreter::ScCountIf()
         }
         double fCount = 0.0;
         short nParam = 1;
+        const SCSIZE nMatRows = GetRefListArrayMaxSize( nParam);
+        // There's either one RefList and nothing else, or none.
+        ScMatrixRef xResMat = (nMatRows ? GetNewMat( 1, nMatRows) : nullptr);
+        SCSIZE nRefListArrayPos = 0;
         size_t nRefInList = 0;
         while (nParam-- > 0)
         {
@@ -5456,8 +5460,10 @@ void ScInterpreter::ScCountIf()
             ScMatrixRef pQueryMatrix;
             switch ( GetStackType() )
             {
-                case svDoubleRef :
                 case svRefList :
+                    nRefListArrayPos = nRefInList;
+                    SAL_FALLTHROUGH;
+                case svDoubleRef :
                     {
                         ScRange aRange;
                         PopDoubleRef( aRange, nParam, nRefInList);
@@ -5566,8 +5572,16 @@ void ScInterpreter::ScCountIf()
                 PushIllegalParameter();
                 return;
             }
+            if (xResMat)
+            {
+                xResMat->PutDouble( fCount, 0, nRefListArrayPos);
+                fCount = 0.0;
+            }
         }
-        PushDouble(fCount);
+        if (xResMat)
+            PushMatrix( xResMat);
+        else
+            PushDouble(fCount);
     }
 }
 


More information about the Libreoffice-commits mailing list