LCOV - code coverage report
Current view: top level - unodevtools/source/skeletonmaker - cpptypemaker.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 533 0.0 %
Date: 2014-11-03 Functions: 0 12 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 "codemaker/codemaker.hxx"
      23             : #include "codemaker/commoncpp.hxx"
      24             : #include "codemaker/global.hxx"
      25             : 
      26             : #include "skeletoncommon.hxx"
      27             : #include "skeletoncpp.hxx"
      28             : 
      29             : using namespace ::codemaker::cpp;
      30             : 
      31             : namespace skeletonmaker { namespace cpp {
      32             : 
      33           0 : void printType(
      34             :     std::ostream & o, ProgramOptions const & options,
      35             :     rtl::Reference< TypeManager > const & manager,
      36             :     codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
      37             :     std::vector< OUString > const & arguments,
      38             :     rtl::Reference< unoidl::Entity > const & entity, short referenceType,
      39             :     bool defaultvalue)
      40             : {
      41           0 :     if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) {
      42           0 :         switch (sort) {
      43             :         case codemaker::UnoType::SORT_BOOLEAN:
      44           0 :             o << "sal_False";
      45           0 :             return;
      46             :         case codemaker::UnoType::SORT_CHAR:
      47             :         case codemaker::UnoType::SORT_BYTE:
      48             :         case codemaker::UnoType::SORT_SHORT:
      49             :         case codemaker::UnoType::SORT_UNSIGNED_SHORT:
      50             :         case codemaker::UnoType::SORT_LONG:
      51             :         case codemaker::UnoType::SORT_UNSIGNED_LONG:
      52             :         case codemaker::UnoType::SORT_HYPER:
      53             :         case codemaker::UnoType::SORT_UNSIGNED_HYPER:
      54             :         case codemaker::UnoType::SORT_FLOAT:
      55             :         case codemaker::UnoType::SORT_DOUBLE:
      56           0 :             o << "0";
      57           0 :             return;
      58             :         default:
      59           0 :             break;
      60             :         }
      61             :     }
      62             : 
      63           0 :     if (defaultvalue && referenceType == 16) {
      64           0 :         if (sort == codemaker::UnoType::SORT_ENUM_TYPE) {
      65           0 :             o << nucleus.copy(nucleus.lastIndexOf('.') + 1) << "_"
      66           0 :               << dynamic_cast< unoidl::EnumTypeEntity * >(entity.get())->
      67           0 :                 getMembers()[0].name;
      68             :         }
      69           0 :         return;
      70             :     }
      71           0 :     bool bReference = false;
      72           0 :     if (((sort > codemaker::UnoType::SORT_CHAR ||
      73           0 :           rank > 0) && referenceType != 8 &&
      74           0 :          !(sort == codemaker::UnoType::SORT_ENUM_TYPE && referenceType == 4 && rank == 0)) ||
      75           0 :         (sort <= codemaker::UnoType::SORT_CHAR && referenceType == 2))
      76             :     {
      77           0 :         bReference = true;
      78             :     }
      79             : 
      80           0 :     if (bReference && referenceType == 4)
      81           0 :         o << "const ";
      82             : 
      83           0 :     for (sal_Int32 i = 0; i < rank; ++i) {
      84             :         o << ((options.shortnames) ? "css::uno::Sequence< " :
      85           0 :               "::com::sun::star::uno::Sequence< ");
      86             :     }
      87           0 :     if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE && referenceType > 0) {
      88             :         o << ((options.shortnames) ? "css::uno::Reference< " :
      89           0 :               "::com::sun::star::uno::Reference< ");
      90             :     }
      91             : 
      92             :     o << scopedCppName(codemaker::cpp::translateUnoToCppType(sort, nucleus),
      93           0 :                        options.shortnames && referenceType > 0);
      94             : 
      95           0 :     if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE && referenceType > 0)
      96           0 :         o << " >";
      97             : 
      98           0 :     if (!arguments.empty()) {
      99           0 :         o << "< ";
     100           0 :         for (std::vector< OUString >::const_iterator i(arguments.begin());
     101           0 :              i != arguments.end(); ++i)
     102             :         {
     103           0 :             if (i != arguments.begin())
     104           0 :                 o << ", ";
     105             : 
     106           0 :             printType(o, options, manager, *i, 1, false);
     107             :         }
     108           0 :         o << " >";
     109             :     }
     110             : 
     111           0 :     for (sal_Int32 i = 0; i < rank; ++i)
     112           0 :         o << " >";
     113             : 
     114           0 :     if (bReference && referenceType > 1)
     115           0 :         o << " &";
     116             : 
     117           0 :     if (referenceType == 8 && (sort > codemaker::UnoType::SORT_CHAR || rank > 0))
     118           0 :         o << "()";
     119             : }
     120             : 
     121           0 : void printType(
     122             :     std::ostream & o, ProgramOptions const & options,
     123             :     rtl::Reference< TypeManager > const & manager, OUString const & name,
     124             :     short referenceType, bool defaultvalue)
     125             : {
     126           0 :     OUString nucleus;
     127             :     sal_Int32 rank;
     128           0 :     std::vector< OUString > arguments;
     129           0 :     rtl::Reference< unoidl::Entity > entity;
     130             :     codemaker::UnoType::Sort sort = manager->decompose(
     131           0 :         name, true, &nucleus, &rank, &arguments, &entity);
     132             :     printType(
     133             :         o, options, manager, sort, nucleus, rank, arguments, entity,
     134           0 :         referenceType, defaultvalue);
     135           0 : }
     136             : 
     137           0 : bool printConstructorParameters(
     138             :     std::ostream & o, ProgramOptions const & options,
     139             :     rtl::Reference< TypeManager > const & manager,
     140             :     codemaker::UnoType::Sort sort,
     141             :     rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
     142             :     std::vector< OUString > const & arguments)
     143             : {
     144           0 :     bool previous = false;
     145           0 :     switch (sort) {
     146             :     case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     147             :         {
     148             :             rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
     149           0 :                 dynamic_cast< unoidl::PlainStructTypeEntity * >(entity.get()));
     150             :             assert(ent2.is());
     151           0 :             if (!ent2->getDirectBase().isEmpty()) {
     152           0 :                 rtl::Reference< unoidl::Entity > baseEnt;
     153             :                 codemaker::UnoType::Sort baseSort = manager->getSort(
     154           0 :                     ent2->getDirectBase(), &baseEnt);
     155             :                 previous = printConstructorParameters(
     156             :                     o, options, manager, baseSort, baseEnt,
     157           0 :                     ent2->getDirectBase(), std::vector< OUString >());
     158             :             }
     159           0 :             for (std::vector< unoidl::PlainStructTypeEntity::Member >::
     160           0 :                      const_iterator i(ent2->getDirectMembers().begin());
     161           0 :                  i != ent2->getDirectMembers().end(); ++i)
     162             :             {
     163           0 :                 if (previous) {
     164           0 :                     o << ", ";
     165             :                 }
     166           0 :                 previous = true;
     167           0 :                 printType(o, options, manager, i->type, 4);
     168           0 :                 o << ' '
     169             :                   << codemaker::cpp::translateUnoToCppIdentifier(
     170           0 :                       u2b(i->name), "param");
     171             :             }
     172           0 :             break;
     173             :         }
     174             :     case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     175             :         {
     176             :             rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
     177             :                 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
     178           0 :                     entity.get()));
     179             :             assert(ent2.is());
     180           0 :             for (std::vector<
     181             :                      unoidl::PolymorphicStructTypeTemplateEntity::Member >::
     182           0 :                      const_iterator i(ent2->getMembers().begin());
     183           0 :                  i != ent2->getMembers().end(); ++i)
     184             :             {
     185           0 :                 if (previous) {
     186           0 :                     o << ", ";
     187             :                 }
     188           0 :                 previous = true;
     189           0 :                 if (i->parameterized) {
     190           0 :                     o << i->type;
     191             :                 } else {
     192           0 :                     printType(o, options, manager, i->type, 4);
     193             :                 }
     194           0 :                 o << ' '
     195             :                   << codemaker::cpp::translateUnoToCppIdentifier(
     196           0 :                       u2b(i->name), "param");
     197             :             }
     198           0 :             break;
     199             :         }
     200             :     case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
     201             :         {
     202             :             rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
     203             :                 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
     204           0 :                     entity.get()));
     205             :             assert(ent2.is());
     206           0 :             for (std::vector<
     207             :                      unoidl::PolymorphicStructTypeTemplateEntity::Member >::
     208           0 :                      const_iterator i(ent2->getMembers().begin());
     209           0 :                  i != ent2->getMembers().end(); ++i)
     210             :             {
     211           0 :                 if (previous) {
     212           0 :                     o << ", ";
     213             :                 }
     214           0 :                 previous = true;
     215           0 :                 if (i->parameterized) {
     216           0 :                     for (std::vector< OUString >::const_iterator j(
     217           0 :                              ent2->getTypeParameters().begin());
     218           0 :                          j != ent2->getTypeParameters().end(); ++j)
     219             :                     {
     220           0 :                         if (i->type == *j) {
     221             :                             o << arguments[
     222           0 :                                 j - ent2->getTypeParameters().begin()];
     223           0 :                             break;
     224             :                         }
     225             :                     }
     226             :                 } else {
     227           0 :                     printType(o, options, manager, i->type, 4);
     228             :                 }
     229           0 :                 o << ' '
     230             :                   << codemaker::cpp::translateUnoToCppIdentifier(
     231           0 :                       u2b(i->name), "param");
     232             :             }
     233           0 :             break;
     234             :         }
     235             :     case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     236             :         {
     237             :             rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
     238           0 :                 dynamic_cast< unoidl::ExceptionTypeEntity * >(entity.get()));
     239             :             assert(ent2.is());
     240           0 :             if (!ent2->getDirectBase().isEmpty()) {
     241           0 :                 rtl::Reference< unoidl::Entity > baseEnt;
     242             :                 codemaker::UnoType::Sort baseSort = manager->getSort(
     243           0 :                     ent2->getDirectBase(), &baseEnt);
     244             :                 previous = printConstructorParameters(
     245             :                     o, options, manager, baseSort, baseEnt,
     246           0 :                     ent2->getDirectBase(), std::vector< OUString >());
     247             :             }
     248           0 :             for (std::vector< unoidl::ExceptionTypeEntity::Member >::
     249           0 :                      const_iterator i(ent2->getDirectMembers().begin());
     250           0 :                  i != ent2->getDirectMembers().end(); ++i)
     251             :             {
     252           0 :                 if (previous) {
     253           0 :                     o << ", ";
     254             :                 }
     255           0 :                 previous = true;
     256           0 :                 printType(o, options, manager, i->type, 4);
     257           0 :                 o << ' '
     258             :                   << codemaker::cpp::translateUnoToCppIdentifier(
     259           0 :                       u2b(i->name), "param");
     260             :             }
     261           0 :             break;
     262             :         }
     263             :     default:
     264             :         throw CannotDumpException(
     265           0 :             "unexpected entity \"" + name
     266           0 :             + "\" in call to skeletonmaker::cpp::printConstructorParameters");
     267             :     }
     268           0 :     return previous;
     269             : }
     270             : 
     271           0 : void printConstructor(
     272             :     std::ostream & o, ProgramOptions const & options,
     273             :     rtl::Reference< TypeManager > const & manager,
     274             :     codemaker::UnoType::Sort sort,
     275             :     rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
     276             :     std::vector< OUString > const & arguments)
     277             : {
     278           0 :     o << "public " << name.copy(name.lastIndexOf('.') + 1) << '(';
     279             :     printConstructorParameters(
     280           0 :         o, options, manager, sort, entity, name, arguments);
     281           0 :     o << ");\n";
     282           0 : }
     283             : 
     284           0 : void printMethodParameters(
     285             :     std::ostream & o, ProgramOptions const & options,
     286             :     rtl::Reference< TypeManager > const & manager,
     287             :     std::vector< unoidl::InterfaceTypeEntity::Method::Parameter > const &
     288             :         parameters,
     289             :     bool withType)
     290             : {
     291           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
     292           0 :              const_iterator i(parameters.begin());
     293           0 :          i != parameters.end(); ++i)
     294             :     {
     295           0 :         if (i != parameters.begin()) {
     296           0 :             o << ", ";
     297             :         }
     298           0 :         if (withType) {
     299             :             short referenceType;
     300           0 :             if (i->direction
     301           0 :                 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
     302             :             {
     303           0 :                 referenceType = 4;
     304             :             } else {
     305           0 :                 referenceType = 2;
     306             :             }
     307           0 :             printType(o, options, manager, i->type, referenceType);
     308           0 :             o << ' ';
     309             :         }
     310           0 :         o << codemaker::cpp::translateUnoToCppIdentifier(u2b(i->name), "param");
     311             :     }
     312           0 : }
     313             : 
     314           0 : void printExceptionSpecification(
     315             :     std::ostream & o,
     316             :     ProgramOptions const & options,
     317             :     rtl::Reference< TypeManager > const & manager,
     318             :     std::vector< OUString > const & exceptions)
     319             : {
     320             :     o << ((options.shortnames) ? " throw (css::uno::RuntimeException" :
     321           0 :           " throw (::com::sun::star::uno::RuntimeException");
     322           0 :     for (std::vector< OUString >::const_iterator i(exceptions.begin());
     323           0 :          i != exceptions.end(); ++i)
     324             :     {
     325           0 :         o << ", ";
     326           0 :         printType(o, options, manager, *i, 1);
     327             :     }
     328           0 :     o << ")";
     329           0 : }
     330             : 
     331           0 : void printSetPropertyMixinBody(
     332             :     std::ostream & o, unoidl::InterfaceTypeEntity::Attribute const & attribute)
     333             : {
     334             :     unoidl::AccumulationBasedServiceEntity::Property::Attributes propFlags
     335           0 :         = checkAdditionalPropertyFlags(attribute);
     336             : 
     337           0 :     o << "\n{\n";
     338             : 
     339           0 :     if (attribute.bound)
     340           0 :         o << "    BoundListeners l;\n";
     341             : 
     342           0 :     if (propFlags & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_CONSTRAINED) {
     343           0 :         OString fieldtype = codemaker::convertString(attribute.type);
     344             : 
     345           0 :         sal_Int32 index = fieldtype.lastIndexOf('<');
     346           0 :         sal_Int32 nPos=0;
     347           0 :         bool single = true;
     348           0 :         bool optional = false;
     349           0 :         OStringBuffer buffer1(64);
     350           0 :         OStringBuffer buffer2(64);
     351           0 :         do
     352             :         {
     353           0 :             OString s(fieldtype.getToken(0, '<', nPos));
     354           0 :             OString t = s.copy(s.lastIndexOf('/')+1);
     355             : 
     356           0 :             if (t.equals("Optional")) {
     357           0 :                 optional=true;
     358           0 :                 if (single) {
     359           0 :                     single=false;
     360           0 :                     buffer1.append("the_value.IsPresent");
     361           0 :                     buffer2.append("the_value.Value");
     362             :                 } else {
     363           0 :                     buffer1.insert(0, t);
     364           0 :                     buffer1.append(".IsPresent");
     365           0 :                     buffer2.insert(0, t);
     366           0 :                     buffer2.append(".Value");
     367             :                 }
     368             :             } else {
     369           0 :                 if (single) {
     370           0 :                     single=false;
     371           0 :                     if (!optional)
     372           0 :                         buffer1.append("the_value.Value");
     373             : 
     374           0 :                     buffer2.append("the_value.Value");
     375             :                 } else {
     376           0 :                     if (!optional) {
     377           0 :                         buffer1.insert(0, t);
     378           0 :                         buffer1.append(".Value");
     379             :                     }
     380           0 :                     buffer2.insert(0, t);
     381           0 :                     buffer2.append(".Value");
     382             :                 }
     383           0 :             }
     384           0 :         } while( nPos <= index );
     385             : 
     386           0 :         o << "    css::uno::Any v;\n";
     387           0 :         if (optional) {
     388           0 :             o << "    if(" << buffer1.makeStringAndClear() << ")\n    {\n        v <<= " << buffer2.makeStringAndClear() << ";\n    }\n";
     389             :         } else {
     390           0 :             o << "    v <<= " << buffer2.makeStringAndClear() << ";\n\n";
     391             :         }
     392             : 
     393           0 :         o << "    prepareSet(\n        rtl::OUString(\""
     394           0 :           << attribute.name << "\"),\n        css::uno::Any(), v, ";
     395             :     } else {
     396           0 :         o << "    prepareSet(\n        rtl::OUString(\""
     397           0 :           << attribute.name << "\"),\n        css::uno::Any(), css::uno::Any(), ";
     398             :     }
     399             : 
     400           0 :     if (attribute.bound)
     401           0 :         o << "&l);\n";
     402             :     else
     403           0 :         o << "0);\n";
     404             : 
     405           0 :     o << "    {\n        osl::MutexGuard g(m_aMutex);\n        m_"
     406           0 :       << attribute.name << " = the_value;\n    }\n";
     407             : 
     408           0 :     if (attribute.bound)
     409           0 :         o << "    l.notify();\n";
     410             : 
     411           0 :     o  << "}\n\n";
     412           0 : }
     413             : 
     414           0 : void printMethods(std::ostream & o,
     415             :     ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
     416             :     OUString const & name, codemaker::GeneratedTypeSet & generated,
     417             :     OString const & delegate, OString const & classname,
     418             :     OString const & indentation, bool defaultvalue,
     419             :     OUString const & propertyhelper)
     420             : {
     421           0 :     if (generated.contains(u2b(name)) || name == "com.sun.star.uno.XInterface" ||
     422           0 :         (defaultvalue &&
     423           0 :          ( name == "com.sun.star.lang.XComponent" ||
     424           0 :            name == "com.sun.star.lang.XTypeProvider" ||
     425           0 :            name == "com.sun.star.uno.XWeak" ) ) )
     426             :     {
     427           0 :         return;
     428             :     }
     429             : 
     430           0 :     static OString sd("_");
     431           0 :     bool body = !delegate.isEmpty();
     432           0 :     bool defaultbody = delegate.equals(sd);
     433             : 
     434           0 :     if (body && propertyhelper.getLength() > 1) {
     435           0 :         if (name == "com.sun.star.beans.XPropertySet") {
     436           0 :             generated.add(u2b(name));
     437             :             generateXPropertySetBodies(
     438           0 :                 o, classname, scopedCppName(u2b(propertyhelper)));
     439           0 :             return;
     440           0 :         } else if (name == "com.sun.star.beans.XFastPropertySet") {
     441           0 :             generated.add(u2b(name));
     442             :             generateXFastPropertySetBodies(
     443           0 :                 o, classname, scopedCppName(u2b(propertyhelper)));
     444           0 :             return;
     445           0 :         } else if (name == "com.sun.star.beans.XPropertyAccess") {
     446           0 :             generated.add(u2b(name));
     447             :             generateXPropertyAccessBodies(
     448           0 :                 o, classname, scopedCppName(u2b(propertyhelper)));
     449           0 :             return;
     450             :         }
     451             :     }
     452             : 
     453           0 :     if (body && options.componenttype == 2) {
     454           0 :         if (name == "com.sun.star.lang.XServiceName") {
     455             :             o << "// ::com::sun::star::lang::XServiceName:\n"
     456           0 :                 "::rtl::OUString SAL_CALL " << classname << "getServiceName() "
     457             :                 "throw (css::uno::RuntimeException)\n{\n    "
     458             :                 "return ::rtl::OUString("
     459           0 :                 "sADDIN_SERVICENAME);\n}\n";
     460           0 :             generated.add(u2b(name));
     461           0 :             return;
     462           0 :         } else if (name == "com.sun.star.sheet.XAddIn") {
     463           0 :             generateXAddInBodies(o, classname);
     464           0 :             generated.add(u2b(name));
     465             : 
     466             :             // special handling of XLocalizable -> parent of XAddIn
     467           0 :             if (!generated.contains("com.sun.star.lang.XLocalizable")) {
     468           0 :                 generateXLocalizable(o, classname);
     469           0 :                 generated.add("com.sun.star.lang.XLocalizable");
     470             :             }
     471           0 :             return;
     472           0 :         } else if (name == "com.sun.star.lang.XLocalizable") {
     473           0 :             generateXLocalizable(o, classname);
     474           0 :             generated.add(u2b(name));
     475           0 :             return;
     476           0 :         } else if (name == "com.sun.star.sheet.XCompatibilityNames") {
     477           0 :             generateXCompatibilityNamesBodies(o, classname);
     478           0 :             generated.add(u2b(name));
     479           0 :             return;
     480             :         }
     481             :     }
     482             : 
     483           0 :     if (body && options.componenttype == 3) {
     484           0 :         if (name == "com.sun.star.lang.XInitialization") {
     485           0 :             generateXInitialization(o, classname);
     486           0 :             generated.add(u2b(name));
     487           0 :             return;
     488           0 :         } else if (name == "com.sun.star.frame.XDispatch") {
     489           0 :             generateXDispatch(o, classname, options.protocolCmdMap);
     490           0 :             generated.add(u2b(name));
     491           0 :             return;
     492           0 :         } else if (name == "com.sun.star.frame.XDispatchProvider") {
     493           0 :             generateXDispatchProvider(o, classname, options.protocolCmdMap);
     494           0 :             generated.add(u2b(name));
     495           0 :             return;
     496             :         }
     497             :     }
     498             : 
     499           0 :     generated.add(u2b(name));
     500           0 :     rtl::Reference< unoidl::Entity > ent;
     501           0 :     if (manager->getSort(name, &ent) != codemaker::UnoType::SORT_INTERFACE_TYPE)
     502             :     {
     503             :         throw CannotDumpException(
     504           0 :             "unexpected entity \"" + name
     505           0 :             + "\" in call to skeletonmaker::cpp::printMethods");
     506             :     }
     507             :     rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
     508           0 :         dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
     509             :     assert(ent2.is());
     510           0 :     if (options.all || defaultvalue) {
     511           0 :         for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     512           0 :                  ent2->getDirectMandatoryBases().begin());
     513           0 :              i != ent2->getDirectMandatoryBases().end(); ++i)
     514             :         {
     515             :             printMethods(
     516           0 :                 o, options, manager, i->name, generated, delegate, classname,
     517           0 :                 indentation, defaultvalue, propertyhelper);
     518             :         }
     519           0 :         if (!(ent2->getDirectAttributes().empty()
     520           0 :               && ent2->getDirectMethods().empty()))
     521             :         {
     522           0 :             o << indentation << "// ";
     523           0 :             printType(o, options, manager, name, 0);
     524           0 :             o << ":\n";
     525             :         }
     526             :     }
     527           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
     528           0 :              i(ent2->getDirectAttributes().begin());
     529           0 :          i != ent2->getDirectAttributes().end(); ++i)
     530             :     {
     531           0 :         o << indentation;
     532           0 :         if (!body)
     533           0 :             o << "virtual ";
     534             : 
     535           0 :         printType(o, options, manager, i->type, 1);
     536           0 :         o << " SAL_CALL ";
     537           0 :         if (!classname.isEmpty())
     538           0 :             o << classname;
     539             : 
     540           0 :         o << "get" << i->name << "()";
     541           0 :         printExceptionSpecification(o, options, manager, i->getExceptions);
     542           0 :         if (body) {
     543           0 :             if (defaultbody) {
     544           0 :                 if (!propertyhelper.isEmpty()) {
     545           0 :                     o << "\n{\n    osl::MutexGuard g(m_aMutex);\n    return m_"
     546           0 :                       << i->name << ";\n}\n\n";
     547             :                 } else {
     548           0 :                     o << "\n{\n    return ";
     549           0 :                     if (options.componenttype == 1) {
     550           0 :                         o << "m_" << i->name;
     551             :                     } else {
     552           0 :                         printType(o, options, manager, i->type, 8, true);
     553             :                     }
     554           0 :                     o << ";\n}\n\n";
     555             :                 }
     556             :             } else {
     557           0 :                 o << "\n" << indentation << "{\n" << indentation << "    return "
     558           0 :                   << delegate.getStr() << "get" << i->name << "();\n"
     559           0 :                   << indentation << "}\n\n";
     560             :             }
     561             :         } else {
     562           0 :             o << ";\n";
     563             :         }
     564             : 
     565           0 :         if (!i->readOnly) {
     566           0 :             o << indentation;
     567           0 :             if (!body)
     568           0 :                 o << "virtual ";
     569             : 
     570           0 :             o << "void SAL_CALL ";
     571           0 :             if (!classname.isEmpty())
     572           0 :                 o << classname;
     573             : 
     574           0 :             o << "set" << i->name << '(';
     575           0 :             printType(o, options, manager, i->type, 4);
     576           0 :             o << " the_value)";
     577           0 :             printExceptionSpecification(o, options, manager, i->setExceptions);
     578           0 :             if (body) {
     579           0 :                 if (defaultbody) {
     580           0 :                     if (!propertyhelper.isEmpty()) {
     581           0 :                         printSetPropertyMixinBody(o, *i);
     582             :                     } else {
     583           0 :                         if (options.componenttype == 1) {
     584           0 :                             o << "\n{\n    m_" << i->name
     585           0 :                               << " = the_value;\n}\n\n";
     586             :                         } else {
     587           0 :                             o << "\n{\n\n}\n\n";
     588             :                         }
     589             :                     }
     590             :                 } else {
     591           0 :                     o << "\n" << indentation << "{\n" << indentation << "    "
     592           0 :                       << delegate.getStr() << "set" << i->name
     593           0 :                       << "(the_value);\n" << indentation << "}\n\n";
     594             :                 }
     595             :             } else {
     596           0 :                 o << ";\n";
     597             :             }
     598             :         }
     599             :     }
     600           0 :     for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
     601           0 :              ent2->getDirectMethods().begin());
     602           0 :          i != ent2->getDirectMethods().end(); ++i)
     603             :     {
     604           0 :         o << indentation;
     605           0 :         if (!body)
     606           0 :             o << "virtual ";
     607             : 
     608           0 :         printType(o, options, manager, i->returnType, 1);
     609           0 :         o << " SAL_CALL ";
     610           0 :         if (!classname.isEmpty())
     611           0 :             o << classname;
     612             : 
     613           0 :         o << i->name << '(';
     614           0 :         printMethodParameters(o, options, manager, i->parameters, true);
     615           0 :         o << ')';
     616           0 :         printExceptionSpecification(o, options, manager, i->exceptions);
     617           0 :         if (body) {
     618           0 :             if (defaultbody) {
     619           0 :                 o << "\n{\n";
     620           0 :                 if (i->returnType != "void") {
     621           0 :                     o << "    // TODO: Exchange the default return implementation for \""
     622           0 :                       << i->name << "\" !!!\n";
     623             :                     o << "    // Exchange the default return implementation.\n"
     624             :                         "    // NOTE: Default initialized polymorphic structs "
     625             :                         "can cause problems because of\n    // missing default "
     626             :                         "initialization of primitive types of some C++ compilers or"
     627             :                         "\n    // different Any initialization in Java and C++ "
     628           0 :                         "polymorphic structs.\n    return ";
     629           0 :                     printType(o, options, manager, i->returnType, 8, true);
     630           0 :                     o << ";";
     631             :                 } else {
     632           0 :                     o << "    // TODO: Insert your implementation for \""
     633           0 :                       << i->name << "\" here.";
     634             :                 }
     635           0 :                 o << "\n}\n\n";
     636             :             } else {
     637           0 :                 o << "\n" << indentation << "{\n" << indentation << "    ";
     638           0 :                 if (i->returnType != "void")
     639           0 :                     o << "return ";
     640             : 
     641           0 :                 o << delegate.getStr() << i->name << '(';
     642             :                 printMethodParameters(
     643           0 :                     o, options, manager, i->parameters, false);
     644           0 :                 o << ");\n" << indentation << "}\n\n";
     645             :             }
     646             :         } else {
     647           0 :             o << ";\n";
     648             :         }
     649             :     }
     650             : 
     651           0 :     if (!body)
     652           0 :         o << "\n";
     653             : }
     654             : 
     655           0 : void printConstructors(
     656             :     std::ostream & o, ProgramOptions const & options,
     657             :     rtl::Reference< TypeManager > const & manager, OUString const & name)
     658             : {
     659           0 :     rtl::Reference< unoidl::Entity > ent;
     660           0 :     if (manager->getSort(name, &ent)
     661             :         != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE)
     662             :     {
     663             :         throw CannotDumpException(
     664           0 :             "unexpected entity \"" + name
     665           0 :             + "\" in call to skeletonmaker::java::printConstructors");
     666             :     }
     667             :     rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
     668           0 :         dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(ent.get()));
     669             :     assert(ent2.is());
     670           0 :     for (std::vector< unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
     671           0 :              const_iterator i(ent2->getConstructors().begin());
     672           0 :          i != ent2->getConstructors().end(); ++i)
     673             :     {
     674           0 :         o << "static ";
     675           0 :         printType(o, options, manager, ent2->getBase(), 1);
     676           0 :         o << ' ';
     677           0 :         if (i->defaultConstructor) {
     678           0 :             o << "create";
     679             :         } else {
     680             :             o << codemaker::cpp::translateUnoToCppIdentifier(
     681           0 :                 u2b(i->name), "method");
     682             :         }
     683             :         o << ((options.shortnames) ? "(css::uno::Reference< css" :
     684           0 :               "(::com::sun::star::uno::Reference< ::com::sun::star")
     685           0 :           << "::uno::XComponentContext > const & the_context";
     686           0 :         for (std::vector<
     687             :                  unoidl::SingleInterfaceBasedServiceEntity::Constructor::
     688           0 :                  Parameter >::const_iterator j(i->parameters.begin());
     689           0 :              j != i->parameters.end(); ++j)
     690             :         {
     691           0 :             o << ", ";
     692           0 :             printType(o, options, manager, j->type, 4);
     693           0 :             o << ' '
     694             :               << codemaker::cpp::translateUnoToCppIdentifier(
     695           0 :                   u2b(j->name), "param");
     696             :         }
     697           0 :         o << ')';
     698           0 :         printExceptionSpecification(o, options, manager, i->exceptions);
     699           0 :         o << ";\n";
     700           0 :     }
     701           0 : }
     702             : 
     703           0 : void printServiceMembers(
     704             :     std::ostream & o, ProgramOptions const & options,
     705             :     rtl::Reference< TypeManager > const & manager,
     706             :     OUString const & name,
     707             :     rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity,
     708             :     OString const & delegate)
     709             : {
     710             :     assert(entity.is());
     711           0 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     712           0 :              entity->getDirectMandatoryBaseServices().begin());
     713           0 :          i != entity->getDirectMandatoryBaseServices().end(); ++i)
     714             :     {
     715           0 :         o << "\n// exported service " << i->name << "\n";
     716           0 :         generateDocumentation(o, options, manager, u2b(i->name), delegate);
     717           0 :         o << "\n// end of exported service " << i->name << "\n";
     718             :     }
     719           0 :     for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
     720           0 :              entity->getDirectMandatoryBaseInterfaces().begin());
     721           0 :          i != entity->getDirectMandatoryBaseInterfaces().end(); ++i)
     722             :     {
     723           0 :         o << "\n// supported interface " << i->name << "\n";
     724           0 :         generateDocumentation(o, options, manager, u2b(i->name), delegate);
     725             :     }
     726           0 :     if (delegate.isEmpty()) {
     727           0 :         o << "\n// properties of service \""<< name << "\"\n";
     728           0 :         for (std::vector< unoidl::AccumulationBasedServiceEntity::Property >::
     729           0 :                  const_iterator i(entity->getDirectProperties().begin());
     730           0 :              i != entity->getDirectProperties().end(); ++i)
     731             :         {
     732           0 :             o << "// private ";
     733           0 :             printType(o, options, manager, i->type, 1);
     734           0 :             o << " "
     735             :               << codemaker::cpp::translateUnoToCppIdentifier(
     736           0 :                   u2b(i->name), "property")
     737           0 :               << ";\n";
     738             :         }
     739             :     }
     740           0 : }
     741             : 
     742           0 : void printMapsToCppType(
     743             :     std::ostream & o, ProgramOptions const & options,
     744             :     rtl::Reference< TypeManager > const & manager,
     745             :     codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
     746             :     std::vector< OUString > const & arguments,
     747             :     rtl::Reference< unoidl::Entity > const & entity, const char * cppTypeSort)
     748             : {
     749           0 :     o << "maps to C++ ";
     750           0 :     if (cppTypeSort != 0)
     751           0 :         o << cppTypeSort << ' ';
     752             : 
     753           0 :     o << "type \"";
     754           0 :     if (rank == 0 && nucleus == "com.sun.star.uno.XInterface") {
     755           0 :         o << "Reference< com::sun::star::uno::XInterface >";
     756             :     } else {
     757             :         printType(
     758             :             o, options, manager, sort, nucleus, rank, arguments, entity, 0,
     759           0 :             false);
     760             :     }
     761           0 :     o << '"';
     762           0 : }
     763             : 
     764           0 : void generateDocumentation(std::ostream & o,
     765             :     ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
     766             :     OString const & type, OString const & delegate)
     767             : {
     768           0 :     OUString nucleus;
     769             :     sal_Int32 rank;
     770             :     codemaker::UnoType::Sort sort = manager->decompose(
     771           0 :         b2u(type), false, &nucleus, &rank, 0, 0);
     772             : 
     773           0 :     bool comment = true;
     774           0 :     if (!delegate.isEmpty()) {
     775           0 :         if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE &&
     776           0 :             sort != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE &&
     777             :             sort != codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE )
     778             :         {
     779           0 :             return;
     780             :         }
     781           0 :         comment = false;
     782             :     }
     783             : 
     784           0 :     if (comment) {
     785           0 :         o << "\n// UNO";
     786           0 :         if (rank != 0) {
     787           0 :             o << " sequence type";
     788           0 :         } else if (sort <= codemaker::UnoType::SORT_ANY) {
     789           0 :             o << " simple type";
     790             :         } else {
     791           0 :             switch (sort) {
     792             :             case codemaker::UnoType::SORT_INTERFACE_TYPE:
     793           0 :                 o << " interface type";
     794           0 :                 break;
     795             : 
     796             :             case codemaker::UnoType::SORT_MODULE:
     797           0 :                 o << "IDL module";
     798           0 :                 break;
     799             : 
     800             :             case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     801           0 :                 o << " simple struct type";
     802           0 :                 break;
     803             : 
     804             :             case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     805           0 :                 o << " polymorphic struct type template";
     806           0 :                 break;
     807             : 
     808             :             case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
     809           0 :                 o << " instantiated polymorphic struct type";
     810           0 :                 break;
     811             : 
     812             :             case codemaker::UnoType::SORT_ENUM_TYPE:
     813           0 :                 o << " enum type";
     814           0 :                 break;
     815             : 
     816             :             case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     817           0 :                 o << " exception type";
     818           0 :                 break;
     819             : 
     820             :             case codemaker::UnoType::SORT_TYPEDEF:
     821           0 :                 o << "IDL typedef";
     822           0 :                 break;
     823             : 
     824             :             case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
     825           0 :                 o << " single-inheritance--based service";
     826           0 :                 break;
     827             : 
     828             :             case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
     829           0 :                 o << "IDL accumulation-based service";
     830           0 :                 break;
     831             : 
     832             :             case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
     833           0 :                 o << " inheritance-based singleton";
     834           0 :                 break;
     835             : 
     836             :             case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
     837           0 :                 o << "IDL service-based singleton";
     838           0 :                 break;
     839             : 
     840             :             case codemaker::UnoType::SORT_CONSTANT_GROUP:
     841           0 :                 o << "IDL constant group";
     842           0 :                 break;
     843             : 
     844             :             default:
     845             :                 OSL_ASSERT(false);
     846           0 :                 break;
     847             :             }
     848             :         }
     849           0 :         o << " \"" << type << "\" ";
     850             :     }
     851           0 :     std::vector< OUString > arguments;
     852           0 :     rtl::Reference< unoidl::Entity > entity;
     853             :     sort = manager->decompose(
     854           0 :         b2u(type), true, &nucleus, &rank, &arguments, &entity);
     855           0 :     if (rank != 0) {
     856           0 :         if (comment) {
     857             :             printMapsToCppType(
     858             :                 o, options, manager, sort, nucleus, rank, arguments, entity,
     859           0 :                 "array");
     860           0 :             o << '\n';
     861             :         }
     862           0 :     } else if (sort <= codemaker::UnoType::SORT_ANY) {
     863           0 :         if (comment) {
     864             :             printMapsToCppType(
     865           0 :                 o, options, manager, sort, nucleus, rank, arguments, entity, 0);
     866           0 :             o << '\n';
     867             :         }
     868             :     } else {
     869           0 :         switch (sort) {
     870             :         case codemaker::UnoType::SORT_INTERFACE_TYPE:
     871           0 :             if (comment)
     872             :                 printMapsToCppType(
     873             :                     o, options, manager, sort, nucleus, rank, arguments, entity,
     874           0 :                     "interface");
     875           0 :             if (nucleus == "com.sun.star.uno.XInterface") {
     876           0 :                 if (comment)
     877           0 :                     o << '\n';
     878             :             } else {
     879           0 :                 if (comment)
     880           0 :                     o << "; " << (options.all ? "all" : "direct") << " methods:\n";
     881             : 
     882           0 :                 codemaker::GeneratedTypeSet generated;
     883             :                 printMethods(
     884             :                     o, options, manager, nucleus, generated, delegate,
     885           0 :                     options.implname, "");
     886             :             }
     887           0 :             break;
     888             : 
     889             :         case codemaker::UnoType::SORT_MODULE:
     890             :             printMapsToCppType(
     891             :                 o, options, manager, sort, nucleus, rank, arguments, entity,
     892           0 :                 "namespace");
     893           0 :             o << '\n';
     894           0 :             break;
     895             : 
     896             :         case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
     897             :             printMapsToCppType(
     898             :                 o, options, manager, sort, nucleus, rank, arguments, entity,
     899           0 :                 "class");
     900           0 :             o << "; full constructor:\n";
     901             :             printConstructor(
     902             :                 o, options, manager, codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE,
     903           0 :                 entity, nucleus, arguments);
     904           0 :             break;
     905             : 
     906             :         case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
     907             :             printMapsToCppType(
     908             :                 o, options, manager, sort, nucleus, rank, arguments, entity,
     909           0 :                 "class template");
     910           0 :             o << "; full constructor:\n";
     911             :             printConstructor(
     912             :                 o, options, manager,
     913             :                 codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE,
     914           0 :                 entity, nucleus, arguments);
     915           0 :             break;
     916             : 
     917             :         case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
     918             :             printMapsToCppType(
     919             :                 o, options, manager, sort, nucleus, rank, arguments, entity,
     920           0 :                 "class template instantiation");
     921           0 :             o << "; full constructor:\n";
     922             :             printConstructor(
     923             :                 o, options, manager,
     924             :                 codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE,
     925           0 :                 entity, nucleus, arguments);
     926           0 :             break;
     927             : 
     928             :         case codemaker::UnoType::SORT_ENUM_TYPE:
     929             :             printMapsToCppType(
     930             :                 o, options, manager, sort, nucleus, rank, arguments, entity,
     931           0 :                 "enum");
     932           0 :             o << '\n';
     933           0 :             break;
     934             : 
     935             :         case codemaker::UnoType::SORT_CONSTANT_GROUP:
     936             :             printMapsToCppType(
     937             :                 o, options, manager, sort, nucleus, rank, arguments, entity,
     938           0 :                 "namespace");
     939           0 :             o << '\n';
     940           0 :             break;
     941             : 
     942             :         case codemaker::UnoType::SORT_EXCEPTION_TYPE:
     943             :             printMapsToCppType(
     944             :                 o, options, manager, sort, nucleus, rank, arguments, entity,
     945           0 :                 "exception class");
     946           0 :             o << "; full constructor:\n";
     947             :             printConstructor(
     948             :                 o, options, manager, codemaker::UnoType::SORT_EXCEPTION_TYPE,
     949           0 :                 entity, nucleus, arguments);
     950           0 :             break;
     951             : 
     952             :         case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
     953           0 :             if (comment) {
     954             :                 printMapsToCppType(
     955             :                     o, options, manager, sort, nucleus, rank, arguments, entity,
     956           0 :                     "class");
     957           0 :                 o << "; construction methods:\n";
     958           0 :                 printConstructors(o, options, manager, nucleus);
     959             :             }
     960             :             generateDocumentation(
     961             :                 o, options, manager,
     962             :                 u2b(dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
     963           0 :                         entity.get())->getBase()),
     964           0 :                 delegate);
     965           0 :             break;
     966             : 
     967             :         case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
     968           0 :             if (comment)
     969             :                 o << ("does not map to C++\n"
     970           0 :                       "// the service members are generated instead\n");
     971             :             printServiceMembers(
     972             :                 o, options, manager, nucleus,
     973             :                 dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
     974           0 :                     entity.get()),
     975           0 :                 delegate);
     976           0 :             break;
     977             : 
     978             :         case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
     979             :             printMapsToCppType(
     980             :                 o, options, manager, sort, nucleus, rank, arguments, entity,
     981           0 :                 "class");
     982           0 :             o << "; get method:\nstatic ";
     983             :             printType(
     984             :                 o, options, manager,
     985             :                 dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
     986           0 :                     entity.get())->getBase(),
     987           0 :                 1);
     988           0 :             o << " get(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);\n";
     989           0 :             break;
     990             : 
     991             :         case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
     992           0 :             o << "does not map to C++\n";
     993           0 :             break;
     994             : 
     995             :         default:
     996             :             OSL_ASSERT(false);
     997           0 :             break;
     998             :         }
     999           0 :     }
    1000             : }
    1001             : 
    1002             : } }
    1003             : 
    1004             : 
    1005             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10