1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: climaker_share.h,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #using <cli_basetypes.dll>
36 #include "osl/diagnose.h"
37 #include "com/sun/star/reflection/XConstantTypeDescription.hpp"
38 #include "com/sun/star/reflection/XConstantsTypeDescription.hpp"
39 #include "com/sun/star/reflection/XEnumTypeDescription.hpp"
40 #include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp"
41 #include "com/sun/star/reflection/XCompoundTypeDescription.hpp"
42 #include "com/sun/star/reflection/XServiceTypeDescription2.hpp"
43 #include "com/sun/star/reflection/XSingletonTypeDescription2.hpp"
44 #include "com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp"
46 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
49 namespace css
= ::com::sun::star
;
54 //------------------------------------------------------------------------------
55 extern bool g_verbose
;
59 static const ::System::String
* sUnoVoid
= S
"void";
60 static const ::System::String
* sUnoType
= S
"type";
61 static const ::System::String
* sUnoAny
= S
"any";
62 static const ::System::String
* sUnoBool
= S
"boolean";
63 static const ::System::String
* sUnoByte
= S
"byte";
64 static const ::System::String
* sUnoChar
= S
"char";
65 static const ::System::String
* sUnoShort
= S
"short";
66 static const ::System::String
* sUnoUShort
= S
"unsigned short";
67 static const ::System::String
* sUnoLong
= S
"long";
68 static const ::System::String
* sUnoULong
= S
"unsigned long";
69 static const ::System::String
* sUnoHyper
= S
"hyper";
70 static const ::System::String
* sUnoUHyper
= S
"unsigned hyper";
71 static const ::System::String
* sUnoString
= S
"string";
72 static const ::System::String
* sUnoFloat
= S
"float";
73 static const ::System::String
* sUnoDouble
= S
"double";
74 static const ::System::String
* sUnoXInterface
= S
"com.sun.star.uno.XInterface";
75 static const ::System::String
* sBrackets
= S
"[]";
77 static const System::String
* sObject
= S
"System.Object";
78 static const System::String
* sType
= S
"System.Type";
79 static const System::String
* sUnoidl
= S
"unoidl.";
80 static const System::String
* sVoid
= S
"System.Void";
81 static const System::String
* sAny
= S
"uno.Any";
82 static const System::String
* sBoolean
= S
"System.Boolean";
83 static const System::String
* sChar
= S
"System.Char";
84 static const System::String
* sByte
= S
"System.Byte";
85 static const System::String
* sInt16
= S
"System.Int16";
86 static const System::String
* sUInt16
= S
"System.UInt16";
87 static const System::String
* sInt32
= S
"System.Int32";
88 static const System::String
* sUInt32
= S
"System.UInt32";
89 static const System::String
* sInt64
= S
"System.Int64";
90 static const System::String
* sUInt64
= S
"System.UInt64";
91 static const System::String
* sString
= S
"System.String";
92 static const System::String
* sSingle
= S
"System.Single";
93 static const System::String
* sDouble
= S
"System.Double";
94 static const System::String
* sComma
= new System::String(S
",");
98 //------------------------------------------------------------------------------
99 inline ::System::String
* ustring_to_String( ::rtl::OUString
const & ustr
)
101 return new ::System::String( ustr
.getStr(), 0, ustr
.getLength() );
104 //------------------------------------------------------------------------------
105 inline ::rtl::OUString
String_to_ustring( ::System::String
* str
)
107 OSL_ASSERT( sizeof (wchar_t) == sizeof (sal_Unicode
) );
108 wchar_t const __pin
* chars
= PtrToStringChars( str
);
109 return ::rtl::OUString( chars
, str
->get_Length() );
112 /* If the argument type is a typedef for an interface then the interface
113 type description is returned, otherwise an exeption is thrown.
115 css::uno::Reference
< css::reflection::XInterfaceTypeDescription2
>
116 resolveInterfaceTypedef(const css::uno::Reference
<css::reflection::XTypeDescription
>& type
);
118 const ::System::Reflection::MethodAttributes c_ctor_method_attr
=
119 (::System::Reflection::MethodAttributes
)
120 (::System::Reflection::MethodAttributes::Public
|
121 ::System::Reflection::MethodAttributes::HideBySig
|
122 ::System::Reflection::MethodAttributes::SpecialName
|
123 ::System::Reflection::MethodAttributes::RTSpecialName
124 /* | xxx todo: ??? compiler does not know Instance ???
125 ::System::Reflection::MethodAttributes::Instance*/);
127 //==============================================================================
128 __gc
class TypeEmitter
: public ::System::IDisposable
130 ::System::Reflection::Emit::ModuleBuilder
* m_module_builder
;
131 ::System::Reflection::Assembly
* m_extra_assemblies __gc
[];
133 ::System::Reflection::MethodInfo
* m_method_info_Type_GetTypeFromHandle
;
135 ::System::Type
* m_type_Exception
;
136 ::System::Type
* get_type_Exception();
137 ::System::Type
* m_type_RuntimeException
;
138 ::System::Type
* get_type_RuntimeException();
140 ::System::Reflection::Emit::CustomAttributeBuilder
* get_service_exception_attribute(
141 const css::uno::Reference
<css::reflection::XServiceConstructorDescription
> & ctorDesc
);
142 ::System::Reflection::Emit::CustomAttributeBuilder
* get_iface_method_exception_attribute(
143 const css::uno::Reference
< css::reflection::XInterfaceMethodTypeDescription
>& xMethod
);
144 ::System::Reflection::Emit::CustomAttributeBuilder
* get_exception_attribute(
145 const css::uno::Sequence
<css::uno::Reference
<
146 css::reflection::XCompoundTypeDescription
> >& seq_exceptionsTd
);
147 /* Creates ::System::Type object for UNO exceptions. The UNO exceptions are
149 com::sun::star::reflection::XServiceConstructorDescription::getExceptions
150 In a first step the respective CLI types are created. Then it is examined
151 if a Type represents a super class of another class. If so the Type of the
152 derived class is discarded. For example there are a uno RuntimeException and
153 a DeploymentException which inherits RuntimeException. Then only the cli Type
154 of the RuntimeException is returned.
155 The purpose of this function is to provide exceptions for which catch blocks
156 are generated in the service constructor code.
158 It is always an instance of an ArrayList returned, even if the sequence argument
159 does not contain elements.
161 ::System::Collections::ArrayList
* get_service_ctor_method_exceptions_reduced(
162 const css::uno::Sequence
<
163 css::uno::Reference
<css::reflection::XCompoundTypeDescription
> > & seqExceptionsTd
);
166 __gc
class iface_entry
169 css::reflection::XInterfaceTypeDescription2
* m_xType
;
170 ::System::Reflection::Emit::TypeBuilder
* m_type_builder
;
172 ::System::Collections::Hashtable
* m_incomplete_ifaces
;
173 ::System::Type
* complete_iface_type( iface_entry
* entry
);
175 __gc
class struct_entry
178 css::reflection::XCompoundTypeDescription
* m_xType
;
179 ::System::Reflection::Emit::TypeBuilder
* m_type_builder
;
180 ::System::Type
* m_base_type
;
182 ::System::String
* m_member_names __gc
[];
183 ::System::Type
* m_param_types __gc
[];
184 ::System::Reflection::ConstructorInfo
* m_default_ctor
;
185 ::System::Reflection::ConstructorInfo
* m_ctor
;
187 ::System::Collections::Hashtable
* m_incomplete_structs
;
188 ::System::Type
* complete_struct_type( struct_entry
* entry
);
190 /* returns the type for the name. If it is a struct then it may
191 complete the struct if not already done. This also refers to its
195 the full name of the type.
196 @return the type object for sName. Not necessarily a struct.
198 ::System::Type
* get_complete_struct( ::System::String
* sName
);
200 __gc
class service_entry
203 ::System::Reflection::Emit::TypeBuilder
* m_type_builder
;
204 css::reflection::XServiceTypeDescription2
* m_xType
;
206 ::System::Collections::Hashtable
* m_incomplete_services
;
207 ::System::Type
* complete_service_type(service_entry
* entry
);
209 __gc
class singleton_entry
212 ::System::Reflection::Emit::TypeBuilder
* m_type_builder
;
213 css::reflection::XSingletonTypeDescription2
* m_xType
;
217 ::System::Collections::Hashtable
* m_incomplete_singletons
;
218 ::System::Type
* complete_singleton_type(singleton_entry
* entry
);
221 ::System::Collections::Hashtable
* m_generated_structs
;
223 ::System::Type
* get_type(
224 ::System::String
* cli_name
, bool throw_exc
);
225 ::System::Type
* get_type(
227 css::reflection::XConstantTypeDescription
> const & xType
);
228 ::System::Type
* get_type(
230 css::reflection::XConstantsTypeDescription
> const & xType
);
231 ::System::Type
* get_type(
233 css::reflection::XEnumTypeDescription
> const & xType
);
234 /* returns the type for a struct or exception. In case of a polymorphic struct it may
235 return a ::uno::PolymorphicType (cli_basetypes.dll) only if the struct is already
238 ::System::Type
* get_type(
240 css::reflection::XCompoundTypeDescription
> const & xType
);
241 ::System::Type
* get_type(
243 css::reflection::XInterfaceTypeDescription2
> const & xType
);
244 ::System::Type
* get_type(
246 css::reflection::XSingletonTypeDescription2
> const & xType
);
249 May return NULL if the service description is an obsolete. See
251 com.sun.star.reflection.XServiceTypeDescription2.isSingleInterfaceBased
253 ::System::Type
* get_type(
255 css::reflection::XServiceTypeDescription2
> const & xType
);
258 ::System::Reflection::Emit::ModuleBuilder
* module_builder
,
259 ::System::Reflection::Assembly
* assemblies __gc
[] );
260 // must be called to finish up uncompleted types
263 ::System::Reflection::Assembly
* type_resolve(
264 ::System::Object
* sender
, ::System::ResolveEventArgs
* args
);
266 ::System::Type
* get_type(
268 css::reflection::XTypeDescription
> const & xType
);