LCOV - code coverage report
Current view: top level - sc/source/core/tool - parclass.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 39 81 48.1 %
Date: 2015-06-13 12:38:46 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11