xref: /aoo41x/main/sc/source/core/inc/parclass.hxx (revision 6e86bbc1)
138d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
338d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
438d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
538d50f7bSAndrew Rist  * distributed with this work for additional information
638d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
738d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
838d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
938d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
1038d50f7bSAndrew Rist  *
1138d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1238d50f7bSAndrew Rist  *
1338d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1438d50f7bSAndrew Rist  * software distributed under the License is distributed on an
1538d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1638d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
1738d50f7bSAndrew Rist  * specific language governing permissions and limitations
1838d50f7bSAndrew Rist  * under the License.
1938d50f7bSAndrew Rist  *
2038d50f7bSAndrew Rist  *************************************************************/
2138d50f7bSAndrew Rist 
2238d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_PARCLASS_HXX
25cdf0e10cSrcweir #define SC_PARCLASS_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "formula/opcode.hxx"
28cdf0e10cSrcweir #include <sys/types.h>  // size_t
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace formula
31cdf0e10cSrcweir {
32cdf0e10cSrcweir     class FormulaToken;
33cdf0e10cSrcweir }
34cdf0e10cSrcweir 
35cdf0e10cSrcweir class ScParameterClassification
36cdf0e10cSrcweir {
37cdf0e10cSrcweir public:
38cdf0e10cSrcweir 
39cdf0e10cSrcweir     enum Type
40cdf0e10cSrcweir     {
41cdf0e10cSrcweir         Unknown = 0,    // MUST be zero for initialization mechanism!
42cdf0e10cSrcweir 
43cdf0e10cSrcweir         /** Out of bounds, function doesn't expect that many parameters.
44cdf0e10cSrcweir             However, not necessarily returned. */
45cdf0e10cSrcweir         Bounds,
46cdf0e10cSrcweir 
47cdf0e10cSrcweir         /** In array formula: single value to be passed. Results in JumpMatrix
48cdf0e10cSrcweir             being created and multiple calls to function. Functions handling a
49cdf0e10cSrcweir             formula::svDoubleRef by means of DoubleRefToPosSingleRef() or
50cdf0e10cSrcweir             PopDoubleRefOrSingleRef() or GetDouble() or GetString() should have
51cdf0e10cSrcweir             this. */
52cdf0e10cSrcweir         Value,
53cdf0e10cSrcweir 
54cdf0e10cSrcweir         /** In array formula: area reference must stay reference. Otherwise
55cdf0e10cSrcweir             don't care. Functions handling a formula::svDoubleRef by means of
56cdf0e10cSrcweir             PopDoubleRefOrSingleRef() should not have this. */
57cdf0e10cSrcweir         Reference,
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         /** In array formula: convert area reference to array. Function will be
60cdf0e10cSrcweir             called only once if no Value type is involved. Functions able to
61cdf0e10cSrcweir             handle a svMatrix parameter but not a formula::svDoubleRef parameter as area
62cdf0e10cSrcweir             should have this. */
63cdf0e10cSrcweir         Array,
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         /** Area reference must be converted to array in any case, and must
66cdf0e10cSrcweir             also be propagated to subsequent operators and functions being part
67cdf0e10cSrcweir             of a parameter of this function. */
68cdf0e10cSrcweir         ForceArray,
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         /** Area reference is not converted to array, but ForceArray must be
71cdf0e10cSrcweir             propagated to subsequent operators and functions being part of a
72cdf0e10cSrcweir             parameter of this function. Used with functions that treat
73cdf0e10cSrcweir             references separately from arrays, but need the forced array
74cdf0e10cSrcweir             calculation of parameters that are not references.*/
75cdf0e10cSrcweir         ReferenceOrForceArray
76cdf0e10cSrcweir     };
77cdf0e10cSrcweir 
78cdf0e10cSrcweir                                 /// MUST be called once before any other method.
79cdf0e10cSrcweir     static  void                Init();
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     static  void                Exit();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir                                 /** Get one parameter type for function eOp.
84cdf0e10cSrcweir                                     @param nParameter
85cdf0e10cSrcweir                                         Which parameter, 0-based */
86cdf0e10cSrcweir     static  Type                GetParameterType( const formula::FormulaToken* pToken,
87cdf0e10cSrcweir                                         sal_uInt16 nParameter);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir                                 /** Whether OpCode has a parameter of type
90cdf0e10cSrcweir                                     ForceArray or ReferenceOrForceArray. */
HasForceArray(OpCode eOp)91cdf0e10cSrcweir     static  inline  bool        HasForceArray( OpCode eOp)
92cdf0e10cSrcweir                                     {
93cdf0e10cSrcweir                                         return 0 <= (short)eOp &&
94cdf0e10cSrcweir                                             eOp <= SC_OPCODE_LAST_OPCODE_ID &&
95cdf0e10cSrcweir                                             pData[eOp].bHasForceArray;
96cdf0e10cSrcweir                                     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir private:
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     struct CommonData
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         const static size_t nMaxParams = 7;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         Type        nParam[nMaxParams];
105*6e86bbc1SAndrew Rist         sal_uInt8   nRepeatLast;
106cdf0e10cSrcweir     };
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     // SUNWS7 needs a forward declared friend, otherwise members of the outer
109cdf0e10cSrcweir     // class are not accessible (in this case CommonData).
110cdf0e10cSrcweir     struct RawData;
111cdf0e10cSrcweir     friend struct ScParameterClassification::RawData;
112cdf0e10cSrcweir     struct RawData
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         OpCode      eOp;
115cdf0e10cSrcweir         CommonData  aData;
116cdf0e10cSrcweir     };
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     struct RunData;
119cdf0e10cSrcweir     friend struct ScParameterClassification::RunData;
120cdf0e10cSrcweir     struct RunData
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         CommonData  aData;
123cdf0e10cSrcweir         sal_uInt8        nMinParams;         // fix or minimum, or repeat start
124cdf0e10cSrcweir         bool        bHasForceArray;
125cdf0e10cSrcweir     };
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     static  const RawData       pRawData[];
128cdf0e10cSrcweir     static  RunData*            pData;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     // ocExternal AddIns
131cdf0e10cSrcweir     static  Type                GetExternalParameterType(
132cdf0e10cSrcweir                                     const formula::FormulaToken* pToken, sal_uInt16 nParameter);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
135cdf0e10cSrcweir     // Generate documentation to stdout if environment variable
136cdf0e10cSrcweir     // OOO_CALC_GENPARCLASSDOC is set.
137cdf0e10cSrcweir     static  void                GenerateDocumentation();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     /* OpCodes not specified in the implementation are taken from the global
140cdf0e10cSrcweir      * function list and all parameters, if any, are assumed to be of type
141cdf0e10cSrcweir      * Value. This could also be done in the product version if needed, but we
142cdf0e10cSrcweir      * don't want to spoil startup time. However, doing so could propagate the
143cdf0e10cSrcweir      * minimum parameter count to the formula compiler, which, together with
144cdf0e10cSrcweir      * additional information about optional parameters, could react on missing
145cdf0e10cSrcweir      * parameters then. */
146cdf0e10cSrcweir     static  void                MergeArgumentsFromFunctionResource();
147cdf0e10cSrcweir 
148cdf0e10cSrcweir                                 /** Minimum number of parameters, or fix number
149cdf0e10cSrcweir                                     of parameters if HasRepeatParameters()
150cdf0e10cSrcweir                                     returns sal_False. For opcodes not specified in
151cdf0e10cSrcweir                                     the implementation a parameter count of 1
152cdf0e10cSrcweir                                     is assumed, for opcodes out of range 0 is
153cdf0e10cSrcweir                                     assumed. If HasRepeatParameters() returns
154cdf0e10cSrcweir                                     sal_True, information is NOT related to whether
155cdf0e10cSrcweir                                     any parameters are optional, only the type
156cdf0e10cSrcweir                                     of parameters is significant. */
GetMinimumParameters(OpCode eOp)157cdf0e10cSrcweir     static  inline  sal_uInt8        GetMinimumParameters( OpCode eOp)
158cdf0e10cSrcweir                                     {
159cdf0e10cSrcweir                                         if ( eOp <= SC_OPCODE_LAST_OPCODE_ID )
160cdf0e10cSrcweir                                             return pData[eOp].aData.nParam[0]
161cdf0e10cSrcweir                                                 == Unknown ? 1 :
162cdf0e10cSrcweir                                                 pData[eOp].nMinParams;
163cdf0e10cSrcweir                                         return 0;
164cdf0e10cSrcweir                                     }
165cdf0e10cSrcweir 
166*6e86bbc1SAndrew Rist                                 /** Whether last parameter types are repeated. */
HasRepeatParameters(OpCode eOp)167cdf0e10cSrcweir     static  inline  bool        HasRepeatParameters( OpCode eOp)
168cdf0e10cSrcweir                                     {
169cdf0e10cSrcweir                                         return eOp <= SC_OPCODE_LAST_OPCODE_ID
170*6e86bbc1SAndrew Rist                                             && pData[eOp].aData.nRepeatLast > 0;
171cdf0e10cSrcweir                                     }
172cdf0e10cSrcweir #endif // OSL_DEBUG_LEVEL
173cdf0e10cSrcweir };
174cdf0e10cSrcweir 
175cdf0e10cSrcweir #endif // SC_PARCLASS_HXX
176cdf0e10cSrcweir 
177