Add this for backwards compatibility
[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                 private bool is_resolved;
25                 private int gen_param_count;
26
27                 public GlobalMethodRef (ITypeRef ret_type, PEAPI.CallConv call_conv,
28                                 string name, ITypeRef[] param, int gen_param_count)
29                 {
30                         this.ret_type = ret_type;
31                         this.call_conv = call_conv;
32                         this.name = name;
33                         this.param = param;
34                         this.gen_param_count = gen_param_count;
35                         if (gen_param_count > 0)
36                                 CallConv |= PEAPI.CallConv.Generic;
37
38                         is_resolved = false;
39                 }
40
41                 public PEAPI.Method PeapiMethod {
42                         get { return peapi_method; }
43                 }
44
45                 public PEAPI.CallConv CallConv {
46                         get { return call_conv; }
47                         set { call_conv = value; }
48                 }
49
50                 public ITypeRef Owner {
51                         get { return null; }
52                 }
53
54                 public void Resolve (CodeGen code_gen)
55                 {
56                         if (is_resolved)
57                                 return;
58
59                         string sig;
60
61                         if ((call_conv & PEAPI.CallConv.Vararg) == 0) {
62                                 sig = MethodDef.CreateSignature (ret_type, name, param, gen_param_count);
63                                 peapi_method = code_gen.ResolveMethod (sig);
64                         } else {
65                                 ArrayList opt_list = new ArrayList ();
66                                 bool in_opt = false;
67                                 foreach (ITypeRef type in param) {
68                                         if (type is SentinelTypeRef) {
69                                                 in_opt = true;
70                                         } else if (in_opt) {
71                                                 type.Resolve (code_gen);
72                                                 opt_list.Add (type.PeapiType);
73                                         }
74                                 }
75                                 sig = MethodDef.CreateVarargSignature (ret_type, name, param);
76                                 peapi_method = code_gen.ResolveVarargMethod (sig, code_gen,
77                                                 (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
78                         }
79
80                         peapi_method.AddCallConv (call_conv);
81                         
82                         is_resolved = true;
83                 }
84
85         }
86
87 }
88