[Libreoffice-commits] core.git: formula/source

Eike Rathke erack at redhat.com
Sat Apr 23 20:36:24 UTC 2016


 formula/source/core/api/FormulaCompiler.cxx |   37 ++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 7 deletions(-)

New commits:
commit 0f8a8332a52cd03b43aaab86e0c232e0964d7111
Author: Eike Rathke <erack at redhat.com>
Date:   Sat Apr 23 22:33:47 2016 +0200

    more differentiated significant whitespace recognition, tdf#96426 follow-up
    
    Change-Id: I081409a82a9ff64f163115bf4597afbb9b2f5fa6

diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 6a11fc0..61c0f82 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -266,6 +266,17 @@ struct OpCodeMapData
 };
 
 
+bool isPotentialRangeLeftOp( OpCode eOp )
+{
+    switch (eOp)
+    {
+        case ocClose:
+            return true;
+        default:
+            return false;
+    }
+}
+
 bool isRangeResultFunction( OpCode eOp )
 {
     switch (eOp)
@@ -293,15 +304,23 @@ bool isRangeResultOpCode( OpCode eOp )
     }
 }
 
-bool isPotentialRangeType( FormulaToken* pToken, bool bRPN )
+/**
+    @param  bRight
+            If bRPN==false, bRight==false means opcodes for left side are
+            checked, bRight==true means opcodes for right side. If bRPN==true
+            it doesn't matter.
+ */
+bool isPotentialRangeType( FormulaToken* pToken, bool bRPN, bool bRight )
 {
     switch (pToken->GetType())
     {
         case svByte:                // could be range result, but only a few
             if (bRPN)
                 return isRangeResultOpCode( pToken->GetOpCode());
-            else
+            else if (bRight)
                 return isRangeResultFunction( pToken->GetOpCode());
+            else
+                return isPotentialRangeLeftOp( pToken->GetOpCode());
         case svSingleRef:
         case svDoubleRef:
         case svIndex:               // could be range
@@ -311,7 +330,9 @@ bool isPotentialRangeType( FormulaToken* pToken, bool bRPN )
         case svExternalName:        // could be range
             return true;
         default:
-            return false;
+            // Separators are not part of RPN and right opcodes need to be
+            // other StackVarEnum types or functions and thus svByte.
+            return !bRPN && !bRight && isPotentialRangeLeftOp( pToken->GetOpCode());
     }
 }
 
@@ -320,7 +341,7 @@ bool isIntersectable( FormulaToken** pCode1, FormulaToken** pCode2 )
     FormulaToken* pToken1 = *pCode1;
     FormulaToken* pToken2 = *pCode2;
     if (pToken1 && pToken2)
-        return isPotentialRangeType( pToken1, true) && isPotentialRangeType( pToken2, true);
+        return isPotentialRangeType( pToken1, true, false) && isPotentialRangeType( pToken2, true, true);
     return false;
 }
 
@@ -1169,7 +1190,8 @@ bool FormulaCompiler::GetToken()
                 pArr->nIndex--;     // we advanced to the second ocColRowName, step back
             }
             else if (pSpacesToken && FormulaGrammar::isExcelSyntax( meGrammar) &&
-                    isPotentialRangeType( pCurrToken.get(), false) && isPotentialRangeType( mpToken.get(), false))
+                    isPotentialRangeType( pCurrToken.get(), false, false) &&
+                    isPotentialRangeType( mpToken.get(), false, true))
             {
                 // Let IntersectionLine() <- Factor() decide how to treat this,
                 // once the actual arguments are determined in RPN.
@@ -2323,10 +2345,11 @@ OpCode FormulaCompiler::NextToken()
         {
             // Fake an intersection op as last op for the next round, but at
             // least roughly check if it could make sense at all.
-            if (eLastOp == ocPush || eLastOp == ocClose)
+            FormulaToken* pPrev = pArr->PeekPrevNoSpaces();
+            if (pPrev && isPotentialRangeType( pPrev, false, false))
             {
                 FormulaToken* pNext = pArr->PeekNextNoSpaces();
-                if (pNext && isPotentialRangeType( pNext, false))
+                if (pNext && isPotentialRangeType( pNext, false, true))
                     eLastOp = ocIntersect;
                 else
                     eLastOp = eOp;


More information about the Libreoffice-commits mailing list