LCOV - code coverage report
Current view: top level - libreoffice/codemaker/source/javamaker - javatype.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1195 1300 91.9 %
Date: 2012-12-27 Functions: 46 46 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10