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 "codemaker/codemaker.hxx"
23 : #include "codemaker/commoncpp.hxx"
24 : #include "codemaker/global.hxx"
25 :
26 : #include "skeletoncommon.hxx"
27 : #include "skeletoncpp.hxx"
28 :
29 : using namespace ::rtl;
30 : using namespace ::codemaker::cpp;
31 :
32 : namespace skeletonmaker { namespace cpp {
33 :
34 0 : void printType(
35 : std::ostream & o, ProgramOptions const & options,
36 : rtl::Reference< TypeManager > const & manager,
37 : codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
38 : std::vector< OUString > const & arguments,
39 : rtl::Reference< unoidl::Entity > const & entity, short referenceType,
40 : bool defaultvalue)
41 : {
42 0 : if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) {
43 0 : switch (sort) {
44 : case codemaker::UnoType::SORT_BOOLEAN:
45 0 : o << "sal_False";
46 0 : return;
47 : case codemaker::UnoType::SORT_CHAR:
48 : case codemaker::UnoType::SORT_BYTE:
49 : case codemaker::UnoType::SORT_SHORT:
50 : case codemaker::UnoType::SORT_UNSIGNED_SHORT:
51 : case codemaker::UnoType::SORT_LONG:
52 : case codemaker::UnoType::SORT_UNSIGNED_LONG:
53 : case codemaker::UnoType::SORT_HYPER:
54 : case codemaker::UnoType::SORT_UNSIGNED_HYPER:
55 : case codemaker::UnoType::SORT_FLOAT:
56 : case codemaker::UnoType::SORT_DOUBLE:
57 0 : o << "0";
58 0 : return;
59 : default:
60 0 : break;
61 : }
62 : }
63 :
64 0 : if (defaultvalue && referenceType == 16) {
65 0 : if (sort == codemaker::UnoType::SORT_ENUM_TYPE) {
66 0 : o << nucleus.copy(nucleus.lastIndexOf('.') + 1) << "_"
67 0 : << dynamic_cast< unoidl::EnumTypeEntity * >(entity.get())->
68 0 : getMembers()[0].name;
69 : }
70 0 : return;
71 : }
72 0 : bool bReference = false;
73 0 : if (((sort > codemaker::UnoType::SORT_CHAR ||
74 0 : rank > 0) && referenceType != 8 &&
75 0 : !(sort == codemaker::UnoType::SORT_ENUM_TYPE && referenceType == 4 && rank == 0)) ||
76 0 : (sort <= codemaker::UnoType::SORT_CHAR && referenceType == 2))
77 : {
78 0 : bReference = true;
79 : }
80 :
81 0 : if (bReference && referenceType == 4)
82 0 : o << "const ";
83 :
84 0 : for (sal_Int32 i = 0; i < rank; ++i) {
85 : o << ((options.shortnames) ? "css::uno::Sequence< " :
86 0 : "::com::sun::star::uno::Sequence< ");
87 : }
88 0 : if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE && referenceType > 0) {
89 : o << ((options.shortnames) ? "css::uno::Reference< " :
90 0 : "::com::sun::star::uno::Reference< ");
91 : }
92 :
93 : o << scopedCppName(codemaker::cpp::translateUnoToCppType(sort, nucleus),
94 0 : options.shortnames && referenceType > 0);
95 :
96 0 : if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE && referenceType > 0)
97 0 : o << " >";
98 :
99 0 : if (!arguments.empty()) {
100 0 : o << "< ";
101 0 : for (std::vector< OUString >::const_iterator i(arguments.begin());
102 0 : i != arguments.end(); ++i)
103 : {
104 0 : if (i != arguments.begin())
105 0 : o << ", ";
106 :
107 0 : printType(o, options, manager, *i, 1, false);
108 : }
109 0 : o << " >";
110 : }
111 :
112 0 : for (sal_Int32 i = 0; i < rank; ++i)
113 0 : o << " >";
114 :
115 0 : if (bReference && referenceType > 1)
116 0 : o << " &";
117 :
118 0 : if (referenceType == 8 && (sort > codemaker::UnoType::SORT_CHAR || rank > 0))
119 0 : o << "()";
120 : }
121 :
122 0 : void printType(
123 : std::ostream & o, ProgramOptions const & options,
124 : rtl::Reference< TypeManager > const & manager, OUString const & name,
125 : short referenceType, bool defaultvalue)
126 : {
127 0 : OUString nucleus;
128 : sal_Int32 rank;
129 0 : std::vector< OUString > arguments;
130 0 : rtl::Reference< unoidl::Entity > entity;
131 : codemaker::UnoType::Sort sort = manager->decompose(
132 0 : name, true, &nucleus, &rank, &arguments, &entity);
133 : printType(
134 : o, options, manager, sort, nucleus, rank, arguments, entity,
135 0 : referenceType, defaultvalue);
136 0 : }
137 :
138 0 : bool printConstructorParameters(
139 : std::ostream & o, ProgramOptions const & options,
140 : rtl::Reference< TypeManager > const & manager,
141 : codemaker::UnoType::Sort sort,
142 : rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
143 : std::vector< OUString > const & arguments)
144 : {
145 0 : bool previous = false;
146 0 : switch (sort) {
147 : case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
148 : {
149 : rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
150 0 : dynamic_cast< unoidl::PlainStructTypeEntity * >(entity.get()));
151 : assert(ent2.is());
152 0 : if (!ent2->getDirectBase().isEmpty()) {
153 0 : rtl::Reference< unoidl::Entity > baseEnt;
154 : codemaker::UnoType::Sort baseSort = manager->getSort(
155 0 : ent2->getDirectBase(), &baseEnt);
156 : previous = printConstructorParameters(
157 : o, options, manager, baseSort, baseEnt,
158 0 : ent2->getDirectBase(), std::vector< OUString >());
159 : }
160 0 : for (std::vector< unoidl::PlainStructTypeEntity::Member >::
161 0 : const_iterator i(ent2->getDirectMembers().begin());
162 0 : i != ent2->getDirectMembers().end(); ++i)
163 : {
164 0 : if (previous) {
165 0 : o << ", ";
166 : }
167 0 : previous = true;
168 0 : printType(o, options, manager, i->type, 4);
169 0 : o << ' '
170 : << codemaker::cpp::translateUnoToCppIdentifier(
171 0 : u2b(i->name), "param");
172 : }
173 0 : break;
174 : }
175 : case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
176 : {
177 : rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
178 : dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
179 0 : entity.get()));
180 : assert(ent2.is());
181 0 : for (std::vector<
182 : unoidl::PolymorphicStructTypeTemplateEntity::Member >::
183 0 : const_iterator i(ent2->getMembers().begin());
184 0 : i != ent2->getMembers().end(); ++i)
185 : {
186 0 : if (previous) {
187 0 : o << ", ";
188 : }
189 0 : previous = true;
190 0 : if (i->parameterized) {
191 0 : o << i->type;
192 : } else {
193 0 : printType(o, options, manager, i->type, 4);
194 : }
195 0 : o << ' '
196 : << codemaker::cpp::translateUnoToCppIdentifier(
197 0 : u2b(i->name), "param");
198 : }
199 0 : break;
200 : }
201 : case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
202 : {
203 : rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
204 : dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
205 0 : entity.get()));
206 : assert(ent2.is());
207 0 : for (std::vector<
208 : unoidl::PolymorphicStructTypeTemplateEntity::Member >::
209 0 : const_iterator i(ent2->getMembers().begin());
210 0 : i != ent2->getMembers().end(); ++i)
211 : {
212 0 : if (previous) {
213 0 : o << ", ";
214 : }
215 0 : previous = true;
216 0 : if (i->parameterized) {
217 0 : for (std::vector< OUString >::const_iterator j(
218 0 : ent2->getTypeParameters().begin());
219 0 : j != ent2->getTypeParameters().end(); ++j)
220 : {
221 0 : if (i->type == *j) {
222 : o << arguments[
223 0 : j - ent2->getTypeParameters().begin()];
224 0 : break;
225 : }
226 : }
227 : } else {
228 0 : printType(o, options, manager, i->type, 4);
229 : }
230 0 : o << ' '
231 : << codemaker::cpp::translateUnoToCppIdentifier(
232 0 : u2b(i->name), "param");
233 : }
234 0 : break;
235 : }
236 : case codemaker::UnoType::SORT_EXCEPTION_TYPE:
237 : {
238 : rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
239 0 : dynamic_cast< unoidl::ExceptionTypeEntity * >(entity.get()));
240 : assert(ent2.is());
241 0 : if (!ent2->getDirectBase().isEmpty()) {
242 0 : rtl::Reference< unoidl::Entity > baseEnt;
243 : codemaker::UnoType::Sort baseSort = manager->getSort(
244 0 : ent2->getDirectBase(), &baseEnt);
245 : previous = printConstructorParameters(
246 : o, options, manager, baseSort, baseEnt,
247 0 : ent2->getDirectBase(), std::vector< OUString >());
248 : }
249 0 : for (std::vector< unoidl::ExceptionTypeEntity::Member >::
250 0 : const_iterator i(ent2->getDirectMembers().begin());
251 0 : i != ent2->getDirectMembers().end(); ++i)
252 : {
253 0 : if (previous) {
254 0 : o << ", ";
255 : }
256 0 : previous = true;
257 0 : printType(o, options, manager, i->type, 4);
258 0 : o << ' '
259 : << codemaker::cpp::translateUnoToCppIdentifier(
260 0 : u2b(i->name), "param");
261 : }
262 0 : break;
263 : }
264 : default:
265 : throw CannotDumpException(
266 0 : "unexpected entity \"" + name
267 0 : + "\" in call to skeletonmaker::cpp::printConstructorParameters");
268 : }
269 0 : return previous;
270 : }
271 :
272 0 : void printConstructor(
273 : std::ostream & o, ProgramOptions const & options,
274 : rtl::Reference< TypeManager > const & manager,
275 : codemaker::UnoType::Sort sort,
276 : rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
277 : std::vector< OUString > const & arguments)
278 : {
279 0 : o << "public " << name.copy(name.lastIndexOf('.') + 1) << '(';
280 : printConstructorParameters(
281 0 : o, options, manager, sort, entity, name, arguments);
282 0 : o << ");\n";
283 0 : }
284 :
285 0 : void printMethodParameters(
286 : std::ostream & o, ProgramOptions const & options,
287 : rtl::Reference< TypeManager > const & manager,
288 : std::vector< unoidl::InterfaceTypeEntity::Method::Parameter > const &
289 : parameters,
290 : bool withType)
291 : {
292 0 : for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
293 0 : const_iterator i(parameters.begin());
294 0 : i != parameters.end(); ++i)
295 : {
296 0 : if (i != parameters.begin()) {
297 0 : o << ", ";
298 : }
299 0 : if (withType) {
300 : short referenceType;
301 0 : if (i->direction
302 0 : == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
303 : {
304 0 : referenceType = 4;
305 : } else {
306 0 : referenceType = 2;
307 : }
308 0 : printType(o, options, manager, i->type, referenceType);
309 0 : o << ' ';
310 : }
311 0 : o << codemaker::cpp::translateUnoToCppIdentifier(u2b(i->name), "param");
312 : }
313 0 : }
314 :
315 0 : void printExceptionSpecification(
316 : std::ostream & o,
317 : ProgramOptions const & options,
318 : rtl::Reference< TypeManager > const & manager,
319 : std::vector< OUString > const & exceptions)
320 : {
321 : o << ((options.shortnames) ? " throw (css::uno::RuntimeException" :
322 0 : " throw (::com::sun::star::uno::RuntimeException");
323 0 : for (std::vector< OUString >::const_iterator i(exceptions.begin());
324 0 : i != exceptions.end(); ++i)
325 : {
326 0 : o << ", ";
327 0 : printType(o, options, manager, *i, 1);
328 : }
329 0 : o << ")";
330 0 : }
331 :
332 0 : void printSetPropertyMixinBody(
333 : std::ostream & o, unoidl::InterfaceTypeEntity::Attribute const & attribute)
334 : {
335 : unoidl::AccumulationBasedServiceEntity::Property::Attributes propFlags
336 0 : = checkAdditionalPropertyFlags(attribute);
337 :
338 0 : o << "\n{\n";
339 :
340 0 : if (attribute.bound)
341 0 : o << " BoundListeners l;\n";
342 :
343 0 : if (propFlags & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_CONSTRAINED) {
344 0 : OString fieldtype = codemaker::convertString(attribute.type);
345 :
346 0 : sal_Int32 index = fieldtype.lastIndexOf('<');
347 0 : sal_Int32 nPos=0;
348 0 : bool single = true;
349 0 : bool optional = false;
350 0 : OStringBuffer buffer1(64);
351 0 : OStringBuffer buffer2(64);
352 0 : do
353 : {
354 0 : OString s(fieldtype.getToken(0, '<', nPos));
355 0 : OString t = s.copy(s.lastIndexOf('/')+1);
356 :
357 0 : if (t.equals("Optional")) {
358 0 : optional=true;
359 0 : if (single) {
360 0 : single=false;
361 0 : buffer1.append("the_value.IsPresent");
362 0 : buffer2.append("the_value.Value");
363 : } else {
364 0 : buffer1.insert(0, t);
365 0 : buffer1.append(".IsPresent");
366 0 : buffer2.insert(0, t);
367 0 : buffer2.append(".Value");
368 : }
369 : } else {
370 0 : if (single) {
371 0 : single=false;
372 0 : if (!optional)
373 0 : buffer1.append("the_value.Value");
374 :
375 0 : buffer2.append("the_value.Value");
376 : } else {
377 0 : if (!optional) {
378 0 : buffer1.insert(0, t);
379 0 : buffer1.append(".Value");
380 : }
381 0 : buffer2.insert(0, t);
382 0 : buffer2.append(".Value");
383 : }
384 0 : }
385 0 : } while( nPos <= index );
386 :
387 0 : o << " css::uno::Any v;\n";
388 0 : if (optional) {
389 0 : o << " if(" << buffer1.makeStringAndClear() << ")\n {\n"
390 0 : << " v <<= " << buffer2.makeStringAndClear() << ";\n }\n";
391 : } else {
392 0 : o << " v <<= " << buffer2.makeStringAndClear() << ";\n\n";
393 : }
394 :
395 0 : o << " prepareSet(\n rtl::OUString(\""
396 0 : << attribute.name << "\"),\n css::uno::Any(), v, ";
397 : } else {
398 0 : o << " prepareSet(\n rtl::OUString(\""
399 0 : << attribute.name << "\"),\n css::uno::Any(), css::uno::Any(), ";
400 : }
401 :
402 0 : if (attribute.bound)
403 0 : o << "&l);\n";
404 : else
405 0 : o << "0);\n";
406 :
407 0 : o << " {\n osl::MutexGuard g(m_aMutex);\n m_"
408 0 : << attribute.name << " = the_value;\n }\n";
409 :
410 0 : if (attribute.bound)
411 0 : o << " l.notify();\n";
412 :
413 0 : o << "}\n\n";
414 0 : }
415 :
416 : void generateXPropertySetBodies(std::ostream& o,
417 : const OString & classname,
418 : const OString & interfaceName);
419 : void generateXFastPropertySetBodies(std::ostream& o,
420 : const OString & classname,
421 : const OString & interfaceName);
422 : void generateXPropertyAccessBodies(std::ostream& o,
423 : const OString & classname,
424 : const OString & interfaceName);
425 :
426 : void generateXAddInBodies(std::ostream& o, const OString & classname);
427 :
428 : void generateXLocalizable(std::ostream& o, const OString & classname);
429 :
430 : void generateXCompatibilityNamesBodies(std::ostream& o, const OString & classname);
431 :
432 : void generateXInitialization(std::ostream& o, const OString & classname);
433 :
434 : void generateXDispatch(std::ostream& o,
435 : const OString & classname,
436 : const ProtocolCmdMap & protocolCmdMap);
437 :
438 : void generateXDispatchProvider(std::ostream& o,
439 : const OString & classname,
440 : const ProtocolCmdMap & protocolCmdMap);
441 :
442 :
443 0 : void printMethods(std::ostream & o,
444 : ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
445 : OUString const & name, codemaker::GeneratedTypeSet & generated,
446 : OString const & delegate, OString const & classname,
447 : OString const & indentation, bool defaultvalue,
448 : OUString const & propertyhelper)
449 : {
450 0 : if (generated.contains(u2b(name)) || name == "com.sun.star.uno.XInterface" ||
451 0 : (defaultvalue &&
452 0 : ( name == "com.sun.star.lang.XComponent" ||
453 0 : name == "com.sun.star.lang.XTypeProvider" ||
454 0 : name == "com.sun.star.uno.XWeak" ) ) )
455 : {
456 0 : return;
457 : }
458 :
459 0 : static OString sd("_");
460 0 : bool body = !delegate.isEmpty();
461 0 : bool defaultbody = ((delegate.equals(sd)) ? true : false);
462 :
463 0 : if (body && propertyhelper.getLength() > 1) {
464 0 : if (name == "com.sun.star.beans.XPropertySet") {
465 0 : generated.add(u2b(name));
466 : generateXPropertySetBodies(
467 0 : o, classname, scopedCppName(u2b(propertyhelper)));
468 0 : return;
469 0 : } else if (name == "com.sun.star.beans.XFastPropertySet") {
470 0 : generated.add(u2b(name));
471 : generateXFastPropertySetBodies(
472 0 : o, classname, scopedCppName(u2b(propertyhelper)));
473 0 : return;
474 0 : } else if (name == "com.sun.star.beans.XPropertyAccess") {
475 0 : generated.add(u2b(name));
476 : generateXPropertyAccessBodies(
477 0 : o, classname, scopedCppName(u2b(propertyhelper)));
478 0 : return;
479 : }
480 : }
481 :
482 0 : if (body && options.componenttype == 2) {
483 0 : if (name == "com.sun.star.lang.XServiceName") {
484 : o << "// ::com::sun::star::lang::XServiceName:\n"
485 0 : "::rtl::OUString SAL_CALL " << classname << "getServiceName() "
486 : "throw (css::uno::RuntimeException)\n{\n "
487 : "return ::rtl::OUString("
488 0 : "sADDIN_SERVICENAME);\n}\n";
489 0 : generated.add(u2b(name));
490 0 : return;
491 0 : } else if (name == "com.sun.star.sheet.XAddIn") {
492 0 : generateXAddInBodies(o, classname);
493 0 : generated.add(u2b(name));
494 :
495 : // special handling of XLocalizable -> parent of XAddIn
496 0 : if (!generated.contains("com.sun.star.lang.XLocalizable")) {
497 0 : generateXLocalizable(o, classname);
498 0 : generated.add("com.sun.star.lang.XLocalizable");
499 : }
500 0 : return;
501 0 : } else if (name == "com.sun.star.lang.XLocalizable") {
502 0 : generateXLocalizable(o, classname);
503 0 : generated.add(u2b(name));
504 0 : return;
505 0 : } else if (name == "com.sun.star.sheet.XCompatibilityNames") {
506 0 : generateXCompatibilityNamesBodies(o, classname);
507 0 : generated.add(u2b(name));
508 0 : return;
509 : }
510 : }
511 :
512 0 : if (body && options.componenttype == 3) {
513 0 : if (name == "com.sun.star.lang.XInitialization") {
514 0 : generateXInitialization(o, classname);
515 0 : generated.add(u2b(name));
516 0 : return;
517 0 : } else if (name == "com.sun.star.frame.XDispatch") {
518 0 : generateXDispatch(o, classname, options.protocolCmdMap);
519 0 : generated.add(u2b(name));
520 0 : return;
521 0 : } else if (name == "com.sun.star.frame.XDispatchProvider") {
522 0 : generateXDispatchProvider(o, classname, options.protocolCmdMap);
523 0 : generated.add(u2b(name));
524 0 : return;
525 : }
526 : }
527 :
528 0 : generated.add(u2b(name));
529 0 : rtl::Reference< unoidl::Entity > ent;
530 0 : if (manager->getSort(name, &ent) != codemaker::UnoType::SORT_INTERFACE_TYPE)
531 : {
532 : throw CannotDumpException(
533 0 : "unexpected entity \"" + name
534 0 : + "\" in call to skeletonmaker::cpp::printMethods");
535 : }
536 : rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
537 0 : dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
538 : assert(ent2.is());
539 0 : if (options.all || defaultvalue) {
540 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
541 0 : ent2->getDirectMandatoryBases().begin());
542 0 : i != ent2->getDirectMandatoryBases().end(); ++i)
543 : {
544 : printMethods(
545 0 : o, options, manager, i->name, generated, delegate, classname,
546 0 : indentation, defaultvalue, propertyhelper);
547 : }
548 0 : if (!(ent2->getDirectAttributes().empty()
549 0 : && ent2->getDirectMethods().empty()))
550 : {
551 0 : o << indentation << "// ";
552 0 : printType(o, options, manager, name, 0);
553 0 : o << ":\n";
554 : }
555 : }
556 0 : for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
557 0 : i(ent2->getDirectAttributes().begin());
558 0 : i != ent2->getDirectAttributes().end(); ++i)
559 : {
560 0 : o << indentation;
561 0 : if (!body)
562 0 : o << "virtual ";
563 :
564 0 : printType(o, options, manager, i->type, 1);
565 0 : o << " SAL_CALL ";
566 0 : if (!classname.isEmpty())
567 0 : o << classname;
568 :
569 0 : o << "get" << i->name << "()";
570 0 : printExceptionSpecification(o, options, manager, i->getExceptions);
571 0 : if (body) {
572 0 : if (defaultbody) {
573 0 : if (!propertyhelper.isEmpty()) {
574 0 : o << "\n{\n osl::MutexGuard g(m_aMutex);\n return m_"
575 0 : << i->name << ";\n}\n\n";
576 : } else {
577 0 : o << "\n{\n return ";
578 0 : if (options.componenttype == 1) {
579 0 : o << "m_" << i->name;
580 : } else {
581 0 : printType(o, options, manager, i->type, 8, true);
582 : }
583 0 : o << ";\n}\n\n";
584 : }
585 : } else {
586 0 : o << "\n" << indentation << "{\n" << indentation << " return "
587 0 : << delegate.getStr() << "get" << i->name << "();\n"
588 0 : << indentation << "}\n\n";
589 : }
590 : } else {
591 0 : o << ";\n";
592 : }
593 :
594 0 : if (!i->readOnly) {
595 0 : o << indentation;
596 0 : if (!body)
597 0 : o << "virtual ";
598 :
599 0 : o << "void SAL_CALL ";
600 0 : if (!classname.isEmpty())
601 0 : o << classname;
602 :
603 0 : o << "set" << i->name << '(';
604 0 : printType(o, options, manager, i->type, 4);
605 0 : o << " the_value)";
606 0 : printExceptionSpecification(o, options, manager, i->setExceptions);
607 0 : if (body) {
608 0 : if (defaultbody) {
609 0 : if (!propertyhelper.isEmpty()) {
610 0 : printSetPropertyMixinBody(o, *i);
611 : } else {
612 0 : if (options.componenttype == 1) {
613 0 : o << "\n{\n m_" << i->name
614 0 : << " = the_value;\n}\n\n";
615 : } else {
616 0 : o << "\n{\n\n}\n\n";
617 : }
618 : }
619 : } else {
620 0 : o << "\n" << indentation << "{\n" << indentation << " "
621 0 : << delegate.getStr() << "set" << i->name
622 0 : << "(the_value);\n" << indentation << "}\n\n";
623 : }
624 : } else {
625 0 : o << ";\n";
626 : }
627 : }
628 : }
629 0 : for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
630 0 : ent2->getDirectMethods().begin());
631 0 : i != ent2->getDirectMethods().end(); ++i)
632 : {
633 0 : o << indentation;
634 0 : if (!body)
635 0 : o << "virtual ";
636 :
637 0 : printType(o, options, manager, i->returnType, 1);
638 0 : o << " SAL_CALL ";
639 0 : if (!classname.isEmpty())
640 0 : o << classname;
641 :
642 0 : o << i->name << '(';
643 0 : printMethodParameters(o, options, manager, i->parameters, true);
644 0 : o << ')';
645 0 : printExceptionSpecification(o, options, manager, i->exceptions);
646 0 : if (body) {
647 0 : if (defaultbody) {
648 0 : o << "\n{\n";
649 0 : if (i->returnType != "void") {
650 0 : o << " // TODO: Exchange the default return implementation for \""
651 0 : << i->name << "\" !!!\n";
652 : o << " // Exchange the default return implementation.\n"
653 : " // NOTE: Default initialized polymorphic structs "
654 : "can cause problems because of\n // missing default "
655 : "initialization of primitive types of some C++ compilers or"
656 : "\n // different Any initialization in Java and C++ "
657 0 : "polymorphic structs.\n return ";
658 0 : printType(o, options, manager, i->returnType, 8, true);
659 0 : o << ";";
660 : } else {
661 0 : o << " // TODO: Insert your implementation for \""
662 0 : << i->name << "\" here.";
663 : }
664 0 : o << "\n}\n\n";
665 : } else {
666 0 : o << "\n" << indentation << "{\n" << indentation << " ";
667 0 : if (i->returnType != "void")
668 0 : o << "return ";
669 :
670 0 : o << delegate.getStr() << i->name << '(';
671 : printMethodParameters(
672 0 : o, options, manager, i->parameters, false);
673 0 : o << ");\n" << indentation << "}\n\n";
674 : }
675 : } else {
676 0 : o << ";\n";
677 : }
678 : }
679 :
680 0 : if (!body)
681 0 : o << "\n";
682 : }
683 :
684 0 : void printConstructors(
685 : std::ostream & o, ProgramOptions const & options,
686 : rtl::Reference< TypeManager > const & manager, OUString const & name)
687 : {
688 0 : rtl::Reference< unoidl::Entity > ent;
689 0 : if (manager->getSort(name, &ent)
690 : != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE)
691 : {
692 : throw CannotDumpException(
693 0 : "unexpected entity \"" + name
694 0 : + "\" in call to skeletonmaker::java::printConstructors");
695 : }
696 : rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
697 0 : dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(ent.get()));
698 : assert(ent2.is());
699 0 : for (std::vector< unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
700 0 : const_iterator i(ent2->getConstructors().begin());
701 0 : i != ent2->getConstructors().end(); ++i)
702 : {
703 0 : o << "static ";
704 0 : printType(o, options, manager, ent2->getBase(), 1);
705 0 : o << ' ';
706 0 : if (i->defaultConstructor) {
707 0 : o << "create";
708 : } else {
709 : o << codemaker::cpp::translateUnoToCppIdentifier(
710 0 : u2b(i->name), "method");
711 : }
712 : o << ((options.shortnames) ? "(css::uno::Reference< css" :
713 0 : "(::com::sun::star::uno::Reference< ::com::sun::star")
714 0 : << "::uno::XComponentContext > const & the_context";
715 0 : for (std::vector<
716 : unoidl::SingleInterfaceBasedServiceEntity::Constructor::
717 0 : Parameter >::const_iterator j(i->parameters.begin());
718 0 : j != i->parameters.end(); ++j)
719 : {
720 0 : o << ", ";
721 0 : printType(o, options, manager, j->type, 4);
722 0 : o << ' '
723 : << codemaker::cpp::translateUnoToCppIdentifier(
724 0 : u2b(j->name), "param");
725 : }
726 0 : o << ')';
727 0 : printExceptionSpecification(o, options, manager, i->exceptions);
728 0 : o << ";\n";
729 0 : }
730 0 : }
731 :
732 0 : void printServiceMembers(
733 : std::ostream & o, ProgramOptions const & options,
734 : rtl::Reference< TypeManager > const & manager,
735 : OUString const & name,
736 : rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity,
737 : OString const & delegate)
738 : {
739 : assert(entity.is());
740 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
741 0 : entity->getDirectMandatoryBaseServices().begin());
742 0 : i != entity->getDirectMandatoryBaseServices().end(); ++i)
743 : {
744 0 : o << "\n// exported service " << i->name << "\n";
745 0 : generateDocumentation(o, options, manager, u2b(i->name), delegate);
746 0 : o << "\n// end of exported service " << i->name << "\n";
747 : }
748 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
749 0 : entity->getDirectMandatoryBaseInterfaces().begin());
750 0 : i != entity->getDirectMandatoryBaseInterfaces().end(); ++i)
751 : {
752 0 : o << "\n// supported interface " << i->name << "\n";
753 0 : generateDocumentation(o, options, manager, u2b(i->name), delegate);
754 : }
755 0 : if (delegate.isEmpty()) {
756 0 : o << "\n// properties of service \""<< name << "\"\n";
757 0 : for (std::vector< unoidl::AccumulationBasedServiceEntity::Property >::
758 0 : const_iterator i(entity->getDirectProperties().begin());
759 0 : i != entity->getDirectProperties().end(); ++i)
760 : {
761 0 : o << "// private ";
762 0 : printType(o, options, manager, i->type, 1);
763 0 : o << " "
764 : << codemaker::cpp::translateUnoToCppIdentifier(
765 0 : u2b(i->name), "property")
766 0 : << ";\n";
767 : }
768 : }
769 0 : }
770 :
771 0 : void printMapsToCppType(
772 : std::ostream & o, ProgramOptions const & options,
773 : rtl::Reference< TypeManager > const & manager,
774 : codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
775 : std::vector< OUString > const & arguments,
776 : rtl::Reference< unoidl::Entity > const & entity, const char * cppTypeSort)
777 : {
778 0 : o << "maps to C++ ";
779 0 : if (cppTypeSort != 0)
780 0 : o << cppTypeSort << ' ';
781 :
782 0 : o << "type \"";
783 0 : if (rank == 0 && nucleus == "com.sun.star.uno.XInterface") {
784 0 : o << "Reference< com::sun::star::uno::XInterface >";
785 : } else {
786 : printType(
787 : o, options, manager, sort, nucleus, rank, arguments, entity, 0,
788 0 : false);
789 : }
790 0 : o << '"';
791 0 : }
792 :
793 0 : void generateDocumentation(std::ostream & o,
794 : ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
795 : OString const & type, OString const & delegate)
796 : {
797 0 : OUString nucleus;
798 : sal_Int32 rank;
799 : codemaker::UnoType::Sort sort = manager->decompose(
800 0 : b2u(type), false, &nucleus, &rank, 0, 0);
801 :
802 0 : bool comment = true;
803 0 : if (!delegate.isEmpty()) {
804 0 : if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE &&
805 0 : sort != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE &&
806 : sort != codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE )
807 : {
808 0 : return;
809 : }
810 0 : comment = false;
811 : }
812 :
813 0 : if (comment) {
814 0 : o << "\n// UNO";
815 0 : if (rank != 0) {
816 0 : o << " sequence type";
817 0 : } else if (sort <= codemaker::UnoType::SORT_ANY) {
818 0 : o << " simple type";
819 : } else {
820 0 : switch (sort) {
821 : case codemaker::UnoType::SORT_INTERFACE_TYPE:
822 0 : o << " interface type";
823 0 : break;
824 :
825 : case codemaker::UnoType::SORT_MODULE:
826 0 : o << "IDL module";
827 0 : break;
828 :
829 : case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
830 0 : o << " simple struct type";
831 0 : break;
832 :
833 : case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
834 0 : o << " polymorphic struct type template";
835 0 : break;
836 :
837 : case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
838 0 : o << " instantiated polymorphic struct type";
839 0 : break;
840 :
841 : case codemaker::UnoType::SORT_ENUM_TYPE:
842 0 : o << " enum type";
843 0 : break;
844 :
845 : case codemaker::UnoType::SORT_EXCEPTION_TYPE:
846 0 : o << " exception type";
847 0 : break;
848 :
849 : case codemaker::UnoType::SORT_TYPEDEF:
850 0 : o << "IDL typedef";
851 0 : break;
852 :
853 : case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
854 0 : o << " single-inheritance--based service";
855 0 : break;
856 :
857 : case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
858 0 : o << "IDL accumulation-based service";
859 0 : break;
860 :
861 : case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
862 0 : o << " inheritance-based singleton";
863 0 : break;
864 :
865 : case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
866 0 : o << "IDL service-based singleton";
867 0 : break;
868 :
869 : case codemaker::UnoType::SORT_CONSTANT_GROUP:
870 0 : o << "IDL constant group";
871 0 : break;
872 :
873 : default:
874 : OSL_ASSERT(false);
875 0 : break;
876 : }
877 : }
878 0 : o << " \"" << type << "\" ";
879 : }
880 0 : std::vector< OUString > arguments;
881 0 : rtl::Reference< unoidl::Entity > entity;
882 : sort = manager->decompose(
883 0 : b2u(type), true, &nucleus, &rank, &arguments, &entity);
884 0 : if (rank != 0) {
885 0 : if (comment) {
886 : printMapsToCppType(
887 : o, options, manager, sort, nucleus, rank, arguments, entity,
888 0 : "array");
889 0 : o << '\n';
890 : }
891 0 : } else if (sort <= codemaker::UnoType::SORT_ANY) {
892 0 : if (comment) {
893 : printMapsToCppType(
894 0 : o, options, manager, sort, nucleus, rank, arguments, entity, 0);
895 0 : o << '\n';
896 : }
897 : } else {
898 0 : switch (sort) {
899 : case codemaker::UnoType::SORT_INTERFACE_TYPE:
900 0 : if (comment)
901 : printMapsToCppType(
902 : o, options, manager, sort, nucleus, rank, arguments, entity,
903 0 : "interface");
904 0 : if (nucleus == "com.sun.star.uno.XInterface") {
905 0 : if (comment)
906 0 : o << '\n';
907 : } else {
908 0 : if (comment)
909 0 : o << "; " << (options.all ? "all" : "direct") << " methods:\n";
910 :
911 0 : codemaker::GeneratedTypeSet generated;
912 : printMethods(
913 : o, options, manager, nucleus, generated, delegate,
914 0 : options.implname, "");
915 : }
916 0 : break;
917 :
918 : case codemaker::UnoType::SORT_MODULE:
919 : printMapsToCppType(
920 : o, options, manager, sort, nucleus, rank, arguments, entity,
921 0 : "namespace");
922 0 : o << '\n';
923 0 : break;
924 :
925 : case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
926 : printMapsToCppType(
927 : o, options, manager, sort, nucleus, rank, arguments, entity,
928 0 : "class");
929 0 : o << "; full constructor:\n";
930 : printConstructor(
931 : o, options, manager, codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE,
932 0 : entity, nucleus, arguments);
933 0 : break;
934 :
935 : case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
936 : printMapsToCppType(
937 : o, options, manager, sort, nucleus, rank, arguments, entity,
938 0 : options.java5 ? "generic class" : "class");
939 0 : o << "; full constructor:\n";
940 : printConstructor(
941 : o, options, manager,
942 : codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE,
943 0 : entity, nucleus, arguments);
944 0 : break;
945 :
946 : case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
947 : printMapsToCppType(
948 : o, options, manager, sort, nucleus, rank, arguments, entity,
949 0 : options.java5 ? "generic class instantiation" : "class");
950 0 : o << "; full constructor:\n";
951 : printConstructor(
952 : o, options, manager,
953 : codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE,
954 0 : entity, nucleus, arguments);
955 0 : break;
956 :
957 : case codemaker::UnoType::SORT_ENUM_TYPE:
958 : printMapsToCppType(
959 : o, options, manager, sort, nucleus, rank, arguments, entity,
960 0 : "enum");
961 0 : o << '\n';
962 0 : break;
963 :
964 : case codemaker::UnoType::SORT_CONSTANT_GROUP:
965 : printMapsToCppType(
966 : o, options, manager, sort, nucleus, rank, arguments, entity,
967 0 : "namespace");
968 0 : o << '\n';
969 0 : break;
970 :
971 : case codemaker::UnoType::SORT_EXCEPTION_TYPE:
972 : printMapsToCppType(
973 : o, options, manager, sort, nucleus, rank, arguments, entity,
974 0 : "exception class");
975 0 : o << "; full constructor:\n";
976 : printConstructor(
977 : o, options, manager, codemaker::UnoType::SORT_EXCEPTION_TYPE,
978 0 : entity, nucleus, arguments);
979 0 : break;
980 :
981 : case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
982 0 : if (comment) {
983 : printMapsToCppType(
984 : o, options, manager, sort, nucleus, rank, arguments, entity,
985 0 : "class");
986 0 : o << "; construction methods:\n";
987 0 : printConstructors(o, options, manager, nucleus);
988 : }
989 : generateDocumentation(
990 : o, options, manager,
991 : u2b(dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
992 0 : entity.get())->getBase()),
993 0 : delegate);
994 0 : break;
995 :
996 : case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
997 0 : if (comment)
998 : o << ("does not map to C++\n"
999 0 : "// the service members are generated instead\n");
1000 : printServiceMembers(
1001 : o, options, manager, nucleus,
1002 : dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
1003 0 : entity.get()),
1004 0 : delegate);
1005 0 : break;
1006 :
1007 : case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
1008 : printMapsToCppType(
1009 : o, options, manager, sort, nucleus, rank, arguments, entity,
1010 0 : "class");
1011 0 : o << "; get method:\nstatic ";
1012 : printType(
1013 : o, options, manager,
1014 : dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
1015 0 : entity.get())->getBase(),
1016 0 : 1);
1017 0 : o << " get(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);\n";
1018 0 : break;
1019 :
1020 : case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
1021 0 : o << "does not map to C++\n";
1022 0 : break;
1023 :
1024 : default:
1025 : OSL_ASSERT(false);
1026 0 : break;
1027 : }
1028 0 : }
1029 : }
1030 :
1031 : } }
1032 :
1033 :
1034 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|