LCOV - code coverage report
Current view: top level - codemaker/source/cppumaker - cpputype.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2362 2419 97.6 %
Date: 2014-04-11 Functions: 126 144 87.5 %
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 "sal/config.h"
      21             : 
      22             : #include <algorithm>
      23             : #include <cassert>
      24             : #include <map>
      25             : #include <set>
      26             : #include <vector>
      27             : 
      28             : #include "boost/noncopyable.hpp"
      29             : #include "rtl/alloc.h"
      30             : #include "rtl/ref.hxx"
      31             : #include "rtl/ustrbuf.hxx"
      32             : #include "rtl/ustring.hxx"
      33             : #include "rtl/strbuf.hxx"
      34             : #include "unoidl/unoidl.hxx"
      35             : 
      36             : #include "codemaker/commoncpp.hxx"
      37             : #include "codemaker/exceptiontree.hxx"
      38             : #include "codemaker/generatedtypeset.hxx"
      39             : #include "codemaker/typemanager.hxx"
      40             : #include "codemaker/unotype.hxx"
      41             : 
      42             : #include "cpputype.hxx"
      43             : #include "cppuoptions.hxx"
      44             : #include "dependencies.hxx"
      45             : #include "dumputils.hxx"
      46             : #include "includes.hxx"
      47             : 
      48             : namespace {
      49             : 
      50        8308 : bool isBootstrapType(OUString const & name) {
      51             :     static char const * const names[] = {
      52             :         "com.sun.star.beans.Property",
      53             :         "com.sun.star.beans.PropertyAttribute",
      54             :         "com.sun.star.beans.PropertyChangeEvent",
      55             :         "com.sun.star.beans.PropertyState",
      56             :         "com.sun.star.beans.PropertyValue",
      57             :         "com.sun.star.beans.XFastPropertySet",
      58             :         "com.sun.star.beans.XMultiPropertySet",
      59             :         "com.sun.star.beans.XPropertiesChangeListener",
      60             :         "com.sun.star.beans.XPropertyAccess",
      61             :         "com.sun.star.beans.XPropertyChangeListener",
      62             :         "com.sun.star.beans.XPropertySet",
      63             :         "com.sun.star.beans.XPropertySetInfo",
      64             :         "com.sun.star.beans.XPropertySetOption",
      65             :         "com.sun.star.beans.XVetoableChangeListener",
      66             :         "com.sun.star.bridge.UnoUrlResolver",
      67             :         "com.sun.star.bridge.XUnoUrlResolver",
      68             :         "com.sun.star.connection.SocketPermission",
      69             :         "com.sun.star.container.XElementAccess",
      70             :         "com.sun.star.container.XEnumeration",
      71             :         "com.sun.star.container.XEnumerationAccess",
      72             :         "com.sun.star.container.XHierarchicalNameAccess",
      73             :         "com.sun.star.container.XNameAccess",
      74             :         "com.sun.star.container.XNameContainer",
      75             :         "com.sun.star.container.XNameReplace",
      76             :         "com.sun.star.container.XSet",
      77             :         "com.sun.star.io.FilePermission",
      78             :         "com.sun.star.io.IOException",
      79             :         "com.sun.star.lang.DisposedException",
      80             :         "com.sun.star.lang.EventObject",
      81             :         "com.sun.star.lang.WrappedTargetRuntimeException",
      82             :         "com.sun.star.lang.XComponent",
      83             :         "com.sun.star.lang.XEventListener",
      84             :         "com.sun.star.lang.XInitialization",
      85             :         "com.sun.star.lang.XMultiComponentFactory",
      86             :         "com.sun.star.lang.XMultiServiceFactory",
      87             :         "com.sun.star.lang.XServiceInfo",
      88             :         "com.sun.star.lang.XSingleComponentFactory",
      89             :         "com.sun.star.lang.XSingleServiceFactory",
      90             :         "com.sun.star.lang.XTypeProvider",
      91             :         "com.sun.star.loader.XImplementationLoader",
      92             :         "com.sun.star.reflection.FieldAccessMode",
      93             :         "com.sun.star.reflection.MethodMode",
      94             :         "com.sun.star.reflection.ParamInfo",
      95             :         "com.sun.star.reflection.ParamMode",
      96             :         "com.sun.star.reflection.TypeDescriptionSearchDepth",
      97             :         "com.sun.star.reflection.XCompoundTypeDescription",
      98             :         "com.sun.star.reflection.XEnumTypeDescription",
      99             :         "com.sun.star.reflection.XIdlArray",
     100             :         "com.sun.star.reflection.XIdlClass",
     101             :         "com.sun.star.reflection.XIdlField",
     102             :         "com.sun.star.reflection.XIdlField2",
     103             :         "com.sun.star.reflection.XIdlMethod",
     104             :         "com.sun.star.reflection.XIdlReflection",
     105             :         "com.sun.star.reflection.XIndirectTypeDescription",
     106             :         "com.sun.star.reflection.XInterfaceAttributeTypeDescription",
     107             :         "com.sun.star.reflection.XInterfaceAttributeTypeDescription2",
     108             :         "com.sun.star.reflection.XInterfaceMemberTypeDescription",
     109             :         "com.sun.star.reflection.XInterfaceMethodTypeDescription",
     110             :         "com.sun.star.reflection.XInterfaceTypeDescription",
     111             :         "com.sun.star.reflection.XInterfaceTypeDescription2",
     112             :         "com.sun.star.reflection.XMethodParameter",
     113             :         "com.sun.star.reflection.XStructTypeDescription",
     114             :         "com.sun.star.reflection.XTypeDescription",
     115             :         "com.sun.star.reflection.XTypeDescriptionEnumeration",
     116             :         "com.sun.star.reflection.XTypeDescriptionEnumerationAccess",
     117             :         "com.sun.star.registry.RegistryKeyType",
     118             :         "com.sun.star.registry.RegistryValueType",
     119             :         "com.sun.star.registry.XImplementationRegistration",
     120             :         "com.sun.star.registry.XRegistryKey",
     121             :         "com.sun.star.registry.XSimpleRegistry",
     122             :         "com.sun.star.security.RuntimePermission",
     123             :         "com.sun.star.security.XAccessControlContext",
     124             :         "com.sun.star.security.XAccessController",
     125             :         "com.sun.star.security.XAction",
     126             :         "com.sun.star.uno.DeploymentException",
     127             :         "com.sun.star.uno.RuntimeException",
     128             :         "com.sun.star.uno.TypeClass",
     129             :         "com.sun.star.uno.Uik",
     130             :         "com.sun.star.uno.XAdapter",
     131             :         "com.sun.star.uno.XAggregation",
     132             :         "com.sun.star.uno.XComponentContext",
     133             :         "com.sun.star.uno.XCurrentContext",
     134             :         "com.sun.star.uno.XInterface",
     135             :         "com.sun.star.uno.XReference",
     136             :         "com.sun.star.uno.XUnloadingPreference",
     137             :         "com.sun.star.uno.XWeak",
     138             :         "com.sun.star.util.XMacroExpander" };
     139             :         // cf. cppuhelper/unotypes/Makefile UNOTYPES (plus missing dependencies)
     140      719620 :     for (std::size_t i = 0; i < SAL_N_ELEMENTS(names); ++i) {
     141      711573 :         if (name.equalsAscii(names[i])) {
     142         261 :             return true;
     143             :         }
     144             :     }
     145        8047 :     return false;
     146             : }
     147             : 
     148             : class CppuType: private boost::noncopyable {
     149             : public:
     150             :     CppuType(
     151             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr);
     152             : 
     153        8308 :     virtual ~CppuType() {}
     154             : 
     155             :     void dump(CppuOptions const & options);
     156             : 
     157             :     void dumpFile(
     158             :         OUString const & uri, OUString const & name, bool hpp,
     159             :         CppuOptions const & options);
     160             : 
     161             :     void dumpDependedTypes(
     162             :         codemaker::GeneratedTypeSet & generated, CppuOptions const & options);
     163             : 
     164        5622 :     virtual void dumpHFile(
     165             :         FileStream & out, codemaker::cppumaker::Includes & includes)
     166        5622 :     { dumpHFileContent(out, includes); }
     167             : 
     168             :     virtual void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) = 0;
     169             : 
     170             :     OUString dumpHeaderDefine(FileStream& o, OUString const & extension);
     171             : 
     172             :     void dumpGetCppuType(FileStream & out);
     173             : 
     174             :     virtual void dumpLightGetCppuType(FileStream & out);
     175             : 
     176           0 :     virtual void dumpNormalGetCppuType(FileStream &)
     177           0 :     { assert(false); } // this cannot happen
     178             : 
     179           0 :     virtual void dumpComprehensiveGetCppuType(FileStream &)
     180           0 :     { assert(false); } // this cannot happen
     181             : 
     182             :     void dumpType(
     183             :         FileStream & out, OUString const & name, bool isConst = false,
     184             :         bool isRef = false, bool native = false, bool cppuUnoType = false)
     185             :         const;
     186             : 
     187             :     OUString getTypeClass(OUString const & name, bool cStyle = false);
     188             : 
     189             :     void dumpCppuGetType(
     190             :         FileStream & out, OUString const & name, OUString const * ownName = 0);
     191             : 
     192             :     sal_uInt32 getInheritedMemberCount();
     193             : 
     194             :     void            inc(sal_Int32 num=4);
     195             :     void            dec(sal_Int32 num=4);
     196             :     OUString indent() const;
     197             : protected:
     198           0 :     virtual sal_uInt32 checkInheritedMemberCount() const
     199           0 :     { assert(false); return 0; } // this cannot happen
     200             : 
     201             :     bool passByReference(OUString const & name) const;
     202             : 
     203             :     OUString resolveOuterTypedefs(OUString const & name) const;
     204             : 
     205             :     OUString resolveAllTypedefs(OUString const & name) const;
     206             : 
     207             :     codemaker::cpp::IdentifierTranslationMode isGlobal() const;
     208             : 
     209           0 :     virtual void dumpDeclaration(FileStream &)
     210           0 :     { assert(false); } // this cannot happen
     211             : 
     212             :     virtual void dumpFiles(OUString const & uri, CppuOptions const & options);
     213             : 
     214             :     virtual void addLightGetCppuTypeIncludes(
     215             :         codemaker::cppumaker::Includes & includes) const;
     216             : 
     217             :     virtual void addNormalGetCppuTypeIncludes(
     218             :         codemaker::cppumaker::Includes & includes) const;
     219             : 
     220             :     virtual void addComprehensiveGetCppuTypeIncludes(
     221             :         codemaker::cppumaker::Includes & includes) const;
     222             : 
     223             :     virtual bool isPolymorphic() const;
     224             : 
     225       11206 :     virtual void dumpTemplateHead(FileStream &) const {}
     226             : 
     227       16806 :     virtual void dumpTemplateParameters(FileStream &) const {}
     228             : 
     229             :     void dumpGetCppuTypePreamble(FileStream & out);
     230             : 
     231             :     void dumpGetCppuTypePostamble(FileStream & out);
     232             : 
     233             :     void addDefaultHIncludes(codemaker::cppumaker::Includes & includes) const;
     234             :     void addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes) const;
     235             : 
     236             :     void dumpInitializer(
     237             :         FileStream & out, bool parameterized, OUString const & name) const;
     238             : 
     239             :     void dumpHFileContent(
     240             :         FileStream & out, codemaker::cppumaker::Includes & includes);
     241             : 
     242             : protected:
     243             :     sal_uInt32          m_inheritedMemberCount;
     244             : 
     245             :     bool                m_cppuTypeLeak;
     246             :     bool                m_cppuTypeDynamic;
     247             :     sal_Int32           m_indentLength;
     248             :     OUString name_;
     249             :     OUString id_;
     250             :     rtl::Reference< TypeManager > m_typeMgr;
     251             :     codemaker::cppumaker::Dependencies m_dependencies;
     252             : 
     253             : private:
     254             :     void addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes)
     255             :         const;
     256             : };
     257             : 
     258        8308 : CppuType::CppuType(
     259             :     OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
     260             :     m_inheritedMemberCount(0)
     261             :     , m_cppuTypeLeak(false)
     262             :     , m_cppuTypeDynamic(true)
     263             :     , m_indentLength(0)
     264             :     , name_(name)
     265        8308 :     , id_(name_.copy(name_.lastIndexOf('.') + 1))
     266             :     , m_typeMgr(typeMgr)
     267       16616 :     , m_dependencies(typeMgr, name_)
     268        8308 : {}
     269             : 
     270        8308 : void CppuType::addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes)
     271             :     const
     272             : {
     273       16616 :     if (name_ == "com.sun.star.uno.XInterface"
     274        8308 :         || name_ == "com.sun.star.uno.Exception")
     275             :     {
     276           6 :         includes.addType();
     277           6 :         includes.addCppuUnotypeHxx();
     278           6 :         includes.addSalTypesH();
     279           6 :         includes.addTypelibTypeclassH();
     280           6 :         includes.addTypelibTypedescriptionH();
     281        8302 :     } else if (m_cppuTypeLeak) {
     282        4226 :         addLightGetCppuTypeIncludes(includes);
     283        4076 :     } else if (m_cppuTypeDynamic) {
     284         294 :         addNormalGetCppuTypeIncludes(includes);
     285             :     } else {
     286        3782 :         addComprehensiveGetCppuTypeIncludes(includes);
     287             :     }
     288        8308 : }
     289             : 
     290        7234 : void CppuType::dumpFiles(OUString const & uri, CppuOptions const & options) {
     291        7234 :     dumpFile(uri, name_, false, options);
     292        7234 :     dumpFile(uri, name_, true, options);
     293        7234 : }
     294             : 
     295        3831 : void CppuType::addLightGetCppuTypeIncludes(
     296             :     codemaker::cppumaker::Includes & includes) const
     297             : {
     298             :     //TODO: Determine what is really needed, instead of relying on
     299             :     // addDefaultHxxIncludes
     300        3831 :     includes.addCppuUnotypeHxx();
     301        3831 : }
     302             : 
     303         263 : void CppuType::addNormalGetCppuTypeIncludes(
     304             :     codemaker::cppumaker::Includes & includes) const
     305             : {
     306             :     //TODO: Determine what is really needed, instead of relying on
     307             :     // addDefaultHxxIncludes
     308         263 :     includes.addCppuUnotypeHxx();
     309         263 : }
     310             : 
     311        1539 : void CppuType::addComprehensiveGetCppuTypeIncludes(
     312             :     codemaker::cppumaker::Includes & includes) const
     313             : {
     314             :     //TODO: Determine what is really needed, instead of relying on
     315             :     // addDefaultHxxIncludes
     316        1539 :     includes.addCppuUnotypeHxx();
     317        1539 : }
     318             : 
     319       17222 : bool CppuType::isPolymorphic() const { return false; }
     320             : 
     321        5616 : void CppuType::dumpGetCppuTypePreamble(FileStream & out) {
     322        5616 :     if (isPolymorphic()) {
     323          16 :         out << "namespace cppu {\n\n";
     324          16 :         dumpTemplateHead(out);
     325          16 :         out << "class UnoType< ";
     326          16 :         dumpType(out, name_);
     327          16 :         dumpTemplateParameters(out);
     328          16 :         out << " > {\npublic:\n";
     329          16 :         inc();
     330          32 :         out << indent()
     331          16 :             << "static inline ::css::uno::Type const & get() {\n";
     332             :     } else {
     333        5600 :         if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
     334        5584 :             out << "\n\n";
     335             :         }
     336             :         out << ("inline ::css::uno::Type const &"
     337        5600 :                 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
     338        5600 :         dumpType(out, name_, false, false, true);
     339        5600 :         out << " const *) {\n";
     340             :     }
     341        5616 :     inc();
     342        5616 : }
     343             : 
     344        5616 : void CppuType::dumpGetCppuTypePostamble(FileStream & out) {
     345        5616 :     dec();
     346        5616 :     if (isPolymorphic()) {
     347          32 :         out << indent() << "}\n\nprivate:\n"
     348          48 :             << indent() << "UnoType(UnoType &); // not defined\n"
     349          48 :             << indent() << "~UnoType(); // not defined\n"
     350          48 :             << indent()
     351          16 :             << "void operator =(UnoType); // not defined\n};\n\n}\n\n";
     352             :     } else {
     353        5600 :         out << "}\n\n";
     354        5600 :         if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
     355        5584 :             out << "\n\n";
     356             :         }
     357             :     }
     358        5616 :     dumpTemplateHead(out);
     359             :     out << ("inline ::css::uno::Type const & SAL_CALL"
     360        5616 :             " getCppuType(SAL_UNUSED_PARAMETER ");
     361        5616 :     dumpType(out, name_);
     362        5616 :     dumpTemplateParameters(out);
     363        5616 :     out << " const *) SAL_THROW(()) {\n";
     364        5616 :     inc();
     365        5616 :     out << indent() << "return ::cppu::UnoType< ";
     366        5616 :     dumpType(out, name_);
     367        5616 :     dumpTemplateParameters(out);
     368        5616 :     out << " >::get();\n";
     369        5616 :     dec();
     370        5616 :     out << indent() << "}\n";
     371        5616 : }
     372             : 
     373        8308 : void CppuType::dump(CppuOptions const & options) {
     374        8308 :     if (isBootstrapType(name_)) {
     375         261 :         m_cppuTypeDynamic = false;
     376             :     } else {
     377             :         // -CS was used as an undocumented option to generate static getCppuType
     378             :         // functions; since the introduction of cppu::UnoType this no longer is
     379             :         // meaningful (getCppuType is just a forward to cppu::UnoType::get now),
     380             :         // and -CS is handled the same way as -C now:
     381        8047 :         if (options.isValid("-L"))
     382        4227 :             m_cppuTypeLeak = true;
     383        8047 :         if (options.isValid("-C") || options.isValid("-CS"))
     384        3525 :             m_cppuTypeDynamic = false;
     385             :     }
     386             :     dumpFiles(
     387        8308 :         options.isValid("-O") ? b2u(options.getOption("-O")) : "", options);
     388        8308 : }
     389             : 
     390       15542 : void CppuType::dumpFile(
     391             :     OUString const & uri, OUString const & name, bool hpp,
     392             :     CppuOptions const & options)
     393             : {
     394             :     OUString fileUri(
     395             :         b2u(createFileNameFromType(
     396       15542 :                 u2b(uri), u2b(name), hpp ? ".hpp" : ".hdl")));
     397       15542 :     if (fileUri.isEmpty()) {
     398           0 :         throw CannotDumpException("empty target URI for entity " + name);
     399             :     }
     400       15542 :     bool exists = fileExists(u2b(fileUri));
     401       15542 :     if (exists && options.isValid("-G")) {
     402       15542 :         return;
     403             :     }
     404       31084 :     FileStream out;
     405       15542 :     out.createTempFile(getTempDir(u2b(fileUri)));
     406       31084 :     OUString tmpUri(b2u(out.getName()));
     407       15542 :     if(!out.isValid()) {
     408           0 :         throw CannotDumpException("cannot open " + tmpUri + " for writing");
     409             :     }
     410       31084 :     codemaker::cppumaker::Includes includes(m_typeMgr, m_dependencies, hpp);
     411             :     try {
     412       15542 :         if (hpp) {
     413        8308 :             addGetCppuTypeIncludes(includes);
     414        8308 :             dumpHxxFile(out, includes);
     415             :         } else {
     416        7234 :             dumpHFile(out, includes);
     417             :         }
     418           0 :     } catch (...) {
     419           0 :         out.close();
     420             :         // Remove existing type file if something goes wrong to ensure
     421             :         // consistency:
     422           0 :         if (fileExists(u2b(fileUri))) {
     423           0 :             removeTypeFile(u2b(fileUri));
     424             :         }
     425           0 :         removeTypeFile(u2b(tmpUri));
     426           0 :         throw;
     427             :     }
     428       15542 :     out.close();
     429             :     makeValidTypeFile(
     430       31084 :         u2b(fileUri), u2b(tmpUri), exists && options.isValid("-Gc"));
     431             : }
     432             : 
     433        6771 : void CppuType::dumpDependedTypes(
     434             :     codemaker::GeneratedTypeSet & generated, CppuOptions const & options)
     435             : {
     436        6771 :     if (!options.isValid("-nD")) {
     437             :         codemaker::cppumaker::Dependencies::Map const & map
     438        6771 :             = m_dependencies.getMap();
     439       72543 :         for (codemaker::cppumaker::Dependencies::Map::const_iterator i(
     440        6771 :                  map.begin());
     441       48362 :              i != map.end(); ++i)
     442             :         {
     443       17410 :             produce(i->first, m_typeMgr, generated, options);
     444             :         }
     445             :     }
     446        6771 : }
     447             : 
     448       15542 : OUString CppuType::dumpHeaderDefine(
     449             :     FileStream & out, OUString const & extension)
     450             : {
     451             :     OUString def(
     452       46626 :         "INCLUDED_" + name_.replace('.', '_').toAsciiUpperCase() + "_"
     453       31084 :         + extension);
     454       15542 :     out << "#ifndef " << def << "\n#define " << def << "\n";
     455       15542 :     return def;
     456             : }
     457             : 
     458        7234 : void CppuType::addDefaultHIncludes(codemaker::cppumaker::Includes & includes)
     459             :     const
     460             : {
     461             :     //TODO: Only include what is really needed
     462        7234 :     includes.addCppuMacrosHxx();
     463        7234 :     if (m_typeMgr->getSort(name_)
     464             :         == codemaker::UnoType::SORT_INTERFACE_TYPE)
     465             :     {
     466        3817 :         includes.addException();
     467        3817 :         includes.addReference();
     468             :     }
     469        7234 : }
     470             : 
     471        4850 : void CppuType::addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes)
     472             :     const
     473             : {
     474             :     //TODO: Only include what is really needed
     475        4850 :     includes.addRtlInstanceHxx();
     476        4850 :     includes.addOslMutexHxx();
     477        4850 :     includes.addType();
     478        4850 :     if (m_typeMgr->getSort(name_)
     479             :         == codemaker::UnoType::SORT_INTERFACE_TYPE)
     480             :     {
     481        3817 :         includes.addException();
     482        3817 :         includes.addReference();
     483             :     }
     484        4850 : }
     485             : 
     486        3268 : void CppuType::dumpInitializer(
     487             :     FileStream & out, bool parameterized, OUString const & name) const
     488             : {
     489        3268 :     out << "(";
     490        3268 :     if (!parameterized) {
     491             :         sal_Int32 k;
     492        3249 :         std::vector< OString > args;
     493             :         OUString n(
     494             :             b2u(codemaker::UnoType::decompose(
     495        6498 :                     u2b(resolveAllTypedefs(name)), &k, &args)));
     496        3249 :         if (k == 0) {
     497        3067 :             rtl::Reference< unoidl::Entity > ent;
     498        3067 :             switch (m_typeMgr->getSort(n, &ent)) {
     499             :             case codemaker::UnoType::SORT_BOOLEAN:
     500         288 :                 out << "false";
     501         288 :                 break;
     502             :             case codemaker::UnoType::SORT_BYTE:
     503             :             case codemaker::UnoType::SORT_SHORT:
     504             :             case codemaker::UnoType::SORT_UNSIGNED_SHORT:
     505             :             case codemaker::UnoType::SORT_LONG:
     506             :             case codemaker::UnoType::SORT_UNSIGNED_LONG:
     507             :             case codemaker::UnoType::SORT_HYPER:
     508             :             case codemaker::UnoType::SORT_UNSIGNED_HYPER:
     509             :             case codemaker::UnoType::SORT_FLOAT:
     510             :             case codemaker::UnoType::SORT_DOUBLE:
     511             :             case codemaker::UnoType::SORT_CHAR:
     512        1316 :                 out << "0";
     513        1316 :                 break;
     514             :             case codemaker::UnoType::SORT_ENUM_TYPE:
     515         258 :                 out << codemaker::cpp::scopedCppName(u2b(n)) << "_"
     516         129 :                     << (dynamic_cast< unoidl::EnumTypeEntity * >(ent.get())->
     517         258 :                         getMembers()[0].name);
     518         129 :                 break;
     519             :             case codemaker::UnoType::SORT_STRING:
     520             :             case codemaker::UnoType::SORT_TYPE:
     521             :             case codemaker::UnoType::SORT_ANY:
     522             :             case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     523             :             case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     524             :             case codemaker::UnoType::SORT_INTERFACE_TYPE:
     525        1334 :                 break;
     526             :             default:
     527             :                 throw CannotDumpException(
     528           0 :                     "unexpected entity \"" + name
     529           0 :                     + "\" in call to CppuType::dumpInitializer");
     530        3067 :             }
     531        3249 :         }
     532             :     }
     533        3268 :     out << ")";
     534        3268 : }
     535             : 
     536        5622 : void CppuType::dumpHFileContent(
     537             :     FileStream & out, codemaker::cppumaker::Includes & includes)
     538             : {
     539        5622 :     addDefaultHIncludes(includes);
     540        5622 :     dumpHeaderDefine(out, "HDL");
     541        5622 :     out << "\n";
     542        5622 :     includes.dump(out, 0);
     543             :     out << ("\nnamespace com { namespace sun { namespace star { namespace uno"
     544        5622 :             " { class Type; } } } }\n\n");
     545        5622 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
     546        5605 :         out << "\n";
     547             :     }
     548        5622 :     dumpDeclaration(out);
     549       11244 :     if (!(name_ == "com.sun.star.uno.XInterface"
     550        5619 :           || name_ == "com.sun.star.uno.Exception"
     551       11238 :           || isPolymorphic()))
     552             :     {
     553       11200 :         out << "\n" << indent()
     554             :             << ("inline ::css::uno::Type const &"
     555        5600 :                 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
     556        5600 :         dumpType(out, name_, false, false, true);
     557        5600 :         out << " const *);\n";
     558             :     }
     559        5622 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
     560        5605 :         out << "\n";
     561             :     }
     562        5622 :     out << "\n";
     563        5622 :     dumpTemplateHead(out);
     564        5622 :     out << "inline ::css::uno::Type const & SAL_CALL getCppuType(";
     565        5622 :     dumpType(out, name_, true);
     566        5622 :     dumpTemplateParameters(out);
     567        5622 :     out << " *) SAL_THROW(());\n\n#endif\n";
     568        5622 : }
     569             : 
     570        5622 : void CppuType::dumpGetCppuType(FileStream & out) {
     571        5622 :     if (name_ == "com.sun.star.uno.XInterface") {
     572           6 :         out << indent()
     573             :             << ("inline ::css::uno::Type const & SAL_CALL"
     574           3 :                 " getCppuType(SAL_UNUSED_PARAMETER ");
     575           3 :         dumpType(out, name_, true);
     576           3 :         out << " *) SAL_THROW(()) {\n";
     577           3 :         inc();
     578           6 :         out << indent()
     579             :             << ("return ::cppu::UnoType< ::css::uno::XInterface"
     580           3 :                 " >::get();\n");
     581           3 :         dec();
     582           3 :         out << indent() << "}\n";
     583        5619 :     } else if (name_ == "com.sun.star.uno.Exception") {
     584           6 :         out << indent()
     585             :             << ("inline ::css::uno::Type const & SAL_CALL"
     586           3 :                 " getCppuType(SAL_UNUSED_PARAMETER ");
     587           3 :         dumpType(out, name_, true);
     588           3 :         out << " *) SAL_THROW(()) {\n";
     589           3 :         inc();
     590           6 :         out << indent()
     591             :             << ("return ::cppu::UnoType< ::css::uno::Exception"
     592           3 :                 " >::get();\n");
     593           3 :         dec();
     594           3 :         out << indent() << "}\n";
     595        5616 :     } else if (m_cppuTypeLeak) {
     596        2652 :         dumpLightGetCppuType(out);
     597        2964 :     } else if (m_cppuTypeDynamic) {
     598         252 :         dumpNormalGetCppuType(out);
     599             :     } else {
     600        2712 :         dumpComprehensiveGetCppuType(out);
     601             :     }
     602        5622 : }
     603             : 
     604        2019 : void CppuType::dumpLightGetCppuType(FileStream & out) {
     605        2019 :     dumpGetCppuTypePreamble(out);
     606        4038 :     out << indent()
     607        2019 :         << "static typelib_TypeDescriptionReference * the_type = 0;\n"
     608        6057 :         << indent() << "if ( !the_type )\n" << indent() << "{\n";
     609        2019 :     inc();
     610        4038 :     out << indent() << "typelib_static_type_init( &the_type, "
     611        6057 :         << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n";
     612        2019 :     dec();
     613        4038 :     out << indent() << "}\n" << indent()
     614             :         << ("return * reinterpret_cast< ::css::uno::Type * >("
     615        2019 :             " &the_type );\n");
     616        2019 :     dumpGetCppuTypePostamble(out);
     617        2019 : }
     618             : 
     619        1074 : codemaker::cpp::IdentifierTranslationMode CppuType::isGlobal() const {
     620        1074 :     return name_.indexOf('.') == -1
     621        1074 :         ? codemaker::cpp::ITM_GLOBAL : codemaker::cpp::ITM_NONGLOBAL;
     622             : }
     623             : 
     624        2433 : sal_uInt32 CppuType::getInheritedMemberCount()
     625             : {
     626        2433 :     if (m_inheritedMemberCount == 0)
     627             :     {
     628        2081 :         m_inheritedMemberCount = checkInheritedMemberCount();
     629             :     }
     630             : 
     631        2433 :     return m_inheritedMemberCount;
     632             : }
     633             : 
     634       20262 : OUString CppuType::getTypeClass(OUString const & name, bool cStyle) {
     635       20262 :     rtl::Reference< unoidl::Entity > ent;
     636       20262 :     switch (m_typeMgr->getSort(name, &ent)) {
     637             :     case codemaker::UnoType::SORT_VOID:
     638             :         return cStyle
     639             :             ? OUString("typelib_TypeClass_VOID")
     640        2419 :             : OUString("::css::uno::TypeClass_VOID");
     641             :     case codemaker::UnoType::SORT_BOOLEAN:
     642             :         return cStyle
     643             :             ? OUString("typelib_TypeClass_BOOLEAN")
     644        1261 :             : OUString("::css::uno::TypeClass_BOOLEAN");
     645             :     case codemaker::UnoType::SORT_BYTE:
     646             :         return cStyle
     647             :             ? OUString("typelib_TypeClass_BYTE")
     648          68 :             : OUString("::css::uno::TypeClass_BYTE");
     649             :     case codemaker::UnoType::SORT_SHORT:
     650             :         return cStyle
     651             :             ? OUString("typelib_TypeClass_SHORT")
     652         547 :             : OUString("::css::uno::TypeClass_SHORT");
     653             :     case codemaker::UnoType::SORT_UNSIGNED_SHORT:
     654             :         return cStyle
     655             :             ? OUString("typelib_TypeClass_UNSIGNED_SHORT")
     656          38 :             : OUString("::css::uno::TypeClass_UNSIGNED_SHORT");
     657             :     case codemaker::UnoType::SORT_LONG:
     658             :         return cStyle
     659             :             ? OUString("typelib_TypeClass_LONG")
     660        1759 :             : OUString("::css::uno::TypeClass_LONG");
     661             :     case codemaker::UnoType::SORT_UNSIGNED_LONG:
     662             :         return cStyle
     663             :             ? OUString("typelib_TypeClass_UNSIGNED_LONG")
     664          40 :             : OUString("::css::uno::TypeClass_UNSIGNED_LONG");
     665             :     case codemaker::UnoType::SORT_HYPER:
     666             :         return cStyle
     667             :             ? OUString("typelib_TypeClass_HYPER")
     668          63 :             : OUString("::css::uno::TypeClass_HYPER");
     669             :     case codemaker::UnoType::SORT_UNSIGNED_HYPER:
     670             :         return cStyle
     671             :             ? OUString("typelib_TypeClass_UNSIGNED_HYPER")
     672           1 :             : OUString("::css::uno::TypeClass_UNSIGNED_HYPER");
     673             :     case codemaker::UnoType::SORT_FLOAT:
     674             :         return cStyle
     675             :             ? OUString("typelib_TypeClass_FLOAT")
     676          24 :             : OUString("::css::uno::TypeClass_FLOAT");
     677             :     case codemaker::UnoType::SORT_DOUBLE:
     678             :         return cStyle
     679             :             ? OUString("typelib_TypeClass_DOUBLE")
     680         372 :             : OUString("::css::uno::TypeClass_DOUBLE");
     681             :     case codemaker::UnoType::SORT_CHAR:
     682             :         return cStyle
     683             :             ? OUString("typelib_TypeClass_CHAR")
     684          19 :             : OUString("::css::uno::TypeClass_CHAR");
     685             :     case codemaker::UnoType::SORT_STRING:
     686             :         return cStyle
     687             :             ? OUString("typelib_TypeClass_STRING")
     688        2506 :             : OUString("::css::uno::TypeClass_STRING");
     689             :     case codemaker::UnoType::SORT_TYPE:
     690             :         return cStyle
     691             :             ? OUString("typelib_TypeClass_TYPE")
     692          36 :             : OUString("::css::uno::TypeClass_TYPE");
     693             :     case codemaker::UnoType::SORT_ANY:
     694             :         return cStyle
     695             :             ? OUString("typelib_TypeClass_ANY")
     696         483 :             : OUString("::css::uno::TypeClass_ANY");
     697             :     case codemaker::UnoType::SORT_SEQUENCE_TYPE:
     698             :         return cStyle
     699             :             ? OUString("typelib_TypeClass_SEQUENCE")
     700        1165 :             : OUString("::css::uno::TypeClass_SEQUENCE");
     701             :     case codemaker::UnoType::SORT_ENUM_TYPE:
     702             :         return cStyle
     703             :             ? OUString("typelib_TypeClass_ENUM")
     704         590 :             : OUString("::css::uno::TypeClass_ENUM");
     705             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     706             :     case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     707             :     case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
     708             :         return cStyle
     709             :             ? OUString("typelib_TypeClass_STRUCT")
     710        1888 :             : OUString("::css::uno::TypeClass_STRUCT");
     711             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     712             :         return cStyle
     713             :             ? OUString("typelib_TypeClass_EXCEPTION")
     714         812 :             : OUString("::css::uno::TypeClass_EXCEPTION");
     715             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
     716             :         return cStyle
     717             :             ? OUString("typelib_TypeClass_INTERFACE")
     718        6149 :             : OUString("::css::uno::TypeClass_INTERFACE");
     719             :     case codemaker::UnoType::SORT_TYPEDEF:
     720             :         return getTypeClass(
     721          22 :             dynamic_cast< unoidl::TypedefEntity * >(ent.get())->getType(),
     722          44 :             cStyle);
     723             :     default:
     724           0 :         for (;;) { std::abort(); }
     725       20262 :     }
     726             : }
     727             : 
     728       81244 : void CppuType::dumpType(
     729             :     FileStream & out, OUString const & name, bool isConst, bool isRef,
     730             :     bool native, bool cppuUnoType) const
     731             : {
     732             :     sal_Int32 k;
     733       81244 :     std::vector< OString > args;
     734             :     OUString n(
     735             :         b2u(codemaker::UnoType::decompose(
     736      162488 :                 u2b(resolveAllTypedefs(name)), &k, &args)));
     737       81244 :     if (isConst) {
     738       25639 :         out << "const ";
     739             :     }
     740       84495 :     for (sal_Int32 i = 0; i != k; ++i) {
     741             :         out << (cppuUnoType
     742        3251 :                 ? "::cppu::UnoSequenceType" : "::css::uno::Sequence")
     743        3251 :             << "< ";
     744             :     }
     745       81244 :     switch (m_typeMgr->getSort(n)) {
     746             :     case codemaker::UnoType::SORT_VOID:
     747        5089 :         out << "void";
     748        5089 :         break;
     749             :     case codemaker::UnoType::SORT_BOOLEAN:
     750        3627 :         out << "::sal_Bool";
     751        3627 :         break;
     752             :     case codemaker::UnoType::SORT_BYTE:
     753         568 :         out << "::sal_Int8";
     754         568 :         break;
     755             :     case codemaker::UnoType::SORT_SHORT:
     756        1876 :         out << "::sal_Int16";
     757        1876 :         break;
     758             :     case codemaker::UnoType::SORT_UNSIGNED_SHORT:
     759         222 :         out << (cppuUnoType ? "::cppu::UnoUnsignedShortType" : "::sal_uInt16");
     760         222 :         break;
     761             :     case codemaker::UnoType::SORT_LONG:
     762        5576 :         out << "::sal_Int32";
     763        5576 :         break;
     764             :     case codemaker::UnoType::SORT_UNSIGNED_LONG:
     765         168 :         out << "::sal_uInt32";
     766         168 :         break;
     767             :     case codemaker::UnoType::SORT_HYPER:
     768         250 :         out << "::sal_Int64";
     769         250 :         break;
     770             :     case codemaker::UnoType::SORT_UNSIGNED_HYPER:
     771          27 :         out << "::sal_uInt64";
     772          27 :         break;
     773             :     case codemaker::UnoType::SORT_FLOAT:
     774         189 :         out << "float";
     775         189 :         break;
     776             :     case codemaker::UnoType::SORT_DOUBLE:
     777        1309 :         out << "double";
     778        1309 :         break;
     779             :     case codemaker::UnoType::SORT_CHAR:
     780         124 :         out << (cppuUnoType ? "::cppu::UnoCharType" : "::sal_Unicode");
     781         124 :         break;
     782             :     case codemaker::UnoType::SORT_STRING:
     783        8875 :         out << "::rtl::OUString";
     784        8875 :         break;
     785             :     case codemaker::UnoType::SORT_TYPE:
     786         164 :         out << "::css::uno::Type";
     787         164 :         break;
     788             :     case codemaker::UnoType::SORT_ANY:
     789        2726 :         out << "::css::uno::Any";
     790        2726 :         break;
     791             :     case codemaker::UnoType::SORT_ENUM_TYPE:
     792             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     793             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     794       17601 :         out << codemaker::cpp::scopedCppName(u2b(n));
     795       17601 :         break;
     796             :     case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     797         226 :         out << codemaker::cpp::scopedCppName(u2b(n));
     798         226 :         if (!args.empty()) {
     799         162 :             out << "< ";
     800        1140 :             for (std::vector< OString >::iterator i(args.begin());
     801         760 :                  i != args.end(); ++i)
     802             :             {
     803         218 :                 if (i != args.begin()) {
     804          56 :                     out << ", ";
     805             :                 }
     806         218 :                 dumpType(out, b2u(*i));
     807             :             }
     808         162 :             out << " >";
     809             :         }
     810         226 :         break;
     811             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
     812       32627 :         if (!native) {
     813       24999 :             out << "::css::uno::Reference< ";
     814             :         }
     815       32627 :         out << codemaker::cpp::scopedCppName(u2b(n));
     816       32627 :         if (!native) {
     817       24999 :             out << " >";
     818             :         }
     819       32627 :         break;
     820             :     default:
     821             :         throw CannotDumpException(
     822           0 :             "unexpected entity \"" + name + "\" in call to CppuType::dumpType");
     823             :     }
     824       84495 :     for (sal_Int32 i = 0; i != k; ++i) {
     825        3251 :         out << " >";
     826             :     }
     827       81244 :     if (isRef) {
     828       20166 :         out << "&";
     829       81244 :     }
     830       81244 : }
     831             : 
     832        4805 : void CppuType::dumpCppuGetType(
     833             :     FileStream & out, OUString const & name, OUString const * ownName)
     834             : {
     835             :     //TODO: What are these calls good for?
     836        4805 :     OUString nucleus;
     837             :     sal_Int32 rank;
     838             :     codemaker::UnoType::Sort sort = m_typeMgr->decompose(
     839        4805 :         name, true, &nucleus, &rank, 0, 0);
     840        4805 :     switch (rank == 0 ? sort : codemaker::UnoType::SORT_SEQUENCE_TYPE) {
     841             :     case codemaker::UnoType::SORT_VOID:
     842             :     case codemaker::UnoType::SORT_BOOLEAN:
     843             :     case codemaker::UnoType::SORT_BYTE:
     844             :     case codemaker::UnoType::SORT_SHORT:
     845             :     case codemaker::UnoType::SORT_UNSIGNED_SHORT:
     846             :     case codemaker::UnoType::SORT_LONG:
     847             :     case codemaker::UnoType::SORT_UNSIGNED_LONG:
     848             :     case codemaker::UnoType::SORT_HYPER:
     849             :     case codemaker::UnoType::SORT_UNSIGNED_HYPER:
     850             :     case codemaker::UnoType::SORT_FLOAT:
     851             :     case codemaker::UnoType::SORT_DOUBLE:
     852             :     case codemaker::UnoType::SORT_CHAR:
     853             :     case codemaker::UnoType::SORT_STRING:
     854             :     case codemaker::UnoType::SORT_TYPE:
     855             :     case codemaker::UnoType::SORT_ANY:
     856         888 :         break;
     857             :     case codemaker::UnoType::SORT_SEQUENCE_TYPE:
     858             :     case codemaker::UnoType::SORT_ENUM_TYPE:
     859             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     860             :     case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
     861             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     862             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
     863             :         // Take care of recursion like struct S { sequence<S> x; }:
     864        3917 :         if (ownName == 0 || nucleus != *ownName) {
     865        3916 :             out << indent() << "::cppu::UnoType< ";
     866        3916 :             dumpType(out, name, false, false, false, true);
     867        3916 :             out << " >::get();\n";
     868             :         }
     869        3917 :         break;
     870             :     case codemaker::UnoType::SORT_TYPEDEF:
     871             :         assert(false); // this cannot happen
     872             :         // fall through
     873             :     default:
     874             :         throw CannotDumpException(
     875           0 :             "unexpected entity \"" + name
     876           0 :             + "\" in call to CppuType::dumpCppuGetType");
     877        4805 :     }
     878        4805 : }
     879             : 
     880       14969 : bool CppuType::passByReference(OUString const & name) const {
     881       14969 :     switch (m_typeMgr->getSort(resolveOuterTypedefs(name))) {
     882             :     case codemaker::UnoType::SORT_BOOLEAN:
     883             :     case codemaker::UnoType::SORT_BYTE:
     884             :     case codemaker::UnoType::SORT_SHORT:
     885             :     case codemaker::UnoType::SORT_UNSIGNED_SHORT:
     886             :     case codemaker::UnoType::SORT_LONG:
     887             :     case codemaker::UnoType::SORT_UNSIGNED_LONG:
     888             :     case codemaker::UnoType::SORT_HYPER:
     889             :     case codemaker::UnoType::SORT_UNSIGNED_HYPER:
     890             :     case codemaker::UnoType::SORT_FLOAT:
     891             :     case codemaker::UnoType::SORT_DOUBLE:
     892             :     case codemaker::UnoType::SORT_CHAR:
     893             :     case codemaker::UnoType::SORT_ENUM_TYPE:
     894        4871 :         return false;
     895             :     case codemaker::UnoType::SORT_STRING:
     896             :     case codemaker::UnoType::SORT_TYPE:
     897             :     case codemaker::UnoType::SORT_ANY:
     898             :     case codemaker::UnoType::SORT_SEQUENCE_TYPE:
     899             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     900             :     case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
     901             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
     902       10098 :         return true;
     903             :     default:
     904             :         throw CannotDumpException(
     905           0 :             "unexpected entity \"" + name
     906           0 :             + "\" in call to CppuType::passByReference");
     907             :     }
     908             : }
     909             : 
     910       14969 : OUString CppuType::resolveOuterTypedefs(OUString const & name) const {
     911       14969 :     for (OUString n(name);;) {
     912       15156 :         rtl::Reference< unoidl::Entity > ent;
     913       15156 :         if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) {
     914       29938 :             return n;
     915             :         }
     916         187 :         n = dynamic_cast< unoidl::TypedefEntity * >(ent.get())->getType();
     917         187 :     }
     918             : }
     919             : 
     920       98494 : OUString CppuType::resolveAllTypedefs(OUString const & name) const {
     921             :     sal_Int32 k1;
     922       98494 :     OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k1)));
     923             :     for (;;) {
     924       99289 :         rtl::Reference< unoidl::Entity > ent;
     925       99289 :         if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) {
     926       98494 :             break;
     927             :         }
     928             :         sal_Int32 k2;
     929        1590 :         n = b2u(
     930             :             codemaker::UnoType::decompose(
     931         795 :                 u2b(dynamic_cast< unoidl::TypedefEntity * >(ent.get())->
     932             :                     getType()),
     933         795 :                 &k2));
     934         795 :         k1 += k2; //TODO: overflow
     935         795 :     }
     936      196988 :     OUStringBuffer b;
     937      103174 :     for (sal_Int32 i = 0; i != k1; ++i) {
     938        4680 :         b.append("[]");
     939             :     }
     940       98494 :     b.append(n);
     941      196988 :     return b.makeStringAndClear();
     942             : }
     943             : 
     944       70971 : void CppuType::inc(sal_Int32 num)
     945             : {
     946       70971 :     m_indentLength += num;
     947       70971 : }
     948             : 
     949       70955 : void CppuType::dec(sal_Int32 num)
     950             : {
     951       70955 :     m_indentLength = std::max< sal_Int32 >(m_indentLength - num, 0);
     952       70955 : }
     953             : 
     954      384586 : OUString CppuType::indent() const {
     955      384586 :     OUStringBuffer buf(m_indentLength);
     956     4627454 :     for (sal_Int32 i = 0; i != m_indentLength; ++i) {
     957     4242868 :         buf.append(' ');
     958             :     }
     959      384586 :     return buf.makeStringAndClear();
     960             : }
     961             : 
     962       17378 : bool isDeprecated(std::vector< OUString > const & annotations) {
     963       52134 :     for (std::vector< OUString >::const_iterator i(annotations.begin());
     964       34756 :          i != annotations.end(); ++i)
     965             :     {
     966         245 :         if (*i == "deprecated") {
     967         245 :             return true;
     968             :         }
     969             :     }
     970       17133 :     return false;
     971             : }
     972             : 
     973       15599 : void dumpDeprecation(FileStream & out, bool deprecated) {
     974       15599 :     if (deprecated) {
     975         702 :         out << "SAL_DEPRECATED_INTERNAL(\"marked @deprecated in UNOIDL\") ";
     976             :     }
     977       15599 : }
     978             : 
     979        1729 : class BaseOffset: private boost::noncopyable {
     980             : public:
     981        1729 :     BaseOffset(
     982             :         rtl::Reference< TypeManager > const & manager,
     983             :         rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
     984        1729 :         manager_(manager), offset_(0) { calculateBases(entity); }
     985             : 
     986        1729 :     sal_Int32 get() const { return offset_; }
     987             : 
     988             : private:
     989             :     void calculateBases(
     990             :         rtl::Reference< unoidl::InterfaceTypeEntity > const & entity);
     991             : 
     992             :     rtl::Reference< TypeManager > manager_;
     993             :     std::set< OUString > set_;
     994             :     sal_Int32 offset_;
     995             : };
     996             : 
     997        4448 : void BaseOffset::calculateBases(
     998             :     rtl::Reference< unoidl::InterfaceTypeEntity > const & entity)
     999             : {
    1000             :     assert(entity.is());
    1001       21975 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
    1002        4448 :              entity->getDirectMandatoryBases().begin());
    1003       14650 :          i != entity->getDirectMandatoryBases().end(); ++i)
    1004             :     {
    1005        2877 :         if (set_.insert(i->name).second) {
    1006        2719 :             rtl::Reference< unoidl::Entity > ent;
    1007        2719 :             codemaker::UnoType::Sort sort = manager_->getSort(i->name, &ent);
    1008        2719 :             if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE) {
    1009             :                 throw CannotDumpException(
    1010           0 :                     "interface type base " + i->name
    1011           0 :                     + " is not an interface type");
    1012             :             }
    1013             :             rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
    1014        5438 :                 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
    1015             :             assert(ent2.is());
    1016        2719 :             calculateBases(ent2);
    1017        2719 :             offset_ += ent2->getDirectAttributes().size()
    1018        5438 :                 + ent2->getDirectMethods().size(); //TODO: overflow
    1019             :         }
    1020             :     }
    1021        4448 : }
    1022             : 
    1023        3817 : class InterfaceType: public CppuType {
    1024             : public:
    1025             :     InterfaceType(
    1026             :         rtl::Reference< unoidl::InterfaceTypeEntity > const & entity,
    1027             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr);
    1028             : 
    1029             :     virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
    1030             :     void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    1031             : 
    1032             :     void        dumpAttributes(FileStream& o);
    1033             :     void        dumpMethods(FileStream& o);
    1034             :     void        dumpNormalGetCppuType(FileStream& o) SAL_OVERRIDE;
    1035             :     void        dumpComprehensiveGetCppuType(FileStream& o) SAL_OVERRIDE;
    1036             :     void        dumpCppuAttributeRefs(FileStream& o, sal_uInt32& index);
    1037             :     void        dumpCppuMethodRefs(FileStream& o, sal_uInt32& index);
    1038             :     void        dumpCppuAttributes(FileStream& o, sal_uInt32& index);
    1039             :     void        dumpCppuMethods(FileStream& o, sal_uInt32& index);
    1040             :     void dumpAttributesCppuDecl(FileStream & out, std::set< OUString > * seen);
    1041             :     void dumpMethodsCppuDecl(FileStream & out, std::set< OUString > * seen);
    1042             : 
    1043             : protected:
    1044             :     virtual void addComprehensiveGetCppuTypeIncludes(
    1045             :         codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
    1046             : 
    1047        1729 :     virtual sal_uInt32 checkInheritedMemberCount() const SAL_OVERRIDE
    1048        1729 :     { return BaseOffset(m_typeMgr, entity_).get(); }
    1049             : 
    1050             :     sal_uInt32  m_inheritedMemberCount;
    1051             :     bool        m_isDeprecated;
    1052             : 
    1053             : private:
    1054             :     void dumpExceptionSpecification(
    1055             :         FileStream & out, std::vector< OUString > const & exceptions,
    1056             :         bool runtimeException);
    1057             : 
    1058             :     void dumpExceptionTypeName(
    1059             :         FileStream & out, OUString const & prefix, sal_uInt32 index,
    1060             :         OUString const & name);
    1061             : 
    1062             :     sal_Int32 dumpExceptionTypeNames(
    1063             :         FileStream & out, OUString const & prefix,
    1064             :         std::vector< OUString > const & exceptions, bool runtimeException);
    1065             : 
    1066             :     rtl::Reference< unoidl::InterfaceTypeEntity > entity_;
    1067             : };
    1068             : 
    1069        3817 : InterfaceType::InterfaceType(
    1070             :     rtl::Reference< unoidl::InterfaceTypeEntity > const & entity,
    1071             :     OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    1072        3817 :     CppuType(name, typeMgr), entity_(entity)
    1073             : {
    1074             :     assert(entity.is());
    1075        3817 :     m_inheritedMemberCount = 0;
    1076        3817 :     m_isDeprecated = isDeprecated(entity->getAnnotations());
    1077        3817 : }
    1078             : 
    1079        3817 : void InterfaceType::dumpDeclaration(FileStream & out) {
    1080        3817 :     out << "\nclass SAL_NO_VTABLE " << id_;
    1081       24366 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
    1082        3817 :              entity_->getDirectMandatoryBases().begin());
    1083       16244 :          i != entity_->getDirectMandatoryBases().end(); ++i)
    1084             :     {
    1085        8610 :         out << (i == entity_->getDirectMandatoryBases().begin() ? " :" : ",")
    1086       12915 :             << " public " << codemaker::cpp::scopedCppName(u2b(i->name));
    1087             :     }
    1088        3817 :     out << "\n{\npublic:\n";
    1089        3817 :     inc();
    1090        3817 :     dumpAttributes(out);
    1091        3817 :     dumpMethods(out);
    1092        7634 :     out << "\n" << indent()
    1093             :         << ("static inline ::css::uno::Type const & SAL_CALL"
    1094        3817 :             " static_type(void * = 0);\n\n");
    1095        3817 :     dec();
    1096        3817 :     out << "protected:\n";
    1097        3817 :     inc();
    1098        7634 :     out << indent() << "~" << id_
    1099             :         << ("() throw () {} // avoid warnings about virtual members and"
    1100        3817 :             " non-virtual dtor\n");
    1101        3817 :     dec();
    1102        3817 :     out << "};\n\n";
    1103        3817 : }
    1104             : 
    1105        3817 : void InterfaceType::dumpHxxFile(
    1106             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    1107             : {
    1108        3817 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    1109        3817 :     out << "\n";
    1110        3817 :     addDefaultHxxIncludes(includes);
    1111        3817 :     includes.dump(out, &name_);
    1112        3817 :     out << "\n";
    1113        3817 :     dumpGetCppuType(out);
    1114        3817 :     out << "\n::css::uno::Type const & "
    1115       11451 :         << codemaker::cpp::scopedCppName(u2b(name_))
    1116        3817 :         << "::static_type(SAL_UNUSED_PARAMETER void *) {\n";
    1117        3817 :     inc();
    1118        3817 :     out << indent() << "return ::getCppuType(static_cast< ";
    1119        3817 :     dumpType(out, name_);
    1120        3817 :     out << " * >(0));\n";
    1121        3817 :     dec();
    1122        3817 :     out << "}\n\n#endif // "<< headerDefine << "\n";
    1123        3817 : }
    1124             : 
    1125        3817 : void InterfaceType::dumpAttributes(FileStream & out) {
    1126        3817 :     if (!entity_->getDirectAttributes().empty()) {
    1127         342 :         out << "\n" << indent() << "// Attributes\n";
    1128             :     }
    1129       16821 :     for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
    1130        3817 :              i(entity_->getDirectAttributes().begin());
    1131       11214 :          i != entity_->getDirectAttributes().end(); ++i)
    1132             :     {
    1133        1790 :         bool depr = m_isDeprecated || isDeprecated(i->annotations);
    1134        1790 :         out << indent();
    1135        1790 :         dumpDeprecation(out, depr);
    1136        1790 :         out << "virtual ";
    1137        1790 :         dumpType(out, i->type);
    1138        1790 :         out << " SAL_CALL get" << i->name << "()";
    1139        1790 :         dumpExceptionSpecification(out, i->getExceptions, true);
    1140        1790 :         out << " = 0;\n";
    1141        1790 :         if (!i->readOnly) {
    1142        1377 :             bool byRef = passByReference(i->type);
    1143        1377 :             out << indent();
    1144        1377 :             dumpDeprecation(out, depr);
    1145        1377 :             out << "virtual void SAL_CALL set" << i->name << "( ";
    1146        1377 :             dumpType(out, i->type, byRef, byRef);
    1147        1377 :             out << " _" << i->name.toAsciiLowerCase() << " )";
    1148        1377 :             dumpExceptionSpecification(out, i->setExceptions, true);
    1149        1377 :             out << " = 0;\n";
    1150             :         }
    1151             :     }
    1152        3817 : }
    1153             : 
    1154        3817 : void InterfaceType::dumpMethods(FileStream & out) {
    1155        3817 :     if (!entity_->getDirectMethods().empty()) {
    1156        3436 :         out << "\n" << indent() << "// Methods\n";
    1157             :     }
    1158       48747 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
    1159        3817 :              entity_->getDirectMethods().begin());
    1160       32498 :          i != entity_->getDirectMethods().end(); ++i)
    1161             :     {
    1162       12432 :         out << indent();
    1163       12432 :         dumpDeprecation(out, m_isDeprecated || isDeprecated(i->annotations));
    1164       12432 :         out << "virtual ";
    1165       12432 :         dumpType(out, i->returnType);
    1166       12432 :         out << " SAL_CALL " << i->name << "(";
    1167       12432 :         if (i->parameters.empty()) {
    1168        4576 :             out << ")";
    1169             :         } else {
    1170        7856 :             out << " ";
    1171       49866 :             for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
    1172        7856 :                      const_iterator j(i->parameters.begin());
    1173       42010 :                  j != i->parameters.end();)
    1174             :             {
    1175             :                 bool isConst;
    1176             :                 bool isRef;
    1177       26298 :                 if (j->direction
    1178       13149 :                     == (unoidl::InterfaceTypeEntity::Method::Parameter::
    1179             :                         DIRECTION_IN))
    1180             :                 {
    1181       12904 :                     isConst = passByReference(j->type);
    1182       12904 :                     isRef = isConst;
    1183             :                 } else {
    1184         245 :                     isConst = false;
    1185         245 :                     isRef = true;
    1186             :                 }
    1187       13149 :                 dumpType(out, j->type, isConst, isRef);
    1188       13149 :                 out << " " << j->name;
    1189       13149 :                 ++j;
    1190       13149 :                 if (j != i->parameters.end()) {
    1191        5293 :                     out << ", ";
    1192             :                 }
    1193             :             }
    1194        7856 :             out << " )";
    1195             :         }
    1196             :         dumpExceptionSpecification(
    1197       12432 :             out, i->exceptions, i->name != "acquire" && i->name != "release");
    1198       12432 :         out << " = 0;\n";
    1199             :     }
    1200        3817 : }
    1201             : 
    1202         159 : void InterfaceType::dumpNormalGetCppuType(FileStream & out) {
    1203         159 :     dumpGetCppuTypePreamble(out);
    1204         318 :     out << indent()
    1205         159 :         << "static typelib_TypeDescriptionReference * the_type = 0;\n"
    1206         477 :         << indent() << "if ( !the_type )\n" << indent() << "{\n";
    1207         159 :     inc();
    1208             :     std::vector< unoidl::AnnotatedReference >::size_type bases(
    1209         159 :         entity_->getDirectMandatoryBases().size());
    1210         159 :     if (bases == 1
    1211         309 :         && (entity_->getDirectMandatoryBases()[0].name
    1212         150 :             == "com.sun.star.uno.XInterface"))
    1213             :     {
    1214         102 :         bases = 0;
    1215             :     }
    1216         159 :     if (bases != 0) {
    1217         114 :         out << indent() << "typelib_TypeDescriptionReference * aSuperTypes["
    1218         114 :             << entity_->getDirectMandatoryBases().size() << "];\n";
    1219          57 :         std::vector< unoidl::AnnotatedReference >::size_type n = 0;
    1220         372 :         for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
    1221          57 :                  entity_->getDirectMandatoryBases().begin());
    1222         248 :              i != entity_->getDirectMandatoryBases().end(); ++i)
    1223             :         {
    1224          67 :             out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< ";
    1225          67 :             dumpType(out, i->name, true, false, false, true);
    1226          67 :             out << " >::get().getTypeLibType();\n";
    1227             :         }
    1228             :     }
    1229         318 :     out << indent() << "typelib_static_mi_interface_type_init( &the_type, \""
    1230         318 :         << name_ << "\", " << bases << ", "
    1231         318 :         << (bases == 0 ? "0" : "aSuperTypes") << " );\n";
    1232         159 :     dec();
    1233         318 :     out << indent() << "}\n" << indent()
    1234             :         << ("return * reinterpret_cast< ::css::uno::Type * >("
    1235         159 :             " &the_type );\n");
    1236         159 :     dumpGetCppuTypePostamble(out);
    1237         159 : }
    1238             : 
    1239        1822 : void InterfaceType::dumpComprehensiveGetCppuType(FileStream & out) {
    1240        1822 :     codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
    1241        1822 :     OUString staticTypeClass("the" + id_ + "Type");
    1242        3644 :     out << " namespace detail {\n\n" << indent() << "struct " << staticTypeClass
    1243        1822 :         << " : public rtl::StaticWithInit< ::css::uno::Type *, "
    1244        5466 :         << staticTypeClass << " >\n" << indent() << "{\n";
    1245        1822 :     inc();
    1246        3644 :     out << indent() << "::css::uno::Type * operator()() const\n"
    1247        5466 :         << indent() << "{\n";
    1248        1822 :     inc();
    1249        3644 :     out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n"
    1250        5466 :         << indent() << "// Start inline typedescription generation\n"
    1251        5466 :         << indent() << "typelib_InterfaceTypeDescription * pTD = 0;\n\n";
    1252        3644 :     out << indent() << "typelib_TypeDescriptionReference * aSuperTypes["
    1253        3644 :         << entity_->getDirectMandatoryBases().size() << "];\n";
    1254        1822 :     std::vector< unoidl::AnnotatedReference >::size_type n = 0;
    1255       11616 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
    1256        1822 :              entity_->getDirectMandatoryBases().begin());
    1257        7744 :          i != entity_->getDirectMandatoryBases().end(); ++i)
    1258             :     {
    1259        2050 :         out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< ";
    1260        2050 :         dumpType(out, i->name, false, false, false, true);
    1261        2050 :         out << " >::get().getTypeLibType();\n";
    1262             :     }
    1263        1822 :     std::size_t count = entity_->getDirectAttributes().size()
    1264        1822 :         + entity_->getDirectMethods().size(); //TODO: overflow
    1265        1822 :     if (count != 0) {
    1266        3458 :         out << indent() << "typelib_TypeDescriptionReference * pMembers["
    1267        1729 :             << count << "] = { ";
    1268        8373 :         for (std::size_t i = 0; i != count; ++i) {
    1269        6644 :             out << "0";
    1270        6644 :             if (i + 1 != count) {
    1271        4915 :                 out << ",";
    1272             :             }
    1273             :         }
    1274        1729 :         out << " };\n";
    1275        1729 :         sal_uInt32 index = 0;
    1276        1729 :         dumpCppuAttributeRefs(out, index);
    1277        1729 :         dumpCppuMethodRefs(out, index);
    1278             :     }
    1279        1822 :     out << "\n" << indent() << "typelib_typedescription_newMIInterface(\n";
    1280        1822 :     inc();
    1281        3644 :     out << indent() << "&pTD,\n" << indent()
    1282        5466 :         << "sTypeName.pData, 0, 0, 0, 0, 0,\n" << indent()
    1283        3644 :         << entity_->getDirectMandatoryBases().size() << ", aSuperTypes,\n"
    1284        5466 :         << indent() << count << ",\n" << indent()
    1285        3644 :         << (count == 0 ? "0" : "pMembers") << " );\n\n";
    1286        1822 :     dec();
    1287        3644 :     out << indent()
    1288             :         << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
    1289        1822 :           " );\n");
    1290        8466 :     for (std::size_t i = 0; i != count; ++i) {
    1291       13288 :         out << indent() << "typelib_typedescriptionreference_release( pMembers["
    1292        6644 :             << i << "] );\n";
    1293             :     }
    1294        3644 :     out << indent()
    1295             :         << ("typelib_typedescription_release( (typelib_TypeDescription*)pTD"
    1296        1822 :             " );\n\n")
    1297        5466 :         << indent() << "return new ::css::uno::Type( "
    1298        5466 :         << getTypeClass(name_) << ", sTypeName ); // leaked\n";
    1299        1822 :     dec();
    1300        1822 :     out << indent() << "}\n";
    1301        1822 :     dec();
    1302        1822 :     out << indent() << "};\n\n";
    1303        1822 :     codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
    1304        1822 :     out << " }\n\n";
    1305        1822 :     dumpGetCppuTypePreamble(out);
    1306        3644 :     out << indent() << "const ::css::uno::Type &rRet = *detail::"
    1307        5466 :         << staticTypeClass << "::get();\n" << indent()
    1308        5466 :         << "// End inline typedescription generation\n" << indent()
    1309        5466 :         << "static bool bInitStarted = false;\n" << indent()
    1310        5466 :         << "if (!bInitStarted)\n" << indent() << "{\n";
    1311        1822 :     inc();
    1312        3644 :     out << indent()
    1313        1822 :         << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n"
    1314        5466 :         << indent() << "if (!bInitStarted)\n" << indent() << "{\n";
    1315        1822 :     inc();
    1316        3644 :     out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"
    1317        5466 :         << indent() << "bInitStarted = true;\n";
    1318        3644 :     std::set< OUString > seen;
    1319             :     // Type for RuntimeException is always needed:
    1320        1822 :     seen.insert("com.sun.star.uno.RuntimeException");
    1321        1822 :     dumpCppuGetType(out, "com.sun.star.uno.RuntimeException");
    1322        1822 :     dumpAttributesCppuDecl(out, &seen);
    1323        1822 :     dumpMethodsCppuDecl(out, &seen);
    1324        1822 :     if (count != 0) {
    1325        1729 :         sal_uInt32 index = getInheritedMemberCount();
    1326        1729 :         dumpCppuAttributes(out, index);
    1327        1729 :         dumpCppuMethods(out, index);
    1328             :     }
    1329        1822 :     dec();
    1330        1822 :     out << indent() << "}\n";
    1331        1822 :     dec();
    1332        1822 :     out << indent() << "}\n" << indent() << "else\n" << indent() << "{\n";
    1333        1822 :     inc();
    1334        1822 :     out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n";
    1335        1822 :     dec();
    1336        1822 :     out << indent() << "}\n" << indent() << "return rRet;\n";
    1337        3644 :     dumpGetCppuTypePostamble(out);
    1338        1822 : }
    1339             : 
    1340        1729 : void InterfaceType::dumpCppuAttributeRefs(FileStream & out, sal_uInt32 & index)
    1341             : {
    1342        1729 :     std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0;
    1343        6981 :     for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
    1344        1729 :              i(entity_->getDirectAttributes().begin());
    1345        4654 :          i != entity_->getDirectAttributes().end(); ++i)
    1346             :     {
    1347        1196 :         out << indent() << "::rtl::OUString sAttributeName" << n << "( \""
    1348        1794 :             << name_ << "::" << i->name << "\" );\n" << indent()
    1349        1196 :             << "typelib_typedescriptionreference_new( &pMembers[" << index++
    1350         598 :             << "],\n";
    1351         598 :         inc(38);
    1352        1196 :         out << indent()
    1353         598 :             << ("(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_ATTRIBUTE,\n")
    1354        1794 :             << indent() << "sAttributeName" << n << ".pData );\n";
    1355         598 :         dec(38);
    1356         598 :         ++n;
    1357             :     }
    1358        1729 : }
    1359             : 
    1360        1729 : void InterfaceType::dumpCppuMethodRefs(FileStream & out, sal_uInt32 & index) {
    1361        1729 :     std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0;
    1362       23325 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
    1363        1729 :              entity_->getDirectMethods().begin());
    1364       15550 :          i != entity_->getDirectMethods().end(); ++i)
    1365             :     {
    1366       12092 :         out << indent() << "::rtl::OUString sMethodName" << n << "( \"" << name_
    1367       18138 :             << "::" << i->name << "\" );\n" << indent()
    1368       12092 :             << "typelib_typedescriptionreference_new( &pMembers[" << index++
    1369        6046 :             << "],\n";
    1370        6046 :         inc(38);
    1371       12092 :         out << indent()
    1372        6046 :             << ("(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_METHOD,\n")
    1373       18138 :             << indent() << "sMethodName" << n << ".pData );\n";
    1374        6046 :         dec(38);
    1375        6046 :         ++n;
    1376             :     }
    1377        1729 : }
    1378             : 
    1379        1822 : void InterfaceType::addComprehensiveGetCppuTypeIncludes(
    1380             :     codemaker::cppumaker::Includes & includes) const
    1381             : {
    1382             :     // The comprehensive getCppuType method always includes a line
    1383             :     // "getCppuType( (const ::css::uno::RuntimeException*)0 );":
    1384        1822 :     includes.addCppuUnotypeHxx();
    1385        1822 :     includes.add("com.sun.star.uno.RuntimeException");
    1386        1822 : }
    1387             : 
    1388        1729 : void InterfaceType::dumpCppuAttributes(FileStream & out, sal_uInt32 & index) {
    1389        1729 :     if (!entity_->getDirectAttributes().empty()) {
    1390         232 :         out << "\n" << indent()
    1391         116 :             << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n";
    1392         116 :         std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0;
    1393        2142 :         for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::
    1394         116 :                  const_iterator i(entity_->getDirectAttributes().begin());
    1395        1428 :              i != entity_->getDirectAttributes().end(); ++i)
    1396             :         {
    1397         598 :             OUString type(resolveAllTypedefs(i->type));
    1398         598 :             out << indent() << "{\n";
    1399         598 :             inc();
    1400        1196 :             out << indent() << "::rtl::OUString sAttributeType" << n << "( \""
    1401        1794 :                 << type << "\" );\n" << indent()
    1402        1196 :                 << "::rtl::OUString sAttributeName" << n << "( \"" << name_
    1403        1196 :                 << "::" << i->name << "\" );\n";
    1404             :             sal_Int32 getExcn = dumpExceptionTypeNames(
    1405         598 :                 out, "get", i->getExceptions, false);
    1406             :             sal_Int32 setExcn = dumpExceptionTypeNames(
    1407         598 :                 out, "set", i->setExceptions, false);
    1408        1196 :             out << indent()
    1409             :                 << ("typelib_typedescription_newExtendedInterfaceAttribute("
    1410         598 :                     " &pAttribute,\n");
    1411         598 :             inc();
    1412        1196 :             out << indent() << index++ << ", sAttributeName" << n
    1413        1794 :                 << ".pData,\n" << indent() << "(typelib_TypeClass)"
    1414        1794 :                 << getTypeClass(type) << ", sAttributeType" << n << ".pData,\n"
    1415        1794 :                 << indent() << "sal_" << (i->readOnly ? "True" : "False")
    1416        1196 :                 << ", " << getExcn << ", "
    1417        1196 :                 << (getExcn == 0 ? "0" : "the_getExceptions") << ", " << setExcn
    1418        1196 :                 << ", " << (setExcn == 0 ? "0" : "the_setExceptions")
    1419         598 :                 << " );\n";
    1420         598 :             dec();
    1421        1196 :             out << indent()
    1422             :                 << ("typelib_typedescription_register("
    1423         598 :                     " (typelib_TypeDescription**)&pAttribute );\n");
    1424         598 :             dec();
    1425         598 :             out << indent() << "}\n";
    1426         598 :             ++n;
    1427         598 :         }
    1428         232 :         out << indent()
    1429             :             << ("typelib_typedescription_release("
    1430         116 :                 " (typelib_TypeDescription*)pAttribute );\n");
    1431             :     }
    1432        1729 : }
    1433             : 
    1434        1729 : void InterfaceType::dumpCppuMethods(FileStream & out, sal_uInt32 & index) {
    1435        1729 :     if (!entity_->getDirectMethods().empty()) {
    1436        3350 :         out << "\n" << indent()
    1437        1675 :             << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n";
    1438        1675 :         std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0;
    1439       23163 :         for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator
    1440        1675 :                  i(entity_->getDirectMethods().begin());
    1441       15442 :              i != entity_->getDirectMethods().end(); ++i)
    1442             :         {
    1443        6046 :             OUString returnType(resolveAllTypedefs(i->returnType));
    1444        6046 :             out << indent() << "{\n";
    1445        6046 :             inc();
    1446        6046 :             if (!i->parameters.empty()) {
    1447        7634 :                 out << indent() << "typelib_Parameter_Init aParameters["
    1448        7634 :                     << i->parameters.size() << "];\n";
    1449             :             }
    1450             :             std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
    1451        6046 :                 size_type m = 0;
    1452       37038 :             for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
    1453        6046 :                      const_iterator j(i->parameters.begin());
    1454       24692 :                  j != i->parameters.end(); ++j)
    1455             :             {
    1456        6300 :                 OUString type(resolveAllTypedefs(j->type));
    1457       12600 :                 out << indent() << "::rtl::OUString sParamName" << m << "( \""
    1458       18900 :                     << j->name << "\" );\n" << indent()
    1459        6300 :                     << "::rtl::OUString sParamType" << m << "( \"" << type
    1460       18900 :                     << "\" );\n" << indent() << "aParameters[" << m
    1461        6300 :                     << "].pParamName = sParamName" << m << ".pData;\n"
    1462       18900 :                     << indent() << "aParameters[" << m
    1463        6300 :                     << "].eTypeClass = (typelib_TypeClass)"
    1464       18900 :                     << getTypeClass(type) << ";\n" << indent() << "aParameters["
    1465        6300 :                     << m << "].pTypeName = sParamType" << m << ".pData;\n"
    1466       18900 :                     << indent() << "aParameters[" << m << "].bIn = "
    1467        6300 :                     << ((j->direction
    1468        6300 :                          == (unoidl::InterfaceTypeEntity::Method::Parameter::
    1469             :                              DIRECTION_OUT))
    1470       12600 :                         ? "sal_False" : "sal_True")
    1471       18900 :                     << ";\n" << indent() << "aParameters[" << m << "].bOut = "
    1472        6300 :                     << ((j->direction
    1473        6300 :                          == (unoidl::InterfaceTypeEntity::Method::Parameter::
    1474             :                              DIRECTION_IN))
    1475       12600 :                         ? "sal_False" : "sal_True")
    1476        6300 :                     << ";\n";
    1477        6300 :                 ++m;
    1478        6300 :             }
    1479             :             sal_Int32 excn = dumpExceptionTypeNames(
    1480        6046 :                 out, "", i->exceptions,
    1481       12092 :                 i->name != "acquire" && i->name != "release");
    1482       12092 :             out << indent() << "::rtl::OUString sReturnType" << n << "( \""
    1483       18138 :                 << returnType << "\" );\n" << indent()
    1484       12092 :                 << "::rtl::OUString sMethodName" << n << "( \"" << name_ << "::"
    1485       18138 :                 << i->name << "\" );\n" << indent()
    1486        6046 :                 << "typelib_typedescription_newInterfaceMethod( &pMethod,\n";
    1487        6046 :             inc();
    1488       12092 :             out << indent() << index++ << ", sal_False,\n" << indent()
    1489       18138 :                 << "sMethodName" << n << ".pData,\n" << indent()
    1490       18138 :                 << "(typelib_TypeClass)" << getTypeClass(returnType)
    1491       18138 :                 << ", sReturnType" << n << ".pData,\n" << indent()
    1492       12092 :                 << i->parameters.size() << ", "
    1493       12092 :                 << (i->parameters.empty() ? "0" : "aParameters") << ",\n"
    1494       18138 :                 << indent() << excn << ", "
    1495       12092 :                 << (excn == 0 ? "0" : "the_Exceptions") << " );\n";
    1496        6046 :             dec();
    1497       12092 :             out << indent()
    1498             :                 << ("typelib_typedescription_register("
    1499        6046 :                     " (typelib_TypeDescription**)&pMethod );\n");
    1500        6046 :             dec();
    1501        6046 :             out << indent() << "}\n";
    1502        6046 :             ++n;
    1503        6046 :         }
    1504        3350 :         out << indent()
    1505             :             << ("typelib_typedescription_release("
    1506        1675 :                 " (typelib_TypeDescription*)pMethod );\n");
    1507             :     }
    1508        1729 : }
    1509             : 
    1510        1822 : void InterfaceType::dumpAttributesCppuDecl(
    1511             :     FileStream & out, std::set< OUString > * seen)
    1512             : {
    1513             :     assert(seen != 0);
    1514        7260 :     for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
    1515        1822 :              i(entity_->getDirectAttributes().begin());
    1516        4840 :          i != entity_->getDirectAttributes().end(); ++i)
    1517             :     {
    1518         598 :         if (seen->insert(i->type).second) {
    1519         287 :             dumpCppuGetType(out, i->type);
    1520             :         }
    1521        2052 :         for (std::vector< OUString >::const_iterator j(
    1522         598 :                  i->getExceptions.begin());
    1523        1368 :              j != i->getExceptions.end(); ++j)
    1524             :         {
    1525          86 :             if (seen->insert(*j).second) {
    1526          11 :                 dumpCppuGetType(out, *j);
    1527             :             }
    1528             :         }
    1529        2148 :         for (std::vector< OUString >::const_iterator j(
    1530         598 :                  i->setExceptions.begin());
    1531        1432 :              j != i->setExceptions.end(); ++j)
    1532             :         {
    1533         118 :             if (seen->insert(*j).second) {
    1534          25 :                 dumpCppuGetType(out, *j);
    1535             :             }
    1536             :         }
    1537             :     }
    1538        1822 : }
    1539             : 
    1540        1822 : void InterfaceType::dumpMethodsCppuDecl(
    1541             :     FileStream & out, std::set< OUString > * seen)
    1542             : {
    1543             :     assert(seen != 0);
    1544       23604 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
    1545        1822 :              entity_->getDirectMethods().begin());
    1546       15736 :          i != entity_->getDirectMethods().end(); ++i)
    1547             :     {
    1548       27144 :         for (std::vector< OUString >::const_iterator j(i->exceptions.begin());
    1549       18096 :              j != i->exceptions.end(); ++j)
    1550             :         {
    1551        3002 :             if (seen->insert(*j).second) {
    1552        1134 :                 dumpCppuGetType(out, *j);
    1553             :             }
    1554             :         }
    1555             :     }
    1556        1822 : }
    1557             : 
    1558       15599 : void InterfaceType::dumpExceptionSpecification(
    1559             :     FileStream & out, std::vector< OUString > const & exceptions,
    1560             :     bool runtimeException)
    1561             : {
    1562             :     // Exception specifications are undesirable in production code, but make
    1563             :     // for useful assertions in debug builds (on platforms where they are
    1564             :     // enforced at runtime):
    1565             : #if !defined DBG_UTIL
    1566       15599 :     out << " /*";
    1567             : #endif
    1568       15599 :     out << " throw (";
    1569       15599 :     bool first = true;
    1570       65856 :     for (std::vector< OUString >::const_iterator i(exceptions.begin());
    1571       43904 :          i != exceptions.end(); ++i)
    1572             :     {
    1573        6353 :         if (*i != "com.sun.star.uno.RuntimeException") {
    1574        6352 :             if (!first) {
    1575        1785 :                 out << ", ";
    1576             :             }
    1577        6352 :             out << codemaker::cpp::scopedCppName(u2b(*i));
    1578        6352 :             first = false;
    1579             :         }
    1580             :     }
    1581       15599 :     if (runtimeException) {
    1582       15593 :         if (!first) {
    1583        4567 :             out << ", ";
    1584             :         }
    1585       15593 :         out << "::css::uno::RuntimeException, ::std::exception";
    1586             :     }
    1587       15599 :     out << ")";
    1588             : #if !defined DBG_UTIL
    1589       15599 :     out << " */";
    1590             : #endif
    1591       15599 : }
    1592             : 
    1593        9251 : void InterfaceType::dumpExceptionTypeName(
    1594             :     FileStream & out, OUString const & prefix, sal_uInt32 index,
    1595             :     OUString const & name)
    1596             : {
    1597       18502 :     out << indent() << "::rtl::OUString the_" << prefix << "ExceptionName"
    1598        9251 :         << index << "( \"" << name << "\" );\n";
    1599        9251 : }
    1600             : 
    1601        7242 : sal_Int32 InterfaceType::dumpExceptionTypeNames(
    1602             :     FileStream & out, OUString const & prefix,
    1603             :     std::vector< OUString > const & exceptions, bool runtimeException)
    1604             : {
    1605        7242 :     sal_Int32 count = 0;
    1606       31344 :     for (std::vector< OUString >::const_iterator i(exceptions.begin());
    1607       20896 :          i != exceptions.end(); ++i)
    1608             :     {
    1609        3206 :         if (*i != "com.sun.star.uno.RuntimeException") {
    1610        3205 :             dumpExceptionTypeName(out, prefix, count++, *i);
    1611             :         }
    1612             :     }
    1613        7242 :     if (runtimeException) {
    1614             :         dumpExceptionTypeName(
    1615        6046 :             out, prefix, count++, "com.sun.star.uno.RuntimeException");
    1616             :     }
    1617        7242 :     if (count != 0) {
    1618        6238 :         out << indent() << "rtl_uString * the_" << prefix << "Exceptions[] = {";
    1619       15489 :         for (sal_Int32 i = 0; i != count; ++i) {
    1620        9251 :             out << (i == 0 ? " " : ", ") << "the_" << prefix << "ExceptionName"
    1621       18502 :                 << i << ".pData";
    1622             :         }
    1623        6238 :         out << " };\n";
    1624             :     }
    1625        7242 :     return count;
    1626             : }
    1627             : 
    1628        1537 : class ConstantGroup: public CppuType {
    1629             : public:
    1630        1537 :     ConstantGroup(
    1631             :         rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
    1632             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    1633        1537 :         CppuType(name, typeMgr), entity_(entity)
    1634        1537 :     { assert(entity.is()); }
    1635             : 
    1636        1537 :     bool hasConstants() const { return !entity_->getMembers().empty(); }
    1637             : 
    1638             : private:
    1639             :     virtual void dumpHFile(
    1640             :         FileStream & out, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    1641             : 
    1642             :     virtual void dumpHxxFile(
    1643             :         FileStream & out, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    1644             : 
    1645             :     virtual void dumpDeclaration(FileStream & out) SAL_OVERRIDE;
    1646             : 
    1647             :     rtl::Reference< unoidl::ConstantGroupEntity > entity_;
    1648             : };
    1649             : 
    1650        1537 : void ConstantGroup::dumpHFile(
    1651             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    1652             : {
    1653        1537 :     OUString headerDefine(dumpHeaderDefine(out, "HDL"));
    1654        1537 :     out << "\n";
    1655        1537 :     addDefaultHIncludes(includes);
    1656        1537 :     includes.dump(out, 0);
    1657        1537 :     out << "\n";
    1658        1537 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, true)) {
    1659        1537 :         out << "\n";
    1660             :     }
    1661        1537 :     out << "\n";
    1662        1537 :     dumpDeclaration(out);
    1663        1537 :     out << "\n";
    1664        1537 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, true)) {
    1665        1537 :         out << "\n";
    1666             :     }
    1667        1537 :     out << "\n#endif // "<< headerDefine << "\n";
    1668        1537 : }
    1669             : 
    1670        1537 : void ConstantGroup::dumpHxxFile(
    1671             :     FileStream & out, codemaker::cppumaker::Includes &)
    1672             : {
    1673        1537 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    1674        1537 :     out << "\n";
    1675        1537 :     codemaker::cppumaker::Includes::dumpInclude(out, u2b(name_), false);
    1676        1537 :     out << "\n#endif // "<< headerDefine << "\n";
    1677        1537 : }
    1678             : 
    1679        1537 : void ConstantGroup::dumpDeclaration(FileStream & out) {
    1680       50262 :     for (std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator i(
    1681        1537 :              entity_->getMembers().begin());
    1682       33508 :          i != entity_->getMembers().end(); ++i)
    1683             :     {
    1684       15217 :         out << "static const ";
    1685       15217 :         switch (i->value.type) {
    1686             :         case unoidl::ConstantValue::TYPE_BOOLEAN:
    1687           0 :             out << "::sal_Bool";
    1688           0 :             break;
    1689             :         case unoidl::ConstantValue::TYPE_BYTE:
    1690         492 :             out << "::sal_Int8";
    1691         492 :             break;
    1692             :         case unoidl::ConstantValue::TYPE_SHORT:
    1693        4158 :             out << "::sal_Int16";
    1694        4158 :             break;
    1695             :         case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
    1696           2 :             out << "::sal_uInt16";
    1697           2 :             break;
    1698             :         case unoidl::ConstantValue::TYPE_LONG:
    1699       10461 :             out << "::sal_Int32";
    1700       10461 :             break;
    1701             :         case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
    1702           2 :             out << "::sal_uInt32";
    1703           2 :             break;
    1704             :         case unoidl::ConstantValue::TYPE_HYPER:
    1705          60 :             out << "::sal_Int64";
    1706          60 :             break;
    1707             :         case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
    1708           2 :             out << "::sal_uInt64";
    1709           2 :             break;
    1710             :         case unoidl::ConstantValue::TYPE_FLOAT:
    1711          40 :             out << "float";
    1712          40 :             break;
    1713             :         case unoidl::ConstantValue::TYPE_DOUBLE:
    1714           0 :             out << "double";
    1715           0 :             break;
    1716             :         }
    1717       15217 :         out << " " << i->name << " = ";
    1718       15217 :         switch (i->value.type) {
    1719             :         case unoidl::ConstantValue::TYPE_BOOLEAN:
    1720           0 :             out << (i->value.booleanValue ? "sal_True" : "sal_False");
    1721           0 :             break;
    1722             :         case unoidl::ConstantValue::TYPE_BYTE:
    1723         492 :             out << "(sal_Int8)" << OUString::number(i->value.byteValue);
    1724         492 :             break;
    1725             :         case unoidl::ConstantValue::TYPE_SHORT:
    1726        4158 :             out << "(sal_Int16)" << OUString::number(i->value.shortValue);
    1727        4158 :             break;
    1728             :         case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
    1729           2 :             out << "(sal_uInt16)"
    1730           4 :                 << OUString::number(i->value.unsignedShortValue);
    1731           2 :             break;
    1732             :         case unoidl::ConstantValue::TYPE_LONG:
    1733             :             // Avoid C++ compiler warnings about (un)signedness of literal
    1734             :             // -2^31:
    1735       10461 :             if (i->value.longValue == SAL_MIN_INT32) {
    1736           9 :                 out << "SAL_MIN_INT32";
    1737             :             } else {
    1738       10452 :                 out << "(sal_Int32)" << OUString::number(i->value.longValue);
    1739             :             }
    1740       10461 :             break;
    1741             :         case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
    1742           2 :             out << "(sal_uInt32)"
    1743           4 :                 << OUString::number(i->value.unsignedLongValue) << "U";
    1744           2 :             break;
    1745             :         case unoidl::ConstantValue::TYPE_HYPER:
    1746             :             // Avoid C++ compiler warnings about (un)signedness of literal
    1747             :             // -2^63:
    1748          60 :             if (i->value.hyperValue == SAL_MIN_INT64) {
    1749           1 :                 out << "SAL_MIN_INT64";
    1750             :             } else {
    1751          59 :                 out << "(sal_Int64) SAL_CONST_INT64("
    1752         118 :                     << OUString::number(i->value.hyperValue) << ")";
    1753             :             }
    1754          60 :             break;
    1755             :         case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
    1756           2 :             out << "SAL_CONST_UINT64("
    1757           4 :                 << OUString::number(i->value.unsignedHyperValue) << ")";
    1758           2 :             break;
    1759             :         case unoidl::ConstantValue::TYPE_FLOAT:
    1760          40 :             out << "(float)" << OUString::number(i->value.floatValue);
    1761          40 :             break;
    1762             :         case unoidl::ConstantValue::TYPE_DOUBLE:
    1763           0 :             out << "(double)" << OUString::number(i->value.doubleValue);
    1764           0 :             break;
    1765             :         }
    1766       15217 :         out << ";\n";
    1767             :     }
    1768        1537 : }
    1769             : 
    1770         447 : void dumpTypeParameterName(FileStream & out, OUString const & name) {
    1771             :     // Prefix all type parameters with "typeparam_" to avoid problems when a
    1772             :     // struct member has the same name as a type parameter, as in
    1773             :     // struct<T> { T T; };
    1774         447 :     out << "typeparam_" << name;
    1775         447 : }
    1776             : 
    1777         831 : class PlainStructType: public CppuType {
    1778             : public:
    1779         831 :     PlainStructType(
    1780             :         rtl::Reference< unoidl::PlainStructTypeEntity > const & entity,
    1781             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    1782         831 :         CppuType(name, typeMgr), entity_(entity)
    1783         831 :     { assert(entity.is()); }
    1784             : 
    1785             : private:
    1786           0 :     virtual sal_uInt32 checkInheritedMemberCount() const SAL_OVERRIDE
    1787           0 :     { return getTotalMemberCount(entity_->getDirectBase()); }
    1788             : 
    1789             :     virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
    1790             : 
    1791             :     void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    1792             : 
    1793             :     virtual void dumpLightGetCppuType(FileStream & out) SAL_OVERRIDE;
    1794             : 
    1795             :     virtual void dumpNormalGetCppuType(FileStream & out) SAL_OVERRIDE;
    1796             : 
    1797             :     virtual void dumpComprehensiveGetCppuType(FileStream & out) SAL_OVERRIDE;
    1798             : 
    1799             :     virtual void addLightGetCppuTypeIncludes(
    1800             :         codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
    1801             : 
    1802             :     virtual void addNormalGetCppuTypeIncludes(
    1803             :         codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
    1804             : 
    1805             :     virtual void addComprehensiveGetCppuTypeIncludes(
    1806             :         codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
    1807             : 
    1808             :     bool dumpBaseMembers(
    1809             :         FileStream & out, OUString const & base, bool withType);
    1810             : 
    1811             :     sal_uInt32 getTotalMemberCount(OUString const & base) const;
    1812             : 
    1813             :     rtl::Reference< unoidl::PlainStructTypeEntity > entity_;
    1814             : };
    1815             : 
    1816         831 : void PlainStructType::dumpDeclaration(FileStream & out) {
    1817        1662 :     out << "\n#ifdef SAL_W32\n#   pragma pack(push, 8)\n#endif\n\n" << indent()
    1818        1662 :         << "struct " << id_;
    1819         831 :     OUString base(entity_->getDirectBase());
    1820         831 :     if (!base.isEmpty()) {
    1821         209 :         out << ": public " << codemaker::cpp::scopedCppName(u2b(base));
    1822             :     }
    1823         831 :     out << " {\n";
    1824         831 :     inc();
    1825         831 :     out << indent() << "inline " << id_ << "() SAL_THROW(());\n";
    1826         831 :     if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
    1827         831 :         out << "\n" << indent() << "inline " << id_ << "(";
    1828         831 :         bool first = !dumpBaseMembers(out, base, true);
    1829       11217 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    1830         831 :                  const_iterator i(entity_->getDirectMembers().begin());
    1831        7478 :              i != entity_->getDirectMembers().end(); ++i)
    1832             :         {
    1833        2908 :             if (!first) {
    1834        2286 :                 out << ", ";
    1835             :             }
    1836        2908 :             dumpType(out, i->type, true, true);
    1837        2908 :             out << " " << i->name << "_";
    1838        2908 :             first = false;
    1839             :         }
    1840         831 :         out << ") SAL_THROW(());\n";
    1841             :     }
    1842         831 :     if (!entity_->getDirectMembers().empty()) {
    1843         831 :         out << "\n";
    1844       11217 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    1845         831 :                  const_iterator i(entity_->getDirectMembers().begin());
    1846        7478 :              i != entity_->getDirectMembers().end(); ++i)
    1847             :         {
    1848        2908 :             out << indent();
    1849        2908 :             dumpType(out, i->type);
    1850        2908 :             out << " " << i->name;
    1851        9555 :             if (i == entity_->getDirectMembers().begin() && !base.isEmpty()
    1852         209 :                 && i->type != "hyper" && i->type != "unsigned hyper"
    1853        8933 :                 && i->type != "double")
    1854             :             {
    1855         209 :                 out << " CPPU_GCC3_ALIGN("
    1856         418 :                     << codemaker::cpp::scopedCppName(u2b(base)) << ")";
    1857             :             }
    1858        2908 :             out << ";\n";
    1859             :         }
    1860             :     }
    1861         831 :     dec();
    1862         831 :     out << "};\n\n#ifdef SAL_W32\n#   pragma pack(pop)\n#endif\n\n";
    1863         831 : }
    1864             : 
    1865         831 : void PlainStructType::dumpHxxFile(
    1866             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    1867             : {
    1868         831 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    1869         831 :     out << "\n";
    1870         831 :     includes.dump(out, &name_);
    1871         831 :     out << "\n";
    1872         831 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
    1873         826 :         out << "\n";
    1874             :     }
    1875         831 :     out << "\ninline " << id_ << "::" << id_ << "() SAL_THROW(())\n";
    1876         831 :     inc();
    1877        1662 :     OUString base(entity_->getDirectBase());
    1878         831 :     bool first = true;
    1879         831 :     if (!base.isEmpty()) {
    1880         418 :         out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
    1881         209 :             << "()\n";
    1882         209 :         first = false;
    1883             :     }
    1884       11217 :     for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
    1885         831 :              entity_->getDirectMembers().begin());
    1886        7478 :          i != entity_->getDirectMembers().end(); ++i)
    1887             :     {
    1888        2908 :         out << indent() << (first ? ":" : ",") << " " << i->name;
    1889        2908 :         dumpInitializer(out, false, i->type);
    1890        2908 :         out << "\n";
    1891        2908 :         first = false;
    1892             :     }
    1893         831 :     dec();
    1894         831 :     out << "{\n}\n\n";
    1895         831 :     if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
    1896         831 :         out << "inline " << id_;
    1897         831 :         out << "::" << id_ << "(";
    1898         831 :         first = !dumpBaseMembers(out, base, true);
    1899       11217 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    1900         831 :                  const_iterator i(entity_->getDirectMembers().begin());
    1901        7478 :              i != entity_->getDirectMembers().end(); ++i)
    1902             :         {
    1903        2908 :             if (!first) {
    1904        2286 :                 out << ", ";
    1905             :             }
    1906        2908 :             dumpType(out, i->type, true, true);
    1907        2908 :             out << " " << i->name << "_";
    1908        2908 :             first = false;
    1909             :         }
    1910         831 :         out << ") SAL_THROW(())\n";
    1911         831 :         inc();
    1912         831 :         first = true;
    1913         831 :         if (!base.isEmpty()) {
    1914         418 :             out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
    1915         209 :                 << "(";
    1916         209 :             dumpBaseMembers(out, base, false);
    1917         209 :             out << ")\n";
    1918         209 :             first = false;
    1919             :         }
    1920       11217 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    1921         831 :                  const_iterator i(entity_->getDirectMembers().begin());
    1922        7478 :              i != entity_->getDirectMembers().end(); ++i)
    1923             :         {
    1924        5816 :             out << indent() << (first ? ":" : ",") << " " << i->name << "("
    1925        5816 :                 << i->name << "_)\n";
    1926        2908 :             first = false;
    1927             :         }
    1928         831 :         dec();
    1929         831 :         out << "{\n}\n\n";
    1930             :     }
    1931         831 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
    1932         826 :         out << "\n";
    1933             :     }
    1934         831 :     out << "\n";
    1935         831 :     dumpGetCppuType(out);
    1936        1662 :     out << "\n#endif // "<< headerDefine << "\n";
    1937         831 : }
    1938             : 
    1939         389 : void PlainStructType::dumpLightGetCppuType(FileStream & out) {
    1940         389 :     dumpGetCppuTypePreamble(out);
    1941         778 :     out << indent()
    1942             :         << ("//TODO: On certain platforms with weak memory models, the"
    1943             :             " following code can result in some threads observing that the_type"
    1944         389 :             " points to garbage\n")
    1945        1167 :         << indent()
    1946         389 :         << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
    1947        1167 :         << indent() << "if (the_type == 0) {\n";
    1948         389 :     inc();
    1949         778 :     out << indent() << "::typelib_static_type_init(&the_type, "
    1950        1167 :         << getTypeClass(name_, true) << ", \"" << name_ << "\");\n";
    1951         389 :     dec();
    1952         778 :     out << indent() << "}\n" << indent()
    1953         389 :         << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
    1954         389 :     dumpGetCppuTypePostamble(out);
    1955         389 : }
    1956             : 
    1957          27 : void PlainStructType::dumpNormalGetCppuType(FileStream & out) {
    1958          27 :     dumpGetCppuTypePreamble(out);
    1959          54 :     out << indent()
    1960             :         << ("//TODO: On certain platforms with weak memory models, the"
    1961             :             " following code can result in some threads observing that the_type"
    1962          27 :             " points to garbage\n")
    1963          81 :         << indent()
    1964          27 :         << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
    1965          81 :         << indent() << "if (the_type == 0) {\n";
    1966          27 :     inc();
    1967          54 :     out << indent()
    1968          27 :         << "::typelib_TypeDescriptionReference * the_members[] = {\n";
    1969          27 :     inc();
    1970         241 :     for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
    1971          27 :              entity_->getDirectMembers().begin());
    1972         214 :          i != entity_->getDirectMembers().end();)
    1973             :     {
    1974          80 :         out << indent() << "::cppu::UnoType< ";
    1975          80 :         dumpType(out, i->type, false, false, false, true);
    1976          80 :         ++i;
    1977          80 :         out << " >::get().getTypeLibType()"
    1978         160 :             << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n";
    1979             :     }
    1980          27 :     dec();
    1981          54 :     out << indent() << "::typelib_static_struct_type_init(&the_type, \""
    1982          54 :         << name_ << "\", ";
    1983          27 :     if (entity_->getDirectBase().isEmpty()) {
    1984          18 :         out << "0";
    1985             :     } else {
    1986           9 :         out << "::cppu::UnoType< ";
    1987           9 :         dumpType(out, entity_->getDirectBase(), false, false, false, true);
    1988           9 :         out << " >::get().getTypeLibType()";
    1989             :     }
    1990          27 :     out << ", " << entity_->getDirectMembers().size() << ", the_members, 0);\n";
    1991          27 :     dec();
    1992          54 :     out << indent() << "}\n" << indent()
    1993          27 :         << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
    1994          27 :     dumpGetCppuTypePostamble(out);
    1995          27 : }
    1996             : 
    1997         415 : void PlainStructType::dumpComprehensiveGetCppuType(FileStream & out) {
    1998         415 :     OUString staticTypeClass("the" + id_ + "Type");
    1999         415 :     codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
    2000         830 :     out << " namespace detail {\n\n" << indent() << "struct "
    2001         415 :         << staticTypeClass
    2002         415 :         << " : public rtl::StaticWithInit< ::css::uno::Type *, "
    2003        1245 :         << staticTypeClass << " >\n" << indent() << "{\n";
    2004         415 :     inc();
    2005         830 :     out << indent() << "::css::uno::Type * operator()() const\n"
    2006        1245 :         << indent() << "{\n";
    2007         415 :     inc();
    2008         415 :     out << indent() << "::rtl::OUString the_name( \"" << name_ << "\" );\n";
    2009         830 :     std::map< OUString, sal_uInt32 > types;
    2010         415 :     std::vector< unoidl::PlainStructTypeEntity::Member >::size_type n = 0;
    2011        5598 :     for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
    2012         415 :              entity_->getDirectMembers().begin());
    2013        3732 :          i != entity_->getDirectMembers().end(); ++i)
    2014             :     {
    2015        2902 :         if (types.insert(
    2016             :                 std::map< OUString, sal_uInt32 >::value_type(
    2017        2902 :                     i->type, static_cast< sal_uInt32 >(types.size()))).
    2018             :             second)
    2019             :         {
    2020         877 :             dumpCppuGetType(out, i->type, &name_);
    2021             :             // For typedefs, use the resolved type name, as there will be no
    2022             :             // information available about the typedef itself at runtime (the
    2023             :             // above getCppuType call will make available information about the
    2024             :             // resolved type); no extra #include for the resolved type is
    2025             :             // needed, as the header for the typedef includes it already:
    2026        1754 :             out << indent() << "::rtl::OUString the_tname"
    2027        1754 :                 << static_cast< sal_uInt32 >(types.size() - 1) << "( \""
    2028        2631 :                 << resolveAllTypedefs(i->type) << "\" );\n";
    2029             :         }
    2030        2902 :         out << indent() << "::rtl::OUString the_name" << n++ << "( \""
    2031        2902 :             << i->name << "\" );\n";
    2032             :     }
    2033         415 :     out << indent() << "::typelib_StructMember_Init the_members[] = {\n";
    2034         415 :     inc();
    2035         415 :     n = 0;
    2036        4147 :     for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
    2037         415 :              entity_->getDirectMembers().begin());
    2038        3732 :          i != entity_->getDirectMembers().end();)
    2039             :     {
    2040        2902 :         out << indent() << "{ { " << getTypeClass(i->type, true)
    2041        4353 :             << ", the_tname" << types.find(i->type)->second
    2042        2902 :             << ".pData, the_name" << n++ << ".pData }, false }";
    2043        1451 :         ++i;
    2044        1451 :         out << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n";
    2045             :     }
    2046         415 :     dec();
    2047         830 :     out << indent() << "::typelib_TypeDescription * the_newType = 0;\n"
    2048        1245 :         << indent()
    2049         415 :         << "::typelib_typedescription_newStruct(&the_newType, the_name.pData, ";
    2050         415 :     if (entity_->getDirectBase().isEmpty()) {
    2051         313 :         out << "0";
    2052             :     } else {
    2053         102 :         out << "::cppu::UnoType< ";
    2054         102 :         dumpType(out, entity_->getDirectBase(), false, false, false, true);
    2055         102 :         out << " >::get().getTypeLibType()";
    2056             :     }
    2057         415 :     out << ", " << entity_->getDirectMembers().size() << ", the_members);\n"
    2058        1245 :         << indent() << "::typelib_typedescription_register(&the_newType);\n"
    2059        1245 :         << indent() << "::typelib_typedescription_release(the_newType);\n"
    2060        1245 :         << indent() << "return new ::css::uno::Type("
    2061        1245 :         << getTypeClass(name_) << ", the_name); // leaked\n";
    2062         415 :     dec();
    2063         415 :     out << indent() << "}\n";
    2064         415 :     dec();
    2065         415 :     out << indent() << "};\n";
    2066         415 :     codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
    2067         415 :     out << " }\n\n";
    2068         415 :     dumpGetCppuTypePreamble(out);
    2069         415 :     out << indent() << "return *detail::" << staticTypeClass << "::get();\n";
    2070         830 :     dumpGetCppuTypePostamble(out);
    2071         415 : }
    2072             : 
    2073        2591 : bool PlainStructType::dumpBaseMembers(
    2074             :     FileStream & out, OUString const & base, bool withType)
    2075             : {
    2076        2591 :     bool hasMember = false;
    2077        2591 :     if (!base.isEmpty()) {
    2078         720 :         rtl::Reference< unoidl::Entity > ent;
    2079         720 :         codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
    2080         720 :         if (sort != codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE) {
    2081             :             throw CannotDumpException(
    2082           0 :                 "plain struct type base " + base
    2083           0 :                 + " is not a plain struct type");
    2084             :         }
    2085             :         rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
    2086        1440 :             dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()));
    2087             :         assert(ent2.is());
    2088         720 :         hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType);
    2089        5454 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    2090         720 :                  const_iterator i(ent2->getDirectMembers().begin());
    2091        3636 :              i != ent2->getDirectMembers().end(); ++i)
    2092             :         {
    2093        1098 :             if (hasMember) {
    2094         471 :                 out << ", ";
    2095             :             }
    2096        1098 :             if (withType) {
    2097         732 :                 dumpType(out, i->type, true, true);
    2098         732 :                 out << " ";
    2099             :             }
    2100        1098 :             out << i->name << "_";
    2101        1098 :             hasMember = true;
    2102         720 :         }
    2103             :     }
    2104        2591 :     return hasMember;
    2105             : }
    2106             : 
    2107         389 : void PlainStructType::addLightGetCppuTypeIncludes(
    2108             :     codemaker::cppumaker::Includes & includes) const
    2109             : {
    2110         389 :     includes.addType();
    2111         389 :     includes.addCppuUnotypeHxx();
    2112         389 :     includes.addSalTypesH();
    2113         389 :     includes.addTypelibTypeclassH();
    2114         389 :     includes.addTypelibTypedescriptionH();
    2115         389 : }
    2116             : 
    2117          27 : void PlainStructType::addNormalGetCppuTypeIncludes(
    2118             :     codemaker::cppumaker::Includes & includes) const
    2119             : {
    2120          27 :     includes.addType();
    2121          27 :     includes.addCppuUnotypeHxx();
    2122          27 :     includes.addSalTypesH();
    2123          27 :     includes.addTypelibTypeclassH();
    2124          27 :     includes.addTypelibTypedescriptionH();
    2125          27 : }
    2126             : 
    2127         415 : void PlainStructType::addComprehensiveGetCppuTypeIncludes(
    2128             :     codemaker::cppumaker::Includes & includes) const
    2129             : {
    2130         415 :     includes.addType();
    2131         415 :     includes.addCppuUnotypeHxx();
    2132         415 :     includes.addRtlInstanceHxx();
    2133         415 :     includes.addOslMutexHxx();
    2134         415 :     includes.addRtlUstringH();
    2135         415 :     includes.addRtlUstringHxx();
    2136         415 :     includes.addSalTypesH();
    2137         415 :     includes.addTypelibTypeclassH();
    2138         415 :     includes.addTypelibTypedescriptionH();
    2139         415 : }
    2140             : 
    2141           0 : sal_uInt32 PlainStructType::getTotalMemberCount(OUString const & base) const {
    2142           0 :     if (base.isEmpty()) {
    2143           0 :         return 0;
    2144             :     }
    2145           0 :     rtl::Reference< unoidl::Entity > ent;
    2146           0 :     codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
    2147           0 :     if (sort != codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE) {
    2148             :         throw CannotDumpException(
    2149           0 :             "plain struct type base " + base + " is not a plain struct type");
    2150             :     }
    2151             :     rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
    2152           0 :         dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()));
    2153             :     assert(ent2.is());
    2154           0 :     return getTotalMemberCount(ent2->getDirectBase())
    2155           0 :         + ent2->getDirectMembers().size(); //TODO: overflow
    2156             : }
    2157             : 
    2158          16 : class PolyStructType: public CppuType {
    2159             : public:
    2160          16 :     PolyStructType(
    2161             :         rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
    2162             :             entity,
    2163             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    2164          16 :         CppuType(name, typeMgr), entity_(entity)
    2165          16 :     { assert(entity.is()); }
    2166             : 
    2167             : private:
    2168             :     virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
    2169             : 
    2170             :     void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    2171             : 
    2172             :     virtual void dumpLightGetCppuType(FileStream & out) SAL_OVERRIDE;
    2173             : 
    2174             :     virtual void dumpNormalGetCppuType(FileStream & out) SAL_OVERRIDE;
    2175             : 
    2176             :     virtual void dumpComprehensiveGetCppuType(FileStream & out) SAL_OVERRIDE;
    2177             : 
    2178             :     virtual void addLightGetCppuTypeIncludes(
    2179             :         codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
    2180             : 
    2181             :     virtual void addNormalGetCppuTypeIncludes(
    2182             :         codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
    2183             : 
    2184             :     virtual void addComprehensiveGetCppuTypeIncludes(
    2185             :         codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
    2186             : 
    2187          48 :     virtual bool isPolymorphic() const SAL_OVERRIDE { return true; }
    2188             : 
    2189             :     virtual void dumpTemplateHead(FileStream & out) const SAL_OVERRIDE;
    2190             : 
    2191             :     virtual void dumpTemplateParameters(FileStream & out) const SAL_OVERRIDE;
    2192             : 
    2193             :     rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
    2194             : };
    2195             : 
    2196          16 : void PolyStructType::dumpDeclaration(FileStream & out) {
    2197          16 :     out << "\n#ifdef SAL_W32\n#   pragma pack(push, 8)\n#endif\n\n" << indent();
    2198          16 :     dumpTemplateHead(out);
    2199          16 :     out << "struct " << id_ << " {\n";
    2200          16 :     inc();
    2201          16 :     out << indent() << "inline " << id_ << "() SAL_THROW(());\n";
    2202          16 :     if (!entity_->getMembers().empty()) {
    2203          16 :         out << "\n" << indent() << "inline " << id_ << "(";
    2204         138 :         for (std::vector<
    2205             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2206          16 :                  const_iterator i(entity_->getMembers().begin());
    2207          92 :              i != entity_->getMembers().end(); ++i)
    2208             :         {
    2209          30 :             if (i != entity_->getMembers().begin()) {
    2210          14 :                 out << ", ";
    2211             :             }
    2212          30 :             if (i->parameterized) {
    2213          19 :                 dumpTypeParameterName(out, i->type);
    2214          19 :                 out << " const &";
    2215             :             } else {
    2216          11 :                 dumpType(out, i->type, true, true);
    2217             :             }
    2218          30 :             out << " " << i->name << "_";
    2219             :         }
    2220          16 :         out << ") SAL_THROW(());\n\n";
    2221         138 :         for (std::vector<
    2222             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2223          16 :                  const_iterator i(entity_->getMembers().begin());
    2224          92 :              i != entity_->getMembers().end(); ++i)
    2225             :         {
    2226          30 :             out << indent();
    2227          30 :             if (i->parameterized) {
    2228          19 :                 dumpTypeParameterName(out, i->type);
    2229             :             } else {
    2230          11 :                 dumpType(out, i->type);
    2231             :             }
    2232          30 :             out << " " << i->name << ";\n";
    2233             :         }
    2234             :     }
    2235          16 :     dec();
    2236          16 :     out << "};\n\n#ifdef SAL_W32\n#   pragma pack(pop)\n#endif\n\n";
    2237          16 : }
    2238             : 
    2239          16 : void PolyStructType::dumpHxxFile(
    2240             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    2241             : {
    2242          16 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    2243          16 :     out << "\n";
    2244          16 :     includes.dump(out, &name_);
    2245          16 :     out << "\n";
    2246          16 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
    2247          15 :         out << "\n";
    2248             :     }
    2249          16 :     out << "\n";
    2250          16 :     dumpTemplateHead(out);
    2251          16 :     out << "inline " << id_;
    2252          16 :     dumpTemplateParameters(out);
    2253          16 :     out << "::" << id_ << "() SAL_THROW(())\n";
    2254          16 :     inc();
    2255         138 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2256          16 :              const_iterator i(entity_->getMembers().begin());
    2257          92 :          i != entity_->getMembers().end(); ++i)
    2258             :     {
    2259          60 :         out << indent() << (i == entity_->getMembers().begin() ? ":" : ",")
    2260          60 :             << " " << i->name;
    2261          30 :         dumpInitializer(out, i->parameterized, i->type);
    2262          30 :         out << "\n";
    2263             :     }
    2264          16 :     dec();
    2265          16 :     out << "{\n}\n\n";
    2266          16 :     if (!entity_->getMembers().empty()) {
    2267          16 :         dumpTemplateHead(out);
    2268          16 :         out << "inline " << id_;
    2269          16 :         dumpTemplateParameters(out);
    2270          16 :         out << "::" << id_ << "(";
    2271         138 :         for (std::vector<
    2272             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2273          16 :                  const_iterator i(entity_->getMembers().begin());
    2274          92 :              i != entity_->getMembers().end(); ++i)
    2275             :         {
    2276          30 :             if (i != entity_->getMembers().begin()) {
    2277          14 :                 out << ", ";
    2278             :             }
    2279          30 :             if (i->parameterized) {
    2280          19 :                 dumpTypeParameterName(out, i->type);
    2281          19 :                 out << " const &";
    2282             :             } else {
    2283          11 :                 dumpType(out, i->type, true, true);
    2284             :             }
    2285          30 :             out << " " << i->name << "_";
    2286             :         }
    2287          16 :         out << ") SAL_THROW(())\n";
    2288          16 :         inc();
    2289         138 :         for (std::vector<
    2290             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2291          16 :                  const_iterator i(entity_->getMembers().begin());
    2292          92 :              i != entity_->getMembers().end(); ++i)
    2293             :         {
    2294          60 :             out << indent() << (i == entity_->getMembers().begin() ? ":" : ",")
    2295          60 :                 << " " << i->name << "(" << i->name << "_)\n";
    2296             :         }
    2297          16 :         dec();
    2298          16 :         out << "{\n}\n\n" << indent();
    2299          16 :         dumpTemplateHead(out);
    2300          16 :         out << "\n" << indent() << "inline " << id_;
    2301          16 :         dumpTemplateParameters(out);
    2302          16 :         out << "\n" << indent() << "make_" << id_ << "(";
    2303         138 :         for (std::vector<
    2304             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2305          16 :                  const_iterator i(entity_->getMembers().begin());
    2306          92 :              i != entity_->getMembers().end(); ++i)
    2307             :         {
    2308          30 :             if (i != entity_->getMembers().begin()) {
    2309          14 :                 out << ", ";
    2310             :             }
    2311          30 :             if (i->parameterized) {
    2312          19 :                 dumpTypeParameterName(out, i->type);
    2313          19 :                 out << " const &";
    2314             :             } else {
    2315          11 :                 dumpType(out, i->type, true, true);
    2316             :             }
    2317          30 :             out << " " << i->name << "_";
    2318             :         }
    2319          16 :         out << ") SAL_THROW(())\n" << indent() << "{\n";
    2320          16 :         inc();
    2321          16 :         out << indent() << "return " << id_;
    2322          16 :         dumpTemplateParameters(out);
    2323          16 :         out << "(";
    2324         138 :         for (std::vector<
    2325             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2326          16 :                  const_iterator i(entity_->getMembers().begin());
    2327          92 :              i != entity_->getMembers().end(); ++i)
    2328             :         {
    2329          30 :             if (i != entity_->getMembers().begin()) {
    2330          14 :                 out << ", ";
    2331             :             }
    2332          30 :             out << i->name << "_";
    2333             :         }
    2334          16 :         out << ");\n";
    2335          16 :         dec();
    2336          16 :         out << indent() << "}\n\n";
    2337             :     }
    2338          16 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
    2339          15 :         out << "\n";
    2340             :     }
    2341          16 :     out << "\n";
    2342          16 :     dumpGetCppuType(out);
    2343          16 :     out << "\n#endif // "<< headerDefine << "\n";
    2344          16 : }
    2345             : 
    2346           6 : void PolyStructType::dumpLightGetCppuType(FileStream & out) {
    2347           6 :     dumpGetCppuTypePreamble(out);
    2348          12 :     out << indent()
    2349             :         << ("//TODO: On certain platforms with weak memory models, the"
    2350             :             " following code can result in some threads observing that the_type"
    2351           6 :             " points to garbage\n")
    2352          18 :         << indent()
    2353           6 :         << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
    2354          18 :         << indent() << "if (the_type == 0) {\n";
    2355           6 :     inc();
    2356          12 :     out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
    2357           6 :         << "<\");\n";
    2358          34 :     for (std::vector< OUString >::const_iterator i(
    2359           6 :              entity_->getTypeParameters().begin());
    2360          28 :          i != entity_->getTypeParameters().end();)
    2361             :     {
    2362          16 :         out << indent()
    2363             :             << ("the_buffer.append(::rtl::OUStringToOString("
    2364           8 :                 "::cppu::getTypeFavourChar(static_cast< ");
    2365           8 :         dumpTypeParameterName(out, *i);
    2366           8 :         out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
    2367           8 :         ++i;
    2368           8 :         if (i != entity_->getTypeParameters().end()) {
    2369           2 :             out << indent() << "the_buffer.append(',');\n";
    2370             :         }
    2371             :     }
    2372          12 :     out << indent() << "the_buffer.append('>');\n" << indent()
    2373          18 :         << "::typelib_static_type_init(&the_type, " << getTypeClass(name_, true)
    2374           6 :         << ", the_buffer.getStr());\n";
    2375           6 :     dec();
    2376          12 :     out << indent() << "}\n" << indent()
    2377           6 :         << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
    2378           6 :     dumpGetCppuTypePostamble(out);
    2379           6 : }
    2380             : 
    2381           4 : void PolyStructType::dumpNormalGetCppuType(FileStream & out) {
    2382           4 :     dumpGetCppuTypePreamble(out);
    2383           8 :     out << indent()
    2384             :         << ("//TODO: On certain platforms with weak memory models, the"
    2385             :             " following code can result in some threads observing that the_type"
    2386           4 :             " points to garbage\n")
    2387          12 :         << indent()
    2388           4 :         << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
    2389          12 :         << indent() << "if (the_type == 0) {\n";
    2390           4 :     inc();
    2391           8 :     out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
    2392           4 :         << "<\");\n";
    2393          22 :     for (std::vector< OUString >::const_iterator i(
    2394           4 :              entity_->getTypeParameters().begin());
    2395          18 :          i != entity_->getTypeParameters().end();)
    2396             :     {
    2397          10 :         out << indent()
    2398             :             << ("the_buffer.append(::rtl::OUStringToOString("
    2399           5 :                 "::cppu::getTypeFavourChar(static_cast< ");
    2400           5 :         dumpTypeParameterName(out, *i);
    2401           5 :         out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
    2402           5 :         ++i;
    2403           5 :         if (i != entity_->getTypeParameters().end()) {
    2404           1 :             out << indent() << "the_buffer.append(',');\n";
    2405             :         }
    2406             :     }
    2407           8 :     out << indent() << "the_buffer.append('>');\n" << indent()
    2408           4 :         << "::typelib_TypeDescriptionReference * the_members[] = {\n";
    2409           4 :     inc();
    2410          28 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2411           4 :              const_iterator i(entity_->getMembers().begin());
    2412          24 :          i != entity_->getMembers().end();)
    2413             :     {
    2414           8 :         out << indent();
    2415           8 :         if (i->parameterized) {
    2416           5 :             out << "::cppu::getTypeFavourChar(static_cast< ";
    2417           5 :             dumpTypeParameterName(out, i->type);
    2418           5 :             out << " * >(0))";
    2419             :         } else {
    2420           3 :             out << "::cppu::UnoType< ";
    2421           3 :             dumpType(out, i->type, false, false, false, true);
    2422           3 :             out << " >::get()";
    2423             :         }
    2424           8 :         ++i;
    2425           8 :         out << ".getTypeLibType()"
    2426          16 :             << (i == entity_->getMembers().end() ? " };" : ",") << "\n";
    2427             :     }
    2428           4 :     dec();
    2429           4 :     out << indent() << "static ::sal_Bool const the_parameterizedTypes[] = { ";
    2430          36 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2431           4 :              const_iterator i(entity_->getMembers().begin());
    2432          24 :          i != entity_->getMembers().end(); ++i)
    2433             :     {
    2434           8 :         if (i != entity_->getMembers().begin()) {
    2435           4 :             out << ", ";
    2436             :         }
    2437           8 :         out << (i->parameterized ? "true" : "false");
    2438             :     }
    2439           8 :     out << " };\n" << indent()
    2440             :         << ("::typelib_static_struct_type_init(&the_type, the_buffer.getStr(),"
    2441           4 :             " 0, ")
    2442           8 :         << entity_->getMembers().size()
    2443           4 :         << ", the_members, the_parameterizedTypes);\n";
    2444           4 :     dec();
    2445           8 :     out << indent() << "}\n" << indent()
    2446             :         << ("return *reinterpret_cast< ::css::uno::Type * >("
    2447           4 :             "&the_type);\n");
    2448           4 :     dumpGetCppuTypePostamble(out);
    2449           4 : }
    2450             : 
    2451           6 : void PolyStructType::dumpComprehensiveGetCppuType(FileStream & out) {
    2452           6 :     out << "namespace cppu {  namespace detail {\n\n" << indent();
    2453           6 :     dumpTemplateHead(out);
    2454           6 :     OUString staticTypeClass("the" + id_ + "Type");
    2455           6 :     out << "struct " << staticTypeClass
    2456           6 :         << " : public rtl::StaticWithInit< ::css::uno::Type *, "
    2457           6 :         << staticTypeClass;
    2458           6 :     dumpTemplateParameters(out);
    2459           6 :     out << " >\n" << indent() << "{\n";
    2460           6 :     inc();
    2461          12 :     out << indent() << "::css::uno::Type * operator()() const\n"
    2462          18 :         << indent() << "{\n";
    2463           6 :     inc();
    2464          12 :     out << indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent()
    2465          12 :         << "the_buffer.append(\"" << name_ << "<\");\n";
    2466          34 :     for (std::vector< OUString >::const_iterator i(
    2467           6 :              entity_->getTypeParameters().begin());
    2468          28 :          i != entity_->getTypeParameters().end();)
    2469             :     {
    2470          16 :         out << indent()
    2471           8 :             << "the_buffer.append(::cppu::getTypeFavourChar(static_cast< ";
    2472           8 :         dumpTypeParameterName(out, *i);
    2473           8 :         out << " * >(0)).getTypeName());\n";
    2474           8 :         ++i;
    2475           8 :         if (i != entity_->getTypeParameters().end()) {
    2476           4 :             out << indent()
    2477             :                 << ("the_buffer.append("
    2478           2 :                     "static_cast< ::sal_Unicode >(','));\n");
    2479             :         }
    2480             :     }
    2481          12 :     out << indent() << "the_buffer.append(static_cast< ::sal_Unicode >('>'));\n"
    2482          18 :         << indent()
    2483           6 :         << "::rtl::OUString the_name(the_buffer.makeStringAndClear());\n";
    2484          12 :     std::map< OUString, sal_uInt32 > parameters;
    2485          12 :     std::map< OUString, sal_uInt32 > types;
    2486             :     std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2487           6 :         size_type n = 0;
    2488          51 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2489           6 :              const_iterator i(entity_->getMembers().begin());
    2490          34 :          i != entity_->getMembers().end(); ++i)
    2491             :     {
    2492          11 :         if (i->parameterized) {
    2493          12 :             if (parameters.insert(
    2494             :                     std::map< OUString, sal_uInt32 >::value_type(
    2495          12 :                         i->type, static_cast< sal_uInt32 >(parameters.size()))).
    2496             :                 second)
    2497             :             {
    2498           6 :                 sal_uInt32 k = static_cast< sal_uInt32 >(parameters.size() - 1);
    2499          12 :                 out << indent()
    2500           6 :                     << "::css::uno::Type const & the_ptype" << k
    2501           6 :                     << " = ::cppu::getTypeFavourChar(static_cast< ";
    2502           6 :                 dumpTypeParameterName(out, i->type);
    2503          12 :                 out << " * >(0));\n" << indent()
    2504           6 :                     << "::typelib_TypeClass the_pclass" << k
    2505           6 :                     << " = (::typelib_TypeClass) the_ptype" << k
    2506          18 :                     << ".getTypeClass();\n" << indent()
    2507           6 :                     << "::rtl::OUString the_pname" << k << "(the_ptype" << k
    2508           6 :                     << ".getTypeName());\n";
    2509             :             }
    2510          10 :         } else if (types.insert(
    2511             :                        std::map< OUString, sal_uInt32 >::value_type(
    2512          10 :                            i->type, static_cast< sal_uInt32 >(types.size()))).
    2513             :                    second)
    2514             :         {
    2515           5 :             dumpCppuGetType(out, i->type, &name_);
    2516             :             // For typedefs, use the resolved type name, as there will be no
    2517             :             // information available about the typedef itself at runtime (the
    2518             :             // above getCppuType call will make available information about the
    2519             :             // resolved type); no extra #include for the resolved type is
    2520             :             // needed, as the header for the typedef includes it already:
    2521          10 :             out << indent() << "::rtl::OUString the_tname"
    2522          10 :                 << static_cast< sal_uInt32 >(types.size() - 1) << "( \""
    2523          15 :                 << resolveAllTypedefs(i->type) << "\" );\n";
    2524             :         }
    2525          22 :         out << indent() << "::rtl::OUString the_name" << n++ << "( \""
    2526          22 :             << i->name << "\" );\n";
    2527             :     }
    2528           6 :     out << indent() << "::typelib_StructMember_Init the_members[] = {\n";
    2529           6 :     inc();
    2530           6 :     n = 0;
    2531          40 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2532           6 :              const_iterator i(entity_->getMembers().begin());
    2533          34 :          i != entity_->getMembers().end();)
    2534             :     {
    2535          11 :         out << indent() << "{ { ";
    2536          11 :         if (i->parameterized) {
    2537           6 :             sal_uInt32 k = parameters.find(i->type)->second;
    2538           6 :             out << "the_pclass" << k << ", the_pname" << k << ".pData";
    2539             :         } else {
    2540          10 :             out << getTypeClass(i->type, true) << ", the_tname"
    2541          15 :                 << types.find(i->type)->second << ".pData";
    2542             :         }
    2543          11 :         out << ", the_name" << n++ << ".pData }, "
    2544          22 :             << (i->parameterized ? "true" : "false") << " }";
    2545          11 :         ++i;
    2546          11 :         out << (i == entity_->getMembers().end() ? " };" : ",") << "\n";
    2547             :     }
    2548           6 :     dec();
    2549           6 :     out << indent() << "::typelib_TypeDescription * the_newType = 0;\n";
    2550          12 :     out << indent()
    2551             :         << ("::typelib_typedescription_newStruct(&the_newType, the_name.pData,"
    2552           6 :             " 0, ")
    2553          18 :         << entity_->getMembers().size() << ", the_members);\n" << indent()
    2554          18 :         << "::typelib_typedescription_register(&the_newType);\n" << indent()
    2555          18 :         << "::typelib_typedescription_release(the_newType);\n" << indent()
    2556          18 :         << "return new ::css::uno::Type(" << getTypeClass(name_)
    2557           6 :         << ", the_name); // leaked\n";
    2558           6 :     dec();
    2559           6 :     out << indent() << "}\n";
    2560           6 :     dec();
    2561           6 :     out << indent() << "};\n" << " }" << " }\n\n";
    2562           6 :     dumpGetCppuTypePreamble(out);
    2563           6 :     out << indent() << "return *detail::" << staticTypeClass;
    2564           6 :     dumpTemplateParameters(out);
    2565           6 :     out << "::get();\n";
    2566          12 :     dumpGetCppuTypePostamble(out);
    2567           6 : }
    2568             : 
    2569           6 : void PolyStructType::addLightGetCppuTypeIncludes(
    2570             :     codemaker::cppumaker::Includes & includes) const
    2571             : {
    2572           6 :     includes.addType();
    2573           6 :     includes.addCppuUnotypeHxx();
    2574           6 :     includes.addSalTypesH();
    2575           6 :     includes.addTypelibTypeclassH();
    2576           6 :     includes.addTypelibTypedescriptionH();
    2577           6 :     includes.addRtlStrbufHxx();
    2578           6 :     includes.addRtlTextencH();
    2579           6 :     includes.addRtlUstringHxx();
    2580           6 : }
    2581             : 
    2582           4 : void PolyStructType::addNormalGetCppuTypeIncludes(
    2583             :     codemaker::cppumaker::Includes & includes) const
    2584             : {
    2585           4 :     includes.addType();
    2586           4 :     includes.addCppuUnotypeHxx();
    2587           4 :     includes.addSalTypesH();
    2588           4 :     includes.addTypelibTypeclassH();
    2589           4 :     includes.addTypelibTypedescriptionH();
    2590           4 :     includes.addRtlStrbufHxx();
    2591           4 :     includes.addRtlTextencH();
    2592           4 :     includes.addRtlUstringHxx();
    2593           4 : }
    2594             : 
    2595           6 : void PolyStructType::addComprehensiveGetCppuTypeIncludes(
    2596             :     codemaker::cppumaker::Includes & includes) const
    2597             : {
    2598           6 :     includes.addType();
    2599           6 :     includes.addCppuUnotypeHxx();
    2600           6 :     includes.addRtlInstanceHxx();
    2601           6 :     includes.addOslMutexHxx();
    2602           6 :     includes.addRtlUstringH();
    2603           6 :     includes.addRtlUstringHxx();
    2604           6 :     includes.addSalTypesH();
    2605           6 :     includes.addTypelibTypeclassH();
    2606           6 :     includes.addTypelibTypedescriptionH();
    2607           6 :     includes.addRtlStringH();
    2608           6 :     includes.addRtlUstrbufHxx();
    2609           6 : }
    2610             : 
    2611         118 : void PolyStructType::dumpTemplateHead(FileStream & out) const {
    2612         118 :     out << "template< ";
    2613         819 :     for (std::vector< OUString >::const_iterator i(
    2614         118 :              entity_->getTypeParameters().begin());
    2615         546 :          i != entity_->getTypeParameters().end(); ++i)
    2616             :     {
    2617         155 :         if (i != entity_->getTypeParameters().begin()) {
    2618          37 :             out << ", ";
    2619             :         }
    2620         155 :         out << "typename ";
    2621         155 :         dumpTypeParameterName(out, *i);
    2622             :     }
    2623         118 :     out << " > ";
    2624         118 : }
    2625             : 
    2626         140 : void PolyStructType::dumpTemplateParameters(FileStream & out) const {
    2627         140 :     out << "< ";
    2628         972 :     for (std::vector< OUString >::const_iterator i(
    2629         140 :              entity_->getTypeParameters().begin());
    2630         648 :          i != entity_->getTypeParameters().end(); ++i)
    2631             :     {
    2632         184 :         if (i != entity_->getTypeParameters().begin()) {
    2633          44 :             out << ", ";
    2634             :         }
    2635         184 :         dumpTypeParameterName(out, *i);
    2636             :     }
    2637         140 :     out << " >";
    2638         140 : }
    2639             : 
    2640          15 : OUString typeToIdentifier(OUString const & name) {
    2641             :     sal_Int32 k;
    2642          15 :     OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k)));
    2643          30 :     OUStringBuffer b;
    2644          15 :     for (sal_Int32 i = 0; i != k; ++i) {
    2645           0 :         b.append("seq_");
    2646             :     }
    2647          15 :     b.append(n);
    2648          15 :     b.replace(' ', '_');
    2649          15 :     b.replace(',', '_');
    2650          15 :     b.replace('.', '_');
    2651          15 :     b.replace('<', '_');
    2652          15 :     b.replace('>', '_');
    2653          30 :     return b.makeStringAndClear();
    2654             : }
    2655             : 
    2656         557 : class ExceptionType: public CppuType {
    2657             : public:
    2658         557 :     ExceptionType(
    2659             :         rtl::Reference< unoidl::ExceptionTypeEntity > const & entity,
    2660             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    2661         557 :         CppuType(name, typeMgr), entity_(entity)
    2662         557 :     { assert(entity.is()); }
    2663             : 
    2664             : private:
    2665             :     virtual void dumpHxxFile(
    2666             :         FileStream & out, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    2667             : 
    2668             :     virtual void dumpLightGetCppuType(FileStream & out) SAL_OVERRIDE;
    2669             : 
    2670             :     virtual void dumpNormalGetCppuType(FileStream & out) SAL_OVERRIDE;
    2671             : 
    2672             :     virtual void dumpComprehensiveGetCppuType(FileStream & out) SAL_OVERRIDE;
    2673             : 
    2674         352 :     virtual sal_uInt32 checkInheritedMemberCount() const SAL_OVERRIDE
    2675         352 :     { return getTotalMemberCount(entity_->getDirectBase()); }
    2676             : 
    2677             :     virtual void dumpDeclaration(FileStream & out) SAL_OVERRIDE;
    2678             : 
    2679             :     bool dumpBaseMembers(
    2680             :         FileStream & out, OUString const & base, bool withType);
    2681             : 
    2682             :     sal_uInt32 getTotalMemberCount(OUString const & base) const;
    2683             : 
    2684             :     rtl::Reference< unoidl::ExceptionTypeEntity > entity_;
    2685             : };
    2686             : 
    2687         557 : void ExceptionType::dumpHxxFile(
    2688             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    2689             : {
    2690         557 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    2691         557 :     out << "\n";
    2692         557 :     addDefaultHxxIncludes(includes);
    2693         557 :     includes.dump(out, &name_);
    2694         557 :     out << "\n";
    2695         557 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
    2696         553 :         out << "\n";
    2697             :     }
    2698         557 :     out << "\ninline " << id_ << "::" << id_ << "() SAL_THROW(())\n";
    2699         557 :     inc();
    2700        1114 :     OUString base(entity_->getDirectBase());
    2701         557 :     bool first = true;
    2702         557 :     if (!base.isEmpty()) {
    2703        1108 :         out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
    2704         554 :             << "()\n";
    2705         554 :         first = false;
    2706             :     }
    2707        2661 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    2708         557 :              entity_->getDirectMembers().begin());
    2709        1774 :          i != entity_->getDirectMembers().end(); ++i)
    2710             :     {
    2711         330 :         out << indent() << (first ? ":" : ",") << " ";
    2712         330 :         out << i->name;
    2713         330 :         dumpInitializer(out, false, i->type);
    2714         330 :         out << "\n";
    2715         330 :         first = false;
    2716             :     }
    2717         557 :     dec();
    2718         557 :     out << "{";
    2719         557 :     if (!m_cppuTypeDynamic) {
    2720         259 :         out << "\n";
    2721         259 :         inc();
    2722         259 :         dumpCppuGetType(out, name_);
    2723         259 :         dec();
    2724             :     } else {
    2725         298 :         out << " ";
    2726             :     }
    2727         557 :     out << "}\n\n";
    2728         557 :     if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
    2729         557 :         out << indent() << "inline " << id_ << "::" << id_ << "(";
    2730         557 :         first = !dumpBaseMembers(out, base, true);
    2731        2661 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2732         557 :                  i(entity_->getDirectMembers().begin());
    2733        1774 :              i != entity_->getDirectMembers().end(); ++i)
    2734             :         {
    2735         330 :             if (!first) {
    2736         327 :                 out << ", ";
    2737             :             }
    2738         330 :             dumpType(out, i->type, true, true);
    2739         330 :             out << " " << i->name << "_";
    2740         330 :             first = false;
    2741             :         }
    2742         557 :         out << ") SAL_THROW(())\n";
    2743         557 :         inc();
    2744         557 :         first = true;
    2745         557 :         if (!base.isEmpty()) {
    2746        1108 :             out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
    2747         554 :                 << "(";
    2748         554 :             dumpBaseMembers(out, base, false);
    2749         554 :             out << ")\n";
    2750         554 :             first = false;
    2751             :         }
    2752        2661 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2753         557 :                  i(entity_->getDirectMembers().begin());
    2754        1774 :              i != entity_->getDirectMembers().end(); ++i)
    2755             :         {
    2756         660 :             out << indent() << (first ? ":" : ",") << " " << i->name << "("
    2757         660 :                 << i->name << "_)\n";
    2758         330 :             first = false;
    2759             :         }
    2760         557 :         dec();
    2761         557 :         out << "{";
    2762         557 :         if (!m_cppuTypeDynamic) {
    2763         259 :             out << "\n";
    2764         259 :             inc();
    2765         259 :             dumpCppuGetType(out, name_);
    2766         259 :             dec();
    2767             :         } else {
    2768         298 :             out << " ";
    2769             :         }
    2770         557 :         out << "}\n\n";
    2771             :     }
    2772        1114 :     out << indent() << id_ << "::" << id_ << "(" << id_
    2773         557 :         << " const & the_other)";
    2774         557 :     first = true;
    2775         557 :     if (!base.isEmpty()) {
    2776        1108 :         out << ": " << codemaker::cpp::scopedCppName(u2b(base))
    2777         554 :             << "(the_other)";
    2778         554 :         first = false;
    2779             :     }
    2780        2661 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    2781         557 :              entity_->getDirectMembers().begin());
    2782        1774 :          i != entity_->getDirectMembers().end(); ++i)
    2783             :     {
    2784         330 :         out << (first ? ":" : ",") << " " << i->name << "(the_other." << i->name
    2785         330 :             << ")";
    2786         330 :         first = false;
    2787             :     }
    2788        1114 :     out << indent() << " {}\n\n" << indent() << id_ << "::~" << id_
    2789        1671 :         << "() {}\n\n" << indent() << id_ << " & " << id_ << "::operator =("
    2790        1114 :         << id_ << " const & the_other) {\n";
    2791         557 :     inc();
    2792        1114 :     out << indent()
    2793             :         << ("//TODO: Just like its implicitly-defined counterpart, this"
    2794         557 :             " function definition is not exception-safe\n");
    2795         557 :     if (!base.isEmpty()) {
    2796        1108 :         out << indent() << codemaker::cpp::scopedCppName(u2b(base))
    2797         554 :             << "::operator =(the_other);\n";
    2798             :     }
    2799        2661 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    2800         557 :              entity_->getDirectMembers().begin());
    2801        1774 :          i != entity_->getDirectMembers().end(); ++i)
    2802             :     {
    2803         330 :         out << indent() << i->name << " = the_other." << i->name << ";\n";
    2804             :     }
    2805         557 :     out << indent() << "return *this;\n";
    2806         557 :     dec();
    2807         557 :     out << indent() << "}\n\n";
    2808         557 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
    2809         553 :         out << "\n";
    2810             :     }
    2811         557 :     out << "\n";
    2812         557 :     dumpGetCppuType(out);
    2813        1114 :     out << "\n#endif // "<< headerDefine << "\n";
    2814         557 : }
    2815             : 
    2816         238 : void ExceptionType::dumpLightGetCppuType(FileStream & out) {
    2817         238 :     dumpGetCppuTypePreamble(out);
    2818         476 :     out << indent()
    2819         238 :         << "static typelib_TypeDescriptionReference * the_type = 0;\n"
    2820         714 :         << indent() << "if ( !the_type )\n" << indent() << "{\n";
    2821         238 :     inc();
    2822         476 :     out << indent() << "typelib_static_type_init( &the_type, "
    2823         714 :         << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n";
    2824         238 :     dec();
    2825         476 :     out << indent() << "}\n" << indent()
    2826             :         << ("return * reinterpret_cast< ::css::uno::Type * >("
    2827         238 :             " &the_type );\n");
    2828         238 :     dumpGetCppuTypePostamble(out);
    2829         238 : }
    2830             : 
    2831          58 : void ExceptionType::dumpNormalGetCppuType(FileStream & out) {
    2832          58 :     dumpGetCppuTypePreamble(out);
    2833         116 :     out << indent()
    2834          58 :         << "static typelib_TypeDescriptionReference * the_type = 0;\n"
    2835         174 :         << indent() << "if ( !the_type )\n" << indent() << "{\n";
    2836          58 :     inc();
    2837          58 :     OUString base(entity_->getDirectBase());
    2838          58 :     bool baseException = false;
    2839          58 :     if (!base.isEmpty()) {
    2840          58 :         if (base == "com.sun.star.uno.Exception") {
    2841          35 :             baseException = true;
    2842             :         } else {
    2843          46 :             out << indent()
    2844             :                 << ("const ::css::uno::Type& rBaseType ="
    2845          23 :                     " ::cppu::UnoType< ");
    2846          23 :             dumpType(out, base, true, false, false, true);
    2847          23 :             out << " >::get();\n\n";
    2848             :         }
    2849             :     }
    2850          58 :     if (!entity_->getDirectMembers().empty()) {
    2851          18 :         out << indent() << "typelib_TypeDescriptionReference * aMemberRefs["
    2852          18 :             << entity_->getDirectMembers().size() << "];\n";
    2853           9 :         std::set< OUString > seen;
    2854           9 :         std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0;
    2855          72 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2856           9 :                  i(entity_->getDirectMembers().begin());
    2857          48 :              i != entity_->getDirectMembers().end(); ++i)
    2858             :         {
    2859          15 :             OUString type(resolveAllTypedefs(i->type));
    2860          30 :             OUString modType(typeToIdentifier(type));
    2861          15 :             if (seen.insert(type).second) {
    2862          24 :                 out << indent()
    2863          12 :                     << "const ::css::uno::Type& rMemberType_"
    2864          12 :                     << modType << " = ::cppu::UnoType< ";
    2865          12 :                 dumpType(out, type, false, false, false, true);
    2866          12 :                 out << " >::get();\n";
    2867             :             }
    2868          30 :             out << indent() << "aMemberRefs[" << n++ << "] = rMemberType_"
    2869          15 :                 << modType << ".getTypeLibType();\n";
    2870          15 :         }
    2871           9 :         out << "\n";
    2872             :     }
    2873         116 :     out << indent() << "typelib_static_compound_type_init( &the_type, "
    2874         174 :         << getTypeClass(name_, true) << ", \"" << name_ << "\", ";
    2875          58 :     if (baseException) {
    2876             :         out << ("* ::typelib_static_type_getByTypeClass("
    2877          35 :                 " typelib_TypeClass_EXCEPTION )");
    2878          23 :     } else if (base.isEmpty()) {
    2879           0 :         out << "0";
    2880             :     } else {
    2881          23 :         out << "rBaseType.getTypeLibType()";
    2882             :     }
    2883          58 :     out << ", " << entity_->getDirectMembers().size() << ",  "
    2884         116 :         << (entity_->getDirectMembers().empty() ? "0" : "aMemberRefs")
    2885          58 :         << " );\n";
    2886          58 :     dec();
    2887         116 :     out << indent() << "}\n" << indent()
    2888             :         << ("return * reinterpret_cast< const ::css::uno::Type * >("
    2889          58 :             " &the_type );\n");
    2890          58 :     dumpGetCppuTypePostamble(out);
    2891          58 : }
    2892             : 
    2893         258 : void ExceptionType::dumpComprehensiveGetCppuType(FileStream & out) {
    2894         258 :     codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
    2895         258 :     out << " namespace detail {\n\n";
    2896         258 :     OUString staticTypeClass("the" + id_ + "Type");
    2897         516 :     out << indent() << "struct " << staticTypeClass
    2898         258 :         << " : public rtl::StaticWithInit< ::css::uno::Type *, "
    2899         774 :         << staticTypeClass << " >\n" << indent() << "{\n";
    2900         258 :     inc();
    2901         516 :     out << indent() << "::css::uno::Type * operator()() const\n"
    2902         774 :         << indent() << "{\n";
    2903         258 :     inc();
    2904         516 :     out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n"
    2905         774 :         << indent() << "// Start inline typedescription generation\n"
    2906         774 :         << indent() << "typelib_TypeDescription * pTD = 0;\n";
    2907         516 :     OUString base(entity_->getDirectBase());
    2908         258 :     if (!base.isEmpty()) {
    2909         516 :         out << indent()
    2910             :             << ("const ::css::uno::Type& rSuperType ="
    2911         258 :                 " ::cppu::UnoType< ");
    2912         258 :         dumpType(out, base, false, false, false, true);
    2913         258 :         out << " >::get();\n";
    2914             :     }
    2915         516 :     std::set< OUString > seen;
    2916        1254 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    2917         258 :              entity_->getDirectMembers().begin());
    2918         836 :          i != entity_->getDirectMembers().end(); ++i)
    2919             :     {
    2920         160 :         if (seen.insert(i->type).second) {
    2921         126 :             dumpCppuGetType(out, i->type);
    2922             :         }
    2923             :     }
    2924         258 :     if (!entity_->getDirectMembers().empty()) {
    2925         200 :         out << "\n" << indent() << "typelib_CompoundMember_Init aMembers["
    2926         200 :             << entity_->getDirectMembers().size() << "];\n";
    2927         100 :         std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0;
    2928         780 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2929         100 :                  i(entity_->getDirectMembers().begin());
    2930         520 :              i != entity_->getDirectMembers().end(); ++i)
    2931             :         {
    2932         160 :             OUString type(resolveAllTypedefs(i->type));
    2933         320 :             out << indent() << "::rtl::OUString sMemberType" << n << "( \""
    2934         480 :                 << type << "\" );\n" << indent()
    2935         320 :                 << "::rtl::OUString sMemberName" << n << "( \"" << i->name
    2936         480 :                 << "\" );\n" << indent() << "aMembers[" << n
    2937         480 :                 << "].eTypeClass = (typelib_TypeClass)" << getTypeClass(type)
    2938         480 :                 << ";\n" << indent() << "aMembers[" << n
    2939         480 :                 << "].pTypeName = sMemberType" << n << ".pData;\n" << indent()
    2940         160 :                 << "aMembers[" << n << "].pMemberName = sMemberName" << n
    2941         160 :                 << ".pData;\n";
    2942         160 :             ++n;
    2943         160 :         }
    2944             :     }
    2945         258 :     out << "\n" << indent() << "typelib_typedescription_new(\n";
    2946         258 :     inc();
    2947         516 :     out << indent() << "&pTD,\n" << indent() << "(typelib_TypeClass)"
    2948         774 :         << getTypeClass(name_) << ", sTypeName.pData,\n" << indent()
    2949         516 :         << (base.isEmpty() ? "0" : "rSuperType.getTypeLibType()") << ",\n"
    2950         774 :         << indent() << entity_->getDirectMembers().size() << ",\n" << indent()
    2951         516 :         << (entity_->getDirectMembers().empty() ? "0" : "aMembers")
    2952         258 :         << " );\n\n";
    2953         258 :     dec();
    2954         516 :     out << indent()
    2955             :         << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
    2956         258 :             " );\n\n")
    2957         774 :         << indent() << "typelib_typedescription_release( pTD );\n" << indent()
    2958         774 :         << "// End inline typedescription generation\n\n" << indent()
    2959         774 :         << "return new ::css::uno::Type( " << getTypeClass(name_)
    2960         258 :         << ", sTypeName ); // leaked\n";
    2961         258 :     dec();
    2962         258 :     out << indent() << "}\n";
    2963         258 :     dec();
    2964         258 :     out << indent() << "};\n\n";
    2965         258 :     codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
    2966         258 :     out << " }\n\n";
    2967         258 :     dumpGetCppuTypePreamble(out);
    2968         258 :     out << indent() << "return *detail::" << staticTypeClass << "::get();\n";
    2969         516 :     dumpGetCppuTypePostamble(out);
    2970         258 : }
    2971             : 
    2972         557 : void ExceptionType::dumpDeclaration(FileStream & out) {
    2973         557 :     out << "\nclass CPPU_GCC_DLLPUBLIC_EXPORT " << id_;
    2974         557 :     OUString base(entity_->getDirectBase());
    2975         557 :     if (!base.isEmpty()) {
    2976         554 :         out << " : public " << codemaker::cpp::scopedCppName(u2b(base));
    2977             :     }
    2978         557 :     out << "\n{\npublic:\n";
    2979         557 :     inc();
    2980        1114 :     out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
    2981         557 :         << "() SAL_THROW(());\n\n";
    2982         557 :     if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
    2983         557 :         out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(";
    2984         557 :         bool first = !dumpBaseMembers(out, base, true);
    2985        2661 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2986         557 :                  i(entity_->getDirectMembers().begin());
    2987        1774 :              i != entity_->getDirectMembers().end(); ++i)
    2988             :         {
    2989         330 :             if (!first) {
    2990         327 :                 out << ", ";
    2991             :             }
    2992         330 :             dumpType(out, i->type, true, true);
    2993         330 :             out << " " << i->name << "_";
    2994         330 :             first = false;
    2995             :         }
    2996         557 :         out << ") SAL_THROW(());\n\n";
    2997             :     }
    2998        1114 :     out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(" << id_
    2999        1671 :         << " const &);\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE ~"
    3000        1671 :         << id_ << "();\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
    3001        1114 :         << " & operator =(" << id_ << " const &);\n\n";
    3002        2661 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    3003         557 :              entity_->getDirectMembers().begin());
    3004        1774 :          i != entity_->getDirectMembers().end(); ++i)
    3005             :     {
    3006         330 :         out << indent();
    3007         330 :         dumpType(out, i->type);
    3008         330 :         out << " " << i->name;
    3009        1195 :         if (i == entity_->getDirectMembers().begin() && !base.isEmpty()
    3010         202 :             && i->type != "hyper" && i->type != "unsigned hyper"
    3011        1192 :             && i->type != "double")
    3012             :         {
    3013         202 :             out << " CPPU_GCC3_ALIGN( "
    3014         404 :                 << codemaker::cpp::scopedCppName(u2b(base)) << " )";
    3015             :         }
    3016         330 :         out << ";\n";
    3017             :     }
    3018         557 :     dec();
    3019         557 :     out << "};\n\n";
    3020         557 : }
    3021             : 
    3022        4524 : bool ExceptionType::dumpBaseMembers(
    3023             :     FileStream & out, OUString const & base, bool withType)
    3024             : {
    3025        4524 :     bool hasMember = false;
    3026        4524 :     if (!base.isEmpty()) {
    3027        2856 :         rtl::Reference< unoidl::Entity > ent;
    3028        2856 :         codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
    3029        2856 :         if (sort != codemaker::UnoType::SORT_EXCEPTION_TYPE) {
    3030             :             throw CannotDumpException(
    3031           0 :                 "exception type base " + base + " is not an exception type");
    3032             :         }
    3033             :         rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
    3034        5712 :             dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
    3035             :         assert(ent2.is());
    3036        2856 :         hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType);
    3037       20187 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    3038        2856 :                  i(ent2->getDirectMembers().begin());
    3039       13458 :              i != ent2->getDirectMembers().end(); ++i)
    3040             :         {
    3041        3873 :             if (hasMember) {
    3042        2211 :                 out << ", ";
    3043             :             }
    3044        3873 :             if (withType) {
    3045        2582 :                 dumpType(out, i->type, true, true);
    3046        2582 :                 out << " ";
    3047             :             }
    3048        3873 :             out << i->name << "_";
    3049        3873 :             hasMember = true;
    3050        2856 :         }
    3051             :     }
    3052        4524 :     return hasMember;
    3053             : }
    3054             : 
    3055         950 : sal_uInt32 ExceptionType::getTotalMemberCount(OUString const & base) const {
    3056         950 :     if (base.isEmpty()) {
    3057         352 :         return 0;
    3058             :     }
    3059         598 :     rtl::Reference< unoidl::Entity > ent;
    3060         598 :     codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
    3061         598 :     if (sort != codemaker::UnoType::SORT_EXCEPTION_TYPE) {
    3062             :         throw CannotDumpException(
    3063           0 :             "exception type base " + base + " is not an exception type");
    3064             :     }
    3065             :     rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
    3066        1196 :         dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
    3067             :     assert(ent2.is());
    3068        1196 :     return getTotalMemberCount(ent2->getDirectBase())
    3069        1196 :         + ent2->getDirectMembers().size(); //TODO: overflow
    3070             : }
    3071             : 
    3072         401 : class EnumType: public CppuType {
    3073             : public:
    3074         401 :     EnumType(
    3075             :         rtl::Reference< unoidl::EnumTypeEntity > const & entity,
    3076             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    3077         401 :         CppuType(name, typeMgr), entity_(entity)
    3078         401 :     { assert(entity.is()); }
    3079             : 
    3080             : private:
    3081             :     virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
    3082             : 
    3083             :     void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    3084             : 
    3085             :     void        dumpNormalGetCppuType(FileStream& o) SAL_OVERRIDE;
    3086             :     void        dumpComprehensiveGetCppuType(FileStream& o) SAL_OVERRIDE;
    3087             : 
    3088             :     rtl::Reference< unoidl::EnumTypeEntity > entity_;
    3089             : };
    3090             : 
    3091         401 : void EnumType::dumpDeclaration(FileStream& o)
    3092             : {
    3093         401 :     o << "\nenum " << id_ << "\n{\n";
    3094         401 :     inc();
    3095             : 
    3096        9402 :     for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
    3097         401 :              entity_->getMembers().begin());
    3098        6268 :          i != entity_->getMembers().end(); ++i)
    3099             :     {
    3100        5466 :         o << indent() << id_ << "_" << u2b(i->name) << " = " << i->value
    3101        2733 :           << ",\n";
    3102             :     }
    3103             : 
    3104         401 :     o << indent() << id_ << "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n";
    3105             : 
    3106         401 :     dec();
    3107         401 :     o << "};\n\n";
    3108         401 : }
    3109             : 
    3110         401 : void EnumType::dumpHxxFile(
    3111             :     FileStream& o, codemaker::cppumaker::Includes & includes)
    3112             : {
    3113         401 :     OUString headerDefine(dumpHeaderDefine(o, "HPP"));
    3114         401 :     o << "\n";
    3115             : 
    3116         401 :     addDefaultHxxIncludes(includes);
    3117         401 :     includes.dump(o, &name_);
    3118         401 :     o << "\n";
    3119             : 
    3120         401 :     dumpGetCppuType(o);
    3121             : 
    3122         401 :     o << "\n#endif // "<< headerDefine << "\n";
    3123         401 : }
    3124             : 
    3125           4 : void EnumType::dumpNormalGetCppuType(FileStream& o)
    3126             : {
    3127           4 :     dumpGetCppuTypePreamble(o);
    3128             : 
    3129           8 :     o << indent()
    3130           4 :       << "static typelib_TypeDescriptionReference * the_type = 0;\n";
    3131             : 
    3132           4 :     o << indent() << "if ( !the_type )\n" << indent() << "{\n";
    3133           4 :     inc();
    3134             : 
    3135           4 :     o << indent() << "typelib_static_enum_type_init( &the_type,\n";
    3136           4 :     inc(31);
    3137           8 :     o << indent() << "\"" << name_ << "\",\n"
    3138          12 :       << indent() << codemaker::cpp::scopedCppName(u2b(name_)) << "_"
    3139          12 :       << u2b(entity_->getMembers()[0].name) << " );\n";
    3140           4 :     dec(31);
    3141           4 :     dec();
    3142           4 :     o << indent() << "}\n";
    3143           8 :     o << indent()
    3144             :       << ("return * reinterpret_cast< ::css::uno::Type * >("
    3145           4 :           " &the_type );\n");
    3146           4 :     dumpGetCppuTypePostamble(o);
    3147           4 : }
    3148             : 
    3149         211 : void EnumType::dumpComprehensiveGetCppuType(FileStream& o)
    3150             : {
    3151         211 :     if (!isPolymorphic())
    3152         211 :         codemaker::cppumaker::dumpNamespaceOpen(o, name_, false);
    3153             :     else
    3154           0 :         o << "namespace cppu { ";
    3155         211 :     o << " namespace detail {\n\n";
    3156             : 
    3157         211 :     OUString sStaticTypeClass("the" + id_ + "Type");
    3158         211 :     o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::css::uno::Type *, " << sStaticTypeClass << " >\n";
    3159         211 :     o << indent() << "{\n";
    3160         211 :     inc();
    3161         211 :     o << indent() << "::css::uno::Type * operator()() const\n";
    3162         211 :     o << indent() << "{\n";
    3163             : 
    3164         211 :     inc();
    3165         422 :     o << indent() << "::rtl::OUString sTypeName( \"" << name_
    3166         211 :       << "\" );\n\n";
    3167             : 
    3168         422 :     o << indent() << "// Start inline typedescription generation\n"
    3169         633 :       << indent() << "typelib_TypeDescription * pTD = 0;\n\n";
    3170             : 
    3171         422 :     o << indent() << "rtl_uString* enumValueNames["
    3172         422 :       << entity_->getMembers().size() << "];\n";
    3173         211 :     std::vector< unoidl::EnumTypeEntity::Member >::size_type n = 0;
    3174        4959 :     for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
    3175         211 :              entity_->getMembers().begin());
    3176        3306 :          i != entity_->getMembers().end(); ++i)
    3177             :     {
    3178        2884 :         o << indent() << "::rtl::OUString sEnumValue" << n << "( \""
    3179        4326 :           << u2b(i->name) << "\" );\n";
    3180        2884 :         o << indent() << "enumValueNames[" << n << "] = sEnumValue" << n
    3181        1442 :           << ".pData;\n";
    3182        1442 :         ++n;
    3183             :     }
    3184             : 
    3185         422 :     o << "\n" << indent() << "sal_Int32 enumValues["
    3186         422 :       << entity_->getMembers().size() << "];\n";
    3187         211 :     n = 0;
    3188        4959 :     for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
    3189         211 :              entity_->getMembers().begin());
    3190        3306 :          i != entity_->getMembers().end(); ++i)
    3191             :     {
    3192        1442 :         o << indent() << "enumValues[" << n++ << "] = " << i->value << ";\n";
    3193             :     }
    3194             : 
    3195         211 :     o << "\n" << indent() << "typelib_typedescription_newEnum( &pTD,\n";
    3196         211 :     inc();
    3197         422 :     o << indent() << "sTypeName.pData,\n"
    3198         633 :       << indent() << "(sal_Int32)"
    3199         633 :       << codemaker::cpp::scopedCppName(u2b(name_), false) << "_"
    3200         633 :       << u2b(entity_->getMembers()[0].name) << ",\n"
    3201         633 :       << indent() << entity_->getMembers().size()
    3202         211 :       << ", enumValueNames, enumValues );\n\n";
    3203         211 :     dec();
    3204             : 
    3205         422 :     o << indent()
    3206             :       << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
    3207         211 :           " );\n");
    3208         422 :     o << indent() << "typelib_typedescription_release( pTD );\n"
    3209         633 :       << indent() << "// End inline typedescription generation\n\n";
    3210             : 
    3211         422 :     o << indent() << "return new ::css::uno::Type( "
    3212         633 :       << getTypeClass(name_) << ", sTypeName ); // leaked\n";
    3213             : 
    3214         211 :     dec();
    3215         211 :     o << indent() << "}\n";
    3216         211 :     dec();
    3217         211 :     o << indent() << "};\n\n";
    3218             : 
    3219         211 :     if (!isPolymorphic())
    3220         211 :         codemaker::cppumaker::dumpNamespaceClose(o, name_, false);
    3221             :     else
    3222           0 :         o << " }";
    3223         211 :     o << " }\n\n";
    3224             : 
    3225         211 :     dumpGetCppuTypePreamble(o);
    3226         211 :     o  << indent() << "return *detail::" << sStaticTypeClass << "::get();\n";
    3227         211 :     dumpGetCppuTypePostamble(o);
    3228         211 : }
    3229             : 
    3230          75 : class Typedef: public CppuType {
    3231             : public:
    3232          75 :     Typedef(
    3233             :         rtl::Reference< unoidl::TypedefEntity > const & entity,
    3234             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    3235          75 :         CppuType(name, typeMgr), entity_(entity)
    3236          75 :     { assert(entity.is()); }
    3237             : 
    3238             : private:
    3239             :     virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
    3240             : 
    3241             :     void dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    3242             : 
    3243             :     void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    3244             : 
    3245             :     rtl::Reference< unoidl::TypedefEntity > entity_;
    3246             : };
    3247             : 
    3248          75 : void Typedef::dumpHFile(
    3249             :     FileStream& o, codemaker::cppumaker::Includes & includes)
    3250             : {
    3251          75 :     OUString headerDefine(dumpHeaderDefine(o, "HDL"));
    3252          75 :     o << "\n";
    3253             : 
    3254          75 :     addDefaultHIncludes(includes);
    3255          75 :     includes.dump(o, 0);
    3256          75 :     o << "\n";
    3257             : 
    3258          75 :     if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
    3259          75 :         o << "\n";
    3260             :     }
    3261             : 
    3262          75 :     dumpDeclaration(o);
    3263             : 
    3264          75 :     if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
    3265          75 :         o << "\n";
    3266             :     }
    3267             : 
    3268          75 :     o << "#endif // "<< headerDefine << "\n";
    3269          75 : }
    3270             : 
    3271          75 : void Typedef::dumpDeclaration(FileStream& o)
    3272             : {
    3273          75 :     o << "\ntypedef ";
    3274          75 :     dumpType(o, entity_->getType());
    3275          75 :     o << " " << id_ << ";\n\n";
    3276          75 : }
    3277             : 
    3278          75 : void Typedef::dumpHxxFile(
    3279             :     FileStream& o, codemaker::cppumaker::Includes & includes)
    3280             : {
    3281          75 :     OUString headerDefine(dumpHeaderDefine(o, "HPP"));
    3282          75 :     o << "\n";
    3283             : 
    3284          75 :     addDefaultHxxIncludes(includes);
    3285          75 :     includes.dump(o, &name_);
    3286          75 :     o << "\n";
    3287             : 
    3288          75 :     o << "\n#endif // "<< headerDefine << "\n";
    3289          75 : }
    3290             : 
    3291        1074 : class ConstructiveType: public CppuType {
    3292             : public:
    3293        1074 :     ConstructiveType(
    3294             :         OUString const & name, rtl::Reference< TypeManager > const & manager):
    3295        1074 :         CppuType(name, manager) {}
    3296             : 
    3297             : private:
    3298           0 :     virtual void dumpHFile(FileStream &, codemaker::cppumaker::Includes &) SAL_OVERRIDE
    3299           0 :     { assert(false); } // this cannot happen
    3300             : 
    3301        1074 :     virtual void dumpFiles(OUString const & uri, CppuOptions const & options) SAL_OVERRIDE
    3302        1074 :     { dumpFile(uri, name_, true, options); }
    3303             : };
    3304             : 
    3305         842 : bool hasRestParameter(
    3306             :     unoidl::SingleInterfaceBasedServiceEntity::Constructor const & constructor)
    3307             : {
    3308         842 :     return !constructor.parameters.empty()
    3309         842 :         && constructor.parameters.back().rest;
    3310             : }
    3311             : 
    3312         446 : void includeExceptions(
    3313             :     codemaker::cppumaker::Includes & includes,
    3314             :     codemaker::ExceptionTreeNode const * node)
    3315             : {
    3316         446 :     if (node->present) {
    3317          30 :         includes.add(node->name);
    3318             :     } else {
    3319        1344 :         for (codemaker::ExceptionTreeNode::Children::const_iterator i(
    3320         416 :                  node->children.begin());
    3321         896 :              i != node->children.end(); ++i)
    3322             :         {
    3323          32 :             includeExceptions(includes, *i);
    3324             :         }
    3325             :     }
    3326         446 : }
    3327             : 
    3328         861 : class ServiceType: public ConstructiveType {
    3329             : public:
    3330         861 :     ServiceType(
    3331             :         rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const &
    3332             :             entity,
    3333             :         OUString const & name, rtl::Reference< TypeManager > const & manager):
    3334         861 :         ConstructiveType(name, manager), entity_(entity)
    3335         861 :     { assert(entity.is()); }
    3336             : 
    3337             : private:
    3338             :     virtual void dumpHxxFile(
    3339             :         FileStream & o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    3340             : 
    3341             :     void dumpCatchClauses(
    3342             :         FileStream & out, codemaker::ExceptionTreeNode const * node);
    3343             : 
    3344             :     rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > entity_;
    3345             : };
    3346             : 
    3347         861 : void ServiceType::dumpHxxFile(
    3348             :     FileStream & o, codemaker::cppumaker::Includes & includes)
    3349             : {
    3350         861 :     if (!entity_->getConstructors().empty()) {
    3351             :         //TODO: Decide whether the types added to includes should rather be
    3352             :         // added to m_dependencies (and thus be generated during
    3353             :         // dumpDependedTypes):
    3354         823 :         includes.addCassert();
    3355         823 :         includes.addReference();
    3356         823 :         includes.addRtlUstringH();
    3357         823 :         includes.addRtlUstringHxx();
    3358         823 :         includes.add("com.sun.star.uno.DeploymentException");
    3359         823 :         includes.add("com.sun.star.uno.XComponentContext");
    3360        5217 :         for (std::vector<
    3361             :                  unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
    3362         823 :                  const_iterator i(entity_->getConstructors().begin());
    3363        3478 :              i != entity_->getConstructors().end(); ++i)
    3364             :         {
    3365         916 :             if (i->defaultConstructor) {
    3366         495 :                 includes.add("com.sun.star.uno.Exception");
    3367         495 :                 includes.add("com.sun.star.uno.RuntimeException");
    3368             :             } else {
    3369         421 :                 if (!hasRestParameter(*i)) {
    3370         419 :                     includes.addAny();
    3371         419 :                     includes.addSequence();
    3372        3051 :                     for (std::vector<
    3373             :                              unoidl::SingleInterfaceBasedServiceEntity::
    3374             :                              Constructor::Parameter >::const_iterator j(
    3375         419 :                                  i->parameters.begin());
    3376        2034 :                          j != i->parameters.end(); ++j)
    3377             :                     {
    3378        1200 :                         if (m_typeMgr->getSort(
    3379             :                                 b2u(codemaker::UnoType::decompose(
    3380        1200 :                                         u2b(j->type), 0, 0)))
    3381             :                             == codemaker::UnoType::SORT_CHAR)
    3382             :                         {
    3383           2 :                             includes.addCppuUnotypeHxx();
    3384           2 :                             break;
    3385             :                         }
    3386             :                     }
    3387             :                 }
    3388         421 :                 codemaker::ExceptionTree tree;
    3389        1611 :                 for (std::vector< OUString >::const_iterator j(
    3390         421 :                          i->exceptions.begin());
    3391        1074 :                      j != i->exceptions.end(); ++j)
    3392             :                 {
    3393         116 :                     tree.add(u2b(*j), m_typeMgr);
    3394             :                 }
    3395         421 :                 if (!tree.getRoot()->present) {
    3396         414 :                     includes.add("com.sun.star.uno.Exception");
    3397         414 :                     includes.add("com.sun.star.uno.RuntimeException");
    3398         414 :                     includeExceptions(includes, tree.getRoot());
    3399         421 :                 }
    3400             :             }
    3401             :         }
    3402             :     }
    3403             :     OString cppName(
    3404             :         codemaker::cpp::translateUnoToCppIdentifier(
    3405         861 :             u2b(id_), "service", isGlobal()));
    3406        1722 :     OUString headerDefine(dumpHeaderDefine(o, "HPP"));
    3407         861 :     o << "\n";
    3408         861 :     includes.dump(o, 0);
    3409         861 :     if (!entity_->getConstructors().empty()) {
    3410             :         o << ("\n#if defined ANDROID || defined IOS //TODO\n"
    3411             :               "#include <com/sun/star/lang/XInitialization.hpp>\n"
    3412             :               "#include <osl/detail/component-defines.h>\n#endif\n\n"
    3413         823 :               "#if defined LO_URE_CURRENT_ENV && defined LO_URE_CTOR_ENV_")
    3414        2469 :           << name_.replaceAll(".", "_dot_")
    3415         823 :           << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3416        2469 :           << name_.replaceAll(".", "_dot_") << ") && defined LO_URE_CTOR_FUN_"
    3417        2469 :           << name_.replaceAll(".", "_dot_")
    3418         823 :           << "\nextern \"C\" ::css::uno::XInterface * SAL_CALL LO_URE_CTOR_FUN_"
    3419        2469 :           << name_.replaceAll(".", "_dot_")
    3420             :           << "(::css::uno::XComponentContext *, ::css::uno::Sequence< "
    3421         823 :              "::css::uno::Any > const &);\n#endif\n";
    3422             :     }
    3423         861 :     o << "\n";
    3424         861 :     if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
    3425         861 :         o << "\n";
    3426             :     }
    3427         861 :     o << "\nclass " << cppName << " {\n";
    3428         861 :     inc();
    3429         861 :     if (!entity_->getConstructors().empty()) {
    3430         823 :         OString baseName(u2b(entity_->getBase()));
    3431        1646 :         OString scopedBaseName(codemaker::cpp::scopedCppName(baseName));
    3432         823 :         o << "public:\n";
    3433        5217 :         for (std::vector<
    3434             :                  unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
    3435         823 :                  const_iterator i(entity_->getConstructors().begin());
    3436        3478 :              i != entity_->getConstructors().end(); ++i)
    3437             :         {
    3438         916 :             if (i->defaultConstructor) {
    3439         990 :                 o << indent() << "static ::css::uno::Reference< "
    3440         495 :                   << scopedBaseName << " > "
    3441             :                   << codemaker::cpp::translateUnoToCppIdentifier(
    3442             :                       "create", "method", codemaker::cpp::ITM_NONGLOBAL,
    3443        1485 :                       &cppName)
    3444             :                   << ("(::css::uno::Reference< ::css::uno::XComponentContext > const &"
    3445         495 :                       " the_context) {\n");
    3446         495 :                 inc();
    3447         990 :                 o << indent() << "assert(the_context.is());\n" << indent()
    3448         495 :                   << "::css::uno::Reference< " << scopedBaseName
    3449        1485 :                   << " > the_instance;\n" << indent() << "try {\n";
    3450         495 :                 inc();
    3451             :                 o << ("#if defined LO_URE_CURRENT_ENV && defined "
    3452         495 :                       "LO_URE_CTOR_ENV_")
    3453        1485 :                   << name_.replaceAll(".", "_dot_")
    3454         495 :                   << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3455        1485 :                   << name_.replaceAll(".", "_dot_")
    3456         495 :                   << ") && defined LO_URE_CTOR_FUN_"
    3457        1485 :                   << name_.replaceAll(".", "_dot_") << "\n" << indent()
    3458         495 :                   << "the_instance = ::css::uno::Reference< " << scopedBaseName
    3459             :                   << (" >(::css::uno::Reference< ::css::uno::XInterface >("
    3460             :                       "static_cast< ::css::uno::XInterface * >((*"
    3461         495 :                       "LO_URE_CTOR_FUN_")
    3462        1485 :                   << name_.replaceAll(".", "_dot_")
    3463             :                   << (")(the_context.get(), ::css::uno::Sequence<"
    3464             :                       " ::css::uno::Any >())), ::SAL_NO_ACQUIRE),"
    3465         495 :                       " ::css::uno::UNO_QUERY);\n#else\n")
    3466        1485 :                   << indent() << "the_instance = ::css::uno::Reference< "
    3467         495 :                   << scopedBaseName
    3468             :                   << (" >(the_context->getServiceManager()->"
    3469             :                       "createInstanceWithContext(::rtl::OUString("
    3470         495 :                       " \"")
    3471         990 :                   << name_
    3472         495 :                   << "\" ), the_context), ::css::uno::UNO_QUERY);\n#endif\n";
    3473         495 :                 dec();
    3474         990 :                 o << indent()
    3475         495 :                   << "} catch (const ::css::uno::RuntimeException &) {\n";
    3476         495 :                 inc();
    3477         495 :                 o << indent() << "throw;\n";
    3478         495 :                 dec();
    3479         990 :                 o << indent()
    3480         495 :                   << ("} catch (const ::css::uno::Exception & the_exception) {\n");
    3481         495 :                 inc();
    3482         990 :                 o << indent()
    3483             :                   << ("throw ::css::uno::DeploymentException("
    3484             :                       "::rtl::OUString( "
    3485         495 :                       "\"component context fails to supply service \" ) + ")
    3486         990 :                   << "\"" << name_ << "\" + "
    3487         495 :                   << "\" of type \" + "
    3488         495 :                   << "\"" << baseName << "\" + "
    3489         495 :                   << "\": \" + the_exception.Message, the_context);\n";
    3490         495 :                 dec();
    3491         990 :                 o << indent() << "}\n" << indent()
    3492         495 :                   << "if (!the_instance.is()) {\n";
    3493         495 :                 inc();
    3494         990 :                 o << indent()
    3495             :                   << ("throw ::css::uno::DeploymentException("
    3496             :                       "::rtl::OUString( "
    3497         495 :                       "\"component context fails to supply service \" ) + ")
    3498         990 :                   << "\"" << name_ << "\" + "
    3499         495 :                   << "\" of type \" + "
    3500         495 :                   << "\"" << baseName << "\""
    3501         495 :                   << ", the_context);\n";
    3502         495 :                 dec();
    3503         495 :                 o << indent() << "}\n" << indent() << "return the_instance;\n";
    3504         495 :                 dec();
    3505         495 :                 o << indent() << "}\n\n";
    3506             :             } else {
    3507         842 :                 o << indent() << "static ::css::uno::Reference< "
    3508         421 :                   << scopedBaseName << " > "
    3509             :                   << codemaker::cpp::translateUnoToCppIdentifier(
    3510         421 :                       u2b(i->name), "method", codemaker::cpp::ITM_NONGLOBAL,
    3511        1684 :                       &cppName)
    3512             :                   << ("(::css::uno::Reference< ::css::uno::XComponentContext > const &"
    3513         421 :                       " the_context");
    3514         421 :                 bool rest = hasRestParameter(*i);
    3515        3327 :                 for (std::vector<
    3516             :                          unoidl::SingleInterfaceBasedServiceEntity::Constructor::
    3517         421 :                          Parameter >::const_iterator j(i->parameters.begin());
    3518        2218 :                      j != i->parameters.end(); ++j)
    3519             :                 {
    3520         688 :                     o << ", ";
    3521         688 :                     OUStringBuffer buf;
    3522         688 :                     if (j->rest) {
    3523           2 :                         buf.append("[]");
    3524             :                     }
    3525         688 :                     buf.append(j->type);
    3526        1376 :                     OUString type(buf.makeStringAndClear());
    3527         688 :                     bool byRef = passByReference(type);
    3528         688 :                     dumpType(o, type, byRef, byRef);
    3529         688 :                     o << " "
    3530             :                       << codemaker::cpp::translateUnoToCppIdentifier(
    3531        1376 :                           u2b(j->name), "param", codemaker::cpp::ITM_NONGLOBAL);
    3532         688 :                 }
    3533         421 :                 o << ") {\n";
    3534         421 :                 inc();
    3535         421 :                 o << indent() << "assert(the_context.is());\n";
    3536         421 :                 if (!rest && !i->parameters.empty()) {
    3537         730 :                     o << indent()
    3538         365 :                       << ("::css::uno::Sequence< ::css::uno::Any > the_arguments(")
    3539         730 :                       << i->parameters.size() << ");\n";
    3540             :                     std::vector<
    3541             :                         unoidl::SingleInterfaceBasedServiceEntity::Constructor::
    3542         365 :                         Parameter >::size_type n = 0;
    3543        3153 :                     for (std::vector<
    3544             :                              unoidl::SingleInterfaceBasedServiceEntity::
    3545             :                              Constructor::Parameter >::const_iterator j(
    3546         365 :                                  i->parameters.begin());
    3547        2102 :                          j != i->parameters.end(); ++j)
    3548             :                     {
    3549         686 :                         o << indent() << "the_arguments[" << n++ << "] ";
    3550             :                         OString param(
    3551             :                             codemaker::cpp::translateUnoToCppIdentifier(
    3552         686 :                                 u2b(j->name), "param",
    3553        1372 :                                 codemaker::cpp::ITM_NONGLOBAL));
    3554             :                         sal_Int32 rank;
    3555        1372 :                         if (m_typeMgr->getSort(
    3556             :                                 b2u(codemaker::UnoType::decompose(
    3557        1372 :                                         u2b(j->type), &rank, 0)))
    3558             :                             == codemaker::UnoType::SORT_CHAR)
    3559             :                         {
    3560           4 :                             o << "= ::css::uno::Any(&" << param
    3561           4 :                               << ", ::cppu::UnoType< ";
    3562           7 :                             for (sal_Int32 k = 0; k < rank; ++k) {
    3563           3 :                                 o << "::cppu::UnoSequenceType< ";
    3564             :                             }
    3565           4 :                             o << "::cppu::UnoCharType";
    3566           7 :                             for (sal_Int32 k = 0; k < rank; ++k) {
    3567           3 :                                 o << " >";
    3568             :                             }
    3569           4 :                             o << " >::get())";
    3570             :                         } else {
    3571         682 :                             o << "<<= " << param;
    3572             :                         }
    3573         686 :                         o << ";\n";
    3574         686 :                     }
    3575             :                 }
    3576         842 :                 o << indent() << "::css::uno::Reference< "
    3577         421 :                   << scopedBaseName << " > the_instance;\n";
    3578         421 :                 codemaker::ExceptionTree tree;
    3579        1611 :                 for (std::vector< OUString >::const_iterator j(
    3580         421 :                          i->exceptions.begin());
    3581        1074 :                      j != i->exceptions.end(); ++j)
    3582             :                 {
    3583         116 :                     tree.add(u2b(*j), m_typeMgr);
    3584             :                 }
    3585         421 :                 if (!tree.getRoot()->present) {
    3586         414 :                     o << indent() << "try {\n";
    3587         414 :                     inc();
    3588             :                 }
    3589             :                 o << ("#if defined LO_URE_CURRENT_ENV && defined "
    3590         421 :                       "LO_URE_CTOR_ENV_")
    3591        1263 :                   << name_.replaceAll(".", "_dot_")
    3592         421 :                   << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3593        1263 :                   << name_.replaceAll(".", "_dot_")
    3594         421 :                   << ") && defined LO_URE_CTOR_FUN_"
    3595        1263 :                   << name_.replaceAll(".", "_dot_") << "\n" << indent()
    3596         421 :                   << "the_instance = ::css::uno::Reference< " << scopedBaseName
    3597             :                   << (" >(::css::uno::Reference< ::css::uno::XInterface >("
    3598             :                       "static_cast< ::css::uno::XInterface * >((*"
    3599         421 :                       "LO_URE_CTOR_FUN_")
    3600        1263 :                   << name_.replaceAll(".", "_dot_")
    3601         421 :                   << ")(the_context.get(), ";
    3602         421 :                 if (rest) {
    3603             :                     o << codemaker::cpp::translateUnoToCppIdentifier(
    3604           2 :                         u2b(i->parameters.back().name), "param",
    3605           4 :                         codemaker::cpp::ITM_NONGLOBAL);
    3606         419 :                 } else if (i->parameters.empty()) {
    3607          54 :                     o << "::css::uno::Sequence< ::css::uno::Any >()";
    3608             :                 } else {
    3609         365 :                     o << "the_arguments";
    3610             :                 }
    3611         842 :                 o << ")), ::SAL_NO_ACQUIRE), ::css::uno::UNO_QUERY);\n" << indent()
    3612             :                   << ("::css::uno::Reference< ::css::lang::XInitialization > "
    3613         421 :                       "init(the_instance, ::css::uno::UNO_QUERY);\n")
    3614        1263 :                   << indent() << "if (init.is()) {\n"
    3615        1263 :                   << indent() << "    init->initialize(";
    3616         421 :                 if (i->parameters.empty()) {
    3617          54 :                     o << "::css::uno::Sequence< ::css::uno::Any >()";
    3618             :                 } else {
    3619         367 :                     o << "the_arguments";
    3620             :                 }
    3621         421 :                 o << ");\n" << indent() << "}\n";
    3622         421 :                 o << ("#else\n")
    3623        1263 :                   << indent() << "the_instance = ::css::uno::Reference< "
    3624         421 :                   << scopedBaseName
    3625             :                   << (" >(the_context->getServiceManager()->"
    3626             :                       "createInstanceWithArgumentsAndContext(::rtl::OUString("
    3627         421 :                       " \"")
    3628         842 :                   << name_ << "\" ), ";
    3629         421 :                 if (rest) {
    3630             :                     o << codemaker::cpp::translateUnoToCppIdentifier(
    3631           2 :                         u2b(i->parameters.back().name), "param",
    3632           4 :                         codemaker::cpp::ITM_NONGLOBAL);
    3633         419 :                 } else if (i->parameters.empty()) {
    3634          54 :                     o << ("::css::uno::Sequence< ::css::uno::Any >()");
    3635             :                 } else {
    3636         365 :                     o << "the_arguments";
    3637             :                 }
    3638         421 :                 o << ", the_context), ::css::uno::UNO_QUERY);\n#endif\n";
    3639         421 :                 if (!tree.getRoot()->present) {
    3640         414 :                     dec();
    3641         828 :                     o << indent()
    3642         414 :                       << ("} catch (const ::css::uno::RuntimeException &) {\n");
    3643         414 :                     inc();
    3644         414 :                     o << indent() << "throw;\n";
    3645         414 :                     dec();
    3646         414 :                     dumpCatchClauses(o, tree.getRoot());
    3647         828 :                     o << indent()
    3648             :                       << ("} catch (const ::css::uno::Exception &"
    3649         414 :                           " the_exception) {\n");
    3650         414 :                     inc();
    3651         828 :                     o << indent()
    3652             :                       << ("throw ::css::uno::DeploymentException("
    3653             :                           "::rtl::OUString( "
    3654         414 :                           "\"component context fails to supply service ")
    3655         828 :                       << name_ << " of type " << baseName
    3656         414 :                       << ": \" ) + the_exception.Message, the_context);\n";
    3657         414 :                     dec();
    3658         414 :                     o << indent() << "}\n";
    3659             :                 }
    3660         421 :                 o << indent() << "if (!the_instance.is()) {\n";
    3661         421 :                 inc();
    3662         842 :                 o << indent()
    3663             :                   << ("throw ::css::uno::DeploymentException("
    3664             :                       "::rtl::OUString( "
    3665         421 :                       "\"component context fails to supply service ")
    3666         842 :                   << name_ << " of type " << baseName
    3667         421 :                   << "\" ), the_context);\n";
    3668         421 :                 dec();
    3669         421 :                 o << indent() << "}\n" << indent() << "return the_instance;\n";
    3670         421 :                 dec();
    3671         421 :                 o << indent() << "}\n\n";
    3672             :             }
    3673         823 :         }
    3674             :     }
    3675         861 :     o << "private:\n";
    3676        1722 :     o << indent() << cppName << "(); // not implemented\n"
    3677        2583 :       << indent() << cppName << "(" << cppName << " &); // not implemented\n"
    3678        2583 :       << indent() << "~" << cppName << "(); // not implemented\n"
    3679        2583 :       << indent() << "void operator =(" << cppName << "); // not implemented\n";
    3680         861 :     dec();
    3681         861 :     o << "};\n\n";
    3682         861 :     if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
    3683         861 :         o << "\n";
    3684             :     }
    3685        1722 :     o << "\n#endif // "<< headerDefine << "\n";
    3686         861 : }
    3687             : 
    3688         446 : void ServiceType::dumpCatchClauses(
    3689             :     FileStream & out, codemaker::ExceptionTreeNode const * node)
    3690             : {
    3691         446 :     if (node->present) {
    3692          30 :         out << indent() << "} catch (const ";
    3693          30 :         dumpType(out, b2u(node->name));
    3694          30 :         out << " &) {\n";
    3695          30 :         inc();
    3696          30 :         out << indent() << "throw;\n";
    3697          30 :         dec();
    3698             :     } else {
    3699        1344 :         for (codemaker::ExceptionTreeNode::Children::const_iterator i(
    3700         416 :                  node->children.begin());
    3701         896 :              i != node->children.end(); ++i)
    3702             :         {
    3703          32 :             dumpCatchClauses(out, *i);
    3704             :         }
    3705             :     }
    3706         446 : }
    3707             : 
    3708         213 : class SingletonType: public ConstructiveType {
    3709             : public:
    3710         213 :     SingletonType(
    3711             :         rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity,
    3712             :         OUString const & name, rtl::Reference< TypeManager > const & manager):
    3713         213 :         ConstructiveType(name, manager), entity_(entity)
    3714         213 :     { assert(entity.is()); }
    3715             : 
    3716             : private:
    3717             :     virtual void dumpHxxFile(
    3718             :         FileStream & o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
    3719             : 
    3720             :     rtl::Reference< unoidl::InterfaceBasedSingletonEntity > entity_;
    3721             : };
    3722             : 
    3723         213 : void SingletonType::dumpHxxFile(
    3724             :     FileStream & o, codemaker::cppumaker::Includes & includes)
    3725             : {
    3726             :     OString cppName(
    3727             :         codemaker::cpp::translateUnoToCppIdentifier(
    3728         213 :             u2b(id_), "singleton", isGlobal()));
    3729         426 :     OString baseName(u2b(entity_->getBase()));
    3730         426 :     OString scopedBaseName(codemaker::cpp::scopedCppName(baseName));
    3731         426 :     OUString headerDefine(dumpHeaderDefine(o, "HPP"));
    3732         213 :     o << "\n";
    3733             :     //TODO: Decide whether the types added to includes should rather be added to
    3734             :     // m_dependencies (and thus be generated during dumpDependedTypes):
    3735         213 :     includes.add("com.sun.star.uno.DeploymentException");
    3736         213 :     includes.add("com.sun.star.uno.XComponentContext");
    3737         213 :     includes.addCassert();
    3738         213 :     includes.addAny();
    3739         213 :     includes.addReference();
    3740         213 :     includes.addRtlUstringH();
    3741         213 :     includes.addRtlUstringHxx();
    3742         213 :     includes.dump(o, 0);
    3743             :     o << ("\n#if defined ANDROID || defined IOS //TODO\n"
    3744             :           "#include <com/sun/star/lang/XInitialization.hpp>\n"
    3745             :           "#include <osl/detail/component-defines.h>\n#endif\n\n"
    3746         213 :           "#if defined LO_URE_CURRENT_ENV && defined LO_URE_CTOR_ENV_")
    3747         639 :       << name_.replaceAll(".", "_dot_")
    3748         213 :       << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3749         639 :       << name_.replaceAll(".", "_dot_") << ") && defined LO_URE_CTOR_FUN_"
    3750         639 :       << name_.replaceAll(".", "_dot_")
    3751         213 :       << "\nextern \"C\" ::css::uno::XInterface * SAL_CALL LO_URE_CTOR_FUN_"
    3752         639 :       << name_.replaceAll(".", "_dot_")
    3753             :       << "(::css::uno::XComponentContext *, ::css::uno::Sequence< "
    3754         213 :          "::css::uno::Any > const &);\n#endif\n";
    3755         213 :     o << "\n";
    3756         213 :     if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
    3757         209 :         o << "\n";
    3758             :     }
    3759         213 :     o << "\nclass " << cppName << " {\npublic:\n";
    3760         213 :     inc();
    3761         426 :     o << indent() << "static ::css::uno::Reference< "
    3762         213 :       << scopedBaseName << " > "
    3763             :       << codemaker::cpp::translateUnoToCppIdentifier(
    3764         639 :           "get", "method", codemaker::cpp::ITM_NONGLOBAL, &cppName)
    3765             :       << ("(::css::uno::Reference<"
    3766             :           " ::css::uno::XComponentContext > const & the_context)"
    3767         213 :           " {\n");
    3768         213 :     inc();
    3769         426 :     o << indent() << "assert(the_context.is());\n" << indent()
    3770         213 :       << "::css::uno::Reference< " << scopedBaseName
    3771         213 :       << " > instance;\n"
    3772             :       << ("#if defined LO_URE_CURRENT_ENV && defined "
    3773         213 :           "LO_URE_CTOR_ENV_")
    3774         639 :       << name_.replaceAll(".", "_dot_")
    3775         213 :       << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3776         639 :       << name_.replaceAll(".", "_dot_")
    3777         213 :       << ") && defined LO_URE_CTOR_FUN_"
    3778         639 :       << name_.replaceAll(".", "_dot_") << "\n" << indent()
    3779         213 :       << "instance = ::css::uno::Reference< " << scopedBaseName
    3780             :       << (" >(::css::uno::Reference< ::css::uno::XInterface >("
    3781             :           "static_cast< ::css::uno::XInterface * >((*"
    3782         213 :           "LO_URE_CTOR_FUN_")
    3783         639 :       << name_.replaceAll(".", "_dot_")
    3784             :       << (")(the_context.get(), ::css::uno::Sequence<"
    3785             :           " ::css::uno::Any >())), ::SAL_NO_ACQUIRE),"
    3786         213 :                       " ::css::uno::UNO_QUERY);\n#else\n")
    3787         639 :       << indent() << ("the_context->getValueByName("
    3788         213 :           "::rtl::OUString( \"/singletons/")
    3789         426 :       << name_ << "\" )) >>= instance;\n" << "#endif\n"
    3790         639 :       << indent() << "if (!instance.is()) {\n";
    3791         213 :     inc();
    3792         426 :     o << indent()
    3793             :       << ("throw ::css::uno::DeploymentException("
    3794             :           "::rtl::OUString( \"component context"
    3795         213 :           " fails to supply singleton ")
    3796         426 :       << name_ << " of type " << baseName << "\" ), the_context);\n";
    3797         213 :     dec();
    3798         213 :     o << indent() << "}\n" << indent() << "return instance;\n";
    3799         213 :     dec();
    3800         213 :     o << indent() << "}\n\n";
    3801         213 :     o << "private:\n";
    3802         426 :     o << indent() << cppName << "(); // not implemented\n"
    3803         639 :       << indent() << cppName << "(" << cppName << " &); // not implemented\n"
    3804         639 :       << indent() << "~" << cppName << "(); // not implemented\n"
    3805         639 :       << indent() << "void operator =(" << cppName << "); // not implemented\n";
    3806         213 :     dec();
    3807         213 :     o << "};\n\n";
    3808         213 :     if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
    3809         209 :         o << "\n";
    3810             :     }
    3811         426 :     o << "\n#endif // "<< headerDefine << "\n";
    3812         213 : }
    3813             : 
    3814             : }
    3815             : 
    3816       28700 : void produce(
    3817             :     OUString const & name, rtl::Reference< TypeManager > const & manager,
    3818             :     codemaker::GeneratedTypeSet & generated, CppuOptions const & options)
    3819             : {
    3820       28700 :     if (generated.contains(u2b(name))) {
    3821       35224 :         return;
    3822             :     }
    3823       11471 :     generated.add(u2b(name));
    3824       11471 :     if (!manager->foundAtPrimaryProvider(name)) {
    3825         766 :         return;
    3826             :     }
    3827       10705 :     rtl::Reference< unoidl::Entity > ent;
    3828       21410 :     rtl::Reference< unoidl::MapCursor > cur;
    3829       10705 :     switch (manager->getSort(name, &ent, &cur)) {
    3830             :     case codemaker::UnoType::SORT_MODULE:
    3831             :         {
    3832         319 :             OUString prefix;
    3833         319 :             if (!name.isEmpty()) {
    3834         308 :                 prefix = name + ".";
    3835             :             }
    3836             :             for (;;) {
    3837       11565 :                 OUString mem;
    3838       11565 :                 if (!cur->getNext(&mem).is()) {
    3839         319 :                     break;
    3840             :                 }
    3841       11246 :                 produce(prefix + mem, manager, generated, options);
    3842       11246 :             }
    3843         319 :             break;
    3844             :         }
    3845             :     case codemaker::UnoType::SORT_ENUM_TYPE:
    3846             :         {
    3847             :             EnumType t(
    3848         401 :                 dynamic_cast< unoidl::EnumTypeEntity * >(ent.get()), name,
    3849         401 :                 manager);
    3850         401 :             t.dump(options);
    3851         401 :             t.dumpDependedTypes(generated, options);
    3852         401 :             break;
    3853             :         }
    3854             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
    3855             :         {
    3856             :             PlainStructType t(
    3857         831 :                 dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()),
    3858         831 :                 name, manager);
    3859         831 :             t.dump(options);
    3860         831 :             t.dumpDependedTypes(generated, options);
    3861         831 :             break;
    3862             :         }
    3863             :     case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
    3864             :         {
    3865             :             PolyStructType t(
    3866             :                 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
    3867          16 :                     ent.get()),
    3868          16 :                 name, manager);
    3869          16 :             t.dump(options);
    3870          16 :             t.dumpDependedTypes(generated, options);
    3871          16 :             break;
    3872             :         }
    3873             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
    3874             :         {
    3875             :             ExceptionType t(
    3876         557 :                 dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()), name,
    3877         557 :                 manager);
    3878         557 :             t.dump(options);
    3879         557 :             t.dumpDependedTypes(generated, options);
    3880         557 :             break;
    3881             :         }
    3882             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
    3883             :         {
    3884             :             InterfaceType t(
    3885        3817 :                 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()), name,
    3886        3817 :                 manager);
    3887        3817 :             t.dump(options);
    3888        3817 :             t.dumpDependedTypes(generated, options);
    3889        3817 :             break;
    3890             :         }
    3891             :     case codemaker::UnoType::SORT_TYPEDEF:
    3892             :         {
    3893             :             Typedef t(
    3894          75 :                 dynamic_cast< unoidl::TypedefEntity * >(ent.get()), name,
    3895          75 :                 manager);
    3896          75 :             t.dump(options);
    3897          75 :             t.dumpDependedTypes(generated, options);
    3898          75 :             break;
    3899             :         }
    3900             :     case codemaker::UnoType::SORT_CONSTANT_GROUP:
    3901             :         {
    3902             :             ConstantGroup t(
    3903        1537 :                 dynamic_cast< unoidl::ConstantGroupEntity * >(ent.get()), name,
    3904        1537 :                 manager);
    3905        1537 :             if (t.hasConstants()) {
    3906        1537 :                 t.dump(options);
    3907             :             }
    3908        1537 :             break;
    3909             :         }
    3910             :     case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
    3911             :         {
    3912             :             ServiceType t(
    3913             :                 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
    3914         861 :                     ent.get()),
    3915         861 :                 name, manager);
    3916         861 :             t.dump(options);
    3917         861 :             t.dumpDependedTypes(generated, options);
    3918         861 :             break;
    3919             :         }
    3920             :     case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
    3921             :         {
    3922             :             SingletonType t(
    3923             :                 dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
    3924         213 :                     ent.get()),
    3925         213 :                 name, manager);
    3926         213 :             t.dump(options);
    3927         213 :             t.dumpDependedTypes(generated, options);
    3928         213 :             break;
    3929             :         }
    3930             :     case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
    3931             :     case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
    3932        2078 :         break;
    3933             :     default:
    3934             :         throw CannotDumpException(
    3935           0 :             "unexpected entity \"" + name + "\" in call to produce");
    3936       10705 :     }
    3937             : }
    3938             : 
    3939             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10