LCOV - code coverage report
Current view: top level - basic/source/comp - exprgen.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 66 86 76.7 %
Date: 2012-08-25 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 59 94 62.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 "sbcomp.hxx"
      22                 :            : #include "expr.hxx"
      23                 :            : 
      24                 :            : // Transform table for token operators and opcodes
      25                 :            : 
      26                 :            : typedef struct {
      27                 :            :         SbiToken  eTok;                 // Token
      28                 :            :         SbiOpcode eOp;                  // Opcode
      29                 :            : } OpTable;
      30                 :            : 
      31                 :            : static OpTable aOpTable [] = {
      32                 :            :     { EXPON,_EXP },
      33                 :            :     { MUL,  _MUL },
      34                 :            :     { DIV,  _DIV },
      35                 :            :     { IDIV, _IDIV },
      36                 :            :     { MOD,  _MOD },
      37                 :            :     { PLUS, _PLUS },
      38                 :            :     { MINUS,_MINUS },
      39                 :            :     { EQ,   _EQ },
      40                 :            :     { NE,   _NE },
      41                 :            :     { LE,   _LE },
      42                 :            :     { GE,   _GE },
      43                 :            :     { LT,   _LT },
      44                 :            :     { GT,   _GT },
      45                 :            :     { AND,  _AND },
      46                 :            :     { OR,   _OR },
      47                 :            :     { XOR,  _XOR },
      48                 :            :     { EQV,  _EQV },
      49                 :            :     { IMP,  _IMP },
      50                 :            :     { NOT,  _NOT },
      51                 :            :     { NEG,  _NEG },
      52                 :            :     { CAT,  _CAT },
      53                 :            :     { LIKE, _LIKE },
      54                 :            :     { IS,   _IS },
      55                 :            :     { NIL,  _NOP }};
      56                 :            : 
      57                 :            : // Output of an element
      58                 :       7857 : void SbiExprNode::Gen( RecursiveMode eRecMode )
      59                 :            : {
      60         [ +  + ]:       7857 :     if( IsConstant() )
      61                 :            :     {
      62   [ -  +  +  + ]:       2100 :         switch( GetType() )
      63                 :            :         {
      64                 :          0 :             case SbxEMPTY:   pGen->Gen( _EMPTY ); break;
      65                 :        726 :             case SbxINTEGER: pGen->Gen( _CONST,  (short) nVal ); break;
      66                 :            :             case SbxSTRING:
      67                 :            :             {
      68         [ +  - ]:       1358 :                 sal_uInt16 nStringId = pGen->GetParser()->aGblStrings.Add( aStrVal, sal_True );
      69                 :       1358 :                 pGen->Gen( _SCONST, nStringId ); break;
      70                 :            :             }
      71                 :            :             default:
      72                 :            :             {
      73                 :         16 :                 sal_uInt16 nStringId = pGen->GetParser()->aGblStrings.Add( nVal, eType );
      74                 :       2100 :                 pGen->Gen( _NUMBER, nStringId );
      75                 :            :             }
      76                 :            :         }
      77                 :            :     }
      78         [ +  + ]:       5757 :     else if( IsOperand() )
      79                 :            :     {
      80                 :       4864 :         SbiExprNode* pWithParent_ = NULL;
      81                 :            :         SbiOpcode eOp;
      82         [ +  + ]:       4864 :         if( aVar.pDef->GetScope() == SbPARAM )
      83                 :            :         {
      84                 :        426 :             eOp = _PARAM;
      85         [ +  + ]:        426 :             if( 0 == aVar.pDef->GetPos() )
      86                 :            :             {
      87                 :        209 :                 bool bTreatFunctionAsParam = true;
      88         [ -  + ]:        209 :                 if( eRecMode == FORCE_CALL )
      89                 :            :                 {
      90                 :          0 :                     bTreatFunctionAsParam = false;
      91                 :            :                 }
      92         [ -  + ]:        209 :                 else if( eRecMode == UNDEFINED )
      93                 :            :                 {
      94 [ #  # ][ #  # ]:          0 :                     if( aVar.pPar && aVar.pPar->IsBracket() )
                 [ #  # ]
      95                 :          0 :                          bTreatFunctionAsParam = false;
      96                 :            :                 }
      97         [ -  + ]:        209 :                 if( !bTreatFunctionAsParam )
      98         [ #  # ]:          0 :                     eOp = aVar.pDef->IsGlobal() ? _FIND_G : _FIND;
      99                 :            :             }
     100                 :            :         }
     101                 :            :         // special treatment for WITH
     102         [ -  + ]:       4438 :         else if( (pWithParent_ = GetWithParent()) != NULL )
     103                 :            :         {
     104                 :          0 :             eOp = _ELEM;            // .-Term in in WITH
     105                 :            :         }
     106                 :            :         else
     107                 :            :         {
     108                 :       4438 :             eOp = ( aVar.pDef->GetScope() == SbRTL ) ? _RTL :
     109 [ +  + ][ +  + ]:       4438 :                 (aVar.pDef->IsGlobal() ? _FIND_G : _FIND);
     110                 :            :         }
     111                 :            : 
     112         [ +  + ]:       4864 :         if( eOp == _FIND )
     113                 :            :         {
     114                 :            : 
     115                 :       3926 :             SbiProcDef* pProc = aVar.pDef->GetProcDef();
     116         [ -  + ]:       3926 :             if ( pGen->GetParser()->bClassModule )
     117                 :          0 :                 eOp = _FIND_CM;
     118 [ +  - ][ +  + ]:       3926 :             else if ( aVar.pDef->IsStatic() || (pProc && pProc->IsStatic()) )
         [ -  + ][ -  + ]
     119                 :            :             {
     120                 :          0 :                 eOp = _FIND_STATIC;
     121                 :            :             }
     122                 :            :         }
     123         [ +  + ]:      10544 :         for( SbiExprNode* p = this; p; p = p->aVar.pNext )
     124                 :            :         {
     125 [ +  + ][ -  + ]:       5680 :             if( p == this && pWithParent_ != NULL )
     126                 :          0 :                 pWithParent_->Gen();
     127                 :       5680 :             p->GenElement( eOp );
     128                 :       5680 :             eOp = _ELEM;
     129                 :            :         }
     130                 :            :     }
     131         [ -  + ]:        893 :     else if( IsTypeOf() )
     132                 :            :     {
     133                 :          0 :         pLeft->Gen();
     134                 :          0 :         pGen->Gen( _TESTCLASS, nTypeStrId );
     135                 :            :     }
     136         [ -  + ]:        893 :     else if( IsNew() )
     137                 :            :     {
     138                 :          0 :         pGen->Gen( _CREATE, 0, nTypeStrId );
     139                 :            :     }
     140                 :            :     else
     141                 :            :     {
     142                 :        893 :         pLeft->Gen();
     143         [ +  + ]:        893 :         if( pRight )
     144                 :        782 :             pRight->Gen();
     145         [ +  - ]:       9542 :         for( OpTable* p = aOpTable; p->eTok != NIL; p++ )
     146                 :            :         {
     147         [ +  + ]:       9542 :             if( p->eTok == eTok )
     148                 :            :             {
     149                 :        893 :                 pGen->Gen( p->eOp ); break;
     150                 :            :             }
     151                 :            :         }
     152                 :            :     }
     153                 :       7857 : }
     154                 :            : 
     155                 :            : // Output of an operand element
     156                 :            : 
     157                 :       5680 : void SbiExprNode::GenElement( SbiOpcode eOp )
     158                 :            : {
     159                 :            : #ifdef DBG_UTIL
     160                 :            :     if( (eOp < _RTL || eOp > _CALLC) && eOp != _FIND_G && eOp != _FIND_CM )
     161                 :            :         pGen->GetParser()->Error( SbERR_INTERNAL_ERROR, "Opcode" );
     162                 :            : #endif
     163                 :       5680 :     SbiSymDef* pDef = aVar.pDef;
     164                 :            :     // The ID is either the position or the String-ID
     165                 :            :     // If the bit Bit 0x8000 is set, the variable have
     166                 :            :     // a parameter list.
     167         [ +  + ]:       5680 :     sal_uInt16 nId = ( eOp == _PARAM ) ? pDef->GetPos() : pDef->GetId();
     168                 :            :     // Build a parameter list
     169 [ +  + ][ +  + ]:       5680 :     if( aVar.pPar && aVar.pPar->GetSize() )
                 [ +  + ]
     170                 :            :     {
     171                 :       1500 :         nId |= 0x8000;
     172                 :       1500 :         aVar.pPar->Gen();
     173                 :            :     }
     174                 :            : 
     175                 :       5680 :     pGen->Gen( eOp, nId, sal::static_int_cast< sal_uInt16 >( GetType() ) );
     176                 :            : 
     177         [ -  + ]:       5680 :     if( aVar.pvMorePar )
     178                 :            :     {
     179                 :          0 :         SbiExprListVector* pvMorePar = aVar.pvMorePar;
     180                 :          0 :         SbiExprListVector::iterator it;
     181 [ #  # ][ #  # ]:          0 :         for( it = pvMorePar->begin() ; it != pvMorePar->end() ; ++it )
     182                 :            :         {
     183                 :          0 :             SbiExprList* pExprList = *it;
     184         [ #  # ]:          0 :             pExprList->Gen();
     185         [ #  # ]:          0 :             pGen->Gen( _ARRAYACCESS );
     186                 :            :         }
     187                 :            :     }
     188                 :       5680 : }
     189                 :            : 
     190                 :            : // Create an Argv-Table
     191                 :            : // The first element remain available for return value etc.
     192                 :            : // See as well SbiProcDef::SbiProcDef() in symtbl.cxx
     193                 :            : 
     194                 :       1500 : void SbiExprList::Gen()
     195                 :            : {
     196         [ +  - ]:       1500 :     if( pFirst )
     197                 :            :     {
     198                 :       1500 :         pParser->aGen.Gen( _ARGC );
     199                 :            :         // Type adjustment at DECLARE
     200                 :       1500 :         sal_uInt16 nCount = 1;
     201                 :            : 
     202         [ +  + ]:       3700 :         for( SbiExpression* pExpr = pFirst; pExpr; pExpr = pExpr->pNext,nCount++ )
     203                 :            :         {
     204                 :       2200 :             pExpr->Gen();
     205         [ +  + ]:       2200 :             if( pExpr->GetName().Len() )
     206                 :            :             {
     207                 :            :                 // named arg
     208         [ +  - ]:         52 :                 sal_uInt16 nSid = pParser->aGblStrings.Add( pExpr->GetName() );
     209                 :         52 :                 pParser->aGen.Gen( _ARGN, nSid );
     210                 :            : 
     211                 :            :                 /* TODO: Check after Declare concept change
     212                 :            :                 // From 1996-01-10: Type adjustment at named -> search suitable parameter
     213                 :            :                 if( pProc )
     214                 :            :                 {
     215                 :            :                     // For the present: trigger an error
     216                 :            :                     pParser->Error( SbERR_NO_NAMED_ARGS );
     217                 :            : 
     218                 :            :                     // Later, if Named Args at DECLARE is posible
     219                 :            :                     //for( sal_uInt16 i = 1 ; i < nParAnz ; i++ )
     220                 :            :                     //{
     221                 :            :                     //  SbiSymDef* pDef = pPool->Get( i );
     222                 :            :                     //  const String& rName = pDef->GetName();
     223                 :            :                     //  if( rName.Len() )
     224                 :            :                     //  {
     225                 :            :                     //      if( pExpr->GetName().ICompare( rName )
     226                 :            :                     //          == COMPARE_EQUAL )
     227                 :            :                     //      {
     228                 :            :                     //          pParser->aGen.Gen( _ARGTYP, pDef->GetType() );
     229                 :            :                     //          break;
     230                 :            :                     //      }
     231                 :            :                     //  }
     232                 :            :                     //}
     233                 :            :                 }
     234                 :            :                 */
     235                 :            :             }
     236                 :            :             else
     237                 :            :             {
     238                 :       2148 :                 pParser->aGen.Gen( _ARGV );
     239                 :            :             }
     240                 :            :         }
     241                 :            :     }
     242                 :       1500 : }
     243                 :            : 
     244                 :       6182 : void SbiExpression::Gen( RecursiveMode eRecMode )
     245                 :            : {
     246                 :            :     // special treatment for WITH
     247                 :            :     // If pExpr == .-term in With, approximately Gen for Basis-Object
     248                 :       6182 :     pExpr->Gen( eRecMode );
     249         [ -  + ]:       6182 :     if( bByVal )
     250                 :          0 :         pParser->aGen.Gen( _BYVAL );
     251         [ +  + ]:       6182 :     if( bBased )
     252                 :            :     {
     253                 :         42 :         sal_uInt16 uBase = pParser->nBase;
     254         [ -  + ]:         42 :         if( pParser->IsCompatible() )
     255                 :          0 :             uBase |= 0x8000;        // #109275 Flag compatiblity
     256                 :         42 :         pParser->aGen.Gen( _BASED, uBase );
     257                 :         42 :         pParser->aGen.Gen( _ARGV );
     258                 :            :     }
     259                 :       6182 : }
     260                 :            : 
     261                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10