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 #pragma once
21 
22 #include <memory>
23 #include "formulabase.hxx"
24 
25 namespace oox::xls {
26 
27 // formula finalizer ==========================================================
28 
43 class FormulaFinalizer : public OpCodeProvider, protected ApiOpCodes
44 {
45 public:
46  explicit FormulaFinalizer( const OpCodeProvider& rOpCodeProv );
47 
50 
51 protected:
58  virtual const FunctionInfo* resolveBadFuncName( const OUString& rTokenData ) const;
59 
66  virtual OUString resolveDefinedName( sal_Int32 nTokenIndex ) const;
67 
68 private:
69  typedef ::std::vector< const ApiToken* > ParameterPosVector;
70 
71  const FunctionInfo* getFunctionInfo( ApiToken& orFuncToken );
72  const FunctionInfo* getExternCallInfo( ApiToken& orFuncToken, const ApiToken& rECToken );
73 
74  void processTokens( const ApiToken* pToken, const ApiToken* pTokenEnd );
75  const ApiToken* processParameters( const FunctionInfo& rFuncInfo, const ApiToken* pToken, const ApiToken* pTokenEnd );
76 
77  bool isEmptyParameter( const ApiToken* pToken, const ApiToken* pTokenEnd ) const;
78  const ApiToken* getSingleToken( const ApiToken* pToken, const ApiToken* pTokenEnd ) const;
79  const ApiToken* skipParentheses( const ApiToken* pToken, const ApiToken* pTokenEnd ) const;
80  const ApiToken* findParameters( ParameterPosVector& rParams, const ApiToken* pToken, const ApiToken* pTokenEnd ) const;
81  void appendEmptyParameter( const FunctionInfo& rFuncInfo, size_t nParam );
82  void appendCalcOnlyParameter( const FunctionInfo& rFuncInfo, size_t nParam, size_t nParamCount );
83  void appendRequiredParameters( const FunctionInfo& rFuncInfo, size_t nParamCount );
84 
85  bool appendFinalToken( const ApiToken& rToken );
86 
87 private:
89 };
90 
91 class FormulaParserImpl;
92 
100 {
101 public:
102  explicit FormulaParser( const WorkbookHelper& rHelper );
103  virtual ~FormulaParser() override;
104 
107  const ScAddress& rBaseAddr,
108  const OUString& rFormulaString ) const;
109 
112  const ScAddress& rBaseAddr,
114  SequenceInputStream& rStrm ) const;
115 
117  OUString importOleTargetLink( const OUString& rFormulaString );
118 
120  OUString importOleTargetLink( SequenceInputStream& rStrm );
121 
123  OUString importMacroName( const OUString& rFormulaString );
124 
125 private:
126  ::std::unique_ptr< FormulaParserImpl > mxImpl;
127 };
128 
129 } // namespace oox::xls
130 
131 /* 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:53
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:57
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.