LCOV - code coverage report
Current view: top level - sc/source/filter/inc - formulaparser.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 1 100.0 %
Date: 2015-06-13 12:38:46 Functions: 1 2 50.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_FORMULAPARSER_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_FORMULAPARSER_HXX
      22             : 
      23             : #include "formulabase.hxx"
      24             : 
      25             : namespace oox {
      26             : namespace xls {
      27             : 
      28             : // formula finalizer ==========================================================
      29             : 
      30             : /** A generic formula token array finalizer.
      31             : 
      32             :     After building a formula token array from alien binary file formats, or
      33             :     parsing an XML formula string using the com.sun.star.sheet.FormulaParser
      34             :     service, the token array is still not ready to be put into the spreadsheet
      35             :     document. There may be functions with a wrong number of parameters (missing
      36             :     but required parameters, or unsupported parameters) or intermediate tokens
      37             :     used to encode references to macro functions or add-in functions. This
      38             :     helper processes a passed token array and builds a new compatible token
      39             :     array.
      40             : 
      41             :     Derived classes may add more functionality by overwriting the virtual
      42             :     functions.
      43             :  */
      44         414 : class FormulaFinalizer : public OpCodeProvider, protected ApiOpCodes
      45             : {
      46             : public:
      47             :     explicit            FormulaFinalizer( const OpCodeProvider& rOpCodeProv );
      48             : 
      49             :     /** Finalizes and returns the passed token array. */
      50             :     ApiTokenSequence    finalizeTokenArray( const ApiTokenSequence& rTokens );
      51             : 
      52             : protected:
      53             :     /** Derived classed may try to find a function info struct from the passed
      54             :         string extracted from an OPCODE_BAD token.
      55             : 
      56             :         @param rTokenData  The string that has been found in an OPCODE_BAD
      57             :             token preceding the function parentheses.
      58             :      */
      59             :     virtual const FunctionInfo* resolveBadFuncName( const OUString& rTokenData ) const;
      60             : 
      61             :     /** Derived classed may try to find the name of a defined name with the
      62             :         passed index extracted from an OPCODE_NAME token.
      63             : 
      64             :         @param nTokenIndex  The index of the defined name that has been found
      65             :             in an OPCODE_NAME token preceding the function parentheses.
      66             :      */
      67             :     virtual OUString resolveDefinedName( sal_Int32 nTokenIndex ) const;
      68             : 
      69             : private:
      70             :     typedef ::std::vector< const ApiToken* > ParameterPosVector;
      71             : 
      72             :     const FunctionInfo* getFunctionInfo( ApiToken& orFuncToken );
      73             :     const FunctionInfo* getExternCallInfo( ApiToken& orFuncToken, const ApiToken& rECToken );
      74             : 
      75             :     void                processTokens( const ApiToken* pToken, const ApiToken* pTokenEnd );
      76             :     const ApiToken*     processParameters( const FunctionInfo& rFuncInfo, const ApiToken* pToken, const ApiToken* pTokenEnd );
      77             : 
      78             :     bool                isEmptyParameter( const ApiToken* pToken, const ApiToken* pTokenEnd ) const;
      79             :     const ApiToken*     getSingleToken( const ApiToken* pToken, const ApiToken* pTokenEnd ) const;
      80             :     const ApiToken*     skipParentheses( const ApiToken* pToken, const ApiToken* pTokenEnd ) const;
      81             :     const ApiToken*     findParameters( ParameterPosVector& rParams, const ApiToken* pToken, const ApiToken* pTokenEnd ) const;
      82             :     void                appendEmptyParameter( const FunctionInfo& rFuncInfo, size_t nParam );
      83             :     void                appendCalcOnlyParameter( const FunctionInfo& rFuncInfo, size_t nParam, size_t nParamCount );
      84             :     void                appendRequiredParameters( const FunctionInfo& rFuncInfo, size_t nParamCount );
      85             : 
      86             :     bool                appendFinalToken( const ApiToken& rToken );
      87             : 
      88             : private:
      89             :     ApiTokenVector      maTokens;
      90             : };
      91             : 
      92             : class FormulaParserImpl;
      93             : 
      94             : /** Import formula parser for OOXML and BIFF filters.
      95             : 
      96             :     This class implements formula import for the OOXML and BIFF filter. One
      97             :     instance is contained in the global filter data to prevent construction and
      98             :     destruction of internal buffers for every imported formula.
      99             :  */
     100             : class FormulaParser : public FormulaProcessorBase
     101             : {
     102             : public:
     103             :     explicit            FormulaParser( const WorkbookHelper& rHelper );
     104             :     virtual             ~FormulaParser();
     105             : 
     106             :     /** Converts an OOXML formula string. */
     107             :     ApiTokenSequence    importFormula(
     108             :                             const ::com::sun::star::table::CellAddress& rBaseAddr,
     109             :                             const OUString& rFormulaString ) const;
     110             : 
     111             :     /** Imports and converts a BIFF12 token array from the passed stream. */
     112             :     ApiTokenSequence    importFormula(
     113             :                             const ::com::sun::star::table::CellAddress& rBaseAddr,
     114             :                             FormulaType eType,
     115             :                             SequenceInputStream& rStrm ) const;
     116             : 
     117             :     /** Imports and converts a BIFF2-BIFF8 token array from the passed stream.
     118             :         @param pnFmlaSize  Size of the token array. If null is passed, reads
     119             :         it from stream (1 byte in BIFF2, 2 bytes otherwise) first. */
     120             :     ApiTokenSequence    importFormula(
     121             :                             const ::com::sun::star::table::CellAddress& rBaseAddr,
     122             :                             FormulaType eType,
     123             :                             BiffInputStream& rStrm,
     124             :                             const sal_uInt16* pnFmlaSize = 0 ) const;
     125             : 
     126             :     /** Converts the passed BIFF error code to a similar formula. */
     127             :     ApiTokenSequence    convertErrorToFormula( sal_uInt8 nErrorCode ) const;
     128             : 
     129             :     /** Converts the passed XML formula to an OLE link target. */
     130             :     OUString     importOleTargetLink( const OUString& rFormulaString );
     131             : 
     132             :     /** Imports and converts an OLE link target from the passed stream. */
     133             :     OUString     importOleTargetLink( SequenceInputStream& rStrm );
     134             : 
     135             :     /** Converts the passed formula to a macro name for a drawing shape. */
     136             :     OUString     importMacroName( const OUString& rFormulaString );
     137             : 
     138             : private:
     139             :     ::std::unique_ptr< FormulaParserImpl > mxImpl;
     140             : };
     141             : 
     142             : } // namespace xls
     143             : } // namespace oox
     144             : 
     145             : #endif
     146             : 
     147             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11