LCOV - code coverage report
Current view: top level - codemaker/source/cppumaker - includes.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 127 143 88.8 %
Date: 2015-06-13 12:38:46 Functions: 7 7 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 "includes.hxx"
      22             : 
      23             : #include "dependencies.hxx"
      24             : #include "dumputils.hxx"
      25             : 
      26             : #include "codemaker/global.hxx"
      27             : #include "codemaker/typemanager.hxx"
      28             : #include "codemaker/unotype.hxx"
      29             : 
      30             : #include "osl/diagnose.h"
      31             : #include "rtl/ref.hxx"
      32             : #include "rtl/string.hxx"
      33             : #include "rtl/ustring.hxx"
      34             : #include "sal/types.h"
      35             : 
      36             : #include <vector>
      37             : 
      38             : using codemaker::cppumaker::Includes;
      39             : 
      40       15632 : Includes::Includes(
      41             :     rtl::Reference< TypeManager > const & manager,
      42             :     codemaker::cppumaker::Dependencies const & dependencies, bool hpp):
      43       15632 :     m_manager(manager), m_map(dependencies.getMap()), m_hpp(hpp),
      44             :     m_includeCassert(false), m_includeException(false),
      45       15632 :     m_includeAny(dependencies.hasAnyDependency()), m_includeReference(false),
      46       15632 :     m_includeSequence(dependencies.hasSequenceDependency()),
      47       15632 :     m_includeType(dependencies.hasTypeDependency()),
      48             :     m_includeCppuMacrosHxx(false), m_includeCppuUnotypeHxx(false),
      49             :     m_includeOslDoublecheckedlockingH(false), m_includeOslMutexHxx(false),
      50             :     m_includeRtlStrbufHxx(false), m_includeRtlStringH(false),
      51             :     m_includeRtlTextencH(false), m_includeRtlUstrbufHxx(false),
      52             :     m_includeRtlUstringH(false),
      53       15632 :     m_includeRtlUstringHxx(dependencies.hasStringDependency()),
      54             :     m_includeRtlInstanceHxx(false),
      55             :     m_includeSalTypesH(
      56       28898 :         dependencies.hasBooleanDependency() || dependencies.hasByteDependency()
      57       12873 :         || dependencies.hasShortDependency()
      58       11575 :         || dependencies.hasUnsignedShortDependency()
      59       11565 :         || dependencies.hasLongDependency()
      60        7918 :         || dependencies.hasUnsignedShortDependency()
      61        7918 :         || dependencies.hasHyperDependency()
      62        7866 :         || dependencies.hasUnsignedHyperDependency()
      63       23492 :         || dependencies.hasCharDependency()),
      64             :     m_includeTypelibTypeclassH(false),
      65      109424 :     m_includeTypelibTypedescriptionH(false)
      66       15632 : {}
      67             : 
      68       15632 : Includes::~Includes()
      69       15632 : {}
      70             : 
      71        5764 : void Includes::add(OString const & entityName) {
      72             :     sal_Int32 k;
      73        5764 :     std::vector< OString > args;
      74       11528 :     OUString n(b2u(codemaker::UnoType::decompose(entityName, &k, &args)));
      75        5764 :     if (k != 0) {
      76           0 :         m_includeSequence = true;
      77             :     }
      78        5764 :     switch (m_manager->getSort(n)) {
      79             :     case codemaker::UnoType::SORT_BOOLEAN:
      80             :     case codemaker::UnoType::SORT_BYTE:
      81             :     case codemaker::UnoType::SORT_SHORT:
      82             :     case codemaker::UnoType::SORT_UNSIGNED_SHORT:
      83             :     case codemaker::UnoType::SORT_LONG:
      84             :     case codemaker::UnoType::SORT_UNSIGNED_LONG:
      85             :     case codemaker::UnoType::SORT_HYPER:
      86             :     case codemaker::UnoType::SORT_UNSIGNED_HYPER:
      87             :     case codemaker::UnoType::SORT_CHAR:
      88           0 :         m_includeSalTypesH = true;
      89           0 :         break;
      90             :     case codemaker::UnoType::SORT_FLOAT:
      91             :     case codemaker::UnoType::SORT_DOUBLE:
      92           0 :         break;
      93             :     case codemaker::UnoType::SORT_STRING:
      94           0 :         m_includeRtlUstringHxx = true;
      95           0 :         break;
      96             :     case codemaker::UnoType::SORT_TYPE:
      97           0 :         m_includeType = true;
      98           0 :         break;
      99             :     case codemaker::UnoType::SORT_ANY:
     100           0 :         m_includeAny = true;
     101           0 :         break;
     102             :     case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     103           0 :         for (std::vector< OString >::iterator i(args.begin()); i != args.end();
     104             :              ++i)
     105             :         {
     106           0 :             add(*i);
     107             :         }
     108             :         // fall through
     109             :     case codemaker::UnoType::SORT_SEQUENCE_TYPE:
     110             :     case codemaker::UnoType::SORT_ENUM_TYPE:
     111             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     112             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     113             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
     114             :     case codemaker::UnoType::SORT_TYPEDEF:
     115             :         m_map.insert(
     116        5764 :             Dependencies::Map::value_type(n, Dependencies::KIND_NO_BASE));
     117        5764 :         break;
     118             :     default:
     119             :         throw CannotDumpException(
     120           0 :             "unexpected type \"" + b2u(entityName)
     121           0 :             + "\" in call to codemaker::cppumaker::Includes::add");
     122        5764 :     }
     123        5764 : }
     124             : 
     125             : namespace {
     126             : 
     127       90464 : void dumpEmptyLineBeforeFirst(FileStream & out, bool * first) {
     128             :     OSL_ASSERT(first != 0);
     129       90464 :     if (*first) {
     130       14079 :         out << "\n";
     131       14079 :         *first = false;
     132             :     }
     133       90464 : }
     134             : 
     135             : }
     136             : 
     137       14079 : void Includes::dump(FileStream & out, OUString const * companionHdl) {
     138             :     OSL_ASSERT(companionHdl == 0 || m_hpp);
     139       14079 :     if (!m_includeReference) {
     140        7569 :         for (Dependencies::Map::iterator i(m_map.begin()); i != m_map.end();
     141             :              ++i)
     142             :         {
     143        2506 :             if (isInterfaceType(u2b(i->first))) {
     144         288 :                 m_includeReference = true;
     145         288 :                 break;
     146             :             }
     147             :         }
     148             :     }
     149       14079 :     out << "#include \"sal/config.h\"\n";
     150       14079 :     if (m_includeCassert || m_includeException) {
     151        8728 :         out << "\n";
     152        8728 :         if (m_includeCassert) {
     153        1038 :             out << "#include <cassert>\n";
     154             :         }
     155        8728 :         if (m_includeException) {
     156        7690 :             out << "#include <exception>\n";
     157             :         }
     158             :     }
     159       14079 :     if (companionHdl) {
     160        5725 :         out << "\n";
     161        5725 :         dumpInclude(out, u2b(*companionHdl), false);
     162             :     }
     163       14079 :     bool first = true;
     164       51607 :     for (Dependencies::Map::iterator i(m_map.begin()); i != m_map.end(); ++i)
     165             :     {
     166       37528 :         dumpEmptyLineBeforeFirst(out, &first);
     167      116919 :         if (m_hpp || i->second == Dependencies::KIND_BASE
     168       98778 :             || !isInterfaceType(u2b(i->first)))
     169             :         {
     170       34520 :             dumpInclude(out, u2b(i->first), m_hpp);
     171             :         } else {
     172        3008 :             bool ns = dumpNamespaceOpen(out, i->first, false);
     173        3008 :             if (ns) {
     174        3008 :                 out << " ";
     175             :             }
     176        3008 :             out << "class ";
     177        3008 :             dumpTypeIdentifier(out, i->first);
     178        3008 :             out << ";";
     179        3008 :             if (ns) {
     180        3008 :                 out << " ";
     181             :             }
     182        3008 :             dumpNamespaceClose(out, i->first, false);
     183        3008 :             out << "\n";
     184             :         }
     185             :     }
     186             :     static char const * hxxExtension[2] = { "h", "hxx" };
     187       14079 :     if (m_includeAny) {
     188        1947 :         dumpEmptyLineBeforeFirst(out, &first);
     189        1947 :         out << "#include \"com/sun/star/uno/Any." << hxxExtension[m_hpp]
     190        1947 :             << "\"\n";
     191             :     }
     192       14079 :     if (m_includeReference) {
     193        9016 :         dumpEmptyLineBeforeFirst(out, &first);
     194        9016 :         out << "#include \"com/sun/star/uno/Reference." << hxxExtension[m_hpp]
     195        9016 :             << "\"\n";
     196             :     }
     197       14079 :     if (m_includeSequence) {
     198        2674 :         dumpEmptyLineBeforeFirst(out, &first);
     199        2674 :         out << "#include \"com/sun/star/uno/Sequence." << hxxExtension[m_hpp]
     200        2674 :             << "\"\n";
     201             :     }
     202       14079 :     if (m_includeType) {
     203        5802 :         dumpEmptyLineBeforeFirst(out, &first);
     204        5802 :         out << "#include \"com/sun/star/uno/Type." << hxxExtension[m_hpp]
     205        5802 :             << "\"\n";
     206             :     }
     207       14079 :     if (m_includeCppuMacrosHxx) {
     208        7278 :         dumpEmptyLineBeforeFirst(out, &first);
     209        7278 :         out << ("#include \"cppu/macros.hxx\"\n");
     210             :     }
     211       14079 :     if (m_includeCppuUnotypeHxx) {
     212        6801 :         dumpEmptyLineBeforeFirst(out, &first);
     213        6801 :         out << ("#include \"cppu/unotype.hxx\"\n");
     214             :     }
     215       14079 :     if (m_includeOslDoublecheckedlockingH) {
     216           0 :         dumpEmptyLineBeforeFirst(out, &first);
     217           0 :         out << ("#include \"osl/doublecheckedlocking.h\"\n");
     218             :     }
     219       14079 :     if (m_includeOslMutexHxx) {
     220        1836 :         dumpEmptyLineBeforeFirst(out, &first);
     221        1836 :         out << "#include \"osl/mutex.hxx\"\n";
     222             :     }
     223       14079 :     if (m_includeRtlStrbufHxx) {
     224          10 :         dumpEmptyLineBeforeFirst(out, &first);
     225          10 :         out << ("#include \"rtl/strbuf.hxx\"\n");
     226             :     }
     227       14079 :     if (m_includeRtlStringH) {
     228           6 :         dumpEmptyLineBeforeFirst(out, &first);
     229           6 :         out << "#include \"rtl/string.h\"\n";
     230             :     }
     231       14079 :     if (m_includeRtlTextencH) {
     232          10 :         dumpEmptyLineBeforeFirst(out, &first);
     233          10 :         out << "#include \"rtl/textenc.h\"\n";
     234             :     }
     235       14079 :     if (m_includeRtlUstrbufHxx) {
     236           6 :         dumpEmptyLineBeforeFirst(out, &first);
     237           6 :         out << ("#include \"rtl/ustrbuf.hxx\"\n");
     238             :     }
     239       14079 :     if (m_includeRtlUstringH) {
     240        1459 :         dumpEmptyLineBeforeFirst(out, &first);
     241        1459 :         out << "#include \"rtl/ustring.h\"\n";
     242             :     }
     243       14079 :     if (m_includeRtlUstringHxx) {
     244        5075 :         dumpEmptyLineBeforeFirst(out, &first);
     245        5075 :         out << ("#include \"rtl/ustring.hxx\"\n");
     246             :     }
     247       14079 :     if (m_includeRtlInstanceHxx) {
     248        2726 :         dumpEmptyLineBeforeFirst(out, &first);
     249        2726 :         out << "#include \"rtl/instance.hxx\"\n";
     250             :     }
     251       14079 :     if (m_includeSalTypesH) {
     252        6584 :         dumpEmptyLineBeforeFirst(out, &first);
     253        6584 :         out << "#include \"sal/types.h\"\n";
     254             :     }
     255       14079 :     if (m_includeTypelibTypeclassH) {
     256         853 :         dumpEmptyLineBeforeFirst(out, &first);
     257         853 :         out << ("#include \"typelib/typeclass.h\"\n");
     258             :     }
     259       14079 :     if (m_includeTypelibTypedescriptionH) {
     260         853 :         dumpEmptyLineBeforeFirst(out, &first);
     261         853 :         out << ("#include \"typelib/typedescription.h\"\n");
     262             :     }
     263       14079 : }
     264             : 
     265       41798 : void Includes::dumpInclude(
     266             :     FileStream & out, OString const & entityName, bool hpp)
     267             : {
     268       83596 :     out << "#include \"" << entityName.replace('.', '/') << "."
     269       83596 :         << (hpp ? "hpp" : "hdl") << "\"\n";
     270       41798 : }
     271             : 
     272       14367 : bool Includes::isInterfaceType(OString const & entityName) const {
     273       14367 :     return m_manager->getSort(b2u(entityName)) == UnoType::SORT_INTERFACE_TYPE;
     274             : }
     275             : 
     276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11