1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_codemaker.hxx" 30 31 #include <stdio.h> 32 #include <rtl/alloc.h> 33 #include <rtl/ustring.hxx> 34 #include <rtl/strbuf.hxx> 35 36 #include "idltype.hxx" 37 #include "idloptions.hxx" 38 39 using namespace rtl; 40 41 //************************************************************************* 42 // IdlType 43 //************************************************************************* 44 IdlType::IdlType(TypeReader& typeReader, 45 const OString& typeName, 46 const TypeManager& typeMgr, 47 const TypeDependency& typeDependencies) 48 : m_inheritedMemberCount(0) 49 , m_indentLength(0) 50 , m_typeName(typeName) 51 , m_reader(typeReader) 52 , m_typeMgr((TypeManager&)typeMgr) 53 , m_dependencies(typeDependencies) 54 { 55 sal_Int32 i = typeName.lastIndexOf('/'); 56 m_name = typeName.copy( i != -1 ? i+1 : 0 ); 57 } 58 59 IdlType::~IdlType() 60 { 61 62 } 63 64 sal_Bool IdlType::dump(IdlOptions* pOptions) 65 throw( CannotDumpException ) 66 { 67 sal_Bool ret = sal_False; 68 69 OString outPath; 70 if (pOptions->isValid("-O")) 71 outPath = pOptions->getOption("-O"); 72 73 OString tmpFileName; 74 OString hFileName = createFileNameFromType(outPath, m_typeName, ".idl"); 75 76 sal_Bool bFileExists = sal_False; 77 sal_Bool bFileCheck = sal_False; 78 79 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") ) 80 { 81 bFileExists = fileExists( hFileName ); 82 ret = sal_True; 83 } 84 85 if ( bFileExists && pOptions->isValid("-Gc") ) 86 { 87 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tml"); 88 bFileCheck = sal_True; 89 } 90 91 if ( !bFileExists || bFileCheck ) 92 { 93 FileStream hFile; 94 95 if ( bFileCheck ) 96 hFile.open(tmpFileName); 97 else 98 hFile.open(hFileName); 99 100 if(!hFile.isValid()) 101 { 102 OString message("cannot open "); 103 message += hFileName + " for writing"; 104 throw CannotDumpException(message); 105 } 106 107 ret = dumpHFile(hFile); 108 109 hFile.close(); 110 if (ret && bFileCheck) 111 { 112 ret = checkFileContent(hFileName, tmpFileName); 113 } 114 } 115 116 return ret; 117 } 118 sal_Bool IdlType::dumpDependedTypes(IdlOptions* pOptions) 119 throw( CannotDumpException ) 120 { 121 sal_Bool ret = sal_True; 122 123 TypeUsingSet usingSet(m_dependencies.getDependencies(m_typeName)); 124 125 TypeUsingSet::const_iterator iter = usingSet.begin(); 126 OString typeName; 127 sal_uInt32 index = 0; 128 while (iter != usingSet.end()) 129 { 130 typeName = (*iter).m_type; 131 if ((index = typeName.lastIndexOf(']')) > 0) 132 typeName = typeName.copy(index + 1); 133 134 if (getBaseType(typeName).getLength() == 0) 135 { 136 if (!produceType(typeName, 137 m_typeMgr, 138 m_dependencies, 139 pOptions)) 140 { 141 fprintf(stderr, "%s ERROR: %s\n", 142 pOptions->getProgramName().getStr(), 143 OString("cannot dump Type '" + typeName + "'").getStr()); 144 exit(99); 145 } 146 } 147 ++iter; 148 } 149 150 return ret; 151 } 152 153 OString IdlType::dumpHeaderDefine(FileStream& o, sal_Char* prefix ) 154 { 155 if (m_typeName.equals("/")) 156 { 157 m_typeName = "global"; 158 } 159 160 sal_uInt32 length = 3 + m_typeName.getLength() + strlen(prefix); 161 162 OStringBuffer tmpBuf(length); 163 164 tmpBuf.append('_'); 165 tmpBuf.append(m_typeName); 166 tmpBuf.append('_'); 167 tmpBuf.append(prefix); 168 tmpBuf.append('_'); 169 170 OString tmp(tmpBuf.makeStringAndClear().replace('/', '_').toAsciiUpperCase()); 171 172 o << "#ifndef " << tmp << "\n#define " << tmp << "\n"; 173 174 return tmp; 175 } 176 177 void IdlType::dumpDefaultHIncludes(FileStream& o) 178 { 179 } 180 181 void IdlType::dumpInclude(FileStream& o, const OString& genTypeName, const OString& typeName, sal_Char* prefix ) 182 { 183 sal_uInt32 length = 3+ m_typeName.getLength() + strlen(prefix); 184 185 OStringBuffer tmpBuf(length); 186 187 tmpBuf.append('_'); 188 tmpBuf.append(typeName); 189 tmpBuf.append('_'); 190 tmpBuf.append(prefix); 191 tmpBuf.append('_'); 192 193 OString tmp(tmpBuf.makeStringAndClear().replace('/', '_').toAsciiUpperCase()); 194 195 length = 1 + typeName.getLength() + strlen(prefix); 196 197 tmpBuf.ensureCapacity(length); 198 tmpBuf.append(typeName); 199 tmpBuf.append('.'); 200 tmpBuf.append(prefix); 201 202 o << "#ifndef " << tmp << "\n#include <"; 203 tmp = tmpBuf.makeStringAndClear(); 204 205 sal_Int32 nIndex = 0; 206 do 207 { 208 genTypeName.getToken(0, '/', nIndex); 209 o << "../"; 210 } while( nIndex != -1 ); 211 212 // sal_Int32 nSlashes = genTypeName.getTokenCount( '/'); 213 // for( sal_Int32 i = 1; i < nSlashes; i++ ) 214 // o << "../"; 215 o << tmp; 216 o << ">\n#endif\n"; 217 } 218 219 void IdlType::dumpDepIncludes(FileStream& o, const OString& typeName, sal_Char* prefix) 220 { 221 TypeUsingSet usingSet(m_dependencies.getDependencies(typeName)); 222 223 TypeUsingSet::const_iterator iter = usingSet.begin(); 224 225 OString sPrefix(OString(prefix).toAsciiUpperCase()); 226 sal_uInt32 index = 0; 227 sal_uInt32 seqNum = 0; 228 OString relType; 229 while (iter != usingSet.end()) 230 { 231 index = (*iter).m_type.lastIndexOf(']'); 232 seqNum = (index > 0 ? ((index+1) / 2) : 0); 233 234 relType = (*iter).m_type; 235 if (index > 0) 236 relType = relType.copy(index+1); 237 238 239 OString defPrefix("IDL"); 240 241 if (getBaseType(relType).getLength() == 0 && 242 m_typeName != relType) 243 { 244 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE) 245 { 246 if (!((*iter).m_use & TYPEUSE_SUPER)) 247 { 248 o << "\n"; 249 dumpNameSpace(o, sal_True, sal_False, relType); 250 o << "\ninterface " << scopedName(m_typeName, relType, sal_True) << ";\n"; 251 dumpNameSpace(o, sal_False, sal_False, relType); 252 o << "\n\n"; 253 } 254 } 255 dumpInclude(o, typeName, relType, prefix); 256 } 257 else if (relType == "type") 258 { 259 o << "module CORBA {\n" 260 << "\tinterface TypeCode;\n" 261 << "};\n\n"; 262 } 263 264 if( seqNum != 0 ) 265 { 266 // write typedef for sequences to support Rational Rose 2000 import 267 OString aST = relType; 268 OString aScope; 269 dumpNameSpace( o, sal_True, sal_False, relType ); 270 for( sal_uInt32 i = 0; i < seqNum; i++ ) 271 { 272 o << "typedef sequence< " << scopedName("", aST) << " > "; 273 274 if( i == 0 ) 275 { 276 aST = aST.replace( '/', '_' ); 277 aST = aST.replace( ' ', '_' ); 278 } 279 aST = aST + "_Sequence" ; 280 o << aST << ";\n"; 281 } 282 dumpNameSpace( o, sal_False, sal_False, relType ); 283 } 284 ++iter; 285 } 286 } 287 288 void IdlType::dumpNameSpace(FileStream& o, sal_Bool bOpen, sal_Bool bFull, const OString& type) 289 { 290 OString typeName(type); 291 sal_Bool bOneLine = sal_True; 292 if (typeName.getLength() == 0) 293 { 294 typeName = m_typeName; 295 bOneLine = sal_False; 296 } 297 298 if (typeName == "/") 299 return; 300 301 if (typeName.indexOf( '/' ) == -1 && !bFull) 302 return; 303 304 if (!bFull) 305 typeName = typeName.copy( 0, typeName.lastIndexOf( '/' ) ); 306 307 if (bOpen) 308 { 309 sal_Int32 nIndex = 0; 310 do 311 { 312 o << "module " << typeName.getToken(0, '/', nIndex); 313 if (bOneLine) 314 o << " { "; 315 else 316 o << "\n{\n"; 317 } while( nIndex != -1 ); 318 } else 319 { 320 sal_Int32 nPos = 0; 321 do 322 { 323 nPos = typeName.lastIndexOf( '/' ); 324 o << "};"; 325 if( bOneLine ) 326 o << " "; 327 else 328 o << " /* " << typeName.copy( nPos+1 ) << " */\n"; 329 if( nPos != -1 ) 330 typeName = typeName.copy( 0, nPos ); 331 } while( nPos != -1 ); 332 } 333 } 334 335 336 sal_uInt32 IdlType::getMemberCount() 337 { 338 sal_uInt32 count = m_reader.getMethodCount(); 339 340 sal_uInt32 fieldCount = m_reader.getFieldCount(); 341 RTFieldAccess access = RT_ACCESS_INVALID; 342 for (sal_uInt16 i=0; i < fieldCount; i++) 343 { 344 access = m_reader.getFieldAccess(i); 345 346 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID) 347 count++; 348 } 349 return count; 350 } 351 352 sal_uInt32 IdlType::checkInheritedMemberCount(const TypeReader* pReader) 353 { 354 sal_Bool bSelfCheck = sal_True; 355 if (!pReader) 356 { 357 bSelfCheck = sal_False; 358 pReader = &m_reader; 359 } 360 361 sal_uInt32 count = 0; 362 OString superType(pReader->getSuperTypeName()); 363 if (superType.getLength() > 0) 364 { 365 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType)); 366 if ( aSuperReader.isValid() ) 367 { 368 count = checkInheritedMemberCount(&aSuperReader); 369 } 370 } 371 372 if (bSelfCheck) 373 { 374 count += pReader->getMethodCount(); 375 sal_uInt32 fieldCount = pReader->getFieldCount(); 376 RTFieldAccess access = RT_ACCESS_INVALID; 377 for (sal_uInt16 i=0; i < fieldCount; i++) 378 { 379 access = pReader->getFieldAccess(i); 380 381 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID) 382 { 383 count++; 384 } 385 } 386 } 387 388 return count; 389 } 390 391 sal_uInt32 IdlType::getInheritedMemberCount() 392 { 393 if (m_inheritedMemberCount == 0) 394 { 395 m_inheritedMemberCount = checkInheritedMemberCount(0); 396 } 397 398 return m_inheritedMemberCount; 399 } 400 401 402 void IdlType::dumpType(FileStream& o, const OString& type ) 403 throw( CannotDumpException ) 404 { 405 OString sType(checkRealBaseType(type, sal_True)); 406 sal_uInt32 index = sType.lastIndexOf(']'); 407 sal_uInt32 seqNum = (index > 0 ? ((index+1) / 2) : 0); 408 409 OString relType = (index > 0 ? (sType).copy(index+1) : type); 410 411 RTTypeClass typeClass = m_typeMgr.getTypeClass(relType); 412 413 sal_uInt32 i; 414 /* 415 for (i=0; i < seqNum; i++) 416 { 417 //o << "sequence< "; 418 } 419 */ 420 switch (typeClass) 421 { 422 case RT_TYPE_INVALID: 423 { 424 OString tmp(getBaseType(relType)); 425 if (tmp.getLength() > 0) 426 { 427 tmp = tmp.replace( ' ', '_' ); 428 o << tmp; 429 } else 430 throw CannotDumpException("Unknown type '" + relType + "', incomplete type library."); 431 } 432 break; 433 case RT_TYPE_INTERFACE: 434 case RT_TYPE_STRUCT: 435 case RT_TYPE_ENUM: 436 case RT_TYPE_TYPEDEF: 437 case RT_TYPE_EXCEPTION: 438 if( seqNum ) 439 { 440 OString aST = relType.replace( '/', '_' ); 441 aST = aST.replace( ' ', '_' ); 442 o << aST; 443 } 444 else 445 o << scopedName(m_typeName, relType); 446 break; 447 } 448 449 for (i=0; i < seqNum; i++) 450 { 451 //o << " >"; 452 // use typedef for sequences to support Rational Rose 2000 import 453 o << "_Sequence"; 454 } 455 } 456 457 OString IdlType::getBaseType(const OString& type) 458 { 459 if (type.equals("long")) 460 return type; 461 if (type.equals("short")) 462 return type; 463 if (type.equals("hyper")) 464 return "long long"; 465 if (type.equals("string")) 466 return "string"; 467 if (type.equals("boolean")) 468 return type; 469 if (type.equals("char")) 470 return "char"; 471 if (type.equals("byte")) 472 return "byte"; 473 if (type.equals("any")) 474 return type; 475 if (type.equals("type")) 476 return "CORBA::TypeCode"; 477 if (type.equals("float")) 478 return type; 479 if (type.equals("double")) 480 return type; 481 if (type.equals("octet")) 482 return type; 483 if (type.equals("void")) 484 return type; 485 if (type.equals("unsigned long")) 486 return type; 487 if (type.equals("unsigned short")) 488 return type; 489 if (type.equals("unsigned hyper")) 490 return "unsigned long long"; 491 492 return OString(); 493 } 494 495 void IdlType::dumpIdlGetType(FileStream& o, const OString& type, sal_Bool bDecl, IdlTypeDecl eDeclFlag) 496 { 497 OString sType( checkRealBaseType(type, sal_True) ); 498 sal_uInt32 index = sType.lastIndexOf(']'); 499 OString relType = (index > 0 ? (sType).copy(index+1) : type); 500 501 if (eDeclFlag == CPPUTYPEDECL_ONLYINTERFACES) 502 { 503 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE) 504 { 505 o << indent() << "getIdlType( ("; 506 dumpType(o, type); 507 o << "*)0 )"; 508 509 if (bDecl) 510 o << ";\n"; 511 } 512 } else 513 { 514 if (isBaseType(type)) 515 { 516 return; 517 } else 518 { 519 if (eDeclFlag == CPPUTYPEDECL_NOINTERFACES && 520 m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE) 521 return; 522 523 // if (m_typeMgr.getTypeClass(type) == RT_TYPE_TYPEDEF) 524 // { 525 // o << indent() << "get_" << type.replace('/', '_') << "_Type()"; 526 // } else 527 // { 528 o << indent() << "getIdlType( ("; 529 dumpType(o, type); 530 o << "*)0 )"; 531 // } 532 } 533 if (bDecl) 534 o << ";\n"; 535 } 536 } 537 538 BASETYPE IdlType::isBaseType(const OString& type) 539 { 540 if (type.equals("long")) 541 return BT_LONG; 542 if (type.equals("short")) 543 return BT_SHORT; 544 if (type.equals("hyper")) 545 return BT_HYPER; 546 if (type.equals("string")) 547 return BT_STRING; 548 if (type.equals("boolean")) 549 return BT_BOOLEAN; 550 if (type.equals("char")) 551 return BT_CHAR; 552 if (type.equals("byte")) 553 return BT_BYTE; 554 if (type.equals("any")) 555 return BT_ANY; 556 if (type.equals("float")) 557 return BT_FLOAT; 558 if (type.equals("double")) 559 return BT_DOUBLE; 560 if (type.equals("void")) 561 return BT_VOID; 562 if (type.equals("unsigned long")) 563 return BT_UNSIGNED_LONG; 564 if (type.equals("unsigned short")) 565 return BT_UNSIGNED_SHORT; 566 if (type.equals("unsigned hyper")) 567 return BT_UNSIGNED_HYPER; 568 569 return BT_INVALID; 570 } 571 572 OString IdlType::checkSpecialIdlType(const OString& type) 573 { 574 OString baseType(type); 575 576 RegistryTypeReaderLoader & rReaderLoader = getRegistryTypeReaderLoader(); 577 578 RegistryKey key; 579 sal_uInt8* pBuffer=NULL; 580 RTTypeClass typeClass; 581 sal_Bool isTypeDef = (m_typeMgr.getTypeClass(baseType) == RT_TYPE_TYPEDEF); 582 TypeReader reader; 583 584 while (isTypeDef) 585 { 586 reader = m_typeMgr.getTypeReader(baseType); 587 588 if (reader.isValid()) 589 { 590 typeClass = reader.getTypeClass(); 591 592 if (typeClass == RT_TYPE_TYPEDEF) 593 baseType = reader.getSuperTypeName(); 594 else 595 isTypeDef = sal_False; 596 } else 597 { 598 break; 599 } 600 } 601 602 return baseType; 603 } 604 605 OString IdlType::checkRealBaseType(const OString& type, sal_Bool bResolveTypeOnly) 606 { 607 sal_uInt32 index = type.lastIndexOf(']'); 608 OString baseType = (index > 0 ? ((OString)type).copy(index+1) : type); 609 OString seqPrefix = (index > 0 ? ((OString)type).copy(0, index+1) : OString()); 610 611 RegistryTypeReaderLoader & rReaderLoader = getRegistryTypeReaderLoader(); 612 613 RegistryKey key; 614 sal_uInt8* pBuffer=NULL; 615 RTTypeClass typeClass; 616 sal_Bool mustBeChecked = (m_typeMgr.getTypeClass(baseType) == RT_TYPE_TYPEDEF); 617 TypeReader reader; 618 619 while (mustBeChecked) 620 { 621 reader = m_typeMgr.getTypeReader(baseType); 622 623 if (reader.isValid()) 624 { 625 typeClass = reader.getTypeClass(); 626 627 if (typeClass == RT_TYPE_TYPEDEF) 628 { 629 baseType = reader.getSuperTypeName(); 630 index = baseType.lastIndexOf(']'); 631 if (index > 0) 632 { 633 seqPrefix += baseType.copy(0, index+1); 634 baseType = baseType.copy(index+1); 635 } 636 } else 637 mustBeChecked = sal_False; 638 } else 639 { 640 break; 641 } 642 } 643 644 if ( bResolveTypeOnly ) 645 baseType = seqPrefix + baseType; 646 647 return baseType; 648 } 649 650 void IdlType::dumpConstantValue(FileStream& o, sal_uInt16 index) 651 { 652 RTConstValue constValue = m_reader.getFieldConstValue(index); 653 654 switch (constValue.m_type) 655 { 656 case RT_TYPE_BOOL: 657 if (constValue.m_value.aBool) 658 o << "true"; 659 else 660 o << "false"; 661 break; 662 case RT_TYPE_BYTE: 663 { 664 char tmp[16]; 665 snprintf(tmp, sizeof(tmp), "0x%x", (sal_Int8)constValue.m_value.aByte); 666 o << tmp; 667 } 668 break; 669 case RT_TYPE_INT16: 670 o << constValue.m_value.aShort; 671 break; 672 case RT_TYPE_UINT16: 673 o << constValue.m_value.aUShort; 674 break; 675 case RT_TYPE_INT32: 676 o << constValue.m_value.aLong; 677 break; 678 case RT_TYPE_UINT32: 679 o << constValue.m_value.aULong; 680 break; 681 case RT_TYPE_INT64: 682 { 683 ::rtl::OString tmp( OString::valueOf(constValue.m_value.aHyper) ); 684 o << tmp.getStr(); 685 } 686 break; 687 case RT_TYPE_UINT64: 688 { 689 ::rtl::OString tmp( OString::valueOf((sal_Int64)constValue.m_value.aUHyper) ); 690 o << tmp.getStr(); 691 } 692 break; 693 case RT_TYPE_FLOAT: 694 { 695 ::rtl::OString tmp( OString::valueOf(constValue.m_value.aFloat) ); 696 o << tmp.getStr(); 697 } 698 break; 699 case RT_TYPE_DOUBLE: 700 { 701 ::rtl::OString tmp( OString::valueOf(constValue.m_value.aDouble) ); 702 o << tmp.getStr(); 703 } 704 break; 705 case RT_TYPE_STRING: 706 { 707 ::rtl::OUString aUStr(constValue.m_value.aString); 708 ::rtl::OString aStr = ::rtl::OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US); 709 o << "\"" << aStr.getStr() << "\")"; 710 } 711 break; 712 } 713 } 714 715 void IdlType::inc(sal_uInt32 num) 716 { 717 m_indentLength += num; 718 } 719 720 void IdlType::dec(sal_uInt32 num) 721 { 722 if (m_indentLength - num < 0) 723 m_indentLength = 0; 724 else 725 m_indentLength -= num; 726 } 727 728 OString IdlType::indent() 729 { 730 OStringBuffer tmp(m_indentLength); 731 732 for (sal_uInt32 i=0; i < m_indentLength; i++) 733 { 734 tmp.append(' '); 735 } 736 return tmp.makeStringAndClear(); 737 } 738 739 OString IdlType::indent(sal_uInt32 num) 740 { 741 OStringBuffer tmp(m_indentLength + num); 742 743 for (sal_uInt32 i=0; i < m_indentLength + num; i++) 744 { 745 tmp.append(' '); 746 } 747 return tmp.makeStringAndClear(); 748 } 749 750 //************************************************************************* 751 // InterfaceType 752 //************************************************************************* 753 InterfaceType::InterfaceType(TypeReader& typeReader, 754 const OString& typeName, 755 const TypeManager& typeMgr, 756 const TypeDependency& typeDependencies) 757 : IdlType(typeReader, typeName, typeMgr, typeDependencies) 758 { 759 m_inheritedMemberCount = 0; 760 m_hasAttributes = sal_False; 761 m_hasMethods = sal_False; 762 } 763 764 InterfaceType::~InterfaceType() 765 { 766 767 } 768 769 sal_Bool InterfaceType::dumpHFile(FileStream& o) 770 throw( CannotDumpException ) 771 { 772 OString headerDefine(dumpHeaderDefine(o, "IDL")); 773 o << "\n"; 774 775 dumpDefaultHIncludes(o); 776 o << "\n"; 777 dumpDepIncludes(o, m_typeName, "idl"); 778 o << "\n"; 779 dumpNameSpace(o); 780 781 // write documentation 782 OString aDoc = m_reader.getDoku(); 783 if( aDoc.getLength() ) 784 o << "/**\n" << aDoc << "\n*/"; 785 o << "\ninterface " << m_name; 786 787 OString superType(m_reader.getSuperTypeName()); 788 if (superType.getLength() > 0) 789 o << " : " << scopedName(m_typeName, superType); 790 791 o << "\n{\n"; 792 inc(); 793 794 dumpAttributes(o); 795 dumpMethods(o); 796 797 dec(); 798 o << "};\n\n"; 799 800 dumpNameSpace(o, sal_False); 801 802 // o << "\nnamespace com { namespace sun { namespace star { namespace uno {\n" 803 // << "class Type;\n} } } }\n\n"; 804 805 o << "#endif /* "<< headerDefine << "*/" << "\n"; 806 return sal_True; 807 } 808 809 void InterfaceType::dumpAttributes(FileStream& o) 810 { 811 sal_uInt32 fieldCount = m_reader.getFieldCount(); 812 sal_Bool first=sal_True; 813 814 RTFieldAccess access = RT_ACCESS_INVALID; 815 OString fieldName; 816 OString fieldType; 817 for (sal_uInt16 i=0; i < fieldCount; i++) 818 { 819 access = m_reader.getFieldAccess(i); 820 821 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) 822 continue; 823 824 fieldName = m_reader.getFieldName(i); 825 fieldType = m_reader.getFieldType(i); 826 827 if (first) 828 { 829 first = sal_False; 830 o << "\n"; 831 } 832 833 // write documentation 834 OString aDoc = m_reader.getFieldDoku(i); 835 if( aDoc.getLength() ) 836 o << "/**\n" << aDoc << "\n*/\n"; 837 838 if (access == RT_ACCESS_READONLY) 839 o << indent() << "readonly attribute "; 840 else 841 o << indent() << "attribute "; 842 dumpType(o, fieldType); 843 o << " " << fieldName << ";\n"; 844 } 845 } 846 847 void InterfaceType::dumpMethods(FileStream& o) 848 { 849 sal_uInt32 methodCount = m_reader.getMethodCount(); 850 851 OString methodName, returnType, paramType, paramName; 852 sal_uInt32 paramCount = 0; 853 sal_uInt32 excCount = 0; 854 RTMethodMode methodMode = RT_MODE_INVALID; 855 RTParamMode paramMode = RT_PARAM_INVALID; 856 857 sal_Bool bRef = sal_False; 858 sal_Bool bConst = sal_False; 859 sal_Bool bWithRunTimeExcp = sal_True; 860 861 for (sal_Int16 i=0; i < methodCount; i++) 862 { 863 methodName = m_reader.getMethodName(i); 864 returnType = m_reader.getMethodReturnType(i); 865 paramCount = m_reader.getMethodParamCount(i); 866 excCount = m_reader.getMethodExcCount(i); 867 methodMode = m_reader.getMethodMode(i); 868 869 if ( methodName.equals("acquire") || methodName.equals("release") ) 870 { 871 bWithRunTimeExcp = sal_False; 872 } 873 874 // write documentation 875 OString aDoc = m_reader.getMethodDoku(i); 876 if( aDoc.getLength() ) 877 o << "/**\n" << aDoc << "\n*/\n"; 878 879 o << indent(); 880 dumpType(o, returnType); 881 o << " " << methodName << "( "; 882 sal_uInt16 j; 883 for (j=0; j < paramCount; j++) 884 { 885 paramName = m_reader.getMethodParamName(i, j); 886 paramType = m_reader.getMethodParamType(i, j); 887 paramMode = m_reader.getMethodParamMode(i, j); 888 889 switch (paramMode) 890 { 891 case RT_PARAM_IN: 892 o << "in "; 893 break; 894 case RT_PARAM_OUT: 895 o << "out "; 896 break; 897 case RT_PARAM_INOUT: 898 o << "inout "; 899 break; 900 break; 901 } 902 903 dumpType(o, paramType); 904 if( paramName == "Object" ) 905 o << " _Object"; 906 else 907 o << " " << paramName; 908 909 if (j+1 < paramCount) o << ", "; 910 } 911 o << " )"; 912 913 if( excCount ) 914 { 915 o << " raises("; 916 OString excpName; 917 sal_Bool bWriteComma = sal_False; 918 sal_Bool bRTExceptionWritten = sal_False; 919 for (j=0; j < excCount; j++) 920 { 921 excpName = m_reader.getMethodExcType(i, j); 922 if( bWriteComma ) 923 o << ", "; 924 o << scopedName(m_typeName, excpName); 925 bWriteComma = sal_True; 926 927 if(excpName == "com/sun/star/uno/RuntimeException") 928 bRTExceptionWritten = sal_True; 929 } 930 931 if ( bWithRunTimeExcp && !bRTExceptionWritten ) 932 { 933 if( bWriteComma ) 934 o << ", "; 935 o << "::com::sun::star::uno::RuntimeException"; 936 } 937 938 o << ");\n"; 939 } 940 else if ( bWithRunTimeExcp ) 941 { 942 o << "raises( ::com::sun::star::uno::RuntimeException );\n"; 943 } 944 else 945 { 946 o << ";\n"; 947 } 948 } 949 } 950 951 952 sal_uInt32 InterfaceType::getMemberCount() 953 { 954 sal_uInt32 count = m_reader.getMethodCount(); 955 956 if (count) 957 m_hasMethods = sal_True; 958 959 sal_uInt32 fieldCount = m_reader.getFieldCount(); 960 RTFieldAccess access = RT_ACCESS_INVALID; 961 for (sal_uInt16 i=0; i < fieldCount; i++) 962 { 963 access = m_reader.getFieldAccess(i); 964 965 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID) 966 { 967 m_hasAttributes = sal_True; 968 count++; 969 } 970 } 971 return count; 972 } 973 974 sal_uInt32 InterfaceType::checkInheritedMemberCount(const TypeReader* pReader) 975 { 976 sal_uInt32 cout = 0; 977 sal_Bool bSelfCheck = sal_True; 978 if (!pReader) 979 { 980 bSelfCheck = sal_False; 981 pReader = &m_reader; 982 } 983 984 sal_uInt32 count = 0; 985 OString superType(pReader->getSuperTypeName()); 986 if (superType.getLength() > 0) 987 { 988 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType)); 989 if (aSuperReader.isValid()) 990 { 991 count = checkInheritedMemberCount(&aSuperReader); 992 } 993 } 994 995 if (bSelfCheck) 996 { 997 count += pReader->getMethodCount(); 998 sal_uInt32 fieldCount = pReader->getFieldCount(); 999 RTFieldAccess access = RT_ACCESS_INVALID; 1000 for (sal_uInt16 i=0; i < fieldCount; i++) 1001 { 1002 access = pReader->getFieldAccess(i); 1003 1004 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID) 1005 { 1006 count++; 1007 } 1008 } 1009 } 1010 1011 return count; 1012 } 1013 1014 sal_uInt32 InterfaceType::getInheritedMemberCount() 1015 { 1016 if (m_inheritedMemberCount == 0) 1017 { 1018 m_inheritedMemberCount = checkInheritedMemberCount(0); 1019 } 1020 1021 return m_inheritedMemberCount; 1022 } 1023 1024 1025 1026 //************************************************************************* 1027 // ModuleType 1028 //************************************************************************* 1029 ModuleType::ModuleType(TypeReader& typeReader, 1030 const OString& typeName, 1031 const TypeManager& typeMgr, 1032 const TypeDependency& typeDependencies) 1033 : IdlType(typeReader, typeName, typeMgr, typeDependencies) 1034 { 1035 } 1036 1037 ModuleType::~ModuleType() 1038 { 1039 1040 } 1041 1042 sal_Bool ModuleType::dump(IdlOptions* pOptions) 1043 throw( CannotDumpException ) 1044 { 1045 sal_Bool ret = sal_False; 1046 1047 OString outPath; 1048 if (pOptions->isValid("-O")) 1049 outPath = pOptions->getOption("-O"); 1050 1051 OString tmpName(m_typeName); 1052 1053 if (tmpName.equals("/")) 1054 tmpName = "global"; 1055 else 1056 // tmpName += "/" + m_typeName.getToken(m_typeName.getTokenCount('/') - 1, '/'); 1057 tmpName += "/" + m_name; 1058 1059 OString tmpFileName; 1060 OString hFileName = createFileNameFromType(outPath, tmpName, ".idl"); 1061 1062 sal_Bool bFileExists = sal_False; 1063 sal_Bool bFileCheck = sal_False; 1064 1065 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") ) 1066 { 1067 bFileExists = fileExists( hFileName ); 1068 ret = sal_True; 1069 } 1070 1071 if ( bFileExists && pOptions->isValid("-Gc") ) 1072 { 1073 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tml"); 1074 bFileCheck = sal_True; 1075 } 1076 1077 if ( !bFileExists || bFileCheck ) 1078 { 1079 FileStream hFile; 1080 1081 if ( bFileCheck ) 1082 hFile.open(tmpFileName); 1083 else 1084 hFile.open(hFileName); 1085 1086 if(!hFile.isValid()) 1087 { 1088 OString message("cannot open "); 1089 message += hFileName + " for writing"; 1090 throw CannotDumpException(message); 1091 } 1092 1093 ret = dumpHFile(hFile); 1094 1095 hFile.close(); 1096 if (ret && bFileCheck) 1097 { 1098 ret = checkFileContent(hFileName, tmpFileName); 1099 } 1100 } 1101 1102 return ret; 1103 } 1104 1105 sal_Bool ModuleType::dumpHFile(FileStream& o) 1106 throw( CannotDumpException ) 1107 { 1108 OString headerDefine(dumpHeaderDefine(o, "IDL")); 1109 o << "\n"; 1110 1111 dumpDefaultHIncludes(o); 1112 o << "\n"; 1113 dumpDepIncludes(o, m_typeName, "idl"); 1114 o << "\n"; 1115 1116 dumpNameSpace(o, sal_True, sal_True); 1117 o << "\n"; 1118 1119 sal_uInt32 fieldCount = m_reader.getFieldCount(); 1120 RTFieldAccess access = RT_ACCESS_INVALID; 1121 OString fieldName; 1122 OString fieldType; 1123 for (sal_uInt16 i=0; i < fieldCount; i++) 1124 { 1125 access = m_reader.getFieldAccess(i); 1126 1127 if (access == RT_ACCESS_CONST) 1128 { 1129 fieldName = m_reader.getFieldName(i); 1130 fieldType = m_reader.getFieldType(i); 1131 1132 o << "const "; 1133 dumpType(o, fieldType); 1134 o << " " << fieldName << " = "; 1135 dumpConstantValue(o, i); 1136 o << ";\n"; 1137 } 1138 } 1139 1140 o << "\n"; 1141 dumpNameSpace(o, sal_False, sal_True); 1142 o << "\n#endif /* "<< headerDefine << "*/" << "\n"; 1143 1144 return sal_True; 1145 } 1146 1147 sal_Bool ModuleType::hasConstants() 1148 { 1149 sal_uInt32 fieldCount = m_reader.getFieldCount(); 1150 RTFieldAccess access = RT_ACCESS_INVALID; 1151 1152 for (sal_uInt16 i=0; i < fieldCount; i++) 1153 { 1154 access = m_reader.getFieldAccess(i); 1155 1156 if (access == RT_ACCESS_CONST) 1157 return sal_True; 1158 } 1159 1160 return sal_False; 1161 } 1162 1163 //************************************************************************* 1164 // ConstantsType 1165 //************************************************************************* 1166 ConstantsType::ConstantsType(TypeReader& typeReader, 1167 const OString& typeName, 1168 const TypeManager& typeMgr, 1169 const TypeDependency& typeDependencies) 1170 : ModuleType(typeReader, typeName, typeMgr, typeDependencies) 1171 { 1172 } 1173 1174 ConstantsType::~ConstantsType() 1175 { 1176 1177 } 1178 1179 sal_Bool ConstantsType::dump(IdlOptions* pOptions) 1180 throw( CannotDumpException ) 1181 { 1182 sal_Bool ret = sal_False; 1183 1184 OString outPath; 1185 if (pOptions->isValid("-O")) 1186 outPath = pOptions->getOption("-O"); 1187 1188 OString tmpFileName; 1189 OString hFileName = createFileNameFromType(outPath, m_typeName, ".idl"); 1190 1191 sal_Bool bFileExists = sal_False; 1192 sal_Bool bFileCheck = sal_False; 1193 1194 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") ) 1195 { 1196 bFileExists = fileExists( hFileName ); 1197 ret = sal_True; 1198 } 1199 1200 if ( bFileExists && pOptions->isValid("-Gc") ) 1201 { 1202 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tml"); 1203 bFileCheck = sal_True; 1204 } 1205 1206 if ( !bFileExists || bFileCheck ) 1207 { 1208 FileStream hFile; 1209 1210 if ( bFileCheck ) 1211 hFile.open(tmpFileName); 1212 else 1213 hFile.open(hFileName); 1214 1215 if(!hFile.isValid()) 1216 { 1217 OString message("cannot open "); 1218 message += hFileName + " for writing"; 1219 throw CannotDumpException(message); 1220 } 1221 1222 ret = dumpHFile(hFile); 1223 1224 hFile.close(); 1225 if (ret && bFileCheck) 1226 { 1227 ret = checkFileContent(hFileName, tmpFileName); 1228 } 1229 } 1230 1231 return ret; 1232 } 1233 1234 //************************************************************************* 1235 // StructureType 1236 //************************************************************************* 1237 StructureType::StructureType(TypeReader& typeReader, 1238 const OString& typeName, 1239 const TypeManager& typeMgr, 1240 const TypeDependency& typeDependencies) 1241 : IdlType(typeReader, typeName, typeMgr, typeDependencies) 1242 { 1243 } 1244 1245 StructureType::~StructureType() 1246 { 1247 1248 } 1249 1250 sal_Bool StructureType::dumpHFile(FileStream& o) 1251 throw( CannotDumpException ) 1252 { 1253 OString headerDefine(dumpHeaderDefine(o, "IDL")); 1254 o << "\n"; 1255 1256 dumpDefaultHIncludes(o); 1257 o << "\n"; 1258 dumpDepIncludes(o, m_typeName, "idl"); 1259 o << "\n"; 1260 1261 dumpNameSpace(o); 1262 1263 // write documentation 1264 OString aDoc = m_reader.getDoku(); 1265 if( aDoc.getLength() ) 1266 o << "/**\n" << aDoc << "\n*/"; 1267 1268 o << "\nstruct " << m_name; 1269 o << "\n{\n"; 1270 inc(); 1271 1272 OString superType(m_reader.getSuperTypeName()); 1273 if (superType.getLength() > 0) 1274 dumpSuperMember(o, superType); 1275 1276 sal_uInt32 fieldCount = m_reader.getFieldCount(); 1277 RTFieldAccess access = RT_ACCESS_INVALID; 1278 OString fieldName; 1279 OString fieldType; 1280 sal_uInt16 i=0; 1281 1282 for (i=0; i < fieldCount; i++) 1283 { 1284 access = m_reader.getFieldAccess(i); 1285 1286 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) 1287 continue; 1288 1289 fieldName = m_reader.getFieldName(i); 1290 fieldType = m_reader.getFieldType(i); 1291 1292 // write documentation 1293 OString aDoc = m_reader.getFieldDoku(i); 1294 if( aDoc.getLength() ) 1295 o << "/**\n" << aDoc << "\n*/"; 1296 1297 o << indent(); 1298 dumpType(o, fieldType); 1299 o << " " << fieldName << ";\n"; 1300 } 1301 1302 dec(); 1303 o << "};\n\n"; 1304 1305 dumpNameSpace(o, sal_False); 1306 1307 o << "#endif /* "<< headerDefine << "*/" << "\n"; 1308 1309 return sal_True; 1310 } 1311 1312 void StructureType::dumpSuperMember(FileStream& o, const OString& superType) 1313 { 1314 if (superType.getLength() > 0) 1315 { 1316 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType)); 1317 1318 if (aSuperReader.isValid()) 1319 { 1320 dumpSuperMember(o, aSuperReader.getSuperTypeName()); 1321 1322 sal_uInt32 fieldCount = aSuperReader.getFieldCount(); 1323 RTFieldAccess access = RT_ACCESS_INVALID; 1324 OString fieldName; 1325 OString fieldType; 1326 for (sal_uInt16 i=0; i < fieldCount; i++) 1327 { 1328 access = aSuperReader.getFieldAccess(i); 1329 1330 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) 1331 continue; 1332 1333 fieldName = aSuperReader.getFieldName(i); 1334 fieldType = aSuperReader.getFieldType(i); 1335 1336 // write documentation 1337 OString aDoc = aSuperReader.getFieldDoku(i); 1338 if( aDoc.getLength() ) 1339 o << "/**\n" << aDoc << "\n*/"; 1340 1341 o << indent(); 1342 dumpType(o, fieldType); 1343 o << " "; 1344 o << fieldName << ";\n"; 1345 } 1346 } 1347 } 1348 } 1349 1350 //************************************************************************* 1351 // ExceptionType 1352 //************************************************************************* 1353 ExceptionType::ExceptionType(TypeReader& typeReader, 1354 const OString& typeName, 1355 const TypeManager& typeMgr, 1356 const TypeDependency& typeDependencies) 1357 : IdlType(typeReader, typeName, typeMgr, typeDependencies) 1358 { 1359 } 1360 1361 ExceptionType::~ExceptionType() 1362 { 1363 1364 } 1365 1366 sal_Bool ExceptionType::dumpHFile(FileStream& o) 1367 throw( CannotDumpException ) 1368 { 1369 OString headerDefine(dumpHeaderDefine(o, "IDL")); 1370 o << "\n"; 1371 1372 dumpDefaultHIncludes(o); 1373 o << "\n"; 1374 dumpDepIncludes(o, m_typeName, "idl"); 1375 o << "\n"; 1376 1377 dumpNameSpace(o); 1378 1379 // write documentation 1380 OString aDoc = m_reader.getDoku(); 1381 if( aDoc.getLength() ) 1382 o << "/**\n" << aDoc << "\n*/"; 1383 1384 o << "\nexception " << m_name; 1385 o << "\n{\n"; 1386 inc(); 1387 1388 // Write extra member for derived exceptions 1389 o << indent() << "/*extra member to hold a derived exception */\n"; 1390 o << indent() << "any _derivedException;\n"; 1391 OString superType(m_reader.getSuperTypeName()); 1392 if (superType.getLength() > 0) 1393 dumpSuperMember(o, superType); 1394 1395 sal_uInt32 fieldCount = m_reader.getFieldCount(); 1396 RTFieldAccess access = RT_ACCESS_INVALID; 1397 OString fieldName; 1398 OString fieldType; 1399 sal_uInt16 i = 0; 1400 1401 for (i=0; i < fieldCount; i++) 1402 { 1403 access = m_reader.getFieldAccess(i); 1404 1405 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) 1406 continue; 1407 1408 fieldName = m_reader.getFieldName(i); 1409 fieldType = m_reader.getFieldType(i); 1410 1411 // write documentation 1412 OString aDoc = m_reader.getFieldDoku(i); 1413 if( aDoc.getLength() ) 1414 o << "/**\n" << aDoc << "\n*/"; 1415 1416 o << indent(); 1417 dumpType(o, fieldType); 1418 o << " " << fieldName << ";\n"; 1419 } 1420 1421 1422 dec(); 1423 o << "};\n\n"; 1424 1425 dumpNameSpace(o, sal_False); 1426 1427 o << "#endif /* "<< headerDefine << "*/" << "\n"; 1428 1429 return sal_True; 1430 } 1431 1432 void ExceptionType::dumpSuperMember(FileStream& o, const OString& superType) 1433 { 1434 if (superType.getLength() > 0) 1435 { 1436 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType)); 1437 1438 if (aSuperReader.isValid()) 1439 { 1440 dumpSuperMember(o, aSuperReader.getSuperTypeName()); 1441 1442 sal_uInt32 fieldCount = aSuperReader.getFieldCount(); 1443 RTFieldAccess access = RT_ACCESS_INVALID; 1444 OString fieldName; 1445 OString fieldType; 1446 for (sal_uInt16 i=0; i < fieldCount; i++) 1447 { 1448 access = aSuperReader.getFieldAccess(i); 1449 1450 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID) 1451 continue; 1452 1453 fieldName = aSuperReader.getFieldName(i); 1454 fieldType = aSuperReader.getFieldType(i); 1455 1456 // write documentation 1457 OString aDoc = aSuperReader.getFieldDoku(i); 1458 if( aDoc.getLength() ) 1459 o << "/**\n" << aDoc << "\n*/"; 1460 1461 o << indent(); 1462 dumpType(o, fieldType); 1463 o << " "; 1464 o << fieldName << ";\n"; 1465 } 1466 } 1467 } 1468 } 1469 1470 //************************************************************************* 1471 // EnumType 1472 //************************************************************************* 1473 EnumType::EnumType(TypeReader& typeReader, 1474 const OString& typeName, 1475 const TypeManager& typeMgr, 1476 const TypeDependency& typeDependencies) 1477 : IdlType(typeReader, typeName, typeMgr, typeDependencies) 1478 { 1479 } 1480 1481 EnumType::~EnumType() 1482 { 1483 1484 } 1485 1486 sal_Bool EnumType::dumpHFile(FileStream& o) 1487 throw( CannotDumpException ) 1488 { 1489 OString headerDefine(dumpHeaderDefine(o, "IDL")); 1490 o << "\n"; 1491 1492 dumpDefaultHIncludes(o); 1493 o << "\n"; 1494 1495 dumpNameSpace(o); 1496 1497 // write documentation 1498 OString aDoc = m_reader.getDoku(); 1499 if( aDoc.getLength() ) 1500 o << "/**\n" << aDoc << "\n*/"; 1501 1502 o << "\nenum " << m_name << "\n{\n"; 1503 inc(); 1504 1505 sal_uInt32 fieldCount = m_reader.getFieldCount(); 1506 RTFieldAccess access = RT_ACCESS_INVALID; 1507 RTConstValue constValue; 1508 OString fieldName; 1509 sal_uInt32 value=0; 1510 for (sal_uInt16 i=0; i < fieldCount; i++) 1511 { 1512 access = m_reader.getFieldAccess(i); 1513 1514 if (access != RT_ACCESS_CONST) 1515 continue; 1516 1517 fieldName = m_reader.getFieldName(i); 1518 constValue = m_reader.getFieldConstValue(i); 1519 1520 if (constValue.m_type == RT_TYPE_INT32) 1521 value = constValue.m_value.aLong; 1522 else 1523 value++; 1524 1525 /* doesn't work with rational rose 2000 1526 // write documentation 1527 OString aDoc = m_reader.getFieldDoku(i); 1528 if( aDoc.getLength() ) 1529 */ 1530 // o << "/**\n" << aDoc << "\n*/\n"; 1531 o << indent() << fieldName; 1532 if( i +1 < fieldCount ) 1533 o << ",\n"; 1534 } 1535 1536 dec(); 1537 o << "\n};\n\n"; 1538 1539 dumpNameSpace(o, sal_False); 1540 1541 o << "#endif /* "<< headerDefine << "*/" << "\n"; 1542 1543 return sal_True; 1544 } 1545 1546 1547 //************************************************************************* 1548 // TypeDefType 1549 //************************************************************************* 1550 TypeDefType::TypeDefType(TypeReader& typeReader, 1551 const OString& typeName, 1552 const TypeManager& typeMgr, 1553 const TypeDependency& typeDependencies) 1554 : IdlType(typeReader, typeName, typeMgr, typeDependencies) 1555 { 1556 } 1557 1558 TypeDefType::~TypeDefType() 1559 { 1560 1561 } 1562 1563 sal_Bool TypeDefType::dumpHFile(FileStream& o) 1564 throw( CannotDumpException ) 1565 { 1566 OString headerDefine(dumpHeaderDefine(o, "IDL")); 1567 o << "\n"; 1568 1569 dumpDefaultHIncludes(o); 1570 o << "\n"; 1571 dumpDepIncludes(o, m_typeName, "idl"); 1572 o << "\n"; 1573 1574 dumpNameSpace(o); 1575 1576 o << "\ntypedef "; 1577 dumpType(o, m_reader.getSuperTypeName()); 1578 o << " " << m_name << ";\n\n"; 1579 1580 dumpNameSpace(o, sal_False); 1581 1582 o << "#endif /* "<< headerDefine << "*/" << "\n"; 1583 1584 return sal_True; 1585 } 1586 1587 1588 //************************************************************************* 1589 // produceType 1590 //************************************************************************* 1591 sal_Bool produceType(const OString& typeName, 1592 TypeManager& typeMgr, 1593 TypeDependency& typeDependencies, 1594 IdlOptions* pOptions) 1595 throw( CannotDumpException ) 1596 { 1597 if (typeDependencies.isGenerated(typeName)) 1598 return sal_True; 1599 1600 TypeReader reader(typeMgr.getTypeReader(typeName)); 1601 1602 if (!reader.isValid()) 1603 { 1604 if (typeName.equals("/")) 1605 return sal_True; 1606 else 1607 return sal_False; 1608 } 1609 1610 if( !checkTypeDependencies(typeMgr, typeDependencies, typeName)) 1611 return sal_False; 1612 1613 RTTypeClass typeClass = reader.getTypeClass(); 1614 sal_Bool ret = sal_False; 1615 switch (typeClass) 1616 { 1617 case RT_TYPE_INTERFACE: 1618 { 1619 InterfaceType iType(reader, typeName, typeMgr, typeDependencies); 1620 ret = iType.dump(pOptions); 1621 if (ret) typeDependencies.setGenerated(typeName); 1622 ret = iType.dumpDependedTypes(pOptions); 1623 } 1624 break; 1625 case RT_TYPE_MODULE: 1626 { 1627 ModuleType mType(reader, typeName, typeMgr, typeDependencies); 1628 if (mType.hasConstants()) 1629 { 1630 ret = mType.dump(pOptions); 1631 if (ret) typeDependencies.setGenerated(typeName); 1632 // ret = mType.dumpDependedTypes(pOptions); 1633 } else 1634 { 1635 typeDependencies.setGenerated(typeName); 1636 ret = sal_True; 1637 } 1638 } 1639 break; 1640 case RT_TYPE_STRUCT: 1641 { 1642 StructureType sType(reader, typeName, typeMgr, typeDependencies); 1643 ret = sType.dump(pOptions); 1644 if (ret) typeDependencies.setGenerated(typeName); 1645 ret = sType.dumpDependedTypes(pOptions); 1646 } 1647 break; 1648 case RT_TYPE_ENUM: 1649 { 1650 EnumType enType(reader, typeName, typeMgr, typeDependencies); 1651 ret = enType.dump(pOptions); 1652 if (ret) typeDependencies.setGenerated(typeName); 1653 ret = enType.dumpDependedTypes(pOptions); 1654 } 1655 break; 1656 case RT_TYPE_EXCEPTION: 1657 { 1658 ExceptionType eType(reader, typeName, typeMgr, typeDependencies); 1659 ret = eType.dump(pOptions); 1660 if (ret) typeDependencies.setGenerated(typeName); 1661 ret = eType.dumpDependedTypes(pOptions); 1662 } 1663 break; 1664 case RT_TYPE_TYPEDEF: 1665 { 1666 TypeDefType tdType(reader, typeName, typeMgr, typeDependencies); 1667 ret = tdType.dump(pOptions); 1668 if (ret) typeDependencies.setGenerated(typeName); 1669 ret = tdType.dumpDependedTypes(pOptions); 1670 } 1671 break; 1672 case RT_TYPE_CONSTANTS: 1673 { 1674 ConstantsType cType(reader, typeName, typeMgr, typeDependencies); 1675 if (cType.hasConstants()) 1676 { 1677 ret = cType.dump(pOptions); 1678 if (ret) typeDependencies.setGenerated(typeName); 1679 // ret = cType.dumpDependedTypes(pOptions); 1680 } else 1681 { 1682 typeDependencies.setGenerated(typeName); 1683 ret = sal_True; 1684 } 1685 } 1686 break; 1687 case RT_TYPE_SERVICE: 1688 case RT_TYPE_OBJECT: 1689 ret = sal_True; 1690 break; 1691 } 1692 1693 return ret; 1694 } 1695 1696 //************************************************************************* 1697 // scopedName 1698 //************************************************************************* 1699 OString scopedName(const OString& scope, const OString& type, 1700 sal_Bool bNoNameSpace) 1701 { 1702 sal_Int32 nPos = type.lastIndexOf( '/' ); 1703 if (nPos == -1) 1704 return type; 1705 1706 if (bNoNameSpace) 1707 return type.copy(nPos+1); 1708 1709 OStringBuffer tmpBuf(type.getLength()*2); 1710 nPos = 0; 1711 do 1712 { 1713 tmpBuf.append("::"); 1714 tmpBuf.append(type.getToken(0, '/', nPos)); 1715 } while( nPos != -1 ); 1716 1717 return tmpBuf.makeStringAndClear(); 1718 } 1719 1720 //************************************************************************* 1721 // shortScopedName 1722 //************************************************************************* 1723 OString scope(const OString& scope, const OString& type ) 1724 { 1725 sal_Int32 nPos = type.lastIndexOf( '/' ); 1726 if( nPos == -1 ) 1727 return OString(); 1728 1729 // scoped name only if the namespace is not equal 1730 if (scope.lastIndexOf('/') > 0) 1731 { 1732 OString tmpScp(scope.copy(0, scope.lastIndexOf('/'))); 1733 OString tmpScp2(type.copy(0, nPos)); 1734 1735 if (tmpScp == tmpScp2) 1736 return OString(); 1737 } 1738 1739 OString aScope( type.copy( 0, nPos ) ); 1740 OStringBuffer tmpBuf(aScope.getLength()*2); 1741 1742 nPos = 0; 1743 do 1744 { 1745 tmpBuf.append("::"); 1746 tmpBuf.append(aScope.getToken(0, '/', nPos)); 1747 } while( nPos != -1 ); 1748 1749 return tmpBuf.makeStringAndClear(); 1750 } 1751 1752 1753