diff options
author | Noel Grandin <noel@peralex.com> | 2016-09-14 15:22:20 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-09-23 15:22:38 +0000 |
commit | 3e22dfa5eb1ccebdc719a671d23bde7ccab256fb (patch) | |
tree | c3890b2a33cc298ad786c50a9d5879531fc6afc4 /include/formula | |
parent | 7d8196ea2f4ec3634dbad7367345e62c4ea9893d (diff) |
convert formula error codes to scoped enum
Change-Id: I5ff214bf1ec9031e30344bc125bc99916fd11bfb
Reviewed-on: https://gerrit.libreoffice.org/28897
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'include/formula')
-rw-r--r-- | include/formula/FormulaCompiler.hxx | 7 | ||||
-rw-r--r-- | include/formula/errorcodes.hxx | 106 | ||||
-rw-r--r-- | include/formula/token.hxx | 13 | ||||
-rw-r--r-- | include/formula/tokenarray.hxx | 12 |
4 files changed, 71 insertions, 67 deletions
diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx index 5d0e3daf64dc..e7268f62e85b 100644 --- a/include/formula/FormulaCompiler.hxx +++ b/include/formula/FormulaCompiler.hxx @@ -48,6 +48,7 @@ namespace com { namespace sun { namespace star { }}} class CharClass; +enum class FormulaError : sal_uInt16; namespace formula { @@ -219,7 +220,7 @@ public: */ OpCode GetEnglishOpCode( const OUString& rName ) const; - sal_uInt16 GetErrorConstant( const OUString& rName ) const; + FormulaError GetErrorConstant( const OUString& rName ) const; void EnableJumpCommandReorder( bool bEnable ); void EnableStopOnError( bool bEnable ); @@ -279,7 +280,7 @@ protected: virtual void fillFromAddInCollectionEnglishName( const NonConstOpCodeMapPtr& xMap ) const; virtual void fillAddInToken(::std::vector< css::sheet::FormulaOpCodeMapEntry >& _rVec, bool _bIsEnglish) const; - virtual void SetError(sal_uInt16 nError); + virtual void SetError(FormulaError nError); virtual FormulaTokenRef ExtendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2 ); virtual bool HandleExternalReference(const FormulaToken& _aToken); virtual bool HandleRange(); @@ -298,7 +299,7 @@ protected: Calc: ForceArray or ReferenceOrForceArray type. */ virtual bool IsForceArrayParameter( const FormulaToken* pToken, sal_uInt16 nParam ) const; - void AppendErrorConstant( OUStringBuffer& rBuffer, sal_uInt16 nError ) const; + void AppendErrorConstant( OUStringBuffer& rBuffer, FormulaError nError ) const; bool GetToken(); OpCode NextToken(); diff --git a/include/formula/errorcodes.hxx b/include/formula/errorcodes.hxx index e4732b3aed24..329be0d3b24d 100644 --- a/include/formula/errorcodes.hxx +++ b/include/formula/errorcodes.hxx @@ -24,99 +24,101 @@ #include <sal/mathconf.h> #include <sal/types.h> -namespace formula { +// Store as 16-bits, since error values are stored in tokens and formula results, +// and that can matter +enum class FormulaError : sal_uInt16 +{ + NONE = 0, -const sal_uInt16 errIllegalChar = 501; -const sal_uInt16 errIllegalArgument = 502; -const sal_uInt16 errIllegalFPOperation = 503; // #NUM! -const sal_uInt16 errIllegalParameter = 504; -const sal_uInt16 errIllegalJump = 505; -const sal_uInt16 errSeparator = 506; -const sal_uInt16 errPair = 507; -const sal_uInt16 errPairExpected = 508; -const sal_uInt16 errOperatorExpected = 509; -const sal_uInt16 errVariableExpected = 510; -const sal_uInt16 errParameterExpected = 511; -const sal_uInt16 errCodeOverflow = 512; -const sal_uInt16 errStringOverflow = 513; -const sal_uInt16 errStackOverflow = 514; -const sal_uInt16 errUnknownState = 515; -const sal_uInt16 errUnknownVariable = 516; -const sal_uInt16 errUnknownOpCode = 517; -const sal_uInt16 errUnknownStackVariable = 518; -const sal_uInt16 errNoValue = 519; // #VALUE! -const sal_uInt16 errUnknownToken = 520; -const sal_uInt16 errNoCode = 521; // #NULL! -const sal_uInt16 errCircularReference = 522; -const sal_uInt16 errNoConvergence = 523; -const sal_uInt16 errNoRef = 524; // #REF! -const sal_uInt16 errNoName = 525; // #NAME? -const sal_uInt16 errDoubleRef = 526; + IllegalChar = 501, + IllegalArgument = 502, + IllegalFPOperation = 503, // #NUM! + IllegalParameter = 504, + IllegalJump = 505, + Separator = 506, + Pair = 507, + PairExpected = 508, + OperatorExpected = 509, + VariableExpected = 510, + ParameterExpected = 511, + CodeOverflow = 512, + StringOverflow = 513, + StackOverflow = 514, + UnknownState = 515, + UnknownVariable = 516, + UnknownOpCode = 517, + UnknownStackVariable = 518, + NoValue = 519, // #VALUE! + UnknownToken = 520, + NoCode = 521, // #NULL! + CircularReference = 522, + NoConvergence = 523, + NoRef = 524, // #REF! + NoName = 525, // #NAME? + DoubleRef = 526, // Not displayed, temporary for TrackFormulas, -// Cell depends on another cell that has errCircularReference -const sal_uInt16 errTrackFromCircRef = 528; +// Cell depends on another cell that has FormulaError::CircularReference + TrackFromCircRef = 528, // ScInterpreter internal: no numeric value but numeric queried. If this is // set as mnStringNoValueError no error is generated but 0 returned. -const sal_uInt16 errCellNoValue = 529; + CellNoValue = 529, // Interpreter: needed AddIn not found -const sal_uInt16 errNoAddin = 530; + NoAddin = 530, // Interpreter: needed Macro not found -const sal_uInt16 errNoMacro = 531; + NoMacro = 531, // Interpreter: Division by zero -const sal_uInt16 errDivisionByZero = 532; // #DIV/0! + DivisionByZero = 532, // #DIV/0! // Compiler: a non-simple (str,err,val) value was put in an array -const sal_uInt16 errNestedArray = 533; + NestedArray = 533, // ScInterpreter internal: no numeric value but numeric queried. If this is // temporarily (!) set as mnStringNoValueError, the error is generated and can // be used to distinguish that condition from all other (inherited) errors. Do // not use for anything else! Never push or inherit the error otherwise! -const sal_uInt16 errNotNumericString = 534; + NotNumericString = 534, // ScInterpreter internal: jump matrix already has a result at this position, // do not overwrite in case of empty code path. -const sal_uInt16 errJumpMatHasResult = 535; + JumpMatHasResult = 535, // ScInterpreter internal: (matrix) element is not a numeric value, i.e. -// string or empty, to be distinguished from the general errNoValue NAN and not +// string or empty, to be distinguished from the general FormulaError::NoValue NAN and not // to be used as result. -const sal_uInt16 errElementNaN = 536; + ElementNaN = 536, // ScInterpreter/ScFormulaCell internal: keep dirty, retry interpreting next // round. -const sal_uInt16 errRetryCircular = 537; + RetryCircular = 537, // If matrix could not be allocated. -const sal_uInt16 errMatrixSize = 538; + MatrixSize = 538, // Interpreter: NA() not available condition, not a real error -const sal_uInt16 NOTAVAILABLE = 0x7fff; - + NotAvailable = 0x7fff +}; /** Unconditionally construct a double value of NAN where the lower bits represent an interpreter error code. */ -inline double CreateDoubleError( sal_uInt16 nErr ) +inline double CreateDoubleError( FormulaError nErr ) { sal_math_Double smVal; ::rtl::math::setNan( &smVal.value ); - smVal.nan_parts.fraction_lo = nErr; + smVal.nan_parts.fraction_lo = static_cast<unsigned>(nErr); return smVal.value; } /** Recreate the error code of a coded double error, if any. */ -inline sal_uInt16 GetDoubleErrorValue( double fVal ) +inline FormulaError GetDoubleErrorValue( double fVal ) { if ( ::rtl::math::isFinite( fVal ) ) - return 0; + return FormulaError::NONE; if ( ::rtl::math::isInf( fVal ) ) - return errIllegalFPOperation; // normal INF + return FormulaError::IllegalFPOperation; // normal INF sal_uInt32 nErr = reinterpret_cast< sal_math_Double * >( &fVal)->nan_parts.fraction_lo; if ( nErr & 0xffff0000 ) - return errNoValue; // just a normal NAN + return FormulaError::NoValue; // just a normal NAN if (!nErr) // Another NAN, e.g. -nan(0x8000000000000) from calculating with -inf - return errIllegalFPOperation; + return FormulaError::IllegalFPOperation; // Any other error known to us as error code. - return (sal_uInt16)(nErr & 0x0000ffff); + return (FormulaError)(nErr & 0x0000ffff); } -} // namespace formula - #endif // INCLUDED_FORMULA_ERRORCODES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/formula/token.hxx b/include/formula/token.hxx index e0ee1201095b..767fa212bc49 100644 --- a/include/formula/token.hxx +++ b/include/formula/token.hxx @@ -39,6 +39,7 @@ class ScJumpMatrix; class ScMatrix; struct ScComplexRefData; struct ScSingleRefData; +enum class FormulaError : sal_uInt16; namespace formula { @@ -161,8 +162,8 @@ public: virtual short* GetJump() const; virtual const OUString& GetExternal() const; virtual FormulaToken* GetFAPOrigToken() const; - virtual sal_uInt16 GetError() const; - virtual void SetError( sal_uInt16 ); + virtual FormulaError GetError() const; + virtual void SetError( FormulaError ); virtual const ScSingleRefData* GetSingleRef() const; virtual ScSingleRefData* GetSingleRef(); @@ -431,16 +432,16 @@ public: class FORMULA_DLLPUBLIC FormulaErrorToken : public FormulaToken { - sal_uInt16 nError; + FormulaError nError; public: - FormulaErrorToken( sal_uInt16 nErr ) : + FormulaErrorToken( FormulaError nErr ) : FormulaToken( svError ), nError( nErr) {} FormulaErrorToken( const FormulaErrorToken& r ) : FormulaToken( r ), nError( r.nError) {} virtual FormulaToken* Clone() const override { return new FormulaErrorToken(*this); } - virtual sal_uInt16 GetError() const override; - virtual void SetError( sal_uInt16 nErr ) override; + virtual FormulaError GetError() const override; + virtual void SetError( FormulaError nErr ) override; virtual bool operator==( const FormulaToken& rToken ) const override; }; diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx index b1d2deb3318d..1c6ed2256f79 100644 --- a/include/formula/tokenarray.hxx +++ b/include/formula/tokenarray.hxx @@ -123,7 +123,7 @@ protected: sal_uInt16 nLen; // Length of token array sal_uInt16 nRPN; // Length of RPN array sal_uInt16 nIndex; // Current step index - sal_uInt16 nError; // Error code + FormulaError nError; // Error code ScRecalcMode nMode; // Flags to indicate when to recalc this code bool bHyperLink; // If HYPERLINK() occurs in the formula. bool mbFromRangeName; // If this array originates from a named expression @@ -230,11 +230,11 @@ public: FormulaToken** GetArray() const { return pCode; } FormulaToken** GetCode() const { return pRPN; } - sal_uInt16 GetLen() const { return nLen; } - sal_uInt16 GetCodeLen() const { return nRPN; } - void Reset() { nIndex = 0; } - sal_uInt16 GetCodeError() const { return nError; } - void SetCodeError( sal_uInt16 n ) { nError = n; } + sal_uInt16 GetLen() const { return nLen; } + sal_uInt16 GetCodeLen() const { return nRPN; } + void Reset() { nIndex = 0; } + FormulaError GetCodeError() const { return nError; } + void SetCodeError( FormulaError n ) { nError = n; } void SetHyperLink( bool bVal ) { bHyperLink = bVal; } bool IsHyperLink() const { return bHyperLink; } |