1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: javatype.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_codemaker.hxx"
34 #include "javatype.hxx"
36 #include "classfile.hxx"
37 #include "javaoptions.hxx"
39 #include "codemaker/exceptiontree.hxx"
40 #include "codemaker/generatedtypeset.hxx"
41 #include "codemaker/global.hxx"
42 #include "codemaker/options.hxx"
43 #include "codemaker/typemanager.hxx"
44 #include "codemaker/unotype.hxx"
45 #include "codemaker/commonjava.hxx"
47 #include "osl/diagnose.h"
48 #include "registry/reader.hxx"
49 #include "registry/refltype.hxx"
50 #include "registry/types.h"
51 #include "rtl/strbuf.hxx"
52 #include "rtl/string.h"
53 #include "rtl/string.hxx"
54 #include "rtl/textcvt.h"
55 #include "rtl/textenc.h"
56 #include "rtl/ustring.h"
57 #include "rtl/ustring.hxx"
58 #include "sal/types.h"
68 using codemaker::javamaker::ClassFile
;
72 void checkNoTypeArguments(std::vector
< rtl::OString
> const & arguments
) {
73 if (!arguments
.empty()) {
74 throw CannotDumpException(
75 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
80 // helper function for createUnoName
82 TypeManager
const & manager
, rtl::OString
const & nucleus
, sal_Int32 rank
,
83 std::vector
< rtl::OString
> const & arguments
, rtl::OStringBuffer
* buffer
)
85 OSL_ASSERT(rank
>= 0 && buffer
!= 0);
86 for (sal_Int32 i
= 0; i
< rank
; ++i
) {
87 buffer
->append(RTL_CONSTASCII_STRINGPARAM("[]"));
89 buffer
->append(nucleus
.replace('/', '.'));
90 if (!arguments
.empty()) {
92 for (std::vector
< rtl::OString
>::const_iterator
i(arguments
.begin());
93 i
!= arguments
.end(); ++i
)
95 if (i
!= arguments
.begin()) {
98 RTTypeClass argTypeClass
;
99 rtl::OString argNucleus
;
101 std::vector
< rtl::OString
> argArgs
;
102 codemaker::decomposeAndResolve(
103 manager
, *i
, true, false, false, &argTypeClass
, &argNucleus
,
105 appendUnoName(manager
, argNucleus
, argRank
, argArgs
, buffer
);
111 // Translate the name of a UNO type registry entity (enum type, plain struct
112 // type, polymorphic struct type template, or interface type, decomposed into
113 // nucleus, rank, and arguments) into a core UNO type name:
114 rtl::OString
createUnoName(
115 TypeManager
const & manager
, rtl::OString
const & nucleus
, sal_Int32 rank
,
116 std::vector
< rtl::OString
> const & arguments
)
118 rtl::OStringBuffer buf
;
119 appendUnoName(manager
, nucleus
, rank
, arguments
, &buf
);
120 return buf
.makeStringAndClear();
124 Set of UTF-8--encoded names of UNO type registry entities a given UNO type
125 registry entity depends on.
127 UNO type registry entities are enum types, plain struct types, polymorphic
128 struct type templates, exception types, interface types, typedefs, modules,
129 constant groupds, single-interface--based services, accumulation-based
130 services, interface-based singletons, and service-based singletons.
132 typedef std::set
< rtl::OString
> Dependencies
;
137 SPECIAL_TYPE_UNSIGNED
,
138 SPECIAL_TYPE_INTERFACE
141 bool isSpecialType(SpecialType special
) {
142 return special
>= SPECIAL_TYPE_UNSIGNED
;
145 rtl::OString
translateUnoTypeToJavaFullyQualifiedName(
146 rtl::OString
const & type
, rtl::OString
const & prefix
)
148 sal_Int32 i
= type
.lastIndexOf('/') + 1;
149 return type
.copy(0, i
) +
150 codemaker::java::translateUnoToJavaIdentifier(type
.copy(i
), prefix
);
153 struct PolymorphicUnoType
{
154 PolymorphicUnoType(): kind(KIND_NONE
) {}
156 enum Kind
{ KIND_NONE
, KIND_STRUCT
, KIND_SEQUENCE
};
161 SpecialType
translateUnoTypeToDescriptor(
162 TypeManager
const & manager
, rtl::OString
const & type
, bool array
,
163 bool classType
, Dependencies
* dependencies
,
164 rtl::OStringBuffer
* descriptor
, rtl::OStringBuffer
* signature
,
165 bool * needsSignature
, PolymorphicUnoType
* polymorphicUnoType
);
167 SpecialType
translateUnoTypeToDescriptor(
168 TypeManager
const & manager
, codemaker::UnoType::Sort sort
,
169 RTTypeClass typeClass
, rtl::OString
const & nucleus
, sal_Int32 rank
,
170 std::vector
< rtl::OString
> const & arguments
, bool array
, bool classType
,
171 Dependencies
* dependencies
, rtl::OStringBuffer
* descriptor
,
172 rtl::OStringBuffer
* signature
, bool * needsSignature
,
173 PolymorphicUnoType
* polymorphicUnoType
)
175 OSL_ASSERT(rank
>= 0 && (signature
== 0) == (needsSignature
== 0));
176 if (rank
> 0xFF - (array
? 1 : 0)) {
177 throw CannotDumpException(
179 RTL_CONSTASCII_STRINGPARAM(
180 "Too many array dimensions for Java class file format")));
185 for (sal_Int32 i
= 0; i
< rank
; ++i
) {
186 if (descriptor
!= 0) {
187 descriptor
->append('[');
189 if (signature
!= 0) {
190 signature
->append('[');
193 if (sort
== codemaker::UnoType::SORT_COMPLEX
) {
194 //TODO: check that nucleus is a valid (Java-modified UTF-8) identifier
195 rtl::OString superClass
;
196 if (typeClass
== RT_TYPE_INTERFACE
199 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XInterface"))))
201 if (descriptor
!= 0) {
204 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;")));
206 if (signature
!= 0) {
209 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;")));
211 if (polymorphicUnoType
!= 0) {
212 polymorphicUnoType
->kind
= PolymorphicUnoType::KIND_NONE
;
214 return SPECIAL_TYPE_INTERFACE
;
216 if (dependencies
!= 0) {
217 dependencies
->insert(nucleus
);
219 if (descriptor
!= 0) {
220 descriptor
->append('L');
221 descriptor
->append(nucleus
);
222 descriptor
->append(';');
224 if (signature
!= 0) {
225 signature
->append('L');
226 signature
->append(nucleus
);
227 if (!arguments
.empty()) {
228 signature
->append('<');
229 for (std::vector
< rtl::OString
>::const_iterator
i(
231 i
!= arguments
.end(); ++i
)
233 translateUnoTypeToDescriptor(
234 manager
, *i
, false, true, dependencies
, 0,
235 signature
, needsSignature
, 0);
237 signature
->append('>');
238 *needsSignature
= true;
240 signature
->append(';');
242 if (polymorphicUnoType
!= 0) {
243 if (arguments
.empty()) {
244 polymorphicUnoType
->kind
= PolymorphicUnoType::KIND_NONE
;
246 polymorphicUnoType
->kind
= rank
== 0
247 ? PolymorphicUnoType::KIND_STRUCT
248 : PolymorphicUnoType::KIND_SEQUENCE
;
249 polymorphicUnoType
->name
= createUnoName(
250 manager
, nucleus
, rank
, arguments
);
253 return SPECIAL_TYPE_NONE
;
256 static rtl::OString
const
257 simpleTypeDescriptors
[codemaker::UnoType::SORT_ANY
+ 1][2] = {
258 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("V")),
259 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Void;"))
261 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("Z")),
263 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Boolean;"))
265 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("B")),
266 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Byte;"))
268 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("S")),
269 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Short;"))
271 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("S")),
272 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Short;"))
274 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("I")),
276 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Integer;"))
278 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("I")),
280 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Integer;"))
282 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("J")),
283 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Long;"))
285 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("J")),
286 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Long;"))
288 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("F")),
289 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Float;"))
291 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("D")),
292 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Double;"))
294 { rtl::OString(RTL_CONSTASCII_STRINGPARAM("C")),
296 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Character;"))
299 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/String;")),
300 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/String;"))
303 RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Type;")),
305 RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Type;"))
308 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;")),
310 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;"))
312 rtl::OString
const & s
313 = simpleTypeDescriptors
[sort
][rank
== 0 && classType
];
314 if (descriptor
!= 0) {
315 descriptor
->append(s
);
317 if (signature
!= 0) {
318 signature
->append(s
);
320 if (polymorphicUnoType
!= 0) {
321 polymorphicUnoType
->kind
= PolymorphicUnoType::KIND_NONE
;
323 static SpecialType
const
324 simpleTypeSpecials
[codemaker::UnoType::SORT_ANY
+ 1] = {
325 SPECIAL_TYPE_NONE
, SPECIAL_TYPE_NONE
, SPECIAL_TYPE_NONE
,
326 SPECIAL_TYPE_NONE
, SPECIAL_TYPE_UNSIGNED
, SPECIAL_TYPE_NONE
,
327 SPECIAL_TYPE_UNSIGNED
, SPECIAL_TYPE_NONE
, SPECIAL_TYPE_UNSIGNED
,
328 SPECIAL_TYPE_NONE
, SPECIAL_TYPE_NONE
, SPECIAL_TYPE_NONE
,
329 SPECIAL_TYPE_NONE
, SPECIAL_TYPE_NONE
, SPECIAL_TYPE_ANY
};
330 return simpleTypeSpecials
[sort
];
334 SpecialType
translateUnoTypeToDescriptor(
335 TypeManager
const & manager
, rtl::OString
const & type
, bool array
,
336 bool classType
, Dependencies
* dependencies
,
337 rtl::OStringBuffer
* descriptor
, rtl::OStringBuffer
* signature
,
338 bool * needsSignature
, PolymorphicUnoType
* polymorphicUnoType
)
340 RTTypeClass typeClass
;
341 rtl::OString nucleus
;
343 std::vector
< rtl::OString
> args
;
344 codemaker::UnoType::Sort sort
= codemaker::decomposeAndResolve(
345 manager
, type
, true, true, false, &typeClass
, &nucleus
, &rank
, &args
);
346 OSL_ASSERT(rank
< SAL_MAX_INT32
);
347 return translateUnoTypeToDescriptor(
348 manager
, sort
, typeClass
, nucleus
, rank
, args
, array
, classType
,
349 dependencies
, descriptor
, signature
, needsSignature
,
353 SpecialType
getFieldDescriptor(
354 TypeManager
const & manager
, Dependencies
* dependencies
,
355 rtl::OString
const & type
, rtl::OString
* descriptor
,
356 rtl::OString
* signature
, PolymorphicUnoType
* polymorphicUnoType
)
358 OSL_ASSERT(dependencies
!= 0 && descriptor
!= 0);
359 rtl::OStringBuffer desc
;
360 rtl::OStringBuffer sig
;
361 bool needsSig
= false;
362 SpecialType specialType
= translateUnoTypeToDescriptor(
363 manager
, type
, false, false, dependencies
, &desc
, &sig
, &needsSig
,
365 *descriptor
= desc
.makeStringAndClear();
366 if (signature
!= 0) {
368 *signature
= sig
.makeStringAndClear();
370 *signature
= rtl::OString();
376 class MethodDescriptor
{
379 TypeManager
const & manager
, Dependencies
* dependencies
,
380 rtl::OString
const & returnType
, SpecialType
* specialReturnType
,
381 PolymorphicUnoType
* polymorphicUnoType
);
383 SpecialType
addParameter(
384 rtl::OString
const & type
, bool array
, bool dependency
,
385 PolymorphicUnoType
* polymorphicUnoType
);
387 void addTypeParameter(rtl::OString
const & name
);
389 rtl::OString
getDescriptor() const;
391 rtl::OString
getSignature() const;
394 TypeManager
const & m_manager
;
395 Dependencies
* m_dependencies
;
396 rtl::OStringBuffer m_descriptorStart
;
397 rtl::OString m_descriptorEnd
;
398 rtl::OStringBuffer m_signatureStart
;
399 rtl::OString m_signatureEnd
;
400 bool m_needsSignature
;
403 MethodDescriptor::MethodDescriptor(
404 TypeManager
const & manager
, Dependencies
* dependencies
,
405 rtl::OString
const & returnType
, SpecialType
* specialReturnType
,
406 PolymorphicUnoType
* polymorphicUnoType
):
407 m_manager(manager
), m_dependencies(dependencies
), m_needsSignature(false)
409 OSL_ASSERT(dependencies
!= 0);
410 m_descriptorStart
.append('(');
411 m_signatureStart
.append('(');
412 rtl::OStringBuffer descEnd
;
414 rtl::OStringBuffer sigEnd
;
416 SpecialType special
= translateUnoTypeToDescriptor(
417 m_manager
, returnType
, false, false, m_dependencies
, &descEnd
, &sigEnd
,
418 &m_needsSignature
, polymorphicUnoType
);
419 m_descriptorEnd
= descEnd
.makeStringAndClear();
420 m_signatureEnd
= sigEnd
.makeStringAndClear();
421 if (specialReturnType
!= 0) {
422 *specialReturnType
= special
;
426 SpecialType
MethodDescriptor::addParameter(
427 rtl::OString
const & type
, bool array
, bool dependency
,
428 PolymorphicUnoType
* polymorphicUnoType
)
430 return translateUnoTypeToDescriptor(
431 m_manager
, type
, array
, false, dependency
? m_dependencies
: 0,
432 &m_descriptorStart
, &m_signatureStart
, &m_needsSignature
,
436 void MethodDescriptor::addTypeParameter(rtl::OString
const & name
) {
437 m_descriptorStart
.append(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;"));
438 m_signatureStart
.append('T');
439 m_signatureStart
.append(name
);
440 m_signatureStart
.append(';');
441 m_needsSignature
= true;
444 rtl::OString
MethodDescriptor::getDescriptor() const {
445 rtl::OStringBuffer
buf(m_descriptorStart
);
446 buf
.append(m_descriptorEnd
);
447 return buf
.makeStringAndClear();
450 rtl::OString
MethodDescriptor::getSignature() const {
451 if (m_needsSignature
) {
452 rtl::OStringBuffer
buf(m_signatureStart
);
453 buf
.append(m_signatureEnd
);
454 return buf
.makeStringAndClear();
456 return rtl::OString();
462 enum Kind
{ KIND_MEMBER
, KIND_ATTRIBUTE
, KIND_METHOD
, KIND_PARAMETER
};
464 // Same values as in com/sun/star/lib/uno/typeinfo/TypeInfo.java:
466 FLAG_READONLY
= 0x008, FLAG_BOUND
= 0x100, FLAG_ONEWAY
= 0x010
471 rtl::OString
const & name
, SpecialType specialType
, sal_Int32 index
,
472 PolymorphicUnoType
const & polymorphicUnoType
,
473 sal_Int32 typeParameterIndex
);
475 // KIND_ATTRIBUTE/METHOD:
477 Kind kind
, rtl::OString
const & name
, SpecialType specialType
,
478 Flags flags
, sal_Int32 index
,
479 PolymorphicUnoType
const & polymorphicUnoType
);
483 rtl::OString
const & parameterName
, SpecialType specialType
,
484 bool inParameter
, bool outParameter
, rtl::OString
const & methodName
,
485 sal_Int32 index
, PolymorphicUnoType
const & polymorphicUnoType
);
487 sal_uInt16
generateCode(ClassFile::Code
& code
, Dependencies
* dependencies
)
490 void generatePolymorphicUnoTypeCode(
491 ClassFile::Code
& code
, Dependencies
* dependencies
) const;
498 rtl::OString m_methodName
;
499 PolymorphicUnoType m_polymorphicUnoType
;
500 sal_Int32 m_typeParameterIndex
;
503 sal_Int32
translateSpecialTypeFlags(
504 SpecialType specialType
, bool inParameter
, bool outParameter
)
506 static sal_Int32
const specialTypeFlags
[SPECIAL_TYPE_INTERFACE
+ 1] = {
507 0, 0x0040 /* ANY */, 0x0004 /* UNSIGNED */, 0x0080 /* INTERFACE */ };
508 sal_Int32 flags
= specialTypeFlags
[specialType
];
510 flags
|= 0x0001; /* IN */
513 flags
|= 0x0002; /* OUT */
519 rtl::OString
const & name
, SpecialType specialType
, sal_Int32 index
,
520 PolymorphicUnoType
const & polymorphicUnoType
,
521 sal_Int32 typeParameterIndex
):
522 m_kind(KIND_MEMBER
), m_name(name
),
523 m_flags(translateSpecialTypeFlags(specialType
, false, false)),
524 m_index(index
), m_polymorphicUnoType(polymorphicUnoType
),
525 m_typeParameterIndex(typeParameterIndex
)
528 polymorphicUnoType
.kind
== PolymorphicUnoType::KIND_NONE
529 ? typeParameterIndex
>= -1 : typeParameterIndex
== -1);
533 Kind kind
, rtl::OString
const & name
, SpecialType specialType
,
534 Flags flags
, sal_Int32 index
,
535 PolymorphicUnoType
const & polymorphicUnoType
):
536 m_kind(kind
), m_name(name
),
537 m_flags(flags
| translateSpecialTypeFlags(specialType
, false, false)),
538 m_index(index
), m_polymorphicUnoType(polymorphicUnoType
)
540 OSL_ASSERT(kind
== KIND_ATTRIBUTE
|| kind
== KIND_METHOD
);
544 rtl::OString
const & parameterName
, SpecialType specialType
,
545 bool inParameter
, bool outParameter
, rtl::OString
const & methodName
,
546 sal_Int32 index
, PolymorphicUnoType
const & polymorphicUnoType
):
547 m_kind(KIND_PARAMETER
), m_name(parameterName
),
548 m_flags(translateSpecialTypeFlags(specialType
, inParameter
, outParameter
)),
549 m_index(index
), m_methodName(methodName
),
550 m_polymorphicUnoType(polymorphicUnoType
)
553 sal_uInt16
TypeInfo::generateCode(
554 ClassFile::Code
& code
, Dependencies
* dependencies
) const
556 OSL_ASSERT(dependencies
!= 0);
561 RTL_CONSTASCII_STRINGPARAM(
562 "com/sun/star/lib/uno/typeinfo/MemberTypeInfo")));
564 code
.loadStringConstant(m_name
);
565 code
.loadIntegerConstant(m_index
);
566 code
.loadIntegerConstant(m_flags
);
567 if (m_polymorphicUnoType
.kind
!= PolymorphicUnoType::KIND_NONE
) {
568 generatePolymorphicUnoTypeCode(code
, dependencies
);
569 code
.loadIntegerConstant(m_typeParameterIndex
);
570 code
.instrInvokespecial(
572 RTL_CONSTASCII_STRINGPARAM(
573 "com/sun/star/lib/uno/typeinfo/MemberTypeInfo")),
574 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
576 RTL_CONSTASCII_STRINGPARAM(
577 "(Ljava/lang/String;IILcom/sun/star/uno/Type;I)V")));
579 } else if (m_typeParameterIndex
>= 0) {
580 code
.instrAconstNull();
581 code
.loadIntegerConstant(m_typeParameterIndex
);
582 code
.instrInvokespecial(
584 RTL_CONSTASCII_STRINGPARAM(
585 "com/sun/star/lib/uno/typeinfo/MemberTypeInfo")),
586 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
588 RTL_CONSTASCII_STRINGPARAM(
589 "(Ljava/lang/String;IILcom/sun/star/uno/Type;I)V")));
592 code
.instrInvokespecial(
594 RTL_CONSTASCII_STRINGPARAM(
595 "com/sun/star/lib/uno/typeinfo/MemberTypeInfo")),
596 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
598 RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;II)V")));
605 RTL_CONSTASCII_STRINGPARAM(
606 "com/sun/star/lib/uno/typeinfo/AttributeTypeInfo")));
608 code
.loadStringConstant(m_name
);
609 code
.loadIntegerConstant(m_index
);
610 code
.loadIntegerConstant(m_flags
);
611 if (m_polymorphicUnoType
.kind
!= PolymorphicUnoType::KIND_NONE
) {
612 generatePolymorphicUnoTypeCode(code
, dependencies
);
613 code
.instrInvokespecial(
615 RTL_CONSTASCII_STRINGPARAM(
616 "com/sun/star/lib/uno/typeinfo/AttributeTypeInfo")),
617 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
619 RTL_CONSTASCII_STRINGPARAM(
620 "(Ljava/lang/String;IILcom/sun/star/uno/Type;)V")));
623 code
.instrInvokespecial(
625 RTL_CONSTASCII_STRINGPARAM(
626 "com/sun/star/lib/uno/typeinfo/AttributeTypeInfo")),
627 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
629 RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;II)V")));
636 RTL_CONSTASCII_STRINGPARAM(
637 "com/sun/star/lib/uno/typeinfo/MethodTypeInfo")));
639 code
.loadStringConstant(m_name
);
640 code
.loadIntegerConstant(m_index
);
641 code
.loadIntegerConstant(m_flags
);
642 if (m_polymorphicUnoType
.kind
!= PolymorphicUnoType::KIND_NONE
) {
643 generatePolymorphicUnoTypeCode(code
, dependencies
);
644 code
.instrInvokespecial(
646 RTL_CONSTASCII_STRINGPARAM(
647 "com/sun/star/lib/uno/typeinfo/MethodTypeInfo")),
648 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
650 RTL_CONSTASCII_STRINGPARAM(
651 "(Ljava/lang/String;IILcom/sun/star/uno/Type;)V")));
654 code
.instrInvokespecial(
656 RTL_CONSTASCII_STRINGPARAM(
657 "com/sun/star/lib/uno/typeinfo/MethodTypeInfo")),
658 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
660 RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;II)V")));
667 RTL_CONSTASCII_STRINGPARAM(
668 "com/sun/star/lib/uno/typeinfo/ParameterTypeInfo")));
670 code
.loadStringConstant(m_name
);
671 code
.loadStringConstant(m_methodName
);
672 code
.loadIntegerConstant(m_index
);
673 code
.loadIntegerConstant(m_flags
);
674 if (m_polymorphicUnoType
.kind
!= PolymorphicUnoType::KIND_NONE
) {
675 generatePolymorphicUnoTypeCode(code
, dependencies
);
676 code
.instrInvokespecial(
678 RTL_CONSTASCII_STRINGPARAM(
679 "com/sun/star/lib/uno/typeinfo/ParameterTypeInfo")),
680 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
682 RTL_CONSTASCII_STRINGPARAM(
683 "(Ljava/lang/String;Ljava/lang/String;II"
684 "Lcom/sun/star/uno/Type;)V")));
687 code
.instrInvokespecial(
689 RTL_CONSTASCII_STRINGPARAM(
690 "com/sun/star/lib/uno/typeinfo/ParameterTypeInfo")),
691 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
693 RTL_CONSTASCII_STRINGPARAM(
694 "(Ljava/lang/String;Ljava/lang/String;II)V")));
704 void TypeInfo::generatePolymorphicUnoTypeCode(
705 ClassFile::Code
& code
, Dependencies
* dependencies
) const
709 && m_polymorphicUnoType
.kind
!= PolymorphicUnoType::KIND_NONE
);
711 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")));
713 code
.loadStringConstant(m_polymorphicUnoType
.name
);
714 if (m_polymorphicUnoType
.kind
== PolymorphicUnoType::KIND_STRUCT
) {
717 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
718 rtl::OString(RTL_CONSTASCII_STRINGPARAM("STRUCT")),
720 RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/TypeClass;")));
724 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
725 rtl::OString(RTL_CONSTASCII_STRINGPARAM("SEQUENCE")),
727 RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/TypeClass;")));
729 dependencies
->insert(
730 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")));
731 code
.instrInvokespecial(
732 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
733 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
735 RTL_CONSTASCII_STRINGPARAM(
736 "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V")));
740 JavaOptions
/*TODO const*/ & options
, rtl::OString
const & type
,
741 ClassFile
const & classFile
)
744 if (options
.isValid(rtl::OString(RTL_CONSTASCII_STRINGPARAM("-O")))) {
745 path
= options
.getOption(
746 rtl::OString(RTL_CONSTASCII_STRINGPARAM("-O")));
748 rtl::OString
filename(
749 createFileNameFromType(
750 path
, type
, rtl::OString(RTL_CONSTASCII_STRINGPARAM(".class"))));
752 if (fileExists(filename
)) {
753 if (options
.isValid(rtl::OString(RTL_CONSTASCII_STRINGPARAM("-G")))) {
756 check
= options
.isValid(
757 rtl::OString(RTL_CONSTASCII_STRINGPARAM("-Gc")));
760 tempfile
.createTempFile(getTempDir(filename
));
761 if (!tempfile
.isValid()) {
762 throw CannotDumpException(
764 RTL_CONSTASCII_STRINGPARAM("Cannot create temporary file for "))
767 rtl::OString
tempname(tempfile
.getName());
769 classFile
.write(tempfile
);
771 // Remove existing file for consistency:
772 if (fileExists(filename
)) {
773 removeTypeFile(filename
);
776 removeTypeFile(tempname
);
780 if (!makeValidTypeFile(filename
, tempname
, check
)) {
781 rtl::OStringBuffer msg
;
782 msg
.append(RTL_CONSTASCII_STRINGPARAM("Cannot create "));
783 msg
.append(filename
);
784 msg
.append(RTL_CONSTASCII_STRINGPARAM(" from temporary file "));
785 msg
.append(tempname
);
786 throw CannotDumpException(msg
.makeStringAndClear());
791 rtl::OString
const & className
, std::vector
< TypeInfo
> const & typeInfo
,
792 Dependencies
* dependencies
, ClassFile
* classFile
)
794 OSL_ASSERT(dependencies
!= 0 && classFile
!= 0);
795 std::vector
< TypeInfo
>::size_type typeInfos
= typeInfo
.size();
796 if (typeInfos
> SAL_MAX_INT32
) {
797 throw CannotDumpException(
799 RTL_CONSTASCII_STRINGPARAM(
800 "UNOTYPEINFO array too big for Java class file format")));
802 if (typeInfos
!= 0) {
804 static_cast< ClassFile::AccessFlags
>(
805 ClassFile::ACC_PUBLIC
| ClassFile::ACC_STATIC
806 | ClassFile::ACC_FINAL
),
807 rtl::OString(RTL_CONSTASCII_STRINGPARAM("UNOTYPEINFO")),
809 RTL_CONSTASCII_STRINGPARAM(
810 "[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;")),
812 std::auto_ptr
< ClassFile::Code
> code(classFile
->newCode());
813 code
->loadIntegerConstant(static_cast< sal_Int32
>(typeInfos
));
814 code
->instrAnewarray(
816 RTL_CONSTASCII_STRINGPARAM(
817 "com/sun/star/lib/uno/typeinfo/TypeInfo")));
819 sal_uInt16 stack
= 0;
820 for (std::vector
< TypeInfo
>::const_iterator
i(typeInfo
.begin());
821 i
!= typeInfo
.end(); ++i
)
824 code
->loadIntegerConstant(index
++);
825 stack
= std::max(stack
, i
->generateCode(*code
, dependencies
));
826 code
->instrAastore();
828 code
->instrPutstatic(
829 className
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("UNOTYPEINFO")),
831 RTL_CONSTASCII_STRINGPARAM(
832 "[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;")));
834 if (stack
> SAL_MAX_UINT16
- 4) {
835 throw CannotDumpException(
837 RTL_CONSTASCII_STRINGPARAM(
838 "Stack too big for Java class file format")));
840 code
->setMaxStackAndLocals(static_cast< sal_uInt16
>(stack
+ 4), 0);
841 classFile
->addMethod(
842 static_cast< ClassFile::AccessFlags
>(
843 ClassFile::ACC_PRIVATE
| ClassFile::ACC_STATIC
),
844 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<clinit>")),
845 rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")), code
.get(),
846 std::vector
< rtl::OString
>(), rtl::OString());
850 typedef void (* handleUnoTypeRegistryEntityFunction
)(
851 TypeManager
const & manager
, JavaOptions
/*TODO const*/ & options
,
852 typereg::Reader
const & reader
, Dependencies
* dependencies
);
855 TypeManager
const &, JavaOptions
/*TODO const*/ & options
,
856 typereg::Reader
const & reader
, Dependencies
*)
858 sal_uInt16 fields
= reader
.getFieldCount();
859 if (fields
== 0 || reader
.getSuperTypeCount() != 0
860 || reader
.getMethodCount() != 0 || reader
.getReferenceCount() != 0)
862 throw CannotDumpException(
863 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
866 rtl::OString
className(codemaker::convertString(reader
.getTypeName()));
867 std::auto_ptr
< ClassFile
> cf(
869 static_cast< ClassFile::AccessFlags
>(
870 ClassFile::ACC_PUBLIC
| ClassFile::ACC_FINAL
871 | ClassFile::ACC_SUPER
),
873 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Enum")),
875 rtl::OStringBuffer buf
;
877 buf
.append(className
);
879 rtl::OString
classDescriptor(buf
.makeStringAndClear());
880 {for (sal_uInt16 i
= 0; i
< fields
; ++i
) {
881 RTConstValue
fieldValue(reader
.getFieldValue(i
));
882 if (fieldValue
.m_type
!= RT_TYPE_INT32
883 || reader
.getFieldFlags(i
) != RT_ACCESS_CONST
884 || reader
.getFieldTypeName(i
).getLength() != 0)
886 throw CannotDumpException(
888 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
890 rtl::OString
fieldName(
891 codemaker::convertString(reader
.getFieldName(i
)));
893 static_cast< ClassFile::AccessFlags
>(
894 ClassFile::ACC_PUBLIC
| ClassFile::ACC_STATIC
895 | ClassFile::ACC_FINAL
),
896 fieldName
, classDescriptor
, 0, rtl::OString());
898 static_cast< ClassFile::AccessFlags
>(
899 ClassFile::ACC_PUBLIC
| ClassFile::ACC_STATIC
900 | ClassFile::ACC_FINAL
),
901 fieldName
+ rtl::OString(RTL_CONSTASCII_STRINGPARAM("_value")),
902 rtl::OString(RTL_CONSTASCII_STRINGPARAM("I")),
903 cf
->addIntegerInfo(fieldValue
.m_value
.aLong
), rtl::OString());
905 std::auto_ptr
< ClassFile::Code
> code(cf
->newCode());
906 code
->loadLocalReference(0);
907 code
->loadLocalInteger(1);
908 code
->instrInvokespecial(
909 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Enum")),
910 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
911 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")));
913 code
->setMaxStackAndLocals(2, 2);
915 ClassFile::ACC_PRIVATE
,
916 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
917 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")), code
.get(),
918 std::vector
< rtl::OString
>(), rtl::OString());
919 code
.reset(cf
->newCode());
920 code
->instrGetstatic(
922 codemaker::convertString(reader
.getFieldName(0)), classDescriptor
);
923 code
->instrAreturn();
924 code
->setMaxStackAndLocals(1, 0);
926 static_cast< ClassFile::AccessFlags
>(
927 ClassFile::ACC_PUBLIC
| ClassFile::ACC_STATIC
),
928 rtl::OString(RTL_CONSTASCII_STRINGPARAM("getDefault")),
929 rtl::OString(RTL_CONSTASCII_STRINGPARAM("()")) + classDescriptor
,
930 code
.get(), std::vector
< rtl::OString
>(), rtl::OString());
931 code
.reset(cf
->newCode());
932 code
->loadLocalInteger(0);
933 std::map
< sal_Int32
, rtl::OString
> map
;
934 sal_Int32 min
= SAL_MAX_INT32
;
935 sal_Int32 max
= SAL_MIN_INT32
;
936 {for (sal_uInt16 i
= 0; i
< fields
; ++i
) {
937 sal_Int32 value
= reader
.getFieldValue(i
).m_value
.aLong
;
938 min
= std::min(min
, value
);
939 max
= std::max(max
, value
);
941 std::map
< sal_Int32
, rtl::OString
>::value_type(
942 value
, codemaker::convertString(reader
.getFieldName(i
))));
944 sal_uInt64 size
= static_cast< sal_uInt64
>(map
.size());
945 if ((static_cast< sal_uInt64
>(max
) - static_cast< sal_uInt64
>(min
)
947 || size
> SAL_MAX_INT32
)
949 std::auto_ptr
< ClassFile::Code
> defCode(cf
->newCode());
950 defCode
->instrAconstNull();
951 defCode
->instrAreturn();
952 std::list
< ClassFile::Code
* > blocks
;
953 //FIXME: pointers contained in blocks may leak
954 sal_Int32 last
= SAL_MAX_INT32
;
955 for (std::map
< sal_Int32
, rtl::OString
>::iterator
i(map
.begin());
958 sal_Int32 value
= i
->first
;
959 if (last
!= SAL_MAX_INT32
) {
960 for (sal_Int32 j
= last
+ 1; j
< value
; ++j
) {
965 std::auto_ptr
< ClassFile::Code
> blockCode(cf
->newCode());
966 blockCode
->instrGetstatic(className
, i
->second
, classDescriptor
);
967 blockCode
->instrAreturn();
968 blocks
.push_back(blockCode
.get());
971 code
->instrTableswitch(defCode
.get(), min
, blocks
);
972 {for (std::list
< ClassFile::Code
* >::iterator
i(blocks
.begin());
973 i
!= blocks
.end(); ++i
)
978 std::auto_ptr
< ClassFile::Code
> defCode(cf
->newCode());
979 defCode
->instrAconstNull();
980 defCode
->instrAreturn();
981 std::list
< std::pair
< sal_Int32
, ClassFile::Code
* > > blocks
;
982 //FIXME: pointers contained in blocks may leak
983 for (std::map
< sal_Int32
, rtl::OString
>::iterator
i(map
.begin());
986 std::auto_ptr
< ClassFile::Code
> blockCode(cf
->newCode());
987 blockCode
->instrGetstatic(className
, i
->second
, classDescriptor
);
988 blockCode
->instrAreturn();
989 blocks
.push_back(std::make_pair(i
->first
, blockCode
.get()));
992 code
->instrLookupswitch(defCode
.get(), blocks
);
993 {for (std::list
< std::pair
< sal_Int32
, ClassFile::Code
* > >::iterator
995 i
!= blocks
.end(); ++i
)
1000 code
->setMaxStackAndLocals(1, 1);
1002 static_cast< ClassFile::AccessFlags
>(
1003 ClassFile::ACC_PUBLIC
| ClassFile::ACC_STATIC
),
1004 rtl::OString(RTL_CONSTASCII_STRINGPARAM("fromInt")),
1005 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)")) + classDescriptor
,
1006 code
.get(), std::vector
< rtl::OString
>(), rtl::OString());
1007 code
.reset(cf
->newCode());
1008 {for (sal_uInt16 i
= 0; i
< fields
; ++i
) {
1009 code
->instrNew(className
);
1011 code
->loadIntegerConstant(reader
.getFieldValue(i
).m_value
.aLong
);
1012 code
->instrInvokespecial(
1013 className
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1014 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")));
1015 code
->instrPutstatic(
1017 codemaker::convertString(reader
.getFieldName(i
)),
1020 code
->instrReturn();
1021 code
->setMaxStackAndLocals(3, 0);
1023 static_cast< ClassFile::AccessFlags
>(
1024 ClassFile::ACC_PRIVATE
| ClassFile::ACC_STATIC
),
1025 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<clinit>")),
1026 rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")), code
.get(),
1027 std::vector
< rtl::OString
>(), rtl::OString());
1028 writeClassFile(options
, className
, *cf
.get());
1032 TypeManager
const & manager
, Dependencies
* dependencies
,
1033 ClassFile
* classFile
, std::vector
< TypeInfo
> * typeInfo
,
1034 sal_Int32 typeParameterIndex
, rtl::OString
const & type
,
1035 rtl::OString
const & name
, sal_Int32 index
)
1037 OSL_ASSERT(dependencies
!= 0 && classFile
!= 0 && typeInfo
!= 0);
1038 rtl::OString descriptor
;
1039 rtl::OString signature
;
1040 SpecialType specialType
;
1041 PolymorphicUnoType polymorphicUnoType
;
1042 if (typeParameterIndex
>= 0) {
1043 descriptor
= rtl::OString(
1044 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;"));
1045 rtl::OStringBuffer buf
;
1049 signature
= buf
.makeStringAndClear();
1050 specialType
= SPECIAL_TYPE_NONE
; //TODO: SPECIAL_TYPE_TYPE_PARAMETER?
1052 specialType
= getFieldDescriptor(
1053 manager
, dependencies
, type
, &descriptor
, &signature
,
1054 &polymorphicUnoType
);
1056 classFile
->addField(ClassFile::ACC_PUBLIC
, name
, descriptor
, 0, signature
);
1057 typeInfo
->push_back(
1059 name
, specialType
, index
, polymorphicUnoType
, typeParameterIndex
));
1062 sal_uInt16
addFieldInit(
1063 TypeManager
const & manager
, rtl::OString
const & className
,
1064 rtl::OString
const & fieldName
, bool typeParameter
,
1065 rtl::OString
const & fieldType
, Dependencies
* dependencies
,
1066 ClassFile::Code
* code
)
1068 OSL_ASSERT(dependencies
!= 0 && code
!= 0);
1069 if (typeParameter
) {
1072 RTTypeClass typeClass
;
1073 rtl::OString nucleus
;
1075 std::vector
< rtl::OString
> args
;
1076 codemaker::UnoType::Sort sort
= codemaker::decomposeAndResolve(
1077 manager
, fieldType
, true, false, false, &typeClass
, &nucleus
, &rank
,
1081 case codemaker::UnoType::SORT_STRING
:
1082 code
->loadLocalReference(0);
1083 code
->loadStringConstant(rtl::OString());
1084 code
->instrPutfield(
1085 className
, fieldName
,
1087 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/String;")));
1090 case codemaker::UnoType::SORT_TYPE
:
1091 code
->loadLocalReference(0);
1092 code
->instrGetstatic(
1094 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
1095 rtl::OString(RTL_CONSTASCII_STRINGPARAM("VOID")),
1097 RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Type;")));
1098 code
->instrPutfield(
1099 className
, fieldName
,
1101 RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Type;")));
1104 case codemaker::UnoType::SORT_ANY
:
1105 code
->loadLocalReference(0);
1106 code
->instrGetstatic(
1108 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1109 rtl::OString(RTL_CONSTASCII_STRINGPARAM("VOID")),
1111 RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Any;")));
1112 code
->instrPutfield(
1113 className
, fieldName
,
1115 RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;")));
1118 case codemaker::UnoType::SORT_COMPLEX
:
1119 switch (typeClass
) {
1122 code
->loadLocalReference(0);
1123 typereg::Reader
reader(manager
.getTypeReader(nucleus
));
1124 if (reader
.getFieldCount() == 0) {
1125 throw CannotDumpException(
1127 RTL_CONSTASCII_STRINGPARAM(
1128 "Bad type information"))); //TODO
1130 rtl::OStringBuffer descBuf
;
1131 translateUnoTypeToDescriptor(
1132 manager
, sort
, typeClass
, nucleus
, 0,
1133 std::vector
< rtl::OString
>(), false, false,
1134 dependencies
, &descBuf
, 0, 0, 0);
1135 rtl::OString
desc(descBuf
.makeStringAndClear());
1136 code
->instrGetstatic(
1138 codemaker::convertString(reader
.getFieldName(0)),
1140 code
->instrPutfield(className
, fieldName
, desc
);
1144 case RT_TYPE_STRUCT
:
1146 code
->loadLocalReference(0);
1147 code
->instrNew(nucleus
);
1149 code
->instrInvokespecial(
1151 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1152 rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")));
1153 rtl::OStringBuffer desc
;
1154 translateUnoTypeToDescriptor(
1155 manager
, sort
, typeClass
, nucleus
, 0,
1156 std::vector
< rtl::OString
>(), false, false,
1157 dependencies
, &desc
, 0, 0, 0);
1158 code
->instrPutfield(
1159 className
, fieldName
, desc
.makeStringAndClear());
1164 OSL_ASSERT(typeClass
== RT_TYPE_INTERFACE
);
1172 code
->loadLocalReference(0);
1173 code
->loadIntegerConstant(0);
1175 if (sort
>= codemaker::UnoType::SORT_BOOLEAN
1176 && sort
<= codemaker::UnoType::SORT_CHAR
)
1178 code
->instrNewarray(sort
);
1180 code
->instrAnewarray(
1181 codemaker::java::translateUnoToJavaType(sort
, typeClass
,
1185 rtl::OStringBuffer desc
;
1186 translateUnoTypeToDescriptor(
1187 manager
, sort
, typeClass
, nucleus
, rank
- 1,
1188 std::vector
< rtl::OString
>(), false, false, dependencies
,
1190 code
->instrAnewarray(desc
.makeStringAndClear());
1192 rtl::OStringBuffer desc
;
1193 translateUnoTypeToDescriptor(
1194 manager
, sort
, typeClass
, nucleus
, rank
,
1195 std::vector
< rtl::OString
>(), false, false, dependencies
,
1197 code
->instrPutfield(
1198 className
, fieldName
, desc
.makeStringAndClear());
1204 sal_uInt16
addLoadLocal(
1205 TypeManager
const & manager
, ClassFile::Code
* code
, sal_uInt16
* index
,
1206 bool typeParameter
, rtl::OString
const & type
, bool any
,
1207 Dependencies
* dependencies
)
1210 code
!= 0 && index
!= 0 && !(typeParameter
&& any
)
1211 && dependencies
!= 0);
1212 sal_uInt16 stack
= 1;
1213 sal_uInt16 size
= 1;
1214 if (typeParameter
) {
1215 code
->loadLocalReference(*index
);
1218 RTTypeClass typeClass
;
1219 rtl::OString nucleus
;
1221 std::vector
< rtl::OString
> args
;
1222 codemaker::UnoType::Sort sort
= codemaker::decomposeAndResolve(
1223 manager
, type
, true, false, false, &typeClass
, &nucleus
, &rank
, &args
);
1226 case codemaker::UnoType::SORT_BOOLEAN
:
1230 RTL_CONSTASCII_STRINGPARAM("java/lang/Boolean")));
1232 code
->loadLocalInteger(*index
);
1233 code
->instrInvokespecial(
1235 RTL_CONSTASCII_STRINGPARAM("java/lang/Boolean")),
1236 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1237 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(Z)V")));
1240 code
->loadLocalInteger(*index
);
1246 case codemaker::UnoType::SORT_BYTE
:
1250 RTL_CONSTASCII_STRINGPARAM("java/lang/Byte")));
1252 code
->loadLocalInteger(*index
);
1253 code
->instrInvokespecial(
1255 RTL_CONSTASCII_STRINGPARAM("java/lang/Byte")),
1256 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1257 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(B)V")));
1260 code
->loadLocalInteger(*index
);
1266 case codemaker::UnoType::SORT_SHORT
:
1270 RTL_CONSTASCII_STRINGPARAM("java/lang/Short")));
1272 code
->loadLocalInteger(*index
);
1273 code
->instrInvokespecial(
1275 RTL_CONSTASCII_STRINGPARAM("java/lang/Short")),
1276 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1277 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(S)V")));
1280 code
->loadLocalInteger(*index
);
1286 case codemaker::UnoType::SORT_UNSIGNED_SHORT
:
1290 RTL_CONSTASCII_STRINGPARAM(
1291 "com/sun/star/uno/Any")));
1293 code
->instrGetstatic(
1295 RTL_CONSTASCII_STRINGPARAM(
1296 "com/sun/star/uno/Type")),
1298 RTL_CONSTASCII_STRINGPARAM("UNSIGNED_SHORT")),
1300 RTL_CONSTASCII_STRINGPARAM(
1301 "Lcom/sun/star/uno/Type;")));
1304 RTL_CONSTASCII_STRINGPARAM("java/lang/Short")));
1306 code
->loadLocalInteger(*index
);
1307 code
->instrInvokespecial(
1309 RTL_CONSTASCII_STRINGPARAM("java/lang/Short")),
1310 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1311 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(S)V")));
1312 code
->instrInvokespecial(
1314 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1315 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1317 RTL_CONSTASCII_STRINGPARAM(
1318 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
1322 code
->loadLocalInteger(*index
);
1328 case codemaker::UnoType::SORT_LONG
:
1332 RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")));
1334 code
->loadLocalInteger(*index
);
1335 code
->instrInvokespecial(
1337 RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")),
1338 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1339 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")));
1342 code
->loadLocalInteger(*index
);
1348 case codemaker::UnoType::SORT_UNSIGNED_LONG
:
1352 RTL_CONSTASCII_STRINGPARAM(
1353 "com/sun/star/uno/Any")));
1355 code
->instrGetstatic(
1357 RTL_CONSTASCII_STRINGPARAM(
1358 "com/sun/star/uno/Type")),
1360 RTL_CONSTASCII_STRINGPARAM("UNSIGNED_LONG")),
1362 RTL_CONSTASCII_STRINGPARAM(
1363 "Lcom/sun/star/uno/Type;")));
1366 RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")));
1368 code
->loadLocalInteger(*index
);
1369 code
->instrInvokespecial(
1371 RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")),
1372 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1373 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")));
1374 code
->instrInvokespecial(
1376 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1377 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1379 RTL_CONSTASCII_STRINGPARAM(
1380 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
1384 code
->loadLocalInteger(*index
);
1390 case codemaker::UnoType::SORT_HYPER
:
1394 RTL_CONSTASCII_STRINGPARAM("java/lang/Long")));
1396 code
->loadLocalLong(*index
);
1397 code
->instrInvokespecial(
1399 RTL_CONSTASCII_STRINGPARAM("java/lang/Long")),
1400 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1401 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(J)V")));
1404 code
->loadLocalLong(*index
);
1410 case codemaker::UnoType::SORT_UNSIGNED_HYPER
:
1414 RTL_CONSTASCII_STRINGPARAM(
1415 "com/sun/star/uno/Any")));
1417 code
->instrGetstatic(
1419 RTL_CONSTASCII_STRINGPARAM(
1420 "com/sun/star/uno/Type")),
1422 RTL_CONSTASCII_STRINGPARAM("UNSIGNED_HYPER")),
1424 RTL_CONSTASCII_STRINGPARAM(
1425 "Lcom/sun/star/uno/Type;")));
1428 RTL_CONSTASCII_STRINGPARAM("java/lang/Long")));
1430 code
->loadLocalLong(*index
);
1431 code
->instrInvokespecial(
1433 RTL_CONSTASCII_STRINGPARAM("java/lang/Long")),
1434 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1435 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(J)V")));
1436 code
->instrInvokespecial(
1438 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1439 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1441 RTL_CONSTASCII_STRINGPARAM(
1442 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
1446 code
->loadLocalLong(*index
);
1452 case codemaker::UnoType::SORT_FLOAT
:
1456 RTL_CONSTASCII_STRINGPARAM("java/lang/Float")));
1458 code
->loadLocalFloat(*index
);
1459 code
->instrInvokespecial(
1461 RTL_CONSTASCII_STRINGPARAM("java/lang/Float")),
1462 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1463 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(F)V")));
1466 code
->loadLocalFloat(*index
);
1472 case codemaker::UnoType::SORT_DOUBLE
:
1476 RTL_CONSTASCII_STRINGPARAM("java/lang/Double")));
1478 code
->loadLocalDouble(*index
);
1479 code
->instrInvokespecial(
1481 RTL_CONSTASCII_STRINGPARAM("java/lang/Double")),
1482 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1483 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(D)V")));
1486 code
->loadLocalDouble(*index
);
1492 case codemaker::UnoType::SORT_CHAR
:
1496 RTL_CONSTASCII_STRINGPARAM("java/lang/Character")));
1498 code
->loadLocalInteger(*index
);
1499 code
->instrInvokespecial(
1501 RTL_CONSTASCII_STRINGPARAM("java/lang/Character")),
1502 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1503 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(C)V")));
1506 code
->loadLocalInteger(*index
);
1512 case codemaker::UnoType::SORT_STRING
:
1513 case codemaker::UnoType::SORT_TYPE
:
1514 case codemaker::UnoType::SORT_ANY
:
1515 code
->loadLocalReference(*index
);
1519 case codemaker::UnoType::SORT_COMPLEX
:
1520 switch (typeClass
) {
1522 // Assuming that no Java types are derived from Java types
1523 // that are directly derived from com.sun.star.uno.Enum:
1524 code
->loadLocalReference(*index
);
1528 case RT_TYPE_STRUCT
:
1532 RTL_CONSTASCII_STRINGPARAM(
1533 "com/sun/star/uno/Any")));
1537 RTL_CONSTASCII_STRINGPARAM(
1538 "com/sun/star/uno/Type")));
1540 code
->loadStringConstant(
1541 createUnoName(manager
, nucleus
, rank
, args
));
1542 code
->instrGetstatic(
1544 RTL_CONSTASCII_STRINGPARAM(
1545 "com/sun/star/uno/TypeClass")),
1546 rtl::OString(RTL_CONSTASCII_STRINGPARAM("STRUCT")),
1548 RTL_CONSTASCII_STRINGPARAM(
1549 "Lcom/sun/star/uno/TypeClass;")));
1550 dependencies
->insert(
1552 RTL_CONSTASCII_STRINGPARAM(
1553 "com/sun/star/uno/TypeClass")));
1554 code
->instrInvokespecial(
1556 RTL_CONSTASCII_STRINGPARAM(
1557 "com/sun/star/uno/Type")),
1558 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1560 RTL_CONSTASCII_STRINGPARAM(
1561 "(Ljava/lang/String;"
1562 "Lcom/sun/star/uno/TypeClass;)V")));
1563 code
->loadLocalReference(*index
);
1564 code
->instrInvokespecial(
1566 RTL_CONSTASCII_STRINGPARAM(
1567 "com/sun/star/uno/Any")),
1568 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1570 RTL_CONSTASCII_STRINGPARAM(
1571 "(Lcom/sun/star/uno/Type;"
1572 "Ljava/lang/Object;)V")));
1575 code
->loadLocalReference(*index
);
1581 case RT_TYPE_INTERFACE
:
1585 RTL_CONSTASCII_STRINGPARAM(
1586 "com/sun/star/uno/XInterface"))))
1590 RTL_CONSTASCII_STRINGPARAM(
1591 "com/sun/star/uno/Any")));
1595 RTL_CONSTASCII_STRINGPARAM(
1596 "com/sun/star/uno/Type")));
1598 code
->loadStringConstant(nucleus
.replace('/', '.'));
1599 code
->instrGetstatic(
1601 RTL_CONSTASCII_STRINGPARAM(
1602 "com/sun/star/uno/TypeClass")),
1604 RTL_CONSTASCII_STRINGPARAM("INTERFACE")),
1606 RTL_CONSTASCII_STRINGPARAM(
1607 "Lcom/sun/star/uno/TypeClass;")));
1608 dependencies
->insert(
1610 RTL_CONSTASCII_STRINGPARAM(
1611 "com/sun/star/uno/TypeClass")));
1612 code
->instrInvokespecial(
1614 RTL_CONSTASCII_STRINGPARAM(
1615 "com/sun/star/uno/Type")),
1616 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1618 RTL_CONSTASCII_STRINGPARAM(
1619 "(Ljava/lang/String;"
1620 "Lcom/sun/star/uno/TypeClass;)V")));
1621 code
->loadLocalReference(*index
);
1622 code
->instrInvokespecial(
1624 RTL_CONSTASCII_STRINGPARAM(
1625 "com/sun/star/uno/Any")),
1626 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1628 RTL_CONSTASCII_STRINGPARAM(
1629 "(Lcom/sun/star/uno/Type;"
1630 "Ljava/lang/Object;)V")));
1633 code
->loadLocalReference(*index
);
1653 case codemaker::UnoType::SORT_BOOLEAN
:
1654 case codemaker::UnoType::SORT_BYTE
:
1655 case codemaker::UnoType::SORT_SHORT
:
1656 case codemaker::UnoType::SORT_LONG
:
1657 case codemaker::UnoType::SORT_HYPER
:
1658 case codemaker::UnoType::SORT_FLOAT
:
1659 case codemaker::UnoType::SORT_DOUBLE
:
1660 case codemaker::UnoType::SORT_CHAR
:
1661 case codemaker::UnoType::SORT_STRING
:
1662 case codemaker::UnoType::SORT_TYPE
:
1663 // assuming that no Java types are derived from
1664 // com.sun.star.uno.Type
1667 case codemaker::UnoType::SORT_UNSIGNED_SHORT
:
1668 case codemaker::UnoType::SORT_UNSIGNED_LONG
:
1669 case codemaker::UnoType::SORT_UNSIGNED_HYPER
:
1670 case codemaker::UnoType::SORT_ANY
:
1674 case codemaker::UnoType::SORT_COMPLEX
:
1675 switch (typeClass
) {
1677 // assuming that no Java types are derived from Java
1678 // types that are directly derived from
1679 // com.sun.star.uno.Enum
1682 case RT_TYPE_STRUCT
:
1683 case RT_TYPE_INTERFACE
:
1701 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")));
1705 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")));
1707 code
->loadStringConstant(
1708 createUnoName(manager
, nucleus
, rank
, args
));
1709 code
->instrInvokespecial(
1711 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
1712 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1714 RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;)V")));
1715 code
->loadLocalReference(*index
);
1716 code
->instrInvokespecial(
1718 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1719 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1721 RTL_CONSTASCII_STRINGPARAM(
1722 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V")));
1725 code
->loadLocalReference(*index
);
1731 if (*index
> SAL_MAX_UINT16
- size
) {
1732 throw CannotDumpException(
1734 RTL_CONSTASCII_STRINGPARAM(
1735 "Too many local variables for Java class file format")));
1737 *index
= *index
+ size
;
1741 void addBaseArguments(
1742 TypeManager
const & manager
, Dependencies
* dependencies
,
1743 MethodDescriptor
* methodDescriptor
, ClassFile::Code
* code
,
1744 RTTypeClass typeClass
, rtl::OString
const & type
, sal_uInt16
* index
)
1747 dependencies
!= 0 && methodDescriptor
!= 0 && code
!= 0 && index
!= 0);
1748 typereg::Reader
reader(manager
.getTypeReader(type
));
1749 if (!reader
.isValid() || reader
.getTypeClass() != typeClass
1750 || codemaker::convertString(reader
.getTypeName()) != type
1751 || reader
.getMethodCount() != 0 || reader
.getReferenceCount() != 0)
1753 throw CannotDumpException(
1754 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1757 sal_uInt16 superTypes
= reader
.getSuperTypeCount();
1758 sal_uInt16 fields
= reader
.getFieldCount();
1759 sal_uInt16 firstField
= 0;
1762 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Exception")))
1764 if (typeClass
!= RT_TYPE_EXCEPTION
|| superTypes
!= 0 || fields
!= 2) {
1765 throw CannotDumpException(
1767 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1772 (typeClass
== RT_TYPE_STRUCT
&& (superTypes
> 1 || fields
== 0)) ||
1773 (typeClass
== RT_TYPE_EXCEPTION
&& superTypes
!= 1)
1776 throw CannotDumpException(
1778 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1780 if (superTypes
== 1) {
1782 manager
, dependencies
, methodDescriptor
, code
, typeClass
,
1783 codemaker::convertString(reader
.getSuperTypeName(0)), index
);
1786 for (sal_uInt16 i
= firstField
; i
< fields
; ++i
) {
1787 if (reader
.getFieldFlags(i
) != RT_ACCESS_READWRITE
1788 || reader
.getFieldValue(i
).m_type
!= RT_TYPE_NONE
)
1790 throw CannotDumpException(
1792 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1794 rtl::OString
fieldType(
1795 codemaker::convertString(reader
.getFieldTypeName(i
)));
1796 methodDescriptor
->addParameter(fieldType
, false, true, 0);
1798 manager
, code
, index
, false, fieldType
, false, dependencies
);
1802 sal_uInt16
addDirectArgument(
1803 TypeManager
const & manager
, Dependencies
* dependencies
,
1804 MethodDescriptor
* methodDescriptor
, ClassFile::Code
* code
,
1805 sal_uInt16
* index
, rtl::OString
const & className
,
1806 rtl::OString
const & fieldName
, bool typeParameter
,
1807 rtl::OString
const & fieldType
)
1810 dependencies
!= 0 && methodDescriptor
!= 0 && code
!= 0 && index
!= 0);
1812 if (typeParameter
) {
1813 methodDescriptor
->addTypeParameter(fieldType
);
1814 desc
= rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;"));
1816 methodDescriptor
->addParameter(fieldType
, false, true, 0);
1817 getFieldDescriptor(manager
, dependencies
, fieldType
, &desc
, 0, 0);
1819 code
->loadLocalReference(0);
1820 sal_uInt16 stack
= addLoadLocal(
1821 manager
, code
, index
, typeParameter
, fieldType
, false, dependencies
);
1822 code
->instrPutfield(className
, fieldName
, desc
);
1826 void handleAggregatingType(
1827 TypeManager
const & manager
, JavaOptions
/*TODO const*/ & options
,
1828 typereg::Reader
const & reader
, Dependencies
* dependencies
)
1830 OSL_ASSERT(dependencies
!= 0);
1831 if (reader
.getMethodCount() != 0)
1833 throw CannotDumpException(
1834 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1837 RTTypeClass typeClass
= reader
.getTypeClass();
1838 rtl::OString
className(codemaker::convertString(reader
.getTypeName()));
1839 sal_uInt16 superTypes
= reader
.getSuperTypeCount();
1840 sal_uInt16 fields
= reader
.getFieldCount();
1841 sal_uInt16 firstField
= 0;
1842 sal_uInt16 references
= reader
.getReferenceCount();
1843 bool runtimeException
= false;
1844 rtl::OString superClass
;
1847 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Exception")))
1849 if (typeClass
!= RT_TYPE_EXCEPTION
|| superTypes
!= 0 || fields
!= 2
1852 throw CannotDumpException(
1854 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1857 superClass
= rtl::OString(
1858 RTL_CONSTASCII_STRINGPARAM("java/lang/Exception"));
1859 } else if (className
1861 RTL_CONSTASCII_STRINGPARAM(
1862 "com/sun/star/uno/RuntimeException")))
1864 if (typeClass
!= RT_TYPE_EXCEPTION
|| superTypes
!= 1 || fields
!= 0
1867 throw CannotDumpException(
1869 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1872 superClass
= rtl::OString(
1873 RTL_CONSTASCII_STRINGPARAM("java/lang/RuntimeException"));
1874 runtimeException
= true;
1878 typeClass
== RT_TYPE_STRUCT
&&
1881 (references
== 0 ? superTypes
> 1 : superTypes
!= 0)
1884 (typeClass
== RT_TYPE_EXCEPTION
&& superTypes
!= 1)
1887 throw CannotDumpException(
1889 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1891 if (superTypes
== 0) {
1892 superClass
= rtl::OString(
1893 RTL_CONSTASCII_STRINGPARAM("java/lang/Object"));
1895 superClass
= codemaker::convertString(reader
.getSuperTypeName(0));
1896 dependencies
->insert(superClass
);
1900 std::map
< rtl::OString
, sal_Int32
> typeParameters
;
1901 if (references
!= 0) {
1902 rtl::OStringBuffer buf
;
1904 for (sal_uInt16 i
= 0; i
< references
; ++i
) {
1905 if (reader
.getReferenceFlags(i
) != RT_ACCESS_INVALID
1906 || reader
.getReferenceSort(i
) != RT_REF_TYPE_PARAMETER
)
1908 throw CannotDumpException(
1910 RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1914 codemaker::convertString(reader
.getReferenceTypeName(i
)));
1916 buf
.append(RTL_CONSTASCII_STRINGPARAM(":Ljava/lang/Object;"));
1917 if (!typeParameters
.insert(
1918 std::map
< rtl::OString
, sal_Int32
>::value_type(name
, i
)).
1921 throw CannotDumpException(
1923 RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1927 buf
.append(RTL_CONSTASCII_STRINGPARAM(">Ljava/lang/Object;"));
1928 sig
= buf
.makeStringAndClear();
1930 std::auto_ptr
< ClassFile
> cf(
1932 static_cast< ClassFile::AccessFlags
>(
1933 ClassFile::ACC_PUBLIC
| ClassFile::ACC_SUPER
),
1934 className
, superClass
, sig
));
1935 std::vector
< TypeInfo
> typeInfo
;
1936 {for (sal_uInt16 i
= firstField
; i
< fields
; ++i
) {
1937 RTFieldAccess flags
= reader
.getFieldFlags(i
);
1938 if ((flags
!= RT_ACCESS_READWRITE
1939 && flags
!= (RT_ACCESS_READWRITE
| RT_ACCESS_PARAMETERIZED_TYPE
))
1940 || ((flags
& RT_ACCESS_PARAMETERIZED_TYPE
) != 0 && references
== 0)
1941 || reader
.getFieldValue(i
).m_type
!= RT_TYPE_NONE
)
1943 throw CannotDumpException(
1945 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1948 codemaker::convertString(reader
.getFieldTypeName(i
)));
1949 sal_Int32 typeParameterIndex
;
1950 if ((flags
& RT_ACCESS_PARAMETERIZED_TYPE
) == 0) {
1951 typeParameterIndex
= -1;
1953 std::map
< rtl::OString
, sal_Int32
>::iterator
it(
1954 typeParameters
.find(type
));
1955 if (it
== typeParameters
.end()) {
1956 throw CannotDumpException(
1958 RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1961 typeParameterIndex
= it
->second
;
1964 manager
, dependencies
, cf
.get(), &typeInfo
, typeParameterIndex
,
1965 type
, codemaker::convertString(reader
.getFieldName(i
)), i
- firstField
);
1967 if (runtimeException
) {
1969 manager
, dependencies
, cf
.get(), &typeInfo
, -1,
1971 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XInterface")),
1972 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Context")), 0);
1974 std::auto_ptr
< ClassFile::Code
> code(cf
->newCode());
1975 code
->loadLocalReference(0);
1976 code
->instrInvokespecial(
1977 superClass
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1978 rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")));
1979 sal_uInt16 stack
= 0;
1980 {for (sal_uInt16 i
= firstField
; i
< fields
; ++i
) {
1985 codemaker::convertString(reader
.getFieldName(i
)),
1986 (reader
.getFieldFlags(i
) & RT_ACCESS_PARAMETERIZED_TYPE
) != 0,
1987 codemaker::convertString(reader
.getFieldTypeName(i
)),
1988 dependencies
, code
.get()));
1990 if (runtimeException
) {
1995 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Context")), false,
1997 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XInterface")),
1998 dependencies
, code
.get()));
2000 code
->instrReturn();
2001 code
->setMaxStackAndLocals(stack
+ 1, 1);
2003 ClassFile::ACC_PUBLIC
,
2004 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2005 rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")), code
.get(),
2006 std::vector
< rtl::OString
>(), rtl::OString());
2007 if (typeClass
== RT_TYPE_EXCEPTION
) {
2008 code
.reset(cf
->newCode());
2009 code
->loadLocalReference(0);
2010 code
->loadLocalReference(1);
2011 code
->instrInvokespecial(
2012 superClass
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2013 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;)V")));
2015 for (sal_uInt16 i
= firstField
; i
< fields
; ++i
) {
2020 codemaker::convertString(reader
.getFieldName(i
)),
2021 ((reader
.getFieldFlags(i
) & RT_ACCESS_PARAMETERIZED_TYPE
)
2023 codemaker::convertString(reader
.getFieldTypeName(i
)),
2024 dependencies
, code
.get()));
2026 if (runtimeException
) {
2031 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Context")), false,
2033 RTL_CONSTASCII_STRINGPARAM(
2034 "com/sun/star/uno/XInterface")),
2035 dependencies
, code
.get()));
2037 code
->instrReturn();
2038 code
->setMaxStackAndLocals(stack
+ 2, 2);
2040 ClassFile::ACC_PUBLIC
,
2041 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2042 rtl::OString(RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;)V")),
2043 code
.get(), std::vector
< rtl::OString
>(), rtl::OString());
2045 MethodDescriptor
desc(
2046 manager
, dependencies
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("void")),
2048 code
.reset(cf
->newCode());
2049 code
->loadLocalReference(0);
2050 sal_uInt16 index
= 1;
2051 if (typeClass
== RT_TYPE_EXCEPTION
) {
2053 rtl::OString(RTL_CONSTASCII_STRINGPARAM("string")), false, true, 0);
2054 code
->loadLocalReference(index
++);
2056 if (superTypes
!= 0) {
2058 manager
, dependencies
, &desc
, code
.get(), typeClass
, superClass
,
2061 code
->instrInvokespecial(
2062 superClass
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2063 desc
.getDescriptor());
2064 sal_uInt16 maxSize
= index
;
2065 {for (sal_uInt16 i
= firstField
; i
< fields
; ++i
) {
2069 manager
, dependencies
, &desc
, code
.get(), &index
, className
,
2070 codemaker::convertString(reader
.getFieldName(i
)),
2071 (reader
.getFieldFlags(i
) & RT_ACCESS_PARAMETERIZED_TYPE
) != 0,
2072 codemaker::convertString(reader
.getFieldTypeName(i
))));
2074 if (runtimeException
) {
2078 manager
, dependencies
, &desc
, code
.get(), &index
, className
,
2079 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Context")), false,
2081 RTL_CONSTASCII_STRINGPARAM(
2082 "com/sun/star/uno/XInterface"))));
2084 code
->instrReturn();
2085 code
->setMaxStackAndLocals(maxSize
, index
);
2087 ClassFile::ACC_PUBLIC
,
2088 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2089 desc
.getDescriptor(), code
.get(), std::vector
< rtl::OString
>(),
2090 desc
.getSignature());
2091 addTypeInfo(className
, typeInfo
, dependencies
, cf
.get());
2092 writeClassFile(options
, className
, *cf
.get());
2095 void createExceptionsAttribute(
2096 TypeManager
const & manager
, typereg::Reader
const & reader
,
2097 sal_uInt16 methodIndex
, Dependencies
* dependencies
,
2098 std::vector
< rtl::OString
> * exceptions
, codemaker::ExceptionTree
* tree
)
2100 OSL_ASSERT(dependencies
!= 0 && exceptions
!= 0);
2101 sal_uInt16 n
= reader
.getMethodExceptionCount(methodIndex
);
2102 for (sal_uInt16 i
= 0; i
< n
; ++i
) {
2104 codemaker::convertString(
2105 reader
.getMethodExceptionTypeName(methodIndex
, i
)));
2106 dependencies
->insert(type
);
2107 exceptions
->push_back(type
);
2109 tree
->add(type
, manager
);
2114 void handleInterfaceType(
2115 TypeManager
const & manager
, JavaOptions
/*TODO const*/ & options
,
2116 typereg::Reader
const & reader
, Dependencies
* dependencies
)
2118 OSL_ASSERT(dependencies
!= 0);
2120 rtl::OString
className(codemaker::convertString(reader
.getTypeName()));
2121 sal_uInt16 superTypes
= reader
.getSuperTypeCount();
2122 sal_uInt16 fields
= reader
.getFieldCount();
2123 sal_uInt16 methods
= reader
.getMethodCount();
2126 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XInterface")))
2128 if (superTypes
!= 0 || fields
!= 0 || methods
!= 3) {
2129 throw CannotDumpException(
2131 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2134 } else if (superTypes
== 0) {
2135 throw CannotDumpException(
2136 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2139 std::auto_ptr
< ClassFile
> cf(
2141 static_cast< ClassFile::AccessFlags
>(
2142 ClassFile::ACC_PUBLIC
| ClassFile::ACC_INTERFACE
2143 | ClassFile::ACC_ABSTRACT
),
2145 rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
2147 {for (sal_uInt16 i
= 0; i
< superTypes
; ++i
) {
2148 rtl::OString
t(codemaker::convertString(reader
.getSuperTypeName(i
)));
2149 dependencies
->insert(t
);
2150 cf
->addInterface(t
);
2152 // As a special case, let com.sun.star.lang.XEventListener extend
2153 // java.util.EventListener ("A tagging interface that all event listener
2154 // interfaces must extend"):
2157 RTL_CONSTASCII_STRINGPARAM("com/sun/star/lang/XEventListener")))
2161 RTL_CONSTASCII_STRINGPARAM("java/util/EventListener")));
2163 std::vector
< TypeInfo
> typeInfo
;
2164 sal_Int32 index
= 0;
2165 {for (sal_uInt16 i
= 0; i
< fields
; ++i
) {
2166 RTFieldAccess flags
= reader
.getFieldFlags(i
);
2167 //TODO: ok if both READONLY and BOUND?
2168 if (((((flags
& RT_ACCESS_READWRITE
) != 0)
2169 ^ ((flags
& RT_ACCESS_READONLY
) != 0))
2172 & ~(RT_ACCESS_READWRITE
| RT_ACCESS_READONLY
2175 || reader
.getFieldValue(i
).m_type
!= RT_TYPE_NONE
)
2177 throw CannotDumpException(
2179 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2181 //TODO: exploit the fact that attribute getter/setter methods preceed
2183 rtl::OUString
attrNameUtf16(reader
.getFieldName(i
));
2184 sal_uInt16 getter
= SAL_MAX_UINT16
;
2185 sal_uInt16 setter
= SAL_MAX_UINT16
;
2186 for (sal_uInt16 j
= 0; j
< methods
; ++j
) {
2187 RTMethodMode mflags
= reader
.getMethodFlags(j
);
2188 if ((mflags
== RT_MODE_ATTRIBUTE_GET
2189 || mflags
== RT_MODE_ATTRIBUTE_SET
)
2190 && reader
.getMethodName(j
) == attrNameUtf16
)
2192 if (!reader
.getMethodReturnTypeName(j
).equalsAsciiL(
2193 RTL_CONSTASCII_STRINGPARAM("void"))
2194 || reader
.getMethodParameterCount(j
) != 0
2195 || (mflags
== RT_MODE_ATTRIBUTE_GET
2196 ? getter
!= SAL_MAX_UINT16
2197 : (setter
!= SAL_MAX_UINT16
2198 || (flags
& RT_ACCESS_READONLY
) != 0)))
2200 throw CannotDumpException(
2202 RTL_CONSTASCII_STRINGPARAM(
2203 "Bad type information"))); //TODO
2205 OSL_ASSERT(j
!= SAL_MAX_UINT16
);
2206 (mflags
== RT_MODE_ATTRIBUTE_GET
? getter
: setter
) = j
;
2209 rtl::OString
fieldType(
2210 codemaker::convertString(reader
.getFieldTypeName(i
)));
2211 SpecialType specialType
;
2212 PolymorphicUnoType polymorphicUnoType
;
2213 MethodDescriptor
gdesc(
2214 manager
, dependencies
, fieldType
, &specialType
,
2215 &polymorphicUnoType
);
2216 std::vector
< rtl::OString
> exc
;
2217 if (getter
!= SAL_MAX_UINT16
) {
2218 createExceptionsAttribute(
2219 manager
, reader
, getter
, dependencies
, &exc
, 0);
2221 rtl::OString
attrName(codemaker::convertString(attrNameUtf16
));
2223 static_cast< ClassFile::AccessFlags
>(
2224 ClassFile::ACC_PUBLIC
| ClassFile::ACC_ABSTRACT
),
2225 rtl::OString(RTL_CONSTASCII_STRINGPARAM("get")) + attrName
,
2226 gdesc
.getDescriptor(), 0, exc
, gdesc
.getSignature());
2227 if ((flags
& RT_ACCESS_READONLY
) == 0) {
2228 MethodDescriptor
sdesc(
2229 manager
, dependencies
,
2230 rtl::OString(RTL_CONSTASCII_STRINGPARAM("void")), 0, 0);
2231 sdesc
.addParameter(fieldType
, false, true, 0);
2232 std::vector
< rtl::OString
> exc2
;
2233 if (setter
!= SAL_MAX_UINT16
) {
2234 createExceptionsAttribute(
2235 manager
, reader
, setter
, dependencies
, &exc2
, 0);
2238 static_cast< ClassFile::AccessFlags
>(
2239 ClassFile::ACC_PUBLIC
| ClassFile::ACC_ABSTRACT
),
2240 rtl::OString(RTL_CONSTASCII_STRINGPARAM("set")) + attrName
,
2241 sdesc
.getDescriptor(), 0, exc2
, sdesc
.getSignature());
2245 TypeInfo::KIND_ATTRIBUTE
, attrName
, specialType
,
2246 static_cast< TypeInfo::Flags
>(
2247 ((flags
& RT_ACCESS_READONLY
) == 0
2248 ? 0 : TypeInfo::FLAG_READONLY
)
2249 | ((flags
& RT_ACCESS_BOUND
) == 0
2250 ? 0 : TypeInfo::FLAG_BOUND
)),
2251 index
, polymorphicUnoType
));
2252 index
+= ((flags
& RT_ACCESS_READONLY
) == 0 ? 2 : 1);
2254 {for (sal_uInt16 i
= 0; i
< methods
; ++i
) {
2255 RTMethodMode flags
= reader
.getMethodFlags(i
);
2257 case RT_MODE_ONEWAY
:
2258 case RT_MODE_TWOWAY
:
2260 rtl::OString
methodName(
2261 codemaker::convertString(reader
.getMethodName(i
)));
2262 SpecialType specialReturnType
;
2263 PolymorphicUnoType polymorphicUnoReturnType
;
2264 MethodDescriptor
desc(
2265 manager
, dependencies
,
2266 codemaker::convertString(
2267 reader
.getMethodReturnTypeName(i
)),
2268 &specialReturnType
, &polymorphicUnoReturnType
);
2271 TypeInfo::KIND_METHOD
, methodName
, specialReturnType
,
2272 static_cast< TypeInfo::Flags
>(
2273 flags
== RT_MODE_ONEWAY
2274 ? TypeInfo::FLAG_ONEWAY
: 0),
2275 index
++, polymorphicUnoReturnType
));
2276 for (sal_uInt16 j
= 0; j
< reader
.getMethodParameterCount(i
);
2281 switch (reader
.getMethodParameterFlags(i
, j
)) {
2292 case RT_PARAM_INOUT
:
2298 throw CannotDumpException(
2300 RTL_CONSTASCII_STRINGPARAM(
2301 "Bad type information"))); //TODO
2303 PolymorphicUnoType polymorphicUnoType
;
2304 SpecialType specialType
= desc
.addParameter(
2305 codemaker::convertString(
2306 reader
.getMethodParameterTypeName(i
, j
)),
2307 out
, true, &polymorphicUnoType
);
2308 if (out
|| isSpecialType(specialType
)
2309 || (polymorphicUnoType
.kind
2310 != PolymorphicUnoType::KIND_NONE
))
2314 codemaker::convertString(
2315 reader
.getMethodParameterName(i
, j
)),
2316 specialType
, in
, out
, methodName
, j
,
2317 polymorphicUnoType
));
2320 std::vector
< rtl::OString
> exc2
;
2321 createExceptionsAttribute(
2322 manager
, reader
, i
, dependencies
, &exc2
, 0);
2324 static_cast< ClassFile::AccessFlags
>(
2325 ClassFile::ACC_PUBLIC
| ClassFile::ACC_ABSTRACT
),
2326 methodName
, desc
.getDescriptor(), 0, exc2
,
2327 desc
.getSignature());
2331 case RT_MODE_ATTRIBUTE_GET
:
2332 case RT_MODE_ATTRIBUTE_SET
:
2334 //TODO: exploit the fact that attribute getter/setter methods
2335 // are ordered the same way as the attribute fields themselves
2336 rtl::OUString
methodNameUtf16(reader
.getMethodName(i
));
2338 for (sal_uInt16 j
= 0; j
< fields
; ++j
) {
2339 if (reader
.getFieldName(j
) == methodNameUtf16
) {
2349 throw CannotDumpException(
2351 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2354 addTypeInfo(className
, typeInfo
, dependencies
, cf
.get());
2355 writeClassFile(options
, className
, *cf
.get());
2359 TypeManager
const & manager
, JavaOptions
/*TODO const*/ &,
2360 typereg::Reader
const & reader
, Dependencies
* dependencies
)
2362 OSL_ASSERT(dependencies
!= 0);
2363 if (reader
.getSuperTypeCount() != 1 || reader
.getFieldCount() != 0
2364 || reader
.getMethodCount() != 0 || reader
.getReferenceCount() != 0)
2366 throw CannotDumpException(
2367 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2370 RTTypeClass typeClass
;
2371 rtl::OString nucleus
;
2373 std::vector
< rtl::OString
> args
;
2374 if (codemaker::decomposeAndResolve(
2375 manager
, codemaker::convertString(reader
.getSuperTypeName(0)),
2376 false, false, false, &typeClass
, &nucleus
, &rank
, &args
)
2377 == codemaker::UnoType::SORT_COMPLEX
)
2379 switch (typeClass
) {
2380 case RT_TYPE_STRUCT
:
2381 if (!args
.empty()) {
2382 throw CannotDumpException(
2384 RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2388 case RT_TYPE_INTERFACE
:
2389 case RT_TYPE_TYPEDEF
:
2390 dependencies
->insert(nucleus
);
2401 TypeManager
const & manager
, typereg::Reader
const & reader
,
2402 bool publishable
, sal_uInt16 index
, Dependencies
* dependencies
,
2403 ClassFile
* classFile
)
2405 OSL_ASSERT(dependencies
!= 0 && classFile
!= 0);
2406 RTFieldAccess flags
= reader
.getFieldFlags(index
);
2407 if (flags
!= RT_ACCESS_CONST
2408 && (!publishable
|| flags
!= (RT_ACCESS_CONST
| RT_ACCESS_PUBLISHED
)))
2410 throw CannotDumpException(
2411 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2414 RTConstValue
fieldValue(reader
.getFieldValue(index
));
2415 sal_uInt16 valueIndex
;
2416 RTTypeClass typeClass
;
2417 rtl::OString nucleus
;
2419 std::vector
< rtl::OString
> args
;
2420 switch (codemaker::decomposeAndResolve(
2422 codemaker::convertString(reader
.getFieldTypeName(index
)),
2423 true, false, false, &typeClass
, &nucleus
, &rank
, &args
))
2425 case codemaker::UnoType::SORT_BOOLEAN
:
2426 if (fieldValue
.m_type
!= RT_TYPE_BOOL
) {
2427 throw CannotDumpException(
2429 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2431 valueIndex
= classFile
->addIntegerInfo(fieldValue
.m_value
.aBool
);
2434 case codemaker::UnoType::SORT_BYTE
:
2435 if (fieldValue
.m_type
!= RT_TYPE_BYTE
) {
2436 throw CannotDumpException(
2438 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2440 valueIndex
= classFile
->addIntegerInfo(fieldValue
.m_value
.aByte
);
2443 case codemaker::UnoType::SORT_SHORT
:
2444 if (fieldValue
.m_type
!= RT_TYPE_INT16
) {
2445 throw CannotDumpException(
2447 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2449 valueIndex
= classFile
->addIntegerInfo(fieldValue
.m_value
.aShort
);
2452 case codemaker::UnoType::SORT_UNSIGNED_SHORT
:
2453 case codemaker::UnoType::SORT_CHAR
:
2454 if (fieldValue
.m_type
!= RT_TYPE_UINT16
) {
2455 throw CannotDumpException(
2457 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2459 valueIndex
= classFile
->addIntegerInfo(fieldValue
.m_value
.aUShort
);
2462 case codemaker::UnoType::SORT_LONG
:
2463 if (fieldValue
.m_type
!= RT_TYPE_INT32
) {
2464 throw CannotDumpException(
2466 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2468 valueIndex
= classFile
->addIntegerInfo(fieldValue
.m_value
.aLong
);
2471 case codemaker::UnoType::SORT_UNSIGNED_LONG
:
2472 if (fieldValue
.m_type
!= RT_TYPE_UINT32
) {
2473 throw CannotDumpException(
2475 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2477 valueIndex
= classFile
->addIntegerInfo(
2478 static_cast< sal_Int32
>(fieldValue
.m_value
.aULong
));
2481 case codemaker::UnoType::SORT_HYPER
:
2482 if (fieldValue
.m_type
!= RT_TYPE_INT64
) {
2483 throw CannotDumpException(
2485 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2487 valueIndex
= classFile
->addLongInfo(fieldValue
.m_value
.aHyper
);
2490 case codemaker::UnoType::SORT_UNSIGNED_HYPER
:
2491 if (fieldValue
.m_type
!= RT_TYPE_UINT64
) {
2492 throw CannotDumpException(
2494 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2496 valueIndex
= classFile
->addLongInfo(
2497 static_cast< sal_Int64
>(fieldValue
.m_value
.aUHyper
));
2500 case codemaker::UnoType::SORT_FLOAT
:
2501 if (fieldValue
.m_type
!= RT_TYPE_FLOAT
) {
2502 throw CannotDumpException(
2504 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2506 valueIndex
= classFile
->addFloatInfo(fieldValue
.m_value
.aFloat
);
2509 case codemaker::UnoType::SORT_DOUBLE
:
2510 if (fieldValue
.m_type
!= RT_TYPE_DOUBLE
) {
2511 throw CannotDumpException(
2513 RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2515 valueIndex
= classFile
->addDoubleInfo(fieldValue
.m_value
.aDouble
);
2519 throw CannotDumpException(
2520 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2526 manager
, dependencies
,
2527 codemaker::convertString(reader
.getFieldTypeName(index
)),
2529 classFile
->addField(
2530 static_cast< ClassFile::AccessFlags
>(
2531 ClassFile::ACC_PUBLIC
| ClassFile::ACC_STATIC
2532 | ClassFile::ACC_FINAL
),
2533 codemaker::convertString(reader
.getFieldName(index
)),
2534 desc
, valueIndex
, sig
);
2537 void handleConstantGroup(
2538 TypeManager
const & manager
, JavaOptions
/*TODO const*/ & options
,
2539 typereg::Reader
const & reader
, Dependencies
* dependencies
)
2541 OSL_ASSERT(dependencies
!= 0);
2542 if (reader
.getSuperTypeCount() != 0 || reader
.getMethodCount() != 0
2543 || reader
.getReferenceCount() != 0)
2545 throw CannotDumpException(
2546 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2549 rtl::OString
className(codemaker::convertString(reader
.getTypeName()));
2550 std::auto_ptr
< ClassFile
> cf(
2552 static_cast< ClassFile::AccessFlags
>(
2553 ClassFile::ACC_PUBLIC
| ClassFile::ACC_INTERFACE
2554 | ClassFile::ACC_ABSTRACT
),
2556 rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
2558 sal_uInt16 fields
= reader
.getFieldCount();
2559 for (sal_uInt16 i
= 0; i
< fields
; ++i
) {
2560 addConstant(manager
, reader
, false, i
, dependencies
, cf
.get());
2562 writeClassFile(options
, className
, *cf
.get());
2566 TypeManager
const & manager
, JavaOptions
/*TODO const*/ & options
,
2567 typereg::Reader
const & reader
, Dependencies
* dependencies
)
2569 OSL_ASSERT(dependencies
!= 0);
2570 if (reader
.getSuperTypeCount() != 0 || reader
.getMethodCount() != 0
2571 || reader
.getReferenceCount() != 0)
2573 throw CannotDumpException(
2574 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2577 rtl::OStringBuffer
buf(codemaker::convertString(reader
.getTypeName()));
2579 rtl::OString
prefix(buf
.makeStringAndClear());
2580 sal_uInt16 fields
= reader
.getFieldCount();
2581 for (sal_uInt16 i
= 0; i
< fields
; ++i
) {
2582 rtl::OString
className(
2583 prefix
+ codemaker::convertString(reader
.getFieldName(i
)));
2584 std::auto_ptr
< ClassFile
> cf(
2586 static_cast< ClassFile::AccessFlags
>(
2587 ClassFile::ACC_PUBLIC
| ClassFile::ACC_INTERFACE
2588 | ClassFile::ACC_ABSTRACT
),
2590 rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
2592 addConstant(manager
, reader
, true, i
, dependencies
, cf
.get());
2593 writeClassFile(options
, className
, *cf
.get());
2597 void addExceptionHandlers(
2598 codemaker::ExceptionTreeNode
const * node
,
2599 ClassFile::Code::Position start
, ClassFile::Code::Position end
,
2600 ClassFile::Code::Position handler
, ClassFile::Code
* code
)
2602 OSL_ASSERT(node
!= 0 && code
!= 0);
2603 if (node
->present
) {
2604 code
->addException(start
, end
, handler
, node
->name
);
2606 for (codemaker::ExceptionTreeNode::Children::const_iterator
i(
2607 node
->children
.begin());
2608 i
!= node
->children
.end(); ++i
)
2610 addExceptionHandlers(*i
, start
, end
, handler
, code
);
2615 void addConstructor(
2616 TypeManager
const & manager
, rtl::OString
const & realJavaBaseName
,
2617 rtl::OString
const & unoName
, rtl::OString
const & className
,
2618 typereg::Reader
const & reader
, sal_uInt16 methodIndex
,
2619 rtl::OString
const & methodName
, rtl::OString
const & returnType
,
2620 bool defaultConstructor
, Dependencies
* dependencies
, ClassFile
* classFile
)
2622 OSL_ASSERT(dependencies
!= 0 && classFile
!= 0);
2623 MethodDescriptor
desc(manager
, dependencies
, returnType
, 0, 0);
2626 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")),
2628 std::auto_ptr
< ClassFile::Code
> code(classFile
->newCode());
2629 code
->loadLocalReference(0);
2631 code
->instrInvokestatic(
2632 className
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("$getFactory")),
2634 RTL_CONSTASCII_STRINGPARAM(
2635 "(Lcom/sun/star/uno/XComponentContext;)"
2636 "Lcom/sun/star/lang/XMultiComponentFactory;")));
2638 code
->loadStringConstant(unoName
);
2639 // stack: factory serviceName
2640 codemaker::ExceptionTree tree
;
2641 ClassFile::Code::Position tryStart
;
2642 ClassFile::Code::Position tryEnd
;
2643 std::vector
< rtl::OString
> exc
;
2645 sal_uInt16 localIndex
= 1;
2646 ClassFile::AccessFlags access
= static_cast< ClassFile::AccessFlags
>(
2647 ClassFile::ACC_PUBLIC
| ClassFile::ACC_STATIC
);
2648 if (defaultConstructor
) {
2649 code
->loadLocalReference(0);
2650 // stack: factory serviceName context
2651 tryStart
= code
->getPosition();
2652 code
->instrInvokeinterface(
2654 RTL_CONSTASCII_STRINGPARAM(
2655 "com/sun/star/lang/XMultiComponentFactory")),
2657 RTL_CONSTASCII_STRINGPARAM(
2658 "createInstanceWithContext")),
2660 RTL_CONSTASCII_STRINGPARAM(
2661 "(Ljava/lang/String;Lcom/sun/star/uno/XComponentContext;)"
2662 "Ljava/lang/Object;")),
2664 tryEnd
= code
->getPosition();
2668 sal_uInt16 parameters
= reader
.getMethodParameterCount(methodIndex
);
2670 && (reader
.getMethodParameterFlags(methodIndex
, 0)
2671 == (RT_PARAM_IN
| RT_PARAM_REST
))
2672 && (reader
.getMethodParameterTypeName(methodIndex
, 0)
2673 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any"))))
2676 rtl::OString(RTL_CONSTASCII_STRINGPARAM("any")), true, true, 0);
2677 code
->loadLocalReference(localIndex
++);
2678 // stack: factory serviceName args
2680 access
= static_cast< ClassFile::AccessFlags
>(
2681 access
| ClassFile::ACC_VARARGS
);
2683 code
->loadIntegerConstant(parameters
);
2684 // stack: factory serviceName N
2685 code
->instrAnewarray(
2686 rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")));
2687 // stack: factory serviceName args
2689 for (sal_uInt16 i
= 0; i
< parameters
; ++i
) {
2690 RTParamMode flags
= reader
.getMethodParameterFlags(
2692 rtl::OString
paramType(
2693 codemaker::convertString(
2694 reader
.getMethodParameterTypeName(methodIndex
, i
)));
2695 if ((flags
!= RT_PARAM_IN
2696 && flags
!= (RT_PARAM_IN
| RT_PARAM_REST
))
2697 || ((flags
& RT_PARAM_REST
) != 0
2701 RTL_CONSTASCII_STRINGPARAM("any"))))))
2703 throw CannotDumpException(
2705 RTL_CONSTASCII_STRINGPARAM(
2706 "Bad type information"))); //TODO
2708 desc
.addParameter(paramType
, false, true, 0);
2710 // stack: factory serviceName args args
2711 code
->loadIntegerConstant(i
);
2712 // stack: factory serviceName args args i
2716 manager
, code
.get(), &localIndex
, false, paramType
,
2717 true, dependencies
));
2718 // stack: factory serviceName args args i any
2719 code
->instrAastore();
2720 // stack: factory serviceName args
2724 code
->loadLocalReference(0);
2725 // stack: factory serviceName args context
2726 tryStart
= code
->getPosition();
2727 code
->instrInvokeinterface(
2729 RTL_CONSTASCII_STRINGPARAM(
2730 "com/sun/star/lang/XMultiComponentFactory")),
2732 RTL_CONSTASCII_STRINGPARAM(
2733 "createInstanceWithArgumentsAndContext")),
2735 RTL_CONSTASCII_STRINGPARAM(
2736 "(Ljava/lang/String;[Ljava/lang/Object;"
2737 "Lcom/sun/star/uno/XComponentContext;)Ljava/lang/Object;")),
2739 tryEnd
= code
->getPosition();
2741 createExceptionsAttribute(
2742 manager
, reader
, methodIndex
, dependencies
, &exc
, &tree
);
2744 code
->loadLocalReference(0);
2745 // stack: instance context
2746 code
->instrInvokestatic(
2747 className
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("$castInstance")),
2749 RTL_CONSTASCII_STRINGPARAM(
2750 "(Ljava/lang/Object;Lcom/sun/star/uno/XComponentContext;)"
2751 "Ljava/lang/Object;")));
2753 code
->instrCheckcast(returnType
);
2755 code
->instrAreturn();
2756 if (!tree
.getRoot()->present
) {
2757 ClassFile::Code::Position pos1
= code
->getPosition();
2759 code
->instrInvokevirtual(
2760 rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Throwable")),
2761 rtl::OString(RTL_CONSTASCII_STRINGPARAM("toString")),
2762 rtl::OString(RTL_CONSTASCII_STRINGPARAM("()Ljava/lang/String;")));
2764 localIndex
= std::max
< sal_uInt16
>(localIndex
, 2);
2765 code
->storeLocalReference(1);
2769 RTL_CONSTASCII_STRINGPARAM(
2770 "com/sun/star/uno/DeploymentException")));
2774 rtl::OStringBuffer msg
;
2776 RTL_CONSTASCII_STRINGPARAM(
2777 "component context fails to supply service "));
2778 msg
.append(unoName
);
2779 msg
.append(RTL_CONSTASCII_STRINGPARAM(" of type "));
2780 msg
.append(realJavaBaseName
);
2781 msg
.append(RTL_CONSTASCII_STRINGPARAM(": "));
2782 code
->loadStringConstant(msg
.makeStringAndClear());
2783 // stack: ex ex "..."
2784 code
->loadLocalReference(1);
2785 // stack: ex ex "..." str
2786 code
->instrInvokevirtual(
2787 rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/String")),
2788 rtl::OString(RTL_CONSTASCII_STRINGPARAM("concat")),
2790 RTL_CONSTASCII_STRINGPARAM(
2791 "(Ljava/lang/String;)Ljava/lang/String;")));
2792 // stack: ex ex "..."
2793 code
->loadLocalReference(0);
2794 // stack: ex ex "..." context
2795 code
->instrInvokespecial(
2797 RTL_CONSTASCII_STRINGPARAM(
2798 "com/sun/star/uno/DeploymentException")),
2799 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2801 RTL_CONSTASCII_STRINGPARAM(
2802 "(Ljava/lang/String;Ljava/lang/Object;)V")));
2804 ClassFile::Code::Position pos2
= code
->getPosition();
2805 code
->instrAthrow();
2806 addExceptionHandlers(
2807 tree
.getRoot(), tryStart
, tryEnd
, pos2
, code
.get());
2809 tryStart
, tryEnd
, pos1
,
2811 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Exception")));
2812 dependencies
->insert(
2814 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Exception")));
2815 stack
= std::max
< sal_uInt16
>(stack
, 4);
2817 code
->setMaxStackAndLocals(stack
, localIndex
);
2818 classFile
->addMethod(
2819 access
, methodName
, desc
.getDescriptor(), code
.get(), exc
,
2820 desc
.getSignature());
2824 TypeManager
const & manager
, JavaOptions
/*TODO const*/ & options
,
2825 typereg::Reader
const & reader
, Dependencies
* dependencies
)
2827 OSL_ASSERT(dependencies
!= 0);
2828 sal_uInt16 superTypes
= reader
.getSuperTypeCount();
2829 sal_uInt16 methods
= reader
.getMethodCount();
2832 : (superTypes
!= 1 || reader
.getFieldCount() != 0
2833 || reader
.getReferenceCount() != 0))
2835 throw CannotDumpException(
2836 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2839 if (superTypes
== 0) {
2842 rtl::OString
unoName(codemaker::convertString(reader
.getTypeName()));
2843 rtl::OString
className(
2844 translateUnoTypeToJavaFullyQualifiedName(
2845 unoName
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("service"))));
2846 unoName
= unoName
.replace('/', '.');
2847 std::auto_ptr
< ClassFile
> cf(
2849 static_cast< ClassFile::AccessFlags
>(
2850 ClassFile::ACC_PUBLIC
| ClassFile::ACC_FINAL
2851 | ClassFile::ACC_SUPER
),
2853 rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
2856 rtl::OString
base(codemaker::convertString(
2857 reader
.getSuperTypeName(0)));
2858 rtl::OString
realJavaBaseName(base
.replace('/', '.'));
2859 dependencies
->insert(base
);
2860 dependencies
->insert(
2862 RTL_CONSTASCII_STRINGPARAM(
2863 "com/sun/star/lang/XMultiComponentFactory")));
2864 dependencies
->insert(
2866 RTL_CONSTASCII_STRINGPARAM(
2867 "com/sun/star/uno/DeploymentException")));
2868 dependencies
->insert(
2870 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")));
2871 dependencies
->insert(
2873 RTL_CONSTASCII_STRINGPARAM(
2874 "com/sun/star/uno/XComponentContext")));
2875 for (sal_uInt16 i
= 0; i
< methods
; ++i
) {
2876 rtl::OString
name(codemaker::convertString(
2877 reader
.getMethodName(i
)));
2878 bool defaultCtor
= name
.getLength() == 0;
2879 if (reader
.getMethodFlags(i
) != RT_MODE_TWOWAY
2880 || (!reader
.getMethodReturnTypeName(i
).equalsAsciiL(
2881 RTL_CONSTASCII_STRINGPARAM("void")))
2883 && (methods
!= 1 || reader
.getMethodParameterCount(i
) != 0
2884 || reader
.getMethodExceptionCount(i
) != 0)))
2886 throw CannotDumpException(
2888 RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2892 name
= rtl::OString(RTL_CONSTASCII_STRINGPARAM("create"));
2894 name
= codemaker::java::translateUnoToJavaIdentifier(
2895 name
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("method")));
2898 manager
, realJavaBaseName
, unoName
, className
, reader
, i
, name
,
2899 base
, defaultCtor
, dependencies
, cf
.get());
2901 // Synthetic getFactory method:
2903 std::auto_ptr
< ClassFile::Code
> code(cf
->newCode());
2904 code
->loadLocalReference(0);
2906 code
->instrInvokeinterface(
2908 RTL_CONSTASCII_STRINGPARAM(
2909 "com/sun/star/uno/XComponentContext")),
2910 rtl::OString(RTL_CONSTASCII_STRINGPARAM("getServiceManager")),
2912 RTL_CONSTASCII_STRINGPARAM(
2913 "()Lcom/sun/star/lang/XMultiComponentFactory;")),
2917 // stack: factory factory
2918 ClassFile::Code::Branch branch
= code
->instrIfnull();
2920 code
->instrAreturn();
2921 code
->branchHere(branch
);
2926 RTL_CONSTASCII_STRINGPARAM(
2927 "com/sun/star/uno/DeploymentException")));
2931 code
->loadStringConstant(
2933 RTL_CONSTASCII_STRINGPARAM(
2934 "component context fails to supply service manager")));
2935 // stack: ex ex "..."
2936 code
->loadLocalReference(0);
2937 // stack: ex ex "..." context
2938 code
->instrInvokespecial(
2940 RTL_CONSTASCII_STRINGPARAM(
2941 "com/sun/star/uno/DeploymentException")),
2942 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2944 RTL_CONSTASCII_STRINGPARAM(
2945 "(Ljava/lang/String;Ljava/lang/Object;)V")));
2947 code
->instrAthrow();
2948 code
->setMaxStackAndLocals(4, 1);
2950 static_cast< ClassFile::AccessFlags
>(
2951 ClassFile::ACC_PRIVATE
| ClassFile::ACC_STATIC
2952 | ClassFile::ACC_SYNTHETIC
),
2953 rtl::OString(RTL_CONSTASCII_STRINGPARAM("$getFactory")),
2955 RTL_CONSTASCII_STRINGPARAM(
2956 "(Lcom/sun/star/uno/XComponentContext;)"
2957 "Lcom/sun/star/lang/XMultiComponentFactory;")),
2958 code
.get(), std::vector
< rtl::OString
>(), rtl::OString());
2960 // Synthetic castInstance method:
2962 std::auto_ptr
< ClassFile::Code
> code(cf
->newCode());
2965 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")));
2969 code
->loadStringConstant(realJavaBaseName
);
2970 // stack: type type "..."
2971 code
->instrGetstatic(
2973 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
2974 rtl::OString(RTL_CONSTASCII_STRINGPARAM("INTERFACE")),
2976 RTL_CONSTASCII_STRINGPARAM(
2977 "Lcom/sun/star/uno/TypeClass;")));
2978 // stack: type type "..." INTERFACE
2979 code
->instrInvokespecial(
2981 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
2982 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2984 RTL_CONSTASCII_STRINGPARAM(
2985 "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V")));
2987 code
->loadLocalReference(0);
2988 // stack: type instance
2989 code
->instrInvokestatic(
2991 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/UnoRuntime")),
2992 rtl::OString(RTL_CONSTASCII_STRINGPARAM("queryInterface")),
2994 RTL_CONSTASCII_STRINGPARAM(
2995 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
2996 "Ljava/lang/Object;")));
2999 // stack: instance instance
3000 ClassFile::Code::Branch branch
= code
->instrIfnull();
3002 code
->instrAreturn();
3003 code
->branchHere(branch
);
3008 RTL_CONSTASCII_STRINGPARAM(
3009 "com/sun/star/uno/DeploymentException")));
3013 rtl::OStringBuffer msg
;
3015 RTL_CONSTASCII_STRINGPARAM(
3016 "component context fails to supply service "));
3017 msg
.append(unoName
);
3018 msg
.append(RTL_CONSTASCII_STRINGPARAM(" of type "));
3019 msg
.append(realJavaBaseName
);
3020 code
->loadStringConstant(msg
.makeStringAndClear());
3021 // stack: ex ex "..."
3022 code
->loadLocalReference(1);
3023 // stack: ex ex "..." context
3024 code
->instrInvokespecial(
3026 RTL_CONSTASCII_STRINGPARAM(
3027 "com/sun/star/uno/DeploymentException")),
3028 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
3030 RTL_CONSTASCII_STRINGPARAM(
3031 "(Ljava/lang/String;Ljava/lang/Object;)V")));
3033 code
->instrAthrow();
3034 code
->setMaxStackAndLocals(4, 2);
3036 static_cast< ClassFile::AccessFlags
>(
3037 ClassFile::ACC_PRIVATE
| ClassFile::ACC_STATIC
3038 | ClassFile::ACC_SYNTHETIC
),
3039 rtl::OString(RTL_CONSTASCII_STRINGPARAM("$castInstance")),
3041 RTL_CONSTASCII_STRINGPARAM(
3042 "(Ljava/lang/Object;Lcom/sun/star/uno/"
3043 "XComponentContext;)Ljava/lang/Object;")),
3044 code
.get(), std::vector
< rtl::OString
>(), rtl::OString());
3047 writeClassFile(options
, className
, *cf
.get());
3050 void handleSingleton(
3051 TypeManager
const & manager
, JavaOptions
/*TODO const*/ & options
,
3052 typereg::Reader
const & reader
, Dependencies
* dependencies
)
3054 OSL_ASSERT(dependencies
!= 0);
3055 if (reader
.getSuperTypeCount() != 1 || reader
.getFieldCount() != 0
3056 || reader
.getMethodCount() != 0 || reader
.getReferenceCount() != 0)
3058 throw CannotDumpException(
3059 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
3062 rtl::OString
base(codemaker::convertString(reader
.getSuperTypeName(0)));
3063 rtl::OString
realJavaBaseName(base
.replace('/', '.'));
3064 switch (manager
.getTypeReader(base
).getTypeClass()) {
3065 case RT_TYPE_INTERFACE
:
3068 case RT_TYPE_SERVICE
:
3072 throw CannotDumpException(
3073 rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
3076 dependencies
->insert(base
);
3077 rtl::OString
unoName(codemaker::convertString(reader
.getTypeName()));
3078 rtl::OString
className(
3079 translateUnoTypeToJavaFullyQualifiedName(
3080 unoName
, rtl::OString(RTL_CONSTASCII_STRINGPARAM("singleton"))));
3081 unoName
= unoName
.replace('/', '.');
3082 dependencies
->insert(
3084 RTL_CONSTASCII_STRINGPARAM(
3085 "com/sun/star/uno/DeploymentException")));
3086 dependencies
->insert(
3087 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")));
3088 dependencies
->insert(
3090 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")));
3091 std::auto_ptr
< ClassFile
> cf(
3093 static_cast< ClassFile::AccessFlags
>(
3094 ClassFile::ACC_PUBLIC
| ClassFile::ACC_FINAL
3095 | ClassFile::ACC_SUPER
),
3097 rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
3099 MethodDescriptor
desc(manager
, dependencies
, base
, 0, 0);
3102 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")),
3104 std::auto_ptr
< ClassFile::Code
> code(cf
->newCode());
3105 code
->loadLocalReference(0);
3107 code
->loadStringConstant(
3108 rtl::OString(RTL_CONSTASCII_STRINGPARAM("/singletons/")) + unoName
);
3109 // stack: context "..."
3110 code
->instrInvokeinterface(
3112 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")),
3113 rtl::OString(RTL_CONSTASCII_STRINGPARAM("getValueByName")),
3115 RTL_CONSTASCII_STRINGPARAM(
3116 "(Ljava/lang/String;)Ljava/lang/Object;")),
3120 // stack: value value
3121 code
->instrInstanceof(
3122 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")));
3124 ClassFile::Code::Branch branch1
= code
->instrIfeq();
3126 code
->instrCheckcast(
3127 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")));
3130 // stack: value value
3131 code
->instrInvokevirtual(
3132 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
3133 rtl::OString(RTL_CONSTASCII_STRINGPARAM("getType")),
3134 rtl::OString(RTL_CONSTASCII_STRINGPARAM("()Lcom/sun/star/uno/Type;")));
3135 // stack: value type
3136 code
->instrInvokevirtual(
3137 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
3138 rtl::OString(RTL_CONSTASCII_STRINGPARAM("getTypeClass")),
3140 RTL_CONSTASCII_STRINGPARAM("()Lcom/sun/star/uno/TypeClass;")));
3141 // stack: value typeClass
3142 code
->instrGetstatic(
3143 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
3144 rtl::OString(RTL_CONSTASCII_STRINGPARAM("INTERFACE")),
3146 RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/TypeClass;")));
3147 // stack: value typeClass INTERFACE
3148 ClassFile::Code::Branch branch2
= code
->instrIfAcmpne();
3150 code
->instrInvokevirtual(
3151 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
3152 rtl::OString(RTL_CONSTASCII_STRINGPARAM("getObject")),
3153 rtl::OString(RTL_CONSTASCII_STRINGPARAM("()Ljava/lang/Object;")));
3155 code
->branchHere(branch1
);
3157 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")));
3158 // stack: value type
3160 // stack: value type type
3161 code
->loadStringConstant(realJavaBaseName
);
3162 // stack: value type type "..."
3163 code
->instrGetstatic(
3164 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
3165 rtl::OString(RTL_CONSTASCII_STRINGPARAM("INTERFACE")),
3167 RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/TypeClass;")));
3168 // stack: value type type "..." INTERFACE
3169 code
->instrInvokespecial(
3170 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
3171 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
3173 RTL_CONSTASCII_STRINGPARAM(
3174 "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V")));
3175 // stack: value type
3177 // stack: type value
3178 code
->instrInvokestatic(
3179 rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/UnoRuntime")),
3180 rtl::OString(RTL_CONSTASCII_STRINGPARAM("queryInterface")),
3182 RTL_CONSTASCII_STRINGPARAM(
3183 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
3184 "Ljava/lang/Object;")));
3187 // stack: instance instance
3188 ClassFile::Code::Branch branch3
= code
->instrIfnull();
3190 code
->instrCheckcast(base
);
3192 code
->instrAreturn();
3193 code
->branchHere(branch2
);
3194 code
->branchHere(branch3
);
3199 RTL_CONSTASCII_STRINGPARAM(
3200 "com/sun/star/uno/DeploymentException")));
3204 rtl::OStringBuffer msg
;
3206 RTL_CONSTASCII_STRINGPARAM(
3207 "component context fails to supply singleton "));
3208 msg
.append(unoName
);
3209 msg
.append(RTL_CONSTASCII_STRINGPARAM(" of type "));
3210 msg
.append(realJavaBaseName
);
3211 code
->loadStringConstant(msg
.makeStringAndClear());
3212 // stack: ex ex "..."
3213 code
->loadLocalReference(0);
3214 // stack: ex ex "..." context
3215 code
->instrInvokespecial(
3217 RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/DeploymentException")),
3218 rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
3220 RTL_CONSTASCII_STRINGPARAM(
3221 "(Ljava/lang/String;Ljava/lang/Object;)V")));
3223 code
->instrAthrow();
3224 code
->setMaxStackAndLocals(5, 1);
3226 static_cast< ClassFile::AccessFlags
>(
3227 ClassFile::ACC_PUBLIC
| ClassFile::ACC_STATIC
),
3228 rtl::OString(RTL_CONSTASCII_STRINGPARAM("get")), desc
.getDescriptor(),
3229 code
.get(), std::vector
< rtl::OString
>(), desc
.getSignature());
3230 writeClassFile(options
, className
, *cf
.get());
3236 rtl::OString
const & type
, TypeManager
const & manager
,
3237 codemaker::GeneratedTypeSet
& generated
, JavaOptions
* options
)
3239 OSL_ASSERT(options
!= 0);
3240 if (type
.equals("/")
3241 || type
.equals(manager
.getBase())
3242 || generated
.contains(type
))
3246 sal_Bool extra
= sal_False
;
3247 typereg::Reader
reader(manager
.getTypeReader(type
, &extra
));
3249 generated
.add(type
);
3252 if (!reader
.isValid()) {
3256 handleUnoTypeRegistryEntityFunction handler
;
3257 switch (reader
.getTypeClass()) {
3259 handler
= handleEnumType
;
3262 case RT_TYPE_STRUCT
:
3263 case RT_TYPE_EXCEPTION
:
3264 handler
= handleAggregatingType
;
3267 case RT_TYPE_INTERFACE
:
3268 handler
= handleInterfaceType
;
3271 case RT_TYPE_TYPEDEF
:
3272 handler
= handleTypedef
;
3275 case RT_TYPE_CONSTANTS
:
3276 handler
= handleConstantGroup
;
3279 case RT_TYPE_MODULE
:
3280 handler
= handleModule
;
3283 case RT_TYPE_SERVICE
:
3284 handler
= handleService
;
3287 case RT_TYPE_SINGLETON
:
3288 handler
= handleSingleton
;
3295 handler(manager
, *options
, reader
, &deps
);
3296 generated
.add(type
);
3297 if (!options
->isValid(rtl::OString(RTL_CONSTASCII_STRINGPARAM("-nD")))) {
3298 for (Dependencies::iterator
i(deps
.begin()); i
!= deps
.end(); ++i
) {
3299 if (!produceType(*i
, manager
, generated
, options
)) {
3308 RegistryKey
& rTypeKey
, bool bIsExtraType
, TypeManager
const & manager
,
3309 codemaker::GeneratedTypeSet
& generated
, JavaOptions
* options
)
3311 ::rtl::OString typeName
= manager
.getTypeName(rTypeKey
);
3313 OSL_ASSERT(options
!= 0);
3314 if (typeName
.equals("/")
3315 || typeName
.equals(manager
.getBase())
3316 || generated
.contains(typeName
))
3320 typereg::Reader
reader(manager
.getTypeReader(rTypeKey
));
3322 generated
.add(typeName
);
3325 if (!reader
.isValid()) {
3328 handleUnoTypeRegistryEntityFunction handler
;
3329 switch (reader
.getTypeClass()) {
3331 handler
= handleEnumType
;
3334 case RT_TYPE_STRUCT
:
3335 case RT_TYPE_EXCEPTION
:
3336 handler
= handleAggregatingType
;
3339 case RT_TYPE_INTERFACE
:
3340 handler
= handleInterfaceType
;
3343 case RT_TYPE_TYPEDEF
:
3344 handler
= handleTypedef
;
3347 case RT_TYPE_CONSTANTS
:
3348 handler
= handleConstantGroup
;
3351 case RT_TYPE_MODULE
:
3352 handler
= handleModule
;
3355 case RT_TYPE_SERVICE
:
3356 handler
= handleService
;
3359 case RT_TYPE_SINGLETON
:
3360 handler
= handleSingleton
;
3367 handler(manager
, *options
, reader
, &deps
);
3368 generated
.add(typeName
);
3369 if (!options
->isValid(rtl::OString(RTL_CONSTASCII_STRINGPARAM("-nD")))) {
3370 for (Dependencies::iterator
i(deps
.begin()); i
!= deps
.end(); ++i
) {
3371 if (!produceType(*i
, manager
, generated
, options
)) {