1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #using <cli_basetypes.dll>
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"
38 //------------------------------------------------------------------------------
39 extern bool g_verbose
;
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
= "[]";
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(",");
82 //------------------------------------------------------------------------------
83 inline ::System::String
^ ustring_to_String( OUString
const & ustr
)
85 return gcnew ::System::String( ustr
.getStr(), 0, ustr
.getLength() );
88 //------------------------------------------------------------------------------
89 inline OUString
String_to_ustring( ::System::String
^ str
)
91 OSL_ASSERT( sizeof (wchar_t) == sizeof (sal_Unicode
) );
92 pin_ptr
<const wchar_t> chars
= PtrToStringChars( str
);
93 return OUString( chars
, str
->Length
);
96 /* If the argument type is a typedef for an interface then the interface
97 type description is returned, otherwise an exeption is thrown.
99 css::uno::Reference
< css::reflection::XInterfaceTypeDescription2
>
100 resolveInterfaceTypedef(const css::uno::Reference
<css::reflection::XTypeDescription
>& type
);
102 static ::System::Reflection::MethodAttributes c_ctor_method_attr
=
103 (::System::Reflection::MethodAttributes
)
104 (::System::Reflection::MethodAttributes::Public
|
105 ::System::Reflection::MethodAttributes::HideBySig
|
106 ::System::Reflection::MethodAttributes::SpecialName
|
107 ::System::Reflection::MethodAttributes::RTSpecialName
108 /* | xxx todo: ??? compiler does not know Instance ???
109 ::System::Reflection::MethodAttributes::Instance*/);
111 //==============================================================================
112 ref
class TypeEmitter
: public ::System::IDisposable
114 ::System::Reflection::Emit::ModuleBuilder
^ m_module_builder
;
115 array
< ::System::Reflection::Assembly
^>^ m_extra_assemblies
;
117 ::System::Reflection::MethodInfo
^ m_method_info_Type_GetTypeFromHandle
;
119 ::System::Type
^ m_type_Exception
;
120 ::System::Type
^ get_type_Exception();
121 ::System::Type
^ m_type_RuntimeException
;
122 ::System::Type
^ get_type_RuntimeException();
124 ::System::Reflection::Emit::CustomAttributeBuilder
^ get_service_exception_attribute(
125 const css::uno::Reference
<css::reflection::XServiceConstructorDescription
> & ctorDesc
);
126 ::System::Reflection::Emit::CustomAttributeBuilder
^ get_iface_method_exception_attribute(
127 const css::uno::Reference
< css::reflection::XInterfaceMethodTypeDescription
>& xMethod
);
128 ::System::Reflection::Emit::CustomAttributeBuilder
^ get_exception_attribute(
129 const css::uno::Sequence
<css::uno::Reference
<
130 css::reflection::XCompoundTypeDescription
> >& seq_exceptionsTd
);
131 /* Creates ::System::Type object for UNO exceptions. The UNO exceptions are
133 com::sun::star::reflection::XServiceConstructorDescription::getExceptions
134 In a first step the respective CLI types are created. Then it is examined
135 if a Type represents a super class of another class. If so the Type of the
136 derived class is discarded. For example there are a uno RuntimeException and
137 a DeploymentException which inherits RuntimeException. Then only the cli Type
138 of the RuntimeException is returned.
139 The purpose of this function is to provide exceptions for which catch blocks
140 are generated in the service constructor code.
142 It is always an instance of an ArrayList returned, even if the sequence argument
143 does not contain elements.
145 ::System::Collections::ArrayList
^ get_service_ctor_method_exceptions_reduced(
146 const css::uno::Sequence
<
147 css::uno::Reference
<css::reflection::XCompoundTypeDescription
> > & seqExceptionsTd
);
150 ref
class iface_entry
153 css::reflection::XInterfaceTypeDescription2
* m_xType
;
154 ::System::Reflection::Emit::TypeBuilder
^ m_type_builder
;
156 ::System::Collections::Hashtable
^ m_incomplete_ifaces
;
157 ::System::Type
^ complete_iface_type( iface_entry
^ entry
);
159 ref
class struct_entry
162 css::reflection::XCompoundTypeDescription
* m_xType
;
163 ::System::Reflection::Emit::TypeBuilder
^ m_type_builder
;
164 ::System::Type
^ m_base_type
;
166 array
< ::System::String
^>^ m_member_names
;
167 array
< ::System::Type
^>^ m_param_types
;
168 ::System::Reflection::ConstructorInfo
^ m_default_ctor
;
169 ::System::Reflection::ConstructorInfo
^ m_ctor
;
171 ::System::Collections::Hashtable
^ m_incomplete_structs
;
172 ::System::Type
^ complete_struct_type( struct_entry
^ entry
);
174 /* returns the type for the name. If it is a struct then it may
175 complete the struct if not already done. This also refers to its
179 the full name of the type.
180 @return the type object for sName. Not necessarily a struct.
182 ::System::Type
^ get_complete_struct( ::System::String
^ sName
);
184 ref
class service_entry
187 ::System::Reflection::Emit::TypeBuilder
^ m_type_builder
;
188 css::reflection::XServiceTypeDescription2
* m_xType
;
190 ::System::Collections::Hashtable
^ m_incomplete_services
;
191 ::System::Type
^ complete_service_type(service_entry
^ entry
);
193 ref
class singleton_entry
196 ::System::Reflection::Emit::TypeBuilder
^ m_type_builder
;
197 css::reflection::XSingletonTypeDescription2
* m_xType
;
201 ::System::Collections::Hashtable
^ m_incomplete_singletons
;
202 ::System::Type
^ complete_singleton_type(singleton_entry
^ entry
);
205 ::System::Collections::Hashtable
^ m_generated_structs
;
207 ::System::Type
^ get_type(
208 ::System::String
^ cli_name
, bool throw_exc
);
209 ::System::Type
^ get_type(
211 css::reflection::XConstantTypeDescription
> const & xType
);
212 ::System::Type
^ get_type(
214 css::reflection::XConstantsTypeDescription
> const & xType
);
215 ::System::Type
^ get_type(
217 css::reflection::XEnumTypeDescription
> const & xType
);
218 /* returns the type for a struct or exception. In case of a polymorphic struct it may
219 return a ::uno::PolymorphicType (cli_basetypes.dll) only if the struct is already
222 ::System::Type
^ get_type(
224 css::reflection::XCompoundTypeDescription
> const & xType
);
225 ::System::Type
^ get_type(
227 css::reflection::XInterfaceTypeDescription2
> const & xType
);
228 ::System::Type
^ get_type(
230 css::reflection::XSingletonTypeDescription2
> const & xType
);
233 May return NULL if the service description is an obsolete. See
235 com.sun.star.reflection.XServiceTypeDescription2.isSingleInterfaceBased
237 ::System::Type
^ get_type(
239 css::reflection::XServiceTypeDescription2
> const & xType
);
242 ::System::Reflection::Emit::ModuleBuilder
^ module_builder
,
243 array
< ::System::Reflection::Assembly
^>^ assemblies
);
244 // must be called to finish up uncompleted types
247 ::System::Reflection::Assembly
^ type_resolve(
248 ::System::Object
^ sender
, ::System::ResolveEventArgs
^ args
);
250 ::System::Type
^ get_type(
252 css::reflection::XTypeDescription
> const & xType
);
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */