1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
//
// Mono.ILASM.ExternMethodRef
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
using System.Collections;
namespace Mono.ILASM {
public class ExternMethodRef : BaseMethodRef {
public ExternMethodRef (ExternTypeRef owner, BaseTypeRef ret_type,
PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
: base (owner, call_conv, ret_type, name, param, gen_param_count)
{
}
public override void Resolve (CodeGen code_gen)
{
if (is_resolved)
return;
if ((call_conv & PEAPI.CallConv.Vararg) != 0) {
ResolveVararg (code_gen);
return;
}
PEAPI.Type[] param_list = new PEAPI.Type[param.Length];
string write_name;
ret_type.Resolve (code_gen);
int count = 0;
foreach (BaseTypeRef typeref in param) {
typeref.Resolve (code_gen);
param_list[count++] = typeref.PeapiType;
}
if (name == "<init>")
write_name = ".ctor";
else
write_name = name;
owner.Resolve (code_gen);
if (owner.UseTypeSpec) {
PEAPI.Type owner_ref = owner.PeapiType;
peapi_method = code_gen.PEFile.AddMethodToTypeSpec (owner_ref, write_name,
ret_type.PeapiType, param_list, gen_param_count);
} else {
PEAPI.ClassRef owner_ref;
owner_ref = (PEAPI.ClassRef) owner.PeapiType;
peapi_method = owner_ref.AddMethod (write_name,
ret_type.PeapiType, param_list, gen_param_count);
}
peapi_method.AddCallConv (call_conv);
is_resolved = true;
}
protected void ResolveVararg (CodeGen code_gen)
{
if (is_resolved)
return;
ArrayList param_list = new ArrayList ();
ArrayList opt_list = new ArrayList ();
bool in_opt = false;
string write_name;
ret_type.Resolve (code_gen);
foreach (BaseTypeRef typeref in param) {
if (in_opt) {
typeref.Resolve (code_gen);
opt_list.Add (typeref.PeapiType);
} else if (TypeRef.Ellipsis == typeref) {
in_opt = true;
} else {
typeref.Resolve (code_gen);
param_list.Add (typeref.PeapiType);
}
}
if (name == "<init>")
write_name = ".ctor";
else
write_name = name;
if (owner.IsArray)
Report.Error ("Vararg methods on arrays are not supported yet.");
owner.Resolve (code_gen);
if (owner.UseTypeSpec) {
PEAPI.Type owner_ref = owner.PeapiType;
peapi_method = code_gen.PEFile.AddVarArgMethodToTypeSpec (owner_ref,
write_name, ret_type.PeapiType,
(PEAPI.Type[]) param_list.ToArray (typeof (PEAPI.Type)),
(PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
} else {
PEAPI.ClassRef owner_ref;
owner_ref = (PEAPI.ClassRef) owner.PeapiType;
peapi_method = owner_ref.AddVarArgMethod (write_name,
ret_type.PeapiType,
(PEAPI.Type[]) param_list.ToArray (typeof (PEAPI.Type)),
(PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
}
peapi_method.AddCallConv (call_conv);
is_resolved = true;
}
}
}
|