merge the formfield patch from ooo-build
[ooovba.git] / unodevtools / source / skeletonmaker / cpptypemaker.cxx
blob78179b162f16362acc27820b410f233bb4926812
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cpptypemaker.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "codemaker/commoncpp.hxx"
33 #include "skeletoncommon.hxx"
34 #include "skeletoncpp.hxx"
36 using namespace ::rtl;
37 using namespace ::codemaker::cpp;
39 namespace skeletonmaker { namespace cpp {
41 void printType(std::ostream & o,
42 ProgramOptions const & options, TypeManager const & manager,
43 codemaker::UnoType::Sort sort, RTTypeClass typeClass,
44 OString const & name, sal_Int32 rank,
45 std::vector< OString > const & arguments, short referenceType,
46 bool defaultvalue)
48 if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) {
49 switch (sort)
51 case codemaker::UnoType::SORT_BOOLEAN:
52 o << "sal_False";
53 return;
54 case codemaker::UnoType::SORT_CHAR:
55 case codemaker::UnoType::SORT_BYTE:
56 case codemaker::UnoType::SORT_SHORT:
57 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
58 case codemaker::UnoType::SORT_LONG:
59 case codemaker::UnoType::SORT_UNSIGNED_LONG:
60 case codemaker::UnoType::SORT_HYPER:
61 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
62 case codemaker::UnoType::SORT_FLOAT:
63 case codemaker::UnoType::SORT_DOUBLE:
64 o << "0";
65 return;
66 case codemaker::UnoType::SORT_VOID:
67 case codemaker::UnoType::SORT_STRING:
68 case codemaker::UnoType::SORT_TYPE:
69 case codemaker::UnoType::SORT_ANY:
70 case codemaker::UnoType::SORT_COMPLEX:
71 break;
75 if (defaultvalue && referenceType == 16) {
76 if (typeClass == RT_TYPE_ENUM) {
77 typereg::Reader reader(manager.getTypeReader(name));
78 o << name.copy(name.lastIndexOf('/'))
79 << "_"
80 << codemaker::convertString(reader.getFieldName(0));
82 return;
84 bool bReference = false;
85 if (((sort > codemaker::UnoType::SORT_CHAR ||
86 rank > 0) && referenceType != 8 &&
87 !(typeClass == RT_TYPE_ENUM && referenceType == 4 && rank == 0)) ||
88 (sort <= codemaker::UnoType::SORT_CHAR && referenceType == 2))
90 bReference = true;
93 if (bReference && referenceType == 4)
94 o << "const ";
96 for (sal_Int32 i = 0; i < rank; ++i) {
97 o << ((options.shortnames) ? "css::uno::Sequence< " :
98 "::com::sun::star::uno::Sequence< ");
100 if (typeClass == RT_TYPE_INTERFACE && referenceType > 0) {
101 o << ((options.shortnames) ? "css::uno::Reference< " :
102 "::com::sun::star::uno::Reference< ");
105 o << scopedCppName(codemaker::cpp::translateUnoToCppType(
106 sort, typeClass, name, false),
107 false, options.shortnames && referenceType > 0);
109 if (typeClass == RT_TYPE_INTERFACE && referenceType > 0)
110 o << " >";
112 if (!arguments.empty()) {
113 o << "< ";
114 for (std::vector< OString >::const_iterator i(arguments.begin());
115 i != arguments.end(); ++i)
117 if (i != arguments.begin())
118 o << ", ";
120 printType(o, options, manager, *i, 1, false);
122 o << " >";
125 for (sal_Int32 i = 0; i < rank; ++i)
126 o << " >";
128 if (bReference && referenceType > 1)
129 o << " &";
131 if (referenceType == 8 && (sort > codemaker::UnoType::SORT_CHAR || rank > 0))
132 o << "()";
135 void printType(std::ostream & o,
136 ProgramOptions const & options, TypeManager const & manager,
137 OString const & type, short referenceType, bool defaultvalue)
139 RTTypeClass typeClass;
140 OString name;
141 sal_Int32 rank;
142 std::vector< OString > arguments;
143 codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve(
144 manager, type, true, true, true, &typeClass, &name, &rank, &arguments);
145 printType(o,
146 options, manager, sort, typeClass, name, rank, arguments,
147 referenceType, defaultvalue);
150 bool printConstructorParameters(std::ostream & o,
151 ProgramOptions const & options, TypeManager const & manager,
152 typereg::Reader const & reader, typereg::Reader const & outerReader,
153 std::vector< OString > const & arguments)
155 bool previous = false;
156 if (reader.getSuperTypeCount() != 0) {
157 OString super(
158 codemaker::convertString(reader.getSuperTypeName(0)));
159 typereg::Reader superReader(manager.getTypeReader(super));
160 if (!superReader.isValid())
161 throw CannotDumpException("Bad type library entity " + super);
163 previous = printConstructorParameters(o,
164 options, manager, superReader, outerReader, arguments);
166 for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
167 if (previous)
168 o << ", ";
169 else
170 previous = true;
172 if ((reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) == 0) {
173 printType(o, options, manager,
174 codemaker::convertString(reader.getFieldTypeName(i)), 4);
175 } else if (arguments.empty()) {
176 // ToDo !
177 // o << "com::sun::star::uno::Any";
178 } else {
179 sal_uInt16 tparam = 0;
180 while (outerReader.getReferenceTypeName(tparam)
181 != reader.getFieldTypeName(i))
183 ++tparam;
184 OSL_ASSERT(tparam < outerReader.getReferenceCount());
186 // assume std::vector< OString >::size_type is at least as
187 // large as sal_uInt16:
188 printType(o, options, manager, arguments[tparam], 4);
190 o << ' '
191 << (codemaker::cpp::translateUnoToCppIdentifier(
192 codemaker::convertString(reader.getFieldName(i)),
193 "param").
194 getStr());
196 return previous;
199 void printConstructor(std::ostream & o,
200 ProgramOptions const & options, TypeManager const & manager,
201 typereg::Reader const & reader,
202 std::vector< OString > const & arguments)
204 OString type(codemaker::convertString(reader.getTypeName()));
205 o << "public ";
206 o << type.copy(type.lastIndexOf('/') + 1) << '(';
207 printConstructorParameters(o, options, manager, reader, reader,
208 arguments);
209 o << ");\n";
212 void printMethodParameters(std::ostream & o,
213 ProgramOptions const & options, TypeManager const & manager,
214 typereg::Reader const & reader, sal_uInt16 method, bool previous,
215 bool withtype)
217 short referenceType = 4;
218 for (sal_uInt16 i = 0; i < reader.getMethodParameterCount(method); ++i) {
219 if (previous)
220 o << ", ";
222 previous = true;
224 if (reader.getMethodParameterFlags(method, i) == RT_PARAM_OUT
225 || reader.getMethodParameterFlags(method, i) == RT_PARAM_INOUT)
227 referenceType = 2;
228 } else {
229 referenceType = 4;
232 if (withtype) {
233 printType(o, options, manager,
234 codemaker::convertString(
235 reader.getMethodParameterTypeName(method, i)),
236 referenceType);
237 o << ' ';
240 o << (codemaker::cpp::translateUnoToCppIdentifier(
241 codemaker::convertString(
242 reader.getMethodParameterName(method, i)),
243 "param").
244 getStr());
248 void printExceptionSpecification(std::ostream & o,
249 ProgramOptions const & options, TypeManager const & manager,
250 typereg::Reader const & reader, sal_uInt16 method)
252 o << ((options.shortnames) ? " throw (css::uno::RuntimeException" :
253 " throw (::com::sun::star::uno::RuntimeException");
254 if (reader.getMethodExceptionCount(method) > 0) {
255 for (sal_uInt16 i = 0; i < reader.getMethodExceptionCount(method); ++i) {
256 o << ", ";
257 printType(o, options, manager,
258 codemaker::convertString(
259 reader.getMethodExceptionTypeName(method, i)), 1);
262 o << ")";
265 void printSetPropertyMixinBody(std::ostream & o,
266 typereg::Reader const & reader,
267 sal_uInt16 field,
268 sal_uInt16 method)
270 RTFieldAccess propFlags = checkAdditionalPropertyFlags(reader, field, method);
271 OString fieldname = codemaker::convertString(reader.getFieldName(field));
272 bool bound = (reader.getFieldFlags(field) & RT_ACCESS_BOUND ? true : false);
274 o << "\n{\n";
276 if (bound)
277 o << " BoundListeners l;\n";
279 if (propFlags & RT_ACCESS_CONSTRAINED) {
280 OString fieldtype = codemaker::convertString(
281 reader.getFieldTypeName(field));
283 sal_Int32 index = fieldtype.lastIndexOf('<');
284 sal_Int32 nPos=0;
285 bool single = true;
286 bool optional = false;
287 OStringBuffer buffer1(64);
288 OStringBuffer buffer2(64);
291 OString s(fieldtype.getToken(0, '<', nPos));
292 OString t = s.copy(s.lastIndexOf('/')+1);
294 if (t.equals("Optional")) {
295 optional=true;
296 if (single) {
297 single=false;
298 buffer1.append("the_value.IsPresent");
299 buffer2.append("the_value.Value");
300 } else {
301 buffer1.insert(0, t);
302 buffer1.append(".IsPresent");
303 buffer2.insert(0, t);
304 buffer2.append(".Value");
306 } else {
307 if (single) {
308 single=false;
309 if (!optional)
310 buffer1.append("the_value.Value");
312 buffer2.append("the_value.Value");
313 } else {
314 if (!optional) {
315 buffer1.insert(0, t);
316 buffer1.append(".Value");
318 buffer2.insert(0, t);
319 buffer2.append(".Value");
322 } while( nPos <= index );
324 o << " css::uno::Any v;\n";
325 if (optional) {
326 o << " if(" << buffer1.makeStringAndClear() << ")\n {\n"
327 << " v <<= " << buffer2.makeStringAndClear() << ";\n }\n";
328 } else {
329 o << " v <<= " << buffer2.makeStringAndClear() << ";\n\n";
332 o << " prepareSet(\n rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(\""
333 << fieldname << "\")),\n css::uno::Any(), v, ";
334 } else {
335 o << " prepareSet(\n rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(\""
336 << fieldname << "\")),\n css::uno::Any(), css::uno::Any(), ";
339 if (bound)
340 o << "&l);\n";
341 else
342 o << "0);\n";
344 o << " {\n osl::MutexGuard g(m_aMutex);\n m_"
345 << fieldname << " = the_value;\n }\n";
347 if (bound)
348 o << " l.notify();\n";
350 o << "}\n\n";
353 void generateXPropertySetBodies(std::ostream& o,
354 const OString & classname,
355 const OString & interfaceName);
356 void generateXFastPropertySetBodies(std::ostream& o,
357 const OString & classname,
358 const OString & interfaceName);
359 void generateXPropertyAccessBodies(std::ostream& o,
360 const OString & classname,
361 const OString & interfaceName);
363 void generateXAddInBodies(std::ostream& o, const OString & classname);
365 void generateXLocalizable(std::ostream& o, const OString & classname);
367 void generateXCompatibilityNamesBodies(std::ostream& o, const OString & classname);
369 void generateXInitialization(std::ostream& o, const OString & classname);
371 void generateXDispatch(std::ostream& o,
372 const OString & classname,
373 const ProtocolCmdMap & protocolCmdMap);
375 void generateXDispatchProvider(std::ostream& o,
376 const OString & classname,
377 const ProtocolCmdMap & protocolCmdMap);
380 void printMethods(std::ostream & o,
381 ProgramOptions const & options, TypeManager const & manager,
382 typereg::Reader const & reader, codemaker::GeneratedTypeSet & generated,
383 OString const & delegate, OString const & classname,
384 OString const & indentation, bool defaultvalue,
385 OString const & propertyhelper)
387 OString type(codemaker::convertString(reader.getTypeName()));
388 if (generated.contains(type) || type.equals("com/sun/star/uno/XInterface") ||
389 (defaultvalue &&
390 ( type.equals("com/sun/star/lang/XComponent") ||
391 type.equals("com/sun/star/lang/XTypeProvider") ||
392 type.equals("com/sun/star/uno/XWeak")) ) )
394 return;
397 static OString sd(RTL_CONSTASCII_STRINGPARAM("_"));
398 bool body = ((delegate.getLength() > 0) ? true : false);
399 bool defaultbody = ((delegate.equals(sd)) ? true : false);
401 if (body && propertyhelper.getLength() > 1) {
402 if ( type.equals("com/sun/star/beans/XPropertySet")) {
403 generated.add(type);
404 generateXPropertySetBodies(
405 o, classname, scopedCppName(propertyhelper, false, true));
406 return;
407 } else if ( type.equals("com/sun/star/beans/XFastPropertySet")) {
408 generated.add(type);
409 generateXFastPropertySetBodies(
410 o, classname, scopedCppName(propertyhelper, false, true));
411 return;
412 } else if ( type.equals("com/sun/star/beans/XPropertyAccess")) {
413 generated.add(type);
414 generateXPropertyAccessBodies(
415 o, classname, scopedCppName(propertyhelper, false, true));
416 return;
420 if (body && options.componenttype == 2) {
421 if (type.equals("com/sun/star/lang/XServiceName")) {
422 o << "// ::com::sun::star::lang::XServiceName:\n"
423 "::rtl::OUString SAL_CALL " << classname << "getServiceName() "
424 "throw (css::uno::RuntimeException)\n{\n "
425 "return ::rtl::OUString::createFromAscii("
426 "sADDIN_SERVICENAME);\n}\n";
427 generated.add(type);
428 return;
429 } else if (type.equals("com/sun/star/sheet/XAddIn")) {
430 generateXAddInBodies(o, classname);
431 generated.add(type);
433 // special handling of XLocalizable -> parent of XAddIn
434 if (!generated.contains("com/sun/star/lang/XLocalizable")) {
435 generateXLocalizable(o, classname);
436 generated.add("com/sun/star/lang/XLocalizable");
438 return;
439 } else if (type.equals("com/sun/star/lang/XLocalizable")) {
440 generateXLocalizable(o, classname);
441 generated.add(type);
442 return;
443 } else if (type.equals("com/sun/star/sheet/XCompatibilityNames")) {
444 generateXCompatibilityNamesBodies(o, classname);
445 generated.add(type);
446 return;
450 if (body && options.componenttype == 3) {
451 if (type.equals("com/sun/star/lang/XInitialization")) {
452 generateXInitialization(o, classname);
453 generated.add(type);
454 return;
455 } else if (type.equals("com/sun/star/frame/XDispatch")) {
456 generateXDispatch(o, classname, options.protocolCmdMap);
457 generated.add(type);
458 return;
459 } else if (type.equals("com/sun/star/frame/XDispatchProvider")) {
460 generateXDispatchProvider(o, classname, options.protocolCmdMap);
461 generated.add(type);
462 return;
466 generated.add(type);
467 if (options.all || defaultvalue) {
468 for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) {
469 typereg::Reader super(
470 manager.getTypeReader(
471 codemaker::convertString(
472 reader.getSuperTypeName(i))));
473 if (!super.isValid()) {
474 throw CannotDumpException(
475 "Bad type library entity "
476 + codemaker::convertString(
477 reader.getSuperTypeName(i)));
480 OString stype(codemaker::convertString(super.getTypeName()));
481 printMethods(o, options, manager, super, generated, delegate,
482 classname, indentation, defaultvalue, propertyhelper);
485 if (reader.getFieldCount() > 0 || reader.getMethodCount() > 0) {
486 o << indentation << "// ";
487 printType(o, options, manager, type, 0);
488 o << ":\n";
491 sal_uInt16 method = 0;
492 for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
493 o << indentation;
494 if (!body)
495 o << "virtual ";
497 printType(o, options, manager,
498 codemaker::convertString(reader.getFieldTypeName(i)), 1);
499 o << " SAL_CALL ";
500 if (classname.getLength() > 0)
501 o << classname;
503 o << "get"
504 << codemaker::convertString(reader.getFieldName(i)).getStr()
505 << "()";
506 if (method < reader.getMethodCount()
507 && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_GET
508 && reader.getMethodName(method) == reader.getFieldName(i))
510 printExceptionSpecification(o, options, manager, reader, method++);
511 } else {
512 o << ((options.shortnames) ? " throw (css::uno::RuntimeException)" :
513 " throw (::com::sun::star::uno::RuntimeException)");
515 if (body) {
516 if (defaultbody) {
517 if (propertyhelper.getLength() > 0) {
518 o << "\n{\n osl::MutexGuard g(m_aMutex);\n return m_"
519 << codemaker::convertString(reader.getFieldName(i)).getStr()
520 << ";\n}\n\n";
521 } else {
522 o << "\n{\n return ";
523 if (options.componenttype == 1) {
524 o << "m_"
525 << codemaker::convertString(
526 reader.getFieldName(i)).getStr();
527 } else {
528 printType(o, options, manager,
529 codemaker::convertString(
530 reader.getFieldTypeName(i)),
531 8, true);
533 o << ";\n}\n\n";
535 } else {
536 o << "\n" << indentation << "{\n" << indentation << " return "
537 << delegate.getStr() << "get"
538 << codemaker::convertString(reader.getFieldName(i)).getStr()
539 << "();\n" << indentation << "}\n\n";
541 } else {
542 o << ";\n";
545 if ((reader.getFieldFlags(i) & RT_ACCESS_READONLY) == 0) {
546 o << indentation;
547 if (!body)
548 o << "virtual ";
550 o << "void SAL_CALL ";
551 if (classname.getLength() > 0)
552 o << classname;
554 o << "set"
555 << (codemaker::convertString(reader.getFieldName(i)).getStr())
556 << '(';
557 printType(o, options, manager,
558 codemaker::convertString(reader.getFieldTypeName(i)), 4);
559 o << " the_value)";
560 if (method < reader.getMethodCount()
561 && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_SET
562 && reader.getMethodName(method) == reader.getFieldName(i))
564 printExceptionSpecification(o, options, manager, reader, method++);
565 } else {
566 o << ((options.shortnames) ? " throw (css::uno::RuntimeException)" :
567 " throw (::com::sun::star::uno::RuntimeException)");
569 if (body) {
570 if (defaultbody) {
571 if (propertyhelper.getLength() > 0) {
572 printSetPropertyMixinBody(o, reader, i, method);
573 } else {
574 if (options.componenttype == 1) {
575 o << "\n{\n m_"
576 << codemaker::convertString(
577 reader.getFieldName(i)).getStr()
578 << " = the_value;\n}\n\n";
579 } else {
580 o << "\n{\n\n}\n\n";
583 } else {
584 o << "\n" << indentation << "{\n" << indentation << " "
585 << delegate.getStr() << "set"
586 << codemaker::convertString(reader.getFieldName(i)).getStr()
587 << "(the_value);\n" << indentation << "}\n\n";
589 } else {
590 o << ";\n";
594 for (; method < reader.getMethodCount(); ++method) {
595 o << indentation;
596 if (!body)
597 o << "virtual ";
599 printType(o, options, manager,
600 codemaker::convertString(
601 reader.getMethodReturnTypeName(method)), 1);
602 o << " SAL_CALL ";
603 if (classname.getLength() > 0)
604 o << classname;
606 const OString methodName(codemaker::convertString(reader.getMethodName(method)));
608 o << methodName << '(';
609 printMethodParameters(o, options, manager, reader, method, false, true);
610 o << ')';
611 printExceptionSpecification(o, options, manager, reader, method);
612 if (body) {
613 static OUString s(RTL_CONSTASCII_USTRINGPARAM("void"));
614 if (defaultbody) {
615 o << "\n{\n";
616 if (!reader.getMethodReturnTypeName(method).equals(s)) {
617 o << " // TODO: Exchange the default return implementation for \""
618 << methodName << "\" !!!\n";
619 o << " // Exchange the default return implementation.\n"
620 " // NOTE: Default initialized polymorphic structs "
621 "can cause problems because of\n // missing default "
622 "initialization of primitive types of some C++ compilers or"
623 "\n // different Any initialization in Java and C++ "
624 "polymorphic structs.\n return ";
625 printType(o, options, manager,
626 codemaker::convertString(
627 reader.getMethodReturnTypeName(method)), 8, true);
628 o << ";";
629 } else {
630 o << " // TODO: Insert your implementation for \""
631 << methodName << "\" here.";
633 o << "\n}\n\n";
634 } else {
635 o << "\n" << indentation << "{\n" << indentation << " ";
636 if (!reader.getMethodReturnTypeName(method).equals(s))
637 o << "return ";
639 o << delegate.getStr()
640 << (codemaker::convertString(
641 reader.getMethodName(method)).getStr())
642 << '(';
643 printMethodParameters(o, options, manager, reader, method,
644 false, false);
645 o << ");\n" << indentation << "}\n\n";
647 } else {
648 o << ";\n";
652 if (method > 0 && !body)
653 o << "\n";
656 void printConstructionMethods(std::ostream & o,
657 ProgramOptions const & options, TypeManager const & manager,
658 typereg::Reader const & reader)
660 for (sal_uInt16 i = 0; i < reader.getMethodCount(); ++i) {
661 o << "static ";
662 printType(o,
663 options, manager,
664 codemaker::convertString(reader.getSuperTypeName(0)), 1);
665 o << ' ';
666 if (reader.getMethodName(i).getLength() == 0) {
667 o << "create";
668 } else {
669 o << (codemaker::cpp::translateUnoToCppIdentifier(
670 codemaker::convertString(reader.getMethodName(i)),
671 "method").
672 getStr());
674 o << ((options.shortnames) ? "(css::uno::Reference< css" :
675 "(::com::sun::star::uno::Reference< ::com::sun::star")
676 << "::uno::XComponentContext > const & the_context";
677 printMethodParameters(o, options, manager, reader, i,
678 true, true);
679 o << ')';
680 printExceptionSpecification(o, options, manager, reader, i);
681 o << ";\n";
685 void printServiceMembers(std::ostream & o,
686 ProgramOptions const & options, TypeManager const & manager,
687 typereg::Reader const & reader, OString const & type,
688 OString const & delegate)
690 for (sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i) {
691 OString referenceType(
692 codemaker::convertString(
693 reader.getReferenceTypeName(i)).replace('/', '.'));
695 if ( reader.getReferenceSort(i) == RT_REF_SUPPORTS ) {
696 o << "\n// supported interface " << referenceType.getStr() << "\n";
697 generateDocumentation(o, options, manager, referenceType, delegate);
698 } else if ( reader.getReferenceSort(i) == RT_REF_EXPORTS ) {
699 o << "\n// exported service " << referenceType.getStr() << "\n";
700 generateDocumentation(o, options, manager, referenceType, delegate);
701 o << "\n// end of exported service " << referenceType.getStr() << "\n";
705 if (delegate.getLength() == 0) {
706 o << "\n// properties of service \""<< type.getStr() << "\"\n";
707 for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
708 OString fieldName(
709 codemaker::convertString(reader.getFieldName(i)));
710 OString fieldType(
711 codemaker::convertString(reader.getFieldTypeName(i)));
713 o << "// private ";
714 printType(o, options, manager, fieldType, 1);
715 o << " "
716 << codemaker::cpp::translateUnoToCppIdentifier(
717 fieldName, "property").getStr()
718 << ";\n";
723 void printMapsToCppType(std::ostream & o,
724 ProgramOptions const & options, TypeManager const & manager,
725 codemaker::UnoType::Sort sort, RTTypeClass typeClass,
726 OString const & name, sal_Int32 rank,
727 std::vector< OString > const & arguments, const char * cppTypeSort)
729 o << "maps to C++ ";
730 if (cppTypeSort != 0)
731 o << cppTypeSort << ' ';
733 o << "type \"";
734 if (rank == 0 && name == "com/sun/star/uno/XInterface") {
735 o << "Reference< com::sun::star::uno::XInterface >";
736 } else {
737 printType(o, options, manager, sort, typeClass, name, rank, arguments, 0);
739 o << '"';
742 void generateDocumentation(std::ostream & o,
743 ProgramOptions const & options, TypeManager const & manager,
744 OString const & type, OString const & delegate)
746 if (type.indexOf('/') >= 0)
747 throw CannotDumpException("Illegal type name " + type);
749 OString binType(type.replace('.', '/'));
750 RTTypeClass typeClass;
751 OString name;
752 sal_Int32 rank;
753 std::vector< OString > arguments;
754 codemaker::UnoType::Sort sort = decomposeResolveAndCheck(
755 manager, binType, false, true, true, &typeClass, &name, &rank,
756 &arguments);
758 bool comment=true;
759 if (delegate.getLength() > 0) {
760 if (typeClass != RT_TYPE_INTERFACE &&
761 typeClass != RT_TYPE_SERVICE )
763 return;
765 comment=false;
768 if (comment) {
769 o << "\n// UNO";
770 if (rank > 0) {
771 o << " sequence type";
772 } else if (sort != codemaker::UnoType::SORT_COMPLEX) {
773 o << " simple type";
774 } else {
775 typereg::Reader reader(manager.getTypeReader(name));
776 if (!reader.isValid())
777 throw CannotDumpException("Bad type library entity " + name);
779 switch (typeClass)
781 case RT_TYPE_INTERFACE:
782 o << " interface type";
783 break;
785 case RT_TYPE_MODULE:
786 o << "IDL module";
787 break;
789 case RT_TYPE_STRUCT:
790 if (reader.getReferenceCount() == 0)
791 o << " simple struct type";
792 else if (arguments.empty())
793 o << " polymorphic struct type template";
794 else
795 o << " instantiated polymorphic struct type";
796 break;
798 case RT_TYPE_ENUM:
799 o << " enum type";
800 break;
802 case RT_TYPE_EXCEPTION:
803 o << " exception type";
804 break;
806 case RT_TYPE_TYPEDEF:
807 o << "IDL typedef";
808 break;
810 case RT_TYPE_SERVICE:
811 if (reader.getSuperTypeCount() > 0)
812 o << " single-inheritance--based service";
813 else
814 o << "IDL accumulation-based service";
815 break;
817 case RT_TYPE_SINGLETON:
818 if ((manager.getTypeReader(
819 codemaker::convertString(
820 reader.getSuperTypeName(0))).getTypeClass())
821 == RT_TYPE_INTERFACE)
822 o << " inheritance-based singleton";
823 else
824 o << "IDL service-based singleton";
825 break;
827 case RT_TYPE_CONSTANTS:
828 o << "IDL constant group";
829 break;
831 default:
832 OSL_ASSERT(false);
833 break;
836 o << " \"" << type.getStr() << "\" ";
838 sort = codemaker::decomposeAndResolve(
839 manager, binType, true, true, true, &typeClass, &name, &rank,
840 &arguments);
841 if (rank > 0) {
842 if (comment) {
843 printMapsToCppType(o,
844 options, manager, sort, typeClass, name, rank, arguments, "array");
845 o << '\n';
847 } else if (sort != codemaker::UnoType::SORT_COMPLEX) {
848 if (comment) {
849 printMapsToCppType(o,
850 options, manager, sort, typeClass, name, rank, arguments, 0);
851 o << '\n';
853 } else {
854 typereg::Reader reader(manager.getTypeReader(name));
855 if (!reader.isValid())
856 throw CannotDumpException("Bad type library entity " + name);
858 switch (typeClass)
860 case RT_TYPE_INTERFACE:
861 if (comment)
862 printMapsToCppType(o,
863 options, manager, sort, typeClass, name, rank, arguments,
864 "interface");
865 if (name == "com/sun/star/uno/XInterface") {
866 if (comment)
867 o << '\n';
868 } else {
869 if (comment)
870 o << "; " << (options.all ? "all" : "direct") << " methods:\n";
872 codemaker::GeneratedTypeSet generated;
873 printMethods(o, options, manager, reader, generated,
874 delegate, options.implname, "");
876 break;
878 case RT_TYPE_MODULE:
879 printMapsToCppType(o,
880 options, manager, sort, typeClass, name, rank, arguments,
881 "namespace");
882 o << '\n';
883 break;
885 case RT_TYPE_STRUCT:
886 if (reader.getReferenceCount() == 0) {
887 printMapsToCppType(o,
888 options, manager, sort, typeClass, name, rank, arguments,
889 "class");
890 } else if (arguments.empty()) {
891 printMapsToCppType(o,
892 options, manager, sort, typeClass, name, rank, arguments,
893 options.java5 ? "generic class" : "class");
894 } else {
895 printMapsToCppType(o,
896 options, manager, sort, typeClass, name, rank, arguments,
897 options.java5 ? "generic class instantiation" : "class");
899 o << "; full constructor:\n";
900 printConstructor(o, options, manager, reader, arguments);
901 break;
903 case RT_TYPE_ENUM:
904 printMapsToCppType(o,
905 options, manager, sort, typeClass, name, rank, arguments,
906 "enum");
907 o << '\n';
908 break;
910 case RT_TYPE_CONSTANTS:
911 printMapsToCppType(o,
912 options, manager, sort, typeClass, name, rank, arguments,
913 "namespace");
914 o << '\n';
915 break;
917 case RT_TYPE_EXCEPTION:
918 printMapsToCppType(o,
919 options, manager, sort, typeClass, name, rank, arguments,
920 "exception class");
921 o << "; full constructor:\n";
922 printConstructor(o, options, manager, reader, arguments);
923 break;
925 case RT_TYPE_SERVICE:
926 if (reader.getSuperTypeCount() > 0) {
927 if (comment) {
928 printMapsToCppType(o, options, manager, sort, typeClass,
929 name, rank, arguments, "class");
930 o << "; construction methods:\n";
931 printConstructionMethods(o, options, manager, reader);
934 OString super(
935 codemaker::convertString(
936 reader.getSuperTypeName(0)).replace('/', '.'));
937 generateDocumentation(o, options, manager, super, delegate);
938 } else {
939 if (comment)
940 o << ("does not map to C++\n"
941 "// the service members are generated instead\n");
942 printServiceMembers(o, options, manager, reader, type, delegate);
944 break;
946 case RT_TYPE_SINGLETON:
947 if (reader.getSuperTypeCount() > 0 &&
948 ((manager.getTypeReader(
949 codemaker::convertString(
950 reader.getSuperTypeName(0))).
951 getTypeClass()) == RT_TYPE_INTERFACE) )
953 printMapsToCppType(o, options, manager, sort, typeClass,
954 name, rank, arguments,
955 "class");
956 o << "; get method:\nstatic ";
957 printType(o, options, manager,
958 codemaker::convertString(reader.getSuperTypeName(0)), 1);
959 o << " get(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);\n";
960 } else {
961 o << "does not map to C++\n";
963 break;
965 default:
966 OSL_ASSERT(false);
967 break;