LCOV - code coverage report
Current view: top level - codemaker/source/cppumaker - includes.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 122 138 88.4 %
Date: 2012-08-25 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 151 244 61.9 %

           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 "includes.hxx"
      22                 :            : 
      23                 :            : #include "dumputils.hxx"
      24                 :            : 
      25                 :            : #include "codemaker/dependencies.hxx"
      26                 :            : #include "codemaker/global.hxx"
      27                 :            : #include "codemaker/typemanager.hxx"
      28                 :            : #include "codemaker/unotype.hxx"
      29                 :            : 
      30                 :            : #include "osl/diagnose.h"
      31                 :            : #include "rtl/string.hxx"
      32                 :            : #include "rtl/ustring.hxx"
      33                 :            : #include "sal/types.h"
      34                 :            : 
      35                 :            : #include <vector>
      36                 :            : 
      37                 :            : using codemaker::cppumaker::Includes;
      38                 :            : 
      39                 :      29700 : Includes::Includes(
      40                 :            :     TypeManager const & manager, codemaker::Dependencies const & dependencies,
      41                 :            :     bool hpp):
      42                 :      29700 :     m_manager(manager), m_map(dependencies.getMap()), m_hpp(hpp),
      43                 :      29700 :     m_includeAny(dependencies.hasAnyDependency()), m_includeReference(false),
      44                 :      29700 :     m_includeSequence(dependencies.hasSequenceDependency()),
      45                 :      29700 :     m_includeType(dependencies.hasTypeDependency()),
      46                 :            :     m_includeCppuMacrosHxx(false), m_includeCppuUnotypeHxx(false),
      47                 :            :     m_includeOslDoublecheckedlockingH(false), m_includeOslMutexHxx(false),
      48                 :            :     m_includeRtlStrbufHxx(false), m_includeRtlStringH(false),
      49                 :            :     m_includeRtlTextencH(false), m_includeRtlUstrbufHxx(false),
      50                 :            :     m_includeRtlUstringH(false),
      51                 :      29700 :     m_includeRtlUstringHxx(dependencies.hasStringDependency()),
      52                 :            :     m_includeRtlInstanceHxx(false),
      53                 :            :     m_includeSalTypesH(
      54                 :      54650 :         dependencies.hasBooleanDependency() || dependencies.hasByteDependency()
      55                 :      24098 :         || dependencies.hasShortDependency()
      56                 :      21502 :         || dependencies.hasUnsignedShortDependency()
      57                 :      21438 :         || dependencies.hasLongDependency()
      58                 :      14308 :         || dependencies.hasUnsignedShortDependency()
      59                 :      14308 :         || dependencies.hasHyperDependency()
      60                 :      14216 :         || dependencies.hasUnsignedHyperDependency()
      61                 :      14208 :         || dependencies.hasCharDependency()),
      62                 :            :     m_includeTypelibTypeclassH(false),
      63   [ +  +  +  +  :     208428 :     m_includeTypelibTypedescriptionH(false)
          +  +  +  +  +  
          +  +  -  +  +  
             +  +  +  + ]
      64                 :      29700 : {}
      65                 :            : 
      66                 :      29700 : Includes::~Includes()
      67                 :      29700 : {}
      68                 :            : 
      69                 :      15752 : void Includes::add(rtl::OString const & registryType) {
      70                 :            :     sal_Int32 rank;
      71         [ +  - ]:      15752 :     std::vector< rtl::OString > args;
      72                 :            :     rtl::OString type(
      73         [ +  - ]:      15752 :         codemaker::UnoType::decompose(registryType, &rank, &args));
      74         [ -  + ]:      15752 :     if (rank > 0) {
      75                 :          0 :         m_includeSequence = true;
      76                 :            :     }
      77 [ +  - ][ -  -  :      15752 :     switch (codemaker::UnoType::getSort(type)) {
          -  -  -  -  +  
                      - ]
      78                 :            :     case codemaker::UnoType::SORT_VOID:
      79                 :            :         OSL_ASSERT(args.empty());
      80                 :            :         OSL_ASSERT(false);
      81                 :          0 :         break;
      82                 :            : 
      83                 :            :     case codemaker::UnoType::SORT_BOOLEAN:
      84                 :            :     case codemaker::UnoType::SORT_BYTE:
      85                 :            :     case codemaker::UnoType::SORT_SHORT:
      86                 :            :     case codemaker::UnoType::SORT_UNSIGNED_SHORT:
      87                 :            :     case codemaker::UnoType::SORT_LONG:
      88                 :            :     case codemaker::UnoType::SORT_UNSIGNED_LONG:
      89                 :            :     case codemaker::UnoType::SORT_HYPER:
      90                 :            :     case codemaker::UnoType::SORT_UNSIGNED_HYPER:
      91                 :            :     case codemaker::UnoType::SORT_CHAR:
      92                 :            :         OSL_ASSERT(args.empty());
      93                 :          0 :         m_includeSalTypesH = true;
      94                 :          0 :         break;
      95                 :            : 
      96                 :            :     case codemaker::UnoType::SORT_FLOAT:
      97                 :            :     case codemaker::UnoType::SORT_DOUBLE:
      98                 :            :         OSL_ASSERT(args.empty());
      99                 :          0 :         break;
     100                 :            : 
     101                 :            :     case codemaker::UnoType::SORT_STRING:
     102                 :            :         OSL_ASSERT(args.empty());
     103                 :          0 :         m_includeRtlUstringHxx = true;
     104                 :          0 :         break;
     105                 :            : 
     106                 :            :     case codemaker::UnoType::SORT_TYPE:
     107                 :            :         OSL_ASSERT(args.empty());
     108                 :          0 :         m_includeType = true;
     109                 :          0 :         break;
     110                 :            : 
     111                 :            :     case codemaker::UnoType::SORT_ANY:
     112                 :            :         OSL_ASSERT(args.empty());
     113                 :          0 :         m_includeAny = true;
     114                 :          0 :         break;
     115                 :            : 
     116                 :            :     case codemaker::UnoType::SORT_COMPLEX:
     117                 :            :         m_map.insert(
     118                 :            :             codemaker::Dependencies::Map::value_type(
     119         [ +  - ]:      15752 :                 type, codemaker::Dependencies::KIND_NO_BASE));
     120 [ +  - ][ -  + ]:      31504 :         {for (std::vector< rtl::OString >::iterator i(args.begin());
     121                 :      15752 :               i != args.end(); ++i)
     122                 :            :         {
     123         [ #  # ]:          0 :             add(*i);
     124                 :            :         }}
     125                 :      15752 :         break;
     126                 :            : 
     127                 :            :     default:
     128                 :            :         OSL_ASSERT(false);
     129                 :          0 :         break;
     130                 :      15752 :     }
     131                 :      15752 : }
     132                 :            : 
     133                 :            : namespace {
     134                 :            : 
     135                 :     179756 : void dumpEmptyLineBeforeFirst(FileStream & out, bool * first) {
     136                 :            :     OSL_ASSERT(first != 0);
     137         [ +  + ]:     179756 :     if (*first) {
     138                 :      26616 :         out << "\n";
     139                 :      26616 :         *first = false;
     140                 :            :     }
     141                 :     179756 : }
     142                 :            : 
     143                 :            : }
     144                 :            : 
     145                 :      26616 : void Includes::dump(FileStream & out, rtl::OString const * companionHdl) {
     146                 :            :     OSL_ASSERT(companionHdl == 0 || m_hpp);
     147         [ +  + ]:      26616 :     if (!m_includeReference) {
     148 [ +  - ][ +  + ]:      31628 :         for (codemaker::Dependencies::Map::iterator i(m_map.begin());
     149         [ +  - ]:      15512 :              i != m_map.end(); ++i)
     150                 :            :         {
     151 [ +  - ][ +  - ]:       5136 :             if (isInterfaceType(i->first)) {
                 [ +  + ]
     152                 :        604 :                 m_includeReference = true;
     153                 :        604 :                 break;
     154                 :            :             }
     155                 :            :         }
     156                 :            :     }
     157         [ +  - ]:      26616 :     out << "#include \"sal/config.h\"\n";
     158         [ +  + ]:      26616 :     if (companionHdl) {
     159         [ +  - ]:      11104 :         out << "\n";
     160         [ +  - ]:      11104 :         dumpInclude(out, *companionHdl, false);
     161                 :            :     }
     162                 :      26616 :     bool first = true;
     163 [ +  - ][ +  + ]:     189872 :     for (codemaker::Dependencies::Map::iterator i(m_map.begin());
     164         [ +  - ]:      94936 :          i != m_map.end(); ++i)
     165                 :            :     {
     166         [ +  - ]:      68320 :         dumpEmptyLineBeforeFirst(out, &first);
     167 [ +  + ][ +  - ]:      89708 :         if (m_hpp || i->second == codemaker::Dependencies::KIND_BASE
         [ +  + ][ +  + ]
                 [ +  + ]
     168 [ +  - ][ +  - ]:      21388 :             || !isInterfaceType(i->first))
     169                 :            :         {
     170 [ +  - ][ +  - ]:      62378 :             dumpInclude(out, i->first, m_hpp);
     171                 :            :         } else {
     172 [ +  - ][ +  - ]:       5942 :             bool ns = dumpNamespaceOpen(out, i->first, false);
     173         [ +  - ]:       5942 :             if (ns) {
     174         [ +  - ]:       5942 :                 out << " ";
     175                 :            :             }
     176         [ +  - ]:       5942 :             out << "class ";
     177 [ +  - ][ +  - ]:       5942 :             dumpTypeIdentifier(out, i->first);
     178         [ +  - ]:       5942 :             out << ";";
     179         [ +  - ]:       5942 :             if (ns) {
     180         [ +  - ]:       5942 :                 out << " ";
     181                 :            :             }
     182 [ +  - ][ +  - ]:       5942 :             dumpNamespaceClose(out, i->first, false);
     183         [ +  - ]:       5942 :             out << "\n";
     184                 :            :         }
     185                 :            :     }
     186                 :            :     static char const * hxxExtension[2] = { "h", "hxx" };
     187         [ +  + ]:      26616 :     if (m_includeAny) {
     188         [ +  - ]:       3462 :         dumpEmptyLineBeforeFirst(out, &first);
     189 [ +  - ][ +  - ]:       3462 :         out << "#include \"com/sun/star/uno/Any." << hxxExtension[m_hpp] << "\"\n";
                 [ +  - ]
     190                 :            :     }
     191         [ +  + ]:      26616 :     if (m_includeReference) {
     192         [ +  - ]:      16240 :         dumpEmptyLineBeforeFirst(out, &first);
     193 [ +  - ][ +  - ]:      16240 :         out << "#include \"com/sun/star/uno/Reference." << hxxExtension[m_hpp] << "\"\n";
                 [ +  - ]
     194                 :            :     }
     195         [ +  + ]:      26616 :     if (m_includeSequence) {
     196         [ +  - ]:       5194 :         dumpEmptyLineBeforeFirst(out, &first);
     197 [ +  - ][ +  - ]:       5194 :         out << "#include \"com/sun/star/uno/Sequence." << hxxExtension[m_hpp] << "\"\n";
                 [ +  - ]
     198                 :            :     }
     199         [ +  + ]:      26616 :     if (m_includeType) {
     200         [ +  - ]:      11234 :         dumpEmptyLineBeforeFirst(out, &first);
     201 [ +  - ][ +  - ]:      11234 :         out << "#include \"com/sun/star/uno/Type." << hxxExtension[m_hpp] << "\"\n";
                 [ +  - ]
     202                 :            :     }
     203         [ +  + ]:      26616 :     if (m_includeCppuMacrosHxx) {
     204         [ +  - ]:      14188 :         dumpEmptyLineBeforeFirst(out, &first);
     205         [ +  - ]:      14188 :         out << ("#include \"cppu/macros.hxx\"\n");
     206                 :            :     }
     207         [ +  + ]:      26616 :     if (m_includeCppuUnotypeHxx) {
     208         [ +  - ]:      12428 :         dumpEmptyLineBeforeFirst(out, &first);
     209         [ +  - ]:      12428 :         out << ("#include \"cppu/unotype.hxx\"\n");
     210                 :            :     }
     211         [ -  + ]:      26616 :     if (m_includeOslDoublecheckedlockingH) {
     212         [ #  # ]:          0 :         dumpEmptyLineBeforeFirst(out, &first);
     213         [ #  # ]:          0 :         out << ("#include \"osl/doublecheckedlocking.h\"\n");
     214                 :            :     }
     215         [ +  + ]:      26616 :     if (m_includeOslMutexHxx) {
     216         [ +  - ]:      10194 :         dumpEmptyLineBeforeFirst(out, &first);
     217         [ +  - ]:      10194 :         out << "#include \"osl/mutex.hxx\"\n";
     218                 :            :     }
     219         [ +  + ]:      26616 :     if (m_includeRtlStrbufHxx) {
     220         [ +  - ]:         12 :         dumpEmptyLineBeforeFirst(out, &first);
     221         [ +  - ]:         12 :         out << ("#include \"rtl/strbuf.hxx\"\n");
     222                 :            :     }
     223         [ +  + ]:      26616 :     if (m_includeRtlStringH) {
     224         [ +  - ]:         12 :         dumpEmptyLineBeforeFirst(out, &first);
     225         [ +  - ]:         12 :         out << "#include \"rtl/string.h\"\n";
     226                 :            :     }
     227         [ +  + ]:      26616 :     if (m_includeRtlTextencH) {
     228         [ +  - ]:         12 :         dumpEmptyLineBeforeFirst(out, &first);
     229         [ +  - ]:         12 :         out << "#include \"rtl/textenc.h\"\n";
     230                 :            :     }
     231         [ +  + ]:      26616 :     if (m_includeRtlUstrbufHxx) {
     232         [ +  - ]:         12 :         dumpEmptyLineBeforeFirst(out, &first);
     233         [ +  - ]:         12 :         out << ("#include \"rtl/ustrbuf.hxx\"\n");
     234                 :            :     }
     235         [ +  + ]:      26616 :     if (m_includeRtlUstringH) {
     236         [ +  - ]:       2156 :         dumpEmptyLineBeforeFirst(out, &first);
     237         [ +  - ]:       2156 :         out << "#include \"rtl/ustring.h\"\n";
     238                 :            :     }
     239         [ +  + ]:      26616 :     if (m_includeRtlUstringHxx) {
     240         [ +  - ]:       9208 :         dumpEmptyLineBeforeFirst(out, &first);
     241         [ +  - ]:       9208 :         out << ("#include \"rtl/ustring.hxx\"\n");
     242                 :            :     }
     243         [ +  + ]:      26616 :     if (m_includeRtlInstanceHxx) {
     244         [ +  - ]:      10194 :         dumpEmptyLineBeforeFirst(out, &first);
     245         [ +  - ]:      10194 :         out << "#include \"rtl/instance.hxx\"\n";
     246                 :            :     }
     247         [ +  + ]:      26616 :     if (m_includeSalTypesH) {
     248         [ +  - ]:      13206 :         dumpEmptyLineBeforeFirst(out, &first);
     249         [ +  - ]:      13206 :         out << "#include \"sal/types.h\"\n";
     250                 :            :     }
     251         [ +  + ]:      26616 :     if (m_includeTypelibTypeclassH) {
     252         [ +  - ]:       1842 :         dumpEmptyLineBeforeFirst(out, &first);
     253         [ +  - ]:       1842 :         out << ("#include \"typelib/typeclass.h\"\n");
     254                 :            :     }
     255         [ +  + ]:      26616 :     if (m_includeTypelibTypedescriptionH) {
     256         [ +  - ]:       1842 :         dumpEmptyLineBeforeFirst(out, &first);
     257         [ +  - ]:       1842 :         out << ("#include \"typelib/typedescription.h\"\n");
     258                 :            :     }
     259                 :      26616 : }
     260                 :            : 
     261                 :      76566 : void Includes::dumpInclude(
     262                 :            :     FileStream & out, rtl::OString const & registryType, bool hpp,
     263                 :            :     rtl::OString const & suffix)
     264                 :            : {
     265                 :            :     static char const * extension[2] = { "hdl", "hpp" };
     266                 :      76566 :     out << "#include \"" << registryType;
     267         [ -  + ]:      76566 :     if (!suffix.isEmpty()) {
     268                 :          0 :         out << "/" << suffix;
     269                 :            :     }
     270                 :      76566 :     out << "." << extension[hpp] << "\"\n";
     271                 :      76566 : }
     272                 :            : 
     273                 :      26524 : bool Includes::isInterfaceType(rtl::OString const & registryType) const {
     274                 :      26524 :     return m_manager.getTypeClass(registryType) == RT_TYPE_INTERFACE;
     275                 :            : }
     276                 :            : 
     277                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10