1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
28 #include "boost/noncopyable.hpp"
29 #include "rtl/alloc.h"
30 #include "rtl/ref.hxx"
31 #include "rtl/ustrbuf.hxx"
32 #include "rtl/ustring.hxx"
33 #include "rtl/strbuf.hxx"
34 #include "unoidl/unoidl.hxx"
36 #include "codemaker/commoncpp.hxx"
37 #include "codemaker/exceptiontree.hxx"
38 #include "codemaker/generatedtypeset.hxx"
39 #include "codemaker/typemanager.hxx"
40 #include "codemaker/unotype.hxx"
42 #include "cpputype.hxx"
43 #include "cppuoptions.hxx"
44 #include "dependencies.hxx"
45 #include "dumputils.hxx"
46 #include "includes.hxx"
50 bool isBootstrapType(OUString
const & name
) {
51 static char const * const names
[] = {
52 "com.sun.star.beans.Property",
53 "com.sun.star.beans.PropertyAttribute",
54 "com.sun.star.beans.PropertyChangeEvent",
55 "com.sun.star.beans.PropertyState",
56 "com.sun.star.beans.PropertyValue",
57 "com.sun.star.beans.XFastPropertySet",
58 "com.sun.star.beans.XMultiPropertySet",
59 "com.sun.star.beans.XPropertiesChangeListener",
60 "com.sun.star.beans.XPropertyAccess",
61 "com.sun.star.beans.XPropertyChangeListener",
62 "com.sun.star.beans.XPropertySet",
63 "com.sun.star.beans.XPropertySetInfo",
64 "com.sun.star.beans.XPropertySetOption",
65 "com.sun.star.beans.XVetoableChangeListener",
66 "com.sun.star.bridge.UnoUrlResolver",
67 "com.sun.star.bridge.XUnoUrlResolver",
68 "com.sun.star.connection.SocketPermission",
69 "com.sun.star.container.XElementAccess",
70 "com.sun.star.container.XEnumeration",
71 "com.sun.star.container.XEnumerationAccess",
72 "com.sun.star.container.XHierarchicalNameAccess",
73 "com.sun.star.container.XNameAccess",
74 "com.sun.star.container.XNameContainer",
75 "com.sun.star.container.XNameReplace",
76 "com.sun.star.container.XSet",
77 "com.sun.star.io.FilePermission",
78 "com.sun.star.io.IOException",
79 "com.sun.star.lang.DisposedException",
80 "com.sun.star.lang.EventObject",
81 "com.sun.star.lang.WrappedTargetRuntimeException",
82 "com.sun.star.lang.XComponent",
83 "com.sun.star.lang.XEventListener",
84 "com.sun.star.lang.XInitialization",
85 "com.sun.star.lang.XMultiComponentFactory",
86 "com.sun.star.lang.XMultiServiceFactory",
87 "com.sun.star.lang.XServiceInfo",
88 "com.sun.star.lang.XSingleComponentFactory",
89 "com.sun.star.lang.XSingleServiceFactory",
90 "com.sun.star.lang.XTypeProvider",
91 "com.sun.star.loader.XImplementationLoader",
92 "com.sun.star.reflection.FieldAccessMode",
93 "com.sun.star.reflection.MethodMode",
94 "com.sun.star.reflection.ParamInfo",
95 "com.sun.star.reflection.ParamMode",
96 "com.sun.star.reflection.TypeDescriptionSearchDepth",
97 "com.sun.star.reflection.XArrayTypeDescription",
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.reflection.XUnionTypeDescription",
119 "com.sun.star.registry.RegistryKeyType",
120 "com.sun.star.registry.RegistryValueType",
121 "com.sun.star.registry.XImplementationRegistration",
122 "com.sun.star.registry.XRegistryKey",
123 "com.sun.star.registry.XSimpleRegistry",
124 "com.sun.star.security.RuntimePermission",
125 "com.sun.star.security.XAccessControlContext",
126 "com.sun.star.security.XAccessController",
127 "com.sun.star.security.XAction",
128 "com.sun.star.uno.DeploymentException",
129 "com.sun.star.uno.RuntimeException",
130 "com.sun.star.uno.TypeClass",
131 "com.sun.star.uno.Uik",
132 "com.sun.star.uno.XAdapter",
133 "com.sun.star.uno.XAggregation",
134 "com.sun.star.uno.XComponentContext",
135 "com.sun.star.uno.XCurrentContext",
136 "com.sun.star.uno.XInterface",
137 "com.sun.star.uno.XReference",
138 "com.sun.star.uno.XUnloadingPreference",
139 "com.sun.star.uno.XWeak",
140 "com.sun.star.util.XMacroExpander" };
141 // cf. cppuhelper/unotypes/Makefile UNOTYPES (plus missing dependencies)
142 for (std::size_t i
= 0; i
< SAL_N_ELEMENTS(names
); ++i
) {
143 if (name
.equalsAscii(names
[i
])) {
150 class CppuType
: private boost::noncopyable
{
153 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
);
155 virtual ~CppuType() {}
157 void dump(CppuOptions
const & options
);
160 OUString
const & uri
, OUString
const & name
, bool hpp
,
161 CppuOptions
const & options
);
163 void dumpDependedTypes(
164 codemaker::GeneratedTypeSet
& generated
, CppuOptions
const & options
);
166 virtual void dumpHFile(
167 FileStream
& out
, codemaker::cppumaker::Includes
& includes
)
168 { dumpHFileContent(out
, includes
); }
170 virtual void dumpHxxFile(FileStream
& o
, codemaker::cppumaker::Includes
& includes
) = 0;
172 OUString
dumpHeaderDefine(FileStream
& o
, OUString
const & extension
);
174 void dumpGetCppuType(FileStream
& out
);
176 virtual void dumpLightGetCppuType(FileStream
& out
);
178 virtual void dumpNormalGetCppuType(FileStream
&)
179 { assert(false); } // this cannot happen
181 virtual void dumpComprehensiveGetCppuType(FileStream
&)
182 { assert(false); } // this cannot happen
185 FileStream
& out
, OUString
const & name
, bool isConst
= false,
186 bool isRef
= false, bool native
= false, bool cppuUnoType
= false)
189 OUString
getTypeClass(OUString
const & name
, bool cStyle
= false);
191 void dumpCppuGetType(
192 FileStream
& out
, OUString
const & name
, OUString
const * ownName
= 0);
194 sal_uInt32
getInheritedMemberCount();
196 void inc(sal_Int32 num
=4);
197 void dec(sal_Int32 num
=4);
198 OUString
indent() const;
200 virtual sal_uInt32
checkInheritedMemberCount() const
201 { assert(false); return 0; } // this cannot happen
203 bool passByReference(OUString
const & name
) const;
205 OUString
resolveOuterTypedefs(OUString
const & name
) const;
207 OUString
resolveAllTypedefs(OUString
const & name
) const;
209 codemaker::cpp::IdentifierTranslationMode
isGlobal() const;
211 virtual void dumpDeclaration(FileStream
&)
212 { assert(false); } // this cannot happen
214 virtual void dumpFiles(OUString
const & uri
, CppuOptions
const & options
);
216 virtual void addLightGetCppuTypeIncludes(
217 codemaker::cppumaker::Includes
& includes
) const;
219 virtual void addNormalGetCppuTypeIncludes(
220 codemaker::cppumaker::Includes
& includes
) const;
222 virtual void addComprehensiveGetCppuTypeIncludes(
223 codemaker::cppumaker::Includes
& includes
) const;
225 virtual bool isPolymorphic() const;
227 virtual void dumpTemplateHead(FileStream
&) const {}
229 virtual void dumpTemplateParameters(FileStream
&) const {}
231 void dumpGetCppuTypePreamble(FileStream
& out
);
233 void dumpGetCppuTypePostamble(FileStream
& out
);
235 void addDefaultHIncludes(codemaker::cppumaker::Includes
& includes
) const;
236 void addDefaultHxxIncludes(codemaker::cppumaker::Includes
& includes
) const;
238 void dumpInitializer(
239 FileStream
& out
, bool parameterized
, OUString
const & name
) const;
241 void dumpHFileContent(
242 FileStream
& out
, codemaker::cppumaker::Includes
& includes
);
245 sal_uInt32 m_inheritedMemberCount
;
248 bool m_cppuTypeDynamic
;
249 sal_Int32 m_indentLength
;
252 rtl::Reference
< TypeManager
> m_typeMgr
;
253 codemaker::cppumaker::Dependencies m_dependencies
;
256 void addGetCppuTypeIncludes(codemaker::cppumaker::Includes
& includes
)
261 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
):
262 m_inheritedMemberCount(0)
263 , m_cppuTypeLeak(false)
264 , m_cppuTypeDynamic(true)
267 , id_(name_
.copy(name_
.lastIndexOf('.') + 1))
269 , m_dependencies(typeMgr
, name_
)
272 void CppuType::addGetCppuTypeIncludes(codemaker::cppumaker::Includes
& includes
)
275 if (name_
== "com.sun.star.uno.XInterface"
276 || name_
== "com.sun.star.uno.Exception")
279 includes
.addCppuUnotypeHxx();
280 includes
.addSalTypesH();
281 includes
.addTypelibTypeclassH();
282 includes
.addTypelibTypedescriptionH();
283 } else if (m_cppuTypeLeak
) {
284 addLightGetCppuTypeIncludes(includes
);
285 } else if (m_cppuTypeDynamic
) {
286 addNormalGetCppuTypeIncludes(includes
);
288 addComprehensiveGetCppuTypeIncludes(includes
);
292 void CppuType::dumpFiles(OUString
const & uri
, CppuOptions
const & options
) {
293 dumpFile(uri
, name_
, false, options
);
294 dumpFile(uri
, name_
, true, options
);
297 void CppuType::addLightGetCppuTypeIncludes(
298 codemaker::cppumaker::Includes
& includes
) const
300 //TODO: Determine what is really needed, instead of relying on
301 // addDefaultHxxIncludes
302 includes
.addCppuUnotypeHxx();
305 void CppuType::addNormalGetCppuTypeIncludes(
306 codemaker::cppumaker::Includes
& includes
) const
308 //TODO: Determine what is really needed, instead of relying on
309 // addDefaultHxxIncludes
310 includes
.addCppuUnotypeHxx();
313 void CppuType::addComprehensiveGetCppuTypeIncludes(
314 codemaker::cppumaker::Includes
& includes
) const
316 //TODO: Determine what is really needed, instead of relying on
317 // addDefaultHxxIncludes
318 includes
.addCppuUnotypeHxx();
321 bool CppuType::isPolymorphic() const { return false; }
323 void CppuType::dumpGetCppuTypePreamble(FileStream
& out
) {
324 if (isPolymorphic()) {
325 out
<< "namespace cppu {\n\n";
326 dumpTemplateHead(out
);
327 out
<< "class UnoType< ";
328 dumpType(out
, name_
);
329 dumpTemplateParameters(out
);
330 out
<< " > {\npublic:\n";
333 << "static inline ::com::sun::star::uno::Type const & get() {\n";
335 if (codemaker::cppumaker::dumpNamespaceOpen(out
, name_
, false)) {
338 out
<< ("inline ::com::sun::star::uno::Type const &"
339 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
340 dumpType(out
, name_
, false, false, true);
341 out
<< " const *) {\n";
346 void CppuType::dumpGetCppuTypePostamble(FileStream
& out
) {
348 if (isPolymorphic()) {
349 out
<< indent() << "}\n\nprivate:\n"
350 << indent() << "UnoType(UnoType &); // not defined\n"
351 << indent() << "~UnoType(); // not defined\n"
353 << "void operator =(UnoType); // not defined\n};\n\n}\n\n";
356 if (codemaker::cppumaker::dumpNamespaceClose(out
, name_
, false)) {
360 dumpTemplateHead(out
);
361 out
<< ("inline ::com::sun::star::uno::Type const & SAL_CALL"
362 " getCppuType(SAL_UNUSED_PARAMETER ");
363 dumpType(out
, name_
);
364 dumpTemplateParameters(out
);
365 out
<< " const *) SAL_THROW(()) {\n";
367 out
<< indent() << "return ::cppu::UnoType< ";
368 dumpType(out
, name_
);
369 dumpTemplateParameters(out
);
370 out
<< " >::get();\n";
372 out
<< indent() << "}\n";
375 void CppuType::dump(CppuOptions
const & options
) {
376 if (isBootstrapType(name_
)) {
377 m_cppuTypeDynamic
= false;
379 // -CS was used as an undocumented option to generate static getCppuType
380 // functions; since the introduction of cppu::UnoType this no longer is
381 // meaningful (getCppuType is just a forward to cppu::UnoType::get now),
382 // and -CS is handled the same way as -C now:
383 if (options
.isValid("-L"))
384 m_cppuTypeLeak
= true;
385 if (options
.isValid("-C") || options
.isValid("-CS"))
386 m_cppuTypeDynamic
= false;
389 options
.isValid("-O") ? b2u(options
.getOption("-O")) : "", options
);
392 void CppuType::dumpFile(
393 OUString
const & uri
, OUString
const & name
, bool hpp
,
394 CppuOptions
const & options
)
397 b2u(createFileNameFromType(
398 u2b(uri
), u2b(name
), hpp
? ".hpp" : ".hdl")));
399 if (fileUri
.isEmpty()) {
400 throw CannotDumpException("empty target URI for entity " + name
);
402 bool exists
= fileExists(u2b(fileUri
));
403 if (exists
&& options
.isValid("-G")) {
407 out
.createTempFile(getTempDir(u2b(fileUri
)));
408 OUString
tmpUri(b2u(out
.getName()));
410 throw CannotDumpException("cannot open " + tmpUri
+ " for writing");
412 codemaker::cppumaker::Includes
includes(m_typeMgr
, m_dependencies
, hpp
);
415 addGetCppuTypeIncludes(includes
);
416 dumpHxxFile(out
, includes
);
418 dumpHFile(out
, includes
);
422 // Remove existing type file if something goes wrong to ensure
424 if (fileExists(u2b(fileUri
))) {
425 removeTypeFile(u2b(fileUri
));
427 removeTypeFile(u2b(tmpUri
));
432 u2b(fileUri
), u2b(tmpUri
), exists
&& options
.isValid("-Gc"));
435 void CppuType::dumpDependedTypes(
436 codemaker::GeneratedTypeSet
& generated
, CppuOptions
const & options
)
438 codemaker::cppumaker::Dependencies::Map
const & map
439 = m_dependencies
.getMap();
440 for (codemaker::cppumaker::Dependencies::Map::const_iterator
i(map
.begin());
443 produce(i
->first
, m_typeMgr
, generated
, options
);
447 OUString
CppuType::dumpHeaderDefine(
448 FileStream
& out
, OUString
const & extension
)
451 "INCLUDED_" + name_
.replace('.', '_').toAsciiUpperCase() + "_"
453 out
<< "#ifndef " << def
<< "\n#define " << def
<< "\n";
457 void CppuType::addDefaultHIncludes(codemaker::cppumaker::Includes
& includes
)
460 //TODO: Only include what is really needed
461 includes
.addCppuMacrosHxx();
462 if (m_typeMgr
->getSort(name_
)
463 == codemaker::UnoType::SORT_INTERFACE_TYPE
)
465 includes
.addReference();
469 void CppuType::addDefaultHxxIncludes(codemaker::cppumaker::Includes
& includes
)
472 //TODO: Only include what is really needed
473 includes
.addRtlInstanceHxx();
474 includes
.addOslMutexHxx();
476 if (m_typeMgr
->getSort(name_
)
477 == codemaker::UnoType::SORT_INTERFACE_TYPE
)
479 includes
.addReference();
483 void CppuType::dumpInitializer(
484 FileStream
& out
, bool parameterized
, OUString
const & name
) const
487 if (!parameterized
) {
489 std::vector
< OString
> args
;
491 b2u(codemaker::UnoType::decompose(
492 u2b(resolveAllTypedefs(name
)), &k
, &args
)));
494 rtl::Reference
< unoidl::Entity
> ent
;
495 switch (m_typeMgr
->getSort(n
, &ent
)) {
496 case codemaker::UnoType::SORT_BOOLEAN
:
499 case codemaker::UnoType::SORT_BYTE
:
500 case codemaker::UnoType::SORT_SHORT
:
501 case codemaker::UnoType::SORT_UNSIGNED_SHORT
:
502 case codemaker::UnoType::SORT_LONG
:
503 case codemaker::UnoType::SORT_UNSIGNED_LONG
:
504 case codemaker::UnoType::SORT_HYPER
:
505 case codemaker::UnoType::SORT_UNSIGNED_HYPER
:
506 case codemaker::UnoType::SORT_FLOAT
:
507 case codemaker::UnoType::SORT_DOUBLE
:
508 case codemaker::UnoType::SORT_CHAR
:
511 case codemaker::UnoType::SORT_ENUM_TYPE
:
512 out
<< codemaker::cpp::scopedCppName(u2b(n
)) << "_"
513 << (dynamic_cast< unoidl::EnumTypeEntity
* >(ent
.get())->
514 getMembers()[0].name
);
516 case codemaker::UnoType::SORT_STRING
:
517 case codemaker::UnoType::SORT_TYPE
:
518 case codemaker::UnoType::SORT_ANY
:
519 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE
:
520 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
:
521 case codemaker::UnoType::SORT_INTERFACE_TYPE
:
524 throw CannotDumpException(
525 "unexpected entity \"" + name
526 + "\" in call to CppuType::dumpInitializer");
533 void CppuType::dumpHFileContent(
534 FileStream
& out
, codemaker::cppumaker::Includes
& includes
)
536 addDefaultHIncludes(includes
);
537 dumpHeaderDefine(out
, "HDL");
539 includes
.dump(out
, 0);
540 out
<< ("\nnamespace com { namespace sun { namespace star { namespace uno"
541 " { class Type; } } } }\n\n");
542 if (codemaker::cppumaker::dumpNamespaceOpen(out
, name_
, false)) {
545 dumpDeclaration(out
);
546 if (!(name_
== "com.sun.star.uno.XInterface"
547 || name_
== "com.sun.star.uno.Exception"
550 out
<< "\n" << indent()
551 << ("inline ::com::sun::star::uno::Type const &"
552 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
553 dumpType(out
, name_
, false, false, true);
554 out
<< " const *);\n";
556 if (codemaker::cppumaker::dumpNamespaceClose(out
, name_
, false)) {
560 dumpTemplateHead(out
);
561 out
<< "inline ::com::sun::star::uno::Type const & SAL_CALL getCppuType(";
562 dumpType(out
, name_
, true);
563 dumpTemplateParameters(out
);
564 out
<< " *) SAL_THROW(());\n\n#endif\n";
567 void CppuType::dumpGetCppuType(FileStream
& out
) {
568 if (name_
== "com.sun.star.uno.XInterface") {
570 << ("inline ::com::sun::star::uno::Type const & SAL_CALL"
571 " getCppuType(SAL_UNUSED_PARAMETER ");
572 dumpType(out
, name_
, true);
573 out
<< " *) SAL_THROW(()) {\n";
576 << ("return ::cppu::UnoType< ::com::sun::star::uno::XInterface"
579 out
<< indent() << "}\n";
580 } else if (name_
== "com.sun.star.uno.Exception") {
582 << ("inline ::com::sun::star::uno::Type const & SAL_CALL"
583 " getCppuType(SAL_UNUSED_PARAMETER ");
584 dumpType(out
, name_
, true);
585 out
<< " *) SAL_THROW(()) {\n";
588 << ("return ::cppu::UnoType< ::com::sun::star::uno::Exception"
591 out
<< indent() << "}\n";
592 } else if (m_cppuTypeLeak
) {
593 dumpLightGetCppuType(out
);
594 } else if (m_cppuTypeDynamic
) {
595 dumpNormalGetCppuType(out
);
597 dumpComprehensiveGetCppuType(out
);
601 void CppuType::dumpLightGetCppuType(FileStream
& out
) {
602 dumpGetCppuTypePreamble(out
);
604 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
605 << indent() << "if ( !the_type )\n" << indent() << "{\n";
607 out
<< indent() << "typelib_static_type_init( &the_type, "
608 << getTypeClass(name_
, true) << ", \"" << name_
<< "\" );\n";
610 out
<< indent() << "}\n" << indent()
611 << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >("
613 dumpGetCppuTypePostamble(out
);
616 codemaker::cpp::IdentifierTranslationMode
CppuType::isGlobal() const {
617 return name_
.indexOf('.') == -1
618 ? codemaker::cpp::ITM_GLOBAL
: codemaker::cpp::ITM_NONGLOBAL
;
621 sal_uInt32
CppuType::getInheritedMemberCount()
623 if (m_inheritedMemberCount
== 0)
625 m_inheritedMemberCount
= checkInheritedMemberCount();
628 return m_inheritedMemberCount
;
631 OUString
CppuType::getTypeClass(OUString
const & name
, bool cStyle
) {
632 rtl::Reference
< unoidl::Entity
> ent
;
633 switch (m_typeMgr
->getSort(name
, &ent
)) {
634 case codemaker::UnoType::SORT_VOID
:
636 ? OUString("typelib_TypeClass_VOID")
637 : OUString("::com::sun::star::uno::TypeClass_VOID");
638 case codemaker::UnoType::SORT_BOOLEAN
:
640 ? OUString("typelib_TypeClass_BOOLEAN")
641 : OUString("::com::sun::star::uno::TypeClass_BOOLEAN");
642 case codemaker::UnoType::SORT_BYTE
:
644 ? OUString("typelib_TypeClass_BYTE")
645 : OUString("::com::sun::star::uno::TypeClass_BYTE");
646 case codemaker::UnoType::SORT_SHORT
:
648 ? OUString("typelib_TypeClass_SHORT")
649 : OUString("::com::sun::star::uno::TypeClass_SHORT");
650 case codemaker::UnoType::SORT_UNSIGNED_SHORT
:
652 ? OUString("typelib_TypeClass_UNSIGNED_SHORT")
653 : OUString("::com::sun::star::uno::TypeClass_UNSIGNED_SHORT");
654 case codemaker::UnoType::SORT_LONG
:
656 ? OUString("typelib_TypeClass_LONG")
657 : OUString("::com::sun::star::uno::TypeClass_LONG");
658 case codemaker::UnoType::SORT_UNSIGNED_LONG
:
660 ? OUString("typelib_TypeClass_UNSIGNED_LONG")
661 : OUString("::com::sun::star::uno::TypeClass_UNSIGNED_LONG");
662 case codemaker::UnoType::SORT_HYPER
:
664 ? OUString("typelib_TypeClass_HYPER")
665 : OUString("::com::sun::star::uno::TypeClass_HYPER");
666 case codemaker::UnoType::SORT_UNSIGNED_HYPER
:
668 ? OUString("typelib_TypeClass_UNSIGNED_HYPER")
669 : OUString("::com::sun::star::uno::TypeClass_UNSIGNED_HYPER");
670 case codemaker::UnoType::SORT_FLOAT
:
672 ? OUString("typelib_TypeClass_FLOAT")
673 : OUString("::com::sun::star::uno::TypeClass_FLOAT");
674 case codemaker::UnoType::SORT_DOUBLE
:
676 ? OUString("typelib_TypeClass_DOUBLE")
677 : OUString("::com::sun::star::uno::TypeClass_DOUBLE");
678 case codemaker::UnoType::SORT_CHAR
:
680 ? OUString("typelib_TypeClass_CHAR")
681 : OUString("::com::sun::star::uno::TypeClass_CHAR");
682 case codemaker::UnoType::SORT_STRING
:
684 ? OUString("typelib_TypeClass_STRING")
685 : OUString("::com::sun::star::uno::TypeClass_STRING");
686 case codemaker::UnoType::SORT_TYPE
:
688 ? OUString("typelib_TypeClass_TYPE")
689 : OUString("::com::sun::star::uno::TypeClass_TYPE");
690 case codemaker::UnoType::SORT_ANY
:
692 ? OUString("typelib_TypeClass_ANY")
693 : OUString("::com::sun::star::uno::TypeClass_ANY");
694 case codemaker::UnoType::SORT_SEQUENCE_TYPE
:
696 ? OUString("typelib_TypeClass_SEQUENCE")
697 : OUString("::com::sun::star::uno::TypeClass_SEQUENCE");
698 case codemaker::UnoType::SORT_ENUM_TYPE
:
700 ? OUString("typelib_TypeClass_ENUM")
701 : OUString("::com::sun::star::uno::TypeClass_ENUM");
702 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE
:
703 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
:
704 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE
:
706 ? OUString("typelib_TypeClass_STRUCT")
707 : OUString("::com::sun::star::uno::TypeClass_STRUCT");
708 case codemaker::UnoType::SORT_EXCEPTION_TYPE
:
710 ? OUString("typelib_TypeClass_EXCEPTION")
711 : OUString("::com::sun::star::uno::TypeClass_EXCEPTION");
712 case codemaker::UnoType::SORT_INTERFACE_TYPE
:
714 ? OUString("typelib_TypeClass_INTERFACE")
715 : OUString("::com::sun::star::uno::TypeClass_INTERFACE");
716 case codemaker::UnoType::SORT_TYPEDEF
:
718 dynamic_cast< unoidl::TypedefEntity
* >(ent
.get())->getType(),
721 for (;;) { std::abort(); }
725 void CppuType::dumpType(
726 FileStream
& out
, OUString
const & name
, bool isConst
, bool isRef
,
727 bool native
, bool cppuUnoType
) const
730 std::vector
< OString
> args
;
732 b2u(codemaker::UnoType::decompose(
733 u2b(resolveAllTypedefs(name
)), &k
, &args
)));
737 for (sal_Int32 i
= 0; i
!= k
; ++i
) {
739 ? "::cppu::UnoSequenceType" : "::com::sun::star::uno::Sequence")
742 switch (m_typeMgr
->getSort(n
)) {
743 case codemaker::UnoType::SORT_VOID
:
746 case codemaker::UnoType::SORT_BOOLEAN
:
749 case codemaker::UnoType::SORT_BYTE
:
752 case codemaker::UnoType::SORT_SHORT
:
753 out
<< "::sal_Int16";
755 case codemaker::UnoType::SORT_UNSIGNED_SHORT
:
756 out
<< (cppuUnoType
? "::cppu::UnoUnsignedShortType" : "::sal_uInt16");
758 case codemaker::UnoType::SORT_LONG
:
759 out
<< "::sal_Int32";
761 case codemaker::UnoType::SORT_UNSIGNED_LONG
:
762 out
<< "::sal_uInt32";
764 case codemaker::UnoType::SORT_HYPER
:
765 out
<< "::sal_Int64";
767 case codemaker::UnoType::SORT_UNSIGNED_HYPER
:
768 out
<< "::sal_uInt64";
770 case codemaker::UnoType::SORT_FLOAT
:
773 case codemaker::UnoType::SORT_DOUBLE
:
776 case codemaker::UnoType::SORT_CHAR
:
777 out
<< (cppuUnoType
? "::cppu::UnoCharType" : "::sal_Unicode");
779 case codemaker::UnoType::SORT_STRING
:
780 out
<< "::rtl::OUString";
782 case codemaker::UnoType::SORT_TYPE
:
783 out
<< "::com::sun::star::uno::Type";
785 case codemaker::UnoType::SORT_ANY
:
786 out
<< "::com::sun::star::uno::Any";
788 case codemaker::UnoType::SORT_ENUM_TYPE
:
789 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE
:
790 case codemaker::UnoType::SORT_EXCEPTION_TYPE
:
791 out
<< codemaker::cpp::scopedCppName(u2b(n
));
793 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
:
794 out
<< codemaker::cpp::scopedCppName(u2b(n
));
797 for (std::vector
< OString
>::iterator
i(args
.begin());
798 i
!= args
.end(); ++i
)
800 if (i
!= args
.begin()) {
803 dumpType(out
, b2u(*i
));
808 case codemaker::UnoType::SORT_INTERFACE_TYPE
:
810 out
<< "::com::sun::star::uno::Reference< ";
812 out
<< codemaker::cpp::scopedCppName(u2b(n
));
818 throw CannotDumpException(
819 "unexpected entity \"" + name
+ "\" in call to CppuType::dumpType");
821 for (sal_Int32 i
= 0; i
!= k
; ++i
) {
829 void CppuType::dumpCppuGetType(
830 FileStream
& out
, OUString
const & name
, OUString
const * ownName
)
832 //TODO: What are these calls good for?
835 codemaker::UnoType::Sort sort
= m_typeMgr
->decompose(
836 name
, true, &nucleus
, &rank
, 0, 0);
837 switch (rank
== 0 ? sort
: codemaker::UnoType::SORT_SEQUENCE_TYPE
) {
838 case codemaker::UnoType::SORT_VOID
:
839 case codemaker::UnoType::SORT_BOOLEAN
:
840 case codemaker::UnoType::SORT_BYTE
:
841 case codemaker::UnoType::SORT_SHORT
:
842 case codemaker::UnoType::SORT_UNSIGNED_SHORT
:
843 case codemaker::UnoType::SORT_LONG
:
844 case codemaker::UnoType::SORT_UNSIGNED_LONG
:
845 case codemaker::UnoType::SORT_HYPER
:
846 case codemaker::UnoType::SORT_UNSIGNED_HYPER
:
847 case codemaker::UnoType::SORT_FLOAT
:
848 case codemaker::UnoType::SORT_DOUBLE
:
849 case codemaker::UnoType::SORT_CHAR
:
850 case codemaker::UnoType::SORT_STRING
:
851 case codemaker::UnoType::SORT_TYPE
:
852 case codemaker::UnoType::SORT_ANY
:
854 case codemaker::UnoType::SORT_SEQUENCE_TYPE
:
855 case codemaker::UnoType::SORT_ENUM_TYPE
:
856 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE
:
857 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE
:
858 case codemaker::UnoType::SORT_EXCEPTION_TYPE
:
859 case codemaker::UnoType::SORT_INTERFACE_TYPE
:
860 // Take care of recursion like struct S { sequence<S> x; }:
861 if (ownName
== 0 || nucleus
!= *ownName
) {
862 out
<< indent() << "::cppu::UnoType< ";
863 dumpType(out
, name
, false, false, false, true);
864 out
<< " >::get();\n";
867 case codemaker::UnoType::SORT_TYPEDEF
:
868 assert(false); // this cannot happen
871 throw CannotDumpException(
872 "unexpected entity \"" + name
873 + "\" in call to CppuType::dumpCppuGetType");
877 bool CppuType::passByReference(OUString
const & name
) const {
878 switch (m_typeMgr
->getSort(resolveOuterTypedefs(name
))) {
879 case codemaker::UnoType::SORT_BOOLEAN
:
880 case codemaker::UnoType::SORT_BYTE
:
881 case codemaker::UnoType::SORT_SHORT
:
882 case codemaker::UnoType::SORT_UNSIGNED_SHORT
:
883 case codemaker::UnoType::SORT_LONG
:
884 case codemaker::UnoType::SORT_UNSIGNED_LONG
:
885 case codemaker::UnoType::SORT_HYPER
:
886 case codemaker::UnoType::SORT_UNSIGNED_HYPER
:
887 case codemaker::UnoType::SORT_FLOAT
:
888 case codemaker::UnoType::SORT_DOUBLE
:
889 case codemaker::UnoType::SORT_CHAR
:
890 case codemaker::UnoType::SORT_ENUM_TYPE
:
892 case codemaker::UnoType::SORT_STRING
:
893 case codemaker::UnoType::SORT_TYPE
:
894 case codemaker::UnoType::SORT_ANY
:
895 case codemaker::UnoType::SORT_SEQUENCE_TYPE
:
896 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE
:
897 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE
:
898 case codemaker::UnoType::SORT_INTERFACE_TYPE
:
901 throw CannotDumpException(
902 "unexpected entity \"" + name
903 + "\" in call to CppuType::passByReference");
907 OUString
CppuType::resolveOuterTypedefs(OUString
const & name
) const {
908 for (OUString
n(name
);;) {
909 rtl::Reference
< unoidl::Entity
> ent
;
910 if (m_typeMgr
->getSort(n
, &ent
) != codemaker::UnoType::SORT_TYPEDEF
) {
913 n
= dynamic_cast< unoidl::TypedefEntity
* >(ent
.get())->getType();
917 OUString
CppuType::resolveAllTypedefs(OUString
const & name
) const {
919 OUString
n(b2u(codemaker::UnoType::decompose(u2b(name
), &k1
)));
921 rtl::Reference
< unoidl::Entity
> ent
;
922 if (m_typeMgr
->getSort(n
, &ent
) != codemaker::UnoType::SORT_TYPEDEF
) {
927 codemaker::UnoType::decompose(
928 u2b(dynamic_cast< unoidl::TypedefEntity
* >(ent
.get())->
931 k1
+= k2
; //TODO: overflow
934 for (sal_Int32 i
= 0; i
!= k1
; ++i
) {
938 return b
.makeStringAndClear();
941 void CppuType::inc(sal_Int32 num
)
943 m_indentLength
+= num
;
946 void CppuType::dec(sal_Int32 num
)
948 m_indentLength
= std::max
< sal_Int32
>(m_indentLength
- num
, 0);
951 OUString
CppuType::indent() const {
952 OUStringBuffer
buf(m_indentLength
);
953 for (sal_Int32 i
= 0; i
!= m_indentLength
; ++i
) {
956 return buf
.makeStringAndClear();
959 bool isDeprecated(std::vector
< OUString
> const & annotations
) {
960 for (std::vector
< OUString
>::const_iterator
i(annotations
.begin());
961 i
!= annotations
.end(); ++i
)
963 if (*i
== "deprecated") {
970 void dumpDeprecation(FileStream
& out
, bool deprecated
) {
972 out
<< "SAL_DEPRECATED_INTERNAL(\"marked @deprecated in UNOIDL\") ";
976 class BaseOffset
: private boost::noncopyable
{
979 rtl::Reference
< TypeManager
> const & manager
,
980 rtl::Reference
< unoidl::InterfaceTypeEntity
> const & entity
):
981 manager_(manager
), offset_(0) { calculateBases(entity
); }
983 sal_Int32
get() const { return offset_
; }
987 rtl::Reference
< unoidl::InterfaceTypeEntity
> const & entity
);
989 rtl::Reference
< TypeManager
> manager_
;
990 std::set
< OUString
> set_
;
994 void BaseOffset::calculateBases(
995 rtl::Reference
< unoidl::InterfaceTypeEntity
> const & entity
)
998 for (std::vector
< unoidl::AnnotatedReference
>::const_iterator
i(
999 entity
->getDirectMandatoryBases().begin());
1000 i
!= entity
->getDirectMandatoryBases().end(); ++i
)
1002 if (set_
.insert(i
->name
).second
) {
1003 rtl::Reference
< unoidl::Entity
> ent
;
1004 codemaker::UnoType::Sort sort
= manager_
->getSort(i
->name
, &ent
);
1005 if (sort
!= codemaker::UnoType::SORT_INTERFACE_TYPE
) {
1006 throw CannotDumpException(
1007 "interface type base " + i
->name
1008 + " is not an interface type");
1010 rtl::Reference
< unoidl::InterfaceTypeEntity
> ent2(
1011 dynamic_cast< unoidl::InterfaceTypeEntity
* >(ent
.get()));
1013 calculateBases(ent2
);
1014 offset_
+= ent2
->getDirectAttributes().size()
1015 + ent2
->getDirectMethods().size(); //TODO: overflow
1020 class InterfaceType
: public CppuType
{
1023 rtl::Reference
< unoidl::InterfaceTypeEntity
> const & entity
,
1024 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
);
1026 virtual void dumpDeclaration(FileStream
& o
);
1027 void dumpHxxFile(FileStream
& o
, codemaker::cppumaker::Includes
& includes
);
1029 void dumpAttributes(FileStream
& o
);
1030 void dumpMethods(FileStream
& o
);
1031 void dumpNormalGetCppuType(FileStream
& o
);
1032 void dumpComprehensiveGetCppuType(FileStream
& o
);
1033 void dumpCppuAttributeRefs(FileStream
& o
, sal_uInt32
& index
);
1034 void dumpCppuMethodRefs(FileStream
& o
, sal_uInt32
& index
);
1035 void dumpCppuAttributes(FileStream
& o
, sal_uInt32
& index
);
1036 void dumpCppuMethods(FileStream
& o
, sal_uInt32
& index
);
1037 void dumpAttributesCppuDecl(FileStream
& out
, std::set
< OUString
> * seen
);
1038 void dumpMethodsCppuDecl(FileStream
& out
, std::set
< OUString
> * seen
);
1041 virtual void addComprehensiveGetCppuTypeIncludes(
1042 codemaker::cppumaker::Includes
& includes
) const;
1044 virtual sal_uInt32
checkInheritedMemberCount() const
1045 { return BaseOffset(m_typeMgr
, entity_
).get(); }
1047 sal_uInt32 m_inheritedMemberCount
;
1048 bool m_isDeprecated
;
1051 void dumpExceptionSpecification(
1052 FileStream
& out
, std::vector
< OUString
> const & exceptions
,
1053 bool runtimeException
);
1055 void dumpExceptionTypeName(
1056 FileStream
& out
, OUString
const & prefix
, sal_uInt32 index
,
1057 OUString
const & name
);
1059 sal_Int32
dumpExceptionTypeNames(
1060 FileStream
& out
, OUString
const & prefix
,
1061 std::vector
< OUString
> const & exceptions
, bool runtimeException
);
1063 rtl::Reference
< unoidl::InterfaceTypeEntity
> entity_
;
1066 InterfaceType::InterfaceType(
1067 rtl::Reference
< unoidl::InterfaceTypeEntity
> const & entity
,
1068 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
):
1069 CppuType(name
, typeMgr
), entity_(entity
)
1071 assert(entity
.is());
1072 m_inheritedMemberCount
= 0;
1073 m_isDeprecated
= isDeprecated(entity
->getAnnotations());
1076 void InterfaceType::dumpDeclaration(FileStream
& out
) {
1077 out
<< "\nclass SAL_NO_VTABLE " << id_
;
1078 for (std::vector
< unoidl::AnnotatedReference
>::const_iterator
i(
1079 entity_
->getDirectMandatoryBases().begin());
1080 i
!= entity_
->getDirectMandatoryBases().end(); ++i
)
1082 out
<< (i
== entity_
->getDirectMandatoryBases().begin() ? " :" : ",")
1083 << " public " << codemaker::cpp::scopedCppName(u2b(i
->name
));
1085 out
<< "\n{\npublic:\n";
1087 dumpAttributes(out
);
1089 out
<< "\n" << indent()
1090 << ("static inline ::com::sun::star::uno::Type const & SAL_CALL"
1091 " static_type(void * = 0);\n\n");
1093 out
<< "protected:\n";
1095 out
<< indent() << "~" << id_
1096 << ("() throw () {} // avoid warnings about virtual members and"
1097 " non-virtual dtor\n");
1102 void InterfaceType::dumpHxxFile(
1103 FileStream
& out
, codemaker::cppumaker::Includes
& includes
)
1105 OUString
headerDefine(dumpHeaderDefine(out
, "HPP"));
1107 addDefaultHxxIncludes(includes
);
1108 includes
.dump(out
, &name_
);
1110 dumpGetCppuType(out
);
1111 out
<< "\n::com::sun::star::uno::Type const & "
1112 << codemaker::cpp::scopedCppName(u2b(name_
))
1113 << "::static_type(SAL_UNUSED_PARAMETER void *) {\n";
1115 out
<< indent() << "return ::getCppuType(static_cast< ";
1116 dumpType(out
, name_
);
1117 out
<< " * >(0));\n";
1119 out
<< "}\n\n#endif // "<< headerDefine
<< "\n";
1122 void InterfaceType::dumpAttributes(FileStream
& out
) {
1123 if (!entity_
->getDirectAttributes().empty()) {
1124 out
<< "\n" << indent() << "// Attributes\n";
1126 for (std::vector
< unoidl::InterfaceTypeEntity::Attribute
>::const_iterator
1127 i(entity_
->getDirectAttributes().begin());
1128 i
!= entity_
->getDirectAttributes().end(); ++i
)
1130 bool depr
= m_isDeprecated
|| isDeprecated(i
->annotations
);
1132 dumpDeprecation(out
, depr
);
1134 dumpType(out
, i
->type
);
1135 out
<< " SAL_CALL get" << i
->name
<< "()";
1136 dumpExceptionSpecification(out
, i
->getExceptions
, true);
1139 bool byRef
= passByReference(i
->type
);
1141 dumpDeprecation(out
, depr
);
1142 out
<< "virtual void SAL_CALL set" << i
->name
<< "( ";
1143 dumpType(out
, i
->type
, byRef
, byRef
);
1144 out
<< " _" << i
->name
.toAsciiLowerCase() << " )";
1145 dumpExceptionSpecification(out
, i
->setExceptions
, true);
1151 void InterfaceType::dumpMethods(FileStream
& out
) {
1152 if (!entity_
->getDirectMethods().empty()) {
1153 out
<< "\n" << indent() << "// Methods\n";
1155 for (std::vector
< unoidl::InterfaceTypeEntity::Method
>::const_iterator
i(
1156 entity_
->getDirectMethods().begin());
1157 i
!= entity_
->getDirectMethods().end(); ++i
)
1160 dumpDeprecation(out
, m_isDeprecated
|| isDeprecated(i
->annotations
));
1162 dumpType(out
, i
->returnType
);
1163 out
<< " SAL_CALL " << i
->name
<< "(";
1164 if (i
->parameters
.empty()) {
1168 for (std::vector
< unoidl::InterfaceTypeEntity::Method::Parameter
>::
1169 const_iterator
j(i
->parameters
.begin());
1170 j
!= i
->parameters
.end();)
1175 == (unoidl::InterfaceTypeEntity::Method::Parameter::
1178 isConst
= passByReference(j
->type
);
1184 dumpType(out
, j
->type
, isConst
, isRef
);
1185 out
<< " " << j
->name
;
1187 if (j
!= i
->parameters
.end()) {
1193 dumpExceptionSpecification(
1194 out
, i
->exceptions
, i
->name
!= "acquire" && i
->name
!= "release");
1199 void InterfaceType::dumpNormalGetCppuType(FileStream
& out
) {
1200 dumpGetCppuTypePreamble(out
);
1202 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
1203 << indent() << "if ( !the_type )\n" << indent() << "{\n";
1205 std::vector
< unoidl::AnnotatedReference
>::size_type
bases(
1206 entity_
->getDirectMandatoryBases().size());
1208 && (entity_
->getDirectMandatoryBases()[0].name
1209 == "com.sun.star.uno.XInterface"))
1214 out
<< indent() << "typelib_TypeDescriptionReference * aSuperTypes["
1215 << entity_
->getDirectMandatoryBases().size() << "];\n";
1216 std::vector
< unoidl::AnnotatedReference
>::size_type n
= 0;
1217 for (std::vector
< unoidl::AnnotatedReference
>::const_iterator
i(
1218 entity_
->getDirectMandatoryBases().begin());
1219 i
!= entity_
->getDirectMandatoryBases().end(); ++i
)
1221 out
<< indent() << "aSuperTypes[" << n
++ << "] = ::cppu::UnoType< ";
1222 dumpType(out
, i
->name
, true, false, false, true);
1223 out
<< " >::get().getTypeLibType();\n";
1226 out
<< indent() << "typelib_static_mi_interface_type_init( &the_type, \""
1227 << name_
<< "\", " << bases
<< ", "
1228 << (bases
== 0 ? "0" : "aSuperTypes") << " );\n";
1230 out
<< indent() << "}\n" << indent()
1231 << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >("
1233 dumpGetCppuTypePostamble(out
);
1236 void InterfaceType::dumpComprehensiveGetCppuType(FileStream
& out
) {
1237 codemaker::cppumaker::dumpNamespaceOpen(out
, name_
, false);
1238 OUString
staticTypeClass("the" + id_
+ "Type");
1239 out
<< " namespace detail {\n\n" << indent() << "struct " << staticTypeClass
1240 << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, "
1241 << staticTypeClass
<< " >\n" << indent() << "{\n";
1243 out
<< indent() << "::com::sun::star::uno::Type * operator()() const\n"
1244 << indent() << "{\n";
1246 out
<< indent() << "::rtl::OUString sTypeName( \"" << name_
<< "\" );\n\n"
1247 << indent() << "// Start inline typedescription generation\n"
1248 << indent() << "typelib_InterfaceTypeDescription * pTD = 0;\n\n";
1249 out
<< indent() << "typelib_TypeDescriptionReference * aSuperTypes["
1250 << entity_
->getDirectMandatoryBases().size() << "];\n";
1251 std::vector
< unoidl::AnnotatedReference
>::size_type n
= 0;
1252 for (std::vector
< unoidl::AnnotatedReference
>::const_iterator
i(
1253 entity_
->getDirectMandatoryBases().begin());
1254 i
!= entity_
->getDirectMandatoryBases().end(); ++i
)
1256 out
<< indent() << "aSuperTypes[" << n
++ << "] = ::cppu::UnoType< ";
1257 dumpType(out
, i
->name
, false, false, false, true);
1258 out
<< " >::get().getTypeLibType();\n";
1260 std::size_t count
= entity_
->getDirectAttributes().size()
1261 + entity_
->getDirectMethods().size(); //TODO: overflow
1263 out
<< indent() << "typelib_TypeDescriptionReference * pMembers["
1264 << count
<< "] = { ";
1265 for (std::size_t i
= 0; i
!= count
; ++i
) {
1267 if (i
+ 1 != count
) {
1272 sal_uInt32 index
= 0;
1273 dumpCppuAttributeRefs(out
, index
);
1274 dumpCppuMethodRefs(out
, index
);
1276 out
<< "\n" << indent() << "typelib_typedescription_newMIInterface(\n";
1278 out
<< indent() << "&pTD,\n" << indent()
1279 << ("sTypeName.pData, 0x00000000, 0x0000, 0x0000, 0x00000000,"
1280 " 0x00000000,\n") // UIK
1281 << indent() << entity_
->getDirectMandatoryBases().size()
1282 << ", aSuperTypes,\n" << indent() << count
<< ",\n" << indent()
1283 << (count
== 0 ? "0" : "pMembers") << " );\n\n";
1286 << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
1288 for (std::size_t i
= 0; i
!= count
; ++i
) {
1289 out
<< indent() << "typelib_typedescriptionreference_release( pMembers["
1293 << ("typelib_typedescription_release( (typelib_TypeDescription*)pTD"
1295 << indent() << "return new ::com::sun::star::uno::Type( "
1296 << getTypeClass(name_
) << ", sTypeName ); // leaked\n";
1298 out
<< indent() << "}\n";
1300 out
<< indent() << "};\n\n";
1301 codemaker::cppumaker::dumpNamespaceClose(out
, name_
, false);
1303 dumpGetCppuTypePreamble(out
);
1304 out
<< indent() << "const ::com::sun::star::uno::Type &rRet = *detail::"
1305 << staticTypeClass
<< "::get();\n" << indent()
1306 << "// End inline typedescription generation\n" << indent()
1307 << "static bool bInitStarted = false;\n" << indent()
1308 << "if (!bInitStarted)\n" << indent() << "{\n";
1311 << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n"
1312 << indent() << "if (!bInitStarted)\n" << indent() << "{\n";
1314 out
<< indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"
1315 << indent() << "bInitStarted = true;\n";
1316 std::set
< OUString
> seen
;
1317 // Type for RuntimeException is always needed:
1318 seen
.insert("com.sun.star.uno.RuntimeException");
1319 dumpCppuGetType(out
, "com.sun.star.uno.RuntimeException");
1320 dumpAttributesCppuDecl(out
, &seen
);
1321 dumpMethodsCppuDecl(out
, &seen
);
1323 sal_uInt32 index
= getInheritedMemberCount();
1324 dumpCppuAttributes(out
, index
);
1325 dumpCppuMethods(out
, index
);
1328 out
<< indent() << "}\n";
1330 out
<< indent() << "}\n" << indent() << "else\n" << indent() << "{\n";
1332 out
<< indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n";
1334 out
<< indent() << "}\n" << indent() << "return rRet;\n";
1335 dumpGetCppuTypePostamble(out
);
1338 void InterfaceType::dumpCppuAttributeRefs(FileStream
& out
, sal_uInt32
& index
)
1340 std::vector
< unoidl::InterfaceTypeEntity::Attribute
>::size_type n
= 0;
1341 for (std::vector
< unoidl::InterfaceTypeEntity::Attribute
>::const_iterator
1342 i(entity_
->getDirectAttributes().begin());
1343 i
!= entity_
->getDirectAttributes().end(); ++i
)
1345 out
<< indent() << "::rtl::OUString sAttributeName" << n
<< "( \""
1346 << name_
<< "::" << i
->name
<< "\" );\n" << indent()
1347 << "typelib_typedescriptionreference_new( &pMembers[" << index
++
1351 << ("(typelib_TypeClass)"
1352 "::com::sun::star::uno::TypeClass_INTERFACE_ATTRIBUTE,\n")
1353 << indent() << "sAttributeName" << n
<< ".pData );\n";
1359 void InterfaceType::dumpCppuMethodRefs(FileStream
& out
, sal_uInt32
& index
) {
1360 std::vector
< unoidl::InterfaceTypeEntity::Method
>::size_type n
= 0;
1361 for (std::vector
< unoidl::InterfaceTypeEntity::Method
>::const_iterator
i(
1362 entity_
->getDirectMethods().begin());
1363 i
!= entity_
->getDirectMethods().end(); ++i
)
1365 out
<< indent() << "::rtl::OUString sMethodName" << n
<< "( \"" << name_
1366 << "::" << i
->name
<< "\" );\n" << indent()
1367 << "typelib_typedescriptionreference_new( &pMembers[" << index
++
1371 << ("(typelib_TypeClass)"
1372 "::com::sun::star::uno::TypeClass_INTERFACE_METHOD,\n")
1373 << indent() << "sMethodName" << n
<< ".pData );\n";
1379 void InterfaceType::addComprehensiveGetCppuTypeIncludes(
1380 codemaker::cppumaker::Includes
& includes
) const
1382 // The comprehensive getCppuType method always includes a line
1383 // "getCppuType( (const ::com::sun::star::uno::RuntimeException*)0 );":
1384 includes
.addCppuUnotypeHxx();
1385 includes
.add("com.sun.star.uno.RuntimeException");
1388 void InterfaceType::dumpCppuAttributes(FileStream
& out
, sal_uInt32
& index
) {
1389 if (!entity_
->getDirectAttributes().empty()) {
1390 out
<< "\n" << indent()
1391 << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n";
1392 std::vector
< unoidl::InterfaceTypeEntity::Attribute
>::size_type n
= 0;
1393 for (std::vector
< unoidl::InterfaceTypeEntity::Attribute
>::
1394 const_iterator
i(entity_
->getDirectAttributes().begin());
1395 i
!= entity_
->getDirectAttributes().end(); ++i
)
1397 OUString
type(resolveAllTypedefs(i
->type
));
1398 out
<< indent() << "{\n";
1400 out
<< indent() << "::rtl::OUString sAttributeType" << n
<< "( \""
1401 << type
<< "\" );\n" << indent()
1402 << "::rtl::OUString sAttributeName" << n
<< "( \"" << name_
1403 << "::" << i
->name
<< "\" );\n";
1404 sal_Int32 getExcn
= dumpExceptionTypeNames(
1405 out
, "get", i
->getExceptions
, false);
1406 sal_Int32 setExcn
= dumpExceptionTypeNames(
1407 out
, "set", i
->setExceptions
, false);
1409 << ("typelib_typedescription_newExtendedInterfaceAttribute("
1412 out
<< indent() << index
++ << ", sAttributeName" << n
1413 << ".pData,\n" << indent() << "(typelib_TypeClass)"
1414 << getTypeClass(type
) << ", sAttributeType" << n
<< ".pData,\n"
1415 << indent() << "sal_" << (i
->readOnly
? "True" : "False")
1416 << ", " << getExcn
<< ", "
1417 << (getExcn
== 0 ? "0" : "the_getExceptions") << ", " << setExcn
1418 << ", " << (setExcn
== 0 ? "0" : "the_setExceptions")
1422 << ("typelib_typedescription_register("
1423 " (typelib_TypeDescription**)&pAttribute );\n");
1425 out
<< indent() << "}\n";
1429 << ("typelib_typedescription_release("
1430 " (typelib_TypeDescription*)pAttribute );\n");
1434 void InterfaceType::dumpCppuMethods(FileStream
& out
, sal_uInt32
& index
) {
1435 if (!entity_
->getDirectMethods().empty()) {
1436 out
<< "\n" << indent()
1437 << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n";
1438 std::vector
< unoidl::InterfaceTypeEntity::Method
>::size_type n
= 0;
1439 for (std::vector
< unoidl::InterfaceTypeEntity::Method
>::const_iterator
1440 i(entity_
->getDirectMethods().begin());
1441 i
!= entity_
->getDirectMethods().end(); ++i
)
1443 OUString
returnType(resolveAllTypedefs(i
->returnType
));
1444 out
<< indent() << "{\n";
1446 if (!i
->parameters
.empty()) {
1447 out
<< indent() << "typelib_Parameter_Init aParameters["
1448 << i
->parameters
.size() << "];\n";
1450 std::vector
< unoidl::InterfaceTypeEntity::Method::Parameter
>::
1452 for (std::vector
< unoidl::InterfaceTypeEntity::Method::Parameter
>::
1453 const_iterator
j(i
->parameters
.begin());
1454 j
!= i
->parameters
.end(); ++j
)
1456 OUString
type(resolveAllTypedefs(j
->type
));
1457 out
<< indent() << "::rtl::OUString sParamName" << m
<< "( \""
1458 << j
->name
<< "\" );\n" << indent()
1459 << "::rtl::OUString sParamType" << m
<< "( \"" << type
1460 << "\" );\n" << indent() << "aParameters[" << m
1461 << "].pParamName = sParamName" << m
<< ".pData;\n"
1462 << indent() << "aParameters[" << m
1463 << "].eTypeClass = (typelib_TypeClass)"
1464 << getTypeClass(type
) << ";\n" << indent() << "aParameters["
1465 << m
<< "].pTypeName = sParamType" << m
<< ".pData;\n"
1466 << indent() << "aParameters[" << m
<< "].bIn = "
1468 == (unoidl::InterfaceTypeEntity::Method::Parameter::
1470 ? "sal_False" : "sal_True")
1471 << ";\n" << indent() << "aParameters[" << m
<< "].bOut = "
1473 == (unoidl::InterfaceTypeEntity::Method::Parameter::
1475 ? "sal_False" : "sal_True")
1479 sal_Int32 excn
= dumpExceptionTypeNames(
1480 out
, "", i
->exceptions
,
1481 i
->name
!= "acquire" && i
->name
!= "release");
1482 out
<< indent() << "::rtl::OUString sReturnType" << n
<< "( \""
1483 << returnType
<< "\" );\n" << indent()
1484 << "::rtl::OUString sMethodName" << n
<< "( \"" << name_
<< "::"
1485 << i
->name
<< "\" );\n" << indent()
1486 << "typelib_typedescription_newInterfaceMethod( &pMethod,\n";
1488 out
<< indent() << index
++ << ", sal_False,\n" << indent()
1489 << "sMethodName" << n
<< ".pData,\n" << indent()
1490 << "(typelib_TypeClass)" << getTypeClass(returnType
)
1491 << ", sReturnType" << n
<< ".pData,\n" << indent()
1492 << i
->parameters
.size() << ", "
1493 << (i
->parameters
.empty() ? "0" : "aParameters") << ",\n"
1494 << indent() << excn
<< ", "
1495 << (excn
== 0 ? "0" : "the_Exceptions") << " );\n";
1498 << ("typelib_typedescription_register("
1499 " (typelib_TypeDescription**)&pMethod );\n");
1501 out
<< indent() << "}\n";
1505 << ("typelib_typedescription_release("
1506 " (typelib_TypeDescription*)pMethod );\n");
1510 void InterfaceType::dumpAttributesCppuDecl(
1511 FileStream
& out
, std::set
< OUString
> * seen
)
1514 for (std::vector
< unoidl::InterfaceTypeEntity::Attribute
>::const_iterator
1515 i(entity_
->getDirectAttributes().begin());
1516 i
!= entity_
->getDirectAttributes().end(); ++i
)
1518 if (seen
->insert(i
->type
).second
) {
1519 dumpCppuGetType(out
, i
->type
);
1521 for (std::vector
< OUString
>::const_iterator
j(
1522 i
->getExceptions
.begin());
1523 j
!= i
->getExceptions
.end(); ++j
)
1525 if (seen
->insert(*j
).second
) {
1526 dumpCppuGetType(out
, *j
);
1529 for (std::vector
< OUString
>::const_iterator
j(
1530 i
->setExceptions
.begin());
1531 j
!= i
->setExceptions
.end(); ++j
)
1533 if (seen
->insert(*j
).second
) {
1534 dumpCppuGetType(out
, *j
);
1540 void InterfaceType::dumpMethodsCppuDecl(
1541 FileStream
& out
, std::set
< OUString
> * seen
)
1544 for (std::vector
< unoidl::InterfaceTypeEntity::Method
>::const_iterator
i(
1545 entity_
->getDirectMethods().begin());
1546 i
!= entity_
->getDirectMethods().end(); ++i
)
1548 for (std::vector
< OUString
>::const_iterator
j(i
->exceptions
.begin());
1549 j
!= i
->exceptions
.end(); ++j
)
1551 if (seen
->insert(*j
).second
) {
1552 dumpCppuGetType(out
, *j
);
1558 void InterfaceType::dumpExceptionSpecification(
1559 FileStream
& out
, std::vector
< OUString
> const & exceptions
,
1560 bool runtimeException
)
1562 // Exception specifications are undesirable in production code, but make
1563 // for useful assertions in debug builds (on platforms where they are
1564 // enforced at runtime):
1565 #if !defined DBG_UTIL
1570 for (std::vector
< OUString
>::const_iterator
i(exceptions
.begin());
1571 i
!= exceptions
.end(); ++i
)
1573 if (*i
!= "com.sun.star.uno.RuntimeException") {
1577 out
<< codemaker::cpp::scopedCppName(u2b(*i
));
1581 if (runtimeException
) {
1585 out
<< "::com::sun::star::uno::RuntimeException";
1588 #if !defined DBG_UTIL
1593 void InterfaceType::dumpExceptionTypeName(
1594 FileStream
& out
, OUString
const & prefix
, sal_uInt32 index
,
1595 OUString
const & name
)
1597 out
<< indent() << "::rtl::OUString the_" << prefix
<< "ExceptionName"
1598 << index
<< "( \"" << name
<< "\" );\n";
1601 sal_Int32
InterfaceType::dumpExceptionTypeNames(
1602 FileStream
& out
, OUString
const & prefix
,
1603 std::vector
< OUString
> const & exceptions
, bool runtimeException
)
1605 sal_Int32 count
= 0;
1606 for (std::vector
< OUString
>::const_iterator
i(exceptions
.begin());
1607 i
!= exceptions
.end(); ++i
)
1609 if (*i
!= "com.sun.star.uno.RuntimeException") {
1610 dumpExceptionTypeName(out
, prefix
, count
++, *i
);
1613 if (runtimeException
) {
1614 dumpExceptionTypeName(
1615 out
, prefix
, count
++, "com.sun.star.uno.RuntimeException");
1618 out
<< indent() << "rtl_uString * the_" << prefix
<< "Exceptions[] = {";
1619 for (sal_Int32 i
= 0; i
!= count
; ++i
) {
1620 out
<< (i
== 0 ? " " : ", ") << "the_" << prefix
<< "ExceptionName"
1628 class ConstantGroup
: public CppuType
{
1631 rtl::Reference
< unoidl::ConstantGroupEntity
> const & entity
,
1632 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
):
1633 CppuType(name
, typeMgr
), entity_(entity
)
1634 { assert(entity
.is()); }
1636 bool hasConstants() const { return !entity_
->getMembers().empty(); }
1639 virtual void dumpHFile(
1640 FileStream
& out
, codemaker::cppumaker::Includes
& includes
);
1642 virtual void dumpHxxFile(
1643 FileStream
& out
, codemaker::cppumaker::Includes
& includes
);
1645 virtual void dumpDeclaration(FileStream
& out
);
1647 rtl::Reference
< unoidl::ConstantGroupEntity
> entity_
;
1650 void ConstantGroup::dumpHFile(
1651 FileStream
& out
, codemaker::cppumaker::Includes
& includes
)
1653 OUString
headerDefine(dumpHeaderDefine(out
, "HDL"));
1655 addDefaultHIncludes(includes
);
1656 includes
.dump(out
, 0);
1658 if (codemaker::cppumaker::dumpNamespaceOpen(out
, name_
, true)) {
1662 dumpDeclaration(out
);
1664 if (codemaker::cppumaker::dumpNamespaceClose(out
, name_
, true)) {
1667 out
<< "\n#endif // "<< headerDefine
<< "\n";
1670 void ConstantGroup::dumpHxxFile(
1671 FileStream
& out
, codemaker::cppumaker::Includes
&)
1673 OUString
headerDefine(dumpHeaderDefine(out
, "HPP"));
1675 codemaker::cppumaker::Includes::dumpInclude(out
, u2b(name_
), false);
1676 out
<< "\n#endif // "<< headerDefine
<< "\n";
1679 void ConstantGroup::dumpDeclaration(FileStream
& out
) {
1680 for (std::vector
< unoidl::ConstantGroupEntity::Member
>::const_iterator
i(
1681 entity_
->getMembers().begin());
1682 i
!= entity_
->getMembers().end(); ++i
)
1684 out
<< "static const ";
1685 switch (i
->value
.type
) {
1686 case unoidl::ConstantValue::TYPE_BOOLEAN
:
1687 out
<< "::sal_Bool";
1689 case unoidl::ConstantValue::TYPE_BYTE
:
1690 out
<< "::sal_Int8";
1692 case unoidl::ConstantValue::TYPE_SHORT
:
1693 out
<< "::sal_Int16";
1695 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT
:
1696 out
<< "::sal_uInt16";
1698 case unoidl::ConstantValue::TYPE_LONG
:
1699 out
<< "::sal_Int32";
1701 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG
:
1702 out
<< "::sal_uInt32";
1704 case unoidl::ConstantValue::TYPE_HYPER
:
1705 out
<< "::sal_Int64";
1707 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER
:
1708 out
<< "::sal_uInt64";
1710 case unoidl::ConstantValue::TYPE_FLOAT
:
1713 case unoidl::ConstantValue::TYPE_DOUBLE
:
1717 out
<< " " << i
->name
<< " = ";
1718 switch (i
->value
.type
) {
1719 case unoidl::ConstantValue::TYPE_BOOLEAN
:
1720 out
<< (i
->value
.booleanValue
? "sal_True" : "sal_False");
1722 case unoidl::ConstantValue::TYPE_BYTE
:
1723 out
<< "(sal_Int8)" << OUString::number(i
->value
.byteValue
);
1725 case unoidl::ConstantValue::TYPE_SHORT
:
1726 out
<< "(sal_Int16)" << OUString::number(i
->value
.shortValue
);
1728 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT
:
1729 out
<< "(sal_uInt16)"
1730 << OUString::number(i
->value
.unsignedShortValue
);
1732 case unoidl::ConstantValue::TYPE_LONG
:
1733 // Avoid C++ compiler warnings about (un)signedness of literal
1735 if (i
->value
.longValue
== SAL_MIN_INT32
) {
1736 out
<< "SAL_MIN_INT32";
1738 out
<< "(sal_Int32)" << OUString::number(i
->value
.longValue
);
1741 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG
:
1742 out
<< "(sal_uInt32)"
1743 << OUString::number(i
->value
.unsignedLongValue
) << "U";
1745 case unoidl::ConstantValue::TYPE_HYPER
:
1746 // Avoid C++ compiler warnings about (un)signedness of literal
1748 if (i
->value
.hyperValue
== SAL_MIN_INT64
) {
1749 out
<< "SAL_MIN_INT64";
1751 out
<< "(sal_Int64) SAL_CONST_INT64("
1752 << OUString::number(i
->value
.hyperValue
) << ")";
1755 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER
:
1756 out
<< "SAL_CONST_UINT64("
1757 << OUString::number(i
->value
.unsignedHyperValue
) << ")";
1759 case unoidl::ConstantValue::TYPE_FLOAT
:
1760 out
<< "(float)" << OUString::number(i
->value
.floatValue
);
1762 case unoidl::ConstantValue::TYPE_DOUBLE
:
1763 out
<< "(double)" << OUString::number(i
->value
.doubleValue
);
1770 void dumpTypeParameterName(FileStream
& out
, OUString
const & name
) {
1771 // Prefix all type parameters with "typeparam_" to avoid problems when a
1772 // struct member has the same name as a type parameter, as in
1773 // struct<T> { T T; };
1774 out
<< "typeparam_" << name
;
1777 class PlainStructType
: public CppuType
{
1780 rtl::Reference
< unoidl::PlainStructTypeEntity
> const & entity
,
1781 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
):
1782 CppuType(name
, typeMgr
), entity_(entity
)
1783 { assert(entity
.is()); }
1786 virtual sal_uInt32
checkInheritedMemberCount() const
1787 { return getTotalMemberCount(entity_
->getDirectBase()); }
1789 virtual void dumpDeclaration(FileStream
& o
);
1791 void dumpHxxFile(FileStream
& o
, codemaker::cppumaker::Includes
& includes
);
1793 virtual void dumpLightGetCppuType(FileStream
& out
);
1795 virtual void dumpNormalGetCppuType(FileStream
& out
);
1797 virtual void dumpComprehensiveGetCppuType(FileStream
& out
);
1799 virtual void addLightGetCppuTypeIncludes(
1800 codemaker::cppumaker::Includes
& includes
) const;
1802 virtual void addNormalGetCppuTypeIncludes(
1803 codemaker::cppumaker::Includes
& includes
) const;
1805 virtual void addComprehensiveGetCppuTypeIncludes(
1806 codemaker::cppumaker::Includes
& includes
) const;
1808 bool dumpBaseMembers(
1809 FileStream
& out
, OUString
const & base
, bool withType
);
1811 sal_uInt32
getTotalMemberCount(OUString
const & base
) const;
1813 rtl::Reference
< unoidl::PlainStructTypeEntity
> entity_
;
1816 void PlainStructType::dumpDeclaration(FileStream
& out
) {
1817 out
<< "\n#ifdef SAL_W32\n# pragma pack(push, 8)\n#endif\n\n" << indent()
1818 << "struct " << id_
;
1819 OUString
base(entity_
->getDirectBase());
1820 if (!base
.isEmpty()) {
1821 out
<< ": public " << codemaker::cpp::scopedCppName(u2b(base
));
1825 out
<< indent() << "inline " << id_
<< "() SAL_THROW(());\n";
1826 if (!entity_
->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
1827 out
<< "\n" << indent() << "inline " << id_
<< "(";
1828 bool first
= !dumpBaseMembers(out
, base
, true);
1829 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::
1830 const_iterator
i(entity_
->getDirectMembers().begin());
1831 i
!= entity_
->getDirectMembers().end(); ++i
)
1836 dumpType(out
, i
->type
, true, true);
1837 out
<< " " << i
->name
<< "_";
1840 out
<< ") SAL_THROW(());\n";
1842 if (!entity_
->getDirectMembers().empty()) {
1844 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::
1845 const_iterator
i(entity_
->getDirectMembers().begin());
1846 i
!= entity_
->getDirectMembers().end(); ++i
)
1849 dumpType(out
, i
->type
);
1850 out
<< " " << i
->name
;
1851 if (i
== entity_
->getDirectMembers().begin() && !base
.isEmpty()
1852 && i
->type
!= "hyper" && i
->type
!= "unsigned hyper"
1853 && i
->type
!= "double")
1855 out
<< " CPPU_GCC3_ALIGN("
1856 << codemaker::cpp::scopedCppName(u2b(base
)) << ")";
1862 out
<< "};\n\n#ifdef SAL_W32\n# pragma pack(pop)\n#endif\n\n";
1865 void PlainStructType::dumpHxxFile(
1866 FileStream
& out
, codemaker::cppumaker::Includes
& includes
)
1868 OUString
headerDefine(dumpHeaderDefine(out
, "HPP"));
1870 includes
.dump(out
, &name_
);
1872 if (codemaker::cppumaker::dumpNamespaceOpen(out
, name_
, false)) {
1875 out
<< "\ninline " << id_
<< "::" << id_
<< "() SAL_THROW(())\n";
1877 OUString
base(entity_
->getDirectBase());
1879 if (!base
.isEmpty()) {
1880 out
<< indent() << ": " << codemaker::cpp::scopedCppName(u2b(base
))
1884 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::const_iterator
i(
1885 entity_
->getDirectMembers().begin());
1886 i
!= entity_
->getDirectMembers().end(); ++i
)
1888 out
<< indent() << (first
? ":" : ",") << " " << i
->name
;
1889 dumpInitializer(out
, false, i
->type
);
1895 if (!entity_
->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
1896 out
<< "inline " << id_
;
1897 out
<< "::" << id_
<< "(";
1898 first
= !dumpBaseMembers(out
, base
, true);
1899 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::
1900 const_iterator
i(entity_
->getDirectMembers().begin());
1901 i
!= entity_
->getDirectMembers().end(); ++i
)
1906 dumpType(out
, i
->type
, true, true);
1907 out
<< " " << i
->name
<< "_";
1910 out
<< ") SAL_THROW(())\n";
1913 if (!base
.isEmpty()) {
1914 out
<< indent() << ": " << codemaker::cpp::scopedCppName(u2b(base
))
1916 dumpBaseMembers(out
, base
, false);
1920 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::
1921 const_iterator
i(entity_
->getDirectMembers().begin());
1922 i
!= entity_
->getDirectMembers().end(); ++i
)
1924 out
<< indent() << (first
? ":" : ",") << " " << i
->name
<< "("
1925 << i
->name
<< "_)\n";
1931 if (codemaker::cppumaker::dumpNamespaceClose(out
, name_
, false)) {
1935 dumpGetCppuType(out
);
1936 out
<< "\n#endif // "<< headerDefine
<< "\n";
1939 void PlainStructType::dumpLightGetCppuType(FileStream
& out
) {
1940 dumpGetCppuTypePreamble(out
);
1942 << ("//TODO: On certain platforms with weak memory models, the"
1943 " following code can result in some threads observing that the_type"
1944 " points to garbage\n")
1946 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
1947 << indent() << "if (the_type == 0) {\n";
1949 out
<< indent() << "::typelib_static_type_init(&the_type, "
1950 << getTypeClass(name_
, true) << ", \"" << name_
<< "\");\n";
1952 out
<< indent() << "}\n" << indent()
1953 << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >("
1955 dumpGetCppuTypePostamble(out
);
1958 void PlainStructType::dumpNormalGetCppuType(FileStream
& out
) {
1959 dumpGetCppuTypePreamble(out
);
1961 << ("//TODO: On certain platforms with weak memory models, the"
1962 " following code can result in some threads observing that the_type"
1963 " points to garbage\n")
1965 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
1966 << indent() << "if (the_type == 0) {\n";
1969 << "::typelib_TypeDescriptionReference * the_members[] = {\n";
1971 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::const_iterator
i(
1972 entity_
->getDirectMembers().begin());
1973 i
!= entity_
->getDirectMembers().end();)
1975 out
<< indent() << "::cppu::UnoType< ";
1976 dumpType(out
, i
->type
, false, false, false, true);
1978 out
<< " >::get().getTypeLibType()"
1979 << (i
== entity_
->getDirectMembers().end() ? " };" : ",") << "\n";
1982 out
<< indent() << "::typelib_static_struct_type_init(&the_type, \""
1984 if (entity_
->getDirectBase().isEmpty()) {
1987 out
<< "::cppu::UnoType< ";
1988 dumpType(out
, entity_
->getDirectBase(), false, false, false, true);
1989 out
<< " >::get().getTypeLibType()";
1991 out
<< ", " << entity_
->getDirectMembers().size() << ", the_members, 0);\n";
1993 out
<< indent() << "}\n" << indent()
1994 << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >("
1996 dumpGetCppuTypePostamble(out
);
1999 void PlainStructType::dumpComprehensiveGetCppuType(FileStream
& out
) {
2000 OUString
staticTypeClass("the" + id_
+ "Type");
2001 codemaker::cppumaker::dumpNamespaceOpen(out
, name_
, false);
2002 out
<< " namespace detail {\n\n" << indent() << "struct "
2004 << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, "
2005 << staticTypeClass
<< " >\n" << indent() << "{\n";
2007 out
<< indent() << "::com::sun::star::uno::Type * operator()() const\n"
2008 << indent() << "{\n";
2010 out
<< indent() << "::rtl::OUString the_name( \"" << name_
<< "\" );\n";
2011 std::map
< OUString
, sal_uInt32
> types
;
2012 std::vector
< unoidl::PlainStructTypeEntity::Member
>::size_type n
= 0;
2013 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::const_iterator
i(
2014 entity_
->getDirectMembers().begin());
2015 i
!= entity_
->getDirectMembers().end(); ++i
)
2018 std::map
< OUString
, sal_uInt32
>::value_type(
2019 i
->type
, static_cast< sal_uInt32
>(types
.size()))).
2022 dumpCppuGetType(out
, i
->type
, &name_
);
2023 // For typedefs, use the resolved type name, as there will be no
2024 // information available about the typedef itself at runtime (the
2025 // above getCppuType call will make available information about the
2026 // resolved type); no extra #include for the resolved type is
2027 // needed, as the header for the typedef includes it already:
2028 out
<< indent() << "::rtl::OUString the_tname"
2029 << static_cast< sal_uInt32
>(types
.size() - 1) << "( \""
2030 << resolveAllTypedefs(i
->type
) << "\" );\n";
2032 out
<< indent() << "::rtl::OUString the_name" << n
++ << "( \""
2033 << i
->name
<< "\" );\n";
2035 out
<< indent() << "::typelib_StructMember_Init the_members[] = {\n";
2038 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::const_iterator
i(
2039 entity_
->getDirectMembers().begin());
2040 i
!= entity_
->getDirectMembers().end();)
2042 out
<< indent() << "{ { " << getTypeClass(i
->type
, true)
2043 << ", the_tname" << types
.find(i
->type
)->second
2044 << ".pData, the_name" << n
++ << ".pData }, false }";
2046 out
<< (i
== entity_
->getDirectMembers().end() ? " };" : ",") << "\n";
2049 out
<< indent() << "::typelib_TypeDescription * the_newType = 0;\n"
2051 << "::typelib_typedescription_newStruct(&the_newType, the_name.pData, ";
2052 if (entity_
->getDirectBase().isEmpty()) {
2055 out
<< "::cppu::UnoType< ";
2056 dumpType(out
, entity_
->getDirectBase(), false, false, false, true);
2057 out
<< " >::get().getTypeLibType()";
2059 out
<< ", " << entity_
->getDirectMembers().size() << ", the_members);\n"
2060 << indent() << "::typelib_typedescription_register(&the_newType);\n"
2061 << indent() << "::typelib_typedescription_release(the_newType);\n"
2062 << indent() << "return new ::com::sun::star::uno::Type("
2063 << getTypeClass(name_
) << ", the_name); // leaked\n";
2065 out
<< indent() << "}\n";
2067 out
<< indent() << "};\n";
2068 codemaker::cppumaker::dumpNamespaceClose(out
, name_
, false);
2070 dumpGetCppuTypePreamble(out
);
2071 out
<< indent() << "return *detail::" << staticTypeClass
<< "::get();\n";
2072 dumpGetCppuTypePostamble(out
);
2075 bool PlainStructType::dumpBaseMembers(
2076 FileStream
& out
, OUString
const & base
, bool withType
)
2078 bool hasMember
= false;
2079 if (!base
.isEmpty()) {
2080 rtl::Reference
< unoidl::Entity
> ent
;
2081 codemaker::UnoType::Sort sort
= m_typeMgr
->getSort(base
, &ent
);
2082 if (sort
!= codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE
) {
2083 throw CannotDumpException(
2084 "plain struct type base " + base
2085 + " is not a plain struct type");
2087 rtl::Reference
< unoidl::PlainStructTypeEntity
> ent2(
2088 dynamic_cast< unoidl::PlainStructTypeEntity
* >(ent
.get()));
2090 hasMember
= dumpBaseMembers(out
, ent2
->getDirectBase(), withType
);
2091 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::
2092 const_iterator
i(ent2
->getDirectMembers().begin());
2093 i
!= ent2
->getDirectMembers().end(); ++i
)
2099 dumpType(out
, i
->type
, true, true);
2102 out
<< i
->name
<< "_";
2109 void PlainStructType::addLightGetCppuTypeIncludes(
2110 codemaker::cppumaker::Includes
& includes
) const
2113 includes
.addCppuUnotypeHxx();
2114 includes
.addSalTypesH();
2115 includes
.addTypelibTypeclassH();
2116 includes
.addTypelibTypedescriptionH();
2119 void PlainStructType::addNormalGetCppuTypeIncludes(
2120 codemaker::cppumaker::Includes
& includes
) const
2123 includes
.addCppuUnotypeHxx();
2124 includes
.addSalTypesH();
2125 includes
.addTypelibTypeclassH();
2126 includes
.addTypelibTypedescriptionH();
2129 void PlainStructType::addComprehensiveGetCppuTypeIncludes(
2130 codemaker::cppumaker::Includes
& includes
) const
2133 includes
.addCppuUnotypeHxx();
2134 includes
.addRtlInstanceHxx();
2135 includes
.addOslMutexHxx();
2136 includes
.addRtlUstringH();
2137 includes
.addRtlUstringHxx();
2138 includes
.addSalTypesH();
2139 includes
.addTypelibTypeclassH();
2140 includes
.addTypelibTypedescriptionH();
2143 sal_uInt32
PlainStructType::getTotalMemberCount(OUString
const & base
) const {
2144 if (base
.isEmpty()) {
2147 rtl::Reference
< unoidl::Entity
> ent
;
2148 codemaker::UnoType::Sort sort
= m_typeMgr
->getSort(base
, &ent
);
2149 if (sort
!= codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE
) {
2150 throw CannotDumpException(
2151 "plain struct type base " + base
+ " is not a plain struct type");
2153 rtl::Reference
< unoidl::PlainStructTypeEntity
> ent2(
2154 dynamic_cast< unoidl::PlainStructTypeEntity
* >(ent
.get()));
2156 return getTotalMemberCount(ent2
->getDirectBase())
2157 + ent2
->getDirectMembers().size(); //TODO: overflow
2160 class PolyStructType
: public CppuType
{
2163 rtl::Reference
< unoidl::PolymorphicStructTypeTemplateEntity
> const &
2165 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
):
2166 CppuType(name
, typeMgr
), entity_(entity
)
2167 { assert(entity
.is()); }
2170 virtual void dumpDeclaration(FileStream
& o
);
2172 void dumpHxxFile(FileStream
& o
, codemaker::cppumaker::Includes
& includes
);
2174 virtual void dumpLightGetCppuType(FileStream
& out
);
2176 virtual void dumpNormalGetCppuType(FileStream
& out
);
2178 virtual void dumpComprehensiveGetCppuType(FileStream
& out
);
2180 virtual void addLightGetCppuTypeIncludes(
2181 codemaker::cppumaker::Includes
& includes
) const;
2183 virtual void addNormalGetCppuTypeIncludes(
2184 codemaker::cppumaker::Includes
& includes
) const;
2186 virtual void addComprehensiveGetCppuTypeIncludes(
2187 codemaker::cppumaker::Includes
& includes
) const;
2189 virtual bool isPolymorphic() const { return true; }
2191 virtual void dumpTemplateHead(FileStream
& out
) const;
2193 virtual void dumpTemplateParameters(FileStream
& out
) const;
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 " << id_
<< " {\n";
2203 out
<< indent() << "inline " << id_
<< "() SAL_THROW(());\n";
2204 if (!entity_
->getMembers().empty()) {
2205 out
<< "\n" << indent() << "inline " << id_
<< "(";
2207 unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2208 const_iterator
i(entity_
->getMembers().begin());
2209 i
!= entity_
->getMembers().end(); ++i
)
2211 if (i
!= entity_
->getMembers().begin()) {
2214 if (i
->parameterized
) {
2215 dumpTypeParameterName(out
, i
->type
);
2218 dumpType(out
, i
->type
, true, true);
2220 out
<< " " << i
->name
<< "_";
2222 out
<< ") SAL_THROW(());\n\n";
2224 unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2225 const_iterator
i(entity_
->getMembers().begin());
2226 i
!= entity_
->getMembers().end(); ++i
)
2229 if (i
->parameterized
) {
2230 dumpTypeParameterName(out
, i
->type
);
2232 dumpType(out
, i
->type
);
2234 out
<< " " << i
->name
<< ";\n";
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"));
2246 includes
.dump(out
, &name_
);
2248 if (codemaker::cppumaker::dumpNamespaceOpen(out
, name_
, false)) {
2252 dumpTemplateHead(out
);
2253 out
<< "inline " << id_
;
2254 dumpTemplateParameters(out
);
2255 out
<< "::" << id_
<< "() SAL_THROW(())\n";
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() ? ":" : ",")
2263 dumpInitializer(out
, i
->parameterized
, i
->type
);
2268 if (!entity_
->getMembers().empty()) {
2269 dumpTemplateHead(out
);
2270 out
<< "inline " << id_
;
2271 dumpTemplateParameters(out
);
2272 out
<< "::" << id_
<< "(";
2274 unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2275 const_iterator
i(entity_
->getMembers().begin());
2276 i
!= entity_
->getMembers().end(); ++i
)
2278 if (i
!= entity_
->getMembers().begin()) {
2281 if (i
->parameterized
) {
2282 dumpTypeParameterName(out
, i
->type
);
2285 dumpType(out
, i
->type
, true, true);
2287 out
<< " " << i
->name
<< "_";
2289 out
<< ") SAL_THROW(())\n";
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";
2300 out
<< "{\n}\n\n" << indent();
2301 dumpTemplateHead(out
);
2302 out
<< "\n" << indent() << "inline " << id_
;
2303 dumpTemplateParameters(out
);
2304 out
<< "\n" << indent() << "make_" << id_
<< "(";
2306 unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2307 const_iterator
i(entity_
->getMembers().begin());
2308 i
!= entity_
->getMembers().end(); ++i
)
2310 if (i
!= entity_
->getMembers().begin()) {
2313 if (i
->parameterized
) {
2314 dumpTypeParameterName(out
, i
->type
);
2317 dumpType(out
, i
->type
, true, true);
2319 out
<< " " << i
->name
<< "_";
2321 out
<< ") SAL_THROW(())\n" << indent() << "{\n";
2323 out
<< indent() << "return " << id_
;
2324 dumpTemplateParameters(out
);
2327 unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2328 const_iterator
i(entity_
->getMembers().begin());
2329 i
!= entity_
->getMembers().end(); ++i
)
2331 if (i
!= entity_
->getMembers().begin()) {
2334 out
<< i
->name
<< "_";
2338 out
<< indent() << "}\n\n";
2340 if (codemaker::cppumaker::dumpNamespaceClose(out
, name_
, false)) {
2344 dumpGetCppuType(out
);
2345 out
<< "\n#endif // "<< headerDefine
<< "\n";
2348 void PolyStructType::dumpLightGetCppuType(FileStream
& out
) {
2349 dumpGetCppuTypePreamble(out
);
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")
2355 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
2356 << indent() << "if (the_type == 0) {\n";
2358 out
<< indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
2360 for (std::vector
< OUString
>::const_iterator
i(
2361 entity_
->getTypeParameters().begin());
2362 i
!= entity_
->getTypeParameters().end();)
2365 << ("the_buffer.append(::rtl::OUStringToOString("
2366 "::cppu::getTypeFavourChar(static_cast< ");
2367 dumpTypeParameterName(out
, *i
);
2368 out
<< " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
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";
2378 out
<< indent() << "}\n" << indent()
2379 << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >("
2381 dumpGetCppuTypePostamble(out
);
2384 void PolyStructType::dumpNormalGetCppuType(FileStream
& out
) {
2385 dumpGetCppuTypePreamble(out
);
2387 << ("//TODO: On certain platforms with weak memory models, the"
2388 " following code can result in some threads observing that the_type"
2389 " points to garbage\n")
2391 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
2392 << indent() << "if (the_type == 0) {\n";
2394 out
<< indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
2396 for (std::vector
< OUString
>::const_iterator
i(
2397 entity_
->getTypeParameters().begin());
2398 i
!= entity_
->getTypeParameters().end();)
2401 << ("the_buffer.append(::rtl::OUStringToOString("
2402 "::cppu::getTypeFavourChar(static_cast< ");
2403 dumpTypeParameterName(out
, *i
);
2404 out
<< " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
2406 if (i
!= entity_
->getTypeParameters().end()) {
2407 out
<< indent() << "the_buffer.append(',');\n";
2410 out
<< indent() << "the_buffer.append('>');\n" << indent()
2411 << "::typelib_TypeDescriptionReference * the_members[] = {\n";
2413 for (std::vector
< unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2414 const_iterator
i(entity_
->getMembers().begin());
2415 i
!= entity_
->getMembers().end();)
2418 if (i
->parameterized
) {
2419 out
<< "::cppu::getTypeFavourChar(static_cast< ";
2420 dumpTypeParameterName(out
, i
->type
);
2423 out
<< "::cppu::UnoType< ";
2424 dumpType(out
, i
->type
, false, false, false, true);
2428 out
<< ".getTypeLibType()"
2429 << (i
== entity_
->getMembers().end() ? " };" : ",") << "\n";
2432 out
<< indent() << "static ::sal_Bool const the_parameterizedTypes[] = { ";
2433 for (std::vector
< unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2434 const_iterator
i(entity_
->getMembers().begin());
2435 i
!= entity_
->getMembers().end(); ++i
)
2437 if (i
!= entity_
->getMembers().begin()) {
2440 out
<< (i
->parameterized
? "true" : "false");
2442 out
<< " };\n" << indent()
2443 << ("::typelib_static_struct_type_init(&the_type, the_buffer.getStr(),"
2445 << entity_
->getMembers().size()
2446 << ", the_members, the_parameterizedTypes);\n";
2448 out
<< indent() << "}\n" << indent()
2449 << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >("
2451 dumpGetCppuTypePostamble(out
);
2454 void PolyStructType::dumpComprehensiveGetCppuType(FileStream
& out
) {
2455 out
<< "namespace cppu { namespace detail {\n\n" << indent();
2456 dumpTemplateHead(out
);
2457 OUString
staticTypeClass("the" + id_
+ "Type");
2458 out
<< "struct " << staticTypeClass
2459 << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, "
2461 dumpTemplateParameters(out
);
2462 out
<< " >\n" << indent() << "{\n";
2464 out
<< indent() << "::com::sun::star::uno::Type * operator()() const\n"
2465 << indent() << "{\n";
2467 out
<< indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent()
2468 << "the_buffer.append(\"" << name_
<< "<\");\n";
2469 for (std::vector
< OUString
>::const_iterator
i(
2470 entity_
->getTypeParameters().begin());
2471 i
!= entity_
->getTypeParameters().end();)
2474 << "the_buffer.append(::cppu::getTypeFavourChar(static_cast< ";
2475 dumpTypeParameterName(out
, *i
);
2476 out
<< " * >(0)).getTypeName());\n";
2478 if (i
!= entity_
->getTypeParameters().end()) {
2480 << ("the_buffer.append("
2481 "static_cast< ::sal_Unicode >(','));\n");
2484 out
<< indent() << "the_buffer.append(static_cast< ::sal_Unicode >('>'));\n"
2486 << "::rtl::OUString the_name(the_buffer.makeStringAndClear());\n";
2487 std::map
< OUString
, sal_uInt32
> parameters
;
2488 std::map
< OUString
, sal_uInt32
> types
;
2489 std::vector
< unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2491 for (std::vector
< unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2492 const_iterator
i(entity_
->getMembers().begin());
2493 i
!= entity_
->getMembers().end(); ++i
)
2495 if (i
->parameterized
) {
2496 if (parameters
.insert(
2497 std::map
< OUString
, sal_uInt32
>::value_type(
2498 i
->type
, static_cast< sal_uInt32
>(parameters
.size()))).
2501 sal_uInt32 k
= static_cast< sal_uInt32
>(parameters
.size() - 1);
2503 << "::com::sun::star::uno::Type const & the_ptype" << k
2504 << " = ::cppu::getTypeFavourChar(static_cast< ";
2505 dumpTypeParameterName(out
, i
->type
);
2506 out
<< " * >(0));\n" << indent()
2507 << "::typelib_TypeClass the_pclass" << k
2508 << " = (::typelib_TypeClass) the_ptype" << k
2509 << ".getTypeClass();\n" << indent()
2510 << "::rtl::OUString the_pname" << k
<< "(the_ptype" << k
2511 << ".getTypeName());\n";
2513 } else if (types
.insert(
2514 std::map
< OUString
, sal_uInt32
>::value_type(
2515 i
->type
, static_cast< sal_uInt32
>(types
.size()))).
2518 dumpCppuGetType(out
, i
->type
, &name_
);
2519 // For typedefs, use the resolved type name, as there will be no
2520 // information available about the typedef itself at runtime (the
2521 // above getCppuType call will make available information about the
2522 // resolved type); no extra #include for the resolved type is
2523 // needed, as the header for the typedef includes it already:
2524 out
<< indent() << "::rtl::OUString the_tname"
2525 << static_cast< sal_uInt32
>(types
.size() - 1) << "( \""
2526 << resolveAllTypedefs(i
->type
) << "\" );\n";
2528 out
<< indent() << "::rtl::OUString the_name" << n
++ << "( \""
2529 << i
->name
<< "\" );\n";
2531 out
<< indent() << "::typelib_StructMember_Init the_members[] = {\n";
2534 for (std::vector
< unoidl::PolymorphicStructTypeTemplateEntity::Member
>::
2535 const_iterator
i(entity_
->getMembers().begin());
2536 i
!= entity_
->getMembers().end();)
2538 out
<< indent() << "{ { ";
2539 if (i
->parameterized
) {
2540 sal_uInt32 k
= parameters
.find(i
->type
)->second
;
2541 out
<< "the_pclass" << k
<< ", the_pname" << k
<< ".pData";
2543 out
<< getTypeClass(i
->type
, true) << ", the_tname"
2544 << types
.find(i
->type
)->second
<< ".pData";
2546 out
<< ", the_name" << n
++ << ".pData }, "
2547 << (i
->parameterized
? "true" : "false") << " }";
2549 out
<< (i
== entity_
->getMembers().end() ? " };" : ",") << "\n";
2552 out
<< indent() << "::typelib_TypeDescription * the_newType = 0;\n";
2554 << ("::typelib_typedescription_newStruct(&the_newType, the_name.pData,"
2556 << entity_
->getMembers().size() << ", the_members);\n" << indent()
2557 << "::typelib_typedescription_register(&the_newType);\n" << indent()
2558 << "::typelib_typedescription_release(the_newType);\n" << indent()
2559 << "return new ::com::sun::star::uno::Type(" << getTypeClass(name_
)
2560 << ", the_name); // leaked\n";
2562 out
<< indent() << "}\n";
2564 out
<< indent() << "};\n" << " }" << " }\n\n";
2565 dumpGetCppuTypePreamble(out
);
2566 out
<< indent() << "return *detail::" << staticTypeClass
;
2567 dumpTemplateParameters(out
);
2568 out
<< "::get();\n";
2569 dumpGetCppuTypePostamble(out
);
2572 void PolyStructType::addLightGetCppuTypeIncludes(
2573 codemaker::cppumaker::Includes
& includes
) const
2576 includes
.addCppuUnotypeHxx();
2577 includes
.addSalTypesH();
2578 includes
.addTypelibTypeclassH();
2579 includes
.addTypelibTypedescriptionH();
2580 includes
.addRtlStrbufHxx();
2581 includes
.addRtlTextencH();
2582 includes
.addRtlUstringHxx();
2585 void PolyStructType::addNormalGetCppuTypeIncludes(
2586 codemaker::cppumaker::Includes
& includes
) const
2589 includes
.addCppuUnotypeHxx();
2590 includes
.addSalTypesH();
2591 includes
.addTypelibTypeclassH();
2592 includes
.addTypelibTypedescriptionH();
2593 includes
.addRtlStrbufHxx();
2594 includes
.addRtlTextencH();
2595 includes
.addRtlUstringHxx();
2598 void PolyStructType::addComprehensiveGetCppuTypeIncludes(
2599 codemaker::cppumaker::Includes
& includes
) const
2602 includes
.addCppuUnotypeHxx();
2603 includes
.addRtlInstanceHxx();
2604 includes
.addOslMutexHxx();
2605 includes
.addRtlUstringH();
2606 includes
.addRtlUstringHxx();
2607 includes
.addSalTypesH();
2608 includes
.addTypelibTypeclassH();
2609 includes
.addTypelibTypedescriptionH();
2610 includes
.addRtlStringH();
2611 includes
.addRtlUstrbufHxx();
2614 void PolyStructType::dumpTemplateHead(FileStream
& out
) const {
2615 out
<< "template< ";
2616 for (std::vector
< OUString
>::const_iterator
i(
2617 entity_
->getTypeParameters().begin());
2618 i
!= entity_
->getTypeParameters().end(); ++i
)
2620 if (i
!= entity_
->getTypeParameters().begin()) {
2624 dumpTypeParameterName(out
, *i
);
2629 void PolyStructType::dumpTemplateParameters(FileStream
& out
) const {
2631 for (std::vector
< OUString
>::const_iterator
i(
2632 entity_
->getTypeParameters().begin());
2633 i
!= entity_
->getTypeParameters().end(); ++i
)
2635 if (i
!= entity_
->getTypeParameters().begin()) {
2638 dumpTypeParameterName(out
, *i
);
2643 OUString
typeToIdentifier(OUString
const & name
) {
2645 OUString
n(b2u(codemaker::UnoType::decompose(u2b(name
), &k
)));
2647 for (sal_Int32 i
= 0; i
!= k
; ++i
) {
2651 b
.replace(' ', '_');
2652 b
.replace(',', '_');
2653 b
.replace('.', '_');
2654 b
.replace('<', '_');
2655 b
.replace('>', '_');
2656 return b
.makeStringAndClear();
2659 class ExceptionType
: public CppuType
{
2662 rtl::Reference
< unoidl::ExceptionTypeEntity
> const & entity
,
2663 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
):
2664 CppuType(name
, typeMgr
), entity_(entity
)
2665 { assert(entity
.is()); }
2668 virtual void dumpHxxFile(
2669 FileStream
& out
, codemaker::cppumaker::Includes
& includes
);
2671 virtual void dumpLightGetCppuType(FileStream
& out
);
2673 virtual void dumpNormalGetCppuType(FileStream
& out
);
2675 virtual void dumpComprehensiveGetCppuType(FileStream
& out
);
2677 virtual sal_uInt32
checkInheritedMemberCount() const
2678 { return getTotalMemberCount(entity_
->getDirectBase()); }
2680 virtual void dumpDeclaration(FileStream
& out
);
2682 bool dumpBaseMembers(
2683 FileStream
& out
, OUString
const & base
, bool withType
);
2685 sal_uInt32
getTotalMemberCount(OUString
const & base
) const;
2687 rtl::Reference
< unoidl::ExceptionTypeEntity
> entity_
;
2690 void ExceptionType::dumpHxxFile(
2691 FileStream
& out
, codemaker::cppumaker::Includes
& includes
)
2693 OUString
headerDefine(dumpHeaderDefine(out
, "HPP"));
2695 addDefaultHxxIncludes(includes
);
2696 includes
.dump(out
, &name_
);
2698 if (codemaker::cppumaker::dumpNamespaceOpen(out
, name_
, false)) {
2701 out
<< "\ninline " << id_
<< "::" << id_
<< "() SAL_THROW(())\n";
2703 OUString
base(entity_
->getDirectBase());
2705 if (!base
.isEmpty()) {
2706 out
<< indent() << ": " << codemaker::cpp::scopedCppName(u2b(base
))
2710 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
i(
2711 entity_
->getDirectMembers().begin());
2712 i
!= entity_
->getDirectMembers().end(); ++i
)
2714 out
<< indent() << (first
? ":" : ",") << " ";
2716 dumpInitializer(out
, false, i
->type
);
2722 if (!m_cppuTypeDynamic
) {
2725 dumpCppuGetType(out
, name_
);
2731 if (!entity_
->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
2732 out
<< indent() << "inline " << id_
<< "::" << id_
<< "(";
2733 first
= !dumpBaseMembers(out
, base
, true);
2734 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
2735 i(entity_
->getDirectMembers().begin());
2736 i
!= entity_
->getDirectMembers().end(); ++i
)
2741 dumpType(out
, i
->type
, true, true);
2742 out
<< " " << i
->name
<< "_";
2745 out
<< ") SAL_THROW(())\n";
2748 if (!base
.isEmpty()) {
2749 out
<< indent() << ": " << codemaker::cpp::scopedCppName(u2b(base
))
2751 dumpBaseMembers(out
, base
, false);
2755 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
2756 i(entity_
->getDirectMembers().begin());
2757 i
!= entity_
->getDirectMembers().end(); ++i
)
2759 out
<< indent() << (first
? ":" : ",") << " " << i
->name
<< "("
2760 << i
->name
<< "_)\n";
2765 if (!m_cppuTypeDynamic
) {
2768 dumpCppuGetType(out
, name_
);
2775 out
<< indent() << id_
<< "::" << id_
<< "(" << id_
2776 << " const & the_other)";
2778 if (!base
.isEmpty()) {
2779 out
<< ": " << codemaker::cpp::scopedCppName(u2b(base
))
2783 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
i(
2784 entity_
->getDirectMembers().begin());
2785 i
!= entity_
->getDirectMembers().end(); ++i
)
2787 out
<< (first
? ":" : ",") << " " << i
->name
<< "(the_other." << i
->name
2791 out
<< indent() << " {}\n\n" << indent() << id_
<< "::~" << id_
2792 << "() {}\n\n" << indent() << id_
<< " & " << id_
<< "::operator =("
2793 << id_
<< " const & the_other) {\n";
2796 << ("//TODO: Just like its implicitly-defined counterpart, this"
2797 " function definition is not exception-safe\n");
2798 if (!base
.isEmpty()) {
2799 out
<< indent() << codemaker::cpp::scopedCppName(u2b(base
))
2800 << "::operator =(the_other);\n";
2802 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
i(
2803 entity_
->getDirectMembers().begin());
2804 i
!= entity_
->getDirectMembers().end(); ++i
)
2806 out
<< indent() << i
->name
<< " = the_other." << i
->name
<< ";\n";
2808 out
<< indent() << "return *this;\n";
2810 out
<< indent() << "}\n\n";
2811 if (codemaker::cppumaker::dumpNamespaceClose(out
, name_
, false)) {
2815 dumpGetCppuType(out
);
2816 out
<< "\n#endif // "<< headerDefine
<< "\n";
2819 void ExceptionType::dumpLightGetCppuType(FileStream
& out
) {
2820 dumpGetCppuTypePreamble(out
);
2822 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
2823 << indent() << "if ( !the_type )\n" << indent() << "{\n";
2825 out
<< indent() << "typelib_static_type_init( &the_type, "
2826 << getTypeClass(name_
, true) << ", \"" << name_
<< "\" );\n";
2828 out
<< indent() << "}\n" << indent()
2829 << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >("
2831 dumpGetCppuTypePostamble(out
);
2834 void ExceptionType::dumpNormalGetCppuType(FileStream
& out
) {
2835 dumpGetCppuTypePreamble(out
);
2837 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
2838 << indent() << "if ( !the_type )\n" << indent() << "{\n";
2840 OUString
base(entity_
->getDirectBase());
2841 bool baseException
= false;
2842 if (!base
.isEmpty()) {
2843 if (base
== "com.sun.star.uno.Exception") {
2844 baseException
= true;
2847 << ("const ::com::sun::star::uno::Type& rBaseType ="
2848 " ::cppu::UnoType< ");
2849 dumpType(out
, base
, true, false, false, true);
2850 out
<< " >::get();\n\n";
2853 if (!entity_
->getDirectMembers().empty()) {
2854 out
<< indent() << "typelib_TypeDescriptionReference * aMemberRefs["
2855 << entity_
->getDirectMembers().size() << "];\n";
2856 std::set
< OUString
> seen
;
2857 std::vector
< unoidl::ExceptionTypeEntity::Member
>::size_type n
= 0;
2858 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
2859 i(entity_
->getDirectMembers().begin());
2860 i
!= entity_
->getDirectMembers().end(); ++i
)
2862 OUString
type(resolveAllTypedefs(i
->type
));
2863 OUString
modType(typeToIdentifier(type
));
2864 if (seen
.insert(type
).second
) {
2866 << "const ::com::sun::star::uno::Type& rMemberType_"
2867 << modType
<< " = ::cppu::UnoType< ";
2868 dumpType(out
, type
, false, false, false, true);
2869 out
<< " >::get();\n";
2871 out
<< indent() << "aMemberRefs[" << n
++ << "] = rMemberType_"
2872 << modType
<< ".getTypeLibType();\n";
2876 out
<< indent() << "typelib_static_compound_type_init( &the_type, "
2877 << getTypeClass(name_
, true) << ", \"" << name_
<< "\", ";
2878 if (baseException
) {
2879 out
<< ("* ::typelib_static_type_getByTypeClass("
2880 " typelib_TypeClass_EXCEPTION )");
2881 } else if (base
.isEmpty()) {
2884 out
<< "rBaseType.getTypeLibType()";
2886 out
<< ", " << entity_
->getDirectMembers().size() << ", "
2887 << (entity_
->getDirectMembers().empty() ? "0" : "aMemberRefs")
2890 out
<< indent() << "}\n" << indent()
2891 << ("return * reinterpret_cast< const ::com::sun::star::uno::Type * >("
2893 dumpGetCppuTypePostamble(out
);
2896 void ExceptionType::dumpComprehensiveGetCppuType(FileStream
& out
) {
2897 codemaker::cppumaker::dumpNamespaceOpen(out
, name_
, false);
2898 out
<< " namespace detail {\n\n";
2899 OUString
staticTypeClass("the" + id_
+ "Type");
2900 out
<< indent() << "struct " << staticTypeClass
2901 << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, "
2902 << staticTypeClass
<< " >\n" << indent() << "{\n";
2904 out
<< indent() << "::com::sun::star::uno::Type * operator()() const\n"
2905 << indent() << "{\n";
2907 out
<< indent() << "::rtl::OUString sTypeName( \"" << name_
<< "\" );\n\n"
2908 << indent() << "// Start inline typedescription generation\n"
2909 << indent() << "typelib_TypeDescription * pTD = 0;\n";
2910 OUString
base(entity_
->getDirectBase());
2911 if (!base
.isEmpty()) {
2913 << ("const ::com::sun::star::uno::Type& rSuperType ="
2914 " ::cppu::UnoType< ");
2915 dumpType(out
, base
, false, false, false, true);
2916 out
<< " >::get();\n";
2918 std::set
< OUString
> seen
;
2919 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
i(
2920 entity_
->getDirectMembers().begin());
2921 i
!= entity_
->getDirectMembers().end(); ++i
)
2923 if (seen
.insert(i
->type
).second
) {
2924 dumpCppuGetType(out
, i
->type
);
2927 if (!entity_
->getDirectMembers().empty()) {
2928 out
<< "\n" << indent() << "typelib_CompoundMember_Init aMembers["
2929 << entity_
->getDirectMembers().size() << "];\n";
2930 std::vector
< unoidl::ExceptionTypeEntity::Member
>::size_type n
= 0;
2931 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
2932 i(entity_
->getDirectMembers().begin());
2933 i
!= entity_
->getDirectMembers().end(); ++i
)
2935 OUString
type(resolveAllTypedefs(i
->type
));
2936 out
<< indent() << "::rtl::OUString sMemberType" << n
<< "( \""
2937 << type
<< "\" );\n" << indent()
2938 << "::rtl::OUString sMemberName" << n
<< "( \"" << i
->name
2939 << "\" );\n" << indent() << "aMembers[" << n
2940 << "].eTypeClass = (typelib_TypeClass)" << getTypeClass(type
)
2941 << ";\n" << indent() << "aMembers[" << n
2942 << "].pTypeName = sMemberType" << n
<< ".pData;\n" << indent()
2943 << "aMembers[" << n
<< "].pMemberName = sMemberName" << n
2948 out
<< "\n" << indent() << "typelib_typedescription_new(\n";
2950 out
<< indent() << "&pTD,\n" << indent() << "(typelib_TypeClass)"
2951 << getTypeClass(name_
) << ", sTypeName.pData,\n" << indent()
2952 << (base
.isEmpty() ? "0" : "rSuperType.getTypeLibType()") << ",\n"
2953 << indent() << entity_
->getDirectMembers().size() << ",\n" << indent()
2954 << (entity_
->getDirectMembers().empty() ? "0" : "aMembers")
2958 << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
2960 << indent() << "typelib_typedescription_release( pTD );\n" << indent()
2961 << "// End inline typedescription generation\n\n" << indent()
2962 << "return new ::com::sun::star::uno::Type( " << getTypeClass(name_
)
2963 << ", sTypeName ); // leaked\n";
2965 out
<< indent() << "}\n";
2967 out
<< indent() << "};\n\n";
2968 codemaker::cppumaker::dumpNamespaceClose(out
, name_
, false);
2970 dumpGetCppuTypePreamble(out
);
2971 out
<< indent() << "return *detail::" << staticTypeClass
<< "::get();\n";
2972 dumpGetCppuTypePostamble(out
);
2975 void ExceptionType::dumpDeclaration(FileStream
& out
) {
2976 out
<< "\nclass CPPU_GCC_DLLPUBLIC_EXPORT " << id_
;
2977 OUString
base(entity_
->getDirectBase());
2978 if (!base
.isEmpty()) {
2979 out
<< " : public " << codemaker::cpp::scopedCppName(u2b(base
));
2981 out
<< "\n{\npublic:\n";
2983 out
<< indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
2984 << "() SAL_THROW(());\n\n";
2985 if (!entity_
->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
2986 out
<< indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
<< "(";
2987 bool first
= !dumpBaseMembers(out
, base
, true);
2988 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
2989 i(entity_
->getDirectMembers().begin());
2990 i
!= entity_
->getDirectMembers().end(); ++i
)
2995 dumpType(out
, i
->type
, true, true);
2996 out
<< " " << i
->name
<< "_";
2999 out
<< ") SAL_THROW(());\n\n";
3001 out
<< indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
<< "(" << id_
3002 << " const &);\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE ~"
3003 << id_
<< "();\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
3004 << " & operator =(" << id_
<< " const &);\n\n";
3005 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
i(
3006 entity_
->getDirectMembers().begin());
3007 i
!= entity_
->getDirectMembers().end(); ++i
)
3010 dumpType(out
, i
->type
);
3011 out
<< " " << i
->name
;
3012 if (i
== entity_
->getDirectMembers().begin() && !base
.isEmpty()
3013 && i
->type
!= "hyper" && i
->type
!= "unsigned hyper"
3014 && i
->type
!= "double")
3016 out
<< " CPPU_GCC3_ALIGN( "
3017 << codemaker::cpp::scopedCppName(u2b(base
)) << " )";
3025 bool ExceptionType::dumpBaseMembers(
3026 FileStream
& out
, OUString
const & base
, bool withType
)
3028 bool hasMember
= false;
3029 if (!base
.isEmpty()) {
3030 rtl::Reference
< unoidl::Entity
> ent
;
3031 codemaker::UnoType::Sort sort
= m_typeMgr
->getSort(base
, &ent
);
3032 if (sort
!= codemaker::UnoType::SORT_EXCEPTION_TYPE
) {
3033 throw CannotDumpException(
3034 "exception type base " + base
+ " is not an exception type");
3036 rtl::Reference
< unoidl::ExceptionTypeEntity
> ent2(
3037 dynamic_cast< unoidl::ExceptionTypeEntity
* >(ent
.get()));
3039 hasMember
= dumpBaseMembers(out
, ent2
->getDirectBase(), withType
);
3040 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::const_iterator
3041 i(ent2
->getDirectMembers().begin());
3042 i
!= ent2
->getDirectMembers().end(); ++i
)
3048 dumpType(out
, i
->type
, true, true);
3051 out
<< i
->name
<< "_";
3058 sal_uInt32
ExceptionType::getTotalMemberCount(OUString
const & base
) const {
3059 if (base
.isEmpty()) {
3062 rtl::Reference
< unoidl::Entity
> ent
;
3063 codemaker::UnoType::Sort sort
= m_typeMgr
->getSort(base
, &ent
);
3064 if (sort
!= codemaker::UnoType::SORT_EXCEPTION_TYPE
) {
3065 throw CannotDumpException(
3066 "exception type base " + base
+ " is not an exception type");
3068 rtl::Reference
< unoidl::ExceptionTypeEntity
> ent2(
3069 dynamic_cast< unoidl::ExceptionTypeEntity
* >(ent
.get()));
3071 return getTotalMemberCount(ent2
->getDirectBase())
3072 + ent2
->getDirectMembers().size(); //TODO: overflow
3075 class EnumType
: public CppuType
{
3078 rtl::Reference
< unoidl::EnumTypeEntity
> const & entity
,
3079 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
):
3080 CppuType(name
, typeMgr
), entity_(entity
)
3081 { assert(entity
.is()); }
3084 virtual void dumpDeclaration(FileStream
& o
);
3086 void dumpHxxFile(FileStream
& o
, codemaker::cppumaker::Includes
& includes
);
3088 void dumpNormalGetCppuType(FileStream
& o
);
3089 void dumpComprehensiveGetCppuType(FileStream
& o
);
3091 rtl::Reference
< unoidl::EnumTypeEntity
> entity_
;
3094 void EnumType::dumpDeclaration(FileStream
& o
)
3096 o
<< "\nenum " << id_
<< "\n{\n";
3099 for (std::vector
< unoidl::EnumTypeEntity::Member
>::const_iterator
i(
3100 entity_
->getMembers().begin());
3101 i
!= entity_
->getMembers().end(); ++i
)
3103 o
<< indent() << id_
<< "_" << u2b(i
->name
) << " = " << i
->value
3107 o
<< indent() << id_
<< "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n";
3113 void EnumType::dumpHxxFile(
3114 FileStream
& o
, codemaker::cppumaker::Includes
& includes
)
3116 OUString
headerDefine(dumpHeaderDefine(o
, "HPP"));
3119 addDefaultHxxIncludes(includes
);
3120 includes
.dump(o
, &name_
);
3125 o
<< "\n#endif // "<< headerDefine
<< "\n";
3128 void EnumType::dumpNormalGetCppuType(FileStream
& o
)
3130 dumpGetCppuTypePreamble(o
);
3133 << "static typelib_TypeDescriptionReference * the_type = 0;\n";
3135 o
<< indent() << "if ( !the_type )\n" << indent() << "{\n";
3138 o
<< indent() << "typelib_static_enum_type_init( &the_type,\n";
3140 o
<< indent() << "\"" << name_
<< "\",\n"
3141 << indent() << codemaker::cpp::scopedCppName(u2b(name_
)) << "_"
3142 << u2b(entity_
->getMembers()[0].name
) << " );\n";
3145 o
<< indent() << "}\n";
3147 << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >("
3149 dumpGetCppuTypePostamble(o
);
3152 void EnumType::dumpComprehensiveGetCppuType(FileStream
& o
)
3154 if (!isPolymorphic())
3155 codemaker::cppumaker::dumpNamespaceOpen(o
, name_
, false);
3157 o
<< "namespace cppu { ";
3158 o
<< " namespace detail {\n\n";
3160 OUString
sStaticTypeClass("the" + id_
+ "Type");
3161 o
<< indent() << "struct " << sStaticTypeClass
<< " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, " << sStaticTypeClass
<< " >\n";
3162 o
<< indent() << "{\n";
3164 o
<< indent() << "::com::sun::star::uno::Type * operator()() const\n";
3165 o
<< indent() << "{\n";
3168 o
<< indent() << "::rtl::OUString sTypeName( \"" << name_
3171 o
<< indent() << "// Start inline typedescription generation\n"
3172 << indent() << "typelib_TypeDescription * pTD = 0;\n\n";
3174 o
<< indent() << "rtl_uString* enumValueNames["
3175 << entity_
->getMembers().size() << "];\n";
3176 std::vector
< unoidl::EnumTypeEntity::Member
>::size_type n
= 0;
3177 for (std::vector
< unoidl::EnumTypeEntity::Member
>::const_iterator
i(
3178 entity_
->getMembers().begin());
3179 i
!= entity_
->getMembers().end(); ++i
)
3181 o
<< indent() << "::rtl::OUString sEnumValue" << n
<< "( \""
3182 << u2b(i
->name
) << "\" );\n";
3183 o
<< indent() << "enumValueNames[" << n
<< "] = sEnumValue" << n
3188 o
<< "\n" << indent() << "sal_Int32 enumValues["
3189 << entity_
->getMembers().size() << "];\n";
3191 for (std::vector
< unoidl::EnumTypeEntity::Member
>::const_iterator
i(
3192 entity_
->getMembers().begin());
3193 i
!= entity_
->getMembers().end(); ++i
)
3195 o
<< indent() << "enumValues[" << n
++ << "] = " << i
->value
<< ";\n";
3198 o
<< "\n" << indent() << "typelib_typedescription_newEnum( &pTD,\n";
3200 o
<< indent() << "sTypeName.pData,\n"
3201 << indent() << "(sal_Int32)"
3202 << codemaker::cpp::scopedCppName(u2b(name_
), false) << "_"
3203 << u2b(entity_
->getMembers()[0].name
) << ",\n"
3204 << indent() << entity_
->getMembers().size()
3205 << ", enumValueNames, enumValues );\n\n";
3209 << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
3211 o
<< indent() << "typelib_typedescription_release( pTD );\n"
3212 << indent() << "// End inline typedescription generation\n\n";
3214 o
<< indent() << "return new ::com::sun::star::uno::Type( "
3215 << getTypeClass(name_
) << ", sTypeName ); // leaked\n";
3218 o
<< indent() << "}\n";
3220 o
<< indent() << "};\n\n";
3222 if (!isPolymorphic())
3223 codemaker::cppumaker::dumpNamespaceClose(o
, name_
, false);
3228 dumpGetCppuTypePreamble(o
);
3229 o
<< indent() << "return *detail::" << sStaticTypeClass
<< "::get();\n";
3230 dumpGetCppuTypePostamble(o
);
3233 class Typedef
: public CppuType
{
3236 rtl::Reference
< unoidl::TypedefEntity
> const & entity
,
3237 OUString
const & name
, rtl::Reference
< TypeManager
> const & typeMgr
):
3238 CppuType(name
, typeMgr
), entity_(entity
)
3239 { assert(entity
.is()); }
3242 virtual void dumpDeclaration(FileStream
& o
);
3244 void dumpHFile(FileStream
& o
, codemaker::cppumaker::Includes
& includes
);
3246 void dumpHxxFile(FileStream
& o
, codemaker::cppumaker::Includes
& includes
);
3248 rtl::Reference
< unoidl::TypedefEntity
> entity_
;
3251 void Typedef::dumpHFile(
3252 FileStream
& o
, codemaker::cppumaker::Includes
& includes
)
3254 OUString
headerDefine(dumpHeaderDefine(o
, "HDL"));
3257 addDefaultHIncludes(includes
);
3258 includes
.dump(o
, 0);
3261 if (codemaker::cppumaker::dumpNamespaceOpen(o
, name_
, false)) {
3267 if (codemaker::cppumaker::dumpNamespaceClose(o
, name_
, false)) {
3271 o
<< "#endif // "<< headerDefine
<< "\n";
3274 void Typedef::dumpDeclaration(FileStream
& o
)
3277 dumpType(o
, entity_
->getType());
3278 o
<< " " << id_
<< ";\n\n";
3281 void Typedef::dumpHxxFile(
3282 FileStream
& o
, codemaker::cppumaker::Includes
& includes
)
3284 OUString
headerDefine(dumpHeaderDefine(o
, "HPP"));
3287 addDefaultHxxIncludes(includes
);
3288 includes
.dump(o
, &name_
);
3291 o
<< "\n#endif // "<< headerDefine
<< "\n";
3294 class ConstructiveType
: public CppuType
{
3297 OUString
const & name
, rtl::Reference
< TypeManager
> const & manager
):
3298 CppuType(name
, manager
) {}
3301 virtual void dumpHFile(FileStream
&, codemaker::cppumaker::Includes
&)
3302 { assert(false); } // this cannot happen
3304 virtual void dumpFiles(OUString
const & uri
, CppuOptions
const & options
)
3305 { dumpFile(uri
, name_
, true, options
); }
3308 bool hasRestParameter(
3309 unoidl::SingleInterfaceBasedServiceEntity::Constructor
const & constructor
)
3311 return !constructor
.parameters
.empty()
3312 && constructor
.parameters
.back().rest
;
3315 void includeExceptions(
3316 codemaker::cppumaker::Includes
& includes
,
3317 codemaker::ExceptionTreeNode
const * node
)
3319 if (node
->present
) {
3320 includes
.add(node
->name
);
3322 for (codemaker::ExceptionTreeNode::Children::const_iterator
i(
3323 node
->children
.begin());
3324 i
!= node
->children
.end(); ++i
)
3326 includeExceptions(includes
, *i
);
3331 class ServiceType
: public ConstructiveType
{
3334 rtl::Reference
< unoidl::SingleInterfaceBasedServiceEntity
> const &
3336 OUString
const & name
, rtl::Reference
< TypeManager
> const & manager
):
3337 ConstructiveType(name
, manager
), entity_(entity
)
3338 { assert(entity
.is()); }
3341 virtual void dumpHxxFile(
3342 FileStream
& o
, codemaker::cppumaker::Includes
& includes
);
3344 void dumpCatchClauses(
3345 FileStream
& out
, codemaker::ExceptionTreeNode
const * node
);
3347 rtl::Reference
< unoidl::SingleInterfaceBasedServiceEntity
> entity_
;
3350 void ServiceType::dumpHxxFile(
3351 FileStream
& o
, codemaker::cppumaker::Includes
& includes
)
3353 if (!entity_
->getConstructors().empty()) {
3354 //TODO: Decide whether the types added to includes should rather be
3355 // added to m_dependencies (and thus be generated during
3356 // dumpDependedTypes):
3357 includes
.addCassert();
3358 includes
.addReference();
3359 includes
.addRtlUstringH();
3360 includes
.addRtlUstringHxx();
3361 includes
.add("com.sun.star.uno.DeploymentException");
3362 includes
.add("com.sun.star.uno.XComponentContext");
3364 unoidl::SingleInterfaceBasedServiceEntity::Constructor
>::
3365 const_iterator
i(entity_
->getConstructors().begin());
3366 i
!= entity_
->getConstructors().end(); ++i
)
3368 if (i
->defaultConstructor
) {
3369 includes
.add("com.sun.star.uno.Exception");
3370 includes
.add("com.sun.star.uno.RuntimeException");
3372 if (!hasRestParameter(*i
)) {
3374 includes
.addSequence();
3376 unoidl::SingleInterfaceBasedServiceEntity::
3377 Constructor::Parameter
>::const_iterator
j(
3378 i
->parameters
.begin());
3379 j
!= i
->parameters
.end(); ++j
)
3381 if (m_typeMgr
->getSort(
3382 b2u(codemaker::UnoType::decompose(
3383 u2b(j
->type
), 0, 0)))
3384 == codemaker::UnoType::SORT_CHAR
)
3386 includes
.addCppuUnotypeHxx();
3391 codemaker::ExceptionTree tree
;
3392 for (std::vector
< OUString
>::const_iterator
j(
3393 i
->exceptions
.begin());
3394 j
!= i
->exceptions
.end(); ++j
)
3396 tree
.add(u2b(*j
), m_typeMgr
);
3398 if (!tree
.getRoot()->present
) {
3399 includes
.add("com.sun.star.uno.Exception");
3400 includes
.add("com.sun.star.uno.RuntimeException");
3401 includeExceptions(includes
, tree
.getRoot());
3407 codemaker::cpp::translateUnoToCppIdentifier(
3408 u2b(id_
), "service", isGlobal()));
3409 OUString
headerDefine(dumpHeaderDefine(o
, "HPP"));
3411 includes
.dump(o
, 0);
3413 if (codemaker::cppumaker::dumpNamespaceOpen(o
, name_
, false)) {
3416 o
<< "\nclass " << cppName
<< " {\n";
3418 if (!entity_
->getConstructors().empty()) {
3419 OString
baseName(u2b(entity_
->getBase()));
3420 OString
scopedBaseName(codemaker::cpp::scopedCppName(baseName
));
3423 unoidl::SingleInterfaceBasedServiceEntity::Constructor
>::
3424 const_iterator
i(entity_
->getConstructors().begin());
3425 i
!= entity_
->getConstructors().end(); ++i
)
3427 if (i
->defaultConstructor
) {
3428 o
<< indent() << "static ::com::sun::star::uno::Reference< "
3429 << scopedBaseName
<< " > "
3430 << codemaker::cpp::translateUnoToCppIdentifier(
3431 "create", "method", codemaker::cpp::ITM_NONGLOBAL
,
3433 << ("(::com::sun::star::uno::Reference<"
3434 " ::com::sun::star::uno::XComponentContext > const &"
3435 " the_context) {\n");
3437 o
<< indent() << "assert(the_context.is());\n" << indent()
3438 << "::com::sun::star::uno::Reference< " << scopedBaseName
3439 << " > the_instance;\n" << indent() << "try {\n";
3442 << "the_instance = ::com::sun::star::uno::Reference< "
3444 << (" >(the_context->getServiceManager()->"
3445 "createInstanceWithContext(::rtl::OUString("
3448 << "\" ), the_context), ::com::sun::star::uno::UNO_QUERY);\n";
3451 << "} catch (const ::com::sun::star::uno::RuntimeException &) {\n";
3453 o
<< indent() << "throw;\n";
3456 << ("} catch (const ::com::sun::star::uno::Exception &"
3457 " the_exception) {\n");
3460 << ("throw ::com::sun::star::uno::DeploymentException("
3462 "\"component context fails to supply service ")
3463 << name_
<< " of type " << baseName
3464 << ": \" ) + the_exception.Message, the_context);\n";
3466 o
<< indent() << "}\n" << indent()
3467 << "if (!the_instance.is()) {\n";
3470 << ("throw ::com::sun::star::uno::DeploymentException("
3472 "\"component context fails to supply service ")
3473 << name_
<< " of type " << baseName
3474 << "\" ), the_context);\n";
3476 o
<< indent() << "}\n" << indent() << "return the_instance;\n";
3478 o
<< indent() << "}\n\n";
3480 o
<< indent() << "static ::com::sun::star::uno::Reference< "
3481 << scopedBaseName
<< " > "
3482 << codemaker::cpp::translateUnoToCppIdentifier(
3483 u2b(i
->name
), "method", codemaker::cpp::ITM_NONGLOBAL
,
3485 << ("(::com::sun::star::uno::Reference<"
3486 " ::com::sun::star::uno::XComponentContext > const &"
3488 bool rest
= hasRestParameter(*i
);
3490 unoidl::SingleInterfaceBasedServiceEntity::Constructor::
3491 Parameter
>::const_iterator
j(i
->parameters
.begin());
3492 j
!= i
->parameters
.end(); ++j
)
3499 buf
.append(j
->type
);
3500 OUString
type(buf
.makeStringAndClear());
3501 bool byRef
= passByReference(type
);
3502 dumpType(o
, type
, byRef
, byRef
);
3504 << codemaker::cpp::translateUnoToCppIdentifier(
3505 u2b(j
->name
), "param", codemaker::cpp::ITM_NONGLOBAL
);
3509 o
<< indent() << "assert(the_context.is());\n";
3510 if (!rest
&& !i
->parameters
.empty()) {
3512 << ("::com::sun::star::uno::Sequence<"
3513 " ::com::sun::star::uno::Any > the_arguments(")
3514 << i
->parameters
.size() << ");\n";
3516 unoidl::SingleInterfaceBasedServiceEntity::Constructor::
3517 Parameter
>::size_type n
= 0;
3519 unoidl::SingleInterfaceBasedServiceEntity::
3520 Constructor::Parameter
>::const_iterator
j(
3521 i
->parameters
.begin());
3522 j
!= i
->parameters
.end(); ++j
)
3524 o
<< indent() << "the_arguments[" << n
++ << "] ";
3526 codemaker::cpp::translateUnoToCppIdentifier(
3527 u2b(j
->name
), "param",
3528 codemaker::cpp::ITM_NONGLOBAL
));
3530 if (m_typeMgr
->getSort(
3531 b2u(codemaker::UnoType::decompose(
3532 u2b(j
->type
), &rank
, 0)))
3533 == codemaker::UnoType::SORT_CHAR
)
3535 o
<< "= ::com::sun::star::uno::Any(&" << param
3536 << ", ::cppu::UnoType< ";
3537 for (sal_Int32 k
= 0; k
< rank
; ++k
) {
3538 o
<< "::cppu::UnoSequenceType< ";
3540 o
<< "::cppu::UnoCharType";
3541 for (sal_Int32 k
= 0; k
< rank
; ++k
) {
3546 o
<< "<<= " << param
;
3551 o
<< indent() << "::com::sun::star::uno::Reference< "
3552 << scopedBaseName
<< " > the_instance;\n";
3553 codemaker::ExceptionTree tree
;
3554 for (std::vector
< OUString
>::const_iterator
j(
3555 i
->exceptions
.begin());
3556 j
!= i
->exceptions
.end(); ++j
)
3558 tree
.add(u2b(*j
), m_typeMgr
);
3560 if (!tree
.getRoot()->present
) {
3561 o
<< indent() << "try {\n";
3565 << "the_instance = ::com::sun::star::uno::Reference< "
3567 << (" >(the_context->getServiceManager()->"
3568 "createInstanceWithArgumentsAndContext(::rtl::OUString("
3570 << name_
<< "\" ), ";
3572 o
<< codemaker::cpp::translateUnoToCppIdentifier(
3573 u2b(i
->parameters
.back().name
), "param",
3574 codemaker::cpp::ITM_NONGLOBAL
);
3575 } else if (i
->parameters
.empty()) {
3576 o
<< ("::com::sun::star::uno::Sequence<"
3577 " ::com::sun::star::uno::Any >()");
3579 o
<< "the_arguments";
3581 o
<< ", the_context), ::com::sun::star::uno::UNO_QUERY);\n";
3582 if (!tree
.getRoot()->present
) {
3585 << ("} catch (const ::com::sun::star::uno::RuntimeException &)"
3588 o
<< indent() << "throw;\n";
3590 dumpCatchClauses(o
, tree
.getRoot());
3592 << ("} catch (const ::com::sun::star::uno::Exception &"
3593 " the_exception) {\n");
3596 << ("throw ::com::sun::star::uno::DeploymentException("
3598 "\"component context fails to supply service ")
3599 << name_
<< " of type " << baseName
3600 << ": \" ) + the_exception.Message, the_context);\n";
3602 o
<< indent() << "}\n";
3604 o
<< indent() << "if (!the_instance.is()) {\n";
3607 << ("throw ::com::sun::star::uno::DeploymentException("
3609 "\"component context fails to supply service ")
3610 << name_
<< " of type " << baseName
3611 << "\" ), the_context);\n";
3613 o
<< indent() << "}\n" << indent() << "return the_instance;\n";
3615 o
<< indent() << "}\n\n";
3620 o
<< indent() << cppName
<< "(); // not implemented\n"
3621 << indent() << cppName
<< "(" << cppName
<< " &); // not implemented\n"
3622 << indent() << "~" << cppName
<< "(); // not implemented\n"
3623 << indent() << "void operator =(" << cppName
<< "); // not implemented\n";
3626 if (codemaker::cppumaker::dumpNamespaceClose(o
, name_
, false)) {
3629 o
<< "\n#endif // "<< headerDefine
<< "\n";
3632 void ServiceType::dumpCatchClauses(
3633 FileStream
& out
, codemaker::ExceptionTreeNode
const * node
)
3635 if (node
->present
) {
3636 out
<< indent() << "} catch (const ";
3637 dumpType(out
, b2u(node
->name
));
3640 out
<< indent() << "throw;\n";
3643 for (codemaker::ExceptionTreeNode::Children::const_iterator
i(
3644 node
->children
.begin());
3645 i
!= node
->children
.end(); ++i
)
3647 dumpCatchClauses(out
, *i
);
3652 class SingletonType
: public ConstructiveType
{
3655 rtl::Reference
< unoidl::InterfaceBasedSingletonEntity
> const & entity
,
3656 OUString
const & name
, rtl::Reference
< TypeManager
> const & manager
):
3657 ConstructiveType(name
, manager
), entity_(entity
)
3658 { assert(entity
.is()); }
3661 virtual void dumpHxxFile(
3662 FileStream
& o
, codemaker::cppumaker::Includes
& includes
);
3664 rtl::Reference
< unoidl::InterfaceBasedSingletonEntity
> entity_
;
3667 void SingletonType::dumpHxxFile(
3668 FileStream
& o
, codemaker::cppumaker::Includes
& includes
)
3671 codemaker::cpp::translateUnoToCppIdentifier(
3672 u2b(id_
), "singleton", isGlobal()));
3673 OString
baseName(u2b(entity_
->getBase()));
3674 OString
scopedBaseName(codemaker::cpp::scopedCppName(baseName
));
3675 OUString
headerDefine(dumpHeaderDefine(o
, "HPP"));
3677 //TODO: Decide whether the types added to includes should rather be added to
3678 // m_dependencies (and thus be generated during dumpDependedTypes):
3679 includes
.add("com.sun.star.uno.DeploymentException");
3680 includes
.add("com.sun.star.uno.XComponentContext");
3681 includes
.addCassert();
3683 includes
.addReference();
3684 includes
.addRtlUstringH();
3685 includes
.addRtlUstringHxx();
3686 includes
.dump(o
, 0);
3688 if (codemaker::cppumaker::dumpNamespaceOpen(o
, name_
, false)) {
3691 o
<< "\nclass " << cppName
<< " {\npublic:\n";
3693 o
<< indent() << "static ::com::sun::star::uno::Reference< "
3694 << scopedBaseName
<< " > "
3695 << codemaker::cpp::translateUnoToCppIdentifier(
3696 "get", "method", codemaker::cpp::ITM_NONGLOBAL
, &cppName
)
3697 << ("(::com::sun::star::uno::Reference<"
3698 " ::com::sun::star::uno::XComponentContext > const & the_context)"
3701 o
<< indent() << "assert(the_context.is());\n" << indent()
3702 << "::com::sun::star::uno::Reference< " << scopedBaseName
3703 << " > instance;\n" << indent()
3704 << ("if (!(the_context->getValueByName("
3705 "::rtl::OUString( \"/singletons/")
3706 << name_
<< "\" )) >>= instance) || !instance.is()) {\n";
3709 << ("throw ::com::sun::star::uno::DeploymentException("
3710 "::rtl::OUString( \"component context"
3711 " fails to supply singleton ")
3712 << name_
<< " of type " << baseName
<< "\" ), the_context);\n";
3714 o
<< indent() << "}\n" << indent() << "return instance;\n";
3716 o
<< indent() << "}\n\n";
3718 o
<< indent() << cppName
<< "(); // not implemented\n"
3719 << indent() << cppName
<< "(" << cppName
<< " &); // not implemented\n"
3720 << indent() << "~" << cppName
<< "(); // not implemented\n"
3721 << indent() << "void operator =(" << cppName
<< "); // not implemented\n";
3724 if (codemaker::cppumaker::dumpNamespaceClose(o
, name_
, false)) {
3727 o
<< "\n#endif // "<< headerDefine
<< "\n";
3733 OUString
const & name
, rtl::Reference
< TypeManager
> const & manager
,
3734 codemaker::GeneratedTypeSet
& generated
, CppuOptions
const & options
)
3736 if (generated
.contains(u2b(name
))) {
3739 generated
.add(u2b(name
));
3740 if (!manager
->foundAtPrimaryProvider(name
)) {
3743 rtl::Reference
< unoidl::Entity
> ent
;
3744 rtl::Reference
< unoidl::MapCursor
> cur
;
3745 switch (manager
->getSort(name
, &ent
, &cur
)) {
3746 case codemaker::UnoType::SORT_MODULE
:
3749 if (!name
.isEmpty()) {
3750 prefix
= name
+ ".";
3754 if (!cur
->getNext(&mem
).is()) {
3757 produce(prefix
+ mem
, manager
, generated
, options
);
3761 case codemaker::UnoType::SORT_ENUM_TYPE
:
3764 dynamic_cast< unoidl::EnumTypeEntity
* >(ent
.get()), name
,
3767 t
.dumpDependedTypes(generated
, options
);
3770 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE
:
3773 dynamic_cast< unoidl::PlainStructTypeEntity
* >(ent
.get()),
3776 t
.dumpDependedTypes(generated
, options
);
3779 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
:
3782 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity
* >(
3786 t
.dumpDependedTypes(generated
, options
);
3789 case codemaker::UnoType::SORT_EXCEPTION_TYPE
:
3792 dynamic_cast< unoidl::ExceptionTypeEntity
* >(ent
.get()), name
,
3795 t
.dumpDependedTypes(generated
, options
);
3798 case codemaker::UnoType::SORT_INTERFACE_TYPE
:
3801 dynamic_cast< unoidl::InterfaceTypeEntity
* >(ent
.get()), name
,
3804 t
.dumpDependedTypes(generated
, options
);
3807 case codemaker::UnoType::SORT_TYPEDEF
:
3810 dynamic_cast< unoidl::TypedefEntity
* >(ent
.get()), name
,
3813 t
.dumpDependedTypes(generated
, options
);
3816 case codemaker::UnoType::SORT_CONSTANT_GROUP
:
3819 dynamic_cast< unoidl::ConstantGroupEntity
* >(ent
.get()), name
,
3821 if (t
.hasConstants()) {
3826 case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE
:
3829 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity
* >(
3833 t
.dumpDependedTypes(generated
, options
);
3836 case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON
:
3839 dynamic_cast< unoidl::InterfaceBasedSingletonEntity
* >(
3843 t
.dumpDependedTypes(generated
, options
);
3846 case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE
:
3847 case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON
:
3850 throw CannotDumpException(
3851 "unexpected entity \"" + name
+ "\" in call to produce");
3855 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */