Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "javatype.hxx"
22 :
23 : #include "classfile.hxx"
24 : #include "javaoptions.hxx"
25 :
26 : #include "codemaker/exceptiontree.hxx"
27 : #include "codemaker/generatedtypeset.hxx"
28 : #include "codemaker/global.hxx"
29 : #include "codemaker/options.hxx"
30 : #include "codemaker/typemanager.hxx"
31 : #include "codemaker/unotype.hxx"
32 : #include "codemaker/commonjava.hxx"
33 :
34 : #include "osl/diagnose.h"
35 : #include "registry/reader.hxx"
36 : #include "registry/refltype.hxx"
37 : #include "registry/types.h"
38 : #include "rtl/strbuf.hxx"
39 : #include "rtl/string.h"
40 : #include "rtl/string.hxx"
41 : #include "rtl/textcvt.h"
42 : #include "rtl/textenc.h"
43 : #include "rtl/ustring.h"
44 : #include "rtl/ustring.hxx"
45 : #include "sal/types.h"
46 :
47 : #include <algorithm>
48 : #include <list>
49 : #include <map>
50 : #include <memory>
51 : #include <set>
52 : #include <utility>
53 : #include <vector>
54 :
55 : using codemaker::javamaker::ClassFile;
56 :
57 : namespace {
58 :
59 : // helper function for createUnoName
60 0 : void appendUnoName(
61 : TypeManager const & manager, rtl::OString const & nucleus, sal_Int32 rank,
62 : std::vector< rtl::OString > const & arguments, rtl::OStringBuffer * buffer)
63 : {
64 : OSL_ASSERT(rank >= 0 && buffer != 0);
65 0 : for (sal_Int32 i = 0; i < rank; ++i) {
66 0 : buffer->append(RTL_CONSTASCII_STRINGPARAM("[]"));
67 : }
68 0 : buffer->append(nucleus.replace('/', '.'));
69 0 : if (!arguments.empty()) {
70 0 : buffer->append('<');
71 0 : for (std::vector< rtl::OString >::const_iterator i(arguments.begin());
72 0 : i != arguments.end(); ++i)
73 : {
74 0 : if (i != arguments.begin()) {
75 0 : buffer->append(',');
76 : }
77 : RTTypeClass argTypeClass;
78 0 : rtl::OString argNucleus;
79 : sal_Int32 argRank;
80 0 : std::vector< rtl::OString > argArgs;
81 : codemaker::decomposeAndResolve(
82 0 : manager, *i, true, false, false, &argTypeClass, &argNucleus,
83 0 : &argRank, &argArgs);
84 0 : appendUnoName(manager, argNucleus, argRank, argArgs, buffer);
85 0 : }
86 0 : buffer->append('>');
87 : }
88 0 : }
89 :
90 : // Translate the name of a UNO type registry entity (enum type, plain struct
91 : // type, polymorphic struct type template, or interface type, decomposed into
92 : // nucleus, rank, and arguments) into a core UNO type name:
93 0 : rtl::OString createUnoName(
94 : TypeManager const & manager, rtl::OString const & nucleus, sal_Int32 rank,
95 : std::vector< rtl::OString > const & arguments)
96 : {
97 0 : rtl::OStringBuffer buf;
98 0 : appendUnoName(manager, nucleus, rank, arguments, &buf);
99 0 : return buf.makeStringAndClear();
100 : }
101 :
102 : /**
103 : Set of UTF-8--encoded names of UNO type registry entities a given UNO type
104 : registry entity depends on.
105 :
106 : UNO type registry entities are enum types, plain struct types, polymorphic
107 : struct type templates, exception types, interface types, typedefs, modules,
108 : constant groupds, single-interface--based services, accumulation-based
109 : services, interface-based singletons, and service-based singletons.
110 : */
111 : typedef std::set< rtl::OString > Dependencies;
112 :
113 : enum SpecialType {
114 : SPECIAL_TYPE_NONE,
115 : SPECIAL_TYPE_ANY,
116 : SPECIAL_TYPE_UNSIGNED,
117 : SPECIAL_TYPE_INTERFACE
118 : };
119 :
120 0 : bool isSpecialType(SpecialType special) {
121 0 : return special >= SPECIAL_TYPE_UNSIGNED;
122 : }
123 :
124 0 : rtl::OString translateUnoTypeToJavaFullyQualifiedName(
125 : rtl::OString const & type, rtl::OString const & prefix)
126 : {
127 0 : sal_Int32 i = type.lastIndexOf('/') + 1;
128 : return type.copy(0, i) +
129 0 : codemaker::java::translateUnoToJavaIdentifier(type.copy(i), prefix);
130 : }
131 :
132 0 : struct PolymorphicUnoType {
133 0 : PolymorphicUnoType(): kind(KIND_NONE) {}
134 :
135 : enum Kind { KIND_NONE, KIND_STRUCT, KIND_SEQUENCE };
136 : Kind kind;
137 : rtl::OString name;
138 : };
139 :
140 : SpecialType translateUnoTypeToDescriptor(
141 : TypeManager const & manager, rtl::OString const & type, bool array,
142 : bool classType, Dependencies * dependencies,
143 : rtl::OStringBuffer * descriptor, rtl::OStringBuffer * signature,
144 : bool * needsSignature, PolymorphicUnoType * polymorphicUnoType);
145 :
146 0 : SpecialType translateUnoTypeToDescriptor(
147 : TypeManager const & manager, codemaker::UnoType::Sort sort,
148 : RTTypeClass typeClass, rtl::OString const & nucleus, sal_Int32 rank,
149 : std::vector< rtl::OString > const & arguments, bool array, bool classType,
150 : Dependencies * dependencies, rtl::OStringBuffer * descriptor,
151 : rtl::OStringBuffer * signature, bool * needsSignature,
152 : PolymorphicUnoType * polymorphicUnoType)
153 : {
154 : OSL_ASSERT(rank >= 0 && (signature == 0) == (needsSignature == 0));
155 0 : if (rank > 0xFF - (array ? 1 : 0)) {
156 : throw CannotDumpException(
157 : rtl::OString(
158 : RTL_CONSTASCII_STRINGPARAM(
159 0 : "Too many array dimensions for Java class file format")));
160 : }
161 0 : if (array) {
162 0 : ++rank;
163 : }
164 0 : for (sal_Int32 i = 0; i < rank; ++i) {
165 0 : if (descriptor != 0) {
166 0 : descriptor->append('[');
167 : }
168 0 : if (signature != 0) {
169 0 : signature->append('[');
170 : }
171 : }
172 0 : if (sort == codemaker::UnoType::SORT_COMPLEX) {
173 : //TODO: check that nucleus is a valid (Java-modified UTF-8) identifier
174 0 : if (typeClass == RT_TYPE_INTERFACE
175 : && (nucleus
176 : == rtl::OString(
177 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XInterface"))))
178 : {
179 0 : if (descriptor != 0) {
180 : descriptor->append(
181 : rtl::OString(
182 0 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;")));
183 : }
184 0 : if (signature != 0) {
185 : signature->append(
186 : rtl::OString(
187 0 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;")));
188 : }
189 0 : if (polymorphicUnoType != 0) {
190 0 : polymorphicUnoType->kind = PolymorphicUnoType::KIND_NONE;
191 : }
192 0 : return SPECIAL_TYPE_INTERFACE;
193 : } else {
194 0 : if (dependencies != 0) {
195 0 : dependencies->insert(nucleus);
196 : }
197 0 : if (descriptor != 0) {
198 0 : descriptor->append('L');
199 0 : descriptor->append(nucleus);
200 0 : descriptor->append(';');
201 : }
202 0 : if (signature != 0) {
203 0 : signature->append('L');
204 0 : signature->append(nucleus);
205 0 : if (!arguments.empty()) {
206 0 : signature->append('<');
207 0 : for (std::vector< rtl::OString >::const_iterator i(
208 0 : arguments.begin());
209 0 : i != arguments.end(); ++i)
210 : {
211 : translateUnoTypeToDescriptor(
212 0 : manager, *i, false, true, dependencies, 0,
213 0 : signature, needsSignature, 0);
214 : }
215 0 : signature->append('>');
216 0 : *needsSignature = true;
217 : }
218 0 : signature->append(';');
219 : }
220 0 : if (polymorphicUnoType != 0) {
221 0 : if (arguments.empty()) {
222 0 : polymorphicUnoType->kind = PolymorphicUnoType::KIND_NONE;
223 : } else {
224 : polymorphicUnoType->kind = rank == 0
225 : ? PolymorphicUnoType::KIND_STRUCT
226 0 : : PolymorphicUnoType::KIND_SEQUENCE;
227 : polymorphicUnoType->name = createUnoName(
228 0 : manager, nucleus, rank, arguments);
229 : }
230 : }
231 0 : return SPECIAL_TYPE_NONE;
232 : }
233 : } else {
234 : static rtl::OString const
235 : simpleTypeDescriptors[codemaker::UnoType::SORT_ANY + 1][2] = {
236 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("V")),
237 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Void;"))
238 : },
239 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("Z")),
240 : rtl::OString(
241 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Boolean;"))
242 : },
243 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("B")),
244 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Byte;"))
245 : },
246 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("S")),
247 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Short;"))
248 : },
249 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("S")),
250 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Short;"))
251 : },
252 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("I")),
253 : rtl::OString(
254 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Integer;"))
255 : },
256 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("I")),
257 : rtl::OString(
258 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Integer;"))
259 : },
260 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("J")),
261 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Long;"))
262 : },
263 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("J")),
264 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Long;"))
265 : },
266 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("F")),
267 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Float;"))
268 : },
269 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("D")),
270 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Double;"))
271 : },
272 : { rtl::OString(RTL_CONSTASCII_STRINGPARAM("C")),
273 : rtl::OString(
274 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Character;"))
275 : },
276 : { rtl::OString(
277 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/String;")),
278 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/String;"))
279 : },
280 : { rtl::OString(
281 : RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Type;")),
282 : rtl::OString(
283 : RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Type;"))
284 : },
285 : { rtl::OString(
286 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;")),
287 : rtl::OString(
288 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;"))
289 0 : } };
290 : rtl::OString const & s
291 0 : = simpleTypeDescriptors[sort][rank == 0 && classType];
292 0 : if (descriptor != 0) {
293 0 : descriptor->append(s);
294 : }
295 0 : if (signature != 0) {
296 0 : signature->append(s);
297 : }
298 0 : if (polymorphicUnoType != 0) {
299 0 : polymorphicUnoType->kind = PolymorphicUnoType::KIND_NONE;
300 : }
301 : static SpecialType const
302 : simpleTypeSpecials[codemaker::UnoType::SORT_ANY + 1] = {
303 : SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE,
304 : SPECIAL_TYPE_NONE, SPECIAL_TYPE_UNSIGNED, SPECIAL_TYPE_NONE,
305 : SPECIAL_TYPE_UNSIGNED, SPECIAL_TYPE_NONE, SPECIAL_TYPE_UNSIGNED,
306 : SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE,
307 : SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE, SPECIAL_TYPE_ANY };
308 0 : return simpleTypeSpecials[sort];
309 : }
310 : }
311 :
312 0 : SpecialType translateUnoTypeToDescriptor(
313 : TypeManager const & manager, rtl::OString const & type, bool array,
314 : bool classType, Dependencies * dependencies,
315 : rtl::OStringBuffer * descriptor, rtl::OStringBuffer * signature,
316 : bool * needsSignature, PolymorphicUnoType * polymorphicUnoType)
317 : {
318 : RTTypeClass typeClass;
319 0 : rtl::OString nucleus;
320 : sal_Int32 rank;
321 0 : std::vector< rtl::OString > args;
322 : codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve(
323 0 : manager, type, true, true, false, &typeClass, &nucleus, &rank, &args);
324 : OSL_ASSERT(rank < SAL_MAX_INT32);
325 : return translateUnoTypeToDescriptor(
326 : manager, sort, typeClass, nucleus, rank, args, array, classType,
327 : dependencies, descriptor, signature, needsSignature,
328 0 : polymorphicUnoType);
329 : }
330 :
331 0 : SpecialType getFieldDescriptor(
332 : TypeManager const & manager, Dependencies * dependencies,
333 : rtl::OString const & type, rtl::OString * descriptor,
334 : rtl::OString * signature, PolymorphicUnoType * polymorphicUnoType)
335 : {
336 : OSL_ASSERT(dependencies != 0 && descriptor != 0);
337 0 : rtl::OStringBuffer desc;
338 0 : rtl::OStringBuffer sig;
339 0 : bool needsSig = false;
340 : SpecialType specialType = translateUnoTypeToDescriptor(
341 : manager, type, false, false, dependencies, &desc, &sig, &needsSig,
342 0 : polymorphicUnoType);
343 0 : *descriptor = desc.makeStringAndClear();
344 0 : if (signature != 0) {
345 0 : if (needsSig) {
346 0 : *signature = sig.makeStringAndClear();
347 : } else {
348 0 : *signature = rtl::OString();
349 : }
350 : }
351 0 : return specialType;
352 : }
353 :
354 0 : class MethodDescriptor {
355 : public:
356 : MethodDescriptor(
357 : TypeManager const & manager, Dependencies * dependencies,
358 : rtl::OString const & returnType, SpecialType * specialReturnType,
359 : PolymorphicUnoType * polymorphicUnoType);
360 :
361 : SpecialType addParameter(
362 : rtl::OString const & type, bool array, bool dependency,
363 : PolymorphicUnoType * polymorphicUnoType);
364 :
365 : void addTypeParameter(rtl::OString const & name);
366 :
367 : rtl::OString getDescriptor() const;
368 :
369 : rtl::OString getSignature() const;
370 :
371 : private:
372 : TypeManager const & m_manager;
373 : Dependencies * m_dependencies;
374 : rtl::OStringBuffer m_descriptorStart;
375 : rtl::OString m_descriptorEnd;
376 : rtl::OStringBuffer m_signatureStart;
377 : rtl::OString m_signatureEnd;
378 : bool m_needsSignature;
379 : };
380 :
381 0 : MethodDescriptor::MethodDescriptor(
382 : TypeManager const & manager, Dependencies * dependencies,
383 : rtl::OString const & returnType, SpecialType * specialReturnType,
384 : PolymorphicUnoType * polymorphicUnoType):
385 0 : m_manager(manager), m_dependencies(dependencies), m_needsSignature(false)
386 : {
387 : OSL_ASSERT(dependencies != 0);
388 0 : m_descriptorStart.append('(');
389 0 : m_signatureStart.append('(');
390 0 : rtl::OStringBuffer descEnd;
391 0 : descEnd.append(')');
392 0 : rtl::OStringBuffer sigEnd;
393 0 : sigEnd.append(')');
394 : SpecialType special = translateUnoTypeToDescriptor(
395 : m_manager, returnType, false, false, m_dependencies, &descEnd, &sigEnd,
396 0 : &m_needsSignature, polymorphicUnoType);
397 0 : m_descriptorEnd = descEnd.makeStringAndClear();
398 0 : m_signatureEnd = sigEnd.makeStringAndClear();
399 0 : if (specialReturnType != 0) {
400 0 : *specialReturnType = special;
401 0 : }
402 0 : }
403 :
404 0 : SpecialType MethodDescriptor::addParameter(
405 : rtl::OString const & type, bool array, bool dependency,
406 : PolymorphicUnoType * polymorphicUnoType)
407 : {
408 : return translateUnoTypeToDescriptor(
409 : m_manager, type, array, false, dependency ? m_dependencies : 0,
410 : &m_descriptorStart, &m_signatureStart, &m_needsSignature,
411 0 : polymorphicUnoType);
412 : }
413 :
414 0 : void MethodDescriptor::addTypeParameter(rtl::OString const & name) {
415 0 : m_descriptorStart.append(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;"));
416 0 : m_signatureStart.append('T');
417 0 : m_signatureStart.append(name);
418 0 : m_signatureStart.append(';');
419 0 : m_needsSignature = true;
420 0 : }
421 :
422 0 : rtl::OString MethodDescriptor::getDescriptor() const {
423 0 : rtl::OStringBuffer buf(m_descriptorStart);
424 0 : buf.append(m_descriptorEnd);
425 0 : return buf.makeStringAndClear();
426 : }
427 :
428 0 : rtl::OString MethodDescriptor::getSignature() const {
429 0 : if (m_needsSignature) {
430 0 : rtl::OStringBuffer buf(m_signatureStart);
431 0 : buf.append(m_signatureEnd);
432 0 : return buf.makeStringAndClear();
433 : } else {
434 0 : return rtl::OString();
435 : }
436 : }
437 :
438 0 : class TypeInfo {
439 : public:
440 : enum Kind { KIND_MEMBER, KIND_ATTRIBUTE, KIND_METHOD, KIND_PARAMETER };
441 :
442 : // Same values as in com/sun/star/lib/uno/typeinfo/TypeInfo.java:
443 : enum Flags {
444 : FLAG_READONLY = 0x008, FLAG_BOUND = 0x100, FLAG_ONEWAY = 0x010
445 : };
446 :
447 : // KIND_MEMBER:
448 : TypeInfo(
449 : rtl::OString const & name, SpecialType specialType, sal_Int32 index,
450 : PolymorphicUnoType const & polymorphicUnoType,
451 : sal_Int32 typeParameterIndex);
452 :
453 : // KIND_ATTRIBUTE/METHOD:
454 : TypeInfo(
455 : Kind kind, rtl::OString const & name, SpecialType specialType,
456 : Flags flags, sal_Int32 index,
457 : PolymorphicUnoType const & polymorphicUnoType);
458 :
459 : // KIND_PARAMETER:
460 : TypeInfo(
461 : rtl::OString const & parameterName, SpecialType specialType,
462 : bool inParameter, bool outParameter, rtl::OString const & methodName,
463 : sal_Int32 index, PolymorphicUnoType const & polymorphicUnoType);
464 :
465 : sal_uInt16 generateCode(ClassFile::Code & code, Dependencies * dependencies)
466 : const;
467 :
468 : void generatePolymorphicUnoTypeCode(
469 : ClassFile::Code & code, Dependencies * dependencies) const;
470 :
471 : private:
472 : Kind m_kind;
473 : rtl::OString m_name;
474 : sal_Int32 m_flags;
475 : sal_Int32 m_index;
476 : rtl::OString m_methodName;
477 : PolymorphicUnoType m_polymorphicUnoType;
478 : sal_Int32 m_typeParameterIndex;
479 : };
480 :
481 0 : sal_Int32 translateSpecialTypeFlags(
482 : SpecialType specialType, bool inParameter, bool outParameter)
483 : {
484 : static sal_Int32 const specialTypeFlags[SPECIAL_TYPE_INTERFACE + 1] = {
485 : 0, 0x0040 /* ANY */, 0x0004 /* UNSIGNED */, 0x0080 /* INTERFACE */ };
486 0 : sal_Int32 flags = specialTypeFlags[specialType];
487 0 : if (inParameter) {
488 0 : flags |= 0x0001; /* IN */
489 : }
490 0 : if (outParameter) {
491 0 : flags |= 0x0002; /* OUT */
492 : }
493 0 : return flags;
494 : }
495 :
496 0 : TypeInfo::TypeInfo(
497 : rtl::OString const & name, SpecialType specialType, sal_Int32 index,
498 : PolymorphicUnoType const & polymorphicUnoType,
499 : sal_Int32 typeParameterIndex):
500 : m_kind(KIND_MEMBER), m_name(name),
501 0 : m_flags(translateSpecialTypeFlags(specialType, false, false)),
502 : m_index(index), m_polymorphicUnoType(polymorphicUnoType),
503 0 : m_typeParameterIndex(typeParameterIndex)
504 : {
505 : OSL_ASSERT(
506 : polymorphicUnoType.kind == PolymorphicUnoType::KIND_NONE
507 : ? typeParameterIndex >= -1 : typeParameterIndex == -1);
508 0 : }
509 :
510 0 : TypeInfo::TypeInfo(
511 : Kind kind, rtl::OString const & name, SpecialType specialType,
512 : Flags flags, sal_Int32 index,
513 : PolymorphicUnoType const & polymorphicUnoType):
514 : m_kind(kind), m_name(name),
515 0 : m_flags(flags | translateSpecialTypeFlags(specialType, false, false)),
516 0 : m_index(index), m_polymorphicUnoType(polymorphicUnoType)
517 : {
518 : OSL_ASSERT(kind == KIND_ATTRIBUTE || kind == KIND_METHOD);
519 0 : }
520 :
521 0 : TypeInfo::TypeInfo(
522 : rtl::OString const & parameterName, SpecialType specialType,
523 : bool inParameter, bool outParameter, rtl::OString const & methodName,
524 : sal_Int32 index, PolymorphicUnoType const & polymorphicUnoType):
525 : m_kind(KIND_PARAMETER), m_name(parameterName),
526 0 : m_flags(translateSpecialTypeFlags(specialType, inParameter, outParameter)),
527 : m_index(index), m_methodName(methodName),
528 0 : m_polymorphicUnoType(polymorphicUnoType)
529 0 : {}
530 :
531 0 : sal_uInt16 TypeInfo::generateCode(
532 : ClassFile::Code & code, Dependencies * dependencies) const
533 : {
534 : OSL_ASSERT(dependencies != 0);
535 0 : switch (m_kind) {
536 : case KIND_MEMBER:
537 : code.instrNew(
538 : rtl::OString(
539 : RTL_CONSTASCII_STRINGPARAM(
540 0 : "com/sun/star/lib/uno/typeinfo/MemberTypeInfo")));
541 0 : code.instrDup();
542 0 : code.loadStringConstant(m_name);
543 0 : code.loadIntegerConstant(m_index);
544 0 : code.loadIntegerConstant(m_flags);
545 0 : if (m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE) {
546 0 : generatePolymorphicUnoTypeCode(code, dependencies);
547 0 : code.loadIntegerConstant(m_typeParameterIndex);
548 : code.instrInvokespecial(
549 : rtl::OString(
550 : RTL_CONSTASCII_STRINGPARAM(
551 : "com/sun/star/lib/uno/typeinfo/MemberTypeInfo")),
552 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
553 : rtl::OString(
554 : RTL_CONSTASCII_STRINGPARAM(
555 0 : "(Ljava/lang/String;IILcom/sun/star/uno/Type;I)V")));
556 0 : return 8;
557 0 : } else if (m_typeParameterIndex >= 0) {
558 0 : code.instrAconstNull();
559 0 : code.loadIntegerConstant(m_typeParameterIndex);
560 : code.instrInvokespecial(
561 : rtl::OString(
562 : RTL_CONSTASCII_STRINGPARAM(
563 : "com/sun/star/lib/uno/typeinfo/MemberTypeInfo")),
564 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
565 : rtl::OString(
566 : RTL_CONSTASCII_STRINGPARAM(
567 0 : "(Ljava/lang/String;IILcom/sun/star/uno/Type;I)V")));
568 0 : return 6;
569 : } else {
570 : code.instrInvokespecial(
571 : rtl::OString(
572 : RTL_CONSTASCII_STRINGPARAM(
573 : "com/sun/star/lib/uno/typeinfo/MemberTypeInfo")),
574 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
575 : rtl::OString(
576 0 : RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;II)V")));
577 0 : return 4;
578 : }
579 :
580 : case KIND_ATTRIBUTE:
581 : code.instrNew(
582 : rtl::OString(
583 : RTL_CONSTASCII_STRINGPARAM(
584 0 : "com/sun/star/lib/uno/typeinfo/AttributeTypeInfo")));
585 0 : code.instrDup();
586 0 : code.loadStringConstant(m_name);
587 0 : code.loadIntegerConstant(m_index);
588 0 : code.loadIntegerConstant(m_flags);
589 0 : if (m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE) {
590 0 : generatePolymorphicUnoTypeCode(code, dependencies);
591 : code.instrInvokespecial(
592 : rtl::OString(
593 : RTL_CONSTASCII_STRINGPARAM(
594 : "com/sun/star/lib/uno/typeinfo/AttributeTypeInfo")),
595 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
596 : rtl::OString(
597 : RTL_CONSTASCII_STRINGPARAM(
598 0 : "(Ljava/lang/String;IILcom/sun/star/uno/Type;)V")));
599 0 : return 8;
600 : } else {
601 : code.instrInvokespecial(
602 : rtl::OString(
603 : RTL_CONSTASCII_STRINGPARAM(
604 : "com/sun/star/lib/uno/typeinfo/AttributeTypeInfo")),
605 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
606 : rtl::OString(
607 0 : RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;II)V")));
608 0 : return 4;
609 : }
610 :
611 : case KIND_METHOD:
612 : code.instrNew(
613 : rtl::OString(
614 : RTL_CONSTASCII_STRINGPARAM(
615 0 : "com/sun/star/lib/uno/typeinfo/MethodTypeInfo")));
616 0 : code.instrDup();
617 0 : code.loadStringConstant(m_name);
618 0 : code.loadIntegerConstant(m_index);
619 0 : code.loadIntegerConstant(m_flags);
620 0 : if (m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE) {
621 0 : generatePolymorphicUnoTypeCode(code, dependencies);
622 : code.instrInvokespecial(
623 : rtl::OString(
624 : RTL_CONSTASCII_STRINGPARAM(
625 : "com/sun/star/lib/uno/typeinfo/MethodTypeInfo")),
626 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
627 : rtl::OString(
628 : RTL_CONSTASCII_STRINGPARAM(
629 0 : "(Ljava/lang/String;IILcom/sun/star/uno/Type;)V")));
630 0 : return 8;
631 : } else {
632 : code.instrInvokespecial(
633 : rtl::OString(
634 : RTL_CONSTASCII_STRINGPARAM(
635 : "com/sun/star/lib/uno/typeinfo/MethodTypeInfo")),
636 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
637 : rtl::OString(
638 0 : RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;II)V")));
639 0 : return 4;
640 : }
641 :
642 : case KIND_PARAMETER:
643 : code.instrNew(
644 : rtl::OString(
645 : RTL_CONSTASCII_STRINGPARAM(
646 0 : "com/sun/star/lib/uno/typeinfo/ParameterTypeInfo")));
647 0 : code.instrDup();
648 0 : code.loadStringConstant(m_name);
649 0 : code.loadStringConstant(m_methodName);
650 0 : code.loadIntegerConstant(m_index);
651 0 : code.loadIntegerConstant(m_flags);
652 0 : if (m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE) {
653 0 : generatePolymorphicUnoTypeCode(code, dependencies);
654 : code.instrInvokespecial(
655 : rtl::OString(
656 : RTL_CONSTASCII_STRINGPARAM(
657 : "com/sun/star/lib/uno/typeinfo/ParameterTypeInfo")),
658 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
659 : rtl::OString(
660 : RTL_CONSTASCII_STRINGPARAM(
661 : "(Ljava/lang/String;Ljava/lang/String;II"
662 0 : "Lcom/sun/star/uno/Type;)V")));
663 0 : return 9;
664 : } else {
665 : code.instrInvokespecial(
666 : rtl::OString(
667 : RTL_CONSTASCII_STRINGPARAM(
668 : "com/sun/star/lib/uno/typeinfo/ParameterTypeInfo")),
669 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
670 : rtl::OString(
671 : RTL_CONSTASCII_STRINGPARAM(
672 0 : "(Ljava/lang/String;Ljava/lang/String;II)V")));
673 0 : return 5;
674 : }
675 :
676 : default:
677 : OSL_ASSERT(false);
678 0 : return 0;
679 : }
680 : }
681 :
682 0 : void TypeInfo::generatePolymorphicUnoTypeCode(
683 : ClassFile::Code & code, Dependencies * dependencies) const
684 : {
685 : OSL_ASSERT(
686 : dependencies != 0
687 : && m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE);
688 : code.instrNew(
689 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")));
690 0 : code.instrDup();
691 0 : code.loadStringConstant(m_polymorphicUnoType.name);
692 0 : if (m_polymorphicUnoType.kind == PolymorphicUnoType::KIND_STRUCT) {
693 : code.instrGetstatic(
694 : rtl::OString(
695 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
696 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("STRUCT")),
697 : rtl::OString(
698 0 : RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/TypeClass;")));
699 : } else {
700 : code.instrGetstatic(
701 : rtl::OString(
702 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
703 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("SEQUENCE")),
704 : rtl::OString(
705 0 : RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/TypeClass;")));
706 : }
707 : dependencies->insert(
708 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")));
709 : code.instrInvokespecial(
710 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
711 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
712 : rtl::OString(
713 : RTL_CONSTASCII_STRINGPARAM(
714 0 : "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V")));
715 0 : }
716 :
717 0 : void writeClassFile(
718 : JavaOptions /*TODO const*/ & options, rtl::OString const & type,
719 : ClassFile const & classFile)
720 : {
721 0 : rtl::OString path;
722 0 : if (options.isValid(rtl::OString(RTL_CONSTASCII_STRINGPARAM("-O")))) {
723 : path = options.getOption(
724 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("-O")));
725 : }
726 : rtl::OString filename(
727 : createFileNameFromType(
728 0 : path, type, rtl::OString(RTL_CONSTASCII_STRINGPARAM(".class"))));
729 0 : bool check = false;
730 0 : if (fileExists(filename)) {
731 0 : if (options.isValid(rtl::OString(RTL_CONSTASCII_STRINGPARAM("-G")))) {
732 0 : return;
733 : }
734 : check = options.isValid(
735 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("-Gc")));
736 : }
737 0 : FileStream tempfile;
738 0 : tempfile.createTempFile(getTempDir(filename));
739 0 : if (!tempfile.isValid()) {
740 : throw CannotDumpException(
741 : rtl::OString(
742 : RTL_CONSTASCII_STRINGPARAM("Cannot create temporary file for "))
743 0 : + filename);
744 : }
745 0 : rtl::OString tempname(tempfile.getName());
746 : try {
747 0 : classFile.write(tempfile);
748 0 : } catch (...) {
749 : // Remove existing file for consistency:
750 0 : if (fileExists(filename)) {
751 0 : removeTypeFile(filename);
752 : }
753 0 : tempfile.close();
754 0 : removeTypeFile(tempname);
755 0 : throw;
756 : }
757 0 : tempfile.close();
758 0 : if (!makeValidTypeFile(filename, tempname, check)) {
759 0 : rtl::OStringBuffer msg;
760 0 : msg.append(RTL_CONSTASCII_STRINGPARAM("Cannot create "));
761 0 : msg.append(filename);
762 0 : msg.append(RTL_CONSTASCII_STRINGPARAM(" from temporary file "));
763 0 : msg.append(tempname);
764 0 : throw CannotDumpException(msg.makeStringAndClear());
765 0 : }
766 : }
767 :
768 0 : void addTypeInfo(
769 : rtl::OString const & className, std::vector< TypeInfo > const & typeInfo,
770 : Dependencies * dependencies, ClassFile * classFile)
771 : {
772 : OSL_ASSERT(dependencies != 0 && classFile != 0);
773 0 : std::vector< TypeInfo >::size_type typeInfos = typeInfo.size();
774 0 : if (typeInfos > SAL_MAX_INT32) {
775 : throw CannotDumpException(
776 : rtl::OString(
777 : RTL_CONSTASCII_STRINGPARAM(
778 0 : "UNOTYPEINFO array too big for Java class file format")));
779 : }
780 0 : if (typeInfos != 0) {
781 : classFile->addField(
782 : static_cast< ClassFile::AccessFlags >(
783 : ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC
784 : | ClassFile::ACC_FINAL),
785 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("UNOTYPEINFO")),
786 : rtl::OString(
787 : RTL_CONSTASCII_STRINGPARAM(
788 : "[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;")),
789 0 : 0, rtl::OString());
790 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
791 0 : std::auto_ptr< ClassFile::Code > code(classFile->newCode());
792 : SAL_WNODEPRECATED_DECLARATIONS_POP
793 0 : code->loadIntegerConstant(static_cast< sal_Int32 >(typeInfos));
794 : code->instrAnewarray(
795 : rtl::OString(
796 : RTL_CONSTASCII_STRINGPARAM(
797 0 : "com/sun/star/lib/uno/typeinfo/TypeInfo")));
798 0 : sal_Int32 index = 0;
799 0 : sal_uInt16 stack = 0;
800 0 : for (std::vector< TypeInfo >::const_iterator i(typeInfo.begin());
801 0 : i != typeInfo.end(); ++i)
802 : {
803 0 : code->instrDup();
804 0 : code->loadIntegerConstant(index++);
805 0 : stack = std::max(stack, i->generateCode(*code, dependencies));
806 0 : code->instrAastore();
807 : }
808 : code->instrPutstatic(
809 : className, rtl::OString(RTL_CONSTASCII_STRINGPARAM("UNOTYPEINFO")),
810 : rtl::OString(
811 : RTL_CONSTASCII_STRINGPARAM(
812 0 : "[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;")));
813 0 : code->instrReturn();
814 0 : if (stack > SAL_MAX_UINT16 - 4) {
815 : throw CannotDumpException(
816 : rtl::OString(
817 : RTL_CONSTASCII_STRINGPARAM(
818 0 : "Stack too big for Java class file format")));
819 : }
820 0 : code->setMaxStackAndLocals(static_cast< sal_uInt16 >(stack + 4), 0);
821 : classFile->addMethod(
822 : static_cast< ClassFile::AccessFlags >(
823 : ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC),
824 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<clinit>")),
825 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")), code.get(),
826 0 : std::vector< rtl::OString >(), rtl::OString());
827 : }
828 0 : }
829 :
830 : typedef void (* handleUnoTypeRegistryEntityFunction)(
831 : TypeManager const & manager, JavaOptions /*TODO const*/ & options,
832 : typereg::Reader const & reader, Dependencies * dependencies);
833 :
834 0 : void handleEnumType(
835 : SAL_UNUSED_PARAMETER TypeManager const &,
836 : JavaOptions /*TODO const*/ & options, typereg::Reader const & reader,
837 : SAL_UNUSED_PARAMETER Dependencies *)
838 : {
839 0 : sal_uInt16 fields = reader.getFieldCount();
840 0 : if (fields == 0 || reader.getSuperTypeCount() != 0
841 0 : || reader.getMethodCount() != 0 || reader.getReferenceCount() != 0)
842 : {
843 : throw CannotDumpException(
844 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
845 : //TODO
846 : }
847 0 : rtl::OString className(codemaker::convertString(reader.getTypeName()));
848 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
849 : std::auto_ptr< ClassFile > cf(
850 : new ClassFile(
851 : static_cast< ClassFile::AccessFlags >(
852 : ClassFile::ACC_PUBLIC | ClassFile::ACC_FINAL
853 : | ClassFile::ACC_SUPER),
854 : className,
855 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Enum")),
856 0 : rtl::OString()));
857 : SAL_WNODEPRECATED_DECLARATIONS_POP
858 0 : rtl::OStringBuffer buf;
859 0 : buf.append('L');
860 0 : buf.append(className);
861 0 : buf.append(';');
862 0 : rtl::OString classDescriptor(buf.makeStringAndClear());
863 0 : {for (sal_uInt16 i = 0; i < fields; ++i) {
864 0 : RTConstValue fieldValue(reader.getFieldValue(i));
865 0 : if (fieldValue.m_type != RT_TYPE_INT32
866 0 : || reader.getFieldFlags(i) != RT_ACCESS_CONST
867 0 : || reader.getFieldTypeName(i).getLength() != 0)
868 : {
869 : throw CannotDumpException(
870 : rtl::OString(
871 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
872 : }
873 : rtl::OString fieldName(
874 0 : codemaker::convertString(reader.getFieldName(i)));
875 : cf->addField(
876 : static_cast< ClassFile::AccessFlags >(
877 : ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC
878 : | ClassFile::ACC_FINAL),
879 0 : fieldName, classDescriptor, 0, rtl::OString());
880 : cf->addField(
881 : static_cast< ClassFile::AccessFlags >(
882 : ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC
883 : | ClassFile::ACC_FINAL),
884 0 : fieldName + rtl::OString(RTL_CONSTASCII_STRINGPARAM("_value")),
885 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("I")),
886 0 : cf->addIntegerInfo(fieldValue.m_value.aLong), rtl::OString());
887 0 : }}
888 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
889 0 : std::auto_ptr< ClassFile::Code > code(cf->newCode());
890 : SAL_WNODEPRECATED_DECLARATIONS_POP
891 0 : code->loadLocalReference(0);
892 0 : code->loadLocalInteger(1);
893 : code->instrInvokespecial(
894 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Enum")),
895 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
896 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")));
897 0 : code->instrReturn();
898 0 : code->setMaxStackAndLocals(2, 2);
899 : cf->addMethod(
900 : ClassFile::ACC_PRIVATE,
901 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
902 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")), code.get(),
903 0 : std::vector< rtl::OString >(), rtl::OString());
904 0 : code.reset(cf->newCode());
905 : code->instrGetstatic(
906 : className,
907 0 : codemaker::convertString(reader.getFieldName(0)), classDescriptor);
908 0 : code->instrAreturn();
909 0 : code->setMaxStackAndLocals(1, 0);
910 : cf->addMethod(
911 : static_cast< ClassFile::AccessFlags >(
912 : ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC),
913 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("getDefault")),
914 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("()")) + classDescriptor,
915 0 : code.get(), std::vector< rtl::OString >(), rtl::OString());
916 0 : code.reset(cf->newCode());
917 0 : code->loadLocalInteger(0);
918 0 : std::map< sal_Int32, rtl::OString > map;
919 0 : sal_Int32 min = SAL_MAX_INT32;
920 0 : sal_Int32 max = SAL_MIN_INT32;
921 0 : {for (sal_uInt16 i = 0; i < fields; ++i) {
922 0 : sal_Int32 value = reader.getFieldValue(i).m_value.aLong;
923 0 : min = std::min(min, value);
924 0 : max = std::max(max, value);
925 : map.insert(
926 : std::map< sal_Int32, rtl::OString >::value_type(
927 0 : value, codemaker::convertString(reader.getFieldName(i))));
928 : }}
929 0 : sal_uInt64 size = static_cast< sal_uInt64 >(map.size());
930 0 : if ((static_cast< sal_uInt64 >(max) - static_cast< sal_uInt64 >(min)
931 : <= 2 * size)
932 : || size > SAL_MAX_INT32)
933 : {
934 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
935 0 : std::auto_ptr< ClassFile::Code > defCode(cf->newCode());
936 : SAL_WNODEPRECATED_DECLARATIONS_POP
937 0 : defCode->instrAconstNull();
938 0 : defCode->instrAreturn();
939 0 : std::list< ClassFile::Code * > blocks;
940 : //FIXME: pointers contained in blocks may leak
941 0 : sal_Int32 last = SAL_MAX_INT32;
942 0 : for (std::map< sal_Int32, rtl::OString >::iterator i(map.begin());
943 0 : i != map.end(); ++i)
944 : {
945 0 : sal_Int32 value = i->first;
946 0 : if (last != SAL_MAX_INT32) {
947 0 : for (sal_Int32 j = last + 1; j < value; ++j) {
948 0 : blocks.push_back(0);
949 : }
950 : }
951 0 : last = value;
952 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
953 0 : std::auto_ptr< ClassFile::Code > blockCode(cf->newCode());
954 : SAL_WNODEPRECATED_DECLARATIONS_POP
955 0 : blockCode->instrGetstatic(className, i->second, classDescriptor);
956 0 : blockCode->instrAreturn();
957 0 : blocks.push_back(blockCode.get());
958 0 : blockCode.release();
959 0 : }
960 0 : code->instrTableswitch(defCode.get(), min, blocks);
961 0 : {for (std::list< ClassFile::Code * >::iterator i(blocks.begin());
962 0 : i != blocks.end(); ++i)
963 : {
964 0 : delete *i;
965 0 : }}
966 : } else{
967 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
968 0 : std::auto_ptr< ClassFile::Code > defCode(cf->newCode());
969 : SAL_WNODEPRECATED_DECLARATIONS_POP
970 0 : defCode->instrAconstNull();
971 0 : defCode->instrAreturn();
972 0 : std::list< std::pair< sal_Int32, ClassFile::Code * > > blocks;
973 : //FIXME: pointers contained in blocks may leak
974 0 : for (std::map< sal_Int32, rtl::OString >::iterator i(map.begin());
975 0 : i != map.end(); ++i)
976 : {
977 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
978 0 : std::auto_ptr< ClassFile::Code > blockCode(cf->newCode());
979 : SAL_WNODEPRECATED_DECLARATIONS_POP
980 0 : blockCode->instrGetstatic(className, i->second, classDescriptor);
981 0 : blockCode->instrAreturn();
982 0 : blocks.push_back(std::make_pair(i->first, blockCode.get()));
983 0 : blockCode.release();
984 0 : }
985 0 : code->instrLookupswitch(defCode.get(), blocks);
986 0 : {for (std::list< std::pair< sal_Int32, ClassFile::Code * > >::iterator
987 0 : i(blocks.begin());
988 0 : i != blocks.end(); ++i)
989 : {
990 0 : delete i->second;
991 0 : }}
992 : }
993 0 : code->setMaxStackAndLocals(1, 1);
994 : cf->addMethod(
995 : static_cast< ClassFile::AccessFlags >(
996 : ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC),
997 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("fromInt")),
998 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)")) + classDescriptor,
999 0 : code.get(), std::vector< rtl::OString >(), rtl::OString());
1000 0 : code.reset(cf->newCode());
1001 0 : {for (sal_uInt16 i = 0; i < fields; ++i) {
1002 0 : code->instrNew(className);
1003 0 : code->instrDup();
1004 0 : code->loadIntegerConstant(reader.getFieldValue(i).m_value.aLong);
1005 : code->instrInvokespecial(
1006 : className, rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1007 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")));
1008 : code->instrPutstatic(
1009 : className,
1010 : codemaker::convertString(reader.getFieldName(i)),
1011 0 : classDescriptor);
1012 : }}
1013 0 : code->instrReturn();
1014 0 : code->setMaxStackAndLocals(3, 0);
1015 : cf->addMethod(
1016 : static_cast< ClassFile::AccessFlags >(
1017 : ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC),
1018 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<clinit>")),
1019 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")), code.get(),
1020 0 : std::vector< rtl::OString >(), rtl::OString());
1021 0 : writeClassFile(options, className, *cf.get());
1022 0 : }
1023 :
1024 0 : void addField(
1025 : TypeManager const & manager, Dependencies * dependencies,
1026 : ClassFile * classFile, std::vector< TypeInfo > * typeInfo,
1027 : sal_Int32 typeParameterIndex, rtl::OString const & type,
1028 : rtl::OString const & name, sal_Int32 index)
1029 : {
1030 : OSL_ASSERT(dependencies != 0 && classFile != 0 && typeInfo != 0);
1031 0 : rtl::OString descriptor;
1032 0 : rtl::OString signature;
1033 : SpecialType specialType;
1034 0 : PolymorphicUnoType polymorphicUnoType;
1035 0 : if (typeParameterIndex >= 0) {
1036 : descriptor = rtl::OString(
1037 0 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;"));
1038 0 : rtl::OStringBuffer buf;
1039 0 : buf.append('T');
1040 0 : buf.append(type);
1041 0 : buf.append(';');
1042 0 : signature = buf.makeStringAndClear();
1043 0 : specialType = SPECIAL_TYPE_NONE; //TODO: SPECIAL_TYPE_TYPE_PARAMETER?
1044 : } else {
1045 : specialType = getFieldDescriptor(
1046 : manager, dependencies, type, &descriptor, &signature,
1047 0 : &polymorphicUnoType);
1048 : }
1049 0 : classFile->addField(ClassFile::ACC_PUBLIC, name, descriptor, 0, signature);
1050 : typeInfo->push_back(
1051 : TypeInfo(
1052 0 : name, specialType, index, polymorphicUnoType, typeParameterIndex));
1053 0 : }
1054 :
1055 0 : sal_uInt16 addFieldInit(
1056 : TypeManager const & manager, rtl::OString const & className,
1057 : rtl::OString const & fieldName, bool typeParameter,
1058 : rtl::OString const & fieldType, Dependencies * dependencies,
1059 : ClassFile::Code * code)
1060 : {
1061 : OSL_ASSERT(dependencies != 0 && code != 0);
1062 0 : if (typeParameter) {
1063 0 : return 0;
1064 : } else {
1065 : RTTypeClass typeClass;
1066 0 : rtl::OString nucleus;
1067 : sal_Int32 rank;
1068 0 : std::vector< rtl::OString > args;
1069 : codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve(
1070 : manager, fieldType, true, false, false, &typeClass, &nucleus, &rank,
1071 0 : &args);
1072 0 : if (rank == 0) {
1073 0 : switch (sort) {
1074 : case codemaker::UnoType::SORT_STRING:
1075 0 : code->loadLocalReference(0);
1076 0 : code->loadStringConstant(rtl::OString());
1077 : code->instrPutfield(
1078 : className, fieldName,
1079 : rtl::OString(
1080 0 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/String;")));
1081 0 : return 2;
1082 :
1083 : case codemaker::UnoType::SORT_TYPE:
1084 0 : code->loadLocalReference(0);
1085 : code->instrGetstatic(
1086 : rtl::OString(
1087 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
1088 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("VOID")),
1089 : rtl::OString(
1090 0 : RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Type;")));
1091 : code->instrPutfield(
1092 : className, fieldName,
1093 : rtl::OString(
1094 0 : RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Type;")));
1095 0 : return 2;
1096 :
1097 : case codemaker::UnoType::SORT_ANY:
1098 0 : code->loadLocalReference(0);
1099 : code->instrGetstatic(
1100 : rtl::OString(
1101 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1102 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("VOID")),
1103 : rtl::OString(
1104 0 : RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/Any;")));
1105 : code->instrPutfield(
1106 : className, fieldName,
1107 : rtl::OString(
1108 0 : RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;")));
1109 0 : return 2;
1110 :
1111 : case codemaker::UnoType::SORT_COMPLEX:
1112 0 : switch (typeClass) {
1113 : case RT_TYPE_ENUM:
1114 : {
1115 0 : code->loadLocalReference(0);
1116 0 : typereg::Reader reader(manager.getTypeReader(nucleus));
1117 0 : if (reader.getFieldCount() == 0) {
1118 : throw CannotDumpException(
1119 : rtl::OString(
1120 : RTL_CONSTASCII_STRINGPARAM(
1121 0 : "Bad type information"))); //TODO
1122 : }
1123 0 : rtl::OStringBuffer descBuf;
1124 : translateUnoTypeToDescriptor(
1125 : manager, sort, typeClass, nucleus, 0,
1126 : std::vector< rtl::OString >(), false, false,
1127 0 : dependencies, &descBuf, 0, 0, 0);
1128 0 : rtl::OString desc(descBuf.makeStringAndClear());
1129 : code->instrGetstatic(
1130 : nucleus,
1131 : codemaker::convertString(reader.getFieldName(0)),
1132 0 : desc);
1133 0 : code->instrPutfield(className, fieldName, desc);
1134 0 : return 2;
1135 : }
1136 :
1137 : case RT_TYPE_STRUCT:
1138 : {
1139 0 : code->loadLocalReference(0);
1140 0 : code->instrNew(nucleus);
1141 0 : code->instrDup();
1142 : code->instrInvokespecial(
1143 : nucleus,
1144 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1145 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")));
1146 0 : rtl::OStringBuffer desc;
1147 : translateUnoTypeToDescriptor(
1148 : manager, sort, typeClass, nucleus, 0,
1149 : std::vector< rtl::OString >(), false, false,
1150 0 : dependencies, &desc, 0, 0, 0);
1151 : code->instrPutfield(
1152 0 : className, fieldName, desc.makeStringAndClear());
1153 0 : return 3;
1154 : }
1155 :
1156 : default:
1157 : OSL_ASSERT(typeClass == RT_TYPE_INTERFACE);
1158 0 : return 0;
1159 : }
1160 :
1161 : default:
1162 0 : return 0;
1163 : }
1164 : } else {
1165 0 : code->loadLocalReference(0);
1166 0 : code->loadIntegerConstant(0);
1167 0 : if (rank == 1) {
1168 0 : if (sort >= codemaker::UnoType::SORT_BOOLEAN
1169 : && sort <= codemaker::UnoType::SORT_CHAR)
1170 : {
1171 0 : code->instrNewarray(sort);
1172 : } else {
1173 : code->instrAnewarray(
1174 : codemaker::java::translateUnoToJavaType(sort, typeClass,
1175 0 : nucleus, 0));
1176 : }
1177 : } else {
1178 0 : rtl::OStringBuffer desc;
1179 : translateUnoTypeToDescriptor(
1180 : manager, sort, typeClass, nucleus, rank - 1,
1181 : std::vector< rtl::OString >(), false, false, dependencies,
1182 0 : &desc, 0, 0, 0);
1183 0 : code->instrAnewarray(desc.makeStringAndClear());
1184 : }
1185 0 : rtl::OStringBuffer desc;
1186 : translateUnoTypeToDescriptor(
1187 : manager, sort, typeClass, nucleus, rank,
1188 : std::vector< rtl::OString >(), false, false, dependencies,
1189 0 : &desc, 0, 0, 0);
1190 : code->instrPutfield(
1191 0 : className, fieldName, desc.makeStringAndClear());
1192 0 : return 2;
1193 0 : }
1194 : }
1195 : }
1196 :
1197 0 : sal_uInt16 addLoadLocal(
1198 : TypeManager const & manager, ClassFile::Code * code, sal_uInt16 * index,
1199 : bool typeParameter, rtl::OString const & type, bool any,
1200 : Dependencies * dependencies)
1201 : {
1202 : OSL_ASSERT(
1203 : code != 0 && index != 0 && !(typeParameter && any)
1204 : && dependencies != 0);
1205 0 : sal_uInt16 stack = 1;
1206 0 : sal_uInt16 size = 1;
1207 0 : if (typeParameter) {
1208 0 : code->loadLocalReference(*index);
1209 0 : stack = size = 1;
1210 : } else {
1211 : RTTypeClass typeClass;
1212 0 : rtl::OString nucleus;
1213 : sal_Int32 rank;
1214 0 : std::vector< rtl::OString > args;
1215 : codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve(
1216 0 : manager, type, true, false, false, &typeClass, &nucleus, &rank, &args);
1217 0 : if (rank == 0) {
1218 0 : switch (sort) {
1219 : case codemaker::UnoType::SORT_BOOLEAN:
1220 0 : if (any) {
1221 : code->instrNew(
1222 : rtl::OString(
1223 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Boolean")));
1224 0 : code->instrDup();
1225 0 : code->loadLocalInteger(*index);
1226 : code->instrInvokespecial(
1227 : rtl::OString(
1228 : RTL_CONSTASCII_STRINGPARAM("java/lang/Boolean")),
1229 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1230 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(Z)V")));
1231 0 : stack = 3;
1232 : } else {
1233 0 : code->loadLocalInteger(*index);
1234 0 : stack = 1;
1235 : }
1236 0 : size = 1;
1237 0 : break;
1238 :
1239 : case codemaker::UnoType::SORT_BYTE:
1240 0 : if (any) {
1241 : code->instrNew(
1242 : rtl::OString(
1243 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Byte")));
1244 0 : code->instrDup();
1245 0 : code->loadLocalInteger(*index);
1246 : code->instrInvokespecial(
1247 : rtl::OString(
1248 : RTL_CONSTASCII_STRINGPARAM("java/lang/Byte")),
1249 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1250 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(B)V")));
1251 0 : stack = 3;
1252 : } else {
1253 0 : code->loadLocalInteger(*index);
1254 0 : stack = 1;
1255 : }
1256 0 : size = 1;
1257 0 : break;
1258 :
1259 : case codemaker::UnoType::SORT_SHORT:
1260 0 : if (any) {
1261 : code->instrNew(
1262 : rtl::OString(
1263 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Short")));
1264 0 : code->instrDup();
1265 0 : code->loadLocalInteger(*index);
1266 : code->instrInvokespecial(
1267 : rtl::OString(
1268 : RTL_CONSTASCII_STRINGPARAM("java/lang/Short")),
1269 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1270 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(S)V")));
1271 0 : stack = 3;
1272 : } else {
1273 0 : code->loadLocalInteger(*index);
1274 0 : stack = 1;
1275 : }
1276 0 : size = 1;
1277 0 : break;
1278 :
1279 : case codemaker::UnoType::SORT_UNSIGNED_SHORT:
1280 0 : if (any) {
1281 : code->instrNew(
1282 : rtl::OString(
1283 : RTL_CONSTASCII_STRINGPARAM(
1284 0 : "com/sun/star/uno/Any")));
1285 0 : code->instrDup();
1286 : code->instrGetstatic(
1287 : rtl::OString(
1288 : RTL_CONSTASCII_STRINGPARAM(
1289 : "com/sun/star/uno/Type")),
1290 : rtl::OString(
1291 : RTL_CONSTASCII_STRINGPARAM("UNSIGNED_SHORT")),
1292 : rtl::OString(
1293 : RTL_CONSTASCII_STRINGPARAM(
1294 0 : "Lcom/sun/star/uno/Type;")));
1295 : code->instrNew(
1296 : rtl::OString(
1297 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Short")));
1298 0 : code->instrDup();
1299 0 : code->loadLocalInteger(*index);
1300 : code->instrInvokespecial(
1301 : rtl::OString(
1302 : RTL_CONSTASCII_STRINGPARAM("java/lang/Short")),
1303 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1304 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(S)V")));
1305 : code->instrInvokespecial(
1306 : rtl::OString(
1307 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1308 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1309 : rtl::OString(
1310 : RTL_CONSTASCII_STRINGPARAM(
1311 : "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
1312 0 : "V")));
1313 0 : stack = 6;
1314 : } else {
1315 0 : code->loadLocalInteger(*index);
1316 0 : stack = 1;
1317 : }
1318 0 : size = 1;
1319 0 : break;
1320 :
1321 : case codemaker::UnoType::SORT_LONG:
1322 0 : if (any) {
1323 : code->instrNew(
1324 : rtl::OString(
1325 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")));
1326 0 : code->instrDup();
1327 0 : code->loadLocalInteger(*index);
1328 : code->instrInvokespecial(
1329 : rtl::OString(
1330 : RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")),
1331 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1332 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")));
1333 0 : stack = 3;
1334 : } else {
1335 0 : code->loadLocalInteger(*index);
1336 0 : stack = 1;
1337 : }
1338 0 : size = 1;
1339 0 : break;
1340 :
1341 : case codemaker::UnoType::SORT_UNSIGNED_LONG:
1342 0 : if (any) {
1343 : code->instrNew(
1344 : rtl::OString(
1345 : RTL_CONSTASCII_STRINGPARAM(
1346 0 : "com/sun/star/uno/Any")));
1347 0 : code->instrDup();
1348 : code->instrGetstatic(
1349 : rtl::OString(
1350 : RTL_CONSTASCII_STRINGPARAM(
1351 : "com/sun/star/uno/Type")),
1352 : rtl::OString(
1353 : RTL_CONSTASCII_STRINGPARAM("UNSIGNED_LONG")),
1354 : rtl::OString(
1355 : RTL_CONSTASCII_STRINGPARAM(
1356 0 : "Lcom/sun/star/uno/Type;")));
1357 : code->instrNew(
1358 : rtl::OString(
1359 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")));
1360 0 : code->instrDup();
1361 0 : code->loadLocalInteger(*index);
1362 : code->instrInvokespecial(
1363 : rtl::OString(
1364 : RTL_CONSTASCII_STRINGPARAM("java/lang/Integer")),
1365 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1366 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(I)V")));
1367 : code->instrInvokespecial(
1368 : rtl::OString(
1369 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1370 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1371 : rtl::OString(
1372 : RTL_CONSTASCII_STRINGPARAM(
1373 : "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
1374 0 : "V")));
1375 0 : stack = 6;
1376 : } else {
1377 0 : code->loadLocalInteger(*index);
1378 0 : stack = 1;
1379 : }
1380 0 : size = 1;
1381 0 : break;
1382 :
1383 : case codemaker::UnoType::SORT_HYPER:
1384 0 : if (any) {
1385 : code->instrNew(
1386 : rtl::OString(
1387 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Long")));
1388 0 : code->instrDup();
1389 0 : code->loadLocalLong(*index);
1390 : code->instrInvokespecial(
1391 : rtl::OString(
1392 : RTL_CONSTASCII_STRINGPARAM("java/lang/Long")),
1393 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1394 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(J)V")));
1395 0 : stack = 4;
1396 : } else {
1397 0 : code->loadLocalLong(*index);
1398 0 : stack = 2;
1399 : }
1400 0 : size = 2;
1401 0 : break;
1402 :
1403 : case codemaker::UnoType::SORT_UNSIGNED_HYPER:
1404 0 : if (any) {
1405 : code->instrNew(
1406 : rtl::OString(
1407 : RTL_CONSTASCII_STRINGPARAM(
1408 0 : "com/sun/star/uno/Any")));
1409 0 : code->instrDup();
1410 : code->instrGetstatic(
1411 : rtl::OString(
1412 : RTL_CONSTASCII_STRINGPARAM(
1413 : "com/sun/star/uno/Type")),
1414 : rtl::OString(
1415 : RTL_CONSTASCII_STRINGPARAM("UNSIGNED_HYPER")),
1416 : rtl::OString(
1417 : RTL_CONSTASCII_STRINGPARAM(
1418 0 : "Lcom/sun/star/uno/Type;")));
1419 : code->instrNew(
1420 : rtl::OString(
1421 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Long")));
1422 0 : code->instrDup();
1423 0 : code->loadLocalLong(*index);
1424 : code->instrInvokespecial(
1425 : rtl::OString(
1426 : RTL_CONSTASCII_STRINGPARAM("java/lang/Long")),
1427 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1428 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(J)V")));
1429 : code->instrInvokespecial(
1430 : rtl::OString(
1431 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1432 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1433 : rtl::OString(
1434 : RTL_CONSTASCII_STRINGPARAM(
1435 : "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
1436 0 : "V")));
1437 0 : stack = 7;
1438 : } else {
1439 0 : code->loadLocalLong(*index);
1440 0 : stack = 2;
1441 : }
1442 0 : size = 2;
1443 0 : break;
1444 :
1445 : case codemaker::UnoType::SORT_FLOAT:
1446 0 : if (any) {
1447 : code->instrNew(
1448 : rtl::OString(
1449 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Float")));
1450 0 : code->instrDup();
1451 0 : code->loadLocalFloat(*index);
1452 : code->instrInvokespecial(
1453 : rtl::OString(
1454 : RTL_CONSTASCII_STRINGPARAM("java/lang/Float")),
1455 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1456 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(F)V")));
1457 0 : stack = 3;
1458 : } else {
1459 0 : code->loadLocalFloat(*index);
1460 0 : stack = 1;
1461 : }
1462 0 : size = 1;
1463 0 : break;
1464 :
1465 : case codemaker::UnoType::SORT_DOUBLE:
1466 0 : if (any) {
1467 : code->instrNew(
1468 : rtl::OString(
1469 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Double")));
1470 0 : code->instrDup();
1471 0 : code->loadLocalDouble(*index);
1472 : code->instrInvokespecial(
1473 : rtl::OString(
1474 : RTL_CONSTASCII_STRINGPARAM("java/lang/Double")),
1475 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1476 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(D)V")));
1477 0 : stack = 4;
1478 : } else {
1479 0 : code->loadLocalDouble(*index);
1480 0 : stack = 2;
1481 : }
1482 0 : size = 2;
1483 0 : break;
1484 :
1485 : case codemaker::UnoType::SORT_CHAR:
1486 0 : if (any) {
1487 : code->instrNew(
1488 : rtl::OString(
1489 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Character")));
1490 0 : code->instrDup();
1491 0 : code->loadLocalInteger(*index);
1492 : code->instrInvokespecial(
1493 : rtl::OString(
1494 : RTL_CONSTASCII_STRINGPARAM("java/lang/Character")),
1495 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1496 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(C)V")));
1497 0 : stack = 3;
1498 : } else {
1499 0 : code->loadLocalInteger(*index);
1500 0 : stack = 1;
1501 : }
1502 0 : size = 1;
1503 0 : break;
1504 :
1505 : case codemaker::UnoType::SORT_STRING:
1506 : case codemaker::UnoType::SORT_TYPE:
1507 : case codemaker::UnoType::SORT_ANY:
1508 0 : code->loadLocalReference(*index);
1509 0 : stack = size = 1;
1510 0 : break;
1511 :
1512 : case codemaker::UnoType::SORT_COMPLEX:
1513 0 : switch (typeClass) {
1514 : case RT_TYPE_ENUM:
1515 : // Assuming that no Java types are derived from Java types
1516 : // that are directly derived from com.sun.star.uno.Enum:
1517 0 : code->loadLocalReference(*index);
1518 0 : stack = size = 1;
1519 0 : break;
1520 :
1521 : case RT_TYPE_STRUCT:
1522 0 : if (any) {
1523 : code->instrNew(
1524 : rtl::OString(
1525 : RTL_CONSTASCII_STRINGPARAM(
1526 0 : "com/sun/star/uno/Any")));
1527 0 : code->instrDup();
1528 : code->instrNew(
1529 : rtl::OString(
1530 : RTL_CONSTASCII_STRINGPARAM(
1531 0 : "com/sun/star/uno/Type")));
1532 0 : code->instrDup();
1533 : code->loadStringConstant(
1534 0 : createUnoName(manager, nucleus, rank, args));
1535 : code->instrGetstatic(
1536 : rtl::OString(
1537 : RTL_CONSTASCII_STRINGPARAM(
1538 : "com/sun/star/uno/TypeClass")),
1539 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("STRUCT")),
1540 : rtl::OString(
1541 : RTL_CONSTASCII_STRINGPARAM(
1542 0 : "Lcom/sun/star/uno/TypeClass;")));
1543 : dependencies->insert(
1544 : rtl::OString(
1545 : RTL_CONSTASCII_STRINGPARAM(
1546 0 : "com/sun/star/uno/TypeClass")));
1547 : code->instrInvokespecial(
1548 : rtl::OString(
1549 : RTL_CONSTASCII_STRINGPARAM(
1550 : "com/sun/star/uno/Type")),
1551 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1552 : rtl::OString(
1553 : RTL_CONSTASCII_STRINGPARAM(
1554 : "(Ljava/lang/String;"
1555 0 : "Lcom/sun/star/uno/TypeClass;)V")));
1556 0 : code->loadLocalReference(*index);
1557 : code->instrInvokespecial(
1558 : rtl::OString(
1559 : RTL_CONSTASCII_STRINGPARAM(
1560 : "com/sun/star/uno/Any")),
1561 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1562 : rtl::OString(
1563 : RTL_CONSTASCII_STRINGPARAM(
1564 : "(Lcom/sun/star/uno/Type;"
1565 0 : "Ljava/lang/Object;)V")));
1566 0 : stack = 6;
1567 : } else {
1568 0 : code->loadLocalReference(*index);
1569 0 : stack = 1;
1570 : }
1571 0 : size = 1;
1572 0 : break;
1573 :
1574 : case RT_TYPE_INTERFACE:
1575 0 : if (any
1576 : && (nucleus
1577 : != rtl::OString(
1578 : RTL_CONSTASCII_STRINGPARAM(
1579 0 : "com/sun/star/uno/XInterface"))))
1580 : {
1581 : code->instrNew(
1582 : rtl::OString(
1583 : RTL_CONSTASCII_STRINGPARAM(
1584 0 : "com/sun/star/uno/Any")));
1585 0 : code->instrDup();
1586 : code->instrNew(
1587 : rtl::OString(
1588 : RTL_CONSTASCII_STRINGPARAM(
1589 0 : "com/sun/star/uno/Type")));
1590 0 : code->instrDup();
1591 0 : code->loadStringConstant(nucleus.replace('/', '.'));
1592 : code->instrGetstatic(
1593 : rtl::OString(
1594 : RTL_CONSTASCII_STRINGPARAM(
1595 : "com/sun/star/uno/TypeClass")),
1596 : rtl::OString(
1597 : RTL_CONSTASCII_STRINGPARAM("INTERFACE")),
1598 : rtl::OString(
1599 : RTL_CONSTASCII_STRINGPARAM(
1600 0 : "Lcom/sun/star/uno/TypeClass;")));
1601 : dependencies->insert(
1602 : rtl::OString(
1603 : RTL_CONSTASCII_STRINGPARAM(
1604 0 : "com/sun/star/uno/TypeClass")));
1605 : code->instrInvokespecial(
1606 : rtl::OString(
1607 : RTL_CONSTASCII_STRINGPARAM(
1608 : "com/sun/star/uno/Type")),
1609 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1610 : rtl::OString(
1611 : RTL_CONSTASCII_STRINGPARAM(
1612 : "(Ljava/lang/String;"
1613 0 : "Lcom/sun/star/uno/TypeClass;)V")));
1614 0 : code->loadLocalReference(*index);
1615 : code->instrInvokespecial(
1616 : rtl::OString(
1617 : RTL_CONSTASCII_STRINGPARAM(
1618 : "com/sun/star/uno/Any")),
1619 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1620 : rtl::OString(
1621 : RTL_CONSTASCII_STRINGPARAM(
1622 : "(Lcom/sun/star/uno/Type;"
1623 0 : "Ljava/lang/Object;)V")));
1624 0 : stack = 6;
1625 : } else {
1626 0 : code->loadLocalReference(*index);
1627 0 : stack = 1;
1628 : }
1629 0 : size = 1;
1630 0 : break;
1631 :
1632 : default:
1633 : OSL_ASSERT(false);
1634 0 : break;
1635 : }
1636 0 : break;
1637 :
1638 : default:
1639 : OSL_ASSERT(false);
1640 0 : break;
1641 : }
1642 : } else {
1643 0 : bool wrap = false;
1644 0 : if (any) {
1645 0 : switch (sort) {
1646 : case codemaker::UnoType::SORT_BOOLEAN:
1647 : case codemaker::UnoType::SORT_BYTE:
1648 : case codemaker::UnoType::SORT_SHORT:
1649 : case codemaker::UnoType::SORT_LONG:
1650 : case codemaker::UnoType::SORT_HYPER:
1651 : case codemaker::UnoType::SORT_FLOAT:
1652 : case codemaker::UnoType::SORT_DOUBLE:
1653 : case codemaker::UnoType::SORT_CHAR:
1654 : case codemaker::UnoType::SORT_STRING:
1655 : case codemaker::UnoType::SORT_TYPE:
1656 : // assuming that no Java types are derived from
1657 : // com.sun.star.uno.Type
1658 0 : break;
1659 :
1660 : case codemaker::UnoType::SORT_UNSIGNED_SHORT:
1661 : case codemaker::UnoType::SORT_UNSIGNED_LONG:
1662 : case codemaker::UnoType::SORT_UNSIGNED_HYPER:
1663 : case codemaker::UnoType::SORT_ANY:
1664 0 : wrap = true;
1665 0 : break;
1666 :
1667 : case codemaker::UnoType::SORT_COMPLEX:
1668 0 : switch (typeClass) {
1669 : case RT_TYPE_ENUM:
1670 : // assuming that no Java types are derived from Java
1671 : // types that are directly derived from
1672 : // com.sun.star.uno.Enum
1673 0 : break;
1674 :
1675 : case RT_TYPE_STRUCT:
1676 : case RT_TYPE_INTERFACE:
1677 0 : wrap = true;
1678 0 : break;
1679 :
1680 : default:
1681 : OSL_ASSERT(false);
1682 0 : break;
1683 : }
1684 0 : break;
1685 :
1686 : default:
1687 : OSL_ASSERT(false);
1688 0 : break;
1689 : }
1690 : }
1691 0 : if (wrap) {
1692 : code->instrNew(
1693 : rtl::OString(
1694 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")));
1695 0 : code->instrDup();
1696 : code->instrNew(
1697 : rtl::OString(
1698 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")));
1699 0 : code->instrDup();
1700 : code->loadStringConstant(
1701 0 : createUnoName(manager, nucleus, rank, args));
1702 : code->instrInvokespecial(
1703 : rtl::OString(
1704 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
1705 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1706 : rtl::OString(
1707 0 : RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;)V")));
1708 0 : code->loadLocalReference(*index);
1709 : code->instrInvokespecial(
1710 : rtl::OString(
1711 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
1712 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1713 : rtl::OString(
1714 : RTL_CONSTASCII_STRINGPARAM(
1715 0 : "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V")));
1716 0 : stack = 5;
1717 : } else {
1718 0 : code->loadLocalReference(*index);
1719 0 : stack = 1;
1720 : }
1721 0 : size = 1;
1722 0 : }
1723 : }
1724 0 : if (*index > SAL_MAX_UINT16 - size) {
1725 : throw CannotDumpException(
1726 : rtl::OString(
1727 : RTL_CONSTASCII_STRINGPARAM(
1728 0 : "Too many local variables for Java class file format")));
1729 : }
1730 0 : *index = *index + size;
1731 0 : return stack;
1732 : }
1733 :
1734 0 : void addBaseArguments(
1735 : TypeManager const & manager, Dependencies * dependencies,
1736 : MethodDescriptor * methodDescriptor, ClassFile::Code * code,
1737 : RTTypeClass typeClass, rtl::OString const & type, sal_uInt16 * index)
1738 : {
1739 : OSL_ASSERT(
1740 : dependencies != 0 && methodDescriptor != 0 && code != 0 && index != 0);
1741 0 : typereg::Reader reader(manager.getTypeReader(type));
1742 0 : if (!reader.isValid() || reader.getTypeClass() != typeClass
1743 0 : || codemaker::convertString(reader.getTypeName()) != type
1744 0 : || reader.getMethodCount() != 0 || reader.getReferenceCount() != 0)
1745 : {
1746 : throw CannotDumpException(
1747 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1748 : //TODO
1749 : }
1750 0 : sal_uInt16 superTypes = reader.getSuperTypeCount();
1751 0 : sal_uInt16 fields = reader.getFieldCount();
1752 0 : sal_uInt16 firstField = 0;
1753 0 : if (type
1754 : == rtl::OString(
1755 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Exception")))
1756 : {
1757 0 : if (typeClass != RT_TYPE_EXCEPTION || superTypes != 0 || fields != 2) {
1758 : throw CannotDumpException(
1759 : rtl::OString(
1760 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1761 : }
1762 0 : firstField = 1;
1763 : } else {
1764 0 : if (
1765 : (typeClass == RT_TYPE_STRUCT && (superTypes > 1 || fields == 0)) ||
1766 : (typeClass == RT_TYPE_EXCEPTION && superTypes != 1)
1767 : )
1768 : {
1769 : throw CannotDumpException(
1770 : rtl::OString(
1771 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1772 : }
1773 0 : if (superTypes == 1) {
1774 : addBaseArguments(
1775 : manager, dependencies, methodDescriptor, code, typeClass,
1776 0 : codemaker::convertString(reader.getSuperTypeName(0)), index);
1777 : }
1778 : }
1779 0 : for (sal_uInt16 i = firstField; i < fields; ++i) {
1780 0 : if (reader.getFieldFlags(i) != RT_ACCESS_READWRITE
1781 : || reader.getFieldValue(i).m_type != RT_TYPE_NONE)
1782 : {
1783 : throw CannotDumpException(
1784 : rtl::OString(
1785 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1786 : }
1787 : rtl::OString fieldType(
1788 0 : codemaker::convertString(reader.getFieldTypeName(i)));
1789 0 : methodDescriptor->addParameter(fieldType, false, true, 0);
1790 : addLoadLocal(
1791 0 : manager, code, index, false, fieldType, false, dependencies);
1792 0 : }
1793 0 : }
1794 :
1795 0 : sal_uInt16 addDirectArgument(
1796 : TypeManager const & manager, Dependencies * dependencies,
1797 : MethodDescriptor * methodDescriptor, ClassFile::Code * code,
1798 : sal_uInt16 * index, rtl::OString const & className,
1799 : rtl::OString const & fieldName, bool typeParameter,
1800 : rtl::OString const & fieldType)
1801 : {
1802 : OSL_ASSERT(
1803 : dependencies != 0 && methodDescriptor != 0 && code != 0 && index != 0);
1804 0 : rtl::OString desc;
1805 0 : if (typeParameter) {
1806 0 : methodDescriptor->addTypeParameter(fieldType);
1807 0 : desc = rtl::OString(RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;"));
1808 : } else {
1809 0 : methodDescriptor->addParameter(fieldType, false, true, 0);
1810 0 : getFieldDescriptor(manager, dependencies, fieldType, &desc, 0, 0);
1811 : }
1812 0 : code->loadLocalReference(0);
1813 : sal_uInt16 stack = addLoadLocal(
1814 0 : manager, code, index, typeParameter, fieldType, false, dependencies);
1815 0 : code->instrPutfield(className, fieldName, desc);
1816 0 : return stack + 1;
1817 : }
1818 :
1819 0 : void handleAggregatingType(
1820 : TypeManager const & manager, JavaOptions /*TODO const*/ & options,
1821 : typereg::Reader const & reader, Dependencies * dependencies)
1822 : {
1823 : OSL_ASSERT(dependencies != 0);
1824 0 : if (reader.getMethodCount() != 0)
1825 : {
1826 : throw CannotDumpException(
1827 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1828 : //TODO
1829 : }
1830 0 : RTTypeClass typeClass = reader.getTypeClass();
1831 0 : rtl::OString className(codemaker::convertString(reader.getTypeName()));
1832 0 : sal_uInt16 superTypes = reader.getSuperTypeCount();
1833 0 : sal_uInt16 fields = reader.getFieldCount();
1834 0 : sal_uInt16 firstField = 0;
1835 0 : sal_uInt16 references = reader.getReferenceCount();
1836 0 : bool runtimeException = false;
1837 0 : rtl::OString superClass;
1838 0 : if (className
1839 : == rtl::OString(
1840 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Exception")))
1841 : {
1842 0 : if (typeClass != RT_TYPE_EXCEPTION || superTypes != 0 || fields != 2
1843 : || references != 0)
1844 : {
1845 : throw CannotDumpException(
1846 : rtl::OString(
1847 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1848 : }
1849 0 : firstField = 1;
1850 : superClass = rtl::OString(
1851 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Exception"));
1852 0 : } else if (className
1853 : == rtl::OString(
1854 : RTL_CONSTASCII_STRINGPARAM(
1855 0 : "com/sun/star/uno/RuntimeException")))
1856 : {
1857 0 : if (typeClass != RT_TYPE_EXCEPTION || superTypes != 1 || fields != 0
1858 : || references != 0)
1859 : {
1860 : throw CannotDumpException(
1861 : rtl::OString(
1862 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1863 : }
1864 0 : superTypes = 0;
1865 : superClass = rtl::OString(
1866 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/RuntimeException"));
1867 0 : runtimeException = true;
1868 : } else {
1869 0 : if (
1870 : (
1871 : typeClass == RT_TYPE_STRUCT &&
1872 : (
1873 : fields == 0 ||
1874 : (references == 0 ? superTypes > 1 : superTypes != 0)
1875 : )
1876 : ) ||
1877 : (typeClass == RT_TYPE_EXCEPTION && superTypes != 1)
1878 : )
1879 : {
1880 : throw CannotDumpException(
1881 : rtl::OString(
1882 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1883 : }
1884 0 : if (superTypes == 0) {
1885 : superClass = rtl::OString(
1886 0 : RTL_CONSTASCII_STRINGPARAM("java/lang/Object"));
1887 : } else {
1888 0 : superClass = codemaker::convertString(reader.getSuperTypeName(0));
1889 0 : dependencies->insert(superClass);
1890 : }
1891 : }
1892 0 : rtl::OString sig;
1893 0 : std::map< rtl::OString, sal_Int32 > typeParameters;
1894 0 : if (references != 0) {
1895 0 : rtl::OStringBuffer buf;
1896 0 : buf.append('<');
1897 0 : for (sal_uInt16 i = 0; i < references; ++i) {
1898 0 : if (reader.getReferenceFlags(i) != RT_ACCESS_INVALID
1899 0 : || reader.getReferenceSort(i) != RT_REF_TYPE_PARAMETER)
1900 : {
1901 : throw CannotDumpException(
1902 : rtl::OString(
1903 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1904 : //TODO
1905 : }
1906 : rtl::OString name(
1907 0 : codemaker::convertString(reader.getReferenceTypeName(i)));
1908 0 : buf.append(name);
1909 0 : buf.append(RTL_CONSTASCII_STRINGPARAM(":Ljava/lang/Object;"));
1910 0 : if (!typeParameters.insert(
1911 0 : std::map< rtl::OString, sal_Int32 >::value_type(name, i)).
1912 0 : second)
1913 : {
1914 : throw CannotDumpException(
1915 : rtl::OString(
1916 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1917 : //TODO
1918 : }
1919 0 : }
1920 0 : buf.append(RTL_CONSTASCII_STRINGPARAM(">Ljava/lang/Object;"));
1921 0 : sig = buf.makeStringAndClear();
1922 : }
1923 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1924 : std::auto_ptr< ClassFile > cf(
1925 : new ClassFile(
1926 : static_cast< ClassFile::AccessFlags >(
1927 : ClassFile::ACC_PUBLIC | ClassFile::ACC_SUPER),
1928 0 : className, superClass, sig));
1929 : SAL_WNODEPRECATED_DECLARATIONS_POP
1930 0 : std::vector< TypeInfo > typeInfo;
1931 0 : {for (sal_uInt16 i = firstField; i < fields; ++i) {
1932 0 : RTFieldAccess flags = reader.getFieldFlags(i);
1933 0 : if ((flags != RT_ACCESS_READWRITE
1934 : && flags != (RT_ACCESS_READWRITE | RT_ACCESS_PARAMETERIZED_TYPE))
1935 : || ((flags & RT_ACCESS_PARAMETERIZED_TYPE) != 0 && references == 0)
1936 : || reader.getFieldValue(i).m_type != RT_TYPE_NONE)
1937 : {
1938 : throw CannotDumpException(
1939 : rtl::OString(
1940 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
1941 : }
1942 : rtl::OString type(
1943 0 : codemaker::convertString(reader.getFieldTypeName(i)));
1944 : sal_Int32 typeParameterIndex;
1945 0 : if ((flags & RT_ACCESS_PARAMETERIZED_TYPE) == 0) {
1946 0 : typeParameterIndex = -1;
1947 : } else {
1948 : std::map< rtl::OString, sal_Int32 >::iterator it(
1949 0 : typeParameters.find(type));
1950 0 : if (it == typeParameters.end()) {
1951 : throw CannotDumpException(
1952 : rtl::OString(
1953 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information")));
1954 : //TODO
1955 : }
1956 0 : typeParameterIndex = it->second;
1957 : }
1958 : addField(
1959 : manager, dependencies, cf.get(), &typeInfo, typeParameterIndex,
1960 0 : type, codemaker::convertString(reader.getFieldName(i)), i - firstField);
1961 0 : }}
1962 0 : if (runtimeException) {
1963 : addField(
1964 : manager, dependencies, cf.get(), &typeInfo, -1,
1965 : rtl::OString(
1966 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XInterface")),
1967 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Context")), 0);
1968 : }
1969 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1970 0 : std::auto_ptr< ClassFile::Code > code(cf->newCode());
1971 : SAL_WNODEPRECATED_DECLARATIONS_POP
1972 0 : code->loadLocalReference(0);
1973 : code->instrInvokespecial(
1974 : superClass, rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
1975 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")));
1976 0 : sal_uInt16 stack = 0;
1977 0 : {for (sal_uInt16 i = firstField; i < fields; ++i) {
1978 : stack = std::max(
1979 : stack,
1980 : addFieldInit(
1981 : manager, className,
1982 : codemaker::convertString(reader.getFieldName(i)),
1983 0 : (reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) != 0,
1984 : codemaker::convertString(reader.getFieldTypeName(i)),
1985 0 : dependencies, code.get()));
1986 : }}
1987 0 : if (runtimeException) {
1988 : stack = std::max(
1989 : stack,
1990 : addFieldInit(
1991 : manager, className,
1992 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Context")), false,
1993 : rtl::OString(
1994 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XInterface")),
1995 0 : dependencies, code.get()));
1996 : }
1997 0 : code->instrReturn();
1998 0 : code->setMaxStackAndLocals(stack + 1, 1);
1999 : cf->addMethod(
2000 : ClassFile::ACC_PUBLIC,
2001 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2002 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("()V")), code.get(),
2003 0 : std::vector< rtl::OString >(), rtl::OString());
2004 0 : if (typeClass == RT_TYPE_EXCEPTION) {
2005 0 : code.reset(cf->newCode());
2006 0 : code->loadLocalReference(0);
2007 0 : code->loadLocalReference(1);
2008 : code->instrInvokespecial(
2009 : superClass, rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2010 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;)V")));
2011 0 : stack = 0;
2012 0 : for (sal_uInt16 i = firstField; i < fields; ++i) {
2013 : stack = std::max(
2014 : stack,
2015 : addFieldInit(
2016 : manager, className,
2017 : codemaker::convertString(reader.getFieldName(i)),
2018 0 : ((reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE)
2019 : != 0),
2020 : codemaker::convertString(reader.getFieldTypeName(i)),
2021 0 : dependencies, code.get()));
2022 : }
2023 0 : if (runtimeException) {
2024 : stack = std::max(
2025 : stack,
2026 : addFieldInit(
2027 : manager, className,
2028 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Context")), false,
2029 : rtl::OString(
2030 : RTL_CONSTASCII_STRINGPARAM(
2031 : "com/sun/star/uno/XInterface")),
2032 0 : dependencies, code.get()));
2033 : }
2034 0 : code->instrReturn();
2035 0 : code->setMaxStackAndLocals(stack + 2, 2);
2036 : cf->addMethod(
2037 : ClassFile::ACC_PUBLIC,
2038 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2039 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("(Ljava/lang/String;)V")),
2040 0 : code.get(), std::vector< rtl::OString >(), rtl::OString());
2041 : }
2042 : MethodDescriptor desc(
2043 : manager, dependencies, rtl::OString(RTL_CONSTASCII_STRINGPARAM("void")),
2044 0 : 0, 0);
2045 0 : code.reset(cf->newCode());
2046 0 : code->loadLocalReference(0);
2047 0 : sal_uInt16 index = 1;
2048 0 : if (typeClass == RT_TYPE_EXCEPTION) {
2049 : desc.addParameter(
2050 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("string")), false, true, 0);
2051 0 : code->loadLocalReference(index++);
2052 : }
2053 0 : if (superTypes != 0) {
2054 : addBaseArguments(
2055 : manager, dependencies, &desc, code.get(), typeClass, superClass,
2056 0 : &index);
2057 : }
2058 : code->instrInvokespecial(
2059 : superClass, rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2060 0 : desc.getDescriptor());
2061 0 : sal_uInt16 maxSize = index;
2062 0 : {for (sal_uInt16 i = firstField; i < fields; ++i) {
2063 : maxSize = std::max(
2064 : maxSize,
2065 : addDirectArgument(
2066 : manager, dependencies, &desc, code.get(), &index, className,
2067 : codemaker::convertString(reader.getFieldName(i)),
2068 0 : (reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) != 0,
2069 0 : codemaker::convertString(reader.getFieldTypeName(i))));
2070 : }}
2071 0 : if (runtimeException) {
2072 : maxSize = std::max(
2073 : maxSize,
2074 : addDirectArgument(
2075 : manager, dependencies, &desc, code.get(), &index, className,
2076 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Context")), false,
2077 : rtl::OString(
2078 : RTL_CONSTASCII_STRINGPARAM(
2079 0 : "com/sun/star/uno/XInterface"))));
2080 : }
2081 0 : code->instrReturn();
2082 0 : code->setMaxStackAndLocals(maxSize, index);
2083 : cf->addMethod(
2084 : ClassFile::ACC_PUBLIC,
2085 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2086 0 : desc.getDescriptor(), code.get(), std::vector< rtl::OString >(),
2087 0 : desc.getSignature());
2088 0 : addTypeInfo(className, typeInfo, dependencies, cf.get());
2089 0 : writeClassFile(options, className, *cf.get());
2090 0 : }
2091 :
2092 0 : void createExceptionsAttribute(
2093 : TypeManager const & manager, typereg::Reader const & reader,
2094 : sal_uInt16 methodIndex, Dependencies * dependencies,
2095 : std::vector< rtl::OString > * exceptions, codemaker::ExceptionTree * tree)
2096 : {
2097 : OSL_ASSERT(dependencies != 0 && exceptions != 0);
2098 0 : sal_uInt16 n = reader.getMethodExceptionCount(methodIndex);
2099 0 : for (sal_uInt16 i = 0; i < n; ++i) {
2100 : rtl::OString type(
2101 : codemaker::convertString(
2102 0 : reader.getMethodExceptionTypeName(methodIndex, i)));
2103 0 : dependencies->insert(type);
2104 0 : exceptions->push_back(type);
2105 0 : if (tree != 0) {
2106 0 : tree->add(type, manager);
2107 : }
2108 0 : }
2109 0 : }
2110 :
2111 0 : void handleInterfaceType(
2112 : TypeManager const & manager, JavaOptions /*TODO const*/ & options,
2113 : typereg::Reader const & reader, Dependencies * dependencies)
2114 : {
2115 : OSL_ASSERT(dependencies != 0);
2116 :
2117 0 : rtl::OString className(codemaker::convertString(reader.getTypeName()));
2118 0 : sal_uInt16 superTypes = reader.getSuperTypeCount();
2119 0 : sal_uInt16 fields = reader.getFieldCount();
2120 0 : sal_uInt16 methods = reader.getMethodCount();
2121 0 : if (className
2122 : == rtl::OString(
2123 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XInterface")))
2124 : {
2125 0 : if (superTypes != 0 || fields != 0 || methods != 3) {
2126 : throw CannotDumpException(
2127 : rtl::OString(
2128 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2129 : }
2130 0 : methods = 0;
2131 0 : } else if (superTypes == 0) {
2132 : throw CannotDumpException(
2133 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2134 : //TODO
2135 : }
2136 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2137 : std::auto_ptr< ClassFile > cf(
2138 : new ClassFile(
2139 : static_cast< ClassFile::AccessFlags >(
2140 : ClassFile::ACC_PUBLIC | ClassFile::ACC_INTERFACE
2141 : | ClassFile::ACC_ABSTRACT),
2142 : className,
2143 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
2144 0 : rtl::OString()));
2145 : SAL_WNODEPRECATED_DECLARATIONS_POP
2146 0 : {for (sal_uInt16 i = 0; i < superTypes; ++i) {
2147 0 : rtl::OString t(codemaker::convertString(reader.getSuperTypeName(i)));
2148 0 : dependencies->insert(t);
2149 0 : cf->addInterface(t);
2150 0 : }}
2151 : // As a special case, let com.sun.star.lang.XEventListener extend
2152 : // java.util.EventListener ("A tagging interface that all event listener
2153 : // interfaces must extend"):
2154 0 : if (className ==
2155 : rtl::OString(
2156 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/lang/XEventListener")))
2157 : {
2158 : cf->addInterface(
2159 : rtl::OString(
2160 0 : RTL_CONSTASCII_STRINGPARAM("java/util/EventListener")));
2161 : }
2162 0 : std::vector< TypeInfo > typeInfo;
2163 0 : sal_Int32 index = 0;
2164 0 : {for (sal_uInt16 i = 0; i < fields; ++i) {
2165 0 : RTFieldAccess flags = reader.getFieldFlags(i);
2166 : //TODO: ok if both READONLY and BOUND?
2167 0 : if (((((flags & RT_ACCESS_READWRITE) != 0)
2168 : ^ ((flags & RT_ACCESS_READONLY) != 0))
2169 : == 0)
2170 : || ((flags
2171 : & ~(RT_ACCESS_READWRITE | RT_ACCESS_READONLY
2172 : | RT_ACCESS_BOUND))
2173 : != 0)
2174 : || reader.getFieldValue(i).m_type != RT_TYPE_NONE)
2175 : {
2176 : throw CannotDumpException(
2177 : rtl::OString(
2178 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2179 : }
2180 : //TODO: exploit the fact that attribute getter/setter methods preceed
2181 : // real methods
2182 0 : rtl::OUString attrNameUtf16(reader.getFieldName(i));
2183 0 : sal_uInt16 getter = SAL_MAX_UINT16;
2184 0 : sal_uInt16 setter = SAL_MAX_UINT16;
2185 0 : for (sal_uInt16 j = 0; j < methods; ++j) {
2186 0 : RTMethodMode mflags = reader.getMethodFlags(j);
2187 0 : if ((mflags == RT_MODE_ATTRIBUTE_GET
2188 : || mflags == RT_MODE_ATTRIBUTE_SET)
2189 0 : && reader.getMethodName(j) == attrNameUtf16)
2190 : {
2191 0 : if (reader.getMethodReturnTypeName(j) != "void"
2192 0 : || reader.getMethodParameterCount(j) != 0
2193 : || (mflags == RT_MODE_ATTRIBUTE_GET
2194 : ? getter != SAL_MAX_UINT16
2195 : : (setter != SAL_MAX_UINT16
2196 : || (flags & RT_ACCESS_READONLY) != 0)))
2197 : {
2198 : throw CannotDumpException(
2199 : rtl::OString(
2200 : RTL_CONSTASCII_STRINGPARAM(
2201 0 : "Bad type information"))); //TODO
2202 : }
2203 : OSL_ASSERT(j != SAL_MAX_UINT16);
2204 0 : (mflags == RT_MODE_ATTRIBUTE_GET ? getter : setter) = j;
2205 : }
2206 : }
2207 : rtl::OString fieldType(
2208 0 : codemaker::convertString(reader.getFieldTypeName(i)));
2209 : SpecialType specialType;
2210 0 : PolymorphicUnoType polymorphicUnoType;
2211 : MethodDescriptor gdesc(
2212 : manager, dependencies, fieldType, &specialType,
2213 0 : &polymorphicUnoType);
2214 0 : std::vector< rtl::OString > exc;
2215 0 : if (getter != SAL_MAX_UINT16) {
2216 : createExceptionsAttribute(
2217 0 : manager, reader, getter, dependencies, &exc, 0);
2218 : }
2219 0 : rtl::OString attrName(codemaker::convertString(attrNameUtf16));
2220 : cf->addMethod(
2221 : static_cast< ClassFile::AccessFlags >(
2222 : ClassFile::ACC_PUBLIC | ClassFile::ACC_ABSTRACT),
2223 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("get")) + attrName,
2224 0 : gdesc.getDescriptor(), 0, exc, gdesc.getSignature());
2225 0 : if ((flags & RT_ACCESS_READONLY) == 0) {
2226 : MethodDescriptor sdesc(
2227 : manager, dependencies,
2228 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("void")), 0, 0);
2229 0 : sdesc.addParameter(fieldType, false, true, 0);
2230 0 : std::vector< rtl::OString > exc2;
2231 0 : if (setter != SAL_MAX_UINT16) {
2232 : createExceptionsAttribute(
2233 0 : manager, reader, setter, dependencies, &exc2, 0);
2234 : }
2235 : cf->addMethod(
2236 : static_cast< ClassFile::AccessFlags >(
2237 : ClassFile::ACC_PUBLIC | ClassFile::ACC_ABSTRACT),
2238 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("set")) + attrName,
2239 0 : sdesc.getDescriptor(), 0, exc2, sdesc.getSignature());
2240 : }
2241 : typeInfo.push_back(
2242 : TypeInfo(
2243 : TypeInfo::KIND_ATTRIBUTE, attrName, specialType,
2244 : static_cast< TypeInfo::Flags >(
2245 : ((flags & RT_ACCESS_READONLY) == 0
2246 : ? 0 : TypeInfo::FLAG_READONLY)
2247 : | ((flags & RT_ACCESS_BOUND) == 0
2248 : ? 0 : TypeInfo::FLAG_BOUND)),
2249 0 : index, polymorphicUnoType));
2250 0 : index += ((flags & RT_ACCESS_READONLY) == 0 ? 2 : 1);
2251 0 : }}
2252 0 : {for (sal_uInt16 i = 0; i < methods; ++i) {
2253 0 : RTMethodMode flags = reader.getMethodFlags(i);
2254 0 : switch (flags) {
2255 : case RT_MODE_ONEWAY:
2256 : case RT_MODE_TWOWAY:
2257 : {
2258 : rtl::OString methodName(
2259 0 : codemaker::convertString(reader.getMethodName(i)));
2260 : SpecialType specialReturnType;
2261 0 : PolymorphicUnoType polymorphicUnoReturnType;
2262 : MethodDescriptor desc(
2263 : manager, dependencies,
2264 : codemaker::convertString(
2265 : reader.getMethodReturnTypeName(i)),
2266 0 : &specialReturnType, &polymorphicUnoReturnType);
2267 : typeInfo.push_back(
2268 : TypeInfo(
2269 : TypeInfo::KIND_METHOD, methodName, specialReturnType,
2270 : static_cast< TypeInfo::Flags >(
2271 : flags == RT_MODE_ONEWAY
2272 : ? TypeInfo::FLAG_ONEWAY : 0),
2273 0 : index++, polymorphicUnoReturnType));
2274 0 : for (sal_uInt16 j = 0; j < reader.getMethodParameterCount(i);
2275 : ++j)
2276 : {
2277 : bool in;
2278 : bool out;
2279 0 : switch (reader.getMethodParameterFlags(i, j)) {
2280 : case RT_PARAM_IN:
2281 0 : in = true;
2282 0 : out = false;
2283 0 : break;
2284 :
2285 : case RT_PARAM_OUT:
2286 0 : in = false;
2287 0 : out = true;
2288 0 : break;
2289 :
2290 : case RT_PARAM_INOUT:
2291 0 : in = true;
2292 0 : out = true;
2293 0 : break;
2294 :
2295 : default:
2296 : throw CannotDumpException(
2297 : rtl::OString(
2298 : RTL_CONSTASCII_STRINGPARAM(
2299 0 : "Bad type information"))); //TODO
2300 : }
2301 0 : PolymorphicUnoType polymorphicUnoType;
2302 : SpecialType specialType = desc.addParameter(
2303 : codemaker::convertString(
2304 : reader.getMethodParameterTypeName(i, j)),
2305 0 : out, true, &polymorphicUnoType);
2306 0 : if (out || isSpecialType(specialType)
2307 : || (polymorphicUnoType.kind
2308 : != PolymorphicUnoType::KIND_NONE))
2309 : {
2310 : typeInfo.push_back(
2311 : TypeInfo(
2312 : codemaker::convertString(
2313 : reader.getMethodParameterName(i, j)),
2314 : specialType, in, out, methodName, j,
2315 0 : polymorphicUnoType));
2316 : }
2317 0 : }
2318 0 : std::vector< rtl::OString > exc2;
2319 : createExceptionsAttribute(
2320 0 : manager, reader, i, dependencies, &exc2, 0);
2321 : cf->addMethod(
2322 : static_cast< ClassFile::AccessFlags >(
2323 : ClassFile::ACC_PUBLIC | ClassFile::ACC_ABSTRACT),
2324 : methodName, desc.getDescriptor(), 0, exc2,
2325 0 : desc.getSignature());
2326 0 : break;
2327 : }
2328 :
2329 : case RT_MODE_ATTRIBUTE_GET:
2330 : case RT_MODE_ATTRIBUTE_SET:
2331 : {
2332 : //TODO: exploit the fact that attribute getter/setter methods
2333 : // are ordered the same way as the attribute fields themselves
2334 0 : rtl::OUString methodNameUtf16(reader.getMethodName(i));
2335 0 : bool found = false;
2336 0 : for (sal_uInt16 j = 0; j < fields; ++j) {
2337 0 : if (reader.getFieldName(j) == methodNameUtf16) {
2338 0 : found = true;
2339 0 : break;
2340 : }
2341 : }
2342 0 : if (found) {
2343 : break;
2344 0 : }
2345 : }
2346 : default:
2347 : throw CannotDumpException(
2348 : rtl::OString(
2349 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2350 : }
2351 : }}
2352 0 : addTypeInfo(className, typeInfo, dependencies, cf.get());
2353 0 : writeClassFile(options, className, *cf.get());
2354 0 : }
2355 :
2356 0 : void handleTypedef(
2357 : TypeManager const & manager,
2358 : SAL_UNUSED_PARAMETER JavaOptions /*TODO const*/ &,
2359 : typereg::Reader const & reader, Dependencies * dependencies)
2360 : {
2361 : OSL_ASSERT(dependencies != 0);
2362 0 : if (reader.getSuperTypeCount() != 1 || reader.getFieldCount() != 0
2363 0 : || reader.getMethodCount() != 0 || reader.getReferenceCount() != 0)
2364 : {
2365 : throw CannotDumpException(
2366 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2367 : //TODO
2368 : }
2369 : RTTypeClass typeClass;
2370 0 : rtl::OString nucleus;
2371 : sal_Int32 rank;
2372 0 : std::vector< rtl::OString > args;
2373 0 : if (codemaker::decomposeAndResolve(
2374 : manager, codemaker::convertString(reader.getSuperTypeName(0)),
2375 0 : false, false, false, &typeClass, &nucleus, &rank, &args)
2376 : == codemaker::UnoType::SORT_COMPLEX)
2377 : {
2378 0 : switch (typeClass) {
2379 : case RT_TYPE_STRUCT:
2380 0 : if (!args.empty()) {
2381 : throw CannotDumpException(
2382 : rtl::OString(
2383 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2384 : //TODO
2385 : }
2386 : case RT_TYPE_ENUM:
2387 : case RT_TYPE_INTERFACE:
2388 : case RT_TYPE_TYPEDEF:
2389 0 : dependencies->insert(nucleus);
2390 0 : break;
2391 :
2392 : default:
2393 : OSL_ASSERT(false);
2394 0 : break;
2395 : }
2396 0 : }
2397 0 : }
2398 :
2399 0 : void addConstant(
2400 : TypeManager const & manager, typereg::Reader const & reader,
2401 : bool publishable, sal_uInt16 index, Dependencies * dependencies,
2402 : ClassFile * classFile)
2403 : {
2404 : OSL_ASSERT(dependencies != 0 && classFile != 0);
2405 0 : RTFieldAccess flags = reader.getFieldFlags(index);
2406 0 : if (flags != RT_ACCESS_CONST
2407 0 : && (!publishable || flags != (RT_ACCESS_CONST | RT_ACCESS_PUBLISHED)))
2408 : {
2409 : throw CannotDumpException(
2410 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2411 : //TODO
2412 : }
2413 0 : RTConstValue fieldValue(reader.getFieldValue(index));
2414 : sal_uInt16 valueIndex;
2415 : RTTypeClass typeClass;
2416 0 : rtl::OString nucleus;
2417 : sal_Int32 rank;
2418 0 : std::vector< rtl::OString > args;
2419 0 : switch (codemaker::decomposeAndResolve(
2420 : manager,
2421 : codemaker::convertString(reader.getFieldTypeName(index)),
2422 0 : true, false, false, &typeClass, &nucleus, &rank, &args))
2423 : {
2424 : case codemaker::UnoType::SORT_BOOLEAN:
2425 0 : if (fieldValue.m_type != RT_TYPE_BOOL) {
2426 : throw CannotDumpException(
2427 : rtl::OString(
2428 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2429 : }
2430 0 : valueIndex = classFile->addIntegerInfo(fieldValue.m_value.aBool);
2431 0 : break;
2432 :
2433 : case codemaker::UnoType::SORT_BYTE:
2434 0 : if (fieldValue.m_type != RT_TYPE_BYTE) {
2435 : throw CannotDumpException(
2436 : rtl::OString(
2437 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2438 : }
2439 0 : valueIndex = classFile->addIntegerInfo(fieldValue.m_value.aByte);
2440 0 : break;
2441 :
2442 : case codemaker::UnoType::SORT_SHORT:
2443 0 : if (fieldValue.m_type != RT_TYPE_INT16) {
2444 : throw CannotDumpException(
2445 : rtl::OString(
2446 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2447 : }
2448 0 : valueIndex = classFile->addIntegerInfo(fieldValue.m_value.aShort);
2449 0 : break;
2450 :
2451 : case codemaker::UnoType::SORT_UNSIGNED_SHORT:
2452 : case codemaker::UnoType::SORT_CHAR:
2453 0 : if (fieldValue.m_type != RT_TYPE_UINT16) {
2454 : throw CannotDumpException(
2455 : rtl::OString(
2456 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2457 : }
2458 0 : valueIndex = classFile->addIntegerInfo(fieldValue.m_value.aUShort);
2459 0 : break;
2460 :
2461 : case codemaker::UnoType::SORT_LONG:
2462 0 : if (fieldValue.m_type != RT_TYPE_INT32) {
2463 : throw CannotDumpException(
2464 : rtl::OString(
2465 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2466 : }
2467 0 : valueIndex = classFile->addIntegerInfo(fieldValue.m_value.aLong);
2468 0 : break;
2469 :
2470 : case codemaker::UnoType::SORT_UNSIGNED_LONG:
2471 0 : if (fieldValue.m_type != RT_TYPE_UINT32) {
2472 : throw CannotDumpException(
2473 : rtl::OString(
2474 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2475 : }
2476 : valueIndex = classFile->addIntegerInfo(
2477 0 : static_cast< sal_Int32 >(fieldValue.m_value.aULong));
2478 0 : break;
2479 :
2480 : case codemaker::UnoType::SORT_HYPER:
2481 0 : if (fieldValue.m_type != RT_TYPE_INT64) {
2482 : throw CannotDumpException(
2483 : rtl::OString(
2484 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2485 : }
2486 0 : valueIndex = classFile->addLongInfo(fieldValue.m_value.aHyper);
2487 0 : break;
2488 :
2489 : case codemaker::UnoType::SORT_UNSIGNED_HYPER:
2490 0 : if (fieldValue.m_type != RT_TYPE_UINT64) {
2491 : throw CannotDumpException(
2492 : rtl::OString(
2493 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2494 : }
2495 : valueIndex = classFile->addLongInfo(
2496 0 : static_cast< sal_Int64 >(fieldValue.m_value.aUHyper));
2497 0 : break;
2498 :
2499 : case codemaker::UnoType::SORT_FLOAT:
2500 0 : if (fieldValue.m_type != RT_TYPE_FLOAT) {
2501 : throw CannotDumpException(
2502 : rtl::OString(
2503 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2504 : }
2505 0 : valueIndex = classFile->addFloatInfo(fieldValue.m_value.aFloat);
2506 0 : break;
2507 :
2508 : case codemaker::UnoType::SORT_DOUBLE:
2509 0 : if (fieldValue.m_type != RT_TYPE_DOUBLE) {
2510 : throw CannotDumpException(
2511 : rtl::OString(
2512 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information"))); //TODO
2513 : }
2514 0 : valueIndex = classFile->addDoubleInfo(fieldValue.m_value.aDouble);
2515 0 : break;
2516 :
2517 : default:
2518 : throw CannotDumpException(
2519 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2520 : //TODO
2521 : }
2522 0 : rtl::OString desc;
2523 0 : rtl::OString sig;
2524 : getFieldDescriptor(
2525 : manager, dependencies,
2526 : codemaker::convertString(reader.getFieldTypeName(index)),
2527 0 : &desc, &sig, 0);
2528 : classFile->addField(
2529 : static_cast< ClassFile::AccessFlags >(
2530 : ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC
2531 : | ClassFile::ACC_FINAL),
2532 : codemaker::convertString(reader.getFieldName(index)),
2533 0 : desc, valueIndex, sig);
2534 0 : }
2535 :
2536 0 : void handleConstantGroup(
2537 : TypeManager const & manager, JavaOptions /*TODO const*/ & options,
2538 : typereg::Reader const & reader, Dependencies * dependencies)
2539 : {
2540 : OSL_ASSERT(dependencies != 0);
2541 0 : if (reader.getSuperTypeCount() != 0 || reader.getMethodCount() != 0
2542 0 : || reader.getReferenceCount() != 0)
2543 : {
2544 : throw CannotDumpException(
2545 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2546 : //TODO
2547 : }
2548 0 : rtl::OString className(codemaker::convertString(reader.getTypeName()));
2549 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2550 : std::auto_ptr< ClassFile > cf(
2551 : new ClassFile(
2552 : static_cast< ClassFile::AccessFlags >(
2553 : ClassFile::ACC_PUBLIC | ClassFile::ACC_INTERFACE
2554 : | ClassFile::ACC_ABSTRACT),
2555 : className,
2556 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
2557 0 : rtl::OString()));
2558 : SAL_WNODEPRECATED_DECLARATIONS_POP
2559 0 : sal_uInt16 fields = reader.getFieldCount();
2560 0 : for (sal_uInt16 i = 0; i < fields; ++i) {
2561 0 : addConstant(manager, reader, false, i, dependencies, cf.get());
2562 : }
2563 0 : writeClassFile(options, className, *cf.get());
2564 0 : }
2565 :
2566 0 : void handleModule(
2567 : TypeManager const & manager, JavaOptions /*TODO const*/ & options,
2568 : typereg::Reader const & reader, Dependencies * dependencies)
2569 : {
2570 : OSL_ASSERT(dependencies != 0);
2571 0 : if (reader.getSuperTypeCount() != 0 || reader.getMethodCount() != 0
2572 0 : || reader.getReferenceCount() != 0)
2573 : {
2574 : throw CannotDumpException(
2575 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2576 : //TODO
2577 : }
2578 0 : rtl::OStringBuffer buf(codemaker::convertString(reader.getTypeName()));
2579 0 : buf.append('/');
2580 0 : rtl::OString prefix(buf.makeStringAndClear());
2581 0 : sal_uInt16 fields = reader.getFieldCount();
2582 0 : for (sal_uInt16 i = 0; i < fields; ++i) {
2583 : rtl::OString className(
2584 0 : prefix + codemaker::convertString(reader.getFieldName(i)));
2585 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2586 : std::auto_ptr< ClassFile > cf(
2587 : new ClassFile(
2588 : static_cast< ClassFile::AccessFlags >(
2589 : ClassFile::ACC_PUBLIC | ClassFile::ACC_INTERFACE
2590 : | ClassFile::ACC_ABSTRACT),
2591 : className,
2592 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
2593 0 : rtl::OString()));
2594 : SAL_WNODEPRECATED_DECLARATIONS_POP
2595 0 : addConstant(manager, reader, true, i, dependencies, cf.get());
2596 0 : writeClassFile(options, className, *cf.get());
2597 0 : }
2598 0 : }
2599 :
2600 0 : void addExceptionHandlers(
2601 : codemaker::ExceptionTreeNode const * node,
2602 : ClassFile::Code::Position start, ClassFile::Code::Position end,
2603 : ClassFile::Code::Position handler, ClassFile::Code * code)
2604 : {
2605 : OSL_ASSERT(node != 0 && code != 0);
2606 0 : if (node->present) {
2607 0 : code->addException(start, end, handler, node->name);
2608 : } else {
2609 0 : for (codemaker::ExceptionTreeNode::Children::const_iterator i(
2610 0 : node->children.begin());
2611 0 : i != node->children.end(); ++i)
2612 : {
2613 0 : addExceptionHandlers(*i, start, end, handler, code);
2614 : }
2615 : }
2616 0 : }
2617 :
2618 0 : void addConstructor(
2619 : TypeManager const & manager, rtl::OString const & realJavaBaseName,
2620 : rtl::OString const & unoName, rtl::OString const & className,
2621 : typereg::Reader const & reader, sal_uInt16 methodIndex,
2622 : rtl::OString const & methodName, rtl::OString const & returnType,
2623 : bool defaultConstructor, Dependencies * dependencies, ClassFile * classFile)
2624 : {
2625 : OSL_ASSERT(dependencies != 0 && classFile != 0);
2626 0 : MethodDescriptor desc(manager, dependencies, returnType, 0, 0);
2627 : desc.addParameter(
2628 : rtl::OString(
2629 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")),
2630 0 : false, false, 0);
2631 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2632 0 : std::auto_ptr< ClassFile::Code > code(classFile->newCode());
2633 : SAL_WNODEPRECATED_DECLARATIONS_POP
2634 0 : code->loadLocalReference(0);
2635 : // stack: context
2636 : code->instrInvokeinterface(
2637 : rtl::OString(
2638 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")),
2639 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("getServiceManager")),
2640 : rtl::OString(
2641 : RTL_CONSTASCII_STRINGPARAM(
2642 : "()Lcom/sun/star/lang/XMultiComponentFactory;")),
2643 0 : 1);
2644 : // stack: factory
2645 0 : code->loadStringConstant(unoName);
2646 : // stack: factory serviceName
2647 0 : codemaker::ExceptionTree tree;
2648 : ClassFile::Code::Position tryStart;
2649 : ClassFile::Code::Position tryEnd;
2650 0 : std::vector< rtl::OString > exc;
2651 : sal_uInt16 stack;
2652 0 : sal_uInt16 localIndex = 1;
2653 : ClassFile::AccessFlags access = static_cast< ClassFile::AccessFlags >(
2654 0 : ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC);
2655 0 : if (defaultConstructor) {
2656 0 : code->loadLocalReference(0);
2657 : // stack: factory serviceName context
2658 0 : tryStart = code->getPosition();
2659 : code->instrInvokeinterface(
2660 : rtl::OString(
2661 : RTL_CONSTASCII_STRINGPARAM(
2662 : "com/sun/star/lang/XMultiComponentFactory")),
2663 : rtl::OString(
2664 : RTL_CONSTASCII_STRINGPARAM(
2665 : "createInstanceWithContext")),
2666 : rtl::OString(
2667 : RTL_CONSTASCII_STRINGPARAM(
2668 : "(Ljava/lang/String;Lcom/sun/star/uno/XComponentContext;)"
2669 : "Ljava/lang/Object;")),
2670 0 : 3);
2671 0 : tryEnd = code->getPosition();
2672 : // stack: instance
2673 0 : stack = 3;
2674 : } else {
2675 0 : sal_uInt16 parameters = reader.getMethodParameterCount(methodIndex);
2676 0 : if (parameters == 1
2677 0 : && (reader.getMethodParameterFlags(methodIndex, 0)
2678 : == (RT_PARAM_IN | RT_PARAM_REST))
2679 : && (reader.getMethodParameterTypeName(methodIndex, 0)
2680 0 : == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any"))))
2681 : {
2682 : desc.addParameter(
2683 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("any")), true, true, 0);
2684 0 : code->loadLocalReference(localIndex++);
2685 : // stack: factory serviceName args
2686 0 : stack = 4;
2687 : access = static_cast< ClassFile::AccessFlags >(
2688 0 : access | ClassFile::ACC_VARARGS);
2689 : } else {
2690 0 : code->loadIntegerConstant(parameters);
2691 : // stack: factory serviceName N
2692 : code->instrAnewarray(
2693 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")));
2694 : // stack: factory serviceName args
2695 0 : stack = 0;
2696 0 : for (sal_uInt16 i = 0; i < parameters; ++i) {
2697 : RTParamMode flags = reader.getMethodParameterFlags(
2698 0 : methodIndex, i);
2699 : rtl::OString paramType(
2700 : codemaker::convertString(
2701 0 : reader.getMethodParameterTypeName(methodIndex, i)));
2702 0 : if ((flags != RT_PARAM_IN
2703 : && flags != (RT_PARAM_IN | RT_PARAM_REST))
2704 : || ((flags & RT_PARAM_REST) != 0
2705 : && (parameters != 1
2706 : || (paramType
2707 : != rtl::OString(
2708 0 : RTL_CONSTASCII_STRINGPARAM("any"))))))
2709 : {
2710 : throw CannotDumpException(
2711 : rtl::OString(
2712 : RTL_CONSTASCII_STRINGPARAM(
2713 0 : "Bad type information"))); //TODO
2714 : }
2715 0 : desc.addParameter(paramType, false, true, 0);
2716 0 : code->instrDup();
2717 : // stack: factory serviceName args args
2718 0 : code->loadIntegerConstant(i);
2719 : // stack: factory serviceName args args i
2720 : stack = std::max(
2721 : stack,
2722 : addLoadLocal(
2723 : manager, code.get(), &localIndex, false, paramType,
2724 0 : true, dependencies));
2725 : // stack: factory serviceName args args i any
2726 0 : code->instrAastore();
2727 : // stack: factory serviceName args
2728 0 : }
2729 0 : stack += 5;
2730 : }
2731 0 : code->loadLocalReference(0);
2732 : // stack: factory serviceName args context
2733 0 : tryStart = code->getPosition();
2734 : code->instrInvokeinterface(
2735 : rtl::OString(
2736 : RTL_CONSTASCII_STRINGPARAM(
2737 : "com/sun/star/lang/XMultiComponentFactory")),
2738 : rtl::OString(
2739 : RTL_CONSTASCII_STRINGPARAM(
2740 : "createInstanceWithArgumentsAndContext")),
2741 : rtl::OString(
2742 : RTL_CONSTASCII_STRINGPARAM(
2743 : "(Ljava/lang/String;[Ljava/lang/Object;"
2744 : "Lcom/sun/star/uno/XComponentContext;)Ljava/lang/Object;")),
2745 0 : 4);
2746 0 : tryEnd = code->getPosition();
2747 : // stack: instance
2748 : createExceptionsAttribute(
2749 0 : manager, reader, methodIndex, dependencies, &exc, &tree);
2750 : }
2751 0 : code->loadLocalReference(0);
2752 : // stack: instance context
2753 : code->instrInvokestatic(
2754 : className, rtl::OString(RTL_CONSTASCII_STRINGPARAM("$castInstance")),
2755 : rtl::OString(
2756 : RTL_CONSTASCII_STRINGPARAM(
2757 : "(Ljava/lang/Object;Lcom/sun/star/uno/XComponentContext;)"
2758 0 : "Ljava/lang/Object;")));
2759 : // stack: instance
2760 0 : code->instrCheckcast(returnType);
2761 : // stack: instance
2762 0 : code->instrAreturn();
2763 0 : if (!tree.getRoot()->present) {
2764 0 : ClassFile::Code::Position pos1 = code->getPosition();
2765 : // stack: e
2766 : code->instrInvokevirtual(
2767 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Throwable")),
2768 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("toString")),
2769 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("()Ljava/lang/String;")));
2770 : // stack: str
2771 0 : localIndex = std::max< sal_uInt16 >(localIndex, 2);
2772 0 : code->storeLocalReference(1);
2773 : // stack: -
2774 : code->instrNew(
2775 : rtl::OString(
2776 : RTL_CONSTASCII_STRINGPARAM(
2777 0 : "com/sun/star/uno/DeploymentException")));
2778 : // stack: ex
2779 0 : code->instrDup();
2780 : // stack: ex ex
2781 0 : rtl::OStringBuffer msg;
2782 : msg.append(
2783 : RTL_CONSTASCII_STRINGPARAM(
2784 0 : "component context fails to supply service "));
2785 0 : msg.append(unoName);
2786 0 : msg.append(RTL_CONSTASCII_STRINGPARAM(" of type "));
2787 0 : msg.append(realJavaBaseName);
2788 0 : msg.append(RTL_CONSTASCII_STRINGPARAM(": "));
2789 0 : code->loadStringConstant(msg.makeStringAndClear());
2790 : // stack: ex ex "..."
2791 0 : code->loadLocalReference(1);
2792 : // stack: ex ex "..." str
2793 : code->instrInvokevirtual(
2794 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/String")),
2795 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("concat")),
2796 : rtl::OString(
2797 : RTL_CONSTASCII_STRINGPARAM(
2798 0 : "(Ljava/lang/String;)Ljava/lang/String;")));
2799 : // stack: ex ex "..."
2800 0 : code->loadLocalReference(0);
2801 : // stack: ex ex "..." context
2802 : code->instrInvokespecial(
2803 : rtl::OString(
2804 : RTL_CONSTASCII_STRINGPARAM(
2805 : "com/sun/star/uno/DeploymentException")),
2806 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2807 : rtl::OString(
2808 : RTL_CONSTASCII_STRINGPARAM(
2809 0 : "(Ljava/lang/String;Ljava/lang/Object;)V")));
2810 : // stack: ex
2811 0 : ClassFile::Code::Position pos2 = code->getPosition();
2812 0 : code->instrAthrow();
2813 : addExceptionHandlers(
2814 0 : tree.getRoot(), tryStart, tryEnd, pos2, code.get());
2815 : code->addException(
2816 : tryStart, tryEnd, pos1,
2817 : rtl::OString(
2818 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Exception")));
2819 : dependencies->insert(
2820 : rtl::OString(
2821 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Exception")));
2822 0 : stack = std::max< sal_uInt16 >(stack, 4);
2823 : }
2824 0 : code->setMaxStackAndLocals(stack, localIndex);
2825 : classFile->addMethod(
2826 0 : access, methodName, desc.getDescriptor(), code.get(), exc,
2827 0 : desc.getSignature());
2828 0 : }
2829 :
2830 0 : void handleService(
2831 : TypeManager const & manager, JavaOptions /*TODO const*/ & options,
2832 : typereg::Reader const & reader, Dependencies * dependencies)
2833 : {
2834 : OSL_ASSERT(dependencies != 0);
2835 0 : sal_uInt16 superTypes = reader.getSuperTypeCount();
2836 0 : sal_uInt16 methods = reader.getMethodCount();
2837 0 : if (superTypes == 0
2838 : ? methods != 0
2839 0 : : (superTypes != 1 || reader.getFieldCount() != 0
2840 0 : || reader.getReferenceCount() != 0))
2841 : {
2842 : throw CannotDumpException(
2843 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2844 : //TODO
2845 : }
2846 0 : if (superTypes == 0) {
2847 0 : return;
2848 : }
2849 0 : rtl::OString unoName(codemaker::convertString(reader.getTypeName()));
2850 : rtl::OString className(
2851 : translateUnoTypeToJavaFullyQualifiedName(
2852 0 : unoName, rtl::OString(RTL_CONSTASCII_STRINGPARAM("service"))));
2853 0 : unoName = unoName.replace('/', '.');
2854 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2855 : std::auto_ptr< ClassFile > cf(
2856 : new ClassFile(
2857 : static_cast< ClassFile::AccessFlags >(
2858 : ClassFile::ACC_PUBLIC | ClassFile::ACC_FINAL
2859 : | ClassFile::ACC_SUPER),
2860 : className,
2861 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
2862 0 : rtl::OString()));
2863 : SAL_WNODEPRECATED_DECLARATIONS_POP
2864 0 : if (methods > 0) {
2865 : rtl::OString base(codemaker::convertString(
2866 0 : reader.getSuperTypeName(0)));
2867 0 : rtl::OString realJavaBaseName(base.replace('/', '.'));
2868 0 : dependencies->insert(base);
2869 : dependencies->insert(
2870 : rtl::OString(
2871 : RTL_CONSTASCII_STRINGPARAM(
2872 0 : "com/sun/star/lang/XMultiComponentFactory")));
2873 : dependencies->insert(
2874 : rtl::OString(
2875 : RTL_CONSTASCII_STRINGPARAM(
2876 0 : "com/sun/star/uno/DeploymentException")));
2877 : dependencies->insert(
2878 : rtl::OString(
2879 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")));
2880 : dependencies->insert(
2881 : rtl::OString(
2882 : RTL_CONSTASCII_STRINGPARAM(
2883 0 : "com/sun/star/uno/XComponentContext")));
2884 0 : for (sal_uInt16 i = 0; i < methods; ++i) {
2885 : rtl::OString name(codemaker::convertString(
2886 0 : reader.getMethodName(i)));
2887 0 : bool defaultCtor = name.getLength() == 0;
2888 0 : if (reader.getMethodFlags(i) != RT_MODE_TWOWAY
2889 0 : || (reader.getMethodReturnTypeName(i) != "void")
2890 : || (defaultCtor
2891 0 : && (methods != 1 || reader.getMethodParameterCount(i) != 0
2892 0 : || reader.getMethodExceptionCount(i) != 0)))
2893 : {
2894 : throw CannotDumpException(
2895 : rtl::OString(
2896 0 : RTL_CONSTASCII_STRINGPARAM("Bad type information")));
2897 : //TODO
2898 : }
2899 0 : if (defaultCtor) {
2900 0 : name = rtl::OString(RTL_CONSTASCII_STRINGPARAM("create"));
2901 : } else {
2902 : name = codemaker::java::translateUnoToJavaIdentifier(
2903 0 : name, rtl::OString(RTL_CONSTASCII_STRINGPARAM("method")));
2904 : }
2905 : addConstructor(
2906 : manager, realJavaBaseName, unoName, className, reader, i, name,
2907 0 : base, defaultCtor, dependencies, cf.get());
2908 0 : }
2909 : // Synthetic castInstance method:
2910 : {
2911 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2912 0 : std::auto_ptr< ClassFile::Code > code(cf->newCode());
2913 : SAL_WNODEPRECATED_DECLARATIONS_POP
2914 : code->instrNew(
2915 : rtl::OString(
2916 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")));
2917 : // stack: type
2918 0 : code->instrDup();
2919 : // stack: type type
2920 0 : code->loadStringConstant(realJavaBaseName);
2921 : // stack: type type "..."
2922 : code->instrGetstatic(
2923 : rtl::OString(
2924 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
2925 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("INTERFACE")),
2926 : rtl::OString(
2927 : RTL_CONSTASCII_STRINGPARAM(
2928 0 : "Lcom/sun/star/uno/TypeClass;")));
2929 : // stack: type type "..." INTERFACE
2930 : code->instrInvokespecial(
2931 : rtl::OString(
2932 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
2933 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2934 : rtl::OString(
2935 : RTL_CONSTASCII_STRINGPARAM(
2936 0 : "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V")));
2937 : // stack: type
2938 0 : code->loadLocalReference(0);
2939 : // stack: type instance
2940 : code->instrInvokestatic(
2941 : rtl::OString(
2942 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/UnoRuntime")),
2943 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("queryInterface")),
2944 : rtl::OString(
2945 : RTL_CONSTASCII_STRINGPARAM(
2946 : "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
2947 0 : "Ljava/lang/Object;")));
2948 : // stack: instance
2949 0 : code->instrDup();
2950 : // stack: instance instance
2951 0 : ClassFile::Code::Branch branch = code->instrIfnull();
2952 : // stack: instance
2953 0 : code->instrAreturn();
2954 0 : code->branchHere(branch);
2955 0 : code->instrPop();
2956 : // stack: -
2957 : code->instrNew(
2958 : rtl::OString(
2959 : RTL_CONSTASCII_STRINGPARAM(
2960 0 : "com/sun/star/uno/DeploymentException")));
2961 : // stack: ex
2962 0 : code->instrDup();
2963 : // stack: ex ex
2964 0 : rtl::OStringBuffer msg;
2965 : msg.append(
2966 : RTL_CONSTASCII_STRINGPARAM(
2967 0 : "component context fails to supply service "));
2968 0 : msg.append(unoName);
2969 0 : msg.append(RTL_CONSTASCII_STRINGPARAM(" of type "));
2970 0 : msg.append(realJavaBaseName);
2971 0 : code->loadStringConstant(msg.makeStringAndClear());
2972 : // stack: ex ex "..."
2973 0 : code->loadLocalReference(1);
2974 : // stack: ex ex "..." context
2975 : code->instrInvokespecial(
2976 : rtl::OString(
2977 : RTL_CONSTASCII_STRINGPARAM(
2978 : "com/sun/star/uno/DeploymentException")),
2979 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
2980 : rtl::OString(
2981 : RTL_CONSTASCII_STRINGPARAM(
2982 0 : "(Ljava/lang/String;Ljava/lang/Object;)V")));
2983 : // stack: ex
2984 0 : code->instrAthrow();
2985 0 : code->setMaxStackAndLocals(4, 2);
2986 : cf->addMethod(
2987 : static_cast< ClassFile::AccessFlags >(
2988 : ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC
2989 : | ClassFile::ACC_SYNTHETIC),
2990 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("$castInstance")),
2991 : rtl::OString(
2992 : RTL_CONSTASCII_STRINGPARAM(
2993 : "(Ljava/lang/Object;Lcom/sun/star/uno/"
2994 : "XComponentContext;)Ljava/lang/Object;")),
2995 0 : code.get(), std::vector< rtl::OString >(), rtl::OString());
2996 0 : }
2997 : }
2998 0 : writeClassFile(options, className, *cf.get());
2999 : }
3000 :
3001 0 : void handleSingleton(
3002 : TypeManager const & manager, JavaOptions /*TODO const*/ & options,
3003 : typereg::Reader const & reader, Dependencies * dependencies)
3004 : {
3005 : OSL_ASSERT(dependencies != 0);
3006 0 : if (reader.getSuperTypeCount() != 1 || reader.getFieldCount() != 0
3007 0 : || reader.getMethodCount() != 0 || reader.getReferenceCount() != 0)
3008 : {
3009 : throw CannotDumpException(
3010 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
3011 : //TODO
3012 : }
3013 0 : rtl::OString base(codemaker::convertString(reader.getSuperTypeName(0)));
3014 0 : rtl::OString realJavaBaseName(base.replace('/', '.'));
3015 0 : switch (manager.getTypeReader(base).getTypeClass()) {
3016 : case RT_TYPE_INTERFACE:
3017 0 : break;
3018 :
3019 : case RT_TYPE_SERVICE:
3020 0 : return;
3021 :
3022 : default:
3023 : throw CannotDumpException(
3024 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
3025 : //TODO
3026 : }
3027 0 : dependencies->insert(base);
3028 0 : rtl::OString unoName(codemaker::convertString(reader.getTypeName()));
3029 : rtl::OString className(
3030 : translateUnoTypeToJavaFullyQualifiedName(
3031 0 : unoName, rtl::OString(RTL_CONSTASCII_STRINGPARAM("singleton"))));
3032 0 : unoName = unoName.replace('/', '.');
3033 : dependencies->insert(
3034 : rtl::OString(
3035 : RTL_CONSTASCII_STRINGPARAM(
3036 0 : "com/sun/star/uno/DeploymentException")));
3037 : dependencies->insert(
3038 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")));
3039 : dependencies->insert(
3040 : rtl::OString(
3041 0 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")));
3042 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
3043 : std::auto_ptr< ClassFile > cf(
3044 : new ClassFile(
3045 : static_cast< ClassFile::AccessFlags >(
3046 : ClassFile::ACC_PUBLIC | ClassFile::ACC_FINAL
3047 : | ClassFile::ACC_SUPER),
3048 : className,
3049 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("java/lang/Object")),
3050 0 : rtl::OString()));
3051 : SAL_WNODEPRECATED_DECLARATIONS_POP
3052 0 : MethodDescriptor desc(manager, dependencies, base, 0, 0);
3053 : desc.addParameter(
3054 : rtl::OString(
3055 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")),
3056 0 : false, false, 0);
3057 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
3058 0 : std::auto_ptr< ClassFile::Code > code(cf->newCode());
3059 : SAL_WNODEPRECATED_DECLARATIONS_POP
3060 0 : code->loadLocalReference(0);
3061 : // stack: context
3062 : code->loadStringConstant(
3063 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("/singletons/")) + unoName);
3064 : // stack: context "..."
3065 : code->instrInvokeinterface(
3066 : rtl::OString(
3067 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/XComponentContext")),
3068 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("getValueByName")),
3069 : rtl::OString(
3070 : RTL_CONSTASCII_STRINGPARAM(
3071 : "(Ljava/lang/String;)Ljava/lang/Object;")),
3072 0 : 2);
3073 : // stack: value
3074 0 : code->instrDup();
3075 : // stack: value value
3076 : code->instrInstanceof(
3077 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")));
3078 : // stack: value 0/1
3079 0 : ClassFile::Code::Branch branch1 = code->instrIfeq();
3080 : // stack: value
3081 : code->instrCheckcast(
3082 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")));
3083 : // stack: value
3084 0 : code->instrDup();
3085 : // stack: value value
3086 : code->instrInvokevirtual(
3087 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
3088 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("getType")),
3089 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("()Lcom/sun/star/uno/Type;")));
3090 : // stack: value type
3091 : code->instrInvokevirtual(
3092 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
3093 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("getTypeClass")),
3094 : rtl::OString(
3095 0 : RTL_CONSTASCII_STRINGPARAM("()Lcom/sun/star/uno/TypeClass;")));
3096 : // stack: value typeClass
3097 : code->instrGetstatic(
3098 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
3099 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("INTERFACE")),
3100 : rtl::OString(
3101 0 : RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/TypeClass;")));
3102 : // stack: value typeClass INTERFACE
3103 0 : ClassFile::Code::Branch branch2 = code->instrIfAcmpne();
3104 : // stack: value
3105 : code->instrInvokevirtual(
3106 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Any")),
3107 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("getObject")),
3108 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("()Ljava/lang/Object;")));
3109 : // stack: value
3110 0 : code->branchHere(branch1);
3111 : code->instrNew(
3112 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")));
3113 : // stack: value type
3114 0 : code->instrDup();
3115 : // stack: value type type
3116 0 : code->loadStringConstant(realJavaBaseName);
3117 : // stack: value type type "..."
3118 : code->instrGetstatic(
3119 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/TypeClass")),
3120 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("INTERFACE")),
3121 : rtl::OString(
3122 0 : RTL_CONSTASCII_STRINGPARAM("Lcom/sun/star/uno/TypeClass;")));
3123 : // stack: value type type "..." INTERFACE
3124 : code->instrInvokespecial(
3125 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/Type")),
3126 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
3127 : rtl::OString(
3128 : RTL_CONSTASCII_STRINGPARAM(
3129 0 : "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V")));
3130 : // stack: value type
3131 0 : code->instrSwap();
3132 : // stack: type value
3133 : code->instrInvokestatic(
3134 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/UnoRuntime")),
3135 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("queryInterface")),
3136 : rtl::OString(
3137 : RTL_CONSTASCII_STRINGPARAM(
3138 : "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
3139 0 : "Ljava/lang/Object;")));
3140 : // stack: instance
3141 0 : code->instrDup();
3142 : // stack: instance instance
3143 0 : ClassFile::Code::Branch branch3 = code->instrIfnull();
3144 : // stack: instance
3145 0 : code->instrCheckcast(base);
3146 : // stack: instance
3147 0 : code->instrAreturn();
3148 0 : code->branchHere(branch2);
3149 0 : code->branchHere(branch3);
3150 0 : code->instrPop();
3151 : // stack: -
3152 : code->instrNew(
3153 : rtl::OString(
3154 : RTL_CONSTASCII_STRINGPARAM(
3155 0 : "com/sun/star/uno/DeploymentException")));
3156 : // stack: ex
3157 0 : code->instrDup();
3158 : // stack: ex ex
3159 0 : rtl::OStringBuffer msg;
3160 : msg.append(
3161 : RTL_CONSTASCII_STRINGPARAM(
3162 0 : "component context fails to supply singleton "));
3163 0 : msg.append(unoName);
3164 0 : msg.append(RTL_CONSTASCII_STRINGPARAM(" of type "));
3165 0 : msg.append(realJavaBaseName);
3166 0 : code->loadStringConstant(msg.makeStringAndClear());
3167 : // stack: ex ex "..."
3168 0 : code->loadLocalReference(0);
3169 : // stack: ex ex "..." context
3170 : code->instrInvokespecial(
3171 : rtl::OString(
3172 : RTL_CONSTASCII_STRINGPARAM("com/sun/star/uno/DeploymentException")),
3173 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("<init>")),
3174 : rtl::OString(
3175 : RTL_CONSTASCII_STRINGPARAM(
3176 0 : "(Ljava/lang/String;Ljava/lang/Object;)V")));
3177 : // stack: ex
3178 0 : code->instrAthrow();
3179 0 : code->setMaxStackAndLocals(5, 1);
3180 : cf->addMethod(
3181 : static_cast< ClassFile::AccessFlags >(
3182 : ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC),
3183 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("get")), desc.getDescriptor(),
3184 0 : code.get(), std::vector< rtl::OString >(), desc.getSignature());
3185 0 : writeClassFile(options, className, *cf.get());
3186 : }
3187 :
3188 : }
3189 :
3190 0 : bool produceType(
3191 : rtl::OString const & type, TypeManager const & manager,
3192 : codemaker::GeneratedTypeSet & generated, JavaOptions * options)
3193 : {
3194 : OSL_ASSERT(options != 0);
3195 0 : if (type.equals("/")
3196 0 : || type.equals(manager.getBase())
3197 0 : || generated.contains(type))
3198 : {
3199 0 : return true;
3200 : }
3201 0 : sal_Bool extra = sal_False;
3202 0 : typereg::Reader reader(manager.getTypeReader(type, &extra));
3203 0 : if (extra) {
3204 0 : generated.add(type);
3205 0 : return true;
3206 : }
3207 0 : if (!reader.isValid()) {
3208 0 : return false;
3209 : }
3210 :
3211 : handleUnoTypeRegistryEntityFunction handler;
3212 0 : switch (reader.getTypeClass()) {
3213 : case RT_TYPE_ENUM:
3214 0 : handler = handleEnumType;
3215 0 : break;
3216 :
3217 : case RT_TYPE_STRUCT:
3218 : case RT_TYPE_EXCEPTION:
3219 0 : handler = handleAggregatingType;
3220 0 : break;
3221 :
3222 : case RT_TYPE_INTERFACE:
3223 0 : handler = handleInterfaceType;
3224 0 : break;
3225 :
3226 : case RT_TYPE_TYPEDEF:
3227 0 : handler = handleTypedef;
3228 0 : break;
3229 :
3230 : case RT_TYPE_CONSTANTS:
3231 0 : handler = handleConstantGroup;
3232 0 : break;
3233 :
3234 : case RT_TYPE_MODULE:
3235 0 : handler = handleModule;
3236 0 : break;
3237 :
3238 : case RT_TYPE_SERVICE:
3239 0 : handler = handleService;
3240 0 : break;
3241 :
3242 : case RT_TYPE_SINGLETON:
3243 0 : handler = handleSingleton;
3244 0 : break;
3245 :
3246 : default:
3247 0 : return false;
3248 : }
3249 0 : Dependencies deps;
3250 0 : handler(manager, *options, reader, &deps);
3251 0 : generated.add(type);
3252 0 : if (!options->isValid(rtl::OString(RTL_CONSTASCII_STRINGPARAM("-nD")))) {
3253 0 : for (Dependencies::iterator i(deps.begin()); i != deps.end(); ++i) {
3254 0 : if (!produceType(*i, manager, generated, options)) {
3255 0 : return false;
3256 : }
3257 : }
3258 : }
3259 0 : return true;
3260 : }
3261 :
3262 0 : bool produceType(
3263 : RegistryKey & rTypeKey, bool bIsExtraType, TypeManager const & manager,
3264 : codemaker::GeneratedTypeSet & generated, JavaOptions * options)
3265 : {
3266 0 : ::rtl::OString typeName = manager.getTypeName(rTypeKey);
3267 :
3268 : OSL_ASSERT(options != 0);
3269 0 : if (typeName.equals("/")
3270 0 : || typeName.equals(manager.getBase())
3271 0 : || generated.contains(typeName))
3272 : {
3273 0 : return true;
3274 : }
3275 0 : typereg::Reader reader(manager.getTypeReader(rTypeKey));
3276 0 : if (bIsExtraType) {
3277 0 : generated.add(typeName);
3278 0 : return true;
3279 : }
3280 0 : if (!reader.isValid()) {
3281 0 : return false;
3282 : }
3283 : handleUnoTypeRegistryEntityFunction handler;
3284 0 : switch (reader.getTypeClass()) {
3285 : case RT_TYPE_ENUM:
3286 0 : handler = handleEnumType;
3287 0 : break;
3288 :
3289 : case RT_TYPE_STRUCT:
3290 : case RT_TYPE_EXCEPTION:
3291 0 : handler = handleAggregatingType;
3292 0 : break;
3293 :
3294 : case RT_TYPE_INTERFACE:
3295 0 : handler = handleInterfaceType;
3296 0 : break;
3297 :
3298 : case RT_TYPE_TYPEDEF:
3299 0 : handler = handleTypedef;
3300 0 : break;
3301 :
3302 : case RT_TYPE_CONSTANTS:
3303 0 : handler = handleConstantGroup;
3304 0 : break;
3305 :
3306 : case RT_TYPE_MODULE:
3307 0 : handler = handleModule;
3308 0 : break;
3309 :
3310 : case RT_TYPE_SERVICE:
3311 0 : handler = handleService;
3312 0 : break;
3313 :
3314 : case RT_TYPE_SINGLETON:
3315 0 : handler = handleSingleton;
3316 0 : break;
3317 :
3318 : default:
3319 0 : return false;
3320 : }
3321 0 : Dependencies deps;
3322 0 : handler(manager, *options, reader, &deps);
3323 0 : generated.add(typeName);
3324 0 : if (!options->isValid(rtl::OString(RTL_CONSTASCII_STRINGPARAM("-nD")))) {
3325 0 : for (Dependencies::iterator i(deps.begin()); i != deps.end(); ++i) {
3326 0 : if (!produceType(*i, manager, generated, options)) {
3327 0 : return false;
3328 : }
3329 : }
3330 : }
3331 0 : return true;
3332 : }
3333 :
3334 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|