Copied remotely
[mono.git] / mcs / ilasm / codegen / MethodRef.cs
1 //
2 // Mono.ILASM.MethodRef
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 MethodRef : IMethodRef {
17
18                 private TypeRef owner;
19                 private PEAPI.CallConv call_conv;
20                 private ITypeRef ret_type;
21                 private string name;
22                 private ITypeRef[] param;
23
24                 private PEAPI.Method peapi_method;
25                 private bool is_resolved;
26
27                 public MethodRef (TypeRef owner, PEAPI.CallConv call_conv,
28                         ITypeRef ret_type, string name, ITypeRef[] param)
29                 {
30                         this.owner = owner;
31                         this.call_conv = call_conv;
32                         this.ret_type = ret_type;
33                         this.name = name;
34                         this.param = param;
35                         is_resolved = false;
36                 }
37
38                 public PEAPI.Method PeapiMethod {
39                         get { return peapi_method; }
40                 }
41
42                 public PEAPI.CallConv CallConv {
43                         get { return call_conv; }
44                         set { call_conv = value; }
45                 }
46
47                 public void Resolve (CodeGen code_gen)
48                 {
49                         if (is_resolved)
50                                 return;
51
52                         TypeDef owner_def = code_gen.TypeManager[owner.FullName];
53                         string write_name;
54
55                         if (name == "<init>")
56                                 write_name = ".ctor";
57                         else
58                                 write_name = name;
59
60                         string sig;
61
62                         if ((call_conv & PEAPI.CallConv.Vararg) == 0) {
63                                 sig = MethodDef.CreateSignature (ret_type, name, param);
64                                 peapi_method = owner_def.ResolveMethod (sig, code_gen);
65                         } else {
66                                 sig = MethodDef.CreateVarargSignature (ret_type, name, param);
67                                 ArrayList opt_list = new ArrayList ();
68                                 bool in_opt = false;
69                                 foreach (ITypeRef type in param) {
70                                         if (type is SentinelTypeRef) {
71                                                 in_opt = true;
72                                         } else if (in_opt) {
73                                                 type.Resolve (code_gen);
74                                                 opt_list.Add (type.PeapiType);
75                                         }
76                                 }
77                                 peapi_method = owner_def.ResolveVarargMethod (sig, code_gen,
78                                                 (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
79                         }
80
81                         is_resolved = true;
82
83                 }
84
85         }
86
87 }
88