Author: damjan Date: Sun Dec 6 18:17:33 2015 New Revision: 1718196 URL: http://svn.apache.org/viewvc?rev=1718196&view=rev Log: #i126701# Patch for adding bit shift functions to 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=1718196&r1=1718195&r2=1718196&view=diff ============================================================================== --- openoffice/trunk/main/formula/inc/formula/compiler.hrc (original) +++ openoffice/trunk/main/formula/inc/formula/compiler.hrc Sun Dec 6 18:17:33 2015 @@ -400,10 +400,12 @@ #define SC_OPCODE_BITAND 404 #define SC_OPCODE_BITOR 405 #define SC_OPCODE_BITXOR 406 +#define SC_OPCODE_BITLSHIFT 407 +#define SC_OPCODE_BITRSHIFT 408 -#define SC_OPCODE_STOP_2_PAR 407 +#define SC_OPCODE_STOP_2_PAR 409 -#define SC_OPCODE_LAST_OPCODE_ID 406 /* last OpCode */ +#define SC_OPCODE_LAST_OPCODE_ID 408 /* 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=1718196&r1=1718195&r2=1718196&view=diff ============================================================================== --- openoffice/trunk/main/formula/inc/formula/opcode.hxx (original) +++ openoffice/trunk/main/formula/inc/formula/opcode.hxx Sun Dec 6 18:17:33 2015 @@ -397,6 +397,8 @@ enum OpCodeEnum ocBitAnd = SC_OPCODE_BITAND, ocBitOr = SC_OPCODE_BITOR, ocBitXor = SC_OPCODE_BITXOR, + ocBitLShift = SC_OPCODE_BITLSHIFT, + ocBitRShift = SC_OPCODE_BITRSHIFT, // 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=1718196&r1=1718195&r2=1718196&view=diff ============================================================================== --- openoffice/trunk/main/formula/source/core/resource/core_resource.src (original) +++ openoffice/trunk/main/formula/source/core/resource/core_resource.src Sun Dec 6 18:17:33 2015 @@ -352,6 +352,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGL String SC_OPCODE_BITAND { Text= "BITAND" ; }; String SC_OPCODE_BITOR { Text= "BITOR" ; }; String SC_OPCODE_BITXOR { Text= "BITXOR" ; }; + String SC_OPCODE_BITLSHIFT { Text= "BITLSHIFT" ; }; + String SC_OPCODE_BITRSHIFT { Text= "BITRSHIFT" ; }; /* BEGIN defined ERROR.TYPE() values. */ String SC_OPCODE_ERROR_NULL { Text = "#NULL!" ; }; @@ -692,6 +694,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGL String SC_OPCODE_BITAND { Text = "BITAND" ; }; String SC_OPCODE_BITOR { Text = "BITOR" ; }; String SC_OPCODE_BITXOR { Text = "BITXOR" ; }; + String SC_OPCODE_BITLSHIFT { Text= "BITLSHIFT" ; }; + String SC_OPCODE_BITRSHIFT { Text= "BITRSHIFT" ; }; /* BEGIN defined ERROR.TYPE() values. */ String SC_OPCODE_ERROR_NULL { Text = "#NULL!" ; }; @@ -1928,6 +1932,14 @@ Resource RID_STRLIST_FUNCTION_NAMES { Text [ en-US ] = "BITXOR"; }; + String SC_OPCODE_BITLSHIFT + { + Text [ en-US ] = "BITLSHIFT"; + }; + String SC_OPCODE_BITRSHIFT + { + Text [ en-US ] = "BITRSHIFT"; + }; /* 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=1718196&r1=1718195&r2=1718196&view=diff ============================================================================== --- openoffice/trunk/main/sc/inc/helpids.h (original) +++ openoffice/trunk/main/sc/inc/helpids.h Sun Dec 6 18:17:33 2015 @@ -777,3 +777,5 @@ #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" \ No newline at end of file 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=1718196&r1=1718195&r2=1718196&view=diff ============================================================================== --- openoffice/trunk/main/sc/source/core/inc/interpre.hxx (original) +++ openoffice/trunk/main/sc/source/core/inc/interpre.hxx Sun Dec 6 18:17:33 2015 @@ -149,6 +149,12 @@ public: BITOR, BITXOR }; + + enum bitShift + { + BITLSHIFT, + BITRSHIFT + }; }; DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter ) @@ -526,6 +532,9 @@ void ScBitAnd(); void ScBitOr(); void ScBitXor(); void ScBitArithmeticOps( bitOperations::bitArithmetic ); +void ScBitLShift(); +void ScBitRShift(); +void ScBitShiftOps(bitOperations::bitShift); // 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=1718196&r1=1718195&r2=1718196&view=diff ============================================================================== --- openoffice/trunk/main/sc/source/core/tool/interpr1.cxx (original) +++ openoffice/trunk/main/sc/source/core/tool/interpr1.cxx Sun Dec 6 18:17:33 2015 @@ -1207,6 +1207,48 @@ void ScInterpreter::ScBitArithmeticOps(b } } +void ScInterpreter::ScBitRShift() { + ScBitShiftOps(bitOperations::BITRSHIFT); +} + +void ScInterpreter::ScBitLShift() { + ScBitShiftOps(bitOperations::BITLSHIFT); +} + +void ScInterpreter::ScBitShiftOps(bitOperations::bitShift bitOp) { + if ( MustHaveParamCount( GetByte(), 2 ) ) + { + double n = ::rtl::math::approxFloor( GetDouble() ); + double val = ::rtl::math::approxFloor( GetDouble() ); + + if ( val < 0 ) + { + PushIllegalArgument(); + } + else + { + double result; + if (n < 0) + { + if (bitOp == bitOperations::BITLSHIFT) + result = (sal_uInt64) val >> (sal_uInt64) -n; + else + result = (sal_uInt64) val << (sal_uInt64) -n; + } + else if( n == 0) + result = val; + else + { + if (bitOp == bitOperations::BITLSHIFT) + result = (sal_uInt64) val << (sal_uInt64) n; + else + result = (sal_uInt64) val >> (sal_uInt64) n; + + } + PushDouble( result ); + } + } +} 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=1718196&r1=1718195&r2=1718196&view=diff ============================================================================== --- openoffice/trunk/main/sc/source/core/tool/interpr4.cxx (original) +++ openoffice/trunk/main/sc/source/core/tool/interpr4.cxx Sun Dec 6 18:17:33 2015 @@ -3769,6 +3769,8 @@ StackVar ScInterpreter::Interpret() case ocBitAnd : ScBitAnd(); break; case ocBitOr : ScBitOr(); break; case ocBitXor : ScBitXor(); break; + case ocBitLShift : ScBitLShift(); break; + case ocBitRShift : ScBitRShift(); 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=1718196&r1=1718195&r2=1718196&view=diff ============================================================================== --- openoffice/trunk/main/sc/source/ui/src/scfuncs.src (original) +++ openoffice/trunk/main/sc/source/ui/src/scfuncs.src Sun Dec 6 18:17:33 2015 @@ -9533,6 +9533,70 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 }; }; + Resource SC_OPCODE_BITLSHIFT + { + String 1 // Description + { + Text [ en-US ] = "Bitwise left shift of an integer value."; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_MATH; + 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 ] = "The value to be shifted. Positive integer." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "Shift" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The number of bits the first argument is to be shifted by." ; + }; + }; + + Resource SC_OPCODE_BITRSHIFT + { + String 1 // Description + { + Text [ en-US ] = "Bitwise right shift of an integer value."; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_MATH; + 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 ] = "The value to be shifted. Positive integer." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "Shift" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The number of bits the first argument is to be shifted by." ; + }; + }; + }; #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=1718196&r1=1718195&r2=1718196&view=diff ============================================================================== --- openoffice/trunk/main/sc/util/hidother.src (original) +++ openoffice/trunk/main/sc/util/hidother.src Sun Dec 6 18:17:33 2015 @@ -489,3 +489,5 @@ hidspecial HID_DAI_FUNC_ROT13 { He 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_BITLSHIFT { HelpID = HID_FUNC_BITLSHIFT; }; +hidspecial HID_FUNC_BITRSHIFT { HelpID = HID_FUNC_BITRSHIFT; };