update dev300-m58
[ooovba.git] / codemaker / source / cunomaker / cunotype.cxx
blob2f5c363df5dd59de30a98f0bf0ca686b1cf1f2d6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cunotype.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_codemaker.hxx"
34 #include <stdio.h>
35 #include <rtl/alloc.h>
36 #include <rtl/ustring.hxx>
37 #include <rtl/strbuf.hxx>
39 #include "cunotype.hxx"
40 #include "cunooptions.hxx"
42 using namespace rtl;
44 //*************************************************************************
45 // CunoType
46 //*************************************************************************
47 CunoType::CunoType(TypeReader& typeReader,
48 const OString& typeName,
49 const TypeManager& typeMgr,
50 const TypeDependency& typeDependencies)
51 : m_inheritedMemberCount(0)
52 , m_cunoTypeLib(sal_False)
53 , m_cunoTypeLeak(sal_False)
54 , m_cunoTypeDynamic(sal_True)
55 , m_indentLength(0)
56 , m_typeName(typeName)
57 // , m_name(typeName.getToken(typeName.getTokenCount('/') - 1, '/'))
58 , m_name(typeName.replace('/', '_'))
59 , m_reader(typeReader)
60 , m_typeMgr((TypeManager&)typeMgr)
61 , m_dependencies(typeDependencies)
62 , m_bIsNestedType(sal_False)
64 // check if this type is nested
65 sal_Int32 i = typeName.lastIndexOf('/');
67 if (i >= 0)
69 OString outerTypeName(typeName.copy(0, i));
70 m_bIsNestedType = (m_typeMgr.getTypeClass(outerTypeName) == RT_TYPE_INTERFACE);
73 // check if this type has nested types
74 RegistryKey key = m_typeMgr.getTypeKey(typeName);
76 key.getKeyNames(OUString(), m_nestedTypeNames);
79 CunoType::~CunoType()
84 sal_Bool CunoType::isNestedTypeByName(const ::rtl::OString& type)
86 sal_Bool ret = sal_False;
88 sal_Int32 i = type.lastIndexOf('/');
90 if (i >= 0)
92 OString outerTypeName(type.copy(0, i));
93 ret = (m_typeMgr.getTypeClass(outerTypeName) == RT_TYPE_INTERFACE);
96 return ret;
99 sal_Bool CunoType::hasNestedType(const ::rtl::OString& type)
101 sal_Bool ret = sal_False;
103 if (m_nestedTypeNames.getLength() > 0)
105 OUString typeName(OStringToOUString(type, RTL_TEXTENCODING_UTF8));
107 for (sal_uInt32 i = 0; !ret && (i < m_nestedTypeNames.getLength()); i++)
108 ret = typeName.equals(m_nestedTypeNames.getElement(i).copy(5));
111 return ret;
114 sal_Bool CunoType::dump(CunoOptions* pOptions)
115 throw( CannotDumpException )
117 sal_Bool ret = sal_False;
119 if (isNestedType())
120 return sal_True;
122 if (pOptions->isValid("-U"))
123 m_cunoTypeLib = sal_True;
124 if (pOptions->isValid("-L"))
125 m_cunoTypeLeak = sal_True;
126 if (pOptions->isValid("-C"))
127 m_cunoTypeDynamic = sal_False;
129 OString outPath;
130 if (pOptions->isValid("-O"))
131 outPath = pOptions->getOption("-O");
133 OString tmpFileName;
134 OString hFileName = createFileNameFromType(outPath, m_typeName, ".h");
136 sal_Bool bFileExists = sal_False;
137 sal_Bool bFileCheck = sal_False;
139 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
141 bFileExists = fileExists( hFileName );
142 ret = sal_True;
145 if ( bFileExists && pOptions->isValid("-Gc") )
147 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmh");
148 bFileCheck = sal_True;
151 if ( !bFileExists || bFileCheck )
153 FileStream hFile;
155 if ( bFileCheck )
156 hFile.open(tmpFileName);
157 else
158 hFile.open(hFileName);
160 if(!hFile.isValid())
162 OString message("cannot open ");
163 message += hFileName + " for writing";
164 throw CannotDumpException(message);
167 ret = dumpHFile(hFile);
169 hFile.close();
170 if (ret && bFileCheck)
172 ret = checkFileContent(hFileName, tmpFileName);
176 if ( m_cunoTypeLib )
178 bFileExists = sal_False;
179 bFileCheck = sal_False;
181 if (pOptions->isValid("-OC"))
182 outPath = pOptions->getOption("-OC");
183 else
184 outPath = OString();
186 OString cFileName = createFileNameFromType(outPath, m_typeName, ".c");
188 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
190 bFileExists = fileExists( cFileName );
191 ret = sal_True;
194 if ( bFileExists && pOptions->isValid("-Gc") )
196 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmc");
197 bFileCheck = sal_True;
200 if ( !bFileExists || bFileCheck )
202 FileStream cFile;
204 if ( bFileCheck )
205 cFile.open(tmpFileName);
206 else
207 cFile.open(cFileName);
209 if(!cFile.isValid())
211 OString message("cannot open ");
212 message += cFileName + " for writing";
213 throw CannotDumpException(message);
216 ret = dumpCFile(cFile);
218 cFile.close();
219 if (ret && bFileCheck)
221 ret = checkFileContent(cFileName, tmpFileName);
225 return ret;
227 sal_Bool CunoType::dumpDependedTypes(CunoOptions* pOptions)
228 throw( CannotDumpException )
230 sal_Bool ret = sal_True;
232 TypeUsingSet usingSet(m_dependencies.getDependencies(m_typeName));
234 TypeUsingSet::const_iterator iter = usingSet.begin();
235 OString typeName;
236 sal_uInt32 index = 0;
237 while (iter != usingSet.end())
239 typeName = (*iter).m_type;
240 if ((index = typeName.lastIndexOf(']')) > 0)
241 typeName = typeName.copy(index + 1);
243 if (getBaseType(typeName).getLength() == 0)
245 if (!produceType(typeName,
246 m_typeMgr,
247 m_dependencies,
248 pOptions))
250 fprintf(stderr, "%s ERROR: %s\n",
251 pOptions->getProgramName().getStr(),
252 OString("cannot dump Type '" + typeName + "'").getStr());
253 exit(99);
256 ++iter;
259 return ret;
262 OString CunoType::dumpHeaderDefine(FileStream& o, sal_Char* prefix, sal_Bool bExtended)
264 if (m_typeName.equals("/"))
266 bExtended = sal_False;
267 m_typeName = "global";
270 sal_uInt32 length = 3 + m_typeName.getLength() + strlen(prefix);
272 if (bExtended)
273 length += m_name.getLength() + 1;
275 OStringBuffer tmpBuf(length);
277 tmpBuf.append('_');
278 tmpBuf.append(m_typeName);
279 tmpBuf.append('_');
280 if (bExtended)
282 tmpBuf.append(m_name);
283 tmpBuf.append('_');
285 tmpBuf.append(prefix);
286 tmpBuf.append('_');
288 OString tmp(tmpBuf.makeStringAndClear().replace('/', '_').toAsciiUpperCase());
290 o << "#ifndef " << tmp << "\n#define " << tmp << "\n";
292 return tmp;
295 void CunoType::dumpDefaultHIncludes(FileStream& o)
297 o << "#ifndef _UNO_CUNO_H_\n"
298 << "#include <uno/cuno.h>\n"
299 << "#endif\n";
301 if (m_typeMgr.getTypeClass(m_typeName) == RT_TYPE_INTERFACE &&
302 !m_typeName.equals("com/sun/star/uno/XInterface") )
304 o << "#ifndef _COM_SUN_STAR_UNO_XINTERFACE_H_\n"
305 << "#include <com/sun/star/uno/XInterface.h>\n"
306 << "#endif\n";
311 void CunoType::dumpDefaultCIncludes(FileStream& o)
313 o << "#ifndef _OSL_MUTEX_H_\n"
314 << "#include <osl/mutex.h>\n"
315 << "#endif\n\n";
318 void CunoType::dumpInclude(FileStream& o, const OString& typeName, sal_Char* prefix, sal_Bool bExtended, sal_Bool bCaseSensitive)
320 sal_uInt32 length = 3+ m_typeName.getLength() + strlen(prefix);
322 if (bExtended)
323 length += m_name.getLength() + 1;
325 OStringBuffer tmpBuf(length);
327 tmpBuf.append('_');
328 tmpBuf.append(typeName);
329 tmpBuf.append('_');
330 if (bExtended)
332 tmpBuf.append(m_name);
333 tmpBuf.append('_');
335 tmpBuf.append(prefix);
336 tmpBuf.append('_');
338 OString tmp(tmpBuf.makeStringAndClear().replace('/', '_').toAsciiUpperCase());
340 length = 1 + typeName.getLength() + strlen(prefix);
341 if (bExtended)
342 length += m_name.getLength() + 1;
344 tmpBuf.ensureCapacity(length);
345 tmpBuf.append(typeName);
346 if (bExtended)
348 tmpBuf.append('/');
349 tmpBuf.append(m_name);
351 tmpBuf.append('.');
352 tmpBuf.append(prefix);
354 o << "#ifndef " << tmp << "\n#include <";
355 if (bCaseSensitive)
357 o << tmpBuf.makeStringAndClear();
358 } else
360 o << tmpBuf.makeStringAndClear();
362 o << ">\n#endif\n";
365 void CunoType::dumpDepIncludes(FileStream& o, const OString& typeName, sal_Char* prefix)
367 TypeUsingSet usingSet(m_dependencies.getDependencies(typeName));
369 TypeUsingSet::const_iterator iter = usingSet.begin();
371 OString sPrefix(OString(prefix).toAsciiUpperCase());
372 sal_Bool bSequenceDumped = sal_False;
373 sal_uInt32 index = 0;
374 sal_uInt32 seqNum = 0;
375 OString relType;
376 while (iter != usingSet.end())
378 sal_Bool bDumpThisType = sal_True;
379 index = (*iter).m_type.lastIndexOf(']');
380 seqNum = (index > 0 ? ((index+1) / 2) : 0);
382 relType = (*iter).m_type;
383 if (index > 0)
384 relType = relType.copy(index+1);
386 if (isNestedTypeByName(relType) && hasNestedType(relType))
387 bDumpThisType = sal_False;
389 if (bDumpThisType)
391 OString defPrefix("H");
392 if (sPrefix.equals("H"))
393 defPrefix = "H";
395 if (seqNum > 0 && !bSequenceDumped)
397 bSequenceDumped = sal_True;
398 o << "#ifndef _UNO_SEQUENCE2_" << defPrefix
399 << "_\n#include <uno/sequence2." << defPrefix.toAsciiLowerCase()
400 << ">\n#endif\n";
403 if (getBaseType(relType).getLength() == 0 &&
404 m_typeName != relType)
406 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE
407 && sPrefix.equals("H"))
409 if (!((*iter).m_use & TYPEUSE_SUPER))
411 if (isNestedTypeByName(relType))
413 sal_Int32 iLastS = relType.lastIndexOf('/');
415 OString outerNamespace(relType.copy(0,iLastS));
416 OString innerClass(relType.copy(iLastS+1));
418 iLastS = outerNamespace.lastIndexOf('/');
419 OString outerClass(outerNamespace.copy(iLastS+1));
421 // o << "\n";
422 // dumpNameSpace(o, sal_True, sal_False, outerNamespace);
423 // o << "\nclass " << outerClass << "::" << innerClass << ";\n";
424 // dumpNameSpace(o, sal_False, sal_False, outerNamespace);
425 // o << "\n\n";
427 else
429 // dumpInclude(o, relType, prefix);
430 OString type(relType.replace('/', '_'));
431 o << "\n#ifndef " << type.toAsciiUpperCase() << "\n";
432 o << "#define " << type.toAsciiUpperCase() << "\n";
433 o << "struct _" << type << ";\n"
434 << "typedef struct _" << type << "_ftab * " << type << ";\n";
435 o << "#endif\n\n";
437 } else
439 if (isNestedTypeByName(relType))
441 sal_Int32 iLastS = relType.lastIndexOf('/');
443 OString outerNamespace(relType.copy(0,iLastS));
445 dumpInclude(o, outerNamespace, prefix);
447 else
448 dumpInclude(o, relType, prefix);
450 } else
452 if (isNestedTypeByName(relType))
454 sal_Int32 iLastS = relType.lastIndexOf('/');
456 OString outerNamespace(relType.copy(0,iLastS));
458 dumpInclude(o, outerNamespace, prefix);
460 else
461 dumpInclude(o, relType, prefix);
463 } else
464 if (relType == "any")
466 o << "#ifndef _UNO_ANY2_H_\n"
467 << "#include <uno/any2.h>\n"
468 << "#endif\n";
469 } else
470 if (relType == "type")
472 o << "#ifndef _TYPELIB_TYPEDESCRIPTION_H_\n"
473 << "#include <typelib/typedescription.h>\n"
474 << "#endif\n";
475 } else
476 if (relType == "string" && sPrefix.equals("H"))
478 o << "#ifndef _RTL_USTRING_H_\n"
479 << "#include <rtl/ustring.h>\n"
480 << "#endif\n";
483 ++iter;
485 if (m_typeName.equals(typeName) && (getNestedTypeNames().getLength() > 0))
487 o << "// includes for nested types\n\n";
489 for (sal_uInt32 i = 0; i < getNestedTypeNames().getLength(); i++)
491 OUString s(getNestedTypeNames().getElement(i));
493 OString nestedName(s.getStr(), s.getLength(), RTL_TEXTENCODING_UTF8);
495 dumpDepIncludes(o, nestedName, prefix);
500 void CunoType::dumpOpenExternC(FileStream& o)
502 o << "#ifdef __cplusplus\n"
503 << "extern \"C\" {\n"
504 << "#endif\n\n";
507 void CunoType::dumpCloseExternC(FileStream& o)
509 o << "#ifdef __cplusplus\n"
510 << "}\n"
511 << "#endif\n\n";
514 void CunoType::dumpLGetCunoType(FileStream& o)
516 OString typeName(m_typeName.replace('/', '_'));
518 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
519 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
520 << "#endif\n\n";
522 if (m_reader.getTypeClass() == RT_TYPE_TYPEDEF)
524 o << "inline const ::com::sun::star::uno::Type& SAL_CALL get_" << typeName << "_Type( ) SAL_THROW( () )\n{\n";
525 } else
527 o << "inline const ::com::sun::star::uno::Type& SAL_CALL getCunoType( ";
528 dumpType(o, m_typeName, sal_True, sal_False);
529 o << "* ) SAL_THROW( () )\n{\n";
531 inc();
533 o << indent() << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
534 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
535 << indent() << "#endif\n\n";
537 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
538 inc();
539 o << indent() << "typelib_static_type_init( &s_pType_" << typeName << ", "
540 << getTypeClass(m_typeName, sal_True) << ", \"" << m_typeName.replace('/', '.') << "\" );\n";
541 dec();
542 o << indent() << "}\n";
543 o << indent() << "return * reinterpret_cast< ::com::sun::star::uno::Type * >( &s_pType_"
544 << typeName <<" );\n";
545 dec();
546 o << indent() << "}\n";
548 return;
551 void CunoType::dumpGetCunoType(FileStream& o)
553 OString typeName(m_typeName.replace('/', '_'));
555 if ( m_cunoTypeLeak )
557 dumpLGetCunoType(o);
558 return;
560 if ( !m_cunoTypeDynamic )
562 dumpCGetCunoType(o);
563 return;
566 dumpOpenExternC(o);
568 if ( !m_typeName.equals("com/sun/star/uno/Exception") )
570 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
571 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
572 << "#endif\n\n";
575 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
576 inc();
578 if ( m_typeName.equals("com/sun/star/uno/Exception") )
580 o << indent() << "return typelib_static_type_getByTypeClass( typelib_TypeClass_EXCEPTION );\n";
581 } else
583 o << indent() << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
584 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
585 << indent() << "#endif\n\n";
587 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
588 inc();
590 OString superType(m_reader.getSuperTypeName());
591 sal_Bool bIsBaseException = sal_False;
592 if (superType.getLength() > 0)
594 if ( superType.equals("com/sun/star/uno/Exception") )
596 bIsBaseException = sal_True;
597 } else
599 o << indent() << "typelib_TypeDescriptionReference * pBaseType = 0;\n";
603 sal_uInt32 count = getMemberCount();
604 if (count)
606 o << indent() << "typelib_TypeDescriptionReference * aMemberRefs[" << count << "];\n";
609 if ( !bIsBaseException )
611 o << indent() << "typelib_typedescriptionreference_newByAsciiName(&pBaseType, typelib_TypeClass_INTERFACE, \""
612 << superType.replace('/', '.') << "\" );\n";
615 if (count)
617 sal_uInt32 fieldCount = m_reader.getFieldCount();
618 RTFieldAccess access = RT_ACCESS_INVALID;
619 OString fieldType, fieldName;
620 OString scope = m_typeName.replace('/', '.');
621 sal_Bool bWithScope = sal_True;
622 OString modFieldType;
623 StringSet generatedTypeSet;
624 StringSet::iterator findIter;
626 for (sal_uInt16 i=0; i < fieldCount; i++)
628 access = m_reader.getFieldAccess(i);
630 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
631 continue;
633 fieldName = m_reader.getFieldName(i);
634 fieldType = checkRealBaseType(m_reader.getFieldType(i), sal_True);
636 // modFieldType = typeToIdentifier(fieldType);
638 findIter = generatedTypeSet.find(fieldType);
639 if ( findIter == generatedTypeSet.end() )
641 generatedTypeSet.insert(fieldType);
642 o << indent() << "typelib_typedescriptionreference_newByAsciiName(&aMemberRefs["
643 << i << "], " << getTypeClass(fieldType, sal_True);
644 o << " , \"" << fieldType.replace('/', '.') << "\" );\n";
647 o << "\n";
650 o << indent() << "typelib_static_compound_type_init( &s_pType_" << typeName << ", "
651 << getTypeClass(m_typeName, sal_True) << ", \"" << m_typeName.replace('/', '.') << "\", ";
652 if ( superType.getLength() > 0 || bIsBaseException )
654 if ( bIsBaseException )
656 o << "* typelib_static_type_getByTypeClass( typelib_TypeClass_EXCEPTION ), "
657 << count << ", ";
658 } else
660 o << "pBaseType, " << count << ", ";
662 } else
664 o << "0, " << count << ", ";
667 if (count)
669 o << " aMemberRefs );\n";
670 } else
672 o << " 0 );\n";
674 dec();
675 o << indent() << "}\n"
676 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName << " );\n"
677 << indent() << "return &_pType_" << typeName <<" );\n";
679 dec();
680 o << indent() << "}\n";
682 dumpCloseExternC(o);
685 void CunoType::dumpCGetCunoType(FileStream& o)
687 OString typeName(m_typeName.replace('/', '_'));
689 dumpOpenExternC(o);
691 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
692 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
693 << "#endif\n\n";
695 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
696 inc();
698 o << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
699 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
700 << "#endif\n\n";
702 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
703 inc();
704 o << indent() << "oslMutex * pMutex = osl_getGlobalMutex();\n"
705 << indent() << "osl_acquireMutex( pMutex );\n";
707 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
708 inc();
709 o << indent() << "rtl_uString * pTypeName = 0;\n"
710 << indent() << "typelib_TypeDescription * pTD = 0;\n";
712 OString superType(m_reader.getSuperTypeName());
713 if (superType.getLength() > 0)
714 o << indent() << "typelib_TypeDescriptionReference * pSuperType = 0;\n";
716 sal_uInt32 count = getMemberCount();
717 sal_uInt32 fieldCount = m_reader.getFieldCount();
718 RTFieldAccess access = RT_ACCESS_INVALID;
719 if (count)
721 o << indent() << "typelib_CompoundMember_Init aMembers["
722 << count << "];\n";
724 for (sal_uInt16 i=0; i < fieldCount; i++)
726 access = m_reader.getFieldAccess(i);
728 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
729 continue;
731 o << indent() << "rtl_uString * pMemberName" << i << " = 0;\n"
732 << indent() << "rtl_uString * pMemberType" << i << " = 0;\n";
736 o << indent() << "rtl_uString_newFromAscii( &pTypeName, \"" << m_typeName.replace('/', '.') << "\" );\n";
738 if (superType.getLength() > 0)
740 o << indent() << "typelib_typedescriptionreference_newByAsciiName(&pSuperType, typelib_TypeClass_INTERFACE, \""
741 << superType.replace('/', '.') << "\" );\n";
744 dumpCppuGetTypeMemberDecl(o, CUNOTYPEDECL_ALLTYPES);
746 if (count)
748 OString fieldType, fieldName;
749 OString scope = m_typeName.replace('/', '.');
751 for (sal_uInt16 i=0; i < fieldCount; i++)
753 access = m_reader.getFieldAccess(i);
755 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
756 continue;
758 fieldName = m_reader.getFieldName(i);
759 fieldType = checkRealBaseType(m_reader.getFieldType(i), sal_True);
761 o << indent() << "rtl_uString_newFromAscii( &pMemberType" << i << ", \""
762 << fieldType.replace('/', '.') << "\") );\n";
763 o << indent() << "rtl_uString_newFromAscii( &pMemberName" << i << ", \"";
764 o << fieldName << "\") );\n";
765 o << indent() << "aMembers[" << i << "].eTypeClass = "
766 << getTypeClass(fieldType, sal_True) << ";\n"
767 << indent() << "aMembers[" << i << "].pTypeName = pMemberType" << i << ";\n"
768 << indent() << "aMembers[" << i << "].pMemberName = pMemberName" << i << ";\n";
771 o << "\n" << indent() << "typelib_typedescription_new(\n";
772 inc();
773 o << indent() << "&pTD,\n" << indent()
774 << getTypeClass(OString(), sal_True) << ", pTypeName,\n";
776 if (superType.getLength() > 0)
777 o << indent() << "pSuperType,\n";
778 else
779 o << indent() << "0,\n";
781 if ( count )
783 o << indent() << count << ",\n" << indent() << "aMembers );\n\n";
784 } else
786 o << indent() << count << ",\n" << indent() << "0 );\n\n";
789 dec();
790 o << indent() << "typelib_typedescription_register( &pTD );\n\n";
792 o << indent() << "typelib_typedescriptionreference_new( &s_pType_ " << typeName
793 << getTypeClass(OString(), sal_True) << ", pTD);\n\n";
795 o << indent() << "typelib_typedescription_release( pTD );\n"
796 << indent() << "typelib_typedescriptionreference_release( pSuperType );\n"
797 << indent() << "rtl_uString_release( pTypeName );\n";
799 for (i=0; i < fieldCount; i++)
801 access = m_reader.getFieldAccess(i);
803 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
804 continue;
806 o << indent() << "rtl_uString_release( pMemberName" << i << " );\n"
807 << indent() << "rtl_uString_release( pMemberType" << i << " );\n";
811 dec();
812 o << indent() << "}\n";
813 o << indent() << "osl_releaseMutex( pMutex );\n";
814 dec();
815 o << indent() << "}\n"
816 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName << " );\n"
817 << indent() << "return &s_pType_" << typeName <<" );\n";
818 dec();
819 o << "}\n";
821 dumpCloseExternC(o);
824 void CunoType::dumpCppuGetTypeMemberDecl(FileStream& o, CunoTypeDecl eDeclFlag)
826 sal_uInt32 fieldCount = m_reader.getFieldCount();
827 RTFieldAccess access = RT_ACCESS_INVALID;
829 if ( fieldCount )
831 o << indent() << "{\n" << indent() << "typelib_TypeDescriptionReference ** ppTypeRef = 0;\n";
833 StringSet aFinishedTypes;
834 for (sal_uInt16 i=0; i < fieldCount; i++)
836 access = m_reader.getFieldAccess(i);
838 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
839 continue;
841 if (aFinishedTypes.count(m_reader.getFieldType(i)) == 0)
843 aFinishedTypes.insert(m_reader.getFieldType(i));
844 dumpCppuGetType(o, m_reader.getFieldType(i), sal_True, eDeclFlag);
847 o << indent() << "}\n";
851 sal_uInt32 CunoType::getMemberCount()
853 sal_uInt32 count = m_reader.getMethodCount();
855 sal_uInt32 fieldCount = m_reader.getFieldCount();
856 RTFieldAccess access = RT_ACCESS_INVALID;
857 for (sal_uInt16 i=0; i < fieldCount; i++)
859 access = m_reader.getFieldAccess(i);
861 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
862 count++;
864 return count;
867 sal_uInt32 CunoType::checkInheritedMemberCount(const TypeReader* pReader)
869 sal_Bool bSelfCheck = sal_True;
870 if (!pReader)
872 bSelfCheck = sal_False;
873 pReader = &m_reader;
876 sal_uInt32 count = 0;
877 OString superType(pReader->getSuperTypeName());
878 if (superType.getLength() > 0)
880 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
881 if ( aSuperReader.isValid() )
883 count = checkInheritedMemberCount(&aSuperReader);
887 if (bSelfCheck)
889 count += pReader->getMethodCount();
890 sal_uInt32 fieldCount = pReader->getFieldCount();
891 RTFieldAccess access = RT_ACCESS_INVALID;
892 for (sal_uInt16 i=0; i < fieldCount; i++)
894 access = pReader->getFieldAccess(i);
896 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
898 count++;
903 return count;
906 sal_uInt32 CunoType::getInheritedMemberCount()
908 if (m_inheritedMemberCount == 0)
910 m_inheritedMemberCount = checkInheritedMemberCount(0);
913 return m_inheritedMemberCount;
916 void CunoType::dumpInheritedMembers(FileStream& o, rtl::OString& superType)
918 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
920 OString baseType(aSuperReader.getSuperTypeName());
921 if (baseType.getLength() > 0)
923 dumpInheritedMembers(o, baseType);
926 sal_uInt32 fieldCount = aSuperReader.getFieldCount();
927 RTFieldAccess access = RT_ACCESS_INVALID;
928 OString fieldName;
929 OString fieldType;
930 for (sal_uInt16 i=0; i < fieldCount; i++)
932 access = aSuperReader.getFieldAccess(i);
934 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
936 fieldName = aSuperReader.getFieldName(i);
937 fieldType = aSuperReader.getFieldType(i);
939 o << indent();
940 dumpType(o, fieldType);
941 o << " " << fieldName << ";\n";
946 OString CunoType::getTypeClass(const OString& type, sal_Bool bCStyle)
948 OString typeName = (type.getLength() > 0 ? type : m_typeName);
949 RTTypeClass rtTypeClass = RT_TYPE_INVALID;
951 if (type.getLength() > 0)
953 typeName = type;
954 rtTypeClass = m_typeMgr.getTypeClass(typeName);
955 } else
957 typeName = m_typeName;
958 rtTypeClass = m_reader.getTypeClass();
961 if (typeName.lastIndexOf(']') > 0)
962 return bCStyle ? "typelib_TypeClass_SEQUENCE" : "::com::sun::star::uno::TypeClass_SEQUENCE";
964 switch (rtTypeClass)
966 case RT_TYPE_INTERFACE:
967 return bCStyle ? "typelib_TypeClass_INTERFACE" : "::com::sun::star::uno::TypeClass_INTERFACE";
968 break;
969 case RT_TYPE_MODULE:
970 return bCStyle ? "typelib_TypeClass_MODULE" : "::com::sun::star::uno::TypeClass_MODULE";
971 break;
972 case RT_TYPE_STRUCT:
973 return bCStyle ? "typelib_TypeClass_STRUCT" : "::com::sun::star::uno::TypeClass_STRUCT";
974 break;
975 case RT_TYPE_ENUM:
976 return bCStyle ? "typelib_TypeClass_ENUM" : "::com::sun::star::uno::TypeClass_ENUM";
977 break;
978 case RT_TYPE_EXCEPTION:
979 return bCStyle ? "typelib_TypeClass_EXCEPTION" : "::com::sun::star::uno::TypeClass_EXCEPTION";
980 break;
981 case RT_TYPE_TYPEDEF:
983 OString realType = checkRealBaseType( typeName );
984 return getTypeClass( realType, bCStyle );
986 // return bCStyle ? "typelib_TypeClass_TYPEDEF" : "::com::sun::star::uno::TypeClass_TYPEDEF";
987 break;
988 case RT_TYPE_SERVICE:
989 return bCStyle ? "typelib_TypeClass_SERVICE" : "::com::sun::star::uno::TypeClass_SERVICE";
990 break;
991 case RT_TYPE_INVALID:
993 if (type.equals("long"))
994 return bCStyle ? "typelib_TypeClass_LONG" : "::com::sun::star::uno::TypeClass_LONG";
995 if (type.equals("short"))
996 return bCStyle ? "typelib_TypeClass_SHORT" : "::com::sun::star::uno::TypeClass_SHORT";
997 if (type.equals("hyper"))
998 return bCStyle ? "typelib_TypeClass_HYPER" : "::com::sun::star::uno::TypeClass_HYPER";
999 if (type.equals("string"))
1000 return bCStyle ? "typelib_TypeClass_STRING" : "::com::sun::star::uno::TypeClass_STRING";
1001 if (type.equals("boolean"))
1002 return bCStyle ? "typelib_TypeClass_BOOLEAN" : "::com::sun::star::uno::TypeClass_BOOLEAN";
1003 if (type.equals("char"))
1004 return bCStyle ? "typelib_TypeClass_CHAR" : "::com::sun::star::uno::TypeClass_CHAR";
1005 if (type.equals("byte"))
1006 return bCStyle ? "typelib_TypeClass_BYTE" : "::com::sun::star::uno::TypeClass_BYTE";
1007 if (type.equals("any"))
1008 return bCStyle ? "typelib_TypeClass_ANY" : "::com::sun::star::uno::TypeClass_ANY";
1009 if (type.equals("type"))
1010 return bCStyle ? "typelib_TypeClass_TYPE" : "::com::sun::star::uno::TypeClass_TYPE";
1011 if (type.equals("float"))
1012 return bCStyle ? "typelib_TypeClass_FLOAT" : "::com::sun::star::uno::TypeClass_FLOAT";
1013 if (type.equals("double"))
1014 return bCStyle ? "typelib_TypeClass_DOUBLE" : "::com::sun::star::uno::TypeClass_DOUBLE";
1015 if (type.equals("void"))
1016 return bCStyle ? "typelib_TypeClass_VOID" : "::com::sun::star::uno::TypeClass_VOID";
1017 if (type.equals("unsigned long"))
1018 return bCStyle ? "typelib_TypeClass_UNSIGNED_LONG" : "::com::sun::star::uno::TypeClass_UNSIGNED_LONG";
1019 if (type.equals("unsigned short"))
1020 return bCStyle ? "typelib_TypeClass_UNSIGNED_SHORT" : "::com::sun::star::uno::TypeClass_UNSIGNED_SHORT";
1021 if (type.equals("unsigned hyper"))
1022 return bCStyle ? "typelib_TypeClass_UNSIGNED_HYPER" : "::com::sun::star::uno::TypeClass_UNSIGNED_HYPER";
1024 break;
1027 return bCStyle ? "typelib_TypeClass_UNKNOWN" : "::com::sun::star::uno::TypeClass_UNKNOWN";
1030 void CunoType::dumpType(FileStream& o, const OString& type,
1031 sal_Bool bConst, sal_Bool bPointer, sal_Bool bParam)
1032 throw( CannotDumpException )
1034 OString sType(checkRealBaseType(type, sal_True));
1035 sal_uInt32 index = sType.lastIndexOf(']');
1036 sal_uInt32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
1038 OString relType = (index > 0 ? (sType).copy(index+1) : type);
1040 RTTypeClass typeClass = m_typeMgr.getTypeClass(relType);
1042 // if (bConst) o << "const ";
1044 if ( seqNum )
1046 o << "/*";
1047 sal_uInt32 i;
1048 for (i=0; i < seqNum; i++)
1050 o << "sequence< ";
1052 o << relType.replace( '/', '.');
1053 for (i=0; i < seqNum; i++)
1055 o << " >";
1057 o << "*/ uno_Sequence *";
1058 if (bPointer) o << "*";
1059 return;
1061 switch (typeClass)
1063 case RT_TYPE_INTERFACE:
1064 o << relType.replace('/', '_') << " *";
1065 break;
1066 case RT_TYPE_INVALID:
1068 OString tmp(getBaseType(relType));
1069 if (tmp.getLength() > 0)
1071 o << tmp.getStr();
1072 if ( bParam && !bPointer && relType.equals("any") )
1073 o << " *";
1074 } else
1075 throw CannotDumpException("Unknown type '" + relType + "', incomplete type library.");
1077 break;
1078 case RT_TYPE_STRUCT:
1079 case RT_TYPE_EXCEPTION:
1080 o << relType.replace('/', '_');
1081 if ( bParam && !bPointer ) o << " *";
1082 break;
1083 case RT_TYPE_ENUM:
1084 case RT_TYPE_TYPEDEF:
1085 o << relType.replace('/', '_');
1086 break;
1089 if (bPointer) o << "*";
1092 OString CunoType::getBaseType(const OString& type)
1094 if (type.equals("long"))
1095 return "sal_Int32";
1096 if (type.equals("short"))
1097 return "sal_Int16";
1098 if (type.equals("hyper"))
1099 return "sal_Int64";
1100 if (type.equals("string"))
1101 return "rtl_uString *";
1102 if (type.equals("boolean"))
1103 return "sal_Bool";
1104 if (type.equals("char"))
1105 return "sal_Unicode";
1106 if (type.equals("byte"))
1107 return "sal_Int8";
1108 if (type.equals("any"))
1109 return "uno_Any";
1110 if (type.equals("type"))
1111 return "typelib_TypeDescriptionReference *";
1112 if (type.equals("float"))
1113 return "float";
1114 if (type.equals("double"))
1115 return "double";
1116 if (type.equals("octet"))
1117 return "sal_Int8";
1118 if (type.equals("void"))
1119 return type;
1120 if (type.equals("unsigned long"))
1121 return "sal_uInt32";
1122 if (type.equals("unsigned short"))
1123 return "sal_uInt16";
1124 if (type.equals("unsigned hyper"))
1125 return "sal_uInt64";
1127 return OString();
1130 void CunoType::dumpCppuGetType(FileStream& o, const OString& type, sal_Bool bDecl, CunoTypeDecl eDeclFlag)
1132 OString sType( checkRealBaseType(type, sal_True) );
1133 sal_uInt32 index = sType.lastIndexOf(']');
1134 OString relType = (index > 0 ? (sType).copy(index+1) : type);
1136 if (eDeclFlag == CUNOTYPEDECL_ONLYINTERFACES)
1138 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE)
1140 if (bDecl)
1141 o << indent() << "ppTypeRef = ";
1142 else
1143 o << indent();
1145 o << "getCUnoType_" << type.replace('/', '_') << "()";
1147 if (bDecl)
1148 o << ";\n" << indent() << "typelib_typedescriptionreference_release( *ppTypeRef );\n";
1150 } else
1152 if (isBaseType(type))
1154 return;
1155 } else
1157 if (eDeclFlag == CUNOTYPEDECL_NOINTERFACES &&
1158 m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE)
1159 return;
1161 if ( type.equals("type") )
1162 return;
1164 if (bDecl)
1165 o << indent() << "ppTypeRef = ";
1166 else
1167 o << indent();
1169 o << indent() << "getCUnoType_" << type.replace('/', '_') << "()";
1171 if (bDecl)
1172 o << ";\n" << indent() << "typelib_typedescriptionreference_release( *ppTypeRef );\n";
1176 void CunoType::dumpTypeInit(FileStream& o, const OString& typeName)
1178 OString type(checkSpecialCunoType(typeName));
1180 BASETYPE baseType = isBaseType(type);
1182 switch (baseType)
1184 case BT_BOOLEAN:
1185 o << "(sal_False)";
1186 return;
1187 break;
1188 case BT_ANY:
1189 case BT_STRING:
1190 o << "()";
1191 return;
1192 break;
1193 case BT_INVALID:
1194 break;
1195 default:
1196 o << "((";
1197 dumpType(o, type);
1198 o << ")" << "0)";
1199 return;
1202 RTTypeClass typeClass = m_typeMgr.getTypeClass(type);
1204 if (typeClass == RT_TYPE_ENUM)
1206 RegistryTypeReaderLoader aReaderLoader;
1208 if (aReaderLoader.isLoaded())
1210 TypeReader reader(m_typeMgr.getTypeReader(type));
1212 if ( reader.isValid() )
1214 sal_Int32 i = type.lastIndexOf('/');
1215 o << "(" << shortScopedName("", type, sal_False)
1216 << "::" << type.copy( i != -1 ? i+1 :0 )
1217 << "_" << reader.getFieldName(0) << ")";
1218 return;
1223 o << "()";
1226 BASETYPE CunoType::isBaseType(const OString& type)
1228 if (type.equals("long"))
1229 return BT_LONG;
1230 if (type.equals("short"))
1231 return BT_SHORT;
1232 if (type.equals("hyper"))
1233 return BT_HYPER;
1234 if (type.equals("string"))
1235 return BT_STRING;
1236 if (type.equals("boolean"))
1237 return BT_BOOLEAN;
1238 if (type.equals("char"))
1239 return BT_CHAR;
1240 if (type.equals("byte"))
1241 return BT_BYTE;
1242 if (type.equals("any"))
1243 return BT_ANY;
1244 if (type.equals("float"))
1245 return BT_FLOAT;
1246 if (type.equals("double"))
1247 return BT_DOUBLE;
1248 if (type.equals("void"))
1249 return BT_VOID;
1250 if (type.equals("unsigned long"))
1251 return BT_UNSIGNED_LONG;
1252 if (type.equals("unsigned short"))
1253 return BT_UNSIGNED_SHORT;
1254 if (type.equals("unsigned hyper"))
1255 return BT_UNSIGNED_HYPER;
1257 return BT_INVALID;
1260 OString CunoType::typeToIdentifier(const OString& type)
1262 sal_uInt32 index = type.lastIndexOf(']');
1263 sal_uInt32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
1265 OString relType = (index > 0 ? ((OString)type).copy(index+1) : type);
1266 OString sIdentifier;
1268 while( seqNum > 0 )
1270 sIdentifier += OString("seq");
1272 if ( --seqNum == 0 )
1274 sIdentifier += OString("_");
1278 if ( isBaseType(relType) )
1280 sIdentifier += relType.replace(' ', '_');
1281 } else
1283 sIdentifier += relType.replace('/', '_');
1287 return sIdentifier;
1290 OString CunoType::checkSpecialCunoType(const OString& type)
1292 OString baseType(type);
1294 RegistryTypeReaderLoader & rReaderLoader = getRegistryTypeReaderLoader();
1296 RegistryKey key;
1297 sal_uInt8* pBuffer=NULL;
1298 RTTypeClass typeClass;
1299 sal_Bool isTypeDef = (m_typeMgr.getTypeClass(baseType) == RT_TYPE_TYPEDEF);
1300 TypeReader reader;
1302 while (isTypeDef)
1304 reader = m_typeMgr.getTypeReader(baseType);
1306 if (reader.isValid())
1308 typeClass = reader.getTypeClass();
1310 if (typeClass == RT_TYPE_TYPEDEF)
1311 baseType = reader.getSuperTypeName();
1312 else
1313 isTypeDef = sal_False;
1314 } else
1316 break;
1320 return baseType;
1323 sal_Bool CunoType::isSeqType(const OString& type, OString& baseType, OString& seqPrefix)
1325 if ( type.getStr()[0] == '[' )
1327 sal_uInt32 index = type.lastIndexOf(']');
1328 baseType = ((OString)type).copy(index+1);
1329 seqPrefix = ((OString)type).copy(0, index+1);
1330 return sal_True;
1331 } else
1333 baseType = type;
1334 seqPrefix = OString();
1336 return sal_False;
1339 sal_Bool CunoType::isArrayType(const OString& type, OString& baseType, OString& arrayPrefix)
1341 if ( type.getStr()[type.getLength()-1] == ']' )
1343 sal_uInt32 index = type.indexOf('[');
1344 baseType = ((OString)type).copy(0, index-1);
1345 arrayPrefix = ((OString)type).copy(index);
1346 return sal_True;
1347 } else
1349 baseType = type;
1350 arrayPrefix = OString();
1352 return sal_False;
1355 OString CunoType::checkRealBaseType(const OString& type, sal_Bool bResolveTypeOnly)
1357 OString realType;
1358 OString baseType;
1359 OString completePrefix;
1360 OString prefix;
1361 sal_Bool bSeqType = sal_True;
1363 if ( !isSeqType(type, baseType, completePrefix) )
1364 isArrayType(type, baseType, completePrefix);
1366 RegistryTypeReaderLoader & rReaderLoader = getRegistryTypeReaderLoader();
1368 RegistryKey key;
1369 sal_uInt8* pBuffer=NULL;
1370 RTTypeClass typeClass;
1371 sal_Bool mustBeChecked = (m_typeMgr.getTypeClass(baseType) == RT_TYPE_TYPEDEF);
1372 TypeReader reader;
1373 while (mustBeChecked)
1375 reader = m_typeMgr.getTypeReader(baseType);
1377 if (reader.isValid())
1379 typeClass = reader.getTypeClass();
1381 if (typeClass == RT_TYPE_TYPEDEF)
1383 realType = reader.getSuperTypeName();
1384 if ( isSeqType(realType, baseType, prefix) ||
1385 isArrayType(realType, baseType, prefix) )
1387 completePrefix += prefix;
1389 } else
1390 mustBeChecked = sal_False;
1391 } else
1393 break;
1397 if ( bResolveTypeOnly )
1399 if ( completePrefix.getLength() > 0 )
1401 baseType = bSeqType ? (completePrefix + baseType) : ( baseType + completePrefix);
1404 return baseType;
1407 void CunoType::dumpConstantValue(FileStream& o, sal_uInt16 index)
1409 RTConstValue constValue = m_reader.getFieldConstValue(index);
1411 switch (constValue.m_type)
1413 case RT_TYPE_BOOL:
1414 if (constValue.m_value.aBool)
1415 o << "sal_True";
1416 else
1417 o << "sal_False";
1418 break;
1419 case RT_TYPE_BYTE:
1421 char tmp[16];
1422 snprintf(tmp, sizeof(tmp), "0x%x", (sal_Int8)constValue.m_value.aByte);
1423 o << "(sal_Int8)" << tmp;
1425 break;
1426 case RT_TYPE_INT16:
1427 o << "(sal_Int16)" << constValue.m_value.aShort;
1428 break;
1429 case RT_TYPE_UINT16:
1430 o << "(sal_uInt16)" << constValue.m_value.aUShort;
1431 break;
1432 case RT_TYPE_INT32:
1433 o << "(sal_Int32)" << constValue.m_value.aLong;
1434 break;
1435 case RT_TYPE_UINT32:
1436 o << "(sal_uInt32)" << constValue.m_value.aULong;
1437 break;
1438 case RT_TYPE_INT64:
1440 ::rtl::OString tmp( OString::valueOf(constValue.m_value.aHyper) );
1441 o << "(sal_Int64)" << tmp.getStr() << "L";
1443 break;
1444 case RT_TYPE_UINT64:
1446 ::rtl::OString tmp( OString::valueOf((sal_Int64)constValue.m_value.aUHyper) );
1447 o << "(sal_uInt64)" << tmp.getStr() << "L";
1449 break;
1450 case RT_TYPE_FLOAT:
1452 ::rtl::OString tmp( OString::valueOf(constValue.m_value.aFloat) );
1453 o << "(float)" << tmp.getStr();
1455 break;
1456 case RT_TYPE_DOUBLE:
1458 ::rtl::OString tmp( OString::valueOf(constValue.m_value.aDouble) );
1459 o << "(double)" << tmp.getStr();
1461 break;
1462 case RT_TYPE_STRING:
1464 ::rtl::OUString aUStr(constValue.m_value.aString);
1465 ::rtl::OString aStr = ::rtl::OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US);
1466 o << "::rtl::OUString::createFromAscii(\"" << aStr.getStr() << "\")";
1468 break;
1472 void CunoType::inc(sal_uInt32 num)
1474 m_indentLength += num;
1477 void CunoType::dec(sal_uInt32 num)
1479 if (m_indentLength - num < 0)
1480 m_indentLength = 0;
1481 else
1482 m_indentLength -= num;
1485 OString CunoType::indent()
1487 OStringBuffer tmp(m_indentLength);
1489 for (sal_uInt32 i=0; i < m_indentLength; i++)
1491 tmp.append(' ');
1493 return tmp.makeStringAndClear();
1496 OString CunoType::indent(sal_uInt32 num)
1498 OStringBuffer tmp(m_indentLength + num);
1500 for (sal_uInt32 i=0; i < m_indentLength + num; i++)
1502 tmp.append(' ');
1504 return tmp.makeStringAndClear();
1507 //*************************************************************************
1508 // InterfaceType
1509 //*************************************************************************
1510 InterfaceType::InterfaceType(TypeReader& typeReader,
1511 const OString& typeName,
1512 const TypeManager& typeMgr,
1513 const TypeDependency& typeDependencies)
1514 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
1516 m_inheritedMemberCount = 0;
1517 m_hasAttributes = sal_False;
1518 m_hasMethods = sal_False;
1521 InterfaceType::~InterfaceType()
1526 sal_Bool InterfaceType::dumpHFile(FileStream& o)
1527 throw( CannotDumpException )
1529 OString headerDefine(dumpHeaderDefine(o, "H"));
1530 o << "\n";
1532 dumpDefaultHIncludes(o);
1533 o << "\n";
1534 dumpDepIncludes(o, m_typeName, "h");
1535 o << "\n";
1536 dumpOpenExternC(o);
1538 o << "#ifndef " << m_name.toAsciiUpperCase() << "\n";
1539 o << "#define " << m_name.toAsciiUpperCase() << "\n";
1540 o << "struct _" << m_name << "_ftab;\n"
1541 << "typedef struct _" << m_name << "_ftab * " << m_name << ";\n";
1542 o << "#endif\n\n";
1544 dumpDeclaration(o);
1546 if ( m_cunoTypeLib )
1548 o << "#ifdef CUNO_TYPELIB\n"
1549 << "typelib_TypeDescriptionReference * SAL_CALL getCUnoType_" << m_name << "() SAL_THROW( () );\n"
1550 << "#endif\n\n";
1554 if (getNestedTypeNames().getLength() > 0)
1556 o << indent() << "// nested types\n\n";
1557 for (sal_uInt32 i = 0; i < getNestedTypeNames().getLength(); i++)
1559 OUString s(getNestedTypeNames().getElement(i));
1561 OString nestedName(s.getStr(), s.getLength(), RTL_TEXTENCODING_UTF8);
1563 nestedName = checkRealBaseType(nestedName.copy(5));
1565 if (nestedName.lastIndexOf(']') < 0)
1567 o << "inline const ::com::sun::star::uno::Type& SAL_CALL getCunoType( ";
1568 dumpType(o, nestedName, sal_True, sal_False);
1569 o << "* ) SAL_THROW( () );\n\n";
1574 dumpCloseExternC(o);
1576 o << "#endif /* "<< headerDefine << " */\n";
1577 return sal_True;
1580 void InterfaceType::dumpInheritedFunctions(FileStream& o, rtl::OString& superType)
1582 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
1584 OString baseType(aSuperReader.getSuperTypeName());
1585 if (baseType.getLength() > 0)
1587 dumpInheritedFunctions(o, baseType);
1590 dumpAttributes(o, superType.replace('/', '_'), aSuperReader);
1591 dumpMethods(o, superType.replace('/', '_'), aSuperReader);
1594 sal_Bool InterfaceType::dumpDeclaration(FileStream& o)
1595 throw( CannotDumpException )
1597 o << "typedef struct _" << m_name << "_ftab\n" << indent() << "{";
1598 inc();
1600 OString superType(m_reader.getSuperTypeName());
1601 if (superType.getLength() > 0)
1602 dumpInheritedFunctions(o, superType);
1604 if (getNestedTypeNames().getLength() > 0)
1606 inc();
1607 o << indent() << "// nested types\n\n";
1608 for (sal_uInt32 i = 0; i < getNestedTypeNames().getLength(); i++)
1610 OUString s(getNestedTypeNames().getElement(i));
1612 OString nestedName(s.getStr(), s.getLength(), RTL_TEXTENCODING_UTF8);
1614 nestedName = nestedName.copy(5);
1616 o << indent() << "// " << nestedName.getStr() << "\n";
1618 TypeReader reader(m_typeMgr.getTypeReader(nestedName));
1620 if (reader.isValid())
1622 RTTypeClass typeClass = reader.getTypeClass();
1623 switch (typeClass) {
1624 case RT_TYPE_INTERFACE:
1626 InterfaceType iType(reader, nestedName, m_typeMgr, m_dependencies);
1627 iType.dumpDeclaration(o);
1629 break;
1630 case RT_TYPE_STRUCT:
1632 StructureType sType(reader, nestedName, m_typeMgr, m_dependencies);
1633 sType.dumpDeclaration(o);
1635 break;
1636 case RT_TYPE_ENUM:
1638 EnumType enType(reader, nestedName, m_typeMgr, m_dependencies);
1639 enType.dumpDeclaration(o);
1641 break;
1642 case RT_TYPE_EXCEPTION:
1644 ExceptionType eType(reader, nestedName, m_typeMgr, m_dependencies);
1645 eType.dumpDeclaration(o);
1647 break;
1648 case RT_TYPE_TYPEDEF:
1650 TypeDefType tdType(reader, nestedName, m_typeMgr, m_dependencies);
1651 tdType.dumpDeclaration(o);
1653 break;
1654 default:
1655 break;
1659 dec();
1662 dumpAttributes(o, m_name, m_reader);
1663 dumpMethods(o, m_name, m_reader);
1665 dec();
1666 o << "} " << m_name << "_ftab;\n\n";
1668 return sal_True;
1671 sal_Bool InterfaceType::dumpCFile(FileStream& o)
1672 throw( CannotDumpException )
1674 dumpInclude(o, m_typeName, "h");
1675 o << "\n";
1676 dumpDefaultCIncludes(o);
1677 o << "\n";
1678 dumpDepIncludes(o, m_typeName, "h");
1679 o << "\n";
1680 dumpGetCunoType(o);
1682 if (getNestedTypeNames().getLength() > 0)
1684 o << indent() << "// nested types\n\n";
1685 for (sal_uInt32 i = 0; i < getNestedTypeNames().getLength(); i++)
1687 OUString s(getNestedTypeNames().getElement(i));
1689 OString nestedName(s.getStr(), s.getLength(), RTL_TEXTENCODING_UTF8);
1691 nestedName = nestedName.copy(5);
1693 o << indent() << "// " << nestedName.getStr() << "\n";
1695 TypeReader reader(m_typeMgr.getTypeReader(nestedName));
1697 if (reader.isValid())
1699 RTTypeClass typeClass = reader.getTypeClass();
1700 switch (typeClass) {
1701 case RT_TYPE_INTERFACE:
1703 InterfaceType iType(reader, nestedName, m_typeMgr, m_dependencies);
1704 iType.dumpGetCunoType(o);
1706 break;
1707 case RT_TYPE_STRUCT:
1709 StructureType sType(reader, nestedName, m_typeMgr, m_dependencies);
1710 sType.dumpGetCunoType(o);
1712 break;
1713 case RT_TYPE_ENUM:
1715 EnumType enType(reader, nestedName, m_typeMgr, m_dependencies);
1716 enType.dumpGetCunoType(o);
1718 break;
1719 case RT_TYPE_EXCEPTION:
1721 ExceptionType eType(reader, nestedName, m_typeMgr, m_dependencies);
1722 eType.dumpGetCunoType(o);
1724 break;
1725 case RT_TYPE_TYPEDEF:
1727 TypeDefType tdType(reader, nestedName, m_typeMgr, m_dependencies);
1728 tdType.dumpGetCunoType(o);
1730 break;
1731 default:
1732 break;
1738 return sal_True;
1741 void InterfaceType::dumpAttributes(FileStream& o, const OString& interfaceType, TypeReader& reader )
1743 sal_uInt32 fieldCount = reader.getFieldCount();
1744 sal_Bool first=sal_True;
1746 RTFieldAccess access = RT_ACCESS_INVALID;
1747 OString fieldName;
1748 OString fieldType;
1749 for (sal_uInt16 i=0; i < fieldCount; i++)
1751 access = reader.getFieldAccess(i);
1753 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
1754 continue;
1756 fieldName = reader.getFieldName(i);
1757 fieldType = reader.getFieldType(i);
1759 if (first)
1761 first = sal_False;
1762 o << "\n" << indent() << "/* Attributes of " << interfaceType << " */\n";
1765 o << indent() << "cuno_ErrorCode (SAL_CALL *get" << fieldName << ")( "
1766 << interfaceType << " *, uno_Any *, ";
1767 dumpType(o, fieldType, sal_False, sal_True);
1768 o << " );\n";
1770 if (access != RT_ACCESS_READONLY)
1772 OString relType = checkSpecialCunoType(fieldType);
1773 sal_Bool bParam = sal_False;
1775 if ( m_typeMgr.getTypeClass(relType) == RT_TYPE_STRUCT ||
1776 m_typeMgr.getTypeClass(relType) == RT_TYPE_EXCEPTION ||
1777 (isBaseType(relType) && relType.equals("any")))
1779 bParam = sal_True;
1780 } else
1782 bParam = sal_False;
1785 o << indent() << "cuno_ErrorCode (SAL_CALL *set" << fieldName << ")( "
1786 << interfaceType << " *, uno_Any *, ";
1787 dumpType(o, fieldType, sal_False, sal_False, bParam);
1788 o << " );\n";
1793 void InterfaceType::dumpMethods(FileStream& o, const OString& interfaceType, TypeReader& reader )
1795 sal_uInt32 methodCount = reader.getMethodCount();
1796 sal_Bool first=sal_True;
1798 OString methodName, returnType, paramType, paramName;
1799 sal_uInt32 paramCount = 0;
1800 sal_uInt32 excCount = 0;
1801 RTMethodMode methodMode = RT_MODE_INVALID;
1802 RTParamMode paramMode = RT_PARAM_INVALID;
1804 sal_Bool bPointer = sal_False;
1805 sal_Bool bParam = sal_False;
1806 sal_Bool bWithRunTimeExcp = sal_True;
1808 for (sal_uInt16 i=0; i < methodCount; i++)
1810 methodName = reader.getMethodName(i);
1811 returnType = reader.getMethodReturnType(i);
1812 paramCount = reader.getMethodParamCount(i);
1813 excCount = reader.getMethodExcCount(i);
1814 methodMode = reader.getMethodMode(i);
1816 if ( methodName.equals("queryInterface") )
1818 first = sal_False;
1819 o << "\n" << indent() << "/* Methods of " << interfaceType << " */\n";
1820 o << indent() << "cuno_ErrorCode (SAL_CALL *queryInterface)( com_sun_star_uno_XInterface *, "
1821 << "uno_Any *, com_sun_star_uno_XInterface **, typelib_TypeDescriptionReference * );\n";
1822 continue;
1825 if ( methodName.equals("acquire") || methodName.equals("release") )
1827 bWithRunTimeExcp = sal_False;
1830 if (first)
1832 first = sal_False;
1833 o << "\n" << indent() << "/* Methods of " << interfaceType << " */\n";
1836 o << indent() << "cuno_ErrorCode (SAL_CALL *" << methodName << ")( "
1837 << interfaceType << " *";
1838 if ( excCount || bWithRunTimeExcp )
1840 o << ", uno_Any *";
1842 if ( !isVoid(returnType) )
1844 o << ", ";
1845 dumpType(o, returnType, sal_False, sal_True);
1848 sal_uInt16 j;
1849 for (j=0; j < paramCount; j++)
1851 paramName = reader.getMethodParamName(i, j);
1852 paramType = reader.getMethodParamType(i, j);
1853 paramMode = reader.getMethodParamMode(i, j);
1855 if (j < (sal_uInt16)paramCount) o << ", ";
1857 switch (paramMode)
1859 case RT_PARAM_IN:
1861 OString relType = checkSpecialCunoType(paramType);
1862 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_STRUCT ||
1863 m_typeMgr.getTypeClass(relType) == RT_TYPE_EXCEPTION ||
1864 (isBaseType(relType) && relType.equals("any")))
1866 bParam = sal_True;
1867 } else
1869 bParam = sal_False;
1871 break;
1873 case RT_PARAM_OUT:
1874 case RT_PARAM_INOUT:
1875 bPointer = sal_True;
1876 break;
1879 dumpType(o, paramType, sal_False, bPointer, bParam);
1881 o << " );\n";
1885 void InterfaceType::dumpGetCunoType(FileStream& o)
1887 OString typeName(m_typeName.replace('/', '_'));
1889 if ( m_cunoTypeLeak )
1891 dumpLGetCunoType(o);
1892 return;
1894 if ( !m_cunoTypeDynamic )
1896 dumpCGetCunoType(o);
1897 return;
1900 dumpOpenExternC(o);
1902 if ( !m_typeName.equals("com/sun/star/uno/XInterface") )
1904 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1905 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
1906 << "#endif\n\n";
1909 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
1910 inc();
1912 if ( m_typeName.equals("com/sun/star/uno/XInterface") )
1914 o << indent() << "return typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE );\n";
1915 } else
1917 o << indent() << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1918 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
1919 << indent() << "#endif\n\n";
1921 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
1922 inc();
1923 OString superType(m_reader.getSuperTypeName());
1924 sal_Bool bWithBase = sal_False;
1925 if (superType.getLength() > 0 && !superType.equals("com/sun/star/uno/XInterface"))
1927 bWithBase = sal_True;
1928 o << indent() << "typelib_TypeDescriptionReference * pSuperType = 0;\n"
1929 << indent() << "typelib_typedescriptionreference_newByAsciiName(&pSuperType, typelib_TypeClass_INTERFACE, \""
1930 << superType.replace('/', '.') << "\" );\n";
1933 o << indent() << "typelib_static_interface_type_init( &s_pType_" << typeName
1934 << ", \"" << m_typeName.replace('/', '.') << "\", ";
1936 if ( bWithBase )
1938 o << "pSuperType );\n";
1939 } else
1941 o << "0 );\n";
1944 dec();
1945 o << indent() << "}\n"
1946 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName << " );\n"
1947 << indent() << "return &s_pType_" << typeName <<" );\n";
1949 dec();
1950 o << indent() << "}\n";
1952 dumpCloseExternC(o);
1955 void InterfaceType::dumpCGetCunoType(FileStream& o)
1957 OString typeName(m_typeName.replace('/', '_'));
1959 dumpOpenExternC(o);
1961 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1962 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
1963 << "#endif\n\n";
1965 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
1966 inc();
1968 o << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1969 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
1970 << "#endif\n\n";
1972 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
1973 inc();
1974 o << indent() << "oslMutex * pMutex = osl_getGlobalMutex();\n"
1975 << indent() << "osl_acquireMutex( pMutex );\n";
1977 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
1978 inc();
1979 o << indent() << "rtl_uString * pTypeName = 0;\n"
1980 << indent() << "typelib_InterfaceTypeDescription * pTD = 0;\n";
1982 OString superType(m_reader.getSuperTypeName());
1983 sal_uInt32 count = getMemberCount();
1985 if (superType.getLength() > 0)
1986 o << indent() << "typelib_TypeDescriptionReference * pSuperType = 0;\n";
1988 if (count)
1990 o << indent() << "typelib_TypeDescriptionReference * pMembers[" << count << "] = { ";
1991 for (sal_uInt32 i = 0; i < count; i++)
1993 o << "0";
1994 if (i+1 < count)
1995 o << ",";
1996 else
1997 o << " };\n";
2000 dumpCUnoAttributeTypeNames(o);
2001 dumpCUnoMethodTypeNames(o);
2004 o << indent() << "rtl_uString_newFromAscii( &pTypeName, \"" << m_typeName.replace('/', '.') << "\" );\n";
2006 if (superType.getLength() > 0)
2008 o << indent() << "typelib_typedescriptionreference_newByAsciiName(&pSuperType, typelib_TypeClass_INTERFACE, \""
2009 << superType.replace('/', '.') << "\" );\n";
2012 if (count)
2014 sal_uInt32 index = 0;
2015 dumpCUnoAttributeRefs(o, index);
2016 dumpCUnoMethodRefs(o, index);
2019 o << "\n" << indent() << "typelib_typedescription_newInterface(\n";
2020 inc();
2021 o << indent() << "&pTD,\n"
2022 << indent() << "pTypeName, ";
2024 RTUik uik;
2025 m_reader.getUik(uik);
2026 sal_Char buffer[53];
2027 snprintf(buffer, sizeof(buffer), "0x%.8x, 0x%.4x, 0x%.4x, 0x%.8x, 0x%.8x,\n",
2028 uik.m_Data1, uik.m_Data2, uik.m_Data3, uik.m_Data4, uik.m_Data5);
2029 o << buffer;
2031 if (superType.getLength() > 0)
2032 o << indent() << "pSuperType,\n";
2033 else
2034 o << indent() << "0,\n";
2036 if ( count )
2038 o << indent() << count << ",\n" << indent() << "pMembers );\n\n";
2039 } else
2041 o << indent() << count << ",\n" << indent() << "0 );\n\n";
2043 dec();
2045 o << indent() << "typelib_typedescription_register( (typelib_TypeDescription**)&pTD );\n";
2046 if ( count )
2048 for (sal_uInt16 i=0; i < count; i++)
2050 o << indent() << "typelib_typedescriptionreference_release( pMembers["
2051 << i << "] );\n";
2054 o << indent() << "typelib_typedescription_release( (typelib_TypeDescription*)pTD );\n";
2056 if (superType.getLength() > 0)
2057 o << indent() << "typelib_typedescription_release( pSuperType );\n\n";
2058 else
2059 o << "\n";
2061 o << indent() << "typelib_typedescriptionreference_new( &s_pType_ " << typeName
2062 << "typelib_TypeClass_INTERFACE, (typelib_TypeDescription*)pTD);\n\n";
2064 o << indent() << "typelib_TypeDescriptionReference ** ppTypeRef = 0;\n";
2065 StringSet aTypes;
2066 // type for RuntimeException is always needed
2067 OString sRunTimeExceptionType("com/sun/star/uno/RuntimeException");
2068 aTypes.insert(sRunTimeExceptionType);
2069 dumpCppuGetType(o, sRunTimeExceptionType, sal_True, CUNOTYPEDECL_ALLTYPES);
2071 dumpAttributesCppuDecl(o, &aTypes, CUNOTYPEDECL_ALLTYPES);
2072 dumpMethodsCppuDecl(o, &aTypes, CUNOTYPEDECL_ALLTYPES);
2074 if (count)
2076 sal_uInt32 index = getInheritedMemberCount();
2077 dumpCUnoAttributes(o, index);
2078 dumpCUnoMethods(o, index);
2081 // release strings for names
2082 dumpCUnoAttributeTypeNames(o, sal_True);
2083 dumpCUnoMethodTypeNames(o, sal_True);
2085 dec();
2086 o << indent() << "}\n";
2087 o << indent() << "osl_releaseMutex( pMutex );\n";
2088 dec();
2089 o << indent() << "}\n\n"
2090 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName << " );\n"
2091 << indent() << "return &s_pType_" << typeName << ";\n";
2093 dec();
2094 o << "}\n";
2096 dumpCloseExternC(o);
2099 void InterfaceType::dumpCUnoAttributeTypeNames(FileStream&o, sal_Bool bRelease)
2101 sal_uInt32 fieldCount = m_reader.getFieldCount();
2102 RTFieldAccess access = RT_ACCESS_INVALID;
2104 for (sal_uInt16 i=0; i < fieldCount; i++)
2106 access = m_reader.getFieldAccess(i);
2107 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2108 continue;
2109 if ( bRelease )
2111 o << indent() << "rtl_uString_release( pAttributeName" << i << " );\n";
2112 } else
2114 o << indent() << "rtl_uString * pAttributeName" << i << " = 0;\n";
2119 void InterfaceType::dumpCUnoMethodTypeNames(FileStream&o, sal_Bool bRelease)
2121 sal_uInt32 methodCount = m_reader.getMethodCount();
2123 for (sal_uInt16 i = 0; i < methodCount; i++)
2125 if ( bRelease )
2127 o << indent() << "rtl_uString_release( pMethodName" << i << " );\n";
2128 } else
2130 o << indent() << "rtl_uString * pMethodName" << i << " = 0;\n";
2135 void InterfaceType::dumpCUnoAttributeRefs(FileStream& o, sal_uInt32& index)
2137 sal_uInt32 fieldCount = m_reader.getFieldCount();
2138 RTFieldAccess access = RT_ACCESS_INVALID;
2139 OString fieldName;
2140 OString scope = m_typeName.replace('/', '.');
2142 for (sal_uInt16 i=0; i < fieldCount; i++)
2144 access = m_reader.getFieldAccess(i);
2145 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2146 continue;
2147 fieldName = m_reader.getFieldName(i);
2149 o << indent() << "rtl_uString_newFromAscii( &pAttributeName" << i << ", \""
2150 << scope << "::" << fieldName << "\" );\n";
2151 o << indent() << "typelib_typedescriptionreference_new( &pMembers["
2152 << index << "],\n";
2153 inc(38);
2154 o << indent() << "typelib_TypeClass_INTERFACE_ATTRIBUTE,\n"
2155 << indent() << "pAttributeName" << i << " );\n";
2156 dec(38);
2157 index++;
2161 void InterfaceType::dumpCUnoMethodRefs(FileStream& o, sal_uInt32& index)
2163 sal_uInt32 methodCount = m_reader.getMethodCount();
2164 OString methodName; //, returnType, paramType, paramName;
2165 OString scope = m_typeName.replace('/', '.');
2167 for (sal_uInt16 i = 0; i < methodCount; i++)
2169 methodName = m_reader.getMethodName(i);
2171 o << indent() << "rtl_uString_newFromAscii( &pMethodName" << i << ", \""
2172 << scope.replace('/', '.') << "::" << methodName << "\" );\n";
2173 o << indent() << "typelib_typedescriptionreference_new( &pMembers["
2174 << index << "],\n";
2175 inc(38);
2176 o << indent() << "typelib_TypeClass_INTERFACE_METHOD,\n"
2177 << indent() << "pMethodName" << i << " );\n";
2178 dec(38);
2179 index++;
2183 sal_uInt32 InterfaceType::getMemberCount()
2185 sal_uInt32 count = m_reader.getMethodCount();
2187 if (count)
2188 m_hasMethods = sal_True;
2190 sal_uInt32 fieldCount = m_reader.getFieldCount();
2191 RTFieldAccess access = RT_ACCESS_INVALID;
2192 for (sal_uInt16 i=0; i < fieldCount; i++)
2194 access = m_reader.getFieldAccess(i);
2196 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
2198 m_hasAttributes = sal_True;
2199 count++;
2202 return count;
2205 sal_uInt32 InterfaceType::checkInheritedMemberCount(const TypeReader* pReader)
2207 sal_uInt32 cout = 0;
2208 sal_Bool bSelfCheck = sal_True;
2209 if (!pReader)
2211 bSelfCheck = sal_False;
2212 pReader = &m_reader;
2215 sal_uInt32 count = 0;
2216 OString superType(pReader->getSuperTypeName());
2217 if (superType.getLength() > 0)
2219 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
2220 if (aSuperReader.isValid())
2222 count = checkInheritedMemberCount(&aSuperReader);
2226 if (bSelfCheck)
2228 count += pReader->getMethodCount();
2229 sal_uInt32 fieldCount = pReader->getFieldCount();
2230 RTFieldAccess access = RT_ACCESS_INVALID;
2231 for (sal_uInt16 i=0; i < fieldCount; i++)
2233 access = pReader->getFieldAccess(i);
2235 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
2237 count++;
2242 return count;
2245 sal_uInt32 InterfaceType::getInheritedMemberCount()
2247 if (m_inheritedMemberCount == 0)
2249 m_inheritedMemberCount = checkInheritedMemberCount(0);
2252 return m_inheritedMemberCount;
2255 void InterfaceType::dumpCUnoAttributes(FileStream& o, sal_uInt32& index)
2257 sal_uInt32 fieldCount = m_reader.getFieldCount();
2259 RTFieldAccess access = RT_ACCESS_INVALID;
2260 OString fieldType;
2262 sal_uInt32 absoluteIndex = index;
2264 if (m_hasAttributes)
2266 o << "\n" << indent() << "{\n" << indent() << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n";
2268 for (sal_uInt16 i=0; i < fieldCount; i++)
2270 access = m_reader.getFieldAccess(i);
2272 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2273 continue;
2275 fieldType = checkRealBaseType(m_reader.getFieldType(i), sal_True);
2276 o << indent() << "{\n";
2277 o << indent() << "rtl_uString * pAttributeType" << i << " = 0;\n";
2278 o << indent() << "rtl_uString_newFromAscii( &pAttributeType" << i << ", \""
2279 << fieldType.replace('/', '.') << "\" );\n";
2280 o << indent() << "typelib_typedescription_newInterfaceAttribute( &pAttribute,\n";
2281 inc();
2282 o << indent() << absoluteIndex++ << ", pAttributeName" << i << ",\n";
2283 o << indent() << getTypeClass(fieldType, sal_True) << ", pAttributeType" << i << ",\n";
2284 if (access == RT_ACCESS_READONLY)
2285 o << indent() << "sal_True );\n";
2286 else
2287 o << indent() << "sal_False );\n";
2288 dec();
2289 o << indent() << "typelib_typedescription_register( (typelib_TypeDescription**)&pAttribute );\n\n";
2290 o << indent() << "}\n";
2292 o << indent() << "typelib_typedescription_release( (typelib_TypeDescription*)pAttribute );\n";
2293 o << indent() << "}\n";
2294 index = absoluteIndex;
2298 void InterfaceType::dumpCUnoMethods(FileStream& o, sal_uInt32& index)
2300 sal_uInt32 methodCount = m_reader.getMethodCount();
2301 OString methodName, returnType, paramType, paramName;
2302 sal_uInt32 paramCount = 0;
2303 sal_uInt32 excCount = 0;
2304 RTMethodMode methodMode = RT_MODE_INVALID;
2305 RTParamMode paramMode = RT_PARAM_INVALID;
2306 sal_Bool bWithRuntimeException = sal_True;
2308 sal_uInt32 absoluteIndex = index;
2310 if (m_hasMethods)
2312 o << "\n" << indent() << "{\n" << indent() << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n";
2314 for (sal_uInt16 i=0; i < methodCount; i++)
2316 methodName = m_reader.getMethodName(i);
2317 returnType = checkRealBaseType(m_reader.getMethodReturnType(i), sal_True);
2318 paramCount = m_reader.getMethodParamCount(i);
2319 excCount = m_reader.getMethodExcCount(i);
2320 methodMode = m_reader.getMethodMode(i);
2322 if ( methodName.equals("acquire") || methodName.equals("release") )
2324 bWithRuntimeException = sal_False;
2326 o << indent() << "{\n";
2327 inc();
2329 if (paramCount)
2331 o << indent() << "typelib_Parameter_Init pParameters[" << paramCount << "];\n";
2333 if ( excCount || bWithRuntimeException )
2335 o << indent() << "rtl_uString * pExceptions[" << excCount + 1 << "];\n";
2337 o << indent() << "rtl_uString * pReturnType" << i << " = 0;\n";
2339 sal_uInt16 j;
2340 for (j=0; j < paramCount; j++)
2342 o << indent() << "rtl_uString * pParamName" << j << " = 0;\n"
2343 << indent() << "rtl_uString * pParamType" << j << " = 0;\n";
2346 for (j=0; j < excCount; j++)
2348 o << indent() << "rtl_uString * pExceptionName" << j << " = 0;\n";
2350 if ( excCount || bWithRuntimeException )
2352 o << indent() << "rtl_uString * pExceptionName" << excCount << " = 0;\n";
2354 for (j=0; j < paramCount; j++)
2356 paramName = m_reader.getMethodParamName(i, j);
2357 paramType = checkRealBaseType(m_reader.getMethodParamType(i, j), sal_True);
2358 paramMode = m_reader.getMethodParamMode(i, j);
2359 o << indent() << "rtl_uString_newFromAscii( &pParamName" << j << ", \""
2360 << paramName << "\" );\n";
2361 o << indent() << "rtl_uString_newFromAscii( &pParamType" << j << ", \""
2362 << paramType.replace('/', '.') << "\" );\n";
2363 o << indent() << "pParameters[" << j << "].pParamName = pParamName" << j << ";\n";
2364 o << indent() << "pParameters[" << j << "].eTypeClass = "
2365 << getTypeClass(paramType, sal_True) << ";\n";
2366 o << indent() << "pParameters[" << j << "].pTypeName = sParamType" << j << ";\n";
2368 if (paramMode == RT_PARAM_IN || paramMode == RT_PARAM_INOUT)
2369 o << indent() << "pParameters[" << j << "].bIn = sal_True;\n";
2370 else
2371 o << indent() << "pParameters[" << j << "].bIn = sal_False;\n";
2373 if (paramMode == RT_PARAM_OUT || paramMode == RT_PARAM_INOUT)
2374 o << indent() << "pParameters[" << j << "].bOut = sal_True;\n";
2375 else
2376 o << indent() << "pParameters[" << j << "].bOut = sal_False;\n";
2379 for (j=0; j < excCount; j++)
2381 if (!m_reader.getMethodExcType(i, j).equals("com/sun/star/uno/RuntimeException"))
2383 o << indent() << "rtl_uString_newFromAscii( & pExceptionName" << j << ", \""
2384 << OString(m_reader.getMethodExcType(i, j)).replace('/', '.') << "\" );\n";
2385 o << indent() << "pExceptions[" << j << "] = pExceptionName" << j << ";\n";
2388 if ( excCount || bWithRuntimeException )
2390 o << indent() << "rtl_uString_newFromAscii( & pExceptionName" << excCount
2391 << ", \"com.sun.star.uno.RuntimeException\") );\n";
2392 o << indent() << "pExceptions[" << excCount << "] = pExceptionName" << excCount << ";\n";
2394 o << indent() << "rtl_uString_newFromAscii( &pReturnType" << i << ", \""
2395 << returnType.replace('/', '.') << "\" );\n";
2396 o << indent() << "typelib_typedescription_newInterfaceMethod( &pMethod,\n";
2397 inc();
2398 o << indent() << absoluteIndex++ << ", ";
2399 if (methodMode == RT_MODE_ONEWAY || methodMode == RT_MODE_ONEWAY_CONST)
2400 o << "sal_True,\n";
2401 else
2402 o << "sal_False,\n";
2403 o << indent() << "pMethodName" << i << ",\n";
2404 o << indent() << getTypeClass(returnType, sal_True) << ", pReturnType" << i << ",\n";
2405 if (paramCount)
2406 o << indent() << paramCount << ", pParameters,\n";
2407 else
2408 o << indent() << "0, 0,\n";
2410 if ( excCount || bWithRuntimeException )
2412 o << indent() << excCount + 1 << ", pExceptions );\n";
2413 } else
2415 o << indent() << "0, 0 );\n";
2418 dec();
2419 o << indent() << "typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );\n";
2421 o << indent() << "rtl_uString_release( pReturnType );\n";
2422 for (j=0; j < paramCount; j++)
2424 o << indent() << "rtl_uString_release( pParamName" << j << " );\n"
2425 << indent() << "rtl_uString_release( pParamType" << j << " );\n";
2428 for (j=0; j < excCount; j++)
2430 o << indent() << "rtl_uString_release( pExceptionName" << j << " );\n";
2432 if ( excCount || bWithRuntimeException )
2434 o << indent() << "rtl_uString_release( pExceptionName" << excCount << " );\n";
2436 dec();
2437 o << indent() << "}\n";
2439 o << indent() << "typelib_typedescription_release( (typelib_TypeDescription*)pMethod );\n";
2441 o << indent() << "}\n";
2442 index = absoluteIndex;
2446 void InterfaceType::dumpAttributesCppuDecl(FileStream& o, StringSet* pFinishedTypes, CunoTypeDecl eDeclFlag)
2448 sal_uInt32 fieldCount = m_reader.getFieldCount();
2450 RTFieldAccess access = RT_ACCESS_INVALID;
2451 OString fieldName;
2452 OString fieldType;
2453 for (sal_uInt16 i=0; i < fieldCount; i++)
2455 access = m_reader.getFieldAccess(i);
2457 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2458 continue;
2460 fieldName = m_reader.getFieldName(i);
2461 fieldType = m_reader.getFieldType(i);
2463 if (pFinishedTypes->count(fieldType) == 0)
2465 pFinishedTypes->insert(fieldType);
2466 dumpCppuGetType(o, fieldType, sal_True, eDeclFlag);
2471 void InterfaceType::dumpMethodsCppuDecl(FileStream& o, StringSet* pFinishedTypes, CunoTypeDecl eDeclFlag)
2473 sal_uInt32 methodCount = m_reader.getMethodCount();
2474 OString returnType, paramType, excType;
2475 sal_uInt32 paramCount = 0;
2476 sal_uInt32 excCount = 0;
2478 for (sal_uInt16 i=0; i < methodCount; i++)
2480 returnType = m_reader.getMethodReturnType(i);
2481 paramCount = m_reader.getMethodParamCount(i);
2482 excCount = m_reader.getMethodExcCount(i);
2484 if (pFinishedTypes->count(returnType) == 0)
2486 pFinishedTypes->insert(returnType);
2487 dumpCppuGetType(o, returnType, sal_True, eDeclFlag);
2489 sal_uInt16 j;
2490 for (j=0; j < paramCount; j++)
2492 paramType = m_reader.getMethodParamType(i, j);
2494 if (pFinishedTypes->count(paramType) == 0)
2496 pFinishedTypes->insert(paramType);
2497 dumpCppuGetType(o, paramType, sal_True, eDeclFlag);
2501 for (j=0; j < excCount; j++)
2503 excType = m_reader.getMethodExcType(i, j);
2504 if (pFinishedTypes->count(excType) == 0)
2506 pFinishedTypes->insert(excType);
2507 dumpCppuGetType(o, excType, sal_True, eDeclFlag);
2513 //*************************************************************************
2514 // ModuleType
2515 //*************************************************************************
2516 ModuleType::ModuleType(TypeReader& typeReader,
2517 const OString& typeName,
2518 const TypeManager& typeMgr,
2519 const TypeDependency& typeDependencies)
2520 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
2524 ModuleType::~ModuleType()
2529 sal_Bool ModuleType::dump(CunoOptions* pOptions)
2530 throw( CannotDumpException )
2532 sal_Bool ret = sal_False;
2534 if (pOptions->isValid("-U"))
2535 m_cunoTypeDynamic = sal_True;
2537 OString outPath;
2538 if (pOptions->isValid("-O"))
2539 outPath = pOptions->getOption("-O");
2541 OString tmpName(m_typeName);
2543 if (tmpName.equals("/"))
2544 tmpName = "global";
2545 else
2546 // tmpName += "/" + m_typeName.getToken(m_typeName.getTokenCount('/') - 1, '/');
2547 tmpName += "/" + m_name;
2549 OString tmpFileName;
2550 OString hFileName = createFileNameFromType(outPath, tmpName, ".hdl");
2552 sal_Bool bFileExists = sal_False;
2553 sal_Bool bFileCheck = sal_False;
2555 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
2557 bFileExists = fileExists( hFileName );
2558 ret = sal_True;
2561 if ( bFileExists && pOptions->isValid("-Gc") )
2563 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tml");
2564 bFileCheck = sal_True;
2567 if ( !bFileExists || bFileCheck )
2569 FileStream hFile;
2571 if ( bFileCheck )
2572 hFile.open(tmpFileName);
2573 else
2574 hFile.open(hFileName);
2576 if(!hFile.isValid())
2578 OString message("cannot open ");
2579 message += hFileName + " for writing";
2580 throw CannotDumpException(message);
2583 ret = dumpHFile(hFile);
2585 hFile.close();
2586 if (ret && bFileCheck)
2588 ret = checkFileContent(hFileName, tmpFileName);
2592 bFileExists = sal_False;
2593 bFileCheck = sal_False;
2594 OString cFileName = createFileNameFromType(outPath, tmpName, ".c");
2596 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
2598 bFileExists = fileExists( cFileName );
2599 ret = sal_True;
2602 if ( bFileExists && pOptions->isValid("-Gc") )
2604 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmc");
2605 bFileCheck = sal_True;
2609 if ( !bFileExists || bFileCheck )
2611 FileStream hxxFile;
2613 if ( bFileCheck )
2614 cFile.open(tmpFileName);
2615 else
2616 cFile.open(cFileName);
2618 if(!cFile.isValid())
2620 OString message("cannot open ");
2621 message += cFileName + " for writing";
2622 throw CannotDumpException(message);
2625 ret = dumpCFile(cFile);
2627 cFile.close();
2628 if (ret && bFileCheck)
2630 ret = checkFileContent(cFileName, tmpFileName);
2634 return ret;
2637 sal_Bool ModuleType::dumpHFile(FileStream& o)
2638 throw( CannotDumpException )
2640 sal_Bool bSpecialDefine = sal_True;
2642 if (m_reader.getTypeClass() == RT_TYPE_CONSTANTS)
2644 bSpecialDefine = sal_False;
2647 OString headerDefine(dumpHeaderDefine(o, "H", bSpecialDefine));
2648 o << "\n";
2650 dumpDefaultHIncludes(o);
2651 o << "\n";
2652 dumpDepIncludes(o, m_typeName, "h");
2653 o << "\n";
2655 dumpOpenExternC(o);
2656 dumpDeclaration(o);
2657 o << "\n";
2658 dumpCloseExternC(o);
2660 o << "\n#endif /* "<< headerDefine << " */\n";
2662 return sal_True;
2665 sal_Bool ModuleType::dumpDeclaration(FileStream& o)
2666 throw( CannotDumpException )
2668 sal_uInt32 fieldCount = m_reader.getFieldCount();
2669 RTFieldAccess access = RT_ACCESS_INVALID;
2670 OString fieldName;
2671 OString fieldType;
2672 for (sal_uInt16 i=0; i < fieldCount; i++)
2674 access = m_reader.getFieldAccess(i);
2676 if (access == RT_ACCESS_CONST)
2678 fieldName = m_reader.getFieldName(i);
2679 fieldType = m_reader.getFieldType(i);
2681 o << "static const ";
2682 dumpType(o, fieldType);
2683 o << " " << m_name << "_" << fieldName << " = ";
2684 dumpConstantValue(o, i);
2685 o << ";\n";
2689 return sal_True;
2692 sal_Bool ModuleType::hasConstants()
2694 sal_uInt32 fieldCount = m_reader.getFieldCount();
2695 RTFieldAccess access = RT_ACCESS_INVALID;
2697 for (sal_uInt16 i=0; i < fieldCount; i++)
2699 access = m_reader.getFieldAccess(i);
2701 if (access == RT_ACCESS_CONST)
2702 return sal_True;
2705 return sal_False;
2708 sal_Bool ModuleType::dumpCFile(FileStream& o)
2709 throw( CannotDumpException )
2711 return sal_True;
2714 //*************************************************************************
2715 // ConstantsType
2716 //*************************************************************************
2717 ConstantsType::ConstantsType(TypeReader& typeReader,
2718 const OString& typeName,
2719 const TypeManager& typeMgr,
2720 const TypeDependency& typeDependencies)
2721 : ModuleType(typeReader, typeName, typeMgr, typeDependencies)
2725 ConstantsType::~ConstantsType()
2730 sal_Bool ConstantsType::dump(CunoOptions* pOptions)
2731 throw( CannotDumpException )
2733 sal_Bool ret = sal_False;
2735 if (pOptions->isValid("-U"))
2736 m_cunoTypeDynamic = sal_True;
2738 OString outPath;
2739 if (pOptions->isValid("-O"))
2740 outPath = pOptions->getOption("-O");
2742 OString tmpFileName;
2743 OString hFileName = createFileNameFromType(outPath, m_typeName, ".h");
2745 sal_Bool bFileExists = sal_False;
2746 sal_Bool bFileCheck = sal_False;
2748 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
2750 bFileExists = fileExists( hFileName );
2751 ret = sal_True;
2754 if ( bFileExists && pOptions->isValid("-Gc") )
2756 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmh");
2757 bFileCheck = sal_True;
2760 if ( !bFileExists || bFileCheck )
2762 FileStream hFile;
2764 if ( bFileCheck )
2765 hFile.open(tmpFileName);
2766 else
2767 hFile.open(hFileName);
2769 if(!hFile.isValid())
2771 OString message("cannot open ");
2772 message += hFileName + " for writing";
2773 throw CannotDumpException(message);
2776 ret = dumpHFile(hFile);
2778 hFile.close();
2779 if (ret && bFileCheck)
2781 ret = checkFileContent(hFileName, tmpFileName);
2785 bFileExists = sal_False;
2786 bFileCheck = sal_False;
2787 OString cFileName = createFileNameFromType(outPath, m_typeName, ".c");
2789 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
2791 bFileExists = fileExists( cFileName );
2792 ret = sal_True;
2795 if ( bFileExists && pOptions->isValid("-Gc") )
2797 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmc");
2798 bFileCheck = sal_True;
2801 if ( !bFileExists || bFileCheck )
2803 FileStream cFile;
2805 if ( bFileCheck )
2806 cFile.open(tmpFileName);
2807 else
2808 cFile.open(cFileName);
2810 if(!cFile.isValid())
2812 OString message("cannot open ");
2813 message += cFileName + " for writing";
2814 throw CannotDumpException(message);
2817 ret = dumpCFile(cFile);
2819 cFile.close();
2820 if (ret && bFileCheck)
2822 ret = checkFileContent(cFileName, tmpFileName);
2826 return ret;
2829 //*************************************************************************
2830 // StructureType
2831 //*************************************************************************
2832 StructureType::StructureType(TypeReader& typeReader,
2833 const OString& typeName,
2834 const TypeManager& typeMgr,
2835 const TypeDependency& typeDependencies)
2836 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
2840 StructureType::~StructureType()
2845 sal_Bool StructureType::dumpHFile(FileStream& o)
2846 throw( CannotDumpException )
2848 OString headerDefine(dumpHeaderDefine(o, "H"));
2849 o << "\n";
2851 dumpDefaultHIncludes(o);
2852 o << "\n";
2853 dumpDepIncludes(o, m_typeName, "h");
2854 o << "\n";
2856 dumpOpenExternC(o);
2858 dumpDeclaration(o);
2860 if ( m_cunoTypeLib )
2862 o << "#ifdef CUNO_TYPELIB\n"
2863 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () );\n"
2864 << "#endif\n\n";
2867 dumpCloseExternC(o);
2869 o << "#endif /* "<< headerDefine << " */\n";
2871 return sal_True;
2874 sal_Bool StructureType::dumpDeclaration(FileStream& o)
2875 throw( CannotDumpException )
2877 o << "#ifdef SAL_W32\n"
2878 << "# pragma pack(push, 8)\n"
2879 << "#elif defined(SAL_OS2)\n"
2880 << "# pragma pack(8)\n"
2881 << "#endif\n\n";
2883 o << "typedef struct _" << m_name << "\n{\n";
2884 inc();
2886 OString superType(m_reader.getSuperTypeName());
2887 if (superType.getLength() > 0)
2888 o << indent() << superType.replace('/', '_').getStr() << " _Base;\n";
2889 //dumpInheritedMembers(o, superType);
2891 sal_uInt32 fieldCount = m_reader.getFieldCount();
2892 RTFieldAccess access = RT_ACCESS_INVALID;
2893 OString fieldName;
2894 OString fieldType;
2895 sal_uInt16 i=0;
2897 for (i=0; i < fieldCount; i++)
2899 access = m_reader.getFieldAccess(i);
2901 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2902 continue;
2904 fieldName = m_reader.getFieldName(i);
2905 fieldType = m_reader.getFieldType(i);
2907 o << indent();
2908 dumpType(o, fieldType);
2909 o << " " << fieldName << ";\n";
2912 dec();
2913 o << "} " << m_name << ";\n\n";
2915 o << "#ifdef SAL_W32\n"
2916 << "# pragma pack(pop)\n"
2917 << "#elif defined(SAL_OS2)\n"
2918 << "# pragma pack()\n"
2919 << "#endif\n\n";
2921 return sal_True;
2924 sal_Bool StructureType::dumpCFile(FileStream& o)
2925 throw( CannotDumpException )
2927 dumpInclude(o, m_typeName, "h");
2928 o << "\n";
2929 dumpDefaultCIncludes(o);
2930 o << "\n";
2931 dumpDepIncludes(o, m_typeName, "h");
2932 o << "\n";
2934 dumpGetCunoType(o);
2936 return sal_True;
2939 //*************************************************************************
2940 // ExceptionType
2941 //*************************************************************************
2942 ExceptionType::ExceptionType(TypeReader& typeReader,
2943 const OString& typeName,
2944 const TypeManager& typeMgr,
2945 const TypeDependency& typeDependencies)
2946 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
2950 ExceptionType::~ExceptionType()
2955 sal_Bool ExceptionType::dumpHFile(FileStream& o)
2956 throw( CannotDumpException )
2958 OString headerDefine(dumpHeaderDefine(o, "H"));
2959 o << "\n";
2961 dumpDefaultHIncludes(o);
2962 o << "\n";
2963 dumpDepIncludes(o, m_typeName, "h");
2964 o << "\n";
2966 dumpOpenExternC(o);
2968 dumpDeclaration(o);
2970 if ( m_cunoTypeLib )
2972 o << "#ifdef CUNO_TYPELIB\n"
2973 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () );\n"
2974 << "#endif\n\n";
2977 dumpCloseExternC(o);
2979 o << "#endif /* "<< headerDefine << " */\n";
2981 return sal_True;
2984 sal_Bool ExceptionType::dumpDeclaration(FileStream& o)
2985 throw( CannotDumpException )
2987 o << "#ifdef SAL_W32\n"
2988 << "# pragma pack(push, 8)\n"
2989 << "#elif defined(SAL_OS2)\n"
2990 << "# pragma pack(8)\n"
2991 << "#endif\n\n";
2993 o << "\n/* Exception type */\ntypedef struct _" << m_name << "\n{\n";
2994 inc();
2996 OString superType(m_reader.getSuperTypeName());
2997 if (superType.getLength() > 0)
2998 o << indent() << superType.replace('/', '_').getStr() << " _Base;\n";
2999 //dumpInheritedMembers(o, superType);
3001 sal_uInt32 fieldCount = m_reader.getFieldCount();
3002 RTFieldAccess access = RT_ACCESS_INVALID;
3003 OString fieldName;
3004 OString fieldType;
3005 sal_uInt16 i = 0;
3007 for (i=0; i < fieldCount; i++)
3009 access = m_reader.getFieldAccess(i);
3011 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
3012 continue;
3014 fieldName = m_reader.getFieldName(i);
3015 fieldType = m_reader.getFieldType(i);
3017 o << indent();
3018 dumpType(o, fieldType);
3019 o << " " << fieldName << ";\n";
3022 dec();
3023 o << "} " << m_name << ";\n\n";
3025 o << "#ifdef SAL_W32\n"
3026 << "# pragma pack(pop)\n"
3027 << "#elif defined(SAL_OS2)\n"
3028 << "# pragma pack()\n"
3029 << "#endif\n\n";
3031 return sal_True;
3034 sal_Bool ExceptionType::dumpCFile(FileStream& o)
3035 throw( CannotDumpException )
3037 dumpInclude(o, m_typeName, "h");
3038 o << "\n";
3039 dumpDefaultCIncludes(o);
3040 o << "\n";
3041 dumpDepIncludes(o, m_typeName, "h");
3042 o << "\n";
3044 dumpGetCunoType(o);
3046 return sal_True;
3050 //*************************************************************************
3051 // EnumType
3052 //*************************************************************************
3053 EnumType::EnumType(TypeReader& typeReader,
3054 const OString& typeName,
3055 const TypeManager& typeMgr,
3056 const TypeDependency& typeDependencies)
3057 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
3061 EnumType::~EnumType()
3066 sal_Bool EnumType::dumpHFile(FileStream& o)
3067 throw( CannotDumpException )
3069 OString headerDefine(dumpHeaderDefine(o, "H"));
3070 o << "\n";
3072 dumpDefaultHIncludes(o);
3073 o << "\n";
3074 dumpOpenExternC(o);
3076 dumpDeclaration(o);
3078 if ( m_cunoTypeLib )
3080 o << "#ifdef CUNO_TYPELIB\n"
3081 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () );\n"
3082 << "#endif\n\n";
3085 dumpCloseExternC(o);
3087 o << "#endif /* "<< headerDefine << " */\n";
3089 return sal_True;
3092 sal_Bool EnumType::dumpDeclaration(FileStream& o)
3093 throw( CannotDumpException )
3095 o << "\ntypedef enum _" << m_name << "\n{\n";
3096 inc();
3098 sal_uInt32 fieldCount = m_reader.getFieldCount();
3099 RTFieldAccess access = RT_ACCESS_INVALID;
3100 RTConstValue constValue;
3101 OString fieldName;
3102 sal_Int32 value=0;
3103 for (sal_uInt16 i=0; i < fieldCount; i++)
3105 access = m_reader.getFieldAccess(i);
3107 if (access != RT_ACCESS_CONST)
3108 continue;
3110 fieldName = m_reader.getFieldName(i);
3111 constValue = m_reader.getFieldConstValue(i);
3113 if (constValue.m_type == RT_TYPE_INT32)
3114 value = constValue.m_value.aLong;
3115 else
3116 value++;
3118 o << indent() << m_name << "_" << fieldName << " = " << value << ",\n";
3121 o << indent() << m_name << "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n";
3123 dec();
3124 o << "} " << m_name << ";\n\n";
3126 return sal_True;
3129 sal_Bool EnumType::dumpCFile(FileStream& o)
3130 throw( CannotDumpException )
3132 dumpInclude(o, m_typeName, "h");
3133 o << "\n";
3134 dumpDefaultCIncludes(o);
3135 o << "\n";
3136 dumpGetCunoType(o);
3137 return sal_True;
3140 void EnumType::dumpGetCunoType(FileStream& o)
3142 OString typeName(m_typeName.replace('/', '_'));
3144 if ( m_cunoTypeLeak )
3146 dumpLGetCunoType(o);
3147 return;
3149 if ( !m_cunoTypeDynamic )
3151 dumpCGetCunoType(o);
3152 return;
3155 dumpOpenExternC(o);
3157 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3158 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
3159 << "#endif\n\n";
3161 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
3162 inc();
3164 o << indent() << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3165 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
3166 << indent() << "#endif\n\n";
3168 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
3169 inc();
3171 o << indent() << "typelib_static_enum_type_init( &s_pType_" << typeName << ",\n";
3172 inc(31);
3173 o << indent() << "\"" << m_typeName.replace('/', '.') << "\",\n"
3174 << indent() << m_name << "_" << m_reader.getFieldName(0) << " );\n";
3175 dec(31);
3176 dec();
3177 o << indent() << "}\n"
3178 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName <<" );\n"
3179 << indent() << "return &s_pType_" << typeName <<" );\n";
3180 dec();
3181 o << indent() << "}\n";
3183 dumpCloseExternC(o);
3186 void EnumType::dumpCGetCunoType(FileStream& o)
3188 OString typeName(m_typeName.replace('/', '_'));
3190 dumpOpenExternC(o);
3192 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3193 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
3194 << "#endif\n\n";
3196 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
3197 inc();
3199 o << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3200 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
3201 << "#endif\n\n";
3203 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
3204 inc();
3205 o << indent() << "oslMutex * pMutex = osl_getGlobalMutex();\n"
3206 << indent() << "osl_acquireMutex( pMutex );\n";
3208 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
3209 inc();
3210 o << indent() << "rtl_uString * pTypeName = 0;\n"
3211 << indent() << "_typelib_TypeDescription * pTD = 0;\n";
3213 sal_uInt32 count = m_reader.getFieldCount();
3214 o << indent() << "rtl_uString* enumValueNames[" << count << "];\n"
3215 << indent() << "sal_Int32 enumValues[" << count << "];\n";
3216 sal_uInt32 i;
3217 for (i = 0; i < count; i++)
3219 o << indent() << "rtl_uString * pEnumValue" << i << " = 0;\n";
3222 o << indent() << "rtl_uString_newFromAscii( &pTypeName, \""
3223 << m_typeName.replace('/', '.') << "\") );\n\n";
3225 for (i = 0; i < count; i++)
3227 o << indent() << "rtl_uString_newFromAscii( &pEnumValue" << i << ", \""
3228 << m_reader.getFieldName((sal_uInt16)i) << "\" );\n";
3229 o << indent() << "enumValueNames[" << i << "] = pEnumValue" << i << ";\n";
3232 RTConstValue constValue;
3233 sal_Int32 value=0;
3234 for (i = 0; i < count; i++)
3236 o << indent() << "enumValues[" << i << "] = ";
3237 constValue = m_reader.getFieldConstValue((sal_uInt16)i);
3238 if (constValue.m_type == RT_TYPE_INT32)
3239 value = constValue.m_value.aLong;
3240 else
3241 value++;
3242 o << value << ";\n";
3245 o << "\n" << indent() << "typelib_typedescription_newEnum( &pTD,\n";
3246 inc();
3247 o << indent() << "pTypeName,\n"
3248 << indent() << "(sal_Int32)" << m_name << "_" << m_reader.getFieldName(0) << ",\n"
3249 << indent() << count << ", enumValueNames, enumValues );\n\n";
3250 dec();
3252 o << indent() << "typelib_typedescription_register( &pTD );\n";
3254 o << indent() << "typelib_typedescriptionreference_new( &s_pType_ " << typeName
3255 << getTypeClass(OString(), sal_True) << ", pTD);\n\n";
3257 o << indent() << "typelib_typedescription_release( pTD );\n"
3258 << indent() << "rtl_uString_release( pTypeName );\n";
3259 for (i = 0; i < count; i++)
3261 o << indent() << "rtl_uString_release( pEnumValue" << i << " );\n";
3264 dec();
3265 o << indent() << "}\n";
3266 o << indent() << "osl_releaseMutex( pMutex );\n";
3267 dec();
3268 o << indent() << "}\n\n"
3269 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName <<" );\n"
3270 << indent() << "return &s_pType_" << typeName <<" );\n";
3272 dec();
3273 o << "}\n";
3275 dumpCloseExternC(o);
3278 //*************************************************************************
3279 // TypeDefType
3280 //*************************************************************************
3281 TypeDefType::TypeDefType(TypeReader& typeReader,
3282 const OString& typeName,
3283 const TypeManager& typeMgr,
3284 const TypeDependency& typeDependencies)
3285 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
3289 TypeDefType::~TypeDefType()
3294 sal_Bool TypeDefType::dumpHFile(FileStream& o)
3295 throw( CannotDumpException )
3297 OString headerDefine(dumpHeaderDefine(o, "H"));
3298 o << "\n";
3300 dumpDefaultHIncludes(o);
3301 o << "\n";
3302 dumpDepIncludes(o, m_typeName, "h");
3303 o << "\n";
3305 dumpOpenExternC(o);
3307 dumpDeclaration(o);
3309 if ( m_cunoTypeLib )
3311 o << "#ifdef CUNO_TYPELIB\n"
3312 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () );\n"
3313 << "#endif\n\n";
3316 dumpCloseExternC(o);
3318 o << "#endif /* "<< headerDefine << " */\n";
3320 return sal_True;
3323 sal_Bool TypeDefType::dumpDeclaration(FileStream& o)
3324 throw( CannotDumpException )
3326 o << "\ntypedef ";
3327 dumpType(o, m_reader.getSuperTypeName());
3328 o << " " << m_name << ";\n\n";
3330 return sal_True;
3333 sal_Bool TypeDefType::dumpCFile(FileStream& o)
3334 throw( CannotDumpException )
3336 dumpInclude(o, m_typeName, "h");
3337 o << "\n";
3338 dumpDefaultCIncludes(o);
3339 o << "\n";
3340 dumpDepIncludes(o, m_typeName, "h");
3341 o << "\n";
3342 dumpGetCunoType(o);
3343 return sal_True;
3346 void TypeDefType::dumpGetCunoType(FileStream& o)
3348 if ( m_cunoTypeLeak )
3350 dumpLGetCunoType(o);
3351 return;
3353 if ( !m_cunoTypeDynamic )
3355 dumpCGetCunoType(o);
3356 return;
3360 void TypeDefType::dumpCGetCunoType(FileStream& o)
3364 void TypeDefType::dumpLGetCunoType(FileStream& o)
3368 //*************************************************************************
3369 // produceType
3370 //*************************************************************************
3371 sal_Bool produceType(const OString& typeName,
3372 TypeManager& typeMgr,
3373 TypeDependency& typeDependencies,
3374 CunoOptions* pOptions)
3375 throw( CannotDumpException )
3377 if (typeDependencies.isGenerated(typeName))
3378 return sal_True;
3380 TypeReader reader(typeMgr.getTypeReader(typeName));
3382 if (!reader.isValid())
3384 if (typeName.equals("/"))
3385 return sal_True;
3386 else
3387 return sal_False;
3390 if( !checkTypeDependencies(typeMgr, typeDependencies, typeName))
3391 return sal_False;
3393 RTTypeClass typeClass = reader.getTypeClass();
3394 sal_Bool ret = sal_False;
3395 switch (typeClass)
3397 case RT_TYPE_INTERFACE:
3399 InterfaceType iType(reader, typeName, typeMgr, typeDependencies);
3400 ret = iType.dump(pOptions);
3401 if (ret) typeDependencies.setGenerated(typeName);
3402 ret = iType.dumpDependedTypes(pOptions);
3404 break;
3405 case RT_TYPE_MODULE:
3407 ModuleType mType(reader, typeName, typeMgr, typeDependencies);
3408 if (mType.hasConstants())
3410 ret = mType.dump(pOptions);
3411 if (ret) typeDependencies.setGenerated(typeName);
3412 // ret = mType.dumpDependedTypes(pOptions);
3413 } else
3415 typeDependencies.setGenerated(typeName);
3416 ret = sal_True;
3419 break;
3420 case RT_TYPE_STRUCT:
3422 StructureType sType(reader, typeName, typeMgr, typeDependencies);
3423 ret = sType.dump(pOptions);
3424 if (ret) typeDependencies.setGenerated(typeName);
3425 ret = sType.dumpDependedTypes(pOptions);
3427 break;
3428 case RT_TYPE_ENUM:
3430 EnumType enType(reader, typeName, typeMgr, typeDependencies);
3431 ret = enType.dump(pOptions);
3432 if (ret) typeDependencies.setGenerated(typeName);
3433 ret = enType.dumpDependedTypes(pOptions);
3435 break;
3436 case RT_TYPE_EXCEPTION:
3438 ExceptionType eType(reader, typeName, typeMgr, typeDependencies);
3439 ret = eType.dump(pOptions);
3440 if (ret) typeDependencies.setGenerated(typeName);
3441 ret = eType.dumpDependedTypes(pOptions);
3443 break;
3444 case RT_TYPE_TYPEDEF:
3446 TypeDefType tdType(reader, typeName, typeMgr, typeDependencies);
3447 ret = tdType.dump(pOptions);
3448 if (ret) typeDependencies.setGenerated(typeName);
3449 ret = tdType.dumpDependedTypes(pOptions);
3451 break;
3452 case RT_TYPE_CONSTANTS:
3454 ConstantsType cType(reader, typeName, typeMgr, typeDependencies);
3455 if (cType.hasConstants())
3457 ret = cType.dump(pOptions);
3458 if (ret) typeDependencies.setGenerated(typeName);
3459 // ret = cType.dumpDependedTypes(pOptions);
3460 } else
3462 typeDependencies.setGenerated(typeName);
3463 ret = sal_True;
3466 break;
3467 case RT_TYPE_SERVICE:
3468 case RT_TYPE_OBJECT:
3469 ret = sal_True;
3470 break;
3473 return ret;
3476 //*************************************************************************
3477 // scopedName
3478 //*************************************************************************
3479 OString scopedName(const OString& scope, const OString& type,
3480 sal_Bool bNoNameSpace)
3482 sal_Int32 nPos = type.lastIndexOf( '/' );
3483 if (nPos == -1)
3484 return type;
3486 if (bNoNameSpace)
3487 return type.copy(nPos+1);
3489 OStringBuffer tmpBuf(type.getLength()*2);
3490 nPos = 0;
3493 tmpBuf.append("::");
3494 tmpBuf.append(type.getToken(0, '/', nPos));
3495 } while( nPos != -1 );
3497 return tmpBuf.makeStringAndClear();
3500 //*************************************************************************
3501 // shortScopedName
3502 //*************************************************************************
3503 OString shortScopedName(const OString& scope, const OString& type,
3504 sal_Bool bNoNameSpace)
3506 sal_Int32 nPos = type.lastIndexOf( '/' );
3507 if( nPos == -1 )
3508 return OString();
3510 if (bNoNameSpace)
3511 return OString();
3513 // scoped name only if the namespace is not equal
3514 if (scope.lastIndexOf('/') > 0)
3516 OString tmpScp(scope.copy(0, scope.lastIndexOf('/')));
3517 OString tmpScp2(type.copy(0, nPos));
3519 if (tmpScp == tmpScp2)
3520 return OString();
3523 OString aScope( type.copy( 0, nPos ) );
3524 OStringBuffer tmpBuf(aScope.getLength()*2);
3526 nPos = 0;
3529 tmpBuf.append("::");
3530 tmpBuf.append(aScope.getToken(0, '/', nPos));
3531 } while( nPos != -1 );
3533 return tmpBuf.makeStringAndClear();