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