Wed Apr 10 12:57:31 CEST 2002 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Wed, 10 Apr 2002 07:08:22 +0000 (07:08 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Wed, 10 Apr 2002 07:08:22 +0000 (07:08 -0000)
* ILGenerator,cs: use a stack to keep track of exception blocks.

svn path=/trunk/mcs/; revision=3727

mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs

index 3558a8e1520fc5429f0df5e6b1b67432d28074e8..81be836a994b6bf5244c3b711eeef5ebb5ca1570 100644 (file)
@@ -1,3 +1,8 @@
+
+Wed Apr 10 12:57:31 CEST 2002 Paolo Molaro <lupus@ximian.com>
+
+       * ILGenerator,cs: use a stack to keep track of exception blocks.
+
 Mon Apr  8 06:19:01  2002 Piers Haken <piersh@friskit.com>
 
        * ILGenerator.cs: added LabelField.label_base to allow for
index 1920d265f61a0f5a9ffa8e1a92ed64d90818b5bd..4c4dcdf94c3448a9b40fc8df4c9f307d43b087c0 100644 (file)
@@ -27,11 +27,13 @@ namespace System.Reflection.Emit {
                internal int filter_offset;
                
                internal void Debug () {
+#if NO
                        System.Console.Write ("\ttype="+type.ToString()+" start="+start.ToString()+" len="+len.ToString());
                        if (extype != null)
                                System.Console.WriteLine (" extype="+extype.ToString());
                        else
                                System.Console.WriteLine ("");
+#endif
                }
        }
        internal struct ILExceptionInfo {
@@ -40,6 +42,10 @@ namespace System.Reflection.Emit {
                int len;
                internal Label end;
 
+               internal int NumHandlers () {
+                       return handlers.Length;
+               }
+               
                internal void AddCatch (Type extype, int offset) {
                        int i;
                        End (offset);
@@ -75,9 +81,9 @@ namespace System.Reflection.Emit {
                                return ILExceptionBlock.CATCH;
                }
 
-               internal void Debug () {
+               internal void Debug (int b) {
 #if NO
-                       System.Console.WriteLine ("Handler at "+start.ToString()+ " len: "+len.ToString());
+                       System.Console.WriteLine ("Handler {0} at {1}, len: {2}", b, start, len);
                        for (int i = 0; i < handlers.Length; ++i)
                                handlers [i].Debug ();
 #endif
@@ -128,7 +134,7 @@ namespace System.Reflection.Emit {
                private ISymbolWriter sym_writer;
                private Stack scopes;
                private int cur_block;
-               private int open_blocks;
+               private Stack open_blocks;
 
                internal ILGenerator (MethodBase mb, int size) {
                        if (size < 0)
@@ -150,6 +156,7 @@ namespace System.Reflection.Emit {
                        }
                        abuilder = (AssemblyBuilder)module.Assembly;
                        sym_writer = module.GetSymWriter ();
+                       open_blocks = new Stack ();
                }
 
                private void add_token_fixup (MemberInfo mi) {
@@ -260,7 +267,7 @@ namespace System.Reflection.Emit {
                }
 
                public virtual void BeginCatchBlock (Type exceptionType) {
-                       if (open_blocks <= 0)
+                       if (open_blocks.Count <= 0)
                                throw new NotSupportedException ("Not in an exception block");
                        InternalEndClause ();
                        ex_handlers [cur_block].AddCatch (exceptionType, code_len);
@@ -282,23 +289,22 @@ namespace System.Reflection.Emit {
                                ex_handlers = new ILExceptionInfo [1];
                                cur_block = 0;
                        }
-                       open_blocks++;
+                       open_blocks.Push (cur_block);
                        ex_handlers [cur_block].start = code_len;
                        return ex_handlers [cur_block].end = DefineLabel ();
                }
                public virtual void BeginFaultBlock() {
-                       if (open_blocks <= 0)
+                       if (open_blocks.Count <= 0)
                                throw new NotSupportedException ("Not in an exception block");
                        //System.Console.WriteLine ("Begin fault Block");
                        //throw new NotImplementedException ();
                }
                public virtual void BeginFinallyBlock() {
-                       if (open_blocks <= 0)
+                       if (open_blocks.Count <= 0)
                                throw new NotSupportedException ("Not in an exception block");
-                       //System.Console.WriteLine ("Begin finally Block");
                        InternalEndClause ();
+                       //System.Console.WriteLine ("Begin finally Block");
                        ex_handlers [cur_block].AddFinally (code_len);
-                       //throw new NotImplementedException ();
                }
                public virtual void BeginScope () {
                        if (sym_writer != null)
@@ -540,15 +546,17 @@ namespace System.Reflection.Emit {
                }
 
                public virtual void EndExceptionBlock () {
-                       if (open_blocks <= 0)
+                       if (open_blocks.Count <= 0)
                                throw new NotSupportedException ("Not in an exception block");
                        InternalEndClause ();
                        MarkLabel (ex_handlers [cur_block].end);
                        ex_handlers [cur_block].End (code_len);
-                       ex_handlers [cur_block].Debug ();
-                       --cur_block;
-                       --open_blocks;
-                       //System.Console.WriteLine ("End Block");
+                       ex_handlers [cur_block].Debug (cur_block);
+                       //System.Console.WriteLine ("End Block {0} (handlers: {1})", cur_block, ex_handlers [cur_block].NumHandlers ());
+                       open_blocks.Pop ();
+                       if (open_blocks.Count > 0)
+                               cur_block = (int)open_blocks.Peek ();
+                       //Console.WriteLine ("curblock restored to {0}", cur_block);
                        //throw new NotImplementedException ();
                }
                public virtual void EndScope () {