xref: /aoo41x/main/sc/source/core/inc/interpre.hxx (revision 0a2b7546)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef SC_INTERPRE_HXX
23 #define SC_INTERPRE_HXX
24 
25 #include <math.h>
26 #include <rtl/math.hxx>
27 #include "formula/errorcodes.hxx"
28 #include "cell.hxx"
29 #include "scdll.hxx"
30 #include "document.hxx"
31 #include "scmatrix.hxx"
32 
33 #include <math.h>
34 #include <map>
35 
36 // STLport definitions
37 // This works around some issues with Boost
38 //
39 #ifdef WNT
40 #define _STLP_HAS_NATIVE_FLOAT_ABS
41 #endif
42 
43 // Math policy definitions for Boost
44 // This header must be included before including any Boost
45 // math function.
46 //
47 #ifndef BOOST_MATH_OVERFLOW_ERROR_POLICY
48 #define BOOST_MATH_OVERFLOW_ERROR_POLICY errno_on_error
49 #endif
50 
51 class ScDocument;
52 class SbxVariable;
53 class ScBaseCell;
54 class ScFormulaCell;
55 class SvNumberFormatter;
56 class ScDBRangeBase;
57 struct MatrixDoubleOp;
58 struct ScQueryParam;
59 struct ScDBQueryParamBase;
60 
61 struct ScCompare
62 {
63     double  nVal[2];
64     String* pVal[2];
65     sal_Bool    bVal[2];
66     sal_Bool    bEmpty[2];
ScCompareScCompare67         ScCompare( String* p1, String* p2 )
68         {
69             pVal[ 0 ] = p1;
70             pVal[ 1 ] = p2;
71             bEmpty[0] = sal_False;
72             bEmpty[1] = sal_False;
73         }
74 };
75 
76 struct ScCompareOptions
77 {
78     ScQueryEntry        aQueryEntry;
79     bool                bRegEx;
80     bool                bMatchWholeCell;
81     bool                bIgnoreCase;
82 
83                         ScCompareOptions( ScDocument* pDoc, const ScQueryEntry& rEntry, bool bReg );
84 private:
85                         // Not implemented, prevent usage.
86                         ScCompareOptions();
87                         ScCompareOptions( const ScCompareOptions & );
88      ScCompareOptions&  operator=( const ScCompareOptions & );
89 };
90 
91 class ScToken;
92 
93 #define MAXSTACK      (4096 / sizeof(formula::FormulaToken*))
94 
95 class ScTokenStack
96 {
97 public:
98     DECL_FIXEDMEMPOOL_NEWDEL( ScTokenStack )
99     formula::FormulaToken* pPointer[ MAXSTACK ];
100 };
101 
102 enum ScIterFunc
103 {
104     ifSUM,     // Sum
105     ifSUMSQ,   // Sum squares
106     ifPRODUCT, // Product
107     ifAVERAGE, // Average
108     ifCOUNT,   // Count
109     ifCOUNT2,  // Count non-empty
110     ifMIN,     // Minimum
111     ifMAX      // Maximum
112 };
113 
114 enum ScIterFuncIf
115 {
116     ifSUMIF,    // Conditional sum
117     ifAVERAGEIF // Conditional average
118 };
119 
120 enum ScIterFuncIfs
121 {
122     ifSUMIFS,     // Multi-Conditional sum
123     ifAVERAGEIFS, // Multi-Conditional average
124     ifCOUNTIFS    // Multi-Conditional count
125 };
126 
127 struct FormulaTokenRef_less
128 {
operator ()FormulaTokenRef_less129     bool operator () ( const formula::FormulaConstTokenRef& r1, const formula::FormulaConstTokenRef& r2 ) const
130         { return &r1 < &r2; }
131 };
132 typedef ::std::map< const formula::FormulaConstTokenRef, formula::FormulaTokenRef, FormulaTokenRef_less> ScTokenMatrixMap;
133 
134 class ScInterpreter
135 {
136     // distibution function objects need the GetxxxDist methods
137     friend class ScGammaDistFunction;
138     friend class ScBetaDistFunction;
139     friend class ScTDistFunction;
140     friend class ScFDistFunction;
141     friend class ScChiDistFunction;
142     friend class ScChiSqDistFunction;
143 
144 public:
145     DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter )
146 
147     static void GlobalExit();           // aus ScGlobal::Clear() gerufen
148 
149     /// Could string be a regular expression?
150     /// If pDoc!=NULL the document options are taken into account and if
151     /// RegularExpressions are disabled the function returns sal_False regardless
152     /// of the string content.
153     static sal_Bool MayBeRegExp( const String& rStr, const ScDocument* pDoc );
154 
155     /// Fail safe division, returning an errDivisionByZero coded into a double
156     /// if denominator is 0.0
157     static inline double div( const double& fNumerator, const double& fDenominator );
158 
159     ScMatrixRef GetNewMat(SCSIZE nC, SCSIZE nR);
160 private:
161     static ScTokenStack*    pGlobalStack;
162     static sal_Bool         bGlobalStackInUse;
163 
164     formula::FormulaTokenIterator aCode;
165     ScAddress   aPos;
166     ScTokenArray& rArr;
167     ScDocument* pDok;
168     formula::FormulaTokenRef  xResult;
169     ScJumpMatrix*   pJumpMatrix;        // currently active array condition, if any
170     ScTokenMatrixMap* pTokenMatrixMap;  // map ScToken* to formula::FormulaTokenRef if in array condition
171     ScFormulaCell* pMyFormulaCell;      // the cell of this formula expression
172     SvNumberFormatter* pFormatter;
173 
174     const formula::FormulaToken*
175                 pCur;                // current token
176     ScToken*    pLastStackRefToken;     // i120962: current valid reference token
177     bool        bRefFunc;               // i120962: is a reference function
178     String      aTempStr;               // for GetString()
179     ScTokenStack* pStackObj;            // contains the stacks
180     formula::FormulaToken**   pStack;                 // the current stack
181     sal_uInt16      nGlobalError;           // global (local to this formula expression) error
182     sal_uInt16      sp;                     // stack pointer
183     sal_uInt16      maxsp;                  // the maximal used stack pointer
184     sal_uLong       nFuncFmtIndex;          // NumberFormatIndex of a function
185     sal_uLong       nCurFmtIndex;           // current NumberFormatIndex
186     sal_uLong       nRetFmtIndex;           // NumberFormatIndex of an expression, if any
187     short       nFuncFmtType;           // NumberFormatType of a function
188     short       nCurFmtType;            // current NumberFormatType
189     short       nRetFmtType;            // NumberFormatType of an expression
190     sal_uInt16      mnStringNoValueError;   // the error set in ConvertStringToValue() if no value
191     sal_Bool        glSubTotal;             // flag for subtotal functions
192     sal_uInt8        cPar;                   // current count of parameters
193     sal_Bool        bCalcAsShown;           // precision as shown
194     sal_Bool        bMatrixFormula;         // formula cell is a matrix formula
195 
196 //---------------------------------Funktionen in interpre.cxx---------
197 // nMust <= nAct <= nMax ? ok : PushError
198 inline sal_Bool MustHaveParamCount( short nAct, short nMust );
199 inline sal_Bool MustHaveParamCount( short nAct, short nMust, short nMax );
200 inline sal_Bool MustHaveParamCountMin( short nAct, short nMin );
201 void PushParameterExpected();
202 void PushIllegalParameter();
203 void PushIllegalArgument();
204 void PushNoValue();
205 void PushNA();
206 //-------------------------------------------------------------------------
207 // Funktionen fuer den Zugriff auf das Document
208 //-------------------------------------------------------------------------
209 void ReplaceCell( ScAddress& );     // for TableOp
210 void ReplaceCell( SCCOL& rCol, SCROW& rRow, SCTAB& rTab );  // for TableOp
211 sal_Bool IsTableOpInRange( const ScRange& );
212 sal_uLong GetCellNumberFormat( const ScAddress&, const ScBaseCell* );
213 double ConvertStringToValue( const String& );
214 double GetCellValue( const ScAddress&, const ScBaseCell* );
215 double GetCellValueOrZero( const ScAddress&, const ScBaseCell* );
216 double GetValueCellValue( const ScAddress&, const ScValueCell* );
GetCell(const ScAddress & rPos)217 ScBaseCell* GetCell( const ScAddress& rPos )
218     { return pDok->GetCell( rPos ); }
219 void GetCellString( String& rStr, const ScBaseCell* pCell );
GetCellErrCode(const ScBaseCell * pCell)220 inline sal_uInt16 GetCellErrCode( const ScBaseCell* pCell )
221     { return pCell ? pCell->GetErrorCode() : 0; }
GetCellType(const ScBaseCell * pCell)222 inline CellType GetCellType( const ScBaseCell* pCell )
223     { return pCell ? pCell->GetCellType() : CELLTYPE_NONE; }
224 /// Really empty or inherited emptiness.
HasCellEmptyData(const ScBaseCell * pCell)225 inline sal_Bool HasCellEmptyData( const ScBaseCell* pCell )
226     { return pCell ? pCell->HasEmptyData() : sal_True; }
227 /// This includes inherited emptiness, which usually is regarded as value!
HasCellValueData(const ScBaseCell * pCell)228 inline sal_Bool HasCellValueData( const ScBaseCell* pCell )
229     { return pCell ? pCell->HasValueData() : sal_False; }
230 /// Not empty and not value.
HasCellStringData(const ScBaseCell * pCell)231 inline sal_Bool HasCellStringData( const ScBaseCell* pCell )
232     { return pCell ? pCell->HasStringData() : sal_False; }
233 
234 sal_Bool CreateDoubleArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
235                      SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
236 sal_Bool CreateStringArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
237                      SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
238 sal_Bool CreateCellArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
239                    SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
240 
241 //-----------------------------------------------------------------------------
242 // Stack operations
243 //-----------------------------------------------------------------------------
244 
245 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
246     passed is not formula::FormulaErrorToken.
247     Increments RefCount of the original token if not substituted. */
248 void Push( formula::FormulaToken& r );
249 
250 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
251     Used to push RPN tokens or from within Push() or tokens that are already
252     explicit formula::FormulaErrorToken. Increments RefCount. */
253 void PushWithoutError( formula::FormulaToken& r );
254 
255 /** Clones the token to be pushed or substitutes with formula::FormulaErrorToken if
256     nGlobalError is set and the token passed is not formula::FormulaErrorToken. */
257 void PushTempToken( const formula::FormulaToken& );
258 
259 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
260     passed is not formula::FormulaErrorToken.
261     Increments RefCount of the original token if not substituted.
262     ATTENTION! The token had to be allocated with `new' and must not be used
263     after this call if no RefCount was set because possibly it gets immediately
264     deleted in case of an errStackOverflow or if substituted with formula::FormulaErrorToken! */
265 void PushTempToken( formula::FormulaToken* );
266 
267 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
268     Used to push tokens from within PushTempToken() or tokens that are already
269     explicit formula::FormulaErrorToken. Increments RefCount.
270     ATTENTION! The token had to be allocated with `new' and must not be used
271     after this call if no RefCount was set because possibly it gets immediately
272     decremented again and thus deleted in case of an errStackOverflow! */
273 void PushTempTokenWithoutError( formula::FormulaToken* );
274 
275 /** If nGlobalError is set push formula::FormulaErrorToken.
276     If nGlobalError is not set do nothing.
277     Used in PushTempToken() and alike to simplify handling.
278     @return: <TRUE/> if nGlobalError. */
IfErrorPushError()279 inline bool IfErrorPushError()
280 {
281     if (nGlobalError)
282     {
283         PushTempTokenWithoutError( new formula::FormulaErrorToken( nGlobalError));
284         return true;
285     }
286     return false;
287 }
288 
289 /** Obtain cell result / content from address and push as temp token.
290     bDisplayEmptyAsString is passed to ScEmptyCell in case of an empty cell
291     result. Also obtain number format and type if _both_, type and index
292     pointer, are not NULL. */
293 void PushCellResultToken( bool bDisplayEmptyAsString, const ScAddress & rAddress,
294         short * pRetTypeExpr, sal_uLong * pRetIndexExpr );
295 
296 formula::FormulaTokenRef PopToken();
297 void Pop();
298 void PopError();
299 double PopDouble();
300 const String& PopString();
301 void ValidateRef( const ScSingleRefData & rRef );
302 void ValidateRef( const ScComplexRefData & rRef );
303 void ValidateRef( const ScRefList & rRefList );
304 void SingleRefToVars( const ScSingleRefData & rRef, SCCOL & rCol, SCROW & rRow, SCTAB & rTab );
305 void PopSingleRef( ScAddress& );
306 void PopSingleRef(SCCOL& rCol, SCROW &rRow, SCTAB& rTab);
307 void DoubleRefToRange( const ScComplexRefData&, ScRange&, sal_Bool bDontCheckForTableOp = sal_False );
308 /** If formula::StackVar formula::svDoubleRef pop ScDoubleRefToken and return values of
309     ScComplexRefData.
310     Else if StackVar svRefList return values of the ScComplexRefData where
311     rRefInList is pointing to. rRefInList is incremented. If rRefInList was the
312     last element in list pop ScRefListToken and set rRefInList to 0, else
313     rParam is incremented (!) to allow usage as in
314     while(nParamCount--) PopDoubleRef(aRange,nParamCount,nRefInList);
315   */
316 void PopDoubleRef( ScRange & rRange, short & rParam, size_t & rRefInList );
317 void PopDoubleRef( ScRange&, sal_Bool bDontCheckForTableOp = sal_False );
318 void DoubleRefToVars( const ScToken* p,
319         SCCOL& rCol1, SCROW &rRow1, SCTAB& rTab1,
320         SCCOL& rCol2, SCROW &rRow2, SCTAB& rTab2,
321         sal_Bool bDontCheckForTableOp = sal_False );
322 ScDBRangeBase* PopDoubleRef();
323 void PopDoubleRef(SCCOL& rCol1, SCROW &rRow1, SCTAB& rTab1,
324                           SCCOL& rCol2, SCROW &rRow2, SCTAB& rTab2,
325                           sal_Bool bDontCheckForTableOp = sal_False );
326 sal_Bool PopDoubleRefOrSingleRef( ScAddress& rAdr );
327 void PopDoubleRefPushMatrix();
328 // If MatrixFormula: convert formula::svDoubleRef to svMatrix, create JumpMatrix.
329 // Else convert area reference parameters marked as ForceArray to array.
330 // Returns sal_True if JumpMatrix created.
331 bool ConvertMatrixParameters();
332 inline void MatrixDoubleRefToMatrix();      // if MatrixFormula: PopDoubleRefPushMatrix
333 // If MatrixFormula or ForceArray: ConvertMatrixParameters()
334 inline bool MatrixParameterConversion();
335 ScMatrixRef PopMatrix();
336 //void PushByte(sal_uInt8 nVal);
337 void PushDouble(double nVal);
338 void PushInt( int nVal );
339 void PushStringBuffer( const sal_Unicode* pString );
340 void PushString( const String& rString );
341 void PushSingleRef(SCCOL nCol, SCROW nRow, SCTAB nTab);
342 void PushDoubleRef(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
343                                  SCCOL nCol2, SCROW nRow2, SCTAB nTab2);
344 void PushMatrix(ScMatrix* pMat);
345 void PushError( sal_uInt16 nError );
346 /// Raw stack type without default replacements.
347 formula::StackVar GetRawStackType();
348 /// Stack type with replacement of defaults, e.g. svMissing and formula::svEmptyCell will result in formula::svDouble.
349 formula::StackVar GetStackType();
350 // peek StackType of Parameter, Parameter 1 == TOS, 2 == TOS-1, ...
351 formula::StackVar GetStackType( sal_uInt8 nParam );
GetByte()352 sal_uInt8 GetByte() { return cPar; }
353 // generiert aus DoubleRef positionsabhaengige SingleRef
354 sal_Bool DoubleRefToPosSingleRef( const ScRange& rRange, ScAddress& rAdr );
355 double GetDouble();
356 double GetDoubleWithDefault(double nDefault);
357 sal_Bool IsMissing();
GetBool()358 sal_Bool GetBool() { return GetDouble() != 0.0; }
359 const String& GetString();
360 // pop matrix and obtain one element, upper left or according to jump matrix
361 ScMatValType GetDoubleOrStringFromMatrix( double& rDouble, String& rString );
362 ScMatrixRef CreateMatrixFromDoubleRef( const formula::FormulaToken* pToken,
363         SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
364         SCCOL nCol2, SCROW nRow2, SCTAB nTab2 );
365 inline ScTokenMatrixMap& GetTokenMatrixMap();
366 ScTokenMatrixMap* CreateTokenMatrixMap();
367 ScMatrixRef GetMatrix();
368 void ScTableOp();                                       // Mehrfachoperationen
369 void ScErrCell();                                       // Sonderbehandlung
370                                                         // Fehlerzelle
371 //-----------------------------allgemeine Hilfsfunktionen
372 void SetMaxIterationCount(sal_uInt16 n);
CurFmtToFuncFmt()373 inline void CurFmtToFuncFmt()
374     { nFuncFmtType = nCurFmtType; nFuncFmtIndex = nCurFmtIndex; }
375 // Check for String overflow of rResult+rAdd and set error and erase rResult
376 // if so. Return sal_True if ok, sal_False if overflow
377 inline sal_Bool CheckStringResultLen( String& rResult, const String& rAdd );
378 // Set error according to rVal, and set rVal to 0.0 if there was an error.
379 inline void TreatDoubleError( double& rVal );
380 // Lookup using ScLookupCache, @returns sal_True if found and result address
381 bool LookupQueryWithCache( ScAddress & o_rResultPos,
382         const ScQueryParam & rParam ) const;
383 
384 //---------------------------------Funktionen in interpr1.cxx---------
385 void ScIfJump();
386 void ScChoseJump();
387 
388 // Be sure to only call this if pStack[sp-nStackLevel] really contains a
389 // ScJumpMatrixToken, no further checks are applied!
390 // Returns true if last jump was executed and result matrix pushed.
391 bool JumpMatrix( short nStackLevel );
392 
393 /** @param pOptions
394         NULL means case sensitivity document option is to be used!
395  */
396 double CompareFunc( const ScCompare& rComp, ScCompareOptions* pOptions = NULL );
397 double Compare();
398 /** @param pOptions
399         NULL means case sensitivity document option is to be used!
400  */
401 ScMatrixRef CompareMat( ScCompareOptions* pOptions = NULL );
402 ScMatrixRef QueryMat( ScMatrix* pMat, ScCompareOptions& rOptions );
403 void ScEqual();
404 void ScNotEqual();
405 void ScLess();
406 void ScGreater();
407 void ScLessEqual();
408 void ScGreaterEqual();
409 void ScAnd();
410 void ScOr();
411 void ScXor();
412 void ScNot();
413 void ScNeg();
414 void ScPercentSign();
415 void ScIntersect();
416 void ScRangeFunc();
417 void ScUnionFunc();
418 void ScPi();
419 void ScRandom();
420 void ScTrue();
421 void ScFalse();
422 void ScDeg();
423 void ScRad();
424 void ScSin();
425 void ScCos();
426 void ScTan();
427 void ScCot();
428 void ScArcSin();
429 void ScArcCos();
430 void ScArcTan();
431 void ScArcCot();
432 void ScSinHyp();
433 void ScCosHyp();
434 void ScTanHyp();
435 void ScCotHyp();
436 void ScArcSinHyp();
437 void ScArcCosHyp();
438 void ScArcTanHyp();
439 void ScArcCotHyp();
440 void ScCosecant();
441 void ScSecant();
442 void ScCosecantHyp();
443 void ScSecantHyp();
444 void ScExp();
445 void ScLn();
446 void ScLog10();
447 void ScSqrt();
448 void ScIsEmpty();
449 short IsString();
450 void ScIsString();
451 void ScIsNonString();
452 void ScIsLogical();
453 void ScType();
454 void ScCell();
455 void ScIsRef();
456 void ScIsValue();
457 void ScIsFormula();
458 void ScFormula();
459 void ScRoman();
460 void ScArabic();
461 void ScIsNV();
462 void ScIsErr();
463 void ScIsError();
464 short IsEven();
465 void ScIsEven();
466 void ScIsOdd();
467 void ScN();
468 void ScCode();
469 void ScTrim();
470 void ScUpper();
471 void ScPropper();
472 void ScLower();
473 void ScLen();
474 void ScT();
475 void ScValue();
476 void ScClean();
477 void ScChar();
478 void ScJis();
479 void ScAsc();
480 void ScUnicode();
481 void ScUnichar();
482 void ScMin( sal_Bool bTextAsZero = sal_False );
483 void ScMax( sal_Bool bTextAsZero = sal_False );
484 double IterateParameters( ScIterFunc, sal_Bool bTextAsZero = sal_False );
485 void ScSumSQ();
486 void ScSum();
487 void ScProduct();
488 void ScAverage( sal_Bool bTextAsZero = sal_False );
489 void ScCount();
490 void ScCount2();
491 void GetStVarParams( double& rVal, double& rValCount, sal_Bool bTextAsZero = sal_False );
492 void ScVar( sal_Bool bTextAsZero = sal_False );
493 void ScVarP( sal_Bool bTextAsZero = sal_False );
494 void ScStDev( sal_Bool bTextAsZero = sal_False );
495 void ScStDevP( sal_Bool bTextAsZero = sal_False );
496 void ScColumns();
497 void ScRows();
498 void ScTables();
499 void ScColumn();
500 void ScRow();
501 void ScTable();
502 void ScMatch();
503 double IterateParametersIf( ScIterFuncIf );
504 void ScCountIf();
505 void ScSumIf();
506 void ScAverageIf();
507 double IterateParametersIfs( ScIterFuncIfs );
508 void ScSumIfs();
509 void ScAverageIfs();
510 void ScCountIfs();
511 void ScCountEmptyCells();
512 void ScLookup();
513 void ScHLookup();
514 void ScVLookup();
515 void ScSubTotal();
516 
517 // If upon call rMissingField==sal_True then the database field parameter may be
518 // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the
519 // value 0.0 or being exactly the entire database range reference (old SO
520 // compatibility). If this was the case then rMissingField is set to sal_True upon
521 // return. If rMissingField==sal_False upon call all "missing cases" are considered
522 // to be an error.
523 ScDBQueryParamBase* GetDBParams( sal_Bool& rMissingField );
524 
525 void DBIterator( ScIterFunc );
526 void ScDBSum();
527 void ScDBCount();
528 void ScDBCount2();
529 void ScDBAverage();
530 void ScDBGet();
531 void ScDBMax();
532 void ScDBMin();
533 void ScDBProduct();
534 void GetDBStVarParams( double& rVal, double& rValCount );
535 void ScDBStdDev();
536 void ScDBStdDevP();
537 void ScDBVar();
538 void ScDBVarP();
539 void ScIndirect();
540 void ScAddressFunc();
541 void ScOffset();
542 void ScIndex();
543 void ScMultiArea();
544 void ScAreas();
545 void ScCurrency();
546 void ScReplace();
547 void ScFixed();
548 void ScFind();
549 void ScExact();
550 void ScLeft();
551 void ScRight();
552 void ScSearch();
553 void ScMid();
554 void ScText();
555 void ScSubstitute();
556 void ScRept();
557 void ScConcat();
558 void ScExternal();
559 void ScMissing();
560 void ScMacro();
561 sal_Bool SetSbxVariable( SbxVariable* pVar, const ScAddress& );
562 sal_Bool SetSbxVariable( SbxVariable* pVar, SCCOL nCol, SCROW nRow, SCTAB nTab );
563 void ScErrorType();
564 void ScDBArea();
565 void ScColRowNameAuto();
566 void ScExternalRef();
567 void ScGetPivotData();
568 void ScHyperLink();
569 void ScBahtText();
570 void ScTTT();
571 
572 //----------------Funktionen in interpr2.cxx---------------
573 
574 /** Obtain the date serial number for a given date.
575     @param bStrict
576         If sal_False, nYear < 100 takes the two-digit year setting into account,
577         and rollover of invalid calendar dates takes place, e.g. 1999-02-31 =>
578         1999-03-03.
579         If sal_True, the date passed must be a valid Gregorian calendar date. No
580         two-digit expanding or rollover is done.
581  */
582 double GetDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, bool bStrict );
583 
584 void ScGetActDate();
585 void ScGetActTime();
586 void ScGetYear();
587 void ScGetMonth();
588 void ScGetDay();
589 void ScGetDayOfWeek();
590 void ScGetWeekOfYear();
591 void ScEasterSunday();
592 void ScGetHour();
593 void ScGetMin();
594 void ScGetSec();
595 void ScPlusMinus();
596 void ScAbs();
597 void ScInt();
598 void ScEven();
599 void ScOdd();
600 void ScCeil();
601 void ScFloor();
602 void RoundNumber( rtl_math_RoundingMode eMode );
603 void ScRound();
604 void ScRoundUp();
605 void ScRoundDown();
606 void ScGetDateValue();
607 void ScGetTimeValue();
608 void ScArcTan2();
609 void ScLog();
610 void ScGetDate();
611 void ScGetTime();
612 void ScGetDiffDate();
613 void ScGetDiffDate360();
614 void ScCurrent();
615 void ScStyle();
616 void ScDde();
617 void ScBase();
618 void ScDecimal();
619 void ScConvert();
620 void ScEuroConvert();
621 
622 //----------------------- Finanzfunktionen ------------------------------------
623 void ScNPV();
624 void ScIRR();
625 void ScMIRR();
626 void ScISPMT();
627 
628 double ScGetBw(double fZins, double fZzr, double fRmz,
629                       double fZw, double fF);
630 void ScBW();
631 void ScDIA();
632 double ScGetGDA(double fWert, double fRest, double fDauer,
633                        double fPeriode, double fFaktor);
634 void ScGDA();
635 void ScGDA2();
636 double ScInterVDB(double fWert,double fRest,double fDauer,double fDauer1,
637                 double fPeriode,double fFaktor);
638 void ScVDB();
639 void ScLaufz();
640 void ScLIA();
641 double ScGetRmz(double fZins, double fZzr, double fBw,
642                        double fZw, double fF);
643 void ScRMZ();
644 void ScZGZ();
645 double ScGetZw(double fZins, double fZzr, double fRmz,
646                       double fBw, double fF);
647 void ScZW();
648 void ScZZR();
649 bool RateIteration(double fNper, double fPayment, double fPv,
650                                 double fFv, double fPayType, double& fGuess);
651 void ScZins();
652 double ScGetZinsZ(double fZins, double fZr, double fZzr, double fBw,
653                          double fZw, double fF, double& fRmz);
654 void ScZinsZ();
655 void ScKapz();
656 void ScKumZinsZ();
657 void ScKumKapZ();
658 void ScEffektiv();
659 void ScNominal();
660 void ScMod();
661 void ScBackSolver();
662 void ScIntercept();
663 //-------------------------Funktionen in interpr5.cxx--------------------------
664 double ScGetGCD(double fx, double fy);
665 void ScGCD();
666 void ScLCM();
667 void ScPower();
668 void ScAmpersand();
669 void ScAdd();
670 void ScSub();
671 void ScMul();
672 void ScDiv();
673 void ScPow();
674 //-------------------------- Matrixfunktionen ---------------------------------
675 
676 void ScMatValue();
677 void MEMat(ScMatrix* mM, SCSIZE n);
678 void ScMatDet();
679 void ScMatInv();
680 void ScMatMult();
681 void ScMatTrans();
682 void ScEMat();
683 void ScMatRef();
684 ScMatrixRef MatConcat(ScMatrix* pMat1, ScMatrix* pMat2);
685 void ScSumProduct();
686 void ScSumX2MY2();
687 void ScSumX2DY2();
688 void ScSumXMY2();
689 void ScGrowth();
690 bool CalculateSkew(double& fSum,double& fCount,double& vSum,std::vector<double>& values);
691 void CalculateSlopeIntercept(sal_Bool bSlope);
692 void CalculateSmallLarge(sal_Bool bSmall);
693 void CalculatePearsonCovar(sal_Bool _bPearson,sal_Bool _bStexy);
694 bool CalculateTest( sal_Bool _bTemplin
695                    ,const SCSIZE nC1, const SCSIZE nC2,const SCSIZE nR1,const SCSIZE nR2
696                    ,const ScMatrixRef& pMat1,const ScMatrixRef& pMat2
697                    ,double& fT,double& fF);
698 void CalculateLookup(sal_Bool HLookup);
699 bool FillEntry(ScQueryEntry& rEntry);
700 void CalculateAddSub(sal_Bool _bSub);
701 void CalculateTrendGrowth(bool _bGrowth);
702 void CalulateRGPRKP(bool _bRKP);
703 void CalculateSumX2MY2SumX2DY2(sal_Bool _bSumX2DY2);
704 void CalculateMatrixValue(const ScMatrix* pMat,SCSIZE nC,SCSIZE nR);
705 bool CheckMatrix(bool _bLOG,sal_uInt8& nCase,SCSIZE& nCX,SCSIZE& nCY,SCSIZE& nRX,SCSIZE& nRY,SCSIZE& M,SCSIZE& N,ScMatrixRef& pMatX,ScMatrixRef& pMatY);
706 void ScRGP();
707 void ScRKP();
708 void ScForecast();
709 //------------------------- Functions in interpr3.cxx -------------------------
710 void ScNoName();
711 void ScBadName();
712 // Statistik:
713 double phi(double x);
714 double integralPhi(double x);
715 double taylor(double* pPolynom, sal_uInt16 nMax, double x);
716 double gauss(double x);
717 double gaussinv(double x);
718 double GetBetaDist(double x, double alpha, double beta);  //cumulative distribution function
719 double GetBetaDistPDF(double fX, double fA, double fB); //probability density function)
720 double GetChiDist(double fChi, double fDF);     // for LEGACY.CHIDIST, returns right tail
721 double GetChiSqDistCDF(double fX, double fDF);  // for CHISQDIST, returns left tail
722 double GetChiSqDistPDF(double fX, double fDF);  // probability density function
723 double GetFDist(double x, double fF1, double fF2);
724 double GetTDist(double T, double fDF);
725 double Fakultaet(double x);
726 double BinomKoeff(double n, double k);
727 double GetGamma(double x);
728 double GetLogGamma(double x);
729 double GetBeta(double fAlpha, double fBeta);
730 double GetLogBeta(double fAlpha, double fBeta);
731 double GetBinomDistPMF(double x, double n, double p); //probability mass function
732 void ScLogGamma();
733 void ScGamma();
734 void ScPhi();
735 void ScGauss();
736 void ScStdNormDist();
737 void ScFisher();
738 void ScFisherInv();
739 void ScFact();
740 void ScNormDist();
741 void ScGammaDist();
742 void ScGammaInv();
743 void ScExpDist();
744 void ScBinomDist();
745 void ScPoissonDist();
746 void ScKombin();
747 void ScKombin2();
748 void ScVariationen();
749 void ScVariationen2();
750 void ScB();
751 void ScHypGeomDist();
752 void ScLogNormDist();
753 void ScLogNormInv();
754 void ScTDist();
755 void ScFDist();
756 void ScChiDist();   // for LEGACY.CHIDIST, returns right tail
757 void ScChiSqDist(); // returns left tail or density
758 void ScChiSqInv(); //invers to CHISQDIST
759 void ScWeibull();
760 void ScBetaDist();
761 void ScFInv();
762 void ScTInv();
763 void ScChiInv();
764 void ScBetaInv();
765 void ScCritBinom();
766 void ScNegBinomDist();
767 void ScKurt();
768 void ScHarMean();
769 void ScGeoMean();
770 void ScStandard();
771 void ScSkew();
772 void ScMedian();
773 double GetMedian( ::std::vector<double> & rArray );
774 double GetPercentile( ::std::vector<double> & rArray, double fPercentile );
775 void GetNumberSequenceArray( sal_uInt8 nParamCount, ::std::vector<double>& rArray );
776 void GetSortArray(sal_uInt8 nParamCount, ::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
777 void QuickSort(::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
778 void ScModalValue();
779 void ScAveDev();
780 void ScDevSq();
781 void ScZTest();
782 void ScTTest();
783 void ScFTest();
784 void ScChiTest();
785 void ScRank();
786 void ScPercentile();
787 void ScPercentrank();
788 void ScLarge();
789 void ScSmall();
790 void ScFrequency();
791 void ScQuartile();
792 void ScNormInv();
793 void ScSNormInv();
794 void ScConfidence();
795 void ScTrimMean();
796 void ScProbability();
797 void ScCorrel();
798 void ScCovar();
799 void ScPearson();
800 void ScRSQ();
801 void ScSTEXY();
802 void ScSlope();
803 void ScTrend();
804 void ScInfo();
805 void ScLenB();
806 void ScRightB();
807 void ScLeftB();
808 void ScMidB();
809 
810 //------------------------ Functions in interpr6.cxx -------------------------
811 
812 static const double fMaxGammaArgument;  // defined in interpr3.cxx
813 
814 double GetGammaContFraction(double fA,double fX);
815 double GetGammaSeries(double fA,double fX);
816 double GetLowRegIGamma(double fA,double fX);    // lower regularized incomplete gamma function, GAMMAQ
817 double GetUpRegIGamma(double fA,double fX);     // upper regularized incomplete gamma function, GAMMAP
818 // probability density function; fLambda is "scale" parameter
819 double GetGammaDistPDF(double fX, double fAlpha, double fLambda);
820 // cumulative distribution function; fLambda is "scale" parameter
821 double GetGammaDist(double fX, double fAlpha, double fLambda);
822 
823 //----------------------------------------------------------------------------
824 public:
825     ScInterpreter( ScFormulaCell* pCell, ScDocument* pDoc,
826                     const ScAddress&, ScTokenArray& );
827     ~ScInterpreter();
828 
829     formula::StackVar Interpret();
830 
SetError(sal_uInt16 nError)831     void SetError(sal_uInt16 nError)
832             { if (nError && !nGlobalError) nGlobalError = nError; }
833 
GetError() const834     sal_uInt16 GetError()                           const   { return nGlobalError; }
GetResultType() const835     formula::StackVar  GetResultType()              const   { return xResult->GetType(); }
GetStringResult() const836     const String&   GetStringResult()               const   { return xResult->GetString(); }
GetNumResult() const837     double          GetNumResult()                  const   { return xResult->GetDouble(); }
838     formula::FormulaTokenRef
GetResultToken() const839                     GetResultToken()                const   { return xResult; }
GetRetFormatType() const840     short           GetRetFormatType()              const   { return nRetFmtType; }
GetRetFormatIndex() const841     sal_uLong       GetRetFormatIndex()             const   { return nRetFmtIndex; }
GetLastStackRefToken()842     ScToken*        GetLastStackRefToken() { return pLastStackRefToken; }
IsReferenceFunc()843     bool            IsReferenceFunc() { return bRefFunc; }
844 };
845 
846 
MatrixDoubleRefToMatrix()847 inline void ScInterpreter::MatrixDoubleRefToMatrix()
848 {
849     if ( bMatrixFormula && GetStackType() == formula::svDoubleRef )
850     {
851         GetTokenMatrixMap();    // make sure it exists, create if not.
852         PopDoubleRefPushMatrix();
853     }
854 }
855 
856 
MatrixParameterConversion()857 inline bool ScInterpreter::MatrixParameterConversion()
858 {
859     if ( (bMatrixFormula || pCur->HasForceArray()) && !pJumpMatrix && sp > 0 )
860         return ConvertMatrixParameters();
861     return false;
862 }
863 
864 
GetTokenMatrixMap()865 inline ScTokenMatrixMap& ScInterpreter::GetTokenMatrixMap()
866 {
867     if (!pTokenMatrixMap)
868         pTokenMatrixMap = CreateTokenMatrixMap();
869     return *pTokenMatrixMap;
870 }
871 
872 
MustHaveParamCount(short nAct,short nMust)873 inline sal_Bool ScInterpreter::MustHaveParamCount( short nAct, short nMust )
874 {
875     if ( nAct == nMust )
876         return sal_True;
877     if ( nAct < nMust )
878         PushParameterExpected();
879     else
880         PushIllegalParameter();
881     return sal_False;
882 }
883 
884 
MustHaveParamCount(short nAct,short nMust,short nMax)885 inline sal_Bool ScInterpreter::MustHaveParamCount( short nAct, short nMust, short nMax )
886 {
887     if ( nMust <= nAct && nAct <= nMax )
888         return sal_True;
889     if ( nAct < nMust )
890         PushParameterExpected();
891     else
892         PushIllegalParameter();
893     return sal_False;
894 }
895 
896 
MustHaveParamCountMin(short nAct,short nMin)897 inline sal_Bool ScInterpreter::MustHaveParamCountMin( short nAct, short nMin )
898 {
899     if ( nAct >= nMin )
900         return sal_True;
901     PushParameterExpected();
902     return sal_False;
903 }
904 
905 
CheckStringResultLen(String & rResult,const String & rAdd)906 inline sal_Bool ScInterpreter::CheckStringResultLen( String& rResult, const String& rAdd )
907 {
908     if ( (sal_uLong) rResult.Len() + rAdd.Len() > STRING_MAXLEN )
909     {
910         SetError( errStringOverflow );
911         rResult.Erase();
912         return sal_False;
913     }
914     return sal_True;
915 }
916 
917 
TreatDoubleError(double & rVal)918 inline void ScInterpreter::TreatDoubleError( double& rVal )
919 {
920     if ( !::rtl::math::isFinite( rVal ) )
921     {
922         sal_uInt16 nErr = GetDoubleErrorValue( rVal );
923         if ( nErr )
924             SetError( nErr );
925         else
926             SetError( errNoValue );
927         rVal = 0.0;
928     }
929 }
930 
931 
932 // static
div(const double & fNumerator,const double & fDenominator)933 inline double ScInterpreter::div( const double& fNumerator, const double& fDenominator )
934 {
935     return (fDenominator != 0.0) ? (fNumerator / fDenominator) :
936         CreateDoubleError( errDivisionByZero);
937 }
938 
939 #endif
940