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 : #include "parclass.hxx"
21 : #include "token.hxx"
22 : #include "global.hxx"
23 : #include "callform.hxx"
24 : #include "addincol.hxx"
25 : #include "funcdesc.hxx"
26 : #include <unotools/charclass.hxx>
27 : #include <osl/diagnose.h>
28 : #include <sal/macros.h>
29 : #include <string.h>
30 :
31 : #if OSL_DEBUG_LEVEL > 1
32 : // the documentation thingy
33 : #include <stdio.h>
34 : #include <com/sun/star/sheet/FormulaLanguage.hpp>
35 : #include <rtl/strbuf.hxx>
36 : #include "compiler.hxx"
37 : #include "sc.hrc"
38 : #endif
39 :
40 : /* Following assumptions are made:
41 : * - OpCodes not specified at all will have at least one and only parameters of
42 : * type Value, no check is done on the count of parameters => no Bounds type
43 : * is returned.
44 : * - For OpCodes with a variable number of parameters the type(s) of the last
45 : * repeated parameter(s) specified determine(s) the type(s) of all following
46 : * parameters.
47 : */
48 :
49 : const ScParameterClassification::RawData ScParameterClassification::pRawData[] =
50 : {
51 : // { OpCode, {{ Type, ... }, nRepeatLast }},
52 :
53 : // IF() and CHOOSE() are somewhat special, since the ScJumpMatrix is
54 : // created inside those functions and ConvertMatrixParameters() is not
55 : // called for them.
56 : { ocIf, {{ Array, Reference, Reference }, 0 }},
57 : { ocIfError, {{ Array, Reference }, 0 }},
58 : { ocIfNA, {{ Array, Reference }, 0 }},
59 : { ocChose, {{ Array, Reference }, 1 }},
60 : // Other specials.
61 : { ocOpen, {{ Bounds }, 0 }},
62 : { ocClose, {{ Bounds }, 0 }},
63 : { ocSep, {{ Bounds }, 0 }},
64 : { ocNoName, {{ Bounds }, 0 }},
65 : { ocStop, {{ Bounds }, 0 }},
66 : { ocUnion, {{ Reference, Reference }, 0 }},
67 : { ocRange, {{ Reference, Reference }, 0 }},
68 : // Functions with Value parameters only but not in resource.
69 : { ocBackSolver, {{ Value, Value, Value }, 0 }},
70 : { ocTableOp, {{ Value, Value, Value, Value, Value }, 0 }},
71 : // Operators and functions.
72 : { ocAdd, {{ Array, Array }, 0 }},
73 : { ocAmpersand, {{ Array, Array }, 0 }},
74 : { ocAnd, {{ Reference }, 1 }},
75 : { ocAreas, {{ Reference }, 0 }},
76 : { ocAveDev, {{ Reference }, 1 }},
77 : { ocAverage, {{ Reference }, 1 }},
78 : { ocAverageA, {{ Reference }, 1 }},
79 : { ocAverageIf, {{ Reference, Value, Reference }, 0 }},
80 : { ocAverageIfs, {{ Reference, Reference, Value }, 2 }},
81 : { ocCell, {{ Value, Reference }, 0 }},
82 : { ocColumn, {{ Reference }, 0 }},
83 : { ocColumns, {{ Reference }, 1 }},
84 : { ocCorrel, {{ ForceArray, ForceArray }, 0 }},
85 : { ocCount, {{ Reference }, 1 }},
86 : { ocCount2, {{ Reference }, 1 }},
87 : { ocCountEmptyCells, {{ Reference }, 0 }},
88 : { ocCountIf, {{ Reference, Value }, 0 }},
89 : { ocCountIfs, {{ Reference, Value }, 2 }},
90 : { ocCovar, {{ ForceArray, ForceArray }, 0 }},
91 : { ocCovarianceP, {{ ForceArray, ForceArray }, 0 }},
92 : { ocCovarianceS, {{ ForceArray, ForceArray }, 0 }},
93 : { ocDBAverage, {{ Reference, Reference, Reference }, 0 }},
94 : { ocDBCount, {{ Reference, Reference, Reference }, 0 }},
95 : { ocDBCount2, {{ Reference, Reference, Reference }, 0 }},
96 : { ocDBGet, {{ Reference, Reference, Reference }, 0 }},
97 : { ocDBMax, {{ Reference, Reference, Reference }, 0 }},
98 : { ocDBMin, {{ Reference, Reference, Reference }, 0 }},
99 : { ocDBProduct, {{ Reference, Reference, Reference }, 0 }},
100 : { ocDBStdDev, {{ Reference, Reference, Reference }, 0 }},
101 : { ocDBStdDevP, {{ Reference, Reference, Reference }, 0 }},
102 : { ocDBSum, {{ Reference, Reference, Reference }, 0 }},
103 : { ocDBVar, {{ Reference, Reference, Reference }, 0 }},
104 : { ocDBVarP, {{ Reference, Reference, Reference }, 0 }},
105 : { ocDevSq, {{ Reference }, 1 }},
106 : { ocDiv, {{ Array, Array }, 0 }},
107 : { ocEqual, {{ Array, Array }, 0 }},
108 : { ocForecast, {{ Value, ForceArray, ForceArray }, 0 }},
109 : { ocFrequency, {{ Reference, Reference }, 0 }},
110 : { ocFTest, {{ ForceArray, ForceArray }, 0 }},
111 : { ocGeoMean, {{ Reference }, 1 }},
112 : { ocGCD, {{ Reference }, 1 }},
113 : { ocGreater, {{ Array, Array }, 0 }},
114 : { ocGreaterEqual, {{ Array, Array }, 0 }},
115 : { ocGrowth, {{ Reference, Reference, Reference, Value }, 0 }},
116 : { ocHarMean, {{ Reference }, 1 }},
117 : { ocHLookup, {{ Value, Reference, Value, Value }, 0 }},
118 : { ocIRR, {{ Reference, Value }, 0 }},
119 : { ocIndex, {{ Reference, Value, Value, Value }, 0 }},
120 : { ocIntercept, {{ ForceArray, ForceArray }, 0 }},
121 : { ocIntersect, {{ Reference, Reference }, 0 }},
122 : { ocIsRef, {{ Reference }, 0 }},
123 : { ocLCM, {{ Reference }, 1 }},
124 : { ocKurt, {{ Reference }, 1 }},
125 : { ocLarge, {{ Reference, Value }, 0 }},
126 : { ocLess, {{ Array, Array }, 0 }},
127 : { ocLessEqual, {{ Array, Array }, 0 }},
128 : { ocLookup, {{ Value, ReferenceOrForceArray, ReferenceOrForceArray }, 0 }},
129 : { ocMatch, {{ Value, Reference, Reference }, 0 }},
130 : { ocMatDet, {{ ForceArray }, 0 }},
131 : { ocMatInv, {{ ForceArray }, 0 }},
132 : { ocMatMult, {{ ForceArray, ForceArray }, 0 }},
133 : { ocMatTrans, {{ Array }, 0 }}, // strange, but Xcl doesn't force MatTrans array
134 : { ocMatValue, {{ Reference, Value, Value }, 0 }},
135 : { ocMax, {{ Reference }, 1 }},
136 : { ocMaxA, {{ Reference }, 1 }},
137 : { ocMedian, {{ Reference }, 1 }},
138 : { ocMin, {{ Reference }, 1 }},
139 : { ocMinA, {{ Reference }, 1 }},
140 : { ocMIRR, {{ Reference, Value, Value }, 0 }},
141 : { ocModalValue, {{ ForceArray }, 1 }},
142 : { ocModalValue_MS, {{ ForceArray }, 1 }},
143 : { ocModalValue_Multi,{{ ForceArray }, 1 }},
144 : { ocMul, {{ Array, Array }, 0 }},
145 : { ocMultiArea, {{ Reference }, 1 }},
146 : { ocNPV, {{ Value, Reference }, 1 }},
147 : { ocNeg, {{ Array }, 0 }},
148 : { ocNegSub, {{ Array }, 0 }},
149 : { ocNot, {{ Array }, 0 }},
150 : { ocNotEqual, {{ Array, Array }, 0 }},
151 : { ocOffset, {{ Reference, Value, Value, Value, Value }, 0 }},
152 : { ocOr, {{ Reference }, 1 }},
153 : { ocPearson, {{ ForceArray, ForceArray }, 0 }},
154 : { ocPercentile, {{ Reference, Value }, 0 }},
155 : { ocPercentile_Exc, {{ Reference, Value }, 0 }},
156 : { ocPercentile_Inc, {{ Reference, Value }, 0 }},
157 : { ocPercentrank, {{ Reference, Value, Value }, 0 }},
158 : { ocPercentrank_Exc, {{ Reference, Value, Value }, 0 }},
159 : { ocPercentrank_Inc, {{ Reference, Value, Value }, 0 }},
160 : { ocPow, {{ Array, Array }, 0 }},
161 : { ocPower, {{ Array, Array }, 0 }},
162 : { ocProb, {{ ForceArray, ForceArray, Value, Value }, 0 }},
163 : { ocProduct, {{ Reference }, 1 }},
164 : { ocQuartile, {{ Reference, Value }, 0 }},
165 : { ocQuartile_Exc, {{ Reference, Value }, 0 }},
166 : { ocQuartile_Inc, {{ Reference, Value }, 0 }},
167 : { ocRank, {{ Value, Reference, Value }, 0 }},
168 : { ocRank_Avg, {{ Value, Reference, Value }, 0 }},
169 : { ocRank_Eq, {{ Value, Reference, Value }, 0 }},
170 : { ocRGP, {{ Reference, Reference, Value, Value }, 0 }},
171 : { ocRKP, {{ Reference, Reference, Value, Value }, 0 }},
172 : { ocRow, {{ Reference }, 0 }},
173 : { ocRows, {{ Reference }, 1 }},
174 : { ocRSQ, {{ ForceArray, ForceArray }, 0 }},
175 : { ocSchiefe, {{ Reference }, 1 }},
176 : { ocSkewp, {{ Reference }, 1 }},
177 : { ocSlope, {{ ForceArray, ForceArray }, 0 }},
178 : { ocSmall, {{ Reference, Value }, 0 }},
179 : { ocStDev, {{ Reference }, 1 }},
180 : { ocStDevA, {{ Reference }, 1 }},
181 : { ocStDevP, {{ Reference }, 1 }},
182 : { ocStDevPA, {{ Reference }, 1 }},
183 : { ocStDevP_MS, {{ Reference }, 1 }},
184 : { ocStDevS, {{ Reference }, 1 }},
185 : { ocSTEYX, {{ ForceArray, ForceArray }, 0 }},
186 : { ocSub, {{ Array, Array }, 0 }},
187 : { ocSubTotal, {{ Value, Reference }, 1 }},
188 : { ocSum, {{ Reference }, 1 }},
189 : { ocSumIf, {{ Reference, Value, Reference }, 0 }},
190 : { ocSumIfs, {{ Reference, Reference, Value }, 2 }},
191 : { ocSumProduct, {{ ForceArray }, 1 }},
192 : { ocSumSQ, {{ Reference }, 1 }},
193 : { ocSumX2MY2, {{ ForceArray, ForceArray }, 0 }},
194 : { ocSumX2DY2, {{ ForceArray, ForceArray }, 0 }},
195 : { ocSumXMY2, {{ ForceArray, ForceArray }, 0 }},
196 : { ocTable, {{ Reference }, 0 }},
197 : { ocTables, {{ Reference }, 1 }},
198 : { ocTrend, {{ Reference, Reference, Reference, Value }, 0 }},
199 : { ocTrimMean, {{ Reference, Value }, 0 }},
200 : { ocTTest, {{ ForceArray, ForceArray, Value, Value }, 0 }},
201 : { ocVar, {{ Reference }, 1 }},
202 : { ocVarA, {{ Reference }, 1 }},
203 : { ocVarP, {{ Reference }, 1 }},
204 : { ocVarPA, {{ Reference }, 1 }},
205 : { ocVarP_MS, {{ Reference }, 1 }},
206 : { ocVarS, {{ Reference }, 1 }},
207 : { ocVLookup, {{ Value, Reference, Value, Value }, 0 }},
208 : { ocXor, {{ Reference }, 1 }},
209 : { ocZTest, {{ Reference, Value, Value }, 0 }},
210 : { ocZTest_MS, {{ Reference, Value, Value }, 0 }},
211 : { ocNetWorkdays_MS, {{ Value, Value, Value, Reference }, 0 }},
212 : { ocWorkday_MS, {{ Value, Value, Value, Reference }, 0 }},
213 : // Excel doubts:
214 : // ocN, ocT: Excel says (and handles) Reference, error? This means no
215 : // position dependent SingleRef if DoubleRef, and no array calculation,
216 : // just the upper left corner. We never did that for ocT and now also not
217 : // for ocN (position dependent intersection worked before but array
218 : // didn't). No specifics in ODFF, so the general rule applies. Gnumeric
219 : // does the same.
220 : { ocN, {{ Value }, 0 }},
221 : { ocT, {{ Value }, 0 }},
222 : // The stopper.
223 : { ocNone, {{ Bounds }, 0 } }
224 : };
225 :
226 : ScParameterClassification::RunData * ScParameterClassification::pData = NULL;
227 :
228 0 : void ScParameterClassification::Init()
229 : {
230 0 : if ( pData )
231 0 : return;
232 0 : pData = new RunData[ SC_OPCODE_LAST_OPCODE_ID + 1 ];
233 0 : memset( pData, 0, sizeof(RunData) * (SC_OPCODE_LAST_OPCODE_ID + 1));
234 :
235 : // init from specified static data above
236 0 : for ( size_t i=0; i < SAL_N_ELEMENTS(pRawData); ++i )
237 : {
238 0 : const RawData* pRaw = &pRawData[i];
239 0 : if ( pRaw->eOp > SC_OPCODE_LAST_OPCODE_ID )
240 : {
241 : OSL_ENSURE( pRaw->eOp == ocNone, "RawData OpCode error");
242 : }
243 : else
244 : {
245 0 : RunData* pRun = &pData[ pRaw->eOp ];
246 : #if OSL_DEBUG_LEVEL > 1
247 : if ( pRun->aData.nParam[0] != Unknown )
248 : {
249 : OSL_TRACE( "already assigned: %d", pRaw->eOp);
250 : }
251 : #endif
252 0 : memcpy( &(pRun->aData), &(pRaw->aData), sizeof(CommonData));
253 : // fill 0-initialized fields with real values
254 0 : if ( pRun->aData.nRepeatLast )
255 : {
256 0 : for ( sal_Int32 j=0; j < CommonData::nMaxParams; ++j )
257 : {
258 0 : if ( pRun->aData.nParam[j] )
259 0 : pRun->nMinParams = sal::static_int_cast<sal_uInt8>( j+1 );
260 0 : else if (j >= pRun->aData.nRepeatLast)
261 0 : pRun->aData.nParam[j] = pRun->aData.nParam[j - pRun->aData.nRepeatLast];
262 : else
263 : {
264 : OSL_TRACE( "bad classification: eOp %d, repeated param %d negative offset", pRaw->eOp, j);
265 0 : pRun->aData.nParam[j] = Unknown;
266 : }
267 : }
268 : }
269 : else
270 : {
271 0 : for ( sal_Int32 j=0; j < CommonData::nMaxParams; ++j )
272 : {
273 0 : if ( !pRun->aData.nParam[j] )
274 : {
275 0 : if ( j == 0 || pRun->aData.nParam[j-1] != Bounds )
276 0 : pRun->nMinParams = sal::static_int_cast<sal_uInt8>( j );
277 0 : pRun->aData.nParam[j] = Bounds;
278 : }
279 : }
280 0 : if ( !pRun->nMinParams &&
281 0 : pRun->aData.nParam[CommonData::nMaxParams-1] != Bounds)
282 0 : pRun->nMinParams = CommonData::nMaxParams;
283 : }
284 0 : for ( sal_Int32 j=0; j < CommonData::nMaxParams; ++j )
285 : {
286 0 : if ( pRun->aData.nParam[j] == ForceArray || pRun->aData.nParam[j] == ReferenceOrForceArray )
287 : {
288 0 : pRun->bHasForceArray = true;
289 0 : break; // for
290 : }
291 : }
292 : }
293 : }
294 :
295 : #if OSL_DEBUG_LEVEL > 1
296 : GenerateDocumentation();
297 : #endif
298 : }
299 :
300 0 : void ScParameterClassification::Exit()
301 : {
302 0 : delete [] pData;
303 0 : pData = NULL;
304 0 : }
305 :
306 0 : ScParameterClassification::Type ScParameterClassification::GetParameterType(
307 : const formula::FormulaToken* pToken, sal_uInt16 nParameter)
308 : {
309 0 : OpCode eOp = pToken->GetOpCode();
310 0 : switch ( eOp )
311 : {
312 : case ocExternal:
313 0 : return GetExternalParameterType( pToken, nParameter);
314 : //break;
315 : case ocMacro:
316 0 : return Reference;
317 : //break;
318 : default:
319 : {
320 : // added to avoid warnings
321 : }
322 : }
323 0 : if ( 0 <= (short)eOp && eOp <= SC_OPCODE_LAST_OPCODE_ID )
324 : {
325 : sal_uInt8 nRepeat;
326 : Type eType;
327 0 : if ( nParameter < CommonData::nMaxParams )
328 0 : eType = pData[eOp].aData.nParam[nParameter];
329 0 : else if ( (nRepeat = pData[eOp].aData.nRepeatLast) > 0 )
330 : {
331 : // The usual case is 1 repeated parameter, we don't need to
332 : // calculate that on each call.
333 : sal_uInt16 nParam = (nRepeat > 1 ?
334 0 : (pData[eOp].nMinParams -
335 0 : ((nParameter - pData[eOp].nMinParams) % nRepeat)) :
336 0 : pData[eOp].nMinParams);
337 0 : return pData[eOp].aData.nParam[nParam];
338 : }
339 : else
340 0 : eType = Bounds;
341 0 : return eType == Unknown ? Value : eType;
342 : }
343 0 : return Unknown;
344 : }
345 :
346 : ScParameterClassification::Type
347 0 : ScParameterClassification::GetExternalParameterType( const formula::FormulaToken* pToken,
348 : sal_uInt16 nParameter)
349 : {
350 0 : Type eRet = Unknown;
351 : // similar to ScInterpreter::ScExternal()
352 0 : OUString aFuncName = ScGlobal::pCharClass->uppercase( pToken->GetExternal());
353 : {
354 0 : const FuncData* pFuncData = ScGlobal::GetFuncCollection()->findByName(aFuncName);
355 0 : if (pFuncData)
356 : {
357 0 : if ( nParameter >= pFuncData->GetParamCount() )
358 0 : eRet = Bounds;
359 : else
360 : {
361 0 : switch ( pFuncData->GetParamType( nParameter) )
362 : {
363 : case PTR_DOUBLE:
364 : case PTR_STRING:
365 0 : eRet = Value;
366 0 : break;
367 : default:
368 0 : eRet = Reference;
369 : // also array types are created using an area reference
370 : }
371 : }
372 0 : return eRet;
373 : }
374 : }
375 :
376 : OUString aUnoName =
377 0 : ScGlobal::GetAddInCollection()->FindFunction(aFuncName, false);
378 :
379 0 : if (!aUnoName.isEmpty())
380 : {
381 : // the relevant parts of ScUnoAddInCall without having to create one
382 : const ScUnoAddInFuncData* pFuncData =
383 0 : ScGlobal::GetAddInCollection()->GetFuncData( aUnoName, true ); // need fully initialized data
384 0 : if ( pFuncData )
385 : {
386 0 : long nCount = pFuncData->GetArgumentCount();
387 0 : if ( nCount <= 0 )
388 0 : eRet = Bounds;
389 : else
390 : {
391 0 : const ScAddInArgDesc* pArgs = pFuncData->GetArguments();
392 0 : if ( nParameter >= nCount &&
393 0 : pArgs[nCount-1].eType == SC_ADDINARG_VARARGS )
394 0 : eRet = Value;
395 : // last arg is sequence, optional "any"s, we simply can't
396 : // determine the type
397 0 : if ( eRet == Unknown )
398 : {
399 0 : if ( nParameter >= nCount )
400 0 : eRet = Bounds;
401 : else
402 : {
403 0 : switch ( pArgs[nParameter].eType )
404 : {
405 : case SC_ADDINARG_INTEGER:
406 : case SC_ADDINARG_DOUBLE:
407 : case SC_ADDINARG_STRING:
408 0 : eRet = Value;
409 0 : break;
410 : default:
411 0 : eRet = Reference;
412 : }
413 : }
414 : }
415 : }
416 : }
417 : }
418 0 : return eRet;
419 : }
420 :
421 : #if OSL_DEBUG_LEVEL > 1
422 :
423 : // add remaining functions, all Value parameters
424 : void ScParameterClassification::MergeArgumentsFromFunctionResource()
425 : {
426 : ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
427 : for ( const ScFuncDesc* pDesc = pFuncList->First(); pDesc;
428 : pDesc = pFuncList->Next() )
429 : {
430 : if ( pDesc->nFIndex > SC_OPCODE_LAST_OPCODE_ID ||
431 : pData[pDesc->nFIndex].aData.nParam[0] != Unknown )
432 : continue; // not an internal opcode or already done
433 :
434 : RunData* pRun = &pData[ pDesc->nFIndex ];
435 : sal_uInt16 nArgs = pDesc->GetSuppressedArgCount();
436 : if ( nArgs >= PAIRED_VAR_ARGS )
437 : {
438 : nArgs -= PAIRED_VAR_ARGS - 2;
439 : pRun->aData.nRepeatLast = 2;
440 : }
441 : else if ( nArgs >= VAR_ARGS )
442 : {
443 : nArgs -= VAR_ARGS - 1;
444 : pRun->aData.nRepeatLast = 1;
445 : }
446 : if ( nArgs > CommonData::nMaxParams )
447 : {
448 : OStringBuffer aBuf;
449 : aBuf.append("ScParameterClassification::Init: too many arguments in listed function: ");
450 : aBuf.append(OUStringToOString(*(pDesc->pFuncName), RTL_TEXTENCODING_UTF8));
451 : aBuf.append(": ");
452 : aBuf.append(sal_Int32(nArgs));
453 : OSL_FAIL( aBuf.getStr());
454 : nArgs = CommonData::nMaxParams - 1;
455 : pRun->aData.nRepeatLast = 1;
456 : }
457 : pRun->nMinParams = static_cast< sal_uInt8 >( nArgs );
458 : for ( sal_Int32 j=0; j < nArgs; ++j )
459 : {
460 : pRun->aData.nParam[j] = Value;
461 : }
462 : if ( pRun->aData.nRepeatLast )
463 : {
464 : for ( sal_Int32 j = nArgs; j < CommonData::nMaxParams; ++j )
465 : {
466 : pRun->aData.nParam[j] = Value;
467 : }
468 : }
469 : else
470 : {
471 : for ( sal_Int32 j = nArgs; j < CommonData::nMaxParams; ++j )
472 : {
473 : pRun->aData.nParam[j] = Bounds;
474 : }
475 : }
476 : }
477 : }
478 :
479 : void ScParameterClassification::GenerateDocumentation()
480 : {
481 : static const sal_Char aEnvVarName[] = "OOO_CALC_GENPARCLASSDOC";
482 : if ( !getenv( aEnvVarName) )
483 : return;
484 : MergeArgumentsFromFunctionResource();
485 : ScAddress aAddress;
486 : ScCompiler aComp(NULL,aAddress);
487 : ScCompiler::OpCodeMapPtr xMap( aComp.GetOpCodeMap(::com::sun::star::sheet::FormulaLanguage::ENGLISH));
488 : if (!xMap)
489 : return;
490 : fflush( stderr);
491 : size_t nCount = xMap->getSymbolCount();
492 : for ( size_t i=0; i<nCount; ++i )
493 : {
494 : OpCode eOp = OpCode(i);
495 : if ( !xMap->getSymbol(eOp).isEmpty() )
496 : {
497 : fprintf( stdout, "%s: ", aEnvVarName);
498 : OStringBuffer aStr(OUStringToOString(xMap->getSymbol(eOp), RTL_TEXTENCODING_UTF8));
499 : aStr.append('(');
500 : formula::FormulaByteToken aToken( eOp);
501 : sal_uInt8 nParams = GetMinimumParameters( eOp);
502 : // preset parameter count according to opcode value, with some
503 : // special handling
504 : if ( eOp < SC_OPCODE_STOP_DIV )
505 : {
506 : switch ( eOp )
507 : {
508 : case ocIf:
509 : aToken.SetByte(3);
510 : break;
511 : case ocIfError:
512 : case ocIfNA:
513 : case ocChose:
514 : aToken.SetByte(2);
515 : break;
516 : case ocPercentSign:
517 : aToken.SetByte(1);
518 : break;
519 : default:;
520 : }
521 : }
522 : else if ( eOp < SC_OPCODE_STOP_ERRORS )
523 : aToken.SetByte(0);
524 : else if ( eOp < SC_OPCODE_STOP_BIN_OP )
525 : {
526 : switch ( eOp )
527 : {
528 : case ocAnd:
529 : case ocOr:
530 : aToken.SetByte(1); // (r1)AND(r2) --> AND( r1, ...)
531 : break;
532 : default:
533 : aToken.SetByte(2);
534 : }
535 : }
536 : else if ( eOp < SC_OPCODE_STOP_UN_OP )
537 : aToken.SetByte(1);
538 : else if ( eOp < SC_OPCODE_STOP_NO_PAR )
539 : aToken.SetByte(0);
540 : else if ( eOp < SC_OPCODE_STOP_1_PAR )
541 : aToken.SetByte(1);
542 : else
543 : aToken.SetByte( nParams);
544 : // compare (this is a mere test for opcode order Div, BinOp, UnOp,
545 : // NoPar, 1Par, ...) and override parameter count with
546 : // classification
547 : if ( nParams != aToken.GetByte() )
548 : fprintf( stdout, "(parameter count differs, token Byte: %d classification: %d) ",
549 : aToken.GetByte(), nParams);
550 : aToken.SetByte( nParams);
551 : if ( nParams != aToken.GetParamCount() )
552 : fprintf( stdout, "(parameter count differs, token ParamCount: %d classification: %d) ",
553 : aToken.GetParamCount(), nParams);
554 : for ( sal_uInt16 j=0; j < nParams; ++j )
555 : {
556 : if ( j > 0 )
557 : aStr.append(',');
558 : Type eType = GetParameterType( &aToken, j);
559 : switch ( eType )
560 : {
561 : case Value :
562 : aStr.append(" Value");
563 : break;
564 : case Reference :
565 : aStr.append(" Reference");
566 : break;
567 : case Array :
568 : aStr.append(" Array");
569 : break;
570 : case ForceArray :
571 : aStr.append(" ForceArray");
572 : break;
573 : case ReferenceOrForceArray :
574 : aStr.append(" ReferenceOrForceArray");
575 : break;
576 : case Bounds :
577 : aStr.append(" (Bounds, classification error?)");
578 : break;
579 : default:
580 : aStr.append(" (???, classification error?)");
581 : }
582 : }
583 : if ( HasRepeatParameters( eOp) )
584 : aStr.append(", ...");
585 : if ( nParams )
586 : aStr.append(' ');
587 : aStr.append(')');
588 : switch ( eOp )
589 : {
590 : case ocZGZ:
591 : aStr.append(" // RRI in English resource, but ZGZ in English-only section");
592 : break;
593 : case ocMultiArea:
594 : aStr.append(" // e.g. combined first parameter of INDEX() function, not a real function");
595 : break;
596 : case ocBackSolver:
597 : aStr.append(" // goal seek via menu, not a real function");
598 : break;
599 : case ocTableOp:
600 : aStr.append(" // MULTIPLE.OPERATIONS in English resource, but TABLE in English-only section");
601 : break;
602 : case ocNoName:
603 : aStr.append(" // error function, not a real function");
604 : break;
605 : default:;
606 : }
607 : fprintf( stdout, "%s\n", aStr.getStr());
608 : }
609 : }
610 : fflush( stdout);
611 : }
612 :
613 : #endif // OSL_DEBUG_LEVEL
614 :
615 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|