LCOV - code coverage report
Current view: top level - basic/source/comp - exprgen.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 72 90 80.0 %
Date: 2014-04-11 Functions: 4 4 100.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             : 
      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 const 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       17036 : void SbiExprNode::Gen( RecursiveMode eRecMode )
      59             : {
      60             :     sal_uInt16 nStringId;
      61             : 
      62       17036 :     if( IsConstant() )
      63             :     {
      64        4939 :         switch( GetType() )
      65             :         {
      66             :         case SbxEMPTY:
      67           0 :             pGen->Gen( _EMPTY );
      68           0 :             break;
      69             :         case SbxINTEGER:
      70        1739 :             pGen->Gen( _CONST,  (short) nVal );
      71        1739 :             break;
      72             :         case SbxSTRING:
      73        3117 :             nStringId = pGen->GetParser()->aGblStrings.Add( aStrVal, true );
      74        3117 :             pGen->Gen( _SCONST, nStringId );
      75        3117 :             break;
      76             :         default:
      77          83 :             nStringId = pGen->GetParser()->aGblStrings.Add( nVal, eType );
      78          83 :             pGen->Gen( _NUMBER, nStringId );
      79          83 :             break;
      80             :         }
      81             :     }
      82       12097 :     else if( IsOperand() )
      83             :     {
      84        9412 :         SbiExprNode* pWithParent_ = NULL;
      85             :         SbiOpcode eOp;
      86        9412 :         if( aVar.pDef->GetScope() == SbPARAM )
      87             :         {
      88         662 :             eOp = _PARAM;
      89         662 :             if( 0 == aVar.pDef->GetPos() )
      90             :             {
      91         250 :                 bool bTreatFunctionAsParam = true;
      92         250 :                 if( eRecMode == FORCE_CALL )
      93             :                 {
      94           0 :                     bTreatFunctionAsParam = false;
      95             :                 }
      96         250 :                 else if( eRecMode == UNDEFINED )
      97             :                 {
      98           0 :                     if( aVar.pPar && aVar.pPar->IsBracket() )
      99             :                     {
     100           0 :                          bTreatFunctionAsParam = false;
     101             :                     }
     102             :                 }
     103         250 :                 if( !bTreatFunctionAsParam )
     104             :                 {
     105           0 :                     eOp = aVar.pDef->IsGlobal() ? _FIND_G : _FIND;
     106             :                 }
     107             :             }
     108             :         }
     109             :         // special treatment for WITH
     110        8750 :         else if( (pWithParent_ = GetWithParent()) != NULL )
     111             :         {
     112          53 :             eOp = _ELEM;            // .-Term in in WITH
     113             :         }
     114             :         else
     115             :         {
     116        8697 :             eOp = ( aVar.pDef->GetScope() == SbRTL ) ? _RTL :
     117        8697 :                 (aVar.pDef->IsGlobal() ? _FIND_G : _FIND);
     118             :         }
     119             : 
     120        9412 :         if( eOp == _FIND )
     121             :         {
     122             : 
     123        7660 :             SbiProcDef* pProc = aVar.pDef->GetProcDef();
     124        7660 :             if ( pGen->GetParser()->bClassModule )
     125             :             {
     126           0 :                 eOp = _FIND_CM;
     127             :             }
     128        7660 :             else if ( aVar.pDef->IsStatic() || (pProc && pProc->IsStatic()) )
     129             :             {
     130           0 :                 eOp = _FIND_STATIC;
     131             :             }
     132             :         }
     133       21553 :         for( SbiExprNode* p = this; p; p = p->aVar.pNext )
     134             :         {
     135       12141 :             if( p == this && pWithParent_ != NULL )
     136             :             {
     137          53 :                 pWithParent_->Gen();
     138             :             }
     139       12141 :             p->GenElement( eOp );
     140       12141 :             eOp = _ELEM;
     141             :         }
     142             :     }
     143        2685 :     else if( IsTypeOf() )
     144             :     {
     145           0 :         pLeft->Gen();
     146           0 :         pGen->Gen( _TESTCLASS, nTypeStrId );
     147             :     }
     148        2685 :     else if( IsNew() )
     149             :     {
     150           0 :         pGen->Gen( _CREATE, 0, nTypeStrId );
     151             :     }
     152             :     else
     153             :     {
     154        2685 :         pLeft->Gen();
     155        2685 :         if( pRight )
     156             :         {
     157        2569 :             pRight->Gen();
     158             :         }
     159       35242 :         for( const OpTable* p = aOpTable; p->eTok != NIL; p++ )
     160             :         {
     161       35242 :             if( p->eTok == eTok )
     162             :             {
     163        2685 :                 pGen->Gen( p->eOp ); break;
     164             :             }
     165             :         }
     166             :     }
     167       17036 : }
     168             : 
     169             : // Output of an operand element
     170             : 
     171       12141 : void SbiExprNode::GenElement( SbiOpcode eOp )
     172             : {
     173             : #ifdef DBG_UTIL
     174             :     if ((eOp < _RTL || eOp > _CALLC) && eOp != _FIND_G && eOp != _FIND_CM && eOp != _FIND_STATIC)
     175             :         pGen->GetParser()->Error( SbERR_INTERNAL_ERROR, "Opcode" );
     176             : #endif
     177       12141 :     SbiSymDef* pDef = aVar.pDef;
     178             :     // The ID is either the position or the String-ID
     179             :     // If the bit Bit 0x8000 is set, the variable have
     180             :     // a parameter list.
     181       12141 :     sal_uInt16 nId = ( eOp == _PARAM ) ? pDef->GetPos() : pDef->GetId();
     182             :     // Build a parameter list
     183       12141 :     if( aVar.pPar && aVar.pPar->GetSize() )
     184             :     {
     185        3038 :         nId |= 0x8000;
     186        3038 :         aVar.pPar->Gen();
     187             :     }
     188             : 
     189       12141 :     pGen->Gen( eOp, nId, sal::static_int_cast< sal_uInt16 >( GetType() ) );
     190             : 
     191       12141 :     if( aVar.pvMorePar )
     192             :     {
     193           0 :         SbiExprListVector* pvMorePar = aVar.pvMorePar;
     194           0 :         SbiExprListVector::iterator it;
     195           0 :         for( it = pvMorePar->begin() ; it != pvMorePar->end() ; ++it )
     196             :         {
     197           0 :             SbiExprList* pExprList = *it;
     198           0 :             pExprList->Gen();
     199           0 :             pGen->Gen( _ARRAYACCESS );
     200             :         }
     201             :     }
     202       12141 : }
     203             : 
     204             : // Create an Argv-Table
     205             : // The first element remain available for return value etc.
     206             : // See as well SbiProcDef::SbiProcDef() in symtbl.cxx
     207             : 
     208        3038 : void SbiExprList::Gen()
     209             : {
     210        3038 :     if( pFirst )
     211             :     {
     212        3038 :         pParser->aGen.Gen( _ARGC );
     213             :         // Type adjustment at DECLARE
     214        3038 :         sal_uInt16 nCount = 1;
     215             : 
     216        7658 :         for( SbiExpression* pExpr = pFirst; pExpr; pExpr = pExpr->pNext,nCount++ )
     217             :         {
     218        4620 :             pExpr->Gen();
     219        4620 :             if( !pExpr->GetName().isEmpty() )
     220             :             {
     221             :                 // named arg
     222         156 :                 sal_uInt16 nSid = pParser->aGblStrings.Add( pExpr->GetName() );
     223         156 :                 pParser->aGen.Gen( _ARGN, nSid );
     224             : 
     225             :                 /* TODO: Check after Declare concept change
     226             :                 // From 1996-01-10: Type adjustment at named -> search suitable parameter
     227             :                 if( pProc )
     228             :                 {
     229             :                     // For the present: trigger an error
     230             :                     pParser->Error( SbERR_NO_NAMED_ARGS );
     231             : 
     232             :                     // Later, if Named Args at DECLARE is posible
     233             :                     //for( sal_uInt16 i = 1 ; i < nParAnz ; i++ )
     234             :                     //{
     235             :                     //  SbiSymDef* pDef = pPool->Get( i );
     236             :                     //  const String& rName = pDef->GetName();
     237             :                     //  if( rName.Len() )
     238             :                     //  {
     239             :                     //      if( pExpr->GetName().ICompare( rName )
     240             :                     //          == COMPARE_EQUAL )
     241             :                     //      {
     242             :                     //          pParser->aGen.Gen( _ARGTYP, pDef->GetType() );
     243             :                     //          break;
     244             :                     //      }
     245             :                     //  }
     246             :                     //}
     247             :                 }
     248             :                 */
     249             :             }
     250             :             else
     251             :             {
     252        4464 :                 pParser->aGen.Gen( _ARGV );
     253             :             }
     254             :         }
     255             :     }
     256        3038 : }
     257             : 
     258       11729 : void SbiExpression::Gen( RecursiveMode eRecMode )
     259             : {
     260             :     // special treatment for WITH
     261             :     // If pExpr == .-term in With, approximately Gen for Basis-Object
     262       11729 :     pExpr->Gen( eRecMode );
     263       11729 :     if( bByVal )
     264             :     {
     265           0 :         pParser->aGen.Gen( _BYVAL );
     266             :     }
     267       11729 :     if( bBased )
     268             :     {
     269          28 :         sal_uInt16 uBase = pParser->nBase;
     270          28 :         if( pParser->IsCompatible() )
     271             :         {
     272           4 :             uBase |= 0x8000;        // #109275 Flag compatiblity
     273             :         }
     274          28 :         pParser->aGen.Gen( _BASED, uBase );
     275          28 :         pParser->aGen.Gen( _ARGV );
     276             :     }
     277       11729 : }
     278             : 
     279             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10