LibreOffice Module sc (master)  1
formulaparser.hxx
Go to the documentation of this file.
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 <memory>
24 #include "formulabase.hxx"
25 
26 namespace oox::xls {
27 
28 // formula finalizer ==========================================================
29 
44 class FormulaFinalizer : public OpCodeProvider, protected ApiOpCodes
45 {
46 public:
47  explicit FormulaFinalizer( const OpCodeProvider& rOpCodeProv );
48 
51 
52 protected:
59  virtual const FunctionInfo* resolveBadFuncName( const OUString& rTokenData ) const;
60 
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:
90 };
91 
92 class FormulaParserImpl;
93 
101 {
102 public:
103  explicit FormulaParser( const WorkbookHelper& rHelper );
104  virtual ~FormulaParser() override;
105 
108  const ScAddress& rBaseAddr,
109  const OUString& rFormulaString ) const;
110 
113  const ScAddress& rBaseAddr,
115  SequenceInputStream& rStrm ) const;
116 
118  OUString importOleTargetLink( const OUString& rFormulaString );
119 
121  OUString importOleTargetLink( SequenceInputStream& rStrm );
122 
124  OUString importMacroName( const OUString& rFormulaString );
125 
126 private:
127  ::std::unique_ptr< FormulaParserImpl > mxImpl;
128 };
129 
130 } // namespace oox::xls
131 
132 #endif
133 
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper class to provide access to global workbook data.
const ApiToken * skipParentheses(const ApiToken *pToken, const ApiToken *pTokenEnd) const
virtual const FunctionInfo * resolveBadFuncName(const OUString &rTokenData) const
Derived classed may try to find a function info struct from the passed string extracted from an OPCOD...
FormulaParser(const WorkbookHelper &rHelper)
bool isEmptyParameter(const ApiToken *pToken, const ApiToken *pTokenEnd) const
Contains all API op-codes needed to build formulas with tokens.
void appendRequiredParameters(const FunctionInfo &rFuncInfo, size_t nParamCount)
const ApiToken * processParameters(const FunctionInfo &rFuncInfo, const ApiToken *pToken, const ApiToken *pTokenEnd)
::std::vector< const ApiToken * > ParameterPosVector
css::sheet::FormulaToken ApiToken
Represents information for a spreadsheet function.
char sal_uInt16 & nParamCount
Definition: callform.cxx:54
A generic formula token array finalizer.
::std::unique_ptr< FormulaParserImpl > mxImpl
const ApiToken * findParameters(ParameterPosVector &rParams, const ApiToken *pToken, const ApiToken *pTokenEnd) const
ApiTokenSequence importFormula(const ScAddress &rBaseAddr, const OUString &rFormulaString) const
Converts an OOXML formula string.
DocumentType eType
Provides access to API op-codes for all available formula tokens and to function info structs for all...
const FunctionInfo * getFunctionInfo(ApiToken &orFuncToken)
virtual ~FormulaParser() override
ApiTokenSequence finalizeTokenArray(const ApiTokenSequence &rTokens)
Finalizes and returns the passed token array.
sal_uInt16 & nParam
Definition: callform.cxx:58
Base class for import formula parsers and export formula compilers.
const FunctionInfo * getExternCallInfo(ApiToken &orFuncToken, const ApiToken &rECToken)
bool appendFinalToken(const ApiToken &rToken)
OUString importOleTargetLink(const OUString &rFormulaString)
Converts the passed XML formula to an OLE link target.
css::uno::Sequence< ApiToken > ApiTokenSequence
void processTokens(const ApiToken *pToken, const ApiToken *pTokenEnd)
FormulaFinalizer(const OpCodeProvider &rOpCodeProv)
virtual OUString resolveDefinedName(sal_Int32 nTokenIndex) const
Derived classed may try to find the name of a defined name with the passed index extracted from an OP...
void appendCalcOnlyParameter(const FunctionInfo &rFuncInfo, size_t nParam, size_t nParamCount)
void appendEmptyParameter(const FunctionInfo &rFuncInfo, size_t nParam)
Import formula parser for OOXML and BIFF filters.
OUString importMacroName(const OUString &rFormulaString)
Converts the passed formula to a macro name for a drawing shape.
void SvStream & rStrm
const ApiToken * getSingleToken(const ApiToken *pToken, const ApiToken *pTokenEnd) const
FormulaType
Function identifier of the WEEKNUM function.
A vector of formula tokens with additional convenience functions.