fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / codemaker / source / cppumaker / cpputype.cxx
blob0b3e9fd9b6b4b5ef0a46d62378f0f35d09560946
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 <algorithm>
23 #include <cassert>
24 #include <map>
25 #include <set>
26 #include <vector>
27 #include <iostream>
29 #include "boost/noncopyable.hpp"
30 #include "rtl/alloc.h"
31 #include "rtl/ref.hxx"
32 #include "rtl/ustrbuf.hxx"
33 #include "rtl/ustring.hxx"
34 #include "rtl/strbuf.hxx"
35 #include "unoidl/unoidl.hxx"
37 #include "codemaker/commoncpp.hxx"
38 #include "codemaker/exceptiontree.hxx"
39 #include "codemaker/generatedtypeset.hxx"
40 #include "codemaker/typemanager.hxx"
41 #include "codemaker/unotype.hxx"
43 #include "cpputype.hxx"
44 #include "cppuoptions.hxx"
45 #include "dependencies.hxx"
46 #include "dumputils.hxx"
47 #include "includes.hxx"
49 namespace {
51 bool isBootstrapType(OUString const & name) {
52 static char const * const names[] = {
53 "com.sun.star.beans.Property",
54 "com.sun.star.beans.PropertyAttribute",
55 "com.sun.star.beans.PropertyChangeEvent",
56 "com.sun.star.beans.PropertyState",
57 "com.sun.star.beans.PropertyValue",
58 "com.sun.star.beans.XFastPropertySet",
59 "com.sun.star.beans.XMultiPropertySet",
60 "com.sun.star.beans.XPropertiesChangeListener",
61 "com.sun.star.beans.XPropertyAccess",
62 "com.sun.star.beans.XPropertyChangeListener",
63 "com.sun.star.beans.XPropertySet",
64 "com.sun.star.beans.XPropertySetInfo",
65 "com.sun.star.beans.XPropertySetOption",
66 "com.sun.star.beans.XVetoableChangeListener",
67 "com.sun.star.bridge.UnoUrlResolver",
68 "com.sun.star.bridge.XUnoUrlResolver",
69 "com.sun.star.connection.SocketPermission",
70 "com.sun.star.container.XElementAccess",
71 "com.sun.star.container.XEnumeration",
72 "com.sun.star.container.XEnumerationAccess",
73 "com.sun.star.container.XHierarchicalNameAccess",
74 "com.sun.star.container.XNameAccess",
75 "com.sun.star.container.XNameContainer",
76 "com.sun.star.container.XNameReplace",
77 "com.sun.star.container.XSet",
78 "com.sun.star.io.FilePermission",
79 "com.sun.star.io.IOException",
80 "com.sun.star.lang.DisposedException",
81 "com.sun.star.lang.EventObject",
82 "com.sun.star.lang.WrappedTargetRuntimeException",
83 "com.sun.star.lang.XComponent",
84 "com.sun.star.lang.XEventListener",
85 "com.sun.star.lang.XInitialization",
86 "com.sun.star.lang.XMultiComponentFactory",
87 "com.sun.star.lang.XMultiServiceFactory",
88 "com.sun.star.lang.XServiceInfo",
89 "com.sun.star.lang.XSingleComponentFactory",
90 "com.sun.star.lang.XSingleServiceFactory",
91 "com.sun.star.lang.XTypeProvider",
92 "com.sun.star.loader.XImplementationLoader",
93 "com.sun.star.reflection.FieldAccessMode",
94 "com.sun.star.reflection.MethodMode",
95 "com.sun.star.reflection.ParamInfo",
96 "com.sun.star.reflection.ParamMode",
97 "com.sun.star.reflection.TypeDescriptionSearchDepth",
98 "com.sun.star.reflection.XCompoundTypeDescription",
99 "com.sun.star.reflection.XEnumTypeDescription",
100 "com.sun.star.reflection.XIdlArray",
101 "com.sun.star.reflection.XIdlClass",
102 "com.sun.star.reflection.XIdlField",
103 "com.sun.star.reflection.XIdlField2",
104 "com.sun.star.reflection.XIdlMethod",
105 "com.sun.star.reflection.XIdlReflection",
106 "com.sun.star.reflection.XIndirectTypeDescription",
107 "com.sun.star.reflection.XInterfaceAttributeTypeDescription",
108 "com.sun.star.reflection.XInterfaceAttributeTypeDescription2",
109 "com.sun.star.reflection.XInterfaceMemberTypeDescription",
110 "com.sun.star.reflection.XInterfaceMethodTypeDescription",
111 "com.sun.star.reflection.XInterfaceTypeDescription",
112 "com.sun.star.reflection.XInterfaceTypeDescription2",
113 "com.sun.star.reflection.XMethodParameter",
114 "com.sun.star.reflection.XStructTypeDescription",
115 "com.sun.star.reflection.XTypeDescription",
116 "com.sun.star.reflection.XTypeDescriptionEnumeration",
117 "com.sun.star.reflection.XTypeDescriptionEnumerationAccess",
118 "com.sun.star.registry.RegistryKeyType",
119 "com.sun.star.registry.RegistryValueType",
120 "com.sun.star.registry.XImplementationRegistration",
121 "com.sun.star.registry.XRegistryKey",
122 "com.sun.star.registry.XSimpleRegistry",
123 "com.sun.star.security.RuntimePermission",
124 "com.sun.star.security.XAccessControlContext",
125 "com.sun.star.security.XAccessController",
126 "com.sun.star.security.XAction",
127 "com.sun.star.uno.DeploymentException",
128 "com.sun.star.uno.RuntimeException",
129 "com.sun.star.uno.TypeClass",
130 "com.sun.star.uno.Uik",
131 "com.sun.star.uno.XAdapter",
132 "com.sun.star.uno.XAggregation",
133 "com.sun.star.uno.XComponentContext",
134 "com.sun.star.uno.XCurrentContext",
135 "com.sun.star.uno.XInterface",
136 "com.sun.star.uno.XReference",
137 "com.sun.star.uno.XUnloadingPreference",
138 "com.sun.star.uno.XWeak",
139 "com.sun.star.util.XMacroExpander" };
140 // cf. cppuhelper/unotypes/Makefile UNOTYPES (plus missing dependencies)
141 for (std::size_t i = 0; i < SAL_N_ELEMENTS(names); ++i) {
142 if (name.equalsAscii(names[i])) {
143 return true;
146 return false;
149 class CppuType: private boost::noncopyable {
150 public:
151 CppuType(
152 OUString const & name, rtl::Reference< TypeManager > const & typeMgr);
154 virtual ~CppuType() {}
156 void dump(CppuOptions const & options);
158 bool dumpFile(
159 OUString const & uri, OUString const & name, bool hpp,
160 CppuOptions const & options);
162 void dumpDependedTypes(
163 codemaker::GeneratedTypeSet & generated, CppuOptions const & options);
165 virtual void dumpHFile(
166 FileStream & out, codemaker::cppumaker::Includes & includes)
167 { dumpHFileContent(out, includes); }
169 virtual void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) = 0;
171 OUString dumpHeaderDefine(FileStream& o, OUString const & extension);
173 void dumpGetCppuType(FileStream & out);
175 virtual void dumpLightGetCppuType(FileStream & out);
177 virtual void dumpNormalGetCppuType(FileStream &)
178 { assert(false); } // this cannot happen
180 virtual void dumpComprehensiveGetCppuType(FileStream &)
181 { assert(false); } // this cannot happen
183 void dumpType(
184 FileStream & out, OUString const & name, bool isConst = false,
185 bool isRef = false, bool native = false, bool cppuUnoType = false)
186 const;
188 OUString getTypeClass(OUString const & name, bool cStyle = false);
190 void dumpCppuGetType(
191 FileStream & out, OUString const & name, OUString const * ownName = 0);
193 sal_uInt32 getInheritedMemberCount();
195 void inc(sal_Int32 num=4);
196 void dec(sal_Int32 num=4);
197 OUString indent() const;
198 protected:
199 virtual sal_uInt32 checkInheritedMemberCount() const
200 { assert(false); return 0; } // this cannot happen
202 bool passByReference(OUString const & name) const;
204 OUString resolveOuterTypedefs(OUString const & name) const;
206 OUString resolveAllTypedefs(OUString const & name) const;
208 codemaker::cpp::IdentifierTranslationMode isGlobal() const;
210 virtual void dumpDeclaration(FileStream &)
211 { assert(false); } // this cannot happen
213 virtual void dumpFiles(OUString const & uri, CppuOptions const & options);
215 virtual void addLightGetCppuTypeIncludes(
216 codemaker::cppumaker::Includes & includes) const;
218 virtual void addNormalGetCppuTypeIncludes(
219 codemaker::cppumaker::Includes & includes) const;
221 virtual void addComprehensiveGetCppuTypeIncludes(
222 codemaker::cppumaker::Includes & includes) const;
224 virtual bool isPolymorphic() const;
226 virtual void dumpTemplateHead(FileStream &) const {}
228 virtual void dumpTemplateParameters(FileStream &) const {}
230 void dumpGetCppuTypePreamble(FileStream & out);
232 void dumpGetCppuTypePostamble(FileStream & out);
234 void addDefaultHIncludes(codemaker::cppumaker::Includes & includes) const;
235 void addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes) const;
237 void dumpInitializer(
238 FileStream & out, bool parameterized, OUString const & name) const;
240 void dumpHFileContent(
241 FileStream & out, codemaker::cppumaker::Includes & includes);
243 protected:
244 sal_uInt32 m_inheritedMemberCount;
246 bool m_cppuTypeLeak;
247 bool m_cppuTypeDynamic;
248 sal_Int32 m_indentLength;
249 OUString name_;
250 OUString id_;
251 rtl::Reference< TypeManager > m_typeMgr;
252 codemaker::cppumaker::Dependencies m_dependencies;
254 private:
255 void addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes)
256 const;
259 CppuType::CppuType(
260 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
261 m_inheritedMemberCount(0)
262 , m_cppuTypeLeak(false)
263 , m_cppuTypeDynamic(true)
264 , m_indentLength(0)
265 , name_(name)
266 , id_(name_.copy(name_.lastIndexOf('.') + 1))
267 , m_typeMgr(typeMgr)
268 , m_dependencies(typeMgr, name_)
271 void CppuType::addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes)
272 const
274 if (name_ == "com.sun.star.uno.XInterface"
275 || name_ == "com.sun.star.uno.Exception")
277 includes.addType();
278 includes.addCppuUnotypeHxx();
279 includes.addSalTypesH();
280 includes.addTypelibTypeclassH();
281 includes.addTypelibTypedescriptionH();
282 } else if (m_cppuTypeLeak) {
283 addLightGetCppuTypeIncludes(includes);
284 } else if (m_cppuTypeDynamic) {
285 addNormalGetCppuTypeIncludes(includes);
286 } else {
287 addComprehensiveGetCppuTypeIncludes(includes);
291 void CppuType::dumpFiles(OUString const & uri, CppuOptions const & options) {
292 dumpFile(uri, name_, false, options);
293 dumpFile(uri, name_, true, options);
296 void CppuType::addLightGetCppuTypeIncludes(
297 codemaker::cppumaker::Includes & includes) const
299 //TODO: Determine what is really needed, instead of relying on
300 // addDefaultHxxIncludes
301 includes.addCppuUnotypeHxx();
304 void CppuType::addNormalGetCppuTypeIncludes(
305 codemaker::cppumaker::Includes & includes) const
307 //TODO: Determine what is really needed, instead of relying on
308 // addDefaultHxxIncludes
309 includes.addCppuUnotypeHxx();
312 void CppuType::addComprehensiveGetCppuTypeIncludes(
313 codemaker::cppumaker::Includes & includes) const
315 //TODO: Determine what is really needed, instead of relying on
316 // addDefaultHxxIncludes
317 includes.addCppuUnotypeHxx();
320 bool CppuType::isPolymorphic() const { return false; }
322 void CppuType::dumpGetCppuTypePreamble(FileStream & out) {
323 if (isPolymorphic()) {
324 out << "namespace cppu {\n\n";
325 dumpTemplateHead(out);
326 out << "class UnoType< ";
327 dumpType(out, name_);
328 dumpTemplateParameters(out);
329 out << " > {\npublic:\n";
330 inc();
331 out << indent()
332 << "static inline ::css::uno::Type const & get() {\n";
333 } else {
334 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
335 out << "\n\n";
337 out << ("inline ::css::uno::Type const &"
338 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
339 dumpType(out, name_, false, false, true);
340 out << " const *) {\n";
342 inc();
345 void CppuType::dumpGetCppuTypePostamble(FileStream & out) {
346 dec();
347 if (isPolymorphic()) {
348 out << indent() << "}\n\nprivate:\n"
349 << indent() << "UnoType(UnoType &); // not defined\n"
350 << indent() << "~UnoType(); // not defined\n"
351 << indent()
352 << "void operator =(UnoType); // not defined\n};\n\n}\n\n";
353 } else {
354 out << "}\n\n";
355 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
356 out << "\n\n";
359 dumpTemplateHead(out);
360 out << ("SAL_DEPRECATED(\"use cppu::UnoType\") inline ::css::uno::Type const & SAL_CALL"
361 " getCppuType(SAL_UNUSED_PARAMETER ");
362 dumpType(out, name_);
363 dumpTemplateParameters(out);
364 out << " const *) {\n";
365 inc();
366 out << indent() << "return ::cppu::UnoType< ";
367 dumpType(out, name_);
368 dumpTemplateParameters(out);
369 out << " >::get();\n";
370 dec();
371 out << indent() << "}\n";
374 void CppuType::dump(CppuOptions const & options) {
375 if (isBootstrapType(name_)) {
376 m_cppuTypeDynamic = false;
377 } else {
378 // -CS was used as an undocumented option to generate static getCppuType
379 // functions; since the introduction of cppu::UnoType this no longer is
380 // meaningful (getCppuType is just a forward to cppu::UnoType::get now),
381 // and -CS is handled the same way as -C now:
382 if (options.isValid("-L"))
383 m_cppuTypeLeak = true;
384 if (options.isValid("-C") || options.isValid("-CS"))
385 m_cppuTypeDynamic = false;
387 dumpFiles(
388 options.isValid("-O") ? b2u(options.getOption("-O")) : "", options);
391 bool CppuType::dumpFile(
392 OUString const & uri, OUString const & name, bool hpp,
393 CppuOptions const & options)
395 OUString fileUri(
396 b2u(createFileNameFromType(
397 u2b(uri), u2b(name), hpp ? ".hpp" : ".hdl")));
398 if (fileUri.isEmpty()) {
399 throw CannotDumpException("empty target URI for entity " + name);
401 bool exists = fileExists(u2b(fileUri));
402 if (exists && options.isValid("-G")) {
403 return false;
405 FileStream out;
406 out.createTempFile(getTempDir(u2b(fileUri)));
407 OUString tmpUri(b2u(out.getName()));
408 if(!out.isValid()) {
409 throw CannotDumpException("cannot open " + tmpUri + " for writing");
411 codemaker::cppumaker::Includes includes(m_typeMgr, m_dependencies, hpp);
412 try {
413 if (hpp) {
414 addGetCppuTypeIncludes(includes);
415 dumpHxxFile(out, includes);
416 } else {
417 dumpHFile(out, includes);
419 } catch (...) {
420 out.close();
421 // Remove existing type file if something goes wrong to ensure
422 // consistency:
423 if (fileExists(u2b(fileUri))) {
424 removeTypeFile(u2b(fileUri));
426 removeTypeFile(u2b(tmpUri));
427 throw;
429 out.close();
430 return makeValidTypeFile(
431 u2b(fileUri), u2b(tmpUri), exists && options.isValid("-Gc"));
434 void CppuType::dumpDependedTypes(
435 codemaker::GeneratedTypeSet & generated, CppuOptions const & options)
437 if (!options.isValid("-nD")) {
438 codemaker::cppumaker::Dependencies::Map const & map
439 = m_dependencies.getMap();
440 for (codemaker::cppumaker::Dependencies::Map::const_iterator i(
441 map.begin());
442 i != map.end(); ++i)
444 produce(i->first, m_typeMgr, generated, options);
449 OUString CppuType::dumpHeaderDefine(
450 FileStream & out, OUString const & extension)
452 OUString def(
453 "INCLUDED_" + name_.replace('.', '_').toAsciiUpperCase() + "_"
454 + extension);
455 out << "#ifndef " << def << "\n#define " << def << "\n";
456 return def;
459 void CppuType::addDefaultHIncludes(codemaker::cppumaker::Includes & includes)
460 const
462 //TODO: Only include what is really needed
463 includes.addCppuMacrosHxx();
464 if (m_typeMgr->getSort(name_)
465 == codemaker::UnoType::SORT_INTERFACE_TYPE)
467 includes.addException();
468 includes.addReference();
472 void CppuType::addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes)
473 const
475 //TODO: Only include what is really needed
476 includes.addType();
477 if (m_typeMgr->getSort(name_)
478 == codemaker::UnoType::SORT_INTERFACE_TYPE)
480 includes.addException();
481 includes.addReference();
485 void CppuType::dumpInitializer(
486 FileStream & out, bool parameterized, OUString const & name) const
488 out << "(";
489 if (!parameterized) {
490 sal_Int32 k;
491 std::vector< OString > args;
492 OUString n(
493 b2u(codemaker::UnoType::decompose(
494 u2b(resolveAllTypedefs(name)), &k, &args)));
495 if (k == 0) {
496 rtl::Reference< unoidl::Entity > ent;
497 switch (m_typeMgr->getSort(n, &ent)) {
498 case codemaker::UnoType::SORT_BOOLEAN:
499 out << "false";
500 break;
501 case codemaker::UnoType::SORT_BYTE:
502 case codemaker::UnoType::SORT_SHORT:
503 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
504 case codemaker::UnoType::SORT_LONG:
505 case codemaker::UnoType::SORT_UNSIGNED_LONG:
506 case codemaker::UnoType::SORT_HYPER:
507 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
508 case codemaker::UnoType::SORT_FLOAT:
509 case codemaker::UnoType::SORT_DOUBLE:
510 case codemaker::UnoType::SORT_CHAR:
511 out << "0";
512 break;
513 case codemaker::UnoType::SORT_ENUM_TYPE:
514 out << codemaker::cpp::scopedCppName(u2b(n)) << "_"
515 << (dynamic_cast< unoidl::EnumTypeEntity * >(ent.get())->
516 getMembers()[0].name);
517 break;
518 case codemaker::UnoType::SORT_STRING:
519 case codemaker::UnoType::SORT_TYPE:
520 case codemaker::UnoType::SORT_ANY:
521 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
522 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
523 case codemaker::UnoType::SORT_INTERFACE_TYPE:
524 break;
525 default:
526 throw CannotDumpException(
527 "unexpected entity \"" + name
528 + "\" in call to CppuType::dumpInitializer");
532 out << ")";
535 void CppuType::dumpHFileContent(
536 FileStream & out, codemaker::cppumaker::Includes & includes)
538 addDefaultHIncludes(includes);
539 dumpHeaderDefine(out, "HDL");
540 out << "\n";
541 includes.dump(out, 0);
542 out << ("\nnamespace com { namespace sun { namespace star { namespace uno"
543 " { class Type; } } } }\n\n");
544 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
545 out << "\n";
547 dumpDeclaration(out);
548 if (!(name_ == "com.sun.star.uno.XInterface"
549 || name_ == "com.sun.star.uno.Exception"
550 || isPolymorphic()))
552 out << "\n" << indent()
553 << ("inline ::css::uno::Type const &"
554 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
555 dumpType(out, name_, false, false, true);
556 out << " const *);\n";
558 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
559 out << "\n";
561 out << "\n";
562 dumpTemplateHead(out);
563 out << "SAL_DEPRECATED(\"use cppu::UnoType\") inline ::css::uno::Type const & SAL_CALL getCppuType(";
564 dumpType(out, name_, true);
565 dumpTemplateParameters(out);
566 out << " *);\n\n#endif\n";
569 void CppuType::dumpGetCppuType(FileStream & out) {
570 if (name_ == "com.sun.star.uno.XInterface") {
571 out << indent()
572 << ("SAL_DEPRECATED(\"use cppu::UnoType\") inline ::css::uno::Type const & SAL_CALL"
573 " getCppuType(SAL_UNUSED_PARAMETER ");
574 dumpType(out, name_, true);
575 out << " *) {\n";
576 inc();
577 out << indent()
578 << ("return ::cppu::UnoType< ::css::uno::XInterface"
579 " >::get();\n");
580 dec();
581 out << indent() << "}\n";
582 } else if (name_ == "com.sun.star.uno.Exception") {
583 out << indent()
584 << ("SAL_DEPRECATED(\"use cppu::UnoType\") inline ::css::uno::Type const & SAL_CALL"
585 " getCppuType(SAL_UNUSED_PARAMETER ");
586 dumpType(out, name_, true);
587 out << " *) {\n";
588 inc();
589 out << indent()
590 << ("return ::cppu::UnoType< ::css::uno::Exception"
591 " >::get();\n");
592 dec();
593 out << indent() << "}\n";
594 } else if (m_cppuTypeLeak) {
595 dumpLightGetCppuType(out);
596 } else if (m_cppuTypeDynamic) {
597 dumpNormalGetCppuType(out);
598 } else {
599 dumpComprehensiveGetCppuType(out);
603 void CppuType::dumpLightGetCppuType(FileStream & out) {
604 dumpGetCppuTypePreamble(out);
605 out << indent()
606 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
607 << indent() << "if ( !the_type )\n" << indent() << "{\n";
608 inc();
609 out << indent() << "typelib_static_type_init( &the_type, "
610 << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n";
611 dec();
612 out << indent() << "}\n" << indent()
613 << ("return * reinterpret_cast< ::css::uno::Type * >("
614 " &the_type );\n");
615 dumpGetCppuTypePostamble(out);
618 codemaker::cpp::IdentifierTranslationMode CppuType::isGlobal() const {
619 return name_.indexOf('.') == -1
620 ? codemaker::cpp::ITM_GLOBAL : codemaker::cpp::ITM_NONGLOBAL;
623 sal_uInt32 CppuType::getInheritedMemberCount()
625 if (m_inheritedMemberCount == 0)
627 m_inheritedMemberCount = checkInheritedMemberCount();
630 return m_inheritedMemberCount;
633 OUString CppuType::getTypeClass(OUString const & name, bool cStyle) {
634 rtl::Reference< unoidl::Entity > ent;
635 switch (m_typeMgr->getSort(name, &ent)) {
636 case codemaker::UnoType::SORT_VOID:
637 return cStyle
638 ? OUString("typelib_TypeClass_VOID")
639 : OUString("::css::uno::TypeClass_VOID");
640 case codemaker::UnoType::SORT_BOOLEAN:
641 return cStyle
642 ? OUString("typelib_TypeClass_BOOLEAN")
643 : OUString("::css::uno::TypeClass_BOOLEAN");
644 case codemaker::UnoType::SORT_BYTE:
645 return cStyle
646 ? OUString("typelib_TypeClass_BYTE")
647 : OUString("::css::uno::TypeClass_BYTE");
648 case codemaker::UnoType::SORT_SHORT:
649 return cStyle
650 ? OUString("typelib_TypeClass_SHORT")
651 : OUString("::css::uno::TypeClass_SHORT");
652 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
653 return cStyle
654 ? OUString("typelib_TypeClass_UNSIGNED_SHORT")
655 : OUString("::css::uno::TypeClass_UNSIGNED_SHORT");
656 case codemaker::UnoType::SORT_LONG:
657 return cStyle
658 ? OUString("typelib_TypeClass_LONG")
659 : OUString("::css::uno::TypeClass_LONG");
660 case codemaker::UnoType::SORT_UNSIGNED_LONG:
661 return cStyle
662 ? OUString("typelib_TypeClass_UNSIGNED_LONG")
663 : OUString("::css::uno::TypeClass_UNSIGNED_LONG");
664 case codemaker::UnoType::SORT_HYPER:
665 return cStyle
666 ? OUString("typelib_TypeClass_HYPER")
667 : OUString("::css::uno::TypeClass_HYPER");
668 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
669 return cStyle
670 ? OUString("typelib_TypeClass_UNSIGNED_HYPER")
671 : OUString("::css::uno::TypeClass_UNSIGNED_HYPER");
672 case codemaker::UnoType::SORT_FLOAT:
673 return cStyle
674 ? OUString("typelib_TypeClass_FLOAT")
675 : OUString("::css::uno::TypeClass_FLOAT");
676 case codemaker::UnoType::SORT_DOUBLE:
677 return cStyle
678 ? OUString("typelib_TypeClass_DOUBLE")
679 : OUString("::css::uno::TypeClass_DOUBLE");
680 case codemaker::UnoType::SORT_CHAR:
681 return cStyle
682 ? OUString("typelib_TypeClass_CHAR")
683 : OUString("::css::uno::TypeClass_CHAR");
684 case codemaker::UnoType::SORT_STRING:
685 return cStyle
686 ? OUString("typelib_TypeClass_STRING")
687 : OUString("::css::uno::TypeClass_STRING");
688 case codemaker::UnoType::SORT_TYPE:
689 return cStyle
690 ? OUString("typelib_TypeClass_TYPE")
691 : OUString("::css::uno::TypeClass_TYPE");
692 case codemaker::UnoType::SORT_ANY:
693 return cStyle
694 ? OUString("typelib_TypeClass_ANY")
695 : OUString("::css::uno::TypeClass_ANY");
696 case codemaker::UnoType::SORT_SEQUENCE_TYPE:
697 return cStyle
698 ? OUString("typelib_TypeClass_SEQUENCE")
699 : OUString("::css::uno::TypeClass_SEQUENCE");
700 case codemaker::UnoType::SORT_ENUM_TYPE:
701 return cStyle
702 ? OUString("typelib_TypeClass_ENUM")
703 : OUString("::css::uno::TypeClass_ENUM");
704 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
705 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
706 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
707 return cStyle
708 ? OUString("typelib_TypeClass_STRUCT")
709 : OUString("::css::uno::TypeClass_STRUCT");
710 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
711 return cStyle
712 ? OUString("typelib_TypeClass_EXCEPTION")
713 : OUString("::css::uno::TypeClass_EXCEPTION");
714 case codemaker::UnoType::SORT_INTERFACE_TYPE:
715 return cStyle
716 ? OUString("typelib_TypeClass_INTERFACE")
717 : OUString("::css::uno::TypeClass_INTERFACE");
718 case codemaker::UnoType::SORT_TYPEDEF:
719 return getTypeClass(
720 dynamic_cast<unoidl::TypedefEntity&>(*ent.get()).getType(),
721 cStyle);
722 default:
723 for (;;) { std::abort(); }
727 void CppuType::dumpType(
728 FileStream & out, OUString const & name, bool isConst, bool isRef,
729 bool native, bool cppuUnoType) const
731 sal_Int32 k;
732 std::vector< OString > args;
733 OUString n(
734 b2u(codemaker::UnoType::decompose(
735 u2b(resolveAllTypedefs(name)), &k, &args)));
736 if (isConst) {
737 out << "const ";
739 for (sal_Int32 i = 0; i != k; ++i) {
740 out << (cppuUnoType
741 ? "::cppu::UnoSequenceType" : "::css::uno::Sequence")
742 << "< ";
744 switch (m_typeMgr->getSort(n)) {
745 case codemaker::UnoType::SORT_VOID:
746 out << "void";
747 break;
748 case codemaker::UnoType::SORT_BOOLEAN:
749 out << "::sal_Bool";
750 break;
751 case codemaker::UnoType::SORT_BYTE:
752 out << "::sal_Int8";
753 break;
754 case codemaker::UnoType::SORT_SHORT:
755 out << "::sal_Int16";
756 break;
757 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
758 out << (cppuUnoType ? "::cppu::UnoUnsignedShortType" : "::sal_uInt16");
759 break;
760 case codemaker::UnoType::SORT_LONG:
761 out << "::sal_Int32";
762 break;
763 case codemaker::UnoType::SORT_UNSIGNED_LONG:
764 out << "::sal_uInt32";
765 break;
766 case codemaker::UnoType::SORT_HYPER:
767 out << "::sal_Int64";
768 break;
769 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
770 out << "::sal_uInt64";
771 break;
772 case codemaker::UnoType::SORT_FLOAT:
773 out << "float";
774 break;
775 case codemaker::UnoType::SORT_DOUBLE:
776 out << "double";
777 break;
778 case codemaker::UnoType::SORT_CHAR:
779 out << (cppuUnoType ? "::cppu::UnoCharType" : "::sal_Unicode");
780 break;
781 case codemaker::UnoType::SORT_STRING:
782 out << "::rtl::OUString";
783 break;
784 case codemaker::UnoType::SORT_TYPE:
785 out << "::css::uno::Type";
786 break;
787 case codemaker::UnoType::SORT_ANY:
788 out << "::css::uno::Any";
789 break;
790 case codemaker::UnoType::SORT_ENUM_TYPE:
791 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
792 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
793 out << codemaker::cpp::scopedCppName(u2b(n));
794 break;
795 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
796 out << codemaker::cpp::scopedCppName(u2b(n));
797 if (!args.empty()) {
798 out << "< ";
799 for (std::vector< OString >::iterator i(args.begin());
800 i != args.end(); ++i)
802 if (i != args.begin()) {
803 out << ", ";
805 dumpType(out, b2u(*i));
807 out << " >";
809 break;
810 case codemaker::UnoType::SORT_INTERFACE_TYPE:
811 if (!native) {
812 out << "::css::uno::Reference< ";
814 out << codemaker::cpp::scopedCppName(u2b(n));
815 if (!native) {
816 out << " >";
818 break;
819 default:
820 throw CannotDumpException(
821 "unexpected entity \"" + name + "\" in call to CppuType::dumpType");
823 for (sal_Int32 i = 0; i != k; ++i) {
824 out << " >";
826 if (isRef) {
827 out << "&";
831 void CppuType::dumpCppuGetType(
832 FileStream & out, OUString const & name, OUString const * ownName)
834 //TODO: What are these calls good for?
835 OUString nucleus;
836 sal_Int32 rank;
837 codemaker::UnoType::Sort sort = m_typeMgr->decompose(
838 name, true, &nucleus, &rank, 0, 0);
839 switch (rank == 0 ? sort : codemaker::UnoType::SORT_SEQUENCE_TYPE) {
840 case codemaker::UnoType::SORT_VOID:
841 case codemaker::UnoType::SORT_BOOLEAN:
842 case codemaker::UnoType::SORT_BYTE:
843 case codemaker::UnoType::SORT_SHORT:
844 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
845 case codemaker::UnoType::SORT_LONG:
846 case codemaker::UnoType::SORT_UNSIGNED_LONG:
847 case codemaker::UnoType::SORT_HYPER:
848 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
849 case codemaker::UnoType::SORT_FLOAT:
850 case codemaker::UnoType::SORT_DOUBLE:
851 case codemaker::UnoType::SORT_CHAR:
852 case codemaker::UnoType::SORT_STRING:
853 case codemaker::UnoType::SORT_TYPE:
854 case codemaker::UnoType::SORT_ANY:
855 break;
856 case codemaker::UnoType::SORT_SEQUENCE_TYPE:
857 case codemaker::UnoType::SORT_ENUM_TYPE:
858 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
859 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
860 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
861 case codemaker::UnoType::SORT_INTERFACE_TYPE:
862 // Take care of recursion like struct S { sequence<S> x; }:
863 if (ownName == 0 || nucleus != *ownName) {
864 out << indent() << "::cppu::UnoType< ";
865 dumpType(out, name, false, false, false, true);
866 out << " >::get();\n";
868 break;
869 case codemaker::UnoType::SORT_TYPEDEF:
870 assert(false); // this cannot happen
871 // fall through
872 default:
873 throw CannotDumpException(
874 "unexpected entity \"" + name
875 + "\" in call to CppuType::dumpCppuGetType");
879 bool CppuType::passByReference(OUString const & name) const {
880 switch (m_typeMgr->getSort(resolveOuterTypedefs(name))) {
881 case codemaker::UnoType::SORT_BOOLEAN:
882 case codemaker::UnoType::SORT_BYTE:
883 case codemaker::UnoType::SORT_SHORT:
884 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
885 case codemaker::UnoType::SORT_LONG:
886 case codemaker::UnoType::SORT_UNSIGNED_LONG:
887 case codemaker::UnoType::SORT_HYPER:
888 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
889 case codemaker::UnoType::SORT_FLOAT:
890 case codemaker::UnoType::SORT_DOUBLE:
891 case codemaker::UnoType::SORT_CHAR:
892 case codemaker::UnoType::SORT_ENUM_TYPE:
893 return false;
894 case codemaker::UnoType::SORT_STRING:
895 case codemaker::UnoType::SORT_TYPE:
896 case codemaker::UnoType::SORT_ANY:
897 case codemaker::UnoType::SORT_SEQUENCE_TYPE:
898 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
899 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
900 case codemaker::UnoType::SORT_INTERFACE_TYPE:
901 return true;
902 default:
903 throw CannotDumpException(
904 "unexpected entity \"" + name
905 + "\" in call to CppuType::passByReference");
909 OUString CppuType::resolveOuterTypedefs(OUString const & name) const {
910 for (OUString n(name);;) {
911 rtl::Reference< unoidl::Entity > ent;
912 if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) {
913 return n;
915 n = dynamic_cast<unoidl::TypedefEntity&>(*ent.get()).getType();
919 OUString CppuType::resolveAllTypedefs(OUString const & name) const {
920 sal_Int32 k1;
921 OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k1)));
922 for (;;) {
923 rtl::Reference< unoidl::Entity > ent;
924 if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) {
925 break;
927 sal_Int32 k2;
928 n = b2u(
929 codemaker::UnoType::decompose(
930 u2b(dynamic_cast<unoidl::TypedefEntity&>(*ent.get()).
931 getType()),
932 &k2));
933 k1 += k2; //TODO: overflow
935 OUStringBuffer b;
936 for (sal_Int32 i = 0; i != k1; ++i) {
937 b.append("[]");
939 b.append(n);
940 return b.makeStringAndClear();
943 void CppuType::inc(sal_Int32 num)
945 m_indentLength += num;
948 void CppuType::dec(sal_Int32 num)
950 m_indentLength = std::max< sal_Int32 >(m_indentLength - num, 0);
953 OUString CppuType::indent() const {
954 OUStringBuffer buf(m_indentLength);
955 for (sal_Int32 i = 0; i != m_indentLength; ++i) {
956 buf.append(' ');
958 return buf.makeStringAndClear();
961 bool isDeprecated(std::vector< OUString > const & annotations) {
962 for (std::vector< OUString >::const_iterator i(annotations.begin());
963 i != annotations.end(); ++i)
965 if (*i == "deprecated") {
966 return true;
969 return false;
972 void dumpDeprecation(FileStream & out, bool deprecated) {
973 if (deprecated) {
974 out << "SAL_DEPRECATED_INTERNAL(\"marked @deprecated in UNOIDL\") ";
978 class BaseOffset: private boost::noncopyable {
979 public:
980 BaseOffset(
981 rtl::Reference< TypeManager > const & manager,
982 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
983 manager_(manager), offset_(0) { calculateBases(entity); }
985 sal_Int32 get() const { return offset_; }
987 private:
988 void calculateBases(
989 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity);
991 rtl::Reference< TypeManager > manager_;
992 std::set< OUString > set_;
993 sal_Int32 offset_;
996 void BaseOffset::calculateBases(
997 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity)
999 assert(entity.is());
1000 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
1001 entity->getDirectMandatoryBases().begin());
1002 i != entity->getDirectMandatoryBases().end(); ++i)
1004 if (set_.insert(i->name).second) {
1005 rtl::Reference< unoidl::Entity > ent;
1006 codemaker::UnoType::Sort sort = manager_->getSort(i->name, &ent);
1007 if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE) {
1008 throw CannotDumpException(
1009 "interface type base " + i->name
1010 + " is not an interface type");
1012 rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
1013 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
1014 assert(ent2.is());
1015 calculateBases(ent2);
1016 offset_ += ent2->getDirectAttributes().size()
1017 + ent2->getDirectMethods().size(); //TODO: overflow
1022 class InterfaceType: public CppuType {
1023 public:
1024 InterfaceType(
1025 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity,
1026 OUString const & name, rtl::Reference< TypeManager > const & typeMgr);
1028 virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
1029 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
1031 void dumpAttributes(FileStream& o);
1032 void dumpMethods(FileStream& o);
1033 void dumpNormalGetCppuType(FileStream& o) SAL_OVERRIDE;
1034 void dumpComprehensiveGetCppuType(FileStream& o) SAL_OVERRIDE;
1035 void dumpCppuAttributeRefs(FileStream& o, sal_uInt32& index);
1036 void dumpCppuMethodRefs(FileStream& o, sal_uInt32& index);
1037 void dumpCppuAttributes(FileStream& o, sal_uInt32& index);
1038 void dumpCppuMethods(FileStream& o, sal_uInt32& index);
1039 void dumpAttributesCppuDecl(FileStream & out, std::set< OUString > * seen);
1040 void dumpMethodsCppuDecl(FileStream & out, std::set< OUString > * seen);
1042 private:
1043 virtual void addComprehensiveGetCppuTypeIncludes(
1044 codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
1046 virtual sal_uInt32 checkInheritedMemberCount() const SAL_OVERRIDE
1047 { return BaseOffset(m_typeMgr, entity_).get(); }
1049 static void dumpExceptionSpecification(
1050 FileStream & out, std::vector< OUString > const & exceptions,
1051 bool runtimeException);
1053 void dumpExceptionTypeName(
1054 FileStream & out, OUString const & prefix, sal_uInt32 index,
1055 OUString const & name);
1057 sal_Int32 dumpExceptionTypeNames(
1058 FileStream & out, OUString const & prefix,
1059 std::vector< OUString > const & exceptions, bool runtimeException);
1061 rtl::Reference< unoidl::InterfaceTypeEntity > entity_;
1062 bool m_isDeprecated;
1065 InterfaceType::InterfaceType(
1066 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity,
1067 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
1068 CppuType(name, typeMgr), entity_(entity),
1069 m_isDeprecated(isDeprecated(entity->getAnnotations()))
1071 assert(entity.is());
1074 void InterfaceType::dumpDeclaration(FileStream & out) {
1075 out << "\nclass SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI " << id_;
1076 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
1077 entity_->getDirectMandatoryBases().begin());
1078 i != entity_->getDirectMandatoryBases().end(); ++i)
1080 out << (i == entity_->getDirectMandatoryBases().begin() ? " :" : ",")
1081 << " public " << codemaker::cpp::scopedCppName(u2b(i->name));
1083 out << "\n{\npublic:\n";
1084 inc();
1085 dumpAttributes(out);
1086 dumpMethods(out);
1087 out << "\n" << indent()
1088 << ("static inline ::css::uno::Type const & SAL_CALL"
1089 " static_type(void * = 0);\n\n");
1090 dec();
1091 out << "protected:\n";
1092 inc();
1093 out << indent() << "~" << id_
1094 << ("() throw () {} // avoid warnings about virtual members and"
1095 " non-virtual dtor\n");
1096 dec();
1097 out << "};\n\n";
1100 void InterfaceType::dumpHxxFile(
1101 FileStream & out, codemaker::cppumaker::Includes & includes)
1103 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
1104 out << "\n";
1105 addDefaultHxxIncludes(includes);
1106 includes.dump(out, &name_);
1107 out << "\n";
1108 dumpGetCppuType(out);
1109 out << "\n::css::uno::Type const & "
1110 << codemaker::cpp::scopedCppName(u2b(name_))
1111 << "::static_type(SAL_UNUSED_PARAMETER void *) {\n";
1112 inc();
1113 out << indent() << "return ::cppu::UnoType< ";
1114 dumpType(out, name_, false, false, true);
1115 out << " >::get();\n";
1116 dec();
1117 out << "}\n\n#endif // "<< headerDefine << "\n";
1120 void InterfaceType::dumpAttributes(FileStream & out) {
1121 if (!entity_->getDirectAttributes().empty()) {
1122 out << "\n" << indent() << "// Attributes\n";
1124 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
1125 i(entity_->getDirectAttributes().begin());
1126 i != entity_->getDirectAttributes().end(); ++i)
1128 bool depr = m_isDeprecated || isDeprecated(i->annotations);
1129 out << indent();
1130 dumpDeprecation(out, depr);
1131 out << "virtual ";
1132 dumpType(out, i->type);
1133 out << " SAL_CALL get" << i->name << "()";
1134 dumpExceptionSpecification(out, i->getExceptions, true);
1135 out << " = 0;\n";
1136 if (!i->readOnly) {
1137 bool byRef = passByReference(i->type);
1138 out << indent();
1139 dumpDeprecation(out, depr);
1140 out << "virtual void SAL_CALL set" << i->name << "( ";
1141 dumpType(out, i->type, byRef, byRef);
1142 out << " _" << i->name.toAsciiLowerCase() << " )";
1143 dumpExceptionSpecification(out, i->setExceptions, true);
1144 out << " = 0;\n";
1149 void InterfaceType::dumpMethods(FileStream & out) {
1150 if (!entity_->getDirectMethods().empty()) {
1151 out << "\n" << indent() << "// Methods\n";
1153 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
1154 entity_->getDirectMethods().begin());
1155 i != entity_->getDirectMethods().end(); ++i)
1157 out << indent();
1158 dumpDeprecation(out, m_isDeprecated || isDeprecated(i->annotations));
1159 out << "virtual ";
1160 dumpType(out, i->returnType);
1161 out << " SAL_CALL " << i->name << "(";
1162 if (i->parameters.empty()) {
1163 out << ")";
1164 } else {
1165 out << " ";
1166 for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
1167 const_iterator j(i->parameters.begin());
1168 j != i->parameters.end();)
1170 bool isConst;
1171 bool isRef;
1172 if (j->direction
1173 == (unoidl::InterfaceTypeEntity::Method::Parameter::
1174 DIRECTION_IN))
1176 isConst = passByReference(j->type);
1177 isRef = isConst;
1178 } else {
1179 isConst = false;
1180 isRef = true;
1182 dumpType(out, j->type, isConst, isRef);
1183 out << " " << j->name;
1184 ++j;
1185 if (j != i->parameters.end()) {
1186 out << ", ";
1189 out << " )";
1191 dumpExceptionSpecification(
1192 out, i->exceptions, i->name != "acquire" && i->name != "release");
1193 out << " = 0;\n";
1197 void InterfaceType::dumpNormalGetCppuType(FileStream & out) {
1198 dumpGetCppuTypePreamble(out);
1199 out << indent()
1200 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
1201 << indent() << "if ( !the_type )\n" << indent() << "{\n";
1202 inc();
1203 std::vector< unoidl::AnnotatedReference >::size_type bases(
1204 entity_->getDirectMandatoryBases().size());
1205 if (bases == 1
1206 && (entity_->getDirectMandatoryBases()[0].name
1207 == "com.sun.star.uno.XInterface"))
1209 bases = 0;
1211 if (bases != 0) {
1212 out << indent() << "typelib_TypeDescriptionReference * aSuperTypes["
1213 << entity_->getDirectMandatoryBases().size() << "];\n";
1214 std::vector< unoidl::AnnotatedReference >::size_type n = 0;
1215 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
1216 entity_->getDirectMandatoryBases().begin());
1217 i != entity_->getDirectMandatoryBases().end(); ++i)
1219 out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< ";
1220 dumpType(out, i->name, true, false, false, true);
1221 out << " >::get().getTypeLibType();\n";
1224 out << indent() << "typelib_static_mi_interface_type_init( &the_type, \""
1225 << name_ << "\", " << bases << ", "
1226 << (bases == 0 ? "0" : "aSuperTypes") << " );\n";
1227 dec();
1228 out << indent() << "}\n" << indent()
1229 << ("return * reinterpret_cast< ::css::uno::Type * >("
1230 " &the_type );\n");
1231 dumpGetCppuTypePostamble(out);
1234 void InterfaceType::dumpComprehensiveGetCppuType(FileStream & out) {
1235 codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
1236 OUString staticTypeClass("the" + id_ + "Type");
1237 out << " namespace detail {\n\n" << indent() << "struct " << staticTypeClass
1238 << " : public rtl::StaticWithInit< ::css::uno::Type *, "
1239 << staticTypeClass << " >\n" << indent() << "{\n";
1240 inc();
1241 out << indent() << "::css::uno::Type * operator()() const\n"
1242 << indent() << "{\n";
1243 inc();
1244 out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n"
1245 << indent() << "// Start inline typedescription generation\n"
1246 << indent() << "typelib_InterfaceTypeDescription * pTD = 0;\n\n";
1247 out << indent() << "typelib_TypeDescriptionReference * aSuperTypes["
1248 << entity_->getDirectMandatoryBases().size() << "];\n";
1249 std::vector< unoidl::AnnotatedReference >::size_type n = 0;
1250 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
1251 entity_->getDirectMandatoryBases().begin());
1252 i != entity_->getDirectMandatoryBases().end(); ++i)
1254 out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< ";
1255 dumpType(out, i->name, false, false, false, true);
1256 out << " >::get().getTypeLibType();\n";
1258 std::size_t count = entity_->getDirectAttributes().size()
1259 + entity_->getDirectMethods().size(); //TODO: overflow
1260 if (count != 0) {
1261 out << indent() << "typelib_TypeDescriptionReference * pMembers["
1262 << count << "] = { ";
1263 for (std::size_t i = 0; i != count; ++i) {
1264 out << "0";
1265 if (i + 1 != count) {
1266 out << ",";
1269 out << " };\n";
1270 sal_uInt32 index = 0;
1271 dumpCppuAttributeRefs(out, index);
1272 dumpCppuMethodRefs(out, index);
1274 out << "\n" << indent() << "typelib_typedescription_newMIInterface(\n";
1275 inc();
1276 out << indent() << "&pTD,\n" << indent()
1277 << "sTypeName.pData, 0, 0, 0, 0, 0,\n" << indent()
1278 << entity_->getDirectMandatoryBases().size() << ", aSuperTypes,\n"
1279 << indent() << count << ",\n" << indent()
1280 << (count == 0 ? "0" : "pMembers") << " );\n\n";
1281 dec();
1282 out << indent()
1283 << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
1284 " );\n");
1285 for (std::size_t i = 0; i != count; ++i) {
1286 out << indent() << "typelib_typedescriptionreference_release( pMembers["
1287 << i << "] );\n";
1289 out << indent()
1290 << ("typelib_typedescription_release( (typelib_TypeDescription*)pTD"
1291 " );\n\n")
1292 << indent() << "return new ::css::uno::Type( "
1293 << getTypeClass(name_) << ", sTypeName ); // leaked\n";
1294 dec();
1295 out << indent() << "}\n";
1296 dec();
1297 out << indent() << "};\n\n";
1298 codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
1299 out << " }\n\n";
1300 dumpGetCppuTypePreamble(out);
1301 out << indent() << "const ::css::uno::Type &rRet = *detail::"
1302 << staticTypeClass << "::get();\n" << indent()
1303 << "// End inline typedescription generation\n" << indent()
1304 << "static bool bInitStarted = false;\n" << indent()
1305 << "if (!bInitStarted)\n" << indent() << "{\n";
1306 inc();
1307 out << indent()
1308 << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n"
1309 << indent() << "if (!bInitStarted)\n" << indent() << "{\n";
1310 inc();
1311 out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"
1312 << indent() << "bInitStarted = true;\n";
1313 std::set< OUString > seen;
1314 // Type for RuntimeException is always needed:
1315 seen.insert("com.sun.star.uno.RuntimeException");
1316 dumpCppuGetType(out, "com.sun.star.uno.RuntimeException");
1317 dumpAttributesCppuDecl(out, &seen);
1318 dumpMethodsCppuDecl(out, &seen);
1319 if (count != 0) {
1320 sal_uInt32 index = getInheritedMemberCount();
1321 dumpCppuAttributes(out, index);
1322 dumpCppuMethods(out, index);
1324 dec();
1325 out << indent() << "}\n";
1326 dec();
1327 out << indent() << "}\n" << indent() << "else\n" << indent() << "{\n";
1328 inc();
1329 out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n";
1330 dec();
1331 out << indent() << "}\n" << indent() << "return rRet;\n";
1332 dumpGetCppuTypePostamble(out);
1335 void InterfaceType::dumpCppuAttributeRefs(FileStream & out, sal_uInt32 & index)
1337 std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0;
1338 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
1339 i(entity_->getDirectAttributes().begin());
1340 i != entity_->getDirectAttributes().end(); ++i)
1342 out << indent() << "::rtl::OUString sAttributeName" << n << "( \""
1343 << name_ << "::" << i->name << "\" );\n" << indent()
1344 << "typelib_typedescriptionreference_new( &pMembers[" << index++
1345 << "],\n";
1346 inc(38);
1347 out << indent()
1348 << ("(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_ATTRIBUTE,\n")
1349 << indent() << "sAttributeName" << n << ".pData );\n";
1350 dec(38);
1351 ++n;
1355 void InterfaceType::dumpCppuMethodRefs(FileStream & out, sal_uInt32 & index) {
1356 std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0;
1357 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
1358 entity_->getDirectMethods().begin());
1359 i != entity_->getDirectMethods().end(); ++i)
1361 out << indent() << "::rtl::OUString sMethodName" << n << "( \"" << name_
1362 << "::" << i->name << "\" );\n" << indent()
1363 << "typelib_typedescriptionreference_new( &pMembers[" << index++
1364 << "],\n";
1365 inc(38);
1366 out << indent()
1367 << ("(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_METHOD,\n")
1368 << indent() << "sMethodName" << n << ".pData );\n";
1369 dec(38);
1370 ++n;
1374 void InterfaceType::addComprehensiveGetCppuTypeIncludes(
1375 codemaker::cppumaker::Includes & includes) const
1377 // The comprehensive getCppuType method always includes a line
1378 // "getCppuType( (const ::css::uno::RuntimeException*)0 );":
1379 includes.addCppuUnotypeHxx();
1380 includes.addRtlInstanceHxx(); // using rtl::StaticWithInit
1381 includes.addOslMutexHxx();
1382 includes.add("com.sun.star.uno.RuntimeException");
1385 void InterfaceType::dumpCppuAttributes(FileStream & out, sal_uInt32 & index) {
1386 if (!entity_->getDirectAttributes().empty()) {
1387 out << "\n" << indent()
1388 << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n";
1389 std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0;
1390 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::
1391 const_iterator i(entity_->getDirectAttributes().begin());
1392 i != entity_->getDirectAttributes().end(); ++i)
1394 OUString type(resolveAllTypedefs(i->type));
1395 out << indent() << "{\n";
1396 inc();
1397 out << indent() << "::rtl::OUString sAttributeType" << n << "( \""
1398 << type << "\" );\n" << indent()
1399 << "::rtl::OUString sAttributeName" << n << "( \"" << name_
1400 << "::" << i->name << "\" );\n";
1401 sal_Int32 getExcn = dumpExceptionTypeNames(
1402 out, "get", i->getExceptions, false);
1403 sal_Int32 setExcn = dumpExceptionTypeNames(
1404 out, "set", i->setExceptions, false);
1405 out << indent()
1406 << ("typelib_typedescription_newExtendedInterfaceAttribute("
1407 " &pAttribute,\n");
1408 inc();
1409 out << indent() << index++ << ", sAttributeName" << n
1410 << ".pData,\n" << indent() << "(typelib_TypeClass)"
1411 << getTypeClass(type) << ", sAttributeType" << n << ".pData,\n"
1412 << indent() << "sal_" << (i->readOnly ? "True" : "False")
1413 << ", " << getExcn << ", "
1414 << (getExcn == 0 ? "0" : "the_getExceptions") << ", " << setExcn
1415 << ", " << (setExcn == 0 ? "0" : "the_setExceptions")
1416 << " );\n";
1417 dec();
1418 out << indent()
1419 << ("typelib_typedescription_register("
1420 " (typelib_TypeDescription**)&pAttribute );\n");
1421 dec();
1422 out << indent() << "}\n";
1423 ++n;
1425 out << indent()
1426 << ("typelib_typedescription_release("
1427 " (typelib_TypeDescription*)pAttribute );\n");
1431 void InterfaceType::dumpCppuMethods(FileStream & out, sal_uInt32 & index) {
1432 if (!entity_->getDirectMethods().empty()) {
1433 out << "\n" << indent()
1434 << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n";
1435 std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0;
1436 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator
1437 i(entity_->getDirectMethods().begin());
1438 i != entity_->getDirectMethods().end(); ++i)
1440 OUString returnType(resolveAllTypedefs(i->returnType));
1441 out << indent() << "{\n";
1442 inc();
1443 if (!i->parameters.empty()) {
1444 out << indent() << "typelib_Parameter_Init aParameters["
1445 << i->parameters.size() << "];\n";
1447 std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
1448 size_type m = 0;
1449 for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
1450 const_iterator j(i->parameters.begin());
1451 j != i->parameters.end(); ++j)
1453 OUString type(resolveAllTypedefs(j->type));
1454 out << indent() << "::rtl::OUString sParamName" << m << "( \""
1455 << j->name << "\" );\n" << indent()
1456 << "::rtl::OUString sParamType" << m << "( \"" << type
1457 << "\" );\n" << indent() << "aParameters[" << m
1458 << "].pParamName = sParamName" << m << ".pData;\n"
1459 << indent() << "aParameters[" << m
1460 << "].eTypeClass = (typelib_TypeClass)"
1461 << getTypeClass(type) << ";\n" << indent() << "aParameters["
1462 << m << "].pTypeName = sParamType" << m << ".pData;\n"
1463 << indent() << "aParameters[" << m << "].bIn = "
1464 << ((j->direction
1465 == (unoidl::InterfaceTypeEntity::Method::Parameter::
1466 DIRECTION_OUT))
1467 ? "sal_False" : "sal_True")
1468 << ";\n" << indent() << "aParameters[" << m << "].bOut = "
1469 << ((j->direction
1470 == (unoidl::InterfaceTypeEntity::Method::Parameter::
1471 DIRECTION_IN))
1472 ? "sal_False" : "sal_True")
1473 << ";\n";
1474 ++m;
1476 sal_Int32 excn = dumpExceptionTypeNames(
1477 out, "", i->exceptions,
1478 i->name != "acquire" && i->name != "release");
1479 out << indent() << "::rtl::OUString sReturnType" << n << "( \""
1480 << returnType << "\" );\n" << indent()
1481 << "::rtl::OUString sMethodName" << n << "( \"" << name_ << "::"
1482 << i->name << "\" );\n" << indent()
1483 << "typelib_typedescription_newInterfaceMethod( &pMethod,\n";
1484 inc();
1485 out << indent() << index++ << ", sal_False,\n" << indent()
1486 << "sMethodName" << n << ".pData,\n" << indent()
1487 << "(typelib_TypeClass)" << getTypeClass(returnType)
1488 << ", sReturnType" << n << ".pData,\n" << indent()
1489 << i->parameters.size() << ", "
1490 << (i->parameters.empty() ? "0" : "aParameters") << ",\n"
1491 << indent() << excn << ", "
1492 << (excn == 0 ? "0" : "the_Exceptions") << " );\n";
1493 dec();
1494 out << indent()
1495 << ("typelib_typedescription_register("
1496 " (typelib_TypeDescription**)&pMethod );\n");
1497 dec();
1498 out << indent() << "}\n";
1499 ++n;
1501 out << indent()
1502 << ("typelib_typedescription_release("
1503 " (typelib_TypeDescription*)pMethod );\n");
1507 void InterfaceType::dumpAttributesCppuDecl(
1508 FileStream & out, std::set< OUString > * seen)
1510 assert(seen != 0);
1511 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
1512 i(entity_->getDirectAttributes().begin());
1513 i != entity_->getDirectAttributes().end(); ++i)
1515 if (seen->insert(i->type).second) {
1516 dumpCppuGetType(out, i->type);
1518 for (std::vector< OUString >::const_iterator j(
1519 i->getExceptions.begin());
1520 j != i->getExceptions.end(); ++j)
1522 if (seen->insert(*j).second) {
1523 dumpCppuGetType(out, *j);
1526 for (std::vector< OUString >::const_iterator j(
1527 i->setExceptions.begin());
1528 j != i->setExceptions.end(); ++j)
1530 if (seen->insert(*j).second) {
1531 dumpCppuGetType(out, *j);
1537 void InterfaceType::dumpMethodsCppuDecl(
1538 FileStream & out, std::set< OUString > * seen)
1540 assert(seen != 0);
1541 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
1542 entity_->getDirectMethods().begin());
1543 i != entity_->getDirectMethods().end(); ++i)
1545 for (std::vector< OUString >::const_iterator j(i->exceptions.begin());
1546 j != i->exceptions.end(); ++j)
1548 if (seen->insert(*j).second) {
1549 dumpCppuGetType(out, *j);
1555 void InterfaceType::dumpExceptionSpecification(
1556 FileStream & out, std::vector< OUString > const & exceptions,
1557 bool runtimeException)
1559 // Exception specifications are undesirable in production code, but make
1560 // for useful assertions in debug builds (on platforms where they are
1561 // enforced at runtime):
1562 #if !defined DBG_UTIL
1563 out << " /*";
1564 #endif
1565 out << " throw (";
1566 bool first = true;
1567 for (std::vector< OUString >::const_iterator i(exceptions.begin());
1568 i != exceptions.end(); ++i)
1570 if (*i != "com.sun.star.uno.RuntimeException") {
1571 if (!first) {
1572 out << ", ";
1574 out << codemaker::cpp::scopedCppName(u2b(*i));
1575 first = false;
1578 if (runtimeException) {
1579 if (!first) {
1580 out << ", ";
1582 out << "::css::uno::RuntimeException, ::std::exception";
1584 out << ")";
1585 #if !defined DBG_UTIL
1586 out << " */";
1587 #endif
1590 void InterfaceType::dumpExceptionTypeName(
1591 FileStream & out, OUString const & prefix, sal_uInt32 index,
1592 OUString const & name)
1594 out << indent() << "::rtl::OUString the_" << prefix << "ExceptionName"
1595 << index << "( \"" << name << "\" );\n";
1598 sal_Int32 InterfaceType::dumpExceptionTypeNames(
1599 FileStream & out, OUString const & prefix,
1600 std::vector< OUString > const & exceptions, bool runtimeException)
1602 sal_Int32 count = 0;
1603 for (std::vector< OUString >::const_iterator i(exceptions.begin());
1604 i != exceptions.end(); ++i)
1606 if (*i != "com.sun.star.uno.RuntimeException") {
1607 dumpExceptionTypeName(out, prefix, count++, *i);
1610 if (runtimeException) {
1611 dumpExceptionTypeName(
1612 out, prefix, count++, "com.sun.star.uno.RuntimeException");
1614 if (count != 0) {
1615 out << indent() << "rtl_uString * the_" << prefix << "Exceptions[] = {";
1616 for (sal_Int32 i = 0; i != count; ++i) {
1617 out << (i == 0 ? " " : ", ") << "the_" << prefix << "ExceptionName"
1618 << i << ".pData";
1620 out << " };\n";
1622 return count;
1625 class ConstantGroup: public CppuType {
1626 public:
1627 ConstantGroup(
1628 rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
1629 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
1630 CppuType(name, typeMgr), entity_(entity)
1631 { assert(entity.is()); }
1633 bool hasConstants() const { return !entity_->getMembers().empty(); }
1635 private:
1636 virtual void dumpHFile(
1637 FileStream & out, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
1639 virtual void dumpHxxFile(
1640 FileStream & out, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
1642 virtual void dumpDeclaration(FileStream & out) SAL_OVERRIDE;
1644 rtl::Reference< unoidl::ConstantGroupEntity > entity_;
1647 void ConstantGroup::dumpHFile(
1648 FileStream & out, codemaker::cppumaker::Includes & includes)
1650 OUString headerDefine(dumpHeaderDefine(out, "HDL"));
1651 out << "\n";
1652 addDefaultHIncludes(includes);
1653 includes.dump(out, 0);
1654 out << "\n";
1655 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, true)) {
1656 out << "\n";
1658 out << "\n";
1659 dumpDeclaration(out);
1660 out << "\n";
1661 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, true)) {
1662 out << "\n";
1664 out << "\n#endif // "<< headerDefine << "\n";
1667 void ConstantGroup::dumpHxxFile(
1668 FileStream & out, codemaker::cppumaker::Includes &)
1670 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
1671 out << "\n";
1672 codemaker::cppumaker::Includes::dumpInclude(out, u2b(name_), false);
1673 out << "\n#endif // "<< headerDefine << "\n";
1676 void ConstantGroup::dumpDeclaration(FileStream & out) {
1677 for (std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator i(
1678 entity_->getMembers().begin());
1679 i != entity_->getMembers().end(); ++i)
1681 out << "static const ";
1682 switch (i->value.type) {
1683 case unoidl::ConstantValue::TYPE_BOOLEAN:
1684 out << "::sal_Bool";
1685 break;
1686 case unoidl::ConstantValue::TYPE_BYTE:
1687 out << "::sal_Int8";
1688 break;
1689 case unoidl::ConstantValue::TYPE_SHORT:
1690 out << "::sal_Int16";
1691 break;
1692 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
1693 out << "::sal_uInt16";
1694 break;
1695 case unoidl::ConstantValue::TYPE_LONG:
1696 out << "::sal_Int32";
1697 break;
1698 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
1699 out << "::sal_uInt32";
1700 break;
1701 case unoidl::ConstantValue::TYPE_HYPER:
1702 out << "::sal_Int64";
1703 break;
1704 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
1705 out << "::sal_uInt64";
1706 break;
1707 case unoidl::ConstantValue::TYPE_FLOAT:
1708 out << "float";
1709 break;
1710 case unoidl::ConstantValue::TYPE_DOUBLE:
1711 out << "double";
1712 break;
1714 out << " " << i->name << " = ";
1715 switch (i->value.type) {
1716 case unoidl::ConstantValue::TYPE_BOOLEAN:
1717 out << (i->value.booleanValue ? "sal_True" : "sal_False");
1718 break;
1719 case unoidl::ConstantValue::TYPE_BYTE:
1720 out << "(sal_Int8)" << OUString::number(i->value.byteValue);
1721 break;
1722 case unoidl::ConstantValue::TYPE_SHORT:
1723 out << "(sal_Int16)" << OUString::number(i->value.shortValue);
1724 break;
1725 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
1726 out << "(sal_uInt16)"
1727 << OUString::number(i->value.unsignedShortValue);
1728 break;
1729 case unoidl::ConstantValue::TYPE_LONG:
1730 // Avoid C++ compiler warnings about (un)signedness of literal
1731 // -2^31:
1732 if (i->value.longValue == SAL_MIN_INT32) {
1733 out << "SAL_MIN_INT32";
1734 } else {
1735 out << "(sal_Int32)" << OUString::number(i->value.longValue);
1737 break;
1738 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
1739 out << "(sal_uInt32)"
1740 << OUString::number(i->value.unsignedLongValue) << "U";
1741 break;
1742 case unoidl::ConstantValue::TYPE_HYPER:
1743 // Avoid C++ compiler warnings about (un)signedness of literal
1744 // -2^63:
1745 if (i->value.hyperValue == SAL_MIN_INT64) {
1746 out << "SAL_MIN_INT64";
1747 } else {
1748 out << "(sal_Int64) SAL_CONST_INT64("
1749 << OUString::number(i->value.hyperValue) << ")";
1751 break;
1752 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
1753 out << "SAL_CONST_UINT64("
1754 << OUString::number(i->value.unsignedHyperValue) << ")";
1755 break;
1756 case unoidl::ConstantValue::TYPE_FLOAT:
1757 out << "(float)" << OUString::number(i->value.floatValue);
1758 break;
1759 case unoidl::ConstantValue::TYPE_DOUBLE:
1760 out << "(double)" << OUString::number(i->value.doubleValue);
1761 break;
1763 out << ";\n";
1767 void dumpTypeParameterName(FileStream & out, OUString const & name) {
1768 // Prefix all type parameters with "typeparam_" to avoid problems when a
1769 // struct member has the same name as a type parameter, as in
1770 // struct<T> { T T; };
1771 out << "typeparam_" << name;
1774 class PlainStructType: public CppuType {
1775 public:
1776 PlainStructType(
1777 rtl::Reference< unoidl::PlainStructTypeEntity > const & entity,
1778 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
1779 CppuType(name, typeMgr), entity_(entity)
1780 { assert(entity.is()); }
1782 private:
1783 virtual sal_uInt32 checkInheritedMemberCount() const SAL_OVERRIDE
1784 { return getTotalMemberCount(entity_->getDirectBase()); }
1786 virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
1788 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
1790 virtual void dumpLightGetCppuType(FileStream & out) SAL_OVERRIDE;
1792 virtual void dumpNormalGetCppuType(FileStream & out) SAL_OVERRIDE;
1794 virtual void dumpComprehensiveGetCppuType(FileStream & out) SAL_OVERRIDE;
1796 virtual void addLightGetCppuTypeIncludes(
1797 codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
1799 virtual void addNormalGetCppuTypeIncludes(
1800 codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
1802 virtual void addComprehensiveGetCppuTypeIncludes(
1803 codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
1805 bool dumpBaseMembers(
1806 FileStream & out, OUString const & base, bool withType);
1808 sal_uInt32 getTotalMemberCount(OUString const & base) const;
1810 rtl::Reference< unoidl::PlainStructTypeEntity > entity_;
1813 void PlainStructType::dumpDeclaration(FileStream & out) {
1814 out << "\n#ifdef SAL_W32\n# pragma pack(push, 8)\n#endif\n\n" << indent()
1815 << "struct SAL_DLLPUBLIC_RTTI " << id_;
1816 OUString base(entity_->getDirectBase());
1817 if (!base.isEmpty()) {
1818 out << ": public " << codemaker::cpp::scopedCppName(u2b(base));
1820 out << " {\n";
1821 inc();
1822 out << indent() << "inline " << id_ << "();\n";
1823 if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
1824 out << "\n" << indent() << "inline " << id_ << "(";
1825 bool first = !dumpBaseMembers(out, base, true);
1826 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
1827 const_iterator i(entity_->getDirectMembers().begin());
1828 i != entity_->getDirectMembers().end(); ++i)
1830 if (!first) {
1831 out << ", ";
1833 dumpType(out, i->type, true, true);
1834 out << " " << i->name << "_";
1835 first = false;
1837 out << ");\n";
1839 if (!entity_->getDirectMembers().empty()) {
1840 out << "\n";
1841 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
1842 const_iterator i(entity_->getDirectMembers().begin());
1843 i != entity_->getDirectMembers().end(); ++i)
1845 out << indent();
1846 dumpType(out, i->type);
1847 out << " " << i->name;
1848 if (i == entity_->getDirectMembers().begin() && !base.isEmpty()
1849 && i->type != "hyper" && i->type != "unsigned hyper"
1850 && i->type != "double")
1852 out << " CPPU_GCC3_ALIGN("
1853 << codemaker::cpp::scopedCppName(u2b(base)) << ")";
1855 out << ";\n";
1858 dec();
1859 out << "};\n\n#ifdef SAL_W32\n# pragma pack(pop)\n#endif\n\n";
1862 void PlainStructType::dumpHxxFile(
1863 FileStream & out, codemaker::cppumaker::Includes & includes)
1865 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
1866 out << "\n";
1867 includes.dump(out, &name_);
1868 out << "\n";
1869 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
1870 out << "\n";
1872 out << "\ninline " << id_ << "::" << id_ << "()\n";
1873 inc();
1874 OUString base(entity_->getDirectBase());
1875 bool first = true;
1876 if (!base.isEmpty()) {
1877 out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
1878 << "()\n";
1879 first = false;
1881 for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
1882 entity_->getDirectMembers().begin());
1883 i != entity_->getDirectMembers().end(); ++i)
1885 out << indent() << (first ? ":" : ",") << " " << i->name;
1886 dumpInitializer(out, false, i->type);
1887 out << "\n";
1888 first = false;
1890 dec();
1891 out << "{\n}\n\n";
1892 if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
1893 out << "inline " << id_;
1894 out << "::" << id_ << "(";
1895 first = !dumpBaseMembers(out, base, true);
1896 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
1897 const_iterator i(entity_->getDirectMembers().begin());
1898 i != entity_->getDirectMembers().end(); ++i)
1900 if (!first) {
1901 out << ", ";
1903 dumpType(out, i->type, true, true);
1904 out << " " << i->name << "_";
1905 first = false;
1907 out << ")\n";
1908 inc();
1909 first = true;
1910 if (!base.isEmpty()) {
1911 out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
1912 << "(";
1913 dumpBaseMembers(out, base, false);
1914 out << ")\n";
1915 first = false;
1917 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
1918 const_iterator i(entity_->getDirectMembers().begin());
1919 i != entity_->getDirectMembers().end(); ++i)
1921 out << indent() << (first ? ":" : ",") << " " << i->name << "("
1922 << i->name << "_)\n";
1923 first = false;
1925 dec();
1926 out << "{\n}\n\n";
1928 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
1929 out << "\n";
1931 out << "\n";
1932 dumpGetCppuType(out);
1933 out << "\n#endif // "<< headerDefine << "\n";
1936 void PlainStructType::dumpLightGetCppuType(FileStream & out) {
1937 dumpGetCppuTypePreamble(out);
1938 out << indent()
1939 << ("//TODO: On certain platforms with weak memory models, the"
1940 " following code can result in some threads observing that the_type"
1941 " points to garbage\n")
1942 << indent()
1943 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
1944 << indent() << "if (the_type == 0) {\n";
1945 inc();
1946 out << indent() << "::typelib_static_type_init(&the_type, "
1947 << getTypeClass(name_, true) << ", \"" << name_ << "\");\n";
1948 dec();
1949 out << indent() << "}\n" << indent()
1950 << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
1951 dumpGetCppuTypePostamble(out);
1954 void PlainStructType::dumpNormalGetCppuType(FileStream & out) {
1955 dumpGetCppuTypePreamble(out);
1956 out << indent()
1957 << ("//TODO: On certain platforms with weak memory models, the"
1958 " following code can result in some threads observing that the_type"
1959 " points to garbage\n")
1960 << indent()
1961 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
1962 << indent() << "if (the_type == 0) {\n";
1963 inc();
1964 out << indent()
1965 << "::typelib_TypeDescriptionReference * the_members[] = {\n";
1966 inc();
1967 for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
1968 entity_->getDirectMembers().begin());
1969 i != entity_->getDirectMembers().end();)
1971 out << indent() << "::cppu::UnoType< ";
1972 dumpType(out, i->type, false, false, false, true);
1973 ++i;
1974 out << " >::get().getTypeLibType()"
1975 << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n";
1977 dec();
1978 out << indent() << "::typelib_static_struct_type_init(&the_type, \""
1979 << name_ << "\", ";
1980 if (entity_->getDirectBase().isEmpty()) {
1981 out << "0";
1982 } else {
1983 out << "::cppu::UnoType< ";
1984 dumpType(out, entity_->getDirectBase(), false, false, false, true);
1985 out << " >::get().getTypeLibType()";
1987 out << ", " << entity_->getDirectMembers().size() << ", the_members, 0);\n";
1988 dec();
1989 out << indent() << "}\n" << indent()
1990 << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
1991 dumpGetCppuTypePostamble(out);
1994 void PlainStructType::dumpComprehensiveGetCppuType(FileStream & out) {
1995 OUString staticTypeClass("the" + id_ + "Type");
1996 codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
1997 out << " namespace detail {\n\n" << indent() << "struct "
1998 << staticTypeClass
1999 << " : public rtl::StaticWithInit< ::css::uno::Type *, "
2000 << staticTypeClass << " >\n" << indent() << "{\n";
2001 inc();
2002 out << indent() << "::css::uno::Type * operator()() const\n"
2003 << indent() << "{\n";
2004 inc();
2005 out << indent() << "::rtl::OUString the_name( \"" << name_ << "\" );\n";
2006 std::map< OUString, sal_uInt32 > types;
2007 std::vector< unoidl::PlainStructTypeEntity::Member >::size_type n = 0;
2008 for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
2009 entity_->getDirectMembers().begin());
2010 i != entity_->getDirectMembers().end(); ++i)
2012 if (types.insert(
2013 std::map< OUString, sal_uInt32 >::value_type(
2014 i->type, static_cast< sal_uInt32 >(types.size()))).
2015 second)
2017 dumpCppuGetType(out, i->type, &name_);
2018 // For typedefs, use the resolved type name, as there will be no
2019 // information available about the typedef itself at runtime (the
2020 // above getCppuType call will make available information about the
2021 // resolved type); no extra #include for the resolved type is
2022 // needed, as the header for the typedef includes it already:
2023 out << indent() << "::rtl::OUString the_tname"
2024 << static_cast< sal_uInt32 >(types.size() - 1) << "( \""
2025 << resolveAllTypedefs(i->type) << "\" );\n";
2027 out << indent() << "::rtl::OUString the_name" << n++ << "( \""
2028 << i->name << "\" );\n";
2030 out << indent() << "::typelib_StructMember_Init the_members[] = {\n";
2031 inc();
2032 n = 0;
2033 for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
2034 entity_->getDirectMembers().begin());
2035 i != entity_->getDirectMembers().end();)
2037 out << indent() << "{ { " << getTypeClass(i->type, true)
2038 << ", the_tname" << types.find(i->type)->second
2039 << ".pData, the_name" << n++ << ".pData }, false }";
2040 ++i;
2041 out << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n";
2043 dec();
2044 out << indent() << "::typelib_TypeDescription * the_newType = 0;\n"
2045 << indent()
2046 << "::typelib_typedescription_newStruct(&the_newType, the_name.pData, ";
2047 if (entity_->getDirectBase().isEmpty()) {
2048 out << "0";
2049 } else {
2050 out << "::cppu::UnoType< ";
2051 dumpType(out, entity_->getDirectBase(), false, false, false, true);
2052 out << " >::get().getTypeLibType()";
2054 out << ", " << entity_->getDirectMembers().size() << ", the_members);\n"
2055 << indent() << "::typelib_typedescription_register(&the_newType);\n"
2056 << indent() << "::typelib_typedescription_release(the_newType);\n"
2057 << indent() << "return new ::css::uno::Type("
2058 << getTypeClass(name_) << ", the_name); // leaked\n";
2059 dec();
2060 out << indent() << "}\n";
2061 dec();
2062 out << indent() << "};\n";
2063 codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
2064 out << " }\n\n";
2065 dumpGetCppuTypePreamble(out);
2066 out << indent() << "return *detail::" << staticTypeClass << "::get();\n";
2067 dumpGetCppuTypePostamble(out);
2070 bool PlainStructType::dumpBaseMembers(
2071 FileStream & out, OUString const & base, bool withType)
2073 bool hasMember = false;
2074 if (!base.isEmpty()) {
2075 rtl::Reference< unoidl::Entity > ent;
2076 codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
2077 if (sort != codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE) {
2078 throw CannotDumpException(
2079 "plain struct type base " + base
2080 + " is not a plain struct type");
2082 rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
2083 dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()));
2084 assert(ent2.is());
2085 if (!ent2.is()) {
2086 return false;
2088 hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType);
2089 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
2090 const_iterator i(ent2->getDirectMembers().begin());
2091 i != ent2->getDirectMembers().end(); ++i)
2093 if (hasMember) {
2094 out << ", ";
2096 if (withType) {
2097 dumpType(out, i->type, true, true);
2098 out << " ";
2100 out << i->name << "_";
2101 hasMember = true;
2104 return hasMember;
2107 void PlainStructType::addLightGetCppuTypeIncludes(
2108 codemaker::cppumaker::Includes & includes) const
2110 includes.addType();
2111 includes.addCppuUnotypeHxx();
2112 includes.addSalTypesH();
2113 includes.addTypelibTypeclassH();
2114 includes.addTypelibTypedescriptionH();
2117 void PlainStructType::addNormalGetCppuTypeIncludes(
2118 codemaker::cppumaker::Includes & includes) const
2120 includes.addType();
2121 includes.addCppuUnotypeHxx();
2122 includes.addSalTypesH();
2123 includes.addTypelibTypeclassH();
2124 includes.addTypelibTypedescriptionH();
2127 void PlainStructType::addComprehensiveGetCppuTypeIncludes(
2128 codemaker::cppumaker::Includes & includes) const
2130 includes.addType();
2131 includes.addCppuUnotypeHxx();
2132 includes.addRtlInstanceHxx();
2133 includes.addRtlUstringH();
2134 includes.addRtlUstringHxx();
2135 includes.addSalTypesH();
2136 includes.addTypelibTypeclassH();
2137 includes.addTypelibTypedescriptionH();
2140 sal_uInt32 PlainStructType::getTotalMemberCount(OUString const & base) const {
2141 if (base.isEmpty()) {
2142 return 0;
2144 rtl::Reference< unoidl::Entity > ent;
2145 codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
2146 if (sort != codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE) {
2147 throw CannotDumpException(
2148 "plain struct type base " + base + " is not a plain struct type");
2150 rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
2151 dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()));
2152 assert(ent2.is());
2153 if (!ent2.is()) {
2154 return 0;
2156 return getTotalMemberCount(ent2->getDirectBase())
2157 + ent2->getDirectMembers().size(); //TODO: overflow
2160 class PolyStructType: public CppuType {
2161 public:
2162 PolyStructType(
2163 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
2164 entity,
2165 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
2166 CppuType(name, typeMgr), entity_(entity)
2167 { assert(entity.is()); }
2169 private:
2170 virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
2172 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
2174 virtual void dumpLightGetCppuType(FileStream & out) SAL_OVERRIDE;
2176 virtual void dumpNormalGetCppuType(FileStream & out) SAL_OVERRIDE;
2178 virtual void dumpComprehensiveGetCppuType(FileStream & out) SAL_OVERRIDE;
2180 virtual void addLightGetCppuTypeIncludes(
2181 codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
2183 virtual void addNormalGetCppuTypeIncludes(
2184 codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
2186 virtual void addComprehensiveGetCppuTypeIncludes(
2187 codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
2189 virtual bool isPolymorphic() const SAL_OVERRIDE { return true; }
2191 virtual void dumpTemplateHead(FileStream & out) const SAL_OVERRIDE;
2193 virtual void dumpTemplateParameters(FileStream & out) const SAL_OVERRIDE;
2195 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
2198 void PolyStructType::dumpDeclaration(FileStream & out) {
2199 out << "\n#ifdef SAL_W32\n# pragma pack(push, 8)\n#endif\n\n" << indent();
2200 dumpTemplateHead(out);
2201 out << "struct SAL_DLLPUBLIC_RTTI " << id_ << " {\n";
2202 inc();
2203 out << indent() << "inline " << id_ << "();\n";
2204 if (!entity_->getMembers().empty()) {
2205 out << "\n" << indent() << "inline " << id_ << "(";
2206 for (std::vector<
2207 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2208 const_iterator i(entity_->getMembers().begin());
2209 i != entity_->getMembers().end(); ++i)
2211 if (i != entity_->getMembers().begin()) {
2212 out << ", ";
2214 if (i->parameterized) {
2215 dumpTypeParameterName(out, i->type);
2216 out << " const &";
2217 } else {
2218 dumpType(out, i->type, true, true);
2220 out << " " << i->name << "_";
2222 out << ");\n\n";
2223 for (std::vector<
2224 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2225 const_iterator i(entity_->getMembers().begin());
2226 i != entity_->getMembers().end(); ++i)
2228 out << indent();
2229 if (i->parameterized) {
2230 dumpTypeParameterName(out, i->type);
2231 } else {
2232 dumpType(out, i->type);
2234 out << " " << i->name << ";\n";
2237 dec();
2238 out << "};\n\n#ifdef SAL_W32\n# pragma pack(pop)\n#endif\n\n";
2241 void PolyStructType::dumpHxxFile(
2242 FileStream & out, codemaker::cppumaker::Includes & includes)
2244 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
2245 out << "\n";
2246 includes.dump(out, &name_);
2247 out << "\n";
2248 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
2249 out << "\n";
2251 out << "\n";
2252 dumpTemplateHead(out);
2253 out << "inline " << id_;
2254 dumpTemplateParameters(out);
2255 out << "::" << id_ << "()\n";
2256 inc();
2257 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2258 const_iterator i(entity_->getMembers().begin());
2259 i != entity_->getMembers().end(); ++i)
2261 out << indent() << (i == entity_->getMembers().begin() ? ":" : ",")
2262 << " " << i->name;
2263 dumpInitializer(out, i->parameterized, i->type);
2264 out << "\n";
2266 dec();
2267 out << "{\n}\n\n";
2268 if (!entity_->getMembers().empty()) {
2269 dumpTemplateHead(out);
2270 out << "inline " << id_;
2271 dumpTemplateParameters(out);
2272 out << "::" << id_ << "(";
2273 for (std::vector<
2274 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2275 const_iterator i(entity_->getMembers().begin());
2276 i != entity_->getMembers().end(); ++i)
2278 if (i != entity_->getMembers().begin()) {
2279 out << ", ";
2281 if (i->parameterized) {
2282 dumpTypeParameterName(out, i->type);
2283 out << " const &";
2284 } else {
2285 dumpType(out, i->type, true, true);
2287 out << " " << i->name << "_";
2289 out << ")\n";
2290 inc();
2291 for (std::vector<
2292 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2293 const_iterator i(entity_->getMembers().begin());
2294 i != entity_->getMembers().end(); ++i)
2296 out << indent() << (i == entity_->getMembers().begin() ? ":" : ",")
2297 << " " << i->name << "(" << i->name << "_)\n";
2299 dec();
2300 out << "{\n}\n\n" << indent();
2301 dumpTemplateHead(out);
2302 out << "\n" << indent() << "inline " << id_;
2303 dumpTemplateParameters(out);
2304 out << "\n" << indent() << "make_" << id_ << "(";
2305 for (std::vector<
2306 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2307 const_iterator i(entity_->getMembers().begin());
2308 i != entity_->getMembers().end(); ++i)
2310 if (i != entity_->getMembers().begin()) {
2311 out << ", ";
2313 if (i->parameterized) {
2314 dumpTypeParameterName(out, i->type);
2315 out << " const &";
2316 } else {
2317 dumpType(out, i->type, true, true);
2319 out << " " << i->name << "_";
2321 out << ")\n" << indent() << "{\n";
2322 inc();
2323 out << indent() << "return " << id_;
2324 dumpTemplateParameters(out);
2325 out << "(";
2326 for (std::vector<
2327 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2328 const_iterator i(entity_->getMembers().begin());
2329 i != entity_->getMembers().end(); ++i)
2331 if (i != entity_->getMembers().begin()) {
2332 out << ", ";
2334 out << i->name << "_";
2336 out << ");\n";
2337 dec();
2338 out << indent() << "}\n\n";
2340 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
2341 out << "\n";
2343 out << "\n";
2344 dumpGetCppuType(out);
2345 out << "\n#endif // "<< headerDefine << "\n";
2348 void PolyStructType::dumpLightGetCppuType(FileStream & out) {
2349 dumpGetCppuTypePreamble(out);
2350 out << indent()
2351 << ("//TODO: On certain platforms with weak memory models, the"
2352 " following code can result in some threads observing that the_type"
2353 " points to garbage\n")
2354 << indent()
2355 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
2356 << indent() << "if (the_type == 0) {\n";
2357 inc();
2358 out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
2359 << "<\");\n";
2360 for (std::vector< OUString >::const_iterator i(
2361 entity_->getTypeParameters().begin());
2362 i != entity_->getTypeParameters().end();)
2364 out << indent()
2365 << ("the_buffer.append(::rtl::OUStringToOString("
2366 "::cppu::getTypeFavourChar(static_cast< ");
2367 dumpTypeParameterName(out, *i);
2368 out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
2369 ++i;
2370 if (i != entity_->getTypeParameters().end()) {
2371 out << indent() << "the_buffer.append(',');\n";
2374 out << indent() << "the_buffer.append('>');\n" << indent()
2375 << "::typelib_static_type_init(&the_type, " << getTypeClass(name_, true)
2376 << ", the_buffer.getStr());\n";
2377 dec();
2378 out << indent() << "}\n" << indent()
2379 << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
2380 dumpGetCppuTypePostamble(out);
2383 void PolyStructType::dumpNormalGetCppuType(FileStream & out) {
2384 dumpGetCppuTypePreamble(out);
2385 out << indent()
2386 << ("//TODO: On certain platforms with weak memory models, the"
2387 " following code can result in some threads observing that the_type"
2388 " points to garbage\n")
2389 << indent()
2390 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
2391 << indent() << "if (the_type == 0) {\n";
2392 inc();
2393 out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
2394 << "<\");\n";
2395 for (std::vector< OUString >::const_iterator i(
2396 entity_->getTypeParameters().begin());
2397 i != entity_->getTypeParameters().end();)
2399 out << indent()
2400 << ("the_buffer.append(::rtl::OUStringToOString("
2401 "::cppu::getTypeFavourChar(static_cast< ");
2402 dumpTypeParameterName(out, *i);
2403 out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
2404 ++i;
2405 if (i != entity_->getTypeParameters().end()) {
2406 out << indent() << "the_buffer.append(',');\n";
2409 out << indent() << "the_buffer.append('>');\n" << indent()
2410 << "::typelib_TypeDescriptionReference * the_members[] = {\n";
2411 inc();
2412 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2413 const_iterator i(entity_->getMembers().begin());
2414 i != entity_->getMembers().end();)
2416 out << indent();
2417 if (i->parameterized) {
2418 out << "::cppu::getTypeFavourChar(static_cast< ";
2419 dumpTypeParameterName(out, i->type);
2420 out << " * >(0))";
2421 } else {
2422 out << "::cppu::UnoType< ";
2423 dumpType(out, i->type, false, false, false, true);
2424 out << " >::get()";
2426 ++i;
2427 out << ".getTypeLibType()"
2428 << (i == entity_->getMembers().end() ? " };" : ",") << "\n";
2430 dec();
2431 out << indent() << "static ::sal_Bool const the_parameterizedTypes[] = { ";
2432 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2433 const_iterator i(entity_->getMembers().begin());
2434 i != entity_->getMembers().end(); ++i)
2436 if (i != entity_->getMembers().begin()) {
2437 out << ", ";
2439 out << (i->parameterized ? "true" : "false");
2441 out << " };\n" << indent()
2442 << ("::typelib_static_struct_type_init(&the_type, the_buffer.getStr(),"
2443 " 0, ")
2444 << entity_->getMembers().size()
2445 << ", the_members, the_parameterizedTypes);\n";
2446 dec();
2447 out << indent() << "}\n" << indent()
2448 << ("return *reinterpret_cast< ::css::uno::Type * >("
2449 "&the_type);\n");
2450 dumpGetCppuTypePostamble(out);
2453 void PolyStructType::dumpComprehensiveGetCppuType(FileStream & out) {
2454 out << "namespace cppu { namespace detail {\n\n" << indent();
2455 dumpTemplateHead(out);
2456 OUString staticTypeClass("the" + id_ + "Type");
2457 out << "struct " << staticTypeClass
2458 << " : public rtl::StaticWithInit< ::css::uno::Type *, "
2459 << staticTypeClass;
2460 dumpTemplateParameters(out);
2461 out << " >\n" << indent() << "{\n";
2462 inc();
2463 out << indent() << "::css::uno::Type * operator()() const\n"
2464 << indent() << "{\n";
2465 inc();
2466 out << indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent()
2467 << "the_buffer.append(\"" << name_ << "<\");\n";
2468 for (std::vector< OUString >::const_iterator i(
2469 entity_->getTypeParameters().begin());
2470 i != entity_->getTypeParameters().end();)
2472 out << indent()
2473 << "the_buffer.append(::cppu::getTypeFavourChar(static_cast< ";
2474 dumpTypeParameterName(out, *i);
2475 out << " * >(0)).getTypeName());\n";
2476 ++i;
2477 if (i != entity_->getTypeParameters().end()) {
2478 out << indent()
2479 << ("the_buffer.append("
2480 "static_cast< ::sal_Unicode >(','));\n");
2483 out << indent() << "the_buffer.append(static_cast< ::sal_Unicode >('>'));\n"
2484 << indent()
2485 << "::rtl::OUString the_name(the_buffer.makeStringAndClear());\n";
2486 std::map< OUString, sal_uInt32 > parameters;
2487 std::map< OUString, sal_uInt32 > types;
2488 std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2489 size_type n = 0;
2490 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2491 const_iterator i(entity_->getMembers().begin());
2492 i != entity_->getMembers().end(); ++i)
2494 if (i->parameterized) {
2495 if (parameters.insert(
2496 std::map< OUString, sal_uInt32 >::value_type(
2497 i->type, static_cast< sal_uInt32 >(parameters.size()))).
2498 second)
2500 sal_uInt32 k = static_cast< sal_uInt32 >(parameters.size() - 1);
2501 out << indent()
2502 << "::css::uno::Type const & the_ptype" << k
2503 << " = ::cppu::getTypeFavourChar(static_cast< ";
2504 dumpTypeParameterName(out, i->type);
2505 out << " * >(0));\n" << indent()
2506 << "::typelib_TypeClass the_pclass" << k
2507 << " = (::typelib_TypeClass) the_ptype" << k
2508 << ".getTypeClass();\n" << indent()
2509 << "::rtl::OUString the_pname" << k << "(the_ptype" << k
2510 << ".getTypeName());\n";
2512 } else if (types.insert(
2513 std::map< OUString, sal_uInt32 >::value_type(
2514 i->type, static_cast< sal_uInt32 >(types.size()))).
2515 second)
2517 dumpCppuGetType(out, i->type, &name_);
2518 // For typedefs, use the resolved type name, as there will be no
2519 // information available about the typedef itself at runtime (the
2520 // above getCppuType call will make available information about the
2521 // resolved type); no extra #include for the resolved type is
2522 // needed, as the header for the typedef includes it already:
2523 out << indent() << "::rtl::OUString the_tname"
2524 << static_cast< sal_uInt32 >(types.size() - 1) << "( \""
2525 << resolveAllTypedefs(i->type) << "\" );\n";
2527 out << indent() << "::rtl::OUString the_name" << n++ << "( \""
2528 << i->name << "\" );\n";
2530 out << indent() << "::typelib_StructMember_Init the_members[] = {\n";
2531 inc();
2532 n = 0;
2533 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2534 const_iterator i(entity_->getMembers().begin());
2535 i != entity_->getMembers().end();)
2537 out << indent() << "{ { ";
2538 if (i->parameterized) {
2539 sal_uInt32 k = parameters.find(i->type)->second;
2540 out << "the_pclass" << k << ", the_pname" << k << ".pData";
2541 } else {
2542 out << getTypeClass(i->type, true) << ", the_tname"
2543 << types.find(i->type)->second << ".pData";
2545 out << ", the_name" << n++ << ".pData }, "
2546 << (i->parameterized ? "true" : "false") << " }";
2547 ++i;
2548 out << (i == entity_->getMembers().end() ? " };" : ",") << "\n";
2550 dec();
2551 out << indent() << "::typelib_TypeDescription * the_newType = 0;\n";
2552 out << indent()
2553 << ("::typelib_typedescription_newStruct(&the_newType, the_name.pData,"
2554 " 0, ")
2555 << entity_->getMembers().size() << ", the_members);\n" << indent()
2556 << "::typelib_typedescription_register(&the_newType);\n" << indent()
2557 << "::typelib_typedescription_release(the_newType);\n" << indent()
2558 << "return new ::css::uno::Type(" << getTypeClass(name_)
2559 << ", the_name); // leaked\n";
2560 dec();
2561 out << indent() << "}\n";
2562 dec();
2563 out << indent() << "};\n } }\n\n";
2564 dumpGetCppuTypePreamble(out);
2565 out << indent() << "return *detail::" << staticTypeClass;
2566 dumpTemplateParameters(out);
2567 out << "::get();\n";
2568 dumpGetCppuTypePostamble(out);
2571 void PolyStructType::addLightGetCppuTypeIncludes(
2572 codemaker::cppumaker::Includes & includes) const
2574 includes.addType();
2575 includes.addCppuUnotypeHxx();
2576 includes.addSalTypesH();
2577 includes.addTypelibTypeclassH();
2578 includes.addTypelibTypedescriptionH();
2579 includes.addRtlStrbufHxx();
2580 includes.addRtlTextencH();
2581 includes.addRtlUstringHxx();
2584 void PolyStructType::addNormalGetCppuTypeIncludes(
2585 codemaker::cppumaker::Includes & includes) const
2587 includes.addType();
2588 includes.addCppuUnotypeHxx();
2589 includes.addSalTypesH();
2590 includes.addTypelibTypeclassH();
2591 includes.addTypelibTypedescriptionH();
2592 includes.addRtlStrbufHxx();
2593 includes.addRtlTextencH();
2594 includes.addRtlUstringHxx();
2597 void PolyStructType::addComprehensiveGetCppuTypeIncludes(
2598 codemaker::cppumaker::Includes & includes) const
2600 includes.addType();
2601 includes.addCppuUnotypeHxx();
2602 includes.addRtlInstanceHxx();
2603 includes.addRtlUstringH();
2604 includes.addRtlUstringHxx();
2605 includes.addSalTypesH();
2606 includes.addTypelibTypeclassH();
2607 includes.addTypelibTypedescriptionH();
2608 includes.addRtlStringH();
2609 includes.addRtlUstrbufHxx();
2612 void PolyStructType::dumpTemplateHead(FileStream & out) const {
2613 out << "template< ";
2614 for (std::vector< OUString >::const_iterator i(
2615 entity_->getTypeParameters().begin());
2616 i != entity_->getTypeParameters().end(); ++i)
2618 if (i != entity_->getTypeParameters().begin()) {
2619 out << ", ";
2621 out << "typename ";
2622 dumpTypeParameterName(out, *i);
2624 out << " > ";
2627 void PolyStructType::dumpTemplateParameters(FileStream & out) const {
2628 out << "< ";
2629 for (std::vector< OUString >::const_iterator i(
2630 entity_->getTypeParameters().begin());
2631 i != entity_->getTypeParameters().end(); ++i)
2633 if (i != entity_->getTypeParameters().begin()) {
2634 out << ", ";
2636 dumpTypeParameterName(out, *i);
2638 out << " >";
2641 OUString typeToIdentifier(OUString const & name) {
2642 sal_Int32 k;
2643 OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k)));
2644 OUStringBuffer b;
2645 for (sal_Int32 i = 0; i != k; ++i) {
2646 b.append("seq_");
2648 b.append(n);
2649 b.replace(' ', '_');
2650 b.replace(',', '_');
2651 b.replace('.', '_');
2652 b.replace('<', '_');
2653 b.replace('>', '_');
2654 return b.makeStringAndClear();
2657 class ExceptionType: public CppuType {
2658 public:
2659 ExceptionType(
2660 rtl::Reference< unoidl::ExceptionTypeEntity > const & entity,
2661 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
2662 CppuType(name, typeMgr), entity_(entity)
2663 { assert(entity.is()); }
2665 private:
2666 virtual void dumpHxxFile(
2667 FileStream & out, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
2669 virtual void addComprehensiveGetCppuTypeIncludes(
2670 codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
2672 virtual void dumpLightGetCppuType(FileStream & out) SAL_OVERRIDE;
2674 virtual void dumpNormalGetCppuType(FileStream & out) SAL_OVERRIDE;
2676 virtual void dumpComprehensiveGetCppuType(FileStream & out) SAL_OVERRIDE;
2678 virtual sal_uInt32 checkInheritedMemberCount() const SAL_OVERRIDE
2679 { return getTotalMemberCount(entity_->getDirectBase()); }
2681 virtual void dumpDeclaration(FileStream & out) SAL_OVERRIDE;
2683 bool dumpBaseMembers(
2684 FileStream & out, OUString const & base, bool withType,
2685 bool eligibleForDefaults);
2687 sal_uInt32 getTotalMemberCount(OUString const & base) const;
2689 rtl::Reference< unoidl::ExceptionTypeEntity > entity_;
2692 void ExceptionType::addComprehensiveGetCppuTypeIncludes(
2693 codemaker::cppumaker::Includes & includes) const
2695 includes.addCppuUnotypeHxx();
2696 includes.addRtlInstanceHxx(); // using rtl::StaticWithInit
2699 void ExceptionType::dumpHxxFile(
2700 FileStream & out, codemaker::cppumaker::Includes & includes)
2702 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
2703 out << "\n";
2704 addDefaultHxxIncludes(includes);
2705 includes.dump(out, &name_);
2706 out << "\n";
2707 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
2708 out << "\n";
2710 out << "\ninline " << id_ << "::" << id_ << "()\n";
2711 inc();
2712 OUString base(entity_->getDirectBase());
2713 bool first = true;
2714 if (!base.isEmpty()) {
2715 out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
2716 << "()\n";
2717 first = false;
2719 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
2720 entity_->getDirectMembers().begin());
2721 i != entity_->getDirectMembers().end(); ++i)
2723 out << indent() << (first ? ":" : ",") << " ";
2724 out << i->name;
2725 dumpInitializer(out, false, i->type);
2726 out << "\n";
2727 first = false;
2729 dec();
2730 out << "{";
2731 if (!m_cppuTypeDynamic) {
2732 out << "\n";
2733 inc();
2734 dumpCppuGetType(out, name_);
2735 dec();
2736 } else {
2737 out << " ";
2739 out << "}\n\n";
2740 if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
2741 out << indent() << "inline " << id_ << "::" << id_ << "(";
2742 first = !dumpBaseMembers(out, base, true, false);
2743 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2744 i(entity_->getDirectMembers().begin());
2745 i != entity_->getDirectMembers().end(); ++i)
2747 if (!first) {
2748 out << ", ";
2750 dumpType(out, i->type, true, true);
2751 out << " " << i->name << "_";
2752 first = false;
2754 out << ")\n";
2755 inc();
2756 first = true;
2757 if (!base.isEmpty()) {
2758 out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
2759 << "(";
2760 dumpBaseMembers(out, base, false, false);
2761 out << ")\n";
2762 first = false;
2764 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2765 i(entity_->getDirectMembers().begin());
2766 i != entity_->getDirectMembers().end(); ++i)
2768 out << indent() << (first ? ":" : ",") << " " << i->name << "("
2769 << i->name << "_)\n";
2770 first = false;
2772 dec();
2773 out << "{";
2774 if (!m_cppuTypeDynamic) {
2775 out << "\n";
2776 inc();
2777 dumpCppuGetType(out, name_);
2778 dec();
2779 } else {
2780 out << " ";
2782 out << "}\n\n";
2784 out << indent() << id_ << "::" << id_ << "(" << id_
2785 << " const & the_other)";
2786 first = true;
2787 if (!base.isEmpty()) {
2788 out << ": " << codemaker::cpp::scopedCppName(u2b(base))
2789 << "(the_other)";
2790 first = false;
2792 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
2793 entity_->getDirectMembers().begin());
2794 i != entity_->getDirectMembers().end(); ++i)
2796 out << (first ? ":" : ",") << " " << i->name << "(the_other." << i->name
2797 << ")";
2798 first = false;
2800 out << indent() << " {}\n\n" << indent() << id_ << "::~" << id_
2801 << "() {}\n\n" << indent() << id_ << " & " << id_ << "::operator =("
2802 << id_ << " const & the_other) {\n";
2803 inc();
2804 out << indent()
2805 << ("//TODO: Just like its implicitly-defined counterpart, this"
2806 " function definition is not exception-safe\n");
2807 if (!base.isEmpty()) {
2808 out << indent() << codemaker::cpp::scopedCppName(u2b(base))
2809 << "::operator =(the_other);\n";
2811 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
2812 entity_->getDirectMembers().begin());
2813 i != entity_->getDirectMembers().end(); ++i)
2815 out << indent() << i->name << " = the_other." << i->name << ";\n";
2817 out << indent() << "return *this;\n";
2818 dec();
2819 out << indent() << "}\n\n";
2820 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
2821 out << "\n";
2823 out << "\n";
2824 dumpGetCppuType(out);
2825 out << "\n#endif // "<< headerDefine << "\n";
2828 void ExceptionType::dumpLightGetCppuType(FileStream & out) {
2829 dumpGetCppuTypePreamble(out);
2830 out << indent()
2831 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
2832 << indent() << "if ( !the_type )\n" << indent() << "{\n";
2833 inc();
2834 out << indent() << "typelib_static_type_init( &the_type, "
2835 << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n";
2836 dec();
2837 out << indent() << "}\n" << indent()
2838 << ("return * reinterpret_cast< ::css::uno::Type * >("
2839 " &the_type );\n");
2840 dumpGetCppuTypePostamble(out);
2843 void ExceptionType::dumpNormalGetCppuType(FileStream & out) {
2844 dumpGetCppuTypePreamble(out);
2845 out << indent()
2846 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
2847 << indent() << "if ( !the_type )\n" << indent() << "{\n";
2848 inc();
2849 OUString base(entity_->getDirectBase());
2850 bool baseException = false;
2851 if (!base.isEmpty()) {
2852 if (base == "com.sun.star.uno.Exception") {
2853 baseException = true;
2854 } else {
2855 out << indent()
2856 << ("const ::css::uno::Type& rBaseType ="
2857 " ::cppu::UnoType< ");
2858 dumpType(out, base, true, false, false, true);
2859 out << " >::get();\n\n";
2862 if (!entity_->getDirectMembers().empty()) {
2863 out << indent() << "typelib_TypeDescriptionReference * aMemberRefs["
2864 << entity_->getDirectMembers().size() << "];\n";
2865 std::set< OUString > seen;
2866 std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0;
2867 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2868 i(entity_->getDirectMembers().begin());
2869 i != entity_->getDirectMembers().end(); ++i)
2871 OUString type(resolveAllTypedefs(i->type));
2872 OUString modType(typeToIdentifier(type));
2873 if (seen.insert(type).second) {
2874 out << indent()
2875 << "const ::css::uno::Type& rMemberType_"
2876 << modType << " = ::cppu::UnoType< ";
2877 dumpType(out, type, false, false, false, true);
2878 out << " >::get();\n";
2880 out << indent() << "aMemberRefs[" << n++ << "] = rMemberType_"
2881 << modType << ".getTypeLibType();\n";
2883 out << "\n";
2885 out << indent() << "typelib_static_compound_type_init( &the_type, "
2886 << getTypeClass(name_, true) << ", \"" << name_ << "\", ";
2887 if (baseException) {
2888 out << ("* ::typelib_static_type_getByTypeClass("
2889 " typelib_TypeClass_EXCEPTION )");
2890 } else if (base.isEmpty()) {
2891 out << "0";
2892 } else {
2893 out << "rBaseType.getTypeLibType()";
2895 out << ", " << entity_->getDirectMembers().size() << ", "
2896 << (entity_->getDirectMembers().empty() ? "0" : "aMemberRefs")
2897 << " );\n";
2898 dec();
2899 out << indent() << "}\n" << indent()
2900 << ("return * reinterpret_cast< const ::css::uno::Type * >("
2901 " &the_type );\n");
2902 dumpGetCppuTypePostamble(out);
2905 void ExceptionType::dumpComprehensiveGetCppuType(FileStream & out) {
2906 codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
2907 out << " namespace detail {\n\n";
2908 OUString staticTypeClass("the" + id_ + "Type");
2909 out << indent() << "struct " << staticTypeClass
2910 << " : public rtl::StaticWithInit< ::css::uno::Type *, "
2911 << staticTypeClass << " >\n" << indent() << "{\n";
2912 inc();
2913 out << indent() << "::css::uno::Type * operator()() const\n"
2914 << indent() << "{\n";
2915 inc();
2916 out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n"
2917 << indent() << "// Start inline typedescription generation\n"
2918 << indent() << "typelib_TypeDescription * pTD = 0;\n";
2919 OUString base(entity_->getDirectBase());
2920 if (!base.isEmpty()) {
2921 out << indent()
2922 << ("const ::css::uno::Type& rSuperType ="
2923 " ::cppu::UnoType< ");
2924 dumpType(out, base, false, false, false, true);
2925 out << " >::get();\n";
2927 std::set< OUString > seen;
2928 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
2929 entity_->getDirectMembers().begin());
2930 i != entity_->getDirectMembers().end(); ++i)
2932 if (seen.insert(i->type).second) {
2933 dumpCppuGetType(out, i->type);
2936 if (!entity_->getDirectMembers().empty()) {
2937 out << "\n" << indent() << "typelib_CompoundMember_Init aMembers["
2938 << entity_->getDirectMembers().size() << "];\n";
2939 std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0;
2940 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2941 i(entity_->getDirectMembers().begin());
2942 i != entity_->getDirectMembers().end(); ++i)
2944 OUString type(resolveAllTypedefs(i->type));
2945 out << indent() << "::rtl::OUString sMemberType" << n << "( \""
2946 << type << "\" );\n" << indent()
2947 << "::rtl::OUString sMemberName" << n << "( \"" << i->name
2948 << "\" );\n" << indent() << "aMembers[" << n
2949 << "].eTypeClass = (typelib_TypeClass)" << getTypeClass(type)
2950 << ";\n" << indent() << "aMembers[" << n
2951 << "].pTypeName = sMemberType" << n << ".pData;\n" << indent()
2952 << "aMembers[" << n << "].pMemberName = sMemberName" << n
2953 << ".pData;\n";
2954 ++n;
2957 out << "\n" << indent() << "typelib_typedescription_new(\n";
2958 inc();
2959 out << indent() << "&pTD,\n" << indent() << "(typelib_TypeClass)"
2960 << getTypeClass(name_) << ", sTypeName.pData,\n" << indent()
2961 << (base.isEmpty() ? "0" : "rSuperType.getTypeLibType()") << ",\n"
2962 << indent() << entity_->getDirectMembers().size() << ",\n" << indent()
2963 << (entity_->getDirectMembers().empty() ? "0" : "aMembers")
2964 << " );\n\n";
2965 dec();
2966 out << indent()
2967 << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
2968 " );\n\n")
2969 << indent() << "typelib_typedescription_release( pTD );\n" << indent()
2970 << "// End inline typedescription generation\n\n" << indent()
2971 << "return new ::css::uno::Type( " << getTypeClass(name_)
2972 << ", sTypeName ); // leaked\n";
2973 dec();
2974 out << indent() << "}\n";
2975 dec();
2976 out << indent() << "};\n\n";
2977 codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
2978 out << " }\n\n";
2979 dumpGetCppuTypePreamble(out);
2980 out << indent() << "return *detail::" << staticTypeClass << "::get();\n";
2981 dumpGetCppuTypePostamble(out);
2984 void ExceptionType::dumpDeclaration(FileStream & out) {
2985 out << "\nclass CPPU_GCC_DLLPUBLIC_EXPORT " << id_;
2986 OUString base(entity_->getDirectBase());
2987 if (!base.isEmpty()) {
2988 out << " : public " << codemaker::cpp::scopedCppName(u2b(base));
2990 out << "\n{\npublic:\n";
2991 inc();
2992 out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
2993 << "();\n\n";
2994 if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
2995 out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(";
2996 bool eligibleForDefaults = entity_->getDirectMembers().empty();
2997 bool first = !dumpBaseMembers(out, base, true, eligibleForDefaults);
2998 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2999 i(entity_->getDirectMembers().begin());
3000 i != entity_->getDirectMembers().end(); ++i)
3002 if (!first) {
3003 out << ", ";
3005 dumpType(out, i->type, true, true);
3006 out << " " << i->name << "_";
3007 first = false;
3009 out << ");\n\n";
3011 out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(" << id_
3012 << " const &);\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE ~"
3013 << id_ << "();\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
3014 << " & operator =(" << id_ << " const &);\n\n";
3015 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
3016 entity_->getDirectMembers().begin());
3017 i != entity_->getDirectMembers().end(); ++i)
3019 out << indent();
3020 dumpType(out, i->type);
3021 out << " " << i->name;
3022 if (i == entity_->getDirectMembers().begin() && !base.isEmpty()
3023 && i->type != "hyper" && i->type != "unsigned hyper"
3024 && i->type != "double")
3026 out << " CPPU_GCC3_ALIGN( "
3027 << codemaker::cpp::scopedCppName(u2b(base)) << " )";
3029 out << ";\n";
3031 dec();
3032 out << "};\n\n";
3035 bool ExceptionType::dumpBaseMembers(
3036 FileStream & out, OUString const & base, bool withType, bool eligibleForDefaults)
3038 bool hasMember = false;
3039 if (!base.isEmpty()) {
3040 rtl::Reference< unoidl::Entity > ent;
3041 codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
3042 if (sort != codemaker::UnoType::SORT_EXCEPTION_TYPE) {
3043 throw CannotDumpException(
3044 "exception type base " + base + " is not an exception type");
3046 rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
3047 dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
3048 assert(ent2.is());
3049 if (!ent2.is()) {
3050 return false;
3052 hasMember = dumpBaseMembers( out, ent2->getDirectBase(), withType,
3053 eligibleForDefaults && ent2->getDirectMembers().empty() );
3054 int memberCount = 0;
3055 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
3056 i(ent2->getDirectMembers().begin());
3057 i != ent2->getDirectMembers().end(); ++i, ++memberCount)
3059 if (hasMember) {
3060 out << ", ";
3062 if (withType) {
3063 dumpType(out, i->type, true, true);
3064 out << " ";
3066 out << i->name << "_";
3067 // We want to provide a default parameter value for uno::Exception subtype
3068 // constructors, since most of the time we don't pass a Context object in to the exception
3069 // throw sites.
3070 if (eligibleForDefaults
3071 && base == "com.sun.star.uno.Exception"
3072 && memberCount == 1
3073 && i->name == "Context"
3074 && i->type == "com.sun.star.uno.XInterface") {
3075 out << " = ::css::uno::Reference< ::css::uno::XInterface >()";
3077 hasMember = true;
3080 return hasMember;
3083 sal_uInt32 ExceptionType::getTotalMemberCount(OUString const & base) const {
3084 if (base.isEmpty()) {
3085 return 0;
3087 rtl::Reference< unoidl::Entity > ent;
3088 codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
3089 if (sort != codemaker::UnoType::SORT_EXCEPTION_TYPE) {
3090 throw CannotDumpException(
3091 "exception type base " + base + " is not an exception type");
3093 unoidl::ExceptionTypeEntity& ent2(
3094 dynamic_cast< unoidl::ExceptionTypeEntity&>(*ent.get()));
3095 return getTotalMemberCount(ent2.getDirectBase())
3096 + ent2.getDirectMembers().size(); //TODO: overflow
3099 class EnumType: public CppuType {
3100 public:
3101 EnumType(
3102 rtl::Reference< unoidl::EnumTypeEntity > const & entity,
3103 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
3104 CppuType(name, typeMgr), entity_(entity)
3105 { assert(entity.is()); }
3107 private:
3108 virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
3110 virtual void addComprehensiveGetCppuTypeIncludes(
3111 codemaker::cppumaker::Includes & includes) const SAL_OVERRIDE;
3113 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
3115 void dumpNormalGetCppuType(FileStream& o) SAL_OVERRIDE;
3116 void dumpComprehensiveGetCppuType(FileStream& o) SAL_OVERRIDE;
3118 rtl::Reference< unoidl::EnumTypeEntity > entity_;
3121 void EnumType::addComprehensiveGetCppuTypeIncludes(
3122 codemaker::cppumaker::Includes & includes) const
3124 includes.addCppuUnotypeHxx();
3125 includes.addRtlInstanceHxx(); // using rtl::StaticWithInit
3128 void EnumType::dumpDeclaration(FileStream& o)
3130 o << "\nenum SAL_DLLPUBLIC_RTTI " << id_ << "\n{\n";
3131 inc();
3133 for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
3134 entity_->getMembers().begin());
3135 i != entity_->getMembers().end(); ++i)
3137 o << indent() << id_ << "_" << u2b(i->name) << " = " << i->value
3138 << ",\n";
3141 o << indent() << id_ << "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n";
3143 dec();
3144 o << "};\n\n";
3147 void EnumType::dumpHxxFile(
3148 FileStream& o, codemaker::cppumaker::Includes & includes)
3150 OUString headerDefine(dumpHeaderDefine(o, "HPP"));
3151 o << "\n";
3153 addDefaultHxxIncludes(includes);
3154 includes.dump(o, &name_);
3155 o << "\n";
3157 dumpGetCppuType(o);
3159 o << "\n#endif // "<< headerDefine << "\n";
3162 void EnumType::dumpNormalGetCppuType(FileStream& o)
3164 dumpGetCppuTypePreamble(o);
3166 o << indent()
3167 << "static typelib_TypeDescriptionReference * the_type = 0;\n";
3169 o << indent() << "if ( !the_type )\n" << indent() << "{\n";
3170 inc();
3172 o << indent() << "typelib_static_enum_type_init( &the_type,\n";
3173 inc(31);
3174 o << indent() << "\"" << name_ << "\",\n"
3175 << indent() << codemaker::cpp::scopedCppName(u2b(name_)) << "_"
3176 << u2b(entity_->getMembers()[0].name) << " );\n";
3177 dec(31);
3178 dec();
3179 o << indent() << "}\n";
3180 o << indent()
3181 << ("return * reinterpret_cast< ::css::uno::Type * >("
3182 " &the_type );\n");
3183 dumpGetCppuTypePostamble(o);
3186 void EnumType::dumpComprehensiveGetCppuType(FileStream& o)
3188 if (!isPolymorphic())
3189 codemaker::cppumaker::dumpNamespaceOpen(o, name_, false);
3190 else
3191 o << "namespace cppu { ";
3192 o << " namespace detail {\n\n";
3194 OUString sStaticTypeClass("the" + id_ + "Type");
3195 o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::css::uno::Type *, " << sStaticTypeClass << " >\n";
3196 o << indent() << "{\n";
3197 inc();
3198 o << indent() << "::css::uno::Type * operator()() const\n";
3199 o << indent() << "{\n";
3201 inc();
3202 o << indent() << "::rtl::OUString sTypeName( \"" << name_
3203 << "\" );\n\n";
3205 o << indent() << "// Start inline typedescription generation\n"
3206 << indent() << "typelib_TypeDescription * pTD = 0;\n\n";
3208 o << indent() << "rtl_uString* enumValueNames["
3209 << entity_->getMembers().size() << "];\n";
3210 std::vector< unoidl::EnumTypeEntity::Member >::size_type n = 0;
3211 for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
3212 entity_->getMembers().begin());
3213 i != entity_->getMembers().end(); ++i)
3215 o << indent() << "::rtl::OUString sEnumValue" << n << "( \""
3216 << u2b(i->name) << "\" );\n";
3217 o << indent() << "enumValueNames[" << n << "] = sEnumValue" << n
3218 << ".pData;\n";
3219 ++n;
3222 o << "\n" << indent() << "sal_Int32 enumValues["
3223 << entity_->getMembers().size() << "];\n";
3224 n = 0;
3225 for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
3226 entity_->getMembers().begin());
3227 i != entity_->getMembers().end(); ++i)
3229 o << indent() << "enumValues[" << n++ << "] = " << i->value << ";\n";
3232 o << "\n" << indent() << "typelib_typedescription_newEnum( &pTD,\n";
3233 inc();
3234 o << indent() << "sTypeName.pData,\n"
3235 << indent() << "(sal_Int32)"
3236 << codemaker::cpp::scopedCppName(u2b(name_), false) << "_"
3237 << u2b(entity_->getMembers()[0].name) << ",\n"
3238 << indent() << entity_->getMembers().size()
3239 << ", enumValueNames, enumValues );\n\n";
3240 dec();
3242 o << indent()
3243 << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
3244 " );\n");
3245 o << indent() << "typelib_typedescription_release( pTD );\n"
3246 << indent() << "// End inline typedescription generation\n\n";
3248 o << indent() << "return new ::css::uno::Type( "
3249 << getTypeClass(name_) << ", sTypeName ); // leaked\n";
3251 dec();
3252 o << indent() << "}\n";
3253 dec();
3254 o << indent() << "};\n\n";
3256 if (!isPolymorphic())
3257 codemaker::cppumaker::dumpNamespaceClose(o, name_, false);
3258 else
3259 o << " }";
3260 o << " }\n\n";
3262 dumpGetCppuTypePreamble(o);
3263 o << indent() << "return *detail::" << sStaticTypeClass << "::get();\n";
3264 dumpGetCppuTypePostamble(o);
3267 class Typedef: public CppuType {
3268 public:
3269 Typedef(
3270 rtl::Reference< unoidl::TypedefEntity > const & entity,
3271 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
3272 CppuType(name, typeMgr), entity_(entity)
3273 { assert(entity.is()); }
3275 private:
3276 virtual void dumpDeclaration(FileStream& o) SAL_OVERRIDE;
3278 void dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
3280 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
3282 rtl::Reference< unoidl::TypedefEntity > entity_;
3285 void Typedef::dumpHFile(
3286 FileStream& o, codemaker::cppumaker::Includes & includes)
3288 OUString headerDefine(dumpHeaderDefine(o, "HDL"));
3289 o << "\n";
3291 addDefaultHIncludes(includes);
3292 includes.dump(o, 0);
3293 o << "\n";
3295 if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
3296 o << "\n";
3299 dumpDeclaration(o);
3301 if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
3302 o << "\n";
3305 o << "#endif // "<< headerDefine << "\n";
3308 void Typedef::dumpDeclaration(FileStream& o)
3310 o << "\ntypedef ";
3311 dumpType(o, entity_->getType());
3312 o << " " << id_ << ";\n\n";
3315 void Typedef::dumpHxxFile(
3316 FileStream& o, codemaker::cppumaker::Includes & includes)
3318 OUString headerDefine(dumpHeaderDefine(o, "HPP"));
3319 o << "\n";
3321 addDefaultHxxIncludes(includes);
3322 includes.dump(o, &name_);
3323 o << "\n";
3325 o << "\n#endif // "<< headerDefine << "\n";
3328 class ConstructiveType: public CppuType {
3329 public:
3330 ConstructiveType(
3331 OUString const & name, rtl::Reference< TypeManager > const & manager):
3332 CppuType(name, manager) {}
3334 private:
3335 virtual void dumpHFile(FileStream &, codemaker::cppumaker::Includes &) SAL_OVERRIDE
3336 { assert(false); } // this cannot happen
3338 virtual void dumpFiles(OUString const & uri, CppuOptions const & options) SAL_OVERRIDE
3339 { dumpFile(uri, name_, true, options); }
3342 bool hasRestParameter(
3343 unoidl::SingleInterfaceBasedServiceEntity::Constructor const & constructor)
3345 return !constructor.parameters.empty()
3346 && constructor.parameters.back().rest;
3349 void includeExceptions(
3350 codemaker::cppumaker::Includes & includes,
3351 codemaker::ExceptionTreeNode const * node)
3353 if (node->present) {
3354 includes.add(node->name);
3355 } else {
3356 for (codemaker::ExceptionTreeNode::Children::const_iterator i(
3357 node->children.begin());
3358 i != node->children.end(); ++i)
3360 includeExceptions(includes, *i);
3365 class ServiceType: public ConstructiveType {
3366 public:
3367 ServiceType(
3368 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const &
3369 entity,
3370 OUString const & name, rtl::Reference< TypeManager > const & manager):
3371 ConstructiveType(name, manager), entity_(entity)
3372 { assert(entity.is()); }
3374 private:
3375 virtual void dumpHxxFile(
3376 FileStream & o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
3378 void dumpCatchClauses(
3379 FileStream & out, codemaker::ExceptionTreeNode const * node);
3381 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > entity_;
3384 static OUString failsToSupply(const OUString& name_, const OString& baseName)
3386 return OUString(
3387 "\n"
3388 "#if OSL_DEBUG_LEVEL > 0\n"
3389 " ::rtl::OUString(\"component context fails to supply service '" + name_ + "' of type '" + OStringToOUString(baseName, RTL_TEXTENCODING_UTF8) + "'\")\n"
3390 "#else\n"
3391 " ::rtl::OUString(\"service not supplied\")\n"
3392 "#endif\n");
3395 void ServiceType::dumpHxxFile(
3396 FileStream & o, codemaker::cppumaker::Includes & includes)
3398 if (!entity_->getConstructors().empty()) {
3399 //TODO: Decide whether the types added to includes should rather be
3400 // added to m_dependencies (and thus be generated during
3401 // dumpDependedTypes):
3402 includes.addCassert();
3403 includes.addReference();
3404 includes.addRtlUstringH();
3405 includes.addRtlUstringHxx();
3406 includes.add("com.sun.star.uno.DeploymentException");
3407 includes.add("com.sun.star.uno.XComponentContext");
3408 for (std::vector<
3409 unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
3410 const_iterator i(entity_->getConstructors().begin());
3411 i != entity_->getConstructors().end(); ++i)
3413 if (i->defaultConstructor) {
3414 includes.add("com.sun.star.uno.Exception");
3415 includes.add("com.sun.star.uno.RuntimeException");
3416 } else {
3417 if (!hasRestParameter(*i)) {
3418 includes.addAny();
3419 includes.addSequence();
3420 for (std::vector<
3421 unoidl::SingleInterfaceBasedServiceEntity::
3422 Constructor::Parameter >::const_iterator j(
3423 i->parameters.begin());
3424 j != i->parameters.end(); ++j)
3426 if (m_typeMgr->getSort(
3427 b2u(codemaker::UnoType::decompose(
3428 u2b(j->type), 0, 0)))
3429 == codemaker::UnoType::SORT_CHAR)
3431 includes.addCppuUnotypeHxx();
3432 break;
3436 codemaker::ExceptionTree tree;
3437 for (std::vector< OUString >::const_iterator j(
3438 i->exceptions.begin());
3439 j != i->exceptions.end(); ++j)
3441 tree.add(u2b(*j), m_typeMgr);
3443 if (!tree.getRoot().present) {
3444 includes.add("com.sun.star.uno.Exception");
3445 includes.add("com.sun.star.uno.RuntimeException");
3446 includeExceptions(includes, &tree.getRoot());
3451 OString cppName(
3452 codemaker::cpp::translateUnoToCppIdentifier(
3453 u2b(id_), "service", isGlobal()));
3454 OUString headerDefine(dumpHeaderDefine(o, "HPP"));
3455 o << "\n";
3456 includes.dump(o, 0);
3457 if (!entity_->getConstructors().empty()) {
3458 o << ("\n#if defined ANDROID || defined IOS //TODO\n"
3459 "#include <com/sun/star/lang/XInitialization.hpp>\n"
3460 "#include <osl/detail/component-defines.h>\n#endif\n\n"
3461 "#if defined LO_URE_CURRENT_ENV && defined LO_URE_CTOR_ENV_")
3462 << name_.replaceAll(".", "_dot_")
3463 << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
3464 << name_.replaceAll(".", "_dot_") << ") && defined LO_URE_CTOR_FUN_"
3465 << name_.replaceAll(".", "_dot_")
3466 << "\nextern \"C\" ::css::uno::XInterface * SAL_CALL LO_URE_CTOR_FUN_"
3467 << name_.replaceAll(".", "_dot_")
3468 << "(::css::uno::XComponentContext *, ::css::uno::Sequence< "
3469 "::css::uno::Any > const &);\n#endif\n";
3471 o << "\n";
3472 if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
3473 o << "\n";
3475 o << "\nclass " << cppName << " {\n";
3476 inc();
3477 if (!entity_->getConstructors().empty()) {
3478 OString baseName(u2b(entity_->getBase()));
3479 OString scopedBaseName(codemaker::cpp::scopedCppName(baseName));
3480 o << "public:\n";
3481 for (std::vector<
3482 unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
3483 const_iterator i(entity_->getConstructors().begin());
3484 i != entity_->getConstructors().end(); ++i)
3486 if (i->defaultConstructor) {
3487 o << indent() << "static ::css::uno::Reference< "
3488 << scopedBaseName << " > "
3489 << codemaker::cpp::translateUnoToCppIdentifier(
3490 "create", "method", codemaker::cpp::ITM_NONGLOBAL,
3491 &cppName)
3492 << ("(::css::uno::Reference< ::css::uno::XComponentContext > const &"
3493 " the_context) {\n");
3494 inc();
3495 o << indent() << "assert(the_context.is());\n" << indent()
3496 << "::css::uno::Reference< " << scopedBaseName
3497 << " > the_instance;\n" << indent() << "try {\n";
3498 inc();
3499 o << ("#if defined LO_URE_CURRENT_ENV && defined "
3500 "LO_URE_CTOR_ENV_")
3501 << name_.replaceAll(".", "_dot_")
3502 << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
3503 << name_.replaceAll(".", "_dot_")
3504 << ") && defined LO_URE_CTOR_FUN_"
3505 << name_.replaceAll(".", "_dot_") << "\n" << indent()
3506 << "the_instance = ::css::uno::Reference< " << scopedBaseName
3507 << (" >(::css::uno::Reference< ::css::uno::XInterface >("
3508 "static_cast< ::css::uno::XInterface * >((*"
3509 "LO_URE_CTOR_FUN_")
3510 << name_.replaceAll(".", "_dot_")
3511 << (")(the_context.get(), ::css::uno::Sequence<"
3512 " ::css::uno::Any >())), ::SAL_NO_ACQUIRE),"
3513 " ::css::uno::UNO_QUERY);\n#else\n")
3514 << indent() << "the_instance = ::css::uno::Reference< "
3515 << scopedBaseName
3516 << (" >(the_context->getServiceManager()->"
3517 "createInstanceWithContext(::rtl::OUString("
3518 " \"")
3519 << name_
3520 << "\" ), the_context), ::css::uno::UNO_QUERY);\n#endif\n";
3521 dec();
3522 o << indent()
3523 << "} catch (const ::css::uno::RuntimeException &) {\n";
3524 inc();
3525 o << indent() << "throw;\n";
3526 dec();
3527 o << indent()
3528 << ("} catch (const ::css::uno::Exception & the_exception) {\n");
3529 inc();
3530 o << indent()
3531 << "throw ::css::uno::DeploymentException("
3532 << failsToSupply(name_, baseName)
3533 << " + \": \" + the_exception.Message, the_context);\n";
3534 dec();
3535 o << indent() << "}\n" << indent()
3536 << "if (!the_instance.is()) {\n";
3537 inc();
3538 o << indent()
3539 << "throw ::css::uno::DeploymentException("
3540 << failsToSupply(name_, baseName)
3541 << ", the_context);\n";
3542 dec();
3543 o << indent() << "}\n" << indent() << "return the_instance;\n";
3544 dec();
3545 o << indent() << "}\n\n";
3546 } else {
3547 o << indent() << "static ::css::uno::Reference< "
3548 << scopedBaseName << " > "
3549 << codemaker::cpp::translateUnoToCppIdentifier(
3550 u2b(i->name), "method", codemaker::cpp::ITM_NONGLOBAL,
3551 &cppName)
3552 << ("(::css::uno::Reference< ::css::uno::XComponentContext > const &"
3553 " the_context");
3554 bool rest = hasRestParameter(*i);
3555 for (std::vector<
3556 unoidl::SingleInterfaceBasedServiceEntity::Constructor::
3557 Parameter >::const_iterator j(i->parameters.begin());
3558 j != i->parameters.end(); ++j)
3560 o << ", ";
3561 OUStringBuffer buf;
3562 if (j->rest) {
3563 buf.append("[]");
3565 buf.append(j->type);
3566 OUString type(buf.makeStringAndClear());
3567 bool byRef = passByReference(type);
3568 dumpType(o, type, byRef, byRef);
3569 o << " "
3570 << codemaker::cpp::translateUnoToCppIdentifier(
3571 u2b(j->name), "param", codemaker::cpp::ITM_NONGLOBAL);
3573 o << ") {\n";
3574 inc();
3575 o << indent() << "assert(the_context.is());\n";
3576 if (!rest && !i->parameters.empty()) {
3577 o << indent()
3578 << ("::css::uno::Sequence< ::css::uno::Any > the_arguments(")
3579 << i->parameters.size() << ");\n";
3580 std::vector<
3581 unoidl::SingleInterfaceBasedServiceEntity::Constructor::
3582 Parameter >::size_type n = 0;
3583 for (std::vector<
3584 unoidl::SingleInterfaceBasedServiceEntity::
3585 Constructor::Parameter >::const_iterator j(
3586 i->parameters.begin());
3587 j != i->parameters.end(); ++j)
3589 o << indent() << "the_arguments[" << n++ << "] ";
3590 OString param(
3591 codemaker::cpp::translateUnoToCppIdentifier(
3592 u2b(j->name), "param",
3593 codemaker::cpp::ITM_NONGLOBAL));
3594 sal_Int32 rank;
3595 if (m_typeMgr->getSort(
3596 b2u(codemaker::UnoType::decompose(
3597 u2b(j->type), &rank, 0)))
3598 == codemaker::UnoType::SORT_CHAR)
3600 o << "= ::css::uno::Any(&" << param
3601 << ", ::cppu::UnoType< ";
3602 for (sal_Int32 k = 0; k < rank; ++k) {
3603 o << "::cppu::UnoSequenceType< ";
3605 o << "::cppu::UnoCharType";
3606 for (sal_Int32 k = 0; k < rank; ++k) {
3607 o << " >";
3609 o << " >::get())";
3610 } else {
3611 o << "<<= " << param;
3613 o << ";\n";
3616 o << indent() << "::css::uno::Reference< "
3617 << scopedBaseName << " > the_instance;\n";
3618 codemaker::ExceptionTree tree;
3619 for (std::vector< OUString >::const_iterator j(
3620 i->exceptions.begin());
3621 j != i->exceptions.end(); ++j)
3623 tree.add(u2b(*j), m_typeMgr);
3625 if (!tree.getRoot().present) {
3626 o << indent() << "try {\n";
3627 inc();
3629 o << ("#if defined LO_URE_CURRENT_ENV && defined "
3630 "LO_URE_CTOR_ENV_")
3631 << name_.replaceAll(".", "_dot_")
3632 << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
3633 << name_.replaceAll(".", "_dot_")
3634 << ") && defined LO_URE_CTOR_FUN_"
3635 << name_.replaceAll(".", "_dot_") << "\n" << indent()
3636 << "the_instance = ::css::uno::Reference< " << scopedBaseName
3637 << (" >(::css::uno::Reference< ::css::uno::XInterface >("
3638 "static_cast< ::css::uno::XInterface * >((*"
3639 "LO_URE_CTOR_FUN_")
3640 << name_.replaceAll(".", "_dot_")
3641 << ")(the_context.get(), ";
3642 if (rest) {
3643 o << codemaker::cpp::translateUnoToCppIdentifier(
3644 u2b(i->parameters.back().name), "param",
3645 codemaker::cpp::ITM_NONGLOBAL);
3646 } else if (i->parameters.empty()) {
3647 o << "::css::uno::Sequence< ::css::uno::Any >()";
3648 } else {
3649 o << "the_arguments";
3651 o << ")), ::SAL_NO_ACQUIRE), ::css::uno::UNO_QUERY);\n" << indent()
3652 << ("::css::uno::Reference< ::css::lang::XInitialization > "
3653 "init(the_instance, ::css::uno::UNO_QUERY);\n")
3654 << indent() << "if (init.is()) {\n"
3655 << indent() << " init->initialize(";
3656 if (i->parameters.empty()) {
3657 o << "::css::uno::Sequence< ::css::uno::Any >()";
3658 } else {
3659 o << "the_arguments";
3661 o << ");\n" << indent() << "}\n";
3662 o << ("#else\n")
3663 << indent() << "the_instance = ::css::uno::Reference< "
3664 << scopedBaseName
3665 << (" >(the_context->getServiceManager()->"
3666 "createInstanceWithArgumentsAndContext(::rtl::OUString("
3667 " \"")
3668 << name_ << "\" ), ";
3669 if (rest) {
3670 o << codemaker::cpp::translateUnoToCppIdentifier(
3671 u2b(i->parameters.back().name), "param",
3672 codemaker::cpp::ITM_NONGLOBAL);
3673 } else if (i->parameters.empty()) {
3674 o << ("::css::uno::Sequence< ::css::uno::Any >()");
3675 } else {
3676 o << "the_arguments";
3678 o << ", the_context), ::css::uno::UNO_QUERY);\n#endif\n";
3679 if (!tree.getRoot().present) {
3680 dec();
3681 o << indent()
3682 << ("} catch (const ::css::uno::RuntimeException &) {\n");
3683 inc();
3684 o << indent() << "throw;\n";
3685 dec();
3686 dumpCatchClauses(o, &tree.getRoot());
3687 o << indent()
3688 << ("} catch (const ::css::uno::Exception &"
3689 " the_exception) {\n");
3690 inc();
3691 o << indent()
3692 << "throw ::css::uno::DeploymentException("
3693 << failsToSupply(name_, baseName)
3694 << " + \": \" + the_exception.Message, the_context);\n";
3695 dec();
3696 o << indent() << "}\n";
3698 o << indent() << "if (!the_instance.is()) {\n";
3699 inc();
3700 o << indent()
3701 << "throw ::css::uno::DeploymentException("
3702 << failsToSupply(name_, baseName)
3703 << ", the_context);\n";
3704 dec();
3705 o << indent() << "}\n" << indent() << "return the_instance;\n";
3706 dec();
3707 o << indent() << "}\n\n";
3711 o << "private:\n";
3712 o << indent() << cppName << "(); // not implemented\n"
3713 << indent() << cppName << "(" << cppName << " &); // not implemented\n"
3714 << indent() << "~" << cppName << "(); // not implemented\n"
3715 << indent() << "void operator =(" << cppName << "); // not implemented\n";
3716 dec();
3717 o << "};\n\n";
3718 if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
3719 o << "\n";
3721 o << "\n#endif // "<< headerDefine << "\n";
3724 void ServiceType::dumpCatchClauses(
3725 FileStream & out, codemaker::ExceptionTreeNode const * node)
3727 if (node->present) {
3728 out << indent() << "} catch (const ";
3729 dumpType(out, b2u(node->name));
3730 out << " &) {\n";
3731 inc();
3732 out << indent() << "throw;\n";
3733 dec();
3734 } else {
3735 for (codemaker::ExceptionTreeNode::Children::const_iterator i(
3736 node->children.begin());
3737 i != node->children.end(); ++i)
3739 dumpCatchClauses(out, *i);
3744 class SingletonType: public ConstructiveType {
3745 public:
3746 SingletonType(
3747 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity,
3748 OUString const & name, rtl::Reference< TypeManager > const & manager):
3749 ConstructiveType(name, manager), entity_(entity)
3750 { assert(entity.is()); }
3752 private:
3753 virtual void dumpHxxFile(
3754 FileStream & o, codemaker::cppumaker::Includes & includes) SAL_OVERRIDE;
3756 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > entity_;
3759 void SingletonType::dumpHxxFile(
3760 FileStream & o, codemaker::cppumaker::Includes & includes)
3762 OString cppName(
3763 codemaker::cpp::translateUnoToCppIdentifier(
3764 u2b(id_), "singleton", isGlobal()));
3765 OString baseName(u2b(entity_->getBase()));
3766 OString scopedBaseName(codemaker::cpp::scopedCppName(baseName));
3767 OUString headerDefine(dumpHeaderDefine(o, "HPP"));
3768 o << "\n";
3769 //TODO: Decide whether the types added to includes should rather be added to
3770 // m_dependencies (and thus be generated during dumpDependedTypes):
3771 includes.add("com.sun.star.uno.DeploymentException");
3772 includes.add("com.sun.star.uno.XComponentContext");
3773 includes.addCassert();
3774 includes.addAny();
3775 includes.addReference();
3776 includes.addRtlUstringH();
3777 includes.addRtlUstringHxx();
3778 includes.dump(o, 0);
3779 o << ("\n#if defined ANDROID || defined IOS //TODO\n"
3780 "#include <com/sun/star/lang/XInitialization.hpp>\n"
3781 "#include <osl/detail/component-defines.h>\n#endif\n\n"
3782 "#if defined LO_URE_CURRENT_ENV && defined LO_URE_CTOR_ENV_")
3783 << name_.replaceAll(".", "_dot_")
3784 << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
3785 << name_.replaceAll(".", "_dot_") << ") && defined LO_URE_CTOR_FUN_"
3786 << name_.replaceAll(".", "_dot_")
3787 << "\nextern \"C\" ::css::uno::XInterface * SAL_CALL LO_URE_CTOR_FUN_"
3788 << name_.replaceAll(".", "_dot_")
3789 << "(::css::uno::XComponentContext *, ::css::uno::Sequence< "
3790 "::css::uno::Any > const &);\n#endif\n";
3791 o << "\n";
3792 if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
3793 o << "\n";
3795 o << "\nclass " << cppName << " {\npublic:\n";
3796 inc();
3797 o << indent() << "static ::css::uno::Reference< "
3798 << scopedBaseName << " > "
3799 << codemaker::cpp::translateUnoToCppIdentifier(
3800 "get", "method", codemaker::cpp::ITM_NONGLOBAL, &cppName)
3801 << ("(::css::uno::Reference<"
3802 " ::css::uno::XComponentContext > const & the_context)"
3803 " {\n");
3804 inc();
3805 o << indent() << "assert(the_context.is());\n" << indent()
3806 << "::css::uno::Reference< " << scopedBaseName
3807 << (" > instance;\n#if defined LO_URE_CURRENT_ENV && defined "
3808 "LO_URE_CTOR_ENV_")
3809 << name_.replaceAll(".", "_dot_")
3810 << " && (LO_URE_CURRENT_ENV) == (LO_URE_CTOR_ENV_"
3811 << name_.replaceAll(".", "_dot_")
3812 << ") && defined LO_URE_CTOR_FUN_"
3813 << name_.replaceAll(".", "_dot_") << "\n" << indent()
3814 << "instance = ::css::uno::Reference< " << scopedBaseName
3815 << (" >(::css::uno::Reference< ::css::uno::XInterface >("
3816 "static_cast< ::css::uno::XInterface * >((*"
3817 "LO_URE_CTOR_FUN_")
3818 << name_.replaceAll(".", "_dot_")
3819 << (")(the_context.get(), ::css::uno::Sequence<"
3820 " ::css::uno::Any >())), ::SAL_NO_ACQUIRE),"
3821 " ::css::uno::UNO_QUERY);\n#else\n")
3822 << indent() << ("the_context->getValueByName("
3823 "::rtl::OUString( \"/singletons/")
3824 << name_ << "\" )) >>= instance;\n#endif\n"
3825 << indent() << "if (!instance.is()) {\n";
3826 inc();
3827 o << indent()
3828 << ("throw ::css::uno::DeploymentException("
3829 "::rtl::OUString( \"component context"
3830 " fails to supply singleton ")
3831 << name_ << " of type " << baseName << "\" ), the_context);\n";
3832 dec();
3833 o << indent() << "}\n" << indent() << "return instance;\n";
3834 dec();
3835 o << indent() << "}\n\n";
3836 o << "private:\n";
3837 o << indent() << cppName << "(); // not implemented\n"
3838 << indent() << cppName << "(" << cppName << " &); // not implemented\n"
3839 << indent() << "~" << cppName << "(); // not implemented\n"
3840 << indent() << "void operator =(" << cppName << "); // not implemented\n";
3841 dec();
3842 o << "};\n\n";
3843 if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
3844 o << "\n";
3846 o << "\n#endif // "<< headerDefine << "\n";
3851 void produce(
3852 OUString const & name, rtl::Reference< TypeManager > const & manager,
3853 codemaker::GeneratedTypeSet & generated, CppuOptions const & options)
3855 if (generated.contains(u2b(name))) {
3856 return;
3858 generated.add(u2b(name));
3859 if (!manager->foundAtPrimaryProvider(name)) {
3860 return;
3862 rtl::Reference< unoidl::Entity > ent;
3863 rtl::Reference< unoidl::MapCursor > cur;
3864 switch (manager->getSort(name, &ent, &cur)) {
3865 case codemaker::UnoType::SORT_MODULE:
3867 OUString prefix;
3868 if (!name.isEmpty()) {
3869 prefix = name + ".";
3871 for (;;) {
3872 OUString mem;
3873 if (!cur->getNext(&mem).is()) {
3874 break;
3876 produce(prefix + mem, manager, generated, options);
3878 break;
3880 case codemaker::UnoType::SORT_ENUM_TYPE:
3882 EnumType t(
3883 dynamic_cast< unoidl::EnumTypeEntity * >(ent.get()), name,
3884 manager);
3885 t.dump(options);
3886 t.dumpDependedTypes(generated, options);
3887 break;
3889 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
3891 PlainStructType t(
3892 dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()),
3893 name, manager);
3894 t.dump(options);
3895 t.dumpDependedTypes(generated, options);
3896 break;
3898 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
3900 PolyStructType t(
3901 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
3902 ent.get()),
3903 name, manager);
3904 t.dump(options);
3905 t.dumpDependedTypes(generated, options);
3906 break;
3908 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
3910 ExceptionType t(
3911 dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()), name,
3912 manager);
3913 t.dump(options);
3914 t.dumpDependedTypes(generated, options);
3915 break;
3917 case codemaker::UnoType::SORT_INTERFACE_TYPE:
3919 InterfaceType t(
3920 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()), name,
3921 manager);
3922 t.dump(options);
3923 t.dumpDependedTypes(generated, options);
3924 break;
3926 case codemaker::UnoType::SORT_TYPEDEF:
3928 Typedef t(
3929 dynamic_cast< unoidl::TypedefEntity * >(ent.get()), name,
3930 manager);
3931 t.dump(options);
3932 t.dumpDependedTypes(generated, options);
3933 break;
3935 case codemaker::UnoType::SORT_CONSTANT_GROUP:
3937 ConstantGroup t(
3938 dynamic_cast< unoidl::ConstantGroupEntity * >(ent.get()), name,
3939 manager);
3940 if (t.hasConstants()) {
3941 t.dump(options);
3943 break;
3945 case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
3947 ServiceType t(
3948 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
3949 ent.get()),
3950 name, manager);
3951 t.dump(options);
3952 t.dumpDependedTypes(generated, options);
3953 break;
3955 case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
3957 SingletonType t(
3958 dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
3959 ent.get()),
3960 name, manager);
3961 t.dump(options);
3962 t.dumpDependedTypes(generated, options);
3963 break;
3965 case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
3966 case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
3967 break;
3968 default:
3969 throw CannotDumpException(
3970 "unexpected entity \"" + name + "\" in call to produce");
3974 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */