LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xlformula.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 22 24 91.7 %
Date: 2014-11-03 Functions: 18 20 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XLFORMULA_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_XLFORMULA_HXX
      22             : 
      23             : #include <map>
      24             : #include <formula/opcode.hxx>
      25             : #include "address.hxx"
      26             : #include "ftools.hxx"
      27             : #include <boost/shared_ptr.hpp>
      28             : 
      29             : namespace svl {
      30             : 
      31             : class SharedStringPool;
      32             : 
      33             : }
      34             : 
      35             : // Constants ==================================================================
      36             : 
      37             : const size_t EXC_TOKARR_MAXLEN              = 4096;     /// Maximum size of a token array.
      38             : 
      39             : // Token class flags ----------------------------------------------------------
      40             : 
      41             : const sal_uInt8 EXC_TOKCLASS_MASK           = 0x60;
      42             : const sal_uInt8 EXC_TOKCLASS_NONE           = 0x00;     /// 00-1F: Base tokens.
      43             : const sal_uInt8 EXC_TOKCLASS_REF            = 0x20;     /// 20-3F: Reference class tokens.
      44             : const sal_uInt8 EXC_TOKCLASS_VAL            = 0x40;     /// 40-5F: Value class tokens.
      45             : const sal_uInt8 EXC_TOKCLASS_ARR            = 0x60;     /// 60-7F: Array class tokens.
      46             : 
      47             : // Base tokens ----------------------------------------------------------------
      48             : 
      49             : const sal_uInt8 EXC_TOKID_MASK              = 0x1F;
      50             : 
      51             : const sal_uInt8 EXC_TOKID_NONE              = 0x00;     /// Placeholder for invalid token id.
      52             : const sal_uInt8 EXC_TOKID_EXP               = 0x01;     /// Array or shared formula reference.
      53             : const sal_uInt8 EXC_TOKID_TBL               = 0x02;     /// Multiple operation reference.
      54             : const sal_uInt8 EXC_TOKID_ADD               = 0x03;     /// Addition operator.
      55             : const sal_uInt8 EXC_TOKID_SUB               = 0x04;     /// Subtraction operator.
      56             : const sal_uInt8 EXC_TOKID_MUL               = 0x05;     /// Multiplication operator.
      57             : const sal_uInt8 EXC_TOKID_DIV               = 0x06;     /// Division operator.
      58             : const sal_uInt8 EXC_TOKID_POWER             = 0x07;     /// Power operator.
      59             : const sal_uInt8 EXC_TOKID_CONCAT            = 0x08;     /// String concatenation operator.
      60             : const sal_uInt8 EXC_TOKID_LT                = 0x09;     /// Less than operator.
      61             : const sal_uInt8 EXC_TOKID_LE                = 0x0A;     /// Less than or equal operator.
      62             : const sal_uInt8 EXC_TOKID_EQ                = 0x0B;     /// Equal operator.
      63             : const sal_uInt8 EXC_TOKID_GE                = 0x0C;     /// Greater than or equal operator.
      64             : const sal_uInt8 EXC_TOKID_GT                = 0x0D;     /// Greater than operator.
      65             : const sal_uInt8 EXC_TOKID_NE                = 0x0E;     /// Not equal operator.
      66             : const sal_uInt8 EXC_TOKID_ISECT             = 0x0F;     /// Intersection operator.
      67             : const sal_uInt8 EXC_TOKID_LIST              = 0x10;     /// List operator.
      68             : const sal_uInt8 EXC_TOKID_RANGE             = 0x11;     /// Range operator.
      69             : const sal_uInt8 EXC_TOKID_UPLUS             = 0x12;     /// Unary plus.
      70             : const sal_uInt8 EXC_TOKID_UMINUS            = 0x13;     /// Unary minus.
      71             : const sal_uInt8 EXC_TOKID_PERCENT           = 0x14;     /// Percent sign.
      72             : const sal_uInt8 EXC_TOKID_PAREN             = 0x15;     /// Parentheses.
      73             : const sal_uInt8 EXC_TOKID_MISSARG           = 0x16;     /// Missing argument.
      74             : const sal_uInt8 EXC_TOKID_STR               = 0x17;     /// String constant.
      75             : const sal_uInt8 EXC_TOKID_NLR               = 0x18;     /// Natural language reference (NLR).
      76             : const sal_uInt8 EXC_TOKID_ATTR              = 0x19;     /// Special attribute.
      77             : const sal_uInt8 EXC_TOKID_SHEET             = 0x1A;     /// Start of a sheet reference (BIFF2-BIFF4).
      78             : const sal_uInt8 EXC_TOKID_ENDSHEET          = 0x1B;     /// End of a sheet reference (BIFF2-BIFF4).
      79             : const sal_uInt8 EXC_TOKID_ERR               = 0x1C;     /// Error constant.
      80             : const sal_uInt8 EXC_TOKID_BOOL              = 0x1D;     /// Boolean constant.
      81             : const sal_uInt8 EXC_TOKID_INT               = 0x1E;     /// Integer constant.
      82             : const sal_uInt8 EXC_TOKID_NUM               = 0x1F;     /// Floating-point constant.
      83             : 
      84             : // Base IDs of classified tokens ----------------------------------------------
      85             : 
      86             : const sal_uInt8 EXC_TOKID_ARRAY             = 0x00;     /// Array constant.
      87             : const sal_uInt8 EXC_TOKID_FUNC              = 0x01;     /// Function, fixed number of arguments.
      88             : const sal_uInt8 EXC_TOKID_FUNCVAR           = 0x02;     /// Function, variable number of arguments.
      89             : const sal_uInt8 EXC_TOKID_NAME              = 0x03;     /// Defined name.
      90             : const sal_uInt8 EXC_TOKID_REF               = 0x04;     /// 2D cell reference.
      91             : const sal_uInt8 EXC_TOKID_AREA              = 0x05;     /// 2D area reference.
      92             : const sal_uInt8 EXC_TOKID_MEMAREA           = 0x06;     /// Constant reference subexpression.
      93             : const sal_uInt8 EXC_TOKID_MEMERR            = 0x07;     /// Deleted reference subexpression.
      94             : const sal_uInt8 EXC_TOKID_MEMNOMEM          = 0x08;     /// Constant reference subexpression without result.
      95             : const sal_uInt8 EXC_TOKID_MEMFUNC           = 0x09;     /// Variable reference subexpression.
      96             : const sal_uInt8 EXC_TOKID_REFERR            = 0x0A;     /// Deleted 2D cell reference.
      97             : const sal_uInt8 EXC_TOKID_AREAERR           = 0x0B;     /// Deleted 2D area reference.
      98             : const sal_uInt8 EXC_TOKID_REFN              = 0x0C;     /// Relative 2D cell reference (in names).
      99             : const sal_uInt8 EXC_TOKID_AREAN             = 0x0D;     /// Relative 2D area reference (in names).
     100             : const sal_uInt8 EXC_TOKID_MEMAREAN          = 0x0E;     /// Reference subexpression (in names).
     101             : const sal_uInt8 EXC_TOKID_MEMNOMEMN         = 0x0F;     /// Reference subexpression (in names) without result.
     102             : const sal_uInt8 EXC_TOKID_FUNCCE            = 0x18;
     103             : const sal_uInt8 EXC_TOKID_NAMEX             = 0x19;     /// External reference.
     104             : const sal_uInt8 EXC_TOKID_REF3D             = 0x1A;     /// 3D cell reference.
     105             : const sal_uInt8 EXC_TOKID_AREA3D            = 0x1B;     /// 3D area reference.
     106             : const sal_uInt8 EXC_TOKID_REFERR3D          = 0x1C;     /// Deleted 3D cell reference.
     107             : const sal_uInt8 EXC_TOKID_AREAERR3D         = 0x1D;     /// Deleted 3D area reference
     108             : 
     109             : // specific token constants ---------------------------------------------------
     110             : 
     111             : const sal_uInt16 EXC_TOK_STR_MAXLEN         = 255;      /// Maximum string length of a tStr token.
     112             : 
     113             : const sal_uInt8 EXC_TOK_BOOL_FALSE          = 0;        /// sal_False value of a tBool token.
     114             : const sal_uInt8 EXC_TOK_BOOL_TRUE           = 1;        /// sal_True value of a tBool token.
     115             : 
     116             : const sal_uInt8 EXC_TOK_ATTR_VOLATILE       = 0x01;     /// Volatile function.
     117             : const sal_uInt8 EXC_TOK_ATTR_IF             = 0x02;     /// Start of true condition in IF function.
     118             : const sal_uInt8 EXC_TOK_ATTR_CHOOSE         = 0x04;     /// Jump array of CHOOSE function.
     119             : const sal_uInt8 EXC_TOK_ATTR_GOTO           = 0x08;     /// Jump to token.
     120             : const sal_uInt8 EXC_TOK_ATTR_SUM            = 0x10;     /// SUM function with one parameter.
     121             : const sal_uInt8 EXC_TOK_ATTR_ASSIGN         = 0x20;     /// BASIC style assignment.
     122             : const sal_uInt8 EXC_TOK_ATTR_SPACE          = 0x40;     /// Spaces in formula representation.
     123             : 
     124             : const sal_uInt8 EXC_TOK_ATTR_SPACE_SP       = 0x00;     /// Spaces before next token.
     125             : const sal_uInt8 EXC_TOK_ATTR_SPACE_BR       = 0x01;     /// Line breaks before next token.
     126             : const sal_uInt8 EXC_TOK_ATTR_SPACE_SP_OPEN  = 0x02;     /// Spaces before opening parenthesis.
     127             : const sal_uInt8 EXC_TOK_ATTR_SPACE_BR_OPEN  = 0x03;     /// Line breaks before opening parenthesis.
     128             : const sal_uInt8 EXC_TOK_ATTR_SPACE_SP_CLOSE = 0x04;     /// Spaces before closing parenthesis.
     129             : const sal_uInt8 EXC_TOK_ATTR_SPACE_BR_CLOSE = 0x05;     /// Line breaks before closing parenthesis.
     130             : const sal_uInt8 EXC_TOK_ATTR_SPACE_SP_PRE   = 0x06;     /// Spaces before formula (BIFF3).
     131             : 
     132             : const sal_uInt16 EXC_TOK_FUNCVAR_CMD        = 0x8000;   /// Macro command.
     133             : const sal_uInt16 EXC_TOK_FUNCVAR_INDEXMASK  = 0x7FFF;   /// Mask for function/command index.
     134             : const sal_uInt8 EXC_TOK_FUNCVAR_PROMPT      = 0x80;     /// User prompt for macro commands.
     135             : const sal_uInt8 EXC_TOK_FUNCVAR_COUNTMASK   = 0x7F;     /// Mask for parameter count.
     136             : 
     137             : const sal_uInt16 EXC_TOK_REF_COLREL         = 0x4000;   /// True = Column is relative.
     138             : const sal_uInt16 EXC_TOK_REF_ROWREL         = 0x8000;   /// True = Row is relative.
     139             : 
     140             : const sal_uInt8 EXC_TOK_NLR_ERR             = 0x01;     /// NLR: Invalid/deleted.
     141             : const sal_uInt8 EXC_TOK_NLR_ROWR            = 0x02;     /// NLR: Row index.
     142             : const sal_uInt8 EXC_TOK_NLR_COLR            = 0x03;     /// NLR: Column index.
     143             : const sal_uInt8 EXC_TOK_NLR_ROWV            = 0x06;     /// NLR: Value in row.
     144             : const sal_uInt8 EXC_TOK_NLR_COLV            = 0x07;     /// NLR: Value in column.
     145             : const sal_uInt8 EXC_TOK_NLR_RANGE           = 0x0A;     /// NLR: Range.
     146             : const sal_uInt8 EXC_TOK_NLR_SRANGE          = 0x0B;     /// Stacked NLR: Range.
     147             : const sal_uInt8 EXC_TOK_NLR_SROWR           = 0x0C;     /// Stacked NLR: Row index.
     148             : const sal_uInt8 EXC_TOK_NLR_SCOLR           = 0x0D;     /// Stacked NLR: Column index.
     149             : const sal_uInt8 EXC_TOK_NLR_SROWV           = 0x0E;     /// Stacked NLR: Value in row.
     150             : const sal_uInt8 EXC_TOK_NLR_SCOLV           = 0x0F;     /// Stacked NLR: Value in column.
     151             : const sal_uInt8 EXC_TOK_NLR_RANGEERR        = 0x10;     /// NLR: Invalid/deleted range.
     152             : const sal_uInt8 EXC_TOK_NLR_SXNAME          = 0x1D;     /// NLR: Pivot table name.
     153             : const sal_uInt16 EXC_TOK_NLR_REL            = 0x8000;   /// True = Natural language ref is relative.
     154             : 
     155             : const sal_uInt32 EXC_TOK_NLR_ADDREL         = 0x80000000;   /// NLR relative (in appended data).
     156             : const sal_uInt32 EXC_TOK_NLR_ADDMASK        = 0x3FFFFFFF;   /// Mask for number of appended ranges.
     157             : 
     158             : /** Type of a formula. */
     159             : enum XclFormulaType
     160             : {
     161             :     EXC_FMLATYPE_CELL,          /// Simple cell formula, also used in change tracking.
     162             :     EXC_FMLATYPE_MATRIX,        /// Matrix (array) formula.
     163             :     EXC_FMLATYPE_SHARED,        /// Shared formula.
     164             :     EXC_FMLATYPE_CONDFMT,       /// Conditional format.
     165             :     EXC_FMLATYPE_DATAVAL,       /// Data validation.
     166             :     EXC_FMLATYPE_NAME,          /// Defined name.
     167             :     EXC_FMLATYPE_CHART,         /// Chart source ranges.
     168             :     EXC_FMLATYPE_CONTROL,       /// Spreadsheet links in form controls.
     169             :     EXC_FMLATYPE_WQUERY,        /// Web query source range.
     170             :     EXC_FMLATYPE_LISTVAL        /// List (cell range) validation.
     171             : };
     172             : 
     173             : // Function parameter info ====================================================
     174             : 
     175             : /** Enumerates validity modes for a function parameter. */
     176             : enum XclFuncParamValidity
     177             : {
     178             :     EXC_PARAM_NONE = 0,         /// Default for an unspecified entry in a C-array.
     179             :     EXC_PARAM_REGULAR,          /// Parameter supported by Calc and Excel.
     180             :     EXC_PARAM_CALCONLY,         /// Parameter supported by Calc only.
     181             :     EXC_PARAM_EXCELONLY         /// Parameter supported by Excel only.
     182             : };
     183             : 
     184             : /** Enumerates different types of token class conversion in function parameters. */
     185             : enum XclFuncParamConv
     186             : {
     187             :     EXC_PARAMCONV_ORG,          /// Use original class of current token.
     188             :     EXC_PARAMCONV_VAL,          /// Convert tokens to VAL class.
     189             :     EXC_PARAMCONV_ARR,          /// Convert tokens to ARR class.
     190             :     EXC_PARAMCONV_RPT,          /// Repeat parent conversion in VALTYPE parameters.
     191             :     EXC_PARAMCONV_RPX,          /// Repeat parent conversion in REFTYPE parameters.
     192             :     EXC_PARAMCONV_RPO           /// Repeat parent conversion in operands of operators.
     193             : };
     194             : 
     195             : /** Structure that contains all needed information for a parameter in a
     196             :     function.
     197             : 
     198             :     The member meValid specifies which application supports the parameter. If
     199             :     set to CALCONLY, import filters have to insert a default value for this
     200             :     parameter, and export filters have to skip the parameter. If set to
     201             :     EXCELONLY, import filters have to skip the parameter, and export filters
     202             :     have to insert a default value for this parameter.
     203             : 
     204             :     The member mbValType specifies whether the parameter requires tokens to be
     205             :     of value type (VAL or ARR class).
     206             : 
     207             :         If set to false, the parameter is called to be REFTYPE. Tokens with REF
     208             :         default class can be inserted for the parameter (e.g. tAreaR tokens).
     209             : 
     210             :         If set to true, the parameter is called to be VALTYPE. Tokens with REF
     211             :         class need to be converted to VAL tokens first (e.g. tAreaR will be
     212             :         converted to tAreaV), and further conversion is done according to this
     213             :         new token class.
     214             : 
     215             :     The member meConv specifies how to convert the current token class of the
     216             :     token inserted for the parameter. If the token class is still REF this
     217             :     means that the token has default REF class and the parameter is REFTYPE
     218             :     (see member mbValType), the token will not be converted at all and remains
     219             :     in REF class. Otherwise, token class conversion is depending on the actual
     220             :     token class of the return value of the function containing this parameter.
     221             :     The function may return REF class (tFuncR, tFuncVarR, tFuncCER), or it may
     222             :     return VAL or ARR class (tFuncV, tFuncA, tFuncVarV, tFuncVarA, tFuncCEV,
     223             :     tFuncCEA). Even if the function is able to return REF class, it may return
     224             :     VAL or ARR class instead due to the VALTYPE data type of the parent
     225             :     function parameter that calls the own function. Example: The INDIRECT
     226             :     function returns REF class by default. But if called from a VALTYPE
     227             :     function parameter, e.g. in the formula =ABS(INDIRECT("A1")), it returns
     228             :     VAL or ARR class instead. Additionally, the repeating conversion types RPT
     229             :     and RPX rely on the conversion executed for the function token class.
     230             : 
     231             :         1) ORG:
     232             :         Use the original class of the token (VAL or ARR), regardless of any
     233             :         conversion done for the function return class.
     234             : 
     235             :         2) VAL:
     236             :         Convert ARR tokens to VAL class, regardless of any conversion done for
     237             :         the function return class.
     238             : 
     239             :         3) ARR:
     240             :         Convert VAL tokens to ARR class, regardless of any conversion done for
     241             :         the function return class.
     242             : 
     243             :         4) RPT:
     244             :         If the own function returns REF class (thus it is called from a REFTYPE
     245             :         parameter, see above), and the parent conversion type (for the function
     246             :         return class) was ORG, VAL, or ARR, ignore that conversion and always
     247             :         use VAL conversion for the own token instead. If the parent conversion
     248             :         type was RPT or RPX, repeat the conversion that would have been used if
     249             :         the function would return value type.
     250             :         If the own function returns value type (VAL or ARR class, see above),
     251             :         and the parent conversion type (for the function return class) was ORG,
     252             :         VAL, ARR, or RPT, repeat this conversion for the own token. If the
     253             :         parent conversion type was RPX, always use ORG conversion type for the
     254             :         own token instead.
     255             : 
     256             :         5) RPX:
     257             :         This type of conversion only occurs in functions returning VAL class by
     258             :         default. If the own token is value type, and the VAL return class of
     259             :         the own function has been changed to ARR class (due to direct ARR
     260             :         conversion, or due to ARR conversion repeated by RPT or RPX), set the
     261             :         own token to ARR type. Otherwise use the original token type (VAL
     262             :         conversion from parent parameter will not be repeated at all). If
     263             :         nested functions have RPT or value-type RPX parameters, they will not
     264             :         repeat this conversion type, but will use ORG conversion instead (see
     265             :         description of RPT above).
     266             : 
     267             :         6) RPO:
     268             :         This type of conversion is only used for the operands of all operators
     269             :         (unary and binary arithmetic operators, comparison operators, and range
     270             :         operators). It is not used for function parameters. On conversion, it
     271             :         will be replaced by the last conversion type that was not the RPO
     272             :         conversion. This leads to a slightly different behaviour than the RPT
     273             :         conversion for operands in conjunction with a parent RPX conversion.
     274             :  */
     275             : struct XclFuncParamInfo
     276             : {
     277             :     XclFuncParamValidity meValid;       /// Parameter validity.
     278             :     XclFuncParamConv    meConv;         /// Token class conversion type.
     279             :     bool                mbValType;      /// Data type (false = REFTYPE, true = VALTYPE).
     280             : };
     281             : 
     282             : // Function data ==============================================================
     283             : 
     284             : const sal_uInt8 EXC_FUNC_MAXPARAM           = 30;       /// Maximum parameter count.
     285             : 
     286             : const size_t EXC_FUNCINFO_PARAMINFO_COUNT   = 5;        /// Number of parameter info entries.
     287             : 
     288             : const sal_uInt8 EXC_FUNCFLAG_VOLATILE       = 0x01;     /// Result is volatile (e.g. NOW() function).
     289             : const sal_uInt8 EXC_FUNCFLAG_IMPORTONLY     = 0x02;     /// Only used in import filter.
     290             : const sal_uInt8 EXC_FUNCFLAG_EXPORTONLY     = 0x04;     /// Only used in export filter.
     291             : const sal_uInt8 EXC_FUNCFLAG_PARAMPAIRS     = 0x08;     /// Optional parameters are expected to appear in pairs.
     292             : const sal_uInt8 EXC_FUNCFLAG_ADDINEQUIV     = 0x10;     /// Function is an add-in equivalent
     293             : 
     294             : // selected function IDs
     295             : const sal_uInt16 EXC_FUNCID_IF              = 1;
     296             : const sal_uInt16 EXC_FUNCID_SUM             = 4;
     297             : const sal_uInt16 EXC_FUNCID_AND             = 36;
     298             : const sal_uInt16 EXC_FUNCID_OR              = 37;
     299             : const sal_uInt16 EXC_FUNCID_CHOOSE          = 100;
     300             : const sal_uInt16 EXC_FUNCID_EXTERNCALL      = 255;
     301             : 
     302             : /** Represents information for a spreadsheet function for import and export.
     303             : 
     304             :     The member mpParamInfos points to an array of type information structures
     305             :     for all parameters of the function. The last initialized structure
     306             :     describing a regular parameter (member meValid == EXC_PARAMVALID_ALWAYS) in
     307             :     this array is used repeatedly for all following parameters supported by a
     308             :     function.
     309             :  */
     310             : struct XclFunctionInfo
     311             : {
     312             :     OpCode              meOpCode;           /// Calc function opcode.
     313             :     sal_uInt16          mnXclFunc;          /// Excel function index.
     314             :     sal_uInt8           mnMinParamCount;    /// Minimum number of parameters.
     315             :     sal_uInt8           mnMaxParamCount;    /// Maximum number of parameters.
     316             :     sal_uInt8           mnRetClass;         /// Token class of the return value.
     317             :     XclFuncParamInfo    mpParamInfos[ EXC_FUNCINFO_PARAMINFO_COUNT ]; /// Information for all parameters.
     318             :     sal_uInt8           mnFlags;            /// Additional flags (EXC_FUNCFLAG_* constants).
     319             :     const sal_Char*     mpcMacroName;       /** Function name, if simulated by
     320             :                                                 a macro call (UTF-8) EXC_FUNCFLAG_ADDINEQUIV is 0;
     321             :                                                 or programmatical add-in name
     322             :                                                 if stored as such and
     323             :                                                 EXC_FUNCFLAG_ADDINEQUIV is set. */
     324             : 
     325             :     /** Returns true, if the function is volatile. */
     326         900 :     inline bool         IsVolatile() const { return ::get_flag( mnFlags, EXC_FUNCFLAG_VOLATILE ); }
     327             :     /** Returns true, if optional parameters are expected to appear in pairs. */
     328        2448 :     inline bool         IsParamPairs() const { return ::get_flag( mnFlags, EXC_FUNCFLAG_PARAMPAIRS ); }
     329             :     /** Returns true, if the function parameter count is fixed. */
     330         896 :     inline bool         IsFixedParamCount() const { return (mnXclFunc != EXC_FUNCID_EXTERNCALL) && (mnMinParamCount == mnMaxParamCount); }
     331             :     /** Returns true, if the function is simulated by a macro call. */
     332      212758 :     inline bool         IsMacroFunc() const { return mpcMacroName != 0 && !(mnFlags & EXC_FUNCFLAG_ADDINEQUIV); }
     333             :     /** Returns true, if the function is stored as an add-in call. */
     334        1604 :     inline bool         IsAddInEquivalent() const { return mpcMacroName != 0 && (mnFlags & EXC_FUNCFLAG_ADDINEQUIV); }
     335             :     /** Returns the name of the external function as string. */
     336             :     OUString            GetMacroFuncName() const;
     337             :     /** Returns the programmatical name of the Add-In function as string. */
     338             :     OUString            GetAddInEquivalentFuncName() const;
     339             : };
     340             : 
     341             : class XclRoot;
     342             : 
     343             : /** Provides access to function info structs for all available functions. */
     344         498 : class XclFunctionProvider
     345             : {
     346             : public:
     347             :     explicit            XclFunctionProvider( const XclRoot& rRoot );
     348             : 
     349             :     /** Returns the function data for an Excel function index, or 0 on error. */
     350             :     const XclFunctionInfo* GetFuncInfoFromXclFunc( sal_uInt16 nXclFunc ) const;
     351             :     /** Returns the function data for an Excel function simulated by a macro call, or 0 on error. */
     352             :     const XclFunctionInfo* GetFuncInfoFromXclMacroName( const OUString& rXclMacroName ) const;
     353             :     /** Returns the function data for a Calc opcode, or 0 on error. */
     354             :     const XclFunctionInfo* GetFuncInfoFromOpCode( OpCode eOpCode ) const;
     355             : 
     356             : private:
     357             :     void                FillXclFuncMap( const XclFunctionInfo* pBeg, const XclFunctionInfo* pEnd );
     358             :     void                FillScFuncMap( const XclFunctionInfo* pBeg, const XclFunctionInfo* pEnd );
     359             : 
     360             : private:
     361             :     typedef ::std::map< sal_uInt16, const XclFunctionInfo* >    XclFuncMap;
     362             :     typedef ::std::map< OUString, const XclFunctionInfo* >      XclMacroNameMap;
     363             :     typedef ::std::map< OpCode, const XclFunctionInfo* >        ScFuncMap;
     364             : 
     365             :     XclFuncMap          maXclFuncMap;       /// Maps Excel function indexes to function data.
     366             :     XclMacroNameMap     maXclMacroNameMap;  /// Maps macro function names to function data.
     367             :     ScFuncMap           maScFuncMap;        /// Maps Calc opcodes to function data.
     368             : };
     369             : 
     370             : // Token array ================================================================
     371             : 
     372             : class XclImpStream;
     373             : class XclExpStream;
     374             : 
     375             : /** Binary representation of an Excel token array. */
     376        2094 : class XclTokenArray
     377             : {
     378             : public:
     379             :     /** Creates an empty token array. */
     380             :     explicit            XclTokenArray( bool bVolatile = false );
     381             :     /** Creates a token array, swaps passed token vectors into own data. */
     382             :     explicit            XclTokenArray( ScfUInt8Vec& rTokVec, ScfUInt8Vec& rExtDataVec, bool bVolatile = false );
     383             : 
     384             :     /** Returns true, if the token array is empty. */
     385         198 :     inline bool         Empty() const { return maTokVec.empty(); }
     386             :     /** Returns the size of the token array in bytes. */
     387             :     sal_uInt16          GetSize() const;
     388             :     /** Returns read-only access to the byte vector storing token data. */
     389         198 :     inline const sal_uInt8* GetData() const { return maTokVec.empty() ? 0 : &maTokVec.front(); }
     390             :     /** Returns true, if the formula contains a volatile function. */
     391        2984 :     inline bool         IsVolatile() const { return mbVolatile; }
     392             : 
     393             :     /** Reads the size field of the token array. */
     394             :     void                ReadSize( XclImpStream& rStrm );
     395             :     /** Reads the tokens of the token array (without size field). */
     396             :     void                ReadArray( XclImpStream& rStrm );
     397             :     /** Reads size field and the tokens. */
     398             :     void                Read( XclImpStream& rStrm );
     399             : 
     400             :     /** Writes the size field of the token array. */
     401             :     void                WriteSize( XclExpStream& rStrm ) const;
     402             :     /** Writes the tokens of the token array (without size field). */
     403             :     void                WriteArray( XclExpStream& rStrm ) const;
     404             :     /** Writes size field and the tokens. */
     405             :     void                Write( XclExpStream& rStrm ) const;
     406             : 
     407             :     /** Compares this token array with the passed. */
     408             :     bool                operator==( const XclTokenArray& rTokArr ) const;
     409             : 
     410             : private:
     411             :     ScfUInt8Vec         maTokVec;       /// Byte vector containing token data.
     412             :     ScfUInt8Vec         maExtDataVec;   /// Byte vector containing extended data (arrays, stacked NLRs).
     413             :     bool                mbVolatile;     /// True = Formula contains volatile function.
     414             : };
     415             : 
     416             : typedef boost::shared_ptr< XclTokenArray > XclTokenArrayRef;
     417             : 
     418             : /** Calls the Read() function at the passed token array. */
     419             : XclImpStream& operator>>( XclImpStream& rStrm, XclTokenArray& rTokArr );
     420             : /** Calls the Read() function at the passed token array. */
     421             : XclImpStream& operator>>( XclImpStream& rStrm, XclTokenArrayRef& rxTokArr );
     422             : /** Calls the Write() function at the passed token array. */
     423             : XclExpStream& operator<<( XclExpStream& rStrm, const XclTokenArray& rTokArr );
     424             : /** Calls the Write() function at the passed token array. */
     425             : XclExpStream& operator<<( XclExpStream& rStrm, const XclTokenArrayRef& rxTokArr );
     426             : 
     427             : namespace formula { class FormulaToken; }
     428             : class ScTokenArray;
     429             : 
     430             : /** Special token array iterator for the Excel filters.
     431             : 
     432             :     Iterates over a Calc token array without modifying it (therefore the
     433             :     iterator can be used with constant token arrays).
     434             : 
     435             :     Usage: Construct a new iterator object and pass a Calc token array, or use
     436             :     the Init() function to assign another Calc token array. As long as the Is()
     437             :     function returns true, the accessor functions can be used to get the
     438             :     current Calc token.
     439             :  */
     440             : class XclTokenArrayIterator
     441             : {
     442             : public:
     443             :     explicit            XclTokenArrayIterator();
     444             :     explicit            XclTokenArrayIterator( const ScTokenArray& rScTokArr, bool bSkipSpaces );
     445             :     /** Copy constructor that allows to change the skip-spaces mode. */
     446             :     explicit            XclTokenArrayIterator( const XclTokenArrayIterator& rTokArrIt, bool bSkipSpaces );
     447             : 
     448             :     void                Init( const ScTokenArray& rScTokArr, bool bSkipSpaces );
     449             : 
     450        8824 :     inline bool         Is() const { return mppScToken != 0; }
     451           0 :     inline bool         operator!() const { return !Is(); }
     452       15164 :     inline const ::formula::FormulaToken* Get() const { return mppScToken ? *mppScToken : 0; }
     453        6492 :     inline const ::formula::FormulaToken* operator->() const { return Get(); }
     454           0 :     inline const ::formula::FormulaToken& operator*() const { return *Get(); }
     455             : 
     456             :     XclTokenArrayIterator& operator++();
     457             : 
     458             : private:
     459             :     void                NextRawToken();
     460             :     void                SkipSpaces();
     461             : 
     462             : private:
     463             :     const ::formula::FormulaToken*const* mppScTokenBeg;     /// Pointer to first token pointer of token array.
     464             :     const ::formula::FormulaToken*const* mppScTokenEnd;     /// Pointer behind last token pointer of token array.
     465             :     const ::formula::FormulaToken*const* mppScToken;        /// Pointer to current token pointer of token array.
     466             :     bool                mbSkipSpaces;       /// true = Skip whitespace tokens.
     467             : };
     468             : 
     469             : /** Contains all cell references that can be extracted from a multiple operations formula. */
     470        2206 : struct XclMultipleOpRefs
     471             : {
     472             :     ScAddress           maFmlaScPos;        /// Position of the (first) formula cell.
     473             :     ScAddress           maColFirstScPos;
     474             :     ScAddress           maColRelScPos;
     475             :     ScAddress           maRowFirstScPos;
     476             :     ScAddress           maRowRelScPos;
     477             :     bool                mbDblRefMode;       /// true = One formula with row and column values.
     478             : };
     479             : 
     480             : /** A helper with Excel specific token array functions.
     481             : 
     482             :     The purpose to not add these functions to ScTokenArray is to prevent code
     483             :     changes in low-level Calc headers and to keep the Excel specific source
     484             :     code in the filter directory. Deriving from ScTokenArray is not viable
     485             :     because that would need expensive copy-constructions of the token arrays.
     486             :  */
     487         208 : class XclTokenArrayHelper
     488             : {
     489             : public:
     490             :     // token identifiers ------------------------------------------------------
     491             : 
     492             :     /** Returns the base token ID of the passed (classified) token ID. */
     493             :     inline static sal_uInt8 GetBaseTokenId( sal_uInt8 nTokenId ) { return nTokenId & EXC_TOKID_MASK; }
     494             :     /** Returns the classified token ID from a base ID and the token class. */
     495             :     inline static sal_uInt8 GetTokenId( sal_uInt8 nBaseId, sal_uInt8 nTokenClass );
     496             : 
     497             :     /** Returns the token class of the passed token ID. */
     498        4510 :     inline static sal_uInt8 GetTokenClass( sal_uInt8 nTokenId ) { return nTokenId & EXC_TOKCLASS_MASK; }
     499             :     /** Changes the token class in the passed classified token ID. */
     500             :     inline static void  ChangeTokenClass( sal_uInt8& rnTokenId, sal_uInt8 nTokenClass );
     501             : 
     502             :     // strings and string lists -----------------------------------------------
     503             : 
     504             :     /** Tries to extract a string from the passed token.
     505             :         @param rString  (out-parameter) The string contained in the token.
     506             :         @return  true = Passed token is a string token, rString parameter is valid. */
     507             :     static bool         GetTokenString( OUString& rString, const ::formula::FormulaToken& rScToken );
     508             : 
     509             :     /** Parses the passed formula and tries to find a single string token, i.e. "abc".
     510             :         @param rString  (out-parameter) The string contained in the formula.
     511             :         @return  true = String token found, rString parameter is valid. */
     512             :     static bool         GetString( OUString& rString, const ScTokenArray& rScTokArr );
     513             : 
     514             :     /** Parses the passed formula and tries to find a string token list, i.e. "abc";"def";"ghi".
     515             :         @descr  Returns the unquoted (!) strings in a single string, separated with the
     516             :         passed character. If a comma is specified, the function will return abc,def,ghi from
     517             :         the example above.
     518             :         @param rStringList  (out-parameter) All strings contained in the formula as list.
     519             :         @param cSep  List separator character.
     520             :         @return  true = String token list found, rString parameter is valid. */
     521             :     static bool         GetStringList( OUString& rStringList, const ScTokenArray& rScTokArr, sal_Unicode cSep );
     522             : 
     523             :     /** Tries to convert a formula that consists of a single string token to a list of strings.
     524             :         @descr  Example: The formula ="abc\ndef\nghi" will be converted to the formula
     525             :         ="abc";"def";"ghi", if the LF character is specified as separator.
     526             :         @param rScTokArr  (in/out-parameter) The token array to modify.
     527             :         @param cStringSep  The separator in the source string.
     528             :         @param bTrimLeadingSpaces  true = remove leading spaces from each token. */
     529             :     static void ConvertStringToList(
     530             :         ScTokenArray& rScTokArr, svl::SharedStringPool& rSPool, sal_Unicode cStringSep, bool bTrimLeadingSpaces );
     531             : 
     532             :     // multiple operations ----------------------------------------------------
     533             : 
     534             :     /** Parses the passed formula and tries to extract references of a multiple operation.
     535             :         @descr  Requires that the formula contains a single MULTIPLE.OPERATION function call.
     536             :         Spaces in the formula are silently ignored.
     537             :         @return  true = Multiple operation found, and all references successfully extracted. */
     538             :     static bool GetMultipleOpRefs( XclMultipleOpRefs& rRefs, const ScTokenArray& rScTokArr, const ScAddress& rScPos );
     539             : };
     540             : 
     541        3580 : inline sal_uInt8 XclTokenArrayHelper::GetTokenId( sal_uInt8 nBaseId, sal_uInt8 nTokenClass )
     542             : {
     543             :     OSL_ENSURE( !::get_flag( nBaseId, static_cast< sal_uInt8 >( ~EXC_TOKID_MASK ) ), "XclTokenArrayHelper::GetTokenId - invalid token ID" );
     544             :     OSL_ENSURE( !::get_flag( nTokenClass, static_cast< sal_uInt8 >( ~EXC_TOKCLASS_MASK ) ), "XclTokenArrayHelper::GetTokenId - invalid token class" );
     545        3580 :     return nBaseId | nTokenClass;
     546             : }
     547             : 
     548         324 : inline void XclTokenArrayHelper::ChangeTokenClass( sal_uInt8& rnTokenId, sal_uInt8 nTokenClass )
     549             : {
     550             :     OSL_ENSURE( !::get_flag( nTokenClass, static_cast< sal_uInt8 >( ~EXC_TOKCLASS_MASK ) ), "XclTokenArrayHelper::ChangeTokenClass - invalid token class" );
     551         324 :     ::set_flag( rnTokenId, EXC_TOKCLASS_MASK, false );
     552         324 :     ::set_flag( rnTokenId, nTokenClass );
     553         324 : }
     554             : 
     555             : #endif
     556             : 
     557             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10