2010-04-01 Jb Evain <jbevain@novell.com>
[mcs.git] / ilasm / codegen / MethodRef.cs
blob5c0553febf0424ae80cc9d05006118c9840ab77c
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 //
11 using System;
12 using System.Collections;
14 namespace Mono.ILASM {
16 public class MethodRef : BaseMethodRef {
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)
24 public override void Resolve (CodeGen code_gen)
26 if (is_resolved)
27 return;
29 owner.Resolve (code_gen);
31 TypeDef owner_def = code_gen.TypeManager[owner.FullName];
32 if (owner_def == null)
33 Report.Error ("Reference to undefined class '" + owner.FullName + "'");
35 string write_name;
37 if (name == "<init>")
38 write_name = ".ctor";
39 else
40 write_name = name;
42 if ((call_conv & PEAPI.CallConv.Vararg) == 0) {
43 peapi_method = owner_def.ResolveMethod (ret_type, call_conv, name,
44 param, gen_param_count, code_gen);
45 } else {
46 ArrayList opt_list = new ArrayList ();
47 bool in_opt = false;
48 foreach (BaseTypeRef type in param) {
49 if (type is SentinelTypeRef) {
50 in_opt = true;
51 } else if (in_opt) {
52 type.Resolve (code_gen);
53 opt_list.Add (type.PeapiType);
56 peapi_method = owner_def.ResolveVarargMethod (
57 ret_type, call_conv, name, param, gen_param_count,
58 (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)),
59 code_gen);
62 is_resolved = true;