Merge pull request #1981 from akoeplinger/ilasm
[mono.git] / mcs / ilasm / codegen / GlobalMethodRef.cs
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 //
9
10
11 using System;
12 using System.Collections;
13
14 namespace Mono.ILASM {
15
16         public class GlobalMethodRef : BaseMethodRef {
17
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)
21                 {
22                 }
23
24                 public override void Resolve (CodeGen code_gen)
25                 {
26                         if (is_resolved)
27                                 return;
28
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);
41                                         }
42                                 }
43
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)));
48                         }
49
50                         peapi_method.AddCallConv (call_conv);
51                         
52                         is_resolved = true;
53                 }
54
55         }
56
57 }
58