[PATCH] BITxxx functions for ODF 1.2

Wolfgang Pechlaner libo at pechlaner.at
Sun Sep 4 05:40:25 PDT 2011


---
 sc/inc/helpids.h                 |    5 +
 sc/qa/unit/ucalc.cxx             |    5 +
 sc/source/core/inc/interpre.hxx  |    5 +
 sc/source/core/tool/interpr1.cxx |  101 ++++++++++++++++++++++++
 sc/source/core/tool/interpr4.cxx |    5 +
 sc/source/ui/src/scfuncs.src     |  156 ++++++++++++++++++++++++++++++++++++++
 sc/util/hidother.src             |    5 +
 7 files changed, 282 insertions(+), 0 deletions(-)

diff --git a/sc/inc/helpids.h b/sc/inc/helpids.h
index c80dd1b..b04aa77 100644
--- a/sc/inc/helpids.h
+++ b/sc/inc/helpids.h
@@ -692,3 +692,8 @@
 #define HID_FUNC_UNICODE                                        "SC_HID_FUNC_UNICODE"
 #define HID_FUNC_UNICHAR                                        "SC_HID_FUNC_UNICHAR"
 #define HID_FUNC_NUMBERVALUE                                    "SC_HID_FUNC_NUMBERVALUE"
+#define HID_FUNC_BITAND                                         "SC_HID_FUNC_BITAND"
+#define HID_FUNC_BITOR                                          "SC_HID_FUNC_BITOR"
+#define HID_FUNC_BITXOR                                         "SC_HID_FUNC_BITXOR"
+#define HID_FUNC_BITLSHIFT                                      "SC_HID_FUNC_BITLSHIFT"
+#define HID_FUNC_BITRSHIFT                                      "SC_HID_FUNC_BITRSHIFT"
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 7430a60..533fbe2 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1742,6 +1742,11 @@ void Test::testFunctionLists()
 
     const char* aLogical[] = {
         "AND",
+        "BITAND",
+        "BITLSHIFT",
+        "BITOR",
+        "BITRSHIFT",
+        "BITXOR",
         "FALSE",
         "IF",
         "NOT",
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 27027d5..50881d6 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -412,6 +412,11 @@ void ScAnd();
 void ScOr();
 void ScNot();
 void ScNeg();
+void ScBitAnd();
+void ScBitOr();
+void ScBitXor();
+void ScBitRshift();
+void ScBitLshift();
 void ScPercentSign();
 void ScIntersect();
 void ScRangeFunc();
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index f581ac7..3921e0e 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1391,6 +1391,107 @@ void ScInterpreter::ScNeg()
 }
 
 
+void ScInterpreter::ScBitAnd()
+{
+    RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScBitAnd" );
+
+    if ( !MustHaveParamCount( GetByte(), 2 ) )
+      return;
+
+     double num1, num2;
+     num1 = GetDouble();
+     num2 = GetDouble();
+     if ((num1 > 281474976710655) or (num1 < 0) or
+         (num2 > 281474976710655) or (num2 < 0)) {
+        PushIllegalArgument();
+     }
+
+      PushDouble ((sal_uInt64) num1 & (sal_uInt64) num2);
+}
+
+
+void ScInterpreter::ScBitOr()
+{
+    RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScBitOr" );
+
+      if ( !MustHaveParamCount( GetByte(), 2 ) )
+      return;
+
+    double num1, num2;
+    num1 = GetDouble();
+    num2 = GetDouble();
+    if ((num1 > 281474976710655) or (num1 < 0) or
+        (num2 > 281474976710655) or (num2 < 0)) {
+          PushIllegalArgument();
+    }
+
+    PushDouble ((sal_uInt64) num1 | (sal_uInt64) num2);
+}
+
+
+void ScInterpreter::ScBitXor()
+{
+    RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScBitXor" );
+
+    if ( !MustHaveParamCount( GetByte(), 2 ) )
+      return;
+
+    double num1, num2;
+    num1 = GetDouble();
+    num2 = GetDouble();
+    if ((num1 > 281474976710655) or (num1 < 0) or
+        (num2 > 281474976710655) or (num2 < 0)) {
+         PushIllegalArgument();
+    }
+
+    PushDouble ((sal_uInt64) num1 ^ (sal_uInt64) num2);
+}
+
+
+void ScInterpreter::ScBitLshift()
+{
+    RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScBitLshift" );
+
+    if ( !MustHaveParamCount( GetByte(), 2 ) )
+      return;
+
+    sal_uInt64 erg;
+    sal_Int32 ishift = GetDouble();
+    double num = GetDouble();
+        if ((num > 281474976710655) or (num < 0))  {
+            PushIllegalArgument();
+    }
+    if (ishift < 0) {
+      erg = (sal_uInt64) num >> -ishift;
+    } else {
+      erg = (sal_uInt64) num << ishift;
+    }
+    PushDouble (erg);
+}
+
+void ScInterpreter::ScBitRshift()
+{
+    RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScBitRshift" );
+
+    if ( !MustHaveParamCount( GetByte(), 2 ) )
+      return;
+    sal_uInt64 erg;
+    sal_Int32 ishift = GetDouble();
+    double num = GetDouble();
+        if ((num > 281474976710655) or (num < 0))  {
+          PushIllegalArgument();
+    }
+    if (ishift < 0) {
+      erg = (sal_uInt64) num << -ishift;
+    } else {
+      erg = (sal_uInt64) num >> ishift;
+    }
+    PushDouble (erg);
+}
+
+
+
+
 void ScInterpreter::ScPercentSign()
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScPercentSign" );
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 05ff646..8e0eb5f 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4064,6 +4064,11 @@ StackVar ScInterpreter::Interpret()
                 case ocUnicode          : ScUnicode();                  break;
                 case ocUnichar          : ScUnichar();                  break;
                 case ocTTT              : ScTTT();                      break;
+                case ocBitAnd           : ScBitAnd();                   break;
+                case ocBitOr            : ScBitOr();                    break;
+                case ocBitXor           : ScBitXor();                   break;
+                case ocBitRshift        : ScBitRshift();                break;
+                case ocBitLshift        : ScBitLshift();                break;
                 case ocNone : nFuncFmtType = NUMBERFORMAT_UNDEFINED;    break;
                 default : PushError( errUnknownOpCode);                 break;
             }
diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src
index 4f99f90..e67b76b 100644
--- a/sc/source/ui/src/scfuncs.src
+++ b/sc/source/ui/src/scfuncs.src
@@ -9037,6 +9037,162 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2
             Text [ en-US ] = "Defines the character used as the decimal point." ;
         };
     };
