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