1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_codemaker.hxx"
24
25 #include <stdio.h>
26 #include <rtl/alloc.h>
27 #include <rtl/ustring.hxx>
28 #include <rtl/strbuf.hxx>
29
30 #include "corbatype.hxx"
31 #include "corbaoptions.hxx"
32
33 #include <hash_set>
34 #include <list>
35
36 using namespace rtl;
37
38 //*************************************************************************
39 // CorbaType
40 //*************************************************************************
CorbaType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies,TypeSet * generatedConversions)41 CorbaType::CorbaType(TypeReader& typeReader,
42 const OString& typeName,
43 const TypeManager& typeMgr,
44 const TypeDependency& typeDependencies,
45 TypeSet* generatedConversions)
46 : m_inheritedMemberCount(0)
47 , m_indentLength(0)
48 , m_typeName(typeName)
49 , m_reader(typeReader)
50 , m_typeMgr((TypeManager&)typeMgr)
51 , m_dependencies(typeDependencies)
52 , m_generatedConversions(generatedConversions)
53 {
54 sal_Int32 i = typeName.lastIndexOf('/');
55 m_name = typeName.copy( i != -1 ? i+1 : 0 );
56 }
57
~CorbaType()58 CorbaType::~CorbaType()
59 {
60
61 }
62
isNestedTypeByName(const::rtl::OString & type)63 sal_Bool CorbaType::isNestedTypeByName(const ::rtl::OString& type)
64 {
65 sal_Bool ret = sal_False;
66
67 sal_Int32 i = type.lastIndexOf('/');
68
69 if (i >= 0)
70 {
71 OString outerTypeName(type.copy(0, i));
72 ret = (m_typeMgr.getTypeClass(outerTypeName) == RT_TYPE_INTERFACE);
73 }
74
75 return ret;
76 }
77
dump(CorbaOptions * pOptions,FileStream & o,TypeSet * allreadyDumped)78 sal_Bool CorbaType::dump(CorbaOptions* pOptions, FileStream& o, TypeSet* allreadyDumped)
79 throw( CannotDumpException )
80 {
81 sal_Bool ret = sal_False;
82
83 ret = dumpConversionFunctions(o, allreadyDumped);
84
85 return ret;
86 }
87
dumpDependedTypes(CorbaOptions * pOptions,FileStream & o,TypeSet * allreadyDumped)88 sal_Bool CorbaType::dumpDependedTypes(CorbaOptions* pOptions, FileStream& o, TypeSet* allreadyDumped)
89 throw( CannotDumpException )
90 {
91 sal_Bool ret = sal_True;
92
93 TypeUsingSet usingSet(m_dependencies.getDependencies(m_typeName));
94
95 TypeUsingSet::const_iterator iter = usingSet.begin();
96 OString typeName;
97 sal_uInt32 index = 0;
98 while (iter != usingSet.end())
99 {
100 typeName = (*iter).m_type;
101 if ((index = typeName.lastIndexOf(']')) > 0)
102 typeName = typeName.copy(index + 1);
103
104 if ( getUnoBaseType(typeName).isEmpty() )
105 {
106 if (!produceType(typeName,
107 m_typeMgr,
108 m_dependencies,
109 pOptions,
110 o, allreadyDumped, m_generatedConversions))
111 {
112 fprintf(stderr, "%s ERROR: %s\n",
113 pOptions->getProgramName().getStr(),
114 OString("cannot dump Type '" + typeName + "'").getStr());
115 exit(99);
116 }
117 }
118 ++iter;
119 }
120
121 return ret;
122 }
123
dumpConversionFunctions(FileStream & o,TypeSet * allreadyDumped)124 sal_Bool CorbaType::dumpConversionFunctions(FileStream& o, TypeSet* allreadyDumped)
125 throw( CannotDumpException )
126 {
127 if (m_typeName.lastIndexOf(']') < 0)
128 {
129 dumpInclude(o, allreadyDumped, m_typeName, "hpp", sal_False);
130 dumpDepIncludes(o, allreadyDumped, m_typeName, "hpp");
131
132 dumpFunctions(o);
133 }
134
135 return sal_True;
136 }
137
138
dumpDefaultHxxIncludes(FileStream & o)139 void CorbaType::dumpDefaultHxxIncludes(FileStream& o)
140 {
141 o << "#ifndef _OSL_MUTEX_HXX_\n"
142 << "#include <osl/mutex.hxx>\n"
143 << "#endif\n\n";
144
145 o << "#ifndef _RTL_USTRING_HXX_\n"
146 << "#include <rtl/ustring.hxx>\n"
147 << "#endif\n\n";
148
149 o << "#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_\n"
150 << "#include <com/sun/star/uno/Type.hxx>\n"
151 << "#endif\n";
152
153 o << "#ifndef _COM_SUN_STAR_UNO_ANY_HXX_\n"
154 << "#include <com/sun/star/uno/Any.hxx>\n"
155 << "#endif\n";
156
157 o << "#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_\n"
158 << "#include <com/sun/star/uno/Reference.hxx>\n"
159 << "#endif\n";
160
161 o << "#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_\n"
162 << "#include <com/sun/star/uno/XInterface.hpp>\n"
163 << "#endif\n";
164
165 o << "#ifndef _BONOBO_NULLINTERFACE_HPP_\n"
166 << "#include <Bonobo/NullInterface.hpp>\n"
167 << "#endif\n";
168
169 o << "#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_\n"
170 << "#include <com/sun/star/uno/Exception.hpp>\n"
171 << "#endif\n";
172
173 o << "#ifndef _COM_SUN_STAR_UNO_RUNTIMEEXCEPTION_HPP_\n"
174 << "#include <com/sun/star/uno/RuntimeException.hpp>\n"
175 << "#endif\n";
176
177 o << "#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_\n"
178 << "#include <com/sun/star/uno/Sequence.hxx>\n"
179 << "#endif\n";
180 }
181
182
dumpInclude(FileStream & o,TypeSet * allreadyDumped,const OString & typeName,sal_Char * prefix,sal_Bool bExtended,sal_Bool bCaseSensitive)183 void CorbaType::dumpInclude(FileStream& o, TypeSet* allreadyDumped, const OString& typeName, sal_Char* prefix, sal_Bool bExtended, sal_Bool bCaseSensitive)
184 {
185 OString realTypeName = checkRealBaseType( typeName );
186
187 if (!isNestedTypeByName(typeName) &&
188 (BT_INVALID == isBaseType(realTypeName)) &&
189 !realTypeName.equals("Bonobo/NullInterface") &&
190 !realTypeName.equals("com/sun/star/uno/XInterface") &&
191 !realTypeName.equals("com/sun/star/uno/TypeClass") &&
192 !realTypeName.equals("com/sun/star/uno/Type") &&
193 !realTypeName.equals("com/sun/star/uno/Exception") &&
194 !realTypeName.equals("com/sun/star/uno/RuntimeException"))
195 {
196 TypeSet::const_iterator iter = allreadyDumped->find(realTypeName);
197
198 if (iter == allreadyDumped->end())
199 {
200 allreadyDumped->insert(realTypeName);
201
202 sal_uInt32 length = 3+ m_typeName.getLength() + strlen(prefix);
203
204 if (bExtended)
205 length += m_name.getLength() + 1;
206
207 OStringBuffer tmpBuf(length);
208
209 tmpBuf.append('_');
210 tmpBuf.append(typeName);
211 tmpBuf.append('_');
212 if (bExtended)
213 {
214 tmpBuf.append(m_name);
215 tmpBuf.append('_');
216 }
217 tmpBuf.append(prefix);
218 tmpBuf.append('_');
219
220 OString tmp(tmpBuf.makeStringAndClear().replace('/', '_').toAsciiUpperCase());
221
222 length = 1 + typeName.getLength() + strlen(prefix);
223 if (bExtended)
224 length += m_name.getLength() + 1;
225
226 tmpBuf.ensureCapacity(length);
227 tmpBuf.append(typeName);
228 if (bExtended)
229 {
230 tmpBuf.append('/');
231 tmpBuf.append(m_name);
232 }
233 tmpBuf.append('.');
234 tmpBuf.append(prefix);
235
236 o << "#ifndef " << tmp << "\n#include <";
237 if (bCaseSensitive)
238 {
239 o << tmpBuf.makeStringAndClear();
240 } else
241 {
242 o << tmpBuf.makeStringAndClear();
243 }
244
245 o << ">\n";
246 o << "#endif\n";
247
248 o << "namespace bonobobridge {\n\n";
249
250 std::list<OString> nestedTypes;
251
252 do
253 {
254 if ((realTypeName.lastIndexOf(']') < 0) &&
255 (BT_INVALID == isBaseType(realTypeName)) &&
256 !realTypeName.equals("Bonobo/NullInterface") &&
257 !realTypeName.equals("com/sun/star/uno/XInterface") &&
258 !realTypeName.equals("com/sun/star/uno/TypeClass") &&
259 !realTypeName.equals("com/sun/star/uno/Type") &&
260 !realTypeName.equals("com/sun/star/uno/Exception") &&
261 !realTypeName.equals("com/sun/star/uno/RuntimeException") &&
262 !realTypeName.equals("com/sun/star/uno/TypeClass"))
263 {
264 o << "inline sal_Bool cpp_convert_b2u(";
265 dumpUnoType(o, realTypeName, sal_False, sal_True);
266 o << " u, ";
267 dumpCorbaType(o, realTypeName, sal_True, sal_True);
268 o << " b, const ::vos::ORef< ::bonobobridge::Bridge >& bridge);\n";
269 o << "inline sal_Bool cpp_convert_u2b(";
270 dumpCorbaType(o, realTypeName, sal_False, sal_True);
271 o << " b, ";
272 dumpUnoType(o, realTypeName, sal_True, sal_True);
273 o << " u, const ::vos::ORef< ::bonobobridge::Bridge >& bridge);\n";
274 }
275
276 RegistryKey key = m_typeMgr.getTypeKey(realTypeName);
277 RegistryKeyNames nestedTypeNames;
278 key.getKeyNames(OUString(), nestedTypeNames);
279 for (sal_uInt32 i = 0; i < nestedTypeNames.getLength(); i++)
280 {
281 OString nTypeName(OUStringToOString(nestedTypeNames.getElement(i), RTL_TEXTENCODING_UTF8));
282
283 nTypeName = checkRealBaseType(nTypeName.copy(5));
284
285 if (BT_INVALID == isBaseType(nTypeName))
286 {
287 allreadyDumped->insert(nTypeName);
288 nestedTypes.push_back(nTypeName);
289 }
290 }
291
292 if (nestedTypes.size() > 0)
293 {
294 realTypeName = nestedTypes.front();
295 nestedTypes.pop_front();
296 }
297 else
298 {
299 realTypeName = "";
300 }
301 }
302 while ( !realTypeName.isEmpty() );
303
304 o << "}; // namespace bonobobridge\n";
305 }
306 }
307 }
308
dumpDepIncludes(FileStream & o,TypeSet * allreadyDumped,const OString & typeName,sal_Char * prefix)309 void CorbaType::dumpDepIncludes(FileStream& o, TypeSet* allreadyDumped, const OString& typeName, sal_Char* prefix)
310 {
311 TypeUsingSet usingSet(m_dependencies.getDependencies(typeName));
312
313 TypeUsingSet::const_iterator iter = usingSet.begin();
314
315 OString sPrefix(OString(prefix).toAsciiUpperCase());
316 sal_Bool bSequenceDumped = sal_False;
317 sal_Bool bInterfaceDumped = sal_False;
318 sal_uInt32 index = 0;
319 sal_uInt32 seqNum = 0;
320 OString relType;
321 while (iter != usingSet.end())
322 {
323 index = (*iter).m_type.lastIndexOf(']');
324 seqNum = (index > 0 ? ((index+1) / 2) : 0);
325
326 relType = (*iter).m_type;
327 if (index > 0)
328 relType = relType.copy(index+1);
329
330 if (!isNestedTypeByName(relType))
331 {
332 OString defPrefix("HXX");
333 if (sPrefix.equals("HDL"))
334 defPrefix = "H";
335
336 if (seqNum > 0 && !bSequenceDumped)
337 {
338 bSequenceDumped = sal_True;
339 }
340
341 if ( getUnoBaseType(relType).isEmpty() &&
342 m_typeName != relType)
343 {
344 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE
345 && sPrefix.equals("HDL"))
346 {
347 if (!bInterfaceDumped)
348 {
349 bInterfaceDumped = sal_True;
350 }
351
352 if (!((*iter).m_use & TYPEUSE_SUPER))
353 {
354 o << "\n";
355 dumpNameSpace(o, sal_True, sal_False, relType);
356 o << "\nclass " << scopedName(m_typeName, relType, sal_True) << ";\n";
357 dumpNameSpace(o, sal_False, sal_False, relType);
358 o << "\n\n";
359 } else
360 {
361 dumpInclude(o, allreadyDumped, relType, prefix);
362 }
363 } else
364 {
365 dumpInclude(o, allreadyDumped, relType, prefix);
366 }
367 }
368 }
369 ++iter;
370 }
371 }
372
dumpNameSpace(FileStream & o,sal_Bool bOpen,sal_Bool bFull,const OString & type)373 void CorbaType::dumpNameSpace(FileStream& o, sal_Bool bOpen, sal_Bool bFull, const OString& type)
374 {
375 OString typeName(type);
376 sal_Bool bOneLine = sal_True;
377 if ( typeName.isEmpty() )
378 {
379 typeName = m_typeName;
380 bOneLine = sal_False;
381 }
382
383 if (typeName == "/")
384 return;
385
386 if (typeName.indexOf( '/' ) == -1 && !bFull)
387 return;
388
389 if (!bFull)
390 typeName = typeName.copy( 0, typeName.lastIndexOf( '/' ) );
391
392 if (bOpen)
393 {
394 sal_Int32 nIndex = 0;
395 do
396 {
397 o << "namespace " << typeName.getToken(0, '/', nIndex);
398 if (bOneLine)
399 o << " { ";
400 else
401 o << "\n{\n";
402 } while( nIndex != -1 );
403 } else
404 {
405 sal_Int32 nPos = 0;
406 do
407 {
408 nPos = typeName.lastIndexOf( '/' );
409 o << "}";
410 if( bOneLine )
411 o << " ";
412 else
413 o << " // " << typeName.copy( nPos+1 ) << "\n";
414 if( nPos != -1 )
415 typeName = typeName.copy( 0, nPos );
416 } while( nPos != -1 );
417 }
418 }
419
420
getMemberCount()421 sal_uInt32 CorbaType::getMemberCount()
422 {
423 sal_uInt32 count = m_reader.getMethodCount();
424
425 sal_uInt32 fieldCount = m_reader.getFieldCount();
426 RTFieldAccess access = RT_ACCESS_INVALID;
427 for (sal_uInt16 i=0; i < fieldCount; i++)
428 {
429 access = m_reader.getFieldAccess(i);
430
431 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
432 count++;
433 }
434 return count;
435 }
436
checkInheritedMemberCount(const TypeReader * pReader)437 sal_uInt32 CorbaType::checkInheritedMemberCount(const TypeReader* pReader)
438 {
439 sal_Bool bSelfCheck = sal_True;
440 if (!pReader)
441 {
442 bSelfCheck = sal_False;
443 pReader = &m_reader;
444 }
445
446 sal_uInt32 count = 0;
447 OString superType(pReader->getSuperTypeName());
448 if ( !superType.isEmpty() )
449 {
450 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
451 if ( aSuperReader.isValid() )
452 {
453 count = checkInheritedMemberCount(&aSuperReader);
454 }
455 }
456
457 if (bSelfCheck)
458 {
459 count += pReader->getMethodCount();
460 sal_uInt32 fieldCount = pReader->getFieldCount();
461 RTFieldAccess access = RT_ACCESS_INVALID;
462 for (sal_uInt16 i=0; i < fieldCount; i++)
463 {
464 access = pReader->getFieldAccess(i);
465
466 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
467 count++;
468 }
469 }
470
471 return count;
472 }
473
getInheritedMemberCount()474 sal_uInt32 CorbaType::getInheritedMemberCount()
475 {
476 if (m_inheritedMemberCount == 0)
477 {
478 m_inheritedMemberCount = checkInheritedMemberCount(0);
479 }
480
481 return m_inheritedMemberCount;
482 }
483
getTypeClass(const OString & type,sal_Bool bCStyle)484 OString CorbaType::getTypeClass(const OString& type, sal_Bool bCStyle)
485 {
486 OString typeName = ( !type.isEmpty() ? type : m_typeName);
487 RTTypeClass rtTypeClass = RT_TYPE_INVALID;
488
489 if ( !type.isEmpty() )
490 {
491 typeName = type;
492 rtTypeClass = m_typeMgr.getTypeClass(typeName);
493 } else
494 {
495 typeName = m_typeName;
496 rtTypeClass = m_reader.getTypeClass();
497 }
498
499 if (typeName.lastIndexOf(']') > 0)
500 return bCStyle ? "typelib_TypeClass_SEQUENCE" : "::com::sun::star::uno::TypeClass_SEQUENCE";
501
502 switch (rtTypeClass)
503 {
504 case RT_TYPE_INTERFACE:
505 return bCStyle ? "typelib_TypeClass_INTERFACE" : "::com::sun::star::uno::TypeClass_INTERFACE";
506 break;
507 case RT_TYPE_MODULE:
508 return bCStyle ? "typelib_TypeClass_MODULE" : "::com::sun::star::uno::TypeClass_MODULE";
509 break;
510 case RT_TYPE_STRUCT:
511 return bCStyle ? "typelib_TypeClass_STRUCT" : "::com::sun::star::uno::TypeClass_STRUCT";
512 break;
513 case RT_TYPE_ENUM:
514 return bCStyle ? "typelib_TypeClass_ENUM" : "::com::sun::star::uno::TypeClass_ENUM";
515 break;
516 case RT_TYPE_EXCEPTION:
517 return bCStyle ? "typelib_TypeClass_EXCEPTION" : "::com::sun::star::uno::TypeClass_EXCEPTION";
518 break;
519 case RT_TYPE_TYPEDEF:
520 {
521 OString realType = checkRealBaseType( typeName );
522 return getTypeClass( realType, bCStyle );
523 }
524 // return bCStyle ? "typelib_TypeClass_TYPEDEF" : "::com::sun::star::uno::TypeClass_TYPEDEF";
525 break;
526 case RT_TYPE_SERVICE:
527 return bCStyle ? "typelib_TypeClass_SERVICE" : "::com::sun::star::uno::TypeClass_SERVICE";
528 break;
529 case RT_TYPE_INVALID:
530 {
531 if (type.equals("long"))
532 return bCStyle ? "typelib_TypeClass_LONG" : "::com::sun::star::uno::TypeClass_LONG";
533 if (type.equals("short"))
534 return bCStyle ? "typelib_TypeClass_SHORT" : "::com::sun::star::uno::TypeClass_SHORT";
535 if (type.equals("hyper"))
536 return bCStyle ? "typelib_TypeClass_HYPER" : "::com::sun::star::uno::TypeClass_HYPER";
537 if (type.equals("string"))
538 return bCStyle ? "typelib_TypeClass_STRING" : "::com::sun::star::uno::TypeClass_STRING";
539 if (type.equals("boolean"))
540 return bCStyle ? "typelib_TypeClass_BOOLEAN" : "::com::sun::star::uno::TypeClass_BOOLEAN";
541 if (type.equals("char"))
542 return bCStyle ? "typelib_TypeClass_CHAR" : "::com::sun::star::uno::TypeClass_CHAR";
543 if (type.equals("byte"))
544 return bCStyle ? "typelib_TypeClass_BYTE" : "::com::sun::star::uno::TypeClass_BYTE";
545 if (type.equals("any"))
546 return bCStyle ? "typelib_TypeClass_ANY" : "::com::sun::star::uno::TypeClass_ANY";
547 if (type.equals("type"))
548 return bCStyle ? "typelib_TypeClass_TYPE" : "::com::sun::star::uno::TypeClass_TYPE";
549 if (type.equals("float"))
550 return bCStyle ? "typelib_TypeClass_FLOAT" : "::com::sun::star::uno::TypeClass_FLOAT";
551 if (type.equals("double"))
552 return bCStyle ? "typelib_TypeClass_DOUBLE" : "::com::sun::star::uno::TypeClass_DOUBLE";
553 if (type.equals("void"))
554 return bCStyle ? "typelib_TypeClass_VOID" : "::com::sun::star::uno::TypeClass_VOID";
555 if (type.equals("unsigned long"))
556 return bCStyle ? "typelib_TypeClass_UNSIGNED_LONG" : "::com::sun::star::uno::TypeClass_UNSIGNED_LONG";
557 if (type.equals("unsigned short"))
558 return bCStyle ? "typelib_TypeClass_UNSIGNED_SHORT" : "::com::sun::star::uno::TypeClass_UNSIGNED_SHORT";
559 if (type.equals("unsigned hyper"))
560 return bCStyle ? "typelib_TypeClass_UNSIGNED_HYPER" : "::com::sun::star::uno::TypeClass_UNSIGNED_HYPER";
561 }
562 break;
563 }
564
565 return bCStyle ? "typelib_TypeClass_UNKNOWN" : "::com::sun::star::uno::TypeClass_UNKNOWN";
566 }
567
printUnoType(const OString & type,sal_Bool bConst,sal_Bool bRef,sal_Bool bNative)568 OString CorbaType::printUnoType(const OString& type, sal_Bool bConst, sal_Bool bRef, sal_Bool bNative)
569 throw( CannotDumpException )
570 {
571 OStringBuffer ret(1024);
572 OString sType(checkRealBaseType(type, sal_True));
573 sal_uInt32 index = sType.lastIndexOf(']');
574 sal_uInt32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
575
576 OString relType = (index > 0 ? (sType).copy(index+1) : type);
577
578 RTTypeClass typeClass = m_typeMgr.getTypeClass(relType);
579
580 if (bConst) ret.append("const ");
581
582 sal_uInt32 i;
583 for (i=0; i < seqNum; i++)
584 {
585 ret.append("::com::sun::star::uno::Sequence< ");
586 }
587
588 switch (typeClass)
589 {
590 case RT_TYPE_INTERFACE:
591 if (bNative)
592 ret.append(scopedName(m_typeName, relType));
593 else
594 ret.append("::com::sun::star::uno::Reference< ").append(scopedName(m_typeName, relType)).append(" >");
595 break;
596 case RT_TYPE_INVALID:
597 {
598 OString tmp(getUnoBaseType(relType));
599 if ( !tmp.isEmpty() )
600 {
601 ret.append(getUnoBaseType(relType));
602 } else
603 throw CannotDumpException("Unknown type '" + relType + "', incomplete type library. ("+type+")");
604 }
605 break;
606 case RT_TYPE_STRUCT:
607 case RT_TYPE_ENUM:
608 case RT_TYPE_TYPEDEF:
609 case RT_TYPE_EXCEPTION:
610 ret.append(scopedName(m_typeName, relType));
611 break;
612 }
613
614 for (i=0; i < seqNum; i++)
615 {
616 ret.append(" >");
617 }
618
619 if (bRef) ret.append("&");
620 return ret.makeStringAndClear();
621 }
622
dumpUnoType(FileStream & o,const OString & type,sal_Bool bConst,sal_Bool bRef,sal_Bool bNative)623 void CorbaType::dumpUnoType(FileStream& o, const OString& type,
624 sal_Bool bConst, sal_Bool bRef, sal_Bool bNative)
625 throw( CannotDumpException )
626 {
627 OString ret = printUnoType(type, bConst, bRef, bNative);
628 o << ret;
629 }
630
printCorbaType(const OString & type,sal_Bool bConst,sal_Bool bRef)631 OString CorbaType::printCorbaType(const OString& type, sal_Bool bConst, sal_Bool bRef)
632 throw( CannotDumpException )
633 {
634 OStringBuffer ret(1024);
635
636 OString sType(type);
637
638 sal_uInt32 index = sType.lastIndexOf(']');
639 sal_uInt32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
640
641 OString relType = (index > 0 ? (sType).copy(index+1) : type);
642
643 RTTypeClass typeClass = m_typeMgr.getTypeClass(relType);
644
645 if (relType.equals("com/sun/star/uno/XInterface"))
646 relType = "Bonobo/Unknown";
647
648 if (relType.equals("com/sun/star/uno/TypeClass"))
649 relType = "CORBA_TypeCode";
650
651 if (relType.equals("com/sun/star/uno/RuntimeException"))
652 relType = "CORBA_SystemException";
653
654 if (relType.equals("com/sun/star/uno/Exception"))
655 relType = "CORBA_any";
656
657 if (bConst) ret.append("const ");
658
659
660 sal_uInt32 i;
661 for (i=0; i < seqNum; i++)
662 {
663 ret.append("CORBA_sequence_");
664 }
665
666 switch (typeClass)
667 {
668 case RT_TYPE_INTERFACE:
669 ret.append(relType.replace('/', '_'));
670 break;
671 case RT_TYPE_INVALID:
672 {
673 OString tmp(getUnoBaseType(relType));
674 if ( !tmp.isEmpty() )
675 ret.append(getCorbaBaseType(relType));
676 else
677 throw CannotDumpException("Unknown type '" + relType + "', incomplete type library. ("+type+")");
678 }
679 break;
680 case RT_TYPE_STRUCT:
681 case RT_TYPE_ENUM:
682 case RT_TYPE_TYPEDEF:
683 case RT_TYPE_EXCEPTION:
684 ret.append(relType.replace('/', '_'));
685 break;
686 }
687
688 if (bRef) ret.append("&");
689
690 return ret.makeStringAndClear();
691 }
692
isPassedAsPointer(const OString & type)693 sal_Bool CorbaType::isPassedAsPointer(const OString& type)
694 {
695 sal_Bool ret = sal_False;
696
697 OString sType(checkSpecialCorbaType(type));
698
699 sal_Int32 index = sType.lastIndexOf(']');
700 sal_Int32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
701
702 OString relType = (index > 0 ? (sType).copy(index+1) : type);
703
704 if (index > 0)
705 {
706 OString fakeTest;
707
708 sal_Int32 j = type.lastIndexOf('/');
709 if (j >= 0)
710 fakeTest = type.copy(0, j+1)+"_faked_array_"+type.copy(j+1);
711 else
712 fakeTest = "_faked_array_"+sType;
713
714 TypeReader fakeTestReader = m_typeMgr.getTypeReader(fakeTest);
715
716 if (fakeTestReader.isValid())
717 ret = sal_False;
718 else
719 ret = sal_True;
720 }
721 else
722 {
723 RTTypeClass typeClass = m_typeMgr.getTypeClass(sType);
724
725 switch (typeClass)
726 {
727 case RT_TYPE_STRUCT:
728 case RT_TYPE_EXCEPTION:
729 ret = sal_True;
730 break;
731
732 case RT_TYPE_INTERFACE:
733 case RT_TYPE_ENUM:
734 case RT_TYPE_INVALID:
735 if (sType.equals("any"))
736 ret = sal_True;
737 else
738 ret = sal_False;
739 break;
740 }
741 }
742
743 return ret;
744 }
745
isDerivedFromUnknown(const::rtl::OString & typeName)746 sal_Bool CorbaType::isDerivedFromUnknown(const ::rtl::OString& typeName)
747 {
748 sal_Bool ret = sal_True;
749 if ( typeName.isEmpty() )
750 ret = sal_False;
751 else if (typeName.equals("Bonobo/NullInterface"))
752 ret = sal_False;
753 else if (typeName.equals("com/sun/star/uno/XInterface"))
754 ret = sal_True;
755 else
756 {
757 TypeReader reader(m_typeMgr.getTypeReader(typeName));
758 if (reader.isValid())
759 ret = isDerivedFromUnknown(reader.getSuperTypeName());
760 else
761 ret = sal_False;
762 }
763 return ret;
764 }
765
766
isArray(const OString & type)767 sal_Bool CorbaType::isArray(const OString& type)
768 {
769 sal_Bool ret = sal_False;
770
771 OString sType(checkSpecialCorbaType(type));
772
773 sal_Int32 index = sType.lastIndexOf(']');
774 sal_Int32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
775
776 OString relType = (index > 0 ? (sType).copy(index+1) : type);
777
778 if (index > 0)
779 {
780 OString fakeTest;
781
782 sal_Int32 j = type.lastIndexOf('/');
783 if (j >= 0)
784 fakeTest = type.copy(0, j+1)+"_faked_array_"+type.copy(j+1);
785 else
786 fakeTest = "_faked_array_"+sType;
787
788 TypeReader fakeTestReader = m_typeMgr.getTypeReader(fakeTest);
789
790 if (fakeTestReader.isValid())
791 ret = sal_True;
792 }
793
794 return ret;
795 }
796
printCorbaParameter(const OString & type,sal_Bool bOut)797 OString CorbaType::printCorbaParameter(const OString& type, sal_Bool bOut)
798 throw( CannotDumpException )
799 {
800 OStringBuffer ret(1024);
801
802 OString sType(type);
803 sal_Int32 index = sType.lastIndexOf(']');
804 sal_Int32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
805
806 OString relType = (index > 0 ? (sType).copy(index+1) : type);
807
808 RTTypeClass typeClass = m_typeMgr.getTypeClass(relType);
809
810 if (relType.equals("Bonobo/NullInterface"))
811 relType = "CORBA_Object";
812
813 if (relType.equals("com/sun/star/uno/XInterface"))
814 relType = "Bonobo/Unknown";
815
816 if (relType.equals("com/sun/star/uno/TypeClass"))
817 relType = "CORBA_TypeCode";
818
819 if (relType.equals("com/sun/star/uno/RuntimeException"))
820 relType = "CORBA_SystemException";
821
822 if (relType.equals("com/sun/star/uno/Exception"))
823 relType = "CORBA_any";
824
825 int i;
826 for (i=0; i < seqNum; i++)
827 {
828 ret.append("CORBA_sequence_");
829 }
830
831 switch (typeClass)
832 {
833 case RT_TYPE_INTERFACE:
834 ret.append(relType.replace('/', '_'));
835 break;
836 case RT_TYPE_INVALID:
837 {
838 OString tmp(getUnoBaseType(relType));
839 if ( !tmp.isEmpty() )
840 {
841 ret.append(getCorbaBaseType(relType));
842 } else
843 throw CannotDumpException("Unknown type '" + relType + "', incomplete type library. ("+type+")");
844 }
845 break;
846 case RT_TYPE_STRUCT:
847 case RT_TYPE_EXCEPTION:
848 case RT_TYPE_ENUM:
849 case RT_TYPE_TYPEDEF:
850 ret.append(relType.replace('/', '_'));
851 break;
852 }
853
854 return ret.makeStringAndClear();
855 }
856
dumpCorbaType(FileStream & o,const OString & type,sal_Bool bConst,sal_Bool bRef)857 void CorbaType::dumpCorbaType(FileStream& o, const OString& type,
858 sal_Bool bConst, sal_Bool bRef)
859 throw( CannotDumpException )
860 {
861 OString ret = printCorbaType(type, bConst, bRef);
862 o << ret;
863 }
864
getUnoBaseType(const OString & type)865 OString CorbaType::getUnoBaseType(const OString& type)
866 {
867 if (type.equals("long"))
868 return "sal_Int32";
869 if (type.equals("short"))
870 return "sal_Int16";
871 if (type.equals("hyper"))
872 return "sal_Int64";
873 if (type.equals("string"))
874 return "::rtl::OUString";
875 if (type.equals("boolean"))
876 return "sal_Bool";
877 if (type.equals("char"))
878 return "sal_Unicode";
879 if (type.equals("byte"))
880 return "sal_Int8";
881 if (type.equals("any"))
882 return "::com::sun::star::uno::Any";
883 if (type.equals("type"))
884 return "::com::sun::star::uno::Type";
885 if (type.equals("float"))
886 return "float";
887 if (type.equals("double"))
888 return "double";
889 if (type.equals("octet"))
890 return "sal_Int8";
891 if (type.equals("void"))
892 return type;
893 if (type.equals("unsigned long"))
894 return "sal_uInt32";
895 if (type.equals("unsigned short"))
896 return "sal_uInt16";
897 if (type.equals("unsigned hyper"))
898 return "sal_uInt64";
899
900 return OString();
901 }
902
getCorbaBaseType(const OString & type)903 OString CorbaType::getCorbaBaseType(const OString& type)
904 {
905 if (type.equals("long"))
906 return "CORBA_long";
907 if (type.equals("short"))
908 return "CORBA_short";
909 if (type.equals("hyper"))
910 return "CORBA_long_long";
911 if (type.equals("string"))
912 return "CORBA_char*";
913 if (type.equals("boolean"))
914 return "CORBA_boolean";
915 if (type.equals("char"))
916 return "CORBA_char";
917 if (type.equals("byte"))
918 return "CORBA_octet";
919 if (type.equals("any"))
920 return "CORBA_any";
921 if (type.equals("type"))
922 return "CORBA_TypeCode";
923 if (type.equals("float"))
924 return "CORBA_float";
925 if (type.equals("double"))
926 return "CORBA_double";
927 if (type.equals("octet"))
928 return "CORBA_octet";
929 if (type.equals("void"))
930 return type;
931 if (type.equals("unsigned long"))
932 return "CORBA_unsigned_long";
933 if (type.equals("unsigned short"))
934 return "CORBA_unsigned_short";
935 if (type.equals("unsigned hyper"))
936 return "CORBA_unsigned_long_long";
937
938 return OString();
939 }
940
941
dumpTypeInit(FileStream & o,const OString & typeName)942 void CorbaType::dumpTypeInit(FileStream& o, const OString& typeName)
943 {
944 OString type(checkSpecialCorbaType(typeName));
945
946 BASETYPE baseType = isBaseType(type);
947
948 switch (baseType)
949 {
950 case BT_BOOLEAN:
951 o << "(sal_False)";
952 return;
953 break;
954 case BT_ANY:
955 case BT_STRING:
956 o << "()";
957 return;
958 break;
959 case BT_INVALID:
960 break;
961 default:
962 o << "((";
963 dumpUnoType(o, type);
964 o << ")" << "0)";
965 return;
966 }
967
968 RTTypeClass typeClass = m_typeMgr.getTypeClass(type);
969
970 if (typeClass == RT_TYPE_ENUM)
971 {
972 RegistryTypeReaderLoader aReaderLoader;
973
974 if (aReaderLoader.isLoaded())
975 {
976 TypeReader reader(m_typeMgr.getTypeReader(type));
977
978 if ( reader.isValid() )
979 {
980 sal_Int32 nPos = type.lastIndexOf( '/' );
981 o << "(" << shortScopedName("", type, sal_False)
982 << "::" << type.copy( nPos != -1 ? nPos+1 : 0 )
983 << "_" << reader.getFieldName(0) << ")";
984 return;
985 }
986 }
987 }
988
989 o << "()";
990 }
991
isBaseType(const OString & type)992 BASETYPE CorbaType::isBaseType(const OString& type)
993 {
994 if (type.equals("long"))
995 return BT_LONG;
996 if (type.equals("short"))
997 return BT_SHORT;
998 if (type.equals("hyper"))
999 return BT_HYPER;
1000 if (type.equals("string"))
1001 return BT_STRING;
1002 if (type.equals("boolean"))
1003 return BT_BOOLEAN;
1004 if (type.equals("char"))
1005 return BT_CHAR;
1006 if (type.equals("byte"))
1007 return BT_BYTE;
1008 if (type.equals("any"))
1009 return BT_ANY;
1010 if (type.equals("float"))
1011 return BT_FLOAT;
1012 if (type.equals("double"))
1013 return BT_DOUBLE;
1014 if (type.equals("void"))
1015 return BT_VOID;
1016 if (type.equals("unsigned long"))
1017 return BT_UNSIGNED_LONG;
1018 if (type.equals("unsigned short"))
1019 return BT_UNSIGNED_SHORT;
1020 if (type.equals("unsigned hyper"))
1021 return BT_UNSIGNED_HYPER;
1022
1023 return BT_INVALID;
1024 }
1025
typeToIdentifier(const OString & type)1026 OString CorbaType::typeToIdentifier(const OString& type)
1027 {
1028 sal_uInt32 index = type.lastIndexOf(']');
1029 sal_uInt32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
1030
1031 OString relType = (index > 0 ? ((OString)type).copy(index+1) : type);
1032 OString sIdentifier;
1033
1034 while( seqNum > 0 )
1035 {
1036 sIdentifier += OString("seq");
1037
1038 if ( --seqNum == 0 )
1039 {
1040 sIdentifier += OString("_");
1041 }
1042 }
1043
1044 if ( isBaseType(relType) )
1045 {
1046 sIdentifier += relType.replace(' ', '_');
1047 } else
1048 {
1049 sIdentifier += relType.replace('/', '_');
1050 }
1051
1052
1053 return sIdentifier;
1054 }
1055
checkSpecialCorbaType(const OString & type)1056 OString CorbaType::checkSpecialCorbaType(const OString& type)
1057 {
1058 OString baseType(type);
1059
1060 RegistryTypeReaderLoader & rReaderLoader = getRegistryTypeReaderLoader();
1061
1062 RegistryKey key;
1063 sal_uInt8* pBuffer=NULL;
1064 RTTypeClass typeClass;
1065 sal_Bool isTypeDef = (m_typeMgr.getTypeClass(baseType) == RT_TYPE_TYPEDEF);
1066 TypeReader reader;
1067
1068 while (isTypeDef)
1069 {
1070 reader = m_typeMgr.getTypeReader(baseType);
1071
1072 if (reader.isValid())
1073 {
1074 typeClass = reader.getTypeClass();
1075
1076 if (typeClass == RT_TYPE_TYPEDEF)
1077 baseType = reader.getSuperTypeName();
1078 else
1079 isTypeDef = sal_False;
1080 } else
1081 break;
1082 }
1083
1084 return baseType;
1085 }
1086
checkRealBaseType(const OString & type,sal_Bool bResolveTypeOnly)1087 OString CorbaType::checkRealBaseType(const OString& type, sal_Bool bResolveTypeOnly)
1088 {
1089 sal_uInt32 index = type.lastIndexOf(']');
1090 OString baseType = (index > 0 ? ((OString)type).copy(index+1) : type);
1091 OString seqPrefix = (index > 0 ? ((OString)type).copy(0, index+1) : OString());
1092
1093 RegistryTypeReaderLoader & rReaderLoader = getRegistryTypeReaderLoader();
1094
1095 RegistryKey key;
1096 sal_uInt8* pBuffer=NULL;
1097 RTTypeClass typeClass;
1098 sal_Bool mustBeChecked = (m_typeMgr.getTypeClass(baseType) == RT_TYPE_TYPEDEF);
1099 TypeReader reader;
1100
1101 while (mustBeChecked)
1102 {
1103 reader = m_typeMgr.getTypeReader(baseType);
1104
1105 if (reader.isValid())
1106 {
1107 typeClass = reader.getTypeClass();
1108
1109 if (typeClass == RT_TYPE_TYPEDEF)
1110 {
1111 baseType = reader.getSuperTypeName();
1112 index = baseType.lastIndexOf(']');
1113 if (index > 0)
1114 {
1115 seqPrefix += baseType.copy(0, index+1);
1116 baseType = baseType.copy(index+1);
1117 }
1118 } else
1119 mustBeChecked = sal_False;
1120 } else
1121 break;
1122 }
1123
1124 if ( bResolveTypeOnly )
1125 baseType = seqPrefix + baseType;
1126
1127 return baseType;
1128 }
1129
1130
inc(sal_uInt32 num)1131 void CorbaType::inc(sal_uInt32 num)
1132 {
1133 m_indentLength += num;
1134 }
1135
dec(sal_uInt32 num)1136 void CorbaType::dec(sal_uInt32 num)
1137 {
1138 if (m_indentLength - num < 0)
1139 m_indentLength = 0;
1140 else
1141 m_indentLength -= num;
1142 }
1143
indent()1144 OString CorbaType::indent()
1145 {
1146 OStringBuffer tmp(m_indentLength);
1147
1148 for (sal_uInt32 i=0; i < m_indentLength; i++)
1149 {
1150 tmp.append(' ');
1151 }
1152 return tmp.makeStringAndClear();
1153 }
1154
indent(sal_uInt32 num)1155 OString CorbaType::indent(sal_uInt32 num)
1156 {
1157 OStringBuffer tmp(m_indentLength + num);
1158
1159 for (sal_uInt32 i=0; i < m_indentLength + num; i++)
1160 {
1161 tmp.append(' ');
1162 }
1163 return tmp.makeStringAndClear();
1164 }
1165
1166 //*************************************************************************
1167 // InterfaceType
1168 //*************************************************************************
InterfaceType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies,TypeSet * generatedConversions)1169 InterfaceType::InterfaceType(TypeReader& typeReader,
1170 const OString& typeName,
1171 const TypeManager& typeMgr,
1172 const TypeDependency& typeDependencies,
1173 TypeSet* generatedConversions)
1174 : CorbaType(typeReader, typeName, typeMgr, typeDependencies, generatedConversions)
1175 {
1176 m_inheritedMemberCount = 0;
1177 m_hasAttributes = sal_False;
1178 m_hasMethods = sal_False;
1179 }
1180
~InterfaceType()1181 InterfaceType::~InterfaceType()
1182 {
1183
1184 }
1185
1186
dumpUnoMethods(FileStream & o,sal_Bool bDeclOnly,sal_Bool bDelegateToSuper)1187 void InterfaceType::dumpUnoMethods(FileStream& o, sal_Bool bDeclOnly, sal_Bool bDelegateToSuper)
1188 {
1189 OString superName(m_reader.getSuperTypeName());
1190 if (bDeclOnly &&
1191 !superName.equals("Bonobo/NullInterface") &&
1192 !superName.equals("com/sun/star/uno/XInterface"))
1193 {
1194 TypeReader reader(m_typeMgr.getTypeReader(superName));
1195 InterfaceType iType(reader, superName, m_typeMgr, TypeDependency(), m_generatedConversions);
1196 iType.inc();
1197 iType.dumpUnoMethods(o, bDeclOnly, sal_True);
1198 }
1199
1200 sal_uInt32 methodCount = m_reader.getMethodCount();
1201 sal_Bool first=sal_True;
1202
1203 OString methodName, returnType, paramType, paramName;
1204 sal_uInt32 paramCount = 0;
1205 sal_uInt32 excCount = 0;
1206 RTMethodMode methodMode = RT_MODE_INVALID;
1207 RTParamMode paramMode = RT_PARAM_INVALID;
1208
1209 sal_Bool bRef = sal_False;
1210 sal_Bool bConst = sal_False;
1211 sal_Bool bWithRunTimeExcp = sal_True;
1212
1213 for (sal_uInt16 i=0; i < methodCount; i++)
1214 {
1215 methodName = m_reader.getMethodName(i);
1216 returnType = m_reader.getMethodReturnType(i);
1217 paramCount = m_reader.getMethodParamCount(i);
1218 excCount = m_reader.getMethodExcCount(i);
1219 methodMode = m_reader.getMethodMode(i);
1220
1221 if ( methodName.equals("acquire") || methodName.equals("release") )
1222 bWithRunTimeExcp = sal_False;
1223
1224 if (first)
1225 {
1226 first = sal_False;
1227 o << "\n" << indent() << "// Methods\n";
1228 }
1229
1230 o << indent();
1231 if (bDeclOnly)
1232 o << "virtual ";
1233 dumpUnoType(o, returnType);
1234 o << " SAL_CALL ";
1235 if (!bDeclOnly)
1236 {
1237 o << "bonobobridge::BonoboWrapper_";
1238 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1239 o << "::";
1240 }
1241
1242 o << methodName << "( ";
1243
1244 sal_uInt16 j;
1245 for (j=0; j < paramCount; j++)
1246 {
1247 paramName = m_reader.getMethodParamName(i, j);
1248 paramType = m_reader.getMethodParamType(i, j);
1249 paramMode = m_reader.getMethodParamMode(i, j);
1250
1251 switch (paramMode)
1252 {
1253 case RT_PARAM_IN:
1254 {
1255 OString relType = checkSpecialCorbaType(paramType);
1256 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_ENUM ||
1257 (isBaseType(relType) && !relType.equals("string") && !relType.equals("any")))
1258 {
1259 bConst = sal_False;
1260 bRef = sal_False;
1261 } else
1262 {
1263 bConst = sal_True;
1264 bRef = sal_True;
1265 }
1266 break;
1267 }
1268 case RT_PARAM_OUT:
1269 case RT_PARAM_INOUT:
1270 bConst = sal_False;
1271 bRef = sal_True;
1272 break;
1273 }
1274
1275 dumpUnoType(o, paramType, bConst, bRef);
1276 o << " " << paramName;
1277
1278 if (j+1 < paramCount) o << ", ";
1279 }
1280 o << " )";
1281
1282 o << " throw(";
1283 OString excpName;
1284 for (j=0; j < excCount; j++)
1285 {
1286 excpName = m_reader.getMethodExcType(i, j);
1287 if (excpName != "com/sun/star/uno/RuntimeException")
1288 o << scopedName(m_typeName, excpName);
1289 if (bWithRunTimeExcp)
1290 o << ", ";
1291 }
1292
1293 if ( bWithRunTimeExcp )
1294 {
1295 o << " ::com::sun::star::uno::RuntimeException";
1296 }
1297
1298 if (bDeclOnly && bDelegateToSuper)
1299 {
1300 o << " ) {\n";
1301 if (returnType.equals("void"))
1302 o << indent() << " ";
1303 else
1304 o << indent() << " return ";
1305 o << "BonoboWrapper_";
1306 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1307 o << "::" << methodName << "( ";
1308 for (j = 0; j < paramCount; j++)
1309 {
1310 paramName = m_reader.getMethodParamName(i, j);
1311 o << paramName;
1312 if (j < (paramCount-1))
1313 o << ", ";
1314 }
1315 o << " );\n"
1316 << indent() << "}\n";
1317 }
1318 else if (!bDeclOnly)
1319 {
1320 o << " ) {\n";
1321
1322 OStringBuffer preBuffer(1024);
1323 OStringBuffer callBuffer(1024);
1324 OStringBuffer postBuffer(1024);
1325
1326 callBuffer.append(" ");
1327
1328 if (!returnType.equals("void"))
1329 {
1330 preBuffer.append(" ");
1331 preBuffer.append(printCorbaParameter(returnType));
1332 if (isPassedAsPointer(returnType))
1333 preBuffer.append("*");
1334 preBuffer.append(" _b_ret;\n");
1335 preBuffer.append(" ");
1336 preBuffer.append(printUnoType(returnType, sal_False, sal_False));
1337 preBuffer.append(" _u_ret;\n");
1338
1339 callBuffer.append("_b_ret = ");
1340 }
1341
1342 callBuffer.append(printCorbaType(m_typeName, sal_False, sal_False));
1343 callBuffer.append("_");
1344 if (methodName.indexOf("_reserved_identifier_") == 0)
1345 callBuffer.append(methodName.copy(OString("_reserved_identifier_").getLength()));
1346 else
1347 callBuffer.append(methodName);
1348
1349 callBuffer.append("( m_corbaObject");
1350
1351 for (j=0; j < paramCount; j++)
1352 {
1353 paramName = m_reader.getMethodParamName(i, j);
1354 paramType = m_reader.getMethodParamType(i, j);
1355 paramMode = m_reader.getMethodParamMode(i, j);
1356
1357 preBuffer.append(" ");
1358 preBuffer.append(printCorbaParameter(paramType));
1359 if (isPassedAsPointer(paramType) && (paramMode == RT_PARAM_OUT))
1360 {
1361 preBuffer.append("* _b_");
1362 preBuffer.append(paramName);
1363 preBuffer.append(";\n");
1364 }
1365 else
1366 {
1367 preBuffer.append(" _b_");
1368 preBuffer.append(paramName);
1369 preBuffer.append(";\n");
1370 }
1371
1372 switch (paramMode) {
1373 case RT_PARAM_IN:
1374
1375 if (isArray(paramType))
1376 preBuffer.append(" // fix me: conversion of array types!\n");
1377 else
1378 {
1379 preBuffer.append(" cpp_convert_u2b(");
1380 preBuffer.append("_b_");
1381 preBuffer.append(paramName);
1382 preBuffer.append(", ");
1383 preBuffer.append(paramName);
1384 preBuffer.append(", m_bridge);\n");
1385 }
1386
1387 if (isPassedAsPointer(paramType))
1388 callBuffer.append(", &_b_");
1389 else
1390 callBuffer.append(", _b_");
1391 break;
1392 case RT_PARAM_INOUT:
1393
1394 if (isArray(paramType))
1395 preBuffer.append(" // fix me: conversion of array types!\n");
1396 else
1397 {
1398 preBuffer.append(" cpp_convert_u2b(");
1399 if (isPassedAsPointer(paramType))
1400 preBuffer.append("_b_");
1401 else
1402 preBuffer.append("_b_");
1403 preBuffer.append(paramName);
1404 preBuffer.append(", ");
1405 preBuffer.append(paramName);
1406 preBuffer.append(", m_bridge);\n");
1407 }
1408
1409 callBuffer.append(", &_b_");
1410
1411 if (isArray(paramType))
1412 postBuffer.append(" // fix me: conversion of array types!\n");
1413 else
1414 {
1415 postBuffer.append(" cpp_convert_b2u(");
1416 postBuffer.append(paramName);
1417 postBuffer.append(", _b_");
1418 postBuffer.append(paramName);
1419 postBuffer.append(", m_bridge);\n");
1420 }
1421
1422 break;
1423 case RT_PARAM_OUT:
1424
1425 callBuffer.append(", &_b_");
1426
1427 if (isArray(paramType))
1428 postBuffer.append(" // fix me: conversion of array types!\n");
1429 else
1430 {
1431 postBuffer.append(" cpp_convert_b2u(");
1432 postBuffer.append(paramName);
1433 if (isPassedAsPointer(paramType))
1434 postBuffer.append(", *_b_");
1435 else
1436 postBuffer.append(", _b_");
1437 postBuffer.append(paramName);
1438 postBuffer.append(", m_bridge);\n");
1439 }
1440
1441 break;
1442 }
1443
1444
1445 callBuffer.append(paramName);
1446 }
1447
1448 callBuffer.append(", &_ev );\n");
1449
1450 if (!returnType.equals("void"))
1451 {
1452 if (isArray(returnType))
1453 {
1454 postBuffer.append(" // fix me: conversion of array types!\n");
1455 }
1456 else
1457 {
1458 if (isPassedAsPointer(returnType))
1459 postBuffer.append(" cpp_convert_b2u(_u_ret, *_b_ret, m_bridge);\n");
1460 else
1461 postBuffer.append(" cpp_convert_b2u(_u_ret, _b_ret, m_bridge);\n");
1462 }
1463 postBuffer.append(" return _u_ret;\n");
1464 }
1465
1466 o << " ::osl::MutexGuard guard(m_bridge->getORBLock());\n"
1467 << " CORBA_Environment _ev;\n"
1468 << " CORBA_exception_init (&_ev);\n";
1469
1470 o << preBuffer;
1471 o << callBuffer;
1472
1473 o << " if (_ev._major != CORBA_NO_EXCEPTION) {\n"
1474 << " ::com::sun::star::uno::RuntimeException _ex(::rtl::OUString::createFromAscii(\"exception raised in bonobobridge\"), NULL);\n"
1475 << " CORBA_exception_free (&_ev);\n"
1476 << " throw _ex;\n"
1477 << " }\n"
1478 << " CORBA_exception_free (&_ev);\n";
1479
1480 o << postBuffer;
1481
1482 o << indent() << "}\n";
1483 }
1484 else
1485 o << " );\n";
1486 }
1487 }
1488
dumpCorbaMethods(FileStream & o,sal_Bool bDeclOnly)1489 void InterfaceType::dumpCorbaMethods(FileStream& o, sal_Bool bDeclOnly)
1490 {
1491 OString superName(m_reader.getSuperTypeName());
1492
1493 sal_uInt32 methodCount = m_reader.getMethodCount();
1494
1495 OString methodName, returnType, paramType, paramName;
1496 sal_uInt32 paramCount = 0;
1497 sal_uInt32 excCount = 0;
1498 RTMethodMode methodMode = RT_MODE_INVALID;
1499 RTParamMode paramMode = RT_PARAM_INVALID;
1500
1501 sal_Bool bRef = sal_False;
1502 sal_Bool bConst = sal_False;
1503 sal_Bool bWithRunTimeExcp = sal_True;
1504
1505 for (sal_uInt16 i=0; i < methodCount; i++)
1506 {
1507 methodName = m_reader.getMethodName(i);
1508 returnType = m_reader.getMethodReturnType(i);
1509 paramCount = m_reader.getMethodParamCount(i);
1510 excCount = m_reader.getMethodExcCount(i);
1511 methodMode = m_reader.getMethodMode(i);
1512
1513 o << indent()
1514 << "extern \"C\" "
1515 << printCorbaParameter(returnType);
1516
1517 if (isPassedAsPointer(returnType))
1518 o << "*";
1519
1520 o << " bonobobridge_";
1521 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1522 o << "_" << methodName << "( PortableServer_Servant _servant, ";
1523
1524 sal_uInt16 j;
1525 for (j=0; j < paramCount; j++)
1526 {
1527 paramName = m_reader.getMethodParamName(i, j);
1528 paramType = m_reader.getMethodParamType(i, j);
1529 paramMode = m_reader.getMethodParamMode(i, j);
1530
1531 if ((isPassedAsPointer(paramType) || paramType.equals("string") || isArray(paramType)) &&
1532 (paramMode == RT_PARAM_IN))
1533 o << "const ";
1534
1535 o << printCorbaParameter(paramType);
1536
1537 if (isPassedAsPointer(paramType))
1538 {
1539 if (paramMode == RT_PARAM_OUT)
1540 o << "**";
1541 else
1542 o << "*";
1543 }
1544 else
1545 {
1546 if (paramMode != RT_PARAM_IN)
1547 o << "*";
1548 }
1549
1550
1551 o << " " << paramName << ", ";
1552 }
1553
1554 o << "CORBA_Environment * _ev)";
1555
1556 if (bDeclOnly)
1557 o << ";\n";
1558 else
1559 {
1560 o << " {\n";
1561 OStringBuffer preBuffer(1024);
1562 OStringBuffer callBuffer(1024);
1563 OStringBuffer postBuffer(1024);
1564
1565 callBuffer.append(" ");
1566
1567 preBuffer.append(" ");
1568 preBuffer.append(printUnoType(m_typeName, sal_False, sal_False));
1569 preBuffer.append(" rThis((");
1570 preBuffer.append(printUnoType(m_typeName, sal_False, sal_False, sal_True));
1571 preBuffer.append(" *)((bonobobridge::UNO_POA_com_sun_star_uno_XInterface*)_servant)->pThis->getUnoObject());\n");
1572
1573 if (!returnType.equals("void"))
1574 {
1575 preBuffer.append(" ");
1576 preBuffer.append(printCorbaParameter(returnType));
1577 if (isPassedAsPointer(returnType))
1578 {
1579 preBuffer.append("* _b_ret = ");
1580 preBuffer.append(printCorbaType(returnType, sal_False, sal_False));
1581 preBuffer.append("__alloc();\n");
1582
1583 }
1584 else
1585 {
1586 preBuffer.append(" _b_ret;\n");
1587 }
1588 preBuffer.append(" ");
1589 preBuffer.append(printUnoType(returnType, sal_False, sal_False));
1590 preBuffer.append(" _u_ret;\n");
1591
1592 callBuffer.append("_u_ret = ");
1593 }
1594
1595 callBuffer.append("rThis->");
1596 callBuffer.append(methodName);
1597 callBuffer.append("( ");
1598
1599 for (j=0; j < paramCount; j++)
1600 {
1601 paramName = m_reader.getMethodParamName(i, j);
1602 paramType = m_reader.getMethodParamType(i, j);
1603 paramMode = m_reader.getMethodParamMode(i, j);
1604
1605 preBuffer.append(" ");
1606 preBuffer.append(printUnoType(paramType, sal_False, sal_False));
1607 preBuffer.append(" _u_");
1608 preBuffer.append(paramName);
1609 preBuffer.append(";\n");
1610
1611 callBuffer.append("_u_");
1612 callBuffer.append(paramName);
1613
1614 if (j < (paramCount-1))
1615 callBuffer.append(", ");
1616
1617 switch (paramMode) {
1618 case RT_PARAM_IN:
1619
1620 if (isArray(paramType))
1621 preBuffer.append(" // fix me: conversion of array types!\n");
1622 else
1623 {
1624 preBuffer.append(" cpp_convert_b2u(");
1625 preBuffer.append("_u_");
1626 preBuffer.append(paramName);
1627 preBuffer.append(", ");
1628 if (isPassedAsPointer(paramType))
1629 preBuffer.append("*");
1630 preBuffer.append(paramName);
1631 preBuffer.append(", ((bonobobridge::UNO_POA_com_sun_star_uno_XInterface*)_servant)->pThis->getBridge());\n");
1632 }
1633 break;
1634 case RT_PARAM_INOUT:
1635
1636 if (isArray(paramType))
1637 {
1638 preBuffer.append(" // fix me: conversion of array types!\n");
1639 postBuffer.append(" // fix me: conversion of array types!\n");
1640 }
1641 else
1642 {
1643 preBuffer.append(" cpp_convert_b2u(");
1644 preBuffer.append("_u_");
1645 preBuffer.append(paramName);
1646 preBuffer.append(", ");
1647 if (isPassedAsPointer(paramType))
1648 preBuffer.append("*");
1649 preBuffer.append(paramName);
1650 preBuffer.append(", ((bonobobridge::UNO_POA_com_sun_star_uno_XInterface*)_servant)->pThis->getBridge());\n");
1651
1652 postBuffer.append(" cpp_convert_u2b(");
1653 if (isPassedAsPointer(paramType))
1654 postBuffer.append("*");
1655 postBuffer.append(paramName);
1656 postBuffer.append(", _u_");
1657 postBuffer.append(paramName);
1658 postBuffer.append(", ((bonobobridge::UNO_POA_com_sun_star_uno_XInterface*)_servant)->pThis->getBridge());\n");
1659 }
1660 break;
1661 case RT_PARAM_OUT:
1662
1663 if (isArray(paramType))
1664 preBuffer.append(" // fix me: conversion of array types!\n");
1665 else
1666 {
1667 postBuffer.append(" cpp_convert_u2b(");
1668 if (isPassedAsPointer(paramType))
1669 postBuffer.append("**");
1670 else
1671 postBuffer.append("*");
1672 postBuffer.append(paramName);
1673 postBuffer.append(", _u_");
1674 postBuffer.append(paramName);
1675 postBuffer.append(", ((bonobobridge::UNO_POA_com_sun_star_uno_XInterface*)_servant)->pThis->getBridge());\n");
1676 }
1677 break;
1678 }
1679 }
1680
1681 callBuffer.append(" );\n");
1682
1683 if (!returnType.equals("void"))
1684 {
1685 if (isArray(returnType))
1686 postBuffer.append(" // fix me: conversion of array types!\n");
1687 else
1688 {
1689 if (isPassedAsPointer(returnType))
1690 postBuffer.append(" cpp_convert_u2b(*_b_ret, _u_ret, ((bonobobridge::UNO_POA_com_sun_star_uno_XInterface*)_servant)->pThis->getBridge());\n");
1691 else
1692 postBuffer.append(" cpp_convert_u2b(_b_ret, _u_ret, ((bonobobridge::UNO_POA_com_sun_star_uno_XInterface*)_servant)->pThis->getBridge());\n");
1693 }
1694
1695 postBuffer.append(" return _b_ret;\n");
1696 }
1697
1698 o << preBuffer;
1699 o << callBuffer;
1700 o << postBuffer;
1701
1702 o << "}\n";
1703 }
1704 }
1705 }
1706
dumpFunctions(FileStream & o)1707 void InterfaceType::dumpFunctions(FileStream& o)
1708 {
1709 if (m_typeName.equals("com/sun/star/uno/XInterface") ||
1710 m_typeName.equals("Bonobo/NullInterface"))
1711 return;
1712
1713 m_generatedConversions->insert(m_typeName);
1714
1715 o << "namespace bonobobridge {\n\n";
1716
1717 /* bonobo implementation class */
1718 o << "class BonoboWrapper_";
1719 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1720
1721 OString superName(m_reader.getSuperTypeName());
1722 o << " : public BonoboWrapper< BonoboWrapper_";
1723 dumpCorbaType(o, superName, sal_False, sal_False);
1724 o << ", ";
1725 dumpUnoType(o, m_typeName, sal_False, sal_False, sal_True);
1726 o << " > {\n";
1727
1728 o << "public: \n"
1729 << " BonoboWrapper_";
1730 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1731 o << "(";
1732 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1733 o << " corbaObject,"
1734 << "const vos::ORef<bonobobridge::Bridge>& bridge)\n";
1735
1736 o << " : BonoboWrapper< "
1737 << "BonoboWrapper_";
1738 dumpCorbaType(o, superName, sal_False, sal_False);
1739 o << ", ";
1740 dumpUnoType(o, m_typeName, sal_False, sal_False, sal_True);
1741 o << " >(corbaObject, bridge) {\n";
1742
1743 if (isDerivedFromUnknown(m_typeName))
1744 {
1745 o << " m_bridge->registerObjectWrapper(::getCppuType((";
1746 dumpUnoType(o, m_typeName, sal_False, sal_False);
1747 o << "*)NULL), m_corbaObject, (";
1748 dumpUnoType(o, m_typeName, sal_False, sal_False, sal_True);
1749 o << "*)this);\n";
1750 }
1751
1752 o << " }\n";
1753
1754 o << " virtual ~BonoboWrapper_";
1755 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1756 o << "() {\n";
1757 if (isDerivedFromUnknown(m_typeName))
1758 {
1759 o << " m_bridge->unregisterObjectWrapper(::getCppuType((";
1760 dumpUnoType(o, m_typeName, sal_False, sal_False);
1761 o << "*)NULL), m_corbaObject, (";
1762 dumpUnoType(o, m_typeName, sal_False, sal_False, sal_True);
1763 o << "*)this);\n";
1764 }
1765 o << " }\n";
1766 inc();
1767 dumpUnoMethods(o, sal_True, sal_False);
1768 dec();
1769
1770 o << "};\n\n";
1771
1772 o << "}; // namespace bonobobridge\n";
1773
1774 dumpUnoMethods(o, sal_False, sal_False);
1775
1776 /* convert function bonobo to uno */
1777 o << "static sal_Bool convert_b2u_" << m_typeName.replace('/', '_')
1778 << "(void* pOut, const void* pIn, const ::com::sun::star::uno::Type& type, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
1779 << " sal_Bool ret = sal_True;\n ";
1780 dumpUnoType(o, m_typeName, sal_False, sal_False);
1781 o << "& _u = *(";
1782 dumpUnoType(o, m_typeName, sal_False, sal_False);
1783 o << "*) pOut;\n const ";
1784 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1785 o << "& _b = *(const ";
1786 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1787 o << "*) pIn;\n\n"
1788 << " _u = new bonobobridge::BonoboWrapper_";
1789 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1790 o << "(_b, bridge);\n"
1791 << " return ret;\n";
1792
1793 o << "}\n\n";
1794
1795 /* POA implementation class */
1796 dumpCorbaMethods(o, sal_True);
1797 o << "static POA_";
1798 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1799 o << "__epv bonobobridge_";
1800 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1801 o << "_epv = {\n";
1802 sal_uInt32 methodCount = m_reader.getMethodCount();
1803 OString methodName;
1804
1805 o << " NULL,\n";
1806
1807 for (sal_uInt16 i=0; i < methodCount; i++)
1808 {
1809 methodName = m_reader.getMethodName(i);
1810 o << " bonobobridge_";
1811 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1812 o << "_" << methodName;
1813
1814 if (i < (methodCount-1))
1815 o << ",\n";
1816 else
1817 o << "\n};\n";
1818 }
1819
1820 OStringBuffer initBuffer(1024);
1821
1822 initBuffer.insert(0, OString("&bonobobridge_") + printCorbaType(m_typeName, sal_False, sal_False) + OString("_epv"));
1823
1824 while( !superName.isEmpty() )
1825 {
1826 if (superName.equals("Bonobo/NullInterface"))
1827 {
1828 superName = "";
1829 }
1830 else
1831 {
1832 if (superName.equals("com/sun/star/uno/XInterface"))
1833 {
1834 initBuffer.insert(0, OString("&bonobobridge_com_sun_star_uno_XInterface_epv, "));
1835 }
1836 else
1837 {
1838 initBuffer.insert(0, OString("&bonobobridge_") + printCorbaType(superName, sal_False, sal_False) + OString("_epv, "));
1839 }
1840 TypeReader reader(m_typeMgr.getTypeReader(superName));
1841 superName = reader.getSuperTypeName();
1842 }
1843 }
1844
1845 initBuffer.insert(0, OString("NULL, "));
1846
1847 o << "static POA_";
1848 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1849 o << "__vepv bonobobridge_";
1850 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1851 o << "__vepv = {";
1852 o << initBuffer.makeStringAndClear();
1853 o << " };\n";
1854
1855 superName = m_reader.getSuperTypeName();
1856
1857 o << "namespace bonobobridge {\n\n";
1858
1859 o << "class UnoServant_";
1860 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1861 o << " : public UnoServant_com_sun_star_uno_XInterface {\n";
1862
1863 o << "public:\n"
1864 << " UnoServant_";
1865
1866 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1867 o << "(";
1868 dumpUnoType(o, m_typeName, sal_False, sal_False, sal_True);
1869 o << "* unoObject,"
1870 << " const ::vos::ORef<bonobobridge::Bridge>& bridge,"
1871 << " CORBA_Environment *ev,"
1872 << " sal_Bool bInitPoa)\n"
1873 << " : UnoServant_com_sun_star_uno_XInterface(unoObject, bridge, ev, sal_False) {\n"
1874 << " if (bInitPoa) {\n"
1875 << " memset(&m_POAUnknown, 0, sizeof(m_POAUnknown));\n"
1876 << " POA_";
1877 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1878 o << "__init((PortableServer_Servant) &(m_POAUnknown.poa), ev);\n"
1879 << " m_POAUnknown.pThis = (UnoServant_com_sun_star_uno_XInterface*)this;\n"
1880 << " m_POAUnknown.poa.vepv = (POA_Bonobo_Unknown__vepv*)&bonobobridge_";
1881 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1882 o << "__vepv;\n"
1883 << " }\n"
1884 << " }\n"
1885 << "};\n"
1886 << "}; // namespace bonobobridge\n";
1887
1888 dumpCorbaMethods(o, sal_False);
1889
1890 /* convert function uno to bonobo */
1891 o << "static sal_Bool convert_u2b_" << m_typeName.replace('/', '_')
1892 << "(void* pOut, const void* pIn, const ::com::sun::star::uno::Type& type, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n";
1893 o << " sal_Bool ret = sal_True;\n const ";
1894 dumpUnoType(o, m_typeName, sal_False, sal_False);
1895 o << "& _u = *(const ";
1896 dumpUnoType(o, m_typeName, sal_False, sal_False);
1897 o << "*) pIn;\n ";
1898 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1899 o << "& _b = *(";
1900 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1901 o << "*) pOut;\n\n"
1902 << " if (_u.is()) {\n"
1903 << " bonobobridge::UnoServant_";
1904 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1905 o << " *uno_servant;\n"
1906 << " POA_";
1907 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1908 o << " *poa;\n"
1909 << " CORBA_Environment ev;\n"
1910 << " CORBA_exception_init (&ev);\n"
1911 << " uno_servant = new bonobobridge::UnoServant_";
1912 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1913 o << "(_u.get(), bridge, &ev, sal_True);\n"
1914 << " poa = (POA_";
1915 dumpCorbaType(o, m_typeName, sal_False, sal_False);
1916 o << "*)uno_servant->getPOA();\n"
1917 << " if (ev._major != CORBA_NO_EXCEPTION) {\n"
1918 << " delete uno_servant;\n"
1919 << " CORBA_exception_free (&ev);\n"
1920 << " _b = CORBA_OBJECT_NIL;\n"
1921 << " ret = sal_False;\n"
1922 << " }\n"
1923 << " else {\n"
1924 << " CORBA_free(PortableServer_POA_activate_object(bridge->getPOA(), poa, &ev));\n"
1925 << " _b = PortableServer_POA_servant_to_reference (bridge->getPOA(), poa, &ev);\n"
1926 << " uno_servant->corbaObjectRegistered(_b, getCppuType((";
1927 dumpUnoType(o, m_typeName, sal_False, sal_False);
1928 o << "*)NULL)";
1929
1930 if (!isDerivedFromUnknown(m_typeName))
1931 o << ", sal_False";
1932
1933 o << ");\n"
1934 << " }\n"
1935 << " CORBA_exception_free (&ev);\n"
1936 << " }\n"
1937 << " return ret;\n"
1938 << "}\n\n";
1939
1940 o << "inline sal_Bool bonobobridge::cpp_convert_b2u(";
1941 dumpUnoType(o, m_typeName, sal_False, sal_True);
1942 o << " u, ";
1943 dumpCorbaType(o, m_typeName, sal_True, sal_True);
1944 o << " b, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
1945 << " return bridge->convertB2U(&u, &b, ::getCppuType(&u));\n"
1946 << "};\n\n";
1947
1948 o << "inline sal_Bool bonobobridge::cpp_convert_u2b(";
1949 dumpCorbaType(o, m_typeName, sal_False, sal_True);
1950 o << " b, ";
1951 dumpUnoType(o, m_typeName, sal_True, sal_True);
1952 o << " u, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
1953 << " return bridge->convertU2B(&b, &u, ::getCppuType(&u));\n"
1954 << "};\n\n";
1955
1956 return;
1957 }
1958
1959
1960
1961
getMemberCount()1962 sal_uInt32 InterfaceType::getMemberCount()
1963 {
1964 sal_uInt32 count = m_reader.getMethodCount();
1965
1966 if (count)
1967 m_hasMethods = sal_True;
1968
1969 sal_uInt32 fieldCount = m_reader.getFieldCount();
1970 RTFieldAccess access = RT_ACCESS_INVALID;
1971 for (sal_uInt16 i=0; i < fieldCount; i++)
1972 {
1973 access = m_reader.getFieldAccess(i);
1974
1975 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
1976 {
1977 m_hasAttributes = sal_True;
1978 count++;
1979 }
1980 }
1981 return count;
1982 }
1983
checkInheritedMemberCount(const TypeReader * pReader)1984 sal_uInt32 InterfaceType::checkInheritedMemberCount(const TypeReader* pReader)
1985 {
1986 sal_uInt32 cout = 0;
1987 sal_Bool bSelfCheck = sal_True;
1988 if (!pReader)
1989 {
1990 bSelfCheck = sal_False;
1991 pReader = &m_reader;
1992 }
1993
1994 sal_uInt32 count = 0;
1995 OString superType(pReader->getSuperTypeName());
1996 if ( !superType.isEmpty() )
1997 {
1998 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
1999 if (aSuperReader.isValid())
2000 {
2001 count = checkInheritedMemberCount(&aSuperReader);
2002 }
2003 }
2004
2005 if (bSelfCheck)
2006 {
2007 count += pReader->getMethodCount();
2008 sal_uInt32 fieldCount = pReader->getFieldCount();
2009 RTFieldAccess access = RT_ACCESS_INVALID;
2010 for (sal_uInt16 i=0; i < fieldCount; i++)
2011 {
2012 access = pReader->getFieldAccess(i);
2013
2014 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
2015 count++;
2016 }
2017 }
2018
2019 return count;
2020 }
2021
getInheritedMemberCount()2022 sal_uInt32 InterfaceType::getInheritedMemberCount()
2023 {
2024 if (m_inheritedMemberCount == 0)
2025 {
2026 m_inheritedMemberCount = checkInheritedMemberCount(0);
2027 }
2028
2029 return m_inheritedMemberCount;
2030 }
2031
2032
2033
2034
2035 //*************************************************************************
2036 // ModuleType
2037 //*************************************************************************
ModuleType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies,TypeSet * generatedConversions)2038 ModuleType::ModuleType(TypeReader& typeReader,
2039 const OString& typeName,
2040 const TypeManager& typeMgr,
2041 const TypeDependency& typeDependencies,
2042 TypeSet* generatedConversions)
2043 : CorbaType(typeReader, typeName, typeMgr, typeDependencies, generatedConversions)
2044 {
2045 }
2046
~ModuleType()2047 ModuleType::~ModuleType()
2048 {
2049
2050 }
2051
2052
hasConstants()2053 sal_Bool ModuleType::hasConstants()
2054 {
2055 sal_uInt32 fieldCount = m_reader.getFieldCount();
2056 RTFieldAccess access = RT_ACCESS_INVALID;
2057
2058 for (sal_uInt16 i=0; i < fieldCount; i++)
2059 {
2060 access = m_reader.getFieldAccess(i);
2061
2062 if (access == RT_ACCESS_CONST)
2063 return sal_True;
2064 }
2065
2066 return sal_False;
2067 }
2068
dumpFunctions(FileStream & o)2069 void ModuleType::dumpFunctions(FileStream& o)
2070 {
2071 };
2072
dumpConversionFunctions(FileStream & o,TypeSet * allreadyDumped)2073 sal_Bool ModuleType::dumpConversionFunctions(FileStream& o, TypeSet* allreadyDumped)
2074 throw( CannotDumpException )
2075 {
2076 sal_Bool bSpecialDefine = sal_True;
2077
2078 if (m_reader.getTypeClass() == RT_TYPE_CONSTANTS)
2079 {
2080 bSpecialDefine = sal_False;
2081 }
2082
2083 dumpInclude(o, allreadyDumped, m_typeName, "hpp", bSpecialDefine);
2084
2085 return sal_True;
2086 }
2087
2088 //*************************************************************************
2089 // ConstantsType
2090 //*************************************************************************
ConstantsType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies,TypeSet * generatedConversions)2091 ConstantsType::ConstantsType(TypeReader& typeReader,
2092 const OString& typeName,
2093 const TypeManager& typeMgr,
2094 const TypeDependency& typeDependencies,
2095 TypeSet* generatedConversions)
2096 : ModuleType(typeReader, typeName, typeMgr, typeDependencies, generatedConversions)
2097 {
2098 }
2099
~ConstantsType()2100 ConstantsType::~ConstantsType()
2101 {
2102
2103 }
2104
dumpFunctions(FileStream & o)2105 void ConstantsType::dumpFunctions(FileStream& o)
2106 {
2107 };
2108
2109 //*************************************************************************
2110 // StructureType
2111 //*************************************************************************
StructureType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies,TypeSet * generatedConversions)2112 StructureType::StructureType(TypeReader& typeReader,
2113 const OString& typeName,
2114 const TypeManager& typeMgr,
2115 const TypeDependency& typeDependencies,
2116 TypeSet* generatedConversions)
2117 : CorbaType(typeReader, typeName, typeMgr, typeDependencies, generatedConversions)
2118 {
2119 }
2120
~StructureType()2121 StructureType::~StructureType()
2122 {
2123
2124 }
2125
dumpFunctions(FileStream & o)2126 void StructureType::dumpFunctions(FileStream& o)
2127 {
2128 m_generatedConversions->insert(m_typeName);
2129
2130 OString superType(m_reader.getSuperTypeName());
2131
2132 o << "static sal_Bool convert_b2u_" << m_typeName.replace('/', '_')
2133 << "(void* pOut, const void* pIn, const ::com::sun::star::uno::Type& type, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2134 << " sal_Bool ret = sal_True;\n ";
2135 dumpUnoType(o, m_typeName, sal_False, sal_False);
2136 o << "& _u = *(";
2137 dumpUnoType(o, m_typeName, sal_False, sal_False);
2138 o << "*) pOut;\n const ";
2139 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2140 o << "& _b = *(const ";
2141 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2142 o << "*) pIn;\n\n";
2143
2144 sal_uInt32 fieldCount = m_reader.getFieldCount();
2145 OString fieldName;
2146 OString fieldType;
2147 sal_uInt16 i=0;
2148 sal_Int32 cIndex;
2149 OString corbaFieldName;
2150
2151 sal_Bool bIsUnion = sal_False;
2152
2153 for (i=0; !bIsUnion && (i < fieldCount); i++)
2154 bIsUnion = OString("_union_fake_tag").equals(m_reader.getFieldName(i));
2155
2156 if (bIsUnion)
2157 {
2158 o << " // fix me: union !!!!\n ret = sal_False;\n";
2159 }
2160 else
2161 {
2162 if ( !superType.isEmpty() )
2163 {
2164 o << " ret = bonobobridge::cpp_convert_b2u((";
2165 dumpUnoType(o, superType, sal_False, sal_False);
2166 o << "&) _u, (const ";
2167 dumpCorbaType(o, superType, sal_False, sal_False);
2168 o << "&) _b, bridge);\n";
2169 }
2170
2171 for (i=0; i < fieldCount; i++)
2172 {
2173 fieldName = m_reader.getFieldName(i);
2174 fieldType = m_reader.getFieldType(i);
2175 cIndex = fieldName.indexOf("_reserved_identifier_");
2176
2177 if (cIndex == 0)
2178 corbaFieldName = fieldName.copy(OString("_reserved_identifier_").getLength());
2179 else
2180 corbaFieldName = fieldName;
2181
2182 if (isArray(fieldType))
2183 o << " // fix me: no conversion of array types!\n";
2184 else
2185 o << " if (ret)\n"
2186 << " ret = bonobobridge::cpp_convert_b2u("
2187 << "_u." << fieldName.getStr()
2188 << " , _b." << corbaFieldName.getStr()
2189 << ", bridge);\n";
2190 }
2191 }
2192 o << " return ret;\n"
2193 << "}\n\n"
2194 << "static sal_Bool convert_u2b_" << m_typeName.replace('/', '_')
2195 << "(void* pOut, const void* pIn, const ::com::sun::star::uno::Type& type, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2196 << " sal_Bool ret = sal_True;\n const ";
2197 dumpUnoType(o, m_typeName, sal_False, sal_False);
2198 o << "& _u = *(const ";
2199 dumpUnoType(o, m_typeName, sal_False, sal_False);
2200 o << "*) pIn;\n ";
2201 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2202 o << "& _b = *(";
2203 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2204 o << "*) pOut;\n\n";
2205
2206 if (bIsUnion)
2207 o << " // fix me: union !!!!\n ret = sal_False;\n";
2208 else
2209 {
2210 if ( !superType.isEmpty() )
2211 {
2212 o << " ret = bonobobridge::cpp_convert_u2b((";
2213 dumpCorbaType(o, superType, sal_False, sal_False);
2214 o << "&) _u, (const ";
2215 dumpUnoType(o, superType, sal_False, sal_False);
2216 o << "&) _b, bridge);\n";
2217 }
2218
2219 for (i=0; i < fieldCount; i++)
2220 {
2221 fieldName = m_reader.getFieldName(i);
2222 fieldType = m_reader.getFieldType(i);
2223
2224 cIndex = fieldName.indexOf("_reserved_identifier_");
2225
2226 if (cIndex == 0)
2227 corbaFieldName = fieldName.copy(OString("_reserved_identifier_").getLength());
2228 else
2229 corbaFieldName = fieldName;
2230
2231 if (isArray(fieldType))
2232 o << " // fix me: no conversion of array types!\n";
2233 else
2234 o << " if (ret)\n"
2235 << " ret = bonobobridge::cpp_convert_u2b("
2236 << "_b." << corbaFieldName.getStr()
2237 << ", _u." << fieldName.getStr()
2238 << ", bridge);\n";
2239 }
2240 }
2241
2242 o << " return ret;\n"
2243 << "}\n\n";
2244
2245 o << "inline sal_Bool bonobobridge::cpp_convert_b2u(";
2246 dumpUnoType(o, m_typeName, sal_False, sal_True);
2247 o << " u , ";
2248 dumpCorbaType(o, m_typeName, sal_True, sal_True);
2249 o << " b, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2250 << " return convert_b2u_" << m_typeName.replace('/', '_')
2251 << "(&u, &b, ::getCppuType(&u), bridge);\n"
2252 << "};\n\n";
2253
2254 o << "inline sal_Bool bonobobridge::cpp_convert_u2b(";
2255 dumpCorbaType(o, m_typeName, sal_False, sal_True);
2256 o << " b, ";
2257 dumpUnoType(o, m_typeName, sal_True, sal_True);
2258 o << " u, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2259 << " return convert_u2b_" << m_typeName.replace('/', '_')
2260 << "(&b, &u, ::getCppuType(&u), bridge);\n"
2261 << "};\n\n";
2262 }
2263
dumpSuperMember(FileStream & o,const OString & superType,sal_Bool bWithType)2264 sal_Bool StructureType::dumpSuperMember(FileStream& o, const OString& superType, sal_Bool bWithType)
2265 {
2266 sal_Bool hasMember = sal_False;
2267
2268 if ( !superType.isEmpty() )
2269 {
2270 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
2271
2272 if (aSuperReader.isValid())
2273 {
2274 hasMember = dumpSuperMember(o, aSuperReader.getSuperTypeName(), bWithType);
2275
2276 sal_uInt32 fieldCount = aSuperReader.getFieldCount();
2277 RTFieldAccess access = RT_ACCESS_INVALID;
2278 OString fieldName;
2279 OString fieldType;
2280 for (sal_uInt16 i=0; i < fieldCount; i++)
2281 {
2282 access = aSuperReader.getFieldAccess(i);
2283
2284 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2285 continue;
2286
2287 fieldName = aSuperReader.getFieldName(i);
2288 fieldType = aSuperReader.getFieldType(i);
2289
2290 if (hasMember)
2291 {
2292 o << ", ";
2293 } else
2294 {
2295 hasMember = (fieldCount > 0);
2296 }
2297
2298 if (bWithType)
2299 {
2300 dumpUnoType(o, fieldType, sal_True, sal_True);
2301 o << " ";
2302 }
2303 o << "__" << fieldName;
2304 }
2305 }
2306 }
2307
2308 return hasMember;
2309 }
2310
2311 //*************************************************************************
2312 // ExceptionType
2313 //*************************************************************************
ExceptionType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies,TypeSet * generatedConversions)2314 ExceptionType::ExceptionType(TypeReader& typeReader,
2315 const OString& typeName,
2316 const TypeManager& typeMgr,
2317 const TypeDependency& typeDependencies,
2318 TypeSet* generatedConversions)
2319 : CorbaType(typeReader, typeName, typeMgr, typeDependencies, generatedConversions)
2320 {
2321 }
2322
~ExceptionType()2323 ExceptionType::~ExceptionType()
2324 {
2325
2326 }
2327
dumpFunctions(FileStream & o)2328 void ExceptionType::dumpFunctions(FileStream& o)
2329 {
2330 if (m_typeName.equals("com/sun/star/uno/Exception"))
2331 return;
2332
2333 if (m_typeName.equals("com/sun/star/uno/RuntimeException"))
2334 return;
2335
2336 m_generatedConversions->insert(m_typeName);
2337
2338 OString superType(m_reader.getSuperTypeName());
2339
2340 o << "static sal_Bool convert_b2u_" << m_typeName.replace('/', '_')
2341 << "(void* pOut, const void* pIn, const ::com::sun::star::uno::Type& type, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2342 << " sal_Bool ret = sal_True;\n";
2343 dumpUnoType(o, m_typeName, sal_False, sal_False);
2344 o << "& _u = *(";
2345 dumpUnoType(o, m_typeName, sal_False, sal_False);
2346 o << "*) pOut;\n const ";
2347 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2348 o << "& _b = *(const ";
2349 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2350 o << "*) pIn;\n\n";
2351
2352 sal_uInt32 fieldCount = m_reader.getFieldCount();
2353 OString fieldName;
2354 OString fieldType;
2355 sal_uInt16 i=0;
2356 sal_Int32 cIndex;
2357 OString corbaFieldName;
2358
2359 if ( !superType.isEmpty() )
2360 {
2361 o << " ret = bonobobridge::cpp_convert_b2u((";
2362 dumpUnoType(o, superType, sal_False, sal_False);
2363 o << "&) _u, (const ";
2364 dumpCorbaType(o, superType, sal_False, sal_False);
2365 o << "&) _b, bridge);\n";
2366 }
2367
2368 for (i=0; i < fieldCount; i++)
2369 {
2370 fieldName = m_reader.getFieldName(i);
2371 fieldType = m_reader.getFieldType(i);
2372 cIndex = fieldName.indexOf("_reserved_identifier_");
2373
2374 if (cIndex == 0)
2375 corbaFieldName = fieldName.copy(OString("_reserved_identifier_").getLength());
2376 else
2377 corbaFieldName = fieldName;
2378
2379 if (isArray(fieldType))
2380 o << " // fix me: no conversion of array types!\n";
2381 else
2382 o << " if (ret)\n"
2383 << " ret = bonobobridge::cpp_convert_b2u("
2384 << "_u." << fieldName.getStr()
2385 << ", _b." << corbaFieldName.getStr()
2386 << ", bridge);\n";
2387 }
2388 o << " return ret;\n"
2389 << "}\n\n";
2390
2391
2392 o << "static sal_Bool convert_u2b_" << m_typeName.replace('/', '_')
2393 << "(void* pOut, const void* pIn, const ::com::sun::star::uno::Type& type, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2394 << " sal_Bool ret = sal_True;\n const ";
2395 dumpUnoType(o, m_typeName, sal_False, sal_False);
2396 o << "& _u = *(const ";
2397 dumpUnoType(o, m_typeName, sal_False, sal_False);
2398 o << "*) pIn;\n ";
2399 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2400 o << "& _b = *(";
2401 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2402 o << "*) pOut;\n\n";
2403
2404 if ( !superType.isEmpty() )
2405 {
2406 o << " ret = bonobobridge::cpp_convert_u2b((";
2407 dumpCorbaType(o, superType, sal_False, sal_False);
2408 o << "&) _u, (const ";
2409 dumpUnoType(o, superType, sal_False, sal_False);
2410 o << "&) _b, bridge);\n";
2411 }
2412
2413 for (i=0; i < fieldCount; i++)
2414 {
2415 fieldName = m_reader.getFieldName(i);
2416 fieldType = m_reader.getFieldType(i);
2417
2418 cIndex = fieldName.indexOf("_reserved_identifier_");
2419
2420 if (cIndex == 0)
2421 corbaFieldName = fieldName.copy(OString("_reserved_identifier_").getLength());
2422 else
2423 corbaFieldName = fieldName;
2424
2425 if (isArray(fieldType))
2426 o << " // fix me: no conversion of array types!\n";
2427 else
2428 o << " if (ret)\n"
2429 << " ret = bonobobridge::cpp_convert_u2b("
2430 << "_b." << corbaFieldName.getStr()
2431 << ", _u." << fieldName.getStr()
2432 << ", bridge);\n";
2433 }
2434
2435 o << " return ret;\n"
2436 << "}\n\n";
2437
2438 o << "inline sal_Bool bonobobridge::cpp_convert_b2u(";
2439 dumpUnoType(o, m_typeName, sal_False, sal_True);
2440 o << " u , ";
2441 dumpCorbaType(o, m_typeName, sal_True, sal_True);
2442 o << " b, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2443 << " return convert_b2u_" << m_typeName.replace('/', '_')
2444 << "(&u, &b, ::getCppuType(&u), bridge);\n"
2445 << "};\n\n";
2446
2447 o << "inline sal_Bool bonobobridge::cpp_convert_u2b(";
2448 dumpCorbaType(o, m_typeName, sal_False, sal_True);
2449 o << " b, ";
2450 dumpUnoType(o, m_typeName, sal_True, sal_True);
2451 o << " u, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2452 << " return convert_u2b_" << m_typeName.replace('/', '_')
2453 << "(&b, &u, ::getCppuType(&u), bridge);\n"
2454 << "};\n\n";
2455 }
2456
2457
2458
dumpSuperMember(FileStream & o,const OString & superType,sal_Bool bWithType)2459 sal_Bool ExceptionType::dumpSuperMember(FileStream& o, const OString& superType, sal_Bool bWithType)
2460 {
2461 sal_Bool hasMember = sal_False;
2462
2463 if ( !superType.isEmpty() )
2464 {
2465 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
2466
2467 if (aSuperReader.isValid())
2468 {
2469 hasMember = dumpSuperMember(o, aSuperReader.getSuperTypeName(), bWithType);
2470
2471 sal_uInt32 fieldCount = aSuperReader.getFieldCount();
2472 RTFieldAccess access = RT_ACCESS_INVALID;
2473 OString fieldName;
2474 OString fieldType;
2475 for (sal_uInt16 i=0; i < fieldCount; i++)
2476 {
2477 access = aSuperReader.getFieldAccess(i);
2478
2479 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2480 continue;
2481
2482 fieldName = aSuperReader.getFieldName(i);
2483 fieldType = aSuperReader.getFieldType(i);
2484
2485 if (hasMember)
2486 {
2487 o << ", ";
2488 } else
2489 {
2490 hasMember = (fieldCount > 0);
2491 }
2492
2493 if (bWithType)
2494 {
2495 dumpUnoType(o, fieldType, sal_True, sal_True);
2496 o << " ";
2497 }
2498 o << "__" << fieldName;
2499 }
2500 }
2501 }
2502
2503 return hasMember;
2504 }
2505
2506 //*************************************************************************
2507 // EnumType
2508 //*************************************************************************
EnumType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies,TypeSet * generatedConversions)2509 EnumType::EnumType(TypeReader& typeReader,
2510 const OString& typeName,
2511 const TypeManager& typeMgr,
2512 const TypeDependency& typeDependencies,
2513 TypeSet* generatedConversions)
2514 : CorbaType(typeReader, typeName, typeMgr, typeDependencies, generatedConversions)
2515 {
2516 }
2517
~EnumType()2518 EnumType::~EnumType()
2519 {
2520
2521 }
2522
dumpFunctions(FileStream & o)2523 void EnumType::dumpFunctions(FileStream& o)
2524 {
2525 if (m_typeName.equals("com/sun/star/uno/TypeClass"))
2526 return;
2527
2528 m_generatedConversions->insert(m_typeName);
2529
2530 o << "static sal_Bool convert_b2u_" << m_typeName.replace('/', '_')
2531 << "(void* pOut, const void* pIn, const ::com::sun::star::uno::Type& type, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2532 << " *(";
2533 dumpUnoType(o, m_typeName, sal_False, sal_False);
2534 o << "*) pOut = (";
2535 dumpUnoType(o, m_typeName, sal_False, sal_False);
2536 o << ") *(const ";
2537 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2538 o << "*) pIn;\n\n"
2539 << " return sal_True;\n"
2540 << "}\n\n";
2541
2542 o << "static sal_Bool convert_u2b_" << m_typeName.replace('/', '_')
2543 << "(void* pOut, const void* pIn, const ::com::sun::star::uno::Type& type, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2544 << " *(";
2545 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2546 o << "*) pOut = (";
2547 dumpCorbaType(o, m_typeName, sal_False, sal_False);
2548 o << ") *(const ";
2549 dumpUnoType(o, m_typeName, sal_False, sal_False);
2550 o << "*) pIn;\n\n"
2551 << " return sal_True;\n"
2552 << "}\n\n";
2553
2554 o << "inline sal_Bool bonobobridge::cpp_convert_b2u(";
2555 dumpUnoType(o, m_typeName, sal_False, sal_True);
2556 o << " u , ";
2557 dumpCorbaType(o, m_typeName, sal_True, sal_True);
2558 o << " b, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2559 << " return convert_b2u_" << m_typeName.replace('/', '_')
2560 << "(&u, &b, ::getCppuType(&u), bridge);\n"
2561 << "};\n\n";
2562
2563 o << "inline sal_Bool bonobobridge::cpp_convert_u2b(";
2564 dumpCorbaType(o, m_typeName, sal_False, sal_True);
2565 o << " b, ";
2566 dumpUnoType(o, m_typeName, sal_True, sal_True);
2567 o << " u, const ::vos::ORef< ::bonobobridge::Bridge >& bridge) {\n"
2568 << " return convert_u2b_" << m_typeName.replace('/', '_')
2569 << "(&b, &u, ::getCppuType(&u), bridge);\n"
2570 << "};\n\n";
2571
2572 return;
2573 }
2574
2575
2576 //*************************************************************************
2577 // TypeDefType
2578 //*************************************************************************
TypeDefType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies,TypeSet * generatedConversions)2579 TypeDefType::TypeDefType(TypeReader& typeReader,
2580 const OString& typeName,
2581 const TypeManager& typeMgr,
2582 const TypeDependency& typeDependencies,
2583 TypeSet* generatedConversions)
2584 : CorbaType(typeReader, typeName, typeMgr, typeDependencies, generatedConversions)
2585 {
2586 }
2587
~TypeDefType()2588 TypeDefType::~TypeDefType()
2589 {
2590
2591 }
2592
dumpFunctions(FileStream & o)2593 void TypeDefType::dumpFunctions(FileStream& o)
2594 {
2595 }
2596
2597
2598
2599 //*************************************************************************
2600 // produceType
2601 //*************************************************************************
produceType(const OString & typeName,TypeManager & typeMgr,TypeDependency & typeDependencies,CorbaOptions * pOptions,FileStream & o,TypeSet * allreadyDumped,TypeSet * generatedConversions)2602 sal_Bool produceType(const OString& typeName,
2603 TypeManager& typeMgr,
2604 TypeDependency& typeDependencies,
2605 CorbaOptions* pOptions,
2606 FileStream& o, TypeSet* allreadyDumped,
2607 TypeSet* generatedConversions)
2608 throw( CannotDumpException )
2609 {
2610 sal_Bool bNewTypeSet = (allreadyDumped == NULL);
2611 sal_Bool ret = sal_True;
2612
2613 if (bNewTypeSet)
2614 allreadyDumped = new TypeSet();
2615
2616
2617 if (!typeDependencies.isGenerated(typeName))
2618 {
2619 TypeReader reader(typeMgr.getTypeReader(typeName));
2620
2621 if (!reader.isValid() && !typeName.equals("/"))
2622 ret = sal_False;
2623
2624 if( ret && !checkTypeDependencies(typeMgr, typeDependencies, typeName))
2625 ret = sal_False;
2626
2627 if (ret)
2628 {
2629 RTTypeClass typeClass = reader.getTypeClass();
2630
2631 switch (typeClass)
2632 {
2633 case RT_TYPE_INTERFACE:
2634 {
2635 InterfaceType iType(reader, typeName, typeMgr, typeDependencies, generatedConversions);
2636 ret = iType.dump(pOptions, o, allreadyDumped);
2637 if (ret) typeDependencies.setGenerated(typeName);
2638 ret = iType.dumpDependedTypes(pOptions, o, allreadyDumped);
2639 }
2640 break;
2641 case RT_TYPE_MODULE:
2642 {
2643 ModuleType mType(reader, typeName, typeMgr, typeDependencies, generatedConversions);
2644 if (mType.hasConstants())
2645 {
2646 ret = mType.dump(pOptions, o, allreadyDumped);
2647 if (ret) typeDependencies.setGenerated(typeName);
2648 } else
2649 {
2650 typeDependencies.setGenerated(typeName);
2651 ret = sal_True;
2652 }
2653 }
2654 break;
2655 case RT_TYPE_STRUCT:
2656 {
2657 StructureType sType(reader, typeName, typeMgr, typeDependencies, generatedConversions);
2658 ret = sType.dump(pOptions, o, allreadyDumped);
2659 if (ret) typeDependencies.setGenerated(typeName);
2660 ret = sType.dumpDependedTypes(pOptions, o, allreadyDumped);
2661 }
2662 break;
2663 case RT_TYPE_ENUM:
2664 {
2665 EnumType enType(reader, typeName, typeMgr, typeDependencies, generatedConversions);
2666 ret = enType.dump(pOptions, o, allreadyDumped);
2667 if (ret) typeDependencies.setGenerated(typeName);
2668 ret = enType.dumpDependedTypes(pOptions, o, allreadyDumped);
2669 }
2670 break;
2671 case RT_TYPE_EXCEPTION:
2672 {
2673 ExceptionType eType(reader, typeName, typeMgr, typeDependencies, generatedConversions);
2674 ret = eType.dump(pOptions, o, allreadyDumped);
2675 if (ret) typeDependencies.setGenerated(typeName);
2676 ret = eType.dumpDependedTypes(pOptions, o, allreadyDumped);
2677 }
2678 break;
2679 case RT_TYPE_TYPEDEF:
2680 {
2681 TypeDefType tdType(reader, typeName, typeMgr, typeDependencies, generatedConversions);
2682 ret = tdType.dump(pOptions, o, allreadyDumped);
2683 if (ret) typeDependencies.setGenerated(typeName);
2684 ret = tdType.dumpDependedTypes(pOptions, o, allreadyDumped);
2685 }
2686 break;
2687 case RT_TYPE_CONSTANTS:
2688 {
2689 ConstantsType cType(reader, typeName, typeMgr, typeDependencies, generatedConversions);
2690 if (cType.hasConstants())
2691 {
2692 ret = cType.dump(pOptions, o, allreadyDumped);
2693 if (ret) typeDependencies.setGenerated(typeName);
2694 } else
2695 {
2696 typeDependencies.setGenerated(typeName);
2697 ret = sal_True;
2698 }
2699 }
2700 break;
2701 case RT_TYPE_SERVICE:
2702 case RT_TYPE_OBJECT:
2703 ret = sal_True;
2704 break;
2705 }
2706 }
2707 }
2708
2709 if (bNewTypeSet)
2710 delete allreadyDumped;
2711
2712 return ret;
2713 }
2714
2715 //*************************************************************************
2716 // scopedName
2717 //*************************************************************************
scopedName(const OString & scope,const OString & type,sal_Bool bNoNameSpace)2718 OString scopedName(const OString& scope, const OString& type,
2719 sal_Bool bNoNameSpace)
2720 {
2721 sal_Int32 nPos = type.lastIndexOf( '/' );
2722 if (nPos == -1)
2723 return type;
2724
2725 if (bNoNameSpace)
2726 return type.copy(nPos+1);
2727
2728 OStringBuffer tmpBuf(type.getLength()*2);
2729 nPos = 0;
2730 do
2731 {
2732 tmpBuf.append("::");
2733 tmpBuf.append(type.getToken(0, '/', nPos));
2734 } while( nPos != -1 );
2735
2736 return tmpBuf.makeStringAndClear();
2737 }
2738
2739 //*************************************************************************
2740 // shortScopedName
2741 //*************************************************************************
shortScopedName(const OString & scope,const OString & type,sal_Bool bNoNameSpace)2742 OString shortScopedName(const OString& scope, const OString& type,
2743 sal_Bool bNoNameSpace)
2744 {
2745 sal_Int32 nPos = type.lastIndexOf( '/' );
2746 if( nPos == -1 )
2747 return OString();
2748
2749 if (bNoNameSpace)
2750 return OString();
2751
2752 // scoped name only if the namespace is not equal
2753 if (scope.lastIndexOf('/') > 0)
2754 {
2755 OString tmpScp(scope.copy(0, scope.lastIndexOf('/')));
2756 OString tmpScp2(type.copy(0, nPos));
2757
2758 if (tmpScp == tmpScp2)
2759 return OString();
2760 }
2761
2762 OString aScope( type.copy( 0, nPos ) );
2763 OStringBuffer tmpBuf(aScope.getLength()*2);
2764
2765 nPos = 0;
2766 do
2767 {
2768 tmpBuf.append("::");
2769 tmpBuf.append(aScope.getToken(0, '/', nPos));
2770 } while( nPos != -1 );
2771
2772 return tmpBuf.makeStringAndClear();
2773 }
2774
2775 /* vim: set noet sw=4 ts=4: */
2776