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

Generated by: LCOV version 1.10