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 "cunotype.hxx"
33 #include "cunooptions.hxx"
34
35 using namespace rtl;
36
37 //*************************************************************************
38 // CunoType
39 //*************************************************************************
CunoType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies)40 CunoType::CunoType(TypeReader& typeReader,
41 const OString& typeName,
42 const TypeManager& typeMgr,
43 const TypeDependency& typeDependencies)
44 : m_inheritedMemberCount(0)
45 , m_cunoTypeLib(sal_False)
46 , m_cunoTypeLeak(sal_False)
47 , m_cunoTypeDynamic(sal_True)
48 , m_indentLength(0)
49 , m_typeName(typeName)
50 // , m_name(typeName.getToken(typeName.getTokenCount('/') - 1, '/'))
51 , m_name(typeName.replace('/', '_'))
52 , m_reader(typeReader)
53 , m_typeMgr((TypeManager&)typeMgr)
54 , m_dependencies(typeDependencies)
55 , m_bIsNestedType(sal_False)
56 {
57 // check if this type is nested
58 sal_Int32 i = typeName.lastIndexOf('/');
59
60 if (i >= 0)
61 {
62 OString outerTypeName(typeName.copy(0, i));
63 m_bIsNestedType = (m_typeMgr.getTypeClass(outerTypeName) == RT_TYPE_INTERFACE);
64 }
65
66 // check if this type has nested types
67 RegistryKey key = m_typeMgr.getTypeKey(typeName);
68
69 key.getKeyNames(OUString(), m_nestedTypeNames);
70 }
71
~CunoType()72 CunoType::~CunoType()
73 {
74
75 }
76
isNestedTypeByName(const::rtl::OString & type)77 sal_Bool CunoType::isNestedTypeByName(const ::rtl::OString& type)
78 {
79 sal_Bool ret = sal_False;
80
81 sal_Int32 i = type.lastIndexOf('/');
82
83 if (i >= 0)
84 {
85 OString outerTypeName(type.copy(0, i));
86 ret = (m_typeMgr.getTypeClass(outerTypeName) == RT_TYPE_INTERFACE);
87 }
88
89 return ret;
90 }
91
hasNestedType(const::rtl::OString & type)92 sal_Bool CunoType::hasNestedType(const ::rtl::OString& type)
93 {
94 sal_Bool ret = sal_False;
95
96 if (m_nestedTypeNames.getLength() > 0)
97 {
98 OUString typeName(OStringToOUString(type, RTL_TEXTENCODING_UTF8));
99
100 for (sal_uInt32 i = 0; !ret && (i < m_nestedTypeNames.getLength()); i++)
101 ret = typeName.equals(m_nestedTypeNames.getElement(i).copy(5));
102 }
103
104 return ret;
105 }
106
dump(CunoOptions * pOptions)107 sal_Bool CunoType::dump(CunoOptions* pOptions)
108 {
109 sal_Bool ret = sal_False;
110
111 if (isNestedType())
112 return sal_True;
113
114 if (pOptions->isValid("-U"))
115 m_cunoTypeLib = sal_True;
116 if (pOptions->isValid("-L"))
117 m_cunoTypeLeak = sal_True;
118 if (pOptions->isValid("-C"))
119 m_cunoTypeDynamic = sal_False;
120
121 OString outPath;
122 if (pOptions->isValid("-O"))
123 outPath = pOptions->getOption("-O");
124
125 OString tmpFileName;
126 OString hFileName = createFileNameFromType(outPath, m_typeName, ".h");
127
128 sal_Bool bFileExists = sal_False;
129 sal_Bool bFileCheck = sal_False;
130
131 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
132 {
133 bFileExists = fileExists( hFileName );
134 ret = sal_True;
135 }
136
137 if ( bFileExists && pOptions->isValid("-Gc") )
138 {
139 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmh");
140 bFileCheck = sal_True;
141 }
142
143 if ( !bFileExists || bFileCheck )
144 {
145 FileStream hFile;
146
147 if ( bFileCheck )
148 hFile.open(tmpFileName);
149 else
150 hFile.open(hFileName);
151
152 if(!hFile.isValid())
153 {
154 OString message("cannot open ");
155 message += hFileName + " for writing";
156 throw CannotDumpException(message);
157 }
158
159 ret = dumpHFile(hFile);
160
161 hFile.close();
162 if (ret && bFileCheck)
163 {
164 ret = checkFileContent(hFileName, tmpFileName);
165 }
166 }
167
168 if ( m_cunoTypeLib )
169 {
170 bFileExists = sal_False;
171 bFileCheck = sal_False;
172
173 if (pOptions->isValid("-OC"))
174 outPath = pOptions->getOption("-OC");
175 else
176 outPath = OString();
177
178 OString cFileName = createFileNameFromType(outPath, m_typeName, ".c");
179
180 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
181 {
182 bFileExists = fileExists( cFileName );
183 ret = sal_True;
184 }
185
186 if ( bFileExists && pOptions->isValid("-Gc") )
187 {
188 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmc");
189 bFileCheck = sal_True;
190 }
191
192 if ( !bFileExists || bFileCheck )
193 {
194 FileStream cFile;
195
196 if ( bFileCheck )
197 cFile.open(tmpFileName);
198 else
199 cFile.open(cFileName);
200
201 if(!cFile.isValid())
202 {
203 OString message("cannot open ");
204 message += cFileName + " for writing";
205 throw CannotDumpException(message);
206 }
207
208 ret = dumpCFile(cFile);
209
210 cFile.close();
211 if (ret && bFileCheck)
212 {
213 ret = checkFileContent(cFileName, tmpFileName);
214 }
215 }
216 }
217 return ret;
218 }
dumpDependedTypes(CunoOptions * pOptions)219 sal_Bool CunoType::dumpDependedTypes(CunoOptions* pOptions)
220 {
221 sal_Bool ret = sal_True;
222
223 TypeUsingSet usingSet(m_dependencies.getDependencies(m_typeName));
224
225 TypeUsingSet::const_iterator iter = usingSet.begin();
226 OString typeName;
227 sal_uInt32 index = 0;
228 while (iter != usingSet.end())
229 {
230 typeName = (*iter).m_type;
231 if ((index = typeName.lastIndexOf(']')) > 0)
232 typeName = typeName.copy(index + 1);
233
234 if ( getBaseType(typeName).isEmpty() )
235 {
236 if (!produceType(typeName,
237 m_typeMgr,
238 m_dependencies,
239 pOptions))
240 {
241 fprintf(stderr, "%s ERROR: %s\n",
242 pOptions->getProgramName().getStr(),
243 OString("cannot dump Type '" + typeName + "'").getStr());
244 exit(99);
245 }
246 }
247 ++iter;
248 }
249
250 return ret;
251 }
252
dumpHeaderDefine(FileStream & o,sal_Char * prefix,sal_Bool bExtended)253 OString CunoType::dumpHeaderDefine(FileStream& o, sal_Char* prefix, sal_Bool bExtended)
254 {
255 if (m_typeName.equals("/"))
256 {
257 bExtended = sal_False;
258 m_typeName = "global";
259 }
260
261 sal_uInt32 length = 3 + m_typeName.getLength() + strlen(prefix);
262
263 if (bExtended)
264 length += m_name.getLength() + 1;
265
266 OStringBuffer tmpBuf(length);
267
268 tmpBuf.append('_');
269 tmpBuf.append(m_typeName);
270 tmpBuf.append('_');
271 if (bExtended)
272 {
273 tmpBuf.append(m_name);
274 tmpBuf.append('_');
275 }
276 tmpBuf.append(prefix);
277 tmpBuf.append('_');
278
279 OString tmp(tmpBuf.makeStringAndClear().replace('/', '_').toAsciiUpperCase());
280
281 o << "#ifndef " << tmp << "\n#define " << tmp << "\n";
282
283 return tmp;
284 }
285
dumpDefaultHIncludes(FileStream & o)286 void CunoType::dumpDefaultHIncludes(FileStream& o)
287 {
288 o << "#ifndef _UNO_CUNO_H_\n"
289 << "#include <uno/cuno.h>\n"
290 << "#endif\n";
291 /*
292 if (m_typeMgr.getTypeClass(m_typeName) == RT_TYPE_INTERFACE &&
293 !m_typeName.equals("com/sun/star/uno/XInterface") )
294 {
295 o << "#ifndef _COM_SUN_STAR_UNO_XINTERFACE_H_\n"
296 << "#include <com/sun/star/uno/XInterface.h>\n"
297 << "#endif\n";
298 }
299 */
300 }
301
dumpDefaultCIncludes(FileStream & o)302 void CunoType::dumpDefaultCIncludes(FileStream& o)
303 {
304 o << "#ifndef _OSL_MUTEX_H_\n"
305 << "#include <osl/mutex.h>\n"
306 << "#endif\n\n";
307 }
308
dumpInclude(FileStream & o,const OString & typeName,sal_Char * prefix,sal_Bool bExtended,sal_Bool bCaseSensitive)309 void CunoType::dumpInclude(FileStream& o, const OString& typeName, sal_Char* prefix, sal_Bool bExtended, sal_Bool bCaseSensitive)
310 {
311 sal_uInt32 length = 3+ m_typeName.getLength() + strlen(prefix);
312
313 if (bExtended)
314 length += m_name.getLength() + 1;
315
316 OStringBuffer tmpBuf(length);
317
318 tmpBuf.append('_');
319 tmpBuf.append(typeName);
320 tmpBuf.append('_');
321 if (bExtended)
322 {
323 tmpBuf.append(m_name);
324 tmpBuf.append('_');
325 }
326 tmpBuf.append(prefix);
327 tmpBuf.append('_');
328
329 OString tmp(tmpBuf.makeStringAndClear().replace('/', '_').toAsciiUpperCase());
330
331 length = 1 + typeName.getLength() + strlen(prefix);
332 if (bExtended)
333 length += m_name.getLength() + 1;
334
335 tmpBuf.ensureCapacity(length);
336 tmpBuf.append(typeName);
337 if (bExtended)
338 {
339 tmpBuf.append('/');
340 tmpBuf.append(m_name);
341 }
342 tmpBuf.append('.');
343 tmpBuf.append(prefix);
344
345 o << "#ifndef " << tmp << "\n#include <";
346 if (bCaseSensitive)
347 {
348 o << tmpBuf.makeStringAndClear();
349 } else
350 {
351 o << tmpBuf.makeStringAndClear();
352 }
353 o << ">\n#endif\n";
354 }
355
dumpDepIncludes(FileStream & o,const OString & typeName,sal_Char * prefix)356 void CunoType::dumpDepIncludes(FileStream& o, const OString& typeName, sal_Char* prefix)
357 {
358 TypeUsingSet usingSet(m_dependencies.getDependencies(typeName));
359
360 TypeUsingSet::const_iterator iter = usingSet.begin();
361
362 OString sPrefix(OString(prefix).toAsciiUpperCase());
363 sal_Bool bSequenceDumped = sal_False;
364 sal_uInt32 index = 0;
365 sal_uInt32 seqNum = 0;
366 OString relType;
367 while (iter != usingSet.end())
368 {
369 sal_Bool bDumpThisType = sal_True;
370 index = (*iter).m_type.lastIndexOf(']');
371 seqNum = (index > 0 ? ((index+1) / 2) : 0);
372
373 relType = (*iter).m_type;
374 if (index > 0)
375 relType = relType.copy(index+1);
376
377 if (isNestedTypeByName(relType) && hasNestedType(relType))
378 bDumpThisType = sal_False;
379
380 if (bDumpThisType)
381 {
382 OString defPrefix("H");
383 if (sPrefix.equals("H"))
384 defPrefix = "H";
385
386 if (seqNum > 0 && !bSequenceDumped)
387 {
388 bSequenceDumped = sal_True;
389 o << "#ifndef _UNO_SEQUENCE2_" << defPrefix
390 << "_\n#include <uno/sequence2." << defPrefix.toAsciiLowerCase()
391 << ">\n#endif\n";
392 }
393
394 if (getBaseType(relType).isEmpty() &&
395 m_typeName != relType)
396 {
397 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE
398 && sPrefix.equals("H"))
399 {
400 if (!((*iter).m_use & TYPEUSE_SUPER))
401 {
402 if (isNestedTypeByName(relType))
403 {
404 sal_Int32 iLastS = relType.lastIndexOf('/');
405
406 OString outerNamespace(relType.copy(0,iLastS));
407 OString innerClass(relType.copy(iLastS+1));
408
409 iLastS = outerNamespace.lastIndexOf('/');
410 OString outerClass(outerNamespace.copy(iLastS+1));
411
412 // o << "\n";
413 // dumpNameSpace(o, sal_True, sal_False, outerNamespace);
414 // o << "\nclass " << outerClass << "::" << innerClass << ";\n";
415 // dumpNameSpace(o, sal_False, sal_False, outerNamespace);
416 // o << "\n\n";
417 }
418 else
419 {
420 // dumpInclude(o, relType, prefix);
421 OString type(relType.replace('/', '_'));
422 o << "\n#ifndef " << type.toAsciiUpperCase() << "\n";
423 o << "#define " << type.toAsciiUpperCase() << "\n";
424 o << "struct _" << type << ";\n"
425 << "typedef struct _" << type << "_ftab * " << type << ";\n";
426 o << "#endif\n\n";
427 }
428 } else
429 {
430 if (isNestedTypeByName(relType))
431 {
432 sal_Int32 iLastS = relType.lastIndexOf('/');
433
434 OString outerNamespace(relType.copy(0,iLastS));
435
436 dumpInclude(o, outerNamespace, prefix);
437 }
438 else
439 dumpInclude(o, relType, prefix);
440 }
441 } else
442 {
443 if (isNestedTypeByName(relType))
444 {
445 sal_Int32 iLastS = relType.lastIndexOf('/');
446
447 OString outerNamespace(relType.copy(0,iLastS));
448
449 dumpInclude(o, outerNamespace, prefix);
450 }
451 else
452 dumpInclude(o, relType, prefix);
453 }
454 } else
455 if (relType == "any")
456 {
457 o << "#ifndef _UNO_ANY2_H_\n"
458 << "#include <uno/any2.h>\n"
459 << "#endif\n";
460 } else
461 if (relType == "type")
462 {
463 o << "#ifndef _TYPELIB_TYPEDESCRIPTION_H_\n"
464 << "#include <typelib/typedescription.h>\n"
465 << "#endif\n";
466 } else
467 if (relType == "string" && sPrefix.equals("H"))
468 {
469 o << "#ifndef _RTL_USTRING_H_\n"
470 << "#include <rtl/ustring.h>\n"
471 << "#endif\n";
472 }
473 }
474 ++iter;
475 }
476 if (m_typeName.equals(typeName) && (getNestedTypeNames().getLength() > 0))
477 {
478 o << "// includes for nested types\n\n";
479
480 for (sal_uInt32 i = 0; i < getNestedTypeNames().getLength(); i++)
481 {
482 OUString s(getNestedTypeNames().getElement(i));
483
484 OString nestedName(s.getStr(), s.getLength(), RTL_TEXTENCODING_UTF8);
485
486 dumpDepIncludes(o, nestedName, prefix);
487 }
488 }
489 }
490
dumpOpenExternC(FileStream & o)491 void CunoType::dumpOpenExternC(FileStream& o)
492 {
493 o << "#ifdef __cplusplus\n"
494 << "extern \"C\" {\n"
495 << "#endif\n\n";
496 }
497
dumpCloseExternC(FileStream & o)498 void CunoType::dumpCloseExternC(FileStream& o)
499 {
500 o << "#ifdef __cplusplus\n"
501 << "}\n"
502 << "#endif\n\n";
503 }
504
dumpLGetCunoType(FileStream & o)505 void CunoType::dumpLGetCunoType(FileStream& o)
506 {
507 OString typeName(m_typeName.replace('/', '_'));
508
509 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
510 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
511 << "#endif\n\n";
512
513 if (m_reader.getTypeClass() == RT_TYPE_TYPEDEF)
514 {
515 o << "inline const ::com::sun::star::uno::Type& SAL_CALL get_" << typeName << "_Type( ) SAL_THROW( () )\n{\n";
516 } else
517 {
518 o << "inline const ::com::sun::star::uno::Type& SAL_CALL getCunoType( ";
519 dumpType(o, m_typeName, sal_True, sal_False);
520 o << "* ) SAL_THROW( () )\n{\n";
521 }
522 inc();
523
524 o << indent() << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
525 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
526 << indent() << "#endif\n\n";
527
528 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
529 inc();
530 o << indent() << "typelib_static_type_init( &s_pType_" << typeName << ", "
531 << getTypeClass(m_typeName, sal_True) << ", \"" << m_typeName.replace('/', '.') << "\" );\n";
532 dec();
533 o << indent() << "}\n";
534 o << indent() << "return * reinterpret_cast< ::com::sun::star::uno::Type * >( &s_pType_"
535 << typeName <<" );\n";
536 dec();
537 o << indent() << "}\n";
538
539 return;
540 }
541
dumpGetCunoType(FileStream & o)542 void CunoType::dumpGetCunoType(FileStream& o)
543 {
544 OString typeName(m_typeName.replace('/', '_'));
545
546 if ( m_cunoTypeLeak )
547 {
548 dumpLGetCunoType(o);
549 return;
550 }
551 if ( !m_cunoTypeDynamic )
552 {
553 dumpCGetCunoType(o);
554 return;
555 }
556
557 dumpOpenExternC(o);
558
559 if ( !m_typeName.equals("com/sun/star/uno/Exception") )
560 {
561 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
562 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
563 << "#endif\n\n";
564 }
565
566 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
567 inc();
568
569 if ( m_typeName.equals("com/sun/star/uno/Exception") )
570 {
571 o << indent() << "return typelib_static_type_getByTypeClass( typelib_TypeClass_EXCEPTION );\n";
572 } else
573 {
574 o << indent() << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
575 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
576 << indent() << "#endif\n\n";
577
578 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
579 inc();
580
581 OString superType(m_reader.getSuperTypeName());
582 sal_Bool bIsBaseException = sal_False;
583 if ( !superType.isEmpty() )
584 {
585 if ( superType.equals("com/sun/star/uno/Exception") )
586 {
587 bIsBaseException = sal_True;
588 } else
589 {
590 o << indent() << "typelib_TypeDescriptionReference * pBaseType = 0;\n";
591 }
592 }
593
594 sal_uInt32 count = getMemberCount();
595 if (count)
596 {
597 o << indent() << "typelib_TypeDescriptionReference * aMemberRefs[" << count << "];\n";
598 }
599
600 if ( !bIsBaseException )
601 {
602 o << indent() << "typelib_typedescriptionreference_newByAsciiName(&pBaseType, typelib_TypeClass_INTERFACE, \""
603 << superType.replace('/', '.') << "\" );\n";
604 }
605
606 if (count)
607 {
608 sal_uInt32 fieldCount = m_reader.getFieldCount();
609 RTFieldAccess access = RT_ACCESS_INVALID;
610 OString fieldType, fieldName;
611 OString scope = m_typeName.replace('/', '.');
612 sal_Bool bWithScope = sal_True;
613 OString modFieldType;
614 StringSet generatedTypeSet;
615 StringSet::iterator findIter;
616
617 for (sal_uInt16 i=0; i < fieldCount; i++)
618 {
619 access = m_reader.getFieldAccess(i);
620
621 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
622 continue;
623
624 fieldName = m_reader.getFieldName(i);
625 fieldType = checkRealBaseType(m_reader.getFieldType(i), sal_True);
626
627 // modFieldType = typeToIdentifier(fieldType);
628
629 findIter = generatedTypeSet.find(fieldType);
630 if ( findIter == generatedTypeSet.end() )
631 {
632 generatedTypeSet.insert(fieldType);
633 o << indent() << "typelib_typedescriptionreference_newByAsciiName(&aMemberRefs["
634 << i << "], " << getTypeClass(fieldType, sal_True);
635 o << " , \"" << fieldType.replace('/', '.') << "\" );\n";
636 }
637 }
638 o << "\n";
639 }
640
641 o << indent() << "typelib_static_compound_type_init( &s_pType_" << typeName << ", "
642 << getTypeClass(m_typeName, sal_True) << ", \"" << m_typeName.replace('/', '.') << "\", ";
643 if ( !superType.isEmpty() || bIsBaseException )
644 {
645 if ( bIsBaseException )
646 {
647 o << "* typelib_static_type_getByTypeClass( typelib_TypeClass_EXCEPTION ), "
648 << count << ", ";
649 } else
650 {
651 o << "pBaseType, " << count << ", ";
652 }
653 } else
654 {
655 o << "0, " << count << ", ";
656 }
657
658 if (count)
659 {
660 o << " aMemberRefs );\n";
661 } else
662 {
663 o << " 0 );\n";
664 }
665 dec();
666 o << indent() << "}\n"
667 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName << " );\n"
668 << indent() << "return &_pType_" << typeName <<" );\n";
669 }
670 dec();
671 o << indent() << "}\n";
672
673 dumpCloseExternC(o);
674 }
675
dumpCGetCunoType(FileStream & o)676 void CunoType::dumpCGetCunoType(FileStream& o)
677 {
678 OString typeName(m_typeName.replace('/', '_'));
679
680 dumpOpenExternC(o);
681
682 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
683 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
684 << "#endif\n\n";
685
686 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
687 inc();
688
689 o << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
690 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
691 << "#endif\n\n";
692
693 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
694 inc();
695 o << indent() << "oslMutex * pMutex = osl_getGlobalMutex();\n"
696 << indent() << "osl_acquireMutex( pMutex );\n";
697
698 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
699 inc();
700 o << indent() << "rtl_uString * pTypeName = 0;\n"
701 << indent() << "typelib_TypeDescription * pTD = 0;\n";
702
703 OString superType(m_reader.getSuperTypeName());
704 if ( !superType.isEmpty() )
705 o << indent() << "typelib_TypeDescriptionReference * pSuperType = 0;\n";
706
707 sal_uInt32 count = getMemberCount();
708 sal_uInt32 fieldCount = m_reader.getFieldCount();
709 RTFieldAccess access = RT_ACCESS_INVALID;
710 if (count)
711 {
712 o << indent() << "typelib_CompoundMember_Init aMembers["
713 << count << "];\n";
714
715 for (sal_uInt16 i=0; i < fieldCount; i++)
716 {
717 access = m_reader.getFieldAccess(i);
718
719 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
720 continue;
721
722 o << indent() << "rtl_uString * pMemberName" << i << " = 0;\n"
723 << indent() << "rtl_uString * pMemberType" << i << " = 0;\n";
724 }
725 }
726
727 o << indent() << "rtl_uString_newFromAscii( &pTypeName, \"" << m_typeName.replace('/', '.') << "\" );\n";
728
729 if ( !superType.isEmpty() )
730 {
731 o << indent() << "typelib_typedescriptionreference_newByAsciiName(&pSuperType, typelib_TypeClass_INTERFACE, \""
732 << superType.replace('/', '.') << "\" );\n";
733 }
734
735 dumpCppuGetTypeMemberDecl(o, CUNOTYPEDECL_ALLTYPES);
736
737 if (count)
738 {
739 OString fieldType, fieldName;
740 OString scope = m_typeName.replace('/', '.');
741
742 for (sal_uInt16 i=0; i < fieldCount; i++)
743 {
744 access = m_reader.getFieldAccess(i);
745
746 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
747 continue;
748
749 fieldName = m_reader.getFieldName(i);
750 fieldType = checkRealBaseType(m_reader.getFieldType(i), sal_True);
751
752 o << indent() << "rtl_uString_newFromAscii( &pMemberType" << i << ", \""
753 << fieldType.replace('/', '.') << "\") );\n";
754 o << indent() << "rtl_uString_newFromAscii( &pMemberName" << i << ", \"";
755 o << fieldName << "\") );\n";
756 o << indent() << "aMembers[" << i << "].eTypeClass = "
757 << getTypeClass(fieldType, sal_True) << ";\n"
758 << indent() << "aMembers[" << i << "].pTypeName = pMemberType" << i << ";\n"
759 << indent() << "aMembers[" << i << "].pMemberName = pMemberName" << i << ";\n";
760 }
761
762 o << "\n" << indent() << "typelib_typedescription_new(\n";
763 inc();
764 o << indent() << "&pTD,\n" << indent()
765 << getTypeClass(OString(), sal_True) << ", pTypeName,\n";
766
767 if ( !superType.isEmpty() )
768 o << indent() << "pSuperType,\n";
769 else
770 o << indent() << "0,\n";
771
772 if ( count )
773 {
774 o << indent() << count << ",\n" << indent() << "aMembers );\n\n";
775 } else
776 {
777 o << indent() << count << ",\n" << indent() << "0 );\n\n";
778 }
779
780 dec();
781 o << indent() << "typelib_typedescription_register( &pTD );\n\n";
782
783 o << indent() << "typelib_typedescriptionreference_new( &s_pType_ " << typeName
784 << getTypeClass(OString(), sal_True) << ", pTD);\n\n";
785
786 o << indent() << "typelib_typedescription_release( pTD );\n"
787 << indent() << "typelib_typedescriptionreference_release( pSuperType );\n"
788 << indent() << "rtl_uString_release( pTypeName );\n";
789
790 for (i=0; i < fieldCount; i++)
791 {
792 access = m_reader.getFieldAccess(i);
793
794 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
795 continue;
796
797 o << indent() << "rtl_uString_release( pMemberName" << i << " );\n"
798 << indent() << "rtl_uString_release( pMemberType" << i << " );\n";
799 }
800 }
801
802 dec();
803 o << indent() << "}\n";
804 o << indent() << "osl_releaseMutex( pMutex );\n";
805 dec();
806 o << indent() << "}\n"
807 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName << " );\n"
808 << indent() << "return &s_pType_" << typeName <<" );\n";
809 dec();
810 o << "}\n";
811
812 dumpCloseExternC(o);
813 }
814
dumpCppuGetTypeMemberDecl(FileStream & o,CunoTypeDecl eDeclFlag)815 void CunoType::dumpCppuGetTypeMemberDecl(FileStream& o, CunoTypeDecl eDeclFlag)
816 {
817 sal_uInt32 fieldCount = m_reader.getFieldCount();
818 RTFieldAccess access = RT_ACCESS_INVALID;
819
820 if ( fieldCount )
821 {
822 o << indent() << "{\n" << indent() << "typelib_TypeDescriptionReference ** ppTypeRef = 0;\n";
823
824 StringSet aFinishedTypes;
825 for (sal_uInt16 i=0; i < fieldCount; i++)
826 {
827 access = m_reader.getFieldAccess(i);
828
829 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
830 continue;
831
832 if (aFinishedTypes.count(m_reader.getFieldType(i)) == 0)
833 {
834 aFinishedTypes.insert(m_reader.getFieldType(i));
835 dumpCppuGetType(o, m_reader.getFieldType(i), sal_True, eDeclFlag);
836 }
837 }
838 o << indent() << "}\n";
839 }
840 }
841
getMemberCount()842 sal_uInt32 CunoType::getMemberCount()
843 {
844 sal_uInt32 count = m_reader.getMethodCount();
845
846 sal_uInt32 fieldCount = m_reader.getFieldCount();
847 RTFieldAccess access = RT_ACCESS_INVALID;
848 for (sal_uInt16 i=0; i < fieldCount; i++)
849 {
850 access = m_reader.getFieldAccess(i);
851
852 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
853 count++;
854 }
855 return count;
856 }
857
checkInheritedMemberCount(const TypeReader * pReader)858 sal_uInt32 CunoType::checkInheritedMemberCount(const TypeReader* pReader)
859 {
860 sal_Bool bSelfCheck = sal_True;
861 if (!pReader)
862 {
863 bSelfCheck = sal_False;
864 pReader = &m_reader;
865 }
866
867 sal_uInt32 count = 0;
868 OString superType(pReader->getSuperTypeName());
869 if ( !superType.isEmpty() )
870 {
871 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
872 if ( aSuperReader.isValid() )
873 {
874 count = checkInheritedMemberCount(&aSuperReader);
875 }
876 }
877
878 if (bSelfCheck)
879 {
880 count += pReader->getMethodCount();
881 sal_uInt32 fieldCount = pReader->getFieldCount();
882 RTFieldAccess access = RT_ACCESS_INVALID;
883 for (sal_uInt16 i=0; i < fieldCount; i++)
884 {
885 access = pReader->getFieldAccess(i);
886
887 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
888 {
889 count++;
890 }
891 }
892 }
893
894 return count;
895 }
896
getInheritedMemberCount()897 sal_uInt32 CunoType::getInheritedMemberCount()
898 {
899 if (m_inheritedMemberCount == 0)
900 {
901 m_inheritedMemberCount = checkInheritedMemberCount(0);
902 }
903
904 return m_inheritedMemberCount;
905 }
906
dumpInheritedMembers(FileStream & o,rtl::OString & superType)907 void CunoType::dumpInheritedMembers(FileStream& o, rtl::OString& superType)
908 {
909 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
910
911 OString baseType(aSuperReader.getSuperTypeName());
912 if ( !baseType.isEmpty() )
913 {
914 dumpInheritedMembers(o, baseType);
915 }
916
917 sal_uInt32 fieldCount = aSuperReader.getFieldCount();
918 RTFieldAccess access = RT_ACCESS_INVALID;
919 OString fieldName;
920 OString fieldType;
921 for (sal_uInt16 i=0; i < fieldCount; i++)
922 {
923 access = aSuperReader.getFieldAccess(i);
924
925 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
926 {
927 fieldName = aSuperReader.getFieldName(i);
928 fieldType = aSuperReader.getFieldType(i);
929
930 o << indent();
931 dumpType(o, fieldType);
932 o << " " << fieldName << ";\n";
933 }
934 }
935 }
936
getTypeClass(const OString & type,sal_Bool bCStyle)937 OString CunoType::getTypeClass(const OString& type, sal_Bool bCStyle)
938 {
939 OString typeName = ( !type.isEmpty() ? type : m_typeName );
940 RTTypeClass rtTypeClass = RT_TYPE_INVALID;
941
942 if ( !type.isEmpty() )
943 {
944 typeName = type;
945 rtTypeClass = m_typeMgr.getTypeClass(typeName);
946 } else
947 {
948 typeName = m_typeName;
949 rtTypeClass = m_reader.getTypeClass();
950 }
951
952 if (typeName.lastIndexOf(']') > 0)
953 return bCStyle ? "typelib_TypeClass_SEQUENCE" : "::com::sun::star::uno::TypeClass_SEQUENCE";
954
955 switch (rtTypeClass)
956 {
957 case RT_TYPE_INTERFACE:
958 return bCStyle ? "typelib_TypeClass_INTERFACE" : "::com::sun::star::uno::TypeClass_INTERFACE";
959 break;
960 case RT_TYPE_MODULE:
961 return bCStyle ? "typelib_TypeClass_MODULE" : "::com::sun::star::uno::TypeClass_MODULE";
962 break;
963 case RT_TYPE_STRUCT:
964 return bCStyle ? "typelib_TypeClass_STRUCT" : "::com::sun::star::uno::TypeClass_STRUCT";
965 break;
966 case RT_TYPE_ENUM:
967 return bCStyle ? "typelib_TypeClass_ENUM" : "::com::sun::star::uno::TypeClass_ENUM";
968 break;
969 case RT_TYPE_EXCEPTION:
970 return bCStyle ? "typelib_TypeClass_EXCEPTION" : "::com::sun::star::uno::TypeClass_EXCEPTION";
971 break;
972 case RT_TYPE_TYPEDEF:
973 {
974 OString realType = checkRealBaseType( typeName );
975 return getTypeClass( realType, bCStyle );
976 }
977 // return bCStyle ? "typelib_TypeClass_TYPEDEF" : "::com::sun::star::uno::TypeClass_TYPEDEF";
978 break;
979 case RT_TYPE_SERVICE:
980 return bCStyle ? "typelib_TypeClass_SERVICE" : "::com::sun::star::uno::TypeClass_SERVICE";
981 break;
982 case RT_TYPE_INVALID:
983 {
984 if (type.equals("long"))
985 return bCStyle ? "typelib_TypeClass_LONG" : "::com::sun::star::uno::TypeClass_LONG";
986 if (type.equals("short"))
987 return bCStyle ? "typelib_TypeClass_SHORT" : "::com::sun::star::uno::TypeClass_SHORT";
988 if (type.equals("hyper"))
989 return bCStyle ? "typelib_TypeClass_HYPER" : "::com::sun::star::uno::TypeClass_HYPER";
990 if (type.equals("string"))
991 return bCStyle ? "typelib_TypeClass_STRING" : "::com::sun::star::uno::TypeClass_STRING";
992 if (type.equals("boolean"))
993 return bCStyle ? "typelib_TypeClass_BOOLEAN" : "::com::sun::star::uno::TypeClass_BOOLEAN";
994 if (type.equals("char"))
995 return bCStyle ? "typelib_TypeClass_CHAR" : "::com::sun::star::uno::TypeClass_CHAR";
996 if (type.equals("byte"))
997 return bCStyle ? "typelib_TypeClass_BYTE" : "::com::sun::star::uno::TypeClass_BYTE";
998 if (type.equals("any"))
999 return bCStyle ? "typelib_TypeClass_ANY" : "::com::sun::star::uno::TypeClass_ANY";
1000 if (type.equals("type"))
1001 return bCStyle ? "typelib_TypeClass_TYPE" : "::com::sun::star::uno::TypeClass_TYPE";
1002 if (type.equals("float"))
1003 return bCStyle ? "typelib_TypeClass_FLOAT" : "::com::sun::star::uno::TypeClass_FLOAT";
1004 if (type.equals("double"))
1005 return bCStyle ? "typelib_TypeClass_DOUBLE" : "::com::sun::star::uno::TypeClass_DOUBLE";
1006 if (type.equals("void"))
1007 return bCStyle ? "typelib_TypeClass_VOID" : "::com::sun::star::uno::TypeClass_VOID";
1008 if (type.equals("unsigned long"))
1009 return bCStyle ? "typelib_TypeClass_UNSIGNED_LONG" : "::com::sun::star::uno::TypeClass_UNSIGNED_LONG";
1010 if (type.equals("unsigned short"))
1011 return bCStyle ? "typelib_TypeClass_UNSIGNED_SHORT" : "::com::sun::star::uno::TypeClass_UNSIGNED_SHORT";
1012 if (type.equals("unsigned hyper"))
1013 return bCStyle ? "typelib_TypeClass_UNSIGNED_HYPER" : "::com::sun::star::uno::TypeClass_UNSIGNED_HYPER";
1014 }
1015 break;
1016 }
1017
1018 return bCStyle ? "typelib_TypeClass_UNKNOWN" : "::com::sun::star::uno::TypeClass_UNKNOWN";
1019 }
1020
dumpType(FileStream & o,const OString & type,sal_Bool bConst,sal_Bool bPointer,sal_Bool bParam)1021 void CunoType::dumpType(FileStream& o, const OString& type,
1022 sal_Bool bConst, sal_Bool bPointer, sal_Bool bParam)
1023 {
1024 OString sType(checkRealBaseType(type, sal_True));
1025 sal_uInt32 index = sType.lastIndexOf(']');
1026 sal_uInt32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
1027
1028 OString relType = (index > 0 ? (sType).copy(index+1) : type);
1029
1030 RTTypeClass typeClass = m_typeMgr.getTypeClass(relType);
1031
1032 // if (bConst) o << "const ";
1033
1034 if ( seqNum )
1035 {
1036 o << "/*";
1037 sal_uInt32 i;
1038 for (i=0; i < seqNum; i++)
1039 {
1040 o << "sequence< ";
1041 }
1042 o << relType.replace( '/', '.');
1043 for (i=0; i < seqNum; i++)
1044 {
1045 o << " >";
1046 }
1047 o << "*/ uno_Sequence *";
1048 if (bPointer) o << "*";
1049 return;
1050 }
1051 switch (typeClass)
1052 {
1053 case RT_TYPE_INTERFACE:
1054 o << relType.replace('/', '_') << " *";
1055 break;
1056 case RT_TYPE_INVALID:
1057 {
1058 OString tmp(getBaseType(relType));
1059 if ( !tmp.isEmpty() )
1060 {
1061 o << tmp.getStr();
1062 if ( bParam && !bPointer && relType.equals("any") )
1063 o << " *";
1064 } else
1065 throw CannotDumpException("Unknown type '" + relType + "', incomplete type library.");
1066 }
1067 break;
1068 case RT_TYPE_STRUCT:
1069 case RT_TYPE_EXCEPTION:
1070 o << relType.replace('/', '_');
1071 if ( bParam && !bPointer ) o << " *";
1072 break;
1073 case RT_TYPE_ENUM:
1074 case RT_TYPE_TYPEDEF:
1075 o << relType.replace('/', '_');
1076 break;
1077 }
1078
1079 if (bPointer) o << "*";
1080 }
1081
getBaseType(const OString & type)1082 OString CunoType::getBaseType(const OString& type)
1083 {
1084 if (type.equals("long"))
1085 return "sal_Int32";
1086 if (type.equals("short"))
1087 return "sal_Int16";
1088 if (type.equals("hyper"))
1089 return "sal_Int64";
1090 if (type.equals("string"))
1091 return "rtl_uString *";
1092 if (type.equals("boolean"))
1093 return "sal_Bool";
1094 if (type.equals("char"))
1095 return "sal_Unicode";
1096 if (type.equals("byte"))
1097 return "sal_Int8";
1098 if (type.equals("any"))
1099 return "uno_Any";
1100 if (type.equals("type"))
1101 return "typelib_TypeDescriptionReference *";
1102 if (type.equals("float"))
1103 return "float";
1104 if (type.equals("double"))
1105 return "double";
1106 if (type.equals("octet"))
1107 return "sal_Int8";
1108 if (type.equals("void"))
1109 return type;
1110 if (type.equals("unsigned long"))
1111 return "sal_uInt32";
1112 if (type.equals("unsigned short"))
1113 return "sal_uInt16";
1114 if (type.equals("unsigned hyper"))
1115 return "sal_uInt64";
1116
1117 return OString();
1118 }
1119
dumpCppuGetType(FileStream & o,const OString & type,sal_Bool bDecl,CunoTypeDecl eDeclFlag)1120 void CunoType::dumpCppuGetType(FileStream& o, const OString& type, sal_Bool bDecl, CunoTypeDecl eDeclFlag)
1121 {
1122 OString sType( checkRealBaseType(type, sal_True) );
1123 sal_uInt32 index = sType.lastIndexOf(']');
1124 OString relType = (index > 0 ? (sType).copy(index+1) : type);
1125
1126 if (eDeclFlag == CUNOTYPEDECL_ONLYINTERFACES)
1127 {
1128 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE)
1129 {
1130 if (bDecl)
1131 o << indent() << "ppTypeRef = ";
1132 else
1133 o << indent();
1134
1135 o << "getCUnoType_" << type.replace('/', '_') << "()";
1136
1137 if (bDecl)
1138 o << ";\n" << indent() << "typelib_typedescriptionreference_release( *ppTypeRef );\n";
1139 }
1140 } else
1141 {
1142 if (isBaseType(type))
1143 {
1144 return;
1145 } else
1146 {
1147 if (eDeclFlag == CUNOTYPEDECL_NOINTERFACES &&
1148 m_typeMgr.getTypeClass(relType) == RT_TYPE_INTERFACE)
1149 return;
1150
1151 if ( type.equals("type") )
1152 return;
1153
1154 if (bDecl)
1155 o << indent() << "ppTypeRef = ";
1156 else
1157 o << indent();
1158
1159 o << indent() << "getCUnoType_" << type.replace('/', '_') << "()";
1160 }
1161 if (bDecl)
1162 o << ";\n" << indent() << "typelib_typedescriptionreference_release( *ppTypeRef );\n";
1163 }
1164 }
1165
dumpTypeInit(FileStream & o,const OString & typeName)1166 void CunoType::dumpTypeInit(FileStream& o, const OString& typeName)
1167 {
1168 OString type(checkSpecialCunoType(typeName));
1169
1170 BASETYPE baseType = isBaseType(type);
1171
1172 switch (baseType)
1173 {
1174 case BT_BOOLEAN:
1175 o << "(sal_False)";
1176 return;
1177 break;
1178 case BT_ANY:
1179 case BT_STRING:
1180 o << "()";
1181 return;
1182 break;
1183 case BT_INVALID:
1184 break;
1185 default:
1186 o << "((";
1187 dumpType(o, type);
1188 o << ")" << "0)";
1189 return;
1190 }
1191
1192 RTTypeClass typeClass = m_typeMgr.getTypeClass(type);
1193
1194 if (typeClass == RT_TYPE_ENUM)
1195 {
1196 RegistryTypeReaderLoader aReaderLoader;
1197
1198 if (aReaderLoader.isLoaded())
1199 {
1200 TypeReader reader(m_typeMgr.getTypeReader(type));
1201
1202 if ( reader.isValid() )
1203 {
1204 sal_Int32 i = type.lastIndexOf('/');
1205 o << "(" << shortScopedName("", type, sal_False)
1206 << "::" << type.copy( i != -1 ? i+1 :0 )
1207 << "_" << reader.getFieldName(0) << ")";
1208 return;
1209 }
1210 }
1211 }
1212
1213 o << "()";
1214 }
1215
isBaseType(const OString & type)1216 BASETYPE CunoType::isBaseType(const OString& type)
1217 {
1218 if (type.equals("long"))
1219 return BT_LONG;
1220 if (type.equals("short"))
1221 return BT_SHORT;
1222 if (type.equals("hyper"))
1223 return BT_HYPER;
1224 if (type.equals("string"))
1225 return BT_STRING;
1226 if (type.equals("boolean"))
1227 return BT_BOOLEAN;
1228 if (type.equals("char"))
1229 return BT_CHAR;
1230 if (type.equals("byte"))
1231 return BT_BYTE;
1232 if (type.equals("any"))
1233 return BT_ANY;
1234 if (type.equals("float"))
1235 return BT_FLOAT;
1236 if (type.equals("double"))
1237 return BT_DOUBLE;
1238 if (type.equals("void"))
1239 return BT_VOID;
1240 if (type.equals("unsigned long"))
1241 return BT_UNSIGNED_LONG;
1242 if (type.equals("unsigned short"))
1243 return BT_UNSIGNED_SHORT;
1244 if (type.equals("unsigned hyper"))
1245 return BT_UNSIGNED_HYPER;
1246
1247 return BT_INVALID;
1248 }
1249
typeToIdentifier(const OString & type)1250 OString CunoType::typeToIdentifier(const OString& type)
1251 {
1252 sal_uInt32 index = type.lastIndexOf(']');
1253 sal_uInt32 seqNum = (index > 0 ? ((index+1) / 2) : 0);
1254
1255 OString relType = (index > 0 ? ((OString)type).copy(index+1) : type);
1256 OString sIdentifier;
1257
1258 while( seqNum > 0 )
1259 {
1260 sIdentifier += OString("seq");
1261
1262 if ( --seqNum == 0 )
1263 {
1264 sIdentifier += OString("_");
1265 }
1266 }
1267
1268 if ( isBaseType(relType) )
1269 {
1270 sIdentifier += relType.replace(' ', '_');
1271 } else
1272 {
1273 sIdentifier += relType.replace('/', '_');
1274 }
1275
1276
1277 return sIdentifier;
1278 }
1279
checkSpecialCunoType(const OString & type)1280 OString CunoType::checkSpecialCunoType(const OString& type)
1281 {
1282 OString baseType(type);
1283
1284 RegistryTypeReaderLoader & rReaderLoader = getRegistryTypeReaderLoader();
1285
1286 RegistryKey key;
1287 sal_uInt8* pBuffer=NULL;
1288 RTTypeClass typeClass;
1289 sal_Bool isTypeDef = (m_typeMgr.getTypeClass(baseType) == RT_TYPE_TYPEDEF);
1290 TypeReader reader;
1291
1292 while (isTypeDef)
1293 {
1294 reader = m_typeMgr.getTypeReader(baseType);
1295
1296 if (reader.isValid())
1297 {
1298 typeClass = reader.getTypeClass();
1299
1300 if (typeClass == RT_TYPE_TYPEDEF)
1301 baseType = reader.getSuperTypeName();
1302 else
1303 isTypeDef = sal_False;
1304 } else
1305 {
1306 break;
1307 }
1308 }
1309
1310 return baseType;
1311 }
1312
isSeqType(const OString & type,OString & baseType,OString & seqPrefix)1313 sal_Bool CunoType::isSeqType(const OString& type, OString& baseType, OString& seqPrefix)
1314 {
1315 if ( type.getStr()[0] == '[' )
1316 {
1317 sal_uInt32 index = type.lastIndexOf(']');
1318 baseType = ((OString)type).copy(index+1);
1319 seqPrefix = ((OString)type).copy(0, index+1);
1320 return sal_True;
1321 } else
1322 {
1323 baseType = type;
1324 seqPrefix = OString();
1325 }
1326 return sal_False;
1327 }
1328
isArrayType(const OString & type,OString & baseType,OString & arrayPrefix)1329 sal_Bool CunoType::isArrayType(const OString& type, OString& baseType, OString& arrayPrefix)
1330 {
1331 if ( type.getStr()[type.getLength()-1] == ']' )
1332 {
1333 sal_uInt32 index = type.indexOf('[');
1334 baseType = ((OString)type).copy(0, index-1);
1335 arrayPrefix = ((OString)type).copy(index);
1336 return sal_True;
1337 } else
1338 {
1339 baseType = type;
1340 arrayPrefix = OString();
1341 }
1342 return sal_False;
1343 }
1344
checkRealBaseType(const OString & type,sal_Bool bResolveTypeOnly)1345 OString CunoType::checkRealBaseType(const OString& type, sal_Bool bResolveTypeOnly)
1346 {
1347 OString realType;
1348 OString baseType;
1349 OString completePrefix;
1350 OString prefix;
1351 sal_Bool bSeqType = sal_True;
1352
1353 if ( !isSeqType(type, baseType, completePrefix) )
1354 isArrayType(type, baseType, completePrefix);
1355
1356 RegistryTypeReaderLoader & rReaderLoader = getRegistryTypeReaderLoader();
1357
1358 RegistryKey key;
1359 sal_uInt8* pBuffer=NULL;
1360 RTTypeClass typeClass;
1361 sal_Bool mustBeChecked = (m_typeMgr.getTypeClass(baseType) == RT_TYPE_TYPEDEF);
1362 TypeReader reader;
1363 while (mustBeChecked)
1364 {
1365 reader = m_typeMgr.getTypeReader(baseType);
1366
1367 if (reader.isValid())
1368 {
1369 typeClass = reader.getTypeClass();
1370
1371 if (typeClass == RT_TYPE_TYPEDEF)
1372 {
1373 realType = reader.getSuperTypeName();
1374 if ( isSeqType(realType, baseType, prefix) ||
1375 isArrayType(realType, baseType, prefix) )
1376 {
1377 completePrefix += prefix;
1378 }
1379 } else
1380 mustBeChecked = sal_False;
1381 } else
1382 {
1383 break;
1384 }
1385 }
1386
1387 if ( bResolveTypeOnly )
1388 {
1389 if ( !completePrefix.isEmpty() )
1390 {
1391 baseType = bSeqType ? (completePrefix + baseType) : ( baseType + completePrefix);
1392 }
1393 }
1394 return baseType;
1395 }
1396
dumpConstantValue(FileStream & o,sal_uInt16 index)1397 void CunoType::dumpConstantValue(FileStream& o, sal_uInt16 index)
1398 {
1399 RTConstValue constValue = m_reader.getFieldConstValue(index);
1400
1401 switch (constValue.m_type)
1402 {
1403 case RT_TYPE_BOOL:
1404 if (constValue.m_value.aBool)
1405 o << "sal_True";
1406 else
1407 o << "sal_False";
1408 break;
1409 case RT_TYPE_BYTE:
1410 {
1411 char tmp[16];
1412 snprintf(tmp, sizeof(tmp), "0x%x", (sal_Int8)constValue.m_value.aByte);
1413 o << "(sal_Int8)" << tmp;
1414 }
1415 break;
1416 case RT_TYPE_INT16:
1417 o << "(sal_Int16)" << constValue.m_value.aShort;
1418 break;
1419 case RT_TYPE_UINT16:
1420 o << "(sal_uInt16)" << constValue.m_value.aUShort;
1421 break;
1422 case RT_TYPE_INT32:
1423 o << "(sal_Int32)" << constValue.m_value.aLong;
1424 break;
1425 case RT_TYPE_UINT32:
1426 o << "(sal_uInt32)" << constValue.m_value.aULong;
1427 break;
1428 case RT_TYPE_INT64:
1429 {
1430 ::rtl::OString tmp( OString::valueOf(constValue.m_value.aHyper) );
1431 o << "(sal_Int64)" << tmp.getStr() << "L";
1432 }
1433 break;
1434 case RT_TYPE_UINT64:
1435 {
1436 ::rtl::OString tmp( OString::valueOf((sal_Int64)constValue.m_value.aUHyper) );
1437 o << "(sal_uInt64)" << tmp.getStr() << "L";
1438 }
1439 break;
1440 case RT_TYPE_FLOAT:
1441 {
1442 ::rtl::OString tmp( OString::valueOf(constValue.m_value.aFloat) );
1443 o << "(float)" << tmp.getStr();
1444 }
1445 break;
1446 case RT_TYPE_DOUBLE:
1447 {
1448 ::rtl::OString tmp( OString::valueOf(constValue.m_value.aDouble) );
1449 o << "(double)" << tmp.getStr();
1450 }
1451 break;
1452 case RT_TYPE_STRING:
1453 {
1454 ::rtl::OUString aUStr(constValue.m_value.aString);
1455 ::rtl::OString aStr = ::rtl::OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US);
1456 o << "::rtl::OUString::createFromAscii(\"" << aStr.getStr() << "\")";
1457 }
1458 break;
1459 }
1460 }
1461
inc(sal_uInt32 num)1462 void CunoType::inc(sal_uInt32 num)
1463 {
1464 m_indentLength += num;
1465 }
1466
dec(sal_uInt32 num)1467 void CunoType::dec(sal_uInt32 num)
1468 {
1469 if (m_indentLength - num < 0)
1470 m_indentLength = 0;
1471 else
1472 m_indentLength -= num;
1473 }
1474
indent()1475 OString CunoType::indent()
1476 {
1477 OStringBuffer tmp(m_indentLength);
1478
1479 for (sal_uInt32 i=0; i < m_indentLength; i++)
1480 {
1481 tmp.append(' ');
1482 }
1483 return tmp.makeStringAndClear();
1484 }
1485
indent(sal_uInt32 num)1486 OString CunoType::indent(sal_uInt32 num)
1487 {
1488 OStringBuffer tmp(m_indentLength + num);
1489
1490 for (sal_uInt32 i=0; i < m_indentLength + num; i++)
1491 {
1492 tmp.append(' ');
1493 }
1494 return tmp.makeStringAndClear();
1495 }
1496
1497 //*************************************************************************
1498 // InterfaceType
1499 //*************************************************************************
InterfaceType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies)1500 InterfaceType::InterfaceType(TypeReader& typeReader,
1501 const OString& typeName,
1502 const TypeManager& typeMgr,
1503 const TypeDependency& typeDependencies)
1504 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
1505 {
1506 m_inheritedMemberCount = 0;
1507 m_hasAttributes = sal_False;
1508 m_hasMethods = sal_False;
1509 }
1510
~InterfaceType()1511 InterfaceType::~InterfaceType()
1512 {
1513
1514 }
1515
dumpHFile(FileStream & o)1516 sal_Bool InterfaceType::dumpHFile(FileStream& o)
1517 {
1518 OString headerDefine(dumpHeaderDefine(o, "H"));
1519 o << "\n";
1520
1521 dumpDefaultHIncludes(o);
1522 o << "\n";
1523 dumpDepIncludes(o, m_typeName, "h");
1524 o << "\n";
1525 dumpOpenExternC(o);
1526
1527 o << "#ifndef " << m_name.toAsciiUpperCase() << "\n";
1528 o << "#define " << m_name.toAsciiUpperCase() << "\n";
1529 o << "struct _" << m_name << "_ftab;\n"
1530 << "typedef struct _" << m_name << "_ftab * " << m_name << ";\n";
1531 o << "#endif\n\n";
1532
1533 dumpDeclaration(o);
1534
1535 if ( m_cunoTypeLib )
1536 {
1537 o << "#ifdef CUNO_TYPELIB\n"
1538 << "typelib_TypeDescriptionReference * SAL_CALL getCUnoType_" << m_name << "() SAL_THROW( () );\n"
1539 << "#endif\n\n";
1540 }
1541
1542 /*
1543 if (getNestedTypeNames().getLength() > 0)
1544 {
1545 o << indent() << "// nested types\n\n";
1546 for (sal_uInt32 i = 0; i < getNestedTypeNames().getLength(); i++)
1547 {
1548 OUString s(getNestedTypeNames().getElement(i));
1549
1550 OString nestedName(s.getStr(), s.getLength(), RTL_TEXTENCODING_UTF8);
1551
1552 nestedName = checkRealBaseType(nestedName.copy(5));
1553
1554 if (nestedName.lastIndexOf(']') < 0)
1555 {
1556 o << "inline const ::com::sun::star::uno::Type& SAL_CALL getCunoType( ";
1557 dumpType(o, nestedName, sal_True, sal_False);
1558 o << "* ) SAL_THROW( () );\n\n";
1559 }
1560 }
1561 }
1562 */
1563 dumpCloseExternC(o);
1564
1565 o << "#endif /* "<< headerDefine << " */\n";
1566 return sal_True;
1567 }
1568
dumpInheritedFunctions(FileStream & o,rtl::OString & superType)1569 void InterfaceType::dumpInheritedFunctions(FileStream& o, rtl::OString& superType)
1570 {
1571 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
1572
1573 OString baseType(aSuperReader.getSuperTypeName());
1574 if ( !baseType.isEmpty() )
1575 {
1576 dumpInheritedFunctions(o, baseType);
1577 }
1578
1579 dumpAttributes(o, superType.replace('/', '_'), aSuperReader);
1580 dumpMethods(o, superType.replace('/', '_'), aSuperReader);
1581 }
1582
dumpDeclaration(FileStream & o)1583 sal_Bool InterfaceType::dumpDeclaration(FileStream& o)
1584 {
1585 o << "typedef struct _" << m_name << "_ftab\n" << indent() << "{";
1586 inc();
1587
1588 OString superType(m_reader.getSuperTypeName());
1589 if ( !superType.isEmpty() )
1590 dumpInheritedFunctions(o, superType);
1591 /*
1592 if (getNestedTypeNames().getLength() > 0)
1593 {
1594 inc();
1595 o << indent() << "// nested types\n\n";
1596 for (sal_uInt32 i = 0; i < getNestedTypeNames().getLength(); i++)
1597 {
1598 OUString s(getNestedTypeNames().getElement(i));
1599
1600 OString nestedName(s.getStr(), s.getLength(), RTL_TEXTENCODING_UTF8);
1601
1602 nestedName = nestedName.copy(5);
1603
1604 o << indent() << "// " << nestedName.getStr() << "\n";
1605
1606 TypeReader reader(m_typeMgr.getTypeReader(nestedName));
1607
1608 if (reader.isValid())
1609 {
1610 RTTypeClass typeClass = reader.getTypeClass();
1611 switch (typeClass) {
1612 case RT_TYPE_INTERFACE:
1613 {
1614 InterfaceType iType(reader, nestedName, m_typeMgr, m_dependencies);
1615 iType.dumpDeclaration(o);
1616 }
1617 break;
1618 case RT_TYPE_STRUCT:
1619 {
1620 StructureType sType(reader, nestedName, m_typeMgr, m_dependencies);
1621 sType.dumpDeclaration(o);
1622 }
1623 break;
1624 case RT_TYPE_ENUM:
1625 {
1626 EnumType enType(reader, nestedName, m_typeMgr, m_dependencies);
1627 enType.dumpDeclaration(o);
1628 }
1629 break;
1630 case RT_TYPE_EXCEPTION:
1631 {
1632 ExceptionType eType(reader, nestedName, m_typeMgr, m_dependencies);
1633 eType.dumpDeclaration(o);
1634 }
1635 break;
1636 case RT_TYPE_TYPEDEF:
1637 {
1638 TypeDefType tdType(reader, nestedName, m_typeMgr, m_dependencies);
1639 tdType.dumpDeclaration(o);
1640 }
1641 break;
1642 default:
1643 break;
1644 }
1645 }
1646 }
1647 dec();
1648 }
1649 */
1650 dumpAttributes(o, m_name, m_reader);
1651 dumpMethods(o, m_name, m_reader);
1652
1653 dec();
1654 o << "} " << m_name << "_ftab;\n\n";
1655
1656 return sal_True;
1657 }
1658
dumpCFile(FileStream & o)1659 sal_Bool InterfaceType::dumpCFile(FileStream& o)
1660 {
1661 dumpInclude(o, m_typeName, "h");
1662 o << "\n";
1663 dumpDefaultCIncludes(o);
1664 o << "\n";
1665 dumpDepIncludes(o, m_typeName, "h");
1666 o << "\n";
1667 dumpGetCunoType(o);
1668 /*
1669 if (getNestedTypeNames().getLength() > 0)
1670 {
1671 o << indent() << "// nested types\n\n";
1672 for (sal_uInt32 i = 0; i < getNestedTypeNames().getLength(); i++)
1673 {
1674 OUString s(getNestedTypeNames().getElement(i));
1675
1676 OString nestedName(s.getStr(), s.getLength(), RTL_TEXTENCODING_UTF8);
1677
1678 nestedName = nestedName.copy(5);
1679
1680 o << indent() << "// " << nestedName.getStr() << "\n";
1681
1682 TypeReader reader(m_typeMgr.getTypeReader(nestedName));
1683
1684 if (reader.isValid())
1685 {
1686 RTTypeClass typeClass = reader.getTypeClass();
1687 switch (typeClass) {
1688 case RT_TYPE_INTERFACE:
1689 {
1690 InterfaceType iType(reader, nestedName, m_typeMgr, m_dependencies);
1691 iType.dumpGetCunoType(o);
1692 }
1693 break;
1694 case RT_TYPE_STRUCT:
1695 {
1696 StructureType sType(reader, nestedName, m_typeMgr, m_dependencies);
1697 sType.dumpGetCunoType(o);
1698 }
1699 break;
1700 case RT_TYPE_ENUM:
1701 {
1702 EnumType enType(reader, nestedName, m_typeMgr, m_dependencies);
1703 enType.dumpGetCunoType(o);
1704 }
1705 break;
1706 case RT_TYPE_EXCEPTION:
1707 {
1708 ExceptionType eType(reader, nestedName, m_typeMgr, m_dependencies);
1709 eType.dumpGetCunoType(o);
1710 }
1711 break;
1712 case RT_TYPE_TYPEDEF:
1713 {
1714 TypeDefType tdType(reader, nestedName, m_typeMgr, m_dependencies);
1715 tdType.dumpGetCunoType(o);
1716 }
1717 break;
1718 default:
1719 break;
1720 }
1721 }
1722 }
1723 }
1724 */
1725 return sal_True;
1726 }
1727
dumpAttributes(FileStream & o,const OString & interfaceType,TypeReader & reader)1728 void InterfaceType::dumpAttributes(FileStream& o, const OString& interfaceType, TypeReader& reader )
1729 {
1730 sal_uInt32 fieldCount = reader.getFieldCount();
1731 sal_Bool first=sal_True;
1732
1733 RTFieldAccess access = RT_ACCESS_INVALID;
1734 OString fieldName;
1735 OString fieldType;
1736 for (sal_uInt16 i=0; i < fieldCount; i++)
1737 {
1738 access = reader.getFieldAccess(i);
1739
1740 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
1741 continue;
1742
1743 fieldName = reader.getFieldName(i);
1744 fieldType = reader.getFieldType(i);
1745
1746 if (first)
1747 {
1748 first = sal_False;
1749 o << "\n" << indent() << "/* Attributes of " << interfaceType << " */\n";
1750 }
1751
1752 o << indent() << "cuno_ErrorCode (SAL_CALL *get" << fieldName << ")( "
1753 << interfaceType << " *, uno_Any *, ";
1754 dumpType(o, fieldType, sal_False, sal_True);
1755 o << " );\n";
1756
1757 if (access != RT_ACCESS_READONLY)
1758 {
1759 OString relType = checkSpecialCunoType(fieldType);
1760 sal_Bool bParam = sal_False;
1761
1762 if ( m_typeMgr.getTypeClass(relType) == RT_TYPE_STRUCT ||
1763 m_typeMgr.getTypeClass(relType) == RT_TYPE_EXCEPTION ||
1764 (isBaseType(relType) && relType.equals("any")))
1765 {
1766 bParam = sal_True;
1767 } else
1768 {
1769 bParam = sal_False;
1770 }
1771
1772 o << indent() << "cuno_ErrorCode (SAL_CALL *set" << fieldName << ")( "
1773 << interfaceType << " *, uno_Any *, ";
1774 dumpType(o, fieldType, sal_False, sal_False, bParam);
1775 o << " );\n";
1776 }
1777 }
1778 }
1779
dumpMethods(FileStream & o,const OString & interfaceType,TypeReader & reader)1780 void InterfaceType::dumpMethods(FileStream& o, const OString& interfaceType, TypeReader& reader )
1781 {
1782 sal_uInt32 methodCount = reader.getMethodCount();
1783 sal_Bool first=sal_True;
1784
1785 OString methodName, returnType, paramType, paramName;
1786 sal_uInt32 paramCount = 0;
1787 sal_uInt32 excCount = 0;
1788 RTMethodMode methodMode = RT_MODE_INVALID;
1789 RTParamMode paramMode = RT_PARAM_INVALID;
1790
1791 sal_Bool bPointer = sal_False;
1792 sal_Bool bParam = sal_False;
1793 sal_Bool bWithRunTimeExcp = sal_True;
1794
1795 for (sal_uInt16 i=0; i < methodCount; i++)
1796 {
1797 methodName = reader.getMethodName(i);
1798 returnType = reader.getMethodReturnType(i);
1799 paramCount = reader.getMethodParamCount(i);
1800 excCount = reader.getMethodExcCount(i);
1801 methodMode = reader.getMethodMode(i);
1802
1803 if ( methodName.equals("queryInterface") )
1804 {
1805 first = sal_False;
1806 o << "\n" << indent() << "/* Methods of " << interfaceType << " */\n";
1807 o << indent() << "cuno_ErrorCode (SAL_CALL *queryInterface)( com_sun_star_uno_XInterface *, "
1808 << "uno_Any *, com_sun_star_uno_XInterface **, typelib_TypeDescriptionReference * );\n";
1809 continue;
1810 }
1811
1812 if ( methodName.equals("acquire") || methodName.equals("release") )
1813 {
1814 bWithRunTimeExcp = sal_False;
1815 }
1816
1817 if (first)
1818 {
1819 first = sal_False;
1820 o << "\n" << indent() << "/* Methods of " << interfaceType << " */\n";
1821 }
1822
1823 o << indent() << "cuno_ErrorCode (SAL_CALL *" << methodName << ")( "
1824 << interfaceType << " *";
1825 if ( excCount || bWithRunTimeExcp )
1826 {
1827 o << ", uno_Any *";
1828 }
1829 if ( !isVoid(returnType) )
1830 {
1831 o << ", ";
1832 dumpType(o, returnType, sal_False, sal_True);
1833 }
1834
1835 sal_uInt16 j;
1836 for (j=0; j < paramCount; j++)
1837 {
1838 paramName = reader.getMethodParamName(i, j);
1839 paramType = reader.getMethodParamType(i, j);
1840 paramMode = reader.getMethodParamMode(i, j);
1841
1842 if (j < (sal_uInt16)paramCount) o << ", ";
1843
1844 switch (paramMode)
1845 {
1846 case RT_PARAM_IN:
1847 {
1848 OString relType = checkSpecialCunoType(paramType);
1849 if (m_typeMgr.getTypeClass(relType) == RT_TYPE_STRUCT ||
1850 m_typeMgr.getTypeClass(relType) == RT_TYPE_EXCEPTION ||
1851 (isBaseType(relType) && relType.equals("any")))
1852 {
1853 bParam = sal_True;
1854 } else
1855 {
1856 bParam = sal_False;
1857 }
1858 break;
1859 }
1860 case RT_PARAM_OUT:
1861 case RT_PARAM_INOUT:
1862 bPointer = sal_True;
1863 break;
1864 }
1865
1866 dumpType(o, paramType, sal_False, bPointer, bParam);
1867 }
1868 o << " );\n";
1869 }
1870 }
1871
dumpGetCunoType(FileStream & o)1872 void InterfaceType::dumpGetCunoType(FileStream& o)
1873 {
1874 OString typeName(m_typeName.replace('/', '_'));
1875
1876 if ( m_cunoTypeLeak )
1877 {
1878 dumpLGetCunoType(o);
1879 return;
1880 }
1881 if ( !m_cunoTypeDynamic )
1882 {
1883 dumpCGetCunoType(o);
1884 return;
1885 }
1886
1887 dumpOpenExternC(o);
1888
1889 if ( !m_typeName.equals("com/sun/star/uno/XInterface") )
1890 {
1891 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1892 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
1893 << "#endif\n\n";
1894 }
1895
1896 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
1897 inc();
1898
1899 if ( m_typeName.equals("com/sun/star/uno/XInterface") )
1900 {
1901 o << indent() << "return typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE );\n";
1902 } else
1903 {
1904 o << indent() << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1905 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
1906 << indent() << "#endif\n\n";
1907
1908 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
1909 inc();
1910 OString superType(m_reader.getSuperTypeName());
1911 sal_Bool bWithBase = sal_False;
1912 if ( !superType.isEmpty() && !superType.equals("com/sun/star/uno/XInterface"))
1913 {
1914 bWithBase = sal_True;
1915 o << indent() << "typelib_TypeDescriptionReference * pSuperType = 0;\n"
1916 << indent() << "typelib_typedescriptionreference_newByAsciiName(&pSuperType, typelib_TypeClass_INTERFACE, \""
1917 << superType.replace('/', '.') << "\" );\n";
1918 }
1919
1920 o << indent() << "typelib_static_interface_type_init( &s_pType_" << typeName
1921 << ", \"" << m_typeName.replace('/', '.') << "\", ";
1922
1923 if ( bWithBase )
1924 {
1925 o << "pSuperType );\n";
1926 } else
1927 {
1928 o << "0 );\n";
1929 }
1930
1931 dec();
1932 o << indent() << "}\n"
1933 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName << " );\n"
1934 << indent() << "return &s_pType_" << typeName <<" );\n";
1935 }
1936 dec();
1937 o << indent() << "}\n";
1938
1939 dumpCloseExternC(o);
1940 }
1941
dumpCGetCunoType(FileStream & o)1942 void InterfaceType::dumpCGetCunoType(FileStream& o)
1943 {
1944 OString typeName(m_typeName.replace('/', '_'));
1945
1946 dumpOpenExternC(o);
1947
1948 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1949 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
1950 << "#endif\n\n";
1951
1952 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
1953 inc();
1954
1955 o << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
1956 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
1957 << "#endif\n\n";
1958
1959 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
1960 inc();
1961 o << indent() << "oslMutex * pMutex = osl_getGlobalMutex();\n"
1962 << indent() << "osl_acquireMutex( pMutex );\n";
1963
1964 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
1965 inc();
1966 o << indent() << "rtl_uString * pTypeName = 0;\n"
1967 << indent() << "typelib_InterfaceTypeDescription * pTD = 0;\n";
1968
1969 OString superType(m_reader.getSuperTypeName());
1970 sal_uInt32 count = getMemberCount();
1971
1972 if ( !superType.isEmpty() )
1973 o << indent() << "typelib_TypeDescriptionReference * pSuperType = 0;\n";
1974
1975 if (count)
1976 {
1977 o << indent() << "typelib_TypeDescriptionReference * pMembers[" << count << "] = { ";
1978 for (sal_uInt32 i = 0; i < count; i++)
1979 {
1980 o << "0";
1981 if (i+1 < count)
1982 o << ",";
1983 else
1984 o << " };\n";
1985 }
1986
1987 dumpCUnoAttributeTypeNames(o);
1988 dumpCUnoMethodTypeNames(o);
1989 }
1990
1991 o << indent() << "rtl_uString_newFromAscii( &pTypeName, \"" << m_typeName.replace('/', '.') << "\" );\n";
1992
1993 if ( !superType.isEmpty() )
1994 {
1995 o << indent() << "typelib_typedescriptionreference_newByAsciiName(&pSuperType, typelib_TypeClass_INTERFACE, \""
1996 << superType.replace('/', '.') << "\" );\n";
1997 }
1998
1999 if (count)
2000 {
2001 sal_uInt32 index = 0;
2002 dumpCUnoAttributeRefs(o, index);
2003 dumpCUnoMethodRefs(o, index);
2004 }
2005
2006 o << "\n" << indent() << "typelib_typedescription_newInterface(\n";
2007 inc();
2008 o << indent() << "&pTD,\n"
2009 << indent() << "pTypeName, ";
2010
2011 RTUik uik;
2012 m_reader.getUik(uik);
2013 sal_Char buffer[53];
2014 snprintf(buffer, sizeof(buffer), "0x%.8x, 0x%.4x, 0x%.4x, 0x%.8x, 0x%.8x,\n",
2015 uik.m_Data1, uik.m_Data2, uik.m_Data3, uik.m_Data4, uik.m_Data5);
2016 o << buffer;
2017
2018 if ( !superType.isEmpty() )
2019 o << indent() << "pSuperType,\n";
2020 else
2021 o << indent() << "0,\n";
2022
2023 if ( count )
2024 {
2025 o << indent() << count << ",\n" << indent() << "pMembers );\n\n";
2026 } else
2027 {
2028 o << indent() << count << ",\n" << indent() << "0 );\n\n";
2029 }
2030 dec();
2031
2032 o << indent() << "typelib_typedescription_register( (typelib_TypeDescription**)&pTD );\n";
2033 if ( count )
2034 {
2035 for (sal_uInt16 i=0; i < count; i++)
2036 {
2037 o << indent() << "typelib_typedescriptionreference_release( pMembers["
2038 << i << "] );\n";
2039 }
2040 }
2041 o << indent() << "typelib_typedescription_release( (typelib_TypeDescription*)pTD );\n";
2042
2043 if ( !superType.isEmpty() )
2044 o << indent() << "typelib_typedescription_release( pSuperType );\n\n";
2045 else
2046 o << "\n";
2047
2048 o << indent() << "typelib_typedescriptionreference_new( &s_pType_ " << typeName
2049 << "typelib_TypeClass_INTERFACE, (typelib_TypeDescription*)pTD);\n\n";
2050
2051 o << indent() << "typelib_TypeDescriptionReference ** ppTypeRef = 0;\n";
2052 StringSet aTypes;
2053 // type for RuntimeException is always needed
2054 OString sRunTimeExceptionType("com/sun/star/uno/RuntimeException");
2055 aTypes.insert(sRunTimeExceptionType);
2056 dumpCppuGetType(o, sRunTimeExceptionType, sal_True, CUNOTYPEDECL_ALLTYPES);
2057
2058 dumpAttributesCppuDecl(o, &aTypes, CUNOTYPEDECL_ALLTYPES);
2059 dumpMethodsCppuDecl(o, &aTypes, CUNOTYPEDECL_ALLTYPES);
2060
2061 if (count)
2062 {
2063 sal_uInt32 index = getInheritedMemberCount();
2064 dumpCUnoAttributes(o, index);
2065 dumpCUnoMethods(o, index);
2066 }
2067
2068 // release strings for names
2069 dumpCUnoAttributeTypeNames(o, sal_True);
2070 dumpCUnoMethodTypeNames(o, sal_True);
2071
2072 dec();
2073 o << indent() << "}\n";
2074 o << indent() << "osl_releaseMutex( pMutex );\n";
2075 dec();
2076 o << indent() << "}\n\n"
2077 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName << " );\n"
2078 << indent() << "return &s_pType_" << typeName << ";\n";
2079
2080 dec();
2081 o << "}\n";
2082
2083 dumpCloseExternC(o);
2084 }
2085
dumpCUnoAttributeTypeNames(FileStream & o,sal_Bool bRelease)2086 void InterfaceType::dumpCUnoAttributeTypeNames(FileStream&o, sal_Bool bRelease)
2087 {
2088 sal_uInt32 fieldCount = m_reader.getFieldCount();
2089 RTFieldAccess access = RT_ACCESS_INVALID;
2090
2091 for (sal_uInt16 i=0; i < fieldCount; i++)
2092 {
2093 access = m_reader.getFieldAccess(i);
2094 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2095 continue;
2096 if ( bRelease )
2097 {
2098 o << indent() << "rtl_uString_release( pAttributeName" << i << " );\n";
2099 } else
2100 {
2101 o << indent() << "rtl_uString * pAttributeName" << i << " = 0;\n";
2102 }
2103 }
2104 }
2105
dumpCUnoMethodTypeNames(FileStream & o,sal_Bool bRelease)2106 void InterfaceType::dumpCUnoMethodTypeNames(FileStream&o, sal_Bool bRelease)
2107 {
2108 sal_uInt32 methodCount = m_reader.getMethodCount();
2109
2110 for (sal_uInt16 i = 0; i < methodCount; i++)
2111 {
2112 if ( bRelease )
2113 {
2114 o << indent() << "rtl_uString_release( pMethodName" << i << " );\n";
2115 } else
2116 {
2117 o << indent() << "rtl_uString * pMethodName" << i << " = 0;\n";
2118 }
2119 }
2120 }
2121
dumpCUnoAttributeRefs(FileStream & o,sal_uInt32 & index)2122 void InterfaceType::dumpCUnoAttributeRefs(FileStream& o, sal_uInt32& index)
2123 {
2124 sal_uInt32 fieldCount = m_reader.getFieldCount();
2125 RTFieldAccess access = RT_ACCESS_INVALID;
2126 OString fieldName;
2127 OString scope = m_typeName.replace('/', '.');
2128
2129 for (sal_uInt16 i=0; i < fieldCount; i++)
2130 {
2131 access = m_reader.getFieldAccess(i);
2132 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2133 continue;
2134 fieldName = m_reader.getFieldName(i);
2135
2136 o << indent() << "rtl_uString_newFromAscii( &pAttributeName" << i << ", \""
2137 << scope << "::" << fieldName << "\" );\n";
2138 o << indent() << "typelib_typedescriptionreference_new( &pMembers["
2139 << index << "],\n";
2140 inc(38);
2141 o << indent() << "typelib_TypeClass_INTERFACE_ATTRIBUTE,\n"
2142 << indent() << "pAttributeName" << i << " );\n";
2143 dec(38);
2144 index++;
2145 }
2146 }
2147
dumpCUnoMethodRefs(FileStream & o,sal_uInt32 & index)2148 void InterfaceType::dumpCUnoMethodRefs(FileStream& o, sal_uInt32& index)
2149 {
2150 sal_uInt32 methodCount = m_reader.getMethodCount();
2151 OString methodName; //, returnType, paramType, paramName;
2152 OString scope = m_typeName.replace('/', '.');
2153
2154 for (sal_uInt16 i = 0; i < methodCount; i++)
2155 {
2156 methodName = m_reader.getMethodName(i);
2157
2158 o << indent() << "rtl_uString_newFromAscii( &pMethodName" << i << ", \""
2159 << scope.replace('/', '.') << "::" << methodName << "\" );\n";
2160 o << indent() << "typelib_typedescriptionreference_new( &pMembers["
2161 << index << "],\n";
2162 inc(38);
2163 o << indent() << "typelib_TypeClass_INTERFACE_METHOD,\n"
2164 << indent() << "pMethodName" << i << " );\n";
2165 dec(38);
2166 index++;
2167 }
2168 }
2169
getMemberCount()2170 sal_uInt32 InterfaceType::getMemberCount()
2171 {
2172 sal_uInt32 count = m_reader.getMethodCount();
2173
2174 if (count)
2175 m_hasMethods = sal_True;
2176
2177 sal_uInt32 fieldCount = m_reader.getFieldCount();
2178 RTFieldAccess access = RT_ACCESS_INVALID;
2179 for (sal_uInt16 i=0; i < fieldCount; i++)
2180 {
2181 access = m_reader.getFieldAccess(i);
2182
2183 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
2184 {
2185 m_hasAttributes = sal_True;
2186 count++;
2187 }
2188 }
2189 return count;
2190 }
2191
checkInheritedMemberCount(const TypeReader * pReader)2192 sal_uInt32 InterfaceType::checkInheritedMemberCount(const TypeReader* pReader)
2193 {
2194 sal_uInt32 cout = 0;
2195 sal_Bool bSelfCheck = sal_True;
2196 if (!pReader)
2197 {
2198 bSelfCheck = sal_False;
2199 pReader = &m_reader;
2200 }
2201
2202 sal_uInt32 count = 0;
2203 OString superType(pReader->getSuperTypeName());
2204 if ( !superType.isEmpty() )
2205 {
2206 TypeReader aSuperReader(m_typeMgr.getTypeReader(superType));
2207 if (aSuperReader.isValid())
2208 {
2209 count = checkInheritedMemberCount(&aSuperReader);
2210 }
2211 }
2212
2213 if (bSelfCheck)
2214 {
2215 count += pReader->getMethodCount();
2216 sal_uInt32 fieldCount = pReader->getFieldCount();
2217 RTFieldAccess access = RT_ACCESS_INVALID;
2218 for (sal_uInt16 i=0; i < fieldCount; i++)
2219 {
2220 access = pReader->getFieldAccess(i);
2221
2222 if (access != RT_ACCESS_CONST && access != RT_ACCESS_INVALID)
2223 {
2224 count++;
2225 }
2226 }
2227 }
2228
2229 return count;
2230 }
2231
getInheritedMemberCount()2232 sal_uInt32 InterfaceType::getInheritedMemberCount()
2233 {
2234 if (m_inheritedMemberCount == 0)
2235 {
2236 m_inheritedMemberCount = checkInheritedMemberCount(0);
2237 }
2238
2239 return m_inheritedMemberCount;
2240 }
2241
dumpCUnoAttributes(FileStream & o,sal_uInt32 & index)2242 void InterfaceType::dumpCUnoAttributes(FileStream& o, sal_uInt32& index)
2243 {
2244 sal_uInt32 fieldCount = m_reader.getFieldCount();
2245
2246 RTFieldAccess access = RT_ACCESS_INVALID;
2247 OString fieldType;
2248
2249 sal_uInt32 absoluteIndex = index;
2250
2251 if (m_hasAttributes)
2252 {
2253 o << "\n" << indent() << "{\n" << indent() << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n";
2254
2255 for (sal_uInt16 i=0; i < fieldCount; i++)
2256 {
2257 access = m_reader.getFieldAccess(i);
2258
2259 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2260 continue;
2261
2262 fieldType = checkRealBaseType(m_reader.getFieldType(i), sal_True);
2263 o << indent() << "{\n";
2264 o << indent() << "rtl_uString * pAttributeType" << i << " = 0;\n";
2265 o << indent() << "rtl_uString_newFromAscii( &pAttributeType" << i << ", \""
2266 << fieldType.replace('/', '.') << "\" );\n";
2267 o << indent() << "typelib_typedescription_newInterfaceAttribute( &pAttribute,\n";
2268 inc();
2269 o << indent() << absoluteIndex++ << ", pAttributeName" << i << ",\n";
2270 o << indent() << getTypeClass(fieldType, sal_True) << ", pAttributeType" << i << ",\n";
2271 if (access == RT_ACCESS_READONLY)
2272 o << indent() << "sal_True );\n";
2273 else
2274 o << indent() << "sal_False );\n";
2275 dec();
2276 o << indent() << "typelib_typedescription_register( (typelib_TypeDescription**)&pAttribute );\n\n";
2277 o << indent() << "}\n";
2278 }
2279 o << indent() << "typelib_typedescription_release( (typelib_TypeDescription*)pAttribute );\n";
2280 o << indent() << "}\n";
2281 index = absoluteIndex;
2282 }
2283 }
2284
dumpCUnoMethods(FileStream & o,sal_uInt32 & index)2285 void InterfaceType::dumpCUnoMethods(FileStream& o, sal_uInt32& index)
2286 {
2287 sal_uInt32 methodCount = m_reader.getMethodCount();
2288 OString methodName, returnType, paramType, paramName;
2289 sal_uInt32 paramCount = 0;
2290 sal_uInt32 excCount = 0;
2291 RTMethodMode methodMode = RT_MODE_INVALID;
2292 RTParamMode paramMode = RT_PARAM_INVALID;
2293 sal_Bool bWithRuntimeException = sal_True;
2294
2295 sal_uInt32 absoluteIndex = index;
2296
2297 if (m_hasMethods)
2298 {
2299 o << "\n" << indent() << "{\n" << indent() << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n";
2300
2301 for (sal_uInt16 i=0; i < methodCount; i++)
2302 {
2303 methodName = m_reader.getMethodName(i);
2304 returnType = checkRealBaseType(m_reader.getMethodReturnType(i), sal_True);
2305 paramCount = m_reader.getMethodParamCount(i);
2306 excCount = m_reader.getMethodExcCount(i);
2307 methodMode = m_reader.getMethodMode(i);
2308
2309 if ( methodName.equals("acquire") || methodName.equals("release") )
2310 {
2311 bWithRuntimeException = sal_False;
2312 }
2313 o << indent() << "{\n";
2314 inc();
2315
2316 if (paramCount)
2317 {
2318 o << indent() << "typelib_Parameter_Init pParameters[" << paramCount << "];\n";
2319 }
2320 if ( excCount || bWithRuntimeException )
2321 {
2322 o << indent() << "rtl_uString * pExceptions[" << excCount + 1 << "];\n";
2323 }
2324 o << indent() << "rtl_uString * pReturnType" << i << " = 0;\n";
2325
2326 sal_uInt16 j;
2327 for (j=0; j < paramCount; j++)
2328 {
2329 o << indent() << "rtl_uString * pParamName" << j << " = 0;\n"
2330 << indent() << "rtl_uString * pParamType" << j << " = 0;\n";
2331 }
2332
2333 for (j=0; j < excCount; j++)
2334 {
2335 o << indent() << "rtl_uString * pExceptionName" << j << " = 0;\n";
2336 }
2337 if ( excCount || bWithRuntimeException )
2338 {
2339 o << indent() << "rtl_uString * pExceptionName" << excCount << " = 0;\n";
2340 }
2341 for (j=0; j < paramCount; j++)
2342 {
2343 paramName = m_reader.getMethodParamName(i, j);
2344 paramType = checkRealBaseType(m_reader.getMethodParamType(i, j), sal_True);
2345 paramMode = m_reader.getMethodParamMode(i, j);
2346 o << indent() << "rtl_uString_newFromAscii( &pParamName" << j << ", \""
2347 << paramName << "\" );\n";
2348 o << indent() << "rtl_uString_newFromAscii( &pParamType" << j << ", \""
2349 << paramType.replace('/', '.') << "\" );\n";
2350 o << indent() << "pParameters[" << j << "].pParamName = pParamName" << j << ";\n";
2351 o << indent() << "pParameters[" << j << "].eTypeClass = "
2352 << getTypeClass(paramType, sal_True) << ";\n";
2353 o << indent() << "pParameters[" << j << "].pTypeName = sParamType" << j << ";\n";
2354
2355 if (paramMode == RT_PARAM_IN || paramMode == RT_PARAM_INOUT)
2356 o << indent() << "pParameters[" << j << "].bIn = sal_True;\n";
2357 else
2358 o << indent() << "pParameters[" << j << "].bIn = sal_False;\n";
2359
2360 if (paramMode == RT_PARAM_OUT || paramMode == RT_PARAM_INOUT)
2361 o << indent() << "pParameters[" << j << "].bOut = sal_True;\n";
2362 else
2363 o << indent() << "pParameters[" << j << "].bOut = sal_False;\n";
2364 }
2365
2366 for (j=0; j < excCount; j++)
2367 {
2368 if (!m_reader.getMethodExcType(i, j).equals("com/sun/star/uno/RuntimeException"))
2369 {
2370 o << indent() << "rtl_uString_newFromAscii( & pExceptionName" << j << ", \""
2371 << OString(m_reader.getMethodExcType(i, j)).replace('/', '.') << "\" );\n";
2372 o << indent() << "pExceptions[" << j << "] = pExceptionName" << j << ";\n";
2373 }
2374 }
2375 if ( excCount || bWithRuntimeException )
2376 {
2377 o << indent() << "rtl_uString_newFromAscii( & pExceptionName" << excCount
2378 << ", \"com.sun.star.uno.RuntimeException\") );\n";
2379 o << indent() << "pExceptions[" << excCount << "] = pExceptionName" << excCount << ";\n";
2380 }
2381 o << indent() << "rtl_uString_newFromAscii( &pReturnType" << i << ", \""
2382 << returnType.replace('/', '.') << "\" );\n";
2383 o << indent() << "typelib_typedescription_newInterfaceMethod( &pMethod,\n";
2384 inc();
2385 o << indent() << absoluteIndex++ << ", ";
2386 if (methodMode == RT_MODE_ONEWAY || methodMode == RT_MODE_ONEWAY_CONST)
2387 o << "sal_True,\n";
2388 else
2389 o << "sal_False,\n";
2390 o << indent() << "pMethodName" << i << ",\n";
2391 o << indent() << getTypeClass(returnType, sal_True) << ", pReturnType" << i << ",\n";
2392 if (paramCount)
2393 o << indent() << paramCount << ", pParameters,\n";
2394 else
2395 o << indent() << "0, 0,\n";
2396
2397 if ( excCount || bWithRuntimeException )
2398 {
2399 o << indent() << excCount + 1 << ", pExceptions );\n";
2400 } else
2401 {
2402 o << indent() << "0, 0 );\n";
2403 }
2404
2405 dec();
2406 o << indent() << "typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );\n";
2407
2408 o << indent() << "rtl_uString_release( pReturnType );\n";
2409 for (j=0; j < paramCount; j++)
2410 {
2411 o << indent() << "rtl_uString_release( pParamName" << j << " );\n"
2412 << indent() << "rtl_uString_release( pParamType" << j << " );\n";
2413 }
2414
2415 for (j=0; j < excCount; j++)
2416 {
2417 o << indent() << "rtl_uString_release( pExceptionName" << j << " );\n";
2418 }
2419 if ( excCount || bWithRuntimeException )
2420 {
2421 o << indent() << "rtl_uString_release( pExceptionName" << excCount << " );\n";
2422 }
2423 dec();
2424 o << indent() << "}\n";
2425 }
2426 o << indent() << "typelib_typedescription_release( (typelib_TypeDescription*)pMethod );\n";
2427
2428 o << indent() << "}\n";
2429 index = absoluteIndex;
2430 }
2431 }
2432
dumpAttributesCppuDecl(FileStream & o,StringSet * pFinishedTypes,CunoTypeDecl eDeclFlag)2433 void InterfaceType::dumpAttributesCppuDecl(FileStream& o, StringSet* pFinishedTypes, CunoTypeDecl eDeclFlag)
2434 {
2435 sal_uInt32 fieldCount = m_reader.getFieldCount();
2436
2437 RTFieldAccess access = RT_ACCESS_INVALID;
2438 OString fieldName;
2439 OString fieldType;
2440 for (sal_uInt16 i=0; i < fieldCount; i++)
2441 {
2442 access = m_reader.getFieldAccess(i);
2443
2444 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2445 continue;
2446
2447 fieldName = m_reader.getFieldName(i);
2448 fieldType = m_reader.getFieldType(i);
2449
2450 if (pFinishedTypes->count(fieldType) == 0)
2451 {
2452 pFinishedTypes->insert(fieldType);
2453 dumpCppuGetType(o, fieldType, sal_True, eDeclFlag);
2454 }
2455 }
2456 }
2457
dumpMethodsCppuDecl(FileStream & o,StringSet * pFinishedTypes,CunoTypeDecl eDeclFlag)2458 void InterfaceType::dumpMethodsCppuDecl(FileStream& o, StringSet* pFinishedTypes, CunoTypeDecl eDeclFlag)
2459 {
2460 sal_uInt32 methodCount = m_reader.getMethodCount();
2461 OString returnType, paramType, excType;
2462 sal_uInt32 paramCount = 0;
2463 sal_uInt32 excCount = 0;
2464
2465 for (sal_uInt16 i=0; i < methodCount; i++)
2466 {
2467 returnType = m_reader.getMethodReturnType(i);
2468 paramCount = m_reader.getMethodParamCount(i);
2469 excCount = m_reader.getMethodExcCount(i);
2470
2471 if (pFinishedTypes->count(returnType) == 0)
2472 {
2473 pFinishedTypes->insert(returnType);
2474 dumpCppuGetType(o, returnType, sal_True, eDeclFlag);
2475 }
2476 sal_uInt16 j;
2477 for (j=0; j < paramCount; j++)
2478 {
2479 paramType = m_reader.getMethodParamType(i, j);
2480
2481 if (pFinishedTypes->count(paramType) == 0)
2482 {
2483 pFinishedTypes->insert(paramType);
2484 dumpCppuGetType(o, paramType, sal_True, eDeclFlag);
2485 }
2486 }
2487
2488 for (j=0; j < excCount; j++)
2489 {
2490 excType = m_reader.getMethodExcType(i, j);
2491 if (pFinishedTypes->count(excType) == 0)
2492 {
2493 pFinishedTypes->insert(excType);
2494 dumpCppuGetType(o, excType, sal_True, eDeclFlag);
2495 }
2496 }
2497 }
2498 }
2499
2500 //*************************************************************************
2501 // ModuleType
2502 //*************************************************************************
ModuleType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies)2503 ModuleType::ModuleType(TypeReader& typeReader,
2504 const OString& typeName,
2505 const TypeManager& typeMgr,
2506 const TypeDependency& typeDependencies)
2507 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
2508 {
2509 }
2510
~ModuleType()2511 ModuleType::~ModuleType()
2512 {
2513
2514 }
2515
dump(CunoOptions * pOptions)2516 sal_Bool ModuleType::dump(CunoOptions* pOptions)
2517 {
2518 sal_Bool ret = sal_False;
2519
2520 if (pOptions->isValid("-U"))
2521 m_cunoTypeDynamic = sal_True;
2522
2523 OString outPath;
2524 if (pOptions->isValid("-O"))
2525 outPath = pOptions->getOption("-O");
2526
2527 OString tmpName(m_typeName);
2528
2529 if (tmpName.equals("/"))
2530 tmpName = "global";
2531 else
2532 // tmpName += "/" + m_typeName.getToken(m_typeName.getTokenCount('/') - 1, '/');
2533 tmpName += "/" + m_name;
2534
2535 OString tmpFileName;
2536 OString hFileName = createFileNameFromType(outPath, tmpName, ".hdl");
2537
2538 sal_Bool bFileExists = sal_False;
2539 sal_Bool bFileCheck = sal_False;
2540
2541 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
2542 {
2543 bFileExists = fileExists( hFileName );
2544 ret = sal_True;
2545 }
2546
2547 if ( bFileExists && pOptions->isValid("-Gc") )
2548 {
2549 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tml");
2550 bFileCheck = sal_True;
2551 }
2552
2553 if ( !bFileExists || bFileCheck )
2554 {
2555 FileStream hFile;
2556
2557 if ( bFileCheck )
2558 hFile.open(tmpFileName);
2559 else
2560 hFile.open(hFileName);
2561
2562 if(!hFile.isValid())
2563 {
2564 OString message("cannot open ");
2565 message += hFileName + " for writing";
2566 throw CannotDumpException(message);
2567 }
2568
2569 ret = dumpHFile(hFile);
2570
2571 hFile.close();
2572 if (ret && bFileCheck)
2573 {
2574 ret = checkFileContent(hFileName, tmpFileName);
2575 }
2576 }
2577 /*
2578 bFileExists = sal_False;
2579 bFileCheck = sal_False;
2580 OString cFileName = createFileNameFromType(outPath, tmpName, ".c");
2581
2582 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
2583 {
2584 bFileExists = fileExists( cFileName );
2585 ret = sal_True;
2586 }
2587
2588 if ( bFileExists && pOptions->isValid("-Gc") )
2589 {
2590 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmc");
2591 bFileCheck = sal_True;
2592 }
2593
2594
2595 if ( !bFileExists || bFileCheck )
2596 {
2597 FileStream hxxFile;
2598
2599 if ( bFileCheck )
2600 cFile.open(tmpFileName);
2601 else
2602 cFile.open(cFileName);
2603
2604 if(!cFile.isValid())
2605 {
2606 OString message("cannot open ");
2607 message += cFileName + " for writing";
2608 throw CannotDumpException(message);
2609 }
2610
2611 ret = dumpCFile(cFile);
2612
2613 cFile.close();
2614 if (ret && bFileCheck)
2615 {
2616 ret = checkFileContent(cFileName, tmpFileName);
2617 }
2618 }
2619 */
2620 return ret;
2621 }
2622
dumpHFile(FileStream & o)2623 sal_Bool ModuleType::dumpHFile(FileStream& o)
2624 {
2625 sal_Bool bSpecialDefine = sal_True;
2626
2627 if (m_reader.getTypeClass() == RT_TYPE_CONSTANTS)
2628 {
2629 bSpecialDefine = sal_False;
2630 }
2631
2632 OString headerDefine(dumpHeaderDefine(o, "H", bSpecialDefine));
2633 o << "\n";
2634
2635 dumpDefaultHIncludes(o);
2636 o << "\n";
2637 dumpDepIncludes(o, m_typeName, "h");
2638 o << "\n";
2639
2640 dumpOpenExternC(o);
2641 dumpDeclaration(o);
2642 o << "\n";
2643 dumpCloseExternC(o);
2644
2645 o << "\n#endif /* "<< headerDefine << " */\n";
2646
2647 return sal_True;
2648 }
2649
dumpDeclaration(FileStream & o)2650 sal_Bool ModuleType::dumpDeclaration(FileStream& o)
2651 {
2652 sal_uInt32 fieldCount = m_reader.getFieldCount();
2653 RTFieldAccess access = RT_ACCESS_INVALID;
2654 OString fieldName;
2655 OString fieldType;
2656 for (sal_uInt16 i=0; i < fieldCount; i++)
2657 {
2658 access = m_reader.getFieldAccess(i);
2659
2660 if (access == RT_ACCESS_CONST)
2661 {
2662 fieldName = m_reader.getFieldName(i);
2663 fieldType = m_reader.getFieldType(i);
2664
2665 o << "static const ";
2666 dumpType(o, fieldType);
2667 o << " " << m_name << "_" << fieldName << " = ";
2668 dumpConstantValue(o, i);
2669 o << ";\n";
2670 }
2671 }
2672
2673 return sal_True;
2674 }
2675
hasConstants()2676 sal_Bool ModuleType::hasConstants()
2677 {
2678 sal_uInt32 fieldCount = m_reader.getFieldCount();
2679 RTFieldAccess access = RT_ACCESS_INVALID;
2680
2681 for (sal_uInt16 i=0; i < fieldCount; i++)
2682 {
2683 access = m_reader.getFieldAccess(i);
2684
2685 if (access == RT_ACCESS_CONST)
2686 return sal_True;
2687 }
2688
2689 return sal_False;
2690 }
2691
dumpCFile(FileStream & o)2692 sal_Bool ModuleType::dumpCFile(FileStream& o)
2693 {
2694 return sal_True;
2695 }
2696
2697 //*************************************************************************
2698 // ConstantsType
2699 //*************************************************************************
ConstantsType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies)2700 ConstantsType::ConstantsType(TypeReader& typeReader,
2701 const OString& typeName,
2702 const TypeManager& typeMgr,
2703 const TypeDependency& typeDependencies)
2704 : ModuleType(typeReader, typeName, typeMgr, typeDependencies)
2705 {
2706 }
2707
~ConstantsType()2708 ConstantsType::~ConstantsType()
2709 {
2710
2711 }
2712
dump(CunoOptions * pOptions)2713 sal_Bool ConstantsType::dump(CunoOptions* pOptions)
2714 {
2715 sal_Bool ret = sal_False;
2716
2717 if (pOptions->isValid("-U"))
2718 m_cunoTypeDynamic = sal_True;
2719
2720 OString outPath;
2721 if (pOptions->isValid("-O"))
2722 outPath = pOptions->getOption("-O");
2723
2724 OString tmpFileName;
2725 OString hFileName = createFileNameFromType(outPath, m_typeName, ".h");
2726
2727 sal_Bool bFileExists = sal_False;
2728 sal_Bool bFileCheck = sal_False;
2729
2730 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
2731 {
2732 bFileExists = fileExists( hFileName );
2733 ret = sal_True;
2734 }
2735
2736 if ( bFileExists && pOptions->isValid("-Gc") )
2737 {
2738 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmh");
2739 bFileCheck = sal_True;
2740 }
2741
2742 if ( !bFileExists || bFileCheck )
2743 {
2744 FileStream hFile;
2745
2746 if ( bFileCheck )
2747 hFile.open(tmpFileName);
2748 else
2749 hFile.open(hFileName);
2750
2751 if(!hFile.isValid())
2752 {
2753 OString message("cannot open ");
2754 message += hFileName + " for writing";
2755 throw CannotDumpException(message);
2756 }
2757
2758 ret = dumpHFile(hFile);
2759
2760 hFile.close();
2761 if (ret && bFileCheck)
2762 {
2763 ret = checkFileContent(hFileName, tmpFileName);
2764 }
2765 }
2766 /*
2767 bFileExists = sal_False;
2768 bFileCheck = sal_False;
2769 OString cFileName = createFileNameFromType(outPath, m_typeName, ".c");
2770
2771 if ( pOptions->isValid("-G") || pOptions->isValid("-Gc") )
2772 {
2773 bFileExists = fileExists( cFileName );
2774 ret = sal_True;
2775 }
2776
2777 if ( bFileExists && pOptions->isValid("-Gc") )
2778 {
2779 tmpFileName = createFileNameFromType(outPath, m_typeName, ".tmc");
2780 bFileCheck = sal_True;
2781 }
2782
2783 if ( !bFileExists || bFileCheck )
2784 {
2785 FileStream cFile;
2786
2787 if ( bFileCheck )
2788 cFile.open(tmpFileName);
2789 else
2790 cFile.open(cFileName);
2791
2792 if(!cFile.isValid())
2793 {
2794 OString message("cannot open ");
2795 message += cFileName + " for writing";
2796 throw CannotDumpException(message);
2797 }
2798
2799 ret = dumpCFile(cFile);
2800
2801 cFile.close();
2802 if (ret && bFileCheck)
2803 {
2804 ret = checkFileContent(cFileName, tmpFileName);
2805 }
2806 }
2807 */
2808 return ret;
2809 }
2810
2811 //*************************************************************************
2812 // StructureType
2813 //*************************************************************************
StructureType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies)2814 StructureType::StructureType(TypeReader& typeReader,
2815 const OString& typeName,
2816 const TypeManager& typeMgr,
2817 const TypeDependency& typeDependencies)
2818 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
2819 {
2820 }
2821
~StructureType()2822 StructureType::~StructureType()
2823 {
2824
2825 }
2826
dumpHFile(FileStream & o)2827 sal_Bool StructureType::dumpHFile(FileStream& o)
2828 {
2829 OString headerDefine(dumpHeaderDefine(o, "H"));
2830 o << "\n";
2831
2832 dumpDefaultHIncludes(o);
2833 o << "\n";
2834 dumpDepIncludes(o, m_typeName, "h");
2835 o << "\n";
2836
2837 dumpOpenExternC(o);
2838
2839 dumpDeclaration(o);
2840
2841 if ( m_cunoTypeLib )
2842 {
2843 o << "#ifdef CUNO_TYPELIB\n"
2844 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () );\n"
2845 << "#endif\n\n";
2846 }
2847
2848 dumpCloseExternC(o);
2849
2850 o << "#endif /* "<< headerDefine << " */\n";
2851
2852 return sal_True;
2853 }
2854
dumpDeclaration(FileStream & o)2855 sal_Bool StructureType::dumpDeclaration(FileStream& o)
2856 {
2857 o << "#ifdef SAL_W32\n"
2858 << "# pragma pack(push, 8)\n"
2859 << "#elif defined(SAL_OS2)\n"
2860 << "# pragma pack(8)\n"
2861 << "#endif\n\n";
2862
2863 o << "typedef struct _" << m_name << "\n{\n";
2864 inc();
2865
2866 OString superType(m_reader.getSuperTypeName());
2867 if ( !superType.isEmpty() )
2868 o << indent() << superType.replace('/', '_').getStr() << " _Base;\n";
2869 //dumpInheritedMembers(o, superType);
2870
2871 sal_uInt32 fieldCount = m_reader.getFieldCount();
2872 RTFieldAccess access = RT_ACCESS_INVALID;
2873 OString fieldName;
2874 OString fieldType;
2875 sal_uInt16 i=0;
2876
2877 for (i=0; i < fieldCount; i++)
2878 {
2879 access = m_reader.getFieldAccess(i);
2880
2881 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2882 continue;
2883
2884 fieldName = m_reader.getFieldName(i);
2885 fieldType = m_reader.getFieldType(i);
2886
2887 o << indent();
2888 dumpType(o, fieldType);
2889 o << " " << fieldName << ";\n";
2890 }
2891
2892 dec();
2893 o << "} " << m_name << ";\n\n";
2894
2895 o << "#ifdef SAL_W32\n"
2896 << "# pragma pack(pop)\n"
2897 << "#elif defined(SAL_OS2)\n"
2898 << "# pragma pack()\n"
2899 << "#endif\n\n";
2900
2901 return sal_True;
2902 }
2903
dumpCFile(FileStream & o)2904 sal_Bool StructureType::dumpCFile(FileStream& o)
2905 {
2906 dumpInclude(o, m_typeName, "h");
2907 o << "\n";
2908 dumpDefaultCIncludes(o);
2909 o << "\n";
2910 dumpDepIncludes(o, m_typeName, "h");
2911 o << "\n";
2912
2913 dumpGetCunoType(o);
2914
2915 return sal_True;
2916 }
2917
2918 //*************************************************************************
2919 // ExceptionType
2920 //*************************************************************************
ExceptionType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies)2921 ExceptionType::ExceptionType(TypeReader& typeReader,
2922 const OString& typeName,
2923 const TypeManager& typeMgr,
2924 const TypeDependency& typeDependencies)
2925 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
2926 {
2927 }
2928
~ExceptionType()2929 ExceptionType::~ExceptionType()
2930 {
2931
2932 }
2933
dumpHFile(FileStream & o)2934 sal_Bool ExceptionType::dumpHFile(FileStream& o)
2935 {
2936 OString headerDefine(dumpHeaderDefine(o, "H"));
2937 o << "\n";
2938
2939 dumpDefaultHIncludes(o);
2940 o << "\n";
2941 dumpDepIncludes(o, m_typeName, "h");
2942 o << "\n";
2943
2944 dumpOpenExternC(o);
2945
2946 dumpDeclaration(o);
2947
2948 if ( m_cunoTypeLib )
2949 {
2950 o << "#ifdef CUNO_TYPELIB\n"
2951 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () );\n"
2952 << "#endif\n\n";
2953 }
2954
2955 dumpCloseExternC(o);
2956
2957 o << "#endif /* "<< headerDefine << " */\n";
2958
2959 return sal_True;
2960 }
2961
dumpDeclaration(FileStream & o)2962 sal_Bool ExceptionType::dumpDeclaration(FileStream& o)
2963 {
2964 o << "#ifdef SAL_W32\n"
2965 << "# pragma pack(push, 8)\n"
2966 << "#elif defined(SAL_OS2)\n"
2967 << "# pragma pack(8)\n"
2968 << "#endif\n\n";
2969
2970 o << "\n/* Exception type */\ntypedef struct _" << m_name << "\n{\n";
2971 inc();
2972
2973 OString superType(m_reader.getSuperTypeName());
2974 if ( !superType.isEmpty() )
2975 o << indent() << superType.replace('/', '_').getStr() << " _Base;\n";
2976 //dumpInheritedMembers(o, superType);
2977
2978 sal_uInt32 fieldCount = m_reader.getFieldCount();
2979 RTFieldAccess access = RT_ACCESS_INVALID;
2980 OString fieldName;
2981 OString fieldType;
2982 sal_uInt16 i = 0;
2983
2984 for (i=0; i < fieldCount; i++)
2985 {
2986 access = m_reader.getFieldAccess(i);
2987
2988 if (access == RT_ACCESS_CONST || access == RT_ACCESS_INVALID)
2989 continue;
2990
2991 fieldName = m_reader.getFieldName(i);
2992 fieldType = m_reader.getFieldType(i);
2993
2994 o << indent();
2995 dumpType(o, fieldType);
2996 o << " " << fieldName << ";\n";
2997 }
2998
2999 dec();
3000 o << "} " << m_name << ";\n\n";
3001
3002 o << "#ifdef SAL_W32\n"
3003 << "# pragma pack(pop)\n"
3004 << "#elif defined(SAL_OS2)\n"
3005 << "# pragma pack()\n"
3006 << "#endif\n\n";
3007
3008 return sal_True;
3009 }
3010
dumpCFile(FileStream & o)3011 sal_Bool ExceptionType::dumpCFile(FileStream& o)
3012 {
3013 dumpInclude(o, m_typeName, "h");
3014 o << "\n";
3015 dumpDefaultCIncludes(o);
3016 o << "\n";
3017 dumpDepIncludes(o, m_typeName, "h");
3018 o << "\n";
3019
3020 dumpGetCunoType(o);
3021
3022 return sal_True;
3023 }
3024
3025
3026 //*************************************************************************
3027 // EnumType
3028 //*************************************************************************
EnumType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies)3029 EnumType::EnumType(TypeReader& typeReader,
3030 const OString& typeName,
3031 const TypeManager& typeMgr,
3032 const TypeDependency& typeDependencies)
3033 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
3034 {
3035 }
3036
~EnumType()3037 EnumType::~EnumType()
3038 {
3039
3040 }
3041
dumpHFile(FileStream & o)3042 sal_Bool EnumType::dumpHFile(FileStream& o)
3043 {
3044 OString headerDefine(dumpHeaderDefine(o, "H"));
3045 o << "\n";
3046
3047 dumpDefaultHIncludes(o);
3048 o << "\n";
3049 dumpOpenExternC(o);
3050
3051 dumpDeclaration(o);
3052
3053 if ( m_cunoTypeLib )
3054 {
3055 o << "#ifdef CUNO_TYPELIB\n"
3056 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () );\n"
3057 << "#endif\n\n";
3058 }
3059
3060 dumpCloseExternC(o);
3061
3062 o << "#endif /* "<< headerDefine << " */\n";
3063
3064 return sal_True;
3065 }
3066
dumpDeclaration(FileStream & o)3067 sal_Bool EnumType::dumpDeclaration(FileStream& o)
3068 {
3069 o << "\ntypedef enum _" << m_name << "\n{\n";
3070 inc();
3071
3072 sal_uInt32 fieldCount = m_reader.getFieldCount();
3073 RTFieldAccess access = RT_ACCESS_INVALID;
3074 RTConstValue constValue;
3075 OString fieldName;
3076 sal_Int32 value=0;
3077 for (sal_uInt16 i=0; i < fieldCount; i++)
3078 {
3079 access = m_reader.getFieldAccess(i);
3080
3081 if (access != RT_ACCESS_CONST)
3082 continue;
3083
3084 fieldName = m_reader.getFieldName(i);
3085 constValue = m_reader.getFieldConstValue(i);
3086
3087 if (constValue.m_type == RT_TYPE_INT32)
3088 value = constValue.m_value.aLong;
3089 else
3090 value++;
3091
3092 o << indent() << m_name << "_" << fieldName << " = " << value << ",\n";
3093 }
3094
3095 o << indent() << m_name << "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n";
3096
3097 dec();
3098 o << "} " << m_name << ";\n\n";
3099
3100 return sal_True;
3101 }
3102
dumpCFile(FileStream & o)3103 sal_Bool EnumType::dumpCFile(FileStream& o)
3104 {
3105 dumpInclude(o, m_typeName, "h");
3106 o << "\n";
3107 dumpDefaultCIncludes(o);
3108 o << "\n";
3109 dumpGetCunoType(o);
3110 return sal_True;
3111 }
3112
dumpGetCunoType(FileStream & o)3113 void EnumType::dumpGetCunoType(FileStream& o)
3114 {
3115 OString typeName(m_typeName.replace('/', '_'));
3116
3117 if ( m_cunoTypeLeak )
3118 {
3119 dumpLGetCunoType(o);
3120 return;
3121 }
3122 if ( !m_cunoTypeDynamic )
3123 {
3124 dumpCGetCunoType(o);
3125 return;
3126 }
3127
3128 dumpOpenExternC(o);
3129
3130 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3131 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
3132 << "#endif\n\n";
3133
3134 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
3135 inc();
3136
3137 o << indent() << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3138 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
3139 << indent() << "#endif\n\n";
3140
3141 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
3142 inc();
3143
3144 o << indent() << "typelib_static_enum_type_init( &s_pType_" << typeName << ",\n";
3145 inc(31);
3146 o << indent() << "\"" << m_typeName.replace('/', '.') << "\",\n"
3147 << indent() << m_name << "_" << m_reader.getFieldName(0) << " );\n";
3148 dec(31);
3149 dec();
3150 o << indent() << "}\n"
3151 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName <<" );\n"
3152 << indent() << "return &s_pType_" << typeName <<" );\n";
3153 dec();
3154 o << indent() << "}\n";
3155
3156 dumpCloseExternC(o);
3157 }
3158
dumpCGetCunoType(FileStream & o)3159 void EnumType::dumpCGetCunoType(FileStream& o)
3160 {
3161 OString typeName(m_typeName.replace('/', '_'));
3162
3163 dumpOpenExternC(o);
3164
3165 o << "#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3166 << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
3167 << "#endif\n\n";
3168
3169 o << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () )\n{\n";
3170 inc();
3171
3172 o << "#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))\n"
3173 << indent() << "static typelib_TypeDescriptionReference * s_pType_" << typeName << " = 0;\n"
3174 << "#endif\n\n";
3175
3176 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
3177 inc();
3178 o << indent() << "oslMutex * pMutex = osl_getGlobalMutex();\n"
3179 << indent() << "osl_acquireMutex( pMutex );\n";
3180
3181 o << indent() << "if ( !s_pType_" << typeName << " )\n" << indent() << "{\n";
3182 inc();
3183 o << indent() << "rtl_uString * pTypeName = 0;\n"
3184 << indent() << "_typelib_TypeDescription * pTD = 0;\n";
3185
3186 sal_uInt32 count = m_reader.getFieldCount();
3187 o << indent() << "rtl_uString* enumValueNames[" << count << "];\n"
3188 << indent() << "sal_Int32 enumValues[" << count << "];\n";
3189 sal_uInt32 i;
3190 for (i = 0; i < count; i++)
3191 {
3192 o << indent() << "rtl_uString * pEnumValue" << i << " = 0;\n";
3193 }
3194
3195 o << indent() << "rtl_uString_newFromAscii( &pTypeName, \""
3196 << m_typeName.replace('/', '.') << "\") );\n\n";
3197
3198 for (i = 0; i < count; i++)
3199 {
3200 o << indent() << "rtl_uString_newFromAscii( &pEnumValue" << i << ", \""
3201 << m_reader.getFieldName((sal_uInt16)i) << "\" );\n";
3202 o << indent() << "enumValueNames[" << i << "] = pEnumValue" << i << ";\n";
3203 }
3204
3205 RTConstValue constValue;
3206 sal_Int32 value=0;
3207 for (i = 0; i < count; i++)
3208 {
3209 o << indent() << "enumValues[" << i << "] = ";
3210 constValue = m_reader.getFieldConstValue((sal_uInt16)i);
3211 if (constValue.m_type == RT_TYPE_INT32)
3212 value = constValue.m_value.aLong;
3213 else
3214 value++;
3215 o << value << ";\n";
3216 }
3217
3218 o << "\n" << indent() << "typelib_typedescription_newEnum( &pTD,\n";
3219 inc();
3220 o << indent() << "pTypeName,\n"
3221 << indent() << "(sal_Int32)" << m_name << "_" << m_reader.getFieldName(0) << ",\n"
3222 << indent() << count << ", enumValueNames, enumValues );\n\n";
3223 dec();
3224
3225 o << indent() << "typelib_typedescription_register( &pTD );\n";
3226
3227 o << indent() << "typelib_typedescriptionreference_new( &s_pType_ " << typeName
3228 << getTypeClass(OString(), sal_True) << ", pTD);\n\n";
3229
3230 o << indent() << "typelib_typedescription_release( pTD );\n"
3231 << indent() << "rtl_uString_release( pTypeName );\n";
3232 for (i = 0; i < count; i++)
3233 {
3234 o << indent() << "rtl_uString_release( pEnumValue" << i << " );\n";
3235 }
3236
3237 dec();
3238 o << indent() << "}\n";
3239 o << indent() << "osl_releaseMutex( pMutex );\n";
3240 dec();
3241 o << indent() << "}\n\n"
3242 << indent() << "typelib_typedescriptionreference_acquire( s_pType_" << typeName <<" );\n"
3243 << indent() << "return &s_pType_" << typeName <<" );\n";
3244
3245 dec();
3246 o << "}\n";
3247
3248 dumpCloseExternC(o);
3249 }
3250
3251 //*************************************************************************
3252 // TypeDefType
3253 //*************************************************************************
TypeDefType(TypeReader & typeReader,const OString & typeName,const TypeManager & typeMgr,const TypeDependency & typeDependencies)3254 TypeDefType::TypeDefType(TypeReader& typeReader,
3255 const OString& typeName,
3256 const TypeManager& typeMgr,
3257 const TypeDependency& typeDependencies)
3258 : CunoType(typeReader, typeName, typeMgr, typeDependencies)
3259 {
3260 }
3261
~TypeDefType()3262 TypeDefType::~TypeDefType()
3263 {
3264
3265 }
3266
dumpHFile(FileStream & o)3267 sal_Bool TypeDefType::dumpHFile(FileStream& o)
3268 {
3269 OString headerDefine(dumpHeaderDefine(o, "H"));
3270 o << "\n";
3271
3272 dumpDefaultHIncludes(o);
3273 o << "\n";
3274 dumpDepIncludes(o, m_typeName, "h");
3275 o << "\n";
3276
3277 dumpOpenExternC(o);
3278
3279 dumpDeclaration(o);
3280
3281 if ( m_cunoTypeLib )
3282 {
3283 o << "#ifdef CUNO_TYPELIB\n"
3284 << "typelib_TypeDescriptionReference ** SAL_CALL getCUnoType_" << m_name << "() SAL_THROW_EXTERN_C( () );\n"
3285 << "#endif\n\n";
3286 }
3287
3288 dumpCloseExternC(o);
3289
3290 o << "#endif /* "<< headerDefine << " */\n";
3291
3292 return sal_True;
3293 }
3294
dumpDeclaration(FileStream & o)3295 sal_Bool TypeDefType::dumpDeclaration(FileStream& o)
3296 {
3297 o << "\ntypedef ";
3298 dumpType(o, m_reader.getSuperTypeName());
3299 o << " " << m_name << ";\n\n";
3300
3301 return sal_True;
3302 }
3303
dumpCFile(FileStream & o)3304 sal_Bool TypeDefType::dumpCFile(FileStream& o)
3305 {
3306 dumpInclude(o, m_typeName, "h");
3307 o << "\n";
3308 dumpDefaultCIncludes(o);
3309 o << "\n";
3310 dumpDepIncludes(o, m_typeName, "h");
3311 o << "\n";
3312 dumpGetCunoType(o);
3313 return sal_True;
3314 }
3315
dumpGetCunoType(FileStream & o)3316 void TypeDefType::dumpGetCunoType(FileStream& o)
3317 {
3318 if ( m_cunoTypeLeak )
3319 {
3320 dumpLGetCunoType(o);
3321 return;
3322 }
3323 if ( !m_cunoTypeDynamic )
3324 {
3325 dumpCGetCunoType(o);
3326 return;
3327 }
3328 }
3329
dumpCGetCunoType(FileStream & o)3330 void TypeDefType::dumpCGetCunoType(FileStream& o)
3331 {
3332 }
3333
dumpLGetCunoType(FileStream & o)3334 void TypeDefType::dumpLGetCunoType(FileStream& o)
3335 {
3336 }
3337
3338 //*************************************************************************
3339 // produceType
3340 //*************************************************************************
produceType(const OString & typeName,TypeManager & typeMgr,TypeDependency & typeDependencies,CunoOptions * pOptions)3341 sal_Bool produceType(const OString& typeName,
3342 TypeManager& typeMgr,
3343 TypeDependency& typeDependencies,
3344 CunoOptions* pOptions)
3345 {
3346 if (typeDependencies.isGenerated(typeName))
3347 return sal_True;
3348
3349 TypeReader reader(typeMgr.getTypeReader(typeName));
3350
3351 if (!reader.isValid())
3352 {
3353 if (typeName.equals("/"))
3354 return sal_True;
3355 else
3356 return sal_False;
3357 }
3358
3359 if( !checkTypeDependencies(typeMgr, typeDependencies, typeName))
3360 return sal_False;
3361
3362 RTTypeClass typeClass = reader.getTypeClass();
3363 sal_Bool ret = sal_False;
3364 switch (typeClass)
3365 {
3366 case RT_TYPE_INTERFACE:
3367 {
3368 InterfaceType iType(reader, typeName, typeMgr, typeDependencies);
3369 ret = iType.dump(pOptions);
3370 if (ret) typeDependencies.setGenerated(typeName);
3371 ret = iType.dumpDependedTypes(pOptions);
3372 }
3373 break;
3374 case RT_TYPE_MODULE:
3375 {
3376 ModuleType mType(reader, typeName, typeMgr, typeDependencies);
3377 if (mType.hasConstants())
3378 {
3379 ret = mType.dump(pOptions);
3380 if (ret) typeDependencies.setGenerated(typeName);
3381 // ret = mType.dumpDependedTypes(pOptions);
3382 } else
3383 {
3384 typeDependencies.setGenerated(typeName);
3385 ret = sal_True;
3386 }
3387 }
3388 break;
3389 case RT_TYPE_STRUCT:
3390 {
3391 StructureType sType(reader, typeName, typeMgr, typeDependencies);
3392 ret = sType.dump(pOptions);
3393 if (ret) typeDependencies.setGenerated(typeName);
3394 ret = sType.dumpDependedTypes(pOptions);
3395 }
3396 break;
3397 case RT_TYPE_ENUM:
3398 {
3399 EnumType enType(reader, typeName, typeMgr, typeDependencies);
3400 ret = enType.dump(pOptions);
3401 if (ret) typeDependencies.setGenerated(typeName);
3402 ret = enType.dumpDependedTypes(pOptions);
3403 }
3404 break;
3405 case RT_TYPE_EXCEPTION:
3406 {
3407 ExceptionType eType(reader, typeName, typeMgr, typeDependencies);
3408 ret = eType.dump(pOptions);
3409 if (ret) typeDependencies.setGenerated(typeName);
3410 ret = eType.dumpDependedTypes(pOptions);
3411 }
3412 break;
3413 case RT_TYPE_TYPEDEF:
3414 {
3415 TypeDefType tdType(reader, typeName, typeMgr, typeDependencies);
3416 ret = tdType.dump(pOptions);
3417 if (ret) typeDependencies.setGenerated(typeName);
3418 ret = tdType.dumpDependedTypes(pOptions);
3419 }
3420 break;
3421 case RT_TYPE_CONSTANTS:
3422 {
3423 ConstantsType cType(reader, typeName, typeMgr, typeDependencies);
3424 if (cType.hasConstants())
3425 {
3426 ret = cType.dump(pOptions);
3427 if (ret) typeDependencies.setGenerated(typeName);
3428 // ret = cType.dumpDependedTypes(pOptions);
3429 } else
3430 {
3431 typeDependencies.setGenerated(typeName);
3432 ret = sal_True;
3433 }
3434 }
3435 break;
3436 case RT_TYPE_SERVICE:
3437 case RT_TYPE_OBJECT:
3438 ret = sal_True;
3439 break;
3440 }
3441
3442 return ret;
3443 }
3444
3445 //*************************************************************************
3446 // scopedName
3447 //*************************************************************************
scopedName(const OString & scope,const OString & type,sal_Bool bNoNameSpace)3448 OString scopedName(const OString& scope, const OString& type,
3449 sal_Bool bNoNameSpace)
3450 {
3451 sal_Int32 nPos = type.lastIndexOf( '/' );
3452 if (nPos == -1)
3453 return type;
3454
3455 if (bNoNameSpace)
3456 return type.copy(nPos+1);
3457
3458 OStringBuffer tmpBuf(type.getLength()*2);
3459 nPos = 0;
3460 do
3461 {
3462 tmpBuf.append("::");
3463 tmpBuf.append(type.getToken(0, '/', nPos));
3464 } while( nPos != -1 );
3465
3466 return tmpBuf.makeStringAndClear();
3467 }
3468
3469 //*************************************************************************
3470 // shortScopedName
3471 //*************************************************************************
shortScopedName(const OString & scope,const OString & type,sal_Bool bNoNameSpace)3472 OString shortScopedName(const OString& scope, const OString& type,
3473 sal_Bool bNoNameSpace)
3474 {
3475 sal_Int32 nPos = type.lastIndexOf( '/' );
3476 if( nPos == -1 )
3477 return OString();
3478
3479 if (bNoNameSpace)
3480 return OString();
3481
3482 // scoped name only if the namespace is not equal
3483 if (scope.lastIndexOf('/') > 0)
3484 {
3485 OString tmpScp(scope.copy(0, scope.lastIndexOf('/')));
3486 OString tmpScp2(type.copy(0, nPos));
3487
3488 if (tmpScp == tmpScp2)
3489 return OString();
3490 }
3491
3492 OString aScope( type.copy( 0, nPos ) );
3493 OStringBuffer tmpBuf(aScope.getLength()*2);
3494
3495 nPos = 0;
3496 do
3497 {
3498 tmpBuf.append("::");
3499 tmpBuf.append(aScope.getToken(0, '/', nPos));
3500 } while( nPos != -1 );
3501
3502 return tmpBuf.makeStringAndClear();
3503 }
3504