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