IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ExceptionBlock.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2010 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24
25using System.Linq;
26using System.Xml.Linq;
27
28using IKVM.Runtime;
29
30using Type = IKVM.Reflection.Type;
31
33{
34
35 [Instruction("exceptionBlock")]
36 public sealed class ExceptionBlock : Instruction
37 {
38
44 public static new ExceptionBlock Read(XElement element)
45 {
46 var inst = new ExceptionBlock();
47 Load(inst, element);
48 return inst;
49 }
50
56 public static void Load(ExceptionBlock inst, XElement element)
57 {
58 Load((Instruction)inst, element);
59 inst.Try = element.Elements(MapXmlSerializer.NS + "try").Select(InstructionList.Read).FirstOrDefault();
60 inst.Catch = element.Elements(MapXmlSerializer.NS + "catch").Select(CatchBlock.Read).FirstOrDefault();
61 inst.Finally = element.Elements(MapXmlSerializer.NS + "finally").Select(InstructionList.Read).FirstOrDefault();
62 }
63
64 public InstructionList Try { get; set; }
65
66 public CatchBlock Catch { get; set; }
67
68 public InstructionList Finally { get; set; }
69
70 internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
71 {
72 ilgen.BeginExceptionBlock();
73
74 Try.Generate(context, ilgen);
75
76 if (Catch != null)
77 {
78 Type type;
79 if (Catch.Type != null)
80 {
81 type = context.ClassLoader.Context.StaticCompiler.GetTypeForMapXml(context.ClassLoader, Catch.Type);
82 }
83 else
84 {
85 type = context.ClassLoader.LoadClassByName(Catch.Class).TypeAsExceptionType;
86 }
87
88 ilgen.BeginCatchBlock(type);
89 Catch.Generate(context, ilgen);
90 }
91
92 if (Finally != null)
93 {
94 ilgen.BeginFinallyBlock();
95 Finally.Generate(context, ilgen);
96 }
97
98 ilgen.EndExceptionBlock();
99 }
100
101 }
102
103}
IKVM.Reflection.Type Type
RuntimeContext Context
Gets a reference to the RuntimeContext that this RuntimeClassLoader is hosted within.
static new CatchBlock Read(XElement element)
Reads the XML element into a new CatchBlock instance.
Definition CatchBlock.cs:38
static void Load(ExceptionBlock inst, XElement element)
Loads the XML element into the instruction.
static new ExceptionBlock Read(XElement element)
Reads the XML element into a new ExceptionBlock instance.
static InstructionList Read(XElement element)
Reads the XML element into a new InstructionList instance.
Base class for MapXML instruction instances.
Provides the ability to serialize MapXML.
IKVM.Runtime.ClassFile.Method.Instruction Instruction
Definition compiler.cs:44