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

Kohei Yoshida kohei.yoshida at collabora.com
Fri Dec 20 17:08:44 PST 2013


 formula/source/core/api/FormulaCompiler.cxx |    4 ++
 include/formula/compiler.hrc                |    5 ++-
 include/formula/opcode.hxx                  |    1 
 sc/source/core/inc/interpre.hxx             |    1 
 sc/source/core/tool/compiler.cxx            |    4 +-
 sc/source/core/tool/interpr4.cxx            |    1 
 sc/source/core/tool/interpr7.cxx            |   40 ++++++++++++++++++++++++++++
 7 files changed, 51 insertions(+), 5 deletions(-)

New commits:
commit 9c09211bce7ed8e85ba75d8702e3d8703f9dc662
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Fri Dec 20 19:57:28 2013 -0500

    Add internal cell function __DEBUG_VAR to sniff arbitrary internal state.
    
    Useful for debugging in a more flashy way.  But never ever document this
    for end users.  If you are an end user reading this, use this at your
    own risk.  You have been warned.
    
    Change-Id: Ibbdb45f576287f707106327704754ffaec27ba3c

diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index e8c40aa..1051b73 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -39,7 +39,7 @@ namespace formula
 {
     using namespace ::com::sun::star;
 
-    static const sal_Char* pInternal[ 1 ] = { "TTT" };
+    static const sal_Char* pInternal[2] = { "TTT", "__DEBUG_VAR" };
 
 namespace {
 
@@ -794,6 +794,8 @@ bool FormulaCompiler::IsOpCodeVolatile( OpCode eOp )
         case ocIndirectXL:
             // ocOffset results in indirect references.
         case ocOffset:
+            // ocDebugVar shows internal value that may change as the internal state changes.
+        case ocDebugVar:
             bRet = true;
             break;
         default:
diff --git a/include/formula/compiler.hrc b/include/formula/compiler.hrc
index 3b7207c..ffab767 100644
--- a/include/formula/compiler.hrc
+++ b/include/formula/compiler.hrc
@@ -450,10 +450,11 @@
 /*** Internal ***/
 #define SC_OPCODE_INTERNAL_BEGIN   9999
 #define SC_OPCODE_TTT              9999
-#define SC_OPCODE_INTERNAL_END     9999
+#define SC_OPCODE_DEBUG_VAR       10000
+#define SC_OPCODE_INTERNAL_END    10000
 
 /*** from here on ExtraData contained ***/
-#define SC_OPCODE_DATA_TOKEN_1    10000
+#define SC_OPCODE_DATA_TOKEN_1    10001
 
 #define SC_OPCODE_NONE           0xFFFF
 
diff --git a/include/formula/opcode.hxx b/include/formula/opcode.hxx
index d978a26..ce6fd15 100644
--- a/include/formula/opcode.hxx
+++ b/include/formula/opcode.hxx
@@ -440,6 +440,7 @@ enum OpCodeEnum
     // internal stuff
         ocInternalBegin     = SC_OPCODE_INTERNAL_BEGIN,
         ocTTT               = SC_OPCODE_TTT,
+        ocDebugVar          = SC_OPCODE_DEBUG_VAR,
         ocInternalEnd       = SC_OPCODE_INTERNAL_END,
     // from here on ExtraData
         ocDataToken1        = SC_OPCODE_DATA_TOKEN_1,
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index c6aa5ad..49c634f 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -561,6 +561,7 @@ void ScBitXor();
 void ScBitRshift();
 void ScBitLshift();
 void ScTTT();
+void ScDebugVar();
 
 /** Obtain the date serial number for a given date.
     @param bStrict
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index ffce53b..b4b9af3 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -89,7 +89,7 @@ enum ScanState
     ssStop
 };
 
-static const sal_Char* pInternal[ 1 ] = { "TTT" };
+static const sal_Char* pInternal[2] = { "TTT", "__DEBUG_VAR" };
 
 using namespace ::com::sun::star::i18n;
 
@@ -3440,7 +3440,7 @@ bool ScCompiler::NextNewToken( bool bInArray )
     bool bAsciiNonAlnum;    // operators, separators, ...
     if ( cSymbol[0] < 128 )
     {
-        bMayBeFuncName = rtl::isAsciiAlpha( cSymbol[0] );
+        bMayBeFuncName = rtl::isAsciiAlpha( cSymbol[0] ) || cSymbol[0] == '_';
         bAsciiNonAlnum = !bMayBeFuncName && !rtl::isAsciiDigit( cSymbol[0] );
     }
     else
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index ed0f34a..ba5b24e 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4228,6 +4228,7 @@ StackVar ScInterpreter::Interpret()
                 case ocBitRshift        : ScBitRshift();                break;
                 case ocBitLshift        : ScBitLshift();                break;
                 case ocTTT              : ScTTT();                      break;
+                case ocDebugVar         : ScDebugVar();                 break;
                 case ocNone : nFuncFmtType = NUMBERFORMAT_UNDEFINED;    break;
                 default : PushError( errUnknownOpCode);                 break;
             }
diff --git a/sc/source/core/tool/interpr7.cxx b/sc/source/core/tool/interpr7.cxx
index bb647c1..0bcf7ae 100644
--- a/sc/source/core/tool/interpr7.cxx
+++ b/sc/source/core/tool/interpr7.cxx
@@ -15,6 +15,8 @@
 #include <com/sun/star/io/XInputStream.hpp>
 
 #include "libxml/xpath.h"
+#include <dpobject.hxx>
+#include <document.hxx>
 
 #include <boost/shared_ptr.hpp>
 #include <cstring>
@@ -205,4 +207,42 @@ void ScInterpreter::ScWebservice()
     }
 }
 
+void ScInterpreter::ScDebugVar()
+{
+    // This is to be used by developers only!  Never document this for end
+    // users.  This is a convenient way to extract arbitrary internal state to
+    // a cell for easier debugging.
+
+    if (!MustHaveParamCount(GetByte(), 1))
+    {
+        PushIllegalParameter();
+        return;
+    }
+
+    rtl_uString* p = GetString().getDataIgnoreCase();
+    if (!p)
+    {
+        PushIllegalParameter();
+        return;
+    }
+
+    OUString aStrUpper(p);
+
+    if (aStrUpper == "PIVOTCOUNT")
+    {
+        // Set the number of pivot tables in the document.
+
+        double fVal = 0.0;
+        if (pDok->HasPivotTable())
+        {
+            const ScDPCollection* pDPs = pDok->GetDPCollection();
+            fVal = pDPs->GetCount();
+        }
+        PushDouble(fVal);
+        return;
+    }
+
+    PushIllegalParameter();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list