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