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