+
+    Resource SC_OPCODE_BITAND
+    {
+    String 1 // Description
+    {
+        Text [ en-US ] = "Logical and of 2 integers.";
+    };
+    ExtraData =
+    {
+        0;
+        ID_FUNCTION_GRP_LOGIC;
+        U2S( HID_FUNC_BITAND );
+        2;  0;  0;
+        0;
+    };
+       String 2 // Name of Parameter 1
+        {
+            Text [ en-US ] = "number" ;
+        };
+        String 3 // Description of Parameter 1
+        {
+            Text [ en-US ] = "positive interger less then 2^48-1." ;
+        };
+        String 4 // Name of Parameter 2
+        {
+                Text [ en-US ] = "number" ;
+        };
+        String 5 // Description of Parameter 2
+        {
+            Text [ en-US ] = "positive interger less then 2^48-1." ;
+        };
+    };
+    Resource SC_OPCODE_BITOR
+    {
+    String 1 // Description
+    {
+        Text [ en-US ] = "Logical or of 2 integers.";
+    };
+    ExtraData =
+    {
+        0;
+        ID_FUNCTION_GRP_LOGIC;
+        U2S( HID_FUNC_BITOR );
+        2;  0;  0;
+        0;
+    };
+       String 2 // Name of Parameter 1
+        {
+            Text [ en-US ] = "number" ;
+        };
+        String 3 // Description of Parameter 1
+        {
+            Text [ en-US ] = "positive interger less then 2^48-1." ;
+        };
+        String 4 // Name of Parameter 2
+        {
+                Text [ en-US ] = "number" ;
+        };
+        String 5 // Description of Parameter 2
+        {
+            Text [ en-US ] = "positive interger less then 2^48-1." ;
+        };
+    };
+    Resource SC_OPCODE_BITXOR
+    {
+    String 1 // Description
+    {
+        Text [ en-US ] = "Logical exclusive or of 2 integers.";
+    };
+    ExtraData =
+    {
+        0;
+        ID_FUNCTION_GRP_LOGIC;
+        U2S( HID_FUNC_BITXOR );
+        2;  0;  0;
+        0;
+    };
+       String 2 // Name of Parameter 1
+        {
+            Text [ en-US ] = "number" ;
+        };
+        String 3 // Description of Parameter 1
+        {
+            Text [ en-US ] = "positive interger less then 2^48-1." ;
+        };
+        String 4 // Name of Parameter 2
+        {
+                Text [ en-US ] = "number" ;
+        };
+        String 5 // Description of Parameter 2
+        {
+            Text [ en-US ] = "positive interger less then 2^48-1." ;
+        };
+    };
+    Resource SC_OPCODE_BITRSHIFT
+    {
+    String 1 // Description
+    {
+        Text [ en-US ] = "Logical right shift.";
+    };
+    ExtraData =
+    {
+        0;
+        ID_FUNCTION_GRP_LOGIC;
+        U2S( HID_FUNC_BITRSHIFT );
+        2;  0;  0;
+        0;
+    };
+       String 2 // Name of Parameter 1
+        {
+            Text [ en-US ] = "number" ;
+        };
+        String 3 // Description of Parameter 1
+        {
+            Text [ en-US ] = "positive interger less then 2^48-1." ;
+        };
+        String 4 // Name of Parameter 2
+        {
+                Text [ en-US ] = "number" ;
+        };
+        String 5 // Description of Parameter 2
+        {
+            Text [ en-US ] = "number between - 48 and 48" ;
+        };
+    };
+    Resource SC_OPCODE_BITLSHIFT
+    {
+    String 1 // Description
+    {
+        Text [ en-US ] = "Logical left shift.";
+    };
+    ExtraData =
+    {
+        0;
+        ID_FUNCTION_GRP_LOGIC;
+        U2S( HID_FUNC_BITLSHIFT );
+        2;  0;  0;
+        0;
+    };
+       String 2 // Name of Parameter 1
+        {
+            Text [ en-US ] = "number" ;
+        };
+        String 3 // Description of Parameter 1
+        {
+            Text [ en-US ] = "positive interger less then 2^48-1." ;
+        };
+        String 4 // Name of Parameter 2
+        {
+                Text [ en-US ] = "number" ;
+        };
+        String 5 // Description of Parameter 2
+        {
+            Text [ en-US ] = "number between - 48 and 48" ;
+        };
+    };
 };
 
 #if defined(U2S)
diff --git a/sc/util/hidother.src b/sc/util/hidother.src
index d575580..37798c3 100644
--- a/sc/util/hidother.src
+++ b/sc/util/hidother.src
@@ -363,6 +363,11 @@ hidspecial HID_FUNC_NUMBERVALUE     { HelpID = HID_FUNC_NUMBERVALUE; };
 hidspecial HID_FUNC_GAMMA           { HelpID = HID_FUNC_GAMMA; };
 hidspecial HID_FUNC_CHISQDIST       { HelpID = HID_FUNC_CHISQDIST; };
 hidspecial HID_FUNC_CHISQINV        { HelpID = HID_FUNC_CHISQINV; };
+hidspecial HID_FUNC_BITAND          { HelpID = HID_FUNC_BITAND; };
+hidspecial HID_FUNC_BITOR           { HelpID = HID_FUNC_BITOR; };
+hidspecial HID_FUNC_BITXOR          { HelpID = HID_FUNC_BITXOR; };
+hidspecial HID_FUNC_BITRSHIFT       { HelpID = HID_FUNC_BITRSHIFT; };
+hidspecial HID_FUNC_BITLSHIFT       { HelpID = HID_FUNC_BITLSHIFT; };
 
 // ... and from Analysis Addin
 
-- 
1.7.3.4


--------------050009030706080009000901
Content-Type: text/x-patch;
 name="0001-new-BITxxx_functions.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0001-new-BITxxx_functions.patch"



More information about the LibreOffice mailing list