* TypeDef.cs (GenericInfo):
[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 : BaseMethodRef {
17
18                 public MethodRef (TypeRef owner, PEAPI.CallConv call_conv,
19                         BaseTypeRef ret_type, string name, BaseTypeRef[] param, int gen_param_count)
20                         : base (owner, 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                         owner.Resolve (code_gen);
30
31                         TypeDef owner_def = code_gen.TypeManager[owner.FullName];
32                         if (owner_def == null)
33                                 throw new Exception (String.Format ("Reference to undefined class '{0}'", owner.FullName));
34
35                         string write_name;
36
37                         if (name == "<init>")
38                                 write_name = ".ctor";
39                         else
40                                 write_name = name;
41
42                         string sig;
43
44                         if ((call_conv & PEAPI.CallConv.Vararg) == 0) {
45                                 sig = MethodDef.CreateSignature (ret_type, name, param, gen_param_count);
46                                 peapi_method = owner_def.ResolveMethod (sig, code_gen);
47                         } else {
48                                 sig = MethodDef.CreateVarargSignature (ret_type, name, param);
49                                 ArrayList opt_list = new ArrayList ();
50                                 bool in_opt = false;
51                                 foreach (BaseTypeRef type in param) {
52                                         if (type is SentinelTypeRef) {
53                                                 in_opt = true;
54                                         } else if (in_opt) {
55                                                 type.Resolve (code_gen);
56                                                 opt_list.Add (type.PeapiType);
57                                         }
58                                 }
59                                 peapi_method = owner_def.ResolveVarargMethod (sig, code_gen,
60                                                 (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
61                         }
62
63                         is_resolved = true;
64
65                 }
66
67         }
68
69 }
70