2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / ilasm / codegen / GlobalMethodRef.cs
blob6a47aa002d1cd3c184c6f092b85376d47d267d8c
1 //
2 // Mono.ILASM.GlobalMethodRef
3 //
4 // Author(s):
5 // Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
11 using System;
12 using System.Collections;
14 namespace Mono.ILASM {
16 public class GlobalMethodRef : BaseMethodRef {
18 public GlobalMethodRef (BaseTypeRef ret_type, PEAPI.CallConv call_conv,
19 string name, BaseTypeRef[] param, int gen_param_count)
20 : base (null, call_conv, ret_type, name, param, gen_param_count)
24 public override void Resolve (CodeGen code_gen)
26 if (is_resolved)
27 return;
29 if ((call_conv & PEAPI.CallConv.Vararg) == 0) {
30 string sig = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, false);
31 peapi_method = code_gen.ResolveMethod (sig);
32 } else {
33 ArrayList opt_list = new ArrayList ();
34 bool in_opt = false;
35 foreach (BaseTypeRef type in param) {
36 if (type is SentinelTypeRef) {
37 in_opt = true;
38 } else if (in_opt) {
39 type.Resolve (code_gen);
40 opt_list.Add (type.PeapiType);
44 string sig_only_required_params = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, false);
45 string sig_with_optional_params = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, true);
46 peapi_method = code_gen.ResolveVarargMethod (sig_only_required_params, sig_with_optional_params, code_gen,
47 (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
50 peapi_method.AddCallConv (call_conv);
52 is_resolved = true;