Line 0
Link Here
|
|
|
1 |
using System; |
2 |
using System.Collections; |
3 |
using System.Reflection; |
4 |
using System.Reflection.Emit; |
5 |
using System.Runtime.InteropServices; |
6 |
|
7 |
enum UnoTypeClass { |
8 |
Unknown, |
9 |
Void, |
10 |
Char, |
11 |
Boolean, |
12 |
Byte, |
13 |
Short, |
14 |
UnsignedShort, |
15 |
Long, |
16 |
UnsignedLong, |
17 |
Hyper, |
18 |
UnsignedHyper, |
19 |
Float, |
20 |
Double, |
21 |
String, |
22 |
Type, |
23 |
Any, |
24 |
Enum, |
25 |
Typedef, |
26 |
Struct, |
27 |
Exception, |
28 |
Sequence, |
29 |
Interface, |
30 |
InterfaceAttribute, |
31 |
InterfaceMethod, |
32 |
Constant, |
33 |
Constants, |
34 |
Service, |
35 |
Singleton, |
36 |
Module |
37 |
} |
38 |
|
39 |
struct Constants |
40 |
{ |
41 |
public static readonly string UnoVoid = "void"; |
42 |
public static readonly string UnoType = "type"; |
43 |
public static readonly string UnoAny = "any"; |
44 |
public static readonly string UnoBool = "boolean"; |
45 |
public static readonly string UnoByte = "byte"; |
46 |
public static readonly string UnoChar = "char"; |
47 |
public static readonly string UnoShort = "short"; |
48 |
public static readonly string UnoUShort = "unsigned short"; |
49 |
public static readonly string UnoLong = "long"; |
50 |
public static readonly string UnoULong = "unsigned long"; |
51 |
public static readonly string UnoHyper = "hyper"; |
52 |
public static readonly string UnoUHyper = "unsigned hyper"; |
53 |
public static readonly string UnoString = "string"; |
54 |
public static readonly string UnoFloat = "float"; |
55 |
public static readonly string UnoDouble = "double"; |
56 |
public static readonly string UnoXInterface = "com.sun.star.uno.XInterface"; |
57 |
public static readonly string Brackets = "[]"; |
58 |
|
59 |
public static readonly string Object = "System.Object"; |
60 |
public static readonly string Type = "System.Type"; |
61 |
public static readonly string Unoidl = "unoidl."; |
62 |
public static readonly string Void = "System.Void"; |
63 |
public static readonly string Any = "uno.Any"; |
64 |
public static readonly string Boolean = "System.Boolean"; |
65 |
public static readonly string Char = "System.Char"; |
66 |
public static readonly string Byte = "System.Byte"; |
67 |
public static readonly string Int16 = "System.Int16"; |
68 |
public static readonly string UInt16 = "System.UInt16"; |
69 |
public static readonly string Int32 = "System.Int32"; |
70 |
public static readonly string UInt32 = "System.UInt32"; |
71 |
public static readonly string Int64 = "System.Int64"; |
72 |
public static readonly string UInt64 = "System.UInt64"; |
73 |
public static readonly string String = "System.String"; |
74 |
public static readonly string Single = "System.Single"; |
75 |
public static readonly string Double = "System.Double"; |
76 |
public static readonly string Comma = ","; |
77 |
} |
78 |
|
79 |
class TypeEmitter : IDisposable |
80 |
{ |
81 |
ResolveEventHandler mTypeResolver; |
82 |
ModuleBuilder mModuleBuilder; |
83 |
ArrayList mExtraAssemblies; |
84 |
Hashtable mIncompleteIFaces; |
85 |
Hashtable mIncompleteServices; |
86 |
Hashtable mIncompleteSingletons; |
87 |
Hashtable mGeneratedStructs; |
88 |
Config mConfig; |
89 |
|
90 |
Type mTypeException = null; |
91 |
Type mTypeRuntimeException = null; |
92 |
|
93 |
readonly static MethodAttributes cCtorMethodAttr = |
94 |
MethodAttributes.Public | |
95 |
MethodAttributes.HideBySig | |
96 |
MethodAttributes.SpecialName | |
97 |
MethodAttributes.RTSpecialName; |
98 |
/* | xxx todo: ??? compiler does not know Instance ??? |
99 |
::System::Reflection::MethodAttributes::Instance*/ |
100 |
|
101 |
MethodInfo mMethodInfoTypeGetTypeFromHandle; |
102 |
|
103 |
class IFaceEntry |
104 |
{ |
105 |
public UnoXInterfaceTypeDescription mType; |
106 |
public TypeBuilder mTypeBuilder; |
107 |
} |
108 |
|
109 |
class ServiceEntry |
110 |
{ |
111 |
public UnoXServiceTypeDescription mType; |
112 |
public TypeBuilder mTypeBuilder; |
113 |
} |
114 |
|
115 |
class SingletonEntry |
116 |
{ |
117 |
public UnoXSingletonTypeDescription mType; |
118 |
public TypeBuilder mTypeBuilder; |
119 |
} |
120 |
|
121 |
class StructEntry |
122 |
{ |
123 |
public string[] mMemberNames; |
124 |
public Type[] mParamTypes; |
125 |
public ConstructorInfo mDefaultConstructor; |
126 |
public ConstructorInfo mConstructor; |
127 |
} |
128 |
|
129 |
public TypeEmitter (Config config, ModuleBuilder builder) |
130 |
{ |
131 |
mConfig = config; |
132 |
|
133 |
// load extra assemblies |
134 |
mExtraAssemblies = new ArrayList (); |
135 |
foreach (string assemblyPath in mConfig.mExtraAssemblies) |
136 |
mExtraAssemblies.Add (Assembly.LoadFrom (assemblyPath)); |
137 |
|
138 |
mTypeResolver = new ResolveEventHandler (TypeResolveHandler); |
139 |
mModuleBuilder = builder; |
140 |
|
141 |
mIncompleteIFaces = new Hashtable (); |
142 |
mIncompleteServices = new Hashtable (); |
143 |
mIncompleteSingletons = new Hashtable (); |
144 |
mGeneratedStructs = new Hashtable (); |
145 |
|
146 |
Type[] paramTypes = { typeof (RuntimeTypeHandle) }; |
147 |
mMethodInfoTypeGetTypeFromHandle = typeof (Type).GetMethod ("GetTypeFromHandle", paramTypes); |
148 |
} |
149 |
|
150 |
public ResolveEventHandler ResolveEventHandler |
151 |
{ |
152 |
get |
153 |
{ |
154 |
return mTypeResolver; |
155 |
} |
156 |
} |
157 |
|
158 |
Assembly TypeResolveHandler (object o, ResolveEventArgs args) |
159 |
{ |
160 |
Type ret = mModuleBuilder.GetType (args.Name, false); |
161 |
//Console.WriteLine ("mModuleBuilder.GetType yields {0}", ret); |
162 |
|
163 |
#if __MonoCS__ |
164 |
if (ret is TypeBuilder) { |
165 |
TypeBuilder tb = ret as TypeBuilder; |
166 |
//Console.WriteLine ("{0} is type builder", tb); |
167 |
if (tb.IsCreated ()) { |
168 |
ret = tb.CreateType (); |
169 |
//Console.WriteLine ("resolving to created {0} {1}", ret, tb); |
170 |
} |
171 |
} |
172 |
#endif |
173 |
if (ret == null) { |
174 |
IFaceEntry entry = mIncompleteIFaces [args.Name] as IFaceEntry; |
175 |
if (entry != null) |
176 |
ret = entry.mTypeBuilder; |
177 |
} |
178 |
|
179 |
if (ret == null && mExtraAssemblies != null) { |
180 |
//Console.WriteLine ("assemblies {0}", mExtraAssemblies); |
181 |
foreach (Assembly assembly in mExtraAssemblies) { |
182 |
ret = assembly.GetType (args.Name, false); |
183 |
if (ret != null) { |
184 |
if (mConfig.mVerbose) { |
185 |
Console.WriteLine ("> resolving type {0} from {1}.", |
186 |
args.Name, ret.Assembly.FullName); |
187 |
} |
188 |
break; |
189 |
} |
190 |
} |
191 |
//Console.WriteLine ("done {0}", ret); |
192 |
} |
193 |
|
194 |
if (ret != null) |
195 |
return ret.Assembly; |
196 |
|
197 |
return null; |
198 |
} |
199 |
|
200 |
Type GetType (string name, bool throwExc) |
201 |
{ |
202 |
Type ret = mModuleBuilder.GetType (name, false); |
203 |
//Console.WriteLine ("mModuleBuilder.GetType yields {0}", ret); |
204 |
|
205 |
#if __MonoCS__ |
206 |
if (ret is TypeBuilder) { |
207 |
TypeBuilder tb = ret as TypeBuilder; |
208 |
//Console.WriteLine ("{0} is type builder", tb); |
209 |
if (tb.IsCreated ()) { |
210 |
ret = tb.CreateType (); |
211 |
//Console.WriteLine ("resolving to created {0} {1}", ret, tb); |
212 |
} |
213 |
} |
214 |
#endif |
215 |
if (ret == null) { |
216 |
//Console.WriteLine ("looking name {0}", name); |
217 |
IFaceEntry entry = mIncompleteIFaces [name] as IFaceEntry; |
218 |
if (entry != null) |
219 |
ret = entry.mTypeBuilder; |
220 |
} |
221 |
|
222 |
//try the cli_basetypes assembly |
223 |
if (ret == null) { |
224 |
ret = Type.GetType (name + ",cli_basetypes"); |
225 |
} |
226 |
|
227 |
if (ret == null) { |
228 |
try { |
229 |
// may call on type_resolve() |
230 |
return Type.GetType (name, throwExc); |
231 |
} catch (Exception e) { |
232 |
//If the type is not found one may have forgotten to specify assemblies with |
233 |
//additional types |
234 |
if (throwExc) |
235 |
throw new Exception ("\nThe type " + name + " \n could not be found. Did you forget to " + |
236 |
"specify an additional assembly with the --reference option?\n", e); |
237 |
} |
238 |
} |
239 |
|
240 |
return ret; |
241 |
} |
242 |
|
243 |
public Type GetType (UnoXEnumTypeDescription xtd) |
244 |
{ |
245 |
//Console.WriteLine ("emit enum {0} {1}", xtd.Name, xtd.Length); |
246 |
string name = "unoidl." + xtd.Name; |
247 |
|
248 |
Type ret = GetType (name, false /* no exc */); |
249 |
if (ret == null) { |
250 |
// Emit::EnumBuilder * enum_builder = |
251 |
// m_module_builder->DefineEnum( |
252 |
// cts_name, |
253 |
// (TypeAttributes) (TypeAttributes::Public | |
254 |
// // TypeAttributes::Sealed | |
255 |
// TypeAttributes::AnsiClass), |
256 |
// __typeof (::System::Int32) ); |
257 |
// workaround enum builder bug |
258 |
TypeBuilder enumBuilder = |
259 |
mModuleBuilder.DefineType (name, |
260 |
TypeAttributes.Public | |
261 |
TypeAttributes.Sealed, |
262 |
typeof (System.Enum)); |
263 |
enumBuilder.DefineField ("value__", typeof (System.Int32), |
264 |
FieldAttributes.Private | |
265 |
FieldAttributes.SpecialName | |
266 |
FieldAttributes.RTSpecialName); |
267 |
|
268 |
int length = xtd.Length; |
269 |
for (int pos = 0; pos < length; pos ++) { |
270 |
// enum_builder->DefineLiteral( |
271 |
// ustring_to_String( enum_names[ enum_pos ] ), |
272 |
// __box ((::System::Int32) enum_values[ enum_pos ]) ); |
273 |
FieldBuilder fieldBuilder = |
274 |
enumBuilder.DefineField (xtd.ValueName (pos), |
275 |
enumBuilder, |
276 |
FieldAttributes.Public | |
277 |
FieldAttributes.Static | |
278 |
FieldAttributes.Literal); |
279 |
fieldBuilder.SetConstant (xtd.Value (pos)); |
280 |
} |
281 |
|
282 |
if (mConfig.mVerbose) |
283 |
Console.WriteLine ("> emitting enum type {0}", name ); |
284 |
|
285 |
ret = enumBuilder.CreateType (); |
286 |
} |
287 |
|
288 |
return ret; |
289 |
} |
290 |
|
291 |
public Type GetType (UnoXInterfaceTypeDescription xtd) |
292 |
{ |
293 |
//Console.WriteLine ("get iface {0}", xtd.Name); |
294 |
|
295 |
if (String.Compare (xtd.Name, "com.sun.star.uno.XInterface") == 0) { |
296 |
return typeof (object); |
297 |
} |
298 |
|
299 |
string name = "unoidl." + xtd.Name; |
300 |
|
301 |
Type ret = GetType (name, false /* no exc */); |
302 |
|
303 |
if (ret == null) { |
304 |
//Console.WriteLine ("creating name {0}", name); |
305 |
TypeBuilder typeBuilder; |
306 |
|
307 |
TypeAttributes attr = TypeAttributes.Public | |
308 |
TypeAttributes.Interface | |
309 |
TypeAttributes.Abstract | |
310 |
TypeAttributes.AnsiClass; |
311 |
|
312 |
int length = xtd.BaseTypes; |
313 |
if (length > 0) { |
314 |
ArrayList ifaces = new ArrayList (); |
315 |
int i; |
316 |
|
317 |
for (i = 0; i < length; i ++) { |
318 |
UnoXInterfaceTypeDescription baseType = xtd.BaseType (i); |
319 |
if (String.Compare (baseType.Name, "com.sun.star.uno.XInterface") != 0) |
320 |
ifaces.Add (baseType); |
321 |
} |
322 |
Type[] baseInterfaces = new Type [ifaces.Count]; |
323 |
|
324 |
i = 0; |
325 |
foreach (UnoXInterfaceTypeDescription iface in ifaces) { |
326 |
baseInterfaces[i] = GetType (iface); |
327 |
i++; |
328 |
} |
329 |
|
330 |
typeBuilder = mModuleBuilder.DefineType (name, attr, null, baseInterfaces); |
331 |
} else { |
332 |
System.Console.WriteLine ("warning: IDL interface {0} is not derived from " + |
333 |
"com.sun.star.uno.XInterface!", name); |
334 |
|
335 |
typeBuilder = mModuleBuilder.DefineType (name, attr); |
336 |
} |
337 |
|
338 |
// insert to be completed |
339 |
IFaceEntry entry = new IFaceEntry (); |
340 |
entry.mType = xtd; |
341 |
entry.mTypeBuilder = typeBuilder; |
342 |
mIncompleteIFaces [name] = entry; |
343 |
|
344 |
// type is incomplete |
345 |
ret = typeBuilder; |
346 |
} |
347 |
|
348 |
return ret; |
349 |
} |
350 |
|
351 |
string PolymorphicStructNameToStructName (string name) |
352 |
{ |
353 |
if (!name.EndsWith (">")) |
354 |
return name; |
355 |
|
356 |
int index = name.IndexOf ('<'); |
357 |
|
358 |
if (index == -1) |
359 |
return name; |
360 |
|
361 |
return name.Substring (0, index); |
362 |
} |
363 |
|
364 |
Type TypeException () |
365 |
{ |
366 |
if (mTypeException == null) { |
367 |
mTypeException = GetType ("unoidl.com.sun.star.uno.Exception", false); |
368 |
|
369 |
if (mTypeException == null) { |
370 |
// define hardcoded type unoidl.com.sun.star.uno.Exception |
371 |
TypeBuilder typeBuilder = mModuleBuilder.DefineType ("unoidl.com.sun.star.uno.Exception", |
372 |
TypeAttributes.Public | |
373 |
TypeAttributes.BeforeFieldInit | |
374 |
TypeAttributes.AnsiClass, |
375 |
typeof (System.Exception)); |
376 |
FieldBuilder fieldContext = typeBuilder.DefineField ("Context", typeof (object), |
377 |
FieldAttributes.Public); |
378 |
// default .ctor |
379 |
typeBuilder.DefineDefaultConstructor (cCtorMethodAttr); |
380 |
// .ctor |
381 |
Type[] paramTypes = new Type [2]; |
382 |
paramTypes [0] = typeof (string); |
383 |
paramTypes [1] = typeof (object); |
384 |
ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr, |
385 |
CallingConventions.Standard, |
386 |
paramTypes); |
387 |
ctorBuilder.DefineParameter (1, ParameterAttributes.In, "Message"); |
388 |
ctorBuilder.DefineParameter (2, ParameterAttributes.In, "Context"); |
389 |
ILGenerator code = ctorBuilder.GetILGenerator (); |
390 |
code.Emit (OpCodes.Ldarg_0); |
391 |
code.Emit (OpCodes.Ldarg_1); |
392 |
paramTypes = new Type [1]; |
393 |
paramTypes [0] = typeof (string); |
394 |
code.Emit (OpCodes.Call, typeof (System.Exception).GetConstructor (paramTypes)); |
395 |
code.Emit( OpCodes.Ldarg_0 ); |
396 |
code.Emit( OpCodes.Ldarg_2 ); |
397 |
code.Emit( OpCodes.Stfld, fieldContext ); |
398 |
code.Emit( OpCodes.Ret ); |
399 |
|
400 |
if (mConfig.mVerbose) |
401 |
Console.WriteLine ("> emitting exception type unoidl.com.sun.star.uno.Exception"); |
402 |
|
403 |
mTypeException = typeBuilder.CreateType (); |
404 |
} |
405 |
} |
406 |
|
407 |
return mTypeException; |
408 |
} |
409 |
|
410 |
Type TypeRuntimeException () |
411 |
{ |
412 |
if (mTypeRuntimeException == null) { |
413 |
mTypeRuntimeException = GetType ("unoidl.com.sun.star.uno.RuntimeException", false); |
414 |
if (mTypeRuntimeException == null) { |
415 |
// define hardcoded type unoidl.com.sun.star.uno.RuntimeException |
416 |
Type typeException = TypeException (); |
417 |
TypeBuilder typeBuilder = mModuleBuilder.DefineType ("unoidl.com.sun.star.uno.RuntimeException", |
418 |
TypeAttributes.Public | |
419 |
TypeAttributes.BeforeFieldInit | |
420 |
TypeAttributes.AnsiClass, |
421 |
typeException); |
422 |
// default .ctor |
423 |
typeBuilder.DefineDefaultConstructor (cCtorMethodAttr); |
424 |
// .ctor |
425 |
Type[] paramTypes = new Type [2]; |
426 |
paramTypes [0] = typeof (string); |
427 |
paramTypes [1] = typeof (object); |
428 |
ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr, |
429 |
CallingConventions.Standard, |
430 |
paramTypes); |
431 |
ctorBuilder.DefineParameter (1, ParameterAttributes.In, "Message"); |
432 |
ctorBuilder.DefineParameter (2, ParameterAttributes.In, "Context"); |
433 |
ILGenerator code = ctorBuilder.GetILGenerator (); |
434 |
code.Emit (OpCodes.Ldarg_0); |
435 |
code.Emit (OpCodes.Ldarg_1); |
436 |
code.Emit (OpCodes.Ldarg_2 ); |
437 |
code.Emit (OpCodes.Call, |
438 |
typeException.GetConstructor (paramTypes)); |
439 |
code.Emit (OpCodes.Ret); |
440 |
|
441 |
if (mConfig.mVerbose) |
442 |
Console.WriteLine ("> emitting exception type unoidl.com.sun.star.uno.RuntimeException"); |
443 |
|
444 |
mTypeRuntimeException = typeBuilder.CreateType (); |
445 |
} |
446 |
} |
447 |
|
448 |
return mTypeRuntimeException; |
449 |
} |
450 |
|
451 |
public Type GetType (UnoXServiceTypeDescription xtd) |
452 |
{ |
453 |
// Console.WriteLine ("get service {0}", xtd.Name); |
454 |
|
455 |
if (!xtd.IsSingleInterfaceBased) |
456 |
return null; |
457 |
|
458 |
string name = "unoidl." + xtd.Name; |
459 |
|
460 |
Type ret = GetType (name, false /* no exc */); |
461 |
|
462 |
if (ret != null) |
463 |
return ret; |
464 |
|
465 |
TypeAttributes attr = |
466 |
TypeAttributes.Public | |
467 |
TypeAttributes.Sealed | |
468 |
TypeAttributes.BeforeFieldInit | |
469 |
TypeAttributes.AnsiClass; |
470 |
|
471 |
// insert to be completed |
472 |
ServiceEntry entry = new ServiceEntry (); |
473 |
entry.mType = xtd; |
474 |
entry.mTypeBuilder = mModuleBuilder.DefineType (name, attr); |
475 |
mIncompleteServices.Add (name, entry); |
476 |
|
477 |
return entry.mTypeBuilder; |
478 |
} |
479 |
|
480 |
static void EmitLdarg (ILGenerator code, int index) |
481 |
{ |
482 |
switch (index) { |
483 |
case 0: |
484 |
code.Emit( OpCodes.Ldarg_0 ); |
485 |
break; |
486 |
case 1: |
487 |
code.Emit( OpCodes.Ldarg_1 ); |
488 |
break; |
489 |
case 2: |
490 |
code.Emit( OpCodes.Ldarg_2 ); |
491 |
break; |
492 |
case 3: |
493 |
code.Emit( OpCodes.Ldarg_3 ); |
494 |
break; |
495 |
default: |
496 |
if (index < 0x100) |
497 |
code.Emit (OpCodes.Ldarg_S, (byte) index); |
498 |
else if (index < 0x8000) |
499 |
code.Emit (OpCodes.Ldarg_S, (System.Int16) index); |
500 |
else |
501 |
code.Emit (OpCodes.Ldarg, index); |
502 |
break; |
503 |
} |
504 |
} |
505 |
|
506 |
/** For example, there is a uno type |
507 |
com.sun.star.Foo<char, long>. |
508 |
The values in the type list |
509 |
are uno types and are replaced by cli types, such as System.Char, |
510 |
System.Int32, etc. |
511 |
|
512 |
Strings can be as complicated as this |
513 |
test.MyStruct<char,test.MyStruct<long, []string>> |
514 |
*/ |
515 |
string MapUnoPolymorphicName (string unoName) |
516 |
{ |
517 |
int index = unoName.IndexOf('<'); |
518 |
if (index == -1) |
519 |
return unoName; |
520 |
|
521 |
System.Text.StringBuilder builder = new System.Text.StringBuilder (unoName.Substring (0, index + 1)); |
522 |
|
523 |
//Find the first occurrence of ',' |
524 |
//If the parameter is a polymorphic struct then we neede to ignore everything |
525 |
//between the brackets because it can also contain commas |
526 |
//get the type list within < and > |
527 |
int endIndex = unoName.Length - 1; |
528 |
index ++; |
529 |
int cur = index; |
530 |
int countParams = 0; |
531 |
while (cur <= endIndex) { |
532 |
char c = unoName [cur]; |
533 |
|
534 |
if (c == ',' || c == '>') { |
535 |
//insert a comma if needed |
536 |
if (countParams != 0) |
537 |
builder.Append (","); |
538 |
countParams++; |
539 |
string param = unoName.Substring (index, cur - index); |
540 |
//skip the comma |
541 |
cur ++; |
542 |
//the the index to the beginning of the next param |
543 |
index = cur; |
544 |
builder.Append (MapUnoTypeName (param)); |
545 |
} else if (c == '<') { |
546 |
cur++; |
547 |
//continue until the matching '>' |
548 |
int numNested = 0; |
549 |
for (;; cur ++) { |
550 |
char curChar = unoName [cur]; |
551 |
if (curChar == '<') |
552 |
numNested ++; |
553 |
else if (curChar == '>') { |
554 |
if (numNested > 0) |
555 |
numNested --; |
556 |
else |
557 |
break; |
558 |
} |
559 |
} |
560 |
} |
561 |
cur ++; |
562 |
} |
563 |
|
564 |
builder.Append ('>'); |
565 |
return builder.ToString(); |
566 |
} |
567 |
|
568 |
string MapUnoTypeName (string typeName) |
569 |
{ |
570 |
System.Text.StringBuilder buf= new System.Text.StringBuilder (); |
571 |
string unoName = String.Copy (typeName); |
572 |
|
573 |
//determine if the type is a sequence and its dimensions |
574 |
int dims = 0; |
575 |
if (typeName.StartsWith ("[")) { |
576 |
int index= 1; |
577 |
while (true) { |
578 |
if (typeName [index ++] == ']') |
579 |
dims++; |
580 |
if (typeName [index ++] != '[') |
581 |
break; |
582 |
} |
583 |
unoName = unoName.Substring (index - 1); |
584 |
} |
585 |
|
586 |
if (unoName.Equals (Constants.UnoBool)) |
587 |
buf.Append (Constants.Boolean); |
588 |
else if (unoName.Equals(Constants.UnoChar)) |
589 |
buf.Append (Constants.Char); |
590 |
else if (unoName.Equals(Constants.UnoByte)) |
591 |
buf.Append (Constants.Byte); |
592 |
else if (unoName.Equals(Constants.UnoShort)) |
593 |
buf.Append (Constants.Int16); |
594 |
else if (unoName.Equals(Constants.UnoUShort)) |
595 |
buf.Append (Constants.UInt16); |
596 |
else if (unoName.Equals(Constants.UnoLong)) |
597 |
buf.Append (Constants.Int32); |
598 |
else if (unoName.Equals(Constants.UnoULong)) |
599 |
buf.Append (Constants.UInt32); |
600 |
else if (unoName.Equals(Constants.UnoHyper)) |
601 |
buf.Append (Constants.Int64); |
602 |
else if (unoName.Equals(Constants.UnoUHyper)) |
603 |
buf.Append (Constants.UInt64); |
604 |
else if (unoName.Equals(Constants.UnoFloat)) |
605 |
buf.Append (Constants.Single); |
606 |
else if (unoName.Equals(Constants.UnoDouble)) |
607 |
buf.Append (Constants.Double); |
608 |
else if (unoName.Equals(Constants.UnoString)) |
609 |
buf.Append (Constants.String); |
610 |
else if (unoName.Equals(Constants.UnoVoid)) |
611 |
buf.Append (Constants.Void); |
612 |
else if (unoName.Equals(Constants.UnoType)) |
613 |
buf.Append (Constants.Type); |
614 |
else if (unoName.Equals(Constants.UnoXInterface)) |
615 |
buf.Append (Constants.Object); |
616 |
else if (unoName.Equals(Constants.UnoAny)) { |
617 |
buf.Append (Constants.Any); |
618 |
} else { |
619 |
//put "unoidl." at the beginning |
620 |
buf.Append (Constants.Unoidl); |
621 |
buf.Append (MapUnoPolymorphicName (unoName)); |
622 |
} |
623 |
|
624 |
// apend [] |
625 |
for (;dims-- > 0;) |
626 |
buf.Append (Constants.Brackets); |
627 |
|
628 |
// Console.WriteLine ("MapUnoTypeName {0} => {1}", typeName, buf.ToString ()); |
629 |
|
630 |
return buf.ToString(); |
631 |
} |
632 |
|
633 |
public Type GetType (UnoXCompoundTypeDescription xtd) |
634 |
{ |
635 |
// Console.WriteLine ("get compound type {0}", xtd.Name); |
636 |
|
637 |
if (xtd.TypeClass == UnoTypeClass.Exception) { |
638 |
if (xtd.Name.Equals ("com.sun.star.uno.Exception")) |
639 |
return TypeException (); |
640 |
|
641 |
if (xtd.Name.Equals ("com.sun.star.uno.RuntimeException")) |
642 |
return TypeRuntimeException (); |
643 |
} |
644 |
|
645 |
string name = "unoidl." + xtd.Name; |
646 |
|
647 |
// if the struct is an instantiated polymorpic struct then we create the simple struct name |
648 |
// For example: |
649 |
// void func ([in] PolyStruct<boolean> arg); |
650 |
// PolyStruct<boolean> will be converted to PolyStruct |
651 |
name = PolymorphicStructNameToStructName (name); |
652 |
|
653 |
Type ret = GetType (name, false /* no exc */); |
654 |
UnoXStructTypeDescription xsd = xtd as UnoXStructTypeDescription; |
655 |
|
656 |
if (ret == null) { |
657 |
// Console.WriteLine ("create compound type {0}", name); |
658 |
UnoXTypeDescription baseTD = xtd.BaseType; |
659 |
Type baseType = baseTD != null ? GetType (baseTD) : typeof (object); |
660 |
CustomAttributeBuilder attrBuilder; |
661 |
TypeBuilder typeBuilder = mModuleBuilder.DefineType (name, |
662 |
TypeAttributes.Public | |
663 |
TypeAttributes.BeforeFieldInit | |
664 |
TypeAttributes.AnsiClass, |
665 |
baseType); |
666 |
int i; |
667 |
|
668 |
// Polymorphic struct, define uno.TypeParametersAttribute |
669 |
// A polymorphic struct cannot have a basetype. |
670 |
// When we create the template of the struct then we have no exact types |
671 |
// and the name does not contain a parameter list |
672 |
if (xsd != null && xsd.TypeParameters > 0) { |
673 |
object[] args = new object [xsd.TypeParameters]; |
674 |
|
675 |
for (i = 0; i < xsd.TypeParameters; i ++) |
676 |
args [i] = xsd.TypeParameter (i); |
677 |
object[] aargs = { args }; |
678 |
|
679 |
Type[] typesCtor = { typeof (string[]) }; |
680 |
attrBuilder = new CustomAttributeBuilder (typeof (uno.TypeParametersAttribute).GetConstructor (typesCtor), aargs); |
681 |
typeBuilder.SetCustomAttribute (attrBuilder); |
682 |
} |
683 |
|
684 |
// optional: lookup base type whether generated entry of this session |
685 |
StructEntry baseTypeEntry = null; |
686 |
if (baseType != null) |
687 |
baseTypeEntry = (StructEntry) mGeneratedStructs [baseType.FullName]; |
688 |
|
689 |
// members |
690 |
for (i = 0; i < xtd.MemberTypes; i ++) { |
691 |
if (xtd.MemberType (i) == null) |
692 |
throw new Exception ("Missing type description . Check if you need to " + |
693 |
"specify additional RDBs with the --extra option. Type missing for: " + |
694 |
xtd.Name + "::" + xtd.MemberName (i)); |
695 |
} |
696 |
|
697 |
// collect base types; wrong order |
698 |
ArrayList baseTypes = new ArrayList (3); |
699 |
int allMembersLength = 0; |
700 |
for (Type baseTypePos = baseType; !baseTypePos.Equals (typeof (object)); baseTypePos = baseTypePos.BaseType) { |
701 |
baseTypes.Add (baseTypePos); |
702 |
if (baseTypePos.Equals (typeof (System.Exception))) { |
703 |
// special Message member |
704 |
allMembersLength ++; |
705 |
break; // don't include System.Exception base classes |
706 |
} else { |
707 |
allMembersLength += baseTypePos.GetFields (BindingFlags.Instance | |
708 |
BindingFlags.Public | |
709 |
BindingFlags.DeclaredOnly).Length; |
710 |
} |
711 |
} |
712 |
|
713 |
// create all_members arrays; right order |
714 |
string[] allMemberNames = new string [allMembersLength + xtd.MemberTypes]; |
715 |
Type[] allParamTypes = new Type [allMembersLength + xtd.MemberTypes]; |
716 |
int memberPos = 0; |
717 |
for (i = baseTypes.Count - 1; i >= 0; i--) { |
718 |
Type type = baseTypes [i] as Type; |
719 |
|
720 |
if (type.Equals (typeof (System.Exception))) { |
721 |
allMemberNames [memberPos] = "Message"; |
722 |
allParamTypes [memberPos] = typeof (string); |
723 |
memberPos ++; |
724 |
} else { |
725 |
StructEntry baseEntry = mGeneratedStructs [type.FullName] as StructEntry; |
726 |
if (baseEntry == null) { |
727 |
// complete type |
728 |
FieldInfo[] fields = type.GetFields (BindingFlags.Instance | |
729 |
BindingFlags.Public | |
730 |
BindingFlags.DeclaredOnly); |
731 |
foreach (FieldInfo fieldInfo in fields) { |
732 |
allMemberNames [memberPos] = fieldInfo.Name; |
733 |
allParamTypes [memberPos] = fieldInfo.FieldType; |
734 |
memberPos ++; |
735 |
} |
736 |
} else { |
737 |
// generated during this session: |
738 |
// members may be incomplete ifaces |
739 |
int j; |
740 |
for (j = 0; j < baseEntry.mParamTypes.Length; j ++) { |
741 |
allMemberNames [memberPos] = baseEntry.mMemberNames [j]; |
742 |
allParamTypes [memberPos] = baseEntry.mParamTypes [j]; |
743 |
memberPos ++; |
744 |
} |
745 |
} |
746 |
} |
747 |
} |
748 |
if (allMembersLength != memberPos) |
749 |
throw new Exception ("something went wrong, allMembersLength != memberPos"); |
750 |
|
751 |
|
752 |
// build up entry |
753 |
StructEntry entry = new StructEntry (); |
754 |
entry.mMemberNames = new string [xtd.MemberTypes]; |
755 |
entry.mParamTypes = new Type [xtd.MemberTypes]; |
756 |
|
757 |
// add members |
758 |
FieldBuilder[] members = new FieldBuilder [xtd.MemberTypes]; |
759 |
int curParamIndex = 0; |
760 |
int typeParamPos = 0; |
761 |
|
762 |
for (memberPos = 0; memberPos < xtd.MemberTypes; memberPos ++) { |
763 |
string fieldName = xtd.MemberName (memberPos); |
764 |
Type fieldType; |
765 |
|
766 |
//Special handling of struct parameter types |
767 |
bool parameterizedType = false; |
768 |
if (xtd.MemberType (memberPos).TypeClass == UnoTypeClass.Unknown) { |
769 |
parameterizedType = true; |
770 |
if (xsd != null && typeParamPos < xsd.TypeParameters) { |
771 |
fieldType = typeof (object); |
772 |
typeParamPos ++; |
773 |
} else { |
774 |
throw new Exception ("unexpected member type in " + xtd.Name); |
775 |
} |
776 |
} else { |
777 |
fieldType = GetType (xtd.MemberType (memberPos)); |
778 |
} |
779 |
members [memberPos] = typeBuilder.DefineField (fieldName, fieldType, FieldAttributes.Public); |
780 |
|
781 |
//parameterized type (polymorphic struct) ? |
782 |
if (parameterizedType && xsd != null) { |
783 |
object[] args = { xsd.TypeParameter (curParamIndex ++) }; |
784 |
Type[] ctorTypes = { typeof (string) }; |
785 |
attrBuilder = new CustomAttributeBuilder (typeof (uno.ParameterizedTypeAttribute).GetConstructor (ctorTypes), args); |
786 |
members [memberPos].SetCustomAttribute (attrBuilder); |
787 |
} |
788 |
|
789 |
// add to all_members |
790 |
allMemberNames [allMembersLength + memberPos] = fieldName; |
791 |
allParamTypes [allMembersLength + memberPos] = fieldType; |
792 |
|
793 |
// add to entry |
794 |
entry.mMemberNames [memberPos] = fieldName; |
795 |
entry.mParamTypes [memberPos] = fieldType; |
796 |
} |
797 |
|
798 |
allMembersLength += xtd.MemberTypes; |
799 |
|
800 |
// default .ctor |
801 |
ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr, CallingConventions.Standard, new Type [0]); |
802 |
ILGenerator code = ctorBuilder.GetILGenerator (); |
803 |
|
804 |
code.Emit (OpCodes.Ldarg_0); |
805 |
// Console.WriteLine ("baseType: {0}", baseType); |
806 |
code.Emit (OpCodes.Call, baseTypeEntry == null ? baseType.GetConstructor (new Type [0]) : baseTypeEntry.mDefaultConstructor); |
807 |
|
808 |
// default initialize members |
809 |
for (memberPos = 0; memberPos < xtd.MemberTypes; memberPos ++) { |
810 |
FieldInfo fieldInfo = members [memberPos]; |
811 |
|
812 |
// default initialize |
813 |
// string, type, enum, sequence, struct, exception, any |
814 |
if (fieldInfo.FieldType.Equals (typeof (string))) { |
815 |
code.Emit (OpCodes.Ldarg_0); |
816 |
code.Emit (OpCodes.Ldstr, ""); |
817 |
code.Emit (OpCodes.Stfld, fieldInfo); |
818 |
} else if (fieldInfo.FieldType.Equals (typeof (Type))) { |
819 |
code.Emit (OpCodes.Ldarg_0); |
820 |
code.Emit (OpCodes.Ldtoken, typeof (void)); |
821 |
code.Emit (OpCodes.Call, mMethodInfoTypeGetTypeFromHandle); |
822 |
code.Emit (OpCodes.Stfld, fieldInfo); |
823 |
} else if (fieldInfo.FieldType.IsArray) { |
824 |
code.Emit (OpCodes.Ldarg_0); |
825 |
code.Emit (OpCodes.Ldc_I4_0); |
826 |
code.Emit (OpCodes.Newarr, fieldInfo.FieldType.GetElementType ()); |
827 |
code.Emit (OpCodes.Stfld, fieldInfo); |
828 |
} else if (fieldInfo.FieldType.IsValueType) { |
829 |
if (fieldInfo.FieldType.FullName.Equals ("uno.Any")) { |
830 |
code.Emit (OpCodes.Ldarg_0); |
831 |
code.Emit (OpCodes.Ldsfld, typeof (uno.Any).GetField ("VOID")); |
832 |
code.Emit (OpCodes.Stfld, fieldInfo); |
833 |
} |
834 |
} else if (fieldInfo.FieldType.IsClass) { |
835 |
// may be XInterface |
836 |
if (!fieldInfo.FieldType.Equals (typeof (object))) { |
837 |
code.Emit (OpCodes.Ldarg_0); |
838 |
code.Emit (OpCodes.Newobj, fieldInfo.FieldType.GetConstructor (new Type [0])); |
839 |
code.Emit (OpCodes.Stfld, fieldInfo); |
840 |
} |
841 |
} |
842 |
} |
843 |
|
844 |
code.Emit (OpCodes.Ret); |
845 |
entry.mDefaultConstructor = ctorBuilder; |
846 |
|
847 |
// parameterized .ctor including all base members |
848 |
ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr, CallingConventions.Standard, allParamTypes); |
849 |
for (memberPos = 0; memberPos < allMembersLength; memberPos ++) |
850 |
ctorBuilder.DefineParameter (memberPos + 1, ParameterAttributes.In, allMemberNames [memberPos]); |
851 |
|
852 |
code = ctorBuilder.GetILGenerator (); |
853 |
// call base .ctor |
854 |
code.Emit (OpCodes.Ldarg_0); // push this |
855 |
int baseMembersLength = allMembersLength - xtd.MemberTypes; |
856 |
Type[] paramTypes = new Type [baseMembersLength]; |
857 |
|
858 |
for (memberPos = 0; memberPos < baseMembersLength; memberPos ++) { |
859 |
EmitLdarg (code, memberPos + 1); |
860 |
paramTypes [memberPos] = allParamTypes [memberPos]; |
861 |
} |
862 |
|
863 |
code.Emit (OpCodes.Call, baseTypeEntry == null ? baseType.GetConstructor (paramTypes) : baseTypeEntry.mConstructor); |
864 |
|
865 |
// initialize members |
866 |
|
867 |
for (memberPos = 0; memberPos < xtd.MemberTypes; memberPos ++) { |
868 |
code.Emit (OpCodes.Ldarg_0); // push this |
869 |
EmitLdarg (code, memberPos + baseMembersLength + 1); |
870 |
code.Emit (OpCodes.Stfld, members [memberPos]); |
871 |
} |
872 |
|
873 |
code.Emit (OpCodes.Ret); |
874 |
entry.mConstructor = ctorBuilder; |
875 |
|
876 |
if (mConfig.mVerbose) |
877 |
Console.WriteLine ("> emitting {0} type {1}", xtd is UnoXStructTypeDescription ? "struct" : "exception", name); |
878 |
|
879 |
// new entry |
880 |
mGeneratedStructs.Add (name, entry); |
881 |
//Console.WriteLine ("added entry to mGeneratedStructs: {0}", name); |
882 |
//if (baseTD != null) |
883 |
//Console.WriteLine ("baseTD: {0}", baseTD.Name, GetType (baseTD).Name); |
884 |
ret = typeBuilder.CreateType (); |
885 |
} |
886 |
|
887 |
// In case of an instantiated polymorphic struct we want to return a |
888 |
// uno.PolymorphicType (inherits Type) rather then Type. |
889 |
if (xsd != null && xsd.TypeArguments > 0) { |
890 |
//Console.WriteLine ("polymorphic struct: call uno.PolymorphicType.GetType ({0}, {1})", ret, xtd.Name); |
891 |
ret = uno.PolymorphicType.GetType (ret, MapUnoTypeName (xtd.Name)); |
892 |
//Console.WriteLine ("polymorphic struct: {0} ({1})", ret, xtd.Name); |
893 |
} |
894 |
|
895 |
return ret; |
896 |
} |
897 |
|
898 |
public Type GetType (UnoXConstantTypeDescription xtd) |
899 |
{ |
900 |
//Console.WriteLine ("get constant type {0}", xtd.Name); |
901 |
|
902 |
string name = "unoidl." + xtd.Name; |
903 |
|
904 |
Type ret = GetType (name, false /* no exc */); |
905 |
|
906 |
if (ret == null) { |
907 |
object constant = xtd.ConstantValue; |
908 |
|
909 |
TypeBuilder typeBuilder = mModuleBuilder.DefineType (name, |
910 |
TypeAttributes.Public | |
911 |
TypeAttributes.Sealed | |
912 |
TypeAttributes.BeforeFieldInit | |
913 |
TypeAttributes.AnsiClass); |
914 |
FieldBuilder field = typeBuilder.DefineField (name.Substring (name.LastIndexOf ('.') + 1), |
915 |
constant.GetType (), |
916 |
FieldAttributes.Public | |
917 |
FieldAttributes.Static | |
918 |
FieldAttributes.Literal); |
919 |
field.SetConstant (constant); |
920 |
|
921 |
if (mConfig.mVerbose) |
922 |
Console.WriteLine ("> emitting constant type {0}", name); |
923 |
|
924 |
ret = typeBuilder.CreateType (); |
925 |
} |
926 |
|
927 |
return ret; |
928 |
} |
929 |
|
930 |
public Type GetType (UnoXConstantsTypeDescription xtd) |
931 |
{ |
932 |
//Console.WriteLine ("get constants type {0}", xtd.Name); |
933 |
|
934 |
string name = "unoidl." + xtd.Name; |
935 |
|
936 |
Type ret = GetType (name, false /* no exc */); |
937 |
|
938 |
if (ret == null) { |
939 |
TypeBuilder typeBuilder = mModuleBuilder.DefineType (name, |
940 |
TypeAttributes.Public | |
941 |
TypeAttributes.Sealed | |
942 |
TypeAttributes.BeforeFieldInit | |
943 |
TypeAttributes.AnsiClass); |
944 |
int i; |
945 |
for (i = 0; i < xtd.Constants; i ++) { |
946 |
UnoXConstantTypeDescription constantTD = xtd.Constant (i); |
947 |
object constant = constantTD.ConstantValue; |
948 |
FieldBuilder field = typeBuilder.DefineField (constantTD.Name.Substring (constantTD.Name.LastIndexOf ('.') + 1), |
949 |
constant.GetType (), |
950 |
FieldAttributes.Public | |
951 |
FieldAttributes.Static | |
952 |
FieldAttributes.Literal); |
953 |
field.SetConstant (constant); |
954 |
} |
955 |
|
956 |
if (mConfig.mVerbose) |
957 |
Console.WriteLine ( "> emitting constants group type {0}", name); |
958 |
|
959 |
ret = typeBuilder.CreateType (); |
960 |
} |
961 |
|
962 |
return ret; |
963 |
} |
964 |
|
965 |
public Type GetType (UnoXSingletonTypeDescription xtd) |
966 |
{ |
967 |
//Console.WriteLine ("get singleton {0}", xtd.Name); |
968 |
|
969 |
if (!xtd.IsInterfaceBased) |
970 |
return null; |
971 |
|
972 |
//Console.WriteLine ("singleton {0} is interface based", xtd.Name); |
973 |
|
974 |
string name = "unoidl." + xtd.Name; |
975 |
|
976 |
Type ret = GetType (name, false /* no exc */); |
977 |
|
978 |
if (ret != null) |
979 |
return ret; |
980 |
|
981 |
TypeAttributes attr = |
982 |
TypeAttributes.Public | |
983 |
TypeAttributes.Sealed | |
984 |
TypeAttributes.BeforeFieldInit | |
985 |
TypeAttributes.AnsiClass; |
986 |
|
987 |
// insert to be completed |
988 |
SingletonEntry entry = new SingletonEntry (); |
989 |
entry.mType = xtd; |
990 |
entry.mTypeBuilder = mModuleBuilder.DefineType (name, attr); |
991 |
mIncompleteSingletons.Add (name, entry); |
992 |
|
993 |
return entry.mTypeBuilder; |
994 |
} |
995 |
|
996 |
public Type GetType (UnoXTypeDescription xtd) |
997 |
{ |
998 |
UnoTypeClass tc = xtd.TypeClass; |
999 |
|
1000 |
switch (tc) { |
1001 |
case UnoTypeClass.Void: |
1002 |
return typeof (void); |
1003 |
case UnoTypeClass.Char: |
1004 |
return typeof (char); |
1005 |
case UnoTypeClass.Boolean: |
1006 |
return typeof (bool); |
1007 |
case UnoTypeClass.Byte: |
1008 |
return typeof (byte); |
1009 |
case UnoTypeClass.Short: |
1010 |
return typeof (Int16); |
1011 |
case UnoTypeClass.UnsignedShort: |
1012 |
return typeof (UInt16); |
1013 |
case UnoTypeClass.Long: |
1014 |
return typeof (Int32); |
1015 |
case UnoTypeClass.UnsignedLong: |
1016 |
return typeof (UInt32); |
1017 |
case UnoTypeClass.Hyper: |
1018 |
return typeof (Int64); |
1019 |
case UnoTypeClass.UnsignedHyper: |
1020 |
return typeof (UInt64); |
1021 |
case UnoTypeClass.Float: |
1022 |
return typeof (Single); |
1023 |
case UnoTypeClass.Double: |
1024 |
return typeof (double); |
1025 |
case UnoTypeClass.String: |
1026 |
return typeof (string); |
1027 |
case UnoTypeClass.Type: |
1028 |
return typeof (Type); |
1029 |
case UnoTypeClass.Any: |
1030 |
return typeof (uno.Any); |
1031 |
case UnoTypeClass.Enum: |
1032 |
return GetType (xtd as UnoXEnumTypeDescription); |
1033 |
case UnoTypeClass.Interface: |
1034 |
return GetType (xtd as UnoXInterfaceTypeDescription); |
1035 |
case UnoTypeClass.Struct: |
1036 |
case UnoTypeClass.Exception: |
1037 |
return GetType (xtd as UnoXCompoundTypeDescription); |
1038 |
case UnoTypeClass.Module: |
1039 |
return null; |
1040 |
case UnoTypeClass.Sequence: |
1041 |
Type elementType = GetType ((xtd as UnoXIndirectTypeDescription).ReferencedType); |
1042 |
Type retType = GetType (elementType.FullName + "[]", true); |
1043 |
uno.PolymorphicType polyType = elementType as uno.PolymorphicType; |
1044 |
if (polyType != null) { |
1045 |
string name = polyType.PolymorphicName + "[]"; |
1046 |
retType = uno.PolymorphicType.GetType (retType, name); |
1047 |
} |
1048 |
return retType; |
1049 |
case UnoTypeClass.Typedef: |
1050 |
return GetType ((xtd as UnoXIndirectTypeDescription).ReferencedType); |
1051 |
case UnoTypeClass.Constant: |
1052 |
return GetType (xtd as UnoXConstantTypeDescription); |
1053 |
case UnoTypeClass.Constants: |
1054 |
return GetType (xtd as UnoXConstantsTypeDescription); |
1055 |
case UnoTypeClass.Service: |
1056 |
return GetType (xtd as UnoXServiceTypeDescription); |
1057 |
case UnoTypeClass.Singleton: |
1058 |
return GetType (xtd as UnoXSingletonTypeDescription); |
1059 |
default: |
1060 |
// fixme, use double for unfinished types |
1061 |
//Console.WriteLine ("warning: unfinished type reached: {0}", xtd.Name); |
1062 |
return typeof (void); |
1063 |
} |
1064 |
|
1065 |
//throw new Exception (String.Format ("Unknown type requested {0}", tc)); |
1066 |
} |
1067 |
|
1068 |
CustomAttributeBuilder IFaceMethodExceptionAttribute (UnoXInterfaceMethodTypeDescription method) |
1069 |
{ |
1070 |
Type[] exceptionTypes = new Type [method.ExceptionTypes]; |
1071 |
int i; |
1072 |
|
1073 |
for (i = 0; i < method.ExceptionTypes; i ++) { |
1074 |
exceptionTypes [i] = GetType (method.ExceptionType (i)); |
1075 |
} |
1076 |
|
1077 |
return ExceptionAttribute (exceptionTypes); |
1078 |
} |
1079 |
|
1080 |
CustomAttributeBuilder ExceptionAttribute (Type[] exceptionTypes) |
1081 |
{ |
1082 |
CustomAttributeBuilder attrBuilder = null; |
1083 |
|
1084 |
if (exceptionTypes.Length > 0) { |
1085 |
object[] args = { exceptionTypes }; |
1086 |
Type[] arTypesCtor = { typeof (Type[]) }; |
1087 |
ConstructorInfo ctorInfo = typeof (uno.ExceptionAttribute).GetConstructor (arTypesCtor); |
1088 |
attrBuilder = new CustomAttributeBuilder (ctorInfo, args); |
1089 |
} |
1090 |
|
1091 |
return attrBuilder; |
1092 |
} |
1093 |
|
1094 |
Type[] GetTypes (UnoXTypeDescription[] tds) |
1095 |
{ |
1096 |
Type[] types = new Type [tds.Length]; |
1097 |
int i; |
1098 |
|
1099 |
for (i = 0; i < tds.Length; i ++) |
1100 |
types [i] = GetType (tds [i]); |
1101 |
|
1102 |
return types; |
1103 |
} |
1104 |
|
1105 |
Type CompleteIFaceType (IFaceEntry entry) |
1106 |
{ |
1107 |
//Console.WriteLine ("going to complete {0}", entry.mTypeBuilder.FullName); |
1108 |
|
1109 |
// complete base interfaces first |
1110 |
foreach (Type type in entry.mTypeBuilder.GetInterfaces ()) { |
1111 |
IFaceEntry baseEntry = mIncompleteIFaces [type.FullName] as IFaceEntry; |
1112 |
if (baseEntry != null) |
1113 |
CompleteIFaceType (baseEntry); |
1114 |
} |
1115 |
|
1116 |
// emit members |
1117 |
const MethodAttributes methodAttr = |
1118 |
MethodAttributes.Public | |
1119 |
MethodAttributes.Abstract | |
1120 |
MethodAttributes.Virtual | |
1121 |
MethodAttributes.NewSlot | |
1122 |
MethodAttributes.HideBySig; |
1123 |
int i; |
1124 |
|
1125 |
for (i = 0; i < entry.mType.Members; i ++) { |
1126 |
UnoXInterfaceMemberTypeDescription member = entry.mType.Member (i); |
1127 |
MethodBuilder methodBuilder; |
1128 |
CustomAttributeBuilder attrBuilder; |
1129 |
|
1130 |
if (member.TypeClass == UnoTypeClass.InterfaceMethod) { |
1131 |
UnoXInterfaceMethodTypeDescription method = new UnoXInterfaceMethodTypeDescription (member.Handle); |
1132 |
UnoXMethodParameter[] parameters = new UnoXMethodParameter [method.Parameters]; |
1133 |
Type[] pTypes = new Type [method.Parameters]; |
1134 |
int j; |
1135 |
|
1136 |
//Console.WriteLine ("method {0}.{1}", entry.mTypeBuilder.FullName, method.MemberName); |
1137 |
|
1138 |
// first determine all types |
1139 |
for (j = 0; j < method.Parameters; j ++) { |
1140 |
parameters [j] = method.Parameter (j); |
1141 |
pTypes [j] = GetType (parameters [j].Type); |
1142 |
if (parameters [j].IsOut) |
1143 |
pTypes [j] = GetType (pTypes [j].FullName + "&", true); |
1144 |
} |
1145 |
|
1146 |
// create method |
1147 |
methodBuilder = entry.mTypeBuilder.DefineMethod (method.MemberName, |
1148 |
methodAttr, |
1149 |
GetType (method.ReturnType), |
1150 |
pTypes); |
1151 |
|
1152 |
// then define parameter infos |
1153 |
for (j = 0; j < method.Parameters; j ++) { |
1154 |
ParameterAttributes attr = 0; |
1155 |
if (parameters [j].IsIn) |
1156 |
attr |= ParameterAttributes.In; |
1157 |
if (parameters [j].IsOut) |
1158 |
attr |= ParameterAttributes.Out; |
1159 |
|
1160 |
if (attr == 0) |
1161 |
throw new Exception ("wrong parameter attributes"); |
1162 |
|
1163 |
methodBuilder.DefineParameter (parameters [j].Position + 1, |
1164 |
attr, |
1165 |
parameters [j].Name); |
1166 |
} |
1167 |
|
1168 |
if (method.ReturnsStruct) { |
1169 |
// Console.WriteLine ("returns struct"); |
1170 |
|
1171 |
UnoXStructTypeDescription std = method.ReturnType as UnoXStructTypeDescription; |
1172 |
if (std.TypeArguments != 0) { |
1173 |
// Console.WriteLine ("std: '{0}' '{1}' {2}", std, method.ReturnType, method.ReturnType.Name); |
1174 |
Type[] ats = new Type [std.TypeArguments]; |
1175 |
|
1176 |
// Console.WriteLine ("type arguments: {0}", std.TypeArguments); |
1177 |
|
1178 |
for (j = 0; j < std.TypeArguments; j ++) { |
1179 |
ats [j] = GetType (std.TypeArgument (j)); |
1180 |
//Console.WriteLine ("ats [{0}] = {1}", j, ats [j]); |
1181 |
} |
1182 |
|
1183 |
object[] atso = { ats }; |
1184 |
Type[] ctor = { typeof (Type[]) }; |
1185 |
attrBuilder = new CustomAttributeBuilder (typeof (uno.TypeArgumentsAttribute).GetConstructor (ctor), |
1186 |
atso); |
1187 |
methodBuilder.SetCustomAttribute (attrBuilder); |
1188 |
} |
1189 |
} |
1190 |
|
1191 |
// define UNO exception attribute (exceptions) -------------------------------------- |
1192 |
attrBuilder = IFaceMethodExceptionAttribute (method); |
1193 |
if (attrBuilder != null) |
1194 |
methodBuilder.SetCustomAttribute (attrBuilder); |
1195 |
|
1196 |
// oneway attribute |
1197 |
if (method.IsOneway) { |
1198 |
Type[] arCtorOneway = new Type [0]; |
1199 |
object[] arArgs = new object [0]; |
1200 |
attrBuilder = new CustomAttributeBuilder (typeof (uno.OnewayAttribute).GetConstructor (arCtorOneway), |
1201 |
arArgs); |
1202 |
methodBuilder.SetCustomAttribute (attrBuilder); |
1203 |
} |
1204 |
} else { |
1205 |
// attribute |
1206 |
if (member.TypeClass != UnoTypeClass.InterfaceAttribute) |
1207 |
throw new Exception (String.Format ("Unknown member type class: {0} ", member.TypeClass)); |
1208 |
|
1209 |
UnoXInterfaceAttributeTypeDescription attribute = new UnoXInterfaceAttributeTypeDescription (member.Handle); |
1210 |
const MethodAttributes propMethodAttr = methodAttr | MethodAttributes.SpecialName; |
1211 |
|
1212 |
Type attrType = GetType (attribute.Type); |
1213 |
//Console.WriteLine ("attribute {2} type: {0} => {1}", attribute.Type, attrType, attribute.Name); |
1214 |
Type[] parameters = new Type [0]; |
1215 |
|
1216 |
PropertyBuilder propBuilder = entry.mTypeBuilder.DefineProperty (attribute.MemberName, PropertyAttributes.None, attrType, parameters); |
1217 |
|
1218 |
//set BoundAttribute, if necessary |
1219 |
if (attribute.IsBound) { |
1220 |
ConstructorInfo ctorBoundAttr = typeof (uno.BoundAttribute).GetConstructor (new Type [0]); |
1221 |
attrBuilder = new CustomAttributeBuilder (ctorBoundAttr, new object [0]); |
1222 |
propBuilder.SetCustomAttribute (attrBuilder); |
1223 |
} |
1224 |
|
1225 |
// getter |
1226 |
methodBuilder = entry.mTypeBuilder.DefineMethod ("get_" + attribute.MemberName, |
1227 |
propMethodAttr, attrType, parameters); |
1228 |
|
1229 |
attrBuilder = ExceptionAttribute (GetTypes (attribute.GetExceptionTypes)); |
1230 |
if (attrBuilder != null) |
1231 |
methodBuilder.SetCustomAttribute (attrBuilder); |
1232 |
|
1233 |
propBuilder.SetGetMethod (methodBuilder); |
1234 |
|
1235 |
if (!attribute.IsReadOnly) { |
1236 |
// setter |
1237 |
parameters = new Type [1]; |
1238 |
parameters [0] = attrType; |
1239 |
//parameters [0] = null; |
1240 |
//Console.WriteLine ("setter parameters: {0} ({1})", parameters, parameters [0]); |
1241 |
methodBuilder = entry.mTypeBuilder.DefineMethod ("set_" + attribute.MemberName, |
1242 |
propMethodAttr, typeof (void), parameters); |
1243 |
methodBuilder.DefineParameter (1, ParameterAttributes.In, "value"); |
1244 |
|
1245 |
attrBuilder = ExceptionAttribute (GetTypes (attribute.SetExceptionTypes)); |
1246 |
if (attrBuilder != null) |
1247 |
methodBuilder.SetCustomAttribute (attrBuilder); |
1248 |
|
1249 |
propBuilder.SetSetMethod (methodBuilder); |
1250 |
} |
1251 |
} |
1252 |
} |
1253 |
// cmm_x_interface_type_description_members_release (membersHandle); |
1254 |
|
1255 |
if (mConfig.mVerbose) |
1256 |
Console.WriteLine ("> emitting interface type {0}", "unoidl." + entry.mType.Name); |
1257 |
|
1258 |
mIncompleteIFaces.Remove (entry.mTypeBuilder.FullName); |
1259 |
|
1260 |
//Console.WriteLine ("completed {0}", entry.mTypeBuilder.FullName); |
1261 |
|
1262 |
return entry.mTypeBuilder.CreateType (); |
1263 |
} |
1264 |
|
1265 |
UnoXInterfaceTypeDescription ResolveInterfaceTypedef (UnoXTypeDescription xtd) |
1266 |
{ |
1267 |
UnoXInterfaceTypeDescription xtdIface = xtd as UnoXInterfaceTypeDescription; |
1268 |
|
1269 |
if (xtdIface != null) |
1270 |
return xtdIface; |
1271 |
|
1272 |
UnoXIndirectTypeDescription xtdIndirect = xtd as UnoXIndirectTypeDescription; |
1273 |
|
1274 |
if (xtdIndirect != null) |
1275 |
return ResolveInterfaceTypedef (xtdIndirect.ReferencedType);; |
1276 |
|
1277 |
throw new Exception ("resolveInterfaceTypedef was called with an invalid argument"); |
1278 |
} |
1279 |
|
1280 |
ArrayList GetServiceConstructorMethodExceptionsReduced (UnoXTypeDescription[] exceptionTypes) |
1281 |
{ |
1282 |
if (exceptionTypes.Length == 0) |
1283 |
return new ArrayList (); |
1284 |
|
1285 |
ArrayList types = new ArrayList(); |
1286 |
int i; |
1287 |
|
1288 |
for (i = 0; i < exceptionTypes.Length; i ++) |
1289 |
types.Add (GetType ("unoidl." + exceptionTypes [i].Name, true)); |
1290 |
|
1291 |
int start = 0; |
1292 |
while (true) { |
1293 |
bool bRemove = false; |
1294 |
|
1295 |
for (i = start; i < types.Count; i ++) { |
1296 |
Type t = types [i] as Type; |
1297 |
int j; |
1298 |
|
1299 |
for (j = 0; j < types.Count; j ++) { |
1300 |
if (t.IsSubclassOf (types [j] as Type)) { |
1301 |
types.RemoveAt (i); |
1302 |
bRemove = true; |
1303 |
break; |
1304 |
} |
1305 |
} |
1306 |
if (bRemove) |
1307 |
break; |
1308 |
start ++; |
1309 |
} |
1310 |
|
1311 |
if (bRemove == false) |
1312 |
break; |
1313 |
} |
1314 |
|
1315 |
return types; |
1316 |
} |
1317 |
|
1318 |
Type CompleteServiceType (ServiceEntry entry) |
1319 |
{ |
1320 |
// Create the private default constructor |
1321 |
ConstructorBuilder ctorBuilder = entry.mTypeBuilder.DefineConstructor (MethodAttributes.Private | |
1322 |
MethodAttributes.HideBySig | |
1323 |
MethodAttributes.SpecialName | |
1324 |
MethodAttributes.RTSpecialName, |
1325 |
CallingConventions.Standard, |
1326 |
null); |
1327 |
|
1328 |
ILGenerator ilGen = ctorBuilder.GetILGenerator (); |
1329 |
ilGen.Emit (OpCodes.Ldarg_0); // push this |
1330 |
ilGen.Emit (OpCodes.Call, entry.mTypeBuilder.BaseType.GetConstructor (new Type[0])); |
1331 |
ilGen.Emit (OpCodes.Ret); |
1332 |
|
1333 |
// Create the service constructors. |
1334 |
// obtain the interface which makes up this service, it is the return |
1335 |
// type of the constructor functions |
1336 |
UnoXInterfaceTypeDescription iface = entry.mType.Interface as UnoXInterfaceTypeDescription; |
1337 |
|
1338 |
if (iface == null) |
1339 |
iface = ResolveInterfaceTypedef (entry.mType.Interface); |
1340 |
|
1341 |
Type ret = GetType (iface); |
1342 |
|
1343 |
// Create the ConstructorInfo for a DeploymentException |
1344 |
Type typeDeploymentException = GetType ("unoidl.com.sun.star.uno.DeploymentException", true); |
1345 |
Type[] arTypeCtor = { typeof (string), typeof (object) }; |
1346 |
ConstructorInfo ctorDeploymentException = typeDeploymentException.GetConstructor (arTypeCtor); |
1347 |
|
1348 |
Type typeUnoException = GetType ("unoidl.com.sun.star.uno.Exception", true); |
1349 |
int i, j; |
1350 |
|
1351 |
for (i = entry.mType.Constructors - 1; i >= 0; i --) { |
1352 |
bool bParameterArray = false; |
1353 |
UnoXServiceConstructorDescription ctorDesc = entry.mType.Constructor (i); |
1354 |
Type[] typeParameters = new Type [ctorDesc.Parameters + 1]; |
1355 |
typeParameters [0] = GetType ("unoidl.com.sun.star.uno.XComponentContext", true); |
1356 |
|
1357 |
for (j = 0; j < ctorDesc.Parameters; j ++) { |
1358 |
UnoXParameter parameter = ctorDesc.Parameter (j); |
1359 |
|
1360 |
if (parameter.IsRest) |
1361 |
typeParameters [j + 1] = typeof (uno.Any[]); |
1362 |
else |
1363 |
typeParameters [j + 1] = GetType (parameter.Type); |
1364 |
} |
1365 |
|
1366 |
// The array typeParameters can contain: |
1367 |
// System.Type and uno.PolymorphicType. |
1368 |
// Passing PolymorphicType to MethodBuilder.DefineMethod will cause a problem. |
1369 |
// The exception will read something like no on information for parameter # d |
1370 |
// Maybe we need no override another Type method in PolymorphicType ... |
1371 |
// Until we have figured this out, we will create another array of System.Type which |
1372 |
// we pass on to DefineMethod. |
1373 |
|
1374 |
Type[] paramTypes = new Type [ctorDesc.Parameters + 1]; |
1375 |
|
1376 |
for (j = 0; j < ctorDesc.Parameters + 1; j ++) { |
1377 |
if (typeParameters [j] is uno.PolymorphicType) |
1378 |
paramTypes [j] = (typeParameters [j] as uno.PolymorphicType).OriginalType; |
1379 |
else |
1380 |
paramTypes [j] = typeParameters [j]; |
1381 |
} |
1382 |
|
1383 |
//define method |
1384 |
string ctorName; |
1385 |
if (ctorDesc.IsDefault) |
1386 |
ctorName = "create"; |
1387 |
else |
1388 |
ctorName = ctorDesc.Name; |
1389 |
|
1390 |
MethodBuilder methodBuilder = entry.mTypeBuilder.DefineMethod (ctorName, |
1391 |
MethodAttributes.Public | |
1392 |
MethodAttributes.HideBySig | |
1393 |
MethodAttributes.Static, |
1394 |
ret, |
1395 |
paramTypes); |
1396 |
|
1397 |
//define UNO exception attribute (exceptions)-------------------------------------- |
1398 |
CustomAttributeBuilder attrBuilder = ExceptionAttribute (GetTypes (ctorDesc.ExceptionTypes)); |
1399 |
if (attrBuilder != null) |
1400 |
methodBuilder.SetCustomAttribute (attrBuilder); |
1401 |
|
1402 |
// define parameter attributes (paramarray), names etc. |
1403 |
// The first parameter is the XComponentContext, which cannot be obtained |
1404 |
// from reflection. |
1405 |
// The context is not part of the idl description |
1406 |
|
1407 |
methodBuilder.DefineParameter (1, ParameterAttributes.In, "the_context"); |
1408 |
|
1409 |
ParameterBuilder[] parameterBuilder = new ParameterBuilder [ctorDesc.Parameters]; |
1410 |
int iparam; |
1411 |
|
1412 |
for (iparam = 0; iparam < ctorDesc.Parameters; iparam ++) { |
1413 |
UnoXParameter parameter = ctorDesc.Parameter (iparam); |
1414 |
|
1415 |
parameterBuilder [iparam] = methodBuilder.DefineParameter (iparam + 2, ParameterAttributes.In, parameter.Name); |
1416 |
|
1417 |
if (parameter.IsRest) { |
1418 |
bParameterArray = true; |
1419 |
//set the ParameterArrayAttribute |
1420 |
ConstructorInfo ctorInfo = typeof (System.ParamArrayAttribute).GetConstructor (new Type [0]); |
1421 |
attrBuilder = new CustomAttributeBuilder (ctorInfo, new object [0]); |
1422 |
|
1423 |
parameterBuilder[iparam].SetCustomAttribute (attrBuilder); |
1424 |
break; |
1425 |
} |
1426 |
} |
1427 |
|
1428 |
ilGen = methodBuilder.GetILGenerator (); |
1429 |
|
1430 |
// Define locals --------------------------------- |
1431 |
// XMultiComponentFactory |
1432 |
LocalBuilder localFactory = ilGen.DeclareLocal (GetType ("unoidl.com.sun.star.lang.XMultiComponentFactory", true)); |
1433 |
|
1434 |
// The return type |
1435 |
LocalBuilder localReturnVal = ilGen.DeclareLocal (ret); |
1436 |
|
1437 |
// Obtain the XMultiComponentFactory and throw an exception if we do not get one |
1438 |
ilGen.Emit (OpCodes.Ldarg_0); |
1439 |
|
1440 |
MethodInfo methodGetServiceManager = GetType ("unoidl.com.sun.star.uno.XComponentContext", true).GetMethod ("getServiceManager"); |
1441 |
ilGen.Emit (OpCodes.Callvirt, methodGetServiceManager); |
1442 |
ilGen.Emit (OpCodes.Stloc, localFactory); |
1443 |
ilGen.Emit (OpCodes.Ldloc, localFactory); |
1444 |
Label label1 = ilGen.DefineLabel (); |
1445 |
ilGen.Emit (OpCodes.Brtrue, label1); |
1446 |
|
1447 |
// The string for the exception |
1448 |
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder (256); |
1449 |
|
1450 |
strBuilder.Append ("The service "); |
1451 |
strBuilder.Append ("unoidl." + entry.mType.Name); |
1452 |
strBuilder.Append (" could not be created. The context failed to supply the service manager."); |
1453 |
|
1454 |
ilGen.Emit (OpCodes.Ldstr, strBuilder.ToString ()); |
1455 |
ilGen.Emit (OpCodes.Ldarg_0); |
1456 |
ilGen.Emit (OpCodes.Newobj, ctorDeploymentException); |
1457 |
ilGen.Emit (OpCodes.Throw); |
1458 |
ilGen.MarkLabel (label1); |
1459 |
|
1460 |
// We create a try/ catch around the createInstanceWithContext, etc. functions |
1461 |
// There are 3 cases |
1462 |
// 1. function do not specify exceptions. Then RuntimeExceptions are retrhown and other |
1463 |
// exceptions produce a DeploymentException. |
1464 |
// 2. function specify Exception. Then all exceptions fly through |
1465 |
// 3. function specifies exceptions but no Exception. Then these are rethrown |
1466 |
// and other exceptions, except RuntimeException, produce a deployment exception. |
1467 |
// In case there are no parameters we call |
1468 |
// XMultiComponentFactory.createInstanceWithContext |
1469 |
|
1470 |
ArrayList exceptionTypes = GetServiceConstructorMethodExceptionsReduced (ctorDesc.ExceptionTypes); |
1471 |
if (!exceptionTypes.Contains (typeUnoException)) { |
1472 |
ilGen.BeginExceptionBlock (); |
1473 |
} |
1474 |
|
1475 |
if (ctorDesc.Parameters == 0) { |
1476 |
ilGen.Emit (OpCodes.Ldloc, localFactory); |
1477 |
ilGen.Emit (OpCodes.Ldstr, entry.mType.Name); |
1478 |
ilGen.Emit (OpCodes.Ldarg_0); |
1479 |
|
1480 |
MethodInfo methodCreate = localFactory.LocalType.GetMethod ("createInstanceWithContext"); |
1481 |
ilGen.Emit (OpCodes.Callvirt, methodCreate); |
1482 |
} else if(bParameterArray) { |
1483 |
//Service constructor with parameter array |
1484 |
ilGen.Emit (OpCodes.Ldloc, localFactory); |
1485 |
ilGen.Emit (OpCodes.Ldstr, entry.mType.Name); |
1486 |
ilGen.Emit (OpCodes.Ldarg_1); |
1487 |
ilGen.Emit (OpCodes.Ldarg_0); |
1488 |
MethodInfo methodCreate = localFactory.LocalType.GetMethod ("createInstanceWithArgumentsAndContext"); |
1489 |
ilGen.Emit(OpCodes.Callvirt, methodCreate); |
1490 |
} else { |
1491 |
// Any param1, Any param2, etc. |
1492 |
// For each parameter,except the component context, and parameter array |
1493 |
// and Any is created. |
1494 |
LocalBuilder[] localAny = new LocalBuilder [ctorDesc.Parameters]; |
1495 |
|
1496 |
for (iparam = 0; iparam < ctorDesc.Parameters; iparam ++) { |
1497 |
localAny [iparam] = ilGen.DeclareLocal (typeof (uno.Any)); |
1498 |
} |
1499 |
|
1500 |
// Any[]. This array is filled with the created Anys which contain the parameters |
1501 |
// and the values contained in the parameter array |
1502 |
LocalBuilder localAnyParams = ilGen.DeclareLocal (typeof (uno.Any [])); |
1503 |
|
1504 |
// Create the Any for every argument, except for the parameter array |
1505 |
// arLocalAny contains the LocalBuilder for all these parameters. |
1506 |
// we call the ctor Any(Type, Object) |
1507 |
// If the parameter is an Any then the Any is created with Any(param.Type, param.Value); |
1508 |
Type[] typesCtorAny = { typeof (Type), |
1509 |
typeof (object) }; |
1510 |
ConstructorInfo ctorAny = typeof (uno.Any).GetConstructor (typesCtorAny); |
1511 |
MethodInfo methodAnyGetType = typeof (uno.Any).GetProperty ("Type").GetGetMethod (); |
1512 |
MethodInfo methodAnyGetValue = typeof (uno.Any).GetProperty ("Value").GetGetMethod (); |
1513 |
|
1514 |
for (j = 0; j < localAny.Length; j ++) { |
1515 |
//check if the parameter is a polymorphic struct |
1516 |
if (typeParameters [j + 1] is uno.PolymorphicType) { |
1517 |
// It is a polymorphic struct |
1518 |
uno.PolymorphicType polyType = typeParameters [j + 1] as uno.PolymorphicType; |
1519 |
|
1520 |
// Load the uninitialized local Any on which we will call the ctor |
1521 |
ilGen.Emit (OpCodes.Ldloca, localAny [j]); |
1522 |
|
1523 |
// Call PolymorphicType PolymorphicType::GetType(Type t, String polyName) |
1524 |
// Prepare the first parameter |
1525 |
ilGen.Emit (OpCodes.Ldtoken, polyType.OriginalType); |
1526 |
Type[] typeParams = { typeof (System.RuntimeTypeHandle) }; |
1527 |
ilGen.Emit (OpCodes.Call, typeof(Type).GetMethod ("GetTypeFromHandle", typeParams)); |
1528 |
|
1529 |
// Prepare the second parameter |
1530 |
ilGen.Emit (OpCodes.Ldstr, polyType.PolymorphicName); |
1531 |
|
1532 |
// Make the actual call |
1533 |
Type[] typeParamGetType = { typeof (Type), typeof (string) }; |
1534 |
ilGen.Emit (OpCodes.Call, |
1535 |
typeof (uno.PolymorphicType).GetMethod("GetType", |
1536 |
typeParamGetType)); |
1537 |
|
1538 |
// Stack is: localAny, PolymorphicType |
1539 |
// Call Any::Any(Type, Object) |
1540 |
// Prepare the second parameter for the any ctor |
1541 |
ilGen.Emit (OpCodes.Ldarg, j + 1); |
1542 |
|
1543 |
// if the parameter is a value type then we need to box it, because |
1544 |
// the Any ctor takes an Object |
1545 |
if (typeParameters [j + 1].IsValueType) |
1546 |
ilGen.Emit (OpCodes.Box, typeParameters [j + 1]); |
1547 |
ilGen.Emit (OpCodes.Call, ctorAny); |
1548 |
} else if (typeParameters [j + 1] == typeof (uno.Any)) { |
1549 |
// Create the call new Any(param.Type,param,Value) |
1550 |
// Stack must be Any,Type,Value |
1551 |
// First load the Any which is to be constructed |
1552 |
ilGen.Emit (OpCodes.Ldloca, localAny [j]); |
1553 |
|
1554 |
//Load the Type, which is obtained by calling param.Type |
1555 |
ilGen.Emit (OpCodes.Ldarga, j + 1); |
1556 |
ilGen.Emit (OpCodes.Call, methodAnyGetType); |
1557 |
|
1558 |
//Load the Value, which is obtained by calling param.Value |
1559 |
ilGen.Emit (OpCodes.Ldarga, j + 1); |
1560 |
ilGen.Emit (OpCodes.Call, methodAnyGetValue); |
1561 |
|
1562 |
//Call the Any ctor. |
1563 |
ilGen.Emit (OpCodes.Call, ctorAny); |
1564 |
} else { |
1565 |
ilGen.Emit (OpCodes.Ldloca, localAny [j]); |
1566 |
ilGen.Emit (OpCodes.Ldtoken, typeParameters [j + 1]); |
1567 |
|
1568 |
Type[] typeParams = { typeof (System.RuntimeTypeHandle) }; |
1569 |
ilGen.Emit (OpCodes.Call, typeof (Type).GetMethod ("GetTypeFromHandle", typeParams)); |
1570 |
ilGen.Emit(OpCodes.Ldarg, j + 1); |
1571 |
|
1572 |
// if the parameter is a value type then we need to box it, because |
1573 |
// the Any ctor takes an Object |
1574 |
if (typeParameters [j + 1].IsValueType) |
1575 |
ilGen.Emit (OpCodes.Box, typeParameters [j + 1]); |
1576 |
ilGen.Emit(OpCodes.Call, ctorAny); |
1577 |
} |
1578 |
} |
1579 |
|
1580 |
|
1581 |
// Create the Any[] that is passed to the |
1582 |
// createInstanceWithContext[AndArguments] function |
1583 |
ilGen.Emit (OpCodes.Ldc_I4, localAny.Length); |
1584 |
ilGen.Emit (OpCodes.Newarr, typeof (uno.Any)); |
1585 |
ilGen.Emit (OpCodes.Stloc, localAnyParams); |
1586 |
|
1587 |
// Assign all anys created from the parameters |
1588 |
// array to the Any[] |
1589 |
for (j = 0; j < localAny.Length; j ++) { |
1590 |
ilGen.Emit (OpCodes.Ldloc, localAnyParams); |
1591 |
ilGen.Emit (OpCodes.Ldc_I4, j); |
1592 |
ilGen.Emit (OpCodes.Ldelema, typeof (uno.Any)); |
1593 |
ilGen.Emit (OpCodes.Ldloc, localAny [j]); |
1594 |
ilGen.Emit (OpCodes.Stobj, typeof (uno.Any)); |
1595 |
} |
1596 |
|
1597 |
// call createInstanceWithContextAndArguments |
1598 |
ilGen.Emit (OpCodes.Ldloc, localFactory); |
1599 |
ilGen.Emit (OpCodes.Ldstr, entry.mType.Name); |
1600 |
ilGen.Emit (OpCodes.Ldloc, localAnyParams); |
1601 |
ilGen.Emit (OpCodes.Ldarg_0); |
1602 |
MethodInfo methodCreate = localFactory.LocalType.GetMethod ("createInstanceWithArgumentsAndContext"); |
1603 |
ilGen.Emit (OpCodes.Callvirt, methodCreate); |
1604 |
} |
1605 |
|
1606 |
// cast the object returned by the functions createInstanceWithContext or |
1607 |
// createInstanceWithArgumentsAndContext to the interface type |
1608 |
ilGen.Emit (OpCodes.Castclass, ret); |
1609 |
ilGen.Emit (OpCodes.Stloc, localReturnVal); |
1610 |
|
1611 |
//catch exceptions thrown by createInstanceWithArgumentsAndContext and createInstanceWithContext |
1612 |
if (!exceptionTypes.Contains (typeUnoException)) { |
1613 |
// catch (unoidl.com.sun.star.uno.RuntimeException) {throw;} |
1614 |
ilGen.BeginCatchBlock (GetType ("unoidl.com.sun.star.uno.RuntimeException", true)); |
1615 |
ilGen.Emit (OpCodes.Pop); |
1616 |
ilGen.Emit (OpCodes.Rethrow); |
1617 |
|
1618 |
//catch and rethrow all other defined Exceptions |
1619 |
for (j = 0; j < exceptionTypes.Count; j ++) { |
1620 |
Type excType = exceptionTypes [j] as Type; |
1621 |
if (excType.IsInstanceOfType (GetType ("unoidl.com.sun.star.uno.RuntimeException", true))) { |
1622 |
// we have a catch for RuntimeException already defined |
1623 |
continue; |
1624 |
} |
1625 |
|
1626 |
//catch Exception and rethrow |
1627 |
ilGen.BeginCatchBlock (excType); |
1628 |
ilGen.Emit (OpCodes.Pop); |
1629 |
ilGen.Emit (OpCodes.Rethrow); |
1630 |
} |
1631 |
|
1632 |
//catch (unoidl.com.sun.star.uno.Exception) {throw DeploymentException...} |
1633 |
ilGen.BeginCatchBlock (typeUnoException); |
1634 |
|
1635 |
//Define the local variabe that keeps the exception |
1636 |
LocalBuilder localException = ilGen.DeclareLocal (typeUnoException); |
1637 |
|
1638 |
//Store the exception |
1639 |
ilGen.Emit (OpCodes.Stloc, localException); |
1640 |
|
1641 |
//prepare the construction of the exception |
1642 |
strBuilder = new System.Text.StringBuilder (256); |
1643 |
strBuilder.Append ("The context (com.sun.star.uno.XComponentContext) failed to supply the service "); |
1644 |
strBuilder.Append ("unoidl." + entry.mType.Name); |
1645 |
strBuilder.Append (": "); |
1646 |
|
1647 |
ilGen.Emit (OpCodes.Ldstr, strBuilder.ToString()); |
1648 |
|
1649 |
// add to the string the Exception.Message |
1650 |
ilGen.Emit (OpCodes.Ldloc, localException); |
1651 |
//Console.WriteLine ("get message property of type: {0}", typeUnoException); |
1652 |
ilGen.Emit (OpCodes.Callvirt, typeUnoException.GetProperty ("Message").GetGetMethod ()); |
1653 |
Type[] concatParams = { typeof (string), typeof (string)}; |
1654 |
ilGen.Emit (OpCodes.Call, typeof (string).GetMethod ("Concat", concatParams)); |
1655 |
|
1656 |
//load contex argument |
1657 |
ilGen.Emit (OpCodes.Ldarg_0); |
1658 |
ilGen.Emit (OpCodes.Newobj, ctorDeploymentException); |
1659 |
ilGen.Emit (OpCodes.Throw); //Exception(typeDeploymentExc); |
1660 |
|
1661 |
ilGen.EndExceptionBlock(); |
1662 |
} |
1663 |
|
1664 |
|
1665 |
// Check if the service instance was create and throw a exception if not. |
1666 |
Label labelServiceCreated = ilGen.DefineLabel (); |
1667 |
ilGen.Emit (OpCodes.Ldloc, localReturnVal); |
1668 |
ilGen.Emit (OpCodes.Brtrue_S, labelServiceCreated); |
1669 |
|
1670 |
strBuilder = new System.Text.StringBuilder(256); |
1671 |
strBuilder.Append ("The context (com.sun.star.uno.XComponentContext) failed to supply the service "); |
1672 |
strBuilder.Append ("unoidl." + entry.mType.Name); |
1673 |
strBuilder.Append ("."); |
1674 |
ilGen.Emit (OpCodes.Ldstr, strBuilder.ToString()); |
1675 |
ilGen.Emit (OpCodes.Ldarg_0); |
1676 |
ilGen.Emit (OpCodes.Newobj, ctorDeploymentException); |
1677 |
ilGen.Emit (OpCodes.Throw); //Exception(typeDeploymentExc); |
1678 |
|
1679 |
ilGen.MarkLabel (labelServiceCreated); |
1680 |
ilGen.Emit (OpCodes.Ldloc, localReturnVal); |
1681 |
ilGen.Emit (OpCodes.Ret); |
1682 |
} |
1683 |
|
1684 |
mIncompleteServices.Remove (entry.mTypeBuilder.FullName); |
1685 |
|
1686 |
if (mConfig.mVerbose) |
1687 |
Console.WriteLine("> emitting service type {0}", "unoidl." + entry.mType.Name); |
1688 |
|
1689 |
//Console.WriteLine ("completed service {0}", entry.mTypeBuilder.FullName); |
1690 |
|
1691 |
return entry.mTypeBuilder.CreateType (); |
1692 |
} |
1693 |
|
1694 |
Type CompleteSingletonType (SingletonEntry entry) |
1695 |
{ |
1696 |
string name = "unoidl." + entry.mType.Name; |
1697 |
|
1698 |
// Create the private default constructor |
1699 |
ConstructorBuilder ctorBuilder = entry.mTypeBuilder.DefineConstructor (MethodAttributes.Private | |
1700 |
MethodAttributes.HideBySig | |
1701 |
MethodAttributes.SpecialName | |
1702 |
MethodAttributes.RTSpecialName, |
1703 |
CallingConventions.Standard, null); |
1704 |
|
1705 |
ILGenerator ilGen = ctorBuilder.GetILGenerator (); |
1706 |
ilGen.Emit (OpCodes.Ldarg_0); // push this |
1707 |
ilGen.Emit (OpCodes.Call, entry.mTypeBuilder.BaseType.GetConstructor (new Type [0])); |
1708 |
ilGen.Emit (OpCodes.Ret); |
1709 |
|
1710 |
// obtain the interface which makes up this service, it is the return |
1711 |
// type of the constructor functions |
1712 |
UnoXTypeDescription ifaceTD = entry.mType.Interface; |
1713 |
if (!(ifaceTD is UnoXInterfaceTypeDescription)) |
1714 |
ifaceTD = ResolveInterfaceTypedef (ifaceTD); |
1715 |
Type retType = GetType (ifaceTD); |
1716 |
|
1717 |
//define method |
1718 |
Type[] typeParameters = { GetType ("unoidl.com.sun.star.uno.XComponentContext", true) }; |
1719 |
MethodBuilder methodBuilder = entry.mTypeBuilder.DefineMethod ("get", MethodAttributes.Public | |
1720 |
MethodAttributes.HideBySig | |
1721 |
MethodAttributes.Static, |
1722 |
retType, |
1723 |
typeParameters); |
1724 |
|
1725 |
// The first parameter is the XComponentContext, which cannot be obtained |
1726 |
// from reflection. |
1727 |
// The context is not part of the idl description |
1728 |
methodBuilder.DefineParameter (1, ParameterAttributes.In, "the_context"); |
1729 |
|
1730 |
ilGen = methodBuilder.GetILGenerator(); |
1731 |
// Define locals --------------------------------- |
1732 |
// Any, returned by XComponentContext.getValueByName |
1733 |
LocalBuilder localAny = ilGen.DeclareLocal (typeof (uno.Any)); |
1734 |
|
1735 |
// Call XContext.getValueByName |
1736 |
ilGen.Emit (OpCodes.Ldarg_0); |
1737 |
|
1738 |
// build the singleton name : /singleton/unoidl.com.sun.star.XXX |
1739 |
ilGen.Emit(OpCodes.Ldstr, "/singletons/" + name); |
1740 |
|
1741 |
MethodInfo methodGetValueByName = GetType ("unoidl.com.sun.star.uno.XComponentContext", true).GetMethod ("getValueByName"); |
1742 |
ilGen.Emit(OpCodes.Callvirt, methodGetValueByName); |
1743 |
ilGen.Emit(OpCodes.Stloc_0); |
1744 |
|
1745 |
//Contains the returned Any a value? |
1746 |
ilGen.Emit(OpCodes.Ldloca_S, localAny); |
1747 |
MethodInfo methodHasValue = typeof (uno.Any).GetMethod ("hasValue"); |
1748 |
ilGen.Emit (OpCodes.Call, methodHasValue); |
1749 |
|
1750 |
//If not, then throw an DeploymentException |
1751 |
Label labelSingletonExists = ilGen.DefineLabel (); |
1752 |
ilGen.Emit (OpCodes.Brtrue_S, labelSingletonExists); |
1753 |
ilGen.Emit (OpCodes.Ldstr, "Component context fails to supply singleton " + name + " of type " + retType.FullName + "."); |
1754 |
ilGen.Emit (OpCodes.Ldarg_0); |
1755 |
Type[] typesCtorDeploymentException = { typeof (string), typeof (object) }; |
1756 |
ilGen.Emit (OpCodes.Newobj, GetType ("unoidl.com.sun.star.uno.DeploymentException", true).GetConstructor (typesCtorDeploymentException)); |
1757 |
ilGen.Emit (OpCodes.Throw); |
1758 |
ilGen.MarkLabel (labelSingletonExists); |
1759 |
|
1760 |
//Cast the singleton contained in the Any to the expected interface and return it. |
1761 |
ilGen.Emit (OpCodes.Ldloca_S, localAny); |
1762 |
ilGen.Emit (OpCodes.Call, typeof (uno.Any).GetProperty ("Value").GetGetMethod ()); |
1763 |
ilGen.Emit (OpCodes.Castclass, retType); |
1764 |
ilGen.Emit (OpCodes.Ret); |
1765 |
|
1766 |
if (mConfig.mVerbose) |
1767 |
Console.WriteLine ("> emitting singleton type {0}", name); |
1768 |
|
1769 |
mIncompleteSingletons.Remove (entry.mTypeBuilder.FullName); |
1770 |
|
1771 |
//Console.WriteLine ("completed singleton {0}", entry.mTypeBuilder.FullName); |
1772 |
|
1773 |
return entry.mTypeBuilder.CreateType (); |
1774 |
} |
1775 |
|
1776 |
public void Dispose () |
1777 |
{ |
1778 |
while (mIncompleteIFaces.Count > 0) { |
1779 |
IDictionaryEnumerator e = mIncompleteIFaces.GetEnumerator (); |
1780 |
e.MoveNext (); |
1781 |
CompleteIFaceType (e.Value as IFaceEntry); |
1782 |
} |
1783 |
|
1784 |
while (mIncompleteServices.Count > 0) { |
1785 |
IDictionaryEnumerator e = mIncompleteServices.GetEnumerator (); |
1786 |
e.MoveNext (); |
1787 |
CompleteServiceType (e.Value as ServiceEntry); |
1788 |
} |
1789 |
|
1790 |
while (mIncompleteSingletons.Count > 0) { |
1791 |
IDictionaryEnumerator e = mIncompleteSingletons.GetEnumerator (); |
1792 |
e.MoveNext (); |
1793 |
CompleteSingletonType (e.Value as SingletonEntry); |
1794 |
} |
1795 |
} |
1796 |
} |
1797 |
|
1798 |
class Config |
1799 |
{ |
1800 |
public ArrayList mMandatoryRegistries = new ArrayList (); |
1801 |
public ArrayList mExplicitTypes = new ArrayList (); |
1802 |
public ArrayList mExtraAssemblies = new ArrayList (); |
1803 |
public ArrayList mExtraRegistries = new ArrayList (); |
1804 |
public bool mVerbose = false; |
1805 |
public string |
1806 |
mOutput = null, |
1807 |
mVersion = null, |
1808 |
mDescription = null, |
1809 |
mProduct = null, |
1810 |
mCompany = null, |
1811 |
mCopyright = null, |
1812 |
mTrademark = null, |
1813 |
mKeyfile = null, |
1814 |
mDelaySign = null; |
1815 |
} |
1816 |
|
1817 |
class CliMaker |
1818 |
{ |
1819 |
IntPtr mUnoHelper; |
1820 |
|
1821 |
// string mOutputDir = "./"; |
1822 |
// string mOutputFile = "cli_types.dll"; |
1823 |
// string mName = "cli_types"; |
1824 |
|
1825 |
string mOutputDir; |
1826 |
string mOutputFile; |
1827 |
string mName; |
1828 |
|
1829 |
Config mConfig; |
1830 |
|
1831 |
AssemblyBuilder mAssemblyBuilder; |
1832 |
ResolveEventHandler mTypeResolver = null; |
1833 |
|
1834 |
public CliMaker (Config config) |
1835 |
{ |
1836 |
mConfig = config; |
1837 |
mUnoHelper = cmm_uno_helper_new (); |
1838 |
} |
1839 |
|
1840 |
~CliMaker () |
1841 |
{ |
1842 |
cmm_uno_helper_delete (mUnoHelper); |
1843 |
} |
1844 |
|
1845 |
public void OpenRegistries () |
1846 |
{ |
1847 |
if (mConfig.mExplicitTypes.Count > 0) |
1848 |
foreach (string typeName in mConfig.mExplicitTypes) |
1849 |
cmm_uno_helper_add_explicit_type (mUnoHelper, typeName); |
1850 |
|
1851 |
foreach (string registry in mConfig.mMandatoryRegistries) |
1852 |
cmm_uno_helper_add_mandatory_registry (mUnoHelper, registry); |
1853 |
|
1854 |
foreach (string registry in mConfig.mExtraRegistries) |
1855 |
cmm_uno_helper_add_extra_registry (mUnoHelper, registry); |
1856 |
|
1857 |
cmm_uno_helper_open_registries (mUnoHelper); |
1858 |
} |
1859 |
|
1860 |
public void PrepareAssembly () |
1861 |
{ |
1862 |
// Get the key pair for making a strong name |
1863 |
StrongNameKeyPair kp = null; |
1864 |
if (mConfig.mKeyfile != null) { |
1865 |
try { |
1866 |
System.IO.FileStream fs = new System.IO.FileStream (mConfig.mKeyfile, System.IO.FileMode.Open); |
1867 |
kp = new StrongNameKeyPair (fs); |
1868 |
fs.Close (); |
1869 |
} catch (System.IO.FileNotFoundException) { |
1870 |
throw new Exception ("Could not find the keyfile. Verify the --keyfile argument!"); |
1871 |
} |
1872 |
} else { |
1873 |
if (mConfig.mVerbose) |
1874 |
Console.WriteLine ("> no key file specified. Cannot create strong name!"); |
1875 |
} |
1876 |
|
1877 |
mOutputFile = System.IO.Path.GetFileName (mConfig.mOutput); |
1878 |
mOutputDir = System.IO.Path.GetDirectoryName (mConfig.mOutput); |
1879 |
mName = System.IO.Path.GetFileNameWithoutExtension (mConfig.mOutput); |
1880 |
// int idx = mOutputFile.LastIndexOf (System.IO.Path.DirectorySeparatorChar); |
1881 |
// if (idx >= 0) |
1882 |
// mOutputDir = mOutputFile.Substring (0, idx); |
1883 |
// else |
1884 |
// mOutputDir = System.IO.Path.CurrentDirectory; |
1885 |
// idx = mOutputFile.LastIndexOf (".dll"); |
1886 |
// mName = mOutputFile.Substring (0, idx); |
1887 |
//Console.WriteLine ("file {0}\ndir {1}\nname {2}", mOutputFile, mOutputDir, mName); |
1888 |
|
1889 |
// setup assembly info: xxx todo set more? e.g. avoid strong versioning |
1890 |
AssemblyName assemblyName = new AssemblyName(); |
1891 |
assemblyName.CodeBase = mOutputDir; |
1892 |
assemblyName.Name = mName; |
1893 |
|
1894 |
if (kp != null) |
1895 |
assemblyName.KeyPair = kp; |
1896 |
|
1897 |
if (mConfig.mVersion != null) |
1898 |
assemblyName.Version = new System.Version (mConfig.mVersion); |
1899 |
|
1900 |
// target assembly |
1901 |
mAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.Save, mOutputDir); |
1902 |
|
1903 |
if (mConfig.mProduct != null) { |
1904 |
Type[] paramTypes = { typeof (string) }; |
1905 |
object[] args = { mConfig.mProduct }; |
1906 |
mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyProductAttribute).GetConstructor (paramTypes), args)); |
1907 |
} |
1908 |
|
1909 |
if (mConfig.mDescription != null) { |
1910 |
Type[] paramTypes = { typeof (string) }; |
1911 |
object[] args = { mConfig.mDescription }; |
1912 |
mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyDescriptionAttribute).GetConstructor (paramTypes), args)); |
1913 |
} |
1914 |
|
1915 |
if (mConfig.mCompany != null) { |
1916 |
Type[] paramTypes = { typeof (string) }; |
1917 |
object[] args = { mConfig.mCompany }; |
1918 |
mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyCompanyAttribute).GetConstructor (paramTypes), args)); |
1919 |
} |
1920 |
|
1921 |
if (mConfig.mCopyright != null) { |
1922 |
Type[] paramTypes = { typeof (string) }; |
1923 |
object[] args = { mConfig.mCopyright }; |
1924 |
mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyCopyrightAttribute).GetConstructor (paramTypes), args)); |
1925 |
} |
1926 |
|
1927 |
if (mConfig.mTrademark != null) { |
1928 |
Type[] paramTypes = { typeof (string) }; |
1929 |
object[] args = { mConfig.mTrademark }; |
1930 |
mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyTrademarkAttribute).GetConstructor (paramTypes), args)); |
1931 |
} |
1932 |
} |
1933 |
|
1934 |
public UnoXTypeDescription NextType () |
1935 |
{ |
1936 |
IntPtr handle = cmm_uno_helper_next_type (mUnoHelper); |
1937 |
|
1938 |
if (handle != IntPtr.Zero) { |
1939 |
return UnoXTypeDescription.Create (handle); |
1940 |
} |
1941 |
|
1942 |
return null; |
1943 |
} |
1944 |
|
1945 |
public void Emit () |
1946 |
{ |
1947 |
TypeEmitter mTypeEmitter = new TypeEmitter (mConfig, mAssemblyBuilder.DefineDynamicModule( mOutputFile )); |
1948 |
|
1949 |
AppDomain.CurrentDomain.TypeResolve += mTypeEmitter.ResolveEventHandler; |
1950 |
|
1951 |
UnoXTypeDescription type; |
1952 |
|
1953 |
while ((type = NextType ()) != null) |
1954 |
mTypeEmitter.GetType (type); |
1955 |
|
1956 |
mTypeEmitter.Dispose (); |
1957 |
} |
1958 |
|
1959 |
public void Save () |
1960 |
{ |
1961 |
if (mConfig.mVerbose) |
1962 |
Console.Write ("> saving assembly {0}{1}{2}...", |
1963 |
mOutputDir, |
1964 |
System.IO.Path.DirectorySeparatorChar, |
1965 |
mOutputFile); |
1966 |
|
1967 |
mAssemblyBuilder.Save (mOutputFile); |
1968 |
|
1969 |
if (mConfig.mVerbose) |
1970 |
Console.WriteLine ("ok."); |
1971 |
|
1972 |
AppDomain.CurrentDomain.TypeResolve -= mTypeResolver; |
1973 |
} |
1974 |
|
1975 |
[DllImport("climaker")] |
1976 |
private static extern IntPtr cmm_uno_helper_new (); |
1977 |
|
1978 |
[DllImport("climaker")] |
1979 |
private static extern void cmm_uno_helper_delete (IntPtr handle); |
1980 |
|
1981 |
[DllImport("climaker")] |
1982 |
private static extern void cmm_uno_helper_add_mandatory_registry (IntPtr handle, string registry); |
1983 |
|
1984 |
[DllImport("climaker")] |
1985 |
private static extern void cmm_uno_helper_add_extra_registry (IntPtr handle, string registry); |
1986 |
|
1987 |
[DllImport("climaker")] |
1988 |
private static extern void cmm_uno_helper_add_explicit_type (IntPtr handle, string typeName); |
1989 |
|
1990 |
[DllImport("climaker")] |
1991 |
private static extern void cmm_uno_helper_open_registries (IntPtr handle); |
1992 |
|
1993 |
[DllImport("climaker")] |
1994 |
private static extern IntPtr cmm_uno_helper_next_type (IntPtr handle); |
1995 |
} |
1996 |
|
1997 |
class UnoObject |
1998 |
{ |
1999 |
protected IntPtr mHandle; |
2000 |
|
2001 |
protected UnoObject (IntPtr handle) |
2002 |
{ |
2003 |
mHandle = handle; |
2004 |
} |
2005 |
|
2006 |
public IntPtr Handle |
2007 |
{ |
2008 |
get |
2009 |
{ |
2010 |
return mHandle; |
2011 |
} |
2012 |
} |
2013 |
} |
2014 |
|
2015 |
class UnoXTypeDescription : UnoObject |
2016 |
{ |
2017 |
protected UnoXTypeDescription (IntPtr handle) : base (handle) |
2018 |
{ |
2019 |
} |
2020 |
|
2021 |
public static UnoXTypeDescription Create (IntPtr handle) |
2022 |
{ |
2023 |
//Console.WriteLine ("Create {0}", handle); |
2024 |
if (handle == IntPtr.Zero) |
2025 |
return null; |
2026 |
|
2027 |
UnoTypeClass tc = cmm_x_type_description_get_type_class (handle); |
2028 |
switch (tc) { |
2029 |
case UnoTypeClass.Enum: |
2030 |
return new UnoXEnumTypeDescription (handle); |
2031 |
case UnoTypeClass.Interface: |
2032 |
return new UnoXInterfaceTypeDescription (handle); |
2033 |
case UnoTypeClass.Struct: |
2034 |
return new UnoXStructTypeDescription (handle); |
2035 |
case UnoTypeClass.Exception: |
2036 |
return new UnoXExceptionTypeDescription (handle); |
2037 |
case UnoTypeClass.Sequence: |
2038 |
case UnoTypeClass.Typedef: |
2039 |
return new UnoXIndirectTypeDescription (handle); |
2040 |
case UnoTypeClass.Constant: |
2041 |
return new UnoXConstantTypeDescription (handle); |
2042 |
case UnoTypeClass.Constants: |
2043 |
return new UnoXConstantsTypeDescription (handle); |
2044 |
case UnoTypeClass.Service: |
2045 |
return new UnoXServiceTypeDescription (handle); |
2046 |
case UnoTypeClass.Singleton: |
2047 |
return new UnoXSingletonTypeDescription (handle); |
2048 |
} |
2049 |
|
2050 |
//Console.WriteLine ("unknown type {0}", tc); |
2051 |
|
2052 |
return new UnoXTypeDescription (handle); |
2053 |
} |
2054 |
|
2055 |
public string Name |
2056 |
{ |
2057 |
get |
2058 |
{ |
2059 |
return Marshal.PtrToStringAnsi (cmm_x_type_description_get_name (mHandle)); |
2060 |
} |
2061 |
} |
2062 |
|
2063 |
public UnoTypeClass TypeClass |
2064 |
{ |
2065 |
get |
2066 |
{ |
2067 |
return cmm_x_type_description_get_type_class (mHandle); |
2068 |
} |
2069 |
} |
2070 |
|
2071 |
[DllImport("climaker")] |
2072 |
private static extern IntPtr cmm_x_type_description_get_name (IntPtr handle); |
2073 |
|
2074 |
[DllImport("climaker")] |
2075 |
private static extern UnoTypeClass cmm_x_type_description_get_type_class (IntPtr handle); |
2076 |
} |
2077 |
|
2078 |
class UnoXEnumTypeDescription : UnoXTypeDescription |
2079 |
{ |
2080 |
public UnoXEnumTypeDescription (IntPtr mHandle) : base (mHandle) |
2081 |
{ |
2082 |
} |
2083 |
|
2084 |
public int Length |
2085 |
{ |
2086 |
get |
2087 |
{ |
2088 |
return cmm_x_enum_type_description_get_length (mHandle); |
2089 |
} |
2090 |
} |
2091 |
|
2092 |
public string ValueName (int idx) |
2093 |
{ |
2094 |
return Marshal.PtrToStringAnsi (cmm_x_enum_type_description_get_name (mHandle, idx)); |
2095 |
} |
2096 |
|
2097 |
public int Value (int idx) |
2098 |
{ |
2099 |
return cmm_x_enum_type_description_get_value (mHandle, idx); |
2100 |
} |
2101 |
|
2102 |
[DllImport("climaker")] |
2103 |
private static extern int cmm_x_enum_type_description_get_length (IntPtr handle); |
2104 |
|
2105 |
[DllImport("climaker")] |
2106 |
private static extern int cmm_x_enum_type_description_get_value (IntPtr handle, int idx); |
2107 |
|
2108 |
[DllImport("climaker")] |
2109 |
private static extern IntPtr cmm_x_enum_type_description_get_name (IntPtr handle, int idx); |
2110 |
} |
2111 |
|
2112 |
class UnoXInterfaceTypeDescription : UnoXTypeDescription |
2113 |
{ |
2114 |
int mMembers = 0; |
2115 |
IntPtr mMembersHandle = IntPtr.Zero; |
2116 |
|
2117 |
public UnoXInterfaceTypeDescription (IntPtr mHandle) : base (mHandle) |
2118 |
{ |
2119 |
} |
2120 |
|
2121 |
public int BaseTypes |
2122 |
{ |
2123 |
get |
2124 |
{ |
2125 |
return cmm_x_interface_type_description_get_length (mHandle); |
2126 |
} |
2127 |
} |
2128 |
|
2129 |
public UnoXInterfaceTypeDescription BaseType (int idx) |
2130 |
{ |
2131 |
return new UnoXInterfaceTypeDescription (cmm_x_interface_type_description_get_base_type (mHandle, idx)); |
2132 |
} |
2133 |
|
2134 |
void AssureMembers () |
2135 |
{ |
2136 |
if (mMembersHandle == IntPtr.Zero) |
2137 |
mMembers = cmm_x_interface_type_description_get_members (mHandle, out mMembersHandle); |
2138 |
} |
2139 |
|
2140 |
public int Members |
2141 |
{ |
2142 |
get |
2143 |
{ |
2144 |
AssureMembers (); |
2145 |
|
2146 |
return mMembers; |
2147 |
} |
2148 |
} |
2149 |
|
2150 |
public UnoXInterfaceMemberTypeDescription Member (int idx) |
2151 |
{ |
2152 |
AssureMembers (); |
2153 |
|
2154 |
if (idx < 0 || idx >= mMembers) |
2155 |
return null; |
2156 |
|
2157 |
return new UnoXInterfaceMemberTypeDescription (cmm_x_interface_type_description_get_member (mMembersHandle, idx)); |
2158 |
} |
2159 |
|
2160 |
[DllImport("climaker")] |
2161 |
private static extern int cmm_x_interface_type_description_get_length (IntPtr handle); |
2162 |
|
2163 |
[DllImport("climaker")] |
2164 |
private static extern IntPtr cmm_x_interface_type_description_get_base_type (IntPtr handle, int idx); |
2165 |
|
2166 |
[DllImport("climaker")] |
2167 |
private static extern int cmm_x_interface_type_description_get_members (IntPtr handle, out IntPtr membersHandle); |
2168 |
|
2169 |
[DllImport("climaker")] |
2170 |
private static extern IntPtr cmm_x_interface_type_description_get_member (IntPtr membersArrayHandle, int idx); |
2171 |
} |
2172 |
|
2173 |
class UnoXInterfaceMemberTypeDescription : UnoXTypeDescription |
2174 |
{ |
2175 |
public UnoXInterfaceMemberTypeDescription (IntPtr handle) : base (handle) |
2176 |
{ |
2177 |
} |
2178 |
|
2179 |
public string MemberName |
2180 |
{ |
2181 |
get |
2182 |
{ |
2183 |
return Marshal.PtrToStringAnsi (cmm_x_interface_member_type_description_get_member_name (mHandle)); |
2184 |
} |
2185 |
} |
2186 |
|
2187 |
[DllImport("climaker")] |
2188 |
private static extern IntPtr cmm_x_interface_member_type_description_get_member_name (IntPtr handle); |
2189 |
} |
2190 |
|
2191 |
class UnoXInterfaceAttributeTypeDescription : UnoXInterfaceMemberTypeDescription |
2192 |
{ |
2193 |
public UnoXInterfaceAttributeTypeDescription (IntPtr handle) : base (handle) |
2194 |
{ |
2195 |
} |
2196 |
|
2197 |
public UnoXTypeDescription Type |
2198 |
{ |
2199 |
get |
2200 |
{ |
2201 |
return UnoXTypeDescription.Create (cmm_x_interface_attribute_type_description_get_type (mHandle)); |
2202 |
} |
2203 |
} |
2204 |
|
2205 |
public bool IsBound |
2206 |
{ |
2207 |
get |
2208 |
{ |
2209 |
return cmm_x_interface_attribute_type_description_is_bound (mHandle); |
2210 |
} |
2211 |
} |
2212 |
|
2213 |
public bool IsReadOnly |
2214 |
{ |
2215 |
get |
2216 |
{ |
2217 |
return cmm_x_interface_attribute_type_description_is_read_only (mHandle); |
2218 |
} |
2219 |
} |
2220 |
|
2221 |
UnoXTypeDescription[] ExceptionTypes (IntPtr handle, int count) |
2222 |
{ |
2223 |
int i; |
2224 |
|
2225 |
UnoXTypeDescription[] types = new UnoXTypeDescription [count]; |
2226 |
for (i = 0; i < count; i ++) { |
2227 |
types [i] = UnoXTypeDescription.Create (cmm_x_interface_attribute_type_description_get_exception_type (handle, i)); |
2228 |
} |
2229 |
|
2230 |
return types; |
2231 |
} |
2232 |
|
2233 |
public UnoXTypeDescription[] GetExceptionTypes |
2234 |
{ |
2235 |
get |
2236 |
{ |
2237 |
IntPtr handle; |
2238 |
int count; |
2239 |
|
2240 |
count = cmm_x_interface_attribute_type_description_get_get_exception_types (mHandle, out handle); |
2241 |
UnoXTypeDescription[] types = ExceptionTypes (handle, count); |
2242 |
|
2243 |
if (count > 0) |
2244 |
cmm_x_interface_attribute_type_description_free_exception_types (handle, count); |
2245 |
|
2246 |
return types; |
2247 |
} |
2248 |
} |
2249 |
|
2250 |
public UnoXTypeDescription[] SetExceptionTypes |
2251 |
{ |
2252 |
get |
2253 |
{ |
2254 |
IntPtr handle; |
2255 |
int count; |
2256 |
|
2257 |
count = cmm_x_interface_attribute_type_description_get_set_exception_types (mHandle, out handle); |
2258 |
UnoXTypeDescription[] types = ExceptionTypes (handle, count); |
2259 |
|
2260 |
if (count > 0) |
2261 |
cmm_x_interface_attribute_type_description_free_exception_types (handle, count); |
2262 |
|
2263 |
return types; |
2264 |
} |
2265 |
} |
2266 |
|
2267 |
[DllImport("climaker")] |
2268 |
private static extern IntPtr cmm_x_interface_attribute_type_description_get_type (IntPtr handle); |
2269 |
|
2270 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2271 |
private static extern bool cmm_x_interface_attribute_type_description_is_bound (IntPtr handle); |
2272 |
|
2273 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2274 |
private static extern bool cmm_x_interface_attribute_type_description_is_read_only (IntPtr handle); |
2275 |
|
2276 |
[DllImport("climaker")] |
2277 |
private static extern int cmm_x_interface_attribute_type_description_get_get_exception_types (IntPtr handle, out IntPtr exceptionTypesHandle); |
2278 |
|
2279 |
[DllImport("climaker")] |
2280 |
private static extern int cmm_x_interface_attribute_type_description_get_set_exception_types (IntPtr handle, out IntPtr exceptionTypesHandle); |
2281 |
|
2282 |
[DllImport("climaker")] |
2283 |
private static extern IntPtr cmm_x_interface_attribute_type_description_get_exception_type (IntPtr handle, int index); |
2284 |
|
2285 |
[DllImport("climaker")] |
2286 |
private static extern void cmm_x_interface_attribute_type_description_free_exception_types (IntPtr handle, int count); |
2287 |
} |
2288 |
|
2289 |
class UnoXInterfaceMethodTypeDescription : UnoXInterfaceMemberTypeDescription |
2290 |
{ |
2291 |
int mParameters = 0; |
2292 |
IntPtr mParametersHandle = IntPtr.Zero; |
2293 |
IntPtr mParametersArrayHandle = IntPtr.Zero; |
2294 |
|
2295 |
bool mGotExceptionTypes = false; |
2296 |
int mExceptionTypes = 0; |
2297 |
IntPtr mExceptionTypesHandle = IntPtr.Zero; |
2298 |
IntPtr mExceptionTypesArrayHandle = IntPtr.Zero; |
2299 |
|
2300 |
public UnoXInterfaceMethodTypeDescription (IntPtr handle) : base (handle) |
2301 |
{ |
2302 |
} |
2303 |
|
2304 |
public UnoXTypeDescription ReturnType |
2305 |
{ |
2306 |
get |
2307 |
{ |
2308 |
return UnoXTypeDescription.Create (cmm_x_interface_method_type_description_get_return_type (mHandle)); |
2309 |
} |
2310 |
} |
2311 |
|
2312 |
public bool ReturnsStruct |
2313 |
{ |
2314 |
get |
2315 |
{ |
2316 |
return cmm_x_interface_method_type_description_returns_struct (mHandle); |
2317 |
} |
2318 |
} |
2319 |
|
2320 |
void AssureParameters () |
2321 |
{ |
2322 |
if (mParametersHandle == IntPtr.Zero) |
2323 |
mParameters = cmm_x_interface_method_type_description_get_parameters (mHandle, out mParametersHandle, out mParametersArrayHandle); |
2324 |
} |
2325 |
|
2326 |
public int Parameters |
2327 |
{ |
2328 |
get |
2329 |
{ |
2330 |
AssureParameters (); |
2331 |
|
2332 |
return mParameters; |
2333 |
} |
2334 |
} |
2335 |
|
2336 |
public UnoXMethodParameter Parameter (int idx) |
2337 |
{ |
2338 |
AssureParameters (); |
2339 |
|
2340 |
if (idx < 0 || idx >= mParameters) |
2341 |
return null; |
2342 |
|
2343 |
return new UnoXMethodParameter (cmm_x_interface_method_type_description_get_parameter (mParametersArrayHandle, idx)); |
2344 |
} |
2345 |
|
2346 |
void AssureExceptionTypes () |
2347 |
{ |
2348 |
if (!mGotExceptionTypes) { |
2349 |
mExceptionTypes = cmm_x_interface_method_type_description_get_exception_types (mHandle, out mExceptionTypesHandle, out mExceptionTypesArrayHandle); |
2350 |
mGotExceptionTypes = true; |
2351 |
} |
2352 |
} |
2353 |
|
2354 |
public int ExceptionTypes |
2355 |
{ |
2356 |
get |
2357 |
{ |
2358 |
AssureExceptionTypes (); |
2359 |
|
2360 |
return mExceptionTypes; |
2361 |
} |
2362 |
} |
2363 |
|
2364 |
public UnoXCompoundTypeDescription ExceptionType (int idx) |
2365 |
{ |
2366 |
AssureExceptionTypes (); |
2367 |
|
2368 |
if (idx < 0 || idx >= mExceptionTypes) |
2369 |
return null; |
2370 |
|
2371 |
return UnoXTypeDescription.Create (cmm_x_interface_method_type_description_get_exception_type (mExceptionTypesArrayHandle, idx)) as UnoXCompoundTypeDescription; |
2372 |
} |
2373 |
|
2374 |
public bool IsOneway |
2375 |
{ |
2376 |
get |
2377 |
{ |
2378 |
return cmm_x_interface_method_type_description_is_oneway (mHandle); |
2379 |
} |
2380 |
} |
2381 |
|
2382 |
[DllImport("climaker")] |
2383 |
private static extern int cmm_x_interface_method_type_description_get_parameters (IntPtr handle, out IntPtr parametersHandle, out IntPtr parametersArrayHandle); |
2384 |
|
2385 |
[DllImport("climaker")] |
2386 |
private static extern IntPtr cmm_x_interface_method_type_description_get_parameter (IntPtr parametersArrayHandle, int idx); |
2387 |
|
2388 |
[DllImport("climaker")] |
2389 |
private static extern int cmm_x_interface_method_type_description_get_exception_types (IntPtr handle, out IntPtr exceptionTypesHandle, out IntPtr exceptionTypesArrayHandle); |
2390 |
|
2391 |
[DllImport("climaker")] |
2392 |
private static extern IntPtr cmm_x_interface_method_type_description_get_exception_type (IntPtr exceptionTypesArrayHandle, int idx); |
2393 |
|
2394 |
[DllImport("climaker")] |
2395 |
private static extern IntPtr cmm_x_interface_method_type_description_get_return_type (IntPtr handle); |
2396 |
|
2397 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2398 |
private static extern bool cmm_x_interface_method_type_description_returns_struct (IntPtr handle); |
2399 |
|
2400 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2401 |
private static extern bool cmm_x_interface_method_type_description_is_oneway (IntPtr handle); |
2402 |
} |
2403 |
|
2404 |
class UnoXCompoundTypeDescription : UnoXTypeDescription |
2405 |
{ |
2406 |
int mMemberNames = 0; |
2407 |
IntPtr mMemberNamesHandle = IntPtr.Zero; |
2408 |
|
2409 |
int mMemberTypes = 0; |
2410 |
IntPtr mMemberTypesHandle = IntPtr.Zero; |
2411 |
|
2412 |
public UnoXCompoundTypeDescription (IntPtr handle) : base (handle) |
2413 |
{ |
2414 |
} |
2415 |
|
2416 |
public UnoXTypeDescription BaseType |
2417 |
{ |
2418 |
get |
2419 |
{ |
2420 |
return UnoXTypeDescription.Create (cmm_x_compound_type_description_get_base_type (mHandle)); |
2421 |
} |
2422 |
} |
2423 |
|
2424 |
void AssureMemberNames () |
2425 |
{ |
2426 |
if (mMemberNamesHandle == IntPtr.Zero) |
2427 |
mMemberNames = cmm_x_compound_type_description_get_member_names (mHandle, out mMemberNamesHandle); |
2428 |
} |
2429 |
|
2430 |
public string MemberName (int idx) |
2431 |
{ |
2432 |
AssureMemberNames (); |
2433 |
|
2434 |
if (idx < 0 || idx >= mMemberNames) |
2435 |
return null; |
2436 |
|
2437 |
return Marshal.PtrToStringAnsi (cmm_x_compound_type_description_get_member_name (mMemberNamesHandle, idx)); |
2438 |
} |
2439 |
|
2440 |
public int MemberNames |
2441 |
{ |
2442 |
get |
2443 |
{ |
2444 |
AssureMemberNames (); |
2445 |
|
2446 |
return mMemberNames; |
2447 |
} |
2448 |
} |
2449 |
|
2450 |
void AssureMemberTypes () |
2451 |
{ |
2452 |
if (mMemberTypesHandle == IntPtr.Zero) |
2453 |
mMemberTypes = cmm_x_compound_type_description_get_member_types (mHandle, out mMemberTypesHandle); |
2454 |
} |
2455 |
|
2456 |
public UnoXTypeDescription MemberType (int idx) |
2457 |
{ |
2458 |
AssureMemberTypes (); |
2459 |
|
2460 |
if (idx < 0 || idx >= mMemberTypes) |
2461 |
return null; |
2462 |
|
2463 |
return UnoXTypeDescription.Create (cmm_x_compound_type_description_get_member_type (mMemberTypesHandle, idx)); |
2464 |
} |
2465 |
|
2466 |
public int MemberTypes |
2467 |
{ |
2468 |
get |
2469 |
{ |
2470 |
AssureMemberTypes (); |
2471 |
|
2472 |
return mMemberTypes; |
2473 |
} |
2474 |
} |
2475 |
|
2476 |
[DllImport("climaker")] |
2477 |
private static extern IntPtr cmm_x_compound_type_description_get_base_type (IntPtr handle); |
2478 |
|
2479 |
[DllImport("climaker")] |
2480 |
private static extern int cmm_x_compound_type_description_get_member_names (IntPtr handle, out IntPtr memberNamesHandle); |
2481 |
|
2482 |
[DllImport("climaker")] |
2483 |
private static extern IntPtr cmm_x_compound_type_description_get_member_name (IntPtr handle, int idx); |
2484 |
|
2485 |
[DllImport("climaker")] |
2486 |
private static extern int cmm_x_compound_type_description_get_member_types (IntPtr handle, out IntPtr memberTypesHandle); |
2487 |
|
2488 |
[DllImport("climaker")] |
2489 |
private static extern IntPtr cmm_x_compound_type_description_get_member_type (IntPtr handle, int idx); |
2490 |
} |
2491 |
|
2492 |
class UnoXExceptionTypeDescription : UnoXCompoundTypeDescription |
2493 |
{ |
2494 |
public UnoXExceptionTypeDescription (IntPtr handle) : base (handle) |
2495 |
{ |
2496 |
} |
2497 |
} |
2498 |
|
2499 |
class UnoXStructTypeDescription : UnoXCompoundTypeDescription |
2500 |
{ |
2501 |
int mTypeArguments = 0; |
2502 |
IntPtr mTypeArgumentsHandle = IntPtr.Zero; |
2503 |
IntPtr mTypeArgumentsArrayHandle = IntPtr.Zero; |
2504 |
|
2505 |
int mTypeParameters = 0; |
2506 |
IntPtr mTypeParametersHandle = IntPtr.Zero; |
2507 |
|
2508 |
public UnoXStructTypeDescription (IntPtr handle) : base (handle) |
2509 |
{ |
2510 |
} |
2511 |
|
2512 |
void AssureTypeParameters () |
2513 |
{ |
2514 |
if (mTypeParametersHandle == IntPtr.Zero) |
2515 |
mTypeParameters = cmm_x_struct_type_description_get_type_parameters (mHandle, out mTypeParametersHandle); |
2516 |
} |
2517 |
|
2518 |
public string TypeParameter (int idx) |
2519 |
{ |
2520 |
AssureTypeParameters (); |
2521 |
|
2522 |
if (idx < 0 || idx >= mTypeParameters) |
2523 |
return null; |
2524 |
|
2525 |
return Marshal.PtrToStringAnsi (cmm_x_struct_type_description_get_type_parameter (mTypeParametersHandle, idx)); |
2526 |
} |
2527 |
|
2528 |
public int TypeParameters |
2529 |
{ |
2530 |
get |
2531 |
{ |
2532 |
AssureTypeParameters (); |
2533 |
|
2534 |
return mTypeParameters; |
2535 |
} |
2536 |
} |
2537 |
|
2538 |
void AssureTypeArguments () |
2539 |
{ |
2540 |
if (mTypeArgumentsHandle == IntPtr.Zero) |
2541 |
mTypeArguments = cmm_x_struct_type_description_get_type_arguments (mHandle, out mTypeArgumentsHandle, out mTypeArgumentsArrayHandle); |
2542 |
} |
2543 |
|
2544 |
public int TypeArguments |
2545 |
{ |
2546 |
get |
2547 |
{ |
2548 |
AssureTypeArguments (); |
2549 |
|
2550 |
return mTypeArguments; |
2551 |
} |
2552 |
} |
2553 |
|
2554 |
public UnoXTypeDescription TypeArgument (int idx) |
2555 |
{ |
2556 |
AssureTypeArguments (); |
2557 |
|
2558 |
if (idx < 0 || idx >= mTypeArguments) |
2559 |
return null; |
2560 |
|
2561 |
return UnoXTypeDescription.Create (cmm_x_struct_type_description_get_type_argument (mTypeArgumentsArrayHandle, idx)); |
2562 |
} |
2563 |
|
2564 |
[DllImport("climaker")] |
2565 |
private static extern int cmm_x_struct_type_description_get_type_parameters (IntPtr handle, out IntPtr typeParametersHandle); |
2566 |
|
2567 |
[DllImport("climaker")] |
2568 |
private static extern IntPtr cmm_x_struct_type_description_get_type_parameter (IntPtr typeParametersHandle, int idx); |
2569 |
|
2570 |
[DllImport("climaker")] |
2571 |
private static extern int cmm_x_struct_type_description_get_type_arguments (IntPtr handle, out IntPtr typeArgumentsHandle, out IntPtr typeArgumentsArrayHandle); |
2572 |
|
2573 |
[DllImport("climaker")] |
2574 |
private static extern IntPtr cmm_x_struct_type_description_get_type_argument (IntPtr typeArgumentsArrayHandle, int idx); |
2575 |
} |
2576 |
|
2577 |
class UnoXMethodParameter : UnoObject |
2578 |
{ |
2579 |
public UnoXMethodParameter (IntPtr handle) : base (handle) |
2580 |
{ |
2581 |
} |
2582 |
|
2583 |
public bool IsOut |
2584 |
{ |
2585 |
get |
2586 |
{ |
2587 |
return cmm_x_method_parameter_is_out (mHandle); |
2588 |
} |
2589 |
} |
2590 |
|
2591 |
public bool IsIn |
2592 |
{ |
2593 |
get |
2594 |
{ |
2595 |
return cmm_x_method_parameter_is_in (mHandle); |
2596 |
} |
2597 |
} |
2598 |
|
2599 |
public string Name |
2600 |
{ |
2601 |
get |
2602 |
{ |
2603 |
return Marshal.PtrToStringAnsi (cmm_x_method_parameter_name (mHandle)); |
2604 |
} |
2605 |
} |
2606 |
|
2607 |
public int Position |
2608 |
{ |
2609 |
get |
2610 |
{ |
2611 |
return cmm_x_method_parameter_position (mHandle); |
2612 |
} |
2613 |
} |
2614 |
|
2615 |
public UnoXTypeDescription Type |
2616 |
{ |
2617 |
get |
2618 |
{ |
2619 |
return UnoXTypeDescription.Create (cmm_x_method_parameter_type (mHandle)); |
2620 |
} |
2621 |
} |
2622 |
|
2623 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2624 |
private static extern bool cmm_x_method_parameter_is_out (IntPtr handle); |
2625 |
|
2626 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2627 |
private static extern bool cmm_x_method_parameter_is_in (IntPtr handle); |
2628 |
|
2629 |
[DllImport("climaker")] |
2630 |
private static extern int cmm_x_method_parameter_position (IntPtr handle); |
2631 |
|
2632 |
[DllImport("climaker")] |
2633 |
private static extern IntPtr cmm_x_method_parameter_name (IntPtr handle); |
2634 |
|
2635 |
[DllImport("climaker")] |
2636 |
private static extern IntPtr cmm_x_method_parameter_type (IntPtr handle); |
2637 |
} |
2638 |
|
2639 |
class UnoXParameter : UnoXMethodParameter |
2640 |
{ |
2641 |
public UnoXParameter (IntPtr handle) : base (handle) |
2642 |
{ |
2643 |
} |
2644 |
|
2645 |
public bool IsRest |
2646 |
{ |
2647 |
get |
2648 |
{ |
2649 |
return cmm_x_parameter_is_rest (mHandle); |
2650 |
} |
2651 |
} |
2652 |
|
2653 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2654 |
private static extern bool cmm_x_parameter_is_rest (IntPtr handle); |
2655 |
} |
2656 |
|
2657 |
class UnoXIndirectTypeDescription : UnoXTypeDescription |
2658 |
{ |
2659 |
public UnoXIndirectTypeDescription (IntPtr handle) : base (handle) |
2660 |
{ |
2661 |
} |
2662 |
|
2663 |
public UnoXTypeDescription ReferencedType |
2664 |
{ |
2665 |
get |
2666 |
{ |
2667 |
return UnoXTypeDescription.Create (cmm_x_indirect_type_description_get_referenced_type (mHandle)); |
2668 |
} |
2669 |
} |
2670 |
|
2671 |
[DllImport("climaker")] |
2672 |
private static extern IntPtr cmm_x_indirect_type_description_get_referenced_type (IntPtr handle); |
2673 |
} |
2674 |
|
2675 |
class UnoXServiceTypeDescription : UnoXTypeDescription |
2676 |
{ |
2677 |
int mConstructors = 0; |
2678 |
IntPtr mConstructorsHandle = IntPtr.Zero; |
2679 |
|
2680 |
public UnoXServiceTypeDescription (IntPtr handle) : base (handle) |
2681 |
{ |
2682 |
} |
2683 |
|
2684 |
public bool IsSingleInterfaceBased |
2685 |
{ |
2686 |
get |
2687 |
{ |
2688 |
return cmm_x_service_type_description_is_single_interface_based (mHandle); |
2689 |
} |
2690 |
} |
2691 |
|
2692 |
public UnoXTypeDescription Interface |
2693 |
{ |
2694 |
get |
2695 |
{ |
2696 |
return UnoXTypeDescription.Create (cmm_x_service_type_description_get_interface (mHandle)); |
2697 |
} |
2698 |
} |
2699 |
|
2700 |
void AssureConstructors () |
2701 |
{ |
2702 |
if (mConstructorsHandle == IntPtr.Zero) |
2703 |
mConstructors = cmm_x_service_type_description_get_constructors (mHandle, out mConstructorsHandle); |
2704 |
} |
2705 |
|
2706 |
public int Constructors |
2707 |
{ |
2708 |
get |
2709 |
{ |
2710 |
AssureConstructors (); |
2711 |
|
2712 |
return mConstructors; |
2713 |
} |
2714 |
} |
2715 |
|
2716 |
public UnoXServiceConstructorDescription Constructor (int idx) |
2717 |
{ |
2718 |
AssureConstructors (); |
2719 |
|
2720 |
if (idx < 0 || idx >= mConstructors) |
2721 |
return null; |
2722 |
|
2723 |
return new UnoXServiceConstructorDescription (cmm_x_service_type_description_get_constructor (mConstructorsHandle, idx)); |
2724 |
} |
2725 |
|
2726 |
[DllImport("climaker")] |
2727 |
private static extern int cmm_x_service_type_description_get_constructors (IntPtr handle, out IntPtr constructorssHandle); |
2728 |
|
2729 |
[DllImport("climaker")] |
2730 |
private static extern IntPtr cmm_x_service_type_description_get_constructor (IntPtr constructorsHandle, int idx); |
2731 |
|
2732 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2733 |
private static extern bool cmm_x_service_type_description_is_single_interface_based (IntPtr handle); |
2734 |
|
2735 |
[DllImport("climaker")] |
2736 |
private static extern IntPtr cmm_x_service_type_description_get_interface (IntPtr handle); |
2737 |
} |
2738 |
|
2739 |
class UnoXSingletonTypeDescription : UnoXTypeDescription |
2740 |
{ |
2741 |
public UnoXSingletonTypeDescription (IntPtr handle) : base (handle) |
2742 |
{ |
2743 |
} |
2744 |
|
2745 |
public bool IsInterfaceBased |
2746 |
{ |
2747 |
get |
2748 |
{ |
2749 |
return cmm_x_singleton_type_description_is_interface_based (mHandle); |
2750 |
} |
2751 |
} |
2752 |
|
2753 |
public UnoXTypeDescription Interface |
2754 |
{ |
2755 |
get |
2756 |
{ |
2757 |
return UnoXTypeDescription.Create (cmm_x_singleton_type_description_get_interface (mHandle)); |
2758 |
} |
2759 |
} |
2760 |
|
2761 |
[DllImport("climaker")] |
2762 |
private static extern IntPtr cmm_x_singleton_type_description_get_interface (IntPtr handle); |
2763 |
|
2764 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2765 |
private static extern bool cmm_x_singleton_type_description_is_interface_based (IntPtr handle); |
2766 |
} |
2767 |
|
2768 |
class UnoXConstantTypeDescription : UnoXTypeDescription |
2769 |
{ |
2770 |
public UnoXConstantTypeDescription (IntPtr handle) : base (handle) |
2771 |
{ |
2772 |
} |
2773 |
|
2774 |
public object ConstantValue |
2775 |
{ |
2776 |
get |
2777 |
{ |
2778 |
char tChar; |
2779 |
bool tBool; |
2780 |
byte tByte; |
2781 |
Int16 tInt16; |
2782 |
System.UInt16 tUInt16; |
2783 |
Int32 tInt32; |
2784 |
System.UInt32 tUInt32; |
2785 |
Int64 tInt64; |
2786 |
System.UInt64 tUInt64; |
2787 |
System.Single tFloat; |
2788 |
double tDouble; |
2789 |
|
2790 |
UnoTypeClass tc = cmm_any_to_cli_constant (mHandle, |
2791 |
out tChar, out tBool, |
2792 |
out tByte, |
2793 |
out tInt16, out tUInt16, |
2794 |
out tInt32, out tUInt32, |
2795 |
out tInt64, out tUInt64, |
2796 |
out tFloat, out tDouble); |
2797 |
switch (tc) { |
2798 |
case UnoTypeClass.Char: |
2799 |
return tChar; |
2800 |
case UnoTypeClass.Boolean: |
2801 |
return tBool; |
2802 |
case UnoTypeClass.Byte: |
2803 |
return tByte; |
2804 |
case UnoTypeClass.Short: |
2805 |
return tInt16; |
2806 |
case UnoTypeClass.UnsignedShort: |
2807 |
return tUInt16; |
2808 |
case UnoTypeClass.Long: |
2809 |
return tInt32; |
2810 |
case UnoTypeClass.UnsignedLong: |
2811 |
return tUInt32; |
2812 |
case UnoTypeClass.Hyper: |
2813 |
return tInt64; |
2814 |
case UnoTypeClass.UnsignedHyper: |
2815 |
return tUInt64; |
2816 |
case UnoTypeClass.Float: |
2817 |
return tFloat; |
2818 |
case UnoTypeClass.Double: |
2819 |
return tDouble; |
2820 |
} |
2821 |
|
2822 |
throw new Exception (String.Format ("Unexpected type {0} for XConstantTypeDescription", tc)); |
2823 |
} |
2824 |
} |
2825 |
|
2826 |
[DllImport("climaker")] |
2827 |
private static extern UnoTypeClass cmm_any_to_cli_constant (IntPtr handle, |
2828 |
out char tChar, out bool tBool, |
2829 |
out byte tByte, |
2830 |
out Int16 tInt16, out System.UInt16 tUInt16, |
2831 |
out Int32 tInt32, out System.UInt32 tUInt32, |
2832 |
out Int64 tInt64, out System.UInt64 tUInt64, |
2833 |
out System.Single tFloat, out double tDouble); |
2834 |
} |
2835 |
|
2836 |
class UnoXConstantsTypeDescription : UnoXTypeDescription |
2837 |
{ |
2838 |
int mConstants = 0; |
2839 |
IntPtr mConstantsHandle = IntPtr.Zero; |
2840 |
|
2841 |
public UnoXConstantsTypeDescription (IntPtr handle) : base (handle) |
2842 |
{ |
2843 |
} |
2844 |
|
2845 |
void AssureConstants () |
2846 |
{ |
2847 |
if (mConstantsHandle == IntPtr.Zero) |
2848 |
mConstants = cmm_x_constants_type_description_get_constants (mHandle, out mConstantsHandle); |
2849 |
} |
2850 |
|
2851 |
public int Constants |
2852 |
{ |
2853 |
get |
2854 |
{ |
2855 |
AssureConstants (); |
2856 |
|
2857 |
return mConstants; |
2858 |
} |
2859 |
} |
2860 |
|
2861 |
public UnoXConstantTypeDescription Constant (int idx) |
2862 |
{ |
2863 |
AssureConstants (); |
2864 |
|
2865 |
if (idx < 0 || idx >= mConstants) |
2866 |
return null; |
2867 |
|
2868 |
return UnoXTypeDescription.Create (cmm_x_constants_type_description_get_constant (mConstantsHandle, idx)) as UnoXConstantTypeDescription; |
2869 |
} |
2870 |
|
2871 |
[DllImport("climaker")] |
2872 |
private static extern int cmm_x_constants_type_description_get_constants (IntPtr handle, out IntPtr constantssHandle); |
2873 |
|
2874 |
[DllImport("climaker")] |
2875 |
private static extern IntPtr cmm_x_constants_type_description_get_constant (IntPtr constantsHandle, int idx); |
2876 |
} |
2877 |
|
2878 |
class UnoXServiceConstructorDescription : UnoObject |
2879 |
{ |
2880 |
int mParameters = 0; |
2881 |
IntPtr mParametersHandle = IntPtr.Zero; |
2882 |
|
2883 |
public UnoXServiceConstructorDescription (IntPtr handle) : base (handle) |
2884 |
{ |
2885 |
} |
2886 |
|
2887 |
void AssureParameters () |
2888 |
{ |
2889 |
if (mParametersHandle == IntPtr.Zero) |
2890 |
mParameters = cmm_x_service_constructor_description_get_parameters (mHandle, out mParametersHandle); |
2891 |
} |
2892 |
|
2893 |
public int Parameters |
2894 |
{ |
2895 |
get |
2896 |
{ |
2897 |
AssureParameters (); |
2898 |
|
2899 |
return mParameters; |
2900 |
} |
2901 |
} |
2902 |
|
2903 |
public UnoXParameter Parameter (int idx) |
2904 |
{ |
2905 |
AssureParameters (); |
2906 |
|
2907 |
if (idx < 0 || idx >= mParameters) |
2908 |
return null; |
2909 |
|
2910 |
return new UnoXParameter (cmm_x_service_constructor_description_get_parameter (mParametersHandle, idx)); |
2911 |
} |
2912 |
|
2913 |
public string Name |
2914 |
{ |
2915 |
get |
2916 |
{ |
2917 |
return Marshal.PtrToStringAnsi (cmm_x_service_constructor_description_get_name (mHandle)); |
2918 |
} |
2919 |
} |
2920 |
|
2921 |
public bool IsDefault |
2922 |
{ |
2923 |
get |
2924 |
{ |
2925 |
return cmm_x_service_constructor_description_is_default_constructor (mHandle); |
2926 |
} |
2927 |
} |
2928 |
|
2929 |
public UnoXTypeDescription[] ExceptionTypes |
2930 |
{ |
2931 |
get |
2932 |
{ |
2933 |
IntPtr handle; |
2934 |
int i, count; |
2935 |
|
2936 |
count = cmm_x_service_constructor_description_get_exception_types (mHandle, out handle); |
2937 |
UnoXTypeDescription[] types = new UnoXTypeDescription [count]; |
2938 |
|
2939 |
for (i = 0; i < count; i ++) { |
2940 |
types [i] = UnoXTypeDescription.Create (cmm_x_service_constructor_description_get_exception_type (handle, i)); |
2941 |
} |
2942 |
|
2943 |
if (count > 0) |
2944 |
cmm_x_service_constructor_description_free_exception_types (handle, count); |
2945 |
|
2946 |
return types; |
2947 |
} |
2948 |
} |
2949 |
|
2950 |
[DllImport("climaker")] |
2951 |
private static extern int cmm_x_service_constructor_description_get_parameters (IntPtr handle, out IntPtr parameterssHandle); |
2952 |
|
2953 |
[DllImport("climaker")] |
2954 |
private static extern IntPtr cmm_x_service_constructor_description_get_parameter (IntPtr parametersHandle, int idx); |
2955 |
|
2956 |
[DllImport("climaker")] |
2957 |
private static extern IntPtr cmm_x_service_constructor_description_get_name (IntPtr handle); |
2958 |
|
2959 |
[DllImport("climaker")][return:MarshalAs(UnmanagedType.I1)] |
2960 |
private static extern bool cmm_x_service_constructor_description_is_default_constructor (IntPtr handle); |
2961 |
|
2962 |
[DllImport("climaker")] |
2963 |
private static extern int cmm_x_service_constructor_description_get_exception_types (IntPtr handle, out IntPtr exceptionTypesHandle); |
2964 |
|
2965 |
[DllImport("climaker")] |
2966 |
private static extern IntPtr cmm_x_service_constructor_description_get_exception_type (IntPtr handle, int index); |
2967 |
|
2968 |
[DllImport("climaker")] |
2969 |
private static extern void cmm_x_service_constructor_description_free_exception_types (IntPtr handle, int count); |
2970 |
} |
2971 |
|
2972 |
|
2973 |
public class MainClass |
2974 |
{ |
2975 |
class OptionInfo |
2976 |
{ |
2977 |
public string mName; |
2978 |
public char mShortOption; |
2979 |
public bool mHasArgument; |
2980 |
|
2981 |
public OptionInfo (string name, char shortOption, bool hasArgument) |
2982 |
{ |
2983 |
mName = name; |
2984 |
mShortOption = shortOption; |
2985 |
mHasArgument = hasArgument; |
2986 |
} |
2987 |
} |
2988 |
|
2989 |
static OptionInfo[] sOptionInfos = { |
2990 |
new OptionInfo ("out", 'O', true ), |
2991 |
new OptionInfo ("types", 'T', true), |
2992 |
new OptionInfo ("extra", 'X', true), |
2993 |
new OptionInfo ("reference", 'r', true), |
2994 |
new OptionInfo ("keyfile", 'k', true), |
2995 |
new OptionInfo ("delaySign", 'd', true), |
2996 |
new OptionInfo ("assembly-version", '\0', true), |
2997 |
new OptionInfo ("assembly-description", '\0', true), |
2998 |
new OptionInfo ("assembly-product", '\0', true), |
2999 |
new OptionInfo ("assembly-company", '\0', true), |
3000 |
new OptionInfo ("assembly-copyright", '\0', true), |
3001 |
new OptionInfo ("assembly-trademark", '\0', true), |
3002 |
new OptionInfo ("verbose", 'v', false), |
3003 |
new OptionInfo ("help", 'h', false) |
3004 |
}; |
3005 |
|
3006 |
static string sUsingText = |
3007 |
"\n" + |
3008 |
"using: climaker <switches> [registry-file-1 registry-file-2 ...]\n" + |
3009 |
"\n" + |
3010 |
"switches:\n" + |
3011 |
" -O, --out <output-file> output assembly file;\n" + |
3012 |
" defaults to cli_unotypes.dll if more than one\n" + |
3013 |
" registry-file is given, else <registry-file>.dll\n" + |
3014 |
" -T, --types types to be generated (if none is given,\n" + |
3015 |
" <type1[;type2;...]> then all types of given registries are emitted\n" + |
3016 |
" -X, --extra <rdb-file> additional rdb to saturate referenced types in\n" + |
3017 |
" given registry file(s); these types will not be\n" + |
3018 |
" emitted into the output assembly file\n" + |
3019 |
" -r, --reference reference metadata from assembly file\n" + |
3020 |
" <assembly-file>\n" + |
3021 |
" -k, --keyfile keyfile needed for strong name\n" + |
3022 |
" --assembly-version <version> sets assembly version\n" + |
3023 |
" --assembly-description <text> sets assembly description text\n" + |
3024 |
" --assembly-product <text> sets assembly product name\n" + |
3025 |
" --assembly-company <text> sets assembly company\n" + |
3026 |
" --assembly-copyright <text> sets assembly copyright\n" + |
3027 |
" --assembly-trademark <text> sets assembly trademark\n" + |
3028 |
" -v, --verbose verbose output to stdout\n" + |
3029 |
" -h, --help this message\n" + |
3030 |
"\n" + |
3031 |
"example: climaker --out cli_mytypes.dll \\\n" + |
3032 |
" --reference cli_types.dll \\\n" + |
3033 |
" --extra types.rdb \\\n" + |
3034 |
" mytypes.rdb\n" + |
3035 |
"\n"; |
3036 |
|
3037 |
static OptionInfo GetOptionInfo (string opt) |
3038 |
{ |
3039 |
return GetOptionInfo (opt, '\0'); |
3040 |
} |
3041 |
|
3042 |
static OptionInfo GetOptionInfo (string opt, char shortOpt) |
3043 |
{ |
3044 |
int pos; |
3045 |
|
3046 |
for (pos = 0; pos < sOptionInfos.Length; pos ++) { |
3047 |
if (opt.Length > 0) { |
3048 |
if (opt.Equals (sOptionInfos [pos].mName)) |
3049 |
return sOptionInfos [pos]; |
3050 |
} else { |
3051 |
if (sOptionInfos [pos].mShortOption == shortOpt) |
3052 |
return sOptionInfos [pos]; |
3053 |
} |
3054 |
} |
3055 |
|
3056 |
return null; |
3057 |
} |
3058 |
|
3059 |
static bool IsOption (OptionInfo optionInfo, ref int pIndex) |
3060 |
{ |
3061 |
if (sArgs.Length <= pIndex) |
3062 |
return false; |
3063 |
string arg = sArgs [pIndex]; |
3064 |
|
3065 |
if (arg.Length < 2 || arg [0] != '-') |
3066 |
return false; |
3067 |
|
3068 |
if (arg.Length == 2 && arg[ 1 ] == optionInfo.mShortOption) { |
3069 |
pIndex ++; |
3070 |
|
3071 |
return true; |
3072 |
} |
3073 |
|
3074 |
if (arg [1] == '-' && arg.Substring (2).Equals (optionInfo.mName)) { |
3075 |
pIndex ++; |
3076 |
|
3077 |
return true; |
3078 |
} |
3079 |
|
3080 |
return false; |
3081 |
} |
3082 |
|
3083 |
static bool ReadOption (ref bool flag, OptionInfo optionInfo, ref int pIndex) |
3084 |
{ |
3085 |
bool ret = IsOption (optionInfo, ref pIndex); |
3086 |
if (ret) |
3087 |
flag = true; |
3088 |
|
3089 |
return ret; |
3090 |
} |
3091 |
|
3092 |
static bool ReadArgument (ref string pValue, OptionInfo optionInfo, ref int pIndex) |
3093 |
{ |
3094 |
if (IsOption (optionInfo, ref pIndex)) { |
3095 |
if (pIndex < sArgs.Length) { |
3096 |
pValue = sArgs [pIndex]; |
3097 |
pIndex ++; |
3098 |
|
3099 |
return true; |
3100 |
} |
3101 |
pIndex --; |
3102 |
} |
3103 |
|
3104 |
return false; |
3105 |
} |
3106 |
|
3107 |
static string[] sArgs; |
3108 |
|
3109 |
public static int Main (string[] args) |
3110 |
{ |
3111 |
if (args.Length <= 0) { |
3112 |
Console.Write (sUsingText); |
3113 |
return 0; |
3114 |
} |
3115 |
|
3116 |
int ret = 0; |
3117 |
|
3118 |
try { |
3119 |
sArgs = args; |
3120 |
Config config = new Config (); |
3121 |
|
3122 |
OptionInfo infoHelp = GetOptionInfo ("help"); |
3123 |
OptionInfo infoVerbose = GetOptionInfo ("verbose"); |
3124 |
OptionInfo infoOut = GetOptionInfo ("out"); |
3125 |
OptionInfo infoTypes = GetOptionInfo ("types"); |
3126 |
OptionInfo infoReference = GetOptionInfo ("reference"); |
3127 |
OptionInfo infoExtra = GetOptionInfo ("extra"); |
3128 |
OptionInfo infoKeyfile = GetOptionInfo ("keyfile"); |
3129 |
OptionInfo infoDelaysign = GetOptionInfo ("delaySign"); |
3130 |
OptionInfo infoVersion = GetOptionInfo ("assembly-version"); |
3131 |
OptionInfo infoProduct = GetOptionInfo ("assembly-product"); |
3132 |
OptionInfo infoDescription = GetOptionInfo ("assembly-description"); |
3133 |
OptionInfo infoCompany = GetOptionInfo ("assembly-company"); |
3134 |
OptionInfo infoCopyright = GetOptionInfo ("assembly-copyright"); |
3135 |
OptionInfo infoTrademark = GetOptionInfo ("assembly-trademark"); |
3136 |
|
3137 |
int pos; |
3138 |
string cmdArg = null; |
3139 |
|
3140 |
for (pos = 0; pos < sArgs.Length; ) { |
3141 |
// options |
3142 |
if (IsOption (infoHelp, ref pos )) { |
3143 |
Console.Write (sUsingText); |
3144 |
return 0; |
3145 |
} else if (ReadArgument (ref cmdArg, infoTypes, ref pos )) { |
3146 |
config.mExplicitTypes.AddRange (cmdArg.Split (new char[] {';'})); |
3147 |
} else if (ReadArgument (ref cmdArg, infoExtra, ref pos )) { |
3148 |
config.mExtraRegistries.Add (cmdArg); |
3149 |
} else if (ReadArgument (ref cmdArg, infoReference, ref pos )) { |
3150 |
config.mExtraAssemblies.Add (cmdArg); |
3151 |
} else if (!ReadOption (ref config.mVerbose, infoVerbose, ref pos) && |
3152 |
!ReadArgument (ref config.mOutput, infoOut, ref pos) && |
3153 |
!ReadArgument (ref config.mVersion, infoVersion, ref pos) && |
3154 |
!ReadArgument (ref config.mDescription, infoDescription, ref pos) && |
3155 |
!ReadArgument (ref config.mProduct, infoProduct, ref pos) && |
3156 |
!ReadArgument (ref config.mCompany, infoCompany, ref pos) && |
3157 |
!ReadArgument (ref config.mCopyright, infoCopyright, ref pos) && |
3158 |
!ReadArgument (ref config.mTrademark, infoTrademark, ref pos) && |
3159 |
!ReadArgument (ref config.mKeyfile, infoKeyfile, ref pos) && |
3160 |
!ReadArgument (ref config.mDelaySign, infoDelaysign, ref pos)) { |
3161 |
cmdArg = args [pos]; |
3162 |
pos ++; |
3163 |
cmdArg = cmdArg.Trim(); |
3164 |
|
3165 |
if (cmdArg.Length > 0) { |
3166 |
if (cmdArg [0] == '-') { // is option |
3167 |
OptionInfo optionInfo = null; |
3168 |
|
3169 |
if (cmdArg.Length > 2 && cmdArg [1] == '-') { |
3170 |
// long option |
3171 |
optionInfo = GetOptionInfo (cmdArg.Substring (2)); |
3172 |
} else if (cmdArg.Length == 2 && cmdArg [1] != '-') { |
3173 |
// short option |
3174 |
optionInfo = GetOptionInfo ("", cmdArg [1]); |
3175 |
} |
3176 |
|
3177 |
if (optionInfo == null) { |
3178 |
Console.WriteLine ("unknown option " + cmdArg + "! Use climaker --help\nto print all options."); |
3179 |
return 1; |
3180 |
} else { |
3181 |
Console.WriteLine ("unhandled valid option?! " + cmdArg); |
3182 |
if (optionInfo.mHasArgument) |
3183 |
pos ++; |
3184 |
} |
3185 |
} else { |
3186 |
config.mMandatoryRegistries.Add (cmdArg); |
3187 |
} |
3188 |
} |
3189 |
} |
3190 |
} |
3191 |
|
3192 |
CliMaker cliMaker = new CliMaker (config); |
3193 |
|
3194 |
cliMaker.OpenRegistries (); |
3195 |
cliMaker.PrepareAssembly (); |
3196 |
cliMaker.Emit (); |
3197 |
cliMaker.Save (); |
3198 |
} catch (Exception e) { |
3199 |
Console.WriteLine ("\n> error: " + e + "\n> dying abnormally..."); |
3200 |
ret = 1; |
3201 |
} |
3202 |
|
3203 |
return ret; |
3204 |
} |
3205 |
} |