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

Generated by: LCOV version 1.10