LCOV - code coverage report
Current view: top level - basic/source/comp - codegen.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 112 268 41.8 %
Date: 2012-08-25 Functions: 8 66 12.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 65 345 18.8 %

           Branch data     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                 :            : 
      21                 :            : #include <basic/sbx.hxx>
      22                 :            : #include "sbcomp.hxx"
      23                 :            : #include "image.hxx"
      24                 :            : #include <limits>
      25                 :            : #include <algorithm>
      26                 :            : #include <com/sun/star/script/ModuleType.hpp>
      27                 :            : 
      28                 :            : // nInc is the increment size of the buffers
      29                 :            : 
      30                 :         65 : SbiCodeGen::SbiCodeGen( SbModule& r, SbiParser* p, short nInc )
      31                 :         65 :          : rMod( r ), aCode( p, nInc )
      32                 :            : {
      33                 :         65 :     pParser = p;
      34                 :         65 :     bStmnt = false;
      35                 :         65 :     nLine = 0;
      36                 :         65 :     nCol = 0;
      37                 :         65 :     nForLevel = 0;
      38                 :         65 : }
      39                 :            : 
      40                 :      19523 : sal_uInt32 SbiCodeGen::GetPC()
      41                 :            : {
      42                 :      19523 :     return aCode.GetSize();
      43                 :            : }
      44                 :            : 
      45                 :            : // memorize the statement
      46                 :            : 
      47                 :       3082 : void SbiCodeGen::Statement()
      48                 :            : {
      49                 :       3082 :     bStmnt = true;
      50                 :            : 
      51                 :       3082 :     nLine = pParser->GetLine();
      52                 :       3082 :     nCol  = pParser->GetCol1();
      53                 :            : 
      54                 :            :     // #29955 Store the information of the for-loop-layer
      55                 :            :     // in the uppper Byte of the column
      56                 :       3082 :     nCol = (nCol & 0xff) + 0x100 * nForLevel;
      57                 :       3082 : }
      58                 :            : 
      59                 :            : // Mark the beginning of a statement
      60                 :            : 
      61                 :      19487 : void SbiCodeGen::GenStmnt()
      62                 :            : {
      63         [ +  + ]:      19487 :     if( bStmnt )
      64                 :            :     {
      65                 :       2888 :         bStmnt = false;
      66                 :       2888 :         Gen( _STMNT, nLine, nCol );
      67                 :            :     }
      68                 :      19487 : }
      69                 :            : 
      70                 :            : // The Gen-Routines return the offset of the 1. operand,
      71                 :            : // so that jumps can sink their backchain there.
      72                 :            : 
      73                 :       6944 : sal_uInt32 SbiCodeGen::Gen( SbiOpcode eOpcode )
      74                 :            : {
      75                 :            : #ifdef DBG_UTIL
      76                 :            :     if( eOpcode < SbOP0_START || eOpcode > SbOP0_END )
      77                 :            :         pParser->Error( SbERR_INTERNAL_ERROR, "OPCODE1" );
      78                 :            : #endif
      79                 :       6944 :     GenStmnt();
      80                 :       6944 :     aCode += (sal_uInt8) eOpcode;
      81                 :       6944 :     return GetPC();
      82                 :            : }
      83                 :            : 
      84                 :       3058 : sal_uInt32 SbiCodeGen::Gen( SbiOpcode eOpcode, sal_uInt32 nOpnd )
      85                 :            : {
      86                 :            : #ifdef DBG_UTIL
      87                 :            :     if( eOpcode < SbOP1_START || eOpcode > SbOP1_END )
      88                 :            :         pParser->Error( SbERR_INTERNAL_ERROR, "OPCODE2" );
      89                 :            : #endif
      90                 :       3058 :     GenStmnt();
      91                 :       3058 :     aCode += (sal_uInt8) eOpcode;
      92                 :       3058 :     sal_uInt32 n = GetPC();
      93                 :       3058 :     aCode += nOpnd;
      94                 :       3058 :     return n;
      95                 :            : }
      96                 :            : 
      97                 :       9256 : sal_uInt32 SbiCodeGen::Gen( SbiOpcode eOpcode, sal_uInt32 nOpnd1, sal_uInt32 nOpnd2 )
      98                 :            : {
      99                 :            : #ifdef DBG_UTIL
     100                 :            :     if( eOpcode < SbOP2_START || eOpcode > SbOP2_END )
     101                 :            :         pParser->Error( SbERR_INTERNAL_ERROR, "OPCODE3" );
     102                 :            : #endif
     103                 :       9256 :     GenStmnt();
     104                 :       9256 :     aCode += (sal_uInt8) eOpcode;
     105                 :       9256 :     sal_uInt32 n = GetPC();
     106                 :       9256 :     aCode += nOpnd1;
     107                 :       9256 :     aCode += nOpnd2;
     108                 :       9256 :     return n;
     109                 :            : }
     110                 :            : 
     111                 :            : // Storing of the created image in the module
     112                 :            : 
     113                 :         65 : void SbiCodeGen::Save()
     114                 :            : {
     115         [ +  - ]:         65 :     SbiImage* p = new SbiImage;
     116                 :         65 :     rMod.StartDefinitions();
     117                 :            :     // OPTION BASE-Value:
     118                 :         65 :     p->nDimBase = pParser->nBase;
     119                 :            :     // OPTION take over the EXPLICIT-Flag
     120         [ +  + ]:         65 :     if( pParser->bExplicit )
     121                 :          5 :         p->SetFlag( SBIMG_EXPLICIT );
     122                 :            : 
     123                 :         65 :     int nIfaceCount = 0;
     124         [ -  + ]:         65 :     if( rMod.mnType == com::sun::star::script::ModuleType::CLASS )
     125                 :            :     {
     126                 :            :                 OSL_TRACE("COdeGen::save() classmodule processing");
     127                 :          0 :         rMod.bIsProxyModule = true;
     128                 :          0 :         p->SetFlag( SBIMG_CLASSMODULE );
     129                 :          0 :         GetSbData()->pClassFac->AddClassModule( &rMod );
     130                 :            : 
     131                 :          0 :         nIfaceCount = pParser->aIfaceVector.size();
     132         [ #  # ]:          0 :         if( !rMod.pClassData )
     133         [ #  # ]:          0 :             rMod.pClassData = new SbClassData;
     134         [ #  # ]:          0 :         if( nIfaceCount )
     135                 :            :         {
     136         [ #  # ]:          0 :             for( int i = 0 ; i < nIfaceCount ; i++ )
     137                 :            :             {
     138                 :          0 :                 const String& rIfaceName = pParser->aIfaceVector[i];
     139         [ #  # ]:          0 :                 SbxVariable* pIfaceVar = new SbxVariable( SbxVARIANT );
     140                 :          0 :                 pIfaceVar->SetName( rIfaceName );
     141                 :          0 :                 SbxArray* pIfaces = rMod.pClassData->mxIfaces;
     142                 :          0 :                 pIfaces->Insert( pIfaceVar, pIfaces->Count() );
     143                 :            :             }
     144                 :            :         }
     145                 :            : 
     146                 :          0 :         rMod.pClassData->maRequiredTypes = pParser->aRequiredTypes;
     147                 :            :     }
     148                 :            :     else
     149                 :            :     {
     150                 :         65 :         GetSbData()->pClassFac->RemoveClassModule( &rMod );
     151                 :            :         // Only a ClassModule can revert to Normal
     152         [ -  + ]:         65 :                 if ( rMod.mnType == com::sun::star::script::ModuleType::CLASS )
     153                 :          0 :             rMod.mnType = com::sun::star::script::ModuleType::NORMAL;
     154                 :         65 :         rMod.bIsProxyModule = false;
     155                 :            :     }
     156                 :            : 
     157                 :            :     // GlobalCode-Flag
     158         [ +  + ]:         65 :     if( pParser->HasGlobalCode() )
     159                 :          8 :         p->SetFlag( SBIMG_INITCODE );
     160                 :            :     // Die Entrypoints:
     161         [ +  + ]:        661 :     for( SbiSymDef* pDef = pParser->aPublics.First(); pDef;
     162                 :        596 :                    pDef = pParser->aPublics.Next() )
     163                 :            :     {
     164                 :        596 :         SbiProcDef* pProc = pDef->GetProcDef();
     165 [ +  + ][ +  + ]:        596 :         if( pProc && pProc->IsDefined() )
                 [ +  + ]
     166                 :            :         {
     167 [ +  - ][ +  - ]:        197 :             String aProcName = pProc->GetName();
     168         [ +  - ]:        197 :             String aIfaceProcName;
     169         [ +  - ]:        197 :             String aIfaceName;
     170                 :        197 :             sal_uInt16 nPassCount = 1;
     171         [ -  + ]:        197 :             if( nIfaceCount )
     172                 :            :             {
     173                 :            :                 int nPropPrefixFound =
     174 [ #  # ][ #  # ]:          0 :                     aProcName.Search( String( RTL_CONSTASCII_USTRINGPARAM("Property ") ) );
                 [ #  # ]
     175         [ #  # ]:          0 :                 String aPureProcName = aProcName;
     176         [ #  # ]:          0 :                 String aPropPrefix;
     177         [ #  # ]:          0 :                 if( nPropPrefixFound == 0 )
     178                 :            :                 {
     179 [ #  # ][ #  # ]:          0 :                     aPropPrefix = aProcName.Copy( 0, 13 );      // 13 == Len( "Property ?et " )
                 [ #  # ]
     180 [ #  # ][ #  # ]:          0 :                     aPureProcName = aProcName.Copy( 13 );
                 [ #  # ]
     181                 :            :                 }
     182         [ #  # ]:          0 :                 for( int i = 0 ; i < nIfaceCount ; i++ )
     183                 :            :                 {
     184         [ #  # ]:          0 :                     const String& rIfaceName = pParser->aIfaceVector[i];
     185         [ #  # ]:          0 :                     int nFound = aPureProcName.Search( rIfaceName );
     186 [ #  # ][ #  # ]:          0 :                     if( nFound == 0 && '_' == aPureProcName.GetChar( rIfaceName.Len() ) )
                 [ #  # ]
     187                 :            :                     {
     188         [ #  # ]:          0 :                         if( nPropPrefixFound == 0 )
     189         [ #  # ]:          0 :                             aIfaceProcName += aPropPrefix;
     190 [ #  # ][ #  # ]:          0 :                         aIfaceProcName += aPureProcName.Copy( rIfaceName.Len() + 1 );
                 [ #  # ]
     191         [ #  # ]:          0 :                         aIfaceName = rIfaceName;
     192                 :          0 :                         nPassCount = 2;
     193                 :          0 :                         break;
     194                 :            :                     }
     195 [ #  # ][ #  # ]:          0 :                 }
     196                 :            :             }
     197                 :        197 :             SbMethod* pMeth = NULL;
     198         [ +  + ]:        394 :             for( sal_uInt16 nPass = 0 ; nPass < nPassCount ; nPass++ )
     199                 :            :             {
     200         [ -  + ]:        197 :                 if( nPass == 1 )
     201         [ #  # ]:          0 :                     aProcName = aIfaceProcName;
     202                 :            : 
     203                 :        197 :                 PropertyMode ePropMode = pProc->getPropertyMode();
     204         [ -  + ]:        197 :                 if( ePropMode != PROPERTY_MODE_NONE )
     205                 :            :                 {
     206                 :          0 :                     SbxDataType ePropType = SbxEMPTY;
     207   [ #  #  #  #  :          0 :                     switch( ePropMode )
                      # ]
     208                 :            :                     {
     209                 :            :                         case PROPERTY_MODE_GET:
     210                 :          0 :                             ePropType = pProc->GetType();
     211                 :          0 :                             break;
     212                 :            :                         case PROPERTY_MODE_LET:
     213                 :            :                         {
     214                 :            :                             // type == type of first parameter
     215                 :          0 :                             ePropType = SbxVARIANT;     // Default
     216                 :          0 :                             SbiSymPool* pPool = &pProc->GetParams();
     217         [ #  # ]:          0 :                             if( pPool->GetSize() > 1 )
     218                 :            :                             {
     219         [ #  # ]:          0 :                                 SbiSymDef* pPar = pPool->Get( 1 );
     220         [ #  # ]:          0 :                                 if( pPar )
     221                 :          0 :                                     ePropType = pPar->GetType();
     222                 :            :                             }
     223                 :          0 :                             break;
     224                 :            :                         }
     225                 :            :                         case PROPERTY_MODE_SET:
     226                 :          0 :                             ePropType = SbxOBJECT;
     227                 :          0 :                             break;
     228                 :            :                         case PROPERTY_MODE_NONE:
     229                 :            :                             OSL_FAIL( "Illegal PropertyMode PROPERTY_MODE_NONE" );
     230                 :          0 :                             break;
     231                 :            :                     }
     232         [ #  # ]:          0 :                     String aPropName = pProc->GetPropName();
     233         [ #  # ]:          0 :                     if( nPass == 1 )
     234 [ #  # ][ #  # ]:          0 :                         aPropName = aPropName.Copy( aIfaceName.Len() + 1 );
                 [ #  # ]
     235                 :            :                     OSL_TRACE("*** getProcedureProperty for thing %s",
     236                 :            :                         rtl::OUStringToOString( aPropName,RTL_TEXTENCODING_UTF8 ).getStr() );
     237 [ #  # ][ #  # ]:          0 :                     rMod.GetProcedureProperty( aPropName, ePropType );
     238                 :            :                 }
     239         [ -  + ]:        197 :                 if( nPass == 1 )
     240                 :            :                 {
     241         [ #  # ]:          0 :                     rMod.GetIfaceMapperMethod( aProcName, pMeth );
     242                 :            :                 }
     243                 :            :                 else
     244                 :            :                 {
     245         [ +  - ]:        197 :                     pMeth = rMod.GetMethod( aProcName, pProc->GetType() );
     246                 :            : 
     247         [ +  + ]:        197 :                     if( !pProc->IsPublic() )
     248                 :         17 :                         pMeth->SetFlag( SBX_PRIVATE );
     249                 :            : 
     250                 :            :                     // Declare? -> Hidden
     251         [ -  + ]:        197 :                     if( pProc->GetLib().Len() > 0 )
     252                 :          0 :                         pMeth->SetFlag( SBX_HIDDEN );
     253                 :            : 
     254                 :        197 :                     pMeth->nStart = pProc->GetAddr();
     255                 :        197 :                     pMeth->nLine1 = pProc->GetLine1();
     256                 :        197 :                     pMeth->nLine2 = pProc->GetLine2();
     257                 :            :                     // The parameter:
     258         [ +  - ]:        197 :                     SbxInfo* pInfo = pMeth->GetInfo();
     259 [ +  - ][ +  - ]:        197 :                     String aHelpFile, aComment;
     260                 :        197 :                     sal_uIntPtr nHelpId = 0;
     261         [ -  + ]:        197 :                     if( pInfo )
     262                 :            :                     {
     263                 :            :                         // Rescue the additional data
     264         [ #  # ]:          0 :                         aHelpFile = pInfo->GetHelpFile();
     265         [ #  # ]:          0 :                         aComment  = pInfo->GetComment();
     266                 :          0 :                         nHelpId   = pInfo->GetHelpId();
     267                 :            :                     }
     268                 :            :                     // And reestablish the parameter list
     269 [ +  - ][ +  - ]:        197 :                     pInfo = new SbxInfo( aHelpFile, nHelpId );
     270         [ +  - ]:        197 :                     pInfo->SetComment( aComment );
     271                 :        197 :                     SbiSymPool* pPool = &pProc->GetParams();
     272                 :            :                     // The first element is always the value of the function!
     273         [ +  + ]:        325 :                     for( sal_uInt16 i = 1; i < pPool->GetSize(); i++ )
     274                 :            :                     {
     275         [ +  - ]:        128 :                         SbiSymDef* pPar = pPool->Get( i );
     276                 :        128 :                         SbxDataType t = pPar->GetType();
     277         [ +  + ]:        128 :                         if( !pPar->IsByVal() )
     278                 :        122 :                             t = (SbxDataType) ( t | SbxBYREF );
     279         [ -  + ]:        128 :                         if( pPar->GetDims() )
     280                 :          0 :                             t = (SbxDataType) ( t | SbxARRAY );
     281                 :            :                         // #33677 hand-over an Optional-Info
     282                 :        128 :                         sal_uInt16 nFlags = SBX_READ;
     283         [ +  + ]:        128 :                         if( pPar->IsOptional() )
     284                 :          2 :                             nFlags |= SBX_OPTIONAL;
     285                 :            : 
     286 [ +  - ][ +  - ]:        128 :                         pInfo->AddParam( pPar->GetName(), t, nFlags );
                 [ +  - ]
     287                 :            : 
     288                 :        128 :                         sal_uInt32 nUserData = 0;
     289                 :        128 :                         sal_uInt16 nDefaultId = pPar->GetDefaultId();
     290         [ -  + ]:        128 :                         if( nDefaultId )
     291                 :          0 :                             nUserData |= nDefaultId;
     292         [ -  + ]:        128 :                         if( pPar->IsParamArray() )
     293                 :          0 :                             nUserData |= PARAM_INFO_PARAMARRAY;
     294         [ -  + ]:        128 :                         if( pPar->IsWithBrackets() )
     295                 :          0 :                             nUserData |= PARAM_INFO_WITHBRACKETS;
     296         [ -  + ]:        128 :                         if( nUserData )
     297                 :            :                         {
     298         [ #  # ]:          0 :                             SbxParamInfo* pParam = (SbxParamInfo*)pInfo->GetParam( i );
     299                 :          0 :                             pParam->nUserData = nUserData;
     300                 :            :                         }
     301                 :            :                     }
     302 [ +  - ][ +  - ]:        197 :                     pMeth->SetInfo( pInfo );
                 [ +  - ]
     303                 :            :                 }
     304                 :            : 
     305 [ +  - ][ +  - ]:        197 :             }   // for( iPass...
                 [ +  - ]
     306                 :            :         }
     307                 :            :     }
     308                 :            :     // The code
     309                 :         65 :     p->AddCode( aCode.GetBuffer(), aCode.GetSize() );
     310                 :            : 
     311                 :            :     // The global StringPool. 0 is not occupied.
     312                 :         65 :     SbiStringPool* pPool = &pParser->aGblStrings;
     313                 :         65 :     sal_uInt16 nSize = pPool->GetSize();
     314                 :         65 :     p->MakeStrings( nSize );
     315                 :            :     sal_uInt16 i;
     316         [ +  + ]:       2720 :     for( i = 1; i <= nSize; i++ )
     317         [ +  - ]:       2655 :         p->AddString( pPool->Find( i ) );
     318                 :            : 
     319                 :            :     // Insert types
     320                 :         65 :     sal_uInt16 nCount = pParser->rTypeArray->Count();
     321         [ -  + ]:         65 :     for (i = 0; i < nCount; i++)
     322                 :          0 :          p->AddType((SbxObject *)pParser->rTypeArray->Get(i));
     323                 :            : 
     324                 :            :     // Insert enum objects
     325                 :         65 :     nCount = pParser->rEnumArray->Count();
     326         [ -  + ]:         65 :     for (i = 0; i < nCount; i++)
     327                 :          0 :          p->AddEnum((SbxObject *)pParser->rEnumArray->Get(i));
     328                 :            : 
     329         [ +  - ]:         65 :     if( !p->IsError() )
     330                 :         65 :         rMod.pImage = p;
     331                 :            :     else
     332         [ #  # ]:          0 :         delete p;
     333                 :            : 
     334                 :         65 :     rMod.EndDefinitions();
     335                 :         65 : }
     336                 :            : 
     337                 :            : template < class T >
     338                 :          0 : class PCodeVisitor
     339                 :            : {
     340                 :            : public:
     341                 :            :     virtual ~PCodeVisitor();
     342                 :            : 
     343                 :            :     virtual void start( sal_uInt8* pStart ) = 0;
     344                 :            :     virtual void processOpCode0( SbiOpcode eOp ) = 0;
     345                 :            :     virtual void processOpCode1( SbiOpcode eOp, T nOp1 ) = 0;
     346                 :            :     virtual void processOpCode2( SbiOpcode eOp, T nOp1, T nOp2 ) = 0;
     347                 :            :     virtual bool processParams() = 0;
     348                 :            :     virtual void end() = 0;
     349                 :            : };
     350                 :            : 
     351                 :          0 : template <class T> PCodeVisitor< T >::~PCodeVisitor()
     352 [ #  # ][ #  # ]:          0 : {}
     353                 :            : 
     354                 :            : template <class T>
     355                 :            : class PCodeBufferWalker
     356                 :            : {
     357                 :            : private:
     358                 :            :     T  m_nBytes;
     359                 :            :     sal_uInt8* m_pCode;
     360                 :          0 :     T readParam( sal_uInt8*& pCode )
     361                 :            :     {
     362                 :          0 :         short nBytes = sizeof( T );
     363                 :          0 :         T nOp1=0;
     364 [ #  # ][ #  # ]:          0 :         for ( int i=0; i<nBytes; ++i )
     365                 :          0 :             nOp1 |= *pCode++ << ( i * 8);
     366                 :          0 :         return nOp1;
     367                 :            :     }
     368                 :            : public:
     369                 :          0 :     PCodeBufferWalker( sal_uInt8* pCode, T nBytes ): m_nBytes( nBytes ), m_pCode( pCode )
     370                 :            :     {
     371                 :          0 :     }
     372                 :          0 :     void visitBuffer( PCodeVisitor< T >& visitor )
     373                 :            :     {
     374                 :          0 :         sal_uInt8* pCode = m_pCode;
     375 [ #  # ][ #  # ]:          0 :         if ( !pCode )
     376                 :          0 :             return;
     377                 :          0 :         sal_uInt8* pEnd = pCode + m_nBytes;
     378 [ #  # ][ #  # ]:          0 :         visitor.start( m_pCode );
     379                 :          0 :         T nOp1 = 0, nOp2 = 0;
     380 [ #  # ][ #  # ]:          0 :         for( ; pCode < pEnd; )
     381                 :            :         {
     382                 :          0 :             SbiOpcode eOp = (SbiOpcode)(*pCode++);
     383                 :            : 
     384 [ #  # ][ #  # ]:          0 :             if ( eOp <= SbOP0_END )
     385 [ #  # ][ #  # ]:          0 :                 visitor.processOpCode0( eOp );
     386 [ #  # ][ #  # ]:          0 :             else if( eOp >= SbOP1_START && eOp <= SbOP1_END )
         [ #  # ][ #  # ]
     387                 :            :             {
     388 [ #  # ][ #  # ]:          0 :                 if ( visitor.processParams() )
         [ #  # ][ #  # ]
     389                 :          0 :                     nOp1 = readParam( pCode );
     390                 :            :                 else
     391                 :          0 :                     pCode += sizeof( T );
     392 [ #  # ][ #  # ]:          0 :                 visitor.processOpCode1( eOp, nOp1 );
     393                 :            :             }
     394 [ #  # ][ #  # ]:          0 :             else if( eOp >= SbOP2_START && eOp <= SbOP2_END )
         [ #  # ][ #  # ]
     395                 :            :             {
     396 [ #  # ][ #  # ]:          0 :                 if ( visitor.processParams() )
         [ #  # ][ #  # ]
     397                 :            :                 {
     398                 :          0 :                     nOp1 = readParam( pCode );
     399                 :          0 :                     nOp2 = readParam( pCode );
     400                 :            :                 }
     401                 :            :                 else
     402                 :          0 :                     pCode += ( sizeof( T ) * 2 );
     403 [ #  # ][ #  # ]:          0 :                 visitor.processOpCode2( eOp, nOp1, nOp2 );
     404                 :            :             }
     405                 :            :         }
     406 [ #  # ][ #  # ]:          0 :         visitor.end();
     407                 :            :     }
     408                 :            : };
     409                 :            : 
     410                 :            : template < class T, class S >
     411 [ #  # ][ #  # ]:          0 : class OffSetAccumulator : public PCodeVisitor< T >
     412                 :            : {
     413                 :            :     T m_nNumOp0;
     414                 :            :     T m_nNumSingleParams;
     415                 :            :     T m_nNumDoubleParams;
     416                 :            : public:
     417                 :            : 
     418                 :          0 :     OffSetAccumulator() : m_nNumOp0(0), m_nNumSingleParams(0), m_nNumDoubleParams(0){}
     419                 :          0 :     virtual void start( sal_uInt8* /*pStart*/ ){}
     420                 :          0 :     virtual void processOpCode0( SbiOpcode /*eOp*/ ){ ++m_nNumOp0; }
     421                 :          0 :     virtual void processOpCode1( SbiOpcode /*eOp*/, T /*nOp1*/ ){  ++m_nNumSingleParams; }
     422                 :          0 :     virtual void processOpCode2( SbiOpcode /*eOp*/, T /*nOp1*/, T /*nOp2*/ ) { ++m_nNumDoubleParams; }
     423                 :          0 :     virtual void end(){}
     424                 :          0 :     S offset()
     425                 :            :     {
     426                 :          0 :         T result = 0 ;
     427                 :            :         static const S max = std::numeric_limits< S >::max();
     428                 :          0 :         result = m_nNumOp0 + ( ( sizeof(S) + 1 ) * m_nNumSingleParams ) + ( (( sizeof(S) * 2 )+ 1 )  * m_nNumDoubleParams );
     429 [ #  # ][ #  # ]:          0 :         return std::min(static_cast<T>(max), result);
     430                 :            :     }
     431                 :          0 :    virtual bool processParams(){ return false; }
     432                 :            : };
     433                 :            : 
     434                 :            : 
     435                 :            : 
     436                 :            : template < class T, class S >
     437                 :            : 
     438 [ #  # ][ #  # ]:          0 : class BufferTransformer : public PCodeVisitor< T >
         [ #  # ][ #  # ]
     439                 :            : {
     440                 :            :     sal_uInt8* m_pStart;
     441                 :            :     SbiBuffer m_ConvertedBuf;
     442                 :            : public:
     443 [ #  # ][ #  # ]:          0 :     BufferTransformer():m_pStart(NULL), m_ConvertedBuf( NULL, 1024 ) {}
     444                 :          0 :     virtual void start( sal_uInt8* pStart ){ m_pStart = pStart; }
     445                 :          0 :     virtual void processOpCode0( SbiOpcode eOp )
     446                 :            :     {
     447                 :          0 :         m_ConvertedBuf += (sal_uInt8)eOp;
     448                 :          0 :     }
     449                 :          0 :     virtual void processOpCode1( SbiOpcode eOp, T nOp1 )
     450                 :            :     {
     451                 :          0 :         m_ConvertedBuf += (sal_uInt8)eOp;
     452   [ #  #  #  #  :          0 :         switch( eOp )
                   #  # ]
     453                 :            :         {
     454                 :            :             case _JUMP:
     455                 :            :             case _JUMPT:
     456                 :            :             case _JUMPF:
     457                 :            :             case _GOSUB:
     458                 :            :             case _CASEIS:
     459                 :            :             case _RETURN:
     460                 :            :             case _ERRHDL:
     461                 :            :             case _TESTFOR:
     462                 :          0 :                 nOp1 = static_cast<T>( convertBufferOffSet(m_pStart, nOp1) );
     463                 :          0 :                 break;
     464                 :            :             case _RESUME:
     465 [ #  # ][ #  # ]:          0 :                 if ( nOp1 > 1 )
     466                 :          0 :                     nOp1 = static_cast<T>( convertBufferOffSet(m_pStart, nOp1) );
     467                 :          0 :                 break;
     468                 :            :             default:
     469                 :          0 :                 break; //
     470                 :            : 
     471                 :            :         }
     472                 :          0 :         m_ConvertedBuf += (S)nOp1;
     473                 :          0 :     }
     474                 :          0 :     virtual void processOpCode2( SbiOpcode eOp, T nOp1, T nOp2 )
     475                 :            :     {
     476                 :          0 :         m_ConvertedBuf += (sal_uInt8)eOp;
     477   [ #  #  #  # ]:          0 :         if ( eOp == _CASEIS )
     478 [ #  # ][ #  # ]:          0 :                 if ( nOp1 )
     479                 :          0 :                     nOp1 = static_cast<T>( convertBufferOffSet(m_pStart, nOp1) );
     480                 :          0 :         m_ConvertedBuf += (S)nOp1;
     481                 :          0 :         m_ConvertedBuf += (S)nOp2;
     482                 :            : 
     483                 :          0 :     }
     484                 :          0 :     virtual bool processParams(){ return true; }
     485                 :          0 :     virtual void end() {}
     486                 :            :     // yeuch, careful here, you can only call
     487                 :            :     // GetBuffer on the returned SbiBuffer once, also
     488                 :            :     // you (as the caller) get to own the memory
     489                 :          0 :     SbiBuffer& buffer()
     490                 :            :     {
     491                 :          0 :         return m_ConvertedBuf;
     492                 :            :     }
     493                 :          0 :     static S convertBufferOffSet( sal_uInt8* pStart, T nOp1 )
     494                 :            :     {
     495                 :          0 :         PCodeBufferWalker< T > aBuff( pStart, nOp1);
     496   [ #  #  #  # ]:          0 :         OffSetAccumulator< T, S > aVisitor;
     497 [ #  # ][ #  # ]:          0 :         aBuff.visitBuffer( aVisitor );
     498 [ #  # ][ #  # ]:          0 :         return aVisitor.offset();
         [ #  # ][ #  # ]
     499                 :            :     }
     500                 :            : };
     501                 :            : 
     502                 :            : sal_uInt32
     503                 :          0 : SbiCodeGen::calcNewOffSet( sal_uInt8* pCode, sal_uInt16 nOffset )
     504                 :            : {
     505                 :          0 :     return BufferTransformer< sal_uInt16, sal_uInt32 >::convertBufferOffSet( pCode, nOffset );
     506                 :            : }
     507                 :            : 
     508                 :            : sal_uInt16
     509                 :          0 : SbiCodeGen::calcLegacyOffSet( sal_uInt8* pCode, sal_uInt32 nOffset )
     510                 :            : {
     511                 :          0 :     return BufferTransformer< sal_uInt32, sal_uInt16 >::convertBufferOffSet( pCode, nOffset );
     512                 :            : }
     513                 :            : 
     514                 :            : template <class T, class S>
     515                 :            : void
     516                 :          0 : PCodeBuffConvertor<T,S>::convert()
     517                 :            : {
     518                 :          0 :     PCodeBufferWalker< T > aBuf( m_pStart, m_nSize );
     519   [ #  #  #  # ]:          0 :     BufferTransformer< T, S > aTrnsfrmer;
     520 [ #  # ][ #  # ]:          0 :     aBuf.visitBuffer( aTrnsfrmer );
     521 [ #  # ][ #  # ]:          0 :     m_pCnvtdBuf = (sal_uInt8*)aTrnsfrmer.buffer().GetBuffer();
     522 [ #  # ][ #  # ]:          0 :     m_nCnvtdSize = static_cast<S>( aTrnsfrmer.buffer().GetSize() );
     523                 :          0 : }
     524                 :            : 
     525                 :            : template class PCodeBuffConvertor< sal_uInt16, sal_uInt32 >;
     526                 :            : template class PCodeBuffConvertor< sal_uInt32, sal_uInt16 >;
     527                 :            : 
     528                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10