LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/idlc/source - astdeclaration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 65 72 90.3 %
Date: 2013-07-09 Functions: 9 11 81.8 %
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 <idlc/astdeclaration.hxx>
      21             : #include <idlc/astscope.hxx>
      22             : #include <rtl/strbuf.hxx>
      23             : 
      24             : using namespace ::rtl;
      25             : 
      26         452 : static OString sGlobal("::");
      27             : 
      28      807030 : static OString convertName(const OString& name)
      29             : {
      30      807030 :     OStringBuffer nameBuffer(name.getLength()+1);
      31      807030 :     sal_Int32 nIndex = 0;
      32     6122504 :     do
      33             :     {
      34     6122504 :         OString token( name.getToken( 0, ':', nIndex ) );
      35     6122504 :         if( !token.isEmpty() )
      36             :         {
      37     3458302 :             nameBuffer.append('/');
      38     3458302 :             nameBuffer.append( token );
      39     6122504 :         }
      40     6122504 :     } while( nIndex != -1 );
      41      807030 :     return nameBuffer.makeStringAndClear();
      42             : }
      43             : 
      44      807030 : 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      807030 :     , m_bPredefined(false)
      52             : {
      53      807030 :     if ( m_pScope )
      54             :     {
      55      800836 :         AstDeclaration* pDecl = scopeAsDecl(m_pScope);
      56      800836 :         if (pDecl)
      57             :         {
      58      800836 :             m_scopedName = pDecl->getScopedName();
      59      800836 :             if (!m_scopedName.isEmpty())
      60      627114 :                 m_scopedName += sGlobal;
      61      800836 :             m_scopedName += m_localName;
      62             :         }
      63             :     } else
      64             :     {
      65        6194 :         m_scopedName = m_localName;
      66             :     }
      67      807030 :     m_fullName = convertName(m_scopedName);
      68             : 
      69      807030 :     if ( idlc()->getFileName() == idlc()->getRealFileName() )
      70             :     {
      71      167163 :         m_fileName = idlc()->getMainFileName();
      72      167163 :         m_bInMainFile = sal_True;
      73             :     } else
      74             :     {
      75      639867 :         m_fileName = idlc()->getFileName();
      76      639867 :         m_bImported = sal_True;
      77             :     }
      78             : 
      79      807030 :     m_documentation = idlc()->processDocumentation();
      80             : 
      81      807030 :     m_bPublished = idlc()->isPublished();
      82      807030 : }
      83             : 
      84             : 
      85      234351 : AstDeclaration::~AstDeclaration()
      86             : {
      87             : 
      88      234351 : }
      89             : 
      90        2874 : void AstDeclaration::setPredefined(bool bPredefined)
      91             : {
      92        2874 :     m_bPredefined = bPredefined;
      93        2874 :     if ( m_bPredefined )
      94             :     {
      95        2260 :         m_fileName = OString();
      96        2260 :         m_bInMainFile = sal_False;
      97             :     }
      98        2874 : }
      99             : 
     100           0 : void AstDeclaration::setName(const OString& name)
     101             : {
     102           0 :     m_scopedName = name;
     103           0 :     sal_Int32 nIndex = name.lastIndexOf( ':' );
     104           0 :     m_localName = name.copy( nIndex+1 );
     105             : 
     106             : // Huh ? There is always at least one token
     107             : 
     108             : //  sal_Int32 count = name.getTokenCount(':');
     109             : 
     110             : //  if ( count > 0 )
     111             : //  {
     112             : //      m_localName = name.getToken(count-1, ':');
     113             : //      m_scopedName = name;
     114             : //  } else if ( m_pScope )
     115             : //  {
     116             : //      m_localName = name;
     117             : //      AstDeclaration* pDecl = scopeAsDecl(m_pScope);
     118             : //      if (pDecl)
     119             : //      {
     120             : //          m_scopedName = pDecl->getScopedName();
     121             : //          if (m_scopedName.getLength() > 0)
     122             : //              m_scopedName += sGlobal;
     123             : //          m_scopedName += m_localName;
     124             : //      }
     125             : //  } else
     126             : //  {
     127             : //      m_localName = name;
     128             : //      m_scopedName = name;
     129             : //  }
     130           0 :     m_fullName = convertName(m_scopedName);
     131           0 : }
     132             : 
     133      211107 : bool AstDeclaration::isType() const {
     134      211107 :     switch (m_nodeType) {
     135             :     case NT_interface:
     136             :     case NT_instantiated_struct:
     137             :     case NT_union:
     138             :     case NT_enum:
     139             :     case NT_sequence:
     140             :     case NT_array:
     141             :     case NT_typedef:
     142             :     case NT_predefined:
     143             :     case NT_type_parameter:
     144      211102 :         return true;
     145             : 
     146             :     default:
     147             :         OSL_ASSERT(m_nodeType != NT_struct); // see AstStruct::isType
     148           5 :         return false;
     149             :     }
     150             : }
     151             : 
     152       15866 : sal_Bool AstDeclaration::hasAncestor(AstDeclaration* pDecl)
     153             : {
     154       15866 :     if (this == pDecl)
     155           0 :         return sal_True;
     156       15866 :     if ( !m_pScope )
     157        7932 :         return sal_False;
     158        7934 :     return scopeAsDecl(m_pScope)->hasAncestor(pDecl);
     159             : }
     160             : 
     161       27734 : sal_Bool AstDeclaration::dump(RegistryKey& rKey)
     162             : {
     163       27734 :     AstScope* pScope = declAsScope(this);
     164       27734 :     sal_Bool bRet = sal_True;
     165             : 
     166       27734 :     if ( pScope )
     167             :     {
     168       27734 :         DeclList::const_iterator iter = pScope->getIteratorBegin();
     169       27734 :         DeclList::const_iterator end = pScope->getIteratorEnd();
     170       27734 :         AstDeclaration* pDecl = NULL;
     171      212143 :         while ( iter != end && bRet)
     172             :         {
     173      156675 :             pDecl = *iter;
     174      156675 :             if ( pDecl->isInMainfile() )
     175             :             {
     176      121921 :                 switch ( pDecl->getNodeType() )
     177             :                 {
     178             :                     case NT_module:
     179             :                     case NT_constants:
     180             :                     case NT_interface:
     181             :                     case NT_struct:
     182             :                     case NT_exception:
     183             :                     case NT_enum:
     184             :                     case NT_union:
     185             :                     case NT_typedef:
     186             :                     case NT_service:
     187             :                     case NT_singleton:
     188       27743 :                         bRet = pDecl->dump(rKey);
     189       27743 :                         break;
     190             :                     default:
     191       94178 :                         break;
     192             :                 }
     193             :             }
     194             : 
     195      156675 :             ++iter;
     196             :         }
     197             :     }
     198       27734 :     return bRet;
     199        1356 : }
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10