Author: damjan Date: Sun Nov 22 06:58:12 2015 New Revision: 1715605 URL: http://svn.apache.org/viewvc?rev=1715605&view=rev Log: #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 Modified: openoffice/trunk/main/formula/inc/formula/compiler.hrc openoffice/trunk/main/formula/inc/formula/opcode.hxx openoffice/trunk/main/formula/source/core/resource/core_resource.src openoffice/trunk/main/sc/inc/helpids.h openoffice/trunk/main/sc/source/core/inc/interpre.hxx openoffice/trunk/main/sc/source/core/tool/interpr1.cxx openoffice/trunk/main/sc/source/core/tool/interpr4.cxx openoffice/trunk/main/sc/source/ui/src/scfuncs.src openoffice/trunk/main/sc/util/hidother.src Modified: openoffice/trunk/main/formula/inc/formula/compiler.hrc URL: http://svn.apache.org/viewvc/openoffice/trunk/main/formula/inc/formula/compiler.hrc?rev=1715605&r1=1715604&r2=1715605&view=diff ============================================================================== --- openoffice/trunk/main/formula/inc/formula/compiler.hrc (original) +++ openoffice/trunk/main/formula/inc/formula/compiler.hrc Sun Nov 22 06:58:12 2015 @@ -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 Modified: openoffice/trunk/main/formula/inc/formula/opcode.hxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/formula/inc/formula/opcode.hxx?rev=1715605&r1=1715604&r2=1715605&view=diff ============================================================================== --- openoffice/trunk/main/formula/inc/formula/opcode.hxx (original) +++ openoffice/trunk/main/formula/inc/formula/opcode.hxx Sun Nov 22 06:58:12 2015 @@ -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, Modified: openoffice/trunk/main/formula/source/core/resource/core_resource.src URL: http://svn.apache.org/viewvc/openoffice/trunk/main/formula/source/core/resource/core_resource.src?rev=1715605&r1=1715604&r2=1715605&view=diff ============================================================================== --- openoffice/trunk/main/formula/source/core/resource/core_resource.src (original) +++ openoffice/trunk/main/formula/source/core/resource/core_resource.src Sun Nov 22 06:58:12 2015 @@ -349,6 +349,9 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGL 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_ENGL 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 Modified: openoffice/trunk/main/sc/inc/helpids.h URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sc/inc/helpids.h?rev=1715605&r1=1715604&r2=1715605&view=diff ============================================================================== --- openoffice/trunk/main/sc/inc/helpids.h (original) +++ openoffice/trunk/main/sc/inc/helpids.h Sun Nov 22 06:58:12 2015 @@ -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" Modified: openoffice/trunk/main/sc/source/core/inc/interpre.hxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sc/source/core/inc/interpre.hxx?rev=1715605&r1=1715604&r2=1715605&view=diff ============================================================================== --- openoffice/trunk/main/sc/source/core/inc/interpre.hxx (original) +++ openoffice/trunk/main/sc/source/core/inc/interpre.hxx Sun Nov 22 06:58:12 2015 @@ -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 Modified: openoffice/trunk/main/sc/source/core/tool/interpr1.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sc/source/core/tool/interpr1.cxx?rev=1715605&r1=1715604&r2=1715605&view=diff ============================================================================== --- openoffice/trunk/main/sc/source/core/tool/interpr1.cxx (original) +++ openoffice/trunk/main/sc/source/core/tool/interpr1.cxx Sun Nov 22 06:58:12 2015 @@ -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() { Modified: openoffice/trunk/main/sc/source/core/tool/interpr4.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sc/source/core/tool/interpr4.cxx?rev=1715605&r1=1715604&r2=1715605&view=diff ============================================================================== --- openoffice/trunk/main/sc/source/core/tool/interpr4.cxx (original) +++ openoffice/trunk/main/sc/source/core/tool/interpr4.cxx Sun Nov 22 06:58:12 2015 @@ -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; } Modified: openoffice/trunk/main/sc/source/ui/src/scfuncs.src URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sc/source/ui/src/scfuncs.src?rev=1715605&r1=1715604&r2=1715605&view=diff ============================================================================== --- openoffice/trunk/main/sc/source/ui/src/scfuncs.src (original) +++ openoffice/trunk/main/sc/source/ui/src/scfuncs.src Sun Nov 22 06:58:12 2015 @@ -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) Modified: openoffice/trunk/main/sc/util/hidother.src URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sc/util/hidother.src?rev=1715605&r1=1715604&r2=1715605&view=diff ============================================================================== --- openoffice/trunk/main/sc/util/hidother.src (original) +++ openoffice/trunk/main/sc/util/hidother.src Sun Nov 22 06:58:12 2015 @@ -486,3 +486,6 @@ hidspecial HID_DAI_FUNC_DIFFWEEKS { He 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; };