LCOV - code coverage report
Current view: top level - codemaker/source/cppumaker - cpputype.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 2419 0.0 %
Date: 2014-04-14 Functions: 0 144 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "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           0 : 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           0 :     for (std::size_t i = 0; i < SAL_N_ELEMENTS(names); ++i) {
     141           0 :         if (name.equalsAscii(names[i])) {
     142           0 :             return true;
     143             :         }
     144             :     }
     145           0 :     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           0 :     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           0 :     virtual void dumpHFile(
     165             :         FileStream & out, codemaker::cppumaker::Includes & includes)
     166           0 :     { 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           0 :     virtual void dumpTemplateHead(FileStream &) const {}
     226             : 
     227           0 :     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           0 : 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           0 :     , id_(name_.copy(name_.lastIndexOf('.') + 1))
     266             :     , m_typeMgr(typeMgr)
     267           0 :     , m_dependencies(typeMgr, name_)
     268           0 : {}
     269             : 
     270           0 : void CppuType::addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes)
     271             :     const
     272             : {
     273           0 :     if (name_ == "com.sun.star.uno.XInterface"
     274           0 :         || name_ == "com.sun.star.uno.Exception")
     275             :     {
     276           0 :         includes.addType();
     277           0 :         includes.addCppuUnotypeHxx();
     278           0 :         includes.addSalTypesH();
     279           0 :         includes.addTypelibTypeclassH();
     280           0 :         includes.addTypelibTypedescriptionH();
     281           0 :     } else if (m_cppuTypeLeak) {
     282           0 :         addLightGetCppuTypeIncludes(includes);
     283           0 :     } else if (m_cppuTypeDynamic) {
     284           0 :         addNormalGetCppuTypeIncludes(includes);
     285             :     } else {
     286           0 :         addComprehensiveGetCppuTypeIncludes(includes);
     287             :     }
     288           0 : }
     289             : 
     290           0 : void CppuType::dumpFiles(OUString const & uri, CppuOptions const & options) {
     291           0 :     dumpFile(uri, name_, false, options);
     292           0 :     dumpFile(uri, name_, true, options);
     293           0 : }
     294             : 
     295           0 : void CppuType::addLightGetCppuTypeIncludes(
     296             :     codemaker::cppumaker::Includes & includes) const
     297             : {
     298             :     //TODO: Determine what is really needed, instead of relying on
     299             :     // addDefaultHxxIncludes
     300           0 :     includes.addCppuUnotypeHxx();
     301           0 : }
     302             : 
     303           0 : void CppuType::addNormalGetCppuTypeIncludes(
     304             :     codemaker::cppumaker::Includes & includes) const
     305             : {
     306             :     //TODO: Determine what is really needed, instead of relying on
     307             :     // addDefaultHxxIncludes
     308           0 :     includes.addCppuUnotypeHxx();
     309           0 : }
     310             : 
     311           0 : void CppuType::addComprehensiveGetCppuTypeIncludes(
     312             :     codemaker::cppumaker::Includes & includes) const
     313             : {
     314             :     //TODO: Determine what is really needed, instead of relying on
     315             :     // addDefaultHxxIncludes
     316           0 :     includes.addCppuUnotypeHxx();
     317           0 : }
     318             : 
     319           0 : bool CppuType::isPolymorphic() const { return false; }
     320             : 
     321           0 : void CppuType::dumpGetCppuTypePreamble(FileStream & out) {
     322           0 :     if (isPolymorphic()) {
     323           0 :         out << "namespace cppu {\n\n";
     324           0 :         dumpTemplateHead(out);
     325           0 :         out << "class UnoType< ";
     326           0 :         dumpType(out, name_);
     327           0 :         dumpTemplateParameters(out);
     328           0 :         out << " > {\npublic:\n";
     329           0 :         inc();
     330           0 :         out << indent()
     331           0 :             << "static inline ::css::uno::Type const & get() {\n";
     332             :     } else {
     333           0 :         if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
     334           0 :             out << "\n\n";
     335             :         }
     336             :         out << ("inline ::css::uno::Type const &"
     337           0 :                 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
     338           0 :         dumpType(out, name_, false, false, true);
     339           0 :         out << " const *) {\n";
     340             :     }
     341           0 :     inc();
     342           0 : }
     343             : 
     344           0 : void CppuType::dumpGetCppuTypePostamble(FileStream & out) {
     345           0 :     dec();
     346           0 :     if (isPolymorphic()) {
     347           0 :         out << indent() << "}\n\nprivate:\n"
     348           0 :             << indent() << "UnoType(UnoType &); // not defined\n"
     349           0 :             << indent() << "~UnoType(); // not defined\n"
     350           0 :             << indent()
     351           0 :             << "void operator =(UnoType); // not defined\n};\n\n}\n\n";
     352             :     } else {
     353           0 :         out << "}\n\n";
     354           0 :         if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
     355           0 :             out << "\n\n";
     356             :         }
     357             :     }
     358           0 :     dumpTemplateHead(out);
     359             :     out << ("inline ::css::uno::Type const & SAL_CALL"
     360           0 :             " getCppuType(SAL_UNUSED_PARAMETER ");
     361           0 :     dumpType(out, name_);
     362           0 :     dumpTemplateParameters(out);
     363           0 :     out << " const *) SAL_THROW(()) {\n";
     364           0 :     inc();
     365           0 :     out << indent() << "return ::cppu::UnoType< ";
     366           0 :     dumpType(out, name_);
     367           0 :     dumpTemplateParameters(out);
     368           0 :     out << " >::get();\n";
     369           0 :     dec();
     370           0 :     out << indent() << "}\n";
     371           0 : }
     372             : 
     373           0 : void CppuType::dump(CppuOptions const & options) {
     374           0 :     if (isBootstrapType(name_)) {
     375           0 :         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           0 :         if (options.isValid("-L"))
     382           0 :             m_cppuTypeLeak = true;
     383           0 :         if (options.isValid("-C") || options.isValid("-CS"))
     384           0 :             m_cppuTypeDynamic = false;
     385             :     }
     386             :     dumpFiles(
     387           0 :         options.isValid("-O") ? b2u(options.getOption("-O")) : "", options);
     388           0 : }
     389             : 
     390           0 : void CppuType::dumpFile(
     391             :     OUString const & uri, OUString const & name, bool hpp,
     392             :     CppuOptions const & options)
     393             : {
     394             :     OUString fileUri(
     395             :         b2u(createFileNameFromType(
     396           0 :                 u2b(uri), u2b(name), hpp ? ".hpp" : ".hdl")));
     397           0 :     if (fileUri.isEmpty()) {
     398           0 :         throw CannotDumpException("empty target URI for entity " + name);
     399             :     }
     400           0 :     bool exists = fileExists(u2b(fileUri));
     401           0 :     if (exists && options.isValid("-G")) {
     402           0 :         return;
     403             :     }
     404           0 :     FileStream out;
     405           0 :     out.createTempFile(getTempDir(u2b(fileUri)));
     406           0 :     OUString tmpUri(b2u(out.getName()));
     407           0 :     if(!out.isValid()) {
     408           0 :         throw CannotDumpException("cannot open " + tmpUri + " for writing");
     409             :     }
     410           0 :     codemaker::cppumaker::Includes includes(m_typeMgr, m_dependencies, hpp);
     411             :     try {
     412           0 :         if (hpp) {
     413           0 :             addGetCppuTypeIncludes(includes);
     414           0 :             dumpHxxFile(out, includes);
     415             :         } else {
     416           0 :             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           0 :     out.close();
     429             :     makeValidTypeFile(
     430           0 :         u2b(fileUri), u2b(tmpUri), exists && options.isValid("-Gc"));
     431             : }
     432             : 
     433           0 : void CppuType::dumpDependedTypes(
     434             :     codemaker::GeneratedTypeSet & generated, CppuOptions const & options)
     435             : {
     436           0 :     if (!options.isValid("-nD")) {
     437             :         codemaker::cppumaker::Dependencies::Map const & map
     438           0 :             = m_dependencies.getMap();
     439           0 :         for (codemaker::cppumaker::Dependencies::Map::const_iterator i(
     440           0 :                  map.begin());
     441           0 :              i != map.end(); ++i)
     442             :         {
     443           0 :             produce(i->first, m_typeMgr, generated, options);
     444             :         }
     445             :     }
     446           0 : }
     447             : 
     448           0 : OUString CppuType::dumpHeaderDefine(
     449             :     FileStream & out, OUString const & extension)
     450             : {
     451             :     OUString def(
     452           0 :         "INCLUDED_" + name_.replace('.', '_').toAsciiUpperCase() + "_"
     453           0 :         + extension);
     454           0 :     out << "#ifndef " << def << "\n#define " << def << "\n";
     455           0 :     return def;
     456             : }
     457             : 
     458           0 : void CppuType::addDefaultHIncludes(codemaker::cppumaker::Includes & includes)
     459             :     const
     460             : {
     461             :     //TODO: Only include what is really needed
     462           0 :     includes.addCppuMacrosHxx();
     463           0 :     if (m_typeMgr->getSort(name_)
     464             :         == codemaker::UnoType::SORT_INTERFACE_TYPE)
     465             :     {
     466           0 :         includes.addException();
     467           0 :         includes.addReference();
     468             :     }
     469           0 : }
     470             : 
     471           0 : void CppuType::addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes)
     472             :     const
     473             : {
     474             :     //TODO: Only include what is really needed
     475           0 :     includes.addRtlInstanceHxx();
     476           0 :     includes.addOslMutexHxx();
     477           0 :     includes.addType();
     478           0 :     if (m_typeMgr->getSort(name_)
     479             :         == codemaker::UnoType::SORT_INTERFACE_TYPE)
     480             :     {
     481           0 :         includes.addException();
     482           0 :         includes.addReference();
     483             :     }
     484           0 : }
     485             : 
     486           0 : void CppuType::dumpInitializer(
     487             :     FileStream & out, bool parameterized, OUString const & name) const
     488             : {
     489           0 :     out << "(";
     490           0 :     if (!parameterized) {
     491             :         sal_Int32 k;
     492           0 :         std::vector< OString > args;
     493             :         OUString n(
     494             :             b2u(codemaker::UnoType::decompose(
     495           0 :                     u2b(resolveAllTypedefs(name)), &k, &args)));
     496           0 :         if (k == 0) {
     497           0 :             rtl::Reference< unoidl::Entity > ent;
     498           0 :             switch (m_typeMgr->getSort(n, &ent)) {
     499             :             case codemaker::UnoType::SORT_BOOLEAN:
     500           0 :                 out << "false";
     501           0 :                 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           0 :                 out << "0";
     513           0 :                 break;
     514             :             case codemaker::UnoType::SORT_ENUM_TYPE:
     515           0 :                 out << codemaker::cpp::scopedCppName(u2b(n)) << "_"
     516           0 :                     << (dynamic_cast< unoidl::EnumTypeEntity * >(ent.get())->
     517           0 :                         getMembers()[0].name);
     518           0 :                 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           0 :                 break;
     526             :             default:
     527             :                 throw CannotDumpException(
     528           0 :                     "unexpected entity \"" + name
     529           0 :                     + "\" in call to CppuType::dumpInitializer");
     530           0 :             }
     531           0 :         }
     532             :     }
     533           0 :     out << ")";
     534           0 : }
     535             : 
     536           0 : void CppuType::dumpHFileContent(
     537             :     FileStream & out, codemaker::cppumaker::Includes & includes)
     538             : {
     539           0 :     addDefaultHIncludes(includes);
     540           0 :     dumpHeaderDefine(out, "HDL");
     541           0 :     out << "\n";
     542           0 :     includes.dump(out, 0);
     543             :     out << ("\nnamespace com { namespace sun { namespace star { namespace uno"
     544           0 :             " { class Type; } } } }\n\n");
     545           0 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
     546           0 :         out << "\n";
     547             :     }
     548           0 :     dumpDeclaration(out);
     549           0 :     if (!(name_ == "com.sun.star.uno.XInterface"
     550           0 :           || name_ == "com.sun.star.uno.Exception"
     551           0 :           || isPolymorphic()))
     552             :     {
     553           0 :         out << "\n" << indent()
     554             :             << ("inline ::css::uno::Type const &"
     555           0 :                 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
     556           0 :         dumpType(out, name_, false, false, true);
     557           0 :         out << " const *);\n";
     558             :     }
     559           0 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
     560           0 :         out << "\n";
     561             :     }
     562           0 :     out << "\n";
     563           0 :     dumpTemplateHead(out);
     564           0 :     out << "inline ::css::uno::Type const & SAL_CALL getCppuType(";
     565           0 :     dumpType(out, name_, true);
     566           0 :     dumpTemplateParameters(out);
     567           0 :     out << " *) SAL_THROW(());\n\n#endif\n";
     568           0 : }
     569             : 
     570           0 : void CppuType::dumpGetCppuType(FileStream & out) {
     571           0 :     if (name_ == "com.sun.star.uno.XInterface") {
     572           0 :         out << indent()
     573             :             << ("inline ::css::uno::Type const & SAL_CALL"
     574           0 :                 " getCppuType(SAL_UNUSED_PARAMETER ");
     575           0 :         dumpType(out, name_, true);
     576           0 :         out << " *) SAL_THROW(()) {\n";
     577           0 :         inc();
     578           0 :         out << indent()
     579             :             << ("return ::cppu::UnoType< ::css::uno::XInterface"
     580           0 :                 " >::get();\n");
     581           0 :         dec();
     582           0 :         out << indent() << "}\n";
     583           0 :     } else if (name_ == "com.sun.star.uno.Exception") {
     584           0 :         out << indent()
     585             :             << ("inline ::css::uno::Type const & SAL_CALL"
     586           0 :                 " getCppuType(SAL_UNUSED_PARAMETER ");
     587           0 :         dumpType(out, name_, true);
     588           0 :         out << " *) SAL_THROW(()) {\n";
     589           0 :         inc();
     590           0 :         out << indent()
     591             :             << ("return ::cppu::UnoType< ::css::uno::Exception"
     592           0 :                 " >::get();\n");
     593           0 :         dec();
     594           0 :         out << indent() << "}\n";
     595           0 :     } else if (m_cppuTypeLeak) {
     596           0 :         dumpLightGetCppuType(out);
     597           0 :     } else if (m_cppuTypeDynamic) {
     598           0 :         dumpNormalGetCppuType(out);
     599             :     } else {
     600           0 :         dumpComprehensiveGetCppuType(out);
     601             :     }
     602           0 : }
     603             : 
     604           0 : void CppuType::dumpLightGetCppuType(FileStream & out) {
     605           0 :     dumpGetCppuTypePreamble(out);
     606           0 :     out << indent()
     607           0 :         << "static typelib_TypeDescriptionReference * the_type = 0;\n"
     608           0 :         << indent() << "if ( !the_type )\n" << indent() << "{\n";
     609           0 :     inc();
     610           0 :     out << indent() << "typelib_static_type_init( &the_type, "
     611           0 :         << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n";
     612           0 :     dec();
     613           0 :     out << indent() << "}\n" << indent()
     614             :         << ("return * reinterpret_cast< ::css::uno::Type * >("
     615           0 :             " &the_type );\n");
     616           0 :     dumpGetCppuTypePostamble(out);
     617           0 : }
     618             : 
     619           0 : codemaker::cpp::IdentifierTranslationMode CppuType::isGlobal() const {
     620           0 :     return name_.indexOf('.') == -1
     621           0 :         ? codemaker::cpp::ITM_GLOBAL : codemaker::cpp::ITM_NONGLOBAL;
     622             : }
     623             : 
     624           0 : sal_uInt32 CppuType::getInheritedMemberCount()
     625             : {
     626           0 :     if (m_inheritedMemberCount == 0)
     627             :     {
     628           0 :         m_inheritedMemberCount = checkInheritedMemberCount();
     629             :     }
     630             : 
     631           0 :     return m_inheritedMemberCount;
     632             : }
     633             : 
     634           0 : OUString CppuType::getTypeClass(OUString const & name, bool cStyle) {
     635           0 :     rtl::Reference< unoidl::Entity > ent;
     636           0 :     switch (m_typeMgr->getSort(name, &ent)) {
     637             :     case codemaker::UnoType::SORT_VOID:
     638             :         return cStyle
     639             :             ? OUString("typelib_TypeClass_VOID")
     640           0 :             : OUString("::css::uno::TypeClass_VOID");
     641             :     case codemaker::UnoType::SORT_BOOLEAN:
     642             :         return cStyle
     643             :             ? OUString("typelib_TypeClass_BOOLEAN")
     644           0 :             : OUString("::css::uno::TypeClass_BOOLEAN");
     645             :     case codemaker::UnoType::SORT_BYTE:
     646             :         return cStyle
     647             :             ? OUString("typelib_TypeClass_BYTE")
     648           0 :             : OUString("::css::uno::TypeClass_BYTE");
     649             :     case codemaker::UnoType::SORT_SHORT:
     650             :         return cStyle
     651             :             ? OUString("typelib_TypeClass_SHORT")
     652           0 :             : OUString("::css::uno::TypeClass_SHORT");
     653             :     case codemaker::UnoType::SORT_UNSIGNED_SHORT:
     654             :         return cStyle
     655             :             ? OUString("typelib_TypeClass_UNSIGNED_SHORT")
     656           0 :             : OUString("::css::uno::TypeClass_UNSIGNED_SHORT");
     657             :     case codemaker::UnoType::SORT_LONG:
     658             :         return cStyle
     659             :             ? OUString("typelib_TypeClass_LONG")
     660           0 :             : OUString("::css::uno::TypeClass_LONG");
     661             :     case codemaker::UnoType::SORT_UNSIGNED_LONG:
     662             :         return cStyle
     663             :             ? OUString("typelib_TypeClass_UNSIGNED_LONG")
     664           0 :             : OUString("::css::uno::TypeClass_UNSIGNED_LONG");
     665             :     case codemaker::UnoType::SORT_HYPER:
     666             :         return cStyle
     667             :             ? OUString("typelib_TypeClass_HYPER")
     668           0 :             : OUString("::css::uno::TypeClass_HYPER");
     669             :     case codemaker::UnoType::SORT_UNSIGNED_HYPER:
     670             :         return cStyle
     671             :             ? OUString("typelib_TypeClass_UNSIGNED_HYPER")
     672           0 :             : OUString("::css::uno::TypeClass_UNSIGNED_HYPER");
     673             :     case codemaker::UnoType::SORT_FLOAT:
     674             :         return cStyle
     675             :             ? OUString("typelib_TypeClass_FLOAT")
     676           0 :             : OUString("::css::uno::TypeClass_FLOAT");
     677             :     case codemaker::UnoType::SORT_DOUBLE:
     678             :         return cStyle
     679             :             ? OUString("typelib_TypeClass_DOUBLE")
     680           0 :             : OUString("::css::uno::TypeClass_DOUBLE");
     681             :     case codemaker::UnoType::SORT_CHAR:
     682             :         return cStyle
     683             :             ? OUString("typelib_TypeClass_CHAR")
     684           0 :             : OUString("::css::uno::TypeClass_CHAR");
     685             :     case codemaker::UnoType::SORT_STRING:
     686             :         return cStyle
     687             :             ? OUString("typelib_TypeClass_STRING")
     688           0 :             : OUString("::css::uno::TypeClass_STRING");
     689             :     case codemaker::UnoType::SORT_TYPE:
     690             :         return cStyle
     691             :             ? OUString("typelib_TypeClass_TYPE")
     692           0 :             : OUString("::css::uno::TypeClass_TYPE");
     693             :     case codemaker::UnoType::SORT_ANY:
     694             :         return cStyle
     695             :             ? OUString("typelib_TypeClass_ANY")
     696           0 :             : OUString("::css::uno::TypeClass_ANY");
     697             :     case codemaker::UnoType::SORT_SEQUENCE_TYPE:
     698             :         return cStyle
     699             :             ? OUString("typelib_TypeClass_SEQUENCE")
     700           0 :             : OUString("::css::uno::TypeClass_SEQUENCE");
     701             :     case codemaker::UnoType::SORT_ENUM_TYPE:
     702             :         return cStyle
     703             :             ? OUString("typelib_TypeClass_ENUM")
     704           0 :             : 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           0 :             : OUString("::css::uno::TypeClass_STRUCT");
     711             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     712             :         return cStyle
     713             :             ? OUString("typelib_TypeClass_EXCEPTION")
     714           0 :             : OUString("::css::uno::TypeClass_EXCEPTION");
     715             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
     716             :         return cStyle
     717             :             ? OUString("typelib_TypeClass_INTERFACE")
     718           0 :             : OUString("::css::uno::TypeClass_INTERFACE");
     719             :     case codemaker::UnoType::SORT_TYPEDEF:
     720             :         return getTypeClass(
     721           0 :             dynamic_cast< unoidl::TypedefEntity * >(ent.get())->getType(),
     722           0 :             cStyle);
     723             :     default:
     724           0 :         for (;;) { std::abort(); }
     725           0 :     }
     726             : }
     727             : 
     728           0 : 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           0 :     std::vector< OString > args;
     734             :     OUString n(
     735             :         b2u(codemaker::UnoType::decompose(
     736           0 :                 u2b(resolveAllTypedefs(name)), &k, &args)));
     737           0 :     if (isConst) {
     738           0 :         out << "const ";
     739             :     }
     740           0 :     for (sal_Int32 i = 0; i != k; ++i) {
     741             :         out << (cppuUnoType
     742           0 :                 ? "::cppu::UnoSequenceType" : "::css::uno::Sequence")
     743           0 :             << "< ";
     744             :     }
     745           0 :     switch (m_typeMgr->getSort(n)) {
     746             :     case codemaker::UnoType::SORT_VOID:
     747           0 :         out << "void";
     748           0 :         break;
     749             :     case codemaker::UnoType::SORT_BOOLEAN:
     750           0 :         out << "::sal_Bool";
     751           0 :         break;
     752             :     case codemaker::UnoType::SORT_BYTE:
     753           0 :         out << "::sal_Int8";
     754           0 :         break;
     755             :     case codemaker::UnoType::SORT_SHORT:
     756           0 :         out << "::sal_Int16";
     757           0 :         break;
     758             :     case codemaker::UnoType::SORT_UNSIGNED_SHORT:
     759           0 :         out << (cppuUnoType ? "::cppu::UnoUnsignedShortType" : "::sal_uInt16");
     760           0 :         break;
     761             :     case codemaker::UnoType::SORT_LONG:
     762           0 :         out << "::sal_Int32";
     763           0 :         break;
     764             :     case codemaker::UnoType::SORT_UNSIGNED_LONG:
     765           0 :         out << "::sal_uInt32";
     766           0 :         break;
     767             :     case codemaker::UnoType::SORT_HYPER:
     768           0 :         out << "::sal_Int64";
     769           0 :         break;
     770             :     case codemaker::UnoType::SORT_UNSIGNED_HYPER:
     771           0 :         out << "::sal_uInt64";
     772           0 :         break;
     773             :     case codemaker::UnoType::SORT_FLOAT:
     774           0 :         out << "float";
     775           0 :         break;
     776             :     case codemaker::UnoType::SORT_DOUBLE:
     777           0 :         out << "double";
     778           0 :         break;
     779             :     case codemaker::UnoType::SORT_CHAR:
     780           0 :         out << (cppuUnoType ? "::cppu::UnoCharType" : "::sal_Unicode");
     781           0 :         break;
     782             :     case codemaker::UnoType::SORT_STRING:
     783           0 :         out << "::rtl::OUString";
     784           0 :         break;
     785             :     case codemaker::UnoType::SORT_TYPE:
     786           0 :         out << "::css::uno::Type";
     787           0 :         break;
     788             :     case codemaker::UnoType::SORT_ANY:
     789           0 :         out << "::css::uno::Any";
     790           0 :         break;
     791             :     case codemaker::UnoType::SORT_ENUM_TYPE:
     792             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     793             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     794           0 :         out << codemaker::cpp::scopedCppName(u2b(n));
     795           0 :         break;
     796             :     case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     797           0 :         out << codemaker::cpp::scopedCppName(u2b(n));
     798           0 :         if (!args.empty()) {
     799           0 :             out << "< ";
     800           0 :             for (std::vector< OString >::iterator i(args.begin());
     801           0 :                  i != args.end(); ++i)
     802             :             {
     803           0 :                 if (i != args.begin()) {
     804           0 :                     out << ", ";
     805             :                 }
     806           0 :                 dumpType(out, b2u(*i));
     807             :             }
     808           0 :             out << " >";
     809             :         }
     810           0 :         break;
     811             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
     812           0 :         if (!native) {
     813           0 :             out << "::css::uno::Reference< ";
     814             :         }
     815           0 :         out << codemaker::cpp::scopedCppName(u2b(n));
     816           0 :         if (!native) {
     817           0 :             out << " >";
     818             :         }
     819           0 :         break;
     820             :     default:
     821             :         throw CannotDumpException(
     822           0 :             "unexpected entity \"" + name + "\" in call to CppuType::dumpType");
     823             :     }
     824           0 :     for (sal_Int32 i = 0; i != k; ++i) {
     825           0 :         out << " >";
     826             :     }
     827           0 :     if (isRef) {
     828           0 :         out << "&";
     829           0 :     }
     830           0 : }
     831             : 
     832           0 : void CppuType::dumpCppuGetType(
     833             :     FileStream & out, OUString const & name, OUString const * ownName)
     834             : {
     835             :     //TODO: What are these calls good for?
     836           0 :     OUString nucleus;
     837             :     sal_Int32 rank;
     838             :     codemaker::UnoType::Sort sort = m_typeMgr->decompose(
     839           0 :         name, true, &nucleus, &rank, 0, 0);
     840           0 :     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           0 :         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           0 :         if (ownName == 0 || nucleus != *ownName) {
     865           0 :             out << indent() << "::cppu::UnoType< ";
     866           0 :             dumpType(out, name, false, false, false, true);
     867           0 :             out << " >::get();\n";
     868             :         }
     869           0 :         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           0 :     }
     878           0 : }
     879             : 
     880           0 : bool CppuType::passByReference(OUString const & name) const {
     881           0 :     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           0 :         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           0 :         return true;
     903             :     default:
     904             :         throw CannotDumpException(
     905           0 :             "unexpected entity \"" + name
     906           0 :             + "\" in call to CppuType::passByReference");
     907             :     }
     908             : }
     909             : 
     910           0 : OUString CppuType::resolveOuterTypedefs(OUString const & name) const {
     911           0 :     for (OUString n(name);;) {
     912           0 :         rtl::Reference< unoidl::Entity > ent;
     913           0 :         if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) {
     914           0 :             return n;
     915             :         }
     916           0 :         n = dynamic_cast< unoidl::TypedefEntity * >(ent.get())->getType();
     917           0 :     }
     918             : }
     919             : 
     920           0 : OUString CppuType::resolveAllTypedefs(OUString const & name) const {
     921             :     sal_Int32 k1;
     922           0 :     OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k1)));
     923             :     for (;;) {
     924           0 :         rtl::Reference< unoidl::Entity > ent;
     925           0 :         if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) {
     926           0 :             break;
     927             :         }
     928             :         sal_Int32 k2;
     929           0 :         n = b2u(
     930             :             codemaker::UnoType::decompose(
     931           0 :                 u2b(dynamic_cast< unoidl::TypedefEntity * >(ent.get())->
     932             :                     getType()),
     933           0 :                 &k2));
     934           0 :         k1 += k2; //TODO: overflow
     935           0 :     }
     936           0 :     OUStringBuffer b;
     937           0 :     for (sal_Int32 i = 0; i != k1; ++i) {
     938           0 :         b.append("[]");
     939             :     }
     940           0 :     b.append(n);
     941           0 :     return b.makeStringAndClear();
     942             : }
     943             : 
     944           0 : void CppuType::inc(sal_Int32 num)
     945             : {
     946           0 :     m_indentLength += num;
     947           0 : }
     948             : 
     949           0 : void CppuType::dec(sal_Int32 num)
     950             : {
     951           0 :     m_indentLength = std::max< sal_Int32 >(m_indentLength - num, 0);
     952           0 : }
     953             : 
     954           0 : OUString CppuType::indent() const {
     955           0 :     OUStringBuffer buf(m_indentLength);
     956           0 :     for (sal_Int32 i = 0; i != m_indentLength; ++i) {
     957           0 :         buf.append(' ');
     958             :     }
     959           0 :     return buf.makeStringAndClear();
     960             : }
     961             : 
     962           0 : bool isDeprecated(std::vector< OUString > const & annotations) {
     963           0 :     for (std::vector< OUString >::const_iterator i(annotations.begin());
     964           0 :          i != annotations.end(); ++i)
     965             :     {
     966           0 :         if (*i == "deprecated") {
     967           0 :             return true;
     968             :         }
     969             :     }
     970           0 :     return false;
     971             : }
     972             : 
     973           0 : void dumpDeprecation(FileStream & out, bool deprecated) {
     974           0 :     if (deprecated) {
     975           0 :         out << "SAL_DEPRECATED_INTERNAL(\"marked @deprecated in UNOIDL\") ";
     976             :     }
     977           0 : }
     978             : 
     979           0 : class BaseOffset: private boost::noncopyable {
     980             : public:
     981           0 :     BaseOffset(
     982             :         rtl::Reference< TypeManager > const & manager,
     983             :         rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
     984           0 :         manager_(manager), offset_(0) { calculateBases(entity); }
     985             : 
     986           0 :     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           0 : void BaseOffset::calculateBases(
     998             :     rtl::Reference< unoidl::InterfaceTypeEntity > const & entity)
     999             : {
    1000             :     assert(entity.is());
    1001           0 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
    1002           0 :              entity->getDirectMandatoryBases().begin());
    1003           0 :          i != entity->getDirectMandatoryBases().end(); ++i)
    1004             :     {
    1005           0 :         if (set_.insert(i->name).second) {
    1006           0 :             rtl::Reference< unoidl::Entity > ent;
    1007           0 :             codemaker::UnoType::Sort sort = manager_->getSort(i->name, &ent);
    1008           0 :             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           0 :                 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
    1015             :             assert(ent2.is());
    1016           0 :             calculateBases(ent2);
    1017           0 :             offset_ += ent2->getDirectAttributes().size()
    1018           0 :                 + ent2->getDirectMethods().size(); //TODO: overflow
    1019             :         }
    1020             :     }
    1021           0 : }
    1022             : 
    1023           0 : 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           0 :     virtual sal_uInt32 checkInheritedMemberCount() const SAL_OVERRIDE
    1048           0 :     { 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           0 : InterfaceType::InterfaceType(
    1070             :     rtl::Reference< unoidl::InterfaceTypeEntity > const & entity,
    1071             :     OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    1072           0 :     CppuType(name, typeMgr), entity_(entity)
    1073             : {
    1074             :     assert(entity.is());
    1075           0 :     m_inheritedMemberCount = 0;
    1076           0 :     m_isDeprecated = isDeprecated(entity->getAnnotations());
    1077           0 : }
    1078             : 
    1079           0 : void InterfaceType::dumpDeclaration(FileStream & out) {
    1080           0 :     out << "\nclass SAL_NO_VTABLE " << id_;
    1081           0 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
    1082           0 :              entity_->getDirectMandatoryBases().begin());
    1083           0 :          i != entity_->getDirectMandatoryBases().end(); ++i)
    1084             :     {
    1085           0 :         out << (i == entity_->getDirectMandatoryBases().begin() ? " :" : ",")
    1086           0 :             << " public " << codemaker::cpp::scopedCppName(u2b(i->name));
    1087             :     }
    1088           0 :     out << "\n{\npublic:\n";
    1089           0 :     inc();
    1090           0 :     dumpAttributes(out);
    1091           0 :     dumpMethods(out);
    1092           0 :     out << "\n" << indent()
    1093             :         << ("static inline ::css::uno::Type const & SAL_CALL"
    1094           0 :             " static_type(void * = 0);\n\n");
    1095           0 :     dec();
    1096           0 :     out << "protected:\n";
    1097           0 :     inc();
    1098           0 :     out << indent() << "~" << id_
    1099             :         << ("() throw () {} // avoid warnings about virtual members and"
    1100           0 :             " non-virtual dtor\n");
    1101           0 :     dec();
    1102           0 :     out << "};\n\n";
    1103           0 : }
    1104             : 
    1105           0 : void InterfaceType::dumpHxxFile(
    1106             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    1107             : {
    1108           0 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    1109           0 :     out << "\n";
    1110           0 :     addDefaultHxxIncludes(includes);
    1111           0 :     includes.dump(out, &name_);
    1112           0 :     out << "\n";
    1113           0 :     dumpGetCppuType(out);
    1114           0 :     out << "\n::css::uno::Type const & "
    1115           0 :         << codemaker::cpp::scopedCppName(u2b(name_))
    1116           0 :         << "::static_type(SAL_UNUSED_PARAMETER void *) {\n";
    1117           0 :     inc();
    1118           0 :     out << indent() << "return ::getCppuType(static_cast< ";
    1119           0 :     dumpType(out, name_);
    1120           0 :     out << " * >(0));\n";
    1121           0 :     dec();
    1122           0 :     out << "}\n\n#endif // "<< headerDefine << "\n";
    1123           0 : }
    1124             : 
    1125           0 : void InterfaceType::dumpAttributes(FileStream & out) {
    1126           0 :     if (!entity_->getDirectAttributes().empty()) {
    1127           0 :         out << "\n" << indent() << "// Attributes\n";
    1128             :     }
    1129           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
    1130           0 :              i(entity_->getDirectAttributes().begin());
    1131           0 :          i != entity_->getDirectAttributes().end(); ++i)
    1132             :     {
    1133           0 :         bool depr = m_isDeprecated || isDeprecated(i->annotations);
    1134           0 :         out << indent();
    1135           0 :         dumpDeprecation(out, depr);
    1136           0 :         out << "virtual ";
    1137           0 :         dumpType(out, i->type);
    1138           0 :         out << " SAL_CALL get" << i->name << "()";
    1139           0 :         dumpExceptionSpecification(out, i->getExceptions, true);
    1140           0 :         out << " = 0;\n";
    1141           0 :         if (!i->readOnly) {
    1142           0 :             bool byRef = passByReference(i->type);
    1143           0 :             out << indent();
    1144           0 :             dumpDeprecation(out, depr);
    1145           0 :             out << "virtual void SAL_CALL set" << i->name << "( ";
    1146           0 :             dumpType(out, i->type, byRef, byRef);
    1147           0 :             out << " _" << i->name.toAsciiLowerCase() << " )";
    1148           0 :             dumpExceptionSpecification(out, i->setExceptions, true);
    1149           0 :             out << " = 0;\n";
    1150             :         }
    1151             :     }
    1152           0 : }
    1153             : 
    1154           0 : void InterfaceType::dumpMethods(FileStream & out) {
    1155           0 :     if (!entity_->getDirectMethods().empty()) {
    1156           0 :         out << "\n" << indent() << "// Methods\n";
    1157             :     }
    1158           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
    1159           0 :              entity_->getDirectMethods().begin());
    1160           0 :          i != entity_->getDirectMethods().end(); ++i)
    1161             :     {
    1162           0 :         out << indent();
    1163           0 :         dumpDeprecation(out, m_isDeprecated || isDeprecated(i->annotations));
    1164           0 :         out << "virtual ";
    1165           0 :         dumpType(out, i->returnType);
    1166           0 :         out << " SAL_CALL " << i->name << "(";
    1167           0 :         if (i->parameters.empty()) {
    1168           0 :             out << ")";
    1169             :         } else {
    1170           0 :             out << " ";
    1171           0 :             for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
    1172           0 :                      const_iterator j(i->parameters.begin());
    1173           0 :                  j != i->parameters.end();)
    1174             :             {
    1175             :                 bool isConst;
    1176             :                 bool isRef;
    1177           0 :                 if (j->direction
    1178           0 :                     == (unoidl::InterfaceTypeEntity::Method::Parameter::
    1179             :                         DIRECTION_IN))
    1180             :                 {
    1181           0 :                     isConst = passByReference(j->type);
    1182           0 :                     isRef = isConst;
    1183             :                 } else {
    1184           0 :                     isConst = false;
    1185           0 :                     isRef = true;
    1186             :                 }
    1187           0 :                 dumpType(out, j->type, isConst, isRef);
    1188           0 :                 out << " " << j->name;
    1189           0 :                 ++j;
    1190           0 :                 if (j != i->parameters.end()) {
    1191           0 :                     out << ", ";
    1192             :                 }
    1193             :             }
    1194           0 :             out << " )";
    1195             :         }
    1196             :         dumpExceptionSpecification(
    1197           0 :             out, i->exceptions, i->name != "acquire" && i->name != "release");
    1198           0 :         out << " = 0;\n";
    1199             :     }
    1200           0 : }
    1201             : 
    1202           0 : void InterfaceType::dumpNormalGetCppuType(FileStream & out) {
    1203           0 :     dumpGetCppuTypePreamble(out);
    1204           0 :     out << indent()
    1205           0 :         << "static typelib_TypeDescriptionReference * the_type = 0;\n"
    1206           0 :         << indent() << "if ( !the_type )\n" << indent() << "{\n";
    1207           0 :     inc();
    1208             :     std::vector< unoidl::AnnotatedReference >::size_type bases(
    1209           0 :         entity_->getDirectMandatoryBases().size());
    1210           0 :     if (bases == 1
    1211           0 :         && (entity_->getDirectMandatoryBases()[0].name
    1212           0 :             == "com.sun.star.uno.XInterface"))
    1213             :     {
    1214           0 :         bases = 0;
    1215             :     }
    1216           0 :     if (bases != 0) {
    1217           0 :         out << indent() << "typelib_TypeDescriptionReference * aSuperTypes["
    1218           0 :             << entity_->getDirectMandatoryBases().size() << "];\n";
    1219           0 :         std::vector< unoidl::AnnotatedReference >::size_type n = 0;
    1220           0 :         for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
    1221           0 :                  entity_->getDirectMandatoryBases().begin());
    1222           0 :              i != entity_->getDirectMandatoryBases().end(); ++i)
    1223             :         {
    1224           0 :             out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< ";
    1225           0 :             dumpType(out, i->name, true, false, false, true);
    1226           0 :             out << " >::get().getTypeLibType();\n";
    1227             :         }
    1228             :     }
    1229           0 :     out << indent() << "typelib_static_mi_interface_type_init( &the_type, \""
    1230           0 :         << name_ << "\", " << bases << ", "
    1231           0 :         << (bases == 0 ? "0" : "aSuperTypes") << " );\n";
    1232           0 :     dec();
    1233           0 :     out << indent() << "}\n" << indent()
    1234             :         << ("return * reinterpret_cast< ::css::uno::Type * >("
    1235           0 :             " &the_type );\n");
    1236           0 :     dumpGetCppuTypePostamble(out);
    1237           0 : }
    1238             : 
    1239           0 : void InterfaceType::dumpComprehensiveGetCppuType(FileStream & out) {
    1240           0 :     codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
    1241           0 :     OUString staticTypeClass("the" + id_ + "Type");
    1242           0 :     out << " namespace detail {\n\n" << indent() << "struct " << staticTypeClass
    1243           0 :         << " : public rtl::StaticWithInit< ::css::uno::Type *, "
    1244           0 :         << staticTypeClass << " >\n" << indent() << "{\n";
    1245           0 :     inc();
    1246           0 :     out << indent() << "::css::uno::Type * operator()() const\n"
    1247           0 :         << indent() << "{\n";
    1248           0 :     inc();
    1249           0 :     out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n"
    1250           0 :         << indent() << "// Start inline typedescription generation\n"
    1251           0 :         << indent() << "typelib_InterfaceTypeDescription * pTD = 0;\n\n";
    1252           0 :     out << indent() << "typelib_TypeDescriptionReference * aSuperTypes["
    1253           0 :         << entity_->getDirectMandatoryBases().size() << "];\n";
    1254           0 :     std::vector< unoidl::AnnotatedReference >::size_type n = 0;
    1255           0 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
    1256           0 :              entity_->getDirectMandatoryBases().begin());
    1257           0 :          i != entity_->getDirectMandatoryBases().end(); ++i)
    1258             :     {
    1259           0 :         out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< ";
    1260           0 :         dumpType(out, i->name, false, false, false, true);
    1261           0 :         out << " >::get().getTypeLibType();\n";
    1262             :     }
    1263           0 :     std::size_t count = entity_->getDirectAttributes().size()
    1264           0 :         + entity_->getDirectMethods().size(); //TODO: overflow
    1265           0 :     if (count != 0) {
    1266           0 :         out << indent() << "typelib_TypeDescriptionReference * pMembers["
    1267           0 :             << count << "] = { ";
    1268           0 :         for (std::size_t i = 0; i != count; ++i) {
    1269           0 :             out << "0";
    1270           0 :             if (i + 1 != count) {
    1271           0 :                 out << ",";
    1272             :             }
    1273             :         }
    1274           0 :         out << " };\n";
    1275           0 :         sal_uInt32 index = 0;
    1276           0 :         dumpCppuAttributeRefs(out, index);
    1277           0 :         dumpCppuMethodRefs(out, index);
    1278             :     }
    1279           0 :     out << "\n" << indent() << "typelib_typedescription_newMIInterface(\n";
    1280           0 :     inc();
    1281           0 :     out << indent() << "&pTD,\n" << indent()
    1282           0 :         << "sTypeName.pData, 0, 0, 0, 0, 0,\n" << indent()
    1283           0 :         << entity_->getDirectMandatoryBases().size() << ", aSuperTypes,\n"
    1284           0 :         << indent() << count << ",\n" << indent()
    1285           0 :         << (count == 0 ? "0" : "pMembers") << " );\n\n";
    1286           0 :     dec();
    1287           0 :     out << indent()
    1288             :         << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
    1289           0 :           " );\n");
    1290           0 :     for (std::size_t i = 0; i != count; ++i) {
    1291           0 :         out << indent() << "typelib_typedescriptionreference_release( pMembers["
    1292           0 :             << i << "] );\n";
    1293             :     }
    1294           0 :     out << indent()
    1295             :         << ("typelib_typedescription_release( (typelib_TypeDescription*)pTD"
    1296           0 :             " );\n\n")
    1297           0 :         << indent() << "return new ::css::uno::Type( "
    1298           0 :         << getTypeClass(name_) << ", sTypeName ); // leaked\n";
    1299           0 :     dec();
    1300           0 :     out << indent() << "}\n";
    1301           0 :     dec();
    1302           0 :     out << indent() << "};\n\n";
    1303           0 :     codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
    1304           0 :     out << " }\n\n";
    1305           0 :     dumpGetCppuTypePreamble(out);
    1306           0 :     out << indent() << "const ::css::uno::Type &rRet = *detail::"
    1307           0 :         << staticTypeClass << "::get();\n" << indent()
    1308           0 :         << "// End inline typedescription generation\n" << indent()
    1309           0 :         << "static bool bInitStarted = false;\n" << indent()
    1310           0 :         << "if (!bInitStarted)\n" << indent() << "{\n";
    1311           0 :     inc();
    1312           0 :     out << indent()
    1313           0 :         << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n"
    1314           0 :         << indent() << "if (!bInitStarted)\n" << indent() << "{\n";
    1315           0 :     inc();
    1316           0 :     out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"
    1317           0 :         << indent() << "bInitStarted = true;\n";
    1318           0 :     std::set< OUString > seen;
    1319             :     // Type for RuntimeException is always needed:
    1320           0 :     seen.insert("com.sun.star.uno.RuntimeException");
    1321           0 :     dumpCppuGetType(out, "com.sun.star.uno.RuntimeException");
    1322           0 :     dumpAttributesCppuDecl(out, &seen);
    1323           0 :     dumpMethodsCppuDecl(out, &seen);
    1324           0 :     if (count != 0) {
    1325           0 :         sal_uInt32 index = getInheritedMemberCount();
    1326           0 :         dumpCppuAttributes(out, index);
    1327           0 :         dumpCppuMethods(out, index);
    1328             :     }
    1329           0 :     dec();
    1330           0 :     out << indent() << "}\n";
    1331           0 :     dec();
    1332           0 :     out << indent() << "}\n" << indent() << "else\n" << indent() << "{\n";
    1333           0 :     inc();
    1334           0 :     out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n";
    1335           0 :     dec();
    1336           0 :     out << indent() << "}\n" << indent() << "return rRet;\n";
    1337           0 :     dumpGetCppuTypePostamble(out);
    1338           0 : }
    1339             : 
    1340           0 : void InterfaceType::dumpCppuAttributeRefs(FileStream & out, sal_uInt32 & index)
    1341             : {
    1342           0 :     std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0;
    1343           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
    1344           0 :              i(entity_->getDirectAttributes().begin());
    1345           0 :          i != entity_->getDirectAttributes().end(); ++i)
    1346             :     {
    1347           0 :         out << indent() << "::rtl::OUString sAttributeName" << n << "( \""
    1348           0 :             << name_ << "::" << i->name << "\" );\n" << indent()
    1349           0 :             << "typelib_typedescriptionreference_new( &pMembers[" << index++
    1350           0 :             << "],\n";
    1351           0 :         inc(38);
    1352           0 :         out << indent()
    1353           0 :             << ("(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_ATTRIBUTE,\n")
    1354           0 :             << indent() << "sAttributeName" << n << ".pData );\n";
    1355           0 :         dec(38);
    1356           0 :         ++n;
    1357             :     }
    1358           0 : }
    1359             : 
    1360           0 : void InterfaceType::dumpCppuMethodRefs(FileStream & out, sal_uInt32 & index) {
    1361           0 :     std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0;
    1362           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
    1363           0 :              entity_->getDirectMethods().begin());
    1364           0 :          i != entity_->getDirectMethods().end(); ++i)
    1365             :     {
    1366           0 :         out << indent() << "::rtl::OUString sMethodName" << n << "( \"" << name_
    1367           0 :             << "::" << i->name << "\" );\n" << indent()
    1368           0 :             << "typelib_typedescriptionreference_new( &pMembers[" << index++
    1369           0 :             << "],\n";
    1370           0 :         inc(38);
    1371           0 :         out << indent()
    1372           0 :             << ("(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_METHOD,\n")
    1373           0 :             << indent() << "sMethodName" << n << ".pData );\n";
    1374           0 :         dec(38);
    1375           0 :         ++n;
    1376             :     }
    1377           0 : }
    1378             : 
    1379           0 : 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           0 :     includes.addCppuUnotypeHxx();
    1385           0 :     includes.add("com.sun.star.uno.RuntimeException");
    1386           0 : }
    1387             : 
    1388           0 : void InterfaceType::dumpCppuAttributes(FileStream & out, sal_uInt32 & index) {
    1389           0 :     if (!entity_->getDirectAttributes().empty()) {
    1390           0 :         out << "\n" << indent()
    1391           0 :             << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n";
    1392           0 :         std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0;
    1393           0 :         for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::
    1394           0 :                  const_iterator i(entity_->getDirectAttributes().begin());
    1395           0 :              i != entity_->getDirectAttributes().end(); ++i)
    1396             :         {
    1397           0 :             OUString type(resolveAllTypedefs(i->type));
    1398           0 :             out << indent() << "{\n";
    1399           0 :             inc();
    1400           0 :             out << indent() << "::rtl::OUString sAttributeType" << n << "( \""
    1401           0 :                 << type << "\" );\n" << indent()
    1402           0 :                 << "::rtl::OUString sAttributeName" << n << "( \"" << name_
    1403           0 :                 << "::" << i->name << "\" );\n";
    1404             :             sal_Int32 getExcn = dumpExceptionTypeNames(
    1405           0 :                 out, "get", i->getExceptions, false);
    1406             :             sal_Int32 setExcn = dumpExceptionTypeNames(
    1407           0 :                 out, "set", i->setExceptions, false);
    1408           0 :             out << indent()
    1409             :                 << ("typelib_typedescription_newExtendedInterfaceAttribute("
    1410           0 :                     " &pAttribute,\n");
    1411           0 :             inc();
    1412           0 :             out << indent() << index++ << ", sAttributeName" << n
    1413           0 :                 << ".pData,\n" << indent() << "(typelib_TypeClass)"
    1414           0 :                 << getTypeClass(type) << ", sAttributeType" << n << ".pData,\n"
    1415           0 :                 << indent() << "sal_" << (i->readOnly ? "True" : "False")
    1416           0 :                 << ", " << getExcn << ", "
    1417           0 :                 << (getExcn == 0 ? "0" : "the_getExceptions") << ", " << setExcn
    1418           0 :                 << ", " << (setExcn == 0 ? "0" : "the_setExceptions")
    1419           0 :                 << " );\n";
    1420           0 :             dec();
    1421           0 :             out << indent()
    1422             :                 << ("typelib_typedescription_register("
    1423           0 :                     " (typelib_TypeDescription**)&pAttribute );\n");
    1424           0 :             dec();
    1425           0 :             out << indent() << "}\n";
    1426           0 :             ++n;
    1427           0 :         }
    1428           0 :         out << indent()
    1429             :             << ("typelib_typedescription_release("
    1430           0 :                 " (typelib_TypeDescription*)pAttribute );\n");
    1431             :     }
    1432           0 : }
    1433             : 
    1434           0 : void InterfaceType::dumpCppuMethods(FileStream & out, sal_uInt32 & index) {
    1435           0 :     if (!entity_->getDirectMethods().empty()) {
    1436           0 :         out << "\n" << indent()
    1437           0 :             << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n";
    1438           0 :         std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0;
    1439           0 :         for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator
    1440           0 :                  i(entity_->getDirectMethods().begin());
    1441           0 :              i != entity_->getDirectMethods().end(); ++i)
    1442             :         {
    1443           0 :             OUString returnType(resolveAllTypedefs(i->returnType));
    1444           0 :             out << indent() << "{\n";
    1445           0 :             inc();
    1446           0 :             if (!i->parameters.empty()) {
    1447           0 :                 out << indent() << "typelib_Parameter_Init aParameters["
    1448           0 :                     << i->parameters.size() << "];\n";
    1449             :             }
    1450             :             std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
    1451           0 :                 size_type m = 0;
    1452           0 :             for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
    1453           0 :                      const_iterator j(i->parameters.begin());
    1454           0 :                  j != i->parameters.end(); ++j)
    1455             :             {
    1456           0 :                 OUString type(resolveAllTypedefs(j->type));
    1457           0 :                 out << indent() << "::rtl::OUString sParamName" << m << "( \""
    1458           0 :                     << j->name << "\" );\n" << indent()
    1459           0 :                     << "::rtl::OUString sParamType" << m << "( \"" << type
    1460           0 :                     << "\" );\n" << indent() << "aParameters[" << m
    1461           0 :                     << "].pParamName = sParamName" << m << ".pData;\n"
    1462           0 :                     << indent() << "aParameters[" << m
    1463           0 :                     << "].eTypeClass = (typelib_TypeClass)"
    1464           0 :                     << getTypeClass(type) << ";\n" << indent() << "aParameters["
    1465           0 :                     << m << "].pTypeName = sParamType" << m << ".pData;\n"
    1466           0 :                     << indent() << "aParameters[" << m << "].bIn = "
    1467           0 :                     << ((j->direction
    1468           0 :                          == (unoidl::InterfaceTypeEntity::Method::Parameter::
    1469             :                              DIRECTION_OUT))
    1470           0 :                         ? "sal_False" : "sal_True")
    1471           0 :                     << ";\n" << indent() << "aParameters[" << m << "].bOut = "
    1472           0 :                     << ((j->direction
    1473           0 :                          == (unoidl::InterfaceTypeEntity::Method::Parameter::
    1474             :                              DIRECTION_IN))
    1475           0 :                         ? "sal_False" : "sal_True")
    1476           0 :                     << ";\n";
    1477           0 :                 ++m;
    1478           0 :             }
    1479             :             sal_Int32 excn = dumpExceptionTypeNames(
    1480           0 :                 out, "", i->exceptions,
    1481           0 :                 i->name != "acquire" && i->name != "release");
    1482           0 :             out << indent() << "::rtl::OUString sReturnType" << n << "( \""
    1483           0 :                 << returnType << "\" );\n" << indent()
    1484           0 :                 << "::rtl::OUString sMethodName" << n << "( \"" << name_ << "::"
    1485           0 :                 << i->name << "\" );\n" << indent()
    1486           0 :                 << "typelib_typedescription_newInterfaceMethod( &pMethod,\n";
    1487           0 :             inc();
    1488           0 :             out << indent() << index++ << ", sal_False,\n" << indent()
    1489           0 :                 << "sMethodName" << n << ".pData,\n" << indent()
    1490           0 :                 << "(typelib_TypeClass)" << getTypeClass(returnType)
    1491           0 :                 << ", sReturnType" << n << ".pData,\n" << indent()
    1492           0 :                 << i->parameters.size() << ", "
    1493           0 :                 << (i->parameters.empty() ? "0" : "aParameters") << ",\n"
    1494           0 :                 << indent() << excn << ", "
    1495           0 :                 << (excn == 0 ? "0" : "the_Exceptions") << " );\n";
    1496           0 :             dec();
    1497           0 :             out << indent()
    1498             :                 << ("typelib_typedescription_register("
    1499           0 :                     " (typelib_TypeDescription**)&pMethod );\n");
    1500           0 :             dec();
    1501           0 :             out << indent() << "}\n";
    1502           0 :             ++n;
    1503           0 :         }
    1504           0 :         out << indent()
    1505             :             << ("typelib_typedescription_release("
    1506           0 :                 " (typelib_TypeDescription*)pMethod );\n");
    1507             :     }
    1508           0 : }
    1509             : 
    1510           0 : void InterfaceType::dumpAttributesCppuDecl(
    1511             :     FileStream & out, std::set< OUString > * seen)
    1512             : {
    1513             :     assert(seen != 0);
    1514           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
    1515           0 :              i(entity_->getDirectAttributes().begin());
    1516           0 :          i != entity_->getDirectAttributes().end(); ++i)
    1517             :     {
    1518           0 :         if (seen->insert(i->type).second) {
    1519           0 :             dumpCppuGetType(out, i->type);
    1520             :         }
    1521           0 :         for (std::vector< OUString >::const_iterator j(
    1522           0 :                  i->getExceptions.begin());
    1523           0 :              j != i->getExceptions.end(); ++j)
    1524             :         {
    1525           0 :             if (seen->insert(*j).second) {
    1526           0 :                 dumpCppuGetType(out, *j);
    1527             :             }
    1528             :         }
    1529           0 :         for (std::vector< OUString >::const_iterator j(
    1530           0 :                  i->setExceptions.begin());
    1531           0 :              j != i->setExceptions.end(); ++j)
    1532             :         {
    1533           0 :             if (seen->insert(*j).second) {
    1534           0 :                 dumpCppuGetType(out, *j);
    1535             :             }
    1536             :         }
    1537             :     }
    1538           0 : }
    1539             : 
    1540           0 : void InterfaceType::dumpMethodsCppuDecl(
    1541             :     FileStream & out, std::set< OUString > * seen)
    1542             : {
    1543             :     assert(seen != 0);
    1544           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
    1545           0 :              entity_->getDirectMethods().begin());
    1546           0 :          i != entity_->getDirectMethods().end(); ++i)
    1547             :     {
    1548           0 :         for (std::vector< OUString >::const_iterator j(i->exceptions.begin());
    1549           0 :              j != i->exceptions.end(); ++j)
    1550             :         {
    1551           0 :             if (seen->insert(*j).second) {
    1552           0 :                 dumpCppuGetType(out, *j);
    1553             :             }
    1554             :         }
    1555             :     }
    1556           0 : }
    1557             : 
    1558           0 : 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           0 :     out << " /*";
    1567             : #endif
    1568           0 :     out << " throw (";
    1569           0 :     bool first = true;
    1570           0 :     for (std::vector< OUString >::const_iterator i(exceptions.begin());
    1571           0 :          i != exceptions.end(); ++i)
    1572             :     {
    1573           0 :         if (*i != "com.sun.star.uno.RuntimeException") {
    1574           0 :             if (!first) {
    1575           0 :                 out << ", ";
    1576             :             }
    1577           0 :             out << codemaker::cpp::scopedCppName(u2b(*i));
    1578           0 :             first = false;
    1579             :         }
    1580             :     }
    1581           0 :     if (runtimeException) {
    1582           0 :         if (!first) {
    1583           0 :             out << ", ";
    1584             :         }
    1585           0 :         out << "::css::uno::RuntimeException, ::std::exception";
    1586             :     }
    1587           0 :     out << ")";
    1588             : #if !defined DBG_UTIL
    1589           0 :     out << " */";
    1590             : #endif
    1591           0 : }
    1592             : 
    1593           0 : void InterfaceType::dumpExceptionTypeName(
    1594             :     FileStream & out, OUString const & prefix, sal_uInt32 index,
    1595             :     OUString const & name)
    1596             : {
    1597           0 :     out << indent() << "::rtl::OUString the_" << prefix << "ExceptionName"
    1598           0 :         << index << "( \"" << name << "\" );\n";
    1599           0 : }
    1600             : 
    1601           0 : sal_Int32 InterfaceType::dumpExceptionTypeNames(
    1602             :     FileStream & out, OUString const & prefix,
    1603             :     std::vector< OUString > const & exceptions, bool runtimeException)
    1604             : {
    1605           0 :     sal_Int32 count = 0;
    1606           0 :     for (std::vector< OUString >::const_iterator i(exceptions.begin());
    1607           0 :          i != exceptions.end(); ++i)
    1608             :     {
    1609           0 :         if (*i != "com.sun.star.uno.RuntimeException") {
    1610           0 :             dumpExceptionTypeName(out, prefix, count++, *i);
    1611             :         }
    1612             :     }
    1613           0 :     if (runtimeException) {
    1614             :         dumpExceptionTypeName(
    1615           0 :             out, prefix, count++, "com.sun.star.uno.RuntimeException");
    1616             :     }
    1617           0 :     if (count != 0) {
    1618           0 :         out << indent() << "rtl_uString * the_" << prefix << "Exceptions[] = {";
    1619           0 :         for (sal_Int32 i = 0; i != count; ++i) {
    1620           0 :             out << (i == 0 ? " " : ", ") << "the_" << prefix << "ExceptionName"
    1621           0 :                 << i << ".pData";
    1622             :         }
    1623           0 :         out << " };\n";
    1624             :     }
    1625           0 :     return count;
    1626             : }
    1627             : 
    1628           0 : class ConstantGroup: public CppuType {
    1629             : public:
    1630           0 :     ConstantGroup(
    1631             :         rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
    1632             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    1633           0 :         CppuType(name, typeMgr), entity_(entity)
    1634           0 :     { assert(entity.is()); }
    1635             : 
    1636           0 :     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           0 : void ConstantGroup::dumpHFile(
    1651             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    1652             : {
    1653           0 :     OUString headerDefine(dumpHeaderDefine(out, "HDL"));
    1654           0 :     out << "\n";
    1655           0 :     addDefaultHIncludes(includes);
    1656           0 :     includes.dump(out, 0);
    1657           0 :     out << "\n";
    1658           0 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, true)) {
    1659           0 :         out << "\n";
    1660             :     }
    1661           0 :     out << "\n";
    1662           0 :     dumpDeclaration(out);
    1663           0 :     out << "\n";
    1664           0 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, true)) {
    1665           0 :         out << "\n";
    1666             :     }
    1667           0 :     out << "\n#endif // "<< headerDefine << "\n";
    1668           0 : }
    1669             : 
    1670           0 : void ConstantGroup::dumpHxxFile(
    1671             :     FileStream & out, codemaker::cppumaker::Includes &)
    1672             : {
    1673           0 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    1674           0 :     out << "\n";
    1675           0 :     codemaker::cppumaker::Includes::dumpInclude(out, u2b(name_), false);
    1676           0 :     out << "\n#endif // "<< headerDefine << "\n";
    1677           0 : }
    1678             : 
    1679           0 : void ConstantGroup::dumpDeclaration(FileStream & out) {
    1680           0 :     for (std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator i(
    1681           0 :              entity_->getMembers().begin());
    1682           0 :          i != entity_->getMembers().end(); ++i)
    1683             :     {
    1684           0 :         out << "static const ";
    1685           0 :         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           0 :             out << "::sal_Int8";
    1691           0 :             break;
    1692             :         case unoidl::ConstantValue::TYPE_SHORT:
    1693           0 :             out << "::sal_Int16";
    1694           0 :             break;
    1695             :         case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
    1696           0 :             out << "::sal_uInt16";
    1697           0 :             break;
    1698             :         case unoidl::ConstantValue::TYPE_LONG:
    1699           0 :             out << "::sal_Int32";
    1700           0 :             break;
    1701             :         case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
    1702           0 :             out << "::sal_uInt32";
    1703           0 :             break;
    1704             :         case unoidl::ConstantValue::TYPE_HYPER:
    1705           0 :             out << "::sal_Int64";
    1706           0 :             break;
    1707             :         case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
    1708           0 :             out << "::sal_uInt64";
    1709           0 :             break;
    1710             :         case unoidl::ConstantValue::TYPE_FLOAT:
    1711           0 :             out << "float";
    1712           0 :             break;
    1713             :         case unoidl::ConstantValue::TYPE_DOUBLE:
    1714           0 :             out << "double";
    1715           0 :             break;
    1716             :         }
    1717           0 :         out << " " << i->name << " = ";
    1718           0 :         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           0 :             out << "(sal_Int8)" << OUString::number(i->value.byteValue);
    1724           0 :             break;
    1725             :         case unoidl::ConstantValue::TYPE_SHORT:
    1726           0 :             out << "(sal_Int16)" << OUString::number(i->value.shortValue);
    1727           0 :             break;
    1728             :         case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
    1729           0 :             out << "(sal_uInt16)"
    1730           0 :                 << OUString::number(i->value.unsignedShortValue);
    1731           0 :             break;
    1732             :         case unoidl::ConstantValue::TYPE_LONG:
    1733             :             // Avoid C++ compiler warnings about (un)signedness of literal
    1734             :             // -2^31:
    1735           0 :             if (i->value.longValue == SAL_MIN_INT32) {
    1736           0 :                 out << "SAL_MIN_INT32";
    1737             :             } else {
    1738           0 :                 out << "(sal_Int32)" << OUString::number(i->value.longValue);
    1739             :             }
    1740           0 :             break;
    1741             :         case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
    1742           0 :             out << "(sal_uInt32)"
    1743           0 :                 << OUString::number(i->value.unsignedLongValue) << "U";
    1744           0 :             break;
    1745             :         case unoidl::ConstantValue::TYPE_HYPER:
    1746             :             // Avoid C++ compiler warnings about (un)signedness of literal
    1747             :             // -2^63:
    1748           0 :             if (i->value.hyperValue == SAL_MIN_INT64) {
    1749           0 :                 out << "SAL_MIN_INT64";
    1750             :             } else {
    1751           0 :                 out << "(sal_Int64) SAL_CONST_INT64("
    1752           0 :                     << OUString::number(i->value.hyperValue) << ")";
    1753             :             }
    1754           0 :             break;
    1755             :         case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
    1756           0 :             out << "SAL_CONST_UINT64("
    1757           0 :                 << OUString::number(i->value.unsignedHyperValue) << ")";
    1758           0 :             break;
    1759             :         case unoidl::ConstantValue::TYPE_FLOAT:
    1760           0 :             out << "(float)" << OUString::number(i->value.floatValue);
    1761           0 :             break;
    1762             :         case unoidl::ConstantValue::TYPE_DOUBLE:
    1763           0 :             out << "(double)" << OUString::number(i->value.doubleValue);
    1764           0 :             break;
    1765             :         }
    1766           0 :         out << ";\n";
    1767             :     }
    1768           0 : }
    1769             : 
    1770           0 : 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           0 :     out << "typeparam_" << name;
    1775           0 : }
    1776             : 
    1777           0 : class PlainStructType: public CppuType {
    1778             : public:
    1779           0 :     PlainStructType(
    1780             :         rtl::Reference< unoidl::PlainStructTypeEntity > const & entity,
    1781             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    1782           0 :         CppuType(name, typeMgr), entity_(entity)
    1783           0 :     { 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           0 : void PlainStructType::dumpDeclaration(FileStream & out) {
    1817           0 :     out << "\n#ifdef SAL_W32\n#   pragma pack(push, 8)\n#endif\n\n" << indent()
    1818           0 :         << "struct " << id_;
    1819           0 :     OUString base(entity_->getDirectBase());
    1820           0 :     if (!base.isEmpty()) {
    1821           0 :         out << ": public " << codemaker::cpp::scopedCppName(u2b(base));
    1822             :     }
    1823           0 :     out << " {\n";
    1824           0 :     inc();
    1825           0 :     out << indent() << "inline " << id_ << "() SAL_THROW(());\n";
    1826           0 :     if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
    1827           0 :         out << "\n" << indent() << "inline " << id_ << "(";
    1828           0 :         bool first = !dumpBaseMembers(out, base, true);
    1829           0 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    1830           0 :                  const_iterator i(entity_->getDirectMembers().begin());
    1831           0 :              i != entity_->getDirectMembers().end(); ++i)
    1832             :         {
    1833           0 :             if (!first) {
    1834           0 :                 out << ", ";
    1835             :             }
    1836           0 :             dumpType(out, i->type, true, true);
    1837           0 :             out << " " << i->name << "_";
    1838           0 :             first = false;
    1839             :         }
    1840           0 :         out << ") SAL_THROW(());\n";
    1841             :     }
    1842           0 :     if (!entity_->getDirectMembers().empty()) {
    1843           0 :         out << "\n";
    1844           0 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    1845           0 :                  const_iterator i(entity_->getDirectMembers().begin());
    1846           0 :              i != entity_->getDirectMembers().end(); ++i)
    1847             :         {
    1848           0 :             out << indent();
    1849           0 :             dumpType(out, i->type);
    1850           0 :             out << " " << i->name;
    1851           0 :             if (i == entity_->getDirectMembers().begin() && !base.isEmpty()
    1852           0 :                 && i->type != "hyper" && i->type != "unsigned hyper"
    1853           0 :                 && i->type != "double")
    1854             :             {
    1855           0 :                 out << " CPPU_GCC3_ALIGN("
    1856           0 :                     << codemaker::cpp::scopedCppName(u2b(base)) << ")";
    1857             :             }
    1858           0 :             out << ";\n";
    1859             :         }
    1860             :     }
    1861           0 :     dec();
    1862           0 :     out << "};\n\n#ifdef SAL_W32\n#   pragma pack(pop)\n#endif\n\n";
    1863           0 : }
    1864             : 
    1865           0 : void PlainStructType::dumpHxxFile(
    1866             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    1867             : {
    1868           0 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    1869           0 :     out << "\n";
    1870           0 :     includes.dump(out, &name_);
    1871           0 :     out << "\n";
    1872           0 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
    1873           0 :         out << "\n";
    1874             :     }
    1875           0 :     out << "\ninline " << id_ << "::" << id_ << "() SAL_THROW(())\n";
    1876           0 :     inc();
    1877           0 :     OUString base(entity_->getDirectBase());
    1878           0 :     bool first = true;
    1879           0 :     if (!base.isEmpty()) {
    1880           0 :         out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
    1881           0 :             << "()\n";
    1882           0 :         first = false;
    1883             :     }
    1884           0 :     for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
    1885           0 :              entity_->getDirectMembers().begin());
    1886           0 :          i != entity_->getDirectMembers().end(); ++i)
    1887             :     {
    1888           0 :         out << indent() << (first ? ":" : ",") << " " << i->name;
    1889           0 :         dumpInitializer(out, false, i->type);
    1890           0 :         out << "\n";
    1891           0 :         first = false;
    1892             :     }
    1893           0 :     dec();
    1894           0 :     out << "{\n}\n\n";
    1895           0 :     if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
    1896           0 :         out << "inline " << id_;
    1897           0 :         out << "::" << id_ << "(";
    1898           0 :         first = !dumpBaseMembers(out, base, true);
    1899           0 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    1900           0 :                  const_iterator i(entity_->getDirectMembers().begin());
    1901           0 :              i != entity_->getDirectMembers().end(); ++i)
    1902             :         {
    1903           0 :             if (!first) {
    1904           0 :                 out << ", ";
    1905             :             }
    1906           0 :             dumpType(out, i->type, true, true);
    1907           0 :             out << " " << i->name << "_";
    1908           0 :             first = false;
    1909             :         }
    1910           0 :         out << ") SAL_THROW(())\n";
    1911           0 :         inc();
    1912           0 :         first = true;
    1913           0 :         if (!base.isEmpty()) {
    1914           0 :             out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
    1915           0 :                 << "(";
    1916           0 :             dumpBaseMembers(out, base, false);
    1917           0 :             out << ")\n";
    1918           0 :             first = false;
    1919             :         }
    1920           0 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    1921           0 :                  const_iterator i(entity_->getDirectMembers().begin());
    1922           0 :              i != entity_->getDirectMembers().end(); ++i)
    1923             :         {
    1924           0 :             out << indent() << (first ? ":" : ",") << " " << i->name << "("
    1925           0 :                 << i->name << "_)\n";
    1926           0 :             first = false;
    1927             :         }
    1928           0 :         dec();
    1929           0 :         out << "{\n}\n\n";
    1930             :     }
    1931           0 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
    1932           0 :         out << "\n";
    1933             :     }
    1934           0 :     out << "\n";
    1935           0 :     dumpGetCppuType(out);
    1936           0 :     out << "\n#endif // "<< headerDefine << "\n";
    1937           0 : }
    1938             : 
    1939           0 : void PlainStructType::dumpLightGetCppuType(FileStream & out) {
    1940           0 :     dumpGetCppuTypePreamble(out);
    1941           0 :     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           0 :             " points to garbage\n")
    1945           0 :         << indent()
    1946           0 :         << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
    1947           0 :         << indent() << "if (the_type == 0) {\n";
    1948           0 :     inc();
    1949           0 :     out << indent() << "::typelib_static_type_init(&the_type, "
    1950           0 :         << getTypeClass(name_, true) << ", \"" << name_ << "\");\n";
    1951           0 :     dec();
    1952           0 :     out << indent() << "}\n" << indent()
    1953           0 :         << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
    1954           0 :     dumpGetCppuTypePostamble(out);
    1955           0 : }
    1956             : 
    1957           0 : void PlainStructType::dumpNormalGetCppuType(FileStream & out) {
    1958           0 :     dumpGetCppuTypePreamble(out);
    1959           0 :     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           0 :             " points to garbage\n")
    1963           0 :         << indent()
    1964           0 :         << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
    1965           0 :         << indent() << "if (the_type == 0) {\n";
    1966           0 :     inc();
    1967           0 :     out << indent()
    1968           0 :         << "::typelib_TypeDescriptionReference * the_members[] = {\n";
    1969           0 :     inc();
    1970           0 :     for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
    1971           0 :              entity_->getDirectMembers().begin());
    1972           0 :          i != entity_->getDirectMembers().end();)
    1973             :     {
    1974           0 :         out << indent() << "::cppu::UnoType< ";
    1975           0 :         dumpType(out, i->type, false, false, false, true);
    1976           0 :         ++i;
    1977           0 :         out << " >::get().getTypeLibType()"
    1978           0 :             << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n";
    1979             :     }
    1980           0 :     dec();
    1981           0 :     out << indent() << "::typelib_static_struct_type_init(&the_type, \""
    1982           0 :         << name_ << "\", ";
    1983           0 :     if (entity_->getDirectBase().isEmpty()) {
    1984           0 :         out << "0";
    1985             :     } else {
    1986           0 :         out << "::cppu::UnoType< ";
    1987           0 :         dumpType(out, entity_->getDirectBase(), false, false, false, true);
    1988           0 :         out << " >::get().getTypeLibType()";
    1989             :     }
    1990           0 :     out << ", " << entity_->getDirectMembers().size() << ", the_members, 0);\n";
    1991           0 :     dec();
    1992           0 :     out << indent() << "}\n" << indent()
    1993           0 :         << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
    1994           0 :     dumpGetCppuTypePostamble(out);
    1995           0 : }
    1996             : 
    1997           0 : void PlainStructType::dumpComprehensiveGetCppuType(FileStream & out) {
    1998           0 :     OUString staticTypeClass("the" + id_ + "Type");
    1999           0 :     codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
    2000           0 :     out << " namespace detail {\n\n" << indent() << "struct "
    2001           0 :         << staticTypeClass
    2002           0 :         << " : public rtl::StaticWithInit< ::css::uno::Type *, "
    2003           0 :         << staticTypeClass << " >\n" << indent() << "{\n";
    2004           0 :     inc();
    2005           0 :     out << indent() << "::css::uno::Type * operator()() const\n"
    2006           0 :         << indent() << "{\n";
    2007           0 :     inc();
    2008           0 :     out << indent() << "::rtl::OUString the_name( \"" << name_ << "\" );\n";
    2009           0 :     std::map< OUString, sal_uInt32 > types;
    2010           0 :     std::vector< unoidl::PlainStructTypeEntity::Member >::size_type n = 0;
    2011           0 :     for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
    2012           0 :              entity_->getDirectMembers().begin());
    2013           0 :          i != entity_->getDirectMembers().end(); ++i)
    2014             :     {
    2015           0 :         if (types.insert(
    2016             :                 std::map< OUString, sal_uInt32 >::value_type(
    2017           0 :                     i->type, static_cast< sal_uInt32 >(types.size()))).
    2018             :             second)
    2019             :         {
    2020           0 :             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           0 :             out << indent() << "::rtl::OUString the_tname"
    2027           0 :                 << static_cast< sal_uInt32 >(types.size() - 1) << "( \""
    2028           0 :                 << resolveAllTypedefs(i->type) << "\" );\n";
    2029             :         }
    2030           0 :         out << indent() << "::rtl::OUString the_name" << n++ << "( \""
    2031           0 :             << i->name << "\" );\n";
    2032             :     }
    2033           0 :     out << indent() << "::typelib_StructMember_Init the_members[] = {\n";
    2034           0 :     inc();
    2035           0 :     n = 0;
    2036           0 :     for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
    2037           0 :              entity_->getDirectMembers().begin());
    2038           0 :          i != entity_->getDirectMembers().end();)
    2039             :     {
    2040           0 :         out << indent() << "{ { " << getTypeClass(i->type, true)
    2041           0 :             << ", the_tname" << types.find(i->type)->second
    2042           0 :             << ".pData, the_name" << n++ << ".pData }, false }";
    2043           0 :         ++i;
    2044           0 :         out << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n";
    2045             :     }
    2046           0 :     dec();
    2047           0 :     out << indent() << "::typelib_TypeDescription * the_newType = 0;\n"
    2048           0 :         << indent()
    2049           0 :         << "::typelib_typedescription_newStruct(&the_newType, the_name.pData, ";
    2050           0 :     if (entity_->getDirectBase().isEmpty()) {
    2051           0 :         out << "0";
    2052             :     } else {
    2053           0 :         out << "::cppu::UnoType< ";
    2054           0 :         dumpType(out, entity_->getDirectBase(), false, false, false, true);
    2055           0 :         out << " >::get().getTypeLibType()";
    2056             :     }
    2057           0 :     out << ", " << entity_->getDirectMembers().size() << ", the_members);\n"
    2058           0 :         << indent() << "::typelib_typedescription_register(&the_newType);\n"
    2059           0 :         << indent() << "::typelib_typedescription_release(the_newType);\n"
    2060           0 :         << indent() << "return new ::css::uno::Type("
    2061           0 :         << getTypeClass(name_) << ", the_name); // leaked\n";
    2062           0 :     dec();
    2063           0 :     out << indent() << "}\n";
    2064           0 :     dec();
    2065           0 :     out << indent() << "};\n";
    2066           0 :     codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
    2067           0 :     out << " }\n\n";
    2068           0 :     dumpGetCppuTypePreamble(out);
    2069           0 :     out << indent() << "return *detail::" << staticTypeClass << "::get();\n";
    2070           0 :     dumpGetCppuTypePostamble(out);
    2071           0 : }
    2072             : 
    2073           0 : bool PlainStructType::dumpBaseMembers(
    2074             :     FileStream & out, OUString const & base, bool withType)
    2075             : {
    2076           0 :     bool hasMember = false;
    2077           0 :     if (!base.isEmpty()) {
    2078           0 :         rtl::Reference< unoidl::Entity > ent;
    2079           0 :         codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
    2080           0 :         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           0 :             dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()));
    2087             :         assert(ent2.is());
    2088           0 :         hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType);
    2089           0 :         for (std::vector< unoidl::PlainStructTypeEntity::Member >::
    2090           0 :                  const_iterator i(ent2->getDirectMembers().begin());
    2091           0 :              i != ent2->getDirectMembers().end(); ++i)
    2092             :         {
    2093           0 :             if (hasMember) {
    2094           0 :                 out << ", ";
    2095             :             }
    2096           0 :             if (withType) {
    2097           0 :                 dumpType(out, i->type, true, true);
    2098           0 :                 out << " ";
    2099             :             }
    2100           0 :             out << i->name << "_";
    2101           0 :             hasMember = true;
    2102           0 :         }
    2103             :     }
    2104           0 :     return hasMember;
    2105             : }
    2106             : 
    2107           0 : void PlainStructType::addLightGetCppuTypeIncludes(
    2108             :     codemaker::cppumaker::Includes & includes) const
    2109             : {
    2110           0 :     includes.addType();
    2111           0 :     includes.addCppuUnotypeHxx();
    2112           0 :     includes.addSalTypesH();
    2113           0 :     includes.addTypelibTypeclassH();
    2114           0 :     includes.addTypelibTypedescriptionH();
    2115           0 : }
    2116             : 
    2117           0 : void PlainStructType::addNormalGetCppuTypeIncludes(
    2118             :     codemaker::cppumaker::Includes & includes) const
    2119             : {
    2120           0 :     includes.addType();
    2121           0 :     includes.addCppuUnotypeHxx();
    2122           0 :     includes.addSalTypesH();
    2123           0 :     includes.addTypelibTypeclassH();
    2124           0 :     includes.addTypelibTypedescriptionH();
    2125           0 : }
    2126             : 
    2127           0 : void PlainStructType::addComprehensiveGetCppuTypeIncludes(
    2128             :     codemaker::cppumaker::Includes & includes) const
    2129             : {
    2130           0 :     includes.addType();
    2131           0 :     includes.addCppuUnotypeHxx();
    2132           0 :     includes.addRtlInstanceHxx();
    2133           0 :     includes.addOslMutexHxx();
    2134           0 :     includes.addRtlUstringH();
    2135           0 :     includes.addRtlUstringHxx();
    2136           0 :     includes.addSalTypesH();
    2137           0 :     includes.addTypelibTypeclassH();
    2138           0 :     includes.addTypelibTypedescriptionH();
    2139           0 : }
    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           0 : class PolyStructType: public CppuType {
    2159             : public:
    2160           0 :     PolyStructType(
    2161             :         rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
    2162             :             entity,
    2163             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    2164           0 :         CppuType(name, typeMgr), entity_(entity)
    2165           0 :     { 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           0 :     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           0 : void PolyStructType::dumpDeclaration(FileStream & out) {
    2197           0 :     out << "\n#ifdef SAL_W32\n#   pragma pack(push, 8)\n#endif\n\n" << indent();
    2198           0 :     dumpTemplateHead(out);
    2199           0 :     out << "struct " << id_ << " {\n";
    2200           0 :     inc();
    2201           0 :     out << indent() << "inline " << id_ << "() SAL_THROW(());\n";
    2202           0 :     if (!entity_->getMembers().empty()) {
    2203           0 :         out << "\n" << indent() << "inline " << id_ << "(";
    2204           0 :         for (std::vector<
    2205             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2206           0 :                  const_iterator i(entity_->getMembers().begin());
    2207           0 :              i != entity_->getMembers().end(); ++i)
    2208             :         {
    2209           0 :             if (i != entity_->getMembers().begin()) {
    2210           0 :                 out << ", ";
    2211             :             }
    2212           0 :             if (i->parameterized) {
    2213           0 :                 dumpTypeParameterName(out, i->type);
    2214           0 :                 out << " const &";
    2215             :             } else {
    2216           0 :                 dumpType(out, i->type, true, true);
    2217             :             }
    2218           0 :             out << " " << i->name << "_";
    2219             :         }
    2220           0 :         out << ") SAL_THROW(());\n\n";
    2221           0 :         for (std::vector<
    2222             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2223           0 :                  const_iterator i(entity_->getMembers().begin());
    2224           0 :              i != entity_->getMembers().end(); ++i)
    2225             :         {
    2226           0 :             out << indent();
    2227           0 :             if (i->parameterized) {
    2228           0 :                 dumpTypeParameterName(out, i->type);
    2229             :             } else {
    2230           0 :                 dumpType(out, i->type);
    2231             :             }
    2232           0 :             out << " " << i->name << ";\n";
    2233             :         }
    2234             :     }
    2235           0 :     dec();
    2236           0 :     out << "};\n\n#ifdef SAL_W32\n#   pragma pack(pop)\n#endif\n\n";
    2237           0 : }
    2238             : 
    2239           0 : void PolyStructType::dumpHxxFile(
    2240             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    2241             : {
    2242           0 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    2243           0 :     out << "\n";
    2244           0 :     includes.dump(out, &name_);
    2245           0 :     out << "\n";
    2246           0 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
    2247           0 :         out << "\n";
    2248             :     }
    2249           0 :     out << "\n";
    2250           0 :     dumpTemplateHead(out);
    2251           0 :     out << "inline " << id_;
    2252           0 :     dumpTemplateParameters(out);
    2253           0 :     out << "::" << id_ << "() SAL_THROW(())\n";
    2254           0 :     inc();
    2255           0 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2256           0 :              const_iterator i(entity_->getMembers().begin());
    2257           0 :          i != entity_->getMembers().end(); ++i)
    2258             :     {
    2259           0 :         out << indent() << (i == entity_->getMembers().begin() ? ":" : ",")
    2260           0 :             << " " << i->name;
    2261           0 :         dumpInitializer(out, i->parameterized, i->type);
    2262           0 :         out << "\n";
    2263             :     }
    2264           0 :     dec();
    2265           0 :     out << "{\n}\n\n";
    2266           0 :     if (!entity_->getMembers().empty()) {
    2267           0 :         dumpTemplateHead(out);
    2268           0 :         out << "inline " << id_;
    2269           0 :         dumpTemplateParameters(out);
    2270           0 :         out << "::" << id_ << "(";
    2271           0 :         for (std::vector<
    2272             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2273           0 :                  const_iterator i(entity_->getMembers().begin());
    2274           0 :              i != entity_->getMembers().end(); ++i)
    2275             :         {
    2276           0 :             if (i != entity_->getMembers().begin()) {
    2277           0 :                 out << ", ";
    2278             :             }
    2279           0 :             if (i->parameterized) {
    2280           0 :                 dumpTypeParameterName(out, i->type);
    2281           0 :                 out << " const &";
    2282             :             } else {
    2283           0 :                 dumpType(out, i->type, true, true);
    2284             :             }
    2285           0 :             out << " " << i->name << "_";
    2286             :         }
    2287           0 :         out << ") SAL_THROW(())\n";
    2288           0 :         inc();
    2289           0 :         for (std::vector<
    2290             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2291           0 :                  const_iterator i(entity_->getMembers().begin());
    2292           0 :              i != entity_->getMembers().end(); ++i)
    2293             :         {
    2294           0 :             out << indent() << (i == entity_->getMembers().begin() ? ":" : ",")
    2295           0 :                 << " " << i->name << "(" << i->name << "_)\n";
    2296             :         }
    2297           0 :         dec();
    2298           0 :         out << "{\n}\n\n" << indent();
    2299           0 :         dumpTemplateHead(out);
    2300           0 :         out << "\n" << indent() << "inline " << id_;
    2301           0 :         dumpTemplateParameters(out);
    2302           0 :         out << "\n" << indent() << "make_" << id_ << "(";
    2303           0 :         for (std::vector<
    2304             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2305           0 :                  const_iterator i(entity_->getMembers().begin());
    2306           0 :              i != entity_->getMembers().end(); ++i)
    2307             :         {
    2308           0 :             if (i != entity_->getMembers().begin()) {
    2309           0 :                 out << ", ";
    2310             :             }
    2311           0 :             if (i->parameterized) {
    2312           0 :                 dumpTypeParameterName(out, i->type);
    2313           0 :                 out << " const &";
    2314             :             } else {
    2315           0 :                 dumpType(out, i->type, true, true);
    2316             :             }
    2317           0 :             out << " " << i->name << "_";
    2318             :         }
    2319           0 :         out << ") SAL_THROW(())\n" << indent() << "{\n";
    2320           0 :         inc();
    2321           0 :         out << indent() << "return " << id_;
    2322           0 :         dumpTemplateParameters(out);
    2323           0 :         out << "(";
    2324           0 :         for (std::vector<
    2325             :                  unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2326           0 :                  const_iterator i(entity_->getMembers().begin());
    2327           0 :              i != entity_->getMembers().end(); ++i)
    2328             :         {
    2329           0 :             if (i != entity_->getMembers().begin()) {
    2330           0 :                 out << ", ";
    2331             :             }
    2332           0 :             out << i->name << "_";
    2333             :         }
    2334           0 :         out << ");\n";
    2335           0 :         dec();
    2336           0 :         out << indent() << "}\n\n";
    2337             :     }
    2338           0 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
    2339           0 :         out << "\n";
    2340             :     }
    2341           0 :     out << "\n";
    2342           0 :     dumpGetCppuType(out);
    2343           0 :     out << "\n#endif // "<< headerDefine << "\n";
    2344           0 : }
    2345             : 
    2346           0 : void PolyStructType::dumpLightGetCppuType(FileStream & out) {
    2347           0 :     dumpGetCppuTypePreamble(out);
    2348           0 :     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           0 :             " points to garbage\n")
    2352           0 :         << indent()
    2353           0 :         << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
    2354           0 :         << indent() << "if (the_type == 0) {\n";
    2355           0 :     inc();
    2356           0 :     out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
    2357           0 :         << "<\");\n";
    2358           0 :     for (std::vector< OUString >::const_iterator i(
    2359           0 :              entity_->getTypeParameters().begin());
    2360           0 :          i != entity_->getTypeParameters().end();)
    2361             :     {
    2362           0 :         out << indent()
    2363             :             << ("the_buffer.append(::rtl::OUStringToOString("
    2364           0 :                 "::cppu::getTypeFavourChar(static_cast< ");
    2365           0 :         dumpTypeParameterName(out, *i);
    2366           0 :         out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
    2367           0 :         ++i;
    2368           0 :         if (i != entity_->getTypeParameters().end()) {
    2369           0 :             out << indent() << "the_buffer.append(',');\n";
    2370             :         }
    2371             :     }
    2372           0 :     out << indent() << "the_buffer.append('>');\n" << indent()
    2373           0 :         << "::typelib_static_type_init(&the_type, " << getTypeClass(name_, true)
    2374           0 :         << ", the_buffer.getStr());\n";
    2375           0 :     dec();
    2376           0 :     out << indent() << "}\n" << indent()
    2377           0 :         << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
    2378           0 :     dumpGetCppuTypePostamble(out);
    2379           0 : }
    2380             : 
    2381           0 : void PolyStructType::dumpNormalGetCppuType(FileStream & out) {
    2382           0 :     dumpGetCppuTypePreamble(out);
    2383           0 :     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           0 :             " points to garbage\n")
    2387           0 :         << indent()
    2388           0 :         << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
    2389           0 :         << indent() << "if (the_type == 0) {\n";
    2390           0 :     inc();
    2391           0 :     out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
    2392           0 :         << "<\");\n";
    2393           0 :     for (std::vector< OUString >::const_iterator i(
    2394           0 :              entity_->getTypeParameters().begin());
    2395           0 :          i != entity_->getTypeParameters().end();)
    2396             :     {
    2397           0 :         out << indent()
    2398             :             << ("the_buffer.append(::rtl::OUStringToOString("
    2399           0 :                 "::cppu::getTypeFavourChar(static_cast< ");
    2400           0 :         dumpTypeParameterName(out, *i);
    2401           0 :         out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
    2402           0 :         ++i;
    2403           0 :         if (i != entity_->getTypeParameters().end()) {
    2404           0 :             out << indent() << "the_buffer.append(',');\n";
    2405             :         }
    2406             :     }
    2407           0 :     out << indent() << "the_buffer.append('>');\n" << indent()
    2408           0 :         << "::typelib_TypeDescriptionReference * the_members[] = {\n";
    2409           0 :     inc();
    2410           0 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2411           0 :              const_iterator i(entity_->getMembers().begin());
    2412           0 :          i != entity_->getMembers().end();)
    2413             :     {
    2414           0 :         out << indent();
    2415           0 :         if (i->parameterized) {
    2416           0 :             out << "::cppu::getTypeFavourChar(static_cast< ";
    2417           0 :             dumpTypeParameterName(out, i->type);
    2418           0 :             out << " * >(0))";
    2419             :         } else {
    2420           0 :             out << "::cppu::UnoType< ";
    2421           0 :             dumpType(out, i->type, false, false, false, true);
    2422           0 :             out << " >::get()";
    2423             :         }
    2424           0 :         ++i;
    2425           0 :         out << ".getTypeLibType()"
    2426           0 :             << (i == entity_->getMembers().end() ? " };" : ",") << "\n";
    2427             :     }
    2428           0 :     dec();
    2429           0 :     out << indent() << "static ::sal_Bool const the_parameterizedTypes[] = { ";
    2430           0 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2431           0 :              const_iterator i(entity_->getMembers().begin());
    2432           0 :          i != entity_->getMembers().end(); ++i)
    2433             :     {
    2434           0 :         if (i != entity_->getMembers().begin()) {
    2435           0 :             out << ", ";
    2436             :         }
    2437           0 :         out << (i->parameterized ? "true" : "false");
    2438             :     }
    2439           0 :     out << " };\n" << indent()
    2440             :         << ("::typelib_static_struct_type_init(&the_type, the_buffer.getStr(),"
    2441           0 :             " 0, ")
    2442           0 :         << entity_->getMembers().size()
    2443           0 :         << ", the_members, the_parameterizedTypes);\n";
    2444           0 :     dec();
    2445           0 :     out << indent() << "}\n" << indent()
    2446             :         << ("return *reinterpret_cast< ::css::uno::Type * >("
    2447           0 :             "&the_type);\n");
    2448           0 :     dumpGetCppuTypePostamble(out);
    2449           0 : }
    2450             : 
    2451           0 : void PolyStructType::dumpComprehensiveGetCppuType(FileStream & out) {
    2452           0 :     out << "namespace cppu {  namespace detail {\n\n" << indent();
    2453           0 :     dumpTemplateHead(out);
    2454           0 :     OUString staticTypeClass("the" + id_ + "Type");
    2455           0 :     out << "struct " << staticTypeClass
    2456           0 :         << " : public rtl::StaticWithInit< ::css::uno::Type *, "
    2457           0 :         << staticTypeClass;
    2458           0 :     dumpTemplateParameters(out);
    2459           0 :     out << " >\n" << indent() << "{\n";
    2460           0 :     inc();
    2461           0 :     out << indent() << "::css::uno::Type * operator()() const\n"
    2462           0 :         << indent() << "{\n";
    2463           0 :     inc();
    2464           0 :     out << indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent()
    2465           0 :         << "the_buffer.append(\"" << name_ << "<\");\n";
    2466           0 :     for (std::vector< OUString >::const_iterator i(
    2467           0 :              entity_->getTypeParameters().begin());
    2468           0 :          i != entity_->getTypeParameters().end();)
    2469             :     {
    2470           0 :         out << indent()
    2471           0 :             << "the_buffer.append(::cppu::getTypeFavourChar(static_cast< ";
    2472           0 :         dumpTypeParameterName(out, *i);
    2473           0 :         out << " * >(0)).getTypeName());\n";
    2474           0 :         ++i;
    2475           0 :         if (i != entity_->getTypeParameters().end()) {
    2476           0 :             out << indent()
    2477             :                 << ("the_buffer.append("
    2478           0 :                     "static_cast< ::sal_Unicode >(','));\n");
    2479             :         }
    2480             :     }
    2481           0 :     out << indent() << "the_buffer.append(static_cast< ::sal_Unicode >('>'));\n"
    2482           0 :         << indent()
    2483           0 :         << "::rtl::OUString the_name(the_buffer.makeStringAndClear());\n";
    2484           0 :     std::map< OUString, sal_uInt32 > parameters;
    2485           0 :     std::map< OUString, sal_uInt32 > types;
    2486             :     std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2487           0 :         size_type n = 0;
    2488           0 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2489           0 :              const_iterator i(entity_->getMembers().begin());
    2490           0 :          i != entity_->getMembers().end(); ++i)
    2491             :     {
    2492           0 :         if (i->parameterized) {
    2493           0 :             if (parameters.insert(
    2494             :                     std::map< OUString, sal_uInt32 >::value_type(
    2495           0 :                         i->type, static_cast< sal_uInt32 >(parameters.size()))).
    2496             :                 second)
    2497             :             {
    2498           0 :                 sal_uInt32 k = static_cast< sal_uInt32 >(parameters.size() - 1);
    2499           0 :                 out << indent()
    2500           0 :                     << "::css::uno::Type const & the_ptype" << k
    2501           0 :                     << " = ::cppu::getTypeFavourChar(static_cast< ";
    2502           0 :                 dumpTypeParameterName(out, i->type);
    2503           0 :                 out << " * >(0));\n" << indent()
    2504           0 :                     << "::typelib_TypeClass the_pclass" << k
    2505           0 :                     << " = (::typelib_TypeClass) the_ptype" << k
    2506           0 :                     << ".getTypeClass();\n" << indent()
    2507           0 :                     << "::rtl::OUString the_pname" << k << "(the_ptype" << k
    2508           0 :                     << ".getTypeName());\n";
    2509             :             }
    2510           0 :         } else if (types.insert(
    2511             :                        std::map< OUString, sal_uInt32 >::value_type(
    2512           0 :                            i->type, static_cast< sal_uInt32 >(types.size()))).
    2513             :                    second)
    2514             :         {
    2515           0 :             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           0 :             out << indent() << "::rtl::OUString the_tname"
    2522           0 :                 << static_cast< sal_uInt32 >(types.size() - 1) << "( \""
    2523           0 :                 << resolveAllTypedefs(i->type) << "\" );\n";
    2524             :         }
    2525           0 :         out << indent() << "::rtl::OUString the_name" << n++ << "( \""
    2526           0 :             << i->name << "\" );\n";
    2527             :     }
    2528           0 :     out << indent() << "::typelib_StructMember_Init the_members[] = {\n";
    2529           0 :     inc();
    2530           0 :     n = 0;
    2531           0 :     for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
    2532           0 :              const_iterator i(entity_->getMembers().begin());
    2533           0 :          i != entity_->getMembers().end();)
    2534             :     {
    2535           0 :         out << indent() << "{ { ";
    2536           0 :         if (i->parameterized) {
    2537           0 :             sal_uInt32 k = parameters.find(i->type)->second;
    2538           0 :             out << "the_pclass" << k << ", the_pname" << k << ".pData";
    2539             :         } else {
    2540           0 :             out << getTypeClass(i->type, true) << ", the_tname"
    2541           0 :                 << types.find(i->type)->second << ".pData";
    2542             :         }
    2543           0 :         out << ", the_name" << n++ << ".pData }, "
    2544           0 :             << (i->parameterized ? "true" : "false") << " }";
    2545           0 :         ++i;
    2546           0 :         out << (i == entity_->getMembers().end() ? " };" : ",") << "\n";
    2547             :     }
    2548           0 :     dec();
    2549           0 :     out << indent() << "::typelib_TypeDescription * the_newType = 0;\n";
    2550           0 :     out << indent()
    2551             :         << ("::typelib_typedescription_newStruct(&the_newType, the_name.pData,"
    2552           0 :             " 0, ")
    2553           0 :         << entity_->getMembers().size() << ", the_members);\n" << indent()
    2554           0 :         << "::typelib_typedescription_register(&the_newType);\n" << indent()
    2555           0 :         << "::typelib_typedescription_release(the_newType);\n" << indent()
    2556           0 :         << "return new ::css::uno::Type(" << getTypeClass(name_)
    2557           0 :         << ", the_name); // leaked\n";
    2558           0 :     dec();
    2559           0 :     out << indent() << "}\n";
    2560           0 :     dec();
    2561           0 :     out << indent() << "};\n" << " }" << " }\n\n";
    2562           0 :     dumpGetCppuTypePreamble(out);
    2563           0 :     out << indent() << "return *detail::" << staticTypeClass;
    2564           0 :     dumpTemplateParameters(out);
    2565           0 :     out << "::get();\n";
    2566           0 :     dumpGetCppuTypePostamble(out);
    2567           0 : }
    2568             : 
    2569           0 : void PolyStructType::addLightGetCppuTypeIncludes(
    2570             :     codemaker::cppumaker::Includes & includes) const
    2571             : {
    2572           0 :     includes.addType();
    2573           0 :     includes.addCppuUnotypeHxx();
    2574           0 :     includes.addSalTypesH();
    2575           0 :     includes.addTypelibTypeclassH();
    2576           0 :     includes.addTypelibTypedescriptionH();
    2577           0 :     includes.addRtlStrbufHxx();
    2578           0 :     includes.addRtlTextencH();
    2579           0 :     includes.addRtlUstringHxx();
    2580           0 : }
    2581             : 
    2582           0 : void PolyStructType::addNormalGetCppuTypeIncludes(
    2583             :     codemaker::cppumaker::Includes & includes) const
    2584             : {
    2585           0 :     includes.addType();
    2586           0 :     includes.addCppuUnotypeHxx();
    2587           0 :     includes.addSalTypesH();
    2588           0 :     includes.addTypelibTypeclassH();
    2589           0 :     includes.addTypelibTypedescriptionH();
    2590           0 :     includes.addRtlStrbufHxx();
    2591           0 :     includes.addRtlTextencH();
    2592           0 :     includes.addRtlUstringHxx();
    2593           0 : }
    2594             : 
    2595           0 : void PolyStructType::addComprehensiveGetCppuTypeIncludes(
    2596             :     codemaker::cppumaker::Includes & includes) const
    2597             : {
    2598           0 :     includes.addType();
    2599           0 :     includes.addCppuUnotypeHxx();
    2600           0 :     includes.addRtlInstanceHxx();
    2601           0 :     includes.addOslMutexHxx();
    2602           0 :     includes.addRtlUstringH();
    2603           0 :     includes.addRtlUstringHxx();
    2604           0 :     includes.addSalTypesH();
    2605           0 :     includes.addTypelibTypeclassH();
    2606           0 :     includes.addTypelibTypedescriptionH();
    2607           0 :     includes.addRtlStringH();
    2608           0 :     includes.addRtlUstrbufHxx();
    2609           0 : }
    2610             : 
    2611           0 : void PolyStructType::dumpTemplateHead(FileStream & out) const {
    2612           0 :     out << "template< ";
    2613           0 :     for (std::vector< OUString >::const_iterator i(
    2614           0 :              entity_->getTypeParameters().begin());
    2615           0 :          i != entity_->getTypeParameters().end(); ++i)
    2616             :     {
    2617           0 :         if (i != entity_->getTypeParameters().begin()) {
    2618           0 :             out << ", ";
    2619             :         }
    2620           0 :         out << "typename ";
    2621           0 :         dumpTypeParameterName(out, *i);
    2622             :     }
    2623           0 :     out << " > ";
    2624           0 : }
    2625             : 
    2626           0 : void PolyStructType::dumpTemplateParameters(FileStream & out) const {
    2627           0 :     out << "< ";
    2628           0 :     for (std::vector< OUString >::const_iterator i(
    2629           0 :              entity_->getTypeParameters().begin());
    2630           0 :          i != entity_->getTypeParameters().end(); ++i)
    2631             :     {
    2632           0 :         if (i != entity_->getTypeParameters().begin()) {
    2633           0 :             out << ", ";
    2634             :         }
    2635           0 :         dumpTypeParameterName(out, *i);
    2636             :     }
    2637           0 :     out << " >";
    2638           0 : }
    2639             : 
    2640           0 : OUString typeToIdentifier(OUString const & name) {
    2641             :     sal_Int32 k;
    2642           0 :     OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k)));
    2643           0 :     OUStringBuffer b;
    2644           0 :     for (sal_Int32 i = 0; i != k; ++i) {
    2645           0 :         b.append("seq_");
    2646             :     }
    2647           0 :     b.append(n);
    2648           0 :     b.replace(' ', '_');
    2649           0 :     b.replace(',', '_');
    2650           0 :     b.replace('.', '_');
    2651           0 :     b.replace('<', '_');
    2652           0 :     b.replace('>', '_');
    2653           0 :     return b.makeStringAndClear();
    2654             : }
    2655             : 
    2656           0 : class ExceptionType: public CppuType {
    2657             : public:
    2658           0 :     ExceptionType(
    2659             :         rtl::Reference< unoidl::ExceptionTypeEntity > const & entity,
    2660             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    2661           0 :         CppuType(name, typeMgr), entity_(entity)
    2662           0 :     { 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           0 :     virtual sal_uInt32 checkInheritedMemberCount() const SAL_OVERRIDE
    2675           0 :     { 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           0 : void ExceptionType::dumpHxxFile(
    2688             :     FileStream & out, codemaker::cppumaker::Includes & includes)
    2689             : {
    2690           0 :     OUString headerDefine(dumpHeaderDefine(out, "HPP"));
    2691           0 :     out << "\n";
    2692           0 :     addDefaultHxxIncludes(includes);
    2693           0 :     includes.dump(out, &name_);
    2694           0 :     out << "\n";
    2695           0 :     if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
    2696           0 :         out << "\n";
    2697             :     }
    2698           0 :     out << "\ninline " << id_ << "::" << id_ << "() SAL_THROW(())\n";
    2699           0 :     inc();
    2700           0 :     OUString base(entity_->getDirectBase());
    2701           0 :     bool first = true;
    2702           0 :     if (!base.isEmpty()) {
    2703           0 :         out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
    2704           0 :             << "()\n";
    2705           0 :         first = false;
    2706             :     }
    2707           0 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    2708           0 :              entity_->getDirectMembers().begin());
    2709           0 :          i != entity_->getDirectMembers().end(); ++i)
    2710             :     {
    2711           0 :         out << indent() << (first ? ":" : ",") << " ";
    2712           0 :         out << i->name;
    2713           0 :         dumpInitializer(out, false, i->type);
    2714           0 :         out << "\n";
    2715           0 :         first = false;
    2716             :     }
    2717           0 :     dec();
    2718           0 :     out << "{";
    2719           0 :     if (!m_cppuTypeDynamic) {
    2720           0 :         out << "\n";
    2721           0 :         inc();
    2722           0 :         dumpCppuGetType(out, name_);
    2723           0 :         dec();
    2724             :     } else {
    2725           0 :         out << " ";
    2726             :     }
    2727           0 :     out << "}\n\n";
    2728           0 :     if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
    2729           0 :         out << indent() << "inline " << id_ << "::" << id_ << "(";
    2730           0 :         first = !dumpBaseMembers(out, base, true);
    2731           0 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2732           0 :                  i(entity_->getDirectMembers().begin());
    2733           0 :              i != entity_->getDirectMembers().end(); ++i)
    2734             :         {
    2735           0 :             if (!first) {
    2736           0 :                 out << ", ";
    2737             :             }
    2738           0 :             dumpType(out, i->type, true, true);
    2739           0 :             out << " " << i->name << "_";
    2740           0 :             first = false;
    2741             :         }
    2742           0 :         out << ") SAL_THROW(())\n";
    2743           0 :         inc();
    2744           0 :         first = true;
    2745           0 :         if (!base.isEmpty()) {
    2746           0 :             out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
    2747           0 :                 << "(";
    2748           0 :             dumpBaseMembers(out, base, false);
    2749           0 :             out << ")\n";
    2750           0 :             first = false;
    2751             :         }
    2752           0 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2753           0 :                  i(entity_->getDirectMembers().begin());
    2754           0 :              i != entity_->getDirectMembers().end(); ++i)
    2755             :         {
    2756           0 :             out << indent() << (first ? ":" : ",") << " " << i->name << "("
    2757           0 :                 << i->name << "_)\n";
    2758           0 :             first = false;
    2759             :         }
    2760           0 :         dec();
    2761           0 :         out << "{";
    2762           0 :         if (!m_cppuTypeDynamic) {
    2763           0 :             out << "\n";
    2764           0 :             inc();
    2765           0 :             dumpCppuGetType(out, name_);
    2766           0 :             dec();
    2767             :         } else {
    2768           0 :             out << " ";
    2769             :         }
    2770           0 :         out << "}\n\n";
    2771             :     }
    2772           0 :     out << indent() << id_ << "::" << id_ << "(" << id_
    2773           0 :         << " const & the_other)";
    2774           0 :     first = true;
    2775           0 :     if (!base.isEmpty()) {
    2776           0 :         out << ": " << codemaker::cpp::scopedCppName(u2b(base))
    2777           0 :             << "(the_other)";
    2778           0 :         first = false;
    2779             :     }
    2780           0 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    2781           0 :              entity_->getDirectMembers().begin());
    2782           0 :          i != entity_->getDirectMembers().end(); ++i)
    2783             :     {
    2784           0 :         out << (first ? ":" : ",") << " " << i->name << "(the_other." << i->name
    2785           0 :             << ")";
    2786           0 :         first = false;
    2787             :     }
    2788           0 :     out << indent() << " {}\n\n" << indent() << id_ << "::~" << id_
    2789           0 :         << "() {}\n\n" << indent() << id_ << " & " << id_ << "::operator =("
    2790           0 :         << id_ << " const & the_other) {\n";
    2791           0 :     inc();
    2792           0 :     out << indent()
    2793             :         << ("//TODO: Just like its implicitly-defined counterpart, this"
    2794           0 :             " function definition is not exception-safe\n");
    2795           0 :     if (!base.isEmpty()) {
    2796           0 :         out << indent() << codemaker::cpp::scopedCppName(u2b(base))
    2797           0 :             << "::operator =(the_other);\n";
    2798             :     }
    2799           0 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    2800           0 :              entity_->getDirectMembers().begin());
    2801           0 :          i != entity_->getDirectMembers().end(); ++i)
    2802             :     {
    2803           0 :         out << indent() << i->name << " = the_other." << i->name << ";\n";
    2804             :     }
    2805           0 :     out << indent() << "return *this;\n";
    2806           0 :     dec();
    2807           0 :     out << indent() << "}\n\n";
    2808           0 :     if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
    2809           0 :         out << "\n";
    2810             :     }
    2811           0 :     out << "\n";
    2812           0 :     dumpGetCppuType(out);
    2813           0 :     out << "\n#endif // "<< headerDefine << "\n";
    2814           0 : }
    2815             : 
    2816           0 : void ExceptionType::dumpLightGetCppuType(FileStream & out) {
    2817           0 :     dumpGetCppuTypePreamble(out);
    2818           0 :     out << indent()
    2819           0 :         << "static typelib_TypeDescriptionReference * the_type = 0;\n"
    2820           0 :         << indent() << "if ( !the_type )\n" << indent() << "{\n";
    2821           0 :     inc();
    2822           0 :     out << indent() << "typelib_static_type_init( &the_type, "
    2823           0 :         << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n";
    2824           0 :     dec();
    2825           0 :     out << indent() << "}\n" << indent()
    2826             :         << ("return * reinterpret_cast< ::css::uno::Type * >("
    2827           0 :             " &the_type );\n");
    2828           0 :     dumpGetCppuTypePostamble(out);
    2829           0 : }
    2830             : 
    2831           0 : void ExceptionType::dumpNormalGetCppuType(FileStream & out) {
    2832           0 :     dumpGetCppuTypePreamble(out);
    2833           0 :     out << indent()
    2834           0 :         << "static typelib_TypeDescriptionReference * the_type = 0;\n"
    2835           0 :         << indent() << "if ( !the_type )\n" << indent() << "{\n";
    2836           0 :     inc();
    2837           0 :     OUString base(entity_->getDirectBase());
    2838           0 :     bool baseException = false;
    2839           0 :     if (!base.isEmpty()) {
    2840           0 :         if (base == "com.sun.star.uno.Exception") {
    2841           0 :             baseException = true;
    2842             :         } else {
    2843           0 :             out << indent()
    2844             :                 << ("const ::css::uno::Type& rBaseType ="
    2845           0 :                     " ::cppu::UnoType< ");
    2846           0 :             dumpType(out, base, true, false, false, true);
    2847           0 :             out << " >::get();\n\n";
    2848             :         }
    2849             :     }
    2850           0 :     if (!entity_->getDirectMembers().empty()) {
    2851           0 :         out << indent() << "typelib_TypeDescriptionReference * aMemberRefs["
    2852           0 :             << entity_->getDirectMembers().size() << "];\n";
    2853           0 :         std::set< OUString > seen;
    2854           0 :         std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0;
    2855           0 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2856           0 :                  i(entity_->getDirectMembers().begin());
    2857           0 :              i != entity_->getDirectMembers().end(); ++i)
    2858             :         {
    2859           0 :             OUString type(resolveAllTypedefs(i->type));
    2860           0 :             OUString modType(typeToIdentifier(type));
    2861           0 :             if (seen.insert(type).second) {
    2862           0 :                 out << indent()
    2863           0 :                     << "const ::css::uno::Type& rMemberType_"
    2864           0 :                     << modType << " = ::cppu::UnoType< ";
    2865           0 :                 dumpType(out, type, false, false, false, true);
    2866           0 :                 out << " >::get();\n";
    2867             :             }
    2868           0 :             out << indent() << "aMemberRefs[" << n++ << "] = rMemberType_"
    2869           0 :                 << modType << ".getTypeLibType();\n";
    2870           0 :         }
    2871           0 :         out << "\n";
    2872             :     }
    2873           0 :     out << indent() << "typelib_static_compound_type_init( &the_type, "
    2874           0 :         << getTypeClass(name_, true) << ", \"" << name_ << "\", ";
    2875           0 :     if (baseException) {
    2876             :         out << ("* ::typelib_static_type_getByTypeClass("
    2877           0 :                 " typelib_TypeClass_EXCEPTION )");
    2878           0 :     } else if (base.isEmpty()) {
    2879           0 :         out << "0";
    2880             :     } else {
    2881           0 :         out << "rBaseType.getTypeLibType()";
    2882             :     }
    2883           0 :     out << ", " << entity_->getDirectMembers().size() << ",  "
    2884           0 :         << (entity_->getDirectMembers().empty() ? "0" : "aMemberRefs")
    2885           0 :         << " );\n";
    2886           0 :     dec();
    2887           0 :     out << indent() << "}\n" << indent()
    2888             :         << ("return * reinterpret_cast< const ::css::uno::Type * >("
    2889           0 :             " &the_type );\n");
    2890           0 :     dumpGetCppuTypePostamble(out);
    2891           0 : }
    2892             : 
    2893           0 : void ExceptionType::dumpComprehensiveGetCppuType(FileStream & out) {
    2894           0 :     codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
    2895           0 :     out << " namespace detail {\n\n";
    2896           0 :     OUString staticTypeClass("the" + id_ + "Type");
    2897           0 :     out << indent() << "struct " << staticTypeClass
    2898           0 :         << " : public rtl::StaticWithInit< ::css::uno::Type *, "
    2899           0 :         << staticTypeClass << " >\n" << indent() << "{\n";
    2900           0 :     inc();
    2901           0 :     out << indent() << "::css::uno::Type * operator()() const\n"
    2902           0 :         << indent() << "{\n";
    2903           0 :     inc();
    2904           0 :     out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n"
    2905           0 :         << indent() << "// Start inline typedescription generation\n"
    2906           0 :         << indent() << "typelib_TypeDescription * pTD = 0;\n";
    2907           0 :     OUString base(entity_->getDirectBase());
    2908           0 :     if (!base.isEmpty()) {
    2909           0 :         out << indent()
    2910             :             << ("const ::css::uno::Type& rSuperType ="
    2911           0 :                 " ::cppu::UnoType< ");
    2912           0 :         dumpType(out, base, false, false, false, true);
    2913           0 :         out << " >::get();\n";
    2914             :     }
    2915           0 :     std::set< OUString > seen;
    2916           0 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    2917           0 :              entity_->getDirectMembers().begin());
    2918           0 :          i != entity_->getDirectMembers().end(); ++i)
    2919             :     {
    2920           0 :         if (seen.insert(i->type).second) {
    2921           0 :             dumpCppuGetType(out, i->type);
    2922             :         }
    2923             :     }
    2924           0 :     if (!entity_->getDirectMembers().empty()) {
    2925           0 :         out << "\n" << indent() << "typelib_CompoundMember_Init aMembers["
    2926           0 :             << entity_->getDirectMembers().size() << "];\n";
    2927           0 :         std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0;
    2928           0 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2929           0 :                  i(entity_->getDirectMembers().begin());
    2930           0 :              i != entity_->getDirectMembers().end(); ++i)
    2931             :         {
    2932           0 :             OUString type(resolveAllTypedefs(i->type));
    2933           0 :             out << indent() << "::rtl::OUString sMemberType" << n << "( \""
    2934           0 :                 << type << "\" );\n" << indent()
    2935           0 :                 << "::rtl::OUString sMemberName" << n << "( \"" << i->name
    2936           0 :                 << "\" );\n" << indent() << "aMembers[" << n
    2937           0 :                 << "].eTypeClass = (typelib_TypeClass)" << getTypeClass(type)
    2938           0 :                 << ";\n" << indent() << "aMembers[" << n
    2939           0 :                 << "].pTypeName = sMemberType" << n << ".pData;\n" << indent()
    2940           0 :                 << "aMembers[" << n << "].pMemberName = sMemberName" << n
    2941           0 :                 << ".pData;\n";
    2942           0 :             ++n;
    2943           0 :         }
    2944             :     }
    2945           0 :     out << "\n" << indent() << "typelib_typedescription_new(\n";
    2946           0 :     inc();
    2947           0 :     out << indent() << "&pTD,\n" << indent() << "(typelib_TypeClass)"
    2948           0 :         << getTypeClass(name_) << ", sTypeName.pData,\n" << indent()
    2949           0 :         << (base.isEmpty() ? "0" : "rSuperType.getTypeLibType()") << ",\n"
    2950           0 :         << indent() << entity_->getDirectMembers().size() << ",\n" << indent()
    2951           0 :         << (entity_->getDirectMembers().empty() ? "0" : "aMembers")
    2952           0 :         << " );\n\n";
    2953           0 :     dec();
    2954           0 :     out << indent()
    2955             :         << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
    2956           0 :             " );\n\n")
    2957           0 :         << indent() << "typelib_typedescription_release( pTD );\n" << indent()
    2958           0 :         << "// End inline typedescription generation\n\n" << indent()
    2959           0 :         << "return new ::css::uno::Type( " << getTypeClass(name_)
    2960           0 :         << ", sTypeName ); // leaked\n";
    2961           0 :     dec();
    2962           0 :     out << indent() << "}\n";
    2963           0 :     dec();
    2964           0 :     out << indent() << "};\n\n";
    2965           0 :     codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
    2966           0 :     out << " }\n\n";
    2967           0 :     dumpGetCppuTypePreamble(out);
    2968           0 :     out << indent() << "return *detail::" << staticTypeClass << "::get();\n";
    2969           0 :     dumpGetCppuTypePostamble(out);
    2970           0 : }
    2971             : 
    2972           0 : void ExceptionType::dumpDeclaration(FileStream & out) {
    2973           0 :     out << "\nclass CPPU_GCC_DLLPUBLIC_EXPORT " << id_;
    2974           0 :     OUString base(entity_->getDirectBase());
    2975           0 :     if (!base.isEmpty()) {
    2976           0 :         out << " : public " << codemaker::cpp::scopedCppName(u2b(base));
    2977             :     }
    2978           0 :     out << "\n{\npublic:\n";
    2979           0 :     inc();
    2980           0 :     out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
    2981           0 :         << "() SAL_THROW(());\n\n";
    2982           0 :     if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
    2983           0 :         out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(";
    2984           0 :         bool first = !dumpBaseMembers(out, base, true);
    2985           0 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    2986           0 :                  i(entity_->getDirectMembers().begin());
    2987           0 :              i != entity_->getDirectMembers().end(); ++i)
    2988             :         {
    2989           0 :             if (!first) {
    2990           0 :                 out << ", ";
    2991             :             }
    2992           0 :             dumpType(out, i->type, true, true);
    2993           0 :             out << " " << i->name << "_";
    2994           0 :             first = false;
    2995             :         }
    2996           0 :         out << ") SAL_THROW(());\n\n";
    2997             :     }
    2998           0 :     out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(" << id_
    2999           0 :         << " const &);\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE ~"
    3000           0 :         << id_ << "();\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
    3001           0 :         << " & operator =(" << id_ << " const &);\n\n";
    3002           0 :     for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
    3003           0 :              entity_->getDirectMembers().begin());
    3004           0 :          i != entity_->getDirectMembers().end(); ++i)
    3005             :     {
    3006           0 :         out << indent();
    3007           0 :         dumpType(out, i->type);
    3008           0 :         out << " " << i->name;
    3009           0 :         if (i == entity_->getDirectMembers().begin() && !base.isEmpty()
    3010           0 :             && i->type != "hyper" && i->type != "unsigned hyper"
    3011           0 :             && i->type != "double")
    3012             :         {
    3013           0 :             out << " CPPU_GCC3_ALIGN( "
    3014           0 :                 << codemaker::cpp::scopedCppName(u2b(base)) << " )";
    3015             :         }
    3016           0 :         out << ";\n";
    3017             :     }
    3018           0 :     dec();
    3019           0 :     out << "};\n\n";
    3020           0 : }
    3021             : 
    3022           0 : bool ExceptionType::dumpBaseMembers(
    3023             :     FileStream & out, OUString const & base, bool withType)
    3024             : {
    3025           0 :     bool hasMember = false;
    3026           0 :     if (!base.isEmpty()) {
    3027           0 :         rtl::Reference< unoidl::Entity > ent;
    3028           0 :         codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
    3029           0 :         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           0 :             dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
    3035             :         assert(ent2.is());
    3036           0 :         hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType);
    3037           0 :         for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
    3038           0 :                  i(ent2->getDirectMembers().begin());
    3039           0 :              i != ent2->getDirectMembers().end(); ++i)
    3040             :         {
    3041           0 :             if (hasMember) {
    3042           0 :                 out << ", ";
    3043             :             }
    3044           0 :             if (withType) {
    3045           0 :                 dumpType(out, i->type, true, true);
    3046           0 :                 out << " ";
    3047             :             }
    3048           0 :             out << i->name << "_";
    3049           0 :             hasMember = true;
    3050           0 :         }
    3051             :     }
    3052           0 :     return hasMember;
    3053             : }
    3054             : 
    3055           0 : sal_uInt32 ExceptionType::getTotalMemberCount(OUString const & base) const {
    3056           0 :     if (base.isEmpty()) {
    3057           0 :         return 0;
    3058             :     }
    3059           0 :     rtl::Reference< unoidl::Entity > ent;
    3060           0 :     codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
    3061           0 :     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           0 :         dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
    3067             :     assert(ent2.is());
    3068           0 :     return getTotalMemberCount(ent2->getDirectBase())
    3069           0 :         + ent2->getDirectMembers().size(); //TODO: overflow
    3070             : }
    3071             : 
    3072           0 : class EnumType: public CppuType {
    3073             : public:
    3074           0 :     EnumType(
    3075             :         rtl::Reference< unoidl::EnumTypeEntity > const & entity,
    3076             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    3077           0 :         CppuType(name, typeMgr), entity_(entity)
    3078           0 :     { 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           0 : void EnumType::dumpDeclaration(FileStream& o)
    3092             : {
    3093           0 :     o << "\nenum " << id_ << "\n{\n";
    3094           0 :     inc();
    3095             : 
    3096           0 :     for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
    3097           0 :              entity_->getMembers().begin());
    3098           0 :          i != entity_->getMembers().end(); ++i)
    3099             :     {
    3100           0 :         o << indent() << id_ << "_" << u2b(i->name) << " = " << i->value
    3101           0 :           << ",\n";
    3102             :     }
    3103             : 
    3104           0 :     o << indent() << id_ << "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n";
    3105             : 
    3106           0 :     dec();
    3107           0 :     o << "};\n\n";
    3108           0 : }
    3109             : 
    3110           0 : void EnumType::dumpHxxFile(
    3111             :     FileStream& o, codemaker::cppumaker::Includes & includes)
    3112             : {
    3113           0 :     OUString headerDefine(dumpHeaderDefine(o, "HPP"));
    3114           0 :     o << "\n";
    3115             : 
    3116           0 :     addDefaultHxxIncludes(includes);
    3117           0 :     includes.dump(o, &name_);
    3118           0 :     o << "\n";
    3119             : 
    3120           0 :     dumpGetCppuType(o);
    3121             : 
    3122           0 :     o << "\n#endif // "<< headerDefine << "\n";
    3123           0 : }
    3124             : 
    3125           0 : void EnumType::dumpNormalGetCppuType(FileStream& o)
    3126             : {
    3127           0 :     dumpGetCppuTypePreamble(o);
    3128             : 
    3129           0 :     o << indent()
    3130           0 :       << "static typelib_TypeDescriptionReference * the_type = 0;\n";
    3131             : 
    3132           0 :     o << indent() << "if ( !the_type )\n" << indent() << "{\n";
    3133           0 :     inc();
    3134             : 
    3135           0 :     o << indent() << "typelib_static_enum_type_init( &the_type,\n";
    3136           0 :     inc(31);
    3137           0 :     o << indent() << "\"" << name_ << "\",\n"
    3138           0 :       << indent() << codemaker::cpp::scopedCppName(u2b(name_)) << "_"
    3139           0 :       << u2b(entity_->getMembers()[0].name) << " );\n";
    3140           0 :     dec(31);
    3141           0 :     dec();
    3142           0 :     o << indent() << "}\n";
    3143           0 :     o << indent()
    3144             :       << ("return * reinterpret_cast< ::css::uno::Type * >("
    3145           0 :           " &the_type );\n");
    3146           0 :     dumpGetCppuTypePostamble(o);
    3147           0 : }
    3148             : 
    3149           0 : void EnumType::dumpComprehensiveGetCppuType(FileStream& o)
    3150             : {
    3151           0 :     if (!isPolymorphic())
    3152           0 :         codemaker::cppumaker::dumpNamespaceOpen(o, name_, false);
    3153             :     else
    3154           0 :         o << "namespace cppu { ";
    3155           0 :     o << " namespace detail {\n\n";
    3156             : 
    3157           0 :     OUString sStaticTypeClass("the" + id_ + "Type");
    3158           0 :     o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::css::uno::Type *, " << sStaticTypeClass << " >\n";
    3159           0 :     o << indent() << "{\n";
    3160           0 :     inc();
    3161           0 :     o << indent() << "::css::uno::Type * operator()() const\n";
    3162           0 :     o << indent() << "{\n";
    3163             : 
    3164           0 :     inc();
    3165           0 :     o << indent() << "::rtl::OUString sTypeName( \"" << name_
    3166           0 :       << "\" );\n\n";
    3167             : 
    3168           0 :     o << indent() << "// Start inline typedescription generation\n"
    3169           0 :       << indent() << "typelib_TypeDescription * pTD = 0;\n\n";
    3170             : 
    3171           0 :     o << indent() << "rtl_uString* enumValueNames["
    3172           0 :       << entity_->getMembers().size() << "];\n";
    3173           0 :     std::vector< unoidl::EnumTypeEntity::Member >::size_type n = 0;
    3174           0 :     for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
    3175           0 :              entity_->getMembers().begin());
    3176           0 :          i != entity_->getMembers().end(); ++i)
    3177             :     {
    3178           0 :         o << indent() << "::rtl::OUString sEnumValue" << n << "( \""
    3179           0 :           << u2b(i->name) << "\" );\n";
    3180           0 :         o << indent() << "enumValueNames[" << n << "] = sEnumValue" << n
    3181           0 :           << ".pData;\n";
    3182           0 :         ++n;
    3183             :     }
    3184             : 
    3185           0 :     o << "\n" << indent() << "sal_Int32 enumValues["
    3186           0 :       << entity_->getMembers().size() << "];\n";
    3187           0 :     n = 0;
    3188           0 :     for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
    3189           0 :              entity_->getMembers().begin());
    3190           0 :          i != entity_->getMembers().end(); ++i)
    3191             :     {
    3192           0 :         o << indent() << "enumValues[" << n++ << "] = " << i->value << ";\n";
    3193             :     }
    3194             : 
    3195           0 :     o << "\n" << indent() << "typelib_typedescription_newEnum( &pTD,\n";
    3196           0 :     inc();
    3197           0 :     o << indent() << "sTypeName.pData,\n"
    3198           0 :       << indent() << "(sal_Int32)"
    3199           0 :       << codemaker::cpp::scopedCppName(u2b(name_), false) << "_"
    3200           0 :       << u2b(entity_->getMembers()[0].name) << ",\n"
    3201           0 :       << indent() << entity_->getMembers().size()
    3202           0 :       << ", enumValueNames, enumValues );\n\n";
    3203           0 :     dec();
    3204             : 
    3205           0 :     o << indent()
    3206             :       << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
    3207           0 :           " );\n");
    3208           0 :     o << indent() << "typelib_typedescription_release( pTD );\n"
    3209           0 :       << indent() << "// End inline typedescription generation\n\n";
    3210             : 
    3211           0 :     o << indent() << "return new ::css::uno::Type( "
    3212           0 :       << getTypeClass(name_) << ", sTypeName ); // leaked\n";
    3213             : 
    3214           0 :     dec();
    3215           0 :     o << indent() << "}\n";
    3216           0 :     dec();
    3217           0 :     o << indent() << "};\n\n";
    3218             : 
    3219           0 :     if (!isPolymorphic())
    3220           0 :         codemaker::cppumaker::dumpNamespaceClose(o, name_, false);
    3221             :     else
    3222           0 :         o << " }";
    3223           0 :     o << " }\n\n";
    3224             : 
    3225           0 :     dumpGetCppuTypePreamble(o);
    3226           0 :     o  << indent() << "return *detail::" << sStaticTypeClass << "::get();\n";
    3227           0 :     dumpGetCppuTypePostamble(o);
    3228           0 : }
    3229             : 
    3230           0 : class Typedef: public CppuType {
    3231             : public:
    3232           0 :     Typedef(
    3233             :         rtl::Reference< unoidl::TypedefEntity > const & entity,
    3234             :         OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
    3235           0 :         CppuType(name, typeMgr), entity_(entity)
    3236           0 :     { 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           0 : void Typedef::dumpHFile(
    3249             :     FileStream& o, codemaker::cppumaker::Includes & includes)
    3250             : {
    3251           0 :     OUString headerDefine(dumpHeaderDefine(o, "HDL"));
    3252           0 :     o << "\n";
    3253             : 
    3254           0 :     addDefaultHIncludes(includes);
    3255           0 :     includes.dump(o, 0);
    3256           0 :     o << "\n";
    3257             : 
    3258           0 :     if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
    3259           0 :         o << "\n";
    3260             :     }
    3261             : 
    3262           0 :     dumpDeclaration(o);
    3263             : 
    3264           0 :     if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
    3265           0 :         o << "\n";
    3266             :     }
    3267             : 
    3268           0 :     o << "#endif // "<< headerDefine << "\n";
    3269           0 : }
    3270             : 
    3271           0 : void Typedef::dumpDeclaration(FileStream& o)
    3272             : {
    3273           0 :     o << "\ntypedef ";
    3274           0 :     dumpType(o, entity_->getType());
    3275           0 :     o << " " << id_ << ";\n\n";
    3276           0 : }
    3277             : 
    3278           0 : void Typedef::dumpHxxFile(
    3279             :     FileStream& o, codemaker::cppumaker::Includes & includes)
    3280             : {
    3281           0 :     OUString headerDefine(dumpHeaderDefine(o, "HPP"));
    3282           0 :     o << "\n";
    3283             : 
    3284           0 :     addDefaultHxxIncludes(includes);
    3285           0 :     includes.dump(o, &name_);
    3286           0 :     o << "\n";
    3287             : 
    3288           0 :     o << "\n#endif // "<< headerDefine << "\n";
    3289           0 : }
    3290             : 
    3291           0 : class ConstructiveType: public CppuType {
    3292             : public:
    3293           0 :     ConstructiveType(
    3294             :         OUString const & name, rtl::Reference< TypeManager > const & manager):
    3295           0 :         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           0 :     virtual void dumpFiles(OUString const & uri, CppuOptions const & options) SAL_OVERRIDE
    3302           0 :     { dumpFile(uri, name_, true, options); }
    3303             : };
    3304             : 
    3305           0 : bool hasRestParameter(
    3306             :     unoidl::SingleInterfaceBasedServiceEntity::Constructor const & constructor)
    3307             : {
    3308           0 :     return !constructor.parameters.empty()
    3309           0 :         && constructor.parameters.back().rest;
    3310             : }
    3311             : 
    3312           0 : void includeExceptions(
    3313             :     codemaker::cppumaker::Includes & includes,
    3314             :     codemaker::ExceptionTreeNode const * node)
    3315             : {
    3316           0 :     if (node->present) {
    3317           0 :         includes.add(node->name);
    3318             :     } else {
    3319           0 :         for (codemaker::ExceptionTreeNode::Children::const_iterator i(
    3320           0 :                  node->children.begin());
    3321           0 :              i != node->children.end(); ++i)
    3322             :         {
    3323           0 :             includeExceptions(includes, *i);
    3324             :         }
    3325             :     }
    3326           0 : }
    3327             : 
    3328           0 : class ServiceType: public ConstructiveType {
    3329             : public:
    3330           0 :     ServiceType(
    3331             :         rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const &
    3332             :             entity,
    3333             :         OUString const & name, rtl::Reference< TypeManager > const & manager):
    3334           0 :         ConstructiveType(name, manager), entity_(entity)
    3335           0 :     { 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           0 : void ServiceType::dumpHxxFile(
    3348             :     FileStream & o, codemaker::cppumaker::Includes & includes)
    3349             : {
    3350           0 :     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           0 :         includes.addCassert();
    3355           0 :         includes.addReference();
    3356           0 :         includes.addRtlUstringH();
    3357           0 :         includes.addRtlUstringHxx();
    3358           0 :         includes.add("com.sun.star.uno.DeploymentException");
    3359           0 :         includes.add("com.sun.star.uno.XComponentContext");
    3360           0 :         for (std::vector<
    3361             :                  unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
    3362           0 :                  const_iterator i(entity_->getConstructors().begin());
    3363           0 :              i != entity_->getConstructors().end(); ++i)
    3364             :         {
    3365           0 :             if (i->defaultConstructor) {
    3366           0 :                 includes.add("com.sun.star.uno.Exception");
    3367           0 :                 includes.add("com.sun.star.uno.RuntimeException");
    3368             :             } else {
    3369           0 :                 if (!hasRestParameter(*i)) {
    3370           0 :                     includes.addAny();
    3371           0 :                     includes.addSequence();
    3372           0 :                     for (std::vector<
    3373             :                              unoidl::SingleInterfaceBasedServiceEntity::
    3374             :                              Constructor::Parameter >::const_iterator j(
    3375           0 :                                  i->parameters.begin());
    3376           0 :                          j != i->parameters.end(); ++j)
    3377             :                     {
    3378           0 :                         if (m_typeMgr->getSort(
    3379             :                                 b2u(codemaker::UnoType::decompose(
    3380           0 :                                         u2b(j->type), 0, 0)))
    3381             :                             == codemaker::UnoType::SORT_CHAR)
    3382             :                         {
    3383           0 :                             includes.addCppuUnotypeHxx();
    3384           0 :                             break;
    3385             :                         }
    3386             :                     }
    3387             :                 }
    3388           0 :                 codemaker::ExceptionTree tree;
    3389           0 :                 for (std::vector< OUString >::const_iterator j(
    3390           0 :                          i->exceptions.begin());
    3391           0 :                      j != i->exceptions.end(); ++j)
    3392             :                 {
    3393           0 :                     tree.add(u2b(*j), m_typeMgr);
    3394             :                 }
    3395           0 :                 if (!tree.getRoot()->present) {
    3396           0 :                     includes.add("com.sun.star.uno.Exception");
    3397           0 :                     includes.add("com.sun.star.uno.RuntimeException");
    3398           0 :                     includeExceptions(includes, tree.getRoot());
    3399           0 :                 }
    3400             :             }
    3401             :         }
    3402             :     }
    3403             :     OString cppName(
    3404             :         codemaker::cpp::translateUnoToCppIdentifier(
    3405           0 :             u2b(id_), "service", isGlobal()));
    3406           0 :     OUString headerDefine(dumpHeaderDefine(o, "HPP"));
    3407           0 :     o << "\n";
    3408           0 :     includes.dump(o, 0);
    3409           0 :     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           0 :               "#if defined LO_URE_CURRENT_ENV && defined LO_URE_CTOR_ENV_")
    3414           0 :           << name_.replaceAll(".", "_dot_")
    3415           0 :           << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3416           0 :           << name_.replaceAll(".", "_dot_") << ") && defined LO_URE_CTOR_FUN_"
    3417           0 :           << name_.replaceAll(".", "_dot_")
    3418           0 :           << "\nextern \"C\" ::css::uno::XInterface * SAL_CALL LO_URE_CTOR_FUN_"
    3419           0 :           << name_.replaceAll(".", "_dot_")
    3420             :           << "(::css::uno::XComponentContext *, ::css::uno::Sequence< "
    3421           0 :              "::css::uno::Any > const &);\n#endif\n";
    3422             :     }
    3423           0 :     o << "\n";
    3424           0 :     if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
    3425           0 :         o << "\n";
    3426             :     }
    3427           0 :     o << "\nclass " << cppName << " {\n";
    3428           0 :     inc();
    3429           0 :     if (!entity_->getConstructors().empty()) {
    3430           0 :         OString baseName(u2b(entity_->getBase()));
    3431           0 :         OString scopedBaseName(codemaker::cpp::scopedCppName(baseName));
    3432           0 :         o << "public:\n";
    3433           0 :         for (std::vector<
    3434             :                  unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
    3435           0 :                  const_iterator i(entity_->getConstructors().begin());
    3436           0 :              i != entity_->getConstructors().end(); ++i)
    3437             :         {
    3438           0 :             if (i->defaultConstructor) {
    3439           0 :                 o << indent() << "static ::css::uno::Reference< "
    3440           0 :                   << scopedBaseName << " > "
    3441             :                   << codemaker::cpp::translateUnoToCppIdentifier(
    3442             :                       "create", "method", codemaker::cpp::ITM_NONGLOBAL,
    3443           0 :                       &cppName)
    3444             :                   << ("(::css::uno::Reference< ::css::uno::XComponentContext > const &"
    3445           0 :                       " the_context) {\n");
    3446           0 :                 inc();
    3447           0 :                 o << indent() << "assert(the_context.is());\n" << indent()
    3448           0 :                   << "::css::uno::Reference< " << scopedBaseName
    3449           0 :                   << " > the_instance;\n" << indent() << "try {\n";
    3450           0 :                 inc();
    3451             :                 o << ("#if defined LO_URE_CURRENT_ENV && defined "
    3452           0 :                       "LO_URE_CTOR_ENV_")
    3453           0 :                   << name_.replaceAll(".", "_dot_")
    3454           0 :                   << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3455           0 :                   << name_.replaceAll(".", "_dot_")
    3456           0 :                   << ") && defined LO_URE_CTOR_FUN_"
    3457           0 :                   << name_.replaceAll(".", "_dot_") << "\n" << indent()
    3458           0 :                   << "the_instance = ::css::uno::Reference< " << scopedBaseName
    3459             :                   << (" >(::css::uno::Reference< ::css::uno::XInterface >("
    3460             :                       "static_cast< ::css::uno::XInterface * >((*"
    3461           0 :                       "LO_URE_CTOR_FUN_")
    3462           0 :                   << name_.replaceAll(".", "_dot_")
    3463             :                   << (")(the_context.get(), ::css::uno::Sequence<"
    3464             :                       " ::css::uno::Any >())), ::SAL_NO_ACQUIRE),"
    3465           0 :                       " ::css::uno::UNO_QUERY);\n#else\n")
    3466           0 :                   << indent() << "the_instance = ::css::uno::Reference< "
    3467           0 :                   << scopedBaseName
    3468             :                   << (" >(the_context->getServiceManager()->"
    3469             :                       "createInstanceWithContext(::rtl::OUString("
    3470           0 :                       " \"")
    3471           0 :                   << name_
    3472           0 :                   << "\" ), the_context), ::css::uno::UNO_QUERY);\n#endif\n";
    3473           0 :                 dec();
    3474           0 :                 o << indent()
    3475           0 :                   << "} catch (const ::css::uno::RuntimeException &) {\n";
    3476           0 :                 inc();
    3477           0 :                 o << indent() << "throw;\n";
    3478           0 :                 dec();
    3479           0 :                 o << indent()
    3480           0 :                   << ("} catch (const ::css::uno::Exception & the_exception) {\n");
    3481           0 :                 inc();
    3482           0 :                 o << indent()
    3483             :                   << ("throw ::css::uno::DeploymentException("
    3484             :                       "::rtl::OUString( "
    3485           0 :                       "\"component context fails to supply service \" ) + ")
    3486           0 :                   << "\"" << name_ << "\" + "
    3487           0 :                   << "\" of type \" + "
    3488           0 :                   << "\"" << baseName << "\" + "
    3489           0 :                   << "\": \" + the_exception.Message, the_context);\n";
    3490           0 :                 dec();
    3491           0 :                 o << indent() << "}\n" << indent()
    3492           0 :                   << "if (!the_instance.is()) {\n";
    3493           0 :                 inc();
    3494           0 :                 o << indent()
    3495             :                   << ("throw ::css::uno::DeploymentException("
    3496             :                       "::rtl::OUString( "
    3497           0 :                       "\"component context fails to supply service \" ) + ")
    3498           0 :                   << "\"" << name_ << "\" + "
    3499           0 :                   << "\" of type \" + "
    3500           0 :                   << "\"" << baseName << "\""
    3501           0 :                   << ", the_context);\n";
    3502           0 :                 dec();
    3503           0 :                 o << indent() << "}\n" << indent() << "return the_instance;\n";
    3504           0 :                 dec();
    3505           0 :                 o << indent() << "}\n\n";
    3506             :             } else {
    3507           0 :                 o << indent() << "static ::css::uno::Reference< "
    3508           0 :                   << scopedBaseName << " > "
    3509             :                   << codemaker::cpp::translateUnoToCppIdentifier(
    3510           0 :                       u2b(i->name), "method", codemaker::cpp::ITM_NONGLOBAL,
    3511           0 :                       &cppName)
    3512             :                   << ("(::css::uno::Reference< ::css::uno::XComponentContext > const &"
    3513           0 :                       " the_context");
    3514           0 :                 bool rest = hasRestParameter(*i);
    3515           0 :                 for (std::vector<
    3516             :                          unoidl::SingleInterfaceBasedServiceEntity::Constructor::
    3517           0 :                          Parameter >::const_iterator j(i->parameters.begin());
    3518           0 :                      j != i->parameters.end(); ++j)
    3519             :                 {
    3520           0 :                     o << ", ";
    3521           0 :                     OUStringBuffer buf;
    3522           0 :                     if (j->rest) {
    3523           0 :                         buf.append("[]");
    3524             :                     }
    3525           0 :                     buf.append(j->type);
    3526           0 :                     OUString type(buf.makeStringAndClear());
    3527           0 :                     bool byRef = passByReference(type);
    3528           0 :                     dumpType(o, type, byRef, byRef);
    3529           0 :                     o << " "
    3530             :                       << codemaker::cpp::translateUnoToCppIdentifier(
    3531           0 :                           u2b(j->name), "param", codemaker::cpp::ITM_NONGLOBAL);
    3532           0 :                 }
    3533           0 :                 o << ") {\n";
    3534           0 :                 inc();
    3535           0 :                 o << indent() << "assert(the_context.is());\n";
    3536           0 :                 if (!rest && !i->parameters.empty()) {
    3537           0 :                     o << indent()
    3538           0 :                       << ("::css::uno::Sequence< ::css::uno::Any > the_arguments(")
    3539           0 :                       << i->parameters.size() << ");\n";
    3540             :                     std::vector<
    3541             :                         unoidl::SingleInterfaceBasedServiceEntity::Constructor::
    3542           0 :                         Parameter >::size_type n = 0;
    3543           0 :                     for (std::vector<
    3544             :                              unoidl::SingleInterfaceBasedServiceEntity::
    3545             :                              Constructor::Parameter >::const_iterator j(
    3546           0 :                                  i->parameters.begin());
    3547           0 :                          j != i->parameters.end(); ++j)
    3548             :                     {
    3549           0 :                         o << indent() << "the_arguments[" << n++ << "] ";
    3550             :                         OString param(
    3551             :                             codemaker::cpp::translateUnoToCppIdentifier(
    3552           0 :                                 u2b(j->name), "param",
    3553           0 :                                 codemaker::cpp::ITM_NONGLOBAL));
    3554             :                         sal_Int32 rank;
    3555           0 :                         if (m_typeMgr->getSort(
    3556             :                                 b2u(codemaker::UnoType::decompose(
    3557           0 :                                         u2b(j->type), &rank, 0)))
    3558             :                             == codemaker::UnoType::SORT_CHAR)
    3559             :                         {
    3560           0 :                             o << "= ::css::uno::Any(&" << param
    3561           0 :                               << ", ::cppu::UnoType< ";
    3562           0 :                             for (sal_Int32 k = 0; k < rank; ++k) {
    3563           0 :                                 o << "::cppu::UnoSequenceType< ";
    3564             :                             }
    3565           0 :                             o << "::cppu::UnoCharType";
    3566           0 :                             for (sal_Int32 k = 0; k < rank; ++k) {
    3567           0 :                                 o << " >";
    3568             :                             }
    3569           0 :                             o << " >::get())";
    3570             :                         } else {
    3571           0 :                             o << "<<= " << param;
    3572             :                         }
    3573           0 :                         o << ";\n";
    3574           0 :                     }
    3575             :                 }
    3576           0 :                 o << indent() << "::css::uno::Reference< "
    3577           0 :                   << scopedBaseName << " > the_instance;\n";
    3578           0 :                 codemaker::ExceptionTree tree;
    3579           0 :                 for (std::vector< OUString >::const_iterator j(
    3580           0 :                          i->exceptions.begin());
    3581           0 :                      j != i->exceptions.end(); ++j)
    3582             :                 {
    3583           0 :                     tree.add(u2b(*j), m_typeMgr);
    3584             :                 }
    3585           0 :                 if (!tree.getRoot()->present) {
    3586           0 :                     o << indent() << "try {\n";
    3587           0 :                     inc();
    3588             :                 }
    3589             :                 o << ("#if defined LO_URE_CURRENT_ENV && defined "
    3590           0 :                       "LO_URE_CTOR_ENV_")
    3591           0 :                   << name_.replaceAll(".", "_dot_")
    3592           0 :                   << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3593           0 :                   << name_.replaceAll(".", "_dot_")
    3594           0 :                   << ") && defined LO_URE_CTOR_FUN_"
    3595           0 :                   << name_.replaceAll(".", "_dot_") << "\n" << indent()
    3596           0 :                   << "the_instance = ::css::uno::Reference< " << scopedBaseName
    3597             :                   << (" >(::css::uno::Reference< ::css::uno::XInterface >("
    3598             :                       "static_cast< ::css::uno::XInterface * >((*"
    3599           0 :                       "LO_URE_CTOR_FUN_")
    3600           0 :                   << name_.replaceAll(".", "_dot_")
    3601           0 :                   << ")(the_context.get(), ";
    3602           0 :                 if (rest) {
    3603             :                     o << codemaker::cpp::translateUnoToCppIdentifier(
    3604           0 :                         u2b(i->parameters.back().name), "param",
    3605           0 :                         codemaker::cpp::ITM_NONGLOBAL);
    3606           0 :                 } else if (i->parameters.empty()) {
    3607           0 :                     o << "::css::uno::Sequence< ::css::uno::Any >()";
    3608             :                 } else {
    3609           0 :                     o << "the_arguments";
    3610             :                 }
    3611           0 :                 o << ")), ::SAL_NO_ACQUIRE), ::css::uno::UNO_QUERY);\n" << indent()
    3612             :                   << ("::css::uno::Reference< ::css::lang::XInitialization > "
    3613           0 :                       "init(the_instance, ::css::uno::UNO_QUERY);\n")
    3614           0 :                   << indent() << "if (init.is()) {\n"
    3615           0 :                   << indent() << "    init->initialize(";
    3616           0 :                 if (i->parameters.empty()) {
    3617           0 :                     o << "::css::uno::Sequence< ::css::uno::Any >()";
    3618             :                 } else {
    3619           0 :                     o << "the_arguments";
    3620             :                 }
    3621           0 :                 o << ");\n" << indent() << "}\n";
    3622           0 :                 o << ("#else\n")
    3623           0 :                   << indent() << "the_instance = ::css::uno::Reference< "
    3624           0 :                   << scopedBaseName
    3625             :                   << (" >(the_context->getServiceManager()->"
    3626             :                       "createInstanceWithArgumentsAndContext(::rtl::OUString("
    3627           0 :                       " \"")
    3628           0 :                   << name_ << "\" ), ";
    3629           0 :                 if (rest) {
    3630             :                     o << codemaker::cpp::translateUnoToCppIdentifier(
    3631           0 :                         u2b(i->parameters.back().name), "param",
    3632           0 :                         codemaker::cpp::ITM_NONGLOBAL);
    3633           0 :                 } else if (i->parameters.empty()) {
    3634           0 :                     o << ("::css::uno::Sequence< ::css::uno::Any >()");
    3635             :                 } else {
    3636           0 :                     o << "the_arguments";
    3637             :                 }
    3638           0 :                 o << ", the_context), ::css::uno::UNO_QUERY);\n#endif\n";
    3639           0 :                 if (!tree.getRoot()->present) {
    3640           0 :                     dec();
    3641           0 :                     o << indent()
    3642           0 :                       << ("} catch (const ::css::uno::RuntimeException &) {\n");
    3643           0 :                     inc();
    3644           0 :                     o << indent() << "throw;\n";
    3645           0 :                     dec();
    3646           0 :                     dumpCatchClauses(o, tree.getRoot());
    3647           0 :                     o << indent()
    3648             :                       << ("} catch (const ::css::uno::Exception &"
    3649           0 :                           " the_exception) {\n");
    3650           0 :                     inc();
    3651           0 :                     o << indent()
    3652             :                       << ("throw ::css::uno::DeploymentException("
    3653             :                           "::rtl::OUString( "
    3654           0 :                           "\"component context fails to supply service ")
    3655           0 :                       << name_ << " of type " << baseName
    3656           0 :                       << ": \" ) + the_exception.Message, the_context);\n";
    3657           0 :                     dec();
    3658           0 :                     o << indent() << "}\n";
    3659             :                 }
    3660           0 :                 o << indent() << "if (!the_instance.is()) {\n";
    3661           0 :                 inc();
    3662           0 :                 o << indent()
    3663             :                   << ("throw ::css::uno::DeploymentException("
    3664             :                       "::rtl::OUString( "
    3665           0 :                       "\"component context fails to supply service ")
    3666           0 :                   << name_ << " of type " << baseName
    3667           0 :                   << "\" ), the_context);\n";
    3668           0 :                 dec();
    3669           0 :                 o << indent() << "}\n" << indent() << "return the_instance;\n";
    3670           0 :                 dec();
    3671           0 :                 o << indent() << "}\n\n";
    3672             :             }
    3673           0 :         }
    3674             :     }
    3675           0 :     o << "private:\n";
    3676           0 :     o << indent() << cppName << "(); // not implemented\n"
    3677           0 :       << indent() << cppName << "(" << cppName << " &); // not implemented\n"
    3678           0 :       << indent() << "~" << cppName << "(); // not implemented\n"
    3679           0 :       << indent() << "void operator =(" << cppName << "); // not implemented\n";
    3680           0 :     dec();
    3681           0 :     o << "};\n\n";
    3682           0 :     if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
    3683           0 :         o << "\n";
    3684             :     }
    3685           0 :     o << "\n#endif // "<< headerDefine << "\n";
    3686           0 : }
    3687             : 
    3688           0 : void ServiceType::dumpCatchClauses(
    3689             :     FileStream & out, codemaker::ExceptionTreeNode const * node)
    3690             : {
    3691           0 :     if (node->present) {
    3692           0 :         out << indent() << "} catch (const ";
    3693           0 :         dumpType(out, b2u(node->name));
    3694           0 :         out << " &) {\n";
    3695           0 :         inc();
    3696           0 :         out << indent() << "throw;\n";
    3697           0 :         dec();
    3698             :     } else {
    3699           0 :         for (codemaker::ExceptionTreeNode::Children::const_iterator i(
    3700           0 :                  node->children.begin());
    3701           0 :              i != node->children.end(); ++i)
    3702             :         {
    3703           0 :             dumpCatchClauses(out, *i);
    3704             :         }
    3705             :     }
    3706           0 : }
    3707             : 
    3708           0 : class SingletonType: public ConstructiveType {
    3709             : public:
    3710           0 :     SingletonType(
    3711             :         rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity,
    3712             :         OUString const & name, rtl::Reference< TypeManager > const & manager):
    3713           0 :         ConstructiveType(name, manager), entity_(entity)
    3714           0 :     { 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           0 : void SingletonType::dumpHxxFile(
    3724             :     FileStream & o, codemaker::cppumaker::Includes & includes)
    3725             : {
    3726             :     OString cppName(
    3727             :         codemaker::cpp::translateUnoToCppIdentifier(
    3728           0 :             u2b(id_), "singleton", isGlobal()));
    3729           0 :     OString baseName(u2b(entity_->getBase()));
    3730           0 :     OString scopedBaseName(codemaker::cpp::scopedCppName(baseName));
    3731           0 :     OUString headerDefine(dumpHeaderDefine(o, "HPP"));
    3732           0 :     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           0 :     includes.add("com.sun.star.uno.DeploymentException");
    3736           0 :     includes.add("com.sun.star.uno.XComponentContext");
    3737           0 :     includes.addCassert();
    3738           0 :     includes.addAny();
    3739           0 :     includes.addReference();
    3740           0 :     includes.addRtlUstringH();
    3741           0 :     includes.addRtlUstringHxx();
    3742           0 :     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           0 :           "#if defined LO_URE_CURRENT_ENV && defined LO_URE_CTOR_ENV_")
    3747           0 :       << name_.replaceAll(".", "_dot_")
    3748           0 :       << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3749           0 :       << name_.replaceAll(".", "_dot_") << ") && defined LO_URE_CTOR_FUN_"
    3750           0 :       << name_.replaceAll(".", "_dot_")
    3751           0 :       << "\nextern \"C\" ::css::uno::XInterface * SAL_CALL LO_URE_CTOR_FUN_"
    3752           0 :       << name_.replaceAll(".", "_dot_")
    3753             :       << "(::css::uno::XComponentContext *, ::css::uno::Sequence< "
    3754           0 :          "::css::uno::Any > const &);\n#endif\n";
    3755           0 :     o << "\n";
    3756           0 :     if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
    3757           0 :         o << "\n";
    3758             :     }
    3759           0 :     o << "\nclass " << cppName << " {\npublic:\n";
    3760           0 :     inc();
    3761           0 :     o << indent() << "static ::css::uno::Reference< "
    3762           0 :       << scopedBaseName << " > "
    3763             :       << codemaker::cpp::translateUnoToCppIdentifier(
    3764           0 :           "get", "method", codemaker::cpp::ITM_NONGLOBAL, &cppName)
    3765             :       << ("(::css::uno::Reference<"
    3766             :           " ::css::uno::XComponentContext > const & the_context)"
    3767           0 :           " {\n");
    3768           0 :     inc();
    3769           0 :     o << indent() << "assert(the_context.is());\n" << indent()
    3770           0 :       << "::css::uno::Reference< " << scopedBaseName
    3771           0 :       << " > instance;\n"
    3772             :       << ("#if defined LO_URE_CURRENT_ENV && defined "
    3773           0 :           "LO_URE_CTOR_ENV_")
    3774           0 :       << name_.replaceAll(".", "_dot_")
    3775           0 :       << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
    3776           0 :       << name_.replaceAll(".", "_dot_")
    3777           0 :       << ") && defined LO_URE_CTOR_FUN_"
    3778           0 :       << name_.replaceAll(".", "_dot_") << "\n" << indent()
    3779           0 :       << "instance = ::css::uno::Reference< " << scopedBaseName
    3780             :       << (" >(::css::uno::Reference< ::css::uno::XInterface >("
    3781             :           "static_cast< ::css::uno::XInterface * >((*"
    3782           0 :           "LO_URE_CTOR_FUN_")
    3783           0 :       << name_.replaceAll(".", "_dot_")
    3784             :       << (")(the_context.get(), ::css::uno::Sequence<"
    3785             :           " ::css::uno::Any >())), ::SAL_NO_ACQUIRE),"
    3786           0 :                       " ::css::uno::UNO_QUERY);\n#else\n")
    3787           0 :       << indent() << ("the_context->getValueByName("
    3788           0 :           "::rtl::OUString( \"/singletons/")
    3789           0 :       << name_ << "\" )) >>= instance;\n" << "#endif\n"
    3790           0 :       << indent() << "if (!instance.is()) {\n";
    3791           0 :     inc();
    3792           0 :     o << indent()
    3793             :       << ("throw ::css::uno::DeploymentException("
    3794             :           "::rtl::OUString( \"component context"
    3795           0 :           " fails to supply singleton ")
    3796           0 :       << name_ << " of type " << baseName << "\" ), the_context);\n";
    3797           0 :     dec();
    3798           0 :     o << indent() << "}\n" << indent() << "return instance;\n";
    3799           0 :     dec();
    3800           0 :     o << indent() << "}\n\n";
    3801           0 :     o << "private:\n";
    3802           0 :     o << indent() << cppName << "(); // not implemented\n"
    3803           0 :       << indent() << cppName << "(" << cppName << " &); // not implemented\n"
    3804           0 :       << indent() << "~" << cppName << "(); // not implemented\n"
    3805           0 :       << indent() << "void operator =(" << cppName << "); // not implemented\n";
    3806           0 :     dec();
    3807           0 :     o << "};\n\n";
    3808           0 :     if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
    3809           0 :         o << "\n";
    3810             :     }
    3811           0 :     o << "\n#endif // "<< headerDefine << "\n";
    3812           0 : }
    3813             : 
    3814             : }
    3815             : 
    3816           0 : void produce(
    3817             :     OUString const & name, rtl::Reference< TypeManager > const & manager,
    3818             :     codemaker::GeneratedTypeSet & generated, CppuOptions const & options)
    3819             : {
    3820           0 :     if (generated.contains(u2b(name))) {
    3821           0 :         return;
    3822             :     }
    3823           0 :     generated.add(u2b(name));
    3824           0 :     if (!manager->foundAtPrimaryProvider(name)) {
    3825           0 :         return;
    3826             :     }
    3827           0 :     rtl::Reference< unoidl::Entity > ent;
    3828           0 :     rtl::Reference< unoidl::MapCursor > cur;
    3829           0 :     switch (manager->getSort(name, &ent, &cur)) {
    3830             :     case codemaker::UnoType::SORT_MODULE:
    3831             :         {
    3832           0 :             OUString prefix;
    3833           0 :             if (!name.isEmpty()) {
    3834           0 :                 prefix = name + ".";
    3835             :             }
    3836             :             for (;;) {
    3837           0 :                 OUString mem;
    3838           0 :                 if (!cur->getNext(&mem).is()) {
    3839           0 :                     break;
    3840             :                 }
    3841           0 :                 produce(prefix + mem, manager, generated, options);
    3842           0 :             }
    3843           0 :             break;
    3844             :         }
    3845             :     case codemaker::UnoType::SORT_ENUM_TYPE:
    3846             :         {
    3847             :             EnumType t(
    3848           0 :                 dynamic_cast< unoidl::EnumTypeEntity * >(ent.get()), name,
    3849           0 :                 manager);
    3850           0 :             t.dump(options);
    3851           0 :             t.dumpDependedTypes(generated, options);
    3852           0 :             break;
    3853             :         }
    3854             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
    3855             :         {
    3856             :             PlainStructType t(
    3857           0 :                 dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()),
    3858           0 :                 name, manager);
    3859           0 :             t.dump(options);
    3860           0 :             t.dumpDependedTypes(generated, options);
    3861           0 :             break;
    3862             :         }
    3863             :     case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
    3864             :         {
    3865             :             PolyStructType t(
    3866             :                 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
    3867           0 :                     ent.get()),
    3868           0 :                 name, manager);
    3869           0 :             t.dump(options);
    3870           0 :             t.dumpDependedTypes(generated, options);
    3871           0 :             break;
    3872             :         }
    3873             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
    3874             :         {
    3875             :             ExceptionType t(
    3876           0 :                 dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()), name,
    3877           0 :                 manager);
    3878           0 :             t.dump(options);
    3879           0 :             t.dumpDependedTypes(generated, options);
    3880           0 :             break;
    3881             :         }
    3882             :     case codemaker::UnoType::SORT_INTERFACE_TYPE:
    3883             :         {
    3884             :             InterfaceType t(
    3885           0 :                 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()), name,
    3886           0 :                 manager);
    3887           0 :             t.dump(options);
    3888           0 :             t.dumpDependedTypes(generated, options);
    3889           0 :             break;
    3890             :         }
    3891             :     case codemaker::UnoType::SORT_TYPEDEF:
    3892             :         {
    3893             :             Typedef t(
    3894           0 :                 dynamic_cast< unoidl::TypedefEntity * >(ent.get()), name,
    3895           0 :                 manager);
    3896           0 :             t.dump(options);
    3897           0 :             t.dumpDependedTypes(generated, options);
    3898           0 :             break;
    3899             :         }
    3900             :     case codemaker::UnoType::SORT_CONSTANT_GROUP:
    3901             :         {
    3902             :             ConstantGroup t(
    3903           0 :                 dynamic_cast< unoidl::ConstantGroupEntity * >(ent.get()), name,
    3904           0 :                 manager);
    3905           0 :             if (t.hasConstants()) {
    3906           0 :                 t.dump(options);
    3907             :             }
    3908           0 :             break;
    3909             :         }
    3910             :     case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
    3911             :         {
    3912             :             ServiceType t(
    3913             :                 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
    3914           0 :                     ent.get()),
    3915           0 :                 name, manager);
    3916           0 :             t.dump(options);
    3917           0 :             t.dumpDependedTypes(generated, options);
    3918           0 :             break;
    3919             :         }
    3920             :     case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
    3921             :         {
    3922             :             SingletonType t(
    3923             :                 dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
    3924           0 :                     ent.get()),
    3925           0 :                 name, manager);
    3926           0 :             t.dump(options);
    3927           0 :             t.dumpDependedTypes(generated, options);
    3928           0 :             break;
    3929             :         }
    3930             :     case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
    3931             :     case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
    3932           0 :         break;
    3933             :     default:
    3934             :         throw CannotDumpException(
    3935           0 :             "unexpected entity \"" + name + "\" in call to produce");
    3936           0 :     }
    3937             : }
    3938             : 
    3939             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10