Bump version to 24.04.3.4
[LibreOffice.git] / unodevtools / source / skeletonmaker / cpptypemaker.cxx
blob5e5e165b2fbc3aaaf49bdb774b50b2865dcecbbf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <codemaker/codemaker.hxx>
23 #include <codemaker/commoncpp.hxx>
24 #include <codemaker/global.hxx>
26 #include "skeletoncommon.hxx"
27 #include "skeletoncpp.hxx"
29 #include <algorithm>
30 #include <string_view>
32 using namespace ::codemaker::cpp;
34 namespace skeletonmaker::cpp {
36 static void printType(
37 std::ostream & o, ProgramOptions const & options,
38 rtl::Reference< TypeManager > const & manager,
39 codemaker::UnoType::Sort sort, std::u16string_view nucleus, sal_Int32 rank,
40 std::vector< OUString > const & arguments,
41 rtl::Reference< unoidl::Entity > const & entity, short referenceType,
42 bool defaultvalue)
44 if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::Sort::Char) {
45 switch (sort) {
46 case codemaker::UnoType::Sort::Boolean:
47 o << "sal_False";
48 return;
49 case codemaker::UnoType::Sort::Char:
50 case codemaker::UnoType::Sort::Byte:
51 case codemaker::UnoType::Sort::Short:
52 case codemaker::UnoType::Sort::UnsignedShort:
53 case codemaker::UnoType::Sort::Long:
54 case codemaker::UnoType::Sort::UnsignedLong:
55 case codemaker::UnoType::Sort::Hyper:
56 case codemaker::UnoType::Sort::UnsignedHyper:
57 case codemaker::UnoType::Sort::Float:
58 case codemaker::UnoType::Sort::Double:
59 o << "0";
60 return;
61 default:
62 break;
66 if (defaultvalue && referenceType == 16) {
67 if (sort == codemaker::UnoType::Sort::Enum) {
68 auto pEnumTypeEntity(dynamic_cast<unoidl::EnumTypeEntity *>(entity.get()));
69 assert(pEnumTypeEntity);
70 o << OUString(nucleus.substr(nucleus.rfind('.') + 1)) << "_"
71 << pEnumTypeEntity->getMembers()[0].name;
73 return;
75 bool bReference = false;
76 if (((sort > codemaker::UnoType::Sort::Char ||
77 rank > 0) && referenceType != 8 &&
78 !(sort == codemaker::UnoType::Sort::Enum && referenceType == 4 && rank == 0)) ||
79 (sort <= codemaker::UnoType::Sort::Char && referenceType == 2))
81 bReference = true;
84 if (bReference && referenceType == 4)
85 o << "const ";
87 for (sal_Int32 i = 0; i < rank; ++i) {
88 o << ((options.shortnames) ? "css::uno::Sequence< " :
89 "::com::sun::star::uno::Sequence< ");
91 if (sort == codemaker::UnoType::Sort::Interface && referenceType > 0) {
92 o << ((options.shortnames) ? "css::uno::Reference< " :
93 "::com::sun::star::uno::Reference< ");
96 o << scopedCppName(codemaker::cpp::translateUnoToCppType(sort, nucleus),
97 options.shortnames && referenceType > 0);
99 if (sort == codemaker::UnoType::Sort::Interface && referenceType > 0)
100 o << " >";
102 if (!arguments.empty()) {
103 o << "< ";
104 for (std::vector< OUString >::const_iterator i(arguments.begin());
105 i != arguments.end(); ++i)
107 if (i != arguments.begin())
108 o << ", ";
110 printType(o, options, manager, *i, 1);
112 o << " >";
115 for (sal_Int32 i = 0; i < rank; ++i)
116 o << " >";
118 if (bReference && referenceType > 1)
119 o << " &";
121 if (referenceType == 8 && (sort > codemaker::UnoType::Sort::Char || rank > 0))
122 o << "()";
125 void printType(
126 std::ostream & o, ProgramOptions const & options,
127 rtl::Reference< TypeManager > const & manager, std::u16string_view name,
128 short referenceType, bool defaultvalue)
130 OUString nucleus;
131 sal_Int32 rank;
132 std::vector< OUString > arguments;
133 rtl::Reference< unoidl::Entity > entity;
134 codemaker::UnoType::Sort sort = manager->decompose(
135 name, true, &nucleus, &rank, &arguments, &entity);
136 printType(
137 o, options, manager, sort, nucleus, rank, arguments, entity,
138 referenceType, defaultvalue);
141 static bool printConstructorParameters(
142 std::ostream & o, ProgramOptions const & options,
143 rtl::Reference< TypeManager > const & manager,
144 codemaker::UnoType::Sort sort,
145 rtl::Reference< unoidl::Entity > const & entity, std::u16string_view name,
146 std::vector< OUString > const & arguments)
148 bool previous = false;
149 switch (sort) {
150 case codemaker::UnoType::Sort::PlainStruct:
152 rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
153 dynamic_cast< unoidl::PlainStructTypeEntity * >(entity.get()));
154 assert(ent2.is());
155 if (!ent2->getDirectBase().isEmpty()) {
156 rtl::Reference< unoidl::Entity > baseEnt;
157 codemaker::UnoType::Sort baseSort = manager->getSort(
158 ent2->getDirectBase(), &baseEnt);
159 previous = printConstructorParameters(
160 o, options, manager, baseSort, baseEnt,
161 ent2->getDirectBase(), std::vector< OUString >());
163 for (const auto& rMember : ent2->getDirectMembers())
165 if (previous) {
166 o << ", ";
168 previous = true;
169 printType(o, options, manager, rMember.type, 4);
170 o << ' '
171 << codemaker::cpp::translateUnoToCppIdentifier(
172 u2b(rMember.name), "param");
174 break;
176 case codemaker::UnoType::Sort::PolymorphicStructTemplate:
178 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
179 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
180 entity.get()));
181 assert(ent2.is());
182 for (const auto& rMember : ent2->getMembers())
184 if (previous) {
185 o << ", ";
187 previous = true;
188 if (rMember.parameterized) {
189 o << rMember.type;
190 } else {
191 printType(o, options, manager, rMember.type, 4);
193 o << ' '
194 << codemaker::cpp::translateUnoToCppIdentifier(
195 u2b(rMember.name), "param");
197 break;
199 case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
201 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
202 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
203 entity.get()));
204 assert(ent2.is());
205 for (const auto& rMember : ent2->getMembers())
207 if (previous) {
208 o << ", ";
210 previous = true;
211 if (rMember.parameterized) {
212 auto j = std::find(ent2->getTypeParameters().begin(),
213 ent2->getTypeParameters().end(), rMember.type);
214 if (j != ent2->getTypeParameters().end()) {
215 o << arguments[j - ent2->getTypeParameters().begin()];
217 } else {
218 printType(o, options, manager, rMember.type, 4);
220 o << ' '
221 << codemaker::cpp::translateUnoToCppIdentifier(
222 u2b(rMember.name), "param");
224 break;
226 case codemaker::UnoType::Sort::Exception:
228 rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
229 dynamic_cast< unoidl::ExceptionTypeEntity * >(entity.get()));
230 assert(ent2.is());
231 if (!ent2->getDirectBase().isEmpty()) {
232 rtl::Reference< unoidl::Entity > baseEnt;
233 codemaker::UnoType::Sort baseSort = manager->getSort(
234 ent2->getDirectBase(), &baseEnt);
235 previous = printConstructorParameters(
236 o, options, manager, baseSort, baseEnt,
237 ent2->getDirectBase(), std::vector< OUString >());
239 for (const auto& rMember : ent2->getDirectMembers())
241 if (previous) {
242 o << ", ";
244 previous = true;
245 printType(o, options, manager, rMember.type, 4);
246 o << ' '
247 << codemaker::cpp::translateUnoToCppIdentifier(
248 u2b(rMember.name), "param");
250 break;
252 default:
253 throw CannotDumpException(
254 OUString::Concat("unexpected entity \"") + name
255 + "\" in call to skeletonmaker::cpp::printConstructorParameters");
257 return previous;
260 static void printConstructor(
261 std::ostream & o, ProgramOptions const & options,
262 rtl::Reference< TypeManager > const & manager,
263 codemaker::UnoType::Sort sort,
264 rtl::Reference< unoidl::Entity > const & entity, std::u16string_view name,
265 std::vector< OUString > const & arguments)
267 o << "public " << OUString(name.substr(name.rfind('.') + 1)) << '(';
268 printConstructorParameters(
269 o, options, manager, sort, entity, name, arguments);
270 o << ");\n";
273 static void printMethodParameters(
274 std::ostream & o, ProgramOptions const & options,
275 rtl::Reference< TypeManager > const & manager,
276 std::vector< unoidl::InterfaceTypeEntity::Method::Parameter > const &
277 parameters,
278 bool withType)
280 for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
281 const_iterator i(parameters.begin());
282 i != parameters.end(); ++i)
284 if (i != parameters.begin()) {
285 o << ", ";
287 if (withType) {
288 short referenceType;
289 if (i->direction
290 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
292 referenceType = 4;
293 } else {
294 referenceType = 2;
296 printType(o, options, manager, i->type, referenceType);
297 o << ' ';
299 o << codemaker::cpp::translateUnoToCppIdentifier(u2b(i->name), "param");
303 static void printExceptionSpecification(
304 std::ostream & o,
305 ProgramOptions const & options,
306 rtl::Reference< TypeManager > const & manager,
307 std::vector< OUString > const & exceptions)
309 o << ((options.shortnames) ? " throw (css::uno::RuntimeException" :
310 " throw (::com::sun::star::uno::RuntimeException");
311 for (const auto& rException : exceptions)
313 o << ", ";
314 printType(o, options, manager, rException, 1);
316 o << ")";
319 static void printSetPropertyMixinBody(
320 std::ostream & o, unoidl::InterfaceTypeEntity::Attribute const & attribute)
322 unoidl::AccumulationBasedServiceEntity::Property::Attributes propFlags
323 = checkAdditionalPropertyFlags(attribute);
325 o << "\n{\n";
327 if (attribute.bound)
328 o << " BoundListeners l;\n";
330 if (propFlags & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_CONSTRAINED) {
331 OString fieldtype = codemaker::convertString(attribute.type);
333 sal_Int32 index = fieldtype.lastIndexOf('<');
334 sal_Int32 nPos=0;
335 bool single = true;
336 bool optional = false;
337 OStringBuffer buffer1(64);
338 OStringBuffer buffer2(64);
341 OString s(fieldtype.getToken(0, '<', nPos));
342 OString t = s.copy(s.lastIndexOf('/')+1);
344 if (t == "Optional") {
345 optional=true;
346 if (single) {
347 single=false;
348 buffer1.append("the_value.IsPresent");
349 buffer2.append("the_value.Value");
350 } else {
351 buffer1.insert(0, t);
352 buffer1.append(".IsPresent");
353 buffer2.insert(0, t);
354 buffer2.append(".Value");
356 } else {
357 if (single) {
358 single=false;
359 if (!optional)
360 buffer1.append("the_value.Value");
362 buffer2.append("the_value.Value");
363 } else {
364 if (!optional) {
365 buffer1.insert(0, t);
366 buffer1.append(".Value");
368 buffer2.insert(0, t);
369 buffer2.append(".Value");
372 } while( nPos <= index );
374 o << " css::uno::Any v;\n";
375 if (optional) {
376 o << " if(" << buffer1.makeStringAndClear() << ")\n {\n v <<= " << buffer2.makeStringAndClear() << ";\n }\n";
377 } else {
378 o << " v <<= " << buffer2.makeStringAndClear() << ";\n\n";
381 o << " prepareSet(\n OUString(\""
382 << attribute.name << "\"),\n css::uno::Any(), v, ";
383 } else {
384 o << " prepareSet(\n OUString(\""
385 << attribute.name << "\"),\n css::uno::Any(), css::uno::Any(), ";
388 if (attribute.bound)
389 o << "&l);\n";
390 else
391 o << "0);\n";
393 o << " {\n osl::MutexGuard g(m_aMutex);\n m_"
394 << attribute.name << " = the_value;\n }\n";
396 if (attribute.bound)
397 o << " l.notify();\n";
399 o << "}\n\n";
402 void printMethods(std::ostream & o,
403 ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
404 OUString const & name, codemaker::GeneratedTypeSet & generated,
405 OString const & delegate, OString const & classname,
406 OString const & indentation, bool defaultvalue,
407 OUString const & propertyhelper)
409 if (generated.contains(u2b(name)) || name == "com.sun.star.uno.XInterface" ||
410 (defaultvalue &&
411 ( name == "com.sun.star.lang.XComponent" ||
412 name == "com.sun.star.lang.XTypeProvider" ||
413 name == "com.sun.star.uno.XWeak" ) ) )
415 return;
418 static OString sd("_"_ostr);
419 bool body = !delegate.isEmpty();
420 bool defaultbody = delegate == sd;
422 if (body && propertyhelper.getLength() > 1) {
423 if (name == "com.sun.star.beans.XPropertySet") {
424 generated.add(u2b(name));
425 generateXPropertySetBodies(
426 o, classname, scopedCppName(u2b(propertyhelper)));
427 return;
428 } else if (name == "com.sun.star.beans.XFastPropertySet") {
429 generated.add(u2b(name));
430 generateXFastPropertySetBodies(
431 o, classname, scopedCppName(u2b(propertyhelper)));
432 return;
433 } else if (name == "com.sun.star.beans.XPropertyAccess") {
434 generated.add(u2b(name));
435 generateXPropertyAccessBodies(
436 o, classname, scopedCppName(u2b(propertyhelper)));
437 return;
441 if (body && options.componenttype == 2) {
442 if (name == "com.sun.star.lang.XServiceName") {
443 o << "// ::com::sun::star::lang::XServiceName:\n"
444 "OUString SAL_CALL " << classname << "getServiceName() "
445 "throw (css::uno::RuntimeException)\n{\n "
446 "return OUString("
447 "sADDIN_SERVICENAME);\n}\n";
448 generated.add(u2b(name));
449 return;
450 } else if (name == "com.sun.star.sheet.XAddIn") {
451 generateXAddInBodies(o, classname);
452 generated.add(u2b(name));
454 // special handling of XLocalizable -> parent of XAddIn
455 if (!generated.contains("com.sun.star.lang.XLocalizable"_ostr)) {
456 generateXLocalizable(o, classname);
457 generated.add("com.sun.star.lang.XLocalizable"_ostr);
459 return;
460 } else if (name == "com.sun.star.lang.XLocalizable") {
461 generateXLocalizable(o, classname);
462 generated.add(u2b(name));
463 return;
464 } else if (name == "com.sun.star.sheet.XCompatibilityNames") {
465 generateXCompatibilityNamesBodies(o, classname);
466 generated.add(u2b(name));
467 return;
471 if (body && options.componenttype == 3) {
472 if (name == "com.sun.star.lang.XInitialization") {
473 generateXInitialization(o, classname);
474 generated.add(u2b(name));
475 return;
476 } else if (name == "com.sun.star.frame.XDispatch") {
477 generateXDispatch(o, classname, options.protocolCmdMap);
478 generated.add(u2b(name));
479 return;
480 } else if (name == "com.sun.star.frame.XDispatchProvider") {
481 generateXDispatchProvider(o, classname, options.protocolCmdMap);
482 generated.add(u2b(name));
483 return;
487 generated.add(u2b(name));
488 rtl::Reference< unoidl::Entity > ent;
489 if (manager->getSort(name, &ent) != codemaker::UnoType::Sort::Interface)
491 throw CannotDumpException(
492 "unexpected entity \"" + name
493 + "\" in call to skeletonmaker::cpp::printMethods");
495 rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
496 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
497 assert(ent2.is());
498 if (options.all || defaultvalue) {
499 for (const auto& rBase : ent2->getDirectMandatoryBases())
501 printMethods(
502 o, options, manager, rBase.name, generated, delegate, classname,
503 indentation, defaultvalue, propertyhelper);
505 if (!(ent2->getDirectAttributes().empty()
506 && ent2->getDirectMethods().empty()))
508 o << indentation << "// ";
509 printType(o, options, manager, name, 0);
510 o << ":\n";
513 for (const auto& rAttr : ent2->getDirectAttributes())
515 o << indentation;
516 if (!body)
517 o << "virtual ";
519 printType(o, options, manager, rAttr.type, 1);
520 o << " SAL_CALL ";
521 if (!classname.isEmpty())
522 o << classname;
524 o << "get" << rAttr.name << "()";
525 printExceptionSpecification(o, options, manager, rAttr.getExceptions);
526 if (body) {
527 if (defaultbody) {
528 if (!propertyhelper.isEmpty()) {
529 o << "\n{\n osl::MutexGuard g(m_aMutex);\n return m_"
530 << rAttr.name << ";\n}\n\n";
531 } else {
532 o << "\n{\n return ";
533 if (options.componenttype == 1) {
534 o << "m_" << rAttr.name;
535 } else {
536 printType(o, options, manager, rAttr.type, 8, true);
538 o << ";\n}\n\n";
540 } else {
541 o << "\n" << indentation << "{\n" << indentation << " return "
542 << delegate << "get" << rAttr.name << "();\n"
543 << indentation << "}\n\n";
545 } else {
546 o << ";\n";
549 if (!rAttr.readOnly) {
550 o << indentation;
551 if (!body)
552 o << "virtual ";
554 o << "void SAL_CALL ";
555 if (!classname.isEmpty())
556 o << classname;
558 o << "set" << rAttr.name << '(';
559 printType(o, options, manager, rAttr.type, 4);
560 o << " the_value)";
561 printExceptionSpecification(o, options, manager, rAttr.setExceptions);
562 if (body) {
563 if (defaultbody) {
564 if (!propertyhelper.isEmpty()) {
565 printSetPropertyMixinBody(o, rAttr);
566 } else {
567 if (options.componenttype == 1) {
568 o << "\n{\n m_" << rAttr.name
569 << " = the_value;\n}\n\n";
570 } else {
571 o << "\n{\n\n}\n\n";
574 } else {
575 o << "\n" << indentation << "{\n" << indentation << " "
576 << delegate << "set" << rAttr.name
577 << "(the_value);\n" << indentation << "}\n\n";
579 } else {
580 o << ";\n";
584 for (const auto& rMethod : ent2->getDirectMethods())
586 o << indentation;
587 if (!body)
588 o << "virtual ";
590 printType(o, options, manager, rMethod.returnType, 1);
591 o << " SAL_CALL ";
592 if (!classname.isEmpty())
593 o << classname;
595 o << rMethod.name << '(';
596 printMethodParameters(o, options, manager, rMethod.parameters, true);
597 o << ')';
598 printExceptionSpecification(o, options, manager, rMethod.exceptions);
599 if (body) {
600 if (defaultbody) {
601 o << "\n{\n";
602 if (rMethod.returnType != "void") {
603 o << " // TODO: Exchange the default return implementation for \""
604 << rMethod.name << "\" !!!\n";
605 o << " // Exchange the default return implementation.\n"
606 " // NOTE: Default initialized polymorphic structs "
607 "can cause problems because of\n // missing default "
608 "initialization of primitive types of some C++ compilers or"
609 "\n // different Any initialization in Java and C++ "
610 "polymorphic structs.\n return ";
611 printType(o, options, manager, rMethod.returnType, 8, true);
612 o << ";";
613 } else {
614 o << " // TODO: Insert your implementation for \""
615 << rMethod.name << "\" here.";
617 o << "\n}\n\n";
618 } else {
619 o << "\n" << indentation << "{\n" << indentation << " ";
620 if (rMethod.returnType != "void")
621 o << "return ";
623 o << delegate << rMethod.name << '(';
624 printMethodParameters(
625 o, options, manager, rMethod.parameters, false);
626 o << ");\n" << indentation << "}\n\n";
628 } else {
629 o << ";\n";
633 if (!body)
634 o << "\n";
637 static void printConstructors(
638 std::ostream & o, ProgramOptions const & options,
639 rtl::Reference< TypeManager > const & manager, OUString const & name)
641 rtl::Reference< unoidl::Entity > ent;
642 if (manager->getSort(name, &ent)
643 != codemaker::UnoType::Sort::SingleInterfaceBasedService)
645 throw CannotDumpException(
646 "unexpected entity \"" + name
647 + "\" in call to skeletonmaker::java::printConstructors");
649 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
650 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(ent.get()));
651 assert(ent2.is());
652 for (const auto& rConstructor : ent2->getConstructors())
654 o << "static ";
655 printType(o, options, manager, ent2->getBase(), 1);
656 o << ' ';
657 if (rConstructor.defaultConstructor) {
658 o << "create";
659 } else {
660 o << codemaker::cpp::translateUnoToCppIdentifier(
661 u2b(rConstructor.name), "method");
663 o << ((options.shortnames) ? "(css::uno::Reference< css" :
664 "(::com::sun::star::uno::Reference< ::com::sun::star")
665 << "::uno::XComponentContext > const & the_context";
666 for (const auto& rParam : rConstructor.parameters)
668 o << ", ";
669 printType(o, options, manager, rParam.type, 4);
670 o << ' '
671 << codemaker::cpp::translateUnoToCppIdentifier(
672 u2b(rParam.name), "param");
674 o << ')';
675 printExceptionSpecification(o, options, manager, rConstructor.exceptions);
676 o << ";\n";
680 static void printServiceMembers(
681 std::ostream & o, ProgramOptions const & options,
682 rtl::Reference< TypeManager > const & manager,
683 OUString const & name,
684 rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity,
685 OString const & delegate)
687 assert(entity.is());
688 for (const auto& rService : entity->getDirectMandatoryBaseServices())
690 o << "\n// exported service " << rService.name << "\n";
691 generateDocumentation(o, options, manager, u2b(rService.name), delegate);
692 o << "\n// end of exported service " << rService.name << "\n";
694 for (const auto& rIface : entity->getDirectMandatoryBaseInterfaces())
696 o << "\n// supported interface " << rIface.name << "\n";
697 generateDocumentation(o, options, manager, u2b(rIface.name), delegate);
699 if (delegate.isEmpty()) {
700 o << "\n// properties of service \""<< name << "\"\n";
701 for (const auto& rProp : entity->getDirectProperties())
703 o << "// private ";
704 printType(o, options, manager, rProp.type, 1);
705 o << " "
706 << codemaker::cpp::translateUnoToCppIdentifier(
707 u2b(rProp.name), "property")
708 << ";\n";
713 static void printMapsToCppType(
714 std::ostream & o, ProgramOptions const & options,
715 rtl::Reference< TypeManager > const & manager,
716 codemaker::UnoType::Sort sort, std::u16string_view nucleus, sal_Int32 rank,
717 std::vector< OUString > const & arguments,
718 rtl::Reference< unoidl::Entity > const & entity, const char * cppTypeSort)
720 o << "maps to C++ ";
721 if (cppTypeSort != nullptr)
722 o << cppTypeSort << ' ';
724 o << "type \"";
725 if (rank == 0 && nucleus == u"com.sun.star.uno.XInterface") {
726 o << "Reference< com::sun::star::uno::XInterface >";
727 } else {
728 printType(
729 o, options, manager, sort, nucleus, rank, arguments, entity, 0,
730 false);
732 o << '"';
735 void generateDocumentation(std::ostream & o,
736 ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
737 OString const & type, OString const & delegate)
739 OUString nucleus;
740 sal_Int32 rank;
741 codemaker::UnoType::Sort sort = manager->decompose(
742 b2u(type), false, &nucleus, &rank, nullptr, nullptr);
744 bool comment = true;
745 if (!delegate.isEmpty()) {
746 if (sort != codemaker::UnoType::Sort::Interface &&
747 sort != codemaker::UnoType::Sort::SingleInterfaceBasedService &&
748 sort != codemaker::UnoType::Sort::AccumulationBasedService )
750 return;
752 comment = false;
755 if (comment) {
756 o << "\n// UNO";
757 if (rank != 0) {
758 o << " sequence type";
759 } else if (sort <= codemaker::UnoType::Sort::Any) {
760 o << " simple type";
761 } else {
762 switch (sort) {
763 case codemaker::UnoType::Sort::Interface:
764 o << " interface type";
765 break;
767 case codemaker::UnoType::Sort::Module:
768 o << "IDL module";
769 break;
771 case codemaker::UnoType::Sort::PlainStruct:
772 o << " simple struct type";
773 break;
775 case codemaker::UnoType::Sort::PolymorphicStructTemplate:
776 o << " polymorphic struct type template";
777 break;
779 case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
780 o << " instantiated polymorphic struct type";
781 break;
783 case codemaker::UnoType::Sort::Enum:
784 o << " enum type";
785 break;
787 case codemaker::UnoType::Sort::Exception:
788 o << " exception type";
789 break;
791 case codemaker::UnoType::Sort::Typedef:
792 o << "IDL typedef";
793 break;
795 case codemaker::UnoType::Sort::SingleInterfaceBasedService:
796 o << " single-inheritance--based service";
797 break;
799 case codemaker::UnoType::Sort::AccumulationBasedService:
800 o << "IDL accumulation-based service";
801 break;
803 case codemaker::UnoType::Sort::InterfaceBasedSingleton:
804 o << " inheritance-based singleton";
805 break;
807 case codemaker::UnoType::Sort::ServiceBasedSingleton:
808 o << "IDL service-based singleton";
809 break;
811 case codemaker::UnoType::Sort::ConstantGroup:
812 o << "IDL constant group";
813 break;
815 default:
816 OSL_ASSERT(false);
817 break;
820 o << " \"" << type << "\" ";
822 std::vector< OUString > arguments;
823 rtl::Reference< unoidl::Entity > entity;
824 sort = manager->decompose(
825 b2u(type), true, &nucleus, &rank, &arguments, &entity);
826 if (rank != 0) {
827 if (comment) {
828 printMapsToCppType(
829 o, options, manager, sort, nucleus, rank, arguments, entity,
830 "array");
831 o << '\n';
833 } else if (sort <= codemaker::UnoType::Sort::Any) {
834 if (comment) {
835 printMapsToCppType(
836 o, options, manager, sort, nucleus, rank, arguments, entity, nullptr);
837 o << '\n';
839 } else {
840 switch (sort) {
841 case codemaker::UnoType::Sort::Interface:
842 if (comment)
843 printMapsToCppType(
844 o, options, manager, sort, nucleus, rank, arguments, entity,
845 "interface");
846 if (nucleus == "com.sun.star.uno.XInterface") {
847 if (comment)
848 o << '\n';
849 } else {
850 if (comment)
851 o << "; " << (options.all ? "all" : "direct") << " methods:\n";
853 codemaker::GeneratedTypeSet generated;
854 printMethods(
855 o, options, manager, nucleus, generated, delegate,
856 options.implname, ""_ostr);
858 break;
860 case codemaker::UnoType::Sort::Module:
861 printMapsToCppType(
862 o, options, manager, sort, nucleus, rank, arguments, entity,
863 "namespace");
864 o << '\n';
865 break;
867 case codemaker::UnoType::Sort::PlainStruct:
868 printMapsToCppType(
869 o, options, manager, sort, nucleus, rank, arguments, entity,
870 "class");
871 o << "; full constructor:\n";
872 printConstructor(
873 o, options, manager, codemaker::UnoType::Sort::PlainStruct,
874 entity, nucleus, arguments);
875 break;
877 case codemaker::UnoType::Sort::PolymorphicStructTemplate:
878 printMapsToCppType(
879 o, options, manager, sort, nucleus, rank, arguments, entity,
880 "class template");
881 o << "; full constructor:\n";
882 printConstructor(
883 o, options, manager,
884 codemaker::UnoType::Sort::PolymorphicStructTemplate,
885 entity, nucleus, arguments);
886 break;
888 case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
889 printMapsToCppType(
890 o, options, manager, sort, nucleus, rank, arguments, entity,
891 "class template instantiation");
892 o << "; full constructor:\n";
893 printConstructor(
894 o, options, manager,
895 codemaker::UnoType::Sort::InstantiatedPolymorphicStruct,
896 entity, nucleus, arguments);
897 break;
899 case codemaker::UnoType::Sort::Enum:
900 printMapsToCppType(
901 o, options, manager, sort, nucleus, rank, arguments, entity,
902 "enum");
903 o << '\n';
904 break;
906 case codemaker::UnoType::Sort::ConstantGroup:
907 printMapsToCppType(
908 o, options, manager, sort, nucleus, rank, arguments, entity,
909 "namespace");
910 o << '\n';
911 break;
913 case codemaker::UnoType::Sort::Exception:
914 printMapsToCppType(
915 o, options, manager, sort, nucleus, rank, arguments, entity,
916 "exception class");
917 o << "; full constructor:\n";
918 printConstructor(
919 o, options, manager, codemaker::UnoType::Sort::Exception,
920 entity, nucleus, arguments);
921 break;
923 case codemaker::UnoType::Sort::SingleInterfaceBasedService:
924 if (comment) {
925 printMapsToCppType(
926 o, options, manager, sort, nucleus, rank, arguments, entity,
927 "class");
928 o << "; construction methods:\n";
929 printConstructors(o, options, manager, nucleus);
931 generateDocumentation(
932 o, options, manager,
933 u2b(dynamic_cast<unoidl::SingleInterfaceBasedServiceEntity&>(*entity)
934 .getBase()),
935 delegate);
936 break;
938 case codemaker::UnoType::Sort::AccumulationBasedService:
939 if (comment)
940 o << ("does not map to C++\n"
941 "// the service members are generated instead\n");
942 printServiceMembers(
943 o, options, manager, nucleus,
944 dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
945 entity.get()),
946 delegate);
947 break;
949 case codemaker::UnoType::Sort::InterfaceBasedSingleton:
950 printMapsToCppType(
951 o, options, manager, sort, nucleus, rank, arguments, entity,
952 "class");
953 o << "; get method:\nstatic ";
954 printType(
955 o, options, manager,
956 dynamic_cast< unoidl::InterfaceBasedSingletonEntity & >(
957 *entity).getBase(),
959 o << " get(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);\n";
960 break;
962 case codemaker::UnoType::Sort::ServiceBasedSingleton:
963 o << "does not map to C++\n";
964 break;
966 default:
967 OSL_ASSERT(false);
968 break;
976 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */