2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Microsoft.JScript / Microsoft.JScript / Try.cs
1 //
2 // Try.cs:
3 //
4 // Author: Cesar Octavio Lopez Nataren
5 //
6 // (C) 2003, 2004, Cesar Octavio Lopez Nataren
7 //
8
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using Microsoft.JScript.Vsa;
32 using System.Reflection;
33 using System.Reflection.Emit;
34 using System.Collections;
35
36 namespace Microsoft.JScript {
37
38         public sealed class Try : AST {
39
40                 internal FieldBuilder field_info;
41                 internal LocalBuilder local_builder;
42                 
43                 internal AST guarded_block;
44                 internal ArrayList catch_blocks;
45                 internal AST finally_block;
46
47
48                 internal Try (AST guarded_block, ArrayList catch_block, AST finally_block, AST parent, int line_number)
49                 {
50                         this.parent = parent;
51                         this.guarded_block = guarded_block;
52                         this.catch_blocks = catch_block;
53                         this.finally_block = finally_block;
54                 }               
55
56                 public static Object JScriptExceptionValue (object e, VsaEngine engine)
57                 {
58                         throw new NotImplementedException ();
59                 }
60
61                 public static void PushHandlerScope (VsaEngine engine, string id, int scopeId)
62                 {
63                         throw new NotImplementedException ();
64                 }
65
66                 internal override bool Resolve (IdentificationTable context)
67                 {
68                         bool r = true;
69                         if (guarded_block != null)
70                                 r &= guarded_block.Resolve (context);
71                         
72                         if (catch_blocks != null && catch_blocks.Count > 0) {
73                                 foreach (Catch c in catch_blocks) {
74                                         context.OpenBlock ();
75                                         context.Enter (c.id, c);
76                                         r &= c.Resolve (context);
77                                         context.CloseBlock ();
78                                 }
79                         }
80                         if (finally_block != null)
81                                 r &= finally_block.Resolve (context);
82                         return r;
83                 }
84
85                 internal override void Emit (EmitContext ec)
86                 {
87                         ILGenerator ig = ec.ig;
88                         
89                         ig.BeginExceptionBlock ();
90
91                         if (guarded_block != null)
92                                 guarded_block.Emit (ec);
93
94                         if (catch_blocks != null && catch_blocks.Count > 0) {
95                                 foreach (Catch c in catch_blocks)
96                                         c.Emit (ec);
97                         }               
98                         if (finally_block != null) {
99                                 ig.BeginFinallyBlock ();
100                                 finally_block.Emit (ec);
101                         }
102                         ig.EndExceptionBlock ();
103                 }
104         }
105 }