In ilasm/tests:
[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                 private int gen_param_count;
26
27                 private bool is_resolved;
28
29                 public TypeSpecMethodRef (ITypeRef owner,
30                                 ITypeRef ret_type, PEAPI.CallConv call_conv,
31                                 string name, ITypeRef[] param, int gen_param_count)
32                 {
33                         this.owner = owner;
34                         this.call_conv = call_conv;
35                         this.ret_type = ret_type;
36                         this.name = name;
37                         this.param = param;
38                         this.gen_param_count = gen_param_count;
39                         if (gen_param_count > 0)
40                                 CallConv |= PEAPI.CallConv.Generic;
41                         is_resolved = false;
42                 }
43
44                 public PEAPI.Method PeapiMethod {
45                         get {
46                                 return peapi_method;
47                         }
48                 }
49
50                 public PEAPI.CallConv CallConv {
51                         get { return call_conv; }
52                         set { call_conv = value; }
53                 }
54
55                 public ITypeRef Owner {
56                         get { return owner; }
57                 }
58
59                 public void Resolve (CodeGen code_gen)
60                 {
61                         if (is_resolved)
62                                 return;
63
64                         PEAPI.Type[] param_list = new PEAPI.Type[param.Length];
65                         string write_name;
66
67                         ret_type.Resolve (code_gen);
68
69                         int count = 0;
70                         foreach (ITypeRef typeref in param) {
71                                 typeref.Resolve (code_gen);
72                                 param_list[count++] = typeref.PeapiType;
73                         }
74
75                         if (name == "<init>")
76                                 write_name = ".ctor";
77                         else
78                                 write_name = name;
79
80                         owner.Resolve (code_gen);
81                         peapi_method = code_gen.PEFile.AddMethodToTypeSpec (owner.PeapiType, write_name,
82                                         ret_type.PeapiType, param_list, gen_param_count);
83
84                         peapi_method.AddCallConv (call_conv);
85
86                         is_resolved = true;
87                 }
88         }
89
90 }
91
92
93