formula/inc/formula/compiler.hrc | 8 +- formula/inc/formula/opcode.hxx | 4 + formula/source/core/resource/core_resource.src | 18 ++++ sc/inc/helpids.h | 4 - sc/source/core/inc/interpre.hxx | 13 +++ sc/source/core/tool/interpr1.cxx | 66 ++++++++++++++++ sc/source/core/tool/interpr4.cxx | 3 sc/source/ui/src/scfuncs.src | 100 +++++++++++++++++++++++++ sc/util/hidother.src | 3 9 files changed, 216 insertions(+), 3 deletions(-)
New commits: commit bb122fab960b1df17bda229dab79841e96aaab11 Author: Damjan Jovanovic <dam...@apache.org> Date: Sun Nov 22 06:58:12 2015 +0000 #i126668# Addition of Bitwise Arithmetic Operations (BITAND, BITOR and BITXOR) in calc Patch by: Pathangi Janardhanan Jatinshravan <JATINSHR001 at e dot ntu dot edu dot sg> Review by: me diff --git a/formula/inc/formula/compiler.hrc b/formula/inc/formula/compiler.hrc index 8f49f46..49f6f7f 100644 --- a/formula/inc/formula/compiler.hrc +++ b/formula/inc/formula/compiler.hrc @@ -397,9 +397,13 @@ #define SC_OPCODE_RIGHTB 401 #define SC_OPCODE_LEFTB 402 #define SC_OPCODE_MIDB 403 -#define SC_OPCODE_STOP_2_PAR 404 +#define SC_OPCODE_BITAND 404 +#define SC_OPCODE_BITOR 405 +#define SC_OPCODE_BITXOR 406 -#define SC_OPCODE_LAST_OPCODE_ID 403 /* last OpCode */ +#define SC_OPCODE_STOP_2_PAR 407 + +#define SC_OPCODE_LAST_OPCODE_ID 406 /* last OpCode */ /*** Interna ***/ #define SC_OPCODE_INTERNAL_BEGIN 9999 diff --git a/formula/inc/formula/opcode.hxx b/formula/inc/formula/opcode.hxx index f1bbb75..0cd908e 100644 --- a/formula/inc/formula/opcode.hxx +++ b/formula/inc/formula/opcode.hxx @@ -393,6 +393,10 @@ enum OpCodeEnum ocEuroConvert = SC_OPCODE_EUROCONVERT, ocNumberValue = SC_OPCODE_NUMBERVALUE, ocXor = SC_OPCODE_XOR, + //bitwise functions + ocBitAnd = SC_OPCODE_BITAND, + ocBitOr = SC_OPCODE_BITOR, + ocBitXor = SC_OPCODE_BITXOR, // internal stuff ocInternalBegin = SC_OPCODE_INTERNAL_BEGIN, ocTTT = SC_OPCODE_TTT, diff --git a/formula/source/core/resource/core_resource.src b/formula/source/core/resource/core_resource.src index d723cb1..a29acd0 100644 --- a/formula/source/core/resource/core_resource.src +++ b/formula/source/core/resource/core_resource.src @@ -349,6 +349,9 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF String SC_OPCODE_GAMMA { Text = "GAMMA" ; }; String SC_OPCODE_CHISQ_DIST { Text = "CHISQDIST" ; }; String SC_OPCODE_CHISQ_INV { Text = "CHISQINV" ;}; + String SC_OPCODE_BITAND { Text= "BITAND" ; }; + String SC_OPCODE_BITOR { Text= "BITOR" ; }; + String SC_OPCODE_BITXOR { Text= "BITXOR" ; }; /* BEGIN defined ERROR.TYPE() values. */ String SC_OPCODE_ERROR_NULL { Text = "#NULL!" ; }; @@ -686,6 +689,9 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH String SC_OPCODE_GAMMA { Text = "GAMMA" ; }; String SC_OPCODE_CHISQ_DIST { Text = "CHISQDIST" ; }; String SC_OPCODE_CHISQ_INV { Text = "CHISQINV" ;}; + String SC_OPCODE_BITAND { Text = "BITAND" ; }; + String SC_OPCODE_BITOR { Text = "BITOR" ; }; + String SC_OPCODE_BITXOR { Text = "BITXOR" ; }; /* BEGIN defined ERROR.TYPE() values. */ String SC_OPCODE_ERROR_NULL { Text = "#NULL!" ; }; @@ -1910,6 +1916,18 @@ Resource RID_STRLIST_FUNCTION_NAMES { Text [ en-US ] = "CHISQINV" ; }; + String SC_OPCODE_BITAND + { + Text [ en-US ] = "BITAND"; + }; + String SC_OPCODE_BITOR + { + Text [ en-US ] = "BITOR"; + }; + String SC_OPCODE_BITXOR + { + Text [ en-US ] = "BITXOR"; + }; /* BEGIN defined ERROR.TYPE() values. */ /* ERROR.TYPE( #NULL! ) == 1 */ String SC_OPCODE_ERROR_NULL diff --git a/sc/inc/helpids.h b/sc/inc/helpids.h index d9dd5f3..ae09a53 100644 --- a/sc/inc/helpids.h +++ b/sc/inc/helpids.h @@ -774,4 +774,6 @@ #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" diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index 3135082..2e1aede 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -142,6 +142,15 @@ class ScInterpreter friend class ScChiSqDistFunction; public: + struct bitOperations { + enum bitArithmetic + { + BITAND, + BITOR, + BITXOR + }; + }; + DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter ) static void GlobalExit(); // aus ScGlobal::Clear() gerufen @@ -513,6 +522,10 @@ void ScLookup(); void ScHLookup(); void ScVLookup(); void ScSubTotal(); +void ScBitAnd(); +void ScBitOr(); +void ScBitXor(); +void ScBitArithmeticOps( bitOperations::bitArithmetic ); // If upon call rMissingField==sal_True then the database field parameter may be // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 0a0d3ae..864cb86 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -1141,6 +1141,72 @@ void ScInterpreter::ScGreaterEqual() PushInt( Compare() >= 0 ); } +void ScInterpreter::ScBitAnd() { + ScBitArithmeticOps(bitOperations::BITAND); +} + +void ScInterpreter::ScBitOr() { + ScBitArithmeticOps(bitOperations::BITOR); +} + +void ScInterpreter::ScBitXor() { + ScBitArithmeticOps(bitOperations::BITXOR); +} + +/* Helper function that calculates the result in bitwise arithmetic operations helping avoid code repetition */ +static void doOperation( sal_uInt64 val, ScInterpreter::bitOperations::bitArithmetic bitOp, sal_uInt64 &res, sal_Bool &first ) +{ + if ( first ) + { + res = val; + first = sal_False; + } + else + { + if (bitOp == ScInterpreter::bitOperations::BITAND) + res = res & val; + else if (bitOp == ScInterpreter::bitOperations::BITOR) + res = res | val; + else if (bitOp == ScInterpreter::bitOperations::BITXOR) + res = res ^ val; + } +} + +void ScInterpreter::ScBitArithmeticOps(bitOperations::bitArithmetic bitOp) +{ + nFuncFmtType = NUMBERFORMAT_NUMBER; + short nParamCount = GetByte(); + static const sal_uInt64 max_val = SAL_CONST_UINT64( 281474976710656 ); + static const int NUMBER_OF_ARGUMENTS = 2; + + if ( MustHaveParamCount( nParamCount, NUMBER_OF_ARGUMENTS ) ) + { + double *arguments = new double[NUMBER_OF_ARGUMENTS]; + + for (int i=0; i<NUMBER_OF_ARGUMENTS; i++) + { + arguments[i] = ::rtl::math::approxFloor( GetDouble() ); + if ( arguments[i] < 0 || arguments[i] > max_val ) + { + PushIllegalArgument(); + } + } + + sal_uInt64 res = 0; + sal_Bool first = sal_True; + + + for (int i=0; i<NUMBER_OF_ARGUMENTS; i++) + { + doOperation( ( sal_uInt64 )arguments[i], bitOp, res, first ); + } + + delete[] arguments; + PushDouble( (double) res ); + + } +} + void ScInterpreter::ScAnd() { diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 77018c2..2232717 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -3766,6 +3766,9 @@ 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 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 f867c6a..81274c7 100644 --- a/sc/source/ui/src/scfuncs.src +++ b/sc/source/ui/src/scfuncs.src @@ -9433,6 +9433,106 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 Text [ en-US ] = "The number of characters for the text." ; }; }; + + // -=*# Resource for function BITAND #*=- + Resource SC_OPCODE_BITAND + { + String 1 // Description + { + Text [ en-US ] = "Returns the bitwise AND of two integers" ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_MATH; + U2S( HID_FUNC_BITAND ); + 2; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "Number1" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "Positive integer less than 2^48." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "Number2" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "Positive integer less than 2^48." ; + }; + }; + + // -=*# Resource for function BITOR #*=- + Resource SC_OPCODE_BITOR + { + String 1 // Description + { + Text [ en-US ] = "Returns the bitwise OR of two integers" ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_MATH; + U2S( HID_FUNC_BITOR ); + 2; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "Number1" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "Positive integer less than 2^48." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "Number2" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "Positive integer less than 2^48." ; + }; + }; + + // -=*# Resource for function BITXOR #*=- + Resource SC_OPCODE_BITXOR + { + String 1 // Description + { + Text [ en-US ] = "Returns the bitwise XOR of two integers" ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_MATH; + U2S( HID_FUNC_BITXOR ); + 2; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "Number1" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "Positive integer less than 2^48." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "Number2" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "Positive integer less than 2^48." ; + }; + }; + }; #if defined(U2S) diff --git a/sc/util/hidother.src b/sc/util/hidother.src index 7733a7b..b3dc678 100644 --- a/sc/util/hidother.src +++ b/sc/util/hidother.src @@ -486,3 +486,6 @@ hidspecial HID_DAI_FUNC_DIFFWEEKS { HelpID = HID_DAI_FUNC_DIFFWEEKS; }; hidspecial HID_DAI_FUNC_DIFFYEARS { HelpID = HID_DAI_FUNC_DIFFYEARS; }; hidspecial HID_DAI_FUNC_ROT13 { HelpID = HID_DAI_FUNC_ROT13; }; +hidspecial HID_FUNC_BITAND { HelpID = HID_FUNC_BITAND; }; +hidspecial HID_FUNC_BITOR { HelpID = HID_FUNC_BITOR; }; +hidspecial HID_FUNC_BITXOR { HelpID = HID_FUNC_BITXOR; }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits