[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[mono.git] / mcs / class / System.Data / Mono.Data.SqlExpressions / Expressions.cs
1 //
2 // Expressions.cs
3 //
4 // Author:
5 //   Juraj Skripsky (juraj@hotfeet.ch)
6 //
7 // (C) 2004 HotFeet GmbH (http://www.hotfeet.ch)
8 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System;
34 using System.Data.Common;
35 using System.Collections;
36 using System.Data;
37
38 namespace Mono.Data.SqlExpressions {
39         internal interface IExpression {
40                 object Eval (DataRow row);
41                 bool DependsOn(DataColumn other);
42
43                 bool EvalBoolean (DataRow row);
44                 void ResetExpression ();
45         }
46
47         internal abstract class BaseExpression : IExpression {
48                 public abstract object Eval (DataRow row);
49                 public abstract bool DependsOn(DataColumn other);
50
51                 public virtual bool EvalBoolean (DataRow row)
52                 {
53                         throw new EvaluateException ("Not a Boolean Expression");
54                 }
55
56                 public override bool Equals(object obj)
57                 {
58                         if (obj == null || !(obj is BaseExpression))
59                                 return false;
60                         
61                         return true;
62                 }
63
64                 public override int GetHashCode()
65                 {
66                         return 0;
67                 }
68
69                 public virtual void ResetExpression ()
70                 {
71                 }
72         }
73
74         // abstract base classes
75         internal abstract class UnaryExpression : BaseExpression {
76                 protected IExpression expr;
77
78                 public override bool Equals(object obj)
79                 {
80                         if (!base.Equals (obj))
81                                 return false;
82
83                         if (!(obj is UnaryExpression))
84                                 return false;
85
86                         UnaryExpression other = (UnaryExpression) obj;
87                         if (!other.expr.Equals (expr))
88                                 return false;
89                         
90                         return true;
91                 }
92
93                 public override int GetHashCode()
94                 {
95                         return base.GetHashCode () ^ expr.GetHashCode ();
96                 }
97         
98                 public UnaryExpression (IExpression e)
99                 {
100                         expr = e;
101                 }
102
103                 override public bool DependsOn(DataColumn other) {
104                         return expr.DependsOn(other);
105                 }
106
107                 override public bool EvalBoolean (DataRow row)
108                 {
109                         return (bool) Eval (row);
110                 }
111         }
112         
113         internal abstract class BinaryExpression : BaseExpression {
114                 protected IExpression expr1, expr2;
115
116                 public override bool Equals(object obj)
117                 {
118                         if (!base.Equals (obj))
119                                 return false;
120
121                         if (!(obj is BinaryExpression))
122                                 return false;
123
124                         BinaryExpression other = (BinaryExpression) obj;
125                         if (!other.expr1.Equals (expr1) || !other.expr2.Equals (expr2))
126                                 return false;
127                         
128                         return true;
129                 }
130
131                 public override int GetHashCode()
132                 {
133                         int hashCode = base.GetHashCode ();
134                         hashCode ^= expr1.GetHashCode ();
135                         hashCode ^= expr2.GetHashCode ();
136                         return hashCode;
137                 }
138         
139                 protected BinaryExpression (IExpression e1, IExpression e2)
140                 {
141                         expr1 = e1;
142                         expr2 = e2;
143                 }
144                 override public bool DependsOn(DataColumn other)
145                 {
146                         return expr1.DependsOn(other) || expr2.DependsOn(other);
147                 }
148
149                 override public void ResetExpression ()
150                 {
151                         expr1.ResetExpression ();
152                         expr2.ResetExpression ();
153                 }
154         }
155         
156         internal enum Operation {
157                 AND, OR,
158                 EQ, NE, LT, LE, GT, GE,
159                 ADD, SUB, MUL, DIV, MOD
160         }
161         
162         internal abstract class BinaryOpExpression : BinaryExpression {
163                 protected Operation op;
164
165                 public override bool Equals(object obj)
166                 {
167                         if (!base.Equals (obj))
168                                 return false;
169
170                         if (!(obj is BinaryOpExpression))
171                                 return false;
172
173                         BinaryOpExpression other = (BinaryOpExpression) obj;
174                         if (other.op != op)
175                                 return false;
176                         
177                         return true;
178                 }
179
180                 public override int GetHashCode()
181                 {
182                         return base.GetHashCode () ^ op.GetHashCode ();
183                 }
184         
185                 protected BinaryOpExpression (Operation op, IExpression e1, IExpression e2) : base (e1, e2)
186                 {
187                         this.op = op;
188                 }
189         }
190 }