Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "osl/thread.hxx"
21 :
22 : #include "codemaker/commonjava.hxx"
23 : #include "codemaker/commoncpp.hxx"
24 : #include "codemaker/generatedtypeset.hxx"
25 :
26 : #include "skeletoncommon.hxx"
27 :
28 : #include <iostream>
29 :
30 : using namespace ::rtl;
31 : using namespace ::codemaker::cpp;
32 :
33 : namespace skeletonmaker {
34 :
35 0 : void printLicenseHeader(std::ostream& o, rtl::OString const & filename)
36 : {
37 0 : sal_Int32 index = -1;
38 : #ifdef SAL_UNX
39 0 : index = filename.lastIndexOf('/');
40 : #else
41 : index = filename.lastIndexOf('\\');
42 : #endif
43 0 : OString shortfilename(filename);
44 0 : if ( index != -1 )
45 0 : shortfilename = filename.copy(index+1);
46 :
47 : o << "/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */\n"
48 : "/*\n"
49 : " * Copyright 2012 LibreOffice contributors.\n"
50 : " *\n"
51 : " * This Source Code Form is subject to the terms of the Mozilla Public\n"
52 : " * License, v. 2.0. If a copy of the MPL was not distributed with this\n"
53 : " * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n"
54 0 : " */\n\n";
55 0 : }
56 :
57 0 : bool getOutputStream(ProgramOptions const & options,
58 : OString const & extension,
59 : std::ostream** ppOutputStream,
60 : OString & targetSourceFileName,
61 : OString & tmpSourceFileName)
62 : {
63 0 : bool bStandardout = false;
64 0 : if ( options.outputpath.equals("stdout") )
65 : {
66 0 : bStandardout = true;
67 0 : *ppOutputStream = &std::cout;
68 0 : return bStandardout;
69 : }
70 :
71 : targetSourceFileName = createFileNameFromType(
72 0 : options.outputpath, options.implname.replace('.','/'), extension);
73 :
74 0 : OString tmpDir = getTempDir(targetSourceFileName);
75 0 : FileStream file;
76 0 : file.createTempFile(tmpDir);
77 :
78 0 : if( !file.isValid() )
79 : {
80 0 : OString message("cannot open ");
81 0 : message += targetSourceFileName + " for writing";
82 0 : throw CannotDumpException(message);
83 : } else {
84 0 : tmpSourceFileName = file.getName();
85 : }
86 0 : file.close();
87 : *ppOutputStream = new std::ofstream(tmpSourceFileName.getStr(),
88 0 : std::ios_base::binary);
89 :
90 0 : return bStandardout;
91 : }
92 :
93 0 : codemaker::UnoType::Sort decomposeResolveAndCheck(
94 : TypeManager const & manager, OString const & type,
95 : bool resolveTypedefs, bool allowVoid, bool allowExtraEntities,
96 : RTTypeClass * typeClass, OString * name, sal_Int32 * rank,
97 : std::vector< OString > * arguments)
98 : {
99 : codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve(
100 : manager, type, resolveTypedefs, allowVoid, allowExtraEntities,
101 0 : typeClass, name, rank, arguments);
102 0 : for ( std::vector< OString >::iterator i(arguments->begin());
103 0 : i != arguments->end(); ++i )
104 : {
105 : RTTypeClass typeClass2;
106 0 : OString name2;
107 : sal_Int32 rank2;
108 0 : std::vector< OString > arguments2;
109 : decomposeResolveAndCheck(
110 0 : manager, *i, true, false, false, &typeClass2, &name2, &rank2,
111 0 : &arguments2);
112 0 : }
113 0 : return sort;
114 : }
115 :
116 0 : bool containsAttribute(AttributeInfo& attributes, OString const & attrname)
117 : {
118 0 : for ( AttributeInfo::const_iterator i(attributes.begin());
119 0 : i != attributes.end(); ++i ) {
120 0 : if ( (*i).first == attrname ) {
121 0 : return true;
122 : }
123 : }
124 0 : return false;
125 : }
126 :
127 : // collect attributes including inherited attributes
128 0 : void checkAttributes(TypeManager const & manager,
129 : const typereg::Reader& reader,
130 : AttributeInfo& attributes,
131 : boost::unordered_set< OString, OStringHash >& propinterfaces)
132 : {
133 0 : OString typeName = codemaker::convertString(reader.getTypeName());
134 0 : if ( typeName.equals("com/sun/star/beans/XPropertySet") ||
135 0 : typeName.equals("com/sun/star/beans/XFastPropertySet") ||
136 : // typeName.equals("com/sun/star/beans/XMultiPropertySet") ||
137 0 : typeName.equals("com/sun/star/beans/XPropertyAccess") )
138 : {
139 0 : propinterfaces.insert(typeName);
140 : }
141 :
142 0 : for ( sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i ) {
143 : typereg::Reader supertype(manager.getTypeReader(
144 : codemaker::convertString(
145 0 : reader.getSuperTypeName(i))));
146 0 : if ( !supertype.isValid() ) {
147 : throw CannotDumpException(
148 : "Bad type library entity "
149 0 : + codemaker::convertString(reader.getSuperTypeName(i)));
150 : }
151 0 : checkAttributes(manager, supertype, attributes, propinterfaces);
152 0 : }
153 :
154 0 : for ( sal_uInt16 i = 0; i < reader.getFieldCount(); ++i ) {
155 : OString fieldName(
156 : codemaker::convertString(reader.getFieldName(i)).
157 0 : replace('/', '.'));
158 :
159 0 : if ( !containsAttribute(attributes, fieldName) ) {
160 : OString fieldType(
161 : codemaker::convertString(reader.getFieldTypeName(i)).
162 0 : replace('/', '.'));
163 : attributes.push_back(AttributeInfo::value_type(
164 : fieldName, std::pair<OString, sal_Int16>(
165 0 : fieldType, reader.getFieldFlags(i))));
166 : }
167 0 : }
168 0 : }
169 :
170 0 : void checkType(TypeManager const & manager,
171 : OString const & type,
172 : boost::unordered_set< OString, OStringHash >& interfaceTypes,
173 : boost::unordered_set< OString, OStringHash >& serviceTypes,
174 : AttributeInfo& properties)
175 : {
176 :
177 0 : OString binType(type.replace('.', '/'));
178 0 : typereg::Reader reader(manager.getTypeReader(binType));
179 0 : if ( !reader.isValid() ) {
180 0 : throw CannotDumpException("Bad type library entity " + binType);
181 : }
182 :
183 0 : switch ( reader.getTypeClass() )
184 : {
185 : case RT_TYPE_INTERFACE:
186 : {
187 : // com/sun/star/lang/XComponent should be also not in the list
188 : // but it will be used for checking the impl helper and will be
189 : // removed later if necessary.
190 0 : if ( binType.equals("com/sun/star/lang/XTypeProvider") ||
191 0 : binType.equals("com/sun/star/uno/XWeak") )
192 0 : return;
193 0 : if (interfaceTypes.find(type) == interfaceTypes.end()) {
194 0 : interfaceTypes.insert(type);
195 : }
196 : }
197 0 : break;
198 : case RT_TYPE_SERVICE:
199 0 : if ( serviceTypes.find(binType) == serviceTypes.end() ) {
200 0 : serviceTypes.insert(binType);
201 :
202 0 : if ( reader.getSuperTypeCount() > 0 ) {
203 : OString supername(codemaker::convertString(
204 0 : reader.getSuperTypeName(0).replace('/', '.')));
205 0 : if ( interfaceTypes.find(supername) == interfaceTypes.end() ) {
206 0 : interfaceTypes.insert(supername);
207 :
208 : typereg::Reader supertype(manager.getTypeReader(
209 : codemaker::convertString(
210 0 : reader.getSuperTypeName(0))));
211 0 : if ( !supertype.isValid() ) {
212 : throw CannotDumpException(
213 : "Bad type library entity "
214 0 : + codemaker::convertString(reader.getSuperTypeName(0)));
215 0 : }
216 : }
217 :
218 : // check if constructors are specified, if yes automatically
219 : // support of XInitialization. We will take care of the default
220 : // constructor because in this case XInitialization is not called.
221 0 : if ( reader.getMethodCount() > 1 ||
222 0 : ( reader.getMethodCount() == 1 &&
223 0 : !reader.getMethodName(0).isEmpty() ) )
224 : {
225 0 : OString s("com.sun.star.lang.XInitialization");
226 0 : if ( interfaceTypes.find(s) == interfaceTypes.end() )
227 0 : interfaceTypes.insert(s);
228 0 : }
229 : } else {
230 0 : for ( sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i ) {
231 : OString referenceType(
232 : codemaker::convertString(
233 0 : reader.getReferenceTypeName(i)).replace('/', '.'));
234 :
235 0 : if ( reader.getReferenceSort(i) == RT_REF_SUPPORTS ) {
236 : checkType(manager, referenceType, interfaceTypes,
237 0 : serviceTypes, properties);
238 0 : } else if ( reader.getReferenceSort(i) == RT_REF_EXPORTS ) {
239 : checkType(manager, referenceType, interfaceTypes,
240 0 : serviceTypes, properties);
241 : }
242 0 : }
243 :
244 0 : for ( sal_uInt16 i = 0; i < reader.getFieldCount(); ++i ) {
245 : OString fieldName(
246 : codemaker::convertString(reader.getFieldName(i)).
247 0 : replace('/', '.'));
248 : OString fieldType(
249 : codemaker::convertString(reader.getFieldTypeName(i)).
250 0 : replace('/', '.'));
251 :
252 : properties.push_back(AttributeInfo::value_type(
253 : fieldName, std::pair<OString, sal_Int16>(
254 0 : fieldType, reader.getFieldFlags(i))));
255 0 : }
256 : }
257 : }
258 0 : break;
259 : default:
260 : OSL_ASSERT(false);
261 0 : break;
262 0 : }
263 : }
264 :
265 0 : void checkDefaultInterfaces(
266 : boost::unordered_set< OString, OStringHash >& interfaces,
267 : const boost::unordered_set< OString, OStringHash >& services,
268 : const OString & propertyhelper)
269 : {
270 0 : if ( services.empty() ) {
271 0 : if (interfaces.find("com.sun.star.lang.XServiceInfo") != interfaces.end())
272 0 : interfaces.erase("com.sun.star.lang.XServiceInfo");
273 : } else {
274 0 : if (interfaces.find("com.sun.star.lang.XServiceInfo") == interfaces.end())
275 0 : interfaces.insert("com.sun.star.lang.XServiceInfo");
276 : }
277 :
278 0 : if ( propertyhelper.equals("_") ) {
279 0 : if (interfaces.find("com.sun.star.beans.XPropertySet")
280 0 : != interfaces.end())
281 0 : interfaces.erase("com.sun.star.beans.XPropertySet");
282 0 : if (interfaces.find("com.sun.star.beans.XFastPropertySet")
283 0 : != interfaces.end())
284 0 : interfaces.erase("com.sun.star.beans.XFastPropertySet");
285 0 : if (interfaces.find("com.sun.star.beans.XPropertyAccess")
286 0 : != interfaces.end())
287 0 : interfaces.erase("com.sun.star.beans.XPropertyAccess");
288 : }
289 0 : }
290 :
291 0 : bool checkServiceProperties(TypeManager const & manager,
292 : const typereg::Reader & reader)
293 : {
294 0 : if ( reader.getFieldCount() > 0 )
295 0 : return true;
296 :
297 0 : if ( reader.getReferenceCount() > 0 ) {
298 0 : for ( sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i ) {
299 0 : if ( reader.getReferenceSort(i) == RT_REF_EXPORTS ) {
300 : typereg::Reader refreader(
301 : manager.getTypeReader(
302 0 : codemaker::convertString(reader.getReferenceTypeName(i))));
303 :
304 0 : if ( checkServiceProperties(manager, refreader) )
305 0 : return true;
306 : }
307 : }
308 : }
309 0 : return false;
310 : }
311 :
312 :
313 0 : OString checkPropertyHelper(
314 : ProgramOptions const & options,
315 : TypeManager const & manager,
316 : const boost::unordered_set< OString, OStringHash >& services,
317 : const boost::unordered_set< OString, OStringHash >& interfaces,
318 : AttributeInfo& attributes,
319 : boost::unordered_set< OString, OStringHash >& propinterfaces)
320 : {
321 0 : boost::unordered_set< OString, OStringHash >::const_iterator iter;
322 0 : boost::unordered_set< OString, OStringHash >::const_iterator end;
323 :
324 0 : if ( !services.empty() ) {
325 0 : iter = services.begin();
326 0 : end = services.end();
327 : } else {
328 0 : iter = interfaces.begin();
329 0 : end = interfaces.end();
330 : }
331 :
332 0 : bool oldStyleWithProperties = false;
333 0 : while ( iter != end ) {
334 0 : typereg::Reader reader(manager.getTypeReader((*iter).replace('.', '/')));
335 :
336 0 : if ( !services.empty() ) {
337 0 : if ( options.supportpropertysetmixin && reader.getSuperTypeCount() > 0 )
338 : {
339 : typereg::Reader supertype(
340 : manager.getTypeReader(
341 : codemaker::convertString(
342 0 : reader.getSuperTypeName(0))));
343 0 : if ( !supertype.isValid() ) {
344 : throw CannotDumpException(
345 : "Bad type library entity "
346 : + codemaker::convertString(
347 0 : reader.getSuperTypeName(0)));
348 : }
349 :
350 0 : checkAttributes(manager, supertype, attributes, propinterfaces);
351 :
352 0 : if ( !(attributes.empty() || propinterfaces.empty()) ) {
353 : return OUStringToOString(
354 : supertype.getTypeName().replace('/', '.'),
355 0 : osl_getThreadTextEncoding());
356 0 : }
357 : } else {
358 0 : oldStyleWithProperties = checkServiceProperties(manager, reader);
359 : }
360 : } else {
361 0 : checkAttributes(manager, reader, attributes, propinterfaces);
362 0 : if ( !(attributes.empty() || propinterfaces.empty()) ) {
363 : return OUStringToOString(
364 : reader.getTypeName().replace('/', '.'),
365 0 : osl_getThreadTextEncoding());
366 : }
367 : }
368 0 : ++iter;
369 0 : }
370 :
371 0 : return (oldStyleWithProperties ? "_" : "");
372 : }
373 :
374 0 : bool checkXComponentSupport(TypeManager const & manager,
375 : typereg::Reader const & reader)
376 : {
377 0 : static OUString s( "com/sun/star/lang/XComponent");
378 0 : if ( reader.getTypeName().equals(s) )
379 0 : return true;
380 :
381 0 : for ( sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i ) {
382 : typereg::Reader super(
383 : manager.getTypeReader(
384 : codemaker::convertString(
385 0 : reader.getSuperTypeName(i))));
386 0 : if ( !super.isValid() ) {
387 : throw CannotDumpException(
388 : "Bad type library entity "
389 : + codemaker::convertString(
390 0 : reader.getSuperTypeName(i)));
391 : }
392 0 : if ( checkXComponentSupport(manager, super) )
393 0 : return true;
394 0 : }
395 :
396 0 : return false;
397 : }
398 :
399 :
400 : // if XComponent is directly specified, return true and remove it from the
401 : // supported interfaces list
402 0 : bool checkXComponentSupport(TypeManager const & manager,
403 : boost::unordered_set< OString, OStringHash >& interfaces)
404 : {
405 0 : if ( interfaces.empty() )
406 0 : return false;
407 :
408 : boost::unordered_set< OString, OStringHash >::const_iterator iter =
409 0 : interfaces.begin();
410 0 : while ( iter != interfaces.end() ) {
411 0 : if ( (*iter).equals("com.sun.star.lang.XComponent") ) {
412 0 : interfaces.erase("com.sun.star.lang.XComponent");
413 0 : return true;
414 : }
415 0 : typereg::Reader reader(manager.getTypeReader((*iter).replace('.', '/')));
416 0 : if ( checkXComponentSupport(manager, reader) )
417 0 : return true;
418 0 : ++iter;
419 0 : }
420 :
421 0 : return false;
422 : }
423 :
424 0 : sal_uInt16 checkAdditionalPropertyFlags(typereg::Reader const & reader,
425 : sal_uInt16 field, sal_uInt16 method)
426 : {
427 0 : sal_uInt16 flags = 0;
428 0 : bool getterSupportsUnknown = false;
429 :
430 0 : OUString su( "com/sun/star/beans/UnknownPropertyException");
431 0 : if ( method < reader.getMethodCount()
432 0 : && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_GET
433 0 : && reader.getMethodName(method) == reader.getFieldName(field) )
434 : {
435 0 : if ( reader.getMethodExceptionCount(method) > 0 ) {
436 0 : for ( sal_uInt16 i = 0; i < reader.getMethodExceptionCount(method);
437 : ++i )
438 : {
439 0 : if (su.equals(reader.getMethodExceptionTypeName(method, i)))
440 0 : getterSupportsUnknown = true;
441 : }
442 : }
443 0 : method++;
444 : }
445 0 : if ( method < reader.getMethodCount()
446 0 : && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_SET
447 0 : && reader.getMethodName(method) == reader.getFieldName(field) )
448 : {
449 0 : if ( reader.getMethodExceptionCount(method) > 0 ) {
450 0 : OUString s( "com/sun/star/beans/PropertyVetoException");
451 0 : for ( sal_uInt16 i = 0; i < reader.getMethodExceptionCount(method);
452 : ++i )
453 : {
454 0 : if ( s.equals(reader.getMethodExceptionTypeName(method, i)) )
455 0 : flags |= RT_ACCESS_CONSTRAINED;
456 0 : if ( getterSupportsUnknown &&
457 0 : su.equals(reader.getMethodExceptionTypeName(method, i)) )
458 0 : flags |= RT_ACCESS_OPTIONAL;
459 0 : }
460 : }
461 : }
462 0 : return flags;
463 : }
464 :
465 : // This function checks if the specified types for parameters and return
466 : // types are allowed add-in types, for more info see the com.sun.star.sheet.AddIn
467 : // service description
468 0 : bool checkAddinType(TypeManager const & manager,
469 : OString const & type, bool & bLastAny,
470 : bool & bHasXPropertySet, bool bIsReturn)
471 : {
472 : RTTypeClass typeClass;
473 0 : OString name;
474 : sal_Int32 rank;
475 0 : std::vector< OString > arguments;
476 : codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve(
477 0 : manager, type, true, true, true, &typeClass, &name, &rank, &arguments);
478 :
479 0 : if ( sort == codemaker::UnoType::SORT_LONG ||
480 : sort == codemaker::UnoType::SORT_DOUBLE ||
481 : sort == codemaker::UnoType::SORT_STRING )
482 : {
483 0 : if ( rank == 0 || rank ==2 )
484 0 : return true;
485 : }
486 0 : if ( sort == codemaker::UnoType::SORT_ANY )
487 : {
488 0 : if ( rank <= 2 ) {
489 0 : if ( rank ==1 ) {
490 0 : if ( bIsReturn )
491 0 : return false;
492 0 : bLastAny = true;
493 : }
494 :
495 0 : return true;
496 : }
497 : }
498 0 : if ( sort == codemaker::UnoType::SORT_COMPLEX &&
499 : typeClass == RT_TYPE_INTERFACE )
500 : {
501 0 : if ( bIsReturn && type.equals("com/sun/star/sheet/XVolatileResult") )
502 0 : return true;
503 0 : if ( !bIsReturn && type.equals("com/sun/star/table/XCellRange") )
504 0 : return true;
505 0 : if ( !bIsReturn && type.equals("com/sun/star/beans/XPropertySet") )
506 : {
507 0 : if ( bHasXPropertySet ) {
508 0 : return false;
509 : } else {
510 0 : bHasXPropertySet = true;
511 0 : return true;
512 : }
513 : }
514 : }
515 0 : return false;
516 : }
517 :
518 0 : void checkAddInTypes(TypeManager const & manager,
519 : typereg::Reader const & reader)
520 : {
521 0 : OString sType(codemaker::convertString(reader.getTypeName()).replace('/', '.'));
522 0 : bool bLastAny = false;
523 0 : bool bHasXPropertySet = false;
524 0 : for ( sal_uInt16 m = 0; m < reader.getMethodCount(); ++m ) {
525 0 : OString sMethod(codemaker::convertString(reader.getMethodName(m)));
526 :
527 : OString sReturnType(codemaker::convertString(
528 0 : reader.getMethodReturnTypeName(m)));
529 0 : if ( !checkAddinType(
530 0 : manager, sReturnType, bLastAny, bHasXPropertySet, true) )
531 : {
532 0 : OStringBuffer msg("the return type of the calc add-in function '");
533 0 : msg.append(sType);
534 0 : msg.append(":");
535 0 : msg.append(sMethod);
536 0 : msg.append("' is invalid. Please check your IDL defintion.");
537 0 : throw CannotDumpException(msg.makeStringAndClear());
538 : }
539 :
540 0 : bHasXPropertySet = false;
541 0 : for ( sal_uInt16 p = 0; p < reader.getMethodParameterCount(m); ++p ) {
542 0 : bLastAny = false;
543 : OString sParamType(codemaker::convertString(
544 0 : reader.getMethodParameterTypeName(m, p)));
545 0 : if ( !checkAddinType(manager, sParamType,
546 0 : bLastAny, bHasXPropertySet, false) ||
547 : bLastAny )
548 : {
549 0 : OStringBuffer msg("the type of the ");
550 0 : msg.append((sal_Int32)p+1);
551 0 : msg.append(". parameter of the calc add-in function '");
552 0 : msg.append(sType);
553 0 : msg.append(":");
554 0 : msg.append(sMethod);
555 0 : msg.append("' is invalid.");
556 0 : if ( bLastAny )
557 : msg.append(" The type 'sequence<any>' is allowed as last "
558 0 : "parameter only.");
559 0 : if ( bHasXPropertySet )
560 0 : msg.append(" The type 'XPropertySet' is allowed only once.");
561 :
562 0 : msg.append(" Please check your IDL definition.");
563 0 : throw CannotDumpException(msg.makeStringAndClear());
564 : }
565 0 : }
566 0 : }
567 0 : }
568 :
569 0 : void generateFunctionParamterMap(std::ostream& o,
570 : ProgramOptions const & options,
571 : TypeManager const & manager,
572 : typereg::Reader const & reader,
573 : ::codemaker::GeneratedTypeSet & generated,
574 : bool bFirst)
575 : {
576 0 : OString sType(codemaker::convertString(reader.getTypeName()));
577 0 : if ( sType.equals("com/sun/star/uno/XInterface") ||
578 0 : sType.equals("com/sun/star/lang/XLocalizable") ||
579 0 : sType.equals("com/sun/star/lang/XServiceInfo") ||
580 : // the next three checks becomes obsolete when configuration is used
581 0 : sType.equals("com/sun/star/sheet/XAddIn") ||
582 0 : sType.equals("com/sun/star/sheet/XCompatibilityNames") ||
583 0 : sType.equals("com/sun/star/lang/XServiceName") )
584 : {
585 : return;
586 : }
587 :
588 : // check if the specified add-in functions supports valid types
589 0 : checkAddInTypes(manager, reader);
590 :
591 0 : for ( sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i ) {
592 : typereg::Reader super(
593 : manager.getTypeReader(
594 : codemaker::convertString(
595 0 : reader.getSuperTypeName(i))));
596 0 : if ( !super.isValid() ) {
597 : throw CannotDumpException(
598 : "Bad type library entity "
599 : + codemaker::convertString(
600 0 : reader.getSuperTypeName(i)));
601 : }
602 0 : generateFunctionParamterMap(o, options, manager, super, generated, bFirst);
603 0 : }
604 :
605 0 : OString type(codemaker::convertString(reader.getTypeName()));
606 0 : if ( generated.contains(type) )
607 : return;
608 : else
609 0 : generated.add(type);
610 :
611 0 : for ( sal_uInt16 m = 0; m < reader.getMethodCount(); ++m ) {
612 0 : OString sMethod(codemaker::convertString(reader.getMethodName(m)));
613 :
614 0 : if ( bFirst ) {
615 0 : if (options.language == 2) {
616 0 : o << " ParamMap fpm;\n";
617 : }
618 : else {
619 0 : if ( options.java5 )
620 : o << " java.util.Hashtable< Integer, String > fpm = "
621 0 : "new java.util.Hashtable< Integer, String >();\n";
622 : else
623 : o << " java.util.Hashtable fpm = "
624 0 : "new java.util.Hashtable();\n";
625 : }
626 0 : bFirst = false;
627 : } else
628 0 : if ( options.language == 2 ) {
629 0 : o << " fpm = ParamMap();\n";
630 : }
631 : else {
632 0 : if ( options.java5 )
633 : o << " fpm = new java.util.Hashtable< "
634 0 : "Integer, String >();\n";
635 : else
636 0 : o << " fpm = new java.util.Hashtable();\n";
637 : }
638 :
639 0 : for ( sal_uInt16 p = 0; p < reader.getMethodParameterCount(m); ++p ) {
640 0 : if ( options.language == 2 ) {
641 0 : o << " fpm[" << p
642 0 : << "] = ::rtl::OUString(\""
643 0 : << codemaker::convertString(reader.getMethodParameterName(m, p))
644 0 : << "\");\n";
645 : }
646 : else {
647 0 : if ( options.java5 )
648 0 : o << " fpm.put(" << p << ", \""
649 : << codemaker::convertString(
650 0 : reader.getMethodParameterName(m, p))
651 0 : << "\");\n";
652 : else
653 0 : o << " fpm.put(new Integer(" << p << "), \""
654 : << codemaker::convertString(
655 0 : reader.getMethodParameterName(m, p))
656 0 : << "\");\n";
657 : }
658 : }
659 :
660 0 : if ( options.language == 2 ) {
661 0 : o << " m_functionMap[::rtl::OUString(\""
662 0 : << sMethod << "\")] = fpm;\n\n";
663 : }
664 : else {
665 0 : o << " m_functionMap.put(\"" << sMethod << "\", fpm);\n\n";
666 : }
667 0 : }
668 : }
669 :
670 0 : void generateFunctionParameterMap(std::ostream& o,
671 : ProgramOptions const & options,
672 : TypeManager const & manager,
673 : const boost::unordered_set< OString, OStringHash >& interfaces)
674 : {
675 0 : ::codemaker::GeneratedTypeSet generated;
676 0 : bool bFirst = true;
677 0 : boost::unordered_set< OString, OStringHash >::const_iterator iter = interfaces.begin();
678 0 : while ( iter != interfaces.end() ) {
679 0 : typereg::Reader reader(manager.getTypeReader((*iter).replace('.','/')));
680 0 : if (!reader.isValid()) {
681 : throw CannotDumpException(
682 : "Bad type library entity "
683 : + codemaker::convertString(
684 0 : reader.getTypeName()));
685 : }
686 :
687 0 : generateFunctionParamterMap(o, options, manager, reader, generated, bFirst);
688 0 : ++iter;
689 0 : }
690 0 : }
691 :
692 0 : }
693 :
694 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|