xref: /AOO41X/main/cli_ure/source/climaker/climaker_emit.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cli_ure.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "climaker_share.h"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "rtl/string.hxx"
34*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
35*cdf0e10cSrcweir #include "com/sun/star/reflection/XIndirectTypeDescription.hpp"
36*cdf0e10cSrcweir #include "com/sun/star/reflection/XStructTypeDescription.hpp"
37*cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp"
38*cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp"
39*cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceAttributeTypeDescription.hpp"
40*cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp"
41*cdf0e10cSrcweir #include <vector>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir using namespace ::System::Reflection;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir using namespace ::rtl;
46*cdf0e10cSrcweir using namespace ::com::sun::star;
47*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir namespace climaker
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir System::String* mapUnoPolymorphicName(System::String* unoName);
52*cdf0e10cSrcweir //------------------------------------------------------------------------------
53*cdf0e10cSrcweir static inline ::System::String * to_cts_name(
54*cdf0e10cSrcweir     OUString const & uno_name )
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir     OUStringBuffer buf( 7 + uno_name.getLength() );
57*cdf0e10cSrcweir     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("unoidl.") );
58*cdf0e10cSrcweir     buf.append( uno_name );
59*cdf0e10cSrcweir     return ustring_to_String( buf.makeStringAndClear() );
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir //------------------------------------------------------------------------------
63*cdf0e10cSrcweir static inline ::System::Object * to_cli_constant( Any const & value )
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     switch (value.getValueTypeClass())
66*cdf0e10cSrcweir     {
67*cdf0e10cSrcweir     case TypeClass_CHAR:
68*cdf0e10cSrcweir         return __box
69*cdf0e10cSrcweir             ((::System::Char) *reinterpret_cast< sal_Unicode const * >(
70*cdf0e10cSrcweir                 value.getValue() ));
71*cdf0e10cSrcweir     case TypeClass_BOOLEAN:
72*cdf0e10cSrcweir         return __box
73*cdf0e10cSrcweir             ((::System::Boolean)
74*cdf0e10cSrcweir              sal_False != *reinterpret_cast< sal_Bool const * >(
75*cdf0e10cSrcweir                  value.getValue() ));
76*cdf0e10cSrcweir     case TypeClass_BYTE:
77*cdf0e10cSrcweir         return __box
78*cdf0e10cSrcweir             ((::System::Byte) *reinterpret_cast< sal_Int8 const * >(
79*cdf0e10cSrcweir                 value.getValue() ));
80*cdf0e10cSrcweir     case TypeClass_SHORT:
81*cdf0e10cSrcweir         return __box
82*cdf0e10cSrcweir             ((::System::Int16) *reinterpret_cast< sal_Int16 const * >(
83*cdf0e10cSrcweir                 value.getValue() ));
84*cdf0e10cSrcweir     case TypeClass_UNSIGNED_SHORT:
85*cdf0e10cSrcweir         return __box
86*cdf0e10cSrcweir             ((::System::UInt16) *reinterpret_cast< sal_uInt16 const * >(
87*cdf0e10cSrcweir                 value.getValue() ));
88*cdf0e10cSrcweir     case TypeClass_LONG:
89*cdf0e10cSrcweir         return __box
90*cdf0e10cSrcweir             ((::System::Int32) *reinterpret_cast< sal_Int32 const * >(
91*cdf0e10cSrcweir                 value.getValue() ));
92*cdf0e10cSrcweir     case TypeClass_UNSIGNED_LONG:
93*cdf0e10cSrcweir         return __box
94*cdf0e10cSrcweir             ((::System::UInt32) *reinterpret_cast< sal_uInt32 const * >(
95*cdf0e10cSrcweir                 value.getValue() ));
96*cdf0e10cSrcweir     case TypeClass_HYPER:
97*cdf0e10cSrcweir         return __box
98*cdf0e10cSrcweir             ((::System::Int64) *reinterpret_cast< sal_Int64 const * >(
99*cdf0e10cSrcweir                 value.getValue() ));
100*cdf0e10cSrcweir     case TypeClass_UNSIGNED_HYPER:
101*cdf0e10cSrcweir         return __box
102*cdf0e10cSrcweir             ((::System::UInt64) *reinterpret_cast< sal_uInt64 const * >(
103*cdf0e10cSrcweir                 value.getValue() ));
104*cdf0e10cSrcweir     case TypeClass_FLOAT:
105*cdf0e10cSrcweir         return __box
106*cdf0e10cSrcweir             ((::System::Single) *reinterpret_cast< float const * >(
107*cdf0e10cSrcweir                 value.getValue() ));
108*cdf0e10cSrcweir     case TypeClass_DOUBLE:
109*cdf0e10cSrcweir         return __box
110*cdf0e10cSrcweir             ((::System::Double) *reinterpret_cast< double const * >(
111*cdf0e10cSrcweir                 value.getValue() ));
112*cdf0e10cSrcweir     default:
113*cdf0e10cSrcweir         throw RuntimeException(
114*cdf0e10cSrcweir             OUSTR("unexpected constant type ") +
115*cdf0e10cSrcweir             value.getValueType().getTypeName(),
116*cdf0e10cSrcweir             Reference< XInterface >() );
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir //------------------------------------------------------------------------------
121*cdf0e10cSrcweir static inline void emit_ldarg( Emit::ILGenerator * code, ::System::Int32 index )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     switch (index)
124*cdf0e10cSrcweir     {
125*cdf0e10cSrcweir     case 0:
126*cdf0e10cSrcweir         code->Emit( Emit::OpCodes::Ldarg_0 );
127*cdf0e10cSrcweir         break;
128*cdf0e10cSrcweir     case 1:
129*cdf0e10cSrcweir         code->Emit( Emit::OpCodes::Ldarg_1 );
130*cdf0e10cSrcweir         break;
131*cdf0e10cSrcweir     case 2:
132*cdf0e10cSrcweir         code->Emit( Emit::OpCodes::Ldarg_2 );
133*cdf0e10cSrcweir         break;
134*cdf0e10cSrcweir     case 3:
135*cdf0e10cSrcweir         code->Emit( Emit::OpCodes::Ldarg_3 );
136*cdf0e10cSrcweir         break;
137*cdf0e10cSrcweir     default:
138*cdf0e10cSrcweir         if (index < 0x100)
139*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_S, (::System::Byte) index );
140*cdf0e10cSrcweir         else if (index < 0x8000)
141*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_S, (::System::Int16) index );
142*cdf0e10cSrcweir         else
143*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg, index );
144*cdf0e10cSrcweir         break;
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir void polymorphicStructNameToStructName(::System::String ** sPolyName)
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir     if ((*sPolyName)->EndsWith(S">") == false)
151*cdf0e10cSrcweir         return;
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     int index = (*sPolyName)->IndexOf('<');
154*cdf0e10cSrcweir     OSL_ASSERT(index != -1);
155*cdf0e10cSrcweir     *sPolyName = (*sPolyName)->Substring(0, index);
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir System::String* mapUnoTypeName(System::String * typeName)
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir 	::System::Text::StringBuilder* buf= new System::Text::StringBuilder();
162*cdf0e10cSrcweir 	::System::String * sUnoName = ::System::String::Copy(typeName);
163*cdf0e10cSrcweir     //determine if the type is a sequence and its dimensions
164*cdf0e10cSrcweir     int dims= 0;
165*cdf0e10cSrcweir     if (typeName->StartsWith(S"["))//if (usUnoName[0] == '[')
166*cdf0e10cSrcweir     {
167*cdf0e10cSrcweir         int index= 1;
168*cdf0e10cSrcweir         while (true)
169*cdf0e10cSrcweir         {
170*cdf0e10cSrcweir             if (typeName->get_Chars(index++) == ']')//if (usUnoName[index++] == ']')
171*cdf0e10cSrcweir                 dims++;
172*cdf0e10cSrcweir             if (typeName->get_Chars(index++) != '[')//usUnoName[index++] != '[')
173*cdf0e10cSrcweir                 break;
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir         sUnoName = sUnoName->Substring(index - 1);//usUnoName = usUnoName.copy(index - 1);
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir 	if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoBool)))
178*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sBoolean));
179*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoChar)))
180*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sChar));
181*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoByte)))
182*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sByte));
183*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoShort)))
184*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sInt16));
185*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoUShort)))
186*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sUInt16));
187*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoLong)))
188*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sInt32));
189*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoULong)))
190*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sUInt32));
191*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoHyper)))
192*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sInt64));
193*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoUHyper)))
194*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sUInt64));
195*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoFloat)))
196*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sSingle));
197*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoDouble)))
198*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sDouble));
199*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoString)))
200*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sString));
201*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoVoid)))
202*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sVoid));
203*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoType)))
204*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sType));
205*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoXInterface)))
206*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sObject));
207*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::sUnoAny)))
208*cdf0e10cSrcweir     {
209*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sAny));
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir     else
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir         //put "unoidl." at the beginning
214*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sUnoidl));
215*cdf0e10cSrcweir         buf->Append(mapUnoPolymorphicName(sUnoName));
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir     // apend []
218*cdf0e10cSrcweir     for (;dims--;)
219*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sBrackets));
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     return buf->ToString();
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir /** For example, there is a uno type
226*cdf0e10cSrcweir     com.sun.star.Foo<char, long>.
227*cdf0e10cSrcweir     The values in the type list
228*cdf0e10cSrcweir     are uno types and are replaced by cli types, such as System.Char,
229*cdf0e10cSrcweir     System.Int32, etc.
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 	Strings can be as complicated as this
232*cdf0e10cSrcweir 	test.MyStruct<char,test.MyStruct<long, []string>>
233*cdf0e10cSrcweir  */
234*cdf0e10cSrcweir System::String* mapUnoPolymorphicName(System::String* unoName)
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir     int index = unoName->IndexOf('<');
237*cdf0e10cSrcweir     if (index == -1)
238*cdf0e10cSrcweir         return unoName;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir     System::Text::StringBuilder * builder =
241*cdf0e10cSrcweir         new System::Text::StringBuilder(unoName->Substring(0, index +1 ));
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 	//Find the first occurrence of ','
244*cdf0e10cSrcweir 	//If the parameter is a polymorphic struct then we neede to ignore everything
245*cdf0e10cSrcweir 	//between the brackets because it can also contain commas
246*cdf0e10cSrcweir     //get the type list within < and >
247*cdf0e10cSrcweir 	int endIndex = unoName->Length - 1;
248*cdf0e10cSrcweir 	index++;
249*cdf0e10cSrcweir 	int cur = index;
250*cdf0e10cSrcweir 	int countParams = 0;
251*cdf0e10cSrcweir 	while (cur <= endIndex)
252*cdf0e10cSrcweir 	{
253*cdf0e10cSrcweir 		System::Char c = unoName->Chars[cur];
254*cdf0e10cSrcweir 		if (c == ',' || c == '>')
255*cdf0e10cSrcweir 		{
256*cdf0e10cSrcweir 			//insert a comma if needed
257*cdf0e10cSrcweir 			if (countParams != 0)
258*cdf0e10cSrcweir 				builder->Append(S",");
259*cdf0e10cSrcweir 			countParams++;
260*cdf0e10cSrcweir 			System::String * sParam = unoName->Substring(index, cur - index);
261*cdf0e10cSrcweir 			//skip the comma
262*cdf0e10cSrcweir 			cur++;
263*cdf0e10cSrcweir 			//the the index to the beginning of the next param
264*cdf0e10cSrcweir 			index = cur;
265*cdf0e10cSrcweir 			builder->Append(mapUnoTypeName(sParam));
266*cdf0e10cSrcweir 		}
267*cdf0e10cSrcweir 		else if (c == '<')
268*cdf0e10cSrcweir 		{
269*cdf0e10cSrcweir 			cur++;
270*cdf0e10cSrcweir 			//continue until the matching '>'
271*cdf0e10cSrcweir 			int numNested = 0;
272*cdf0e10cSrcweir 			for (;;cur++)
273*cdf0e10cSrcweir 			{
274*cdf0e10cSrcweir 				System::Char curChar = unoName->Chars[cur];
275*cdf0e10cSrcweir 				if (curChar == '<')
276*cdf0e10cSrcweir 				{
277*cdf0e10cSrcweir 					numNested ++;
278*cdf0e10cSrcweir 				}
279*cdf0e10cSrcweir 				else if (curChar == '>')
280*cdf0e10cSrcweir 				{
281*cdf0e10cSrcweir 					if (numNested > 0)
282*cdf0e10cSrcweir 						numNested--;
283*cdf0e10cSrcweir 					else
284*cdf0e10cSrcweir 						break;
285*cdf0e10cSrcweir 				}
286*cdf0e10cSrcweir 			}
287*cdf0e10cSrcweir 		}
288*cdf0e10cSrcweir 		cur++;
289*cdf0e10cSrcweir 	}
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     builder->Append((System::Char) '>');
292*cdf0e10cSrcweir     return builder->ToString();
293*cdf0e10cSrcweir }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir //______________________________________________________________________________
298*cdf0e10cSrcweir Assembly * TypeEmitter::type_resolve(
299*cdf0e10cSrcweir     ::System::Object *, ::System::ResolveEventArgs * args )
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir     ::System::String * cts_name = args->get_Name();
302*cdf0e10cSrcweir     ::System::Type * ret_type = m_module_builder->GetType(
303*cdf0e10cSrcweir         cts_name, false /* no exc */ );
304*cdf0e10cSrcweir     if (0 == ret_type)
305*cdf0e10cSrcweir     {
306*cdf0e10cSrcweir         iface_entry * entry = dynamic_cast< iface_entry * >(
307*cdf0e10cSrcweir             m_incomplete_ifaces->get_Item( cts_name ) );
308*cdf0e10cSrcweir         if (0 != entry)
309*cdf0e10cSrcweir             ret_type = entry->m_type_builder;
310*cdf0e10cSrcweir     }
311*cdf0e10cSrcweir     if (0 == ret_type)
312*cdf0e10cSrcweir     {
313*cdf0e10cSrcweir         sal_Int32 len = m_extra_assemblies->get_Length();
314*cdf0e10cSrcweir         for ( sal_Int32 pos = 0; pos < len; ++pos )
315*cdf0e10cSrcweir         {
316*cdf0e10cSrcweir             ret_type = m_extra_assemblies[ pos ]->GetType(
317*cdf0e10cSrcweir                 cts_name, false /* no exc */ );
318*cdf0e10cSrcweir             if (0 != ret_type)
319*cdf0e10cSrcweir             {
320*cdf0e10cSrcweir                 if (g_verbose)
321*cdf0e10cSrcweir                 {
322*cdf0e10cSrcweir                     ::System::Console::WriteLine(
323*cdf0e10cSrcweir                         "> resolving type {0} from {1}.",
324*cdf0e10cSrcweir                         cts_name, ret_type->get_Assembly()->get_FullName() );
325*cdf0e10cSrcweir                 }
326*cdf0e10cSrcweir                 break;
327*cdf0e10cSrcweir             }
328*cdf0e10cSrcweir         }
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir     if (0 != ret_type)
331*cdf0e10cSrcweir         return ret_type->get_Assembly();
332*cdf0e10cSrcweir     return 0;
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir //______________________________________________________________________________
336*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type(
337*cdf0e10cSrcweir     ::System::String * cts_name, bool throw_exc )
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     ::System::Type * ret_type = m_module_builder->GetType( cts_name, false );
340*cdf0e10cSrcweir     //We get the type from the ModuleBuilder even if the type is not complete
341*cdf0e10cSrcweir     //but have been defined.
342*cdf0e10cSrcweir     //if (ret_type == 0)
343*cdf0e10cSrcweir     //{
344*cdf0e10cSrcweir     //    iface_entry * entry = dynamic_cast< iface_entry * >(
345*cdf0e10cSrcweir     //        m_incomplete_ifaces->get_Item( cts_name ) );
346*cdf0e10cSrcweir     //    if (0 != entry)
347*cdf0e10cSrcweir     //        ret_type = entry->m_type_builder;
348*cdf0e10cSrcweir     //}
349*cdf0e10cSrcweir         //try the cli_basetypes assembly
350*cdf0e10cSrcweir     if (ret_type == 0)
351*cdf0e10cSrcweir     {
352*cdf0e10cSrcweir         ::System::Text::StringBuilder * builder = new ::System::Text::StringBuilder(cts_name);
353*cdf0e10cSrcweir         builder->Append(S",cli_basetypes");
354*cdf0e10cSrcweir         ret_type = ::System::Type::GetType(builder->ToString());
355*cdf0e10cSrcweir     }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir     if (ret_type == 0)
358*cdf0e10cSrcweir     {
359*cdf0e10cSrcweir 		try
360*cdf0e10cSrcweir 		{
361*cdf0e10cSrcweir 			// may call on type_resolve()
362*cdf0e10cSrcweir 			return ::System::Type::GetType( cts_name, throw_exc );
363*cdf0e10cSrcweir 		}
364*cdf0e10cSrcweir 		catch (::System::Exception* exc)
365*cdf0e10cSrcweir 		{
366*cdf0e10cSrcweir 			//If the type is not found one may have forgotten to specify assemblies with
367*cdf0e10cSrcweir 			//additional types
368*cdf0e10cSrcweir 			::System::Text::StringBuilder * sb = new ::System::Text::StringBuilder();
369*cdf0e10cSrcweir 			sb->Append(new ::System::String(S"\nThe type "));
370*cdf0e10cSrcweir 			sb->Append(cts_name);
371*cdf0e10cSrcweir 			sb->Append(new ::System::String(S" \n could not be found. Did you forget to " \
372*cdf0e10cSrcweir 				S"specify an additional assembly with the --reference option?\n"));
373*cdf0e10cSrcweir 			if (throw_exc)
374*cdf0e10cSrcweir 				throw new ::System::Exception(sb->ToString(), exc);
375*cdf0e10cSrcweir 		}
376*cdf0e10cSrcweir     }
377*cdf0e10cSrcweir     else
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir         return ret_type;
380*cdf0e10cSrcweir     }
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir //______________________________________________________________________________
384*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type_Exception()
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir     if (0 == m_type_Exception)
387*cdf0e10cSrcweir     {
388*cdf0e10cSrcweir         m_type_Exception = get_type(
389*cdf0e10cSrcweir             S"unoidl.com.sun.star.uno.Exception", false /* no exc */ );
390*cdf0e10cSrcweir         if (0 == m_type_Exception)
391*cdf0e10cSrcweir         {
392*cdf0e10cSrcweir             // define hardcoded type unoidl.com.sun.star.uno.Exception
393*cdf0e10cSrcweir             Emit::TypeBuilder * type_builder =
394*cdf0e10cSrcweir                 m_module_builder->DefineType(
395*cdf0e10cSrcweir                       S"unoidl.com.sun.star.uno.Exception",
396*cdf0e10cSrcweir                       (TypeAttributes) (TypeAttributes::Public |
397*cdf0e10cSrcweir                                         TypeAttributes::BeforeFieldInit |
398*cdf0e10cSrcweir                                         TypeAttributes::AnsiClass),
399*cdf0e10cSrcweir                       __typeof (::System::Exception) );
400*cdf0e10cSrcweir             Emit::FieldBuilder * field_Context = type_builder->DefineField(
401*cdf0e10cSrcweir                 S"Context", __typeof (::System::Object),
402*cdf0e10cSrcweir                 FieldAttributes::Public );
403*cdf0e10cSrcweir             // default .ctor
404*cdf0e10cSrcweir             type_builder->DefineDefaultConstructor( c_ctor_method_attr );
405*cdf0e10cSrcweir             // .ctor
406*cdf0e10cSrcweir             ::System::Type * param_types[] =
407*cdf0e10cSrcweir                   new ::System::Type *[ 2 ];
408*cdf0e10cSrcweir             param_types[ 0 ] = __typeof (::System::String);
409*cdf0e10cSrcweir             param_types[ 1 ] = __typeof (::System::Object);
410*cdf0e10cSrcweir             Emit::ConstructorBuilder * ctor_builder =
411*cdf0e10cSrcweir                 type_builder->DefineConstructor(
412*cdf0e10cSrcweir                     c_ctor_method_attr, CallingConventions::Standard,
413*cdf0e10cSrcweir                     param_types );
414*cdf0e10cSrcweir             ctor_builder->DefineParameter(
415*cdf0e10cSrcweir                 1, ParameterAttributes::In, S"Message" );
416*cdf0e10cSrcweir             ctor_builder->DefineParameter(
417*cdf0e10cSrcweir                 2, ParameterAttributes::In, S"Context" );
418*cdf0e10cSrcweir             Emit::ILGenerator * code = ctor_builder->GetILGenerator();
419*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_0 );
420*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_1 );
421*cdf0e10cSrcweir             param_types = new ::System::Type * [ 1 ];
422*cdf0e10cSrcweir             param_types[ 0 ] = __typeof (::System::String);
423*cdf0e10cSrcweir             code->Emit(
424*cdf0e10cSrcweir                 Emit::OpCodes::Call,
425*cdf0e10cSrcweir                 __typeof (::System::Exception)
426*cdf0e10cSrcweir                   ->GetConstructor( param_types ) );
427*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_0 );
428*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_2 );
429*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Stfld, field_Context );
430*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ret );
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir             if (g_verbose)
433*cdf0e10cSrcweir             {
434*cdf0e10cSrcweir                 ::System::Console::WriteLine(
435*cdf0e10cSrcweir                     "> emitting exception type "
436*cdf0e10cSrcweir                     "unoidl.com.sun.star.uno.Exception" );
437*cdf0e10cSrcweir             }
438*cdf0e10cSrcweir             m_type_Exception = type_builder->CreateType();
439*cdf0e10cSrcweir         }
440*cdf0e10cSrcweir     }
441*cdf0e10cSrcweir     return m_type_Exception;
442*cdf0e10cSrcweir }
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir //______________________________________________________________________________
445*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type_RuntimeException()
446*cdf0e10cSrcweir {
447*cdf0e10cSrcweir     if (0 == m_type_RuntimeException)
448*cdf0e10cSrcweir     {
449*cdf0e10cSrcweir         m_type_RuntimeException = get_type(
450*cdf0e10cSrcweir             S"unoidl.com.sun.star.uno.RuntimeException", false /* no exc */ );
451*cdf0e10cSrcweir         if (0 == m_type_RuntimeException)
452*cdf0e10cSrcweir         {
453*cdf0e10cSrcweir             // define hardcoded type unoidl.com.sun.star.uno.RuntimeException
454*cdf0e10cSrcweir             ::System::Type * type_Exception = get_type_Exception();
455*cdf0e10cSrcweir             Emit::TypeBuilder * type_builder =
456*cdf0e10cSrcweir                   m_module_builder->DefineType(
457*cdf0e10cSrcweir                       S"unoidl.com.sun.star.uno.RuntimeException",
458*cdf0e10cSrcweir                       (TypeAttributes) (TypeAttributes::Public |
459*cdf0e10cSrcweir                                         TypeAttributes::BeforeFieldInit |
460*cdf0e10cSrcweir                                         TypeAttributes::AnsiClass),
461*cdf0e10cSrcweir                       type_Exception );
462*cdf0e10cSrcweir             // default .ctor
463*cdf0e10cSrcweir             type_builder->DefineDefaultConstructor( c_ctor_method_attr );
464*cdf0e10cSrcweir             // .ctor
465*cdf0e10cSrcweir             ::System::Type * param_types [] =
466*cdf0e10cSrcweir                   new ::System::Type * [ 2 ];
467*cdf0e10cSrcweir             param_types[ 0 ] = __typeof (::System::String);
468*cdf0e10cSrcweir             param_types[ 1 ] = __typeof (::System::Object);
469*cdf0e10cSrcweir             Emit::ConstructorBuilder * ctor_builder =
470*cdf0e10cSrcweir                 type_builder->DefineConstructor(
471*cdf0e10cSrcweir                     c_ctor_method_attr, CallingConventions::Standard,
472*cdf0e10cSrcweir                     param_types );
473*cdf0e10cSrcweir             ctor_builder->DefineParameter(
474*cdf0e10cSrcweir                 1, ParameterAttributes::In, S"Message" );
475*cdf0e10cSrcweir             ctor_builder->DefineParameter(
476*cdf0e10cSrcweir                 2, ParameterAttributes::In, S"Context" );
477*cdf0e10cSrcweir             Emit::ILGenerator * code = ctor_builder->GetILGenerator();
478*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_0 );
479*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_1 );
480*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_2 );
481*cdf0e10cSrcweir             code->Emit(
482*cdf0e10cSrcweir                 Emit::OpCodes::Call,
483*cdf0e10cSrcweir                 type_Exception->GetConstructor( param_types ) );
484*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ret );
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir             if (g_verbose)
487*cdf0e10cSrcweir             {
488*cdf0e10cSrcweir                 ::System::Console::WriteLine(
489*cdf0e10cSrcweir                     "> emitting exception type "
490*cdf0e10cSrcweir                     "unoidl.com.sun.star.uno.RuntimeException" );
491*cdf0e10cSrcweir             }
492*cdf0e10cSrcweir             m_type_RuntimeException = type_builder->CreateType();
493*cdf0e10cSrcweir         }
494*cdf0e10cSrcweir     }
495*cdf0e10cSrcweir     return m_type_RuntimeException;
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir //______________________________________________________________________________
499*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type(
500*cdf0e10cSrcweir     Reference< reflection::XConstantTypeDescription > const & xType )
501*cdf0e10cSrcweir {
502*cdf0e10cSrcweir     ::System::String * cts_name = to_cts_name( xType->getName() );
503*cdf0e10cSrcweir     ::System::Type * ret_type = get_type( cts_name, false /* no exc */ );
504*cdf0e10cSrcweir     if (0 == ret_type)
505*cdf0e10cSrcweir     {
506*cdf0e10cSrcweir         Reference< reflection::XConstantTypeDescription > xConstant(
507*cdf0e10cSrcweir             xType, UNO_QUERY_THROW );
508*cdf0e10cSrcweir         ::System::Object * constant =
509*cdf0e10cSrcweir               to_cli_constant( xConstant->getConstantValue() );
510*cdf0e10cSrcweir         Emit::TypeBuilder * type_builder =
511*cdf0e10cSrcweir             m_module_builder->DefineType(
512*cdf0e10cSrcweir                 cts_name,
513*cdf0e10cSrcweir                 (TypeAttributes) (TypeAttributes::Public |
514*cdf0e10cSrcweir                                   TypeAttributes::Sealed |
515*cdf0e10cSrcweir                                   TypeAttributes::BeforeFieldInit |
516*cdf0e10cSrcweir                                   TypeAttributes::AnsiClass) );
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir         Emit::FieldBuilder * field_builder = type_builder->DefineField(
519*cdf0e10cSrcweir             cts_name->Substring( cts_name->LastIndexOf( '.' ) +1 ),
520*cdf0e10cSrcweir             constant->GetType(),
521*cdf0e10cSrcweir             (FieldAttributes) (FieldAttributes::Public |
522*cdf0e10cSrcweir                                FieldAttributes::Static |
523*cdf0e10cSrcweir                                FieldAttributes::Literal) );
524*cdf0e10cSrcweir         field_builder->SetConstant( constant );
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir         if (g_verbose)
527*cdf0e10cSrcweir         {
528*cdf0e10cSrcweir             ::System::Console::WriteLine(
529*cdf0e10cSrcweir                 "> emitting constant type {0}", cts_name );
530*cdf0e10cSrcweir         }
531*cdf0e10cSrcweir         ret_type = type_builder->CreateType();
532*cdf0e10cSrcweir     }
533*cdf0e10cSrcweir     return ret_type;
534*cdf0e10cSrcweir }
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir //______________________________________________________________________________
537*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type(
538*cdf0e10cSrcweir     Reference< reflection::XConstantsTypeDescription > const & xType )
539*cdf0e10cSrcweir {
540*cdf0e10cSrcweir     ::System::String * cts_name = to_cts_name( xType->getName() );
541*cdf0e10cSrcweir     ::System::Type * ret_type = get_type( cts_name, false /* no exc */ );
542*cdf0e10cSrcweir     if (0 == ret_type)
543*cdf0e10cSrcweir     {
544*cdf0e10cSrcweir         Emit::TypeBuilder * type_builder =
545*cdf0e10cSrcweir             m_module_builder->DefineType(
546*cdf0e10cSrcweir                 cts_name,
547*cdf0e10cSrcweir                 (TypeAttributes) (TypeAttributes::Public |
548*cdf0e10cSrcweir                                   TypeAttributes::Sealed |
549*cdf0e10cSrcweir                                   TypeAttributes::BeforeFieldInit |
550*cdf0e10cSrcweir                                   TypeAttributes::AnsiClass) );
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir         Sequence< Reference<
553*cdf0e10cSrcweir             reflection::XConstantTypeDescription > > seq_constants(
554*cdf0e10cSrcweir                 xType->getConstants() );
555*cdf0e10cSrcweir         Reference< reflection::XConstantTypeDescription > const * constants =
556*cdf0e10cSrcweir             seq_constants.getConstArray();
557*cdf0e10cSrcweir         sal_Int32 constants_length = seq_constants.getLength();
558*cdf0e10cSrcweir         for ( sal_Int32 constants_pos = 0;
559*cdf0e10cSrcweir               constants_pos < constants_length; ++constants_pos )
560*cdf0e10cSrcweir         {
561*cdf0e10cSrcweir             Reference<
562*cdf0e10cSrcweir                 reflection::XConstantTypeDescription > const & xConstant =
563*cdf0e10cSrcweir                 constants[ constants_pos ];
564*cdf0e10cSrcweir             ::System::Object * constant =
565*cdf0e10cSrcweir                   to_cli_constant( xConstant->getConstantValue() );
566*cdf0e10cSrcweir             ::System::String * uno_name =
567*cdf0e10cSrcweir                   ustring_to_String( xConstant->getName() );
568*cdf0e10cSrcweir             Emit::FieldBuilder * field_builder = type_builder->DefineField(
569*cdf0e10cSrcweir                 uno_name->Substring( uno_name->LastIndexOf( '.' ) +1 ),
570*cdf0e10cSrcweir                 constant->GetType(),
571*cdf0e10cSrcweir                 (FieldAttributes) (FieldAttributes::Public |
572*cdf0e10cSrcweir                                    FieldAttributes::Static |
573*cdf0e10cSrcweir                                    FieldAttributes::Literal) );
574*cdf0e10cSrcweir             field_builder->SetConstant( constant );
575*cdf0e10cSrcweir         }
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir         if (g_verbose)
578*cdf0e10cSrcweir         {
579*cdf0e10cSrcweir             ::System::Console::WriteLine(
580*cdf0e10cSrcweir                 "> emitting constants group type {0}", cts_name );
581*cdf0e10cSrcweir         }
582*cdf0e10cSrcweir         ret_type = type_builder->CreateType();
583*cdf0e10cSrcweir     }
584*cdf0e10cSrcweir     return ret_type;
585*cdf0e10cSrcweir }
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir //______________________________________________________________________________
588*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type(
589*cdf0e10cSrcweir     Reference< reflection::XEnumTypeDescription > const & xType )
590*cdf0e10cSrcweir {
591*cdf0e10cSrcweir     ::System::String * cts_name = to_cts_name( xType->getName() );
592*cdf0e10cSrcweir     ::System::Type * ret_type = get_type( cts_name, false /* no exc */ );
593*cdf0e10cSrcweir     if (0 == ret_type)
594*cdf0e10cSrcweir     {
595*cdf0e10cSrcweir //         Emit::EnumBuilder * enum_builder =
596*cdf0e10cSrcweir //             m_module_builder->DefineEnum(
597*cdf0e10cSrcweir //                 cts_name,
598*cdf0e10cSrcweir //                 (TypeAttributes) (TypeAttributes::Public |
599*cdf0e10cSrcweir // //                                   TypeAttributes::Sealed |
600*cdf0e10cSrcweir //                                   TypeAttributes::AnsiClass),
601*cdf0e10cSrcweir //                 __typeof (::System::Int32) );
602*cdf0e10cSrcweir         // workaround enum builder bug
603*cdf0e10cSrcweir         Emit::TypeBuilder * enum_builder =
604*cdf0e10cSrcweir             m_module_builder->DefineType(
605*cdf0e10cSrcweir                 cts_name,
606*cdf0e10cSrcweir                 (TypeAttributes) (TypeAttributes::Public |
607*cdf0e10cSrcweir                                   TypeAttributes::Sealed),
608*cdf0e10cSrcweir                 __typeof (::System::Enum) );
609*cdf0e10cSrcweir         enum_builder->DefineField(
610*cdf0e10cSrcweir             S"value__", __typeof (::System::Int32),
611*cdf0e10cSrcweir             (FieldAttributes) (FieldAttributes::Private |
612*cdf0e10cSrcweir                                FieldAttributes::SpecialName |
613*cdf0e10cSrcweir                                FieldAttributes::RTSpecialName) );
614*cdf0e10cSrcweir         Sequence< OUString > seq_enum_names( xType->getEnumNames() );
615*cdf0e10cSrcweir         Sequence< sal_Int32 > seq_enum_values( xType->getEnumValues() );
616*cdf0e10cSrcweir         sal_Int32 enum_length = seq_enum_names.getLength();
617*cdf0e10cSrcweir         OSL_ASSERT( enum_length == seq_enum_values.getLength() );
618*cdf0e10cSrcweir         OUString const * enum_names = seq_enum_names.getConstArray();
619*cdf0e10cSrcweir         sal_Int32 const * enum_values = seq_enum_values.getConstArray();
620*cdf0e10cSrcweir         for ( sal_Int32 enum_pos = 0; enum_pos < enum_length; ++enum_pos )
621*cdf0e10cSrcweir         {
622*cdf0e10cSrcweir //             enum_builder->DefineLiteral(
623*cdf0e10cSrcweir //                 ustring_to_String( enum_names[ enum_pos ] ),
624*cdf0e10cSrcweir //                 __box ((::System::Int32) enum_values[ enum_pos ]) );
625*cdf0e10cSrcweir             Emit::FieldBuilder * field_builder =
626*cdf0e10cSrcweir                 enum_builder->DefineField(
627*cdf0e10cSrcweir                     ustring_to_String( enum_names[ enum_pos ] ),
628*cdf0e10cSrcweir                     enum_builder,
629*cdf0e10cSrcweir                     (FieldAttributes) (FieldAttributes::Public |
630*cdf0e10cSrcweir                                        FieldAttributes::Static |
631*cdf0e10cSrcweir                                        FieldAttributes::Literal) );
632*cdf0e10cSrcweir             field_builder->SetConstant(
633*cdf0e10cSrcweir                 __box ((::System::Int32) enum_values[ enum_pos ]) );
634*cdf0e10cSrcweir         }
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir         if (g_verbose)
637*cdf0e10cSrcweir         {
638*cdf0e10cSrcweir             ::System::Console::WriteLine(
639*cdf0e10cSrcweir                 "> emitting enum type {0}", cts_name );
640*cdf0e10cSrcweir         }
641*cdf0e10cSrcweir         ret_type = enum_builder->CreateType();
642*cdf0e10cSrcweir     }
643*cdf0e10cSrcweir     return ret_type;
644*cdf0e10cSrcweir }
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir //______________________________________________________________________________
647*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type(
648*cdf0e10cSrcweir     Reference< reflection::XCompoundTypeDescription > const & xType )
649*cdf0e10cSrcweir {
650*cdf0e10cSrcweir     OUString uno_name( xType->getName() );
651*cdf0e10cSrcweir     if (TypeClass_EXCEPTION == xType->getTypeClass())
652*cdf0e10cSrcweir     {
653*cdf0e10cSrcweir         if (uno_name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
654*cdf0e10cSrcweir                                        "com.sun.star.uno.Exception") ))
655*cdf0e10cSrcweir         {
656*cdf0e10cSrcweir             return get_type_Exception();
657*cdf0e10cSrcweir         }
658*cdf0e10cSrcweir         if (uno_name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
659*cdf0e10cSrcweir                                        "com.sun.star.uno.RuntimeException") ))
660*cdf0e10cSrcweir         {
661*cdf0e10cSrcweir             return get_type_RuntimeException();
662*cdf0e10cSrcweir         }
663*cdf0e10cSrcweir     }
664*cdf0e10cSrcweir     ::System::String * cts_name = to_cts_name( uno_name );
665*cdf0e10cSrcweir     // if the struct is an instantiated polymorpic struct then we create the simple struct name
666*cdf0e10cSrcweir     // For example:
667*cdf0e10cSrcweir     // void func ([in] PolyStruct<boolean> arg);
668*cdf0e10cSrcweir     //PolyStruct<boolean> will be converted to PolyStruct
669*cdf0e10cSrcweir     polymorphicStructNameToStructName( & cts_name);
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir     ::System::Type * ret_type = get_type( cts_name, false /* no exc */ );
672*cdf0e10cSrcweir     if (0 == ret_type)
673*cdf0e10cSrcweir     {
674*cdf0e10cSrcweir         Reference< reflection::XCompoundTypeDescription > xBaseType(
675*cdf0e10cSrcweir             xType->getBaseType(), UNO_QUERY );
676*cdf0e10cSrcweir         ::System::Type * base_type = (xBaseType.is()
677*cdf0e10cSrcweir                                       ? get_type( xBaseType )
678*cdf0e10cSrcweir                                       : __typeof (::System::Object));
679*cdf0e10cSrcweir         Emit::TypeBuilder * type_builder =
680*cdf0e10cSrcweir             m_module_builder->DefineType(
681*cdf0e10cSrcweir                 cts_name,
682*cdf0e10cSrcweir                 (TypeAttributes) (TypeAttributes::Public |
683*cdf0e10cSrcweir                                   TypeAttributes::BeforeFieldInit |
684*cdf0e10cSrcweir                                   TypeAttributes::AnsiClass),
685*cdf0e10cSrcweir                 base_type );
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir          // insert to be completed
689*cdf0e10cSrcweir         struct_entry * entry = new struct_entry();
690*cdf0e10cSrcweir         xType->acquire();
691*cdf0e10cSrcweir         entry->m_xType = xType.get();
692*cdf0e10cSrcweir         entry->m_type_builder = type_builder;
693*cdf0e10cSrcweir         entry->m_base_type = base_type;
694*cdf0e10cSrcweir         m_incomplete_structs->Add( cts_name, entry );
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir         // type is incomplete
697*cdf0e10cSrcweir         ret_type = type_builder;
698*cdf0e10cSrcweir     }
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir     //In case of an instantiated polymorphic struct we want to return a
701*cdf0e10cSrcweir     //uno.PolymorphicType (inherits Type) rather then Type. This is neaded for constructing
702*cdf0e10cSrcweir     //the service code. We can only do that if the struct is completed.
703*cdf0e10cSrcweir     if (m_generated_structs->get_Item(cts_name))
704*cdf0e10cSrcweir     {
705*cdf0e10cSrcweir         Reference< reflection::XStructTypeDescription> xStructTypeDesc(
706*cdf0e10cSrcweir             xType, UNO_QUERY);
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir         if (xStructTypeDesc.is())
709*cdf0e10cSrcweir         {
710*cdf0e10cSrcweir             Sequence< Reference< reflection::XTypeDescription > > seqTypeArgs = xStructTypeDesc->getTypeArguments();
711*cdf0e10cSrcweir             sal_Int32 numTypes = seqTypeArgs.getLength();
712*cdf0e10cSrcweir             if (numTypes > 0)
713*cdf0e10cSrcweir             {
714*cdf0e10cSrcweir                 //it is an instantiated polymorphic struct
715*cdf0e10cSrcweir                 ::System::String * sCliName = mapUnoTypeName(ustring_to_String(xType->getName()));
716*cdf0e10cSrcweir                 ret_type = ::uno::PolymorphicType::GetType(ret_type, sCliName);
717*cdf0e10cSrcweir             }
718*cdf0e10cSrcweir         }
719*cdf0e10cSrcweir     }
720*cdf0e10cSrcweir     return ret_type;
721*cdf0e10cSrcweir }
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir //______________________________________________________________________________
724*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type(
725*cdf0e10cSrcweir     Reference< reflection::XInterfaceTypeDescription2 > const & xType )
726*cdf0e10cSrcweir {
727*cdf0e10cSrcweir     OUString uno_name( xType->getName() );
728*cdf0e10cSrcweir     if (uno_name.equalsAsciiL(
729*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("com.sun.star.uno.XInterface") ))
730*cdf0e10cSrcweir     {
731*cdf0e10cSrcweir         return __typeof (::System::Object);
732*cdf0e10cSrcweir     }
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir     ::System::String * cts_name = to_cts_name( xType->getName() );
735*cdf0e10cSrcweir     ::System::Type * ret_type = get_type( cts_name, false /* no exc */ );
736*cdf0e10cSrcweir     if (0 == ret_type)
737*cdf0e10cSrcweir     {
738*cdf0e10cSrcweir         Emit::TypeBuilder * type_builder;
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir         TypeAttributes attr = (TypeAttributes) (TypeAttributes::Public |
741*cdf0e10cSrcweir                                                 TypeAttributes::Interface |
742*cdf0e10cSrcweir                                                 TypeAttributes::Abstract |
743*cdf0e10cSrcweir                                                 TypeAttributes::AnsiClass);
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir         std::vector<Reference<reflection::XInterfaceTypeDescription2> > vecBaseTypes;
746*cdf0e10cSrcweir         Sequence<Reference< reflection::XTypeDescription > > seqBaseTypes =
747*cdf0e10cSrcweir             xType->getBaseTypes();
748*cdf0e10cSrcweir         if (seqBaseTypes.getLength() > 0)
749*cdf0e10cSrcweir         {
750*cdf0e10cSrcweir             for (int i = 0; i < seqBaseTypes.getLength(); i++)
751*cdf0e10cSrcweir             {
752*cdf0e10cSrcweir                 Reference<reflection::XInterfaceTypeDescription2> xIfaceTd =
753*cdf0e10cSrcweir                     resolveInterfaceTypedef(seqBaseTypes[i]);
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir                 if (xIfaceTd->getName().equalsAsciiL(
756*cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM("com.sun.star.uno.XInterface") ) == sal_False)
757*cdf0e10cSrcweir                 {
758*cdf0e10cSrcweir                     vecBaseTypes.push_back(xIfaceTd);
759*cdf0e10cSrcweir                 }
760*cdf0e10cSrcweir             }
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir             ::System::Type * base_interfaces [] =
763*cdf0e10cSrcweir                   new ::System::Type * [ vecBaseTypes.size() ];
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir             typedef std::vector<Reference<reflection::XInterfaceTypeDescription2> >::const_iterator it;
766*cdf0e10cSrcweir             int index = 0;
767*cdf0e10cSrcweir             for (it i = vecBaseTypes.begin(); i != vecBaseTypes.end(); i++, index++)
768*cdf0e10cSrcweir                 base_interfaces[ index ] = get_type( *i );
769*cdf0e10cSrcweir             type_builder = m_module_builder->DefineType(
770*cdf0e10cSrcweir                 cts_name, attr, 0, base_interfaces );
771*cdf0e10cSrcweir         }
772*cdf0e10cSrcweir         else
773*cdf0e10cSrcweir         {
774*cdf0e10cSrcweir             ::System::Console::WriteLine(
775*cdf0e10cSrcweir                 "warning: IDL interface {0} is not derived from "
776*cdf0e10cSrcweir                 "com.sun.star.uno.XInterface!",
777*cdf0e10cSrcweir                 ustring_to_String( uno_name ) );
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir             type_builder = m_module_builder->DefineType( cts_name, attr );
780*cdf0e10cSrcweir         }
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir         // insert to be completed
783*cdf0e10cSrcweir         iface_entry * entry = new iface_entry();
784*cdf0e10cSrcweir         xType->acquire();
785*cdf0e10cSrcweir         entry->m_xType = xType.get();
786*cdf0e10cSrcweir         entry->m_type_builder = type_builder;
787*cdf0e10cSrcweir         m_incomplete_ifaces->Add( cts_name, entry );
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir         // type is incomplete
790*cdf0e10cSrcweir         ret_type = type_builder;
791*cdf0e10cSrcweir     }
792*cdf0e10cSrcweir     return ret_type;
793*cdf0e10cSrcweir }
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir //______________________________________________________________________________
797*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type(
798*cdf0e10cSrcweir     Reference< reflection::XServiceTypeDescription2 > const & xType )
799*cdf0e10cSrcweir {
800*cdf0e10cSrcweir     if (xType->isSingleInterfaceBased() == sal_False)
801*cdf0e10cSrcweir         return NULL;
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir     System::String * cts_name = to_cts_name( xType->getName() );
804*cdf0e10cSrcweir     System::Type * ret_type = get_type( cts_name, false /* no exc */ );
805*cdf0e10cSrcweir     if (ret_type != NULL)
806*cdf0e10cSrcweir         return ret_type;
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir     TypeAttributes attr = (TypeAttributes) (TypeAttributes::Public |
809*cdf0e10cSrcweir                                             TypeAttributes::Sealed |
810*cdf0e10cSrcweir                                             TypeAttributes::BeforeFieldInit |
811*cdf0e10cSrcweir                                             TypeAttributes::AnsiClass);
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir     Emit::TypeBuilder * type_builder = m_module_builder->DefineType(
814*cdf0e10cSrcweir         cts_name, attr);
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir     // insert to be completed
817*cdf0e10cSrcweir     service_entry * entry = new service_entry();
818*cdf0e10cSrcweir     xType->acquire();
819*cdf0e10cSrcweir     entry->m_xType = xType.get();
820*cdf0e10cSrcweir     entry->m_type_builder = type_builder;
821*cdf0e10cSrcweir     m_incomplete_services->Add(cts_name,entry );
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir     return type_builder;
824*cdf0e10cSrcweir }
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type(
827*cdf0e10cSrcweir     Reference<reflection::XSingletonTypeDescription2 > const & xType )
828*cdf0e10cSrcweir {
829*cdf0e10cSrcweir     if (xType->isInterfaceBased() == sal_False)
830*cdf0e10cSrcweir         return NULL;
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir     ::System::String* cts_name = to_cts_name( xType->getName() );
833*cdf0e10cSrcweir     ::System::Type * ret_type = get_type( cts_name, false /* no exc */ );
834*cdf0e10cSrcweir     if (ret_type != NULL)
835*cdf0e10cSrcweir         return ret_type;
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir     TypeAttributes attr = static_cast<TypeAttributes>(
838*cdf0e10cSrcweir         TypeAttributes::Public |
839*cdf0e10cSrcweir         TypeAttributes::Sealed |
840*cdf0e10cSrcweir         TypeAttributes::BeforeFieldInit |
841*cdf0e10cSrcweir         TypeAttributes::AnsiClass);
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir     Emit::TypeBuilder * type_builder = m_module_builder->DefineType(
844*cdf0e10cSrcweir         cts_name, attr);
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir     // insert to be completed
847*cdf0e10cSrcweir     singleton_entry * entry = new singleton_entry();
848*cdf0e10cSrcweir     xType->acquire();
849*cdf0e10cSrcweir     entry->m_xType = xType.get();
850*cdf0e10cSrcweir     entry->m_type_builder = type_builder;
851*cdf0e10cSrcweir     m_incomplete_singletons->Add(cts_name,entry );
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir     return type_builder;
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir }
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir //______________________________________________________________________________
858*cdf0e10cSrcweir ::System::Type * TypeEmitter::complete_iface_type( iface_entry * entry )
859*cdf0e10cSrcweir {
860*cdf0e10cSrcweir     Emit::TypeBuilder * type_builder = entry->m_type_builder;
861*cdf0e10cSrcweir     reflection::XInterfaceTypeDescription2 * xType = entry->m_xType;
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir     Sequence<Reference< reflection::XTypeDescription > > seqBaseTypes( xType->getBaseTypes() );
864*cdf0e10cSrcweir     if (seqBaseTypes.getLength() > 0)
865*cdf0e10cSrcweir     {
866*cdf0e10cSrcweir         for (int i = 0; i < seqBaseTypes.getLength(); i++)
867*cdf0e10cSrcweir         {
868*cdf0e10cSrcweir             //make sure we get the interface rather then a typedef
869*cdf0e10cSrcweir             Reference<reflection::XInterfaceTypeDescription2> aBaseType =
870*cdf0e10cSrcweir                 resolveInterfaceTypedef( seqBaseTypes[i]);
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir             if (aBaseType->getName().equalsAsciiL(
873*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM("com.sun.star.uno.XInterface") ) == sal_False)
874*cdf0e10cSrcweir             {
875*cdf0e10cSrcweir                 ::System::String * basetype_name = to_cts_name( aBaseType->getName() );
876*cdf0e10cSrcweir                 iface_entry * base_entry = dynamic_cast< iface_entry * >(
877*cdf0e10cSrcweir                     m_incomplete_ifaces->get_Item( basetype_name ) );
878*cdf0e10cSrcweir                 if (0 != base_entry)
879*cdf0e10cSrcweir                 {
880*cdf0e10cSrcweir                 // complete uncompleted base type first
881*cdf0e10cSrcweir                     complete_iface_type( base_entry );
882*cdf0e10cSrcweir                 }
883*cdf0e10cSrcweir             }
884*cdf0e10cSrcweir         }
885*cdf0e10cSrcweir     }
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir     Sequence<
888*cdf0e10cSrcweir         Reference< reflection::XInterfaceMemberTypeDescription > > seq_members(
889*cdf0e10cSrcweir             xType->getMembers() );
890*cdf0e10cSrcweir     Reference< reflection::XInterfaceMemberTypeDescription > const * members =
891*cdf0e10cSrcweir         seq_members.getConstArray();
892*cdf0e10cSrcweir     sal_Int32 members_length = seq_members.getLength();
893*cdf0e10cSrcweir     for ( sal_Int32 members_pos = 0;
894*cdf0e10cSrcweir           members_pos < members_length; ++members_pos )
895*cdf0e10cSrcweir     {
896*cdf0e10cSrcweir         Reference<
897*cdf0e10cSrcweir             reflection::XInterfaceMemberTypeDescription > const & xMember =
898*cdf0e10cSrcweir             members[ members_pos ];
899*cdf0e10cSrcweir         Sequence< Reference< reflection::XTypeDescription > > seq_exceptions;
900*cdf0e10cSrcweir         Emit::MethodBuilder * method_builder;
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir         const MethodAttributes c_method_attr = (MethodAttributes)
903*cdf0e10cSrcweir             (MethodAttributes::Public |
904*cdf0e10cSrcweir              MethodAttributes::Abstract |
905*cdf0e10cSrcweir              MethodAttributes::Virtual |
906*cdf0e10cSrcweir              MethodAttributes::NewSlot |
907*cdf0e10cSrcweir              MethodAttributes::HideBySig);
908*cdf0e10cSrcweir //#if defined(_MSC_VER) && (_MSC_VER < 1400)
909*cdf0e10cSrcweir //             MethodAttributes::Instance);
910*cdf0e10cSrcweir //#else
911*cdf0e10cSrcweir //	     Instance);
912*cdf0e10cSrcweir //#endif
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir         if (TypeClass_INTERFACE_METHOD == xMember->getTypeClass())
915*cdf0e10cSrcweir         {
916*cdf0e10cSrcweir             Reference< reflection::XInterfaceMethodTypeDescription > xMethod(
917*cdf0e10cSrcweir                 xMember, UNO_QUERY_THROW );
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir             Sequence<
920*cdf0e10cSrcweir                 Reference< reflection::XMethodParameter > > seq_parameters(
921*cdf0e10cSrcweir                     xMethod->getParameters() );
922*cdf0e10cSrcweir             sal_Int32 params_length = seq_parameters.getLength();
923*cdf0e10cSrcweir             ::System::Type * param_types [] =
924*cdf0e10cSrcweir                   new ::System::Type * [ params_length ];
925*cdf0e10cSrcweir             Reference< reflection::XMethodParameter > const * parameters =
926*cdf0e10cSrcweir                 seq_parameters.getConstArray();
927*cdf0e10cSrcweir             // first determine all types
928*cdf0e10cSrcweir             //Make the first param type as return type
929*cdf0e10cSrcweir             sal_Int32 params_pos = 0;
930*cdf0e10cSrcweir             for ( ; params_pos < params_length; ++params_pos )
931*cdf0e10cSrcweir             {
932*cdf0e10cSrcweir                 Reference< reflection::XMethodParameter > const & xParam =
933*cdf0e10cSrcweir                     parameters[ params_pos ];
934*cdf0e10cSrcweir                 ::System::Type * param_type = get_type( xParam->getType() );
935*cdf0e10cSrcweir                 ::System::String * param_type_name = param_type->get_FullName();
936*cdf0e10cSrcweir                 if (xParam->isOut())
937*cdf0e10cSrcweir                 {
938*cdf0e10cSrcweir                     param_type = get_type(
939*cdf0e10cSrcweir                         ::System::String::Concat(
940*cdf0e10cSrcweir                             param_type_name, S"&" ), true );
941*cdf0e10cSrcweir                 }
942*cdf0e10cSrcweir                 param_types[ xParam->getPosition() ] = param_type;
943*cdf0e10cSrcweir             }
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir             // create method
947*cdf0e10cSrcweir //             if (tb)
948*cdf0e10cSrcweir //                 method_builder = type_builder->DefineMethod(
949*cdf0e10cSrcweir //                 ustring_to_String( xMethod->getMemberName() ),
950*cdf0e10cSrcweir //                 c_method_attr, tb,
951*cdf0e10cSrcweir //                 param_types );
952*cdf0e10cSrcweir //             else
953*cdf0e10cSrcweir                 method_builder = type_builder->DefineMethod(
954*cdf0e10cSrcweir                     ustring_to_String( xMethod->getMemberName() ),
955*cdf0e10cSrcweir                     c_method_attr, get_type( xMethod->getReturnType() ),
956*cdf0e10cSrcweir                     param_types );
957*cdf0e10cSrcweir             // then define parameter infos
958*cdf0e10cSrcweir             params_pos = 0;
959*cdf0e10cSrcweir             for ( ; params_pos < params_length; ++params_pos )
960*cdf0e10cSrcweir             {
961*cdf0e10cSrcweir                 Reference< reflection::XMethodParameter > const & xParam =
962*cdf0e10cSrcweir                     parameters[ params_pos ];
963*cdf0e10cSrcweir                 long param_flags = 0;
964*cdf0e10cSrcweir                 if (xParam->isIn())
965*cdf0e10cSrcweir                     param_flags |= ParameterAttributes::In;
966*cdf0e10cSrcweir                 if (xParam->isOut())
967*cdf0e10cSrcweir                     param_flags |= ParameterAttributes::Out;
968*cdf0e10cSrcweir                 OSL_ASSERT( 0 != param_flags );
969*cdf0e10cSrcweir                 method_builder->DefineParameter(
970*cdf0e10cSrcweir                     xParam->getPosition() +1 /* starts with 1 */,
971*cdf0e10cSrcweir                     (ParameterAttributes) param_flags,
972*cdf0e10cSrcweir                     ustring_to_String( xParam->getName() ) );
973*cdf0e10cSrcweir             }
974*cdf0e10cSrcweir             //Apply attribute TypeParametersAttribute to return value if it
975*cdf0e10cSrcweir             //is a parameterized Type. Currently only structs can have parameters.
976*cdf0e10cSrcweir             Reference<reflection::XStructTypeDescription> xReturnStruct(
977*cdf0e10cSrcweir                 xMethod->getReturnType(), UNO_QUERY);
978*cdf0e10cSrcweir 
979*cdf0e10cSrcweir             if (xReturnStruct.is())
980*cdf0e10cSrcweir             {
981*cdf0e10cSrcweir                 Sequence<Reference<reflection::XTypeDescription> > seq_type_args =
982*cdf0e10cSrcweir                     xReturnStruct->getTypeArguments();
983*cdf0e10cSrcweir                 if (seq_type_args.getLength() != 0)
984*cdf0e10cSrcweir                 {
985*cdf0e10cSrcweir                     //get th ctor of the attribute
986*cdf0e10cSrcweir                     ::System::Type * arCtor[] = {::System::Type::GetType(S"System.Type[]")};
987*cdf0e10cSrcweir                     //Get the arguments for the attribute's ctor
988*cdf0e10cSrcweir                     Reference<reflection::XTypeDescription> const * arXTypeArgs =
989*cdf0e10cSrcweir                         seq_type_args.getConstArray();
990*cdf0e10cSrcweir                     int numTypes = seq_type_args.getLength();
991*cdf0e10cSrcweir                     ::System::Type * arCtsTypes[] = new ::System::Type*[numTypes];
992*cdf0e10cSrcweir                     for (int i = 0; i < numTypes; i++)
993*cdf0e10cSrcweir                         arCtsTypes[i] = get_type(arXTypeArgs[i]);
994*cdf0e10cSrcweir                     ::System::Object * arArgs[] = {arCtsTypes};
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir 					Emit::CustomAttributeBuilder * attrBuilder =
997*cdf0e10cSrcweir                         new Emit::CustomAttributeBuilder(
998*cdf0e10cSrcweir                             __typeof(::uno::TypeArgumentsAttribute)
999*cdf0e10cSrcweir                             ->GetConstructor( arCtor),
1000*cdf0e10cSrcweir                             arArgs);
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir                     method_builder->SetCustomAttribute(attrBuilder);
1003*cdf0e10cSrcweir                 }
1004*cdf0e10cSrcweir             }
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir             //define UNO exception attribute (exceptions)--------------------------------------
1007*cdf0e10cSrcweir             Emit::CustomAttributeBuilder* attrBuilder =
1008*cdf0e10cSrcweir                 get_iface_method_exception_attribute(xMethod);
1009*cdf0e10cSrcweir             if (attrBuilder != NULL)
1010*cdf0e10cSrcweir                 method_builder->SetCustomAttribute(attrBuilder);
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir             // oneway attribute
1013*cdf0e10cSrcweir             if (xMethod->isOneway())
1014*cdf0e10cSrcweir             {
1015*cdf0e10cSrcweir                 ::System::Type * arCtorOneway[] = new ::System::Type*[0];
1016*cdf0e10cSrcweir                 ::System::Object * arArgs[] = new ::System::Object*[0];
1017*cdf0e10cSrcweir                 Emit::CustomAttributeBuilder * attrBuilder =
1018*cdf0e10cSrcweir                     new Emit::CustomAttributeBuilder(
1019*cdf0e10cSrcweir                         __typeof(::uno::OnewayAttribute)->GetConstructor( arCtorOneway),
1020*cdf0e10cSrcweir                         arArgs);
1021*cdf0e10cSrcweir                 method_builder->SetCustomAttribute(attrBuilder);
1022*cdf0e10cSrcweir             }
1023*cdf0e10cSrcweir         }
1024*cdf0e10cSrcweir         else // attribute
1025*cdf0e10cSrcweir         {
1026*cdf0e10cSrcweir             OSL_ASSERT(
1027*cdf0e10cSrcweir                 TypeClass_INTERFACE_ATTRIBUTE == xMember->getTypeClass() );
1028*cdf0e10cSrcweir             Reference<
1029*cdf0e10cSrcweir                 reflection::XInterfaceAttributeTypeDescription2 > xAttribute(
1030*cdf0e10cSrcweir                     xMember, UNO_QUERY_THROW );
1031*cdf0e10cSrcweir 
1032*cdf0e10cSrcweir             const MethodAttributes c_property_method_attr = (MethodAttributes)
1033*cdf0e10cSrcweir                 (c_method_attr | MethodAttributes::SpecialName);
1034*cdf0e10cSrcweir 
1035*cdf0e10cSrcweir             ::System::Type * attribute_type = get_type( xAttribute->getType() );
1036*cdf0e10cSrcweir             ::System::Type * parameters [] =
1037*cdf0e10cSrcweir                   new ::System::Type * [ 0 ];
1038*cdf0e10cSrcweir 
1039*cdf0e10cSrcweir             Emit::PropertyBuilder * property_builder =
1040*cdf0e10cSrcweir                 type_builder->DefineProperty(
1041*cdf0e10cSrcweir                     ustring_to_String( xAttribute->getMemberName() ),
1042*cdf0e10cSrcweir                     PropertyAttributes::None,
1043*cdf0e10cSrcweir                     attribute_type, parameters );
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir             //set BoundAttribute, if necessary
1046*cdf0e10cSrcweir             if (xAttribute->isBound())
1047*cdf0e10cSrcweir             {
1048*cdf0e10cSrcweir                 ConstructorInfo * ctorBoundAttr =
1049*cdf0e10cSrcweir                     __typeof(::uno::BoundAttribute)->GetConstructor(
1050*cdf0e10cSrcweir                         new System::Type*[0]);
1051*cdf0e10cSrcweir                 Emit::CustomAttributeBuilder * attrBuilderBound =
1052*cdf0e10cSrcweir                     new Emit::CustomAttributeBuilder(
1053*cdf0e10cSrcweir                         ctorBoundAttr, new ::System::Object*[0]);
1054*cdf0e10cSrcweir                 property_builder->SetCustomAttribute(attrBuilderBound);
1055*cdf0e10cSrcweir             }
1056*cdf0e10cSrcweir 
1057*cdf0e10cSrcweir             // getter
1058*cdf0e10cSrcweir             Emit::MethodBuilder * method_builder =
1059*cdf0e10cSrcweir                 type_builder->DefineMethod(
1060*cdf0e10cSrcweir                     ustring_to_String( OUSTR("get_") +
1061*cdf0e10cSrcweir                                        xAttribute->getMemberName() ),
1062*cdf0e10cSrcweir                     c_property_method_attr, attribute_type, parameters );
1063*cdf0e10cSrcweir 
1064*cdf0e10cSrcweir            //define UNO exception attribute (exceptions)--------------------------------------
1065*cdf0e10cSrcweir             Emit::CustomAttributeBuilder* attrBuilder =
1066*cdf0e10cSrcweir                 get_exception_attribute(xAttribute->getGetExceptions());
1067*cdf0e10cSrcweir             if (attrBuilder != NULL)
1068*cdf0e10cSrcweir                 method_builder->SetCustomAttribute(attrBuilder);
1069*cdf0e10cSrcweir 
1070*cdf0e10cSrcweir             property_builder->SetGetMethod( method_builder );
1071*cdf0e10cSrcweir 
1072*cdf0e10cSrcweir             if (! xAttribute->isReadOnly())
1073*cdf0e10cSrcweir             {
1074*cdf0e10cSrcweir                 // setter
1075*cdf0e10cSrcweir                 parameters = new ::System::Type * [ 1 ];
1076*cdf0e10cSrcweir                 parameters[ 0 ] = attribute_type;
1077*cdf0e10cSrcweir                 method_builder =
1078*cdf0e10cSrcweir                     type_builder->DefineMethod(
1079*cdf0e10cSrcweir                         ustring_to_String( OUSTR("set_") +
1080*cdf0e10cSrcweir                                            xAttribute->getMemberName() ),
1081*cdf0e10cSrcweir                         c_property_method_attr, 0, parameters );
1082*cdf0e10cSrcweir                 // define parameter info
1083*cdf0e10cSrcweir                 method_builder->DefineParameter(
1084*cdf0e10cSrcweir                     1 /* starts with 1 */, ParameterAttributes::In, S"value" );
1085*cdf0e10cSrcweir                 //define UNO exception attribute (exceptions)--------------------------------------
1086*cdf0e10cSrcweir                 Emit::CustomAttributeBuilder* attrBuilder =
1087*cdf0e10cSrcweir                     get_exception_attribute(xAttribute->getSetExceptions());
1088*cdf0e10cSrcweir                 if (attrBuilder != NULL)
1089*cdf0e10cSrcweir                     method_builder->SetCustomAttribute(attrBuilder);
1090*cdf0e10cSrcweir 
1091*cdf0e10cSrcweir                 property_builder->SetSetMethod( method_builder );
1092*cdf0e10cSrcweir             }
1093*cdf0e10cSrcweir         }
1094*cdf0e10cSrcweir     }
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir     // remove from incomplete types map
1097*cdf0e10cSrcweir     ::System::String * cts_name = type_builder->get_FullName();
1098*cdf0e10cSrcweir     m_incomplete_ifaces->Remove( cts_name );
1099*cdf0e10cSrcweir     xType->release();
1100*cdf0e10cSrcweir 
1101*cdf0e10cSrcweir     if (g_verbose)
1102*cdf0e10cSrcweir     {
1103*cdf0e10cSrcweir         ::System::Console::WriteLine(
1104*cdf0e10cSrcweir             "> emitting interface type {0}", cts_name );
1105*cdf0e10cSrcweir     }
1106*cdf0e10cSrcweir     return type_builder->CreateType();
1107*cdf0e10cSrcweir }
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir ::System::Type * TypeEmitter::complete_struct_type( struct_entry * entry )
1110*cdf0e10cSrcweir {
1111*cdf0e10cSrcweir      OSL_ASSERT(entry);
1112*cdf0e10cSrcweir     ::System::String * cts_name = entry->m_type_builder->get_FullName();
1113*cdf0e10cSrcweir 
1114*cdf0e10cSrcweir     //Polymorphic struct, define uno.TypeParametersAttribute
1115*cdf0e10cSrcweir     //A polymorphic struct cannot have a basetype.
1116*cdf0e10cSrcweir     //When we create the template of the struct then we have no exact types
1117*cdf0e10cSrcweir     //and the name does not contain a parameter list
1118*cdf0e10cSrcweir     Sequence< OUString > seq_type_parameters;
1119*cdf0e10cSrcweir     Reference< reflection::XStructTypeDescription> xStructTypeDesc(
1120*cdf0e10cSrcweir         entry->m_xType, UNO_QUERY);
1121*cdf0e10cSrcweir     if (xStructTypeDesc.is())
1122*cdf0e10cSrcweir     {
1123*cdf0e10cSrcweir         seq_type_parameters = xStructTypeDesc->getTypeParameters();
1124*cdf0e10cSrcweir         int numTypes = 0;
1125*cdf0e10cSrcweir         if ((numTypes = seq_type_parameters.getLength()) > 0)
1126*cdf0e10cSrcweir         {
1127*cdf0e10cSrcweir             ::System::Object * aArg[] = new ::System::Object*[numTypes];
1128*cdf0e10cSrcweir             for (int i = 0; i < numTypes; i++)
1129*cdf0e10cSrcweir                 aArg[i] = ustring_to_String(seq_type_parameters.getConstArray()[i]);
1130*cdf0e10cSrcweir             ::System::Object * args[] = {aArg};
1131*cdf0e10cSrcweir 
1132*cdf0e10cSrcweir             ::System::Type * arTypesCtor[] =
1133*cdf0e10cSrcweir             {::System::Type::GetType(S"System.String[]")};
1134*cdf0e10cSrcweir             Emit::CustomAttributeBuilder * attrBuilder =
1135*cdf0e10cSrcweir                 new Emit::CustomAttributeBuilder(
1136*cdf0e10cSrcweir                 __typeof(::uno::TypeParametersAttribute)->GetConstructor(arTypesCtor),
1137*cdf0e10cSrcweir                 args);
1138*cdf0e10cSrcweir             entry->m_type_builder->SetCustomAttribute(attrBuilder);
1139*cdf0e10cSrcweir         }
1140*cdf0e10cSrcweir     }
1141*cdf0e10cSrcweir 
1142*cdf0e10cSrcweir     // optional: lookup base type whether generated entry of this session
1143*cdf0e10cSrcweir     struct_entry * base_type_entry = 0;
1144*cdf0e10cSrcweir     if (0 != entry->m_base_type)
1145*cdf0e10cSrcweir     {
1146*cdf0e10cSrcweir         //ToDo maybe get from incomplete structs
1147*cdf0e10cSrcweir         base_type_entry =
1148*cdf0e10cSrcweir             dynamic_cast< struct_entry * >(
1149*cdf0e10cSrcweir                 m_generated_structs->get_Item(
1150*cdf0e10cSrcweir                     entry->m_base_type->get_FullName() ) );
1151*cdf0e10cSrcweir     }
1152*cdf0e10cSrcweir 
1153*cdf0e10cSrcweir         // members
1154*cdf0e10cSrcweir     Sequence< Reference< reflection::XTypeDescription > > seq_members(
1155*cdf0e10cSrcweir         entry->m_xType->getMemberTypes() );
1156*cdf0e10cSrcweir     Sequence< OUString > seq_member_names( entry->m_xType->getMemberNames() );
1157*cdf0e10cSrcweir     sal_Int32 members_length = seq_members.getLength();
1158*cdf0e10cSrcweir     OSL_ASSERT( seq_member_names.getLength() == members_length );
1159*cdf0e10cSrcweir 	//check if we have a XTypeDescription for every member. If not then the user may
1160*cdf0e10cSrcweir 	//have forgotten to specify additional rdbs with the --extra option.
1161*cdf0e10cSrcweir     Reference< reflection::XTypeDescription > const * pseq_members =
1162*cdf0e10cSrcweir 	        seq_members.getConstArray();
1163*cdf0e10cSrcweir     OUString const * pseq_member_names =
1164*cdf0e10cSrcweir         seq_member_names.getConstArray();
1165*cdf0e10cSrcweir 	for (int i = 0; i < members_length; i++)
1166*cdf0e10cSrcweir 	{
1167*cdf0e10cSrcweir 		const OUString sType(entry->m_xType->getName());
1168*cdf0e10cSrcweir 		const OUString sMemberName(pseq_member_names[i]);
1169*cdf0e10cSrcweir 		if ( ! pseq_members[i].is())
1170*cdf0e10cSrcweir 			throw RuntimeException(OUSTR("Missing type description . Check if you need to " \
1171*cdf0e10cSrcweir 			"specify additional RDBs with the --extra option. Type missing for: ") +  sType +
1172*cdf0e10cSrcweir 			OUSTR("::") + sMemberName,0);
1173*cdf0e10cSrcweir 	}
1174*cdf0e10cSrcweir 
1175*cdf0e10cSrcweir     sal_Int32 all_members_length = 0;
1176*cdf0e10cSrcweir     sal_Int32 member_pos;
1177*cdf0e10cSrcweir     sal_Int32 type_param_pos = 0;
1178*cdf0e10cSrcweir 
1179*cdf0e10cSrcweir     // collect base types; wrong order
1180*cdf0e10cSrcweir     ::System::Collections::ArrayList * base_types_list =
1181*cdf0e10cSrcweir             new ::System::Collections::ArrayList( 3 /* initial capacity */ );
1182*cdf0e10cSrcweir     for (::System::Type * base_type_pos = entry->m_base_type;
1183*cdf0e10cSrcweir         ! base_type_pos->Equals( __typeof (::System::Object) );
1184*cdf0e10cSrcweir         base_type_pos = base_type_pos->get_BaseType() )
1185*cdf0e10cSrcweir     {
1186*cdf0e10cSrcweir         base_types_list->Add( base_type_pos );
1187*cdf0e10cSrcweir         if (base_type_pos->Equals( __typeof (::System::Exception) ))
1188*cdf0e10cSrcweir         {
1189*cdf0e10cSrcweir             // special Message member
1190*cdf0e10cSrcweir             all_members_length += 1;
1191*cdf0e10cSrcweir             break; // don't include System.Exception base classes
1192*cdf0e10cSrcweir         }
1193*cdf0e10cSrcweir         else
1194*cdf0e10cSrcweir         {
1195*cdf0e10cSrcweir             //ensure the base type is complete. Otherwise GetFields won't work
1196*cdf0e10cSrcweir             get_complete_struct(base_type_pos->get_FullName());
1197*cdf0e10cSrcweir             all_members_length +=
1198*cdf0e10cSrcweir                 base_type_pos->GetFields(
1199*cdf0e10cSrcweir                 (BindingFlags) (BindingFlags::Instance |
1200*cdf0e10cSrcweir                 BindingFlags::Public |
1201*cdf0e10cSrcweir                 BindingFlags::DeclaredOnly) )
1202*cdf0e10cSrcweir                 ->get_Length();
1203*cdf0e10cSrcweir         }
1204*cdf0e10cSrcweir     }
1205*cdf0e10cSrcweir 
1206*cdf0e10cSrcweir     // create all_members arrays; right order
1207*cdf0e10cSrcweir     ::System::String * all_member_names[] =
1208*cdf0e10cSrcweir         new ::System::String * [all_members_length + members_length ];
1209*cdf0e10cSrcweir     ::System::Type * all_param_types[] =
1210*cdf0e10cSrcweir         new ::System::Type * [all_members_length + members_length ];
1211*cdf0e10cSrcweir     member_pos = 0;
1212*cdf0e10cSrcweir     for ( sal_Int32 pos = base_types_list->get_Count(); pos--; )
1213*cdf0e10cSrcweir     {
1214*cdf0e10cSrcweir         ::System::Type * base_type = __try_cast< ::System::Type * >(
1215*cdf0e10cSrcweir             base_types_list->get_Item( pos ) );
1216*cdf0e10cSrcweir         if (base_type->Equals( __typeof (::System::Exception) ))
1217*cdf0e10cSrcweir         {
1218*cdf0e10cSrcweir             all_member_names[ member_pos ] = S"Message";
1219*cdf0e10cSrcweir             all_param_types[ member_pos ] = __typeof (::System::String);
1220*cdf0e10cSrcweir             ++member_pos;
1221*cdf0e10cSrcweir         }
1222*cdf0e10cSrcweir         else
1223*cdf0e10cSrcweir         {
1224*cdf0e10cSrcweir             ::System::String * base_type_name = base_type->get_FullName();
1225*cdf0e10cSrcweir 
1226*cdf0e10cSrcweir             //ToDo m_generated_structs?
1227*cdf0e10cSrcweir             struct_entry * entry =
1228*cdf0e10cSrcweir                 dynamic_cast< struct_entry * >(
1229*cdf0e10cSrcweir                 m_generated_structs->get_Item( base_type_name ) );
1230*cdf0e10cSrcweir             if (0 == entry)
1231*cdf0e10cSrcweir             {
1232*cdf0e10cSrcweir                 // complete type
1233*cdf0e10cSrcweir                 FieldInfo * fields [] =
1234*cdf0e10cSrcweir                     base_type->GetFields(
1235*cdf0e10cSrcweir                     (BindingFlags) (BindingFlags::Instance |
1236*cdf0e10cSrcweir                     BindingFlags::Public |
1237*cdf0e10cSrcweir                     BindingFlags::DeclaredOnly) );
1238*cdf0e10cSrcweir                 sal_Int32 len = fields->get_Length();
1239*cdf0e10cSrcweir                 for ( sal_Int32 pos = 0; pos < len; ++pos )
1240*cdf0e10cSrcweir                 {
1241*cdf0e10cSrcweir                     FieldInfo * field = fields[ pos ];
1242*cdf0e10cSrcweir                     all_member_names[ member_pos ] = field->get_Name();
1243*cdf0e10cSrcweir                     all_param_types[ member_pos ] = field->get_FieldType();
1244*cdf0e10cSrcweir                     ++member_pos;
1245*cdf0e10cSrcweir                 }
1246*cdf0e10cSrcweir             }
1247*cdf0e10cSrcweir             else // generated during this session:
1248*cdf0e10cSrcweir                 // members may be incomplete ifaces
1249*cdf0e10cSrcweir             {
1250*cdf0e10cSrcweir                 sal_Int32 len = entry->m_member_names->get_Length();
1251*cdf0e10cSrcweir                 for ( sal_Int32 pos = 0; pos < len; ++pos )
1252*cdf0e10cSrcweir                 {
1253*cdf0e10cSrcweir                     all_member_names[ member_pos ] =
1254*cdf0e10cSrcweir                         entry->m_member_names[ pos ];
1255*cdf0e10cSrcweir                     all_param_types[ member_pos ] =
1256*cdf0e10cSrcweir                         entry->m_param_types[ pos ];
1257*cdf0e10cSrcweir                     ++member_pos;
1258*cdf0e10cSrcweir                 }
1259*cdf0e10cSrcweir             }
1260*cdf0e10cSrcweir         }
1261*cdf0e10cSrcweir     }
1262*cdf0e10cSrcweir     OSL_ASSERT( all_members_length == member_pos );
1263*cdf0e10cSrcweir 
1264*cdf0e10cSrcweir     // build up entry
1265*cdf0e10cSrcweir //    struct_entry * entry = new struct_entry();
1266*cdf0e10cSrcweir     entry->m_member_names = new ::System::String * [ members_length ];
1267*cdf0e10cSrcweir     entry->m_param_types = new ::System::Type * [ members_length ];
1268*cdf0e10cSrcweir 
1269*cdf0e10cSrcweir     // add members
1270*cdf0e10cSrcweir     Emit::FieldBuilder * members[] = new Emit::FieldBuilder * [ members_length ];
1271*cdf0e10cSrcweir     //Reference< reflection::XTypeDescription > const * pseq_members =
1272*cdf0e10cSrcweir     //    seq_members.getConstArray();
1273*cdf0e10cSrcweir     //OUString const * pseq_member_names =
1274*cdf0e10cSrcweir     //    seq_member_names.getConstArray();
1275*cdf0e10cSrcweir 
1276*cdf0e10cSrcweir     int curParamIndex = 0; //count the fields which have parameterized types
1277*cdf0e10cSrcweir     for ( member_pos = 0; member_pos < members_length; ++member_pos )
1278*cdf0e10cSrcweir     {
1279*cdf0e10cSrcweir         ::System::String * field_name =
1280*cdf0e10cSrcweir             ustring_to_String( pseq_member_names[ member_pos ] );
1281*cdf0e10cSrcweir         ::System::Type * field_type;
1282*cdf0e10cSrcweir         //Special handling of struct parameter types
1283*cdf0e10cSrcweir         bool bParameterizedType = false;
1284*cdf0e10cSrcweir         if (pseq_members[ member_pos ]->getTypeClass() == TypeClass_UNKNOWN)
1285*cdf0e10cSrcweir         {
1286*cdf0e10cSrcweir             bParameterizedType = true;
1287*cdf0e10cSrcweir             if (type_param_pos < seq_type_parameters.getLength())
1288*cdf0e10cSrcweir             {
1289*cdf0e10cSrcweir                 field_type = __typeof(::System::Object);
1290*cdf0e10cSrcweir                 type_param_pos++;
1291*cdf0e10cSrcweir             }
1292*cdf0e10cSrcweir             else
1293*cdf0e10cSrcweir             {
1294*cdf0e10cSrcweir                 throw RuntimeException(
1295*cdf0e10cSrcweir                     OUSTR("unexpected member type in ") + entry->m_xType->getName(),
1296*cdf0e10cSrcweir                     Reference< XInterface >() );
1297*cdf0e10cSrcweir             }
1298*cdf0e10cSrcweir         }
1299*cdf0e10cSrcweir         else
1300*cdf0e10cSrcweir         {
1301*cdf0e10cSrcweir             field_type =
1302*cdf0e10cSrcweir                 get_type( pseq_members[ member_pos ] );
1303*cdf0e10cSrcweir         }
1304*cdf0e10cSrcweir         members[ member_pos ] =
1305*cdf0e10cSrcweir             entry->m_type_builder->DefineField(
1306*cdf0e10cSrcweir             field_name, field_type, FieldAttributes::Public );
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir         //parameterized type (polymorphic struct) ?
1309*cdf0e10cSrcweir         if (bParameterizedType && xStructTypeDesc.is())
1310*cdf0e10cSrcweir         {
1311*cdf0e10cSrcweir             //get the name
1312*cdf0e10cSrcweir             OSL_ASSERT(seq_type_parameters.getLength() > curParamIndex);
1313*cdf0e10cSrcweir             ::System::String* sTypeName = ustring_to_String(
1314*cdf0e10cSrcweir                 seq_type_parameters.getConstArray()[curParamIndex++]);
1315*cdf0e10cSrcweir             ::System::Object * args[] = {sTypeName};
1316*cdf0e10cSrcweir             //set ParameterizedTypeAttribute
1317*cdf0e10cSrcweir             ::System::Type * arCtorTypes[] = {__typeof(::System::String)};
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir             Emit::CustomAttributeBuilder * attrBuilder =
1320*cdf0e10cSrcweir                 new Emit::CustomAttributeBuilder(
1321*cdf0e10cSrcweir                 __typeof(::uno::ParameterizedTypeAttribute)
1322*cdf0e10cSrcweir                 ->GetConstructor(arCtorTypes),
1323*cdf0e10cSrcweir                 args);
1324*cdf0e10cSrcweir 
1325*cdf0e10cSrcweir             members[member_pos]->SetCustomAttribute(attrBuilder);
1326*cdf0e10cSrcweir         }
1327*cdf0e10cSrcweir         // add to all_members
1328*cdf0e10cSrcweir         all_member_names[ all_members_length + member_pos ] = field_name;
1329*cdf0e10cSrcweir         all_param_types[ all_members_length + member_pos ] = field_type;
1330*cdf0e10cSrcweir         // add to entry
1331*cdf0e10cSrcweir         entry->m_member_names[ member_pos ] = field_name;
1332*cdf0e10cSrcweir         entry->m_param_types[ member_pos ] = field_type;
1333*cdf0e10cSrcweir     }
1334*cdf0e10cSrcweir     all_members_length += members_length;
1335*cdf0e10cSrcweir 
1336*cdf0e10cSrcweir     // default .ctor
1337*cdf0e10cSrcweir     Emit::ConstructorBuilder * ctor_builder =
1338*cdf0e10cSrcweir         entry->m_type_builder->DefineConstructor(
1339*cdf0e10cSrcweir         c_ctor_method_attr, CallingConventions::Standard,
1340*cdf0e10cSrcweir         new ::System::Type * [ 0 ] );
1341*cdf0e10cSrcweir     Emit::ILGenerator * code = ctor_builder->GetILGenerator();
1342*cdf0e10cSrcweir     code->Emit( Emit::OpCodes::Ldarg_0 );
1343*cdf0e10cSrcweir     code->Emit(
1344*cdf0e10cSrcweir         Emit::OpCodes::Call,
1345*cdf0e10cSrcweir         0 == base_type_entry
1346*cdf0e10cSrcweir         ? entry->m_base_type->GetConstructor( new ::System::Type * [ 0 ] )
1347*cdf0e10cSrcweir         : base_type_entry->m_default_ctor );
1348*cdf0e10cSrcweir     // default initialize members
1349*cdf0e10cSrcweir     for ( member_pos = 0; member_pos < members_length; ++member_pos )
1350*cdf0e10cSrcweir     {
1351*cdf0e10cSrcweir         FieldInfo * field = members[ member_pos ];
1352*cdf0e10cSrcweir         ::System::Type * field_type = field->get_FieldType();
1353*cdf0e10cSrcweir         //            ::System::Type * new_field_type = m_module_builder->GetType(field_type->FullName, false);
1354*cdf0e10cSrcweir         // default initialize:
1355*cdf0e10cSrcweir         // string, type, enum, sequence, struct, exception, any
1356*cdf0e10cSrcweir         if (field_type->Equals( __typeof (::System::String) ))
1357*cdf0e10cSrcweir         {
1358*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_0 );
1359*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldstr, S"" );
1360*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Stfld, field );
1361*cdf0e10cSrcweir         }
1362*cdf0e10cSrcweir         else if (field_type->Equals( __typeof (::System::Type) ))
1363*cdf0e10cSrcweir         {
1364*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_0 );
1365*cdf0e10cSrcweir             code->Emit(
1366*cdf0e10cSrcweir                 Emit::OpCodes::Ldtoken, __typeof (::System::Void) );
1367*cdf0e10cSrcweir             code->Emit(
1368*cdf0e10cSrcweir                 Emit::OpCodes::Call, m_method_info_Type_GetTypeFromHandle );
1369*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Stfld, field );
1370*cdf0e10cSrcweir         }
1371*cdf0e10cSrcweir         else if (field_type->get_IsArray())
1372*cdf0e10cSrcweir         {
1373*cdf0e10cSrcweir             //Find the value type. In case of sequence<sequence< ... > > find the actual value type
1374*cdf0e10cSrcweir             ::System::Type * value = field_type;
1375*cdf0e10cSrcweir             while ((value = value->GetElementType())->get_IsArray());
1376*cdf0e10cSrcweir             //If the value type is a struct then make sure it is fully created.
1377*cdf0e10cSrcweir             get_complete_struct(value->get_FullName());
1378*cdf0e10cSrcweir 
1379*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldarg_0 );
1380*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Ldc_I4_0 );
1381*cdf0e10cSrcweir             code->Emit(
1382*cdf0e10cSrcweir                 Emit::OpCodes::Newarr, field_type->GetElementType() );
1383*cdf0e10cSrcweir             code->Emit( Emit::OpCodes::Stfld, field );
1384*cdf0e10cSrcweir         }
1385*cdf0e10cSrcweir         else if (field_type->get_IsValueType())
1386*cdf0e10cSrcweir         {
1387*cdf0e10cSrcweir             if (field_type->get_FullName()->Equals( S"uno.Any" ))
1388*cdf0e10cSrcweir             {
1389*cdf0e10cSrcweir                 code->Emit( Emit::OpCodes::Ldarg_0 );
1390*cdf0e10cSrcweir                 code->Emit( Emit::OpCodes::Ldsfld, __typeof(::uno::Any)->GetField(S"VOID"));
1391*cdf0e10cSrcweir                 code->Emit( Emit::OpCodes::Stfld, field );
1392*cdf0e10cSrcweir             }
1393*cdf0e10cSrcweir         }
1394*cdf0e10cSrcweir         else if (field_type->get_IsClass())
1395*cdf0e10cSrcweir         {
1396*cdf0e10cSrcweir             /* may be XInterface */
1397*cdf0e10cSrcweir             if (! field_type->Equals( __typeof (::System::Object) ))
1398*cdf0e10cSrcweir             {
1399*cdf0e10cSrcweir                 // struct, exception
1400*cdf0e10cSrcweir                 //make sure the struct is already complete.
1401*cdf0e10cSrcweir                 get_complete_struct(field_type->get_FullName());
1402*cdf0e10cSrcweir                 code->Emit( Emit::OpCodes::Ldarg_0 );
1403*cdf0e10cSrcweir                 code->Emit(
1404*cdf0e10cSrcweir                     Emit::OpCodes::Newobj,
1405*cdf0e10cSrcweir                     //GetConstructor requies that the member types of the object which is to be constructed are already known.
1406*cdf0e10cSrcweir                     field_type->GetConstructor(
1407*cdf0e10cSrcweir                     new ::System::Type * [ 0 ] ) );
1408*cdf0e10cSrcweir                 code->Emit( Emit::OpCodes::Stfld, field );
1409*cdf0e10cSrcweir             }
1410*cdf0e10cSrcweir         }
1411*cdf0e10cSrcweir     }
1412*cdf0e10cSrcweir     code->Emit( Emit::OpCodes::Ret );
1413*cdf0e10cSrcweir     entry->m_default_ctor = ctor_builder;
1414*cdf0e10cSrcweir 
1415*cdf0e10cSrcweir     // parameterized .ctor including all base members
1416*cdf0e10cSrcweir     ctor_builder = entry->m_type_builder->DefineConstructor(
1417*cdf0e10cSrcweir         c_ctor_method_attr, CallingConventions::Standard, all_param_types );
1418*cdf0e10cSrcweir     for ( member_pos = 0; member_pos < all_members_length; ++member_pos )
1419*cdf0e10cSrcweir     {
1420*cdf0e10cSrcweir         ctor_builder->DefineParameter(
1421*cdf0e10cSrcweir             member_pos +1 /* starts with 1 */, ParameterAttributes::In,
1422*cdf0e10cSrcweir             all_member_names[ member_pos ] );
1423*cdf0e10cSrcweir     }
1424*cdf0e10cSrcweir     code = ctor_builder->GetILGenerator();
1425*cdf0e10cSrcweir     // call base .ctor
1426*cdf0e10cSrcweir     code->Emit( Emit::OpCodes::Ldarg_0 ); // push this
1427*cdf0e10cSrcweir     sal_Int32 base_members_length = all_members_length - members_length;
1428*cdf0e10cSrcweir     ::System::Type * param_types [] =
1429*cdf0e10cSrcweir         new ::System::Type * [ base_members_length ];
1430*cdf0e10cSrcweir     for ( member_pos = 0; member_pos < base_members_length; ++member_pos )
1431*cdf0e10cSrcweir     {
1432*cdf0e10cSrcweir         emit_ldarg( code, member_pos +1 );
1433*cdf0e10cSrcweir         param_types[ member_pos ] = all_param_types[ member_pos ];
1434*cdf0e10cSrcweir     }
1435*cdf0e10cSrcweir     code->Emit(
1436*cdf0e10cSrcweir         Emit::OpCodes::Call,
1437*cdf0e10cSrcweir         0 == base_type_entry
1438*cdf0e10cSrcweir         ? entry->m_base_type->GetConstructor( param_types )
1439*cdf0e10cSrcweir         : base_type_entry->m_ctor );
1440*cdf0e10cSrcweir     // initialize members
1441*cdf0e10cSrcweir     for ( member_pos = 0; member_pos < members_length; ++member_pos )
1442*cdf0e10cSrcweir     {
1443*cdf0e10cSrcweir         code->Emit( Emit::OpCodes::Ldarg_0 ); // push this
1444*cdf0e10cSrcweir         emit_ldarg( code, member_pos + base_members_length +1 );
1445*cdf0e10cSrcweir         code->Emit( Emit::OpCodes::Stfld, members[ member_pos ] );
1446*cdf0e10cSrcweir     }
1447*cdf0e10cSrcweir     code->Emit( Emit::OpCodes::Ret );
1448*cdf0e10cSrcweir     entry->m_ctor = ctor_builder;
1449*cdf0e10cSrcweir 
1450*cdf0e10cSrcweir     if (g_verbose)
1451*cdf0e10cSrcweir     {
1452*cdf0e10cSrcweir         ::System::Console::WriteLine(
1453*cdf0e10cSrcweir             "> emitting {0} type {1}",
1454*cdf0e10cSrcweir             TypeClass_STRUCT == entry->m_xType->getTypeClass()
1455*cdf0e10cSrcweir             ? S"struct"
1456*cdf0e10cSrcweir             : S"exception",
1457*cdf0e10cSrcweir             cts_name);
1458*cdf0e10cSrcweir     }
1459*cdf0e10cSrcweir     // new entry
1460*cdf0e10cSrcweir     m_generated_structs->Add(cts_name, entry );
1461*cdf0e10cSrcweir     ::System::Type * ret_type = entry->m_type_builder->CreateType();
1462*cdf0e10cSrcweir 
1463*cdf0e10cSrcweir     // remove from incomplete types map
1464*cdf0e10cSrcweir     m_incomplete_structs->Remove( cts_name );
1465*cdf0e10cSrcweir     entry->m_xType->release();
1466*cdf0e10cSrcweir 
1467*cdf0e10cSrcweir     if (g_verbose)
1468*cdf0e10cSrcweir     {
1469*cdf0e10cSrcweir         ::System::Console::WriteLine(
1470*cdf0e10cSrcweir             "> emitting struct type {0}", cts_name);
1471*cdf0e10cSrcweir     }
1472*cdf0e10cSrcweir     return ret_type;
1473*cdf0e10cSrcweir }
1474*cdf0e10cSrcweir 
1475*cdf0e10cSrcweir //Examples of generated code
1476*cdf0e10cSrcweir // 		public static XWeak constructor1(XComponentContext ctx)
1477*cdf0e10cSrcweir // 		{
1478*cdf0e10cSrcweir // 			XMultiComponentFactory factory = ctx.getServiceManager();
1479*cdf0e10cSrcweir // 			if (factory == null)
1480*cdf0e10cSrcweir // 				throw new com.sun.star.uno.DeploymentException("bla", null);
1481*cdf0e10cSrcweir // 			return (XWeak) factory.createInstanceWithContext("service_specifier", ctx);
1482*cdf0e10cSrcweir // 		}
1483*cdf0e10cSrcweir // 		public static XWeak constructor2(XComponentContext ctx, int a, int b, Any c)
1484*cdf0e10cSrcweir // 		{
1485*cdf0e10cSrcweir // 			XMultiComponentFactory factory = ctx.getServiceManager();
1486*cdf0e10cSrcweir // 			if (factory == null)
1487*cdf0e10cSrcweir // 				throw new com.sun.star.uno.DeploymentException("bla", null);
1488*cdf0e10cSrcweir // 			Any[] arAny = new Any[3];
1489*cdf0e10cSrcweir // 			arAny[0] = new Any(typeof(int), a);
1490*cdf0e10cSrcweir // 			arAny[1] = new Any(typeof(int), b);
1491*cdf0e10cSrcweir //			arAny[2] = new Any(c.Type, c.Value);
1492*cdf0e10cSrcweir // 			return (XWeak) factory.createInstanceWithArgumentsAndContext("service_specifier", arAny, ctx);
1493*cdf0e10cSrcweir // 		}
1494*cdf0e10cSrcweir // Notice that a any parameter is NOT wrapped by another any. Instead the new any is created with the type and value
1495*cdf0e10cSrcweir // of the parameter.
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir // 		public static XWeak constructor3(XComponentContext ctx, params Any[] c)
1498*cdf0e10cSrcweir // 		{
1499*cdf0e10cSrcweir // 			XMultiComponentFactory factory = ctx.getServiceManager();
1500*cdf0e10cSrcweir // 			if (factory == null)
1501*cdf0e10cSrcweir // 				throw new com.sun.star.uno.DeploymentException("bla", null);
1502*cdf0e10cSrcweir // 			return (XWeak) factory.createInstanceWithArgumentsAndContext("service_specifier", c, ctx);
1503*cdf0e10cSrcweir //		}
1504*cdf0e10cSrcweir ::System::Type * TypeEmitter::complete_service_type(service_entry * entry)
1505*cdf0e10cSrcweir {
1506*cdf0e10cSrcweir     Emit::TypeBuilder * type_builder = entry->m_type_builder;
1507*cdf0e10cSrcweir     reflection::XServiceTypeDescription2 * xServiceType = entry->m_xType;
1508*cdf0e10cSrcweir 
1509*cdf0e10cSrcweir     //Create the private default constructor
1510*cdf0e10cSrcweir     Emit::ConstructorBuilder* ctor_builder =
1511*cdf0e10cSrcweir         type_builder->DefineConstructor(
1512*cdf0e10cSrcweir             (MethodAttributes) (MethodAttributes::Private |
1513*cdf0e10cSrcweir                                 MethodAttributes::HideBySig |
1514*cdf0e10cSrcweir                                 MethodAttributes::SpecialName |
1515*cdf0e10cSrcweir                                 MethodAttributes::RTSpecialName),
1516*cdf0e10cSrcweir             CallingConventions::Standard, NULL);
1517*cdf0e10cSrcweir 
1518*cdf0e10cSrcweir     Emit::ILGenerator* ilGen = ctor_builder->GetILGenerator();
1519*cdf0e10cSrcweir     ilGen->Emit( Emit::OpCodes::Ldarg_0 ); // push this
1520*cdf0e10cSrcweir     ilGen->Emit(
1521*cdf0e10cSrcweir             Emit::OpCodes::Call,
1522*cdf0e10cSrcweir             type_builder->BaseType->GetConstructor(new ::System::Type*[0]));
1523*cdf0e10cSrcweir     ilGen->Emit( Emit::OpCodes::Ret );
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir 
1526*cdf0e10cSrcweir     //Create the service constructors.
1527*cdf0e10cSrcweir     //obtain the interface which makes up this service, it is the return
1528*cdf0e10cSrcweir     //type of the constructor functions
1529*cdf0e10cSrcweir     Reference<reflection::XInterfaceTypeDescription2> xIfaceType(
1530*cdf0e10cSrcweir         xServiceType->getInterface(), UNO_QUERY);
1531*cdf0e10cSrcweir     if (xIfaceType.is () == sal_False)
1532*cdf0e10cSrcweir         xIfaceType = resolveInterfaceTypedef(xServiceType->getInterface());
1533*cdf0e10cSrcweir     System::Type * retType = get_type(xIfaceType);
1534*cdf0e10cSrcweir 
1535*cdf0e10cSrcweir     //Create the ConstructorInfo for a DeploymentException
1536*cdf0e10cSrcweir     ::System::Type * typeDeploymentExc =
1537*cdf0e10cSrcweir           get_type(S"unoidl.com.sun.star.uno.DeploymentException", true);
1538*cdf0e10cSrcweir 
1539*cdf0e10cSrcweir     ::System::Type * arTypeCtor[] = {__typeof(::System::String),
1540*cdf0e10cSrcweir                                          __typeof(::System::Object)};
1541*cdf0e10cSrcweir     ::System::Reflection::ConstructorInfo * ctorDeploymentException  =
1542*cdf0e10cSrcweir           typeDeploymentExc->GetConstructor(arTypeCtor);
1543*cdf0e10cSrcweir 
1544*cdf0e10cSrcweir     Sequence<Reference<reflection::XServiceConstructorDescription> >  seqCtors =
1545*cdf0e10cSrcweir         xServiceType->getConstructors();
1546*cdf0e10cSrcweir 
1547*cdf0e10cSrcweir     ::System::Type * type_uno_exception = get_type(S"unoidl.com.sun.star.uno.Exception", true);
1548*cdf0e10cSrcweir 
1549*cdf0e10cSrcweir     for (int i = seqCtors.getLength() - 1; i >= 0; i--)
1550*cdf0e10cSrcweir     {
1551*cdf0e10cSrcweir         bool bParameterArray = false;
1552*cdf0e10cSrcweir         ::System::Type * typeAny = __typeof(::uno::Any);
1553*cdf0e10cSrcweir         const Reference<reflection::XServiceConstructorDescription> & ctorDes =
1554*cdf0e10cSrcweir             seqCtors[i];
1555*cdf0e10cSrcweir         //obtain the parameter types
1556*cdf0e10cSrcweir         Sequence<Reference<reflection::XParameter> > seqParams =
1557*cdf0e10cSrcweir             ctorDes->getParameters();
1558*cdf0e10cSrcweir         Reference<reflection::XParameter> const * arXParams = seqParams.getConstArray();
1559*cdf0e10cSrcweir         sal_Int32 cParams = seqParams.getLength();
1560*cdf0e10cSrcweir         ::System::Type * arTypeParameters[] = new ::System::Type* [cParams + 1];
1561*cdf0e10cSrcweir         arTypeParameters[0] = get_type(S"unoidl.com.sun.star.uno.XComponentContext", true);
1562*cdf0e10cSrcweir         for (int iparam = 0; iparam != cParams; iparam++)
1563*cdf0e10cSrcweir         {
1564*cdf0e10cSrcweir             if (arXParams[iparam]->isRestParameter())
1565*cdf0e10cSrcweir                 arTypeParameters[iparam + 1] = __typeof(::uno::Any[]);
1566*cdf0e10cSrcweir             else
1567*cdf0e10cSrcweir                 arTypeParameters[iparam + 1] = get_type(arXParams[iparam]->getType());
1568*cdf0e10cSrcweir         }
1569*cdf0e10cSrcweir         //The array arTypeParameters can contain:
1570*cdf0e10cSrcweir 		//System.Type and uno.PolymorphicType.
1571*cdf0e10cSrcweir 		//Passing PolymorphicType to MethodBuilder.DefineMethod will cause a problem.
1572*cdf0e10cSrcweir 		//The exception will read something like no on information for parameter # d
1573*cdf0e10cSrcweir 		//Maybe we need no override another Type method in PolymorphicType ...
1574*cdf0e10cSrcweir 		//Until we have figured this out, we will create another array of System.Type which
1575*cdf0e10cSrcweir 		//we pass on to DefineMethod.
1576*cdf0e10cSrcweir 		::System::Type * arParamTypes[] = new ::System::Type * [cParams + 1];
1577*cdf0e10cSrcweir //        arParamTypes[0] = get_type(S"unoidl.com.sun.star.uno.XComponentContext", true);
1578*cdf0e10cSrcweir 		for (int i = 0; i < cParams + 1; i++)
1579*cdf0e10cSrcweir 		{
1580*cdf0e10cSrcweir 			::uno::PolymorphicType * pT = dynamic_cast< ::uno::PolymorphicType * >(arTypeParameters[i]);
1581*cdf0e10cSrcweir 			if (pT)
1582*cdf0e10cSrcweir 				arParamTypes[i] = pT->OriginalType;
1583*cdf0e10cSrcweir 			else
1584*cdf0e10cSrcweir 				arParamTypes[i] = arTypeParameters[i];
1585*cdf0e10cSrcweir 		}
1586*cdf0e10cSrcweir         //define method
1587*cdf0e10cSrcweir 		System::String * ctorName;
1588*cdf0e10cSrcweir         if (ctorDes->isDefaultConstructor())
1589*cdf0e10cSrcweir             ctorName = new ::System::String(S"create");
1590*cdf0e10cSrcweir         else
1591*cdf0e10cSrcweir             ctorName = ustring_to_String(ctorDes->getName());
1592*cdf0e10cSrcweir         Emit::MethodBuilder* method_builder = type_builder->DefineMethod(
1593*cdf0e10cSrcweir             ctorName,
1594*cdf0e10cSrcweir             static_cast<MethodAttributes>(MethodAttributes::Public | MethodAttributes::HideBySig |
1595*cdf0e10cSrcweir                                           MethodAttributes::Static),
1596*cdf0e10cSrcweir             retType,
1597*cdf0e10cSrcweir //            arTypeParameters);
1598*cdf0e10cSrcweir 			arParamTypes);
1599*cdf0e10cSrcweir 
1600*cdf0e10cSrcweir         //define UNO exception attribute (exceptions)--------------------------------------
1601*cdf0e10cSrcweir         Emit::CustomAttributeBuilder* attrBuilder = get_service_exception_attribute(ctorDes);
1602*cdf0e10cSrcweir         if (attrBuilder != NULL)
1603*cdf0e10cSrcweir             method_builder->SetCustomAttribute(attrBuilder);
1604*cdf0e10cSrcweir 
1605*cdf0e10cSrcweir 		//-------------------------------------------------------------
1606*cdf0e10cSrcweir         //define parameter attributes (paramarray), names etc.
1607*cdf0e10cSrcweir         //The first parameter is the XComponentContext, which cannot be obtained
1608*cdf0e10cSrcweir         //from reflection.
1609*cdf0e10cSrcweir         //The context is not part of the idl description
1610*cdf0e10cSrcweir         method_builder->DefineParameter(
1611*cdf0e10cSrcweir             1, ParameterAttributes::In, S"the_context");
1612*cdf0e10cSrcweir 
1613*cdf0e10cSrcweir         Emit::ParameterBuilder * arParameterBuilder[] =
1614*cdf0e10cSrcweir             new Emit::ParameterBuilder * [cParams];
1615*cdf0e10cSrcweir         for (int iparam = 0; iparam != cParams; iparam++)
1616*cdf0e10cSrcweir         {
1617*cdf0e10cSrcweir             Reference<reflection::XParameter> const & aParam = arXParams[iparam];
1618*cdf0e10cSrcweir             ::System::String * sParamName = ustring_to_String(aParam->getName());
1619*cdf0e10cSrcweir 
1620*cdf0e10cSrcweir             arParameterBuilder[iparam] = method_builder->DefineParameter(
1621*cdf0e10cSrcweir                 iparam + 2, ParameterAttributes::In, sParamName);
1622*cdf0e10cSrcweir 
1623*cdf0e10cSrcweir             if (aParam->isRestParameter())
1624*cdf0e10cSrcweir             {
1625*cdf0e10cSrcweir                 bParameterArray = true;
1626*cdf0e10cSrcweir                 //set the ParameterArrayAttribute
1627*cdf0e10cSrcweir                 ::System::Reflection::ConstructorInfo* ctor_info =
1628*cdf0e10cSrcweir                     __typeof(System::ParamArrayAttribute)->GetConstructor(
1629*cdf0e10cSrcweir                         new ::System::Type*[0]);
1630*cdf0e10cSrcweir                 Emit::CustomAttributeBuilder * attr_builder =
1631*cdf0e10cSrcweir                     new Emit::CustomAttributeBuilder(ctor_info, new ::System::Object*[0]);
1632*cdf0e10cSrcweir 				arParameterBuilder[iparam]->SetCustomAttribute(attr_builder);
1633*cdf0e10cSrcweir                 break;
1634*cdf0e10cSrcweir             }
1635*cdf0e10cSrcweir         }
1636*cdf0e10cSrcweir 
1637*cdf0e10cSrcweir         Emit::ILGenerator * ilGen = method_builder->GetILGenerator();
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir         //Define locals ---------------------------------
1640*cdf0e10cSrcweir         //XMultiComponentFactory
1641*cdf0e10cSrcweir         Emit::LocalBuilder* local_factory =
1642*cdf0e10cSrcweir             ilGen->DeclareLocal(
1643*cdf0e10cSrcweir                 get_type(S"unoidl.com.sun.star.lang.XMultiComponentFactory", true));
1644*cdf0e10cSrcweir 
1645*cdf0e10cSrcweir         //The return type
1646*cdf0e10cSrcweir         Emit::LocalBuilder* local_return_val =
1647*cdf0e10cSrcweir             ilGen->DeclareLocal(retType);
1648*cdf0e10cSrcweir 
1649*cdf0e10cSrcweir         //Obtain the XMultiComponentFactory and throw an exception if we do not get one
1650*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Ldarg_0);
1651*cdf0e10cSrcweir 
1652*cdf0e10cSrcweir         ::System::Reflection::MethodInfo * methodGetServiceManager = get_type(
1653*cdf0e10cSrcweir             S"unoidl.com.sun.star.uno.XComponentContext", true)
1654*cdf0e10cSrcweir                 ->GetMethod(S"getServiceManager");
1655*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Callvirt, methodGetServiceManager);
1656*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Stloc, local_factory);
1657*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Ldloc, local_factory);
1658*cdf0e10cSrcweir         Emit::Label label1 = ilGen->DefineLabel();
1659*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Brtrue, label1);
1660*cdf0e10cSrcweir         //The string for the exception
1661*cdf0e10cSrcweir         ::System::Text::StringBuilder * strbuilder = new ::System::Text::StringBuilder(256);
1662*cdf0e10cSrcweir         strbuilder->Append(S"The service ");
1663*cdf0e10cSrcweir         strbuilder->Append(to_cts_name(xServiceType->getName()));
1664*cdf0e10cSrcweir         strbuilder->Append(S" could not be created. The context failed to supply the service manager.");
1665*cdf0e10cSrcweir 
1666*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Ldstr, strbuilder->ToString());
1667*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Ldarg_0);
1668*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Newobj, ctorDeploymentException);
1669*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Throw);
1670*cdf0e10cSrcweir         ilGen->MarkLabel(label1);
1671*cdf0e10cSrcweir 
1672*cdf0e10cSrcweir         //We create a try/ catch around the createInstanceWithContext, etc. functions
1673*cdf0e10cSrcweir         //There are 3 cases
1674*cdf0e10cSrcweir         //1. function do not specify exceptions. Then RuntimeExceptions are retrhown and other
1675*cdf0e10cSrcweir         //   exceptions produce a DeploymentException.
1676*cdf0e10cSrcweir         //2. function specify  Exception. Then all exceptions fly through
1677*cdf0e10cSrcweir         //3. function specifies exceptions but no Exception. Then these are rethrown
1678*cdf0e10cSrcweir         //   and other exceptions, except RuntimeException, produce a deployment exception.
1679*cdf0e10cSrcweir         //In case there are no parameters we call
1680*cdf0e10cSrcweir         //XMultiComponentFactory.createInstanceWithContext
1681*cdf0e10cSrcweir 
1682*cdf0e10cSrcweir         ::System::Collections::ArrayList * arExceptionTypes =
1683*cdf0e10cSrcweir               get_service_ctor_method_exceptions_reduced(ctorDes->getExceptions());
1684*cdf0e10cSrcweir         if (arExceptionTypes->Contains(
1685*cdf0e10cSrcweir                 type_uno_exception) == false)
1686*cdf0e10cSrcweir         {
1687*cdf0e10cSrcweir             ilGen->BeginExceptionBlock();
1688*cdf0e10cSrcweir         }
1689*cdf0e10cSrcweir         if (cParams == 0)
1690*cdf0e10cSrcweir         {
1691*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldloc, local_factory);
1692*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldstr, ustring_to_String(xServiceType->getName()));
1693*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldarg_0);
1694*cdf0e10cSrcweir 
1695*cdf0e10cSrcweir             ::System::Reflection::MethodInfo * methodCreate =
1696*cdf0e10cSrcweir                     local_factory->get_LocalType()->GetMethod(S"createInstanceWithContext");
1697*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Callvirt, methodCreate);
1698*cdf0e10cSrcweir         }
1699*cdf0e10cSrcweir         else if(bParameterArray)
1700*cdf0e10cSrcweir         {
1701*cdf0e10cSrcweir             //Service constructor with parameter array
1702*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldloc, local_factory);
1703*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldstr, ustring_to_String(xServiceType->getName()));
1704*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldarg_1);
1705*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldarg_0);
1706*cdf0e10cSrcweir             ::System::Reflection::MethodInfo * methodCreate =
1707*cdf0e10cSrcweir                     local_factory->get_LocalType()->GetMethod(S"createInstanceWithArgumentsAndContext");
1708*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Callvirt, methodCreate);
1709*cdf0e10cSrcweir         }
1710*cdf0e10cSrcweir         else
1711*cdf0e10cSrcweir         {
1712*cdf0e10cSrcweir             // Any param1, Any param2, etc.
1713*cdf0e10cSrcweir             // For each parameter,except the component context, and parameter array
1714*cdf0e10cSrcweir             // and Any is created.
1715*cdf0e10cSrcweir             Emit::LocalBuilder * arLocalAny[] = new Emit::LocalBuilder* [cParams];
1716*cdf0e10cSrcweir 
1717*cdf0e10cSrcweir             for (int iParam = 0; iParam < cParams; iParam ++)
1718*cdf0e10cSrcweir             {
1719*cdf0e10cSrcweir                 arLocalAny[iParam] = ilGen->DeclareLocal(typeAny);
1720*cdf0e10cSrcweir             }
1721*cdf0e10cSrcweir 
1722*cdf0e10cSrcweir             //Any[]. This array is filled with the created Anys which contain the parameters
1723*cdf0e10cSrcweir             //and the values contained in the parameter array
1724*cdf0e10cSrcweir             Emit::LocalBuilder * local_anyParams =
1725*cdf0e10cSrcweir                 ilGen->DeclareLocal(__typeof(::uno::Any[]));
1726*cdf0e10cSrcweir 
1727*cdf0e10cSrcweir             //Create the Any for every argument, except for the parameter array
1728*cdf0e10cSrcweir             //arLocalAny contains the LocalBuilder for all these parameters.
1729*cdf0e10cSrcweir             //we call the ctor Any(Type, Object)
1730*cdf0e10cSrcweir 			//If the parameter is an Any then the Any is created with Any(param.Type, param.Value);
1731*cdf0e10cSrcweir             ::System::Type * arTypesCtorAny[] = {__typeof(::System::Type),
1732*cdf0e10cSrcweir                                                     __typeof(::System::Object)};
1733*cdf0e10cSrcweir             ::System::Reflection::ConstructorInfo * ctorAny =
1734*cdf0e10cSrcweir                 typeAny->GetConstructor( arTypesCtorAny);
1735*cdf0e10cSrcweir 			::System::Reflection::MethodInfo * methodAnyGetType =
1736*cdf0e10cSrcweir 				typeAny->GetProperty(S"Type")->GetGetMethod();
1737*cdf0e10cSrcweir 			::System::Reflection::MethodInfo * methodAnyGetValue =
1738*cdf0e10cSrcweir 				typeAny->GetProperty(S"Value")->GetGetMethod();
1739*cdf0e10cSrcweir             for (int i = 0; i < arLocalAny->Length; i ++)
1740*cdf0e10cSrcweir             {
1741*cdf0e10cSrcweir 				//check if the parameter is a polymorphic struct
1742*cdf0e10cSrcweir 				::uno::PolymorphicType *polyType = dynamic_cast< ::uno::PolymorphicType* >(arTypeParameters[i+1]);
1743*cdf0e10cSrcweir 				//arTypeParameters[i+1] = polyType->OriginalType;
1744*cdf0e10cSrcweir 				if (polyType)
1745*cdf0e10cSrcweir 				{
1746*cdf0e10cSrcweir 					//It is a polymorphic struct
1747*cdf0e10cSrcweir 					//Load the uninitialized local Any on which we will call the ctor
1748*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldloca, arLocalAny[i]);
1749*cdf0e10cSrcweir 					// Call PolymorphicType PolymorphicType::GetType(Type t, String polyName)
1750*cdf0e10cSrcweir 					// Prepare the first parameter
1751*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldtoken, polyType->get_OriginalType());
1752*cdf0e10cSrcweir 					::System::Type * arTypeParams[] = {__typeof(::System::RuntimeTypeHandle)};
1753*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Call,
1754*cdf0e10cSrcweir 								__typeof(::System::Type)->GetMethod(
1755*cdf0e10cSrcweir 									S"GetTypeFromHandle", arTypeParams));
1756*cdf0e10cSrcweir 					// Prepare the second parameter
1757*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldstr, polyType->get_PolymorphicName());
1758*cdf0e10cSrcweir 					// Make the actual call
1759*cdf0e10cSrcweir 					::System::Type * arTypeParam_GetType[] = {
1760*cdf0e10cSrcweir 						__typeof(::System::Type), __typeof(::System::String) };
1761*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Call,
1762*cdf0e10cSrcweir 					__typeof(::uno::PolymorphicType)->GetMethod(new System::String(S"GetType"),
1763*cdf0e10cSrcweir 						arTypeParam_GetType));
1764*cdf0e10cSrcweir 
1765*cdf0e10cSrcweir 					//Stack is: localAny, PolymorphicType
1766*cdf0e10cSrcweir 					//Call Any::Any(Type, Object)
1767*cdf0e10cSrcweir 					//Prepare the second parameter for the any ctor
1768*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldarg, i + 1);
1769*cdf0e10cSrcweir 					// if the parameter is a value type then we need to box it, because
1770*cdf0e10cSrcweir 					// the Any ctor takes an Object
1771*cdf0e10cSrcweir 					if (arTypeParameters[i+1]->IsValueType)
1772*cdf0e10cSrcweir 						ilGen->Emit(Emit::OpCodes::Box, arTypeParameters[i+1]);
1773*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Call, ctorAny);
1774*cdf0e10cSrcweir 				}
1775*cdf0e10cSrcweir 				else if (arTypeParameters[i+1] == typeAny)
1776*cdf0e10cSrcweir 				{
1777*cdf0e10cSrcweir 					//Create the call new Any(param.Type,param,Value)
1778*cdf0e10cSrcweir 					//Stack must be Any,Type,Value
1779*cdf0e10cSrcweir 					//First load the Any which is to be constructed
1780*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldloca, arLocalAny[i]);
1781*cdf0e10cSrcweir 					//Load the Type, which is obtained by calling param.Type
1782*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldarga, i + 1);
1783*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Call, methodAnyGetType);
1784*cdf0e10cSrcweir 					//Load the Value, which is obtained by calling param.Value
1785*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldarga, i + 1);
1786*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Call, methodAnyGetValue);
1787*cdf0e10cSrcweir 					//Call the Any ctor.
1788*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Call, ctorAny);
1789*cdf0e10cSrcweir 				}
1790*cdf0e10cSrcweir 				else
1791*cdf0e10cSrcweir 				{
1792*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldloca, arLocalAny[i]);
1793*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldtoken, arTypeParameters[i+1]);
1794*cdf0e10cSrcweir 
1795*cdf0e10cSrcweir 					::System::Type * arTypeParams[] = {__typeof(::System::RuntimeTypeHandle)};
1796*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Call,
1797*cdf0e10cSrcweir 								__typeof(::System::Type)->GetMethod(
1798*cdf0e10cSrcweir 									S"GetTypeFromHandle", arTypeParams));
1799*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Ldarg, i + 1);
1800*cdf0e10cSrcweir 					// if the parameter is a value type then we need to box it, because
1801*cdf0e10cSrcweir 					// the Any ctor takes an Object
1802*cdf0e10cSrcweir 					if (arTypeParameters[i+1]->IsValueType)
1803*cdf0e10cSrcweir 						ilGen->Emit(Emit::OpCodes::Box, arTypeParameters[i+1]);
1804*cdf0e10cSrcweir 					ilGen->Emit(Emit::OpCodes::Call, ctorAny);
1805*cdf0e10cSrcweir 				}
1806*cdf0e10cSrcweir             }
1807*cdf0e10cSrcweir 
1808*cdf0e10cSrcweir             //Create the Any[] that is passed to the
1809*cdf0e10cSrcweir             //createInstanceWithContext[AndArguments] function
1810*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldc_I4, arLocalAny->Length);
1811*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Newarr, typeAny);
1812*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Stloc, local_anyParams);
1813*cdf0e10cSrcweir 
1814*cdf0e10cSrcweir             //Assign all anys created from the parameters
1815*cdf0e10cSrcweir             //array to the Any[]
1816*cdf0e10cSrcweir             for (int i = 0; i < arLocalAny->Length; i++)
1817*cdf0e10cSrcweir             {
1818*cdf0e10cSrcweir                 ilGen->Emit(Emit::OpCodes::Ldloc, local_anyParams);
1819*cdf0e10cSrcweir                 ilGen->Emit(Emit::OpCodes::Ldc_I4, i);
1820*cdf0e10cSrcweir                 ilGen->Emit(Emit::OpCodes::Ldelema, typeAny);
1821*cdf0e10cSrcweir                 ilGen->Emit(Emit::OpCodes::Ldloc, arLocalAny[i]);
1822*cdf0e10cSrcweir                 ilGen->Emit(Emit::OpCodes::Stobj, typeAny);
1823*cdf0e10cSrcweir             }
1824*cdf0e10cSrcweir             // call createInstanceWithContextAndArguments
1825*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldloc, local_factory);
1826*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldstr, ustring_to_String(xServiceType->getName()));
1827*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldloc, local_anyParams);
1828*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldarg_0);
1829*cdf0e10cSrcweir             ::System::Reflection::MethodInfo * methodCreate =
1830*cdf0e10cSrcweir                     local_factory->get_LocalType()->GetMethod(S"createInstanceWithArgumentsAndContext");
1831*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Callvirt, methodCreate);
1832*cdf0e10cSrcweir         }
1833*cdf0e10cSrcweir         //cast the object returned by the functions createInstanceWithContext or
1834*cdf0e10cSrcweir         //createInstanceWithArgumentsAndContext to the interface type
1835*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Castclass, retType);
1836*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Stloc, local_return_val);
1837*cdf0e10cSrcweir 
1838*cdf0e10cSrcweir         //catch exceptions thrown by createInstanceWithArgumentsAndContext and createInstanceWithContext
1839*cdf0e10cSrcweir         if (arExceptionTypes->Contains(type_uno_exception) == false)
1840*cdf0e10cSrcweir         {
1841*cdf0e10cSrcweir             // catch (unoidl.com.sun.star.uno.RuntimeException) {throw;}
1842*cdf0e10cSrcweir             ilGen->BeginCatchBlock(get_type(S"unoidl.com.sun.star.uno.RuntimeException", true));
1843*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Pop);
1844*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Rethrow);
1845*cdf0e10cSrcweir 
1846*cdf0e10cSrcweir             //catch and rethrow all other defined Exceptions
1847*cdf0e10cSrcweir             for (int i = 0; i < arExceptionTypes->Count; i++)
1848*cdf0e10cSrcweir             {
1849*cdf0e10cSrcweir                 ::System::Type * excType = __try_cast< ::System::Type* >(
1850*cdf0e10cSrcweir                     arExceptionTypes->get_Item(i));
1851*cdf0e10cSrcweir                 if (excType->IsInstanceOfType(
1852*cdf0e10cSrcweir                         get_type(S"unoidl.com.sun.star.uno.RuntimeException", true)))
1853*cdf0e10cSrcweir                 {// we have a catch for RuntimeException already defined
1854*cdf0e10cSrcweir                     continue;
1855*cdf0e10cSrcweir                 }
1856*cdf0e10cSrcweir 
1857*cdf0e10cSrcweir                 //catch Exception and rethrow
1858*cdf0e10cSrcweir                 ilGen->BeginCatchBlock(excType);
1859*cdf0e10cSrcweir                 ilGen->Emit(Emit::OpCodes::Pop);
1860*cdf0e10cSrcweir                 ilGen->Emit(Emit::OpCodes::Rethrow);
1861*cdf0e10cSrcweir             }
1862*cdf0e10cSrcweir             //catch (unoidl.com.sun.star.uno.Exception) {throw DeploymentException...}
1863*cdf0e10cSrcweir             ilGen->BeginCatchBlock(type_uno_exception);
1864*cdf0e10cSrcweir 
1865*cdf0e10cSrcweir             //Define the local variabe that keeps the exception
1866*cdf0e10cSrcweir              Emit::LocalBuilder * local_exception = ilGen->DeclareLocal(
1867*cdf0e10cSrcweir                  type_uno_exception);
1868*cdf0e10cSrcweir 
1869*cdf0e10cSrcweir              //Store the exception
1870*cdf0e10cSrcweir              ilGen->Emit(Emit::OpCodes::Stloc, local_exception);
1871*cdf0e10cSrcweir 
1872*cdf0e10cSrcweir             //prepare the construction of the exception
1873*cdf0e10cSrcweir              strbuilder = new ::System::Text::StringBuilder(256);
1874*cdf0e10cSrcweir              strbuilder->Append(S"The context (com.sun.star.uno.XComponentContext) failed to supply the service ");
1875*cdf0e10cSrcweir              strbuilder->Append(to_cts_name(xServiceType->getName()));
1876*cdf0e10cSrcweir              strbuilder->Append(S": ");
1877*cdf0e10cSrcweir 
1878*cdf0e10cSrcweir              ilGen->Emit(Emit::OpCodes::Ldstr, strbuilder->ToString());
1879*cdf0e10cSrcweir 
1880*cdf0e10cSrcweir             //add to the string the Exception.Message
1881*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldloc, local_exception);
1882*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Callvirt,
1883*cdf0e10cSrcweir                         type_uno_exception->GetProperty(S"Message")->GetGetMethod());
1884*cdf0e10cSrcweir             ::System::Type * arConcatParams [] = {__typeof(System::String),
1885*cdf0e10cSrcweir                                                   __typeof(System::String)};
1886*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Call,
1887*cdf0e10cSrcweir                         __typeof(System::String)->GetMethod(S"Concat", arConcatParams));
1888*cdf0e10cSrcweir             //load contex argument
1889*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Ldarg_0);
1890*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Newobj, ctorDeploymentException);
1891*cdf0e10cSrcweir             ilGen->Emit(Emit::OpCodes::Throw);//Exception(typeDeploymentExc);
1892*cdf0e10cSrcweir 
1893*cdf0e10cSrcweir             ilGen->EndExceptionBlock();
1894*cdf0e10cSrcweir         }
1895*cdf0e10cSrcweir 
1896*cdf0e10cSrcweir 
1897*cdf0e10cSrcweir         //Check if the service instance was create and throw a exception if not.
1898*cdf0e10cSrcweir         Emit::Label label_service_created = ilGen->DefineLabel();
1899*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Ldloc, local_return_val);
1900*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Brtrue_S, label_service_created);
1901*cdf0e10cSrcweir 
1902*cdf0e10cSrcweir         strbuilder = new ::System::Text::StringBuilder(256);
1903*cdf0e10cSrcweir         strbuilder->Append(S"The context (com.sun.star.uno.XComponentContext) failed to supply the service ");
1904*cdf0e10cSrcweir         strbuilder->Append(to_cts_name(xServiceType->getName()));
1905*cdf0e10cSrcweir         strbuilder->Append(S".");
1906*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Ldstr, strbuilder->ToString());
1907*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Ldarg_0);
1908*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Newobj, ctorDeploymentException);
1909*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Throw);//Exception(typeDeploymentExc);
1910*cdf0e10cSrcweir 
1911*cdf0e10cSrcweir         ilGen->MarkLabel(label_service_created);
1912*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Ldloc, local_return_val);
1913*cdf0e10cSrcweir         ilGen->Emit(Emit::OpCodes::Ret);
1914*cdf0e10cSrcweir 
1915*cdf0e10cSrcweir     }
1916*cdf0e10cSrcweir     // remove from incomplete types map
1917*cdf0e10cSrcweir     ::System::String * cts_name = type_builder->get_FullName();
1918*cdf0e10cSrcweir     m_incomplete_services->Remove( cts_name );
1919*cdf0e10cSrcweir     xServiceType->release();
1920*cdf0e10cSrcweir     if (g_verbose)
1921*cdf0e10cSrcweir     {
1922*cdf0e10cSrcweir         ::System::Console::WriteLine(
1923*cdf0e10cSrcweir             "> emitting service type {0}", cts_name );
1924*cdf0e10cSrcweir     }
1925*cdf0e10cSrcweir     return type_builder->CreateType();
1926*cdf0e10cSrcweir }
1927*cdf0e10cSrcweir 
1928*cdf0e10cSrcweir 
1929*cdf0e10cSrcweir Emit::CustomAttributeBuilder* TypeEmitter::get_service_exception_attribute(
1930*cdf0e10cSrcweir     const Reference<reflection::XServiceConstructorDescription> & ctorDes  )
1931*cdf0e10cSrcweir {
1932*cdf0e10cSrcweir     return get_exception_attribute(ctorDes->getExceptions());
1933*cdf0e10cSrcweir }
1934*cdf0e10cSrcweir 
1935*cdf0e10cSrcweir Emit::CustomAttributeBuilder* TypeEmitter::get_iface_method_exception_attribute(
1936*cdf0e10cSrcweir     const Reference< reflection::XInterfaceMethodTypeDescription >& xMethod )
1937*cdf0e10cSrcweir {
1938*cdf0e10cSrcweir 
1939*cdf0e10cSrcweir     const Sequence<Reference<reflection::XTypeDescription> > seqTD = xMethod->getExceptions();
1940*cdf0e10cSrcweir     int len = seqTD.getLength();
1941*cdf0e10cSrcweir     Sequence<Reference<reflection::XCompoundTypeDescription> > seqCTD(len);
1942*cdf0e10cSrcweir     Reference<reflection::XCompoundTypeDescription> * arCTD = seqCTD.getArray();
1943*cdf0e10cSrcweir     for (int i = 0; i < len; i++)
1944*cdf0e10cSrcweir         arCTD[i] = Reference<reflection::XCompoundTypeDescription>(seqTD[i], UNO_QUERY_THROW);
1945*cdf0e10cSrcweir     return get_exception_attribute(seqCTD);
1946*cdf0e10cSrcweir }
1947*cdf0e10cSrcweir 
1948*cdf0e10cSrcweir Emit::CustomAttributeBuilder* TypeEmitter::get_exception_attribute(
1949*cdf0e10cSrcweir 
1950*cdf0e10cSrcweir     const Sequence<Reference< reflection::XCompoundTypeDescription > >& seq_exceptionsTd )
1951*cdf0e10cSrcweir {
1952*cdf0e10cSrcweir     Emit::CustomAttributeBuilder * attr_builder = NULL;
1953*cdf0e10cSrcweir 
1954*cdf0e10cSrcweir     Reference< reflection::XCompoundTypeDescription > const * exceptions =
1955*cdf0e10cSrcweir         seq_exceptionsTd.getConstArray();
1956*cdf0e10cSrcweir 
1957*cdf0e10cSrcweir     ::System::Type * arTypesCtor[] = {::System::Type::GetType(S"System.Type[]")};
1958*cdf0e10cSrcweir     ConstructorInfo * ctor_ExceptionAttribute =
1959*cdf0e10cSrcweir         __typeof(::uno::ExceptionAttribute)->GetConstructor(arTypesCtor);
1960*cdf0e10cSrcweir 
1961*cdf0e10cSrcweir     sal_Int32 exc_length = seq_exceptionsTd.getLength();
1962*cdf0e10cSrcweir     if (exc_length != 0) // opt
1963*cdf0e10cSrcweir     {
1964*cdf0e10cSrcweir         ::System::Type * exception_types [] =
1965*cdf0e10cSrcweir               new ::System::Type * [ exc_length ];
1966*cdf0e10cSrcweir         for ( sal_Int32 exc_pos = 0; exc_pos < exc_length; ++exc_pos )
1967*cdf0e10cSrcweir         {
1968*cdf0e10cSrcweir             Reference< reflection::XCompoundTypeDescription > const & xExc =
1969*cdf0e10cSrcweir                 exceptions[ exc_pos ];
1970*cdf0e10cSrcweir             exception_types[ exc_pos ] = get_type( xExc );
1971*cdf0e10cSrcweir         }
1972*cdf0e10cSrcweir         ::System::Object * args [] = {exception_types};
1973*cdf0e10cSrcweir         attr_builder = new Emit::CustomAttributeBuilder(
1974*cdf0e10cSrcweir             ctor_ExceptionAttribute, args );
1975*cdf0e10cSrcweir     }
1976*cdf0e10cSrcweir     return attr_builder;
1977*cdf0e10cSrcweir }
1978*cdf0e10cSrcweir 
1979*cdf0e10cSrcweir 
1980*cdf0e10cSrcweir ::System::Type * TypeEmitter::complete_singleton_type(singleton_entry * entry)
1981*cdf0e10cSrcweir {
1982*cdf0e10cSrcweir     Emit::TypeBuilder * type_builder = entry->m_type_builder;
1983*cdf0e10cSrcweir     reflection::XSingletonTypeDescription2 * xSingletonType = entry->m_xType;
1984*cdf0e10cSrcweir     ::System::String* sSingletonName = to_cts_name(xSingletonType->getName());
1985*cdf0e10cSrcweir 
1986*cdf0e10cSrcweir     //Create the private default constructor
1987*cdf0e10cSrcweir     Emit::ConstructorBuilder* ctor_builder =
1988*cdf0e10cSrcweir         type_builder->DefineConstructor(
1989*cdf0e10cSrcweir             static_cast<MethodAttributes>(MethodAttributes::Private |
1990*cdf0e10cSrcweir                                           MethodAttributes::HideBySig |
1991*cdf0e10cSrcweir                                           MethodAttributes::SpecialName |
1992*cdf0e10cSrcweir                                           MethodAttributes::RTSpecialName),
1993*cdf0e10cSrcweir             CallingConventions::Standard, NULL);
1994*cdf0e10cSrcweir 
1995*cdf0e10cSrcweir     Emit::ILGenerator* ilGen = ctor_builder->GetILGenerator();
1996*cdf0e10cSrcweir     ilGen->Emit( Emit::OpCodes::Ldarg_0 ); // push this
1997*cdf0e10cSrcweir     ilGen->Emit(
1998*cdf0e10cSrcweir             Emit::OpCodes::Call,
1999*cdf0e10cSrcweir             type_builder->BaseType->GetConstructor(new ::System::Type*[0]));
2000*cdf0e10cSrcweir     ilGen->Emit( Emit::OpCodes::Ret );
2001*cdf0e10cSrcweir 
2002*cdf0e10cSrcweir 
2003*cdf0e10cSrcweir     //obtain the interface which makes up this service, it is the return
2004*cdf0e10cSrcweir     //type of the constructor functions
2005*cdf0e10cSrcweir     Reference<reflection::XInterfaceTypeDescription2> xIfaceType(
2006*cdf0e10cSrcweir         xSingletonType->getInterface(), UNO_QUERY);
2007*cdf0e10cSrcweir     if (xIfaceType.is () == sal_False)
2008*cdf0e10cSrcweir         xIfaceType = resolveInterfaceTypedef(xSingletonType->getInterface());
2009*cdf0e10cSrcweir     System::Type * retType = get_type(xIfaceType);
2010*cdf0e10cSrcweir 
2011*cdf0e10cSrcweir     //define method
2012*cdf0e10cSrcweir     ::System::Type * arTypeParameters[] = {get_type(S"unoidl.com.sun.star.uno.XComponentContext", true)};
2013*cdf0e10cSrcweir     Emit::MethodBuilder* method_builder = type_builder->DefineMethod(
2014*cdf0e10cSrcweir         new System::String(S"get"),
2015*cdf0e10cSrcweir         static_cast<MethodAttributes>(MethodAttributes::Public | MethodAttributes::HideBySig |
2016*cdf0e10cSrcweir                                       MethodAttributes::Static),
2017*cdf0e10cSrcweir         retType,
2018*cdf0e10cSrcweir         arTypeParameters);
2019*cdf0e10cSrcweir 
2020*cdf0e10cSrcweir 
2021*cdf0e10cSrcweir //         method_builder->SetCustomAttribute(get_service_ctor_method_attribute(ctorDes));
2022*cdf0e10cSrcweir 
2023*cdf0e10cSrcweir     //The first parameter is the XComponentContext, which cannot be obtained
2024*cdf0e10cSrcweir     //from reflection.
2025*cdf0e10cSrcweir     //The context is not part of the idl description
2026*cdf0e10cSrcweir     method_builder->DefineParameter(1, ParameterAttributes::In, S"the_context");
2027*cdf0e10cSrcweir 
2028*cdf0e10cSrcweir 
2029*cdf0e10cSrcweir     ilGen = method_builder->GetILGenerator();
2030*cdf0e10cSrcweir     //Define locals ---------------------------------
2031*cdf0e10cSrcweir 	// Any, returned by XComponentContext.getValueByName
2032*cdf0e10cSrcweir 	Emit::LocalBuilder* local_any =
2033*cdf0e10cSrcweir 		ilGen->DeclareLocal(__typeof(::uno::Any));
2034*cdf0e10cSrcweir 
2035*cdf0e10cSrcweir     //Call XContext::getValueByName
2036*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Ldarg_0);
2037*cdf0e10cSrcweir     // build the singleton name : /singleton/unoidl.com.sun.star.XXX
2038*cdf0e10cSrcweir     ::System::Text::StringBuilder* sBuilder =
2039*cdf0e10cSrcweir           new ::System::Text::StringBuilder(S"/singletons/");
2040*cdf0e10cSrcweir     sBuilder->Append(sSingletonName);
2041*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Ldstr, sBuilder->ToString());
2042*cdf0e10cSrcweir 
2043*cdf0e10cSrcweir     ::System::Reflection::MethodInfo * methodGetValueByName =
2044*cdf0e10cSrcweir           get_type(S"unoidl.com.sun.star.uno.XComponentContext", true)->GetMethod(S"getValueByName");
2045*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Callvirt, methodGetValueByName);
2046*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Stloc_0);
2047*cdf0e10cSrcweir 
2048*cdf0e10cSrcweir     //Contains the returned Any a value?
2049*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Ldloca_S, local_any);
2050*cdf0e10cSrcweir     ::System::Reflection::MethodInfo * methodHasValue =
2051*cdf0e10cSrcweir           __typeof(::uno::Any)->GetMethod(S"hasValue");
2052*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Call, methodHasValue);
2053*cdf0e10cSrcweir 
2054*cdf0e10cSrcweir     //If not, then throw an DeploymentException
2055*cdf0e10cSrcweir     Emit::Label label_singleton_exists = ilGen->DefineLabel();
2056*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Brtrue_S, label_singleton_exists);
2057*cdf0e10cSrcweir     sBuilder = new ::System::Text::StringBuilder(
2058*cdf0e10cSrcweir         S"Component context fails to supply singleton ");
2059*cdf0e10cSrcweir     sBuilder->Append(sSingletonName);
2060*cdf0e10cSrcweir     sBuilder->Append(S" of type ");
2061*cdf0e10cSrcweir     sBuilder->Append(retType->FullName);
2062*cdf0e10cSrcweir     sBuilder->Append(S".");
2063*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Ldstr, sBuilder->ToString());
2064*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Ldarg_0);
2065*cdf0e10cSrcweir     ::System::Type * arTypesCtorDeploymentException[] = {
2066*cdf0e10cSrcweir         __typeof(::System::String), __typeof(::System::Object)};
2067*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Newobj,
2068*cdf0e10cSrcweir                 get_type(S"unoidl.com.sun.star.uno.DeploymentException",true)
2069*cdf0e10cSrcweir                 ->GetConstructor(arTypesCtorDeploymentException));
2070*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Throw);
2071*cdf0e10cSrcweir     ilGen->MarkLabel(label_singleton_exists);
2072*cdf0e10cSrcweir 
2073*cdf0e10cSrcweir     //Cast the singleton contained in the Any to the expected interface and return it.
2074*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Ldloca_S, local_any);
2075*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Call,  __typeof(::uno::Any)->GetProperty(S"Value")->GetGetMethod());
2076*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Castclass, retType);
2077*cdf0e10cSrcweir     ilGen->Emit(Emit::OpCodes::Ret);
2078*cdf0e10cSrcweir 
2079*cdf0e10cSrcweir     // remove from incomplete types map
2080*cdf0e10cSrcweir     ::System::String * cts_name = type_builder->get_FullName();
2081*cdf0e10cSrcweir     m_incomplete_singletons->Remove( cts_name );
2082*cdf0e10cSrcweir     xSingletonType->release();
2083*cdf0e10cSrcweir     if (g_verbose)
2084*cdf0e10cSrcweir     {
2085*cdf0e10cSrcweir         ::System::Console::WriteLine(
2086*cdf0e10cSrcweir             "> emitting singleton type {0}", cts_name );
2087*cdf0e10cSrcweir     }
2088*cdf0e10cSrcweir     return type_builder->CreateType();
2089*cdf0e10cSrcweir }
2090*cdf0e10cSrcweir 
2091*cdf0e10cSrcweir 
2092*cdf0e10cSrcweir //______________________________________________________________________________
2093*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_type(
2094*cdf0e10cSrcweir     Reference< reflection::XTypeDescription > const & xType )
2095*cdf0e10cSrcweir {
2096*cdf0e10cSrcweir     switch (xType->getTypeClass())
2097*cdf0e10cSrcweir     {
2098*cdf0e10cSrcweir     case TypeClass_VOID:
2099*cdf0e10cSrcweir         return __typeof (::System::Void);
2100*cdf0e10cSrcweir     case TypeClass_CHAR:
2101*cdf0e10cSrcweir         return __typeof (::System::Char);
2102*cdf0e10cSrcweir     case TypeClass_BOOLEAN:
2103*cdf0e10cSrcweir         return __typeof (::System::Boolean);
2104*cdf0e10cSrcweir     case TypeClass_BYTE:
2105*cdf0e10cSrcweir         return __typeof (::System::Byte);
2106*cdf0e10cSrcweir     case TypeClass_SHORT:
2107*cdf0e10cSrcweir         return __typeof (::System::Int16);
2108*cdf0e10cSrcweir     case TypeClass_UNSIGNED_SHORT:
2109*cdf0e10cSrcweir         return __typeof (::System::UInt16);
2110*cdf0e10cSrcweir     case TypeClass_LONG:
2111*cdf0e10cSrcweir         return __typeof (::System::Int32);
2112*cdf0e10cSrcweir     case TypeClass_UNSIGNED_LONG:
2113*cdf0e10cSrcweir         return __typeof (::System::UInt32);
2114*cdf0e10cSrcweir     case TypeClass_HYPER:
2115*cdf0e10cSrcweir         return __typeof (::System::Int64);
2116*cdf0e10cSrcweir     case TypeClass_UNSIGNED_HYPER:
2117*cdf0e10cSrcweir         return __typeof (::System::UInt64);
2118*cdf0e10cSrcweir     case TypeClass_FLOAT:
2119*cdf0e10cSrcweir         return __typeof (::System::Single);
2120*cdf0e10cSrcweir     case TypeClass_DOUBLE:
2121*cdf0e10cSrcweir         return __typeof (::System::Double);
2122*cdf0e10cSrcweir     case TypeClass_STRING:
2123*cdf0e10cSrcweir         return __typeof (::System::String);
2124*cdf0e10cSrcweir     case TypeClass_TYPE:
2125*cdf0e10cSrcweir         return __typeof (::System::Type);
2126*cdf0e10cSrcweir     case TypeClass_ANY:
2127*cdf0e10cSrcweir         return __typeof(::uno::Any);
2128*cdf0e10cSrcweir     case TypeClass_ENUM:
2129*cdf0e10cSrcweir         return get_type( Reference< reflection::XEnumTypeDescription >(
2130*cdf0e10cSrcweir                              xType, UNO_QUERY_THROW ) );
2131*cdf0e10cSrcweir     case TypeClass_TYPEDEF:
2132*cdf0e10cSrcweir         // unwind typedefs
2133*cdf0e10cSrcweir         return get_type(
2134*cdf0e10cSrcweir             Reference< reflection::XIndirectTypeDescription >(
2135*cdf0e10cSrcweir                 xType, UNO_QUERY_THROW )->getReferencedType() );
2136*cdf0e10cSrcweir     case TypeClass_STRUCT:
2137*cdf0e10cSrcweir     case TypeClass_EXCEPTION:
2138*cdf0e10cSrcweir         return get_type(
2139*cdf0e10cSrcweir             Reference< reflection::XCompoundTypeDescription >(
2140*cdf0e10cSrcweir                 xType, UNO_QUERY_THROW ) );
2141*cdf0e10cSrcweir     case TypeClass_SEQUENCE:
2142*cdf0e10cSrcweir     {
2143*cdf0e10cSrcweir         ::System::Type * element_type = get_type(
2144*cdf0e10cSrcweir             Reference< reflection::XIndirectTypeDescription >(
2145*cdf0e10cSrcweir                 xType, UNO_QUERY_THROW )->getReferencedType() );
2146*cdf0e10cSrcweir 		::System::Type * retType = get_type(
2147*cdf0e10cSrcweir             ::System::String::Concat(
2148*cdf0e10cSrcweir                 element_type->get_FullName(), S"[]" ), true );
2149*cdf0e10cSrcweir 
2150*cdf0e10cSrcweir 		::uno::PolymorphicType * pt = dynamic_cast< ::uno::PolymorphicType * >(element_type);
2151*cdf0e10cSrcweir 		if (pt)
2152*cdf0e10cSrcweir 		{
2153*cdf0e10cSrcweir 			::System::String * sName = ::System::String::Concat(pt->PolymorphicName, S"[]");
2154*cdf0e10cSrcweir 			retType = ::uno::PolymorphicType::GetType(retType, sName);
2155*cdf0e10cSrcweir 		}
2156*cdf0e10cSrcweir         return retType;
2157*cdf0e10cSrcweir     }
2158*cdf0e10cSrcweir     case TypeClass_INTERFACE:
2159*cdf0e10cSrcweir         return get_type(
2160*cdf0e10cSrcweir             Reference< reflection::XInterfaceTypeDescription2 >(
2161*cdf0e10cSrcweir                 xType, UNO_QUERY_THROW ) );
2162*cdf0e10cSrcweir     case TypeClass_CONSTANT:
2163*cdf0e10cSrcweir         return get_type(
2164*cdf0e10cSrcweir             Reference< reflection::XConstantTypeDescription >(
2165*cdf0e10cSrcweir                 xType, UNO_QUERY_THROW ) );
2166*cdf0e10cSrcweir     case TypeClass_CONSTANTS:
2167*cdf0e10cSrcweir         return get_type(
2168*cdf0e10cSrcweir             Reference< reflection::XConstantsTypeDescription >(
2169*cdf0e10cSrcweir                 xType, UNO_QUERY_THROW ) );
2170*cdf0e10cSrcweir     case TypeClass_SERVICE:
2171*cdf0e10cSrcweir 		return get_type(
2172*cdf0e10cSrcweir 			Reference< reflection::XServiceTypeDescription2 >(
2173*cdf0e10cSrcweir 				xType, UNO_QUERY_THROW) );
2174*cdf0e10cSrcweir     case TypeClass_SINGLETON:
2175*cdf0e10cSrcweir 		return get_type(
2176*cdf0e10cSrcweir 			Reference< reflection::XSingletonTypeDescription2 >(
2177*cdf0e10cSrcweir 				xType, UNO_QUERY_THROW) );
2178*cdf0e10cSrcweir     case TypeClass_MODULE:
2179*cdf0e10cSrcweir         // ignore these
2180*cdf0e10cSrcweir         return 0;
2181*cdf0e10cSrcweir     default:
2182*cdf0e10cSrcweir         throw RuntimeException(
2183*cdf0e10cSrcweir             OUSTR("unexpected type ") + xType->getName(),
2184*cdf0e10cSrcweir             Reference< XInterface >() );
2185*cdf0e10cSrcweir     }
2186*cdf0e10cSrcweir }
2187*cdf0e10cSrcweir 
2188*cdf0e10cSrcweir //______________________________________________________________________________
2189*cdf0e10cSrcweir ::System::Type * TypeEmitter::get_complete_struct( ::System::String * sName)
2190*cdf0e10cSrcweir {
2191*cdf0e10cSrcweir     struct_entry * pStruct = __try_cast< struct_entry *>(
2192*cdf0e10cSrcweir         m_incomplete_structs->get_Item(sName));
2193*cdf0e10cSrcweir     if (pStruct)
2194*cdf0e10cSrcweir     {
2195*cdf0e10cSrcweir         complete_struct_type(pStruct);
2196*cdf0e10cSrcweir     }
2197*cdf0e10cSrcweir     //get_type will asked the module builder for the type or otherwise all known assemblies.
2198*cdf0e10cSrcweir     return get_type(sName, true);
2199*cdf0e10cSrcweir }
2200*cdf0e10cSrcweir void TypeEmitter::Dispose()
2201*cdf0e10cSrcweir {
2202*cdf0e10cSrcweir     while (true)
2203*cdf0e10cSrcweir     {
2204*cdf0e10cSrcweir         ::System::Collections::IDictionaryEnumerator * enumerator =
2205*cdf0e10cSrcweir               m_incomplete_ifaces->GetEnumerator();
2206*cdf0e10cSrcweir         if (! enumerator->MoveNext())
2207*cdf0e10cSrcweir             break;
2208*cdf0e10cSrcweir         complete_iface_type(
2209*cdf0e10cSrcweir             __try_cast< iface_entry * >( enumerator->get_Value() ) );
2210*cdf0e10cSrcweir     }
2211*cdf0e10cSrcweir 
2212*cdf0e10cSrcweir     while (true)
2213*cdf0e10cSrcweir     {
2214*cdf0e10cSrcweir         ::System::Collections::IDictionaryEnumerator * enumerator =
2215*cdf0e10cSrcweir               m_incomplete_structs->GetEnumerator();
2216*cdf0e10cSrcweir         if (! enumerator->MoveNext())
2217*cdf0e10cSrcweir             break;
2218*cdf0e10cSrcweir         complete_struct_type(
2219*cdf0e10cSrcweir             __try_cast< struct_entry * >( enumerator->get_Value() ) );
2220*cdf0e10cSrcweir     }
2221*cdf0e10cSrcweir 
2222*cdf0e10cSrcweir 
2223*cdf0e10cSrcweir     while (true)
2224*cdf0e10cSrcweir     {
2225*cdf0e10cSrcweir         ::System::Collections::IDictionaryEnumerator * enumerator =
2226*cdf0e10cSrcweir               m_incomplete_services->GetEnumerator();
2227*cdf0e10cSrcweir         if (! enumerator->MoveNext())
2228*cdf0e10cSrcweir             break;
2229*cdf0e10cSrcweir         complete_service_type(
2230*cdf0e10cSrcweir             __try_cast< service_entry * >( enumerator->get_Value() ) );
2231*cdf0e10cSrcweir     }
2232*cdf0e10cSrcweir 
2233*cdf0e10cSrcweir     while (true)
2234*cdf0e10cSrcweir     {
2235*cdf0e10cSrcweir         ::System::Collections::IDictionaryEnumerator * enumerator =
2236*cdf0e10cSrcweir               m_incomplete_singletons->GetEnumerator();
2237*cdf0e10cSrcweir         if (! enumerator->MoveNext())
2238*cdf0e10cSrcweir             break;
2239*cdf0e10cSrcweir         complete_singleton_type(
2240*cdf0e10cSrcweir             __try_cast< singleton_entry * >( enumerator->get_Value() ) );
2241*cdf0e10cSrcweir     }
2242*cdf0e10cSrcweir }
2243*cdf0e10cSrcweir //______________________________________________________________________________
2244*cdf0e10cSrcweir TypeEmitter::TypeEmitter(
2245*cdf0e10cSrcweir     ::System::Reflection::Emit::ModuleBuilder * module_builder,
2246*cdf0e10cSrcweir     ::System::Reflection::Assembly * extra_assemblies [] )
2247*cdf0e10cSrcweir     : m_module_builder( module_builder ),
2248*cdf0e10cSrcweir       m_extra_assemblies( extra_assemblies ),
2249*cdf0e10cSrcweir       m_method_info_Type_GetTypeFromHandle( 0 ),
2250*cdf0e10cSrcweir       m_type_Exception( 0 ),
2251*cdf0e10cSrcweir       m_type_RuntimeException( 0 ),
2252*cdf0e10cSrcweir       m_incomplete_ifaces( new ::System::Collections::Hashtable() ),
2253*cdf0e10cSrcweir       m_incomplete_structs( new ::System::Collections::Hashtable() ),
2254*cdf0e10cSrcweir       m_incomplete_services(new ::System::Collections::Hashtable() ),
2255*cdf0e10cSrcweir       m_incomplete_singletons(new ::System::Collections::Hashtable() ),
2256*cdf0e10cSrcweir       m_generated_structs( new ::System::Collections::Hashtable() )
2257*cdf0e10cSrcweir {
2258*cdf0e10cSrcweir     ::System::Type * param_types[] = new ::System::Type * [ 1 ];
2259*cdf0e10cSrcweir     param_types[ 0 ] = __typeof (::System::RuntimeTypeHandle);
2260*cdf0e10cSrcweir     m_method_info_Type_GetTypeFromHandle =
2261*cdf0e10cSrcweir         __typeof (::System::Type)
2262*cdf0e10cSrcweir           ->GetMethod( "GetTypeFromHandle", param_types );
2263*cdf0e10cSrcweir }
2264*cdf0e10cSrcweir 
2265*cdf0e10cSrcweir ::System::Collections::ArrayList * TypeEmitter::get_service_ctor_method_exceptions_reduced(
2266*cdf0e10cSrcweir     const Sequence<Reference<reflection::XCompoundTypeDescription> > & seqExceptionsTd)
2267*cdf0e10cSrcweir {
2268*cdf0e10cSrcweir     if (seqExceptionsTd.getLength() == 0)
2269*cdf0e10cSrcweir         return new ::System::Collections::ArrayList();
2270*cdf0e10cSrcweir 
2271*cdf0e10cSrcweir     ::System::Collections::ArrayList * arTypes = new ::System::Collections::ArrayList();
2272*cdf0e10cSrcweir     for (int i = 0; i < seqExceptionsTd.getLength(); i++)
2273*cdf0e10cSrcweir         arTypes->Add(get_type(to_cts_name(seqExceptionsTd[i]->getName()), true));
2274*cdf0e10cSrcweir 
2275*cdf0e10cSrcweir     int start = 0;
2276*cdf0e10cSrcweir     while (true)
2277*cdf0e10cSrcweir     {
2278*cdf0e10cSrcweir         bool bRemove = false;
2279*cdf0e10cSrcweir         for (int i = start; i < arTypes->Count; i++)
2280*cdf0e10cSrcweir         {
2281*cdf0e10cSrcweir             ::System::Type * t = __try_cast< ::System::Type* >(arTypes->get_Item(i));
2282*cdf0e10cSrcweir             for (int j = 0; j < arTypes->Count; j++)
2283*cdf0e10cSrcweir             {
2284*cdf0e10cSrcweir                 if (t->IsSubclassOf(__try_cast< ::System::Type* >(arTypes->get_Item(j))))
2285*cdf0e10cSrcweir                 {
2286*cdf0e10cSrcweir                     arTypes->RemoveAt(i);
2287*cdf0e10cSrcweir                     bRemove = true;
2288*cdf0e10cSrcweir                     break;
2289*cdf0e10cSrcweir                 }
2290*cdf0e10cSrcweir             }
2291*cdf0e10cSrcweir             if (bRemove)
2292*cdf0e10cSrcweir                 break;
2293*cdf0e10cSrcweir             start++;
2294*cdf0e10cSrcweir         }
2295*cdf0e10cSrcweir 
2296*cdf0e10cSrcweir         if (bRemove == false)
2297*cdf0e10cSrcweir             break;
2298*cdf0e10cSrcweir     }
2299*cdf0e10cSrcweir     return arTypes;
2300*cdf0e10cSrcweir }
2301*cdf0e10cSrcweir 
2302*cdf0e10cSrcweir 
2303*cdf0e10cSrcweir css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
2304*cdf0e10cSrcweir resolveInterfaceTypedef(
2305*cdf0e10cSrcweir     const css::uno::Reference<css::reflection::XTypeDescription>& type)
2306*cdf0e10cSrcweir {
2307*cdf0e10cSrcweir     Reference<reflection::XInterfaceTypeDescription2>
2308*cdf0e10cSrcweir         xIfaceTd(type, UNO_QUERY);
2309*cdf0e10cSrcweir 
2310*cdf0e10cSrcweir     if (xIfaceTd.is())
2311*cdf0e10cSrcweir         return xIfaceTd;
2312*cdf0e10cSrcweir 
2313*cdf0e10cSrcweir     Reference<reflection::XIndirectTypeDescription> xIndTd(
2314*cdf0e10cSrcweir         type, UNO_QUERY);
2315*cdf0e10cSrcweir     if (xIndTd.is() == sal_False)
2316*cdf0e10cSrcweir         throw css::uno::Exception(
2317*cdf0e10cSrcweir             OUSTR("resolveInterfaceTypedef was called with an invalid argument"), 0);
2318*cdf0e10cSrcweir 
2319*cdf0e10cSrcweir     return resolveInterfaceTypedef(xIndTd->getReferencedType());
2320*cdf0e10cSrcweir }
2321*cdf0e10cSrcweir 
2322*cdf0e10cSrcweir 
2323*cdf0e10cSrcweir }
2324