1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_codemaker.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "sal/config.h" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "codemaker/codemaker.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include "codemaker/options.hxx" 36*cdf0e10cSrcweir #include "codemaker/typemanager.hxx" 37*cdf0e10cSrcweir #include "codemaker/unotype.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include "osl/diagnose.h" 40*cdf0e10cSrcweir #include "registry/reader.hxx" 41*cdf0e10cSrcweir #include "registry/types.h" 42*cdf0e10cSrcweir #include "rtl/strbuf.h" 43*cdf0e10cSrcweir #include "rtl/string.h" 44*cdf0e10cSrcweir #include "rtl/string.hxx" 45*cdf0e10cSrcweir #include "rtl/ustring.hxx" 46*cdf0e10cSrcweir #include "sal/types.h" 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <vector> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir namespace { 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir void checkNoTypeArguments(std::vector< rtl::OString > const & arguments) { 53*cdf0e10cSrcweir if (!arguments.empty()) { 54*cdf0e10cSrcweir throw CannotDumpException( 55*cdf0e10cSrcweir rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information"))); 56*cdf0e10cSrcweir //TODO 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir namespace codemaker { 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir rtl::OString convertString(rtl::OUString const & string) { 65*cdf0e10cSrcweir rtl::OString s; 66*cdf0e10cSrcweir if (!string.convertToString( 67*cdf0e10cSrcweir &s, RTL_TEXTENCODING_UTF8, 68*cdf0e10cSrcweir (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR 69*cdf0e10cSrcweir | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir throw CannotDumpException( 72*cdf0e10cSrcweir rtl::OString( 73*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( 74*cdf0e10cSrcweir "Failure converting string from UTF-16 to UTF-8"))); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir return s; 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir rtl::OString errorMsg(rtl::OString const & desc, rtl::OString const & type) { 80*cdf0e10cSrcweir rtl::OStringBuffer msg(128); 81*cdf0e10cSrcweir msg.append(desc); 82*cdf0e10cSrcweir msg.append(type); 83*cdf0e10cSrcweir return msg.makeStringAndClear(); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir codemaker::UnoType::Sort decomposeAndResolve( 87*cdf0e10cSrcweir TypeManager const & manager, rtl::OString const & type, 88*cdf0e10cSrcweir bool resolveTypedefs, bool allowVoid, bool allowExtraEntities, 89*cdf0e10cSrcweir RTTypeClass * typeClass, rtl::OString * name, sal_Int32 * rank, 90*cdf0e10cSrcweir std::vector< rtl::OString > * arguments) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir OSL_ASSERT(typeClass != 0 && name != 0 && rank != 0 && arguments != 0); 93*cdf0e10cSrcweir *rank = 0; 94*cdf0e10cSrcweir for (rtl::OString t(type);;) { 95*cdf0e10cSrcweir sal_Int32 n = 0; 96*cdf0e10cSrcweir *name = codemaker::UnoType::decompose(t, &n, arguments); 97*cdf0e10cSrcweir if (n > SAL_MAX_INT32 - *rank) { 98*cdf0e10cSrcweir throw CannotDumpException( 99*cdf0e10cSrcweir errorMsg(rtl::OString( 100*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")), 101*cdf0e10cSrcweir type)); 102*cdf0e10cSrcweir //TODO 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir *rank += n; 105*cdf0e10cSrcweir if (n > 0) { 106*cdf0e10cSrcweir allowVoid = false; 107*cdf0e10cSrcweir allowExtraEntities = false; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir codemaker::UnoType::Sort sort = codemaker::UnoType::getSort(*name); 110*cdf0e10cSrcweir switch (sort) { 111*cdf0e10cSrcweir case codemaker::UnoType::SORT_VOID: 112*cdf0e10cSrcweir if (!allowVoid) { 113*cdf0e10cSrcweir throw CannotDumpException( 114*cdf0e10cSrcweir errorMsg(rtl::OString( 115*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")), 116*cdf0e10cSrcweir type)); 117*cdf0e10cSrcweir //TODO 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir default: 120*cdf0e10cSrcweir checkNoTypeArguments(*arguments); 121*cdf0e10cSrcweir *typeClass = RT_TYPE_INVALID; 122*cdf0e10cSrcweir return sort; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir case codemaker::UnoType::SORT_COMPLEX: 125*cdf0e10cSrcweir typereg::Reader reader(manager.getTypeReader(*name)); 126*cdf0e10cSrcweir *typeClass = reader.getTypeClass(); 127*cdf0e10cSrcweir switch (*typeClass) { 128*cdf0e10cSrcweir case RT_TYPE_ENUM: 129*cdf0e10cSrcweir case RT_TYPE_INTERFACE: 130*cdf0e10cSrcweir checkNoTypeArguments(*arguments); 131*cdf0e10cSrcweir return sort; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir case RT_TYPE_STRUCT: 134*cdf0e10cSrcweir if (!(allowExtraEntities && arguments->empty()) 135*cdf0e10cSrcweir && (arguments->size() > SAL_MAX_UINT16 136*cdf0e10cSrcweir || (static_cast< sal_uInt16 >(arguments->size()) 137*cdf0e10cSrcweir != reader.getReferenceCount()))) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir throw CannotDumpException( 140*cdf0e10cSrcweir errorMsg(rtl::OString( 141*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")), 142*cdf0e10cSrcweir type)); 143*cdf0e10cSrcweir //TODO 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir return sort; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir case RT_TYPE_MODULE: 148*cdf0e10cSrcweir case RT_TYPE_EXCEPTION: 149*cdf0e10cSrcweir case RT_TYPE_SERVICE: 150*cdf0e10cSrcweir case RT_TYPE_SINGLETON: 151*cdf0e10cSrcweir case RT_TYPE_CONSTANTS: 152*cdf0e10cSrcweir if (!allowExtraEntities) { 153*cdf0e10cSrcweir throw CannotDumpException( 154*cdf0e10cSrcweir errorMsg(rtl::OString( 155*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")), 156*cdf0e10cSrcweir type)); 157*cdf0e10cSrcweir //TODO 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir checkNoTypeArguments(*arguments); 160*cdf0e10cSrcweir //TODO: check reader for consistency 161*cdf0e10cSrcweir return sort; 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir case RT_TYPE_TYPEDEF: 164*cdf0e10cSrcweir checkNoTypeArguments(*arguments); 165*cdf0e10cSrcweir if (reader.getSuperTypeCount() == 1 166*cdf0e10cSrcweir && reader.getFieldCount() == 0 167*cdf0e10cSrcweir && reader.getMethodCount() == 0 168*cdf0e10cSrcweir && reader.getReferenceCount() == 0) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir if (resolveTypedefs) { 171*cdf0e10cSrcweir t = convertString(reader.getSuperTypeName(0)); 172*cdf0e10cSrcweir continue; 173*cdf0e10cSrcweir } else { 174*cdf0e10cSrcweir return sort; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir default: 178*cdf0e10cSrcweir throw CannotDumpException( 179*cdf0e10cSrcweir errorMsg(rtl::OString( 180*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")), 181*cdf0e10cSrcweir type)); 182*cdf0e10cSrcweir //TODO 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir } 189