Bump for 3.6-28
[LibreOffice.git] / unodevtools / source / skeletonmaker / cpptypemaker.cxx
blobef2907010f4e8b26b750afa33b0297ee7d8631d5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "codemaker/commoncpp.hxx"
31 #include "ostringostreaminserter.hxx"
32 #include "skeletoncommon.hxx"
33 #include "skeletoncpp.hxx"
35 using namespace ::rtl;
36 using namespace ::codemaker::cpp;
38 namespace skeletonmaker { namespace cpp {
40 void printType(std::ostream & o,
41 ProgramOptions const & options, TypeManager const & manager,
42 codemaker::UnoType::Sort sort, RTTypeClass typeClass,
43 OString const & name, sal_Int32 rank,
44 std::vector< OString > const & arguments, short referenceType,
45 bool defaultvalue)
47 if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) {
48 switch (sort)
50 case codemaker::UnoType::SORT_BOOLEAN:
51 o << "sal_False";
52 return;
53 case codemaker::UnoType::SORT_CHAR:
54 case codemaker::UnoType::SORT_BYTE:
55 case codemaker::UnoType::SORT_SHORT:
56 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
57 case codemaker::UnoType::SORT_LONG:
58 case codemaker::UnoType::SORT_UNSIGNED_LONG:
59 case codemaker::UnoType::SORT_HYPER:
60 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
61 case codemaker::UnoType::SORT_FLOAT:
62 case codemaker::UnoType::SORT_DOUBLE:
63 o << "0";
64 return;
65 case codemaker::UnoType::SORT_VOID:
66 case codemaker::UnoType::SORT_STRING:
67 case codemaker::UnoType::SORT_TYPE:
68 case codemaker::UnoType::SORT_ANY:
69 case codemaker::UnoType::SORT_COMPLEX:
70 break;
74 if (defaultvalue && referenceType == 16) {
75 if (typeClass == RT_TYPE_ENUM) {
76 typereg::Reader reader(manager.getTypeReader(name));
77 o << name.copy(name.lastIndexOf('/'))
78 << "_"
79 << codemaker::convertString(reader.getFieldName(0));
81 return;
83 bool bReference = false;
84 if (((sort > codemaker::UnoType::SORT_CHAR ||
85 rank > 0) && referenceType != 8 &&
86 !(typeClass == RT_TYPE_ENUM && referenceType == 4 && rank == 0)) ||
87 (sort <= codemaker::UnoType::SORT_CHAR && referenceType == 2))
89 bReference = true;
92 if (bReference && referenceType == 4)
93 o << "const ";
95 for (sal_Int32 i = 0; i < rank; ++i) {
96 o << ((options.shortnames) ? "css::uno::Sequence< " :
97 "::com::sun::star::uno::Sequence< ");
99 if (typeClass == RT_TYPE_INTERFACE && referenceType > 0) {
100 o << ((options.shortnames) ? "css::uno::Reference< " :
101 "::com::sun::star::uno::Reference< ");
104 o << scopedCppName(codemaker::cpp::translateUnoToCppType(
105 sort, typeClass, name, false),
106 false, options.shortnames && referenceType > 0);
108 if (typeClass == RT_TYPE_INTERFACE && referenceType > 0)
109 o << " >";
111 if (!arguments.empty()) {
112 o << "< ";
113 for (std::vector< OString >::const_iterator i(arguments.begin());
114 i != arguments.end(); ++i)
116 if (i != arguments.begin())
117 o << ", ";
119 printType(o, options, manager, *i, 1, false);
121 o << " >";
124 for (sal_Int32 i = 0; i < rank; ++i)
125 o << " >";
127 if (bReference && referenceType > 1)
128 o << " &";
130 if (referenceType == 8 && (sort > codemaker::UnoType::SORT_CHAR || rank > 0))
131 o << "()";
134 void printType(std::ostream & o,
135 ProgramOptions const & options, TypeManager const & manager,
136 OString const & type, short referenceType, bool defaultvalue)
138 RTTypeClass typeClass;
139 OString name;
140 sal_Int32 rank;
141 std::vector< OString > arguments;
142 codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve(
143 manager, type, true, true, true, &typeClass, &name, &rank, &arguments);
144 printType(o,
145 options, manager, sort, typeClass, name, rank, arguments,
146 referenceType, defaultvalue);
149 bool printConstructorParameters(std::ostream & o,
150 ProgramOptions const & options, TypeManager const & manager,
151 typereg::Reader const & reader, typereg::Reader const & outerReader,
152 std::vector< OString > const & arguments)
154 bool previous = false;
155 if (reader.getSuperTypeCount() != 0) {
156 OString super(
157 codemaker::convertString(reader.getSuperTypeName(0)));
158 typereg::Reader superReader(manager.getTypeReader(super));
159 if (!superReader.isValid())
160 throw CannotDumpException("Bad type library entity " + super);
162 previous = printConstructorParameters(o,
163 options, manager, superReader, outerReader, arguments);
165 for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
166 if (previous)
167 o << ", ";
168 else
169 previous = true;
171 if ((reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) == 0) {
172 printType(o, options, manager,
173 codemaker::convertString(reader.getFieldTypeName(i)), 4);
174 } else if (arguments.empty()) {
175 // ToDo !
176 // o << "com::sun::star::uno::Any";
177 } else {
178 sal_uInt16 tparam = 0;
179 while (outerReader.getReferenceTypeName(tparam)
180 != reader.getFieldTypeName(i))
182 ++tparam;
183 OSL_ASSERT(tparam < outerReader.getReferenceCount());
185 // assume std::vector< OString >::size_type is at least as
186 // large as sal_uInt16:
187 printType(o, options, manager, arguments[tparam], 4);
189 o << ' '
190 << (codemaker::cpp::translateUnoToCppIdentifier(
191 codemaker::convertString(reader.getFieldName(i)),
192 "param").
193 getStr());
195 return previous;
198 void printConstructor(std::ostream & o,
199 ProgramOptions const & options, TypeManager const & manager,
200 typereg::Reader const & reader,
201 std::vector< OString > const & arguments)
203 OString type(codemaker::convertString(reader.getTypeName()));
204 o << "public ";
205 o << type.copy(type.lastIndexOf('/') + 1) << '(';
206 printConstructorParameters(o, options, manager, reader, reader,
207 arguments);
208 o << ");\n";
211 void printMethodParameters(std::ostream & o,
212 ProgramOptions const & options, TypeManager const & manager,
213 typereg::Reader const & reader, sal_uInt16 method, bool previous,
214 bool withtype)
216 short referenceType = 4;
217 for (sal_uInt16 i = 0; i < reader.getMethodParameterCount(method); ++i) {
218 if (previous)
219 o << ", ";
221 previous = true;
223 if (reader.getMethodParameterFlags(method, i) == RT_PARAM_OUT
224 || reader.getMethodParameterFlags(method, i) == RT_PARAM_INOUT)
226 referenceType = 2;
227 } else {
228 referenceType = 4;
231 if (withtype) {
232 printType(o, options, manager,
233 codemaker::convertString(
234 reader.getMethodParameterTypeName(method, i)),
235 referenceType);
236 o << ' ';
239 o << (codemaker::cpp::translateUnoToCppIdentifier(
240 codemaker::convertString(
241 reader.getMethodParameterName(method, i)),
242 "param").
243 getStr());
247 void printExceptionSpecification(std::ostream & o,
248 ProgramOptions const & options, TypeManager const & manager,
249 typereg::Reader const & reader, sal_uInt16 method)
251 o << ((options.shortnames) ? " throw (css::uno::RuntimeException" :
252 " throw (::com::sun::star::uno::RuntimeException");
253 if (reader.getMethodExceptionCount(method) > 0) {
254 for (sal_uInt16 i = 0; i < reader.getMethodExceptionCount(method); ++i) {
255 o << ", ";
256 printType(o, options, manager,
257 codemaker::convertString(
258 reader.getMethodExceptionTypeName(method, i)), 1);
261 o << ")";
264 void printSetPropertyMixinBody(std::ostream & o,
265 typereg::Reader const & reader,
266 sal_uInt16 field,
267 sal_uInt16 method)
269 RTFieldAccess propFlags = checkAdditionalPropertyFlags(reader, field, method);
270 OString fieldname = codemaker::convertString(reader.getFieldName(field));
271 bool bound = (reader.getFieldFlags(field) & RT_ACCESS_BOUND ? true : false);
273 o << "\n{\n";
275 if (bound)
276 o << " BoundListeners l;\n";
278 if (propFlags & RT_ACCESS_CONSTRAINED) {
279 OString fieldtype = codemaker::convertString(
280 reader.getFieldTypeName(field));
282 sal_Int32 index = fieldtype.lastIndexOf('<');
283 sal_Int32 nPos=0;
284 bool single = true;
285 bool optional = false;
286 OStringBuffer buffer1(64);
287 OStringBuffer buffer2(64);
290 OString s(fieldtype.getToken(0, '<', nPos));
291 OString t = s.copy(s.lastIndexOf('/')+1);
293 if (t.equals("Optional")) {
294 optional=true;
295 if (single) {
296 single=false;
297 buffer1.append("the_value.IsPresent");
298 buffer2.append("the_value.Value");
299 } else {
300 buffer1.insert(0, t);
301 buffer1.append(".IsPresent");
302 buffer2.insert(0, t);
303 buffer2.append(".Value");
305 } else {
306 if (single) {
307 single=false;
308 if (!optional)
309 buffer1.append("the_value.Value");
311 buffer2.append("the_value.Value");
312 } else {
313 if (!optional) {
314 buffer1.insert(0, t);
315 buffer1.append(".Value");
317 buffer2.insert(0, t);
318 buffer2.append(".Value");
321 } while( nPos <= index );
323 o << " css::uno::Any v;\n";
324 if (optional) {
325 o << " if(" << buffer1.makeStringAndClear() << ")\n {\n"
326 << " v <<= " << buffer2.makeStringAndClear() << ";\n }\n";
327 } else {
328 o << " v <<= " << buffer2.makeStringAndClear() << ";\n\n";
331 o << " prepareSet(\n rtl::OUString(\""
332 << fieldname << "\"),\n css::uno::Any(), v, ";
333 } else {
334 o << " prepareSet(\n rtl::OUString(\""
335 << fieldname << "\"),\n css::uno::Any(), css::uno::Any(), ";
338 if (bound)
339 o << "&l);\n";
340 else
341 o << "0);\n";
343 o << " {\n osl::MutexGuard g(m_aMutex);\n m_"
344 << fieldname << " = the_value;\n }\n";
346 if (bound)
347 o << " l.notify();\n";
349 o << "}\n\n";
352 void generateXPropertySetBodies(std::ostream& o,
353 const OString & classname,
354 const OString & interfaceName);
355 void generateXFastPropertySetBodies(std::ostream& o,
356 const OString & classname,
357 const OString & interfaceName);
358 void generateXPropertyAccessBodies(std::ostream& o,
359 const OString & classname,
360 const OString & interfaceName);
362 void generateXAddInBodies(std::ostream& o, const OString & classname);
364 void generateXLocalizable(std::ostream& o, const OString & classname);
366 void generateXCompatibilityNamesBodies(std::ostream& o, const OString & classname);
368 void generateXInitialization(std::ostream& o, const OString & classname);
370 void generateXDispatch(std::ostream& o,
371 const OString & classname,
372 const ProtocolCmdMap & protocolCmdMap);
374 void generateXDispatchProvider(std::ostream& o,
375 const OString & classname,
376 const ProtocolCmdMap & protocolCmdMap);
379 void printMethods(std::ostream & o,
380 ProgramOptions const & options, TypeManager const & manager,
381 typereg::Reader const & reader, codemaker::GeneratedTypeSet & generated,
382 OString const & delegate, OString const & classname,
383 OString const & indentation, bool defaultvalue,
384 OString const & propertyhelper)
386 OString type(codemaker::convertString(reader.getTypeName()));
387 if (generated.contains(type) || type.equals("com/sun/star/uno/XInterface") ||
388 (defaultvalue &&
389 ( type.equals("com/sun/star/lang/XComponent") ||
390 type.equals("com/sun/star/lang/XTypeProvider") ||
391 type.equals("com/sun/star/uno/XWeak")) ) )
393 return;
396 static OString sd(RTL_CONSTASCII_STRINGPARAM("_"));
397 bool body = !delegate.isEmpty();
398 bool defaultbody = ((delegate.equals(sd)) ? true : false);
400 if (body && propertyhelper.getLength() > 1) {
401 if ( type.equals("com/sun/star/beans/XPropertySet")) {
402 generated.add(type);
403 generateXPropertySetBodies(
404 o, classname, scopedCppName(propertyhelper, false, true));
405 return;
406 } else if ( type.equals("com/sun/star/beans/XFastPropertySet")) {
407 generated.add(type);
408 generateXFastPropertySetBodies(
409 o, classname, scopedCppName(propertyhelper, false, true));
410 return;
411 } else if ( type.equals("com/sun/star/beans/XPropertyAccess")) {
412 generated.add(type);
413 generateXPropertyAccessBodies(
414 o, classname, scopedCppName(propertyhelper, false, true));
415 return;
419 if (body && options.componenttype == 2) {
420 if (type.equals("com/sun/star/lang/XServiceName")) {
421 o << "// ::com::sun::star::lang::XServiceName:\n"
422 "::rtl::OUString SAL_CALL " << classname << "getServiceName() "
423 "throw (css::uno::RuntimeException)\n{\n "
424 "return ::rtl::OUString("
425 "sADDIN_SERVICENAME);\n}\n";
426 generated.add(type);
427 return;
428 } else if (type.equals("com/sun/star/sheet/XAddIn")) {
429 generateXAddInBodies(o, classname);
430 generated.add(type);
432 // special handling of XLocalizable -> parent of XAddIn
433 if (!generated.contains("com/sun/star/lang/XLocalizable")) {
434 generateXLocalizable(o, classname);
435 generated.add("com/sun/star/lang/XLocalizable");
437 return;
438 } else if (type.equals("com/sun/star/lang/XLocalizable")) {
439 generateXLocalizable(o, classname);
440 generated.add(type);
441 return;
442 } else if (type.equals("com/sun/star/sheet/XCompatibilityNames")) {
443 generateXCompatibilityNamesBodies(o, classname);
444 generated.add(type);
445 return;
449 if (body && options.componenttype == 3) {
450 if (type.equals("com/sun/star/lang/XInitialization")) {
451 generateXInitialization(o, classname);
452 generated.add(type);
453 return;
454 } else if (type.equals("com/sun/star/frame/XDispatch")) {
455 generateXDispatch(o, classname, options.protocolCmdMap);
456 generated.add(type);
457 return;
458 } else if (type.equals("com/sun/star/frame/XDispatchProvider")) {
459 generateXDispatchProvider(o, classname, options.protocolCmdMap);
460 generated.add(type);
461 return;
465 generated.add(type);
466 if (options.all || defaultvalue) {
467 for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) {
468 typereg::Reader super(
469 manager.getTypeReader(
470 codemaker::convertString(
471 reader.getSuperTypeName(i))));
472 if (!super.isValid()) {
473 throw CannotDumpException(
474 "Bad type library entity "
475 + codemaker::convertString(
476 reader.getSuperTypeName(i)));
479 OString stype(codemaker::convertString(super.getTypeName()));
480 printMethods(o, options, manager, super, generated, delegate,
481 classname, indentation, defaultvalue, propertyhelper);
484 if (reader.getFieldCount() > 0 || reader.getMethodCount() > 0) {
485 o << indentation << "// ";
486 printType(o, options, manager, type, 0);
487 o << ":\n";
490 sal_uInt16 method = 0;
491 for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
492 o << indentation;
493 if (!body)
494 o << "virtual ";
496 printType(o, options, manager,
497 codemaker::convertString(reader.getFieldTypeName(i)), 1);
498 o << " SAL_CALL ";
499 if (!classname.isEmpty())
500 o << classname;
502 o << "get"
503 << codemaker::convertString(reader.getFieldName(i)).getStr()
504 << "()";
505 if (method < reader.getMethodCount()
506 && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_GET
507 && reader.getMethodName(method) == reader.getFieldName(i))
509 printExceptionSpecification(o, options, manager, reader, method++);
510 } else {
511 o << ((options.shortnames) ? " throw (css::uno::RuntimeException)" :
512 " throw (::com::sun::star::uno::RuntimeException)");
514 if (body) {
515 if (defaultbody) {
516 if (!propertyhelper.isEmpty()) {
517 o << "\n{\n osl::MutexGuard g(m_aMutex);\n return m_"
518 << codemaker::convertString(reader.getFieldName(i)).getStr()
519 << ";\n}\n\n";
520 } else {
521 o << "\n{\n return ";
522 if (options.componenttype == 1) {
523 o << "m_"
524 << codemaker::convertString(
525 reader.getFieldName(i)).getStr();
526 } else {
527 printType(o, options, manager,
528 codemaker::convertString(
529 reader.getFieldTypeName(i)),
530 8, true);
532 o << ";\n}\n\n";
534 } else {
535 o << "\n" << indentation << "{\n" << indentation << " return "
536 << delegate.getStr() << "get"
537 << codemaker::convertString(reader.getFieldName(i)).getStr()
538 << "();\n" << indentation << "}\n\n";
540 } else {
541 o << ";\n";
544 if ((reader.getFieldFlags(i) & RT_ACCESS_READONLY) == 0) {
545 o << indentation;
546 if (!body)
547 o << "virtual ";
549 o << "void SAL_CALL ";
550 if (!classname.isEmpty())
551 o << classname;
553 o << "set"
554 << (codemaker::convertString(reader.getFieldName(i)).getStr())
555 << '(';
556 printType(o, options, manager,
557 codemaker::convertString(reader.getFieldTypeName(i)), 4);
558 o << " the_value)";
559 if (method < reader.getMethodCount()
560 && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_SET
561 && reader.getMethodName(method) == reader.getFieldName(i))
563 printExceptionSpecification(o, options, manager, reader, method++);
564 } else {
565 o << ((options.shortnames) ? " throw (css::uno::RuntimeException)" :
566 " throw (::com::sun::star::uno::RuntimeException)");
568 if (body) {
569 if (defaultbody) {
570 if (!propertyhelper.isEmpty()) {
571 printSetPropertyMixinBody(o, reader, i, method);
572 } else {
573 if (options.componenttype == 1) {
574 o << "\n{\n m_"
575 << codemaker::convertString(
576 reader.getFieldName(i)).getStr()
577 << " = the_value;\n}\n\n";
578 } else {
579 o << "\n{\n\n}\n\n";
582 } else {
583 o << "\n" << indentation << "{\n" << indentation << " "
584 << delegate.getStr() << "set"
585 << codemaker::convertString(reader.getFieldName(i)).getStr()
586 << "(the_value);\n" << indentation << "}\n\n";
588 } else {
589 o << ";\n";
593 for (; method < reader.getMethodCount(); ++method) {
594 o << indentation;
595 if (!body)
596 o << "virtual ";
598 printType(o, options, manager,
599 codemaker::convertString(
600 reader.getMethodReturnTypeName(method)), 1);
601 o << " SAL_CALL ";
602 if (!classname.isEmpty())
603 o << classname;
605 const OString methodName(codemaker::convertString(reader.getMethodName(method)));
607 o << methodName << '(';
608 printMethodParameters(o, options, manager, reader, method, false, true);
609 o << ')';
610 printExceptionSpecification(o, options, manager, reader, method);
611 if (body) {
612 static OUString s("void");
613 if (defaultbody) {
614 o << "\n{\n";
615 if (!reader.getMethodReturnTypeName(method).equals(s)) {
616 o << " // TODO: Exchange the default return implementation for \""
617 << methodName << "\" !!!\n";
618 o << " // Exchange the default return implementation.\n"
619 " // NOTE: Default initialized polymorphic structs "
620 "can cause problems because of\n // missing default "
621 "initialization of primitive types of some C++ compilers or"
622 "\n // different Any initialization in Java and C++ "
623 "polymorphic structs.\n return ";
624 printType(o, options, manager,
625 codemaker::convertString(
626 reader.getMethodReturnTypeName(method)), 8, true);
627 o << ";";
628 } else {
629 o << " // TODO: Insert your implementation for \""
630 << methodName << "\" here.";
632 o << "\n}\n\n";
633 } else {
634 o << "\n" << indentation << "{\n" << indentation << " ";
635 if (!reader.getMethodReturnTypeName(method).equals(s))
636 o << "return ";
638 o << delegate.getStr()
639 << (codemaker::convertString(
640 reader.getMethodName(method)).getStr())
641 << '(';
642 printMethodParameters(o, options, manager, reader, method,
643 false, false);
644 o << ");\n" << indentation << "}\n\n";
646 } else {
647 o << ";\n";
651 if (method > 0 && !body)
652 o << "\n";
655 void printConstructionMethods(std::ostream & o,
656 ProgramOptions const & options, TypeManager const & manager,
657 typereg::Reader const & reader)
659 for (sal_uInt16 i = 0; i < reader.getMethodCount(); ++i) {
660 o << "static ";
661 printType(o,
662 options, manager,
663 codemaker::convertString(reader.getSuperTypeName(0)), 1);
664 o << ' ';
665 if (reader.getMethodName(i).isEmpty()) {
666 o << "create";
667 } else {
668 o << (codemaker::cpp::translateUnoToCppIdentifier(
669 codemaker::convertString(reader.getMethodName(i)),
670 "method").
671 getStr());
673 o << ((options.shortnames) ? "(css::uno::Reference< css" :
674 "(::com::sun::star::uno::Reference< ::com::sun::star")
675 << "::uno::XComponentContext > const & the_context";
676 printMethodParameters(o, options, manager, reader, i,
677 true, true);
678 o << ')';
679 printExceptionSpecification(o, options, manager, reader, i);
680 o << ";\n";
684 void printServiceMembers(std::ostream & o,
685 ProgramOptions const & options, TypeManager const & manager,
686 typereg::Reader const & reader, OString const & type,
687 OString const & delegate)
689 for (sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i) {
690 OString referenceType(
691 codemaker::convertString(
692 reader.getReferenceTypeName(i)).replace('/', '.'));
694 if ( reader.getReferenceSort(i) == RT_REF_SUPPORTS ) {
695 o << "\n// supported interface " << referenceType.getStr() << "\n";
696 generateDocumentation(o, options, manager, referenceType, delegate);
697 } else if ( reader.getReferenceSort(i) == RT_REF_EXPORTS ) {
698 o << "\n// exported service " << referenceType.getStr() << "\n";
699 generateDocumentation(o, options, manager, referenceType, delegate);
700 o << "\n// end of exported service " << referenceType.getStr() << "\n";
704 if (delegate.isEmpty()) {
705 o << "\n// properties of service \""<< type.getStr() << "\"\n";
706 for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
707 OString fieldName(
708 codemaker::convertString(reader.getFieldName(i)));
709 OString fieldType(
710 codemaker::convertString(reader.getFieldTypeName(i)));
712 o << "// private ";
713 printType(o, options, manager, fieldType, 1);
714 o << " "
715 << codemaker::cpp::translateUnoToCppIdentifier(
716 fieldName, "property").getStr()
717 << ";\n";
722 void printMapsToCppType(std::ostream & o,
723 ProgramOptions const & options, TypeManager const & manager,
724 codemaker::UnoType::Sort sort, RTTypeClass typeClass,
725 OString const & name, sal_Int32 rank,
726 std::vector< OString > const & arguments, const char * cppTypeSort)
728 o << "maps to C++ ";
729 if (cppTypeSort != 0)
730 o << cppTypeSort << ' ';
732 o << "type \"";
733 if (rank == 0 && name == "com/sun/star/uno/XInterface") {
734 o << "Reference< com::sun::star::uno::XInterface >";
735 } else {
736 printType(o, options, manager, sort, typeClass, name, rank, arguments, 0);
738 o << '"';
741 void generateDocumentation(std::ostream & o,
742 ProgramOptions const & options, TypeManager const & manager,
743 OString const & type, OString const & delegate)
745 if (type.indexOf('/') >= 0)
746 throw CannotDumpException("Illegal type name " + type);
748 OString binType(type.replace('.', '/'));
749 RTTypeClass typeClass;
750 OString name;
751 sal_Int32 rank;
752 std::vector< OString > arguments;
753 codemaker::UnoType::Sort sort = decomposeResolveAndCheck(
754 manager, binType, false, true, true, &typeClass, &name, &rank,
755 &arguments);
757 bool comment=true;
758 if (!delegate.isEmpty()) {
759 if (typeClass != RT_TYPE_INTERFACE &&
760 typeClass != RT_TYPE_SERVICE )
762 return;
764 comment=false;
767 if (comment) {
768 o << "\n// UNO";
769 if (rank > 0) {
770 o << " sequence type";
771 } else if (sort != codemaker::UnoType::SORT_COMPLEX) {
772 o << " simple type";
773 } else {
774 typereg::Reader reader(manager.getTypeReader(name));
775 if (!reader.isValid())
776 throw CannotDumpException("Bad type library entity " + name);
778 switch (typeClass)
780 case RT_TYPE_INTERFACE:
781 o << " interface type";
782 break;
784 case RT_TYPE_MODULE:
785 o << "IDL module";
786 break;
788 case RT_TYPE_STRUCT:
789 if (reader.getReferenceCount() == 0)
790 o << " simple struct type";
791 else if (arguments.empty())
792 o << " polymorphic struct type template";
793 else
794 o << " instantiated polymorphic struct type";
795 break;
797 case RT_TYPE_ENUM:
798 o << " enum type";
799 break;
801 case RT_TYPE_EXCEPTION:
802 o << " exception type";
803 break;
805 case RT_TYPE_TYPEDEF:
806 o << "IDL typedef";
807 break;
809 case RT_TYPE_SERVICE:
810 if (reader.getSuperTypeCount() > 0)
811 o << " single-inheritance--based service";
812 else
813 o << "IDL accumulation-based service";
814 break;
816 case RT_TYPE_SINGLETON:
817 if ((manager.getTypeReader(
818 codemaker::convertString(
819 reader.getSuperTypeName(0))).getTypeClass())
820 == RT_TYPE_INTERFACE)
821 o << " inheritance-based singleton";
822 else
823 o << "IDL service-based singleton";
824 break;
826 case RT_TYPE_CONSTANTS:
827 o << "IDL constant group";
828 break;
830 default:
831 OSL_ASSERT(false);
832 break;
835 o << " \"" << type.getStr() << "\" ";
837 sort = codemaker::decomposeAndResolve(
838 manager, binType, true, true, true, &typeClass, &name, &rank,
839 &arguments);
840 if (rank > 0) {
841 if (comment) {
842 printMapsToCppType(o,
843 options, manager, sort, typeClass, name, rank, arguments, "array");
844 o << '\n';
846 } else if (sort != codemaker::UnoType::SORT_COMPLEX) {
847 if (comment) {
848 printMapsToCppType(o,
849 options, manager, sort, typeClass, name, rank, arguments, 0);
850 o << '\n';
852 } else {
853 typereg::Reader reader(manager.getTypeReader(name));
854 if (!reader.isValid())
855 throw CannotDumpException("Bad type library entity " + name);
857 switch (typeClass)
859 case RT_TYPE_INTERFACE:
860 if (comment)
861 printMapsToCppType(o,
862 options, manager, sort, typeClass, name, rank, arguments,
863 "interface");
864 if (name == "com/sun/star/uno/XInterface") {
865 if (comment)
866 o << '\n';
867 } else {
868 if (comment)
869 o << "; " << (options.all ? "all" : "direct") << " methods:\n";
871 codemaker::GeneratedTypeSet generated;
872 printMethods(o, options, manager, reader, generated,
873 delegate, options.implname, "");
875 break;
877 case RT_TYPE_MODULE:
878 printMapsToCppType(o,
879 options, manager, sort, typeClass, name, rank, arguments,
880 "namespace");
881 o << '\n';
882 break;
884 case RT_TYPE_STRUCT:
885 if (reader.getReferenceCount() == 0) {
886 printMapsToCppType(o,
887 options, manager, sort, typeClass, name, rank, arguments,
888 "class");
889 } else if (arguments.empty()) {
890 printMapsToCppType(o,
891 options, manager, sort, typeClass, name, rank, arguments,
892 options.java5 ? "generic class" : "class");
893 } else {
894 printMapsToCppType(o,
895 options, manager, sort, typeClass, name, rank, arguments,
896 options.java5 ? "generic class instantiation" : "class");
898 o << "; full constructor:\n";
899 printConstructor(o, options, manager, reader, arguments);
900 break;
902 case RT_TYPE_ENUM:
903 printMapsToCppType(o,
904 options, manager, sort, typeClass, name, rank, arguments,
905 "enum");
906 o << '\n';
907 break;
909 case RT_TYPE_CONSTANTS:
910 printMapsToCppType(o,
911 options, manager, sort, typeClass, name, rank, arguments,
912 "namespace");
913 o << '\n';
914 break;
916 case RT_TYPE_EXCEPTION:
917 printMapsToCppType(o,
918 options, manager, sort, typeClass, name, rank, arguments,
919 "exception class");
920 o << "; full constructor:\n";
921 printConstructor(o, options, manager, reader, arguments);
922 break;
924 case RT_TYPE_SERVICE:
925 if (reader.getSuperTypeCount() > 0) {
926 if (comment) {
927 printMapsToCppType(o, options, manager, sort, typeClass,
928 name, rank, arguments, "class");
929 o << "; construction methods:\n";
930 printConstructionMethods(o, options, manager, reader);
933 OString super(
934 codemaker::convertString(
935 reader.getSuperTypeName(0)).replace('/', '.'));
936 generateDocumentation(o, options, manager, super, delegate);
937 } else {
938 if (comment)
939 o << ("does not map to C++\n"
940 "// the service members are generated instead\n");
941 printServiceMembers(o, options, manager, reader, type, delegate);
943 break;
945 case RT_TYPE_SINGLETON:
946 if (reader.getSuperTypeCount() > 0 &&
947 ((manager.getTypeReader(
948 codemaker::convertString(
949 reader.getSuperTypeName(0))).
950 getTypeClass()) == RT_TYPE_INTERFACE) )
952 printMapsToCppType(o, options, manager, sort, typeClass,
953 name, rank, arguments,
954 "class");
955 o << "; get method:\nstatic ";
956 printType(o, options, manager,
957 codemaker::convertString(reader.getSuperTypeName(0)), 1);
958 o << " get(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);\n";
959 } else {
960 o << "does not map to C++\n";
962 break;
964 default:
965 OSL_ASSERT(false);
966 break;
974 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */