build fix
[LibreOffice.git] / include / formula / errorcodes.hxx
blob2af9b1112de710de4ed78a0b209692f43585b8ba
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_FORMULA_ERRORCODES_HXX
21 #define INCLUDED_FORMULA_ERRORCODES_HXX
23 #include <rtl/math.hxx>
24 #include <sal/mathconf.h>
25 #include <sal/types.h>
27 // Store as 16-bits, since error values are stored in tokens and formula results,
28 // and that can matter
29 enum class FormulaError : sal_uInt16
31 NONE = 0,
33 IllegalChar = 501,
34 IllegalArgument = 502,
35 IllegalFPOperation = 503, // #NUM!
36 IllegalParameter = 504,
37 IllegalJump = 505,
38 Separator = 506,
39 Pair = 507,
40 PairExpected = 508,
41 OperatorExpected = 509,
42 VariableExpected = 510,
43 ParameterExpected = 511,
44 CodeOverflow = 512,
45 StringOverflow = 513,
46 StackOverflow = 514,
47 UnknownState = 515,
48 UnknownVariable = 516,
49 UnknownOpCode = 517,
50 UnknownStackVariable = 518,
51 NoValue = 519, // #VALUE!
52 UnknownToken = 520,
53 NoCode = 521, // #NULL!
54 CircularReference = 522,
55 NoConvergence = 523,
56 NoRef = 524, // #REF!
57 NoName = 525, // #NAME?
58 DoubleRef = 526,
59 // Not displayed, temporary for TrackFormulas,
60 // Cell depends on another cell that has FormulaError::CircularReference
61 TrackFromCircRef = 528,
62 // ScInterpreter internal: no numeric value but numeric queried. If this is
63 // set as mnStringNoValueError no error is generated but 0 returned.
64 CellNoValue = 529,
65 // Interpreter: needed AddIn not found
66 NoAddin = 530,
67 // Interpreter: needed Macro not found
68 NoMacro = 531,
69 // Interpreter: Division by zero
70 DivisionByZero = 532, // #DIV/0!
71 // Compiler: a non-simple (str,err,val) value was put in an array
72 NestedArray = 533,
73 // ScInterpreter internal: no numeric value but numeric queried. If this is
74 // temporarily (!) set as mnStringNoValueError, the error is generated and can
75 // be used to distinguish that condition from all other (inherited) errors. Do
76 // not use for anything else! Never push or inherit the error otherwise!
77 NotNumericString = 534,
78 // ScInterpreter internal: jump matrix already has a result at this position,
79 // do not overwrite in case of empty code path.
80 JumpMatHasResult = 535,
81 // ScInterpreter internal: (matrix) element is not a numeric value, i.e.
82 // string or empty, to be distinguished from the general FormulaError::NoValue NAN and not
83 // to be used as result.
84 ElementNaN = 536,
85 // ScInterpreter/ScFormulaCell internal: keep dirty, retry interpreting next
86 // round.
87 RetryCircular = 537,
88 // If matrix could not be allocated.
89 MatrixSize = 538,
91 // Interpreter: NA() not available condition, not a real error
92 NotAvailable = 0x7fff
95 /** Unconditionally construct a double value of NAN where the lower bits
96 represent an interpreter error code. */
97 inline double CreateDoubleError( FormulaError nErr )
99 sal_math_Double smVal;
100 ::rtl::math::setNan( &smVal.value );
101 smVal.nan_parts.fraction_lo = static_cast<unsigned>(nErr);
102 return smVal.value;
105 /** Recreate the error code of a coded double error, if any. */
106 inline FormulaError GetDoubleErrorValue( double fVal )
108 if ( ::rtl::math::isFinite( fVal ) )
109 return FormulaError::NONE;
110 if ( ::rtl::math::isInf( fVal ) )
111 return FormulaError::IllegalFPOperation; // normal INF
112 sal_uInt32 nErr = reinterpret_cast< sal_math_Double * >( &fVal)->nan_parts.fraction_lo;
113 if ( nErr & 0xffff0000 )
114 return FormulaError::NoValue; // just a normal NAN
115 if (!nErr)
116 // Another NAN, e.g. -nan(0x8000000000000) from calculating with -inf
117 return FormulaError::IllegalFPOperation;
118 // Any other error known to us as error code.
119 return (FormulaError)(nErr & 0x0000ffff);
122 /** Error values that are accepted as detailed "#ERRxxx!" constants.
124 Used in FormulaCompiler::GetErrorConstant() to prevent users from inventing
125 arbitrary values that already have or later might get a significant meaning.
127 inline bool isPublishedFormulaError( FormulaError nErr )
129 // Every value has to be handled explicitly, do not add a default case to
130 // let the compiler complain if a value is missing.
131 switch (nErr)
133 case FormulaError::NONE:
134 return false;
136 case FormulaError::IllegalChar:
137 case FormulaError::IllegalArgument:
138 case FormulaError::IllegalFPOperation:
139 case FormulaError::IllegalParameter:
140 case FormulaError::IllegalJump:
141 case FormulaError::Separator:
142 case FormulaError::Pair:
143 case FormulaError::PairExpected:
144 case FormulaError::OperatorExpected:
145 case FormulaError::VariableExpected:
146 case FormulaError::ParameterExpected:
147 case FormulaError::CodeOverflow:
148 case FormulaError::StringOverflow:
149 case FormulaError::StackOverflow:
150 case FormulaError::UnknownState:
151 case FormulaError::UnknownVariable:
152 case FormulaError::UnknownOpCode:
153 case FormulaError::UnknownStackVariable:
154 case FormulaError::NoValue:
155 case FormulaError::UnknownToken:
156 case FormulaError::NoCode:
157 case FormulaError::CircularReference:
158 case FormulaError::NoConvergence:
159 case FormulaError::NoRef:
160 case FormulaError::NoName:
161 case FormulaError::DoubleRef:
162 return true;
164 case FormulaError::TrackFromCircRef:
165 case FormulaError::CellNoValue:
166 return false;
168 case FormulaError::NoAddin:
169 case FormulaError::NoMacro:
170 case FormulaError::DivisionByZero:
171 case FormulaError::NestedArray:
172 return true;
174 case FormulaError::NotNumericString:
175 case FormulaError::JumpMatHasResult:
176 case FormulaError::ElementNaN:
177 case FormulaError::RetryCircular:
178 return false;
180 case FormulaError::MatrixSize:
181 return true;
183 case FormulaError::NotAvailable:
184 return false;
186 return false;
189 #endif // INCLUDED_FORMULA_ERRORCODES_HXX
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */