merge from trunk revisions 58933, 58935, 58936
[mono.git] / mcs / ilasm / codegen / TypeSpecMethodRef.cs
1 //
2 // Mono.ILASM.TypeSpecMethodRef
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
13
14 namespace Mono.ILASM {
15
16         public class TypeSpecMethodRef : IMethodRef {
17
18                 private PEAPI.MethodRef peapi_method;
19                 private ITypeRef owner;
20
21                 private PEAPI.CallConv call_conv;
22                 private ITypeRef ret_type;
23                 private string name;
24                 private ITypeRef[] param;
25
26                 private bool is_resolved;
27
28                 public TypeSpecMethodRef (ITypeRef owner,
29                                 ITypeRef ret_type, PEAPI.CallConv call_conv,
30                                 string name, ITypeRef[] param)
31                 {
32                         this.owner = owner;
33                         this.call_conv = call_conv;
34                         this.ret_type = ret_type;
35                         this.name = name;
36                         this.param = param;
37                         is_resolved = false;
38                 }
39
40                 public PEAPI.Method PeapiMethod {
41                         get {
42                                 return peapi_method;
43                         }
44                 }
45
46                 public PEAPI.CallConv CallConv {
47                         get { return call_conv; }
48                         set { call_conv = value; }
49                 }
50
51                 public ITypeRef Owner {
52                         get { return owner; }
53                 }
54
55                 public void Resolve (CodeGen code_gen)
56                 {
57                         if (is_resolved)
58                                 return;
59
60                         PEAPI.Type[] param_list = new PEAPI.Type[param.Length];
61                         string write_name;
62
63                         ret_type.Resolve (code_gen);
64
65                         int count = 0;
66                         foreach (ITypeRef typeref in param) {
67                                 typeref.Resolve (code_gen);
68                                 param_list[count++] = typeref.PeapiType;
69                         }
70
71                         if (name == "<init>")
72                                 write_name = ".ctor";
73                         else
74                                 write_name = name;
75
76                         owner.Resolve (code_gen);
77                         peapi_method = code_gen.PEFile.AddMethodToTypeSpec (owner.PeapiType, write_name,
78                                         ret_type.PeapiType, param_list);
79
80                         peapi_method.AddCallConv (call_conv);
81
82                         is_resolved = true;
83                 }
84         }
85
86 }
87
88
89