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

Generated by: LCOV version 1.10