| 1 |
/* |
| 2 |
Copyright (C) 2012 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 |
[email protected] |
| 22 |
|
| 23 |
*/ |
| 24 |
using System; |
| 25 |
using System.Collections.Generic; |
| 26 |
|
| 27 |
namespace IKVM.Reflection.Emit |
| 28 |
{ |
| 29 |
public struct ExceptionHandler : IEquatable<ExceptionHandler> |
| 30 |
{ |
| 31 |
private readonly int tryOffset; |
| 32 |
private readonly int tryLength; |
| 33 |
private readonly int filterOffset; |
| 34 |
private readonly int handlerOffset; |
| 35 |
private readonly int handlerLength; |
| 36 |
private readonly ExceptionHandlingClauseOptions kind; |
| 37 |
private readonly int exceptionTypeToken; |
| 38 |
|
| 39 |
public ExceptionHandler(int tryOffset, int tryLength, int filterOffset, int handlerOffset, int handlerLength, ExceptionHandlingClauseOptions kind, int exceptionTypeToken) |
| 40 |
{ |
| 41 |
if (tryOffset < 0 || tryLength < 0 || filterOffset < 0 || handlerOffset < 0 || handlerLength < 0) |
| 42 |
{ |
| 43 |
throw new ArgumentOutOfRangeException(); |
| 44 |
} |
| 45 |
this.tryOffset = tryOffset; |
| 46 |
this.tryLength = tryLength; |
| 47 |
this.filterOffset = filterOffset; |
| 48 |
this.handlerOffset = handlerOffset; |
| 49 |
this.handlerLength = handlerLength; |
| 50 |
this.kind = kind; |
| 51 |
this.exceptionTypeToken = exceptionTypeToken; |
| 52 |
} |
| 53 |
|
| 54 |
public int TryOffset |
| 55 |
{ |
| 56 |
get { return tryOffset; } |
| 57 |
} |
| 58 |
|
| 59 |
public int TryLength |
| 60 |
{ |
| 61 |
get { return tryLength; } |
| 62 |
} |
| 63 |
|
| 64 |
public int FilterOffset |
| 65 |
{ |
| 66 |
get { return filterOffset; } |
| 67 |
} |
| 68 |
|
| 69 |
public int HandlerOffset |
| 70 |
{ |
| 71 |
get { return handlerOffset; } |
| 72 |
} |
| 73 |
|
| 74 |
public int HandlerLength |
| 75 |
{ |
| 76 |
get { return handlerLength; } |
| 77 |
} |
| 78 |
|
| 79 |
public ExceptionHandlingClauseOptions Kind |
| 80 |
{ |
| 81 |
get { return kind; } |
| 82 |
} |
| 83 |
|
| 84 |
public int ExceptionTypeToken |
| 85 |
{ |
| 86 |
get { return exceptionTypeToken; } |
| 87 |
} |
| 88 |
|
| 89 |
public bool Equals(ExceptionHandler other) |
| 90 |
{ |
| 91 |
return tryOffset == other.tryOffset |
| 92 |
&& tryLength == other.tryLength |
| 93 |
&& filterOffset == other.filterOffset |
| 94 |
&& handlerOffset == other.handlerOffset |
| 95 |
&& handlerLength == other.handlerLength |
| 96 |
&& kind == other.kind |
| 97 |
&& exceptionTypeToken == other.exceptionTypeToken; |
| 98 |
} |
| 99 |
|
| 100 |
public override bool Equals(object obj) |
| 101 |
{ |
| 102 |
ExceptionHandler? other = obj as ExceptionHandler?; |
| 103 |
return other != null && Equals(other.Value); |
| 104 |
} |
| 105 |
|
| 106 |
public override int GetHashCode() |
| 107 |
{ |
| 108 |
return tryOffset ^ tryLength * 33 ^ filterOffset * 333 ^ handlerOffset * 3333 ^ handlerLength * 33333; |
| 109 |
} |
| 110 |
|
| 111 |
public static bool operator ==(ExceptionHandler left, ExceptionHandler right) |
| 112 |
{ |
| 113 |
return left.Equals(right); |
| 114 |
} |
| 115 |
|
| 116 |
public static bool operator !=(ExceptionHandler left, ExceptionHandler right) |
| 117 |
{ |
| 118 |
return !left.Equals(right); |
| 119 |
} |
| 120 |
} |
| 121 |
} |