Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Class.cs « codegen « ilasm « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 58a946cd1fe27320d4a95cde7b746cec2b19cae7 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Class.cs
// (C) Sergey Chaban (serge@wildwestsoftware.com)

using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;

namespace Mono.ILASM {

	/// <summary>
	/// </summary>
	public class ClassName {

		private string name;
		private string assembly;
		private string module;


		/// <summary>
		/// </summary>
		/// <param name="name"></param>
		public ClassName (string name) {
			this.name = name;
			this.assembly = String.Empty;
			this.module = String.Empty;
		}


		public string Name {
			get {
				return name;
			}
		}


	}


	/// <summary>
	/// </summary>
	public class Class {

		private string name;

		// extends clause
		private ClassName baseClass;

		// implements clause
		private ArrayList interfaces;

		private ArrayList methods;

		private TypeBuilder tb;

		private CodeGen codgen;

		private TypeAttributes attrs;



		/// <summary>
		/// </summary>
		/// <param name="name"></param>
		public Class (string name)
		{
			this.name = name;
		}



		/// <summary>
		/// </summary>
		/// <param name="m"></param>
		public void AddMethod (Method m)
		{
			if (methods == null) methods = new ArrayList ();
			methods.Add (m);
		}


		/// <summary>
		/// </summary>
		public CodeGen CodeGen {
			get {
				return codgen;
			}
		}


		/// <summary>
		/// </summary>
		public TypeAttributes Attrs {
			get {
				return attrs;
			}
			set {
				attrs = value;
			}
		}


		/// <summary>
		/// </summary>
		public TypeBuilder TypeBuilder {
			get {
				if (tb == null && codgen != null) {
					tb = codgen.ModBuilder.DefineType (name, Attrs);
				}
				return tb;
			}
		}

		/// <summary>
		/// </summary>
		/// <param name="cg"></param>
		public void Emit (CodeGen cg)
		{
			codgen = cg;
			
			TypeBuilder.CreateType();
			cg.TypeManager[name] = TypeBuilder;

			if (methods != null) {
				foreach (Method m in methods) 
					m.Resolve (this);
			}

			if (methods != null) {
				foreach (Method m in methods) {
					m.Emit (this);
					if (m.IsEntryPoint)
						cg.SetEntryPoint (m.Builder);
				}
			}	
		}
		
		// This can be removed when System.Reflection.Emit.TypeBuilder.GetMethod is implemented
		// TODO: This function needs allot of work
		public MethodInfo GetMethod (string method_name, BindingFlags binding_flags,
			Type[] param_type_list)
		{
			foreach (Method method in methods) {
				if (method.Name != method_name)
					continue;
				ParameterInfo[] param_info = method.Builder.GetParameters ();
				if (param_info == null) {
					if (param_type_list.Length == 0)
						return method.Builder;
					else
						continue;
				}
				int size = param_info.Length;
				if (param_type_list.Length != size)
					continue;
				for (int i=0; i<size; i++) {
					if (param_type_list[i] != param_info[i].ParameterType)
						goto end;	
				}

				return method.Builder;
				end: continue;
			}
	
			return null;
		}
	}
}