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