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: idltype.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 "idltype.hxx"
40 #include "idloptions.hxx"
44 //*************************************************************************
46 //*************************************************************************
47 IdlType::IdlType(TypeReader
& typeReader
,
48 const OString
& typeName
,
49 const TypeManager
& typeMgr
,
50 const TypeDependency
& typeDependencies
)
51 : m_inheritedMemberCount(0)
53 , m_typeName(typeName
)
54 , m_reader(typeReader
)
55 , m_typeMgr((TypeManager
&)typeMgr
)
56 , m_dependencies(typeDependencies
)
58 sal_Int32 i
= typeName
.lastIndexOf('/');
59 m_name
= typeName
.copy( i
!= -1 ? i
+1 : 0 );
67 sal_Bool
IdlType::dump(IdlOptions
* pOptions
)
68 throw( CannotDumpException
)
70 sal_Bool ret
= sal_False
;
73 if (pOptions
->isValid("-O"))
74 outPath
= pOptions
->getOption("-O");
77 OString hFileName
= createFileNameFromType(outPath
, m_typeName
, ".idl");
79 sal_Bool bFileExists
= sal_False
;
80 sal_Bool bFileCheck
= sal_False
;
82 if ( pOptions
->isValid("-G") || pOptions
->isValid("-Gc") )
84 bFileExists
= fileExists( hFileName
);
88 if ( bFileExists
&& pOptions
->isValid("-Gc") )
90 tmpFileName
= createFileNameFromType(outPath
, m_typeName
, ".tml");
91 bFileCheck
= sal_True
;
94 if ( !bFileExists
|| bFileCheck
)
99 hFile
.open(tmpFileName
);
101 hFile
.open(hFileName
);
105 OString
message("cannot open ");
106 message
+= hFileName
+ " for writing";
107 throw CannotDumpException(message
);
110 ret
= dumpHFile(hFile
);
113 if (ret
&& bFileCheck
)
115 ret
= checkFileContent(hFileName
, tmpFileName
);
121 sal_Bool
IdlType::dumpDependedTypes(IdlOptions
* pOptions
)
122 throw( CannotDumpException
)
124 sal_Bool ret
= sal_True
;
126 TypeUsingSet
usingSet(m_dependencies
.getDependencies(m_typeName
));
128 TypeUsingSet::const_iterator iter
= usingSet
.begin();
130 sal_uInt32 index
= 0;
131 while (iter
!= usingSet
.end())
133 typeName
= (*iter
).m_type
;
134 if ((index
= typeName
.lastIndexOf(']')) > 0)
135 typeName
= typeName
.copy(index
+ 1);
137 if (getBaseType(typeName
).getLength() == 0)
139 if (!produceType(typeName
,
144 fprintf(stderr
, "%s ERROR: %s\n",
145 pOptions
->getProgramName().getStr(),
146 OString("cannot dump Type '" + typeName
+ "'").getStr());
156 OString
IdlType::dumpHeaderDefine(FileStream
& o
, sal_Char
* prefix
)
158 if (m_typeName
.equals("/"))
160 m_typeName
= "global";
163 sal_uInt32 length
= 3 + m_typeName
.getLength() + strlen(prefix
);
165 OStringBuffer
tmpBuf(length
);
168 tmpBuf
.append(m_typeName
);
170 tmpBuf
.append(prefix
);
173 OString
tmp(tmpBuf
.makeStringAndClear().replace('/', '_').toAsciiUpperCase());
175 o
<< "#ifndef " << tmp
<< "\n#define " << tmp
<< "\n";
180 void IdlType::dumpDefaultHIncludes(FileStream
& o
)
184 void IdlType::dumpInclude(FileStream
& o
, const OString
& genTypeName
, const OString
& typeName
, sal_Char
* prefix
)
186 sal_uInt32 length
= 3+ m_typeName
.getLength() + strlen(prefix
);
188 OStringBuffer
tmpBuf(length
);
191 tmpBuf
.append(typeName
);
193 tmpBuf
.append(prefix
);
196 OString
tmp(tmpBuf
.makeStringAndClear().replace('/', '_').toAsciiUpperCase());
198 length
= 1 + typeName
.getLength() + strlen(prefix
);
200 tmpBuf
.ensureCapacity(length
);
201 tmpBuf
.append(typeName
);
203 tmpBuf
.append(prefix
);
205 o
<< "#ifndef " << tmp
<< "\n#include <";
206 tmp
= tmpBuf
.makeStringAndClear();
208 sal_Int32 nIndex
= 0;
211 genTypeName
.getToken(0, '/', nIndex
);
213 } while( nIndex
!= -1 );
215 // sal_Int32 nSlashes = genTypeName.getTokenCount( '/');
216 // for( sal_Int32 i = 1; i < nSlashes; i++ )
222 void IdlType::dumpDepIncludes(FileStream
& o
, const OString
& typeName
, sal_Char
* prefix
)
224 TypeUsingSet
usingSet(m_dependencies
.getDependencies(typeName
));
226 TypeUsingSet::const_iterator iter
= usingSet
.begin();
228 OString
sPrefix(OString(prefix
).toAsciiUpperCase());
229 sal_uInt32 index
= 0;
230 sal_uInt32 seqNum
= 0;
232 while (iter
!= usingSet
.end())
234 index
= (*iter
).m_type
.lastIndexOf(']');
235 seqNum
= (index
> 0 ? ((index
+1) / 2) : 0);
237 relType
= (*iter
).m_type
;
239 relType
= relType
.copy(index
+1);
242 OString
defPrefix("IDL");
244 if (getBaseType(relType
).getLength() == 0 &&
245 m_typeName
!= relType
)
247 if (m_typeMgr
.getTypeClass(relType
) == RT_TYPE_INTERFACE
)
249 if (!((*iter
).m_use
& TYPEUSE_SUPER
))
252 dumpNameSpace(o
, sal_True
, sal_False
, relType
);
253 o
<< "\ninterface " << scopedName(m_typeName
, relType
, sal_True
) << ";\n";
254 dumpNameSpace(o
, sal_False
, sal_False
, relType
);
258 dumpInclude(o
, typeName
, relType
, prefix
);
260 else if (relType
== "type")
262 o
<< "module CORBA {\n"
263 << "\tinterface TypeCode;\n"
269 // write typedef for sequences to support Rational Rose 2000 import
270 OString aST
= relType
;
272 dumpNameSpace( o
, sal_True
, sal_False
, relType
);
273 for( sal_uInt32 i
= 0; i
< seqNum
; i
++ )
275 o
<< "typedef sequence< " << scopedName("", aST
) << " > ";
279 aST
= aST
.replace( '/', '_' );
280 aST
= aST
.replace( ' ', '_' );
282 aST
= aST
+ "_Sequence" ;
285 dumpNameSpace( o
, sal_False
, sal_False
, relType
);
291 void IdlType::dumpNameSpace(FileStream
& o
, sal_Bool bOpen
, sal_Bool bFull
, const OString
& type
)
293 OString
typeName(type
);
294 sal_Bool bOneLine
= sal_True
;
295 if (typeName
.getLength() == 0)
297 typeName
= m_typeName
;
298 bOneLine
= sal_False
;
304 if (typeName
.indexOf( '/' ) == -1 && !bFull
)
308 typeName
= typeName
.copy( 0, typeName
.lastIndexOf( '/' ) );
312 sal_Int32 nIndex
= 0;
315 o
<< "module " << typeName
.getToken(0, '/', nIndex
);
320 } while( nIndex
!= -1 );
326 nPos
= typeName
.lastIndexOf( '/' );
331 o
<< " /* " << typeName
.copy( nPos
+1 ) << " */\n";
333 typeName
= typeName
.copy( 0, nPos
);
334 } while( nPos
!= -1 );
339 sal_uInt32
IdlType::getMemberCount()
341 sal_uInt32 count
= m_reader
.getMethodCount();
343 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
344 RTFieldAccess access
= RT_ACCESS_INVALID
;
345 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
347 access
= m_reader
.getFieldAccess(i
);
349 if (access
!= RT_ACCESS_CONST
&& access
!= RT_ACCESS_INVALID
)
355 sal_uInt32
IdlType::checkInheritedMemberCount(const TypeReader
* pReader
)
357 sal_Bool bSelfCheck
= sal_True
;
360 bSelfCheck
= sal_False
;
364 sal_uInt32 count
= 0;
365 OString
superType(pReader
->getSuperTypeName());
366 if (superType
.getLength() > 0)
368 TypeReader
aSuperReader(m_typeMgr
.getTypeReader(superType
));
369 if ( aSuperReader
.isValid() )
371 count
= checkInheritedMemberCount(&aSuperReader
);
377 count
+= pReader
->getMethodCount();
378 sal_uInt32 fieldCount
= pReader
->getFieldCount();
379 RTFieldAccess access
= RT_ACCESS_INVALID
;
380 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
382 access
= pReader
->getFieldAccess(i
);
384 if (access
!= RT_ACCESS_CONST
&& access
!= RT_ACCESS_INVALID
)
394 sal_uInt32
IdlType::getInheritedMemberCount()
396 if (m_inheritedMemberCount
== 0)
398 m_inheritedMemberCount
= checkInheritedMemberCount(0);
401 return m_inheritedMemberCount
;
405 void IdlType::dumpType(FileStream
& o
, const OString
& type
)
406 throw( CannotDumpException
)
408 OString
sType(checkRealBaseType(type
, sal_True
));
409 sal_uInt32 index
= sType
.lastIndexOf(']');
410 sal_uInt32 seqNum
= (index
> 0 ? ((index
+1) / 2) : 0);
412 OString relType
= (index
> 0 ? (sType
).copy(index
+1) : type
);
414 RTTypeClass typeClass
= m_typeMgr
.getTypeClass(relType
);
418 for (i=0; i < seqNum; i++)
425 case RT_TYPE_INVALID
:
427 OString
tmp(getBaseType(relType
));
428 if (tmp
.getLength() > 0)
430 tmp
= tmp
.replace( ' ', '_' );
433 throw CannotDumpException("Unknown type '" + relType
+ "', incomplete type library.");
436 case RT_TYPE_INTERFACE
:
439 case RT_TYPE_TYPEDEF
:
440 case RT_TYPE_EXCEPTION
:
443 OString aST
= relType
.replace( '/', '_' );
444 aST
= aST
.replace( ' ', '_' );
448 o
<< scopedName(m_typeName
, relType
);
452 for (i
=0; i
< seqNum
; i
++)
455 // use typedef for sequences to support Rational Rose 2000 import
460 OString
IdlType::getBaseType(const OString
& type
)
462 if (type
.equals("long"))
464 if (type
.equals("short"))
466 if (type
.equals("hyper"))
468 if (type
.equals("string"))
470 if (type
.equals("boolean"))
472 if (type
.equals("char"))
474 if (type
.equals("byte"))
476 if (type
.equals("any"))
478 if (type
.equals("type"))
479 return "CORBA::TypeCode";
480 if (type
.equals("float"))
482 if (type
.equals("double"))
484 if (type
.equals("octet"))
486 if (type
.equals("void"))
488 if (type
.equals("unsigned long"))
490 if (type
.equals("unsigned short"))
492 if (type
.equals("unsigned hyper"))
493 return "unsigned long long";
498 void IdlType::dumpIdlGetType(FileStream
& o
, const OString
& type
, sal_Bool bDecl
, IdlTypeDecl eDeclFlag
)
500 OString
sType( checkRealBaseType(type
, sal_True
) );
501 sal_uInt32 index
= sType
.lastIndexOf(']');
502 OString relType
= (index
> 0 ? (sType
).copy(index
+1) : type
);
504 if (eDeclFlag
== CPPUTYPEDECL_ONLYINTERFACES
)
506 if (m_typeMgr
.getTypeClass(relType
) == RT_TYPE_INTERFACE
)
508 o
<< indent() << "getIdlType( (";
517 if (isBaseType(type
))
522 if (eDeclFlag
== CPPUTYPEDECL_NOINTERFACES
&&
523 m_typeMgr
.getTypeClass(relType
) == RT_TYPE_INTERFACE
)
526 // if (m_typeMgr.getTypeClass(type) == RT_TYPE_TYPEDEF)
528 // o << indent() << "get_" << type.replace('/', '_') << "_Type()";
531 o
<< indent() << "getIdlType( (";
541 BASETYPE
IdlType::isBaseType(const OString
& type
)
543 if (type
.equals("long"))
545 if (type
.equals("short"))
547 if (type
.equals("hyper"))
549 if (type
.equals("string"))
551 if (type
.equals("boolean"))
553 if (type
.equals("char"))
555 if (type
.equals("byte"))
557 if (type
.equals("any"))
559 if (type
.equals("float"))
561 if (type
.equals("double"))
563 if (type
.equals("void"))
565 if (type
.equals("unsigned long"))
566 return BT_UNSIGNED_LONG
;
567 if (type
.equals("unsigned short"))
568 return BT_UNSIGNED_SHORT
;
569 if (type
.equals("unsigned hyper"))
570 return BT_UNSIGNED_HYPER
;
575 OString
IdlType::checkSpecialIdlType(const OString
& type
)
577 OString
baseType(type
);
579 RegistryTypeReaderLoader
& rReaderLoader
= getRegistryTypeReaderLoader();
582 sal_uInt8
* pBuffer
=NULL
;
583 RTTypeClass typeClass
;
584 sal_Bool isTypeDef
= (m_typeMgr
.getTypeClass(baseType
) == RT_TYPE_TYPEDEF
);
589 reader
= m_typeMgr
.getTypeReader(baseType
);
591 if (reader
.isValid())
593 typeClass
= reader
.getTypeClass();
595 if (typeClass
== RT_TYPE_TYPEDEF
)
596 baseType
= reader
.getSuperTypeName();
598 isTypeDef
= sal_False
;
608 OString
IdlType::checkRealBaseType(const OString
& type
, sal_Bool bResolveTypeOnly
)
610 sal_uInt32 index
= type
.lastIndexOf(']');
611 OString baseType
= (index
> 0 ? ((OString
)type
).copy(index
+1) : type
);
612 OString seqPrefix
= (index
> 0 ? ((OString
)type
).copy(0, index
+1) : OString());
614 RegistryTypeReaderLoader
& rReaderLoader
= getRegistryTypeReaderLoader();
617 sal_uInt8
* pBuffer
=NULL
;
618 RTTypeClass typeClass
;
619 sal_Bool mustBeChecked
= (m_typeMgr
.getTypeClass(baseType
) == RT_TYPE_TYPEDEF
);
622 while (mustBeChecked
)
624 reader
= m_typeMgr
.getTypeReader(baseType
);
626 if (reader
.isValid())
628 typeClass
= reader
.getTypeClass();
630 if (typeClass
== RT_TYPE_TYPEDEF
)
632 baseType
= reader
.getSuperTypeName();
633 index
= baseType
.lastIndexOf(']');
636 seqPrefix
+= baseType
.copy(0, index
+1);
637 baseType
= baseType
.copy(index
+1);
640 mustBeChecked
= sal_False
;
647 if ( bResolveTypeOnly
)
648 baseType
= seqPrefix
+ baseType
;
653 void IdlType::dumpConstantValue(FileStream
& o
, sal_uInt16 index
)
655 RTConstValue constValue
= m_reader
.getFieldConstValue(index
);
657 switch (constValue
.m_type
)
660 if (constValue
.m_value
.aBool
)
668 snprintf(tmp
, sizeof(tmp
), "0x%x", (sal_Int8
)constValue
.m_value
.aByte
);
673 o
<< constValue
.m_value
.aShort
;
676 o
<< constValue
.m_value
.aUShort
;
679 o
<< constValue
.m_value
.aLong
;
682 o
<< constValue
.m_value
.aULong
;
686 ::rtl::OString
tmp( OString::valueOf(constValue
.m_value
.aHyper
) );
692 ::rtl::OString
tmp( OString::valueOf((sal_Int64
)constValue
.m_value
.aUHyper
) );
698 ::rtl::OString
tmp( OString::valueOf(constValue
.m_value
.aFloat
) );
704 ::rtl::OString
tmp( OString::valueOf(constValue
.m_value
.aDouble
) );
710 ::rtl::OUString
aUStr(constValue
.m_value
.aString
);
711 ::rtl::OString aStr
= ::rtl::OUStringToOString(aUStr
, RTL_TEXTENCODING_ASCII_US
);
712 o
<< "\"" << aStr
.getStr() << "\")";
718 void IdlType::inc(sal_uInt32 num
)
720 m_indentLength
+= num
;
723 void IdlType::dec(sal_uInt32 num
)
725 if (m_indentLength
- num
< 0)
728 m_indentLength
-= num
;
731 OString
IdlType::indent()
733 OStringBuffer
tmp(m_indentLength
);
735 for (sal_uInt32 i
=0; i
< m_indentLength
; i
++)
739 return tmp
.makeStringAndClear();
742 OString
IdlType::indent(sal_uInt32 num
)
744 OStringBuffer
tmp(m_indentLength
+ num
);
746 for (sal_uInt32 i
=0; i
< m_indentLength
+ num
; i
++)
750 return tmp
.makeStringAndClear();
753 //*************************************************************************
755 //*************************************************************************
756 InterfaceType::InterfaceType(TypeReader
& typeReader
,
757 const OString
& typeName
,
758 const TypeManager
& typeMgr
,
759 const TypeDependency
& typeDependencies
)
760 : IdlType(typeReader
, typeName
, typeMgr
, typeDependencies
)
762 m_inheritedMemberCount
= 0;
763 m_hasAttributes
= sal_False
;
764 m_hasMethods
= sal_False
;
767 InterfaceType::~InterfaceType()
772 sal_Bool
InterfaceType::dumpHFile(FileStream
& o
)
773 throw( CannotDumpException
)
775 OString
headerDefine(dumpHeaderDefine(o
, "IDL"));
778 dumpDefaultHIncludes(o
);
780 dumpDepIncludes(o
, m_typeName
, "idl");
784 // write documentation
785 OString aDoc
= m_reader
.getDoku();
786 if( aDoc
.getLength() )
787 o
<< "/**\n" << aDoc
<< "\n*/";
788 o
<< "\ninterface " << m_name
;
790 OString
superType(m_reader
.getSuperTypeName());
791 if (superType
.getLength() > 0)
792 o
<< " : " << scopedName(m_typeName
, superType
);
803 dumpNameSpace(o
, sal_False
);
805 // o << "\nnamespace com { namespace sun { namespace star { namespace uno {\n"
806 // << "class Type;\n} } } }\n\n";
808 o
<< "#endif /* "<< headerDefine
<< "*/" << "\n";
812 void InterfaceType::dumpAttributes(FileStream
& o
)
814 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
815 sal_Bool first
=sal_True
;
817 RTFieldAccess access
= RT_ACCESS_INVALID
;
820 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
822 access
= m_reader
.getFieldAccess(i
);
824 if (access
== RT_ACCESS_CONST
|| access
== RT_ACCESS_INVALID
)
827 fieldName
= m_reader
.getFieldName(i
);
828 fieldType
= m_reader
.getFieldType(i
);
836 // write documentation
837 OString aDoc
= m_reader
.getFieldDoku(i
);
838 if( aDoc
.getLength() )
839 o
<< "/**\n" << aDoc
<< "\n*/\n";
841 if (access
== RT_ACCESS_READONLY
)
842 o
<< indent() << "readonly attribute ";
844 o
<< indent() << "attribute ";
845 dumpType(o
, fieldType
);
846 o
<< " " << fieldName
<< ";\n";
850 void InterfaceType::dumpMethods(FileStream
& o
)
852 sal_uInt32 methodCount
= m_reader
.getMethodCount();
854 OString methodName
, returnType
, paramType
, paramName
;
855 sal_uInt32 paramCount
= 0;
856 sal_uInt32 excCount
= 0;
857 RTMethodMode methodMode
= RT_MODE_INVALID
;
858 RTParamMode paramMode
= RT_PARAM_INVALID
;
860 sal_Bool bRef
= sal_False
;
861 sal_Bool bConst
= sal_False
;
862 sal_Bool bWithRunTimeExcp
= sal_True
;
864 for (sal_Int16 i
=0; i
< methodCount
; i
++)
866 methodName
= m_reader
.getMethodName(i
);
867 returnType
= m_reader
.getMethodReturnType(i
);
868 paramCount
= m_reader
.getMethodParamCount(i
);
869 excCount
= m_reader
.getMethodExcCount(i
);
870 methodMode
= m_reader
.getMethodMode(i
);
872 if ( methodName
.equals("acquire") || methodName
.equals("release") )
874 bWithRunTimeExcp
= sal_False
;
877 // write documentation
878 OString aDoc
= m_reader
.getMethodDoku(i
);
879 if( aDoc
.getLength() )
880 o
<< "/**\n" << aDoc
<< "\n*/\n";
883 dumpType(o
, returnType
);
884 o
<< " " << methodName
<< "( ";
886 for (j
=0; j
< paramCount
; j
++)
888 paramName
= m_reader
.getMethodParamName(i
, j
);
889 paramType
= m_reader
.getMethodParamType(i
, j
);
890 paramMode
= m_reader
.getMethodParamMode(i
, j
);
906 dumpType(o
, paramType
);
907 if( paramName
== "Object" )
910 o
<< " " << paramName
;
912 if (j
+1 < paramCount
) o
<< ", ";
920 sal_Bool bWriteComma
= sal_False
;
921 sal_Bool bRTExceptionWritten
= sal_False
;
922 for (j
=0; j
< excCount
; j
++)
924 excpName
= m_reader
.getMethodExcType(i
, j
);
927 o
<< scopedName(m_typeName
, excpName
);
928 bWriteComma
= sal_True
;
930 if(excpName
== "com/sun/star/uno/RuntimeException")
931 bRTExceptionWritten
= sal_True
;
934 if ( bWithRunTimeExcp
&& !bRTExceptionWritten
)
938 o
<< "::com::sun::star::uno::RuntimeException";
943 else if ( bWithRunTimeExcp
)
945 o
<< "raises( ::com::sun::star::uno::RuntimeException );\n";
955 sal_uInt32
InterfaceType::getMemberCount()
957 sal_uInt32 count
= m_reader
.getMethodCount();
960 m_hasMethods
= sal_True
;
962 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
963 RTFieldAccess access
= RT_ACCESS_INVALID
;
964 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
966 access
= m_reader
.getFieldAccess(i
);
968 if (access
!= RT_ACCESS_CONST
&& access
!= RT_ACCESS_INVALID
)
970 m_hasAttributes
= sal_True
;
977 sal_uInt32
InterfaceType::checkInheritedMemberCount(const TypeReader
* pReader
)
980 sal_Bool bSelfCheck
= sal_True
;
983 bSelfCheck
= sal_False
;
987 sal_uInt32 count
= 0;
988 OString
superType(pReader
->getSuperTypeName());
989 if (superType
.getLength() > 0)
991 TypeReader
aSuperReader(m_typeMgr
.getTypeReader(superType
));
992 if (aSuperReader
.isValid())
994 count
= checkInheritedMemberCount(&aSuperReader
);
1000 count
+= pReader
->getMethodCount();
1001 sal_uInt32 fieldCount
= pReader
->getFieldCount();
1002 RTFieldAccess access
= RT_ACCESS_INVALID
;
1003 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
1005 access
= pReader
->getFieldAccess(i
);
1007 if (access
!= RT_ACCESS_CONST
&& access
!= RT_ACCESS_INVALID
)
1017 sal_uInt32
InterfaceType::getInheritedMemberCount()
1019 if (m_inheritedMemberCount
== 0)
1021 m_inheritedMemberCount
= checkInheritedMemberCount(0);
1024 return m_inheritedMemberCount
;
1029 //*************************************************************************
1031 //*************************************************************************
1032 ModuleType::ModuleType(TypeReader
& typeReader
,
1033 const OString
& typeName
,
1034 const TypeManager
& typeMgr
,
1035 const TypeDependency
& typeDependencies
)
1036 : IdlType(typeReader
, typeName
, typeMgr
, typeDependencies
)
1040 ModuleType::~ModuleType()
1045 sal_Bool
ModuleType::dump(IdlOptions
* pOptions
)
1046 throw( CannotDumpException
)
1048 sal_Bool ret
= sal_False
;
1051 if (pOptions
->isValid("-O"))
1052 outPath
= pOptions
->getOption("-O");
1054 OString
tmpName(m_typeName
);
1056 if (tmpName
.equals("/"))
1059 // tmpName += "/" + m_typeName.getToken(m_typeName.getTokenCount('/') - 1, '/');
1060 tmpName
+= "/" + m_name
;
1062 OString tmpFileName
;
1063 OString hFileName
= createFileNameFromType(outPath
, tmpName
, ".idl");
1065 sal_Bool bFileExists
= sal_False
;
1066 sal_Bool bFileCheck
= sal_False
;
1068 if ( pOptions
->isValid("-G") || pOptions
->isValid("-Gc") )
1070 bFileExists
= fileExists( hFileName
);
1074 if ( bFileExists
&& pOptions
->isValid("-Gc") )
1076 tmpFileName
= createFileNameFromType(outPath
, m_typeName
, ".tml");
1077 bFileCheck
= sal_True
;
1080 if ( !bFileExists
|| bFileCheck
)
1085 hFile
.open(tmpFileName
);
1087 hFile
.open(hFileName
);
1089 if(!hFile
.isValid())
1091 OString
message("cannot open ");
1092 message
+= hFileName
+ " for writing";
1093 throw CannotDumpException(message
);
1096 ret
= dumpHFile(hFile
);
1099 if (ret
&& bFileCheck
)
1101 ret
= checkFileContent(hFileName
, tmpFileName
);
1108 sal_Bool
ModuleType::dumpHFile(FileStream
& o
)
1109 throw( CannotDumpException
)
1111 OString
headerDefine(dumpHeaderDefine(o
, "IDL"));
1114 dumpDefaultHIncludes(o
);
1116 dumpDepIncludes(o
, m_typeName
, "idl");
1119 dumpNameSpace(o
, sal_True
, sal_True
);
1122 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
1123 RTFieldAccess access
= RT_ACCESS_INVALID
;
1126 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
1128 access
= m_reader
.getFieldAccess(i
);
1130 if (access
== RT_ACCESS_CONST
)
1132 fieldName
= m_reader
.getFieldName(i
);
1133 fieldType
= m_reader
.getFieldType(i
);
1136 dumpType(o
, fieldType
);
1137 o
<< " " << fieldName
<< " = ";
1138 dumpConstantValue(o
, i
);
1144 dumpNameSpace(o
, sal_False
, sal_True
);
1145 o
<< "\n#endif /* "<< headerDefine
<< "*/" << "\n";
1150 sal_Bool
ModuleType::hasConstants()
1152 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
1153 RTFieldAccess access
= RT_ACCESS_INVALID
;
1155 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
1157 access
= m_reader
.getFieldAccess(i
);
1159 if (access
== RT_ACCESS_CONST
)
1166 //*************************************************************************
1168 //*************************************************************************
1169 ConstantsType::ConstantsType(TypeReader
& typeReader
,
1170 const OString
& typeName
,
1171 const TypeManager
& typeMgr
,
1172 const TypeDependency
& typeDependencies
)
1173 : ModuleType(typeReader
, typeName
, typeMgr
, typeDependencies
)
1177 ConstantsType::~ConstantsType()
1182 sal_Bool
ConstantsType::dump(IdlOptions
* pOptions
)
1183 throw( CannotDumpException
)
1185 sal_Bool ret
= sal_False
;
1188 if (pOptions
->isValid("-O"))
1189 outPath
= pOptions
->getOption("-O");
1191 OString tmpFileName
;
1192 OString hFileName
= createFileNameFromType(outPath
, m_typeName
, ".idl");
1194 sal_Bool bFileExists
= sal_False
;
1195 sal_Bool bFileCheck
= sal_False
;
1197 if ( pOptions
->isValid("-G") || pOptions
->isValid("-Gc") )
1199 bFileExists
= fileExists( hFileName
);
1203 if ( bFileExists
&& pOptions
->isValid("-Gc") )
1205 tmpFileName
= createFileNameFromType(outPath
, m_typeName
, ".tml");
1206 bFileCheck
= sal_True
;
1209 if ( !bFileExists
|| bFileCheck
)
1214 hFile
.open(tmpFileName
);
1216 hFile
.open(hFileName
);
1218 if(!hFile
.isValid())
1220 OString
message("cannot open ");
1221 message
+= hFileName
+ " for writing";
1222 throw CannotDumpException(message
);
1225 ret
= dumpHFile(hFile
);
1228 if (ret
&& bFileCheck
)
1230 ret
= checkFileContent(hFileName
, tmpFileName
);
1237 //*************************************************************************
1239 //*************************************************************************
1240 StructureType::StructureType(TypeReader
& typeReader
,
1241 const OString
& typeName
,
1242 const TypeManager
& typeMgr
,
1243 const TypeDependency
& typeDependencies
)
1244 : IdlType(typeReader
, typeName
, typeMgr
, typeDependencies
)
1248 StructureType::~StructureType()
1253 sal_Bool
StructureType::dumpHFile(FileStream
& o
)
1254 throw( CannotDumpException
)
1256 OString
headerDefine(dumpHeaderDefine(o
, "IDL"));
1259 dumpDefaultHIncludes(o
);
1261 dumpDepIncludes(o
, m_typeName
, "idl");
1266 // write documentation
1267 OString aDoc
= m_reader
.getDoku();
1268 if( aDoc
.getLength() )
1269 o
<< "/**\n" << aDoc
<< "\n*/";
1271 o
<< "\nstruct " << m_name
;
1275 OString
superType(m_reader
.getSuperTypeName());
1276 if (superType
.getLength() > 0)
1277 dumpSuperMember(o
, superType
);
1279 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
1280 RTFieldAccess access
= RT_ACCESS_INVALID
;
1285 for (i
=0; i
< fieldCount
; i
++)
1287 access
= m_reader
.getFieldAccess(i
);
1289 if (access
== RT_ACCESS_CONST
|| access
== RT_ACCESS_INVALID
)
1292 fieldName
= m_reader
.getFieldName(i
);
1293 fieldType
= m_reader
.getFieldType(i
);
1295 // write documentation
1296 OString aDoc
= m_reader
.getFieldDoku(i
);
1297 if( aDoc
.getLength() )
1298 o
<< "/**\n" << aDoc
<< "\n*/";
1301 dumpType(o
, fieldType
);
1302 o
<< " " << fieldName
<< ";\n";
1308 dumpNameSpace(o
, sal_False
);
1310 o
<< "#endif /* "<< headerDefine
<< "*/" << "\n";
1315 void StructureType::dumpSuperMember(FileStream
& o
, const OString
& superType
)
1317 if (superType
.getLength() > 0)
1319 TypeReader
aSuperReader(m_typeMgr
.getTypeReader(superType
));
1321 if (aSuperReader
.isValid())
1323 dumpSuperMember(o
, aSuperReader
.getSuperTypeName());
1325 sal_uInt32 fieldCount
= aSuperReader
.getFieldCount();
1326 RTFieldAccess access
= RT_ACCESS_INVALID
;
1329 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
1331 access
= aSuperReader
.getFieldAccess(i
);
1333 if (access
== RT_ACCESS_CONST
|| access
== RT_ACCESS_INVALID
)
1336 fieldName
= aSuperReader
.getFieldName(i
);
1337 fieldType
= aSuperReader
.getFieldType(i
);
1339 // write documentation
1340 OString aDoc
= aSuperReader
.getFieldDoku(i
);
1341 if( aDoc
.getLength() )
1342 o
<< "/**\n" << aDoc
<< "\n*/";
1345 dumpType(o
, fieldType
);
1347 o
<< fieldName
<< ";\n";
1353 //*************************************************************************
1355 //*************************************************************************
1356 ExceptionType::ExceptionType(TypeReader
& typeReader
,
1357 const OString
& typeName
,
1358 const TypeManager
& typeMgr
,
1359 const TypeDependency
& typeDependencies
)
1360 : IdlType(typeReader
, typeName
, typeMgr
, typeDependencies
)
1364 ExceptionType::~ExceptionType()
1369 sal_Bool
ExceptionType::dumpHFile(FileStream
& o
)
1370 throw( CannotDumpException
)
1372 OString
headerDefine(dumpHeaderDefine(o
, "IDL"));
1375 dumpDefaultHIncludes(o
);
1377 dumpDepIncludes(o
, m_typeName
, "idl");
1382 // write documentation
1383 OString aDoc
= m_reader
.getDoku();
1384 if( aDoc
.getLength() )
1385 o
<< "/**\n" << aDoc
<< "\n*/";
1387 o
<< "\nexception " << m_name
;
1391 // Write extra member for derived exceptions
1392 o
<< indent() << "/*extra member to hold a derived exception */\n";
1393 o
<< indent() << "any _derivedException;\n";
1394 OString
superType(m_reader
.getSuperTypeName());
1395 if (superType
.getLength() > 0)
1396 dumpSuperMember(o
, superType
);
1398 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
1399 RTFieldAccess access
= RT_ACCESS_INVALID
;
1404 for (i
=0; i
< fieldCount
; i
++)
1406 access
= m_reader
.getFieldAccess(i
);
1408 if (access
== RT_ACCESS_CONST
|| access
== RT_ACCESS_INVALID
)
1411 fieldName
= m_reader
.getFieldName(i
);
1412 fieldType
= m_reader
.getFieldType(i
);
1414 // write documentation
1415 OString aDoc
= m_reader
.getFieldDoku(i
);
1416 if( aDoc
.getLength() )
1417 o
<< "/**\n" << aDoc
<< "\n*/";
1420 dumpType(o
, fieldType
);
1421 o
<< " " << fieldName
<< ";\n";
1428 dumpNameSpace(o
, sal_False
);
1430 o
<< "#endif /* "<< headerDefine
<< "*/" << "\n";
1435 void ExceptionType::dumpSuperMember(FileStream
& o
, const OString
& superType
)
1437 if (superType
.getLength() > 0)
1439 TypeReader
aSuperReader(m_typeMgr
.getTypeReader(superType
));
1441 if (aSuperReader
.isValid())
1443 dumpSuperMember(o
, aSuperReader
.getSuperTypeName());
1445 sal_uInt32 fieldCount
= aSuperReader
.getFieldCount();
1446 RTFieldAccess access
= RT_ACCESS_INVALID
;
1449 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
1451 access
= aSuperReader
.getFieldAccess(i
);
1453 if (access
== RT_ACCESS_CONST
|| access
== RT_ACCESS_INVALID
)
1456 fieldName
= aSuperReader
.getFieldName(i
);
1457 fieldType
= aSuperReader
.getFieldType(i
);
1459 // write documentation
1460 OString aDoc
= aSuperReader
.getFieldDoku(i
);
1461 if( aDoc
.getLength() )
1462 o
<< "/**\n" << aDoc
<< "\n*/";
1465 dumpType(o
, fieldType
);
1467 o
<< fieldName
<< ";\n";
1473 //*************************************************************************
1475 //*************************************************************************
1476 EnumType::EnumType(TypeReader
& typeReader
,
1477 const OString
& typeName
,
1478 const TypeManager
& typeMgr
,
1479 const TypeDependency
& typeDependencies
)
1480 : IdlType(typeReader
, typeName
, typeMgr
, typeDependencies
)
1484 EnumType::~EnumType()
1489 sal_Bool
EnumType::dumpHFile(FileStream
& o
)
1490 throw( CannotDumpException
)
1492 OString
headerDefine(dumpHeaderDefine(o
, "IDL"));
1495 dumpDefaultHIncludes(o
);
1500 // write documentation
1501 OString aDoc
= m_reader
.getDoku();
1502 if( aDoc
.getLength() )
1503 o
<< "/**\n" << aDoc
<< "\n*/";
1505 o
<< "\nenum " << m_name
<< "\n{\n";
1508 sal_uInt32 fieldCount
= m_reader
.getFieldCount();
1509 RTFieldAccess access
= RT_ACCESS_INVALID
;
1510 RTConstValue constValue
;
1513 for (sal_uInt16 i
=0; i
< fieldCount
; i
++)
1515 access
= m_reader
.getFieldAccess(i
);
1517 if (access
!= RT_ACCESS_CONST
)
1520 fieldName
= m_reader
.getFieldName(i
);
1521 constValue
= m_reader
.getFieldConstValue(i
);
1523 if (constValue
.m_type
== RT_TYPE_INT32
)
1524 value
= constValue
.m_value
.aLong
;
1528 /* doesn't work with rational rose 2000
1529 // write documentation
1530 OString aDoc = m_reader.getFieldDoku(i);
1531 if( aDoc.getLength() )
1533 // o << "/**\n" << aDoc << "\n*/\n";
1534 o
<< indent() << fieldName
;
1535 if( i
+1 < fieldCount
)
1542 dumpNameSpace(o
, sal_False
);
1544 o
<< "#endif /* "<< headerDefine
<< "*/" << "\n";
1550 //*************************************************************************
1552 //*************************************************************************
1553 TypeDefType::TypeDefType(TypeReader
& typeReader
,
1554 const OString
& typeName
,
1555 const TypeManager
& typeMgr
,
1556 const TypeDependency
& typeDependencies
)
1557 : IdlType(typeReader
, typeName
, typeMgr
, typeDependencies
)
1561 TypeDefType::~TypeDefType()
1566 sal_Bool
TypeDefType::dumpHFile(FileStream
& o
)
1567 throw( CannotDumpException
)
1569 OString
headerDefine(dumpHeaderDefine(o
, "IDL"));
1572 dumpDefaultHIncludes(o
);
1574 dumpDepIncludes(o
, m_typeName
, "idl");
1580 dumpType(o
, m_reader
.getSuperTypeName());
1581 o
<< " " << m_name
<< ";\n\n";
1583 dumpNameSpace(o
, sal_False
);
1585 o
<< "#endif /* "<< headerDefine
<< "*/" << "\n";
1591 //*************************************************************************
1593 //*************************************************************************
1594 sal_Bool
produceType(const OString
& typeName
,
1595 TypeManager
& typeMgr
,
1596 TypeDependency
& typeDependencies
,
1597 IdlOptions
* pOptions
)
1598 throw( CannotDumpException
)
1600 if (typeDependencies
.isGenerated(typeName
))
1603 TypeReader
reader(typeMgr
.getTypeReader(typeName
));
1605 if (!reader
.isValid())
1607 if (typeName
.equals("/"))
1613 if( !checkTypeDependencies(typeMgr
, typeDependencies
, typeName
))
1616 RTTypeClass typeClass
= reader
.getTypeClass();
1617 sal_Bool ret
= sal_False
;
1620 case RT_TYPE_INTERFACE
:
1622 InterfaceType
iType(reader
, typeName
, typeMgr
, typeDependencies
);
1623 ret
= iType
.dump(pOptions
);
1624 if (ret
) typeDependencies
.setGenerated(typeName
);
1625 ret
= iType
.dumpDependedTypes(pOptions
);
1628 case RT_TYPE_MODULE
:
1630 ModuleType
mType(reader
, typeName
, typeMgr
, typeDependencies
);
1631 if (mType
.hasConstants())
1633 ret
= mType
.dump(pOptions
);
1634 if (ret
) typeDependencies
.setGenerated(typeName
);
1635 // ret = mType.dumpDependedTypes(pOptions);
1638 typeDependencies
.setGenerated(typeName
);
1643 case RT_TYPE_STRUCT
:
1645 StructureType
sType(reader
, typeName
, typeMgr
, typeDependencies
);
1646 ret
= sType
.dump(pOptions
);
1647 if (ret
) typeDependencies
.setGenerated(typeName
);
1648 ret
= sType
.dumpDependedTypes(pOptions
);
1653 EnumType
enType(reader
, typeName
, typeMgr
, typeDependencies
);
1654 ret
= enType
.dump(pOptions
);
1655 if (ret
) typeDependencies
.setGenerated(typeName
);
1656 ret
= enType
.dumpDependedTypes(pOptions
);
1659 case RT_TYPE_EXCEPTION
:
1661 ExceptionType
eType(reader
, typeName
, typeMgr
, typeDependencies
);
1662 ret
= eType
.dump(pOptions
);
1663 if (ret
) typeDependencies
.setGenerated(typeName
);
1664 ret
= eType
.dumpDependedTypes(pOptions
);
1667 case RT_TYPE_TYPEDEF
:
1669 TypeDefType
tdType(reader
, typeName
, typeMgr
, typeDependencies
);
1670 ret
= tdType
.dump(pOptions
);
1671 if (ret
) typeDependencies
.setGenerated(typeName
);
1672 ret
= tdType
.dumpDependedTypes(pOptions
);
1675 case RT_TYPE_CONSTANTS
:
1677 ConstantsType
cType(reader
, typeName
, typeMgr
, typeDependencies
);
1678 if (cType
.hasConstants())
1680 ret
= cType
.dump(pOptions
);
1681 if (ret
) typeDependencies
.setGenerated(typeName
);
1682 // ret = cType.dumpDependedTypes(pOptions);
1685 typeDependencies
.setGenerated(typeName
);
1690 case RT_TYPE_SERVICE
:
1691 case RT_TYPE_OBJECT
:
1699 //*************************************************************************
1701 //*************************************************************************
1702 OString
scopedName(const OString
& scope
, const OString
& type
,
1703 sal_Bool bNoNameSpace
)
1705 sal_Int32 nPos
= type
.lastIndexOf( '/' );
1710 return type
.copy(nPos
+1);
1712 OStringBuffer
tmpBuf(type
.getLength()*2);
1716 tmpBuf
.append("::");
1717 tmpBuf
.append(type
.getToken(0, '/', nPos
));
1718 } while( nPos
!= -1 );
1720 return tmpBuf
.makeStringAndClear();
1723 //*************************************************************************
1725 //*************************************************************************
1726 OString
scope(const OString
& scope
, const OString
& type
)
1728 sal_Int32 nPos
= type
.lastIndexOf( '/' );
1732 // scoped name only if the namespace is not equal
1733 if (scope
.lastIndexOf('/') > 0)
1735 OString
tmpScp(scope
.copy(0, scope
.lastIndexOf('/')));
1736 OString
tmpScp2(type
.copy(0, nPos
));
1738 if (tmpScp
== tmpScp2
)
1742 OString
aScope( type
.copy( 0, nPos
) );
1743 OStringBuffer
tmpBuf(aScope
.getLength()*2);
1748 tmpBuf
.append("::");
1749 tmpBuf
.append(aScope
.getToken(0, '/', nPos
));
1750 } while( nPos
!= -1 );
1752 return tmpBuf
.makeStringAndClear();