LCOV - code coverage report
Current view: top level - idlc/source - astdeclaration.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 63 66 95.5 %
Date: 2015-06-13 12:38:46 Functions: 9 10 90.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             : #include <idlc/astdeclaration.hxx>
      21             : #include <idlc/astscope.hxx>
      22             : #include <rtl/strbuf.hxx>
      23             : #include <osl/diagnose.h>
      24             : 
      25         329 : static OString sGlobal("::");
      26             : 
      27       14770 : static OString convertName(const OString& name)
      28             : {
      29       14770 :     OStringBuffer nameBuffer(name.getLength()+1);
      30       14770 :     sal_Int32 nIndex = 0;
      31       36964 :     do
      32             :     {
      33       36964 :         OString token( name.getToken( 0, ':', nIndex ) );
      34       36964 :         if( !token.isEmpty() )
      35             :         {
      36       25209 :             nameBuffer.append('/');
      37       25209 :             nameBuffer.append( token );
      38       36964 :         }
      39       36964 :     } while( nIndex != -1 );
      40       14770 :     return nameBuffer.makeStringAndClear();
      41             : }
      42             : 
      43       14770 : AstDeclaration::AstDeclaration(NodeType type, const OString& name, AstScope* pScope)
      44             :     : m_localName(name)
      45             :     , m_pScope(pScope)
      46             :     , m_nodeType(type)
      47             :     , m_bImported(false)
      48             :     , m_bIsAdded(false)
      49             :     , m_bInMainFile(false)
      50             :     , m_bPredefined(false)
      51       14770 :     , m_lineNumber(0)
      52             : {
      53       14770 :     if ( m_pScope )
      54             :     {
      55       14037 :         AstDeclaration* pDecl = scopeAsDecl(m_pScope);
      56       14037 :         if (pDecl)
      57             :         {
      58       14037 :             m_scopedName = pDecl->getScopedName();
      59       14037 :             if (!m_scopedName.isEmpty())
      60        3159 :                 m_scopedName += sGlobal;
      61       14037 :             m_scopedName += m_localName;
      62             :         }
      63             :     } else
      64             :     {
      65         733 :         m_scopedName = m_localName;
      66             :     }
      67       14770 :     m_fullName = convertName(m_scopedName);
      68             : 
      69       14770 :     if ( idlc()->getFileName() == idlc()->getRealFileName() )
      70             :     {
      71       14770 :         m_fileName = idlc()->getMainFileName();
      72       14770 :         m_bInMainFile = true;
      73             :     } else
      74             :     {
      75           0 :         m_fileName = idlc()->getFileName();
      76           0 :         m_bImported = true;
      77             :     }
      78             : 
      79       14770 :     m_documentation = idlc()->processDocumentation();
      80             : 
      81       14770 :     m_bPublished = idlc()->isPublished();
      82       14770 : }
      83             : 
      84             : 
      85         442 : AstDeclaration::~AstDeclaration()
      86             : {
      87             : 
      88         442 : }
      89             : 
      90        1752 : void AstDeclaration::setPredefined(bool bPredefined)
      91             : {
      92        1752 :     m_bPredefined = bPredefined;
      93        1752 :     if ( m_bPredefined )
      94             :     {
      95        1645 :         m_fileName.clear();
      96        1645 :         m_bInMainFile = false;
      97             :     }
      98        1752 : }
      99             : 
     100         276 : bool AstDeclaration::isType() const {
     101         276 :     switch (m_nodeType) {
     102             :     case NT_interface:
     103             :     case NT_instantiated_struct:
     104             :     case NT_enum:
     105             :     case NT_sequence:
     106             :     case NT_typedef:
     107             :     case NT_predefined:
     108             :     case NT_type_parameter:
     109         271 :         return true;
     110             : 
     111             :     default:
     112             :         OSL_ASSERT(m_nodeType != NT_struct); // see AstStruct::isType
     113           5 :         return false;
     114             :     }
     115             : }
     116             : 
     117          12 : bool AstDeclaration::hasAncestor(AstDeclaration* pDecl)
     118             : {
     119          12 :     if (this == pDecl)
     120           0 :         return true;
     121          12 :     if ( !m_pScope )
     122           4 :         return false;
     123           8 :     return scopeAsDecl(m_pScope)->hasAncestor(pDecl);
     124             : }
     125             : 
     126         240 : bool AstDeclaration::dump(RegistryKey& rKey)
     127             : {
     128         240 :     AstScope* pScope = declAsScope(this);
     129         240 :     bool bRet = true;
     130             : 
     131         240 :     if ( pScope )
     132             :     {
     133         240 :         DeclList::const_iterator iter = pScope->getIteratorBegin();
     134         240 :         DeclList::const_iterator end = pScope->getIteratorEnd();
     135         240 :         AstDeclaration* pDecl = NULL;
     136        3270 :         while ( iter != end && bRet)
     137             :         {
     138        2790 :             pDecl = *iter;
     139        2790 :             if ( pDecl->isInMainfile() )
     140             :             {
     141        2649 :                 switch ( pDecl->getNodeType() )
     142             :                 {
     143             :                     case NT_module:
     144             :                     case NT_constants:
     145             :                     case NT_interface:
     146             :                     case NT_struct:
     147             :                     case NT_exception:
     148             :                     case NT_enum:
     149             :                     case NT_typedef:
     150             :                     case NT_service:
     151             :                     case NT_singleton:
     152         393 :                         bRet = pDecl->dump(rKey);
     153         393 :                         break;
     154             :                     default:
     155        2256 :                         break;
     156             :                 }
     157             :             }
     158             : 
     159        2790 :             ++iter;
     160             :         }
     161             :     }
     162         240 :     return bRet;
     163         987 : }
     164             : 
     165             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11