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 #using <mscorlib.dll> 29*cdf0e10cSrcweir #using <cli_basetypes.dll> 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <vcclr.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "osl/diagnose.h" 34*cdf0e10cSrcweir #include "com/sun/star/reflection/XConstantTypeDescription.hpp" 35*cdf0e10cSrcweir #include "com/sun/star/reflection/XConstantsTypeDescription.hpp" 36*cdf0e10cSrcweir #include "com/sun/star/reflection/XEnumTypeDescription.hpp" 37*cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp" 38*cdf0e10cSrcweir #include "com/sun/star/reflection/XCompoundTypeDescription.hpp" 39*cdf0e10cSrcweir #include "com/sun/star/reflection/XServiceTypeDescription2.hpp" 40*cdf0e10cSrcweir #include "com/sun/star/reflection/XSingletonTypeDescription2.hpp" 41*cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir namespace css = ::com::sun::star; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir namespace climaker 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //------------------------------------------------------------------------------ 52*cdf0e10cSrcweir extern bool g_verbose; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir __gc struct Constants 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir static const ::System::String * sUnoVoid = S"void"; 57*cdf0e10cSrcweir static const ::System::String * sUnoType = S"type"; 58*cdf0e10cSrcweir static const ::System::String * sUnoAny = S"any"; 59*cdf0e10cSrcweir static const ::System::String * sUnoBool = S"boolean"; 60*cdf0e10cSrcweir static const ::System::String * sUnoByte = S"byte"; 61*cdf0e10cSrcweir static const ::System::String * sUnoChar = S"char"; 62*cdf0e10cSrcweir static const ::System::String * sUnoShort = S"short"; 63*cdf0e10cSrcweir static const ::System::String * sUnoUShort = S"unsigned short"; 64*cdf0e10cSrcweir static const ::System::String * sUnoLong = S"long"; 65*cdf0e10cSrcweir static const ::System::String * sUnoULong = S"unsigned long"; 66*cdf0e10cSrcweir static const ::System::String * sUnoHyper = S"hyper"; 67*cdf0e10cSrcweir static const ::System::String * sUnoUHyper = S"unsigned hyper"; 68*cdf0e10cSrcweir static const ::System::String * sUnoString = S"string"; 69*cdf0e10cSrcweir static const ::System::String * sUnoFloat = S"float"; 70*cdf0e10cSrcweir static const ::System::String * sUnoDouble = S"double"; 71*cdf0e10cSrcweir static const ::System::String * sUnoXInterface = S"com.sun.star.uno.XInterface"; 72*cdf0e10cSrcweir static const ::System::String * sBrackets = S"[]"; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir static const System::String* sObject = S"System.Object"; 75*cdf0e10cSrcweir static const System::String* sType = S"System.Type"; 76*cdf0e10cSrcweir static const System::String* sUnoidl = S"unoidl."; 77*cdf0e10cSrcweir static const System::String* sVoid = S"System.Void"; 78*cdf0e10cSrcweir static const System::String* sAny = S"uno.Any"; 79*cdf0e10cSrcweir static const System::String* sBoolean = S"System.Boolean"; 80*cdf0e10cSrcweir static const System::String* sChar = S"System.Char"; 81*cdf0e10cSrcweir static const System::String* sByte = S"System.Byte"; 82*cdf0e10cSrcweir static const System::String* sInt16 = S"System.Int16"; 83*cdf0e10cSrcweir static const System::String* sUInt16 = S"System.UInt16"; 84*cdf0e10cSrcweir static const System::String* sInt32 = S"System.Int32"; 85*cdf0e10cSrcweir static const System::String* sUInt32 = S"System.UInt32"; 86*cdf0e10cSrcweir static const System::String* sInt64 = S"System.Int64"; 87*cdf0e10cSrcweir static const System::String* sUInt64 = S"System.UInt64"; 88*cdf0e10cSrcweir static const System::String* sString = S"System.String"; 89*cdf0e10cSrcweir static const System::String* sSingle = S"System.Single"; 90*cdf0e10cSrcweir static const System::String* sDouble = S"System.Double"; 91*cdf0e10cSrcweir static const System::String* sComma = new System::String(S","); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir }; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir //------------------------------------------------------------------------------ 96*cdf0e10cSrcweir inline ::System::String * ustring_to_String( ::rtl::OUString const & ustr ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir return new ::System::String( ustr.getStr(), 0, ustr.getLength() ); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //------------------------------------------------------------------------------ 102*cdf0e10cSrcweir inline ::rtl::OUString String_to_ustring( ::System::String * str ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir OSL_ASSERT( sizeof (wchar_t) == sizeof (sal_Unicode) ); 105*cdf0e10cSrcweir wchar_t const __pin * chars = PtrToStringChars( str ); 106*cdf0e10cSrcweir return ::rtl::OUString( chars, str->get_Length() ); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /* If the argument type is a typedef for an interface then the interface 110*cdf0e10cSrcweir type description is returned, otherwise an exeption is thrown. 111*cdf0e10cSrcweir */ 112*cdf0e10cSrcweir css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > 113*cdf0e10cSrcweir resolveInterfaceTypedef(const css::uno::Reference<css::reflection::XTypeDescription>& type); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir const ::System::Reflection::MethodAttributes c_ctor_method_attr = 116*cdf0e10cSrcweir (::System::Reflection::MethodAttributes) 117*cdf0e10cSrcweir (::System::Reflection::MethodAttributes::Public | 118*cdf0e10cSrcweir ::System::Reflection::MethodAttributes::HideBySig | 119*cdf0e10cSrcweir ::System::Reflection::MethodAttributes::SpecialName | 120*cdf0e10cSrcweir ::System::Reflection::MethodAttributes::RTSpecialName 121*cdf0e10cSrcweir /* | xxx todo: ??? compiler does not know Instance ??? 122*cdf0e10cSrcweir ::System::Reflection::MethodAttributes::Instance*/); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir //============================================================================== 125*cdf0e10cSrcweir __gc class TypeEmitter : public ::System::IDisposable 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir ::System::Reflection::Emit::ModuleBuilder * m_module_builder; 128*cdf0e10cSrcweir ::System::Reflection::Assembly * m_extra_assemblies __gc []; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir ::System::Reflection::MethodInfo * m_method_info_Type_GetTypeFromHandle; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir ::System::Type * m_type_Exception; 133*cdf0e10cSrcweir ::System::Type * get_type_Exception(); 134*cdf0e10cSrcweir ::System::Type * m_type_RuntimeException; 135*cdf0e10cSrcweir ::System::Type * get_type_RuntimeException(); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir ::System::Reflection::Emit::CustomAttributeBuilder* get_service_exception_attribute( 138*cdf0e10cSrcweir const css::uno::Reference<css::reflection::XServiceConstructorDescription> & ctorDesc); 139*cdf0e10cSrcweir ::System::Reflection::Emit::CustomAttributeBuilder* get_iface_method_exception_attribute( 140*cdf0e10cSrcweir const css::uno::Reference< css::reflection::XInterfaceMethodTypeDescription >& xMethod ); 141*cdf0e10cSrcweir ::System::Reflection::Emit::CustomAttributeBuilder* get_exception_attribute( 142*cdf0e10cSrcweir const css::uno::Sequence<css::uno::Reference< 143*cdf0e10cSrcweir css::reflection::XCompoundTypeDescription > >& seq_exceptionsTd ); 144*cdf0e10cSrcweir /* Creates ::System::Type object for UNO exceptions. The UNO exceptions are 145*cdf0e10cSrcweir obtained by 146*cdf0e10cSrcweir com::sun::star::reflection::XServiceConstructorDescription::getExceptions 147*cdf0e10cSrcweir In a first step the respective CLI types are created. Then it is examined 148*cdf0e10cSrcweir if a Type represents a super class of another class. If so the Type of the 149*cdf0e10cSrcweir derived class is discarded. For example there are a uno RuntimeException and 150*cdf0e10cSrcweir a DeploymentException which inherits RuntimeException. Then only the cli Type 151*cdf0e10cSrcweir of the RuntimeException is returned. 152*cdf0e10cSrcweir The purpose of this function is to provide exceptions for which catch blocks 153*cdf0e10cSrcweir are generated in the service constructor code. 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir It is always an instance of an ArrayList returned, even if the sequence argument 156*cdf0e10cSrcweir does not contain elements. 157*cdf0e10cSrcweir */ 158*cdf0e10cSrcweir ::System::Collections::ArrayList * get_service_ctor_method_exceptions_reduced( 159*cdf0e10cSrcweir const css::uno::Sequence< 160*cdf0e10cSrcweir css::uno::Reference<css::reflection::XCompoundTypeDescription> > & seqExceptionsTd); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir __gc class iface_entry 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir public: 166*cdf0e10cSrcweir css::reflection::XInterfaceTypeDescription2 * m_xType; 167*cdf0e10cSrcweir ::System::Reflection::Emit::TypeBuilder * m_type_builder; 168*cdf0e10cSrcweir }; 169*cdf0e10cSrcweir ::System::Collections::Hashtable * m_incomplete_ifaces; 170*cdf0e10cSrcweir ::System::Type * complete_iface_type( iface_entry * entry ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir __gc class struct_entry 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir public: 175*cdf0e10cSrcweir css::reflection::XCompoundTypeDescription * m_xType; 176*cdf0e10cSrcweir ::System::Reflection::Emit::TypeBuilder * m_type_builder; 177*cdf0e10cSrcweir ::System::Type * m_base_type; 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir ::System::String * m_member_names __gc []; 180*cdf0e10cSrcweir ::System::Type * m_param_types __gc []; 181*cdf0e10cSrcweir ::System::Reflection::ConstructorInfo * m_default_ctor; 182*cdf0e10cSrcweir ::System::Reflection::ConstructorInfo * m_ctor; 183*cdf0e10cSrcweir }; 184*cdf0e10cSrcweir ::System::Collections::Hashtable * m_incomplete_structs; 185*cdf0e10cSrcweir ::System::Type * complete_struct_type( struct_entry * entry ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir /* returns the type for the name. If it is a struct then it may 188*cdf0e10cSrcweir complete the struct if not already done. This also refers to its 189*cdf0e10cSrcweir base types. 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir @param sName 192*cdf0e10cSrcweir the full name of the type. 193*cdf0e10cSrcweir @return the type object for sName. Not necessarily a struct. 194*cdf0e10cSrcweir */ 195*cdf0e10cSrcweir ::System::Type * get_complete_struct( ::System::String * sName); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir __gc class service_entry 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir public: 200*cdf0e10cSrcweir ::System::Reflection::Emit::TypeBuilder * m_type_builder; 201*cdf0e10cSrcweir css::reflection::XServiceTypeDescription2 * m_xType; 202*cdf0e10cSrcweir }; 203*cdf0e10cSrcweir ::System::Collections::Hashtable * m_incomplete_services; 204*cdf0e10cSrcweir ::System::Type * complete_service_type(service_entry * entry); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir __gc class singleton_entry 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir public: 209*cdf0e10cSrcweir ::System::Reflection::Emit::TypeBuilder * m_type_builder; 210*cdf0e10cSrcweir css::reflection::XSingletonTypeDescription2 * m_xType; 211*cdf0e10cSrcweir }; 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir ::System::Collections::Hashtable * m_incomplete_singletons; 215*cdf0e10cSrcweir ::System::Type * complete_singleton_type(singleton_entry * entry); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir ::System::Collections::Hashtable * m_generated_structs; 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir ::System::Type * get_type( 221*cdf0e10cSrcweir ::System::String * cli_name, bool throw_exc ); 222*cdf0e10cSrcweir ::System::Type * get_type( 223*cdf0e10cSrcweir css::uno::Reference< 224*cdf0e10cSrcweir css::reflection::XConstantTypeDescription > const & xType ); 225*cdf0e10cSrcweir ::System::Type * get_type( 226*cdf0e10cSrcweir css::uno::Reference< 227*cdf0e10cSrcweir css::reflection::XConstantsTypeDescription > const & xType ); 228*cdf0e10cSrcweir ::System::Type * get_type( 229*cdf0e10cSrcweir css::uno::Reference< 230*cdf0e10cSrcweir css::reflection::XEnumTypeDescription > const & xType ); 231*cdf0e10cSrcweir /* returns the type for a struct or exception. In case of a polymorphic struct it may 232*cdf0e10cSrcweir return a ::uno::PolymorphicType (cli_basetypes.dll) only if the struct is already 233*cdf0e10cSrcweir complete. 234*cdf0e10cSrcweir */ 235*cdf0e10cSrcweir ::System::Type * get_type( 236*cdf0e10cSrcweir css::uno::Reference< 237*cdf0e10cSrcweir css::reflection::XCompoundTypeDescription > const & xType ); 238*cdf0e10cSrcweir ::System::Type * get_type( 239*cdf0e10cSrcweir css::uno::Reference< 240*cdf0e10cSrcweir css::reflection::XInterfaceTypeDescription2 > const & xType ); 241*cdf0e10cSrcweir ::System::Type * get_type( 242*cdf0e10cSrcweir css::uno::Reference< 243*cdf0e10cSrcweir css::reflection::XSingletonTypeDescription2 > const & xType ); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir /* 246*cdf0e10cSrcweir May return NULL if the service description is an obsolete. See 247*cdf0e10cSrcweir description of 248*cdf0e10cSrcweir com.sun.star.reflection.XServiceTypeDescription2.isSingleInterfaceBased 249*cdf0e10cSrcweir */ 250*cdf0e10cSrcweir ::System::Type * get_type( 251*cdf0e10cSrcweir css::uno::Reference< 252*cdf0e10cSrcweir css::reflection::XServiceTypeDescription2 > const & xType ); 253*cdf0e10cSrcweir public: 254*cdf0e10cSrcweir TypeEmitter( 255*cdf0e10cSrcweir ::System::Reflection::Emit::ModuleBuilder * module_builder, 256*cdf0e10cSrcweir ::System::Reflection::Assembly * assemblies __gc [] ); 257*cdf0e10cSrcweir // must be called to finish up uncompleted types 258*cdf0e10cSrcweir void Dispose(); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir ::System::Reflection::Assembly * type_resolve( 261*cdf0e10cSrcweir ::System::Object * sender, ::System::ResolveEventArgs * args ); 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir ::System::Type * get_type( 264*cdf0e10cSrcweir css::uno::Reference< 265*cdf0e10cSrcweir css::reflection::XTypeDescription > const & xType ); 266*cdf0e10cSrcweir }; 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir } 269