Преглед изворни кода

2002-07-19 Martin Baulig <[email protected]>

	* ILGenerator.cs (Emit (OpCode, LocalBuilder)): Throw an exception
	when trying to emit a local that was defined in a different ILGenerator.

	* LocalBuilder.cs (LocalBuilder): Added `ILGenetator' argument to
	the constructor.

svn path=/trunk/mcs/; revision=5914
Martin Baulig пре 23 година
родитељ
комит
fa8a352b57

+ 7 - 0
mcs/class/corlib/System.Reflection.Emit/ChangeLog

@@ -1,3 +1,10 @@
+2002-07-19  Martin Baulig  <[email protected]>
+
+	* ILGenerator.cs (Emit (OpCode, LocalBuilder)): Throw an exception
+	when trying to emit a local that was defined in a different ILGenerator.
+
+	* LocalBuilder.cs (LocalBuilder): Added `ILGenetator' argument to
+	the constructor.
 
 Tue Jul 16 19:32:08 CEST 2002 Paolo Molaro <[email protected]>
 

+ 5 - 1
mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs

@@ -311,7 +311,7 @@ namespace System.Reflection.Emit {
 				scopes.Push (sym_writer.OpenScope (code_len));
 		}
 		public LocalBuilder DeclareLocal (Type localType) {
-			LocalBuilder res = new LocalBuilder (module, localType);
+			LocalBuilder res = new LocalBuilder (module, localType, this);
 			if (locals != null) {
 				LocalBuilder[] new_l = new LocalBuilder [locals.Length + 1];
 				System.Array.Copy (locals, new_l, locals.Length);
@@ -445,6 +445,10 @@ namespace System.Reflection.Emit {
 			bool load_addr = false;
 			bool is_store = false;
 			make_room (6);
+
+			if (lbuilder.ilgen != this)
+				throw new Exception ("Trying to emit a local from a different ILGenerator.");
+
 			/* inline the code from ll_emit () to optimize il code size */
 			if (opcode.StackBehaviourPop == StackBehaviour.Pop1) {
 				cur_stack --;

+ 3 - 1
mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs

@@ -32,11 +32,13 @@ namespace System.Reflection.Emit {
 		//
 		private ModuleBuilder module;
 		internal uint position;
+		internal ILGenerator ilgen;
 
-		internal LocalBuilder (ModuleBuilder m, Type t)
+		internal LocalBuilder (ModuleBuilder m, Type t, ILGenerator ilgen)
 		{
 			this.module = m;
 			this.type = t;
+			this.ilgen = ilgen;
 		}
 		public void SetLocalSymInfo (string lname, int startOffset, int endOffset)
 		{