LCOV - code coverage report
Current view: top level - sc/source/core/tool - parclass.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 39 81 48.1 %
Date: 2014-11-03 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 <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             :     { 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          76 : void ScParameterClassification::Init()
     230             : {
     231          76 :     if ( pData )
     232          76 :         return;
     233          76 :     pData = new RunData[ SC_OPCODE_LAST_OPCODE_ID + 1 ];
     234          76 :     memset( pData, 0, sizeof(RunData) * (SC_OPCODE_LAST_OPCODE_ID + 1));
     235             : 
     236             :     // init from specified static data above
     237       12084 :     for ( size_t i=0; i < SAL_N_ELEMENTS(pRawData); ++i )
     238             :     {
     239       12008 :         const RawData* pRaw = &pRawData[i];
     240       12008 :         if ( pRaw->eOp > SC_OPCODE_LAST_OPCODE_ID )
     241             :         {
     242             :             OSL_ENSURE( pRaw->eOp == ocNone, "RawData OpCode error");
     243             :         }
     244             :         else
     245             :         {
     246       11932 :             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       11932 :             memcpy( &(pRun->aData), &(pRaw->aData), sizeof(CommonData));
     254             :             // fill 0-initialized fields with real values
     255       11932 :             if ( pRun->aData.nRepeatLast )
     256             :             {
     257       31008 :                 for ( sal_Int32 j=0; j < CommonData::nMaxParams; ++j )
     258             :                 {
     259       27132 :                     if ( pRun->aData.nParam[j] )
     260        4636 :                         pRun->nMinParams = sal::static_int_cast<sal_uInt8>( j+1 );
     261       22496 :                     else if (j >= pRun->aData.nRepeatLast)
     262       22496 :                         pRun->aData.nParam[j] =  pRun->aData.nParam[j - pRun->aData.nRepeatLast];
     263             :                     else
     264             :                     {
     265             :                         OSL_TRACE( "bad classification: eOp %d, repeated param %d negative offset", pRaw->eOp, j);
     266           0 :                         pRun->aData.nParam[j] =  Unknown;
     267             :                     }
     268             :                 }
     269             :             }
     270             :             else
     271             :             {
     272       64448 :                 for ( sal_Int32 j=0; j < CommonData::nMaxParams; ++j )
     273             :                 {
     274       56392 :                     if ( !pRun->aData.nParam[j] )
     275             :                     {
     276       37392 :                         if ( j == 0 || pRun->aData.nParam[j-1] != Bounds )
     277        7676 :                             pRun->nMinParams = sal::static_int_cast<sal_uInt8>( j );
     278       37392 :                         pRun->aData.nParam[j] = Bounds;
     279             :                     }
     280             :                 }
     281        8436 :                 if ( !pRun->nMinParams &&
     282         380 :                         pRun->aData.nParam[CommonData::nMaxParams-1] != Bounds)
     283           0 :                     pRun->nMinParams = CommonData::nMaxParams;
     284             :             }
     285       82840 :             for ( sal_Int32 j=0; j < CommonData::nMaxParams; ++j )
     286             :             {
     287       72732 :                 if ( pRun->aData.nParam[j] == ForceArray || pRun->aData.nParam[j] == ReferenceOrForceArray )
     288             :                 {
     289        1824 :                     pRun->bHasForceArray = true;
     290        1824 :                     break;  // for
     291             :                 }
     292             :             }
     293             :         }
     294             :     }
     295             : 
     296             : #if OSL_DEBUG_LEVEL > 1
     297             :     GenerateDocumentation();
     298             : #endif
     299             : }
     300             : 
     301          20 : void ScParameterClassification::Exit()
     302             : {
     303          20 :     delete [] pData;
     304          20 :     pData = NULL;
     305          20 : }
     306             : 
     307         154 : ScParameterClassification::Type ScParameterClassification::GetParameterType(
     308             :         const formula::FormulaToken* pToken, sal_uInt16 nParameter)
     309             : {
     310         154 :     OpCode eOp = pToken->GetOpCode();
     311         154 :     switch ( eOp )
     312             :     {
     313             :         case ocExternal:
     314           0 :             return GetExternalParameterType( pToken, nParameter);
     315             :         //break;
     316             :         case ocMacro:
     317           0 :             return Reference;
     318             :         //break;
     319             :         default:
     320             :         {
     321             :             // added to avoid warnings
     322             :         }
     323             :     }
     324         154 :     if ( 0 <= (short)eOp && eOp <= SC_OPCODE_LAST_OPCODE_ID )
     325             :     {
     326             :         sal_uInt8 nRepeat;
     327             :         Type eType;
     328         154 :         if ( nParameter < CommonData::nMaxParams )
     329         154 :             eType = pData[eOp].aData.nParam[nParameter];
     330           0 :         else if ( (nRepeat = pData[eOp].aData.nRepeatLast) > 0 )
     331             :         {
     332             :             // The usual case is 1 repeated parameter, we don't need to
     333             :             // calculate that on each call.
     334             :             sal_uInt16 nParam = (nRepeat > 1 ?
     335           0 :                     (pData[eOp].nMinParams -
     336           0 :                      ((nParameter - pData[eOp].nMinParams) % nRepeat)) :
     337           0 :                     pData[eOp].nMinParams);
     338           0 :             return pData[eOp].aData.nParam[nParam];
     339             :         }
     340             :         else
     341           0 :             eType = Bounds;
     342         154 :         return eType == Unknown ? Value : eType;
     343             :     }
     344           0 :     return Unknown;
     345             : }
     346             : 
     347             : ScParameterClassification::Type
     348           0 : ScParameterClassification::GetExternalParameterType( const formula::FormulaToken* pToken,
     349             :         sal_uInt16 nParameter)
     350             : {
     351           0 :     Type eRet = Unknown;
     352             :     // similar to ScInterpreter::ScExternal()
     353           0 :     OUString aFuncName = ScGlobal::pCharClass->uppercase( pToken->GetExternal());
     354             :     {
     355           0 :         const FuncData* pFuncData = ScGlobal::GetFuncCollection()->findByName(aFuncName);
     356           0 :         if (pFuncData)
     357             :         {
     358           0 :             if ( nParameter >= pFuncData->GetParamCount() )
     359           0 :                 eRet = Bounds;
     360             :             else
     361             :             {
     362           0 :                 switch ( pFuncData->GetParamType( nParameter) )
     363             :                 {
     364             :                     case ParamType::PTR_DOUBLE:
     365             :                     case ParamType::PTR_STRING:
     366           0 :                         eRet = Value;
     367           0 :                     break;
     368             :                     default:
     369           0 :                         eRet = Reference;
     370             :                         // also array types are created using an area reference
     371             :                 }
     372             :             }
     373           0 :             return eRet;
     374             :         }
     375             :     }
     376             : 
     377             :     OUString aUnoName =
     378           0 :         ScGlobal::GetAddInCollection()->FindFunction(aFuncName, false);
     379             : 
     380           0 :     if (!aUnoName.isEmpty())
     381             :     {
     382             :         // the relevant parts of ScUnoAddInCall without having to create one
     383             :         const ScUnoAddInFuncData* pFuncData =
     384           0 :             ScGlobal::GetAddInCollection()->GetFuncData( aUnoName, true );      // need fully initialized data
     385           0 :         if ( pFuncData )
     386             :         {
     387           0 :             long nCount = pFuncData->GetArgumentCount();
     388           0 :             if ( nCount <= 0 )
     389           0 :                 eRet = Bounds;
     390             :             else
     391             :             {
     392           0 :                 const ScAddInArgDesc* pArgs = pFuncData->GetArguments();
     393           0 :                 if ( nParameter >= nCount &&
     394           0 :                         pArgs[nCount-1].eType == SC_ADDINARG_VARARGS )
     395           0 :                     eRet = Value;
     396             :                     // last arg is sequence, optional "any"s, we simply can't
     397             :                     // determine the type
     398           0 :                 if ( eRet == Unknown )
     399             :                 {
     400           0 :                     if ( nParameter >= nCount )
     401           0 :                         eRet = Bounds;
     402             :                     else
     403             :                     {
     404           0 :                         switch ( pArgs[nParameter].eType )
     405             :                         {
     406             :                             case SC_ADDINARG_INTEGER:
     407             :                             case SC_ADDINARG_DOUBLE:
     408             :                             case SC_ADDINARG_STRING:
     409           0 :                                 eRet = Value;
     410           0 :                             break;
     411             :                             default:
     412           0 :                                 eRet = Reference;
     413             :                         }
     414             :                     }
     415             :                 }
     416             :             }
     417             :         }
     418             :     }
     419           0 :     return eRet;
     420         228 : }
     421             : 
     422             : #if OSL_DEBUG_LEVEL > 1
     423             : 
     424             : // add remaining functions, all Value parameters
     425             : void ScParameterClassification::MergeArgumentsFromFunctionResource()
     426             : {
     427             :     ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
     428             :     for ( const ScFuncDesc* pDesc = pFuncList->First(); pDesc;
     429             :             pDesc = pFuncList->Next() )
     430             :     {
     431             :         if ( pDesc->nFIndex > SC_OPCODE_LAST_OPCODE_ID ||
     432             :                 pData[pDesc->nFIndex].aData.nParam[0] != Unknown )
     433             :             continue;   // not an internal opcode or already done
     434             : 
     435             :         RunData* pRun = &pData[ pDesc->nFIndex ];
     436             :         sal_uInt16 nArgs = pDesc->GetSuppressedArgCount();
     437             :         if ( nArgs >= PAIRED_VAR_ARGS )
     438             :         {
     439             :             nArgs -= PAIRED_VAR_ARGS - 2;
     440             :             pRun->aData.nRepeatLast = 2;
     441             :         }
     442             :         else if ( nArgs >= VAR_ARGS )
     443             :         {
     444             :             nArgs -= VAR_ARGS - 1;
     445             :             pRun->aData.nRepeatLast = 1;
     446             :         }
     447             :         if ( nArgs > CommonData::nMaxParams )
     448             :         {
     449             :             OStringBuffer aBuf;
     450             :             aBuf.append("ScParameterClassification::Init: too many arguments in listed function: ");
     451             :             aBuf.append(OUStringToOString(*(pDesc->pFuncName), RTL_TEXTENCODING_UTF8));
     452             :             aBuf.append(": ");
     453             :             aBuf.append(sal_Int32(nArgs));
     454             :             OSL_FAIL( aBuf.getStr());
     455             :             nArgs = CommonData::nMaxParams - 1;
     456             :             pRun->aData.nRepeatLast = 1;
     457             :         }
     458             :         pRun->nMinParams = static_cast< sal_uInt8 >( nArgs );
     459             :         for ( sal_Int32 j=0; j < nArgs; ++j )
     460             :         {
     461             :             pRun->aData.nParam[j] = Value;
     462             :         }
     463             :         if ( pRun->aData.nRepeatLast )
     464             :         {
     465             :             for ( sal_Int32 j = nArgs; j < CommonData::nMaxParams; ++j )
     466             :             {
     467             :                 pRun->aData.nParam[j] = Value;
     468             :             }
     469             :         }
     470             :         else
     471             :         {
     472             :             for ( sal_Int32 j = nArgs; j < CommonData::nMaxParams; ++j )
     473             :             {
     474             :                 pRun->aData.nParam[j] = Bounds;
     475             :             }
     476             :         }
     477             :     }
     478             : }
     479             : 
     480             : void ScParameterClassification::GenerateDocumentation()
     481             : {
     482             :     static const sal_Char aEnvVarName[] = "OOO_CALC_GENPARCLASSDOC";
     483             :     if ( !getenv( aEnvVarName) )
     484             :         return;
     485             :     MergeArgumentsFromFunctionResource();
     486             :     ScAddress aAddress;
     487             :     ScCompiler aComp(NULL,aAddress);
     488             :     ScCompiler::OpCodeMapPtr xMap( aComp.GetOpCodeMap(::com::sun::star::sheet::FormulaLanguage::ENGLISH));
     489             :     if (!xMap)
     490             :         return;
     491             :     fflush( stderr);
     492             :     size_t nCount = xMap->getSymbolCount();
     493             :     for ( size_t i=0; i<nCount; ++i )
     494             :     {
     495             :         OpCode eOp = OpCode(i);
     496             :         if ( !xMap->getSymbol(eOp).isEmpty() )
     497             :         {
     498             :             fprintf( stdout, "%s: ", aEnvVarName);
     499             :             OStringBuffer aStr(OUStringToOString(xMap->getSymbol(eOp), RTL_TEXTENCODING_UTF8));
     500             :             aStr.append('(');
     501             :             formula::FormulaByteToken aToken( eOp);
     502             :             sal_uInt8 nParams = GetMinimumParameters( eOp);
     503             :             // preset parameter count according to opcode value, with some
     504             :             // special handling
     505             :             if ( eOp < SC_OPCODE_STOP_DIV )
     506             :             {
     507             :                 switch ( eOp )
     508             :                 {
     509             :                     case ocIf:
     510             :                         aToken.SetByte(3);
     511             :                     break;
     512             :                     case ocIfError:
     513             :                     case ocIfNA:
     514             :                     case ocChose:
     515             :                         aToken.SetByte(2);
     516             :                     break;
     517             :                     case ocPercentSign:
     518             :                         aToken.SetByte(1);
     519             :                     break;
     520             :                     default:;
     521             :                 }
     522             :             }
     523             :             else if ( eOp < SC_OPCODE_STOP_ERRORS )
     524             :                 aToken.SetByte(0);
     525             :             else if ( eOp < SC_OPCODE_STOP_BIN_OP )
     526             :             {
     527             :                 switch ( eOp )
     528             :                 {
     529             :                     case ocAnd:
     530             :                     case ocOr:
     531             :                         aToken.SetByte(1);  // (r1)AND(r2) --> AND( r1, ...)
     532             :                     break;
     533             :                     default:
     534             :                         aToken.SetByte(2);
     535             :                 }
     536             :             }
     537             :             else if ( eOp < SC_OPCODE_STOP_UN_OP )
     538             :                 aToken.SetByte(1);
     539             :             else if ( eOp < SC_OPCODE_STOP_NO_PAR )
     540             :                 aToken.SetByte(0);
     541             :             else if ( eOp < SC_OPCODE_STOP_1_PAR )
     542             :                 aToken.SetByte(1);
     543             :             else
     544             :                 aToken.SetByte( nParams);
     545             :             // compare (this is a mere test for opcode order Div, BinOp, UnOp,
     546             :             // NoPar, 1Par, ...) and override parameter count with
     547             :             // classification
     548             :             if ( nParams != aToken.GetByte() )
     549             :                 fprintf( stdout, "(parameter count differs, token Byte: %d  classification: %d) ",
     550             :                         aToken.GetByte(), nParams);
     551             :             aToken.SetByte( nParams);
     552             :             if ( nParams != aToken.GetParamCount() )
     553             :                 fprintf( stdout, "(parameter count differs, token ParamCount: %d  classification: %d) ",
     554             :                         aToken.GetParamCount(), 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 ocZGZ:
     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             :             fprintf( stdout, "%s\n", aStr.getStr());
     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.10