**** Merged from MCS ****
[mono-project.git] / mcs / class / Microsoft.JScript / Microsoft.JScript / Try.cs
blob4393787a8c0b9560f15eab65da266204bd0005b9
1 //
2 // Try.cs:
3 //
4 // Author: Cesar Octavio Lopez Nataren
5 //
6 // (C) 2003, 2004, Cesar Octavio Lopez Nataren
7 //
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.
30 using System;
31 using Microsoft.JScript.Vsa;
32 using System.Reflection;
33 using System.Reflection.Emit;
34 using System.Collections;
36 namespace Microsoft.JScript {
38 public sealed class Try : AST {
40 internal FieldBuilder field_info;
41 internal LocalBuilder local_builder;
43 internal AST guarded_block;
44 internal ArrayList catch_blocks;
45 internal AST finally_block;
48 internal Try (AST guarded_block, ArrayList catch_block, AST finally_block, AST parent, int line_number)
50 this.parent = parent;
51 this.guarded_block = guarded_block;
52 this.catch_blocks = catch_block;
53 this.finally_block = finally_block;
56 public static Object JScriptExceptionValue (object e, VsaEngine engine)
58 throw new NotImplementedException ();
61 public static void PushHandlerScope (VsaEngine engine, string id, int scopeId)
63 throw new NotImplementedException ();
66 internal override bool Resolve (IdentificationTable context)
68 bool r = true;
69 if (guarded_block != null)
70 r &= guarded_block.Resolve (context);
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 ();
80 if (finally_block != null)
81 r &= finally_block.Resolve (context);
82 return r;
85 internal override void Emit (EmitContext ec)
87 ILGenerator ig = ec.ig;
88 Type t = typeof (object);
89 bool not_inside_func = parent == null;
91 ig.BeginExceptionBlock ();
93 if (guarded_block != null)
94 guarded_block.Emit (ec);
96 if (catch_blocks != null && catch_blocks.Count > 0) {
97 foreach (Catch c in catch_blocks)
98 c.Emit (ec);
100 if (finally_block != null) {
101 ig.BeginFinallyBlock ();
102 finally_block.Emit (ec);
104 ig.EndExceptionBlock ();