2 // Mono.ILASM.ExternMethodRef
5 // Jackson Harper (Jackson@LatitudeGeo.com)
7 // (C) 2003 Jackson Harper, All rights reserved
12 using System.Collections;
14 namespace Mono.ILASM {
16 public class ExternMethodRef : IMethodRef {
18 private ExternTypeRef owner;
19 private ITypeRef ret_type;
21 private ITypeRef[] param;
22 private PEAPI.CallConv call_conv;
24 private PEAPI.Method peapi_method;
25 private bool is_resolved;
27 public ExternMethodRef (ExternTypeRef owner, ITypeRef ret_type,
28 PEAPI.CallConv call_conv, string name, ITypeRef[] param)
31 this.ret_type = ret_type;
34 this.call_conv = call_conv;
39 public PEAPI.Method PeapiMethod {
40 get { return peapi_method; }
43 public PEAPI.CallConv CallConv {
44 get { return call_conv; }
45 set { call_conv = value; }
48 public ITypeRef Owner {
52 public void Resolve (CodeGen code_gen)
57 if ((call_conv & PEAPI.CallConv.Vararg) != 0) {
58 ResolveVararg (code_gen);
62 PEAPI.Type[] param_list = new PEAPI.Type[param.Length];
65 ret_type.Resolve (code_gen);
68 foreach (ITypeRef typeref in param) {
69 typeref.Resolve (code_gen);
70 param_list[count++] = typeref.PeapiType;
78 owner.Resolve (code_gen);
80 if (owner.UseTypeSpec) {
81 PEAPI.Type owner_ref = owner.PeapiType;
82 peapi_method = code_gen.PEFile.AddMethodToTypeSpec (owner_ref, write_name,
83 ret_type.PeapiType, param_list);
85 PEAPI.ClassRef owner_ref;
86 owner_ref = (PEAPI.ClassRef) owner.PeapiType;
87 peapi_method = owner_ref.AddMethod (write_name,
88 ret_type.PeapiType, param_list);
91 peapi_method.AddCallConv (call_conv);
96 protected void ResolveVararg (CodeGen code_gen)
101 ArrayList param_list = new ArrayList ();
102 ArrayList opt_list = new ArrayList ();
106 ret_type.Resolve (code_gen);
109 foreach (ITypeRef typeref in param) {
111 typeref.Resolve (code_gen);
112 opt_list.Add (typeref.PeapiType);
113 } else if (TypeRef.Ellipsis == typeref) {
116 typeref.Resolve (code_gen);
117 param_list.Add (typeref.PeapiType);
121 if (name == "<init>")
122 write_name = ".ctor";
127 throw new NotImplementedException ("Vararg methods on arrays are not supported yet.");
129 owner.Resolve (code_gen);
131 if (owner.UseTypeSpec) {
132 PEAPI.Type owner_ref = owner.PeapiType;
133 peapi_method = code_gen.PEFile.AddVarArgMethodToTypeSpec (owner_ref,
134 write_name, ret_type.PeapiType,
135 (PEAPI.Type[]) param_list.ToArray (typeof (PEAPI.Type)),
136 (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
138 PEAPI.ClassRef owner_ref;
139 owner_ref = (PEAPI.ClassRef) owner.PeapiType;
140 peapi_method = owner_ref.AddVarArgMethod (write_name,
142 (PEAPI.Type[]) param_list.ToArray (typeof (PEAPI.Type)),
143 (PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
147 peapi_method.AddCallConv (call_conv);