Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_PARCLASS_HXX
30 : : #define SC_PARCLASS_HXX
31 : :
32 : : #include "formula/opcode.hxx"
33 : : #include <sys/types.h> // size_t
34 : :
35 : : namespace formula
36 : : {
37 : : class FormulaToken;
38 : : }
39 : :
40 : : class ScParameterClassification
41 : : {
42 : : public:
43 : :
44 : : enum Type
45 : : {
46 : : Unknown = 0, // MUST be zero for initialization mechanism!
47 : :
48 : : /** Out of bounds, function doesn't expect that many parameters.
49 : : However, not necessarily returned. */
50 : : Bounds,
51 : :
52 : : /** In array formula: single value to be passed. Results in JumpMatrix
53 : : being created and multiple calls to function. Functions handling a
54 : : formula::svDoubleRef by means of DoubleRefToPosSingleRef() or
55 : : PopDoubleRefOrSingleRef() or GetDouble() or GetString() should have
56 : : this. */
57 : : Value,
58 : :
59 : : /** In array formula: area reference must stay reference. Otherwise
60 : : don't care. Functions handling a formula::svDoubleRef by means of
61 : : PopDoubleRefOrSingleRef() should not have this. */
62 : : Reference,
63 : :
64 : : /** In array formula: convert area reference to array. Function will be
65 : : called only once if no Value type is involved. Functions able to
66 : : handle a svMatrix parameter but not a formula::svDoubleRef parameter as area
67 : : should have this. */
68 : : Array,
69 : :
70 : : /** Area reference must be converted to array in any case, and must
71 : : also be propagated to subsequent operators and functions being part
72 : : of a parameter of this function. */
73 : : ForceArray,
74 : :
75 : : /** Area reference is not converted to array, but ForceArray must be
76 : : propagated to subsequent operators and functions being part of a
77 : : parameter of this function. Used with functions that treat
78 : : references separately from arrays, but need the forced array
79 : : calculation of parameters that are not references.*/
80 : : ReferenceOrForceArray
81 : : };
82 : :
83 : : /// MUST be called once before any other method.
84 : : static void Init();
85 : :
86 : : static void Exit();
87 : :
88 : : /** Get one parameter type for function eOp.
89 : : @param nParameter
90 : : Which parameter, 0-based */
91 : : static Type GetParameterType( const formula::FormulaToken* pToken,
92 : : sal_uInt16 nParameter);
93 : :
94 : : /** Whether OpCode has a parameter of type
95 : : ForceArray or ReferenceOrForceArray. */
96 : 16903 : static inline bool HasForceArray( OpCode eOp)
97 : : {
98 : : return 0 <= (short)eOp &&
99 : : eOp <= SC_OPCODE_LAST_OPCODE_ID &&
100 [ + - ][ + - ]: 16903 : pData[eOp].bHasForceArray;
[ + + ]
101 : : }
102 : :
103 : : private:
104 : :
105 : : struct CommonData
106 : : {
107 : : const static sal_Int32 nMaxParams = 7;
108 : :
109 : : Type nParam[nMaxParams];
110 : : bool bRepeatLast;
111 : : };
112 : :
113 : : // SUNWS7 needs a forward declared friend, otherwise members of the outer
114 : : // class are not accessible (in this case CommonData).
115 : : struct RawData;
116 : : friend struct ScParameterClassification::RawData;
117 : : struct RawData
118 : : {
119 : : OpCode eOp;
120 : : CommonData aData;
121 : : };
122 : :
123 : : struct RunData;
124 : : friend struct ScParameterClassification::RunData;
125 : : struct RunData
126 : : {
127 : : CommonData aData;
128 : : sal_uInt8 nMinParams; // fix or minimum, or repeat start
129 : : bool bHasForceArray;
130 : : };
131 : :
132 : : static const RawData pRawData[];
133 : : static RunData* pData;
134 : :
135 : : // ocExternal AddIns
136 : : static Type GetExternalParameterType(
137 : : const formula::FormulaToken* pToken, sal_uInt16 nParameter);
138 : :
139 : : #if OSL_DEBUG_LEVEL > 1
140 : : // Generate documentation to stdout if environment variable
141 : : // OOO_CALC_GENPARCLASSDOC is set.
142 : : static void GenerateDocumentation();
143 : :
144 : : /* OpCodes not specified in the implementation are taken from the global
145 : : * function list and all parameters, if any, are assumed to be of type
146 : : * Value. This could also be done in the product version if needed, but we
147 : : * don't want to spoil startup time. However, doing so could propagate the
148 : : * minimum parameter count to the formula compiler, which, together with
149 : : * additional information about optional parameters, could react on missing
150 : : * parameters then. */
151 : : static void MergeArgumentsFromFunctionResource();
152 : :
153 : : /** Minimum number of parameters, or fix number
154 : : of parameters if HasRepeatParameters()
155 : : returns sal_False. For opcodes not specified in
156 : : the implementation a parameter count of 1
157 : : is assumed, for opcodes out of range 0 is
158 : : assumed. If HasRepeatParameters() returns
159 : : sal_True, information is NOT related to whether
160 : : any parameters are optional, only the type
161 : : of parameters is significant. */
162 : : static inline sal_uInt8 GetMinimumParameters( OpCode eOp)
163 : : {
164 : : if ( eOp <= SC_OPCODE_LAST_OPCODE_ID )
165 : : return pData[eOp].aData.nParam[0]
166 : : == Unknown ? 1 :
167 : : pData[eOp].nMinParams;
168 : : return 0;
169 : : }
170 : :
171 : : /** Whether last parameter type is repeated. */
172 : : static inline bool HasRepeatParameters( OpCode eOp)
173 : : {
174 : : return eOp <= SC_OPCODE_LAST_OPCODE_ID
175 : : && pData[eOp].aData.bRepeatLast;
176 : : }
177 : : #endif // OSL_DEBUG_LEVEL
178 : : };
179 : :
180 : : #endif // SC_PARCLASS_HXX
181 : :
182 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|