LCOV - code coverage report
Current view: top level - idlc/source - astdeclaration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 64 72 88.9 %
Date: 2012-08-25 Functions: 9 11 81.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 43 68 63.2 %

           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                 :            : #include <idlc/astdeclaration.hxx>
      21                 :            : #include <idlc/astscope.hxx>
      22                 :            : #include <rtl/strbuf.hxx>
      23                 :            : 
      24                 :            : using namespace ::rtl;
      25                 :            : 
      26                 :        166 : static OString sGlobal("::");
      27                 :            : 
      28                 :     884034 : static OString convertName(const OString& name)
      29                 :            : {
      30                 :     884034 :     OStringBuffer nameBuffer(name.getLength()+1);
      31                 :     884034 :     sal_Int32 nIndex = 0;
      32         [ +  + ]:    6805918 :     do
      33                 :            :     {
      34                 :    6805918 :         OString token( name.getToken( 0, ':', nIndex ) );
      35         [ +  + ]:    6805918 :         if( !token.isEmpty() )
      36                 :            :         {
      37         [ +  - ]:    3838357 :             nameBuffer.append('/');
      38         [ +  - ]:    3838357 :             nameBuffer.append( token );
      39                 :    6805918 :         }
      40                 :            :     } while( nIndex != -1 );
      41                 :     884034 :     return nameBuffer.makeStringAndClear();
      42                 :            : }
      43                 :            : 
      44                 :     884034 : AstDeclaration::AstDeclaration(NodeType type, const OString& name, AstScope* pScope)
      45                 :            :     : m_localName(name)
      46                 :            :     , m_pScope(pScope)
      47                 :            :     , m_nodeType(type)
      48                 :            :     , m_bImported(sal_False)
      49                 :            :     , m_bIsAdded(sal_False)
      50                 :            :     , m_bInMainFile(sal_False)
      51                 :     884034 :     , m_bPredefined(false)
      52                 :            : {
      53         [ +  + ]:     884034 :     if ( m_pScope )
      54                 :            :     {
      55         [ +  - ]:     877822 :         AstDeclaration* pDecl = scopeAsDecl(m_pScope);
      56         [ +  - ]:     877822 :         if (pDecl)
      57                 :            :         {
      58                 :     877822 :             m_scopedName = pDecl->getScopedName();
      59         [ +  + ]:     877822 :             if (!m_scopedName.isEmpty())
      60                 :     694842 :                 m_scopedName += sGlobal;
      61                 :     877822 :             m_scopedName += m_localName;
      62                 :            :         }
      63                 :            :     } else
      64                 :            :     {
      65                 :       6212 :         m_scopedName = m_localName;
      66                 :            :     }
      67         [ +  - ]:     884034 :     m_fullName = convertName(m_scopedName);
      68                 :            : 
      69 [ +  - ][ +  + ]:     884034 :     if ( idlc()->getFileName() == idlc()->getRealFileName() )
                 [ +  - ]
      70                 :            :     {
      71         [ +  - ]:     174379 :         m_fileName = idlc()->getMainFileName();
      72                 :     174379 :         m_bInMainFile = sal_True;
      73                 :            :     } else
      74                 :            :     {
      75         [ +  - ]:     709655 :         m_fileName = idlc()->getFileName();
      76                 :     709655 :         m_bImported = sal_True;
      77                 :            :     }
      78                 :            : 
      79 [ +  - ][ +  - ]:     884034 :     if ( idlc()->isDocValid() )
                 [ -  + ]
      80 [ #  # ][ #  # ]:          0 :         m_documentation = OStringToOUString(idlc()->getDocumentation(), RTL_TEXTENCODING_UTF8);
      81                 :            : 
      82         [ +  - ]:     884034 :     m_bPublished = idlc()->isPublished();
      83                 :     884034 : }
      84                 :            : 
      85                 :            : 
      86                 :     256125 : AstDeclaration::~AstDeclaration()
      87                 :            : {
      88                 :            : 
      89         [ -  + ]:     256125 : }
      90                 :            : 
      91                 :       1421 : void AstDeclaration::setPredefined(bool bPredefined)
      92                 :            : {
      93                 :       1421 :     m_bPredefined = bPredefined;
      94         [ +  + ]:       1421 :     if ( m_bPredefined )
      95                 :            :     {
      96                 :        830 :         m_fileName = OString();
      97                 :        830 :         m_bInMainFile = sal_False;
      98                 :            :     }
      99                 :       1421 : }
     100                 :            : 
     101                 :          0 : void AstDeclaration::setName(const ::rtl::OString& name)
     102                 :            : {
     103                 :          0 :     m_scopedName = name;
     104                 :          0 :     sal_Int32 nIndex = name.lastIndexOf( ':' );
     105                 :          0 :     m_localName = name.copy( nIndex+1 );
     106                 :            : 
     107                 :            : // Huh ? There is always at least one token
     108                 :            : 
     109                 :            : //  sal_Int32 count = name.getTokenCount(':');
     110                 :            : 
     111                 :            : //  if ( count > 0 )
     112                 :            : //  {
     113                 :            : //      m_localName = name.getToken(count-1, ':');
     114                 :            : //      m_scopedName = name;
     115                 :            : //  } else if ( m_pScope )
     116                 :            : //  {
     117                 :            : //      m_localName = name;
     118                 :            : //      AstDeclaration* pDecl = scopeAsDecl(m_pScope);
     119                 :            : //      if (pDecl)
     120                 :            : //      {
     121                 :            : //          m_scopedName = pDecl->getScopedName();
     122                 :            : //          if (m_scopedName.getLength() > 0)
     123                 :            : //              m_scopedName += sGlobal;
     124                 :            : //          m_scopedName += m_localName;
     125                 :            : //      }
     126                 :            : //  } else
     127                 :            : //  {
     128                 :            : //      m_localName = name;
     129                 :            : //      m_scopedName = name;
     130                 :            : //  }
     131                 :          0 :     m_fullName = convertName(m_scopedName);
     132                 :          0 : }
     133                 :            : 
     134                 :     235385 : bool AstDeclaration::isType() const {
     135         [ +  - ]:     235385 :     switch (m_nodeType) {
     136                 :            :     case NT_interface:
     137                 :            :     case NT_instantiated_struct:
     138                 :            :     case NT_union:
     139                 :            :     case NT_enum:
     140                 :            :     case NT_sequence:
     141                 :            :     case NT_array:
     142                 :            :     case NT_typedef:
     143                 :            :     case NT_predefined:
     144                 :            :     case NT_type_parameter:
     145                 :     235385 :         return true;
     146                 :            : 
     147                 :            :     default:
     148                 :            :         OSL_ASSERT(m_nodeType != NT_struct); // see AstStruct::isType
     149                 :     235385 :         return false;
     150                 :            :     }
     151                 :            : }
     152                 :            : 
     153                 :      18068 : sal_Bool AstDeclaration::hasAncestor(AstDeclaration* pDecl)
     154                 :            : {
     155         [ -  + ]:      18068 :     if (this == pDecl)
     156                 :          0 :         return sal_True;
     157         [ +  + ]:      18068 :     if ( !m_pScope )
     158                 :       9034 :         return sal_False;
     159                 :      18068 :     return scopeAsDecl(m_pScope)->hasAncestor(pDecl);
     160                 :            : }
     161                 :            : 
     162                 :      31079 : sal_Bool AstDeclaration::dump(RegistryKey& rKey)
     163                 :            : {
     164                 :      31079 :     AstScope* pScope = declAsScope(this);
     165                 :      31079 :     sal_Bool bRet = sal_True;
     166                 :            : 
     167         [ +  - ]:      31079 :     if ( pScope )
     168                 :            :     {
     169                 :      31079 :         DeclList::const_iterator iter = pScope->getIteratorBegin();
     170                 :      31079 :         DeclList::const_iterator end = pScope->getIteratorEnd();
     171                 :      31079 :         AstDeclaration* pDecl = NULL;
     172 [ +  + ][ +  - ]:     203820 :         while ( iter != end && bRet)
                 [ +  + ]
     173                 :            :         {
     174                 :     172741 :             pDecl = *iter;
     175         [ +  + ]:     172741 :             if ( pDecl->isInMainfile() )
     176                 :            :             {
     177         [ +  + ]:     133964 :                 switch ( pDecl->getNodeType() )
     178                 :            :                 {
     179                 :            :                     case NT_module:
     180                 :            :                     case NT_constants:
     181                 :            :                     case NT_interface:
     182                 :            :                     case NT_struct:
     183                 :            :                     case NT_exception:
     184                 :            :                     case NT_enum:
     185                 :            :                     case NT_union:
     186                 :            :                     case NT_typedef:
     187                 :            :                     case NT_service:
     188                 :            :                     case NT_singleton:
     189         [ +  - ]:      31032 :                         bRet = pDecl->dump(rKey);
     190                 :      31032 :                         break;
     191                 :            :                     default:
     192                 :     133964 :                         break;
     193                 :            :                 }
     194                 :            :             }
     195                 :            : 
     196                 :     172741 :             ++iter;
     197                 :            :         }
     198                 :            :     }
     199                 :      31079 :     return bRet;
     200 [ +  - ][ +  - ]:        498 : }
     201                 :            : 
     202                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10