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