1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cunotype.cxx,v $
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"
35 #include <rtl/alloc.h>
36 #include <rtl/ustring.hxx>
37 #include <rtl/strbuf.hxx>
39 #include "cunotype.hxx"
40 #include "cunooptions.hxx"
44 //*************************************************************************
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
)
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('/');
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
);
84 sal_Bool
CunoType::isNestedTypeByName(const ::rtl::OString
& type
)
86 sal_Bool ret
= sal_False
;
88 sal_Int32 i
= type
.lastIndexOf('/');
92 OString
outerTypeName(type
.copy(0, i
));
93 ret
= (m_typeMgr
.getTypeClass(outerTypeName
) == RT_TYPE_INTERFACE
);
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));
114 sal_Bool
CunoType::dump(CunoOptions
* pOptions
)
115 throw( CannotDumpException
)
117 sal_Bool ret
= sal_False
;
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
;
130 if (pOptions
->isValid("-O"))
131 outPath
= pOptions
->getOption("-O");
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
);
145 if ( bFileExists
&& pOptions
->isValid("-Gc") )
147 tmpFileName
= createFileNameFromType(outPath
, m_typeName
, ".tmh");
148 bFileCheck
= sal_True
;
151 if ( !bFileExists
|| bFileCheck
)
156 hFile
.open(tmpFileName
);
158 hFile
.open(hFileName
);
162 OString
message("cannot open ");
163 message
+= hFileName
+ " for writing";
164 throw CannotDumpException(message
);
167 ret
= dumpHFile(hFile
);
170 if (ret
&& bFileCheck
)
172 ret
= checkFileContent(hFileName
, tmpFileName
);
178 bFileExists
= sal_False
;
179 bFileCheck
= sal_False
;
181 if (pOptions
->isValid("-OC"))
182 outPath
= pOptions
->getOption("-OC");
186 OString cFileName
= createFileNameFromType(outPath
, m_typeName
, ".c");
188 if ( pOptions
->isValid("-G") || pOptions
->isValid("-Gc") )
190 bFileExists
= fileExists( cFileName
);
194 if ( bFileExists
&& pOptions
->isValid("-Gc") )
196 tmpFileName
= createFileNameFromType(outPath
, m_typeName
, ".tmc");
197 bFileCheck
= sal_True
;
200 if ( !bFileExists
|| bFileCheck
)
205 cFile
.open(tmpFileName
);
207 cFile
.open(cFileName
);
211 OString
message("cannot open ");
212 message
+= cFileName
+ " for writing";
213 throw CannotDumpException(message
);
216 ret
= dumpCFile(cFile
);
219 if (ret
&& bFileCheck
)
221 ret
= checkFileContent(cFileName
, tmpFileName
);
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();
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
,
250 fprintf(stderr
, "%s ERROR: %s\n",
251 pOptions
->getProgramName().getStr(),
252 OString("cannot dump Type '" + typeName
+ "'").getStr());
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
);
273 length
+= m_name
.getLength() + 1;
275 OStringBuffer
tmpBuf(length
);
278 tmpBuf
.append(m_typeName
);
282 tmpBuf
.append(m_name
);
285 tmpBuf
.append(prefix
);
288 OString
tmp(tmpBuf
.makeStringAndClear().replace('/', '_').toAsciiUpperCase());
290 o
<< "#ifndef " << tmp
<< "\n#define " << tmp
<< "\n";
295 void CunoType::dumpDefaultHIncludes(FileStream
& o
)
297 o
<< "#ifndef _UNO_CUNO_H_\n"
298 << "#include <uno/cuno.h>\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"
311 void CunoType::dumpDefaultCIncludes(FileStream
& o
)
313 o
<< "#ifndef _OSL_MUTEX_H_\n"
314 << "#include <osl/mutex.h>\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
);
323 length
+= m_name
.getLength() + 1;
325 OStringBuffer
tmpBuf(length
);
328 tmpBuf
.append(typeName
);
332 tmpBuf
.append(m_name
);
335 tmpBuf
.append(prefix
);
338 OString
tmp(tmpBuf
.makeStringAndClear().replace('/', '_').toAsciiUpperCase());
340 length
= 1 + typeName
.getLength() + strlen(prefix
);
342 length
+= m_name
.getLength() + 1;
344 tmpBuf
.ensureCapacity(length
);
345 tmpBuf
.append(typeName
);
349 tmpBuf
.append(m_name
);
352 tmpBuf
.append(prefix
);
354 o
<< "#ifndef " << tmp
<< "\n#include <";
357 o
<< tmpBuf
.makeStringAndClear();
360 o
<< tmpBuf
.makeStringAndClear();
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;
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
;
384 relType
= relType
.copy(index
+1);
386 if (isNestedTypeByName(relType
) && hasNestedType(relType
))
387 bDumpThisType
= sal_False
;
391 OString
defPrefix("H");
392 if (sPrefix
.equals("H"))
395 if (seqNum
> 0 && !bSequenceDumped
)
397 bSequenceDumped
= sal_True
;
398 o
<< "#ifndef _UNO_SEQUENCE2_" << defPrefix
399 << "_\n#include <uno/sequence2." << defPrefix
.toAsciiLowerCase()
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));
422 // dumpNameSpace(o, sal_True, sal_False, outerNamespace);
423 // o << "\nclass " << outerClass << "::" << innerClass << ";\n";
424 // dumpNameSpace(o, sal_False, sal_False, outerNamespace);
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";
439 if (isNestedTypeByName(relType
))
441 sal_Int32 iLastS
= relType
.lastIndexOf('/');
443 OString
outerNamespace(relType
.copy(0,iLastS
));
445 dumpInclude(o
, outerNamespace
, prefix
);
448 dumpInclude(o
, relType
, prefix
);
452 if (isNestedTypeByName(relType
))
454 sal_Int32 iLastS
= relType
.lastIndexOf('/');
456 OString
outerNamespace(relType
.copy(0,iLastS
));
458 dumpInclude(o
, outerNamespace
, prefix
);
461 dumpInclude(o
, relType
, prefix
);
464 if (relType
== "any")
466 o
<< "#ifndef _UNO_ANY2_H_\n"
467 << "#include <uno/any2.h>\n"
470 if (relType
== "type")
472 o
<< "#ifndef _TYPELIB_TYPEDESCRIPTION_H_\n"
473 << "#include <typelib/typedescription.h>\n"
476 if (relType
== "string" && sPrefix
.equals("H"))
478 o
<< "#ifndef _RTL_USTRING_H_\n"
479 << "#include <rtl/ustring.h>\n"
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"
507 void CunoType::dumpCloseExternC(FileStream
& o
)
509 o
<< "#ifdef __cplusplus\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"
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";
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";
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";
539 o
<< indent() << "typelib_static_type_init( &s_pType_" << typeName
<< ", "
540 << getTypeClass(m_typeName
, sal_True
) << ", \"" << m_typeName
.replace('/', '.') << "\" );\n";
542 o
<< indent() << "}\n";
543 o
<< indent() << "return * reinterpret_cast< ::com::sun::star::uno::Type * >( &s_pType_"
544 << typeName
<<" );\n";
546 o
<< indent() << "}\n";
551 void CunoType::dumpGetCunoType(FileStream
& o
)
553 OString
typeName(m_typeName
.replace('/', '_'));
555 if ( m_cunoTypeLeak
)
560 if ( !m_cunoTypeDynamic
)
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"
575 o
<< "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () )\n{\n";
578 if ( m_typeName
.equals("com/sun/star/uno/Exception") )
580 o
<< indent() << "return typelib_static_type_getByTypeClass( typelib_TypeClass_EXCEPTION );\n";
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";
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
;
599 o
<< indent() << "typelib_TypeDescriptionReference * pBaseType = 0;\n";
603 sal_uInt32 count
= getMemberCount();
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";
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
)
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";
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 ), "
660 o
<< "pBaseType, " << count
<< ", ";
664 o
<< "0, " << count
<< ", ";
669 o
<< " aMemberRefs );\n";
675 o
<< indent() << "}\n"
676 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName
<< " );\n"
677 << indent() << "return &_pType_" << typeName
<<" );\n";
680 o
<< indent() << "}\n";
685 void CunoType::dumpCGetCunoType(FileStream
& o
)
687 OString
typeName(m_typeName
.replace('/', '_'));
691 o
<< "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
692 << "static typelib_TypeDescriptionReference * s_pType_" << typeName
<< " = 0;\n"
695 o
<< "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () )\n{\n";
698 o
<< "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
699 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName
<< " = 0;\n"
702 o
<< indent() << "if ( !s_pType_" << typeName
<< " )\n" << indent() << "{\n";
704 o
<< indent() << "oslMutex * pMutex = osl_getGlobalMutex();\n"
705 << indent() << "osl_acquireMutex( pMutex );\n";
707 o
<< indent() << "if ( !s_pType_" << typeName
<< " )\n" << indent() << "{\n";
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
;
721 o
<< indent() << "typelib_CompoundMember_Init aMembers["
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
)
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
);
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
)
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";
773 o
<< indent() << "&pTD,\n" << indent()
774 << getTypeClass(OString(), sal_True
) << ", pTypeName,\n";
776 if (superType
.getLength() > 0)
777 o
<< indent() << "pSuperType,\n";
779 o
<< indent() << "0,\n";
783 o
<< indent() << count
<< ",\n" << indent() << "aMembers );\n\n";
786 o
<< indent() << count
<< ",\n" << indent() << "0 );\n\n";
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
)
806 o
<< indent() << "rtl_uString_release( pMemberName" << i
<< " );\n"
807 << indent() << "rtl_uString_release( pMemberType" << i
<< " );\n";
812 o
<< indent() << "}\n";
813 o
<< indent() << "osl_releaseMutex( pMutex );\n";
815 o
<< indent() << "}\n"
816 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName
<< " );\n"
817 << indent() << "return &s_pType_" << typeName
<<" );\n";
824 void CunoType::dumpCppuGetTypeMemberDecl(FileStream
& o
, CunoTypeDecl eDeclFlag
)
826 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
827 RTFieldAccess access
= RT_ACCESS_INVALID
;
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
)
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
)
867 sal_uInt32
CunoType::checkInheritedMemberCount(const TypeReader
* pReader
)
869 sal_Bool bSelfCheck
= sal_True
;
872 bSelfCheck
= sal_False
;
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
);
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
)
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
;
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
);
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)
954 rtTypeClass
= m_typeMgr
.getTypeClass(typeName
);
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";
966 case RT_TYPE_INTERFACE
:
967 return bCStyle
? "typelib_TypeClass_INTERFACE" : "::com::sun::star::uno::TypeClass_INTERFACE";
970 return bCStyle
? "typelib_TypeClass_MODULE" : "::com::sun::star::uno::TypeClass_MODULE";
973 return bCStyle
? "typelib_TypeClass_STRUCT" : "::com::sun::star::uno::TypeClass_STRUCT";
976 return bCStyle
? "typelib_TypeClass_ENUM" : "::com::sun::star::uno::TypeClass_ENUM";
978 case RT_TYPE_EXCEPTION
:
979 return bCStyle
? "typelib_TypeClass_EXCEPTION" : "::com::sun::star::uno::TypeClass_EXCEPTION";
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";
988 case RT_TYPE_SERVICE
:
989 return bCStyle
? "typelib_TypeClass_SERVICE" : "::com::sun::star::uno::TypeClass_SERVICE";
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";
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 ";
1048 for (i
=0; i
< seqNum
; i
++)
1052 o
<< relType
.replace( '/', '.');
1053 for (i
=0; i
< seqNum
; i
++)
1057 o
<< "*/ uno_Sequence *";
1058 if (bPointer
) o
<< "*";
1063 case RT_TYPE_INTERFACE
:
1064 o
<< relType
.replace('/', '_') << " *";
1066 case RT_TYPE_INVALID
:
1068 OString
tmp(getBaseType(relType
));
1069 if (tmp
.getLength() > 0)
1072 if ( bParam
&& !bPointer
&& relType
.equals("any") )
1075 throw CannotDumpException("Unknown type '" + relType
+ "', incomplete type library.");
1078 case RT_TYPE_STRUCT
:
1079 case RT_TYPE_EXCEPTION
:
1080 o
<< relType
.replace('/', '_');
1081 if ( bParam
&& !bPointer
) o
<< " *";
1084 case RT_TYPE_TYPEDEF
:
1085 o
<< relType
.replace('/', '_');
1089 if (bPointer
) o
<< "*";
1092 OString
CunoType::getBaseType(const OString
& type
)
1094 if (type
.equals("long"))
1096 if (type
.equals("short"))
1098 if (type
.equals("hyper"))
1100 if (type
.equals("string"))
1101 return "rtl_uString *";
1102 if (type
.equals("boolean"))
1104 if (type
.equals("char"))
1105 return "sal_Unicode";
1106 if (type
.equals("byte"))
1108 if (type
.equals("any"))
1110 if (type
.equals("type"))
1111 return "typelib_TypeDescriptionReference *";
1112 if (type
.equals("float"))
1114 if (type
.equals("double"))
1116 if (type
.equals("octet"))
1118 if (type
.equals("void"))
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";
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
)
1141 o
<< indent() << "ppTypeRef = ";
1145 o
<< "getCUnoType_" << type
.replace('/', '_') << "()";
1148 o
<< ";\n" << indent() << "typelib_typedescriptionreference_release( *ppTypeRef );\n";
1152 if (isBaseType(type
))
1157 if (eDeclFlag
== CUNOTYPEDECL_NOINTERFACES
&&
1158 m_typeMgr
.getTypeClass(relType
) == RT_TYPE_INTERFACE
)
1161 if ( type
.equals("type") )
1165 o
<< indent() << "ppTypeRef = ";
1169 o
<< indent() << "getCUnoType_" << type
.replace('/', '_') << "()";
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
);
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) << ")";
1226 BASETYPE
CunoType::isBaseType(const OString
& type
)
1228 if (type
.equals("long"))
1230 if (type
.equals("short"))
1232 if (type
.equals("hyper"))
1234 if (type
.equals("string"))
1236 if (type
.equals("boolean"))
1238 if (type
.equals("char"))
1240 if (type
.equals("byte"))
1242 if (type
.equals("any"))
1244 if (type
.equals("float"))
1246 if (type
.equals("double"))
1248 if (type
.equals("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
;
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
;
1270 sIdentifier
+= OString("seq");
1272 if ( --seqNum
== 0 )
1274 sIdentifier
+= OString("_");
1278 if ( isBaseType(relType
) )
1280 sIdentifier
+= relType
.replace(' ', '_');
1283 sIdentifier
+= relType
.replace('/', '_');
1290 OString
CunoType::checkSpecialCunoType(const OString
& type
)
1292 OString
baseType(type
);
1294 RegistryTypeReaderLoader
& rReaderLoader
= getRegistryTypeReaderLoader();
1297 sal_uInt8
* pBuffer
=NULL
;
1298 RTTypeClass typeClass
;
1299 sal_Bool isTypeDef
= (m_typeMgr
.getTypeClass(baseType
) == RT_TYPE_TYPEDEF
);
1304 reader
= m_typeMgr
.getTypeReader(baseType
);
1306 if (reader
.isValid())
1308 typeClass
= reader
.getTypeClass();
1310 if (typeClass
== RT_TYPE_TYPEDEF
)
1311 baseType
= reader
.getSuperTypeName();
1313 isTypeDef
= sal_False
;
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);
1334 seqPrefix
= OString();
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
);
1350 arrayPrefix
= OString();
1355 OString
CunoType::checkRealBaseType(const OString
& type
, sal_Bool bResolveTypeOnly
)
1359 OString completePrefix
;
1361 sal_Bool bSeqType
= sal_True
;
1363 if ( !isSeqType(type
, baseType
, completePrefix
) )
1364 isArrayType(type
, baseType
, completePrefix
);
1366 RegistryTypeReaderLoader
& rReaderLoader
= getRegistryTypeReaderLoader();
1369 sal_uInt8
* pBuffer
=NULL
;
1370 RTTypeClass typeClass
;
1371 sal_Bool mustBeChecked
= (m_typeMgr
.getTypeClass(baseType
) == RT_TYPE_TYPEDEF
);
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
;
1390 mustBeChecked
= sal_False
;
1397 if ( bResolveTypeOnly
)
1399 if ( completePrefix
.getLength() > 0 )
1401 baseType
= bSeqType
? (completePrefix
+ baseType
) : ( baseType
+ completePrefix
);
1407 void CunoType::dumpConstantValue(FileStream
& o
, sal_uInt16 index
)
1409 RTConstValue constValue
= m_reader
.getFieldConstValue(index
);
1411 switch (constValue
.m_type
)
1414 if (constValue
.m_value
.aBool
)
1422 snprintf(tmp
, sizeof(tmp
), "0x%x", (sal_Int8
)constValue
.m_value
.aByte
);
1423 o
<< "(sal_Int8)" << tmp
;
1427 o
<< "(sal_Int16)" << constValue
.m_value
.aShort
;
1429 case RT_TYPE_UINT16
:
1430 o
<< "(sal_uInt16)" << constValue
.m_value
.aUShort
;
1433 o
<< "(sal_Int32)" << constValue
.m_value
.aLong
;
1435 case RT_TYPE_UINT32
:
1436 o
<< "(sal_uInt32)" << constValue
.m_value
.aULong
;
1440 ::rtl::OString
tmp( OString::valueOf(constValue
.m_value
.aHyper
) );
1441 o
<< "(sal_Int64)" << tmp
.getStr() << "L";
1444 case RT_TYPE_UINT64
:
1446 ::rtl::OString
tmp( OString::valueOf((sal_Int64
)constValue
.m_value
.aUHyper
) );
1447 o
<< "(sal_uInt64)" << tmp
.getStr() << "L";
1452 ::rtl::OString
tmp( OString::valueOf(constValue
.m_value
.aFloat
) );
1453 o
<< "(float)" << tmp
.getStr();
1456 case RT_TYPE_DOUBLE
:
1458 ::rtl::OString
tmp( OString::valueOf(constValue
.m_value
.aDouble
) );
1459 o
<< "(double)" << tmp
.getStr();
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() << "\")";
1472 void CunoType::inc(sal_uInt32 num
)
1474 m_indentLength
+= num
;
1477 void CunoType::dec(sal_uInt32 num
)
1479 if (m_indentLength
- num
< 0)
1482 m_indentLength
-= num
;
1485 OString
CunoType::indent()
1487 OStringBuffer
tmp(m_indentLength
);
1489 for (sal_uInt32 i
=0; i
< m_indentLength
; i
++)
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
++)
1504 return tmp
.makeStringAndClear();
1507 //*************************************************************************
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"));
1532 dumpDefaultHIncludes(o
);
1534 dumpDepIncludes(o
, m_typeName
, "h");
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";
1546 if ( m_cunoTypeLib
)
1548 o
<< "#ifdef CUNO_TYPELIB\n"
1549 << "typelib_TypeDescriptionReference * SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW( () );\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";
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() << "{";
1600 OString
superType(m_reader
.getSuperTypeName());
1601 if (superType
.getLength() > 0)
1602 dumpInheritedFunctions(o
, superType
);
1604 if (getNestedTypeNames().getLength() > 0)
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);
1630 case RT_TYPE_STRUCT:
1632 StructureType sType(reader, nestedName, m_typeMgr, m_dependencies);
1633 sType.dumpDeclaration(o);
1638 EnumType enType(reader, nestedName, m_typeMgr, m_dependencies);
1639 enType.dumpDeclaration(o);
1642 case RT_TYPE_EXCEPTION:
1644 ExceptionType eType(reader, nestedName, m_typeMgr, m_dependencies);
1645 eType.dumpDeclaration(o);
1648 case RT_TYPE_TYPEDEF:
1650 TypeDefType tdType(reader, nestedName, m_typeMgr, m_dependencies);
1651 tdType.dumpDeclaration(o);
1662 dumpAttributes(o
, m_name
, m_reader
);
1663 dumpMethods(o
, m_name
, m_reader
);
1666 o
<< "} " << m_name
<< "_ftab;\n\n";
1671 sal_Bool
InterfaceType::dumpCFile(FileStream
& o
)
1672 throw( CannotDumpException
)
1674 dumpInclude(o
, m_typeName
, "h");
1676 dumpDefaultCIncludes(o
);
1678 dumpDepIncludes(o
, m_typeName
, "h");
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);
1707 case RT_TYPE_STRUCT:
1709 StructureType sType(reader, nestedName, m_typeMgr, m_dependencies);
1710 sType.dumpGetCunoType(o);
1715 EnumType enType(reader, nestedName, m_typeMgr, m_dependencies);
1716 enType.dumpGetCunoType(o);
1719 case RT_TYPE_EXCEPTION:
1721 ExceptionType eType(reader, nestedName, m_typeMgr, m_dependencies);
1722 eType.dumpGetCunoType(o);
1725 case RT_TYPE_TYPEDEF:
1727 TypeDefType tdType(reader, nestedName, m_typeMgr, m_dependencies);
1728 tdType.dumpGetCunoType(o);
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
;
1749 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
1751 access
= reader
.getFieldAccess(i
);
1753 if (access
== RT_ACCESS_CONST
|| access
== RT_ACCESS_INVALID
)
1756 fieldName
= reader
.getFieldName(i
);
1757 fieldType
= reader
.getFieldType(i
);
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
);
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")))
1785 o
<< indent() << "cuno_ErrorCode (SAL_CALL *set" << fieldName
<< ")( "
1786 << interfaceType
<< " *, uno_Any *, ";
1787 dumpType(o
, fieldType
, sal_False
, sal_False
, bParam
);
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") )
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";
1825 if ( methodName
.equals("acquire") || methodName
.equals("release") )
1827 bWithRunTimeExcp
= sal_False
;
1833 o
<< "\n" << indent() << "/* Methods of " << interfaceType
<< " */\n";
1836 o
<< indent() << "cuno_ErrorCode (SAL_CALL *" << methodName
<< ")( "
1837 << interfaceType
<< " *";
1838 if ( excCount
|| bWithRunTimeExcp
)
1842 if ( !isVoid(returnType
) )
1845 dumpType(o
, returnType
, sal_False
, sal_True
);
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
<< ", ";
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")))
1874 case RT_PARAM_INOUT
:
1875 bPointer
= sal_True
;
1879 dumpType(o
, paramType
, sal_False
, bPointer
, bParam
);
1885 void InterfaceType::dumpGetCunoType(FileStream
& o
)
1887 OString
typeName(m_typeName
.replace('/', '_'));
1889 if ( m_cunoTypeLeak
)
1891 dumpLGetCunoType(o
);
1894 if ( !m_cunoTypeDynamic
)
1896 dumpCGetCunoType(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"
1909 o
<< "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () )\n{\n";
1912 if ( m_typeName
.equals("com/sun/star/uno/XInterface") )
1914 o
<< indent() << "return typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE );\n";
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";
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('/', '.') << "\", ";
1938 o
<< "pSuperType );\n";
1945 o
<< indent() << "}\n"
1946 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName
<< " );\n"
1947 << indent() << "return &s_pType_" << typeName
<<" );\n";
1950 o
<< indent() << "}\n";
1952 dumpCloseExternC(o
);
1955 void InterfaceType::dumpCGetCunoType(FileStream
& o
)
1957 OString
typeName(m_typeName
.replace('/', '_'));
1961 o
<< "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1962 << "static typelib_TypeDescriptionReference * s_pType_" << typeName
<< " = 0;\n"
1965 o
<< "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () )\n{\n";
1968 o
<< "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1969 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName
<< " = 0;\n"
1972 o
<< indent() << "if ( !s_pType_" << typeName
<< " )\n" << indent() << "{\n";
1974 o
<< indent() << "oslMutex * pMutex = osl_getGlobalMutex();\n"
1975 << indent() << "osl_acquireMutex( pMutex );\n";
1977 o
<< indent() << "if ( !s_pType_" << typeName
<< " )\n" << indent() << "{\n";
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";
1990 o
<< indent() << "typelib_TypeDescriptionReference * pMembers[" << count
<< "] = { ";
1991 for (sal_uInt32 i
= 0; i
< count
; i
++)
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";
2014 sal_uInt32 index
= 0;
2015 dumpCUnoAttributeRefs(o
, index
);
2016 dumpCUnoMethodRefs(o
, index
);
2019 o
<< "\n" << indent() << "typelib_typedescription_newInterface(\n";
2021 o
<< indent() << "&pTD,\n"
2022 << indent() << "pTypeName, ";
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
);
2031 if (superType
.getLength() > 0)
2032 o
<< indent() << "pSuperType,\n";
2034 o
<< indent() << "0,\n";
2038 o
<< indent() << count
<< ",\n" << indent() << "pMembers );\n\n";
2041 o
<< indent() << count
<< ",\n" << indent() << "0 );\n\n";
2045 o
<< indent() << "typelib_typedescription_register( (typelib_TypeDescription**)&pTD );\n";
2048 for (sal_uInt16 i
=0; i
< count
; i
++)
2050 o
<< indent() << "typelib_typedescriptionreference_release( pMembers["
2054 o
<< indent() << "typelib_typedescription_release( (typelib_TypeDescription*)pTD );\n";
2056 if (superType
.getLength() > 0)
2057 o
<< indent() << "typelib_typedescription_release( pSuperType );\n\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";
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
);
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
);
2086 o
<< indent() << "}\n";
2087 o
<< indent() << "osl_releaseMutex( pMutex );\n";
2089 o
<< indent() << "}\n\n"
2090 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName
<< " );\n"
2091 << indent() << "return &s_pType_" << typeName
<< ";\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
)
2111 o
<< indent() << "rtl_uString_release( pAttributeName" << i
<< " );\n";
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
++)
2127 o
<< indent() << "rtl_uString_release( pMethodName" << i
<< " );\n";
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
;
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
)
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["
2154 o
<< indent() << "typelib_TypeClass_INTERFACE_ATTRIBUTE,\n"
2155 << indent() << "pAttributeName" << i
<< " );\n";
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["
2176 o
<< indent() << "typelib_TypeClass_INTERFACE_METHOD,\n"
2177 << indent() << "pMethodName" << i
<< " );\n";
2183 sal_uInt32
InterfaceType::getMemberCount()
2185 sal_uInt32 count
= m_reader
.getMethodCount();
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
;
2205 sal_uInt32
InterfaceType::checkInheritedMemberCount(const TypeReader
* pReader
)
2207 sal_uInt32 cout
= 0;
2208 sal_Bool bSelfCheck
= sal_True
;
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
);
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
)
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
;
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
)
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";
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";
2287 o
<< indent() << "sal_False );\n";
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
;
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";
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";
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";
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";
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";
2398 o
<< indent() << absoluteIndex
++ << ", ";
2399 if (methodMode
== RT_MODE_ONEWAY
|| methodMode
== RT_MODE_ONEWAY_CONST
)
2402 o
<< "sal_False,\n";
2403 o
<< indent() << "pMethodName" << i
<< ",\n";
2404 o
<< indent() << getTypeClass(returnType
, sal_True
) << ", pReturnType" << i
<< ",\n";
2406 o
<< indent() << paramCount
<< ", pParameters,\n";
2408 o
<< indent() << "0, 0,\n";
2410 if ( excCount
|| bWithRuntimeException
)
2412 o
<< indent() << excCount
+ 1 << ", pExceptions );\n";
2415 o
<< indent() << "0, 0 );\n";
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";
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
;
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
)
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
);
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 //*************************************************************************
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
;
2538 if (pOptions
->isValid("-O"))
2539 outPath
= pOptions
->getOption("-O");
2541 OString
tmpName(m_typeName
);
2543 if (tmpName
.equals("/"))
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
);
2561 if ( bFileExists
&& pOptions
->isValid("-Gc") )
2563 tmpFileName
= createFileNameFromType(outPath
, m_typeName
, ".tml");
2564 bFileCheck
= sal_True
;
2567 if ( !bFileExists
|| bFileCheck
)
2572 hFile
.open(tmpFileName
);
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
);
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 );
2602 if ( bFileExists && pOptions->isValid("-Gc") )
2604 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmc");
2605 bFileCheck = sal_True;
2609 if ( !bFileExists || bFileCheck )
2614 cFile.open(tmpFileName);
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);
2628 if (ret && bFileCheck)
2630 ret = checkFileContent(cFileName, tmpFileName);
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
));
2650 dumpDefaultHIncludes(o
);
2652 dumpDepIncludes(o
, m_typeName
, "h");
2658 dumpCloseExternC(o
);
2660 o
<< "\n#endif /* "<< headerDefine
<< " */\n";
2665 sal_Bool
ModuleType::dumpDeclaration(FileStream
& o
)
2666 throw( CannotDumpException
)
2668 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
2669 RTFieldAccess access
= RT_ACCESS_INVALID
;
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
);
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
)
2708 sal_Bool
ModuleType::dumpCFile(FileStream
& o
)
2709 throw( CannotDumpException
)
2714 //*************************************************************************
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
;
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
);
2754 if ( bFileExists
&& pOptions
->isValid("-Gc") )
2756 tmpFileName
= createFileNameFromType(outPath
, m_typeName
, ".tmh");
2757 bFileCheck
= sal_True
;
2760 if ( !bFileExists
|| bFileCheck
)
2765 hFile
.open(tmpFileName
);
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
);
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 );
2795 if ( bFileExists && pOptions->isValid("-Gc") )
2797 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmc");
2798 bFileCheck = sal_True;
2801 if ( !bFileExists || bFileCheck )
2806 cFile.open(tmpFileName);
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);
2820 if (ret && bFileCheck)
2822 ret = checkFileContent(cFileName, tmpFileName);
2829 //*************************************************************************
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"));
2851 dumpDefaultHIncludes(o
);
2853 dumpDepIncludes(o
, m_typeName
, "h");
2860 if ( m_cunoTypeLib
)
2862 o
<< "#ifdef CUNO_TYPELIB\n"
2863 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () );\n"
2867 dumpCloseExternC(o
);
2869 o
<< "#endif /* "<< headerDefine
<< " */\n";
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"
2883 o
<< "typedef struct _" << m_name
<< "\n{\n";
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
;
2897 for (i
=0; i
< fieldCount
; i
++)
2899 access
= m_reader
.getFieldAccess(i
);
2901 if (access
== RT_ACCESS_CONST
|| access
== RT_ACCESS_INVALID
)
2904 fieldName
= m_reader
.getFieldName(i
);
2905 fieldType
= m_reader
.getFieldType(i
);
2908 dumpType(o
, fieldType
);
2909 o
<< " " << fieldName
<< ";\n";
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"
2924 sal_Bool
StructureType::dumpCFile(FileStream
& o
)
2925 throw( CannotDumpException
)
2927 dumpInclude(o
, m_typeName
, "h");
2929 dumpDefaultCIncludes(o
);
2931 dumpDepIncludes(o
, m_typeName
, "h");
2939 //*************************************************************************
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"));
2961 dumpDefaultHIncludes(o
);
2963 dumpDepIncludes(o
, m_typeName
, "h");
2970 if ( m_cunoTypeLib
)
2972 o
<< "#ifdef CUNO_TYPELIB\n"
2973 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () );\n"
2977 dumpCloseExternC(o
);
2979 o
<< "#endif /* "<< headerDefine
<< " */\n";
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"
2993 o
<< "\n/* Exception type */\ntypedef struct _" << m_name
<< "\n{\n";
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
;
3007 for (i
=0; i
< fieldCount
; i
++)
3009 access
= m_reader
.getFieldAccess(i
);
3011 if (access
== RT_ACCESS_CONST
|| access
== RT_ACCESS_INVALID
)
3014 fieldName
= m_reader
.getFieldName(i
);
3015 fieldType
= m_reader
.getFieldType(i
);
3018 dumpType(o
, fieldType
);
3019 o
<< " " << fieldName
<< ";\n";
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"
3034 sal_Bool
ExceptionType::dumpCFile(FileStream
& o
)
3035 throw( CannotDumpException
)
3037 dumpInclude(o
, m_typeName
, "h");
3039 dumpDefaultCIncludes(o
);
3041 dumpDepIncludes(o
, m_typeName
, "h");
3050 //*************************************************************************
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"));
3072 dumpDefaultHIncludes(o
);
3078 if ( m_cunoTypeLib
)
3080 o
<< "#ifdef CUNO_TYPELIB\n"
3081 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () );\n"
3085 dumpCloseExternC(o
);
3087 o
<< "#endif /* "<< headerDefine
<< " */\n";
3092 sal_Bool
EnumType::dumpDeclaration(FileStream
& o
)
3093 throw( CannotDumpException
)
3095 o
<< "\ntypedef enum _" << m_name
<< "\n{\n";
3098 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
3099 RTFieldAccess access
= RT_ACCESS_INVALID
;
3100 RTConstValue constValue
;
3103 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
3105 access
= m_reader
.getFieldAccess(i
);
3107 if (access
!= RT_ACCESS_CONST
)
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
;
3118 o
<< indent() << m_name
<< "_" << fieldName
<< " = " << value
<< ",\n";
3121 o
<< indent() << m_name
<< "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n";
3124 o
<< "} " << m_name
<< ";\n\n";
3129 sal_Bool
EnumType::dumpCFile(FileStream
& o
)
3130 throw( CannotDumpException
)
3132 dumpInclude(o
, m_typeName
, "h");
3134 dumpDefaultCIncludes(o
);
3140 void EnumType::dumpGetCunoType(FileStream
& o
)
3142 OString
typeName(m_typeName
.replace('/', '_'));
3144 if ( m_cunoTypeLeak
)
3146 dumpLGetCunoType(o
);
3149 if ( !m_cunoTypeDynamic
)
3151 dumpCGetCunoType(o
);
3157 o
<< "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3158 << "static typelib_TypeDescriptionReference * s_pType_" << typeName
<< " = 0;\n"
3161 o
<< "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () )\n{\n";
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";
3171 o
<< indent() << "typelib_static_enum_type_init( &s_pType_" << typeName
<< ",\n";
3173 o
<< indent() << "\"" << m_typeName
.replace('/', '.') << "\",\n"
3174 << indent() << m_name
<< "_" << m_reader
.getFieldName(0) << " );\n";
3177 o
<< indent() << "}\n"
3178 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName
<<" );\n"
3179 << indent() << "return &s_pType_" << typeName
<<" );\n";
3181 o
<< indent() << "}\n";
3183 dumpCloseExternC(o
);
3186 void EnumType::dumpCGetCunoType(FileStream
& o
)
3188 OString
typeName(m_typeName
.replace('/', '_'));
3192 o
<< "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3193 << "static typelib_TypeDescriptionReference * s_pType_" << typeName
<< " = 0;\n"
3196 o
<< "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () )\n{\n";
3199 o
<< "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3200 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName
<< " = 0;\n"
3203 o
<< indent() << "if ( !s_pType_" << typeName
<< " )\n" << indent() << "{\n";
3205 o
<< indent() << "oslMutex * pMutex = osl_getGlobalMutex();\n"
3206 << indent() << "osl_acquireMutex( pMutex );\n";
3208 o
<< indent() << "if ( !s_pType_" << typeName
<< " )\n" << indent() << "{\n";
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";
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
;
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
;
3242 o
<< value
<< ";\n";
3245 o
<< "\n" << indent() << "typelib_typedescription_newEnum( &pTD,\n";
3247 o
<< indent() << "pTypeName,\n"
3248 << indent() << "(sal_Int32)" << m_name
<< "_" << m_reader
.getFieldName(0) << ",\n"
3249 << indent() << count
<< ", enumValueNames, enumValues );\n\n";
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";
3265 o
<< indent() << "}\n";
3266 o
<< indent() << "osl_releaseMutex( pMutex );\n";
3268 o
<< indent() << "}\n\n"
3269 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName
<<" );\n"
3270 << indent() << "return &s_pType_" << typeName
<<" );\n";
3275 dumpCloseExternC(o
);
3278 //*************************************************************************
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"));
3300 dumpDefaultHIncludes(o
);
3302 dumpDepIncludes(o
, m_typeName
, "h");
3309 if ( m_cunoTypeLib
)
3311 o
<< "#ifdef CUNO_TYPELIB\n"
3312 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name
<< "() SAL_THROW_EXTERN_C( () );\n"
3316 dumpCloseExternC(o
);
3318 o
<< "#endif /* "<< headerDefine
<< " */\n";
3323 sal_Bool
TypeDefType::dumpDeclaration(FileStream
& o
)
3324 throw( CannotDumpException
)
3327 dumpType(o
, m_reader
.getSuperTypeName());
3328 o
<< " " << m_name
<< ";\n\n";
3333 sal_Bool
TypeDefType::dumpCFile(FileStream
& o
)
3334 throw( CannotDumpException
)
3336 dumpInclude(o
, m_typeName
, "h");
3338 dumpDefaultCIncludes(o
);
3340 dumpDepIncludes(o
, m_typeName
, "h");
3346 void TypeDefType::dumpGetCunoType(FileStream
& o
)
3348 if ( m_cunoTypeLeak
)
3350 dumpLGetCunoType(o
);
3353 if ( !m_cunoTypeDynamic
)
3355 dumpCGetCunoType(o
);
3360 void TypeDefType::dumpCGetCunoType(FileStream
& o
)
3364 void TypeDefType::dumpLGetCunoType(FileStream
& o
)
3368 //*************************************************************************
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
))
3380 TypeReader
reader(typeMgr
.getTypeReader(typeName
));
3382 if (!reader
.isValid())
3384 if (typeName
.equals("/"))
3390 if( !checkTypeDependencies(typeMgr
, typeDependencies
, typeName
))
3393 RTTypeClass typeClass
= reader
.getTypeClass();
3394 sal_Bool ret
= sal_False
;
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
);
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);
3415 typeDependencies
.setGenerated(typeName
);
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
);
3430 EnumType
enType(reader
, typeName
, typeMgr
, typeDependencies
);
3431 ret
= enType
.dump(pOptions
);
3432 if (ret
) typeDependencies
.setGenerated(typeName
);
3433 ret
= enType
.dumpDependedTypes(pOptions
);
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
);
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
);
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);
3462 typeDependencies
.setGenerated(typeName
);
3467 case RT_TYPE_SERVICE
:
3468 case RT_TYPE_OBJECT
:
3476 //*************************************************************************
3478 //*************************************************************************
3479 OString
scopedName(const OString
& scope
, const OString
& type
,
3480 sal_Bool bNoNameSpace
)
3482 sal_Int32 nPos
= type
.lastIndexOf( '/' );
3487 return type
.copy(nPos
+1);
3489 OStringBuffer
tmpBuf(type
.getLength()*2);
3493 tmpBuf
.append("::");
3494 tmpBuf
.append(type
.getToken(0, '/', nPos
));
3495 } while( nPos
!= -1 );
3497 return tmpBuf
.makeStringAndClear();
3500 //*************************************************************************
3502 //*************************************************************************
3503 OString
shortScopedName(const OString
& scope
, const OString
& type
,
3504 sal_Bool bNoNameSpace
)
3506 sal_Int32 nPos
= type
.lastIndexOf( '/' );
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
)
3523 OString
aScope( type
.copy( 0, nPos
) );
3524 OStringBuffer
tmpBuf(aScope
.getLength()*2);
3529 tmpBuf
.append("::");
3530 tmpBuf
.append(aScope
.getToken(0, '/', nPos
));
3531 } while( nPos
!= -1 );
3533 return tmpBuf
.makeStringAndClear();