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