[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Fri Apr 26 20:14:27 PDT 2013


 sc/inc/formulacell.hxx              |    3 
 sc/source/core/data/formulacell.cxx |  156 ++++++++++++++++++------------------
 2 files changed, 82 insertions(+), 77 deletions(-)

New commits:
commit b77a730516be574e0db5b80e90c7dd87a5b897c0
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Apr 26 23:16:43 2013 -0400

    Move the invariant group handler into its own method.
    
    Change-Id: I3ed8da3c9673b990d5ae17d235bcf4fc1a4541f1

diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 397fd9c..e4f1cfa 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -302,7 +302,8 @@ public:
 
     CompareState CompareByTokenArray( ScFormulaCell *pOther ) const;
 
-    bool                   InterpretFormulaGroup();
+    bool InterpretFormulaGroup();
+    bool InterpretInvariantFormulaGroup();
 
     // nOnlyNames may be one or more of SC_LISTENING_NAMES_*
     void StartListeningTo( ScDocument* pDoc );
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 43d80cf..3bfd458 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2965,82 +2965,7 @@ bool ScFormulaCell::InterpretFormulaGroup()
     }
 
     if (xGroup->mbInvariant)
-    {
-        if (pCode->GetVectorState() == FormulaVectorCheckReference)
-        {
-            // An invariant group should only have absolute references, and no
-            // external references are allowed.
-
-            ScTokenArray aCode;
-            pCode->Reset();
-            for (const formula::FormulaToken* p = pCode->First(); p; p = pCode->Next())
-            {
-                const ScToken* pToken = static_cast<const ScToken*>(p);
-                switch (pToken->GetType())
-                {
-                    case svSingleRef:
-                    {
-                        const ScSingleRefData& rRef = pToken->GetSingleRef();
-                        ScAddress aRefPos(rRef.nCol, rRef.nRow, rRef.nTab);
-                        formula::FormulaTokenRef pNewToken = pDocument->ResolveStaticReference(aRefPos);
-                        if (!pNewToken)
-                            return false;
-
-                        aCode.AddToken(*pNewToken);
-                    }
-                    break;
-                    case svDoubleRef:
-                    {
-                        const ScComplexRefData& rRef = pToken->GetDoubleRef();
-                        ScRange aRefRange(
-                            rRef.Ref1.nCol, rRef.Ref1.nRow, rRef.Ref1.nTab,
-                            rRef.Ref2.nCol, rRef.Ref2.nRow, rRef.Ref2.nTab);
-
-                        formula::FormulaTokenRef pNewToken = pDocument->ResolveStaticReference(aRefRange);
-                        if (!pNewToken)
-                            return false;
-
-                        aCode.AddToken(*pNewToken);
-                    }
-                    break;
-                    default:
-                        aCode.AddToken(*pToken);
-                }
-            }
-
-            ScCompiler aComp(pDocument, aPos, aCode);
-            aComp.SetGrammar(pDocument->GetGrammar());
-            aComp.CompileTokenArray(); // Create RPN token array.
-            ScInterpreter aInterpreter(this, pDocument, aPos, aCode);
-            aInterpreter.Interpret();
-            aResult.SetToken(aInterpreter.GetResultToken().get());
-        }
-        else
-        {
-            // Formula contains no references.
-            ScInterpreter aInterpreter(this, pDocument, aPos, *pCode);
-            aInterpreter.Interpret();
-            aResult.SetToken(aInterpreter.GetResultToken().get());
-        }
-
-        for ( sal_Int32 i = 0; i < xGroup->mnLength; i++ )
-        {
-            ScAddress aTmpPos = aPos;
-            aTmpPos.SetRow(xGroup->mnStart + i);
-            ScFormulaCell* pCell = pDocument->GetFormulaCell(aTmpPos);
-            assert( pCell != NULL );
-
-            // FIXME: this set of horrors is unclear to me ... certainly
-            // the above GetCell is profoundly nasty & slow ...
-
-            // Ensure the cell truly has a result:
-            pCell->aResult = aResult;
-            pCell->ResetDirty();
-
-            // FIXME: there is a view / refresh missing here it appears.
-        }
-        return true;
-    }
+        return InterpretInvariantFormulaGroup();
 
     // scan the formula ...
     // have a document method: "Get2DRangeAsDoublesArray" that does the
@@ -3072,6 +2997,85 @@ bool ScFormulaCell::InterpretFormulaGroup()
     return false;
 }
 
+bool ScFormulaCell::InterpretInvariantFormulaGroup()
+{
+    if (pCode->GetVectorState() == FormulaVectorCheckReference)
+    {
+        // An invariant group should only have absolute references, and no
+        // external references are allowed.
+
+        ScTokenArray aCode;
+        pCode->Reset();
+        for (const formula::FormulaToken* p = pCode->First(); p; p = pCode->Next())
+        {
+            const ScToken* pToken = static_cast<const ScToken*>(p);
+            switch (pToken->GetType())
+            {
+                case svSingleRef:
+                {
+                    const ScSingleRefData& rRef = pToken->GetSingleRef();
+                    ScAddress aRefPos(rRef.nCol, rRef.nRow, rRef.nTab);
+                    formula::FormulaTokenRef pNewToken = pDocument->ResolveStaticReference(aRefPos);
+                    if (!pNewToken)
+                        return false;
+
+                    aCode.AddToken(*pNewToken);
+                }
+                break;
+                case svDoubleRef:
+                {
+                    const ScComplexRefData& rRef = pToken->GetDoubleRef();
+                    ScRange aRefRange(
+                        rRef.Ref1.nCol, rRef.Ref1.nRow, rRef.Ref1.nTab,
+                        rRef.Ref2.nCol, rRef.Ref2.nRow, rRef.Ref2.nTab);
+
+                    formula::FormulaTokenRef pNewToken = pDocument->ResolveStaticReference(aRefRange);
+                    if (!pNewToken)
+                        return false;
+
+                    aCode.AddToken(*pNewToken);
+                }
+                break;
+                default:
+                    aCode.AddToken(*pToken);
+            }
+        }
+
+        ScCompiler aComp(pDocument, aPos, aCode);
+        aComp.SetGrammar(pDocument->GetGrammar());
+        aComp.CompileTokenArray(); // Create RPN token array.
+        ScInterpreter aInterpreter(this, pDocument, aPos, aCode);
+        aInterpreter.Interpret();
+        aResult.SetToken(aInterpreter.GetResultToken().get());
+    }
+    else
+    {
+        // Formula contains no references.
+        ScInterpreter aInterpreter(this, pDocument, aPos, *pCode);
+        aInterpreter.Interpret();
+        aResult.SetToken(aInterpreter.GetResultToken().get());
+    }
+
+    for ( sal_Int32 i = 0; i < xGroup->mnLength; i++ )
+    {
+        ScAddress aTmpPos = aPos;
+        aTmpPos.SetRow(xGroup->mnStart + i);
+        ScFormulaCell* pCell = pDocument->GetFormulaCell(aTmpPos);
+        assert( pCell != NULL );
+
+        // FIXME: this set of horrors is unclear to me ... certainly
+        // the above GetCell is profoundly nasty & slow ...
+
+        // Ensure the cell truly has a result:
+        pCell->aResult = aResult;
+        pCell->ResetDirty();
+
+        // FIXME: there is a view / refresh missing here it appears.
+    }
+
+    return true;
+}
+
 void ScFormulaCell::StartListeningTo( ScDocument* pDoc )
 {
     if (pDoc->IsClipOrUndo() || pDoc->GetNoListening() || IsInChangeTrack())


More information about the Libreoffice-commits mailing list