LCOV - code coverage report
Current view: top level - codemaker/source/cppumaker - cppumaker.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 65 93 69.9 %
Date: 2012-08-25 Functions: 6 7 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 87 186 46.8 %

           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 <stdio.h>
      22                 :            : 
      23                 :            : #include "sal/main.h"
      24                 :            : 
      25                 :            : #include "codemaker/typemanager.hxx"
      26                 :            : #include "codemaker/generatedtypeset.hxx"
      27                 :            : 
      28                 :            : #include "cppuoptions.hxx"
      29                 :            : #include "cpputype.hxx"
      30                 :            : 
      31                 :            : using ::rtl::OString;
      32                 :            : using ::rtl::OUString;
      33                 :            : 
      34                 :            : namespace {
      35                 :            : 
      36                 :          0 : void failed(rtl::OString const & typeName, CppuOptions * options) {
      37         [ #  # ]:          0 :     fprintf(stderr, "%s ERROR: %s\n", options->getProgramName().getStr(),
      38         [ #  # ]:          0 :             rtl::OString("cannot dump Type '" + typeName + "'").getStr());
      39                 :          0 :     exit(99);
      40                 :            : }
      41                 :            : 
      42                 :      20746 : void produce(
      43                 :            :     RegistryKey& rTypeKey, bool bIsExtraType, TypeManager const & typeMgr,
      44                 :            :     codemaker::GeneratedTypeSet & generated, CppuOptions * options)
      45                 :            : {
      46         [ -  + ]:      20746 :     if (!produceType(rTypeKey, bIsExtraType, typeMgr, generated, options)) {
      47         [ #  # ]:          0 :         OString typeName = typeMgr.getTypeName(rTypeKey);
      48         [ #  # ]:          0 :         failed(typeName, options);
      49                 :            :     }
      50                 :      20746 : }
      51                 :            : 
      52                 :         90 : void produce(
      53                 :            :     rtl::OString const & typeName, TypeManager const & typeMgr,
      54                 :            :     codemaker::GeneratedTypeSet & generated, CppuOptions * options)
      55                 :            : {
      56         [ -  + ]:         90 :     if (!produceType(typeName, typeMgr, generated, options)) {
      57                 :          0 :         failed(typeName, options);
      58                 :            :     }
      59                 :         90 : }
      60                 :            : 
      61                 :      20746 : void produceAllTypes(RegistryKey& rTypeKey, bool bIsExtraType,
      62                 :            :                          TypeManager const & typeMgr,
      63                 :            :                          codemaker::GeneratedTypeSet & generated,
      64                 :            :                          CppuOptions* pOptions,
      65                 :            :                          sal_Bool bFullScope)
      66                 :            :     throw( CannotDumpException )
      67                 :            : {
      68         [ +  - ]:      20746 :     OString typeName = typeMgr.getTypeName(rTypeKey);
      69                 :            : 
      70         [ +  - ]:      20746 :     produce(rTypeKey, bIsExtraType, typeMgr, generated, pOptions);
      71                 :            : 
      72         [ +  - ]:      20746 :     RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName);
      73         [ +  - ]:      20746 :     RegistryKeyList::const_iterator iter = typeKeys.begin();
      74 [ +  - ][ +  - ]:      20746 :     RegistryKey key, subKey;
      75         [ +  - ]:      20746 :     RegistryKeyArray subKeys;
      76                 :            : 
      77 [ +  - ][ +  + ]:      41558 :     while (iter != typeKeys.end())
      78                 :            :     {
      79         [ +  - ]:      20812 :         key = (*iter).first;
      80                 :            : 
      81 [ +  + ][ +  - ]:      20812 :         if (!(*iter).second  && !key.openSubKeys(OUString(), subKeys))
         [ +  - ][ +  + ]
           [ +  +  #  # ]
      82                 :            :         {
      83         [ +  + ]:      41428 :             for (sal_uInt32 i = 0; i < subKeys.getLength(); i++)
      84                 :            :             {
      85 [ +  - ][ +  - ]:      20682 :                 subKey = subKeys.getElement(i);
                 [ +  - ]
      86         [ +  - ]:      20682 :                 if (bFullScope)
      87                 :            :                 {
      88                 :      20682 :                     produceAllTypes(subKey, (*iter).second, typeMgr,
      89         [ +  - ]:      20682 :                                     generated, pOptions, true);
      90                 :            :                 } else
      91                 :            :                 {
      92                 :          0 :                     produce(subKey, (*iter).second,
      93         [ #  # ]:          0 :                             typeMgr, generated, pOptions);
      94                 :            :                 }
      95                 :            :             }
      96                 :            :         }
      97                 :            : 
      98                 :      20812 :         ++iter;
      99 [ +  - ][ +  - ]:      20746 :     }
                 [ +  - ]
     100                 :      20746 : }
     101                 :            : 
     102                 :         20 : void produceAllTypes(const OString& typeName,
     103                 :            :                      TypeManager const & typeMgr,
     104                 :            :                      codemaker::GeneratedTypeSet & generated,
     105                 :            :                      CppuOptions* pOptions,
     106                 :            :                      sal_Bool bFullScope)
     107                 :            :     throw( CannotDumpException )
     108                 :            : {
     109         [ +  - ]:         20 :     produce(typeName, typeMgr, generated, pOptions);
     110                 :            : 
     111         [ +  - ]:         20 :     RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName);
     112         [ +  - ]:         20 :     RegistryKeyList::const_iterator iter = typeKeys.begin();
     113 [ +  - ][ +  - ]:         20 :     RegistryKey key, subKey;
     114         [ +  - ]:         20 :     RegistryKeyArray subKeys;
     115                 :            : 
     116 [ +  - ][ +  + ]:         58 :     while (iter != typeKeys.end())
     117                 :            :     {
     118         [ +  - ]:         38 :         key = (*iter).first;
     119 [ +  + ][ +  - ]:         38 :         if (!(*iter).second  && !key.openSubKeys(OUString(), subKeys))
         [ +  - ][ +  + ]
           [ +  +  #  # ]
     120                 :            :         {
     121         [ +  + ]:         84 :             for (sal_uInt32 i = 0; i < subKeys.getLength(); i++)
     122                 :            :             {
     123 [ +  - ][ +  - ]:         64 :                 subKey = subKeys.getElement(i);
                 [ +  - ]
     124         [ +  - ]:         64 :                 if (bFullScope)
     125                 :            :                 {
     126                 :         64 :                     produceAllTypes(subKey, (*iter).second, typeMgr,
     127         [ +  - ]:         64 :                                     generated, pOptions, true);
     128                 :            :                 } else
     129                 :            :                 {
     130                 :          0 :                     produce(subKey, (*iter).second,
     131         [ #  # ]:          0 :                             typeMgr, generated, pOptions);
     132                 :            :                 }
     133                 :            :             }
     134                 :            :         }
     135                 :            : 
     136                 :         38 :         ++iter;
     137 [ +  - ][ +  - ]:         20 :     }
                 [ +  - ]
     138                 :         20 : }
     139                 :            : 
     140                 :            : }
     141                 :            : 
     142                 :         22 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
     143                 :            : {
     144         [ +  - ]:         22 :     CppuOptions options;
     145                 :            : 
     146                 :            :     try
     147                 :            :     {
     148 [ +  - ][ -  + ]:         22 :         if (!options.initOptions(argc, argv))
     149                 :            :         {
     150                 :          0 :             exit(1);
     151                 :            :         }
     152                 :            :     }
     153         [ #  # ]:          0 :     catch( IllegalArgument& e)
     154                 :            :     {
     155         [ #  # ]:          0 :         fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr());
     156                 :          0 :         exit(99);
     157                 :            :     }
     158                 :            : 
     159         [ +  - ]:         22 :     RegistryTypeManager typeMgr;
     160                 :            : 
     161 [ +  - ][ +  - ]:         22 :     if (!typeMgr.init(options.getInputFiles(), options.getExtraInputFiles()))
                 [ -  + ]
     162                 :            :     {
     163 [ #  # ][ #  # ]:          0 :         fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr());
     164                 :          0 :         exit(99);
     165                 :            :     }
     166                 :            : 
     167 [ +  - ][ +  - ]:         22 :     if (options.isValid("-B"))
     168                 :            :     {
     169 [ +  - ][ +  - ]:         22 :         typeMgr.setBase(options.getOption("-B"));
     170                 :            :     }
     171                 :            : 
     172         [ +  - ]:         22 :     codemaker::GeneratedTypeSet generated;
     173                 :            :     try
     174                 :            :     {
     175 [ +  - ][ +  + ]:         22 :         if (options.isValid("-T"))
     176                 :            :         {
     177         [ +  - ]:          2 :             OString tOption(options.getOption("-T"));
     178                 :            : 
     179                 :          2 :             OString typeName, tmpName;
     180                 :          2 :             sal_Int32 nIndex = 0;
     181         [ +  + ]:          4 :             do
     182                 :            :             {
     183                 :          4 :                 typeName = tOption.getToken(0, ';', nIndex);
     184                 :            : 
     185                 :          4 :                 sal_Int32 nPos = typeName.lastIndexOf( '.' );
     186         [ +  - ]:          4 :                 tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 );
     187         [ -  + ]:          4 :                 if (tmpName == "*")
     188                 :            :                 {
     189                 :            :                     // produce this type and his scope
     190         [ #  # ]:          0 :                     if (typeName.equals("*"))
     191                 :            :                     {
     192                 :          0 :                         tmpName = "/";
     193                 :            :                     } else
     194                 :            :                     {
     195                 :          0 :                         tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/');
     196         [ #  # ]:          0 :                         if (tmpName.isEmpty())
     197                 :          0 :                             tmpName = "/";
     198                 :            :                         else
     199                 :          0 :                             tmpName.replace('.', '/');
     200                 :            :                     }
     201                 :            :                     // related to task #116780# the scope is recursively
     202                 :            :                     // generated.  bFullScope = true
     203                 :            :                     produceAllTypes(
     204         [ #  # ]:          0 :                         tmpName, typeMgr, generated, &options, true);
     205                 :            :                 } else
     206                 :            :                 {
     207                 :            :                     // produce only this type
     208                 :            :                     produce(
     209         [ +  - ]:          4 :                         typeName.replace('.', '/'), typeMgr, generated, &options);
     210                 :            :                 }
     211                 :          2 :             } while( nIndex != -1 );
     212                 :            :         } else
     213                 :            :         {
     214                 :            :             // produce all types
     215         [ +  - ]:         20 :             produceAllTypes("/", typeMgr, generated, &options, true);
     216                 :            :         }
     217                 :            :         // C++ header files generated for the following UNO types are included
     218                 :            :         // in header files in cppu/inc/com/sun/star/uno (Any.hxx, Reference.hxx,
     219                 :            :         // Type.h), so it seems best to always generate those C++ header files:
     220         [ +  - ]:         22 :         produce("com/sun/star/uno/RuntimeException", typeMgr, generated, &options);
     221         [ +  - ]:         22 :         produce("com/sun/star/uno/TypeClass", typeMgr, generated, &options);
     222         [ +  - ]:         22 :         produce("com/sun/star/uno/XInterface", typeMgr, generated, &options);
     223                 :            :     }
     224         [ #  # ]:          0 :     catch( CannotDumpException& e)
     225                 :            :     {
     226                 :            :         fprintf(stderr, "%s ERROR: %s\n",
     227         [ #  # ]:          0 :                 options.getProgramName().getStr(),
     228         [ #  # ]:          0 :                 e.m_message.getStr());
     229                 :          0 :         exit(99);
     230                 :            :     }
     231                 :            : 
     232 [ +  - ][ +  - ]:         22 :     return 0;
                 [ +  - ]
     233                 :            : }
     234                 :            : 
     235                 :            : 
     236                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10