* CodeGen.cs: Add method to resolve global vararg methods.
[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 : IMethodRef {
17
18                 private ITypeRef ret_type;
19                 private string name;
20                 private ITypeRef[] param;
21                 private PEAPI.CallConv call_conv;
22
23                 private PEAPI.Method peapi_method;
24
25                 public GlobalMethodRef (ITypeRef ret_type, PEAPI.CallConv call_conv,
26                                 string name, ITypeRef[] param)
27                 {
28                         this.ret_type = ret_type;
29                         this.call_conv = call_conv;
30                         this.name = name;
31                         this.param = param;
32                 }
33
34                 public PEAPI.Method PeapiMethod {
35                         get { return peapi_method; }
36                 }
37
38                 public void Resolve (CodeGen code_gen)
39                 {
40                         string sig = MethodDef.CreateSignature (name, param);
41
42                         if ((call_conv & PEAPI.CallConv.Vararg) == 0) {
43                                 peapi_method = code_gen.ResolveMethod (sig);
44                         } else {
45                                 ArrayList opt_list = new ArrayList ();
46                                 bool in_opt = false;
47                                 foreach (ITypeRef type in param) {
48                                         if (TypeRef.Ellipsis == type) {
49                                                 in_opt = true;
50                                         } else if (in_opt) {
51                                                 type.Resolve (code_gen);
52                                                 opt_list.Add (type.PeapiType);
53                                         }
54                                 }
55                                 peapi_method = code_gen.ResolveVarargMethod (sig, code_gen,
56                                                 (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
57                         }
58
59                         peapi_method.AddCallConv (call_conv);
60                 }
61
62         }
63
64 }
65