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 void Resolve (CodeGen code_gen
)
53 if ((call_conv
& PEAPI
.CallConv
.Vararg
) != 0) {
54 ResolveVararg (code_gen
);
58 PEAPI
.Type
[] param_list
= new PEAPI
.Type
[param
.Length
];
61 ret_type
.Resolve (code_gen
);
64 foreach (ITypeRef typeref
in param
) {
65 typeref
.Resolve (code_gen
);
66 param_list
[count
++] = typeref
.PeapiType
;
74 owner
.Resolve (code_gen
);
76 if (owner
.UseTypeSpec
) {
77 PEAPI
.Type owner_ref
= owner
.PeapiType
;
78 peapi_method
= code_gen
.PEFile
.AddMethodToTypeSpec (owner_ref
, write_name
,
79 ret_type
.PeapiType
, param_list
);
81 PEAPI
.ClassRef owner_ref
;
82 owner_ref
= (PEAPI
.ClassRef
) owner
.PeapiType
;
83 peapi_method
= owner_ref
.AddMethod (write_name
,
84 ret_type
.PeapiType
, param_list
);
87 peapi_method
.AddCallConv (call_conv
);
92 protected void ResolveVararg (CodeGen code_gen
)
97 ArrayList param_list
= new ArrayList ();
98 ArrayList opt_list
= new ArrayList ();
102 ret_type
.Resolve (code_gen
);
105 foreach (ITypeRef typeref
in param
) {
107 typeref
.Resolve (code_gen
);
108 opt_list
.Add (typeref
.PeapiType
);
109 } else if (TypeRef
.Ellipsis
== typeref
) {
112 typeref
.Resolve (code_gen
);
113 param_list
.Add (typeref
.PeapiType
);
117 if (name
== "<init>")
118 write_name
= ".ctor";
123 throw new NotImplementedException ("Vararg methods on arrays are not supported yet.");
125 owner
.Resolve (code_gen
);
127 if (owner
.UseTypeSpec
) {
128 PEAPI
.Type owner_ref
= owner
.PeapiType
;
129 peapi_method
= code_gen
.PEFile
.AddVarArgMethodToTypeSpec (owner_ref
,
130 write_name
, ret_type
.PeapiType
,
131 (PEAPI
.Type
[]) param_list
.ToArray (typeof (PEAPI
.Type
)),
132 (PEAPI
.Type
[]) opt_list
.ToArray (typeof (PEAPI
.Type
)));
134 PEAPI
.ClassRef owner_ref
;
135 owner_ref
= (PEAPI
.ClassRef
) owner
.PeapiType
;
136 peapi_method
= owner_ref
.AddVarArgMethod (write_name
,
138 (PEAPI
.Type
[]) param_list
.ToArray (typeof (PEAPI
.Type
)),
139 (PEAPI
.Type
[]) opt_list
.ToArray (typeof (PEAPI
.Type
)));
143 peapi_method
.AddCallConv (call_conv
